2 * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
4 * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
5 * Copyright (C) 2003 Robert Schwebel, Pengutronix
6 * Copyright (C) 2003 Benedikt Spranger, Pengutronix
7 * Copyright (C) 2003 David Brownell
8 * Copyright (C) 2003 Joshua Wise
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /* #define VERBOSE_DEBUG */
28 #include <linux/device.h>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/ioport.h>
32 #include <linux/types.h>
33 #include <linux/errno.h>
34 #include <linux/delay.h>
35 #include <linux/slab.h>
36 #include <linux/init.h>
37 #include <linux/timer.h>
38 #include <linux/list.h>
39 #include <linux/interrupt.h>
41 #include <linux/platform_device.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/irq.h>
44 #include <linux/clk.h>
45 #include <linux/err.h>
46 #include <linux/seq_file.h>
47 #include <linux/debugfs.h>
50 #include <asm/byteorder.h>
53 #include <asm/system.h>
54 #include <asm/mach-types.h>
55 #include <asm/unaligned.h>
57 #include <linux/usb/ch9.h>
58 #include <linux/usb/gadget.h>
59 #include <linux/usb/otg.h>
62 * This driver is PXA25x only. Grab the right register definitions.
64 #ifdef CONFIG_ARCH_PXA
65 #include <mach/pxa25x-udc.h>
68 #ifdef CONFIG_ARCH_LUBBOCK
69 #include <mach/lubbock.h>
72 #include <asm/mach/udc_pxa2xx.h>
76 * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
77 * series processors. The UDC for the IXP 4xx series is very similar.
78 * There are fifteen endpoints, in addition to ep0.
80 * Such controller drivers work with a gadget driver. The gadget driver
81 * returns descriptors, implements configuration and data protocols used
82 * by the host to interact with this device, and allocates endpoints to
83 * the different protocol interfaces. The controller driver virtualizes
84 * usb hardware so that the gadget drivers will be more portable.
86 * This UDC hardware wants to implement a bit too much USB protocol, so
87 * it constrains the sorts of USB configuration change events that work.
88 * The errata for these chips are misleading; some "fixed" bugs from
89 * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
91 * Note that the UDC hardware supports DMA (except on IXP) but that's
92 * not used here. IN-DMA (to host) is simple enough, when the data is
93 * suitably aligned (16 bytes) ... the network stack doesn't do that,
94 * other software can. OUT-DMA is buggy in most chip versions, as well
95 * as poorly designed (data toggle not automatic). So this driver won't
96 * bother using DMA. (Mostly-working IN-DMA support was available in
97 * kernels before 2.6.23, but was never enabled or well tested.)
100 #define DRIVER_VERSION "30-June-2007"
101 #define DRIVER_DESC "PXA 25x USB Device Controller driver"
104 static const char driver_name
[] = "pxa25x_udc";
106 static const char ep0name
[] = "ep0";
109 #ifdef CONFIG_ARCH_IXP4XX
111 /* cpu-specific register addresses are compiled in to this code */
112 #ifdef CONFIG_ARCH_PXA
113 #error "Can't configure both IXP and PXA"
116 /* IXP doesn't yet support <linux/clk.h> */
117 #define clk_get(dev,name) NULL
118 #define clk_enable(clk) do { } while (0)
119 #define clk_disable(clk) do { } while (0)
120 #define clk_put(clk) do { } while (0)
124 #include "pxa25x_udc.h"
127 #ifdef CONFIG_USB_PXA25X_SMALL
128 #define SIZE_STR " (small)"
133 /* ---------------------------------------------------------------------------
134 * endpoint related parts of the api to the usb controller hardware,
135 * used by gadget driver; and the inner talker-to-hardware core.
136 * ---------------------------------------------------------------------------
139 static void pxa25x_ep_fifo_flush (struct usb_ep
*ep
);
140 static void nuke (struct pxa25x_ep
*, int status
);
142 /* one GPIO should be used to detect VBUS from the host */
143 static int is_vbus_present(void)
145 struct pxa2xx_udc_mach_info
*mach
= the_controller
->mach
;
147 if (gpio_is_valid(mach
->gpio_vbus
)) {
148 int value
= gpio_get_value(mach
->gpio_vbus
);
150 if (mach
->gpio_vbus_inverted
)
155 if (mach
->udc_is_connected
)
156 return mach
->udc_is_connected();
160 /* one GPIO should control a D+ pullup, so host sees this device (or not) */
161 static void pullup_off(void)
163 struct pxa2xx_udc_mach_info
*mach
= the_controller
->mach
;
164 int off_level
= mach
->gpio_pullup_inverted
;
166 if (gpio_is_valid(mach
->gpio_pullup
))
167 gpio_set_value(mach
->gpio_pullup
, off_level
);
168 else if (mach
->udc_command
)
169 mach
->udc_command(PXA2XX_UDC_CMD_DISCONNECT
);
172 static void pullup_on(void)
174 struct pxa2xx_udc_mach_info
*mach
= the_controller
->mach
;
175 int on_level
= !mach
->gpio_pullup_inverted
;
177 if (gpio_is_valid(mach
->gpio_pullup
))
178 gpio_set_value(mach
->gpio_pullup
, on_level
);
179 else if (mach
->udc_command
)
180 mach
->udc_command(PXA2XX_UDC_CMD_CONNECT
);
183 static void pio_irq_enable(int bEndpointAddress
)
185 bEndpointAddress
&= 0xf;
186 if (bEndpointAddress
< 8)
187 UICR0
&= ~(1 << bEndpointAddress
);
189 bEndpointAddress
-= 8;
190 UICR1
&= ~(1 << bEndpointAddress
);
194 static void pio_irq_disable(int bEndpointAddress
)
196 bEndpointAddress
&= 0xf;
197 if (bEndpointAddress
< 8)
198 UICR0
|= 1 << bEndpointAddress
;
200 bEndpointAddress
-= 8;
201 UICR1
|= 1 << bEndpointAddress
;
205 /* The UDCCR reg contains mask and interrupt status bits,
206 * so using '|=' isn't safe as it may ack an interrupt.
208 #define UDCCR_MASK_BITS (UDCCR_REM | UDCCR_SRM | UDCCR_UDE)
210 static inline void udc_set_mask_UDCCR(int mask
)
212 UDCCR
= (UDCCR
& UDCCR_MASK_BITS
) | (mask
& UDCCR_MASK_BITS
);
215 static inline void udc_clear_mask_UDCCR(int mask
)
217 UDCCR
= (UDCCR
& UDCCR_MASK_BITS
) & ~(mask
& UDCCR_MASK_BITS
);
220 static inline void udc_ack_int_UDCCR(int mask
)
222 /* udccr contains the bits we dont want to change */
223 __u32 udccr
= UDCCR
& UDCCR_MASK_BITS
;
225 UDCCR
= udccr
| (mask
& ~UDCCR_MASK_BITS
);
229 * endpoint enable/disable
231 * we need to verify the descriptors used to enable endpoints. since pxa25x
232 * endpoint configurations are fixed, and are pretty much always enabled,
233 * there's not a lot to manage here.
235 * because pxa25x can't selectively initialize bulk (or interrupt) endpoints,
236 * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
237 * for a single interface (with only the default altsetting) and for gadget
238 * drivers that don't halt endpoints (not reset by set_interface). that also
239 * means that if you use ISO, you must violate the USB spec rule that all
240 * iso endpoints must be in non-default altsettings.
242 static int pxa25x_ep_enable (struct usb_ep
*_ep
,
243 const struct usb_endpoint_descriptor
*desc
)
245 struct pxa25x_ep
*ep
;
246 struct pxa25x_udc
*dev
;
248 ep
= container_of (_ep
, struct pxa25x_ep
, ep
);
249 if (!_ep
|| !desc
|| ep
->desc
|| _ep
->name
== ep0name
250 || desc
->bDescriptorType
!= USB_DT_ENDPOINT
251 || ep
->bEndpointAddress
!= desc
->bEndpointAddress
252 || ep
->fifo_size
< le16_to_cpu
253 (desc
->wMaxPacketSize
)) {
254 DMSG("%s, bad ep or descriptor\n", __func__
);
258 /* xfer types must match, except that interrupt ~= bulk */
259 if (ep
->bmAttributes
!= desc
->bmAttributes
260 && ep
->bmAttributes
!= USB_ENDPOINT_XFER_BULK
261 && desc
->bmAttributes
!= USB_ENDPOINT_XFER_INT
) {
262 DMSG("%s, %s type mismatch\n", __func__
, _ep
->name
);
266 /* hardware _could_ do smaller, but driver doesn't */
267 if ((desc
->bmAttributes
== USB_ENDPOINT_XFER_BULK
268 && le16_to_cpu (desc
->wMaxPacketSize
)
270 || !desc
->wMaxPacketSize
) {
271 DMSG("%s, bad %s maxpacket\n", __func__
, _ep
->name
);
276 if (!dev
->driver
|| dev
->gadget
.speed
== USB_SPEED_UNKNOWN
) {
277 DMSG("%s, bogus device state\n", __func__
);
284 ep
->ep
.maxpacket
= le16_to_cpu (desc
->wMaxPacketSize
);
286 /* flush fifo (mostly for OUT buffers) */
287 pxa25x_ep_fifo_flush (_ep
);
289 /* ... reset halt state too, if we could ... */
291 DBG(DBG_VERBOSE
, "enabled %s\n", _ep
->name
);
295 static int pxa25x_ep_disable (struct usb_ep
*_ep
)
297 struct pxa25x_ep
*ep
;
300 ep
= container_of (_ep
, struct pxa25x_ep
, ep
);
301 if (!_ep
|| !ep
->desc
) {
302 DMSG("%s, %s not enabled\n", __func__
,
303 _ep
? ep
->ep
.name
: NULL
);
306 local_irq_save(flags
);
308 nuke (ep
, -ESHUTDOWN
);
310 /* flush fifo (mostly for IN buffers) */
311 pxa25x_ep_fifo_flush (_ep
);
316 local_irq_restore(flags
);
317 DBG(DBG_VERBOSE
, "%s disabled\n", _ep
->name
);
321 /*-------------------------------------------------------------------------*/
323 /* for the pxa25x, these can just wrap kmalloc/kfree. gadget drivers
324 * must still pass correctly initialized endpoints, since other controller
325 * drivers may care about how it's currently set up (dma issues etc).
329 * pxa25x_ep_alloc_request - allocate a request data structure
331 static struct usb_request
*
332 pxa25x_ep_alloc_request (struct usb_ep
*_ep
, gfp_t gfp_flags
)
334 struct pxa25x_request
*req
;
336 req
= kzalloc(sizeof(*req
), gfp_flags
);
340 INIT_LIST_HEAD (&req
->queue
);
346 * pxa25x_ep_free_request - deallocate a request data structure
349 pxa25x_ep_free_request (struct usb_ep
*_ep
, struct usb_request
*_req
)
351 struct pxa25x_request
*req
;
353 req
= container_of (_req
, struct pxa25x_request
, req
);
354 WARN_ON(!list_empty (&req
->queue
));
358 /*-------------------------------------------------------------------------*/
361 * done - retire a request; caller blocked irqs
363 static void done(struct pxa25x_ep
*ep
, struct pxa25x_request
*req
, int status
)
365 unsigned stopped
= ep
->stopped
;
367 list_del_init(&req
->queue
);
369 if (likely (req
->req
.status
== -EINPROGRESS
))
370 req
->req
.status
= status
;
372 status
= req
->req
.status
;
374 if (status
&& status
!= -ESHUTDOWN
)
375 DBG(DBG_VERBOSE
, "complete %s req %p stat %d len %u/%u\n",
376 ep
->ep
.name
, &req
->req
, status
,
377 req
->req
.actual
, req
->req
.length
);
379 /* don't modify queue heads during completion callback */
381 req
->req
.complete(&ep
->ep
, &req
->req
);
382 ep
->stopped
= stopped
;
386 static inline void ep0_idle (struct pxa25x_udc
*dev
)
388 dev
->ep0state
= EP0_IDLE
;
392 write_packet(volatile u32
*uddr
, struct pxa25x_request
*req
, unsigned max
)
395 unsigned length
, count
;
397 buf
= req
->req
.buf
+ req
->req
.actual
;
400 /* how big will this packet be? */
401 length
= min(req
->req
.length
- req
->req
.actual
, max
);
402 req
->req
.actual
+= length
;
405 while (likely(count
--))
412 * write to an IN endpoint fifo, as many packets as possible.
413 * irqs will use this to write the rest later.
414 * caller guarantees at least one packet buffer is ready (or a zlp).
417 write_fifo (struct pxa25x_ep
*ep
, struct pxa25x_request
*req
)
421 max
= le16_to_cpu(ep
->desc
->wMaxPacketSize
);
424 int is_last
, is_short
;
426 count
= write_packet(ep
->reg_uddr
, req
, max
);
428 /* last packet is usually short (or a zlp) */
429 if (unlikely (count
!= max
))
430 is_last
= is_short
= 1;
432 if (likely(req
->req
.length
!= req
->req
.actual
)
437 /* interrupt/iso maxpacket may not fill the fifo */
438 is_short
= unlikely (max
< ep
->fifo_size
);
441 DBG(DBG_VERY_NOISY
, "wrote %s %d bytes%s%s %d left %p\n",
443 is_last
? "/L" : "", is_short
? "/S" : "",
444 req
->req
.length
- req
->req
.actual
, req
);
446 /* let loose that packet. maybe try writing another one,
447 * double buffering might work. TSP, TPC, and TFS
448 * bit values are the same for all normal IN endpoints.
450 *ep
->reg_udccs
= UDCCS_BI_TPC
;
452 *ep
->reg_udccs
= UDCCS_BI_TSP
;
454 /* requests complete when all IN data is in the FIFO */
457 if (list_empty(&ep
->queue
))
458 pio_irq_disable (ep
->bEndpointAddress
);
462 // TODO experiment: how robust can fifo mode tweaking be?
463 // double buffering is off in the default fifo mode, which
464 // prevents TFS from being set here.
466 } while (*ep
->reg_udccs
& UDCCS_BI_TFS
);
470 /* caller asserts req->pending (ep0 irq status nyet cleared); starts
471 * ep0 data stage. these chips want very simple state transitions.
474 void ep0start(struct pxa25x_udc
*dev
, u32 flags
, const char *tag
)
476 UDCCS0
= flags
|UDCCS0_SA
|UDCCS0_OPR
;
478 dev
->req_pending
= 0;
479 DBG(DBG_VERY_NOISY
, "%s %s, %02x/%02x\n",
480 __func__
, tag
, UDCCS0
, flags
);
484 write_ep0_fifo (struct pxa25x_ep
*ep
, struct pxa25x_request
*req
)
489 count
= write_packet(&UDDR0
, req
, EP0_FIFO_SIZE
);
490 ep
->dev
->stats
.write
.bytes
+= count
;
492 /* last packet "must be" short (or a zlp) */
493 is_short
= (count
!= EP0_FIFO_SIZE
);
495 DBG(DBG_VERY_NOISY
, "ep0in %d bytes %d left %p\n", count
,
496 req
->req
.length
- req
->req
.actual
, req
);
498 if (unlikely (is_short
)) {
499 if (ep
->dev
->req_pending
)
500 ep0start(ep
->dev
, UDCCS0_IPR
, "short IN");
504 count
= req
->req
.length
;
507 #ifndef CONFIG_ARCH_IXP4XX
509 /* This seems to get rid of lost status irqs in some cases:
510 * host responds quickly, or next request involves config
511 * change automagic, or should have been hidden, or ...
513 * FIXME get rid of all udelays possible...
515 if (count
>= EP0_FIFO_SIZE
) {
518 if ((UDCCS0
& UDCCS0_OPR
) != 0) {
519 /* clear OPR, generate ack */
529 } else if (ep
->dev
->req_pending
)
530 ep0start(ep
->dev
, 0, "IN");
536 * read_fifo - unload packet(s) from the fifo we use for usb OUT
537 * transfers and put them into the request. caller should have made
538 * sure there's at least one packet ready.
540 * returns true if the request completed because of short packet or the
541 * request buffer having filled (and maybe overran till end-of-packet).
544 read_fifo (struct pxa25x_ep
*ep
, struct pxa25x_request
*req
)
549 unsigned bufferspace
, count
, is_short
;
551 /* make sure there's a packet in the FIFO.
552 * UDCCS_{BO,IO}_RPC are all the same bit value.
553 * UDCCS_{BO,IO}_RNE are all the same bit value.
555 udccs
= *ep
->reg_udccs
;
556 if (unlikely ((udccs
& UDCCS_BO_RPC
) == 0))
558 buf
= req
->req
.buf
+ req
->req
.actual
;
560 bufferspace
= req
->req
.length
- req
->req
.actual
;
562 /* read all bytes from this packet */
563 if (likely (udccs
& UDCCS_BO_RNE
)) {
564 count
= 1 + (0x0ff & *ep
->reg_ubcr
);
565 req
->req
.actual
+= min (count
, bufferspace
);
568 is_short
= (count
< ep
->ep
.maxpacket
);
569 DBG(DBG_VERY_NOISY
, "read %s %02x, %d bytes%s req %p %d/%d\n",
570 ep
->ep
.name
, udccs
, count
,
571 is_short
? "/S" : "",
572 req
, req
->req
.actual
, req
->req
.length
);
573 while (likely (count
-- != 0)) {
574 u8 byte
= (u8
) *ep
->reg_uddr
;
576 if (unlikely (bufferspace
== 0)) {
577 /* this happens when the driver's buffer
578 * is smaller than what the host sent.
579 * discard the extra data.
581 if (req
->req
.status
!= -EOVERFLOW
)
582 DMSG("%s overflow %d\n",
584 req
->req
.status
= -EOVERFLOW
;
590 *ep
->reg_udccs
= UDCCS_BO_RPC
;
591 /* RPC/RSP/RNE could now reflect the other packet buffer */
593 /* iso is one request per packet */
594 if (ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
) {
595 if (udccs
& UDCCS_IO_ROF
)
596 req
->req
.status
= -EHOSTUNREACH
;
597 /* more like "is_done" */
602 if (is_short
|| req
->req
.actual
== req
->req
.length
) {
604 if (list_empty(&ep
->queue
))
605 pio_irq_disable (ep
->bEndpointAddress
);
609 /* finished that packet. the next one may be waiting... */
615 * special ep0 version of the above. no UBCR0 or double buffering; status
616 * handshaking is magic. most device protocols don't need control-OUT.
617 * CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
618 * protocols do use them.
621 read_ep0_fifo (struct pxa25x_ep
*ep
, struct pxa25x_request
*req
)
624 unsigned bufferspace
;
626 buf
= req
->req
.buf
+ req
->req
.actual
;
627 bufferspace
= req
->req
.length
- req
->req
.actual
;
629 while (UDCCS0
& UDCCS0_RNE
) {
632 if (unlikely (bufferspace
== 0)) {
633 /* this happens when the driver's buffer
634 * is smaller than what the host sent.
635 * discard the extra data.
637 if (req
->req
.status
!= -EOVERFLOW
)
638 DMSG("%s overflow\n", ep
->ep
.name
);
639 req
->req
.status
= -EOVERFLOW
;
647 UDCCS0
= UDCCS0_OPR
| UDCCS0_IPR
;
650 if (req
->req
.actual
>= req
->req
.length
)
653 /* finished that packet. the next one may be waiting... */
657 /*-------------------------------------------------------------------------*/
660 pxa25x_ep_queue(struct usb_ep
*_ep
, struct usb_request
*_req
, gfp_t gfp_flags
)
662 struct pxa25x_request
*req
;
663 struct pxa25x_ep
*ep
;
664 struct pxa25x_udc
*dev
;
667 req
= container_of(_req
, struct pxa25x_request
, req
);
668 if (unlikely (!_req
|| !_req
->complete
|| !_req
->buf
669 || !list_empty(&req
->queue
))) {
670 DMSG("%s, bad params\n", __func__
);
674 ep
= container_of(_ep
, struct pxa25x_ep
, ep
);
675 if (unlikely (!_ep
|| (!ep
->desc
&& ep
->ep
.name
!= ep0name
))) {
676 DMSG("%s, bad ep\n", __func__
);
681 if (unlikely (!dev
->driver
682 || dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)) {
683 DMSG("%s, bogus device state\n", __func__
);
687 /* iso is always one packet per request, that's the only way
688 * we can report per-packet status. that also helps with dma.
690 if (unlikely (ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
691 && req
->req
.length
> le16_to_cpu
692 (ep
->desc
->wMaxPacketSize
)))
695 DBG(DBG_NOISY
, "%s queue req %p, len %d buf %p\n",
696 _ep
->name
, _req
, _req
->length
, _req
->buf
);
698 local_irq_save(flags
);
700 _req
->status
= -EINPROGRESS
;
703 /* kickstart this i/o queue? */
704 if (list_empty(&ep
->queue
) && !ep
->stopped
) {
705 if (ep
->desc
== NULL
/* ep0 */) {
706 unsigned length
= _req
->length
;
708 switch (dev
->ep0state
) {
709 case EP0_IN_DATA_PHASE
:
710 dev
->stats
.write
.ops
++;
711 if (write_ep0_fifo(ep
, req
))
715 case EP0_OUT_DATA_PHASE
:
716 dev
->stats
.read
.ops
++;
718 if (dev
->req_config
) {
719 DBG(DBG_VERBOSE
, "ep0 config ack%s\n",
720 dev
->has_cfr
? "" : " raced");
722 UDCCFR
= UDCCFR_AREN
|UDCCFR_ACM
725 dev
->ep0state
= EP0_END_XFER
;
726 local_irq_restore (flags
);
729 if (dev
->req_pending
)
730 ep0start(dev
, UDCCS0_IPR
, "OUT");
731 if (length
== 0 || ((UDCCS0
& UDCCS0_RNE
) != 0
732 && read_ep0_fifo(ep
, req
))) {
740 DMSG("ep0 i/o, odd state %d\n", dev
->ep0state
);
741 local_irq_restore (flags
);
744 /* can the FIFO can satisfy the request immediately? */
745 } else if ((ep
->bEndpointAddress
& USB_DIR_IN
) != 0) {
746 if ((*ep
->reg_udccs
& UDCCS_BI_TFS
) != 0
747 && write_fifo(ep
, req
))
749 } else if ((*ep
->reg_udccs
& UDCCS_BO_RFS
) != 0
750 && read_fifo(ep
, req
)) {
754 if (likely (req
&& ep
->desc
))
755 pio_irq_enable(ep
->bEndpointAddress
);
758 /* pio or dma irq handler advances the queue. */
759 if (likely(req
!= NULL
))
760 list_add_tail(&req
->queue
, &ep
->queue
);
761 local_irq_restore(flags
);
768 * nuke - dequeue ALL requests
770 static void nuke(struct pxa25x_ep
*ep
, int status
)
772 struct pxa25x_request
*req
;
774 /* called with irqs blocked */
775 while (!list_empty(&ep
->queue
)) {
776 req
= list_entry(ep
->queue
.next
,
777 struct pxa25x_request
,
779 done(ep
, req
, status
);
782 pio_irq_disable (ep
->bEndpointAddress
);
786 /* dequeue JUST ONE request */
787 static int pxa25x_ep_dequeue(struct usb_ep
*_ep
, struct usb_request
*_req
)
789 struct pxa25x_ep
*ep
;
790 struct pxa25x_request
*req
;
793 ep
= container_of(_ep
, struct pxa25x_ep
, ep
);
794 if (!_ep
|| ep
->ep
.name
== ep0name
)
797 local_irq_save(flags
);
799 /* make sure it's actually queued on this endpoint */
800 list_for_each_entry (req
, &ep
->queue
, queue
) {
801 if (&req
->req
== _req
)
804 if (&req
->req
!= _req
) {
805 local_irq_restore(flags
);
809 done(ep
, req
, -ECONNRESET
);
811 local_irq_restore(flags
);
815 /*-------------------------------------------------------------------------*/
817 static int pxa25x_ep_set_halt(struct usb_ep
*_ep
, int value
)
819 struct pxa25x_ep
*ep
;
822 ep
= container_of(_ep
, struct pxa25x_ep
, ep
);
824 || (!ep
->desc
&& ep
->ep
.name
!= ep0name
))
825 || ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
) {
826 DMSG("%s, bad ep\n", __func__
);
830 /* this path (reset toggle+halt) is needed to implement
831 * SET_INTERFACE on normal hardware. but it can't be
832 * done from software on the PXA UDC, and the hardware
833 * forgets to do it as part of SET_INTERFACE automagic.
835 DMSG("only host can clear %s halt\n", _ep
->name
);
839 local_irq_save(flags
);
841 if ((ep
->bEndpointAddress
& USB_DIR_IN
) != 0
842 && ((*ep
->reg_udccs
& UDCCS_BI_TFS
) == 0
843 || !list_empty(&ep
->queue
))) {
844 local_irq_restore(flags
);
848 /* FST bit is the same for control, bulk in, bulk out, interrupt in */
849 *ep
->reg_udccs
= UDCCS_BI_FST
|UDCCS_BI_FTF
;
851 /* ep0 needs special care */
853 start_watchdog(ep
->dev
);
854 ep
->dev
->req_pending
= 0;
855 ep
->dev
->ep0state
= EP0_STALL
;
857 /* and bulk/intr endpoints like dropping stalls too */
860 for (i
= 0; i
< 1000; i
+= 20) {
861 if (*ep
->reg_udccs
& UDCCS_BI_SST
)
866 local_irq_restore(flags
);
868 DBG(DBG_VERBOSE
, "%s halt\n", _ep
->name
);
872 static int pxa25x_ep_fifo_status(struct usb_ep
*_ep
)
874 struct pxa25x_ep
*ep
;
876 ep
= container_of(_ep
, struct pxa25x_ep
, ep
);
878 DMSG("%s, bad ep\n", __func__
);
881 /* pxa can't report unclaimed bytes from IN fifos */
882 if ((ep
->bEndpointAddress
& USB_DIR_IN
) != 0)
884 if (ep
->dev
->gadget
.speed
== USB_SPEED_UNKNOWN
885 || (*ep
->reg_udccs
& UDCCS_BO_RFS
) == 0)
888 return (*ep
->reg_ubcr
& 0xfff) + 1;
891 static void pxa25x_ep_fifo_flush(struct usb_ep
*_ep
)
893 struct pxa25x_ep
*ep
;
895 ep
= container_of(_ep
, struct pxa25x_ep
, ep
);
896 if (!_ep
|| ep
->ep
.name
== ep0name
|| !list_empty(&ep
->queue
)) {
897 DMSG("%s, bad ep\n", __func__
);
901 /* toggle and halt bits stay unchanged */
903 /* for OUT, just read and discard the FIFO contents. */
904 if ((ep
->bEndpointAddress
& USB_DIR_IN
) == 0) {
905 while (((*ep
->reg_udccs
) & UDCCS_BO_RNE
) != 0)
906 (void) *ep
->reg_uddr
;
910 /* most IN status is the same, but ISO can't stall */
911 *ep
->reg_udccs
= UDCCS_BI_TPC
|UDCCS_BI_FTF
|UDCCS_BI_TUR
912 | (ep
->bmAttributes
== USB_ENDPOINT_XFER_ISOC
917 static struct usb_ep_ops pxa25x_ep_ops
= {
918 .enable
= pxa25x_ep_enable
,
919 .disable
= pxa25x_ep_disable
,
921 .alloc_request
= pxa25x_ep_alloc_request
,
922 .free_request
= pxa25x_ep_free_request
,
924 .queue
= pxa25x_ep_queue
,
925 .dequeue
= pxa25x_ep_dequeue
,
927 .set_halt
= pxa25x_ep_set_halt
,
928 .fifo_status
= pxa25x_ep_fifo_status
,
929 .fifo_flush
= pxa25x_ep_fifo_flush
,
933 /* ---------------------------------------------------------------------------
934 * device-scoped parts of the api to the usb controller hardware
935 * ---------------------------------------------------------------------------
938 static int pxa25x_udc_get_frame(struct usb_gadget
*_gadget
)
940 return ((UFNRH
& 0x07) << 8) | (UFNRL
& 0xff);
943 static int pxa25x_udc_wakeup(struct usb_gadget
*_gadget
)
945 /* host may not have enabled remote wakeup */
946 if ((UDCCS0
& UDCCS0_DRWF
) == 0)
947 return -EHOSTUNREACH
;
948 udc_set_mask_UDCCR(UDCCR_RSM
);
952 static void stop_activity(struct pxa25x_udc
*, struct usb_gadget_driver
*);
953 static void udc_enable (struct pxa25x_udc
*);
954 static void udc_disable(struct pxa25x_udc
*);
956 /* We disable the UDC -- and its 48 MHz clock -- whenever it's not
959 static int pullup(struct pxa25x_udc
*udc
)
961 int is_active
= udc
->vbus
&& udc
->pullup
&& !udc
->suspended
;
962 DMSG("%s\n", is_active
? "active" : "inactive");
966 /* Enable clock for USB device */
967 clk_enable(udc
->clk
);
972 if (udc
->gadget
.speed
!= USB_SPEED_UNKNOWN
) {
973 DMSG("disconnect %s\n", udc
->driver
974 ? udc
->driver
->driver
.name
976 stop_activity(udc
, udc
->driver
);
979 /* Disable clock for USB device */
980 clk_disable(udc
->clk
);
988 /* VBUS reporting logically comes from a transceiver */
989 static int pxa25x_udc_vbus_session(struct usb_gadget
*_gadget
, int is_active
)
991 struct pxa25x_udc
*udc
;
993 udc
= container_of(_gadget
, struct pxa25x_udc
, gadget
);
994 udc
->vbus
= is_active
;
995 DMSG("vbus %s\n", is_active
? "supplied" : "inactive");
1000 /* drivers may have software control over D+ pullup */
1001 static int pxa25x_udc_pullup(struct usb_gadget
*_gadget
, int is_active
)
1003 struct pxa25x_udc
*udc
;
1005 udc
= container_of(_gadget
, struct pxa25x_udc
, gadget
);
1007 /* not all boards support pullup control */
1008 if (!gpio_is_valid(udc
->mach
->gpio_pullup
) && !udc
->mach
->udc_command
)
1011 udc
->pullup
= (is_active
!= 0);
1016 /* boards may consume current from VBUS, up to 100-500mA based on config.
1017 * the 500uA suspend ceiling means that exclusively vbus-powered PXA designs
1018 * violate USB specs.
1020 static int pxa25x_udc_vbus_draw(struct usb_gadget
*_gadget
, unsigned mA
)
1022 struct pxa25x_udc
*udc
;
1024 udc
= container_of(_gadget
, struct pxa25x_udc
, gadget
);
1026 if (udc
->transceiver
)
1027 return otg_set_power(udc
->transceiver
, mA
);
1031 static const struct usb_gadget_ops pxa25x_udc_ops
= {
1032 .get_frame
= pxa25x_udc_get_frame
,
1033 .wakeup
= pxa25x_udc_wakeup
,
1034 .vbus_session
= pxa25x_udc_vbus_session
,
1035 .pullup
= pxa25x_udc_pullup
,
1036 .vbus_draw
= pxa25x_udc_vbus_draw
,
1039 /*-------------------------------------------------------------------------*/
1041 #ifdef CONFIG_USB_GADGET_DEBUG_FS
1044 udc_seq_show(struct seq_file
*m
, void *_d
)
1046 struct pxa25x_udc
*dev
= m
->private;
1047 unsigned long flags
;
1051 local_irq_save(flags
);
1053 /* basic device status */
1054 seq_printf(m
, DRIVER_DESC
"\n"
1055 "%s version: %s\nGadget driver: %s\nHost %s\n\n",
1056 driver_name
, DRIVER_VERSION SIZE_STR
"(pio)",
1057 dev
->driver
? dev
->driver
->driver
.name
: "(none)",
1058 is_vbus_present() ? "full speed" : "disconnected");
1060 /* registers for device and ep0 */
1062 "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
1063 UICR1
, UICR0
, USIR1
, USIR0
, UFNRH
, UFNRL
);
1067 "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp
,
1068 (tmp
& UDCCR_REM
) ? " rem" : "",
1069 (tmp
& UDCCR_RSTIR
) ? " rstir" : "",
1070 (tmp
& UDCCR_SRM
) ? " srm" : "",
1071 (tmp
& UDCCR_SUSIR
) ? " susir" : "",
1072 (tmp
& UDCCR_RESIR
) ? " resir" : "",
1073 (tmp
& UDCCR_RSM
) ? " rsm" : "",
1074 (tmp
& UDCCR_UDA
) ? " uda" : "",
1075 (tmp
& UDCCR_UDE
) ? " ude" : "");
1079 "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp
,
1080 (tmp
& UDCCS0_SA
) ? " sa" : "",
1081 (tmp
& UDCCS0_RNE
) ? " rne" : "",
1082 (tmp
& UDCCS0_FST
) ? " fst" : "",
1083 (tmp
& UDCCS0_SST
) ? " sst" : "",
1084 (tmp
& UDCCS0_DRWF
) ? " dwrf" : "",
1085 (tmp
& UDCCS0_FTF
) ? " ftf" : "",
1086 (tmp
& UDCCS0_IPR
) ? " ipr" : "",
1087 (tmp
& UDCCS0_OPR
) ? " opr" : "");
1092 "udccfr %02X =%s%s\n", tmp
,
1093 (tmp
& UDCCFR_AREN
) ? " aren" : "",
1094 (tmp
& UDCCFR_ACM
) ? " acm" : "");
1097 if (!is_vbus_present() || !dev
->driver
)
1100 seq_printf(m
, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
1101 dev
->stats
.write
.bytes
, dev
->stats
.write
.ops
,
1102 dev
->stats
.read
.bytes
, dev
->stats
.read
.ops
,
1105 /* dump endpoint queues */
1106 for (i
= 0; i
< PXA_UDC_NUM_ENDPOINTS
; i
++) {
1107 struct pxa25x_ep
*ep
= &dev
->ep
[i
];
1108 struct pxa25x_request
*req
;
1111 const struct usb_endpoint_descriptor
*desc
;
1116 tmp
= *dev
->ep
[i
].reg_udccs
;
1118 "%s max %d %s udccs %02x irqs %lu\n",
1119 ep
->ep
.name
, le16_to_cpu(desc
->wMaxPacketSize
),
1120 "pio", tmp
, ep
->pio_irqs
);
1121 /* TODO translate all five groups of udccs bits! */
1123 } else /* ep0 should only have one transfer queued */
1124 seq_printf(m
, "ep0 max 16 pio irqs %lu\n",
1127 if (list_empty(&ep
->queue
)) {
1128 seq_printf(m
, "\t(nothing queued)\n");
1131 list_for_each_entry(req
, &ep
->queue
, queue
) {
1133 "\treq %p len %d/%d buf %p\n",
1134 &req
->req
, req
->req
.actual
,
1135 req
->req
.length
, req
->req
.buf
);
1140 local_irq_restore(flags
);
1145 udc_debugfs_open(struct inode
*inode
, struct file
*file
)
1147 return single_open(file
, udc_seq_show
, inode
->i_private
);
1150 static const struct file_operations debug_fops
= {
1151 .open
= udc_debugfs_open
,
1153 .llseek
= seq_lseek
,
1154 .release
= single_release
,
1155 .owner
= THIS_MODULE
,
1158 #define create_debug_files(dev) \
1160 dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
1161 S_IRUGO, NULL, dev, &debug_fops); \
1163 #define remove_debug_files(dev) \
1165 if (dev->debugfs_udc) \
1166 debugfs_remove(dev->debugfs_udc); \
1169 #else /* !CONFIG_USB_GADGET_DEBUG_FILES */
1171 #define create_debug_files(dev) do {} while (0)
1172 #define remove_debug_files(dev) do {} while (0)
1174 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1176 /*-------------------------------------------------------------------------*/
1179 * udc_disable - disable USB device controller
1181 static void udc_disable(struct pxa25x_udc
*dev
)
1183 /* block all irqs */
1184 udc_set_mask_UDCCR(UDCCR_SRM
|UDCCR_REM
);
1185 UICR0
= UICR1
= 0xff;
1188 /* if hardware supports it, disconnect from usb */
1191 udc_clear_mask_UDCCR(UDCCR_UDE
);
1194 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1199 * udc_reinit - initialize software state
1201 static void udc_reinit(struct pxa25x_udc
*dev
)
1205 /* device/ep0 records init */
1206 INIT_LIST_HEAD (&dev
->gadget
.ep_list
);
1207 INIT_LIST_HEAD (&dev
->gadget
.ep0
->ep_list
);
1208 dev
->ep0state
= EP0_IDLE
;
1210 /* basic endpoint records init */
1211 for (i
= 0; i
< PXA_UDC_NUM_ENDPOINTS
; i
++) {
1212 struct pxa25x_ep
*ep
= &dev
->ep
[i
];
1215 list_add_tail (&ep
->ep
.ep_list
, &dev
->gadget
.ep_list
);
1219 INIT_LIST_HEAD (&ep
->queue
);
1223 /* the rest was statically initialized, and is read-only */
1226 /* until it's enabled, this UDC should be completely invisible
1229 static void udc_enable (struct pxa25x_udc
*dev
)
1231 udc_clear_mask_UDCCR(UDCCR_UDE
);
1233 /* try to clear these bits before we enable the udc */
1234 udc_ack_int_UDCCR(UDCCR_SUSIR
|/*UDCCR_RSTIR|*/UDCCR_RESIR
);
1237 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1238 dev
->stats
.irqs
= 0;
1241 * sequence taken from chapter 12.5.10, PXA250 AppProcDevManual:
1243 * - if RESET is already in progress, ack interrupt
1244 * - unmask reset interrupt
1246 udc_set_mask_UDCCR(UDCCR_UDE
);
1247 if (!(UDCCR
& UDCCR_UDA
))
1248 udc_ack_int_UDCCR(UDCCR_RSTIR
);
1250 if (dev
->has_cfr
/* UDC_RES2 is defined */) {
1251 /* pxa255 (a0+) can avoid a set_config race that could
1252 * prevent gadget drivers from configuring correctly
1254 UDCCFR
= UDCCFR_ACM
| UDCCFR_MB1
;
1256 /* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1)
1257 * which could result in missing packets and interrupts.
1258 * supposedly one bit per endpoint, controlling whether it
1259 * double buffers or not; ACM/AREN bits fit into the holes.
1260 * zero bits (like USIR0_IRx) disable double buffering.
1266 /* enable suspend/resume and reset irqs */
1267 udc_clear_mask_UDCCR(UDCCR_SRM
| UDCCR_REM
);
1269 /* enable ep0 irqs */
1270 UICR0
&= ~UICR0_IM0
;
1272 /* if hardware supports it, pullup D+ and wait for reset */
1277 /* when a driver is successfully registered, it will receive
1278 * control requests including set_configuration(), which enables
1279 * non-control requests. then usb traffic follows until a
1280 * disconnect is reported. then a host may connect again, or
1281 * the driver might get unbound.
1283 int usb_gadget_probe_driver(struct usb_gadget_driver
*driver
,
1284 int (*bind
)(struct usb_gadget
*))
1286 struct pxa25x_udc
*dev
= the_controller
;
1290 || driver
->speed
< USB_SPEED_FULL
1292 || !driver
->disconnect
1300 /* first hook up the driver ... */
1301 dev
->driver
= driver
;
1302 dev
->gadget
.dev
.driver
= &driver
->driver
;
1305 retval
= device_add (&dev
->gadget
.dev
);
1309 dev
->gadget
.dev
.driver
= NULL
;
1312 retval
= bind(&dev
->gadget
);
1314 DMSG("bind to driver %s --> error %d\n",
1315 driver
->driver
.name
, retval
);
1316 device_del (&dev
->gadget
.dev
);
1320 /* ... then enable host detection and ep0; and we're ready
1321 * for set_configuration as well as eventual disconnect.
1323 DMSG("registered gadget driver '%s'\n", driver
->driver
.name
);
1325 /* connect to bus through transceiver */
1326 if (dev
->transceiver
) {
1327 retval
= otg_set_peripheral(dev
->transceiver
, &dev
->gadget
);
1329 DMSG("can't bind to transceiver\n");
1331 driver
->unbind(&dev
->gadget
);
1342 EXPORT_SYMBOL(usb_gadget_probe_driver
);
1345 stop_activity(struct pxa25x_udc
*dev
, struct usb_gadget_driver
*driver
)
1349 /* don't disconnect drivers more than once */
1350 if (dev
->gadget
.speed
== USB_SPEED_UNKNOWN
)
1352 dev
->gadget
.speed
= USB_SPEED_UNKNOWN
;
1354 /* prevent new request submissions, kill any outstanding requests */
1355 for (i
= 0; i
< PXA_UDC_NUM_ENDPOINTS
; i
++) {
1356 struct pxa25x_ep
*ep
= &dev
->ep
[i
];
1359 nuke(ep
, -ESHUTDOWN
);
1361 del_timer_sync(&dev
->timer
);
1363 /* report disconnect; the driver is already quiesced */
1365 driver
->disconnect(&dev
->gadget
);
1367 /* re-init driver-visible data structures */
1371 int usb_gadget_unregister_driver(struct usb_gadget_driver
*driver
)
1373 struct pxa25x_udc
*dev
= the_controller
;
1377 if (!driver
|| driver
!= dev
->driver
|| !driver
->unbind
)
1380 local_irq_disable();
1383 stop_activity(dev
, driver
);
1386 if (dev
->transceiver
)
1387 (void) otg_set_peripheral(dev
->transceiver
, NULL
);
1389 driver
->unbind(&dev
->gadget
);
1390 dev
->gadget
.dev
.driver
= NULL
;
1393 device_del (&dev
->gadget
.dev
);
1395 DMSG("unregistered gadget driver '%s'\n", driver
->driver
.name
);
1399 EXPORT_SYMBOL(usb_gadget_unregister_driver
);
1402 /*-------------------------------------------------------------------------*/
1404 #ifdef CONFIG_ARCH_LUBBOCK
1406 /* Lubbock has separate connect and disconnect irqs. More typical designs
1407 * use one GPIO as the VBUS IRQ, and another to control the D+ pullup.
1411 lubbock_vbus_irq(int irq
, void *_dev
)
1413 struct pxa25x_udc
*dev
= _dev
;
1418 case LUBBOCK_USB_IRQ
:
1420 disable_irq(LUBBOCK_USB_IRQ
);
1421 enable_irq(LUBBOCK_USB_DISC_IRQ
);
1423 case LUBBOCK_USB_DISC_IRQ
:
1425 disable_irq(LUBBOCK_USB_DISC_IRQ
);
1426 enable_irq(LUBBOCK_USB_IRQ
);
1432 pxa25x_udc_vbus_session(&dev
->gadget
, vbus
);
1438 static irqreturn_t
udc_vbus_irq(int irq
, void *_dev
)
1440 struct pxa25x_udc
*dev
= _dev
;
1442 pxa25x_udc_vbus_session(&dev
->gadget
, is_vbus_present());
1447 /*-------------------------------------------------------------------------*/
1449 static inline void clear_ep_state (struct pxa25x_udc
*dev
)
1453 /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
1454 * fifos, and pending transactions mustn't be continued in any case.
1456 for (i
= 1; i
< PXA_UDC_NUM_ENDPOINTS
; i
++)
1457 nuke(&dev
->ep
[i
], -ECONNABORTED
);
1460 static void udc_watchdog(unsigned long _dev
)
1462 struct pxa25x_udc
*dev
= (void *)_dev
;
1464 local_irq_disable();
1465 if (dev
->ep0state
== EP0_STALL
1466 && (UDCCS0
& UDCCS0_FST
) == 0
1467 && (UDCCS0
& UDCCS0_SST
) == 0) {
1468 UDCCS0
= UDCCS0_FST
|UDCCS0_FTF
;
1469 DBG(DBG_VERBOSE
, "ep0 re-stall\n");
1470 start_watchdog(dev
);
1475 static void handle_ep0 (struct pxa25x_udc
*dev
)
1477 u32 udccs0
= UDCCS0
;
1478 struct pxa25x_ep
*ep
= &dev
->ep
[0];
1479 struct pxa25x_request
*req
;
1481 struct usb_ctrlrequest r
;
1486 if (list_empty(&ep
->queue
))
1489 req
= list_entry(ep
->queue
.next
, struct pxa25x_request
, queue
);
1491 /* clear stall status */
1492 if (udccs0
& UDCCS0_SST
) {
1494 UDCCS0
= UDCCS0_SST
;
1495 del_timer(&dev
->timer
);
1499 /* previous request unfinished? non-error iff back-to-back ... */
1500 if ((udccs0
& UDCCS0_SA
) != 0 && dev
->ep0state
!= EP0_IDLE
) {
1502 del_timer(&dev
->timer
);
1506 switch (dev
->ep0state
) {
1508 /* late-breaking status? */
1511 /* start control request? */
1512 if (likely((udccs0
& (UDCCS0_OPR
|UDCCS0_SA
|UDCCS0_RNE
))
1513 == (UDCCS0_OPR
|UDCCS0_SA
|UDCCS0_RNE
))) {
1518 /* read SETUP packet */
1519 for (i
= 0; i
< 8; i
++) {
1520 if (unlikely(!(UDCCS0
& UDCCS0_RNE
))) {
1522 DMSG("SETUP %d!\n", i
);
1525 u
.raw
[i
] = (u8
) UDDR0
;
1527 if (unlikely((UDCCS0
& UDCCS0_RNE
) != 0))
1531 DBG(DBG_VERBOSE
, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1532 u
.r
.bRequestType
, u
.r
.bRequest
,
1533 le16_to_cpu(u
.r
.wValue
),
1534 le16_to_cpu(u
.r
.wIndex
),
1535 le16_to_cpu(u
.r
.wLength
));
1537 /* cope with automagic for some standard requests. */
1538 dev
->req_std
= (u
.r
.bRequestType
& USB_TYPE_MASK
)
1539 == USB_TYPE_STANDARD
;
1540 dev
->req_config
= 0;
1541 dev
->req_pending
= 1;
1542 switch (u
.r
.bRequest
) {
1543 /* hardware restricts gadget drivers here! */
1544 case USB_REQ_SET_CONFIGURATION
:
1545 if (u
.r
.bRequestType
== USB_RECIP_DEVICE
) {
1546 /* reflect hardware's automagic
1547 * up to the gadget driver.
1550 dev
->req_config
= 1;
1551 clear_ep_state(dev
);
1552 /* if !has_cfr, there's no synch
1553 * else use AREN (later) not SA|OPR
1554 * USIR0_IR0 acts edge sensitive
1558 /* ... and here, even more ... */
1559 case USB_REQ_SET_INTERFACE
:
1560 if (u
.r
.bRequestType
== USB_RECIP_INTERFACE
) {
1561 /* udc hardware is broken by design:
1562 * - altsetting may only be zero;
1563 * - hw resets all interfaces' eps;
1564 * - ep reset doesn't include halt(?).
1566 DMSG("broken set_interface (%d/%d)\n",
1567 le16_to_cpu(u
.r
.wIndex
),
1568 le16_to_cpu(u
.r
.wValue
));
1572 /* hardware was supposed to hide this */
1573 case USB_REQ_SET_ADDRESS
:
1574 if (u
.r
.bRequestType
== USB_RECIP_DEVICE
) {
1575 ep0start(dev
, 0, "address");
1581 if (u
.r
.bRequestType
& USB_DIR_IN
)
1582 dev
->ep0state
= EP0_IN_DATA_PHASE
;
1584 dev
->ep0state
= EP0_OUT_DATA_PHASE
;
1586 i
= dev
->driver
->setup(&dev
->gadget
, &u
.r
);
1588 /* hardware automagic preventing STALL... */
1589 if (dev
->req_config
) {
1590 /* hardware sometimes neglects to tell
1591 * tell us about config change events,
1592 * so later ones may fail...
1594 WARNING("config change %02x fail %d?\n",
1597 /* TODO experiment: if has_cfr,
1598 * hardware didn't ACK; maybe we
1599 * could actually STALL!
1602 DBG(DBG_VERBOSE
, "protocol STALL, "
1603 "%02x err %d\n", UDCCS0
, i
);
1605 /* the watchdog timer helps deal with cases
1606 * where udc seems to clear FST wrongly, and
1607 * then NAKs instead of STALLing.
1609 ep0start(dev
, UDCCS0_FST
|UDCCS0_FTF
, "stall");
1610 start_watchdog(dev
);
1611 dev
->ep0state
= EP0_STALL
;
1613 /* deferred i/o == no response yet */
1614 } else if (dev
->req_pending
) {
1615 if (likely(dev
->ep0state
== EP0_IN_DATA_PHASE
1616 || dev
->req_std
|| u
.r
.wLength
))
1617 ep0start(dev
, 0, "defer");
1619 ep0start(dev
, UDCCS0_IPR
, "defer/IPR");
1622 /* expect at least one data or status stage irq */
1625 } else if (likely((udccs0
& (UDCCS0_OPR
|UDCCS0_SA
))
1626 == (UDCCS0_OPR
|UDCCS0_SA
))) {
1629 /* pxa210/250 erratum 131 for B0/B1 says RNE lies.
1630 * still observed on a pxa255 a0.
1632 DBG(DBG_VERBOSE
, "e131\n");
1635 /* read SETUP data, but don't trust it too much */
1636 for (i
= 0; i
< 8; i
++)
1637 u
.raw
[i
] = (u8
) UDDR0
;
1638 if ((u
.r
.bRequestType
& USB_RECIP_MASK
)
1641 if (u
.word
[0] == 0 && u
.word
[1] == 0)
1645 /* some random early IRQ:
1648 * - OPR got set, without SA (likely status stage)
1650 UDCCS0
= udccs0
& (UDCCS0_SA
|UDCCS0_OPR
);
1653 case EP0_IN_DATA_PHASE
: /* GET_DESCRIPTOR etc */
1654 if (udccs0
& UDCCS0_OPR
) {
1655 UDCCS0
= UDCCS0_OPR
|UDCCS0_FTF
;
1656 DBG(DBG_VERBOSE
, "ep0in premature status\n");
1660 } else /* irq was IPR clearing */ {
1662 /* this IN packet might finish the request */
1663 (void) write_ep0_fifo(ep
, req
);
1664 } /* else IN token before response was written */
1667 case EP0_OUT_DATA_PHASE
: /* SET_DESCRIPTOR etc */
1668 if (udccs0
& UDCCS0_OPR
) {
1670 /* this OUT packet might finish the request */
1671 if (read_ep0_fifo(ep
, req
))
1673 /* else more OUT packets expected */
1674 } /* else OUT token before read was issued */
1675 } else /* irq was IPR clearing */ {
1676 DBG(DBG_VERBOSE
, "ep0out premature status\n");
1685 /* ack control-IN status (maybe in-zlp was skipped)
1686 * also appears after some config change events.
1688 if (udccs0
& UDCCS0_OPR
)
1689 UDCCS0
= UDCCS0_OPR
;
1693 UDCCS0
= UDCCS0_FST
;
1699 static void handle_ep(struct pxa25x_ep
*ep
)
1701 struct pxa25x_request
*req
;
1702 int is_in
= ep
->bEndpointAddress
& USB_DIR_IN
;
1708 if (likely (!list_empty(&ep
->queue
)))
1709 req
= list_entry(ep
->queue
.next
,
1710 struct pxa25x_request
, queue
);
1714 // TODO check FST handling
1716 udccs
= *ep
->reg_udccs
;
1717 if (unlikely(is_in
)) { /* irq from TPC, SST, or (ISO) TUR */
1719 if (likely(ep
->bmAttributes
== USB_ENDPOINT_XFER_BULK
))
1720 tmp
|= UDCCS_BI_SST
;
1723 *ep
->reg_udccs
= tmp
;
1724 if (req
&& likely ((udccs
& UDCCS_BI_TFS
) != 0))
1725 completed
= write_fifo(ep
, req
);
1727 } else { /* irq from RPC (or for ISO, ROF) */
1728 if (likely(ep
->bmAttributes
== USB_ENDPOINT_XFER_BULK
))
1729 tmp
= UDCCS_BO_SST
| UDCCS_BO_DME
;
1731 tmp
= UDCCS_IO_ROF
| UDCCS_IO_DME
;
1734 *ep
->reg_udccs
= tmp
;
1736 /* fifos can hold packets, ready for reading... */
1738 completed
= read_fifo(ep
, req
);
1740 pio_irq_disable (ep
->bEndpointAddress
);
1743 } while (completed
);
1747 * pxa25x_udc_irq - interrupt handler
1749 * avoid delays in ep0 processing. the control handshaking isn't always
1750 * under software control (pxa250c0 and the pxa255 are better), and delays
1751 * could cause usb protocol errors.
1754 pxa25x_udc_irq(int irq
, void *_dev
)
1756 struct pxa25x_udc
*dev
= _dev
;
1765 /* SUSpend Interrupt Request */
1766 if (unlikely(udccr
& UDCCR_SUSIR
)) {
1767 udc_ack_int_UDCCR(UDCCR_SUSIR
);
1769 DBG(DBG_VERBOSE
, "USB suspend%s\n", is_vbus_present()
1770 ? "" : "+disconnect");
1772 if (!is_vbus_present())
1773 stop_activity(dev
, dev
->driver
);
1774 else if (dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
1776 && dev
->driver
->suspend
)
1777 dev
->driver
->suspend(&dev
->gadget
);
1781 /* RESume Interrupt Request */
1782 if (unlikely(udccr
& UDCCR_RESIR
)) {
1783 udc_ack_int_UDCCR(UDCCR_RESIR
);
1785 DBG(DBG_VERBOSE
, "USB resume\n");
1787 if (dev
->gadget
.speed
!= USB_SPEED_UNKNOWN
1789 && dev
->driver
->resume
1790 && is_vbus_present())
1791 dev
->driver
->resume(&dev
->gadget
);
1794 /* ReSeT Interrupt Request - USB reset */
1795 if (unlikely(udccr
& UDCCR_RSTIR
)) {
1796 udc_ack_int_UDCCR(UDCCR_RSTIR
);
1799 if ((UDCCR
& UDCCR_UDA
) == 0) {
1800 DBG(DBG_VERBOSE
, "USB reset start\n");
1802 /* reset driver and endpoints,
1803 * in case that's not yet done
1805 stop_activity (dev
, dev
->driver
);
1808 DBG(DBG_VERBOSE
, "USB reset end\n");
1809 dev
->gadget
.speed
= USB_SPEED_FULL
;
1810 memset(&dev
->stats
, 0, sizeof dev
->stats
);
1811 /* driver and endpoints are still reset */
1815 u32 usir0
= USIR0
& ~UICR0
;
1816 u32 usir1
= USIR1
& ~UICR1
;
1819 if (unlikely (!usir0
&& !usir1
))
1822 DBG(DBG_VERY_NOISY
, "irq %02x.%02x\n", usir1
, usir0
);
1824 /* control traffic */
1825 if (usir0
& USIR0_IR0
) {
1826 dev
->ep
[0].pio_irqs
++;
1831 /* endpoint data transfers */
1832 for (i
= 0; i
< 8; i
++) {
1835 if (i
&& (usir0
& tmp
)) {
1836 handle_ep(&dev
->ep
[i
]);
1840 #ifndef CONFIG_USB_PXA25X_SMALL
1842 handle_ep(&dev
->ep
[i
+8]);
1850 /* we could also ask for 1 msec SOF (SIR) interrupts */
1856 /*-------------------------------------------------------------------------*/
1858 static void nop_release (struct device
*dev
)
1860 DMSG("%s %s\n", __func__
, dev_name(dev
));
1863 /* this uses load-time allocation and initialization (instead of
1864 * doing it at run-time) to save code, eliminate fault paths, and
1865 * be more obviously correct.
1867 static struct pxa25x_udc memory
= {
1869 .ops
= &pxa25x_udc_ops
,
1870 .ep0
= &memory
.ep
[0].ep
,
1871 .name
= driver_name
,
1873 .init_name
= "gadget",
1874 .release
= nop_release
,
1878 /* control endpoint */
1882 .ops
= &pxa25x_ep_ops
,
1883 .maxpacket
= EP0_FIFO_SIZE
,
1886 .reg_udccs
= &UDCCS0
,
1890 /* first group of endpoints */
1893 .name
= "ep1in-bulk",
1894 .ops
= &pxa25x_ep_ops
,
1895 .maxpacket
= BULK_FIFO_SIZE
,
1898 .fifo_size
= BULK_FIFO_SIZE
,
1899 .bEndpointAddress
= USB_DIR_IN
| 1,
1900 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
1901 .reg_udccs
= &UDCCS1
,
1906 .name
= "ep2out-bulk",
1907 .ops
= &pxa25x_ep_ops
,
1908 .maxpacket
= BULK_FIFO_SIZE
,
1911 .fifo_size
= BULK_FIFO_SIZE
,
1912 .bEndpointAddress
= 2,
1913 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
1914 .reg_udccs
= &UDCCS2
,
1918 #ifndef CONFIG_USB_PXA25X_SMALL
1921 .name
= "ep3in-iso",
1922 .ops
= &pxa25x_ep_ops
,
1923 .maxpacket
= ISO_FIFO_SIZE
,
1926 .fifo_size
= ISO_FIFO_SIZE
,
1927 .bEndpointAddress
= USB_DIR_IN
| 3,
1928 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
1929 .reg_udccs
= &UDCCS3
,
1934 .name
= "ep4out-iso",
1935 .ops
= &pxa25x_ep_ops
,
1936 .maxpacket
= ISO_FIFO_SIZE
,
1939 .fifo_size
= ISO_FIFO_SIZE
,
1940 .bEndpointAddress
= 4,
1941 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
1942 .reg_udccs
= &UDCCS4
,
1948 .name
= "ep5in-int",
1949 .ops
= &pxa25x_ep_ops
,
1950 .maxpacket
= INT_FIFO_SIZE
,
1953 .fifo_size
= INT_FIFO_SIZE
,
1954 .bEndpointAddress
= USB_DIR_IN
| 5,
1955 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
1956 .reg_udccs
= &UDCCS5
,
1960 /* second group of endpoints */
1963 .name
= "ep6in-bulk",
1964 .ops
= &pxa25x_ep_ops
,
1965 .maxpacket
= BULK_FIFO_SIZE
,
1968 .fifo_size
= BULK_FIFO_SIZE
,
1969 .bEndpointAddress
= USB_DIR_IN
| 6,
1970 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
1971 .reg_udccs
= &UDCCS6
,
1976 .name
= "ep7out-bulk",
1977 .ops
= &pxa25x_ep_ops
,
1978 .maxpacket
= BULK_FIFO_SIZE
,
1981 .fifo_size
= BULK_FIFO_SIZE
,
1982 .bEndpointAddress
= 7,
1983 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
1984 .reg_udccs
= &UDCCS7
,
1990 .name
= "ep8in-iso",
1991 .ops
= &pxa25x_ep_ops
,
1992 .maxpacket
= ISO_FIFO_SIZE
,
1995 .fifo_size
= ISO_FIFO_SIZE
,
1996 .bEndpointAddress
= USB_DIR_IN
| 8,
1997 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
1998 .reg_udccs
= &UDCCS8
,
2003 .name
= "ep9out-iso",
2004 .ops
= &pxa25x_ep_ops
,
2005 .maxpacket
= ISO_FIFO_SIZE
,
2008 .fifo_size
= ISO_FIFO_SIZE
,
2009 .bEndpointAddress
= 9,
2010 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
2011 .reg_udccs
= &UDCCS9
,
2017 .name
= "ep10in-int",
2018 .ops
= &pxa25x_ep_ops
,
2019 .maxpacket
= INT_FIFO_SIZE
,
2022 .fifo_size
= INT_FIFO_SIZE
,
2023 .bEndpointAddress
= USB_DIR_IN
| 10,
2024 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
2025 .reg_udccs
= &UDCCS10
,
2026 .reg_uddr
= &UDDR10
,
2029 /* third group of endpoints */
2032 .name
= "ep11in-bulk",
2033 .ops
= &pxa25x_ep_ops
,
2034 .maxpacket
= BULK_FIFO_SIZE
,
2037 .fifo_size
= BULK_FIFO_SIZE
,
2038 .bEndpointAddress
= USB_DIR_IN
| 11,
2039 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
2040 .reg_udccs
= &UDCCS11
,
2041 .reg_uddr
= &UDDR11
,
2045 .name
= "ep12out-bulk",
2046 .ops
= &pxa25x_ep_ops
,
2047 .maxpacket
= BULK_FIFO_SIZE
,
2050 .fifo_size
= BULK_FIFO_SIZE
,
2051 .bEndpointAddress
= 12,
2052 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
2053 .reg_udccs
= &UDCCS12
,
2054 .reg_ubcr
= &UBCR12
,
2055 .reg_uddr
= &UDDR12
,
2059 .name
= "ep13in-iso",
2060 .ops
= &pxa25x_ep_ops
,
2061 .maxpacket
= ISO_FIFO_SIZE
,
2064 .fifo_size
= ISO_FIFO_SIZE
,
2065 .bEndpointAddress
= USB_DIR_IN
| 13,
2066 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
2067 .reg_udccs
= &UDCCS13
,
2068 .reg_uddr
= &UDDR13
,
2072 .name
= "ep14out-iso",
2073 .ops
= &pxa25x_ep_ops
,
2074 .maxpacket
= ISO_FIFO_SIZE
,
2077 .fifo_size
= ISO_FIFO_SIZE
,
2078 .bEndpointAddress
= 14,
2079 .bmAttributes
= USB_ENDPOINT_XFER_ISOC
,
2080 .reg_udccs
= &UDCCS14
,
2081 .reg_ubcr
= &UBCR14
,
2082 .reg_uddr
= &UDDR14
,
2086 .name
= "ep15in-int",
2087 .ops
= &pxa25x_ep_ops
,
2088 .maxpacket
= INT_FIFO_SIZE
,
2091 .fifo_size
= INT_FIFO_SIZE
,
2092 .bEndpointAddress
= USB_DIR_IN
| 15,
2093 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
2094 .reg_udccs
= &UDCCS15
,
2095 .reg_uddr
= &UDDR15
,
2097 #endif /* !CONFIG_USB_PXA25X_SMALL */
2100 #define CP15R0_VENDOR_MASK 0xffffe000
2102 #if defined(CONFIG_ARCH_PXA)
2103 #define CP15R0_XSCALE_VALUE 0x69052000 /* intel/arm/xscale */
2105 #elif defined(CONFIG_ARCH_IXP4XX)
2106 #define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/ixp4xx */
2110 #define CP15R0_PROD_MASK 0x000003f0
2111 #define PXA25x 0x00000100 /* and PXA26x */
2112 #define PXA210 0x00000120
2114 #define CP15R0_REV_MASK 0x0000000f
2116 #define CP15R0_PRODREV_MASK (CP15R0_PROD_MASK | CP15R0_REV_MASK)
2118 #define PXA255_A0 0x00000106 /* or PXA260_B1 */
2119 #define PXA250_C0 0x00000105 /* or PXA26x_B0 */
2120 #define PXA250_B2 0x00000104
2121 #define PXA250_B1 0x00000103 /* or PXA260_A0 */
2122 #define PXA250_B0 0x00000102
2123 #define PXA250_A1 0x00000101
2124 #define PXA250_A0 0x00000100
2126 #define PXA210_C0 0x00000125
2127 #define PXA210_B2 0x00000124
2128 #define PXA210_B1 0x00000123
2129 #define PXA210_B0 0x00000122
2130 #define IXP425_A0 0x000001c1
2131 #define IXP425_B0 0x000001f1
2132 #define IXP465_AD 0x00000200
2135 * probe - binds to the platform device
2137 static int __init
pxa25x_udc_probe(struct platform_device
*pdev
)
2139 struct pxa25x_udc
*dev
= &memory
;
2140 int retval
, vbus_irq
, irq
;
2143 /* insist on Intel/ARM/XScale */
2144 asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev
));
2145 if ((chiprev
& CP15R0_VENDOR_MASK
) != CP15R0_XSCALE_VALUE
) {
2146 pr_err("%s: not XScale!\n", driver_name
);
2150 /* trigger chiprev-specific logic */
2151 switch (chiprev
& CP15R0_PRODREV_MASK
) {
2152 #if defined(CONFIG_ARCH_PXA)
2158 /* A0/A1 "not released"; ep 13, 15 unusable */
2160 case PXA250_B2
: case PXA210_B2
:
2161 case PXA250_B1
: case PXA210_B1
:
2162 case PXA250_B0
: case PXA210_B0
:
2163 /* OUT-DMA is broken ... */
2165 case PXA250_C0
: case PXA210_C0
:
2167 #elif defined(CONFIG_ARCH_IXP4XX)
2175 pr_err("%s: unrecognized processor: %08x\n",
2176 driver_name
, chiprev
);
2177 /* iop3xx, ixp4xx, ... */
2181 irq
= platform_get_irq(pdev
, 0);
2185 dev
->clk
= clk_get(&pdev
->dev
, NULL
);
2186 if (IS_ERR(dev
->clk
)) {
2187 retval
= PTR_ERR(dev
->clk
);
2191 pr_debug("%s: IRQ %d%s%s\n", driver_name
, irq
,
2192 dev
->has_cfr
? "" : " (!cfr)",
2196 /* other non-static parts of init */
2197 dev
->dev
= &pdev
->dev
;
2198 dev
->mach
= pdev
->dev
.platform_data
;
2200 dev
->transceiver
= otg_get_transceiver();
2202 if (gpio_is_valid(dev
->mach
->gpio_vbus
)) {
2203 if ((retval
= gpio_request(dev
->mach
->gpio_vbus
,
2204 "pxa25x_udc GPIO VBUS"))) {
2206 "can't get vbus gpio %d, err: %d\n",
2207 dev
->mach
->gpio_vbus
, retval
);
2210 gpio_direction_input(dev
->mach
->gpio_vbus
);
2211 vbus_irq
= gpio_to_irq(dev
->mach
->gpio_vbus
);
2215 if (gpio_is_valid(dev
->mach
->gpio_pullup
)) {
2216 if ((retval
= gpio_request(dev
->mach
->gpio_pullup
,
2217 "pca25x_udc GPIO PULLUP"))) {
2219 "can't get pullup gpio %d, err: %d\n",
2220 dev
->mach
->gpio_pullup
, retval
);
2221 goto err_gpio_pullup
;
2223 gpio_direction_output(dev
->mach
->gpio_pullup
, 0);
2226 init_timer(&dev
->timer
);
2227 dev
->timer
.function
= udc_watchdog
;
2228 dev
->timer
.data
= (unsigned long) dev
;
2230 device_initialize(&dev
->gadget
.dev
);
2231 dev
->gadget
.dev
.parent
= &pdev
->dev
;
2232 dev
->gadget
.dev
.dma_mask
= pdev
->dev
.dma_mask
;
2234 the_controller
= dev
;
2235 platform_set_drvdata(pdev
, dev
);
2240 dev
->vbus
= !!is_vbus_present();
2242 /* irq setup after old hardware state is cleaned up */
2243 retval
= request_irq(irq
, pxa25x_udc_irq
,
2244 IRQF_DISABLED
, driver_name
, dev
);
2246 pr_err("%s: can't get irq %d, err %d\n",
2247 driver_name
, irq
, retval
);
2252 #ifdef CONFIG_ARCH_LUBBOCK
2253 if (machine_is_lubbock()) {
2254 retval
= request_irq(LUBBOCK_USB_DISC_IRQ
,
2256 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
,
2259 pr_err("%s: can't get irq %i, err %d\n",
2260 driver_name
, LUBBOCK_USB_DISC_IRQ
, retval
);
2264 retval
= request_irq(LUBBOCK_USB_IRQ
,
2266 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
,
2269 pr_err("%s: can't get irq %i, err %d\n",
2270 driver_name
, LUBBOCK_USB_IRQ
, retval
);
2271 free_irq(LUBBOCK_USB_DISC_IRQ
, dev
);
2277 retval
= request_irq(vbus_irq
, udc_vbus_irq
,
2278 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
|
2279 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
2282 pr_err("%s: can't get irq %i, err %d\n",
2283 driver_name
, vbus_irq
, retval
);
2287 create_debug_files(dev
);
2292 #ifdef CONFIG_ARCH_LUBBOCK
2293 free_irq(LUBBOCK_USB_DISC_IRQ
, dev
);
2298 if (gpio_is_valid(dev
->mach
->gpio_pullup
))
2299 gpio_free(dev
->mach
->gpio_pullup
);
2301 if (gpio_is_valid(dev
->mach
->gpio_vbus
))
2302 gpio_free(dev
->mach
->gpio_vbus
);
2304 if (dev
->transceiver
) {
2305 otg_put_transceiver(dev
->transceiver
);
2306 dev
->transceiver
= NULL
;
2313 static void pxa25x_udc_shutdown(struct platform_device
*_dev
)
2318 static int __exit
pxa25x_udc_remove(struct platform_device
*pdev
)
2320 struct pxa25x_udc
*dev
= platform_get_drvdata(pdev
);
2328 remove_debug_files(dev
);
2331 free_irq(platform_get_irq(pdev
, 0), dev
);
2334 #ifdef CONFIG_ARCH_LUBBOCK
2335 if (machine_is_lubbock()) {
2336 free_irq(LUBBOCK_USB_DISC_IRQ
, dev
);
2337 free_irq(LUBBOCK_USB_IRQ
, dev
);
2340 if (gpio_is_valid(dev
->mach
->gpio_vbus
)) {
2341 free_irq(gpio_to_irq(dev
->mach
->gpio_vbus
), dev
);
2342 gpio_free(dev
->mach
->gpio_vbus
);
2344 if (gpio_is_valid(dev
->mach
->gpio_pullup
))
2345 gpio_free(dev
->mach
->gpio_pullup
);
2349 if (dev
->transceiver
) {
2350 otg_put_transceiver(dev
->transceiver
);
2351 dev
->transceiver
= NULL
;
2354 platform_set_drvdata(pdev
, NULL
);
2355 the_controller
= NULL
;
2359 /*-------------------------------------------------------------------------*/
2363 /* USB suspend (controlled by the host) and system suspend (controlled
2364 * by the PXA) don't necessarily work well together. If USB is active,
2365 * the 48 MHz clock is required; so the system can't enter 33 MHz idle
2366 * mode, or any deeper PM saving state.
2368 * For now, we punt and forcibly disconnect from the USB host when PXA
2369 * enters any suspend state. While we're disconnected, we always disable
2370 * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
2371 * Boards without software pullup control shouldn't use those states.
2372 * VBUS IRQs should probably be ignored so that the PXA device just acts
2373 * "dead" to USB hosts until system resume.
2375 static int pxa25x_udc_suspend(struct platform_device
*dev
, pm_message_t state
)
2377 struct pxa25x_udc
*udc
= platform_get_drvdata(dev
);
2378 unsigned long flags
;
2380 if (!gpio_is_valid(udc
->mach
->gpio_pullup
) && !udc
->mach
->udc_command
)
2381 WARNING("USB host won't detect disconnect!\n");
2384 local_irq_save(flags
);
2386 local_irq_restore(flags
);
2391 static int pxa25x_udc_resume(struct platform_device
*dev
)
2393 struct pxa25x_udc
*udc
= platform_get_drvdata(dev
);
2394 unsigned long flags
;
2397 local_irq_save(flags
);
2399 local_irq_restore(flags
);
2405 #define pxa25x_udc_suspend NULL
2406 #define pxa25x_udc_resume NULL
2409 /*-------------------------------------------------------------------------*/
2411 static struct platform_driver udc_driver
= {
2412 .shutdown
= pxa25x_udc_shutdown
,
2413 .remove
= __exit_p(pxa25x_udc_remove
),
2414 .suspend
= pxa25x_udc_suspend
,
2415 .resume
= pxa25x_udc_resume
,
2417 .owner
= THIS_MODULE
,
2418 .name
= "pxa25x-udc",
2422 static int __init
udc_init(void)
2424 pr_info("%s: version %s\n", driver_name
, DRIVER_VERSION
);
2425 return platform_driver_probe(&udc_driver
, pxa25x_udc_probe
);
2427 module_init(udc_init
);
2429 static void __exit
udc_exit(void)
2431 platform_driver_unregister(&udc_driver
);
2433 module_exit(udc_exit
);
2435 MODULE_DESCRIPTION(DRIVER_DESC
);
2436 MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
2437 MODULE_LICENSE("GPL");
2438 MODULE_ALIAS("platform:pxa25x-udc");