1 diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
2 index 4097a86..5d3ea6e 100644
3 --- a/drivers/usb/gadget/Kconfig
4 +++ b/drivers/usb/gadget/Kconfig
5 @@ -111,6 +111,24 @@ config USB_PXA2XX
7 select USB_GADGET_SELECTED
9 +config USB_GADGET_PXA27X
11 + depends on ARCH_PXA && PXA27x
13 + Intel's PXA 27x series XScale processors include an integrated
14 + full speed USB 1.1 device controller.
16 + Say "y" to link the driver statically, or "m" to build a
17 + dynamically linked module called "pxa2xx_udc" and force all
18 + gadget drivers to also be dynamically linked.
23 + depends on USB_GADGET_PXA27X
25 + select USB_GADGET_SELECTED
27 # if there's only one gadget driver, using only two bulk endpoints,
28 # don't waste memory for the other endpoints
29 config USB_PXA2XX_SMALL
30 diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
31 index e71e086..7e508a6 100644
32 --- a/drivers/usb/gadget/Makefile
33 +++ b/drivers/usb/gadget/Makefile
35 obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
36 obj-$(CONFIG_USB_NET2280) += net2280.o
37 obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o
38 +obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o
39 obj-$(CONFIG_USB_GOKU) += goku_udc.o
40 obj-$(CONFIG_USB_OMAP) += omap_udc.o
41 obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
42 diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
43 index f28af06..e7d72ff 100644
44 --- a/drivers/usb/gadget/epautoconf.c
45 +++ b/drivers/usb/gadget/epautoconf.c
46 @@ -230,7 +230,8 @@ find_ep (struct usb_gadget *gadget, const char *name)
48 struct usb_ep * __devinit usb_ep_autoconfig (
49 struct usb_gadget *gadget,
50 - struct usb_endpoint_descriptor *desc
51 + struct usb_endpoint_descriptor *desc,
52 + int config, int interface, int alt
56 @@ -238,6 +239,11 @@ struct usb_ep * __devinit usb_ep_autoconfig (
58 type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
60 + /* If have ep_alloc() function use it! */
61 + if (gadget->ops->ep_alloc)
62 + return gadget->ops->ep_alloc(gadget, desc,
63 + config, interface, alt);
65 /* First, apply chip-specific "best usage" knowledge.
66 * This might make a good usb_gadget_ops hook ...
68 diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
69 index 04e6b85..bc6de31 100644
70 --- a/drivers/usb/gadget/ether.c
71 +++ b/drivers/usb/gadget/ether.c
72 @@ -258,10 +258,6 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
73 #define DEV_CONFIG_CDC
76 -#ifdef CONFIG_USB_GADGET_PXA27X
77 -#define DEV_CONFIG_CDC
80 #ifdef CONFIG_USB_GADGET_S3C2410
81 #define DEV_CONFIG_CDC
83 @@ -294,6 +290,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
84 #define DEV_CONFIG_SUBSET
87 +#ifdef CONFIG_USB_GADGET_PXA27X
88 +#define DEV_CONFIG_SUBSET
91 #ifdef CONFIG_USB_GADGET_SA1100
92 /* use non-CDC for backwards compatibility */
93 #define DEV_CONFIG_SUBSET
94 @@ -2309,6 +2309,9 @@ eth_bind (struct usb_gadget *gadget)
95 * non-CDC to be compatible with ARM Linux-2.4 "usb-eth".
98 + } else if (gadget_is_pxa27x(gadget)) {
99 + /* hardware can't write zlps */
103 gcnum = usb_gadget_controller_number (gadget);
104 @@ -2375,7 +2378,22 @@ eth_bind (struct usb_gadget *gadget)
106 /* all we really need is bulk IN/OUT */
107 usb_ep_autoconfig_reset (gadget);
108 - in_ep = usb_ep_autoconfig (gadget, &fs_source_desc);
109 +#ifdef CONFIG_USB_ETH_RNDIS
110 + in_ep = usb_ep_autoconfig (gadget, &fs_source_desc,
111 + DEV_RNDIS_CONFIG_VALUE,
112 + (int)rndis_data_intf.bInterfaceNumber,
113 + (int)rndis_data_intf.bAlternateSetting);
114 +#elif defined(DEV_CONFIG_CDC)
115 + in_ep = usb_ep_autoconfig (gadget, &fs_source_desc,
117 + (int)data_intf.bInterfaceNumber,
118 + (int)data_intf.bAlternateSetting);
119 +#elif defined(DEV_CONFIG_SUBSET)
120 + in_ep = usb_ep_autoconfig (gadget, &fs_source_desc,
122 + (int)subset_data_intf.bInterfaceNumber,
123 + (int)subset_data_intf.bAlternateSetting);
124 +#endif /* CONFIG_USB_ETH_RNDIS */
127 dev_err (&gadget->dev,
128 @@ -2385,7 +2403,22 @@ autoconf_fail:
130 in_ep->driver_data = in_ep; /* claim */
132 - out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
133 +#ifdef CONFIG_USB_ETH_RNDIS
134 + out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc,
135 + DEV_RNDIS_CONFIG_VALUE,
136 + (int)rndis_data_intf.bInterfaceNumber,
137 + (int)rndis_data_intf.bAlternateSetting);
138 +#elif defined(DEV_CONFIG_CDC)
139 + out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc,
141 + (int)data_intf.bInterfaceNumber,
142 + (int)data_intf.bAlternateSetting);
143 +#elif defined(DEV_CONFIG_SUBSET)
144 + out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc,
146 + (int)subset_data_intf.bInterfaceNumber,
147 + (int)subset_data_intf.bAlternateSetting);
148 +#endif /* CONFIG_USB_ETH_RNDIS */
151 out_ep->driver_data = out_ep; /* claim */
152 @@ -2395,7 +2428,17 @@ autoconf_fail:
153 * Since some hosts expect one, try to allocate one anyway.
156 - status_ep = usb_ep_autoconfig (gadget, &fs_status_desc);
157 +#ifdef CONFIG_USB_ETH_RNDIS
158 + status_ep = usb_ep_autoconfig (gadget, &fs_status_desc,
159 + DEV_RNDIS_CONFIG_VALUE,
160 + (int)rndis_control_intf.bInterfaceNumber,
161 + (int)rndis_control_intf.bAlternateSetting);
162 +#elif defined(DEV_CONFIG_CDC)
163 + status_ep = usb_ep_autoconfig (gadget, &fs_status_desc,
165 + (int)control_intf.bInterfaceNumber,
166 + (int)control_intf.bAlternateSetting);
167 +#endif /* CONFIG_USB_ETH_RNDIS */
169 status_ep->driver_data = status_ep; /* claim */
171 @@ -2403,13 +2446,14 @@ autoconf_fail:
172 "can't run RNDIS on %s\n",
176 #ifdef DEV_CONFIG_CDC
177 /* pxa25x only does CDC subset; often used with RNDIS */
180 control_intf.bNumEndpoints = 0;
181 /* FIXME remove endpoint from descriptor list */
188 diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
189 index c6b6479..6af5fdd 100644
190 --- a/drivers/usb/gadget/file_storage.c
191 +++ b/drivers/usb/gadget/file_storage.c
192 @@ -3920,20 +3920,20 @@ static int __init fsg_bind(struct usb_gadget *gadget)
194 /* Find all the endpoints we will use */
195 usb_ep_autoconfig_reset(gadget);
196 - ep = usb_ep_autoconfig(gadget, &fs_bulk_in_desc);
197 + ep = usb_ep_autoconfig(gadget, &fs_bulk_in_desc, 0, 0, 0);
200 ep->driver_data = fsg; // claim the endpoint
203 - ep = usb_ep_autoconfig(gadget, &fs_bulk_out_desc);
204 + ep = usb_ep_autoconfig(gadget, &fs_bulk_out_desc, 0, 0, 0);
207 ep->driver_data = fsg; // claim the endpoint
210 if (transport_is_cbi()) {
211 - ep = usb_ep_autoconfig(gadget, &fs_intr_in_desc);
212 + ep = usb_ep_autoconfig(gadget, &fs_intr_in_desc, 0, 0, 0);
215 ep->driver_data = fsg; // claim the endpoint
216 diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
217 index 2e3d662..f3b3291 100644
218 --- a/drivers/usb/gadget/gadget_chips.h
219 +++ b/drivers/usb/gadget/gadget_chips.h
220 @@ -177,5 +177,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
222 else if (gadget_is_husb2dev(gadget))
224 + else if (gadget_is_pxa27x(gadget))
228 diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
229 index d08a8d0..d51feb2 100644
230 --- a/drivers/usb/gadget/gmidi.c
231 +++ b/drivers/usb/gadget/gmidi.c
232 @@ -1204,7 +1204,7 @@ static int __devinit gmidi_bind(struct usb_gadget *gadget)
233 * but there may also be important quirks to address.
235 usb_ep_autoconfig_reset(gadget);
236 - in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc);
237 + in_ep = usb_ep_autoconfig(gadget, &bulk_in_desc, 0, 0, 0);
240 printk(KERN_ERR "%s: can't autoconfigure on %s\n",
241 @@ -1214,7 +1214,7 @@ autoconf_fail:
242 EP_IN_NAME = in_ep->name;
243 in_ep->driver_data = in_ep; /* claim */
245 - out_ep = usb_ep_autoconfig(gadget, &bulk_out_desc);
246 + out_ep = usb_ep_autoconfig(gadget, &bulk_out_desc, 0, 0, 0);
250 diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
252 index 0000000..d89ecc5
254 +++ b/drivers/usb/gadget/pxa27x_udc.c
257 + * linux/drivers/usb/gadget/pxa27x_udc.c
258 + * Intel PXA2xx and IXP4xx on-chip full speed USB device controllers
260 + * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
261 + * Copyright (C) 2003 Robert Schwebel, Pengutronix
262 + * Copyright (C) 2003 Benedikt Spranger, Pengutronix
263 + * Copyright (C) 2003 David Brownell
264 + * Copyright (C) 2003 Joshua Wise
265 + * Copyright (C) 2004 Intel Corporation
266 + * Copyright (C) 2007 Rodolfo Giometti <giometti@linux.it>
268 + * This program is free software; you can redistribute it and/or modify
269 + * it under the terms of the GNU General Public License as published by
270 + * the Free Software Foundation; either version 2 of the License, or
271 + * (at your option) any later version.
273 + * This program is distributed in the hope that it will be useful,
274 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
275 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
276 + * GNU General Public License for more details.
278 + * You should have received a copy of the GNU General Public License
279 + * along with this program; if not, write to the Free Software
280 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
285 +/* #define VERBOSE DBG_VERBOSE */
287 +#include <linux/module.h>
288 +#include <linux/kernel.h>
289 +#include <linux/ioport.h>
290 +#include <linux/types.h>
291 +#include <linux/version.h>
292 +#include <linux/errno.h>
293 +#include <linux/delay.h>
294 +#include <linux/sched.h>
295 +#include <linux/slab.h>
296 +#include <linux/init.h>
297 +#include <linux/timer.h>
298 +#include <linux/list.h>
299 +#include <linux/interrupt.h>
300 +#include <linux/proc_fs.h>
301 +#include <linux/mm.h>
302 +#include <linux/device.h>
303 +#include <linux/dma-mapping.h>
304 +#include <linux/platform_device.h>
306 +#include <asm/byteorder.h>
307 +#include <asm/dma.h>
309 +#include <asm/irq.h>
310 +#include <asm/system.h>
311 +#include <asm/mach-types.h>
312 +#include <asm/unaligned.h>
313 +#include <asm/hardware.h>
314 +#include <asm/arch/pxa-regs.h>
316 +#include <linux/usb/ch9.h>
317 +#include <linux/usb_gadget.h>
319 +#include <asm/arch/udc.h>
323 + * This driver handles the USB Device Controller (UDC) in Intel's PXA 27x
324 + * series processors.
325 + * Such controller drivers work with a gadget driver. The gadget driver
326 + * returns descriptors, implements configuration and data protocols used
327 + * by the host to interact with this device, and allocates endpoints to
328 + * the different protocol interfaces. The controller driver virtualizes
329 + * usb hardware so that the gadget drivers will be more portable.
331 + * This UDC hardware wants to implement a bit too much USB protocol, so
332 + * it constrains the sorts of USB configuration change events that work.
333 + * The errata for these chips are misleading; some "fixed" bugs from
334 + * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
337 +#define DRIVER_VERSION "08-Feb-2007"
338 +#define DRIVER_DESC "PXA 27x USB Device Controller driver"
341 +static const char driver_name [] = "pxa27x_udc";
343 +static const char ep0name [] = "ep0";
347 +#undef DISABLE_TEST_MODE
349 +#ifdef CONFIG_PROC_FS
350 +#define UDC_PROC_FILE
353 +#include "pxa27x_udc.h"
355 +#ifdef CONFIG_EMBEDDED
356 +/* few strings, and little code to use them */
358 +#undef UDC_PROC_FILE
362 +static int use_dma = 1;
363 +module_param(use_dma, bool, 0);
364 +MODULE_PARM_DESC (use_dma, "true to use dma");
366 +static void dma_nodesc_handler (int dmach, void *_ep);
367 +static void kick_dma(struct pxa27x_ep *ep, struct pxa27x_request *req);
369 +#define DMASTR " (dma support)"
371 +#else /* !USE_DMA */
372 +#define DMASTR " (pio only)"
375 +#ifdef CONFIG_USB_PXA27X_SMALL
376 +#define SIZE_STR " (small)"
381 +#ifdef DISABLE_TEST_MODE
382 +/* (mode == 0) == no undocumented chip tweaks
383 + * (mode & 1) == double buffer bulk IN
384 + * (mode & 2) == double buffer bulk OUT
385 + * ... so mode = 3 (or 7, 15, etc) does it for both
387 +static ushort fifo_mode = 0;
388 +module_param(fifo_mode, ushort, 0);
389 +MODULE_PARM_DESC (fifo_mode, "pxa27x udc fifo mode");
392 +#define UDCISR0_IR0 0x3
393 +#define UDCISR_INT_MASK (UDC_INT_FIFOERROR | UDC_INT_PACKETCMP)
394 +#define UDCICR_INT_MASK UDCISR_INT_MASK
396 +#define UDCCSR_MASK (UDCCSR_FST | UDCCSR_DME)
397 +/* ---------------------------------------------------------------------------
398 + * endpoint related parts of the api to the usb controller hardware,
399 + * used by gadget driver; and the inner talker-to-hardware core.
400 + * ---------------------------------------------------------------------------
403 +static void pxa27x_ep_fifo_flush (struct usb_ep *ep);
404 +static void nuke (struct pxa27x_ep *, int status);
406 +static void pio_irq_enable(int ep_num)
409 + UDCICR0 |= 3 << (ep_num * 2);
412 + UDCICR1 |= 3 << (ep_num * 2);
416 +static void pio_irq_disable(int ep_num)
420 + UDCICR0 &= ~(3 << (ep_num * 2));
423 + UDCICR1 &= ~(3 << (ep_num * 2));
427 +/* The UDCCR reg contains mask and interrupt status bits,
428 + * so using '|=' isn't safe as it may ack an interrupt.
430 +#define UDCCR_MASK_BITS (UDCCR_OEN | UDCCR_UDE)
432 +static inline void udc_set_mask_UDCCR(int mask)
434 + UDCCR = (UDCCR & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS);
437 +static inline void udc_clear_mask_UDCCR(int mask)
439 + UDCCR = (UDCCR & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS);
442 +static inline void udc_ack_int_UDCCR(int mask)
444 + /* udccr contains the bits we dont want to change */
445 + __u32 udccr = UDCCR & UDCCR_MASK_BITS;
447 + UDCCR = udccr | (mask & ~UDCCR_MASK_BITS);
451 + * endpoint enable/disable
453 + * we need to verify the descriptors used to enable endpoints. since pxa27x
454 + * endpoint configurations are fixed, and are pretty much always enabled,
455 + * there's not a lot to manage here.
457 + * because pxa27x can't selectively initialize bulk (or interrupt) endpoints,
458 + * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
459 + * for a single interface (with only the default altsetting) and for gadget
460 + * drivers that don't halt endpoints (not reset by set_interface). that also
461 + * means that if you use ISO, you must violate the USB spec rule that all
462 + * iso endpoints must be in non-default altsettings.
464 +static int pxa27x_ep_enable (struct usb_ep *_ep,
465 + const struct usb_endpoint_descriptor *desc)
467 + struct pxa27x_ep *ep;
468 + struct pxa27x_udc *dev;
470 + ep = container_of (_ep, struct pxa27x_ep, ep);
471 + if (!_ep || !desc || _ep->name == ep0name
472 + || desc->bDescriptorType != USB_DT_ENDPOINT
473 + || ep->fifo_size < le16_to_cpu(desc->wMaxPacketSize)) {
474 + DMSG("%s, bad ep or descriptor\n", __FUNCTION__);
478 + /* xfer types must match, except that interrupt ~= bulk */
479 + if( ep->ep_type != USB_ENDPOINT_XFER_BULK
480 + && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
481 + DMSG("%s, %s type mismatch\n", __FUNCTION__, _ep->name);
485 + /* hardware _could_ do smaller, but driver doesn't */
486 + if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
487 + && le16_to_cpu (desc->wMaxPacketSize)
489 + || !desc->wMaxPacketSize) {
490 + DMSG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name);
495 + if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
496 + DMSG("%s, bogus device state\n", __FUNCTION__);
503 + ep->pio_irqs = ep->dma_irqs = 0;
504 + ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize);
506 + /* flush fifo (mostly for OUT buffers) */
507 + pxa27x_ep_fifo_flush (_ep);
509 + /* ... reset halt state too, if we could ... */
512 + /* for (some) bulk and ISO endpoints, try to get a DMA channel and
513 + * bind it to the endpoint. otherwise use PIO.
515 + DMSG("%s: called attributes=%d\n", __FUNCTION__, ep->ep_type);
516 + switch (ep->ep_type) {
517 + case USB_ENDPOINT_XFER_ISOC:
518 + if (le16_to_cpu(desc->wMaxPacketSize) % 32)
521 + case USB_ENDPOINT_XFER_BULK:
522 + if (!use_dma || !ep->reg_drcmr)
524 + ep->dma = pxa_request_dma ((char *)_ep->name,
525 + (le16_to_cpu (desc->wMaxPacketSize) > 64)
526 + ? DMA_PRIO_MEDIUM /* some iso */
528 + dma_nodesc_handler, ep);
529 + if (ep->dma >= 0) {
530 + *ep->reg_drcmr = DRCMR_MAPVLD | ep->dma;
531 + DMSG("%s using dma%d\n", _ep->name, ep->dma);
537 + DBG(DBG_VERBOSE, "enabled %s\n", _ep->name);
541 +static int pxa27x_ep_disable (struct usb_ep *_ep)
543 + struct pxa27x_ep *ep;
545 + ep = container_of (_ep, struct pxa27x_ep, ep);
546 + if (!_ep || !ep->desc) {
547 + DMSG("%s, %s not enabled\n", __FUNCTION__,
548 + _ep ? ep->ep.name : NULL);
551 + nuke (ep, -ESHUTDOWN);
554 + if (ep->dma >= 0) {
555 + *ep->reg_drcmr = 0;
556 + pxa_free_dma (ep->dma);
561 + /* flush fifo (mostly for IN buffers) */
562 + pxa27x_ep_fifo_flush (_ep);
567 + DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
571 +/*-------------------------------------------------------------------------*/
573 +/* for the pxa27x, these can just wrap kmalloc/kfree. gadget drivers
574 + * must still pass correctly initialized endpoints, since other controller
575 + * drivers may care about how it's currently set up (dma issues etc).
579 + * pxa27x_ep_alloc_request - allocate a request data structure
581 +static struct usb_request *
582 +pxa27x_ep_alloc_request (struct usb_ep *_ep, unsigned int gfp_flags)
584 + struct pxa27x_request *req;
586 + req = kmalloc (sizeof *req, gfp_flags);
590 + memset (req, 0, sizeof *req);
591 + INIT_LIST_HEAD (&req->queue);
597 + * pxa27x_ep_free_request - deallocate a request data structure
600 +pxa27x_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
602 + struct pxa27x_request *req;
604 + req = container_of(_req, struct pxa27x_request, req);
605 + WARN_ON (!list_empty (&req->queue));
610 +/* PXA cache needs flushing with DMA I/O (it's dma-incoherent), but there's
611 + * no device-affinity and the heap works perfectly well for i/o buffers.
612 + * It wastes much less memory than dma_alloc_coherent() would, and even
613 + * prevents cacheline (32 bytes wide) sharing problems.
616 +pxa27x_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
617 + dma_addr_t *dma, unsigned int gfp_flags)
621 + retval = kmalloc (bytes, gfp_flags & ~(__GFP_DMA|__GFP_HIGHMEM));
623 + *dma = virt_to_bus (retval);
628 +pxa27x_ep_free_buffer(struct usb_ep *_ep, void *buf, dma_addr_t dma,
634 +/*-------------------------------------------------------------------------*/
637 + * done - retire a request; caller blocked irqs
639 +static void done(struct pxa27x_ep *ep, struct pxa27x_request *req, int status)
641 + list_del_init(&req->queue);
642 + if (likely (req->req.status == -EINPROGRESS))
643 + req->req.status = status;
645 + status = req->req.status;
647 + if (status && status != -ESHUTDOWN)
648 + DBG(DBG_VERBOSE, "complete %s req %p stat %d len %u/%u\n",
649 + ep->ep.name, &req->req, status,
650 + req->req.actual, req->req.length);
652 + /* don't modify queue heads during completion callback */
653 + req->req.complete(&ep->ep, &req->req);
657 +static inline void ep0_idle (struct pxa27x_udc *dev)
659 + dev->ep0state = EP0_IDLE;
664 +write_packet(volatile u32 *uddr, struct pxa27x_request *req, unsigned max)
667 + int length, count, remain;
669 + buf = (u32*)(req->req.buf + req->req.actual);
672 + /* how big will this packet be? */
673 + length = min(req->req.length - req->req.actual, max);
674 + req->req.actual += length;
676 + remain = length & 0x3;
677 + count = length & ~(0x3);
679 + while (likely(count)) {
685 + volatile u8* reg=(u8*)uddr;
686 + char *rd =(u8*)buf;
697 + * write to an IN endpoint fifo, as many packets as possible.
698 + * irqs will use this to write the rest later.
699 + * caller guarantees at least one packet buffer is ready (or a zlp).
702 +write_fifo (struct pxa27x_ep *ep, struct pxa27x_request *req)
706 + max = le16_to_cpu(ep->desc->wMaxPacketSize);
709 + int is_last, is_short;
711 + count = write_packet(ep->reg_udcdr, req, max);
713 + /* last packet is usually short (or a zlp) */
714 + if (unlikely (count != max))
715 + is_last = is_short = 1;
717 + if (likely(req->req.length != req->req.actual)
722 + /* interrupt/iso maxpacket may not fill the fifo */
723 + is_short = unlikely (max < ep->fifo_size);
726 + DMSG("wrote %s count:%d bytes%s%s %d left %p\n",
727 + ep->ep.name, count,
728 + is_last ? "/L" : "", is_short ? "/S" : "",
729 + req->req.length - req->req.actual, &req->req);
731 + /* let loose that packet. maybe try writing another one,
732 + * double buffering might work. TSP, TPC, and TFS
733 + * bit values are the same for all normal IN endpoints.
735 + *ep->reg_udccsr = UDCCSR_PC;
737 + *ep->reg_udccsr = UDCCSR_SP;
739 + /* requests complete when all IN data is in the FIFO */
742 + if (list_empty(&ep->queue) || unlikely(ep->dma >= 0)) {
743 + pio_irq_disable (ep->ep_num);
745 + /* unaligned data and zlps couldn't use dma */
746 + if (unlikely(!list_empty(&ep->queue))) {
747 + req = list_entry(ep->queue.next,
748 + struct pxa27x_request, queue);
757 + // TODO experiment: how robust can fifo mode tweaking be?
758 + // double buffering is off in the default fifo mode, which
759 + // prevents TFS from being set here.
761 + } while (*ep->reg_udccsr & UDCCSR_FS);
765 +/* caller asserts req->pending (ep0 irq status nyet cleared); starts
766 + * ep0 data stage. these chips want very simple state transitions.
769 +void ep0start(struct pxa27x_udc *dev, u32 flags, const char *tag)
771 + UDCCSR0 = flags|UDCCSR0_SA|UDCCSR0_OPC;
772 + UDCISR0 = UDCICR_INT(0, UDC_INT_FIFOERROR | UDC_INT_PACKETCMP);
773 + dev->req_pending = 0;
774 + DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
775 + __FUNCTION__, tag, UDCCSR0, flags);
779 +write_ep0_fifo (struct pxa27x_ep *ep, struct pxa27x_request *req)
784 + count = write_packet(&UDCDR0, req, EP0_FIFO_SIZE);
785 + ep->dev->stats.write.bytes += count;
787 + /* last packet "must be" short (or a zlp) */
788 + is_short = (count != EP0_FIFO_SIZE);
790 + DBG(DBG_VERY_NOISY, "ep0in %d bytes %d left %p\n", count,
791 + req->req.length - req->req.actual, &req->req);
793 + if (unlikely (is_short)) {
794 + if (ep->dev->req_pending)
795 + ep0start(ep->dev, UDCCSR0_IPR, "short IN");
797 + UDCCSR0 = UDCCSR0_IPR;
799 + count = req->req.length;
803 + /* This seems to get rid of lost status irqs in some cases:
804 + * host responds quickly, or next request involves config
805 + * change automagic, or should have been hidden, or ...
807 + * FIXME get rid of all udelays possible...
809 + if (count >= EP0_FIFO_SIZE) {
812 + if ((UDCCSR0 & UDCCSR0_OPC) != 0) {
813 + /* clear OPC, generate ack */
814 + UDCCSR0 = UDCCSR0_OPC;
822 + } else if (ep->dev->req_pending)
823 + ep0start(ep->dev, 0, "IN");
829 + * read_fifo - unload packet(s) from the fifo we use for usb OUT
830 + * transfers and put them into the request. caller should have made
831 + * sure there's at least one packet ready.
833 + * returns true if the request completed because of short packet or the
834 + * request buffer having filled (and maybe overran till end-of-packet).
837 +read_fifo (struct pxa27x_ep *ep, struct pxa27x_request *req)
841 + int bufferspace, count, is_short;
843 + /* make sure there's a packet in the FIFO.*/
844 + if (unlikely ((*ep->reg_udccsr & UDCCSR_PC) == 0))
846 + buf =(u32*) (req->req.buf + req->req.actual);
848 + bufferspace = req->req.length - req->req.actual;
850 + /* read all bytes from this packet */
851 + if (likely (*ep->reg_udccsr & UDCCSR_BNE)) {
852 + count = 0x3ff & *ep->reg_udcbcr;
853 + req->req.actual += min (count, bufferspace);
857 + is_short = (count < ep->ep.maxpacket);
858 + DMSG("read %s udccsr:%02x, count:%d bytes%s req %p %d/%d\n",
859 + ep->ep.name, *ep->reg_udccsr, count,
860 + is_short ? "/S" : "",
861 + &req->req, req->req.actual, req->req.length);
863 +// dump_regs(ep->ep_num );
864 + count = min(count, bufferspace);
865 + while (likely (count > 0)) {
866 + *buf++ = *ep->reg_udcdr;
869 + DMSG("Buf:0x%p\n", req->req.buf);
871 + *ep->reg_udccsr = UDCCSR_PC;
872 + /* RPC/RSP/RNE could now reflect the other packet buffer */
875 + if (is_short || req->req.actual == req->req.length) {
877 + if (list_empty(&ep->queue))
878 + pio_irq_disable (ep->ep_num);
882 + /* finished that packet. the next one may be waiting... */
888 + * special ep0 version of the above. no UBCR0 or double buffering; status
889 + * handshaking is magic. most device protocols don't need control-OUT.
890 + * CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
891 + * protocols do use them.
894 +read_ep0_fifo (struct pxa27x_ep *ep, struct pxa27x_request *req)
897 + unsigned bufferspace;
899 + buf = (u32*) (req->req.buf + req->req.actual);
900 + bufferspace = req->req.length - req->req.actual;
902 + while (UDCCSR0 & UDCCSR0_RNE) {
905 + if (unlikely (bufferspace == 0)) {
906 + /* this happens when the driver's buffer
907 + * is smaller than what the host sent.
908 + * discard the extra data.
910 + if (req->req.status != -EOVERFLOW)
911 + DMSG("%s overflow\n", ep->ep.name);
912 + req->req.status = -EOVERFLOW;
915 + req->req.actual += 4;
920 + UDCCSR0 = UDCCSR0_OPC ;
923 + if (req->req.actual >= req->req.length)
926 + /* finished that packet. the next one may be waiting... */
932 +#define MAX_IN_DMA ((DCMD_LENGTH + 1) - BULK_FIFO_SIZE)
933 +static void kick_dma(struct pxa27x_ep *ep, struct pxa27x_request *req)
936 + u32 len = req->req.length;
937 + u32 buf = req->req.dma;
938 + u32 fifo = io_v2p ((u32)ep->reg_udcdr);
940 + buf += req->req.actual;
941 + len -= req->req.actual;
944 + DMSG("%s: req:0x%p length:%d, actual:%d dma:%d\n",
945 + __FUNCTION__, &req->req, req->req.length,
946 + req->req.actual,ep->dma);
948 + /* no-descriptor mode can be simple for bulk-in, iso-in, iso-out */
949 + DCSR(ep->dma) = DCSR_NODESC;
951 + DALGN |= 1 << ep->dma;
953 + DALGN &= ~(1 << ep->dma);
956 + DSADR(ep->dma) = buf;
957 + DTADR(ep->dma) = fifo;
958 + if (len > MAX_IN_DMA) {
961 + } else if (len >= ep->ep.maxpacket) {
962 + if ((ep->dma_con = (len % ep->ep.maxpacket) != 0))
963 + len = ep->ep.maxpacket;
965 + dcmd = len | DCMD_BURST32 | DCMD_WIDTH4 | DCMD_ENDIRQEN
966 + | DCMD_FLOWTRG | DCMD_INCSRCADDR;
968 + DSADR(ep->dma) = fifo;
969 + DTADR(ep->dma) = buf;
970 + dcmd = len | DCMD_BURST32 | DCMD_WIDTH4 | DCMD_ENDIRQEN
971 + | DCMD_FLOWSRC | DCMD_INCTRGADDR;
973 + *ep->reg_udccsr = UDCCSR_DME;
974 + DCMD(ep->dma) = dcmd;
975 + DCSR(ep->dma) = DCSR_NODESC | DCSR_EORIRQEN \
976 + | ((ep->dir_in) ? DCSR_STOPIRQEN : 0);
977 + *ep->reg_drcmr = ep->dma | DRCMR_MAPVLD;
978 + DCSR(ep->dma) |= DCSR_RUN;
981 +static void cancel_dma(struct pxa27x_ep *ep)
983 + struct pxa27x_request *req;
986 + if (DCSR(ep->dma) == 0 || list_empty(&ep->queue))
989 + DMSG("hehe dma:%d,dcsr:0x%x\n", ep->dma, DCSR(ep->dma));
991 + while ((DCSR(ep->dma) & DCSR_STOPSTATE) == 0)
994 + req = list_entry(ep->queue.next, struct pxa27x_request, queue);
995 + tmp = DCMD(ep->dma) & DCMD_LENGTH;
996 + req->req.actual = req->req.length - tmp;
998 + /* the last tx packet may be incomplete, so flush the fifo.
999 + * FIXME correct req.actual if we can
1001 + *ep->reg_udccsr = UDCCSR_FEF;
1004 +static void dma_nodesc_handler(int dmach, void *_ep, struct pt_regs *r)
1006 + struct pxa27x_ep *ep = _ep;
1007 + struct pxa27x_request *req, *req_next;
1008 + u32 dcsr, tmp, completed;
1010 + local_irq_disable();
1012 + req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1014 + DMSG("%s, buf:0x%p\n",__FUNCTION__, req->req.buf);
1017 + ep->dev->stats.irqs++;
1018 + HEX_DISPLAY(ep->dev->stats.irqs);
1022 + dcsr = DCSR(dmach);
1023 + DCSR(ep->dma) &= ~DCSR_RUN;
1025 + if (dcsr & DCSR_BUSERR) {
1026 + DCSR(dmach) = DCSR_BUSERR;
1027 + printk(KERN_ERR " Buss Error\n");
1028 + req->req.status = -EIO;
1030 + } else if (dcsr & DCSR_ENDINTR) {
1031 + DCSR(dmach) = DCSR_ENDINTR;
1033 + tmp = req->req.length - req->req.actual;
1034 + /* Last packet is a short one*/
1035 + if ( tmp < ep->ep.maxpacket) {
1038 + *ep->reg_udccsr = UDCCSR_SP | \
1039 + (*ep->reg_udccsr & UDCCSR_MASK);
1040 + /*Wait for packet out */
1041 + while( (count++ < 10000) && \
1042 + !(*ep->reg_udccsr & UDCCSR_FS));
1043 + if (count >= 10000)
1044 + DMSG("Failed to send packet\n");
1046 + DMSG("%s: short packet sent len:%d,"
1047 + "length:%d,actual:%d\n", __FUNCTION__,
1048 + tmp, req->req.length, req->req.actual);
1049 + req->req.actual = req->req.length;
1051 + /* There are still packets to transfer */
1052 + } else if ( ep->dma_con) {
1053 + DMSG("%s: more packets,length:%d,actual:%d\n",
1054 + __FUNCTION__,req->req.length,
1056 + req->req.actual += ep->ep.maxpacket;
1059 + DMSG("%s: no more packets,length:%d,"
1060 + "actual:%d\n", __FUNCTION__,
1061 + req->req.length, req->req.actual);
1062 + req->req.actual = req->req.length;
1066 + req->req.actual = req->req.length;
1069 + } else if (dcsr & DCSR_EORINTR) { //Only happened in OUT DMA
1070 + int remain,udccsr ;
1072 + DCSR(dmach) = DCSR_EORINTR;
1073 + remain = DCMD(dmach) & DCMD_LENGTH;
1074 + req->req.actual = req->req.length - remain;
1076 + udccsr = *ep->reg_udccsr;
1077 + if (udccsr & UDCCSR_SP) {
1078 + *ep->reg_udccsr = UDCCSR_PC | (udccsr & UDCCSR_MASK);
1081 + DMSG("%s: length:%d actual:%d\n",
1082 + __FUNCTION__, req->req.length, req->req.actual);
1084 + DMSG("%s: Others dma:%d DCSR:0x%x DCMD:0x%x\n",
1085 + __FUNCTION__, dmach, DCSR(dmach), DCMD(dmach));
1087 + if (likely(completed)) {
1088 + if (req->queue.next != &ep->queue) {
1089 + req_next = list_entry(req->queue.next,
1090 + struct pxa27x_request, queue);
1091 + kick_dma(ep, req_next);
1095 + kick_dma(ep, req);
1098 + local_irq_enable();
1102 +/*-------------------------------------------------------------------------*/
1105 +pxa27x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned int gfp_flags)
1107 + struct pxa27x_ep *ep;
1108 + struct pxa27x_request *req;
1109 + struct pxa27x_udc *dev;
1110 + unsigned long flags;
1112 + req = container_of(_req, struct pxa27x_request, req);
1113 + if (unlikely (!_req || !_req->complete || !_req->buf||
1114 + !list_empty(&req->queue))) {
1115 + DMSG("%s, bad params\n", __FUNCTION__);
1119 + ep = container_of(_ep, struct pxa27x_ep, ep);
1120 + if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
1121 + DMSG("%s, bad ep\n", __FUNCTION__);
1125 + DMSG("%s, ep point %d is queue\n", __FUNCTION__, ep->ep_num);
1128 + if (unlikely (!dev->driver
1129 + || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1130 + DMSG("%s, bogus device state\n", __FUNCTION__);
1131 + return -ESHUTDOWN;
1134 + /* iso is always one packet per request, that's the only way
1135 + * we can report per-packet status. that also helps with dma.
1137 + if (unlikely (ep->ep_type == USB_ENDPOINT_XFER_ISOC
1138 + && req->req.length > le16_to_cpu
1139 + (ep->desc->wMaxPacketSize)))
1143 + /* FIXME: caller may already have done the dma mapping */
1144 + if (ep->dma >= 0) {
1145 + _req->dma = dma_map_single(dev->dev, _req->buf, _req->length,
1146 + (ep->dir_in) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
1150 + DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n",
1151 + _ep->name, _req, _req->length, _req->buf);
1153 + local_irq_save(flags);
1155 + _req->status = -EINPROGRESS;
1158 + /* kickstart this i/o queue? */
1159 + if (list_empty(&ep->queue) && !ep->stopped) {
1160 + if (ep->desc == 0 /* ep0 */) {
1161 + unsigned length = _req->length;
1163 + switch (dev->ep0state) {
1164 + case EP0_IN_DATA_PHASE:
1165 + dev->stats.write.ops++;
1166 + if (write_ep0_fifo(ep, req))
1170 + case EP0_OUT_DATA_PHASE:
1171 + dev->stats.read.ops++;
1172 + if (dev->req_pending)
1173 + ep0start(dev, UDCCSR0_IPR, "OUT");
1174 + if (length == 0 || ((UDCCSR0 & UDCCSR0_RNE) != 0
1175 + && read_ep0_fifo(ep, req))) {
1181 + case EP0_NO_ACTION:
1186 + DMSG("ep0 i/o, odd state %d\n", dev->ep0state);
1187 + local_irq_restore (flags);
1191 + /* either start dma or prime pio pump */
1192 + } else if (ep->dma >= 0) {
1193 + kick_dma(ep, req);
1195 + /* can the FIFO can satisfy the request immediately? */
1196 + } else if (ep->dir_in
1197 + && (*ep->reg_udccsr & UDCCSR_FS) != 0
1198 + && write_fifo(ep, req)) {
1200 + } else if ((*ep->reg_udccsr & UDCCSR_FS) != 0
1201 + && read_fifo(ep, req)) {
1204 + DMSG("req:%p,ep->desc:%p,ep->dma:%d\n", req, ep->desc, ep->dma);
1205 + if (likely (req && ep->desc) && ep->dma < 0)
1206 + pio_irq_enable(ep->ep_num);
1209 + /* pio or dma irq handler advances the queue. */
1210 + if (likely (req != 0))
1211 + list_add_tail(&req->queue, &ep->queue);
1212 + local_irq_restore(flags);
1219 + * nuke - dequeue ALL requests
1221 +static void nuke(struct pxa27x_ep *ep, int status)
1223 + struct pxa27x_request *req;
1225 + /* called with irqs blocked */
1227 + if (ep->dma >= 0 && !ep->stopped)
1230 + while (!list_empty(&ep->queue)) {
1231 + req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1232 + done(ep, req, status);
1235 + pio_irq_disable (ep->ep_num);
1239 +/* dequeue JUST ONE request */
1240 +static int pxa27x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1242 + struct pxa27x_ep *ep;
1243 + struct pxa27x_request *req;
1244 + unsigned long flags;
1246 + ep = container_of(_ep, struct pxa27x_ep, ep);
1247 + if (!_ep || ep->ep.name == ep0name)
1250 + local_irq_save(flags);
1252 + /* make sure it's actually queued on this endpoint */
1253 + list_for_each_entry (req, &ep->queue, queue) {
1254 + if (&req->req == _req)
1257 + if (&req->req != _req) {
1258 + local_irq_restore(flags);
1263 + if (ep->dma >= 0 && ep->queue.next == &req->queue && !ep->stopped) {
1265 + done(ep, req, -ECONNRESET);
1267 + if (!list_empty(&ep->queue)) {
1268 + req = list_entry(ep->queue.next,
1269 + struct pxa27x_request, queue);
1270 + kick_dma(ep, req);
1274 + done(ep, req, -ECONNRESET);
1276 + local_irq_restore(flags);
1280 +/*-------------------------------------------------------------------------*/
1282 +static int pxa27x_ep_set_halt(struct usb_ep *_ep, int value)
1284 + struct pxa27x_ep *ep;
1285 + unsigned long flags;
1287 + DMSG("%s is called\n", __FUNCTION__);
1288 + ep = container_of(_ep, struct pxa27x_ep, ep);
1289 + if (unlikely (!_ep
1290 + || (!ep->desc && ep->ep.name != ep0name))
1291 + || ep->ep_type == USB_ENDPOINT_XFER_ISOC) {
1292 + DMSG("%s, bad ep\n", __FUNCTION__);
1296 + /* this path (reset toggle+halt) is needed to implement
1297 + * SET_INTERFACE on normal hardware. but it can't be
1298 + * done from software on the PXA UDC, and the hardware
1299 + * forgets to do it as part of SET_INTERFACE automagic.
1301 + DMSG("only host can clear %s halt\n", _ep->name);
1305 + local_irq_save(flags);
1307 + if (ep->dir_in && ((*ep->reg_udccsr & UDCCSR_FS) == 0
1308 + || !list_empty(&ep->queue))) {
1309 + local_irq_restore(flags);
1313 + /* FST bit is the same for control, bulk in, bulk out, interrupt in */
1314 + *ep->reg_udccsr = UDCCSR_FST|UDCCSR_FEF;
1316 + /* ep0 needs special care */
1318 + start_watchdog(ep->dev);
1319 + ep->dev->req_pending = 0;
1320 + ep->dev->ep0state = EP0_STALL;
1323 + /* and bulk/intr endpoints like dropping stalls too */
1326 + for (i = 0; i < 1000; i += 20) {
1327 + if (*ep->reg_udccsr & UDCCSR_SST)
1332 + local_irq_restore(flags);
1334 + DBG(DBG_VERBOSE, "%s halt\n", _ep->name);
1338 +static int pxa27x_ep_fifo_status(struct usb_ep *_ep)
1340 + struct pxa27x_ep *ep;
1342 + ep = container_of(_ep, struct pxa27x_ep, ep);
1344 + DMSG("%s, bad ep\n", __FUNCTION__);
1347 + /* pxa can't report unclaimed bytes from IN fifos */
1349 + return -EOPNOTSUPP;
1350 + if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN
1351 + || (*ep->reg_udccsr & UDCCSR_FS) == 0)
1354 + return (*ep->reg_udcbcr & 0xfff) + 1;
1357 +static void pxa27x_ep_fifo_flush(struct usb_ep *_ep)
1359 + struct pxa27x_ep *ep;
1361 + ep = container_of(_ep, struct pxa27x_ep, ep);
1362 + if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
1363 + DMSG("%s, bad ep\n", __FUNCTION__);
1367 + /* toggle and halt bits stay unchanged */
1369 + /* for OUT, just read and discard the FIFO contents. */
1370 + if (!ep->dir_in) {
1371 + while (((*ep->reg_udccsr) & UDCCSR_BNE) != 0)
1372 + (void) *ep->reg_udcdr;
1376 + /* most IN status is the same, but ISO can't stall */
1377 + *ep->reg_udccsr = UDCCSR_PC|UDCCSR_FST|UDCCSR_TRN
1378 + | (ep->ep_type == USB_ENDPOINT_XFER_ISOC)
1383 +static struct usb_ep_ops pxa27x_ep_ops = {
1384 + .enable = pxa27x_ep_enable,
1385 + .disable = pxa27x_ep_disable,
1387 + .alloc_request = pxa27x_ep_alloc_request,
1388 + .free_request = pxa27x_ep_free_request,
1390 + .alloc_buffer = pxa27x_ep_alloc_buffer,
1391 + .free_buffer = pxa27x_ep_free_buffer,
1393 + .queue = pxa27x_ep_queue,
1394 + .dequeue = pxa27x_ep_dequeue,
1396 + .set_halt = pxa27x_ep_set_halt,
1397 + .fifo_status = pxa27x_ep_fifo_status,
1398 + .fifo_flush = pxa27x_ep_fifo_flush,
1402 +/* ---------------------------------------------------------------------------
1403 + * device-scoped parts of the api to the usb controller hardware
1404 + * ---------------------------------------------------------------------------
1407 +static inline void validate_fifo_size(struct pxa27x_ep *pxa_ep, u8 bmAttributes)
1409 + switch (bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
1410 + case USB_ENDPOINT_XFER_CONTROL:
1411 + pxa_ep->fifo_size = EP0_FIFO_SIZE;
1413 + case USB_ENDPOINT_XFER_ISOC:
1414 + pxa_ep->fifo_size = ISO_FIFO_SIZE;
1416 + case USB_ENDPOINT_XFER_BULK:
1417 + pxa_ep->fifo_size = BULK_FIFO_SIZE;
1419 + case USB_ENDPOINT_XFER_INT:
1420 + pxa_ep->fifo_size = INT_FIFO_SIZE;
1427 +#define NAME_SIZE 18
1428 +struct usb_ep* pxa27x_ep_alloc(struct usb_gadget *gadget, struct usb_endpoint_descriptor *desc, int config, int interface, int alt)
1433 + struct usb_ep * ep = NULL;
1434 + struct pxa27x_ep *pxa_ep = NULL;
1435 + struct pxa27x_udc *dev = the_controller;
1437 + DMSG("pxa27x_config_ep is called\n");
1438 + DMSG(" usb endpoint descriptor is:\n"
1440 + " bDescriptorType:%x\n"
1441 + " bEndpointAddress:%x\n"
1442 + " bmAttributes:%x\n"
1443 + " wMaxPacketSize:%d\n",
1445 + desc->bDescriptorType,desc->bEndpointAddress,
1446 + desc->bmAttributes,desc->wMaxPacketSize);
1448 + for (i = 1; i < UDC_EP_NUM; i++) {
1449 + if(!dev->ep[i].assigned) {
1450 + pxa_ep = &dev->ep[i];
1451 + pxa_ep->assigned = 1;
1452 + pxa_ep->ep_num = i;
1456 + if (unlikely(i == UDC_EP_NUM)) {
1457 + printk(KERN_ERR __FILE__ ": Failed to find a spare endpoint\n");
1464 + pxa_ep->dev = dev;
1465 + pxa_ep->desc = desc;
1466 + pxa_ep->pio_irqs = pxa_ep->dma_irqs = 0;
1469 + if (!(desc->bEndpointAddress & 0xF))
1470 + desc->bEndpointAddress |= i;
1472 + if (!(desc->wMaxPacketSize)) {
1473 + validate_fifo_size(pxa_ep, desc->bmAttributes);
1474 + desc->wMaxPacketSize = pxa_ep->fifo_size;
1476 + pxa_ep->fifo_size = desc->wMaxPacketSize;
1478 + pxa_ep->dir_in = (desc->bEndpointAddress & USB_DIR_IN) ? 1 : 0;
1479 + pxa_ep->ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
1480 + pxa_ep->stopped = 1;
1481 + pxa_ep->dma_con = 0;
1482 + pxa_ep->config = config;
1483 + pxa_ep->interface = interface;
1484 + pxa_ep->aisn = alt;
1486 + pxa_ep->reg_udccsr = &UDCCSR0 + i;
1487 + pxa_ep->reg_udcbcr = &UDCBCR0 + i;
1488 + pxa_ep->reg_udcdr = &UDCDR0 + i ;
1489 + pxa_ep->reg_udccr = &UDCCRA - 1 + i;
1491 + pxa_ep->reg_drcmr = &DRCMR24 + i;
1494 + DMSG("udccsr=0x%8x, udcbcr=0x%8x, udcdr=0x%8x,"
1496 + (unsigned)pxa_ep->reg_udccsr,
1497 + (unsigned)pxa_ep->reg_udcbcr,
1498 + (unsigned)pxa_ep->reg_udcdr,
1499 + (unsigned)pxa_ep->reg_udccr);
1501 + /* Configure UDCCR */
1503 + tmp |= (pxa_ep->config << UDCCONR_CN_S) & UDCCONR_CN;
1505 + tmp |= (pxa_ep->interface << UDCCONR_IN_S) & UDCCONR_IN;
1506 + tmp |= (pxa_ep->aisn << UDCCONR_AISN_S) & UDCCONR_AISN;
1508 + tmp |= (0 << UDCCONR_IN_S) & UDCCONR_IN;
1509 + tmp |= (0 << UDCCONR_AISN_S) & UDCCONR_AISN;
1511 + tmp |= (desc->bEndpointAddress << UDCCONR_EN_S) & UDCCONR_EN;
1512 + tmp |= (pxa_ep->ep_type << UDCCONR_ET_S) & UDCCONR_ET;
1513 + tmp |= (pxa_ep->dir_in) ? UDCCONR_ED : 0;
1514 + tmp |= (min(pxa_ep->fifo_size, (unsigned)desc->wMaxPacketSize) \
1515 + << UDCCONR_MPS_S ) & UDCCONR_MPS;
1516 + tmp |= UDCCONR_DE | UDCCONR_EE;
1517 +// tmp |= UDCCONR_EE;
1519 + *pxa_ep->reg_udccr = tmp;
1522 + /* Only BULK use DMA */
1523 + if ((pxa_ep->ep_type & USB_ENDPOINT_XFERTYPE_MASK)\
1524 + == USB_ENDPOINT_XFER_BULK)
1525 + *pxa_ep->reg_udccsr = UDCCSR_DME;
1528 + DMSG("UDCCR: 0x%p is 0x%x\n", pxa_ep->reg_udccr,*pxa_ep->reg_udccr);
1531 + name = kmalloc(NAME_SIZE, GFP_KERNEL);
1533 + printk(KERN_ERR "%s: Error\n", __FUNCTION__);
1537 + switch (pxa_ep->ep_type) {
1538 + case USB_ENDPOINT_XFER_BULK:
1539 + sprintf(name, "Bulk-%s-%d", (pxa_ep->dir_in ? "in":"out"), i);
1541 + case USB_ENDPOINT_XFER_INT:
1542 + sprintf(name, "Interrupt-%s-%d", (pxa_ep->dir_in ? \
1546 + sprintf(name, "endpoint-%s-%d", (pxa_ep->dir_in ? \
1552 + ep->ops = &pxa27x_ep_ops;
1553 + ep->maxpacket = min((ushort)pxa_ep->fifo_size, desc->wMaxPacketSize);
1555 + list_add_tail (&ep->ep_list, &gadget->ep_list);
1559 +static int pxa27x_udc_get_frame(struct usb_gadget *_gadget)
1561 + return (UDCFNR & 0x3FF);
1564 +static int pxa27x_udc_wakeup(struct usb_gadget *_gadget)
1566 + /* host may not have enabled remote wakeup */
1567 + if ((UDCCR & UDCCR_DWRE) == 0)
1568 + return -EHOSTUNREACH;
1569 + udc_set_mask_UDCCR(UDCCR_UDR);
1573 +static const struct usb_gadget_ops pxa27x_udc_ops = {
1574 + .ep_alloc = pxa27x_ep_alloc,
1575 + .get_frame = pxa27x_udc_get_frame,
1576 + .wakeup = pxa27x_udc_wakeup,
1577 + // current versions must always be self-powered
1581 +/*-------------------------------------------------------------------------*/
1583 +#ifdef UDC_PROC_FILE
1585 +static const char proc_node_name [] = "driver/udc";
1588 +udc_proc_read(char *page, char **start, off_t off, int count,
1589 + int *eof, void *_dev)
1592 + struct pxa27x_udc *dev = _dev;
1594 + unsigned size = count;
1595 + unsigned long flags;
1602 + local_irq_save(flags);
1604 + /* basic device status */
1605 + t = scnprintf(next, size, DRIVER_DESC "\n"
1606 + "%s version: %s\nGadget driver: %s\n",
1607 + driver_name, DRIVER_VERSION SIZE_STR DMASTR,
1608 + dev->driver ? dev->driver->driver.name : "(none)");
1612 + /* registers for device and ep0 */
1613 + t = scnprintf(next, size,
1614 + "uicr %02X.%02X, usir %02X.%02x, ufnr %02X\n",
1615 + UDCICR1, UDCICR0, UDCISR1, UDCISR0, UDCFNR);
1620 + t = scnprintf(next, size,"udccr %02X =%s%s%s%s%s%s%s%s%s%s, con=%d,inter=%d,altinter=%d\n", tmp,
1621 + (tmp & UDCCR_OEN) ? " oen":"",
1622 + (tmp & UDCCR_AALTHNP) ? " aalthnp":"",
1623 + (tmp & UDCCR_AHNP) ? " rem" : "",
1624 + (tmp & UDCCR_BHNP) ? " rstir" : "",
1625 + (tmp & UDCCR_DWRE) ? " dwre" : "",
1626 + (tmp & UDCCR_SMAC) ? " smac" : "",
1627 + (tmp & UDCCR_EMCE) ? " emce" : "",
1628 + (tmp & UDCCR_UDR) ? " udr" : "",
1629 + (tmp & UDCCR_UDA) ? " uda" : "",
1630 + (tmp & UDCCR_UDE) ? " ude" : "",
1631 + (tmp & UDCCR_ACN) >> UDCCR_ACN_S,
1632 + (tmp & UDCCR_AIN) >> UDCCR_AIN_S,
1633 + (tmp & UDCCR_AAISN)>> UDCCR_AAISN_S );
1639 + t = scnprintf(next, size,
1640 + "udccsr0 %02X =%s%s%s%s%s%s%s\n", tmp,
1641 + (tmp & UDCCSR0_SA) ? " sa" : "",
1642 + (tmp & UDCCSR0_RNE) ? " rne" : "",
1643 + (tmp & UDCCSR0_FST) ? " fst" : "",
1644 + (tmp & UDCCSR0_SST) ? " sst" : "",
1645 + (tmp & UDCCSR0_DME) ? " dme" : "",
1646 + (tmp & UDCCSR0_IPR) ? " ipr" : "",
1647 + (tmp & UDCCSR0_OPC) ? " opc" : "");
1654 + t = scnprintf(next, size, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
1655 + dev->stats.write.bytes, dev->stats.write.ops,
1656 + dev->stats.read.bytes, dev->stats.read.ops,
1661 + /* dump endpoint queues */
1662 + for (i = 0; i < UDC_EP_NUM; i++) {
1663 + struct pxa27x_ep *ep = &dev->ep [i];
1664 + struct pxa27x_request *req;
1668 + const struct usb_endpoint_descriptor *d;
1673 + tmp = *dev->ep [i].reg_udccsr;
1674 + t = scnprintf(next, size,
1675 + "%s max %d %s udccs %02x udccr:0x%x\n",
1676 + ep->ep.name, le16_to_cpu (d->wMaxPacketSize),
1677 + (ep->dma >= 0) ? "dma" : "pio", tmp,
1678 + *dev->ep[i].reg_udccr);
1679 + /* TODO translate all five groups of udccs bits! */
1681 + } else /* ep0 should only have one transfer queued */
1682 + t = scnprintf(next, size, "ep0 max 16 pio irqs %lu\n",
1684 + if (t <= 0 || t > size)
1689 + if (list_empty(&ep->queue)) {
1690 + t = scnprintf(next, size, "\t(nothing queued)\n");
1691 + if (t <= 0 || t > size)
1697 + list_for_each_entry(req, &ep->queue, queue) {
1699 + if (ep->dma >= 0 && req->queue.prev == &ep->queue)
1700 + t = scnprintf(next, size,
1701 + "\treq %p len %d/%d "
1702 + "buf %p (dma%d dcmd %08x)\n",
1703 + &req->req, req->req.actual,
1704 + req->req.length, req->req.buf,
1705 + ep->dma, DCMD(ep->dma)
1706 + // low 13 bits == bytes-to-go
1710 + t = scnprintf(next, size,
1711 + "\treq %p len %d/%d buf %p\n",
1712 + &req->req, req->req.actual,
1713 + req->req.length, req->req.buf);
1714 + if (t <= 0 || t > size)
1722 + local_irq_restore(flags);
1724 + return count - size;
1727 +#define create_proc_files() \
1728 + create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev)
1729 +#define remove_proc_files() \
1730 + remove_proc_entry(proc_node_name, NULL)
1732 +#else /* !UDC_PROC_FILE */
1733 +#define create_proc_files() do {} while (0)
1734 +#define remove_proc_files() do {} while (0)
1736 +#endif /* UDC_PROC_FILE */
1738 +/* "function" sysfs attribute */
1740 +show_function (struct device *_dev, struct device_attribute *attr, char *buf)
1742 + struct pxa27x_udc *dev = dev_get_drvdata (_dev);
1745 + || !dev->driver->function
1746 + || strlen (dev->driver->function) > PAGE_SIZE)
1748 + return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
1750 +static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
1752 +/*-------------------------------------------------------------------------*/
1755 + * udc_disable - disable USB device controller
1757 +static void udc_disable(struct pxa27x_udc *dev)
1759 + UDCICR0 = UDCICR1 = 0x00000000;
1761 + udc_clear_mask_UDCCR(UDCCR_UDE);
1763 + /* Disable clock for USB device */
1764 + pxa_set_cken(CKEN11_USB, 0);
1767 + dev->gadget.speed = USB_SPEED_UNKNOWN;
1769 + if (dev->mach->gpio_pullup)
1770 + GPCR(dev->mach->gpio_pullup) = GPIO_bit(dev->mach->gpio_pullup);
1771 + if (dev->mach->udc_command)
1772 + dev->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
1774 + make_usb_disappear();
1779 + * udc_reinit - initialize software state
1781 +static void udc_reinit(struct pxa27x_udc *dev)
1785 + dev->ep0state = EP0_IDLE;
1787 + /* basic endpoint records init */
1788 + for (i = 0; i < UDC_EP_NUM; i++) {
1789 + struct pxa27x_ep *ep = &dev->ep[i];
1792 + ep->pio_irqs = ep->dma_irqs = 0;
1794 + dev->configuration = 0;
1795 + dev->interface = 0;
1796 + dev->alternate = 0;
1797 + /* the rest was statically initialized, and is read-only */
1800 +/* until it's enabled, this UDC should be completely invisible
1801 + * to any USB host.
1803 +static void udc_enable (struct pxa27x_udc *dev)
1805 + udc_clear_mask_UDCCR(UDCCR_UDE);
1807 + /* Enable clock for USB device */
1808 + pxa_set_cken(CKEN11_USB, 1);
1810 + UDCICR0 = UDCICR1 = 0;
1813 + dev->gadget.speed = USB_SPEED_FULL;
1814 + dev->stats.irqs = 0;
1816 + udc_set_mask_UDCCR(UDCCR_UDE);
1818 + if (UDCCR & UDCCR_EMCE)
1820 + printk(KERN_ERR ": There are error in configuration, udc disabled\n");
1823 + /* caller must be able to sleep in order to cope
1824 + * with startup transients.
1828 + /* enable suspend/resume and reset irqs */
1829 + UDCICR1 = UDCICR1_IECC | UDCICR1_IERU | UDCICR1_IESU | UDCICR1_IERS;
1831 + /* enable ep0 irqs */
1832 + UDCICR0 = UDCICR_INT(0,UDCICR_INT_MASK);
1834 + for(i=1; i < UDC_EP_NUM; i++) {
1835 + if (dev->ep[i].assigned)
1836 + pio_irq_enable(i);
1840 + if (dev->mach->gpio_pullup)
1841 + GPSR(dev->mach->gpio_pullup) = GPIO_bit(dev->mach->gpio_pullup);
1842 + if (dev->mach->udc_command)
1843 + dev->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
1850 +/* when a driver is successfully registered, it will receive
1851 + * control requests including set_configuration(), which enables
1852 + * non-control requests. then usb traffic follows until a
1853 + * disconnect is reported. then a host may connect again, or
1854 + * the driver might get unbound.
1856 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1858 + struct pxa27x_udc *dev = the_controller;
1861 + DMSG("dev=0x%x, driver=0x%x, speed=%d, "
1862 + "bind=0x%x, unbind=0x%x, disconnect=0x%x, setup=0x%x\n",
1863 + (unsigned)dev, (unsigned)driver, driver->speed,
1864 + (unsigned)driver->bind, (unsigned)driver->unbind,
1865 + (unsigned)driver->disconnect, (unsigned)driver->setup);
1867 + if (!driver || driver->speed != USB_SPEED_FULL
1869 + || !driver->unbind
1870 + || !driver->disconnect
1871 + || !driver->setup)
1878 + /* first hook up the driver ... */
1879 + dev->driver = driver;
1880 + dev->gadget.dev.driver = &driver->driver;
1882 + device_add(&dev->gadget.dev);
1883 + retval = driver->bind(&dev->gadget);
1885 + DMSG("bind to driver %s --> error %d\n",
1886 + driver->driver.name, retval);
1887 + device_del (&dev->gadget.dev);
1890 + dev->gadget.dev.driver = 0;
1893 + device_create_file(dev->dev, &dev_attr_function);
1895 + /* ... then enable host detection and ep0; and we're ready
1896 + * for set_configuration as well as eventual disconnect.
1897 + * NOTE: this shouldn't power up until later.
1899 + DMSG("registered gadget driver '%s'\n", driver->driver.name);
1904 +EXPORT_SYMBOL(usb_gadget_register_driver);
1907 +stop_activity(struct pxa27x_udc *dev, struct usb_gadget_driver *driver)
1911 + DMSG("Trace path 1\n");
1912 + /* don't disconnect drivers more than once */
1913 + if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1915 + dev->gadget.speed = USB_SPEED_UNKNOWN;
1917 + /* prevent new request submissions, kill any outstanding requests */
1918 + for (i = 0; i < UDC_EP_NUM; i++) {
1919 + struct pxa27x_ep *ep = &dev->ep[i];
1922 + nuke(ep, -ESHUTDOWN);
1924 + del_timer_sync(&dev->timer);
1926 + /* report disconnect; the driver is already quiesced */
1928 + driver->disconnect(&dev->gadget);
1930 + /* re-init driver-visible data structures */
1934 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1936 + struct pxa27x_udc *dev = the_controller;
1940 + if (!driver || driver != dev->driver)
1943 + local_irq_disable();
1945 + stop_activity(dev, driver);
1946 + local_irq_enable();
1948 + driver->unbind(&dev->gadget);
1951 + device_del (&dev->gadget.dev);
1952 + device_remove_file(dev->dev, &dev_attr_function);
1954 + DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
1958 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
1960 +#ifndef enable_disconnect_irq
1961 +#define enable_disconnect_irq() do {} while (0)
1962 +#define disable_disconnect_irq() do {} while (0)
1966 +/*-------------------------------------------------------------------------*/
1968 +static inline void clear_ep_state (struct pxa27x_udc *dev)
1972 + /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
1973 + * fifos, and pending transactions mustn't be continued in any case.
1975 + for (i = 1; i < UDC_EP_NUM; i++)
1976 + nuke(&dev->ep[i], -ECONNABORTED);
1979 +static void udc_watchdog(unsigned long _dev)
1981 + struct pxa27x_udc *dev = (void *)_dev;
1983 + local_irq_disable();
1984 + if (dev->ep0state == EP0_STALL
1985 + && (UDCCSR0 & UDCCSR0_FST) == 0
1986 + && (UDCCSR0 & UDCCSR0_SST) == 0) {
1987 + UDCCSR0 = UDCCSR0_FST|UDCCSR0_FTF;
1988 + DBG(DBG_VERBOSE, "ep0 re-stall\n");
1989 + start_watchdog(dev);
1991 + local_irq_enable();
1994 +static void handle_ep0 (struct pxa27x_udc *dev)
1996 + u32 udccsr0 = UDCCSR0;
1997 + struct pxa27x_ep *ep = &dev->ep [0];
1998 + struct pxa27x_request *req;
2000 + struct usb_ctrlrequest r;
2005 + if (list_empty(&ep->queue))
2008 + req = list_entry(ep->queue.next, struct pxa27x_request, queue);
2010 + /* clear stall status */
2011 + if (udccsr0 & UDCCSR0_SST) {
2013 + UDCCSR0 = UDCCSR0_SST;
2014 + del_timer(&dev->timer);
2018 + /* previous request unfinished? non-error iff back-to-back ... */
2019 + if ((udccsr0 & UDCCSR0_SA) != 0 && dev->ep0state != EP0_IDLE) {
2021 + del_timer(&dev->timer);
2025 + switch (dev->ep0state) {
2026 + case EP0_NO_ACTION:
2027 + printk(KERN_INFO"%s: Busy\n", __FUNCTION__);
2030 + /* late-breaking status? */
2031 + udccsr0 = UDCCSR0;
2033 + /* start control request? */
2034 + if (likely((udccsr0 & (UDCCSR0_OPC|UDCCSR0_SA|UDCCSR0_RNE))
2035 + == (UDCCSR0_OPC|UDCCSR0_SA|UDCCSR0_RNE))) {
2038 + nuke (ep, -EPROTO);
2039 + /* read SETUP packet */
2040 + for (i = 0; i < 2; i++) {
2041 + if (unlikely(!(UDCCSR0 & UDCCSR0_RNE))) {
2043 + DMSG("SETUP %d!\n", i);
2046 + u.word [i] = UDCDR0;
2048 + if (unlikely((UDCCSR0 & UDCCSR0_RNE) != 0))
2051 + le16_to_cpus (&u.r.wValue);
2052 + le16_to_cpus (&u.r.wIndex);
2053 + le16_to_cpus (&u.r.wLength);
2057 + DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n",
2058 + u.r.bRequestType, u.r.bRequest,
2059 + u.r.wValue, u.r.wIndex, u.r.wLength);
2060 + /* cope with automagic for some standard requests. */
2061 + dev->req_std = (u.r.bRequestType & USB_TYPE_MASK)
2062 + == USB_TYPE_STANDARD;
2063 + dev->req_config = 0;
2064 + dev->req_pending = 1;
2066 + switch (u.r.bRequest) {
2067 + /* hardware was supposed to hide this */
2068 + case USB_REQ_SET_CONFIGURATION:
2069 + case USB_REQ_SET_INTERFACE:
2070 + case USB_REQ_SET_ADDRESS:
2071 + printk(KERN_ERR "Should not come here\n");
2076 + if (u.r.bRequestType & USB_DIR_IN)
2077 + dev->ep0state = EP0_IN_DATA_PHASE;
2079 + dev->ep0state = EP0_OUT_DATA_PHASE;
2080 + i = dev->driver->setup(&dev->gadget, &u.r);
2083 + /* hardware automagic preventing STALL... */
2084 + if (dev->req_config) {
2085 + /* hardware sometimes neglects to tell
2086 + * tell us about config change events,
2087 + * so later ones may fail...
2089 + WARN("config change %02x fail %d?\n",
2092 + /* TODO experiment: if has_cfr,
2093 + * hardware didn't ACK; maybe we
2094 + * could actually STALL!
2097 + DBG(DBG_VERBOSE, "protocol STALL, "
2098 + "%02x err %d\n", UDCCSR0, i);
2100 + /* the watchdog timer helps deal with cases
2101 + * where udc seems to clear FST wrongly, and
2102 + * then NAKs instead of STALLing.
2104 + ep0start(dev, UDCCSR0_FST|UDCCSR0_FTF, "stall");
2105 + start_watchdog(dev);
2106 + dev->ep0state = EP0_STALL;
2109 + /* deferred i/o == no response yet */
2110 + } else if (dev->req_pending) {
2111 + if (likely(dev->ep0state == EP0_IN_DATA_PHASE
2112 + || dev->req_std || u.r.wLength))
2113 + ep0start(dev, 0, "defer");
2115 + ep0start(dev, UDCCSR0_IPR, "defer/IPR");
2118 + /* expect at least one data or status stage irq */
2122 + /* some random early IRQ:
2125 + * - OPC got set, without SA (likely status stage)
2127 + UDCCSR0 = udccsr0 & (UDCCSR0_SA|UDCCSR0_OPC);
2130 + case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR etc */
2131 + if (udccsr0 & UDCCSR0_OPC) {
2132 + UDCCSR0 = UDCCSR0_OPC|UDCCSR0_FTF;
2133 + DBG(DBG_VERBOSE, "ep0in premature status\n");
2137 + } else /* irq was IPR clearing */ {
2139 + /* this IN packet might finish the request */
2140 + (void) write_ep0_fifo(ep, req);
2141 + } /* else IN token before response was written */
2144 + case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR etc */
2145 + if (udccsr0 & UDCCSR0_OPC) {
2147 + /* this OUT packet might finish the request */
2148 + if (read_ep0_fifo(ep, req))
2150 + /* else more OUT packets expected */
2151 + } /* else OUT token before read was issued */
2152 + } else /* irq was IPR clearing */ {
2153 + DBG(DBG_VERBOSE, "ep0out premature status\n");
2160 + UDCCSR0 = UDCCSR0_FST;
2163 + UDCISR0 = UDCISR_INT(0, UDCISR_INT_MASK);
2167 +static void handle_ep(struct pxa27x_ep *ep)
2169 + struct pxa27x_request *req;
2173 + DMSG("%s is called\n", __FUNCTION__);
2176 + if (likely (!list_empty(&ep->queue))) {
2177 + req = list_entry(ep->queue.next,
2178 + struct pxa27x_request, queue);
2182 +// udccsr = *ep->reg_udccsr;
2183 + DMSG("%s: req:%p, udcisr0:0x%x udccsr %p:0x%x\n", __FUNCTION__,
2184 + req, UDCISR0, ep->reg_udccsr, *ep->reg_udccsr);
2185 + if (unlikely(ep->dir_in)) {
2186 + udccsr = (UDCCSR_SST | UDCCSR_TRN) & *ep->reg_udccsr;
2187 + if (unlikely (udccsr))
2188 + *ep->reg_udccsr = udccsr;
2190 + if (req && likely ((*ep->reg_udccsr & UDCCSR_FS) != 0))
2191 + completed = write_fifo(ep, req);
2194 + udccsr = (UDCCSR_SST | UDCCSR_TRN) & *ep->reg_udccsr;
2195 + if (unlikely(udccsr))
2196 + *ep->reg_udccsr = udccsr;
2198 + /* fifos can hold packets, ready for reading... */
2199 + if (likely(req)) {
2200 + completed = read_fifo(ep, req);
2202 + pio_irq_disable (ep->ep_num);
2203 + *ep->reg_udccsr = UDCCSR_FEF;
2204 + DMSG("%s: no req for out data\n",
2209 + } while (completed);
2212 +static void pxa27x_change_configuration (struct pxa27x_udc *dev)
2214 + struct usb_ctrlrequest req ;
2216 + req.bRequestType = 0;
2217 + req.bRequest = USB_REQ_SET_CONFIGURATION;
2218 + req.wValue = dev->configuration;
2222 + dev->ep0state = EP0_NO_ACTION;
2223 + dev->driver->setup(&dev->gadget, &req);
2227 +static void pxa27x_change_interface (struct pxa27x_udc *dev)
2229 + struct usb_ctrlrequest req;
2231 + req.bRequestType = USB_RECIP_INTERFACE;
2232 + req.bRequest = USB_REQ_SET_INTERFACE;
2233 + req.wValue = dev->alternate;
2234 + req.wIndex = dev->interface;
2237 + dev->ep0state = EP0_NO_ACTION;
2238 + dev->driver->setup(&dev->gadget, &req);
2242 + * pxa27x_udc_irq - interrupt handler
2244 + * avoid delays in ep0 processing. the control handshaking isn't always
2245 + * under software control (pxa250c0 and the pxa255 are better), and delays
2246 + * could cause usb protocol errors.
2248 +static irqreturn_t pxa27x_udc_irq(int irq, void *_dev)
2250 + struct pxa27x_udc *dev = _dev;
2253 + dev->stats.irqs++;
2254 + HEX_DISPLAY(dev->stats.irqs);
2256 + DBG(DBG_VERBOSE, "Interrupt, UDCISR0:0x%08x, UDCISR1:0x%08x, "
2257 + "UDCCR:0x%08x\n", UDCISR0, UDCISR1, UDCCR);
2260 + u32 udcir = UDCISR1 & 0xF8000000;
2264 + /* SUSpend Interrupt Request */
2265 + if (unlikely(udcir & UDCISR1_IRSU)) {
2266 + UDCISR1 = UDCISR1_IRSU;
2268 + DBG(DBG_VERBOSE, "USB suspend\n");
2269 + if (dev->gadget.speed != USB_SPEED_UNKNOWN
2271 + && dev->driver->suspend)
2272 + dev->driver->suspend(&dev->gadget);
2276 + /* RESume Interrupt Request */
2277 + if (unlikely(udcir & UDCISR1_IRRU)) {
2278 + UDCISR1 = UDCISR1_IRRU;
2280 + DBG(DBG_VERBOSE, "USB resume\n");
2282 + if (dev->gadget.speed != USB_SPEED_UNKNOWN
2284 + && dev->driver->resume)
2285 + dev->driver->resume(&dev->gadget);
2288 + if (unlikely(udcir & UDCISR1_IRCC)) {
2289 + unsigned config, interface, alternate;
2292 + DBG(DBG_VERBOSE, "USB SET_CONFIGURATION or "
2293 + "SET_INTERFACE command received\n");
2295 + UDCCR |= UDCCR_SMAC;
2297 + config = (UDCCR & UDCCR_ACN) >> UDCCR_ACN_S;
2299 + if (dev->configuration != config) {
2300 + dev->configuration = config;
2301 + pxa27x_change_configuration(dev) ;
2304 + interface = (UDCCR & UDCCR_AIN) >> UDCCR_AIN_S;
2305 + alternate = (UDCCR & UDCCR_AAISN) >> UDCCR_AAISN_S;
2307 + if ( (dev->configuration != interface) || \
2308 + (dev->alternate != alternate)){
2309 + dev->interface = config;
2310 + dev->alternate = alternate;
2311 + pxa27x_change_interface(dev);
2314 + UDCISR1 = UDCISR1_IRCC;
2315 + DMSG("%s: con:%d,inter:%d,alt:%d\n",
2316 + __FUNCTION__, config,interface, alternate);
2319 + /* ReSeT Interrupt Request - USB reset */
2320 + if (unlikely(udcir & UDCISR1_IRRS)) {
2321 + UDCISR1 = UDCISR1_IRRS;
2324 + if ((UDCCR & UDCCR_UDA) == 0) {
2325 + DBG(DBG_VERBOSE, "SB reset start\n");
2327 + /* reset driver and endpoints,
2328 + * in case that's not yet done
2330 + stop_activity (dev, dev->driver);
2333 + INFO("USB reset\n");
2334 + dev->gadget.speed = USB_SPEED_FULL;
2335 + memset(&dev->stats, 0, sizeof dev->stats);
2338 + u32 udcisr0 = UDCISR0 ;
2339 + u32 udcisr1 = UDCISR1 & 0xFFFF;
2342 + if (unlikely (!udcisr0 && !udcisr1))
2345 + DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", udcisr1,udcisr0);
2347 + /* control traffic */
2348 + if (udcisr0 & UDCISR0_IR0) {
2349 + dev->ep[0].pio_irqs++;
2355 + /* endpoint data transfers */
2356 + for (i = 1; udcisr0!=0 && i < 16; udcisr0>>=2,i++) {
2357 + UDCISR0 = UDCISR_INT(i, UDCISR_INT_MASK);
2359 + if (udcisr0 & UDC_INT_FIFOERROR)
2360 + printk(KERN_ERR" Endpoint %d Fifo error\n", i);
2361 + if (udcisr0 & UDC_INT_PACKETCMP) {
2362 + handle_ep(&dev->ep[i]);
2368 + for (i = 0; udcisr1!=0 && i < 8; udcisr1 >>= 2, i++) {
2369 + UDCISR1 = UDCISR_INT(i, UDCISR_INT_MASK);
2371 + if (udcisr1 & UDC_INT_FIFOERROR) {
2372 + printk(KERN_ERR" Endpoint %d fifo error\n", (i+16));
2375 + if (udcisr1 & UDC_INT_PACKETCMP) {
2376 + handle_ep(&dev->ep[i+16]);
2382 + /* we could also ask for 1 msec SOF (SIR) interrupts */
2384 + } while (handled);
2385 + return IRQ_HANDLED;
2388 +static void udc_init_ep(struct pxa27x_udc *dev)
2392 + INIT_LIST_HEAD (&dev->gadget.ep_list);
2393 + INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
2395 + for (i = 0; i < UDC_EP_NUM; i++) {
2396 + struct pxa27x_ep *ep = &dev->ep[i];
2400 + memset(ep, 0, sizeof(*ep));
2402 + INIT_LIST_HEAD (&ep->queue);
2406 +/*-------------------------------------------------------------------------*/
2408 +static void nop_release (struct device *dev)
2410 + DMSG("%s %s\n", __FUNCTION__, dev->bus_id);
2413 +/* this uses load-time allocation and initialization (instead of
2414 + * doing it at run-time) to save code, eliminate fault paths, and
2415 + * be more obviously correct.
2417 +static struct pxa27x_udc memory = {
2419 + .ops = &pxa27x_udc_ops,
2420 + .ep0 = &memory.ep[0].ep,
2421 + .name = driver_name,
2423 + .bus_id = "gadget",
2424 + .release = nop_release,
2428 + /* control endpoint */
2432 + .ops = &pxa27x_ep_ops,
2433 + .maxpacket = EP0_FIFO_SIZE,
2436 + .reg_udccsr = &UDCCSR0,
2437 + .reg_udcdr = &UDCDR0,
2441 +#define CP15R0_VENDOR_MASK 0xffffe000
2443 +#define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/xscale */
2446 + * probe - binds to the platform device
2448 +static int pxa27x_udc_probe(struct platform_device *pdev)
2450 + struct device *dev = &pdev->dev;
2451 + struct pxa27x_udc *udc = &memory;
2455 + /* insist on Intel/ARM/XScale */
2456 + asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
2457 + if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
2458 + printk(KERN_ERR "%s: not XScale!\n", driver_name);
2461 + /* other non-static parts of init */
2463 + udc->mach = dev->platform_data;
2466 + if (udc->mach->gpio_pullup)
2467 + pxa_gpio_mode((udc->mach->gpio_pullup & GPIO_MD_MASK_NR) | \
2468 + GPIO_OUT | GPIO_DFLT_HIGH);
2470 + init_timer(&udc->timer);
2471 + udc->timer.function = udc_watchdog;
2472 + udc->timer.data = (unsigned long) udc;
2474 + device_initialize(&udc->gadget.dev);
2475 + udc->gadget.dev.parent = dev;
2476 + udc->gadget.dev.dma_mask = dev->dma_mask;
2478 + the_controller = udc;
2479 + dev_set_drvdata(dev, udc);
2485 + /* irq setup after old hardware state is cleaned up */
2486 + retval = request_irq(IRQ_USB, pxa27x_udc_irq,
2487 + SA_INTERRUPT, driver_name, udc);
2488 + if (retval != 0) {
2489 + printk(KERN_ERR "%s: can't get irq %i, err %d\n",
2490 + driver_name, IRQ_USB, retval);
2495 + create_proc_files();
2500 +static int pxa27x_udc_remove(struct platform_device *pdev)
2502 + struct device *dev = &pdev->dev;
2503 + struct pxa27x_udc *udc = dev->driver_data;
2506 + remove_proc_files();
2507 + usb_gadget_unregister_driver(udc->driver);
2509 + if (udc->got_irq) {
2510 + free_irq(IRQ_USB, udc);
2513 + if (machine_is_lubbock() && udc->got_disc) {
2514 + free_irq(LUBBOCK_USB_DISC_IRQ, udc);
2515 + udc->got_disc = 0;
2517 + dev_set_drvdata(dev, 0);
2518 + the_controller = 0;
2523 +static int pxa27x_udc_suspend(struct platform_device *pdev, pm_message_t state)
2525 + struct device *dev = &pdev->dev;
2526 + struct pxa27x_udc *udc = dev->driver_data;
2529 + DMSG("%s will go into SUSPEND_POWER_DOWN\n", __FUNCTION__);
2530 + udc->udccsr0 = UDCCSR0;
2531 + for(i=1; (i<UDC_EP_NUM); i++) {
2532 + if (udc->ep[i].assigned) {
2533 + struct pxa27x_ep *ep = &udc->ep[i];
2535 + ep->udccsr_value = *ep->reg_udccsr;
2536 + ep->udccr_value = *ep->reg_udccr;
2537 + DMSG("EP%d, udccsr:0x%x, udccr:0x%x\n",
2538 + i, *ep->reg_udccsr, *ep->reg_udccr);
2542 + udc_clear_mask_UDCCR(UDCCR_UDE);
2543 + pxa_set_cken(CKEN11_USB, 0);
2548 +static int pxa27x_udc_resume(struct platform_device *pdev)
2550 + struct device *dev = &pdev->dev;
2551 + struct pxa27x_udc *udc = dev->driver_data;
2554 + DMSG("%s: udc resume\n", __FUNCTION__);
2556 + UDCCSR0 = udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME);
2557 + for (i=1; i < UDC_EP_NUM; i++) {
2558 + if (udc->ep[i].assigned) {
2559 + struct pxa27x_ep *ep = &udc->ep[i];
2561 + *ep->reg_udccsr = ep->udccsr_value;
2562 + *ep->reg_udccr = ep->udccr_value;
2563 + DMSG("EP%d, udccsr:0x%x, udccr:0x%x\n",
2564 + i, *ep->reg_udccsr, *ep->reg_udccr);
2568 + /* OTGPH bit is set when sleep mode is entered.
2569 + * it indicates that OTG pad is retaining its state.
2570 + * Upon exit from sleep mode and before clearing OTGPH,
2571 + * Software must configure the USB OTG pad, UDC, and UHC
2572 + * to the state they were in before entering sleep mode.*/
2573 + PSSR |= PSSR_OTGPH;
2578 +#define pxa27x_udc_suspend NULL
2579 +#define pxa27x_udc_resume NULL
2582 +/*-------------------------------------------------------------------------*/
2584 +static struct platform_driver pxa27x_udc_driver = {
2585 + .probe = pxa27x_udc_probe,
2586 + .remove = pxa27x_udc_remove,
2587 + .suspend = pxa27x_udc_suspend,
2588 + .resume = pxa27x_udc_resume,
2590 + .name = "pxa2xx-udc",
2594 +static int __init udc_init(void)
2596 + printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
2597 + return platform_driver_register(&pxa27x_udc_driver);
2599 +module_init(udc_init);
2601 +static void __exit udc_exit(void)
2603 + platform_driver_unregister(&pxa27x_udc_driver);
2605 +module_exit(udc_exit);
2607 +MODULE_DESCRIPTION(DRIVER_DESC);
2608 +MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
2609 +MODULE_LICENSE("GPL");
2610 diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
2611 new file mode 100644
2612 index 0000000..c4b72a2
2614 +++ b/drivers/usb/gadget/pxa27x_udc.h
2617 + * linux/drivers/usb/gadget/pxa27x_udc.h
2618 + * Intel PXA27x on-chip full speed USB device controller
2620 + * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
2621 + * Copyright (C) 2003 David Brownell
2622 + * Copyright (C) 2004 Intel Corporation
2624 + * This program is free software; you can redistribute it and/or modify
2625 + * it under the terms of the GNU General Public License as published by
2626 + * the Free Software Foundation; either version 2 of the License, or
2627 + * (at your option) any later version.
2629 + * This program is distributed in the hope that it will be useful,
2630 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2631 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2632 + * GNU General Public License for more details.
2634 + * You should have received a copy of the GNU General Public License
2635 + * along with this program; if not, write to the Free Software
2636 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2639 +#ifndef __LINUX_USB_GADGET_PXA27X_H
2640 +#define __LINUX_USB_GADGET_PXA27X_H
2642 +#include <linux/types.h>
2648 + struct pxa27x_udc *dev;
2650 + const struct usb_endpoint_descriptor *desc;
2651 + struct list_head queue;
2652 + unsigned long pio_irqs;
2653 + unsigned long dma_irqs;
2656 + unsigned fifo_size;
2660 + unsigned stopped : 1;
2661 + unsigned dma_con : 1;
2662 + unsigned dir_in : 1;
2663 + unsigned assigned : 1;
2666 + unsigned interface;
2668 + /* UDCCSR = UDC Control/Status Register for this EP
2669 + * UBCR = UDC Byte Count Remaining (contents of OUT fifo)
2670 + * UDCDR = UDC Endpoint Data Register (the fifo)
2671 + * UDCCR = UDC Endpoint Configuration Registers
2672 + * DRCM = DMA Request Channel Map
2674 + volatile u32 *reg_udccsr;
2675 + volatile u32 *reg_udcbcr;
2676 + volatile u32 *reg_udcdr;
2677 + volatile u32 *reg_udccr;
2679 + volatile u32 *reg_drcmr;
2680 +#define drcmr(n) .reg_drcmr = & DRCMR ## n ,
2686 + unsigned udccsr_value;
2687 + unsigned udccr_value;
2691 +struct pxa27x_request {
2692 + struct usb_request req;
2693 + struct list_head queue;
2698 + EP0_IN_DATA_PHASE,
2699 + EP0_OUT_DATA_PHASE,
2705 +#define EP0_FIFO_SIZE ((unsigned)16)
2706 +#define BULK_FIFO_SIZE ((unsigned)64)
2707 +#define ISO_FIFO_SIZE ((unsigned)256)
2708 +#define INT_FIFO_SIZE ((unsigned)8)
2712 + unsigned long ops;
2713 + unsigned long bytes;
2715 + unsigned long irqs;
2718 +#ifdef CONFIG_USB_PXA27X_SMALL
2719 +/* when memory's tight, SMALL config saves code+data. */
2721 +//#define UDC_EP_NUM 3
2725 +#define UDC_EP_NUM 24
2728 +struct pxa27x_udc {
2729 + struct usb_gadget gadget;
2730 + struct usb_gadget_driver *driver;
2732 + enum ep0_state ep0state;
2733 + struct udc_stats stats;
2734 + unsigned got_irq : 1,
2741 +#define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200))
2742 + struct timer_list timer;
2744 + struct device *dev;
2745 + struct pxa2xx_udc_mach_info *mach;
2747 + struct pxa27x_ep ep [UDC_EP_NUM];
2749 + unsigned configuration,
2757 +/*-------------------------------------------------------------------------*/
2760 +#define HEX_DISPLAY(n) do { \
2761 + if (machine_is_mainstone())\
2762 + { MST_LEDDAT1 = (n); } \
2765 +#define HEX_DISPLAY1(n) HEX_DISPLAY(n)
2767 +#define HEX_DISPLAY2(n) do { \
2768 + if (machine_is_mainstone()) \
2769 + { MST_LEDDAT2 = (n); } \
2774 +/*-------------------------------------------------------------------------*/
2776 +/* LEDs are only for debug */
2777 +#ifndef HEX_DISPLAY
2778 +#define HEX_DISPLAY(n) do {} while(0)
2781 +#ifndef LED_CONNECTED_ON
2782 +#define LED_CONNECTED_ON do {} while(0)
2783 +#define LED_CONNECTED_OFF do {} while(0)
2786 +#define LED_EP0_ON do {} while (0)
2787 +#define LED_EP0_OFF do {} while (0)
2790 +static struct pxa27x_udc *the_controller;
2792 +/*-------------------------------------------------------------------------*/
2794 +/* one GPIO should be used to detect host disconnect */
2795 +static inline int is_usb_connected(void)
2797 + if (!the_controller->mach->udc_is_connected)
2799 + return the_controller->mach->udc_is_connected();
2802 +/* one GPIO should force the host to see this device (or not) */
2803 +static inline void make_usb_disappear(void)
2805 + if (!the_controller->mach->udc_command)
2807 + the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
2810 +static inline void let_usb_appear(void)
2812 + if (!the_controller->mach->udc_command)
2814 + the_controller->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
2817 +/*-------------------------------------------------------------------------*/
2820 + * Debugging support vanishes in non-debug builds. DBG_NORMAL should be
2821 + * mostly silent during normal use/testing, with no timing side-effects.
2823 +#define DBG_NORMAL 1 /* error paths, device state transitions */
2824 +#define DBG_VERBOSE 2 /* add some success path trace info */
2825 +#define DBG_NOISY 3 /* ... even more: request level */
2826 +#define DBG_VERY_NOISY 4 /* ... even more: packet level */
2830 +static const char *state_name[] = {
2832 + "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE",
2833 + "EP0_END_XFER", "EP0_STALL"
2836 +#define DMSG(stuff...) printk(KERN_ERR "udc: " stuff)
2839 +# define UDC_DEBUG DBG_VERBOSE
2841 +# define UDC_DEBUG DBG_NORMAL
2844 +static void __attribute__ ((__unused__))
2845 +dump_udccr(const char *label)
2847 + u32 udccr = UDCCR;
2848 + DMSG("%s 0x%08x =%s%s%s%s%s%s%s%s%s%s, con=%d,inter=%d,altinter=%d\n",
2850 + (udccr & UDCCR_OEN) ? " oen":"",
2851 + (udccr & UDCCR_AALTHNP) ? " aalthnp":"",
2852 + (udccr & UDCCR_AHNP) ? " rem" : "",
2853 + (udccr & UDCCR_BHNP) ? " rstir" : "",
2854 + (udccr & UDCCR_DWRE) ? " dwre" : "",
2855 + (udccr & UDCCR_SMAC) ? " smac" : "",
2856 + (udccr & UDCCR_EMCE) ? " emce" : "",
2857 + (udccr & UDCCR_UDR) ? " udr" : "",
2858 + (udccr & UDCCR_UDA) ? " uda" : "",
2859 + (udccr & UDCCR_UDE) ? " ude" : "",
2860 + (udccr & UDCCR_ACN) >> UDCCR_ACN_S,
2861 + (udccr & UDCCR_AIN) >> UDCCR_AIN_S,
2862 + (udccr & UDCCR_AAISN)>> UDCCR_AAISN_S );
2865 +static void __attribute__ ((__unused__))
2866 +dump_udccsr0(const char *label)
2868 + u32 udccsr0 = UDCCSR0;
2870 + DMSG("%s %s 0x%08x =%s%s%s%s%s%s%s\n",
2871 + label, state_name[the_controller->ep0state], udccsr0,
2872 + (udccsr0 & UDCCSR0_SA) ? " sa" : "",
2873 + (udccsr0 & UDCCSR0_RNE) ? " rne" : "",
2874 + (udccsr0 & UDCCSR0_FST) ? " fst" : "",
2875 + (udccsr0 & UDCCSR0_SST) ? " sst" : "",
2876 + (udccsr0 & UDCCSR0_DME) ? " dme" : "",
2877 + (udccsr0 & UDCCSR0_IPR) ? " ipr" : "",
2878 + (udccsr0 & UDCCSR0_OPC) ? " opr" : "");
2881 +static void __attribute__ ((__unused__))
2882 +dump_state(struct pxa27x_udc *dev)
2886 + DMSG("%s, udcicr %02X.%02X, udcsir %02X.%02x, udcfnr %02X\n",
2887 + state_name[dev->ep0state],
2888 + UDCICR1, UDCICR0, UDCISR1, UDCISR0, UDCFNR);
2889 + dump_udccr("udccr");
2891 + if (!dev->driver) {
2892 + DMSG("no gadget driver bound\n");
2895 + DMSG("ep0 driver '%s'\n", dev->driver->driver.name);
2898 + dump_udccsr0 ("udccsr0");
2899 + DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n",
2900 + dev->stats.write.bytes, dev->stats.write.ops,
2901 + dev->stats.read.bytes, dev->stats.read.ops);
2903 + for (i = 1; i < UDC_EP_NUM; i++) {
2904 + if (dev->ep [i].desc == 0)
2906 + DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccsr);
2911 +static void dump_regs(u8 ep)
2913 + DMSG("EP:%d UDCCSR:0x%08x UDCBCR:0x%08x\n UDCCR:0x%08x\n",
2914 + ep,UDCCSN(ep), UDCBCN(ep), UDCCN(ep));
2916 +static void dump_req (struct pxa27x_request *req)
2918 + struct usb_request *r = &req->req;
2920 + DMSG("%s: buf:0x%08x length:%d dma:0x%08x actual:%d\n",
2921 + __FUNCTION__, (unsigned)r->buf, r->length,
2922 + r->dma, r->actual);
2928 +#define DMSG(stuff...) do{}while(0)
2930 +#define dump_udccr(x) do{}while(0)
2931 +#define dump_udccsr0(x) do{}while(0)
2932 +#define dump_state(x) do{}while(0)
2934 +#define UDC_DEBUG ((unsigned)0)
2938 +#define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
2940 +#define WARN(stuff...) printk(KERN_WARNING "udc: " stuff)
2941 +#define INFO(stuff...) printk(KERN_INFO "udc: " stuff)
2944 +#endif /* __LINUX_USB_GADGET_PXA27X_H */
2945 diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
2946 index e552668..971e491 100644
2947 --- a/drivers/usb/gadget/serial.c
2948 +++ b/drivers/usb/gadget/serial.c
2949 @@ -1378,20 +1378,20 @@ static int __init gs_bind(struct usb_gadget *gadget)
2951 usb_ep_autoconfig_reset(gadget);
2953 - ep = usb_ep_autoconfig(gadget, &gs_fullspeed_in_desc);
2954 + ep = usb_ep_autoconfig(gadget, &gs_fullspeed_in_desc, 0, 0, 0);
2957 EP_IN_NAME = ep->name;
2958 ep->driver_data = ep; /* claim the endpoint */
2960 - ep = usb_ep_autoconfig(gadget, &gs_fullspeed_out_desc);
2961 + ep = usb_ep_autoconfig(gadget, &gs_fullspeed_out_desc, 0, 0, 0);
2964 EP_OUT_NAME = ep->name;
2965 ep->driver_data = ep; /* claim the endpoint */
2968 - ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc);
2969 + ep = usb_ep_autoconfig(gadget, &gs_fullspeed_notify_desc, 0, 0, 0);
2971 printk(KERN_ERR "gs_bind: cannot run ACM on %s\n", gadget->name);
2973 diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
2974 index 8c85e33..46ffe6c 100644
2975 --- a/drivers/usb/gadget/zero.c
2976 +++ b/drivers/usb/gadget/zero.c
2977 @@ -1155,7 +1155,7 @@ zero_bind (struct usb_gadget *gadget)
2978 * but there may also be important quirks to address.
2980 usb_ep_autoconfig_reset (gadget);
2981 - ep = usb_ep_autoconfig (gadget, &fs_source_desc);
2982 + ep = usb_ep_autoconfig (gadget, &fs_source_desc, 0, 0, 0);
2985 printk (KERN_ERR "%s: can't autoconfigure on %s\n",
2986 @@ -1165,7 +1165,7 @@ autoconf_fail:
2987 EP_IN_NAME = ep->name;
2988 ep->driver_data = ep; /* claim */
2990 - ep = usb_ep_autoconfig (gadget, &fs_sink_desc);
2991 + ep = usb_ep_autoconfig (gadget, &fs_sink_desc, 0, 0, 0);
2994 EP_OUT_NAME = ep->name;
2995 diff --git a/include/linux/usb_gadget.h b/include/linux/usb_gadget.h
2996 index e17186d..64c81fd 100644
2997 --- a/include/linux/usb_gadget.h
2998 +++ b/include/linux/usb_gadget.h
2999 @@ -445,10 +445,28 @@ usb_ep_fifo_flush (struct usb_ep *ep)
3004 + * struct usb_endpoint_config - possible configurations of a given endpoint
3005 + * @config: the configuration number
3006 + * @interface: the interface number
3007 + * @altinterface: the altinterface number
3009 + * Used as an array to pass information about the possible configurations
3010 + * of a given endpoint to the bus controller.
3012 +struct usb_endpoint_config {
3018 /* the rest of the api to the controller hardware: device operations,
3019 * which don't involve endpoints (or i/o).
3021 struct usb_gadget_ops {
3022 + struct usb_ep* (*ep_alloc)(struct usb_gadget *gadget,
3023 + struct usb_endpoint_descriptor *desc,
3024 + int config, int interface, int alt);
3025 int (*get_frame)(struct usb_gadget *);
3026 int (*wakeup)(struct usb_gadget *);
3027 int (*set_selfpowered) (struct usb_gadget *, int is_selfpowered);
3028 @@ -872,7 +890,8 @@ int usb_gadget_config_buf(const struct usb_config_descriptor *config,
3029 /* utility wrapping a simple endpoint selection policy */
3031 extern struct usb_ep *usb_ep_autoconfig (struct usb_gadget *,
3032 - struct usb_endpoint_descriptor *) __devinit;
3033 + struct usb_endpoint_descriptor *,
3034 + int, int, int) __devinit;
3036 extern void usb_ep_autoconfig_reset (struct usb_gadget *) __devinit;