2 * linux/drivers/usb/gadget/pxa2xx_udc.c
3 * Intel PXA25x 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
27 /* #define VERBOSE_DEBUG */
29 #include <linux/device.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/ioport.h>
33 #include <linux/types.h>
34 #include <linux/errno.h>
35 #include <linux/delay.h>
36 #include <linux/slab.h>
37 #include <linux/init.h>
38 #include <linux/timer.h>
39 #include <linux/list.h>
40 #include <linux/interrupt.h>
42 #include <linux/platform_device.h>
43 #include <linux/dma-mapping.h>
44 #include <linux/irq.h>
45 #include <linux/clk.h>
46 #include <linux/err.h>
47 #include <linux/seq_file.h>
48 #include <linux/debugfs.h>
50 #include <asm/byteorder.h>
54 #include <asm/system.h>
55 #include <asm/mach-types.h>
56 #include <asm/unaligned.h>
57 #include <asm/hardware.h>
59 #include <linux/usb/ch9.h>
60 #include <linux/usb/gadget.h>
62 #include <asm/mach/udc_pxa2xx.h>
66 * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
67 * series processors. The UDC for the IXP 4xx series is very similar.
68 * There are fifteen endpoints, in addition to ep0.
70 * Such controller drivers work with a gadget driver. The gadget driver
71 * returns descriptors, implements configuration and data protocols used
72 * by the host to interact with this device, and allocates endpoints to
73 * the different protocol interfaces. The controller driver virtualizes
74 * usb hardware so that the gadget drivers will be more portable.
76 * This UDC hardware wants to implement a bit too much USB protocol, so
77 * it constrains the sorts of USB configuration change events that work.
78 * The errata for these chips are misleading; some "fixed" bugs from
79 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
81 * Note that the UDC hardware supports DMA (except on IXP) but that's
82 * not used here. IN-DMA (to host) is simple enough, when the data is
83 * suitably aligned (16 bytes) ... the network stack doesn't do that,
84 * other software can. OUT-DMA is buggy in most chip versions, as well
85 * as poorly designed (data toggle not automatic). So this driver won't
86 * bother using DMA. (Mostly-working IN-DMA support was available in
87 * kernels before 2.6.23, but was never enabled or well tested.)
90 #define DRIVER_VERSION "30-June-2007"
91 #define DRIVER_DESC "PXA 25x USB Device Controller driver"
94 static const char driver_name
[] = "pxa2xx_udc";
96 static const char ep0name
[] = "ep0";
99 #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"
106 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
108 /* IXP doesn't yet support <linux/clk.h> */
109 #define clk_get(dev,name) NULL
110 #define clk_enable(clk) do { } while (0)
111 #define clk_disable(clk) do { } while (0)
112 #define clk_put(clk) do { } while (0)
114 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
117 #include "pxa2xx_udc.h"
120 #ifdef CONFIG_USB_PXA2XX_SMALL
121 #define SIZE_STR " (small)"
126 /* ---------------------------------------------------------------------------
127 * endpoint related parts of the api to the usb controller hardware,
128 * used by gadget driver; and the inner talker-to-hardware core.
129 * ---------------------------------------------------------------------------
132 static void pxa2xx_ep_fifo_flush (struct usb_ep
*ep
);
133 static void nuke (struct pxa2xx_ep
*, int status
);
135 /* one GPIO should be used to detect VBUS from the host */
136 static int is_vbus_present(void)
138 struct pxa2xx_udc_mach_info
*mach
= the_controller
->mach
;
140 if (mach
->gpio_vbus
) {
141 int value
= gpio_get_value(mach
->gpio_vbus
);
142 return mach
->gpio_vbus_inverted
? !value
: value
;
144 if (mach
->udc_is_connected
)
145 return mach
->udc_is_connected();
149 /* one GPIO should control a D+ pullup, so host sees this device (or not) */
150 static void pullup_off(void)
152 struct pxa2xx_udc_mach_info
*mach
= the_controller
->mach
;
154 if (mach
->gpio_pullup
)
155 gpio_set_value(mach
->gpio_pullup
, 0);
156 else if (mach
->udc_command
)
157 mach
->udc_command(PXA2XX_UDC_CMD_DISCONNECT
);
160 static void pullup_on(void)
162 struct pxa2xx_udc_mach_info
*mach
= the_controller
->mach
;
164 if (mach
->gpio_pullup
)
165 gpio_set_value(mach
->gpio_pullup
, 1);
166 else if (mach
->udc_command
)
167 mach
->udc_command(PXA2XX_UDC_CMD_CONNECT
);
170 static void pio_irq_enable(int bEndpointAddress
)
172 bEndpointAddress
&= 0xf;
173 if (bEndpointAddress
< 8)
174 UICR0
&= ~(1 << bEndpointAddress
);
176 bEndpointAddress
-= 8;
177 UICR1
&= ~(1 << bEndpointAddress
);
181 static void pio_irq_disable(int bEndpointAddress
)
183 bEndpointAddress
&= 0xf;
184 if (bEndpointAddress
< 8)
185 UICR0
|= 1 << bEndpointAddress
;
187 bEndpointAddress
-= 8;
188 UICR1
|= 1 << bEndpointAddress
;
192 /* The UDCCR reg contains mask and interrupt status bits,
193 * so using '|=' isn't safe as it may ack an interrupt.
195 #define UDCCR_MASK_BITS (UDCCR_REM | UDCCR_SRM | UDCCR_UDE)
197 static inline void udc_set_mask_UDCCR(int mask
)
199 UDCCR
= (UDCCR
& UDCCR_MASK_BITS
) | (mask
& UDCCR_MASK_BITS
);
202 static inline void udc_clear_mask_UDCCR(int mask
)
204 UDCCR
= (UDCCR
& UDCCR_MASK_BITS
) & ~(mask
& UDCCR_MASK_BITS
);
207 static inline void udc_ack_int_UDCCR(int mask
)
209 /* udccr contains the bits we dont want to change */
210 __u32 udccr
= UDCCR
& UDCCR_MASK_BITS
;
212 UDCCR
= udccr
| (mask
& ~UDCCR_MASK_BITS
);
216 * endpoint enable/disable
218 * we need to verify the descriptors used to enable endpoints. since pxa2xx
219 * endpoint configurations are fixed, and are pretty much always enabled,
220 * there's not a lot to manage here.
222 * because pxa2xx can't selectively initialize bulk (or interrupt) endpoints,
223 * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
224 * for a single interface (with only the default altsetting) and for gadget
225 * drivers that don't halt endpoints (not reset by set_interface). that also
226 * means that if you use ISO, you must violate the USB spec rule that all
227 * iso endpoints must be in non-default altsettings.
229 static int pxa2xx_ep_enable (struct usb_ep
*_ep
,
230 const struct usb_endpoint_descriptor
*desc
)
232 struct pxa2xx_ep
*ep
;
233 struct pxa2xx_udc
*dev
;
235 ep
= container_of (_ep
, struct pxa2xx_ep
, ep
);
236 if (!_ep
|| !desc
|| ep
->desc
|| _ep
->name
== ep0name
237 || desc
->bDescriptorType
!= USB_DT_ENDPOINT
238 || ep
->bEndpointAddress
!= desc
->bEndpointAddress
239 || ep
->fifo_size
< le16_to_cpu
240 (desc
->wMaxPacketSize
)) {
241 DMSG("%s, bad ep or descriptor\n", __FUNCTION__
);
245 /* xfer types must match, except that interrupt ~= bulk */
246 if (ep
->bmAttributes
!= desc
->bmAttributes
247 && ep
->bmAttributes
!= USB_ENDPOINT_XFER_BULK
248 && desc
->bmAttributes
!= USB_ENDPOINT_XFER_INT
) {
249 DMSG("%s, %s type mismatch\n", __FUNCTION__
, _ep
->name
);
253 /* hardware _could_ do smaller, but driver doesn't */
254 if ((desc
->bmAttributes
== USB_ENDPOINT_XFER_BULK
255 && le16_to_cpu (desc
->wMaxPacketSize
)
257 || !desc
->wMaxPacketSize
) {
258 DMSG("%s, bad %s maxpacket\n", __FUNCTION__
, _ep
->name
);
263 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
264 DMSG("%s, bogus device state\n", __FUNCTION__
);
271 ep
->ep
.maxpacket
= le16_to_cpu (desc
->wMaxPacketSize
);
273 /* flush fifo (mostly for OUT buffers) */
274 pxa2xx_ep_fifo_flush (_ep
);
276 /* ... reset halt state too, if we could ... */
278 DBG(DBG_VERBOSE
, "enabled %s\n", _ep
->name
);
282 static int pxa2xx_ep_disable (struct usb_ep
*_ep
)
284 struct pxa2xx_ep
*ep
;
287 ep
= container_of (_ep
, struct pxa2xx_ep
, ep
);
288 if (!_ep
|| !ep
->desc
) {
289 DMSG("%s, %s not enabled\n", __FUNCTION__
,
290 _ep
? ep
->ep
.name
: NULL
);
293 local_irq_save(flags
);
295 nuke (ep
, -ESHUTDOWN
);
297 /* flush fifo (mostly for IN buffers) */
298 pxa2xx_ep_fifo_flush (_ep
);
303 local_irq_restore(flags
);
304 DBG(DBG_VERBOSE
, "%s disabled\n", _ep
->name
);
308 /*-------------------------------------------------------------------------*/
310 /* for the pxa2xx, these can just wrap kmalloc/kfree. gadget drivers
311 * must still pass correctly initialized endpoints, since other controller
312 * drivers may care about how it's currently set up (dma issues etc).
316 * pxa2xx_ep_alloc_request - allocate a request data structure
318 static struct usb_request
*
319 pxa2xx_ep_alloc_request (struct usb_ep
*_ep
, gfp_t gfp_flags
)
321 struct pxa2xx_request
*req
;
323 req
= kzalloc(sizeof(*req
), gfp_flags
);
327 INIT_LIST_HEAD (&req
->queue
);
333 * pxa2xx_ep_free_request - deallocate a request data structure
336 pxa2xx_ep_free_request (struct usb_ep
*_ep
, struct usb_request
*_req
)
338 struct pxa2xx_request
*req
;
340 req
= container_of (_req
, struct pxa2xx_request
, req
);
341 WARN_ON (!list_empty (&req
->queue
));
345 /*-------------------------------------------------------------------------*/
348 * done - retire a request; caller blocked irqs
350 static void done(struct pxa2xx_ep
*ep
, struct pxa2xx_request
*req
, int status
)
352 unsigned stopped
= ep
->stopped
;
354 list_del_init(&req
->queue
);
356 if (likely (req
->req
.status
== -EINPROGRESS
))
357 req
->req
.status
= status
;
359 status
= req
->req
.status
;
361 if (status
&& status
!= -ESHUTDOWN
)
362 DBG(DBG_VERBOSE
, "complete %s req %p stat %d len %u/%u\n",
363 ep
->ep
.name
, &req
->req
, status
,
364 req
->req
.actual
, req
->req
.length
);
366 /* don't modify queue heads during completion callback */
368 req
->req
.complete(&ep
->ep
, &req
->req
);
369 ep
->stopped
= stopped
;
373 static inline void ep0_idle (struct pxa2xx_udc
*dev
)
375 dev
->ep0state
= EP0_IDLE
;
379 write_packet(volatile u32
*uddr
, struct pxa2xx_request
*req
, unsigned max
)
382 unsigned length
, count
;
384 buf
= req
->req
.buf
+ req
->req
.actual
;
387 /* how big will this packet be? */
388 length
= min(req
->req
.length
- req
->req
.actual
, max
);
389 req
->req
.actual
+= length
;
392 while (likely(count
--))
399 * write to an IN endpoint fifo, as many packets as possible.
400 * irqs will use this to write the rest later.
401 * caller guarantees at least one packet buffer is ready (or a zlp).
404 write_fifo (struct pxa2xx_ep
*ep
, struct pxa2xx_request
*req
)
408 max
= le16_to_cpu(ep
->desc
->wMaxPacketSize
);
411 int is_last
, is_short
;
413 count
= write_packet(ep
->reg_uddr
, req
, max
);
415 /* last packet is usually short (or a zlp) */
416 if (unlikely (count
!= max
))
417 is_last
= is_short
= 1;
419 if (likely(req
->req
.length
!= req
->req
.actual
)
424 /* interrupt/iso maxpacket may not fill the fifo */
425 is_short
= unlikely (max
< ep
->fifo_size
);
428 DBG(DBG_VERY_NOISY
, "wrote %s %d bytes%s%s %d left %p\n",
430 is_last
? "/L" : "", is_short
? "/S" : "",
431 req
->req
.length
- req
->req
.actual
, req
);
433 /* let loose that packet. maybe try writing another one,
434 * double buffering might work. TSP, TPC, and TFS
435 * bit values are the same for all normal IN endpoints.
437 *ep
->reg_udccs
= UDCCS_BI_TPC
;
439 *ep
->reg_udccs
= UDCCS_BI_TSP
;
441 /* requests complete when all IN data is in the FIFO */
444 if (list_empty(&ep
->queue
))
445 pio_irq_disable (ep
->bEndpointAddress
);
449 // TODO experiment: how robust can fifo mode tweaking be?
450 // double buffering is off in the default fifo mode, which
451 // prevents TFS from being set here.
453 } while (*ep
->reg_udccs
& UDCCS_BI_TFS
);
457 /* caller asserts req->pending (ep0 irq status nyet cleared); starts
458 * ep0 data stage. these chips want very simple state transitions.
461 void ep0start(struct pxa2xx_udc
*dev
, u32 flags
, const char *tag
)
463 UDCCS0
= flags
|UDCCS0_SA
|UDCCS0_OPR
;
465 dev
->req_pending
= 0;
466 DBG(DBG_VERY_NOISY
, "%s %s, %02x/%02x\n",
467 __FUNCTION__
, tag
, UDCCS0
, flags
);
471 write_ep0_fifo (struct pxa2xx_ep
*ep
, struct pxa2xx_request
*req
)
476 count
= write_packet(&UDDR0
, req
, EP0_FIFO_SIZE
);
477 ep
->dev
->stats
.write
.bytes
+= count
;
479 /* last packet "must be" short (or a zlp) */
480 is_short
= (count
!= EP0_FIFO_SIZE
);
482 DBG(DBG_VERY_NOISY
, "ep0in %d bytes %d left %p\n", count
,
483 req
->req
.length
- req
->req
.actual
, req
);
485 if (unlikely (is_short
)) {
486 if (ep
->dev
->req_pending
)
487 ep0start(ep
->dev
, UDCCS0_IPR
, "short IN");
491 count
= req
->req
.length
;
494 #ifndef CONFIG_ARCH_IXP4XX
496 /* This seems to get rid of lost status irqs in some cases:
497 * host responds quickly, or next request involves config
498 * change automagic, or should have been hidden, or ...
500 * FIXME get rid of all udelays possible...
502 if (count
>= EP0_FIFO_SIZE
) {
505 if ((UDCCS0
& UDCCS0_OPR
) != 0) {
506 /* clear OPR, generate ack */
516 } else if (ep
->dev
->req_pending
)
517 ep0start(ep
->dev
, 0, "IN");
523 * read_fifo - unload packet(s) from the fifo we use for usb OUT
524 * transfers and put them into the request. caller should have made
525 * sure there's at least one packet ready.
527 * returns true if the request completed because of short packet or the
528 * request buffer having filled (and maybe overran till end-of-packet).
531 read_fifo (struct pxa2xx_ep
*ep
, struct pxa2xx_request
*req
)
536 unsigned bufferspace
, count
, is_short
;
538 /* make sure there's a packet in the FIFO.
539 * UDCCS_{BO,IO}_RPC are all the same bit value.
540 * UDCCS_{BO,IO}_RNE are all the same bit value.
542 udccs
= *ep
->reg_udccs
;
543 if (unlikely ((udccs
& UDCCS_BO_RPC
) == 0))
545 buf
= req
->req
.buf
+ req
->req
.actual
;
547 bufferspace
= req
->req
.length
- req
->req
.actual
;
549 /* read all bytes from this packet */
550 if (likely (udccs
& UDCCS_BO_RNE
)) {
551 count
= 1 + (0x0ff & *ep
->reg_ubcr
);
552 req
->req
.actual
+= min (count
, bufferspace
);
555 is_short
= (count
< ep
->ep
.maxpacket
);
556 DBG(DBG_VERY_NOISY
, "read %s %02x, %d bytes%s req %p %d/%d\n",
557 ep
->ep
.name
, udccs
, count
,
558 is_short
? "/S" : "",
559 req
, req
->req
.actual
, req
->req
.length
);
560 while (likely (count
-- != 0)) {
561 u8 byte
= (u8
) *ep
->reg_uddr
;
563 if (unlikely (bufferspace
== 0)) {
564 /* this happens when the driver's buffer
565 * is smaller than what the host sent.
566 * discard the extra data.
568 if (req
->req
.status
!= -EOVERFLOW
)
569 DMSG("%s overflow %d\n",
571 req
->req
.status
= -EOVERFLOW
;
577 *ep
->reg_udccs
= UDCCS_BO_RPC
;
578 /* RPC/RSP/RNE could now reflect the other packet buffer */
580 /* iso is one request per packet */
581 if (ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
) {
582 if (udccs
& UDCCS_IO_ROF
)
583 req
->req
.status
= -EHOSTUNREACH
;
584 /* more like "is_done" */
589 if (is_short
|| req
->req
.actual
== req
->req
.length
) {
591 if (list_empty(&ep
->queue
))
592 pio_irq_disable (ep
->bEndpointAddress
);
596 /* finished that packet. the next one may be waiting... */
602 * special ep0 version of the above. no UBCR0 or double buffering; status
603 * handshaking is magic. most device protocols don't need control-OUT.
604 * CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
605 * protocols do use them.
608 read_ep0_fifo (struct pxa2xx_ep
*ep
, struct pxa2xx_request
*req
)
611 unsigned bufferspace
;
613 buf
= req
->req
.buf
+ req
->req
.actual
;
614 bufferspace
= req
->req
.length
- req
->req
.actual
;
616 while (UDCCS0
& UDCCS0_RNE
) {
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\n", ep
->ep
.name
);
626 req
->req
.status
= -EOVERFLOW
;
634 UDCCS0
= UDCCS0_OPR
| UDCCS0_IPR
;
637 if (req
->req
.actual
>= req
->req
.length
)
640 /* finished that packet. the next one may be waiting... */
644 /*-------------------------------------------------------------------------*/
647 pxa2xx_ep_queue(struct usb_ep
*_ep
, struct usb_request
*_req
, gfp_t gfp_flags
)
649 struct pxa2xx_request
*req
;
650 struct pxa2xx_ep
*ep
;
651 struct pxa2xx_udc
*dev
;
654 req
= container_of(_req
, struct pxa2xx_request
, req
);
655 if (unlikely (!_req
|| !_req
->complete
|| !_req
->buf
656 || !list_empty(&req
->queue
))) {
657 DMSG("%s, bad params\n", __FUNCTION__
);
661 ep
= container_of(_ep
, struct pxa2xx_ep
, ep
);
662 if (unlikely (!_ep
|| (!ep
->desc
&& ep
->ep
.name
!= ep0name
))) {
663 DMSG("%s, bad ep\n", __FUNCTION__
);
668 if (unlikely (!dev
->driver
669 || dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)) {
670 DMSG("%s, bogus device state\n", __FUNCTION__
);
674 /* iso is always one packet per request, that's the only way
675 * we can report per-packet status. that also helps with dma.
677 if (unlikely (ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
678 && req
->req
.length
> le16_to_cpu
679 (ep
->desc
->wMaxPacketSize
)))
682 DBG(DBG_NOISY
, "%s queue req %p, len %d buf %p\n",
683 _ep
->name
, _req
, _req
->length
, _req
->buf
);
685 local_irq_save(flags
);
687 _req
->status
= -EINPROGRESS
;
690 /* kickstart this i/o queue? */
691 if (list_empty(&ep
->queue
) && !ep
->stopped
) {
692 if (ep
->desc
== NULL
/* ep0 */) {
693 unsigned length
= _req
->length
;
695 switch (dev
->ep0state
) {
696 case EP0_IN_DATA_PHASE
:
697 dev
->stats
.write
.ops
++;
698 if (write_ep0_fifo(ep
, req
))
702 case EP0_OUT_DATA_PHASE
:
703 dev
->stats
.read
.ops
++;
705 if (dev
->req_config
) {
706 DBG(DBG_VERBOSE
, "ep0 config ack%s\n",
707 dev
->has_cfr
? "" : " raced");
709 UDCCFR
= UDCCFR_AREN
|UDCCFR_ACM
712 dev
->ep0state
= EP0_END_XFER
;
713 local_irq_restore (flags
);
716 if (dev
->req_pending
)
717 ep0start(dev
, UDCCS0_IPR
, "OUT");
718 if (length
== 0 || ((UDCCS0
& UDCCS0_RNE
) != 0
719 && read_ep0_fifo(ep
, req
))) {
727 DMSG("ep0 i/o, odd state %d\n", dev
->ep0state
);
728 local_irq_restore (flags
);
731 /* can the FIFO can satisfy the request immediately? */
732 } else if ((ep
->bEndpointAddress
& USB_DIR_IN
) != 0) {
733 if ((*ep
->reg_udccs
& UDCCS_BI_TFS
) != 0
734 && write_fifo(ep
, req
))
736 } else if ((*ep
->reg_udccs
& UDCCS_BO_RFS
) != 0
737 && read_fifo(ep
, req
)) {
741 if (likely (req
&& ep
->desc
))
742 pio_irq_enable(ep
->bEndpointAddress
);
745 /* pio or dma irq handler advances the queue. */
746 if (likely(req
!= NULL
))
747 list_add_tail(&req
->queue
, &ep
->queue
);
748 local_irq_restore(flags
);
755 * nuke - dequeue ALL requests
757 static void nuke(struct pxa2xx_ep
*ep
, int status
)
759 struct pxa2xx_request
*req
;
761 /* called with irqs blocked */
762 while (!list_empty(&ep
->queue
)) {
763 req
= list_entry(ep
->queue
.next
,
764 struct pxa2xx_request
,
766 done(ep
, req
, status
);
769 pio_irq_disable (ep
->bEndpointAddress
);
773 /* dequeue JUST ONE request */
774 static int pxa2xx_ep_dequeue(struct usb_ep
*_ep
, struct usb_request
*_req
)
776 struct pxa2xx_ep
*ep
;
777 struct pxa2xx_request
*req
;
780 ep
= container_of(_ep
, struct pxa2xx_ep
, ep
);
781 if (!_ep
|| ep
->ep
.name
== ep0name
)
784 local_irq_save(flags
);
786 /* make sure it's actually queued on this endpoint */
787 list_for_each_entry (req
, &ep
->queue
, queue
) {
788 if (&req
->req
== _req
)
791 if (&req
->req
!= _req
) {
792 local_irq_restore(flags
);
796 done(ep
, req
, -ECONNRESET
);
798 local_irq_restore(flags
);
802 /*-------------------------------------------------------------------------*/
804 static int pxa2xx_ep_set_halt(struct usb_ep
*_ep
, int value
)
806 struct pxa2xx_ep
*ep
;
809 ep
= container_of(_ep
, struct pxa2xx_ep
, ep
);
811 || (!ep
->desc
&& ep
->ep
.name
!= ep0name
))
812 || ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
) {
813 DMSG("%s, bad ep\n", __FUNCTION__
);
817 /* this path (reset toggle+halt) is needed to implement
818 * SET_INTERFACE on normal hardware. but it can't be
819 * done from software on the PXA UDC, and the hardware
820 * forgets to do it as part of SET_INTERFACE automagic.
822 DMSG("only host can clear %s halt\n", _ep
->name
);
826 local_irq_save(flags
);
828 if ((ep
->bEndpointAddress
& USB_DIR_IN
) != 0
829 && ((*ep
->reg_udccs
& UDCCS_BI_TFS
) == 0
830 || !list_empty(&ep
->queue
))) {
831 local_irq_restore(flags
);
835 /* FST bit is the same for control, bulk in, bulk out, interrupt in */
836 *ep
->reg_udccs
= UDCCS_BI_FST
|UDCCS_BI_FTF
;
838 /* ep0 needs special care */
840 start_watchdog(ep
->dev
);
841 ep
->dev
->req_pending
= 0;
842 ep
->dev
->ep0state
= EP0_STALL
;
844 /* and bulk/intr endpoints like dropping stalls too */
847 for (i
= 0; i
< 1000; i
+= 20) {
848 if (*ep
->reg_udccs
& UDCCS_BI_SST
)
853 local_irq_restore(flags
);
855 DBG(DBG_VERBOSE
, "%s halt\n", _ep
->name
);
859 static int pxa2xx_ep_fifo_status(struct usb_ep
*_ep
)
861 struct pxa2xx_ep
*ep
;
863 ep
= container_of(_ep
, struct pxa2xx_ep
, ep
);
865 DMSG("%s, bad ep\n", __FUNCTION__
);
868 /* pxa can't report unclaimed bytes from IN fifos */
869 if ((ep
->bEndpointAddress
& USB_DIR_IN
) != 0)
871 if (ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
872 || (*ep
->reg_udccs
& UDCCS_BO_RFS
) == 0)
875 return (*ep
->reg_ubcr
& 0xfff) + 1;
878 static void pxa2xx_ep_fifo_flush(struct usb_ep
*_ep
)
880 struct pxa2xx_ep
*ep
;
882 ep
= container_of(_ep
, struct pxa2xx_ep
, ep
);
883 if (!_ep
|| ep
->ep
.name
== ep0name
|| !list_empty(&ep
->queue
)) {
884 DMSG("%s, bad ep\n", __FUNCTION__
);
888 /* toggle and halt bits stay unchanged */
890 /* for OUT, just read and discard the FIFO contents. */
891 if ((ep
->bEndpointAddress
& USB_DIR_IN
) == 0) {
892 while (((*ep
->reg_udccs
) & UDCCS_BO_RNE
) != 0)
893 (void) *ep
->reg_uddr
;
897 /* most IN status is the same, but ISO can't stall */
898 *ep
->reg_udccs
= UDCCS_BI_TPC
|UDCCS_BI_FTF
|UDCCS_BI_TUR
899 | (ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
)
904 static struct usb_ep_ops pxa2xx_ep_ops
= {
905 .enable
= pxa2xx_ep_enable
,
906 .disable
= pxa2xx_ep_disable
,
908 .alloc_request
= pxa2xx_ep_alloc_request
,
909 .free_request
= pxa2xx_ep_free_request
,
911 .queue
= pxa2xx_ep_queue
,
912 .dequeue
= pxa2xx_ep_dequeue
,
914 .set_halt
= pxa2xx_ep_set_halt
,
915 .fifo_status
= pxa2xx_ep_fifo_status
,
916 .fifo_flush
= pxa2xx_ep_fifo_flush
,
920 /* ---------------------------------------------------------------------------
921 * device-scoped parts of the api to the usb controller hardware
922 * ---------------------------------------------------------------------------
925 static int pxa2xx_udc_get_frame(struct usb_gadget
*_gadget
)
927 return ((UFNRH
& 0x07) << 8) | (UFNRL
& 0xff);
930 static int pxa2xx_udc_wakeup(struct usb_gadget
*_gadget
)
932 /* host may not have enabled remote wakeup */
933 if ((UDCCS0
& UDCCS0_DRWF
) == 0)
934 return -EHOSTUNREACH
;
935 udc_set_mask_UDCCR(UDCCR_RSM
);
939 static void stop_activity(struct pxa2xx_udc
*, struct usb_gadget_driver
*);
940 static void udc_enable (struct pxa2xx_udc
*);
941 static void udc_disable(struct pxa2xx_udc
*);
943 /* We disable the UDC -- and its 48 MHz clock -- whenever it's not
946 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
947 static int pullup(struct pxa2xx_udc
*udc
, int is_active
)
949 static int pullup(struct pxa2xx_udc
*udc
)
950 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
952 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
953 is_active
= is_active
&& udc
->vbus
&& udc
->pullup
;
955 int is_active
= udc
->vbus
&& udc
->pullup
&& !udc
->suspended
;
956 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
957 DMSG("%s\n", is_active
? "active" : "inactive");
958 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
962 if (udc
->gadget
.speed
!= USB_SPEED_UNKNOWN
) {
963 DMSG("disconnect %s\n", udc
->driver
964 ? udc
->driver
->driver
.name
966 stop_activity(udc
, udc
->driver
);
971 /* Enable clock for USB device */
972 clk_enable(udc
->clk
);
974 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
976 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
981 if (udc
->gadget
.speed
!= USB_SPEED_UNKNOWN
) {
982 DMSG("disconnect %s\n", udc
->driver
983 ? udc
->driver
->driver
.name
985 stop_activity(udc
, udc
->driver
);
988 /* Disable clock for USB device */
989 clk_disable(udc
->clk
);
993 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
998 /* VBUS reporting logically comes from a transceiver */
999 static int pxa2xx_udc_vbus_session(struct usb_gadget
*_gadget
, int is_active
)
1001 struct pxa2xx_udc
*udc
;
1003 udc
= container_of(_gadget
, struct pxa2xx_udc
, gadget
);
1004 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1005 udc
->vbus
= is_active
= (is_active
!= 0);
1007 udc
->vbus
= (is_active
!= 0);
1008 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1009 DMSG("vbus %s\n", is_active
? "supplied" : "inactive");
1010 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1011 pullup(udc
, is_active
);
1014 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1018 /* drivers may have software control over D+ pullup */
1019 static int pxa2xx_udc_pullup(struct usb_gadget
*_gadget
, int is_active
)
1021 struct pxa2xx_udc
*udc
;
1023 udc
= container_of(_gadget
, struct pxa2xx_udc
, gadget
);
1025 /* not all boards support pullup control */
1026 if (!udc
->mach
->gpio_pullup
&& !udc
->mach
->udc_command
)
1029 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1030 is_active
= (is_active
!= 0);
1031 udc
->pullup
= is_active
;
1032 pullup(udc
, is_active
);
1034 udc
->pullup
= (is_active
!= 0);
1036 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1040 static const struct usb_gadget_ops pxa2xx_udc_ops
= {
1041 .get_frame
= pxa2xx_udc_get_frame
,
1042 .wakeup
= pxa2xx_udc_wakeup
,
1043 .vbus_session
= pxa2xx_udc_vbus_session
,
1044 .pullup
= pxa2xx_udc_pullup
,
1046 // .vbus_draw ... boards may consume current from VBUS, up to
1047 // 100-500mA based on config. the 500uA suspend ceiling means
1048 // that exclusively vbus-powered PXA designs violate USB specs.
1051 /*-------------------------------------------------------------------------*/
1053 #ifdef CONFIG_USB_GADGET_DEBUG_FS
1056 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1057 udc_seq_show(struct seq_file
*m
, void *d
)
1059 udc_seq_show(struct seq_file
*m
, void *_d
)
1060 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1062 struct pxa2xx_udc
*dev
= m
->private;
1063 unsigned long flags
;
1067 local_irq_save(flags
);
1069 /* basic device status */
1070 seq_printf(m
, DRIVER_DESC
"\n"
1071 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1072 driver_name
, DRIVER_VERSION SIZE_STR
"(pio)",
1073 dev
->driver
? dev
->driver
->driver
.name
: "(none)",
1074 is_vbus_present() ? "full speed" : "disconnected");
1076 /* registers for device and ep0 */
1078 "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
1079 UICR1
, UICR0
, USIR1
, USIR0
, UFNRH
, UFNRL
);
1083 "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp
,
1084 (tmp
& UDCCR_REM
) ? " rem" : "",
1085 (tmp
& UDCCR_RSTIR
) ? " rstir" : "",
1086 (tmp
& UDCCR_SRM
) ? " srm" : "",
1087 (tmp
& UDCCR_SUSIR
) ? " susir" : "",
1088 (tmp
& UDCCR_RESIR
) ? " resir" : "",
1089 (tmp
& UDCCR_RSM
) ? " rsm" : "",
1090 (tmp
& UDCCR_UDA
) ? " uda" : "",
1091 (tmp
& UDCCR_UDE
) ? " ude" : "");
1095 "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp
,
1096 (tmp
& UDCCS0_SA
) ? " sa" : "",
1097 (tmp
& UDCCS0_RNE
) ? " rne" : "",
1098 (tmp
& UDCCS0_FST
) ? " fst" : "",
1099 (tmp
& UDCCS0_SST
) ? " sst" : "",
1100 (tmp
& UDCCS0_DRWF
) ? " dwrf" : "",
1101 (tmp
& UDCCS0_FTF
) ? " ftf" : "",
1102 (tmp
& UDCCS0_IPR
) ? " ipr" : "",
1103 (tmp
& UDCCS0_OPR
) ? " opr" : "");
1108 "udccfr %02X =%s%s\n", tmp
,
1109 (tmp
& UDCCFR_AREN
) ? " aren" : "",
1110 (tmp
& UDCCFR_ACM
) ? " acm" : "");
1113 if (!is_vbus_present() || !dev
->driver
)
1116 seq_printf(m
, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
1117 dev
->stats
.write
.bytes
, dev
->stats
.write
.ops
,
1118 dev
->stats
.read
.bytes
, dev
->stats
.read
.ops
,
1121 /* dump endpoint queues */
1122 for (i
= 0; i
< PXA_UDC_NUM_ENDPOINTS
; i
++) {
1123 struct pxa2xx_ep
*ep
= &dev
->ep
[i
];
1124 struct pxa2xx_request
*req
;
1127 const struct usb_endpoint_descriptor
*desc
;
1132 tmp
= *dev
->ep
[i
].reg_udccs
;
1134 "%s max %d %s udccs %02x irqs %lu\n",
1135 ep
->ep
.name
, le16_to_cpu(desc
->wMaxPacketSize
),
1136 "pio", tmp
, ep
->pio_irqs
);
1137 /* TODO translate all five groups of udccs bits! */
1139 } else /* ep0 should only have one transfer queued */
1140 seq_printf(m
, "ep0 max 16 pio irqs %lu\n",
1143 if (list_empty(&ep
->queue
)) {
1144 seq_printf(m
, "\t(nothing queued)\n");
1147 list_for_each_entry(req
, &ep
->queue
, queue
) {
1149 "\treq %p len %d/%d buf %p\n",
1150 &req
->req
, req
->req
.actual
,
1151 req
->req
.length
, req
->req
.buf
);
1156 local_irq_restore(flags
);
1161 udc_debugfs_open(struct inode
*inode
, struct file
*file
)
1163 return single_open(file
, udc_seq_show
, inode
->i_private
);
1166 static const struct file_operations debug_fops
= {
1167 .open
= udc_debugfs_open
,
1169 .llseek
= seq_lseek
,
1170 .release
= single_release
,
1171 .owner
= THIS_MODULE
,
1174 #define create_debug_files(dev) \
1176 dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
1177 S_IRUGO, NULL, dev, &debug_fops); \
1179 #define remove_debug_files(dev) \
1181 if (dev->debugfs_udc) \
1182 debugfs_remove(dev->debugfs_udc); \
1185 #else /* !CONFIG_USB_GADGET_DEBUG_FILES */
1187 #define create_debug_files(dev) do {} while (0)
1188 #define remove_debug_files(dev) do {} while (0)
1190 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1192 /*-------------------------------------------------------------------------*/
1195 * udc_disable - disable USB device controller
1197 static void udc_disable(struct pxa2xx_udc
*dev
)
1199 /* block all irqs */
1200 udc_set_mask_UDCCR(UDCCR_SRM
|UDCCR_REM
);
1201 UICR0
= UICR1
= 0xff;
1204 /* if hardware supports it, disconnect from usb */
1207 udc_clear_mask_UDCCR(UDCCR_UDE
);
1209 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1210 #ifdef CONFIG_ARCH_PXA
1211 /* Disable clock for USB device */
1212 clk_disable(dev
->clk
);
1216 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1218 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1223 * udc_reinit - initialize software state
1225 static void udc_reinit(struct pxa2xx_udc
*dev
)
1229 /* device/ep0 records init */
1230 INIT_LIST_HEAD (&dev
->gadget
.ep_list
);
1231 INIT_LIST_HEAD (&dev
->gadget
.ep0
->ep_list
);
1232 dev
->ep0state
= EP0_IDLE
;
1234 /* basic endpoint records init */
1235 for (i
= 0; i
< PXA_UDC_NUM_ENDPOINTS
; i
++) {
1236 struct pxa2xx_ep
*ep
= &dev
->ep
[i
];
1239 list_add_tail (&ep
->ep
.ep_list
, &dev
->gadget
.ep_list
);
1243 INIT_LIST_HEAD (&ep
->queue
);
1247 /* the rest was statically initialized, and is read-only */
1250 /* until it's enabled, this UDC should be completely invisible
1253 static void udc_enable (struct pxa2xx_udc
*dev
)
1255 udc_clear_mask_UDCCR(UDCCR_UDE
);
1257 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1258 #ifdef CONFIG_ARCH_PXA
1259 /* Enable clock for USB device */
1260 clk_enable(dev
->clk
);
1264 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1265 /* try to clear these bits before we enable the udc */
1266 udc_ack_int_UDCCR(UDCCR_SUSIR
|/*UDCCR_RSTIR|*/UDCCR_RESIR
);
1269 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1270 dev
->stats
.irqs
= 0;
1273 * sequence taken from chapter 12.5.10, PXA250 AppProcDevManual:
1275 * - if RESET is already in progress, ack interrupt
1276 * - unmask reset interrupt
1278 udc_set_mask_UDCCR(UDCCR_UDE
);
1279 if (!(UDCCR
& UDCCR_UDA
))
1280 udc_ack_int_UDCCR(UDCCR_RSTIR
);
1282 if (dev
->has_cfr
/* UDC_RES2 is defined */) {
1283 /* pxa255 (a0+) can avoid a set_config race that could
1284 * prevent gadget drivers from configuring correctly
1286 UDCCFR
= UDCCFR_ACM
| UDCCFR_MB1
;
1288 /* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1)
1289 * which could result in missing packets and interrupts.
1290 * supposedly one bit per endpoint, controlling whether it
1291 * double buffers or not; ACM/AREN bits fit into the holes.
1292 * zero bits (like USIR0_IRx) disable double buffering.
1298 /* enable suspend/resume and reset irqs */
1299 udc_clear_mask_UDCCR(UDCCR_SRM
| UDCCR_REM
);
1301 /* enable ep0 irqs */
1302 UICR0
&= ~UICR0_IM0
;
1304 /* if hardware supports it, pullup D+ and wait for reset */
1309 /* when a driver is successfully registered, it will receive
1310 * control requests including set_configuration(), which enables
1311 * non-control requests. then usb traffic follows until a
1312 * disconnect is reported. then a host may connect again, or
1313 * the driver might get unbound.
1315 int usb_gadget_register_driver(struct usb_gadget_driver
*driver
)
1317 struct pxa2xx_udc
*dev
= the_controller
;
1321 || driver
->speed
< USB_SPEED_FULL
1323 || !driver
->disconnect
1331 /* first hook up the driver ... */
1332 dev
->driver
= driver
;
1333 dev
->gadget
.dev
.driver
= &driver
->driver
;
1336 retval
= device_add (&dev
->gadget
.dev
);
1340 dev
->gadget
.dev
.driver
= NULL
;
1343 retval
= driver
->bind(&dev
->gadget
);
1345 DMSG("bind to driver %s --> error %d\n",
1346 driver
->driver
.name
, retval
);
1347 device_del (&dev
->gadget
.dev
);
1351 /* ... then enable host detection and ep0; and we're ready
1352 * for set_configuration as well as eventual disconnect.
1354 DMSG("registered gadget driver '%s'\n", driver
->driver
.name
);
1355 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1359 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1363 EXPORT_SYMBOL(usb_gadget_register_driver
);
1366 stop_activity(struct pxa2xx_udc
*dev
, struct usb_gadget_driver
*driver
)
1370 /* don't disconnect drivers more than once */
1371 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1373 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1375 /* prevent new request submissions, kill any outstanding requests */
1376 for (i
= 0; i
< PXA_UDC_NUM_ENDPOINTS
; i
++) {
1377 struct pxa2xx_ep
*ep
= &dev
->ep
[i
];
1380 nuke(ep
, -ESHUTDOWN
);
1382 del_timer_sync(&dev
->timer
);
1384 /* report disconnect; the driver is already quiesced */
1386 driver
->disconnect(&dev
->gadget
);
1388 /* re-init driver-visible data structures */
1392 int usb_gadget_unregister_driver(struct usb_gadget_driver
*driver
)
1394 struct pxa2xx_udc
*dev
= the_controller
;
1398 if (!driver
|| driver
!= dev
->driver
|| !driver
->unbind
)
1401 local_irq_disable();
1402 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1407 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
1408 stop_activity(dev
, driver
);
1411 driver
->unbind(&dev
->gadget
);
1412 dev
->gadget
.dev
.driver
= NULL
;
1415 device_del (&dev
->gadget
.dev
);
1417 DMSG("unregistered gadget driver '%s'\n", driver
->driver
.name
);
1421 EXPORT_SYMBOL(usb_gadget_unregister_driver
);
1424 /*-------------------------------------------------------------------------*/
1426 #ifdef CONFIG_ARCH_LUBBOCK
1428 /* Lubbock has separate connect and disconnect irqs. More typical designs
1429 * use one GPIO as the VBUS IRQ, and another to control the D+ pullup.
1433 lubbock_vbus_irq(int irq
, void *_dev
)
1435 struct pxa2xx_udc
*dev
= _dev
;
1440 case LUBBOCK_USB_IRQ
:
1442 disable_irq(LUBBOCK_USB_IRQ
);
1443 enable_irq(LUBBOCK_USB_DISC_IRQ
);
1445 case LUBBOCK_USB_DISC_IRQ
:
1447 disable_irq(LUBBOCK_USB_DISC_IRQ
);
1448 enable_irq(LUBBOCK_USB_IRQ
);
1454 pxa2xx_udc_vbus_session(&dev
->gadget
, vbus
);
1460 static irqreturn_t
udc_vbus_irq(int irq
, void *_dev
)
1462 struct pxa2xx_udc
*dev
= _dev
;
1463 int vbus
= gpio_get_value(dev
->mach
->gpio_vbus
);
1465 if (dev
->mach
->gpio_vbus_inverted
)
1468 pxa2xx_udc_vbus_session(&dev
->gadget
, vbus
);
1473 /*-------------------------------------------------------------------------*/
1475 static inline void clear_ep_state (struct pxa2xx_udc
*dev
)
1479 /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
1480 * fifos, and pending transactions mustn't be continued in any case.
1482 for (i
= 1; i
< PXA_UDC_NUM_ENDPOINTS
; i
++)
1483 nuke(&dev
->ep
[i
], -ECONNABORTED
);
1486 static void udc_watchdog(unsigned long _dev
)
1488 struct pxa2xx_udc
*dev
= (void *)_dev
;
1490 local_irq_disable();
1491 if (dev
->ep0state
== EP0_STALL
1492 && (UDCCS0
& UDCCS0_FST
) == 0
1493 && (UDCCS0
& UDCCS0_SST
) == 0) {
1494 UDCCS0
= UDCCS0_FST
|UDCCS0_FTF
;
1495 DBG(DBG_VERBOSE
, "ep0 re-stall\n");
1496 start_watchdog(dev
);
1501 static void handle_ep0 (struct pxa2xx_udc
*dev
)
1503 u32 udccs0
= UDCCS0
;
1504 struct pxa2xx_ep
*ep
= &dev
->ep
[0];
1505 struct pxa2xx_request
*req
;
1507 struct usb_ctrlrequest r
;
1512 if (list_empty(&ep
->queue
))
1515 req
= list_entry(ep
->queue
.next
, struct pxa2xx_request
, queue
);
1517 /* clear stall status */
1518 if (udccs0
& UDCCS0_SST
) {
1520 UDCCS0
= UDCCS0_SST
;
1521 del_timer(&dev
->timer
);
1525 /* previous request unfinished? non-error iff back-to-back ... */
1526 if ((udccs0
& UDCCS0_SA
) != 0 && dev
->ep0state
!= EP0_IDLE
) {
1528 del_timer(&dev
->timer
);
1532 switch (dev
->ep0state
) {
1534 /* late-breaking status? */
1537 /* start control request? */
1538 if (likely((udccs0
& (UDCCS0_OPR
|UDCCS0_SA
|UDCCS0_RNE
))
1539 == (UDCCS0_OPR
|UDCCS0_SA
|UDCCS0_RNE
))) {
1544 /* read SETUP packet */
1545 for (i
= 0; i
< 8; i
++) {
1546 if (unlikely(!(UDCCS0
& UDCCS0_RNE
))) {
1548 DMSG("SETUP %d!\n", i
);
1551 u
.raw
[i
] = (u8
) UDDR0
;
1553 if (unlikely((UDCCS0
& UDCCS0_RNE
) != 0))
1557 DBG(DBG_VERBOSE
, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1558 u
.r
.bRequestType
, u
.r
.bRequest
,
1559 le16_to_cpu(u
.r
.wValue
),
1560 le16_to_cpu(u
.r
.wIndex
),
1561 le16_to_cpu(u
.r
.wLength
));
1563 /* cope with automagic for some standard requests. */
1564 dev
->req_std
= (u
.r
.bRequestType
& USB_TYPE_MASK
)
1565 == USB_TYPE_STANDARD
;
1566 dev
->req_config
= 0;
1567 dev
->req_pending
= 1;
1568 switch (u
.r
.bRequest
) {
1569 /* hardware restricts gadget drivers here! */
1570 case USB_REQ_SET_CONFIGURATION
:
1571 if (u
.r
.bRequestType
== USB_RECIP_DEVICE
) {
1572 /* reflect hardware's automagic
1573 * up to the gadget driver.
1576 dev
->req_config
= 1;
1577 clear_ep_state(dev
);
1578 /* if !has_cfr, there's no synch
1579 * else use AREN (later) not SA|OPR
1580 * USIR0_IR0 acts edge sensitive
1584 /* ... and here, even more ... */
1585 case USB_REQ_SET_INTERFACE
:
1586 if (u
.r
.bRequestType
== USB_RECIP_INTERFACE
) {
1587 /* udc hardware is broken by design:
1588 * - altsetting may only be zero;
1589 * - hw resets all interfaces' eps;
1590 * - ep reset doesn't include halt(?).
1592 DMSG("broken set_interface (%d/%d)\n",
1593 le16_to_cpu(u
.r
.wIndex
),
1594 le16_to_cpu(u
.r
.wValue
));
1598 /* hardware was supposed to hide this */
1599 case USB_REQ_SET_ADDRESS
:
1600 if (u
.r
.bRequestType
== USB_RECIP_DEVICE
) {
1601 ep0start(dev
, 0, "address");
1607 if (u
.r
.bRequestType
& USB_DIR_IN
)
1608 dev
->ep0state
= EP0_IN_DATA_PHASE
;
1610 dev
->ep0state
= EP0_OUT_DATA_PHASE
;
1612 i
= dev
->driver
->setup(&dev
->gadget
, &u
.r
);
1614 /* hardware automagic preventing STALL... */
1615 if (dev
->req_config
) {
1616 /* hardware sometimes neglects to tell
1617 * tell us about config change events,
1618 * so later ones may fail...
1620 WARN("config change %02x fail %d?\n",
1623 /* TODO experiment: if has_cfr,
1624 * hardware didn't ACK; maybe we
1625 * could actually STALL!
1628 DBG(DBG_VERBOSE
, "protocol STALL, "
1629 "%02x err %d\n", UDCCS0
, i
);
1631 /* the watchdog timer helps deal with cases
1632 * where udc seems to clear FST wrongly, and
1633 * then NAKs instead of STALLing.
1635 ep0start(dev
, UDCCS0_FST
|UDCCS0_FTF
, "stall");
1636 start_watchdog(dev
);
1637 dev
->ep0state
= EP0_STALL
;
1639 /* deferred i/o == no response yet */
1640 } else if (dev
->req_pending
) {
1641 if (likely(dev
->ep0state
== EP0_IN_DATA_PHASE
1642 || dev
->req_std
|| u
.r
.wLength
))
1643 ep0start(dev
, 0, "defer");
1645 ep0start(dev
, UDCCS0_IPR
, "defer/IPR");
1648 /* expect at least one data or status stage irq */
1651 } else if (likely((udccs0
& (UDCCS0_OPR
|UDCCS0_SA
))
1652 == (UDCCS0_OPR
|UDCCS0_SA
))) {
1655 /* pxa210/250 erratum 131 for B0/B1 says RNE lies.
1656 * still observed on a pxa255 a0.
1658 DBG(DBG_VERBOSE
, "e131\n");
1661 /* read SETUP data, but don't trust it too much */
1662 for (i
= 0; i
< 8; i
++)
1663 u
.raw
[i
] = (u8
) UDDR0
;
1664 if ((u
.r
.bRequestType
& USB_RECIP_MASK
)
1667 if (u
.word
[0] == 0 && u
.word
[1] == 0)
1671 /* some random early IRQ:
1674 * - OPR got set, without SA (likely status stage)
1676 UDCCS0
= udccs0
& (UDCCS0_SA
|UDCCS0_OPR
);
1679 case EP0_IN_DATA_PHASE
: /* GET_DESCRIPTOR etc */
1680 if (udccs0
& UDCCS0_OPR
) {
1681 UDCCS0
= UDCCS0_OPR
|UDCCS0_FTF
;
1682 DBG(DBG_VERBOSE
, "ep0in premature status\n");
1686 } else /* irq was IPR clearing */ {
1688 /* this IN packet might finish the request */
1689 (void) write_ep0_fifo(ep
, req
);
1690 } /* else IN token before response was written */
1693 case EP0_OUT_DATA_PHASE
: /* SET_DESCRIPTOR etc */
1694 if (udccs0
& UDCCS0_OPR
) {
1696 /* this OUT packet might finish the request */
1697 if (read_ep0_fifo(ep
, req
))
1699 /* else more OUT packets expected */
1700 } /* else OUT token before read was issued */
1701 } else /* irq was IPR clearing */ {
1702 DBG(DBG_VERBOSE
, "ep0out premature status\n");
1711 /* ack control-IN status (maybe in-zlp was skipped)
1712 * also appears after some config change events.
1714 if (udccs0
& UDCCS0_OPR
)
1715 UDCCS0
= UDCCS0_OPR
;
1719 UDCCS0
= UDCCS0_FST
;
1725 static void handle_ep(struct pxa2xx_ep
*ep
)
1727 struct pxa2xx_request
*req
;
1728 int is_in
= ep
->bEndpointAddress
& USB_DIR_IN
;
1734 if (likely (!list_empty(&ep
->queue
)))
1735 req
= list_entry(ep
->queue
.next
,
1736 struct pxa2xx_request
, queue
);
1740 // TODO check FST handling
1742 udccs
= *ep
->reg_udccs
;
1743 if (unlikely(is_in
)) { /* irq from TPC, SST, or (ISO) TUR */
1745 if (likely(ep
->bmAttributes
== USB_ENDPOINT_XFER_BULK
))
1746 tmp
|= UDCCS_BI_SST
;
1749 *ep
->reg_udccs
= tmp
;
1750 if (req
&& likely ((udccs
& UDCCS_BI_TFS
) != 0))
1751 completed
= write_fifo(ep
, req
);
1753 } else { /* irq from RPC (or for ISO, ROF) */
1754 if (likely(ep
->bmAttributes
== USB_ENDPOINT_XFER_BULK
))
1755 tmp
= UDCCS_BO_SST
| UDCCS_BO_DME
;
1757 tmp
= UDCCS_IO_ROF
| UDCCS_IO_DME
;
1760 *ep
->reg_udccs
= tmp
;
1762 /* fifos can hold packets, ready for reading... */
1764 completed
= read_fifo(ep
, req
);
1766 pio_irq_disable (ep
->bEndpointAddress
);
1769 } while (completed
);
1773 * pxa2xx_udc_irq - interrupt handler
1775 * avoid delays in ep0 processing. the control handshaking isn't always
1776 * under software control (pxa250c0 and the pxa255 are better), and delays
1777 * could cause usb protocol errors.
1780 pxa2xx_udc_irq(int irq
, void *_dev
)
1782 struct pxa2xx_udc
*dev
= _dev
;
1791 /* SUSpend Interrupt Request */
1792 if (unlikely(udccr
& UDCCR_SUSIR
)) {
1793 udc_ack_int_UDCCR(UDCCR_SUSIR
);
1795 DBG(DBG_VERBOSE
, "USB suspend%s\n", is_vbus_present()
1796 ? "" : "+disconnect");
1798 if (!is_vbus_present())
1799 stop_activity(dev
, dev
->driver
);
1800 else if (dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
1802 && dev
->driver
->suspend
)
1803 dev
->driver
->suspend(&dev
->gadget
);
1807 /* RESume Interrupt Request */
1808 if (unlikely(udccr
& UDCCR_RESIR
)) {
1809 udc_ack_int_UDCCR(UDCCR_RESIR
);
1811 DBG(DBG_VERBOSE
, "USB resume\n");
1813 if (dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
1815 && dev
->driver
->resume
1816 && is_vbus_present())
1817 dev
->driver
->resume(&dev
->gadget
);
1820 /* ReSeT Interrupt Request - USB reset */
1821 if (unlikely(udccr
& UDCCR_RSTIR
)) {
1822 udc_ack_int_UDCCR(UDCCR_RSTIR
);
1825 if ((UDCCR
& UDCCR_UDA
) == 0) {
1826 DBG(DBG_VERBOSE
, "USB reset start\n");
1828 /* reset driver and endpoints,
1829 * in case that's not yet done
1831 stop_activity (dev
, dev
->driver
);
1834 DBG(DBG_VERBOSE
, "USB reset end\n");
1835 dev
->gadget
.speed
= USB_SPEED_FULL
;
1836 memset(&dev
->stats
, 0, sizeof dev
->stats
);
1837 /* driver and endpoints are still reset */
1841 u32 usir0
= USIR0
& ~UICR0
;
1842 u32 usir1
= USIR1
& ~UICR1
;
1845 if (unlikely (!usir0
&& !usir1
))
1848 DBG(DBG_VERY_NOISY
, "irq %02x.%02x\n", usir1
, usir0
);
1850 /* control traffic */
1851 if (usir0
& USIR0_IR0
) {
1852 dev
->ep
[0].pio_irqs
++;
1857 /* endpoint data transfers */
1858 for (i
= 0; i
< 8; i
++) {
1861 if (i
&& (usir0
& tmp
)) {
1862 handle_ep(&dev
->ep
[i
]);
1867 handle_ep(&dev
->ep
[i
+8]);
1874 /* we could also ask for 1 msec SOF (SIR) interrupts */
1880 /*-------------------------------------------------------------------------*/
1882 static void nop_release (struct device
*dev
)
1884 DMSG("%s %s\n", __FUNCTION__
, dev
->bus_id
);
1887 /* this uses load-time allocation and initialization (instead of
1888 * doing it at run-time) to save code, eliminate fault paths, and
1889 * be more obviously correct.
1891 static struct pxa2xx_udc memory
= {
1893 .ops
= &pxa2xx_udc_ops
,
1894 .ep0
= &memory
.ep
[0].ep
,
1895 .name
= driver_name
,
1898 .release
= nop_release
,
1902 /* control endpoint */
1906 .ops
= &pxa2xx_ep_ops
,
1907 .maxpacket
= EP0_FIFO_SIZE
,
1910 .reg_udccs
= &UDCCS0
,
1914 /* first group of endpoints */
1917 .name
= "ep1in-bulk",
1918 .ops
= &pxa2xx_ep_ops
,
1919 .maxpacket
= BULK_FIFO_SIZE
,
1922 .fifo_size
= BULK_FIFO_SIZE
,
1923 .bEndpointAddress
= USB_DIR_IN
| 1,
1924 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
1925 .reg_udccs
= &UDCCS1
,
1930 .name
= "ep2out-bulk",
1931 .ops
= &pxa2xx_ep_ops
,
1932 .maxpacket
= BULK_FIFO_SIZE
,
1935 .fifo_size
= BULK_FIFO_SIZE
,
1936 .bEndpointAddress
= 2,
1937 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
1938 .reg_udccs
= &UDCCS2
,
1942 #ifndef CONFIG_USB_PXA2XX_SMALL
1945 .name
= "ep3in-iso",
1946 .ops
= &pxa2xx_ep_ops
,
1947 .maxpacket
= ISO_FIFO_SIZE
,
1950 .fifo_size
= ISO_FIFO_SIZE
,
1951 .bEndpointAddress
= USB_DIR_IN
| 3,
1952 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
1953 .reg_udccs
= &UDCCS3
,
1958 .name
= "ep4out-iso",
1959 .ops
= &pxa2xx_ep_ops
,
1960 .maxpacket
= ISO_FIFO_SIZE
,
1963 .fifo_size
= ISO_FIFO_SIZE
,
1964 .bEndpointAddress
= 4,
1965 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
1966 .reg_udccs
= &UDCCS4
,
1972 .name
= "ep5in-int",
1973 .ops
= &pxa2xx_ep_ops
,
1974 .maxpacket
= INT_FIFO_SIZE
,
1977 .fifo_size
= INT_FIFO_SIZE
,
1978 .bEndpointAddress
= USB_DIR_IN
| 5,
1979 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
1980 .reg_udccs
= &UDCCS5
,
1984 /* second group of endpoints */
1987 .name
= "ep6in-bulk",
1988 .ops
= &pxa2xx_ep_ops
,
1989 .maxpacket
= BULK_FIFO_SIZE
,
1992 .fifo_size
= BULK_FIFO_SIZE
,
1993 .bEndpointAddress
= USB_DIR_IN
| 6,
1994 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
1995 .reg_udccs
= &UDCCS6
,
2000 .name
= "ep7out-bulk",
2001 .ops
= &pxa2xx_ep_ops
,
2002 .maxpacket
= BULK_FIFO_SIZE
,
2005 .fifo_size
= BULK_FIFO_SIZE
,
2006 .bEndpointAddress
= 7,
2007 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
2008 .reg_udccs
= &UDCCS7
,
2014 .name
= "ep8in-iso",
2015 .ops
= &pxa2xx_ep_ops
,
2016 .maxpacket
= ISO_FIFO_SIZE
,
2019 .fifo_size
= ISO_FIFO_SIZE
,
2020 .bEndpointAddress
= USB_DIR_IN
| 8,
2021 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
2022 .reg_udccs
= &UDCCS8
,
2027 .name
= "ep9out-iso",
2028 .ops
= &pxa2xx_ep_ops
,
2029 .maxpacket
= ISO_FIFO_SIZE
,
2032 .fifo_size
= ISO_FIFO_SIZE
,
2033 .bEndpointAddress
= 9,
2034 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
2035 .reg_udccs
= &UDCCS9
,
2041 .name
= "ep10in-int",
2042 .ops
= &pxa2xx_ep_ops
,
2043 .maxpacket
= INT_FIFO_SIZE
,
2046 .fifo_size
= INT_FIFO_SIZE
,
2047 .bEndpointAddress
= USB_DIR_IN
| 10,
2048 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
2049 .reg_udccs
= &UDCCS10
,
2050 .reg_uddr
= &UDDR10
,
2053 /* third group of endpoints */
2056 .name
= "ep11in-bulk",
2057 .ops
= &pxa2xx_ep_ops
,
2058 .maxpacket
= BULK_FIFO_SIZE
,
2061 .fifo_size
= BULK_FIFO_SIZE
,
2062 .bEndpointAddress
= USB_DIR_IN
| 11,
2063 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
2064 .reg_udccs
= &UDCCS11
,
2065 .reg_uddr
= &UDDR11
,
2069 .name
= "ep12out-bulk",
2070 .ops
= &pxa2xx_ep_ops
,
2071 .maxpacket
= BULK_FIFO_SIZE
,
2074 .fifo_size
= BULK_FIFO_SIZE
,
2075 .bEndpointAddress
= 12,
2076 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
2077 .reg_udccs
= &UDCCS12
,
2078 .reg_ubcr
= &UBCR12
,
2079 .reg_uddr
= &UDDR12
,
2083 .name
= "ep13in-iso",
2084 .ops
= &pxa2xx_ep_ops
,
2085 .maxpacket
= ISO_FIFO_SIZE
,
2088 .fifo_size
= ISO_FIFO_SIZE
,
2089 .bEndpointAddress
= USB_DIR_IN
| 13,
2090 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
2091 .reg_udccs
= &UDCCS13
,
2092 .reg_uddr
= &UDDR13
,
2096 .name
= "ep14out-iso",
2097 .ops
= &pxa2xx_ep_ops
,
2098 .maxpacket
= ISO_FIFO_SIZE
,
2101 .fifo_size
= ISO_FIFO_SIZE
,
2102 .bEndpointAddress
= 14,
2103 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
2104 .reg_udccs
= &UDCCS14
,
2105 .reg_ubcr
= &UBCR14
,
2106 .reg_uddr
= &UDDR14
,
2110 .name
= "ep15in-int",
2111 .ops
= &pxa2xx_ep_ops
,
2112 .maxpacket
= INT_FIFO_SIZE
,
2115 .fifo_size
= INT_FIFO_SIZE
,
2116 .bEndpointAddress
= USB_DIR_IN
| 15,
2117 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
2118 .reg_udccs
= &UDCCS15
,
2119 .reg_uddr
= &UDDR15
,
2121 #endif /* !CONFIG_USB_PXA2XX_SMALL */
2124 #define CP15R0_VENDOR_MASK 0xffffe000
2126 #if defined(CONFIG_ARCH_PXA)
2127 #define CP15R0_XSCALE_VALUE 0x69052000 /* intel/arm/xscale */
2129 #elif defined(CONFIG_ARCH_IXP4XX)
2130 #define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/ixp4xx */
2134 #define CP15R0_PROD_MASK 0x000003f0
2135 #define PXA25x 0x00000100 /* and PXA26x */
2136 #define PXA210 0x00000120
2138 #define CP15R0_REV_MASK 0x0000000f
2140 #define CP15R0_PRODREV_MASK (CP15R0_PROD_MASK | CP15R0_REV_MASK)
2142 #define PXA255_A0 0x00000106 /* or PXA260_B1 */
2143 #define PXA250_C0 0x00000105 /* or PXA26x_B0 */
2144 #define PXA250_B2 0x00000104
2145 #define PXA250_B1 0x00000103 /* or PXA260_A0 */
2146 #define PXA250_B0 0x00000102
2147 #define PXA250_A1 0x00000101
2148 #define PXA250_A0 0x00000100
2150 #define PXA210_C0 0x00000125
2151 #define PXA210_B2 0x00000124
2152 #define PXA210_B1 0x00000123
2153 #define PXA210_B0 0x00000122
2154 #define IXP425_A0 0x000001c1
2155 #define IXP425_B0 0x000001f1
2156 #define IXP465_AD 0x00000200
2159 * probe - binds to the platform device
2161 static int __init
pxa2xx_udc_probe(struct platform_device
*pdev
)
2163 struct pxa2xx_udc
*dev
= &memory
;
2164 int retval
, vbus_irq
, irq
;
2167 /* insist on Intel/ARM/XScale */
2168 asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev
));
2169 if ((chiprev
& CP15R0_VENDOR_MASK
) != CP15R0_XSCALE_VALUE
) {
2170 pr_err("%s: not XScale!\n", driver_name
);
2174 /* trigger chiprev-specific logic */
2175 switch (chiprev
& CP15R0_PRODREV_MASK
) {
2176 #if defined(CONFIG_ARCH_PXA)
2182 /* A0/A1 "not released"; ep 13, 15 unusable */
2184 case PXA250_B2
: case PXA210_B2
:
2185 case PXA250_B1
: case PXA210_B1
:
2186 case PXA250_B0
: case PXA210_B0
:
2187 /* OUT-DMA is broken ... */
2189 case PXA250_C0
: case PXA210_C0
:
2191 #elif defined(CONFIG_ARCH_IXP4XX)
2199 pr_err("%s: unrecognized processor: %08x\n",
2200 driver_name
, chiprev
);
2201 /* iop3xx, ixp4xx, ... */
2205 irq
= platform_get_irq(pdev
, 0);
2209 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2210 #ifdef CONFIG_ARCH_PXA
2212 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2213 dev
->clk
= clk_get(&pdev
->dev
, "UDCCLK");
2214 if (IS_ERR(dev
->clk
)) {
2215 retval
= PTR_ERR(dev
->clk
);
2218 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2221 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2223 pr_debug("%s: IRQ %d%s%s\n", driver_name
, irq
,
2224 dev
->has_cfr
? "" : " (!cfr)",
2228 /* other non-static parts of init */
2229 dev
->dev
= &pdev
->dev
;
2230 dev
->mach
= pdev
->dev
.platform_data
;
2232 if (dev
->mach
->gpio_vbus
) {
2233 if ((retval
= gpio_request(dev
->mach
->gpio_vbus
,
2234 "pxa2xx_udc GPIO VBUS"))) {
2236 "can't get vbus gpio %d, err: %d\n",
2237 dev
->mach
->gpio_vbus
, retval
);
2240 gpio_direction_input(dev
->mach
->gpio_vbus
);
2241 vbus_irq
= gpio_to_irq(dev
->mach
->gpio_vbus
);
2245 if (dev
->mach
->gpio_pullup
) {
2246 if ((retval
= gpio_request(dev
->mach
->gpio_pullup
,
2247 "pca2xx_udc GPIO PULLUP"))) {
2249 "can't get pullup gpio %d, err: %d\n",
2250 dev
->mach
->gpio_pullup
, retval
);
2251 goto err_gpio_pullup
;
2253 gpio_direction_output(dev
->mach
->gpio_pullup
, 0);
2256 init_timer(&dev
->timer
);
2257 dev
->timer
.function
= udc_watchdog
;
2258 dev
->timer
.data
= (unsigned long) dev
;
2260 device_initialize(&dev
->gadget
.dev
);
2261 dev
->gadget
.dev
.parent
= &pdev
->dev
;
2262 dev
->gadget
.dev
.dma_mask
= pdev
->dev
.dma_mask
;
2264 the_controller
= dev
;
2265 platform_set_drvdata(pdev
, dev
);
2270 dev
->vbus
= is_vbus_present();
2272 /* irq setup after old hardware state is cleaned up */
2273 retval
= request_irq(irq
, pxa2xx_udc_irq
,
2274 IRQF_DISABLED
, driver_name
, dev
);
2276 pr_err("%s: can't get irq %d, err %d\n",
2277 driver_name
, irq
, retval
);
2282 #ifdef CONFIG_ARCH_LUBBOCK
2283 if (machine_is_lubbock()) {
2284 retval
= request_irq(LUBBOCK_USB_DISC_IRQ
,
2286 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
,
2289 pr_err("%s: can't get irq %i, err %d\n",
2290 driver_name
, LUBBOCK_USB_DISC_IRQ
, retval
);
2294 retval
= request_irq(LUBBOCK_USB_IRQ
,
2296 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
,
2299 pr_err("%s: can't get irq %i, err %d\n",
2300 driver_name
, LUBBOCK_USB_IRQ
, retval
);
2301 free_irq(LUBBOCK_USB_DISC_IRQ
, dev
);
2307 retval
= request_irq(vbus_irq
, udc_vbus_irq
,
2308 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
|
2309 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
2312 pr_err("%s: can't get irq %i, err %d\n",
2313 driver_name
, vbus_irq
, retval
);
2317 create_debug_files(dev
);
2322 #ifdef CONFIG_ARCH_LUBBOCK
2323 free_irq(LUBBOCK_USB_DISC_IRQ
, dev
);
2328 if (dev
->mach
->gpio_pullup
)
2329 gpio_free(dev
->mach
->gpio_pullup
);
2331 if (dev
->mach
->gpio_vbus
)
2332 gpio_free(dev
->mach
->gpio_vbus
);
2334 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2335 #ifdef CONFIG_ARCH_PXA
2337 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2340 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2343 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2347 static void pxa2xx_udc_shutdown(struct platform_device
*_dev
)
2352 static int __exit
pxa2xx_udc_remove(struct platform_device
*pdev
)
2354 struct pxa2xx_udc
*dev
= platform_get_drvdata(pdev
);
2359 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2365 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2366 remove_debug_files(dev
);
2369 free_irq(platform_get_irq(pdev
, 0), dev
);
2372 #ifdef CONFIG_ARCH_LUBBOCK
2373 if (machine_is_lubbock()) {
2374 free_irq(LUBBOCK_USB_DISC_IRQ
, dev
);
2375 free_irq(LUBBOCK_USB_IRQ
, dev
);
2378 if (dev
->mach
->gpio_vbus
) {
2379 free_irq(gpio_to_irq(dev
->mach
->gpio_vbus
), dev
);
2380 gpio_free(dev
->mach
->gpio_vbus
);
2382 if (dev
->mach
->gpio_pullup
)
2383 gpio_free(dev
->mach
->gpio_pullup
);
2385 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2386 #ifdef CONFIG_ARCH_PXA
2388 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2390 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2393 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2395 platform_set_drvdata(pdev
, NULL
);
2396 the_controller
= NULL
;
2400 /*-------------------------------------------------------------------------*/
2404 /* USB suspend (controlled by the host) and system suspend (controlled
2405 * by the PXA) don't necessarily work well together. If USB is active,
2406 * the 48 MHz clock is required; so the system can't enter 33 MHz idle
2407 * mode, or any deeper PM saving state.
2409 * For now, we punt and forcibly disconnect from the USB host when PXA
2410 * enters any suspend state. While we're disconnected, we always disable
2411 * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
2412 * Boards without software pullup control shouldn't use those states.
2413 * VBUS IRQs should probably be ignored so that the PXA device just acts
2414 * "dead" to USB hosts until system resume.
2416 static int pxa2xx_udc_suspend(struct platform_device
*dev
, pm_message_t state
)
2418 struct pxa2xx_udc
*udc
= platform_get_drvdata(dev
);
2419 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2421 unsigned long flags
;
2422 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2424 if (!udc
->mach
->gpio_pullup
&& !udc
->mach
->udc_command
)
2425 WARN("USB host won't detect disconnect!\n");
2426 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2431 local_irq_save(flags
);
2433 local_irq_restore(flags
);
2434 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2439 static int pxa2xx_udc_resume(struct platform_device
*dev
)
2441 struct pxa2xx_udc
*udc
= platform_get_drvdata(dev
);
2442 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2444 unsigned long flags
;
2445 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2447 <<<<<<< HEAD
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2451 local_irq_save(flags
);
2453 local_irq_restore(flags
);
2454 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/usb
/gadget
/pxa2xx_udc
.c
2460 #define pxa2xx_udc_suspend NULL
2461 #define pxa2xx_udc_resume NULL
2464 /*-------------------------------------------------------------------------*/
2466 static struct platform_driver udc_driver
= {
2467 .shutdown
= pxa2xx_udc_shutdown
,
2468 .remove
= __exit_p(pxa2xx_udc_remove
),
2469 .suspend
= pxa2xx_udc_suspend
,
2470 .resume
= pxa2xx_udc_resume
,
2472 .owner
= THIS_MODULE
,
2473 .name
= "pxa2xx-udc",
2477 static int __init
udc_init(void)
2479 pr_info("%s: version %s\n", driver_name
, DRIVER_VERSION
);
2480 return platform_driver_probe(&udc_driver
, pxa2xx_udc_probe
);
2482 module_init(udc_init
);
2484 static void __exit
udc_exit(void)
2486 platform_driver_unregister(&udc_driver
);
2488 module_exit(udc_exit
);
2490 MODULE_DESCRIPTION(DRIVER_DESC
);
2491 MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
2492 MODULE_LICENSE("GPL");