1 From 1a44a003bdaf917193114d0d40534496c39644ba Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Fri, 15 Mar 2013 20:58:18 +0100
4 Subject: [PATCH 202/208] owrt: USB: adds dwc_otg
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 drivers/usb/Kconfig | 2 +
9 drivers/usb/Makefile | 1 +
10 drivers/usb/dwc_otg/Kconfig | 24 +
11 drivers/usb/dwc_otg/Makefile | 25 +
12 drivers/usb/dwc_otg/dummy_audio.c | 1575 +++++++++++++
13 drivers/usb/dwc_otg/dwc_otg_attr.c | 966 ++++++++
14 drivers/usb/dwc_otg/dwc_otg_attr.h | 67 +
15 drivers/usb/dwc_otg/dwc_otg_cil.c | 3692 ++++++++++++++++++++++++++++++
16 drivers/usb/dwc_otg/dwc_otg_cil.h | 1098 +++++++++
17 drivers/usb/dwc_otg/dwc_otg_cil_intr.c | 750 ++++++
18 drivers/usb/dwc_otg/dwc_otg_driver.c | 1273 ++++++++++
19 drivers/usb/dwc_otg/dwc_otg_driver.h | 83 +
20 drivers/usb/dwc_otg/dwc_otg_hcd.c | 2852 +++++++++++++++++++++++
21 drivers/usb/dwc_otg/dwc_otg_hcd.h | 668 ++++++
22 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c | 1873 +++++++++++++++
23 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c | 684 ++++++
24 drivers/usb/dwc_otg/dwc_otg_pcd.c | 2523 ++++++++++++++++++++
25 drivers/usb/dwc_otg/dwc_otg_pcd.h | 248 ++
26 drivers/usb/dwc_otg/dwc_otg_pcd_intr.c | 3654 +++++++++++++++++++++++++++++
27 drivers/usb/dwc_otg/dwc_otg_regs.h | 2075 +++++++++++++++++
28 drivers/usb/dwc_otg/linux/dwc_otg_plat.h | 260 +++
29 21 files changed, 24393 insertions(+)
30 create mode 100644 drivers/usb/dwc_otg/Kconfig
31 create mode 100644 drivers/usb/dwc_otg/Makefile
32 create mode 100644 drivers/usb/dwc_otg/dummy_audio.c
33 create mode 100644 drivers/usb/dwc_otg/dwc_otg_attr.c
34 create mode 100644 drivers/usb/dwc_otg/dwc_otg_attr.h
35 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.c
36 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.h
37 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil_intr.c
38 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.c
39 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.h
40 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.c
41 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.h
42 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
43 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
44 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.c
45 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.h
46 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd_intr.c
47 create mode 100644 drivers/usb/dwc_otg/dwc_otg_regs.h
48 create mode 100644 drivers/usb/dwc_otg/linux/dwc_otg_plat.h
50 diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
51 index 640ae6c..20a629a 100644
52 --- a/drivers/usb/Kconfig
53 +++ b/drivers/usb/Kconfig
54 @@ -126,6 +126,8 @@ source "drivers/usb/core/Kconfig"
56 source "drivers/usb/dwc3/Kconfig"
58 +source "drivers/usb/dwc_otg/Kconfig"
60 source "drivers/usb/mon/Kconfig"
62 source "drivers/usb/wusbcore/Kconfig"
63 diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
64 index 8f5ebce..4bcfe6d 100644
65 --- a/drivers/usb/Makefile
66 +++ b/drivers/usb/Makefile
67 @@ -9,6 +9,7 @@ obj-$(CONFIG_USB) += core/
68 obj-$(CONFIG_USB_OTG_UTILS) += otg/
70 obj-$(CONFIG_USB_DWC3) += dwc3/
71 +obj-$(CONFIG_DWC_OTG) += dwc_otg/
73 obj-$(CONFIG_USB_MON) += mon/
75 diff --git a/drivers/usb/dwc_otg/Kconfig b/drivers/usb/dwc_otg/Kconfig
77 index 0000000..6dd75f1
79 +++ b/drivers/usb/dwc_otg/Kconfig
82 + tristate "Ralink RT305X DWC_OTG support"
83 + depends on SOC_RT305X
85 + This driver supports Ralink DWC_OTG
88 + prompt "USB Operation Mode"
90 + default DWC_OTG_HOST_ONLY
92 +config DWC_OTG_HOST_ONLY
93 + bool "HOST ONLY MODE"
96 +config DWC_OTG_DEVICE_ONLY
97 + bool "DEVICE ONLY MODE"
102 +config DWC_OTG_DEBUG
103 + bool "Enable debug mode"
105 diff --git a/drivers/usb/dwc_otg/Makefile b/drivers/usb/dwc_otg/Makefile
107 index 0000000..95c5b66
109 +++ b/drivers/usb/dwc_otg/Makefile
112 +# Makefile for DWC_otg Highspeed USB controller driver
115 +ifeq ($(CONFIG_DWC_OTG_DEBUG),y)
116 +EXTRA_CFLAGS += -DDEBUG
119 +# Use one of the following flags to compile the software in host-only or
121 +ifeq ($(CONFIG_DWC_OTG_HOST_ONLY),y)
122 +EXTRA_CFLAGS += -DDWC_HOST_ONLY
123 +EXTRA_CFLAGS += -DDWC_EN_ISOC
126 +ifeq ($(CONFIG_DWC_OTG_DEVICE_ONLY),y)
127 +EXTRA_CFLAGS += -DDWC_DEVICE_ONLY
130 +obj-$(CONFIG_DWC_OTG) := dwc_otg.o
132 +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
133 +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
134 +dwc_otg-objs += dwc_otg_pcd.o dwc_otg_pcd_intr.o
135 +dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o
136 diff --git a/drivers/usb/dwc_otg/dummy_audio.c b/drivers/usb/dwc_otg/dummy_audio.c
138 index 0000000..225decf
140 +++ b/drivers/usb/dwc_otg/dummy_audio.c
143 + * zero.c -- Gadget Zero, for USB development
145 + * Copyright (C) 2003-2004 David Brownell
146 + * All rights reserved.
148 + * Redistribution and use in source and binary forms, with or without
149 + * modification, are permitted provided that the following conditions
151 + * 1. Redistributions of source code must retain the above copyright
152 + * notice, this list of conditions, and the following disclaimer,
153 + * without modification.
154 + * 2. Redistributions in binary form must reproduce the above copyright
155 + * notice, this list of conditions and the following disclaimer in the
156 + * documentation and/or other materials provided with the distribution.
157 + * 3. The names of the above-listed copyright holders may not be used
158 + * to endorse or promote products derived from this software without
159 + * specific prior written permission.
161 + * ALTERNATIVELY, this software may be distributed under the terms of the
162 + * GNU General Public License ("GPL") as published by the Free Software
163 + * Foundation, either version 2 of that License or (at your option) any
166 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
167 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
168 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
169 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
170 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
171 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
172 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
173 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
174 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
175 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
176 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
181 + * Gadget Zero only needs two bulk endpoints, and is an example of how you
182 + * can write a hardware-agnostic gadget driver running inside a USB device.
184 + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
185 + * affect most of the driver.
187 + * Use it with the Linux host/master side "usbtest" driver to get a basic
188 + * functional test of your device-side usb stack, or with "usb-skeleton".
190 + * It supports two similar configurations. One sinks whatever the usb host
191 + * writes, and in return sources zeroes. The other loops whatever the host
192 + * writes back, so the host can read it. Module options include:
194 + * buflen=N default N=4096, buffer size used
195 + * qlen=N default N=32, how many buffers in the loopback queue
196 + * loopdefault default false, list loopback config first
198 + * Many drivers will only have one configuration, letting them be much
199 + * simpler if they also don't support high speed operation (like this
203 +#include <linux/config.h>
204 +#include <linux/module.h>
205 +#include <linux/kernel.h>
206 +#include <linux/delay.h>
207 +#include <linux/ioport.h>
208 +#include <linux/sched.h>
209 +#include <linux/slab.h>
210 +#include <linux/smp_lock.h>
211 +#include <linux/errno.h>
212 +#include <linux/init.h>
213 +#include <linux/timer.h>
214 +#include <linux/list.h>
215 +#include <linux/interrupt.h>
216 +#include <linux/uts.h>
217 +#include <linux/version.h>
218 +#include <linux/device.h>
219 +#include <linux/moduleparam.h>
220 +#include <linux/proc_fs.h>
222 +#include <asm/byteorder.h>
224 +#include <asm/irq.h>
225 +#include <asm/system.h>
226 +#include <asm/unaligned.h>
228 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
229 +# include <linux/usb/ch9.h>
231 +# include <linux/usb_ch9.h>
234 +#include <linux/usb_gadget.h>
237 +/*-------------------------------------------------------------------------*/
238 +/*-------------------------------------------------------------------------*/
241 +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
247 + /* this insists on correct encodings, though not minimal ones.
248 + * BUT it currently rejects legit 4-byte UTF-8 code points,
249 + * which need surrogate pairs. (Unicode 3.1 can use them.)
251 + while (len != 0 && (c = (u8) *s++) != 0) {
252 + if (unlikely(c & 0x80)) {
253 + // 2-byte sequence:
254 + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
255 + if ((c & 0xe0) == 0xc0) {
256 + uchar = (c & 0x1f) << 6;
259 + if ((c & 0xc0) != 0xc0)
264 + // 3-byte sequence (most CJKV characters):
265 + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
266 + } else if ((c & 0xf0) == 0xe0) {
267 + uchar = (c & 0x0f) << 12;
270 + if ((c & 0xc0) != 0xc0)
276 + if ((c & 0xc0) != 0xc0)
281 + /* no bogus surrogates */
282 + if (0xd800 <= uchar && uchar <= 0xdfff)
285 + // 4-byte sequence (surrogate pairs, currently rare):
286 + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
287 + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
288 + // (uuuuu = wwww + 1)
289 + // FIXME accept the surrogate code points (only)
295 + put_unaligned (cpu_to_le16 (uchar), cp++);
306 + * usb_gadget_get_string - fill out a string descriptor
307 + * @table: of c strings encoded using UTF-8
308 + * @id: string id, from low byte of wValue in get string descriptor
309 + * @buf: at least 256 bytes
311 + * Finds the UTF-8 string matching the ID, and converts it into a
312 + * string descriptor in utf16-le.
313 + * Returns length of descriptor (always even) or negative errno
315 + * If your driver needs stings in multiple languages, you'll probably
316 + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
317 + * using this routine after choosing which set of UTF-8 strings to use.
318 + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
319 + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
320 + * characters (which are also widely used in C strings).
323 +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
325 + struct usb_string *s;
328 + /* descriptor 0 has the language id */
331 + buf [1] = USB_DT_STRING;
332 + buf [2] = (u8) table->language;
333 + buf [3] = (u8) (table->language >> 8);
336 + for (s = table->strings; s && s->s; s++)
340 + /* unrecognized: stall. */
344 + /* string descriptors have length, tag, then UTF16-LE text */
345 + len = min ((size_t) 126, strlen (s->s));
346 + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
347 + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
350 + buf [0] = (len + 1) * 2;
351 + buf [1] = USB_DT_STRING;
356 +/*-------------------------------------------------------------------------*/
357 +/*-------------------------------------------------------------------------*/
361 + * usb_descriptor_fillbuf - fill buffer with descriptors
362 + * @buf: Buffer to be filled
363 + * @buflen: Size of buf
364 + * @src: Array of descriptor pointers, terminated by null pointer.
366 + * Copies descriptors into the buffer, returning the length or a
367 + * negative error code if they can't all be copied. Useful when
368 + * assembling descriptors for an associated set of interfaces used
369 + * as part of configuring a composite device; or in other cases where
370 + * sets of descriptors need to be marshaled.
373 +usb_descriptor_fillbuf(void *buf, unsigned buflen,
374 + const struct usb_descriptor_header **src)
381 + /* fill buffer from src[] until null descriptor ptr */
382 + for (; 0 != *src; src++) {
383 + unsigned len = (*src)->bLength;
387 + memcpy(dest, *src, len);
391 + return dest - (u8 *)buf;
396 + * usb_gadget_config_buf - builts a complete configuration descriptor
397 + * @config: Header for the descriptor, including characteristics such
398 + * as power requirements and number of interfaces.
399 + * @desc: Null-terminated vector of pointers to the descriptors (interface,
400 + * endpoint, etc) defining all functions in this device configuration.
401 + * @buf: Buffer for the resulting configuration descriptor.
402 + * @length: Length of buffer. If this is not big enough to hold the
403 + * entire configuration descriptor, an error code will be returned.
405 + * This copies descriptors into the response buffer, building a descriptor
406 + * for that configuration. It returns the buffer length or a negative
407 + * status code. The config.wTotalLength field is set to match the length
408 + * of the result, but other descriptor fields (including power usage and
409 + * interface count) must be set by the caller.
411 + * Gadget drivers could use this when constructing a config descriptor
412 + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
413 + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
415 +int usb_gadget_config_buf(
416 + const struct usb_config_descriptor *config,
419 + const struct usb_descriptor_header **desc
422 + struct usb_config_descriptor *cp = buf;
425 + /* config descriptor first */
426 + if (length < USB_DT_CONFIG_SIZE || !desc)
430 + /* then interface/endpoint/class/vendor/... */
431 + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
432 + length - USB_DT_CONFIG_SIZE, desc);
435 + len += USB_DT_CONFIG_SIZE;
439 + /* patch up the config descriptor */
440 + cp->bLength = USB_DT_CONFIG_SIZE;
441 + cp->bDescriptorType = USB_DT_CONFIG;
442 + cp->wTotalLength = cpu_to_le16(len);
443 + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
447 +/*-------------------------------------------------------------------------*/
448 +/*-------------------------------------------------------------------------*/
451 +#define RBUF_LEN (1024*1024)
452 +static int rbuf_start;
453 +static int rbuf_len;
454 +static __u8 rbuf[RBUF_LEN];
456 +/*-------------------------------------------------------------------------*/
458 +#define DRIVER_VERSION "St Patrick's Day 2004"
460 +static const char shortname [] = "zero";
461 +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
463 +static const char source_sink [] = "source and sink data";
464 +static const char loopback [] = "loop input to output";
466 +/*-------------------------------------------------------------------------*/
469 + * driver assumes self-powered hardware, and
470 + * has no way for users to trigger remote wakeup.
472 + * this version autoconfigures as much as possible,
473 + * which is reasonable for most "bulk-only" drivers.
475 +static const char *EP_IN_NAME; /* source */
476 +static const char *EP_OUT_NAME; /* sink */
478 +/*-------------------------------------------------------------------------*/
480 +/* big enough to hold our biggest descriptor */
481 +#define USB_BUFSIZ 512
485 + struct usb_gadget *gadget;
486 + struct usb_request *req; /* for control responses */
488 + /* when configured, we have one of two configs:
489 + * - source data (in to host) and sink it (out from host)
490 + * - or loop it back (out from host back in to host)
493 + struct usb_ep *in_ep, *out_ep;
495 + /* autoresume timer */
496 + struct timer_list resume;
499 +#define xprintk(d,level,fmt,args...) \
500 + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
503 +#define DBG(dev,fmt,args...) \
504 + xprintk(dev , KERN_DEBUG , fmt , ## args)
506 +#define DBG(dev,fmt,args...) \
513 +#define VDBG(dev,fmt,args...) \
515 +#endif /* VERBOSE */
517 +#define ERROR(dev,fmt,args...) \
518 + xprintk(dev , KERN_ERR , fmt , ## args)
519 +#define WARN(dev,fmt,args...) \
520 + xprintk(dev , KERN_WARNING , fmt , ## args)
521 +#define INFO(dev,fmt,args...) \
522 + xprintk(dev , KERN_INFO , fmt , ## args)
524 +/*-------------------------------------------------------------------------*/
526 +static unsigned buflen = 4096;
527 +static unsigned qlen = 32;
528 +static unsigned pattern = 0;
530 +module_param (buflen, uint, S_IRUGO|S_IWUSR);
531 +module_param (qlen, uint, S_IRUGO|S_IWUSR);
532 +module_param (pattern, uint, S_IRUGO|S_IWUSR);
535 + * if it's nonzero, autoresume says how many seconds to wait
536 + * before trying to wake up the host after suspend.
538 +static unsigned autoresume = 0;
539 +module_param (autoresume, uint, 0);
542 + * Normally the "loopback" configuration is second (index 1) so
543 + * it's not the default. Here's where to change that order, to
544 + * work better with hosts where config changes are problematic.
545 + * Or controllers (like superh) that only support one config.
547 +static int loopdefault = 0;
549 +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
551 +/*-------------------------------------------------------------------------*/
553 +/* Thanks to NetChip Technologies for donating this product ID.
555 + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
556 + * Instead: allocate your own, using normal USB-IF procedures.
558 +#ifndef CONFIG_USB_ZERO_HNPTEST
559 +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
560 +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
562 +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
563 +#define DRIVER_PRODUCT_NUM 0xbadd
566 +/*-------------------------------------------------------------------------*/
569 + * DESCRIPTORS ... most are static, but strings and (full)
570 + * configuration descriptors are built on demand.
574 +#define STRING_MANUFACTURER 25
575 +#define STRING_PRODUCT 42
576 +#define STRING_SERIAL 101
578 +#define STRING_MANUFACTURER 1
579 +#define STRING_PRODUCT 2
580 +#define STRING_SERIAL 3
582 +#define STRING_SOURCE_SINK 250
583 +#define STRING_LOOPBACK 251
586 + * This device advertises two configurations; these numbers work
587 + * on a pxa250 as well as more flexible hardware.
589 +#define CONFIG_SOURCE_SINK 3
590 +#define CONFIG_LOOPBACK 2
593 +static struct usb_device_descriptor
595 + .bLength = sizeof device_desc,
596 + .bDescriptorType = USB_DT_DEVICE,
598 + .bcdUSB = __constant_cpu_to_le16 (0x0200),
599 + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
601 + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
602 + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
603 + .iManufacturer = STRING_MANUFACTURER,
604 + .iProduct = STRING_PRODUCT,
605 + .iSerialNumber = STRING_SERIAL,
606 + .bNumConfigurations = 2,
609 +static struct usb_device_descriptor
611 + .bLength = sizeof device_desc,
612 + .bDescriptorType = USB_DT_DEVICE,
613 + .bcdUSB = __constant_cpu_to_le16 (0x0100),
614 + .bDeviceClass = USB_CLASS_PER_INTERFACE,
615 + .bDeviceSubClass = 0,
616 + .bDeviceProtocol = 0,
617 + .bMaxPacketSize0 = 64,
618 + .bcdDevice = __constant_cpu_to_le16 (0x0100),
619 + .idVendor = __constant_cpu_to_le16 (0x0499),
620 + .idProduct = __constant_cpu_to_le16 (0x3002),
621 + .iManufacturer = STRING_MANUFACTURER,
622 + .iProduct = STRING_PRODUCT,
623 + .iSerialNumber = STRING_SERIAL,
624 + .bNumConfigurations = 1,
627 +static struct usb_config_descriptor
629 + .bLength = sizeof z_config,
630 + .bDescriptorType = USB_DT_CONFIG,
632 + /* compute wTotalLength on the fly */
633 + .bNumInterfaces = 2,
634 + .bConfigurationValue = 1,
635 + .iConfiguration = 0,
636 + .bmAttributes = 0x40,
637 + .bMaxPower = 0, /* self-powered */
641 +static struct usb_otg_descriptor
643 + .bLength = sizeof otg_descriptor,
644 + .bDescriptorType = USB_DT_OTG,
646 + .bmAttributes = USB_OTG_SRP,
649 +/* one interface in each configuration */
650 +#ifdef CONFIG_USB_GADGET_DUALSPEED
653 + * usb 2.0 devices need to expose both high speed and full speed
654 + * descriptors, unless they only run at full speed.
656 + * that means alternate endpoint descriptors (bigger packets)
657 + * and a "device qualifier" ... plus more construction options
658 + * for the config descriptor.
661 +static struct usb_qualifier_descriptor
663 + .bLength = sizeof dev_qualifier,
664 + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
666 + .bcdUSB = __constant_cpu_to_le16 (0x0200),
667 + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
669 + .bNumConfigurations = 2,
673 +struct usb_cs_as_general_descriptor {
675 + __u8 bDescriptorType;
677 + __u8 bDescriptorSubType;
678 + __u8 bTerminalLink;
681 +} __attribute__ ((packed));
683 +struct usb_cs_as_format_descriptor {
685 + __u8 bDescriptorType;
687 + __u8 bDescriptorSubType;
690 + __u8 bSubframeSize;
691 + __u8 bBitResolution;
693 + __u8 tLowerSamFreq[3];
694 + __u8 tUpperSamFreq[3];
695 +} __attribute__ ((packed));
697 +static const struct usb_interface_descriptor
698 +z_audio_control_if_desc = {
699 + .bLength = sizeof z_audio_control_if_desc,
700 + .bDescriptorType = USB_DT_INTERFACE,
701 + .bInterfaceNumber = 0,
702 + .bAlternateSetting = 0,
703 + .bNumEndpoints = 0,
704 + .bInterfaceClass = USB_CLASS_AUDIO,
705 + .bInterfaceSubClass = 0x1,
706 + .bInterfaceProtocol = 0,
710 +static const struct usb_interface_descriptor
712 + .bLength = sizeof z_audio_if_desc,
713 + .bDescriptorType = USB_DT_INTERFACE,
714 + .bInterfaceNumber = 1,
715 + .bAlternateSetting = 0,
716 + .bNumEndpoints = 0,
717 + .bInterfaceClass = USB_CLASS_AUDIO,
718 + .bInterfaceSubClass = 0x2,
719 + .bInterfaceProtocol = 0,
723 +static const struct usb_interface_descriptor
724 +z_audio_if_desc2 = {
725 + .bLength = sizeof z_audio_if_desc,
726 + .bDescriptorType = USB_DT_INTERFACE,
727 + .bInterfaceNumber = 1,
728 + .bAlternateSetting = 1,
729 + .bNumEndpoints = 1,
730 + .bInterfaceClass = USB_CLASS_AUDIO,
731 + .bInterfaceSubClass = 0x2,
732 + .bInterfaceProtocol = 0,
736 +static const struct usb_cs_as_general_descriptor
737 +z_audio_cs_as_if_desc = {
739 + .bDescriptorType = 0x24,
741 + .bDescriptorSubType = 0x01,
742 + .bTerminalLink = 0x01,
744 + .wFormatTag = __constant_cpu_to_le16 (0x0001)
748 +static const struct usb_cs_as_format_descriptor
749 +z_audio_cs_as_format_desc = {
751 + .bDescriptorType = 0x24,
753 + .bDescriptorSubType = 2,
756 + .bSubframeSize = 1,
757 + .bBitResolution = 8,
759 + .tLowerSamFreq = {0x7e, 0x13, 0x00},
760 + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
763 +static const struct usb_endpoint_descriptor
766 + .bDescriptorType = 0x05,
767 + .bEndpointAddress = 0x04,
768 + .bmAttributes = 0x09,
769 + .wMaxPacketSize = 0x0038,
772 + .bSynchAddress = 0x00,
775 +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
778 +static char z_ac_interface_header_desc[] =
779 +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
782 +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
783 + 0x03, 0x00, 0x00, 0x00};
785 +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
786 + 0x02, 0x00, 0x02, 0x00, 0x00};
788 +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
791 +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
794 +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
796 +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
797 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
799 +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
802 +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
804 +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
807 +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
809 +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
810 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
812 +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
815 +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
817 +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
820 +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
822 +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
823 + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
825 +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
828 +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
830 +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
833 +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
835 +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
836 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
838 +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
841 +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
843 +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
846 +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
848 +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
849 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
851 +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
854 +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
858 +static const struct usb_descriptor_header *z_function [] = {
859 + (struct usb_descriptor_header *) &z_audio_control_if_desc,
860 + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
861 + (struct usb_descriptor_header *) &z_0,
862 + (struct usb_descriptor_header *) &z_1,
863 + (struct usb_descriptor_header *) &z_2,
864 + (struct usb_descriptor_header *) &z_audio_if_desc,
865 + (struct usb_descriptor_header *) &z_audio_if_desc2,
866 + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
867 + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
868 + (struct usb_descriptor_header *) &z_iso_ep,
869 + (struct usb_descriptor_header *) &z_iso_ep2,
870 + (struct usb_descriptor_header *) &za_0,
871 + (struct usb_descriptor_header *) &za_1,
872 + (struct usb_descriptor_header *) &za_2,
873 + (struct usb_descriptor_header *) &za_3,
874 + (struct usb_descriptor_header *) &za_4,
875 + (struct usb_descriptor_header *) &za_5,
876 + (struct usb_descriptor_header *) &za_6,
877 + (struct usb_descriptor_header *) &za_7,
878 + (struct usb_descriptor_header *) &za_8,
879 + (struct usb_descriptor_header *) &za_9,
880 + (struct usb_descriptor_header *) &za_10,
881 + (struct usb_descriptor_header *) &za_11,
882 + (struct usb_descriptor_header *) &za_12,
883 + (struct usb_descriptor_header *) &za_13,
884 + (struct usb_descriptor_header *) &za_14,
885 + (struct usb_descriptor_header *) &za_15,
886 + (struct usb_descriptor_header *) &za_16,
887 + (struct usb_descriptor_header *) &za_17,
888 + (struct usb_descriptor_header *) &za_18,
889 + (struct usb_descriptor_header *) &za_19,
890 + (struct usb_descriptor_header *) &za_20,
891 + (struct usb_descriptor_header *) &za_21,
892 + (struct usb_descriptor_header *) &za_22,
893 + (struct usb_descriptor_header *) &za_23,
894 + (struct usb_descriptor_header *) &za_24,
898 +/* maxpacket and other transfer characteristics vary by speed. */
899 +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
903 +/* if there's no high speed support, maxpacket doesn't change. */
904 +#define ep_desc(g,hs,fs) fs
906 +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
908 +static char manufacturer [40];
909 +//static char serial [40];
910 +static char serial [] = "Ser 00 em";
912 +/* static strings, in UTF-8 */
913 +static struct usb_string strings [] = {
914 + { STRING_MANUFACTURER, manufacturer, },
915 + { STRING_PRODUCT, longname, },
916 + { STRING_SERIAL, serial, },
917 + { STRING_LOOPBACK, loopback, },
918 + { STRING_SOURCE_SINK, source_sink, },
919 + { } /* end of list */
922 +static struct usb_gadget_strings stringtab = {
923 + .language = 0x0409, /* en-us */
924 + .strings = strings,
928 + * config descriptors are also handcrafted. these must agree with code
929 + * that sets configurations, and with code managing interfaces and their
930 + * altsettings. other complexity may come from:
932 + * - high speed support, including "other speed config" rules
933 + * - multiple configurations
934 + * - interfaces with alternate settings
935 + * - embedded class or vendor-specific descriptors
937 + * this handles high speed, and has a second config that could as easily
938 + * have been an alternate interface setting (on most hardware).
940 + * NOTE: to demonstrate (and test) more USB capabilities, this driver
941 + * should include an altsetting to test interrupt transfers, including
942 + * high bandwidth modes at high speed. (Maybe work like Intel's test
946 +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
949 + const struct usb_descriptor_header **function;
951 + function = z_function;
952 + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
955 + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
959 +/*-------------------------------------------------------------------------*/
961 +static struct usb_request *
962 +alloc_ep_req (struct usb_ep *ep, unsigned length)
964 + struct usb_request *req;
966 + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
968 + req->length = length;
969 + req->buf = usb_ep_alloc_buffer (ep, length,
970 + &req->dma, GFP_ATOMIC);
972 + usb_ep_free_request (ep, req);
979 +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
982 + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
983 + usb_ep_free_request (ep, req);
986 +/*-------------------------------------------------------------------------*/
988 +/* optionally require specific source/sink data patterns */
992 + struct zero_dev *dev,
994 + struct usb_request *req
998 + u8 *buf = req->buf;
1000 + for (i = 0; i < req->actual; i++, buf++) {
1001 + switch (pattern) {
1002 + /* all-zeroes has no synchronization issues */
1007 + /* mod63 stays in sync with short-terminated transfers,
1008 + * or otherwise when host and gadget agree on how large
1009 + * each usb transfer request should be. resync is done
1010 + * with set_interface or set_config.
1013 + if (*buf == (u8)(i % 63))
1017 + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
1018 + usb_ep_set_halt (ep);
1024 +/*-------------------------------------------------------------------------*/
1026 +static void zero_reset_config (struct zero_dev *dev)
1028 + if (dev->config == 0)
1031 + DBG (dev, "reset config\n");
1033 + /* just disable endpoints, forcing completion of pending i/o.
1034 + * all our completion handlers free their requests in this case.
1037 + usb_ep_disable (dev->in_ep);
1038 + dev->in_ep = NULL;
1040 + if (dev->out_ep) {
1041 + usb_ep_disable (dev->out_ep);
1042 + dev->out_ep = NULL;
1045 + del_timer (&dev->resume);
1048 +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
1051 +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
1053 + struct zero_dev *dev = ep->driver_data;
1054 + int status = req->status;
1059 + case 0: /* normal completion? */
1060 + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
1061 + for (i=0, j=rbuf_start; i<req->actual; i++) {
1062 + //printk ("%02x ", ((__u8*)req->buf)[i]);
1063 + rbuf[j] = ((__u8*)req->buf)[i];
1065 + if (j >= RBUF_LEN) j=0;
1068 + //printk ("\n\n");
1070 + if (rbuf_len < RBUF_LEN) {
1071 + rbuf_len += req->actual;
1072 + if (rbuf_len > RBUF_LEN) {
1073 + rbuf_len = RBUF_LEN;
1079 + /* this endpoint is normally active while we're configured */
1080 + case -ECONNABORTED: /* hardware forced ep reset */
1081 + case -ECONNRESET: /* request dequeued */
1082 + case -ESHUTDOWN: /* disconnect from host */
1083 + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
1084 + req->actual, req->length);
1085 + if (ep == dev->out_ep)
1086 + check_read_data (dev, ep, req);
1087 + free_ep_req (ep, req);
1090 + case -EOVERFLOW: /* buffer overrun on read means that
1091 + * we didn't provide a big enough
1096 + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
1097 + status, req->actual, req->length);
1099 + case -EREMOTEIO: /* short read */
1103 + status = usb_ep_queue (ep, req, GFP_ATOMIC);
1105 + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
1106 + ep->name, req->length, status);
1107 + usb_ep_set_halt (ep);
1108 + /* FIXME recover later ... somehow */
1112 +static struct usb_request *
1113 +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
1115 + struct usb_request *req;
1118 + req = alloc_ep_req (ep, 512);
1122 + req->complete = zero_isoc_complete;
1124 + status = usb_ep_queue (ep, req, gfp_flags);
1126 + struct zero_dev *dev = ep->driver_data;
1128 + ERROR (dev, "start %s --> %d\n", ep->name, status);
1129 + free_ep_req (ep, req);
1136 +/* change our operational config. this code must agree with the code
1137 + * that returns config descriptors, and altsetting code.
1139 + * it's also responsible for power management interactions. some
1140 + * configurations might not work with our current power sources.
1142 + * note that some device controller hardware will constrain what this
1143 + * code can do, perhaps by disallowing more than one configuration or
1144 + * by limiting configuration choices (like the pxa2xx).
1147 +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
1150 + struct usb_gadget *gadget = dev->gadget;
1151 + const struct usb_endpoint_descriptor *d;
1152 + struct usb_ep *ep;
1154 + if (number == dev->config)
1157 + zero_reset_config (dev);
1159 + gadget_for_each_ep (ep, gadget) {
1161 + if (strcmp (ep->name, "ep4") == 0) {
1163 + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
1164 + result = usb_ep_enable (ep, d);
1166 + if (result == 0) {
1167 + ep->driver_data = dev;
1170 + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
1176 + usb_ep_disable (ep);
1183 + dev->config = number;
1187 +/*-------------------------------------------------------------------------*/
1189 +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
1191 + if (req->status || req->actual != req->length)
1192 + DBG ((struct zero_dev *) ep->driver_data,
1193 + "setup complete --> %d, %d/%d\n",
1194 + req->status, req->actual, req->length);
1198 + * The setup() callback implements all the ep0 functionality that's
1199 + * not handled lower down, in hardware or the hardware driver (like
1200 + * device and endpoint feature flags, and their status). It's all
1201 + * housekeeping for the gadget function we're implementing. Most of
1202 + * the work is in config-specific setup.
1205 +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1207 + struct zero_dev *dev = get_gadget_data (gadget);
1208 + struct usb_request *req = dev->req;
1209 + int value = -EOPNOTSUPP;
1211 + /* usually this stores reply data in the pre-allocated ep0 buffer,
1212 + * but config change events will reconfigure hardware.
1215 + switch (ctrl->bRequest) {
1217 + case USB_REQ_GET_DESCRIPTOR:
1219 + switch (ctrl->wValue >> 8) {
1221 + case USB_DT_DEVICE:
1222 + value = min (ctrl->wLength, (u16) sizeof device_desc);
1223 + memcpy (req->buf, &device_desc, value);
1225 +#ifdef CONFIG_USB_GADGET_DUALSPEED
1226 + case USB_DT_DEVICE_QUALIFIER:
1227 + if (!gadget->is_dualspeed)
1229 + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
1230 + memcpy (req->buf, &dev_qualifier, value);
1233 + case USB_DT_OTHER_SPEED_CONFIG:
1234 + if (!gadget->is_dualspeed)
1237 +#endif /* CONFIG_USB_GADGET_DUALSPEED */
1238 + case USB_DT_CONFIG:
1239 + value = config_buf (gadget, req->buf,
1240 + ctrl->wValue >> 8,
1241 + ctrl->wValue & 0xff);
1243 + value = min (ctrl->wLength, (u16) value);
1246 + case USB_DT_STRING:
1247 + /* wIndex == language code.
1248 + * this driver only handles one language, you can
1249 + * add string tables for other languages, using
1250 + * any UTF-8 characters
1252 + value = usb_gadget_get_string (&stringtab,
1253 + ctrl->wValue & 0xff, req->buf);
1255 + value = min (ctrl->wLength, (u16) value);
1261 + /* currently two configs, two speeds */
1262 + case USB_REQ_SET_CONFIGURATION:
1263 + if (ctrl->bRequestType != 0)
1266 + spin_lock (&dev->lock);
1267 + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
1268 + spin_unlock (&dev->lock);
1270 + case USB_REQ_GET_CONFIGURATION:
1271 + if (ctrl->bRequestType != USB_DIR_IN)
1273 + *(u8 *)req->buf = dev->config;
1274 + value = min (ctrl->wLength, (u16) 1);
1277 + /* until we add altsetting support, or other interfaces,
1278 + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
1279 + * and already killed pending endpoint I/O.
1281 + case USB_REQ_SET_INTERFACE:
1283 + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
1285 + spin_lock (&dev->lock);
1286 + if (dev->config) {
1287 + u8 config = dev->config;
1289 + /* resets interface configuration, forgets about
1290 + * previous transaction state (queued bufs, etc)
1291 + * and re-inits endpoint state (toggle etc)
1292 + * no response queued, just zero status == success.
1293 + * if we had more than one interface we couldn't
1294 + * use this "reset the config" shortcut.
1296 + zero_reset_config (dev);
1297 + zero_set_config (dev, config, GFP_ATOMIC);
1300 + spin_unlock (&dev->lock);
1302 + case USB_REQ_GET_INTERFACE:
1303 + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
1304 + value = ctrl->wLength;
1308 + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
1312 + if (ctrl->wIndex != 0) {
1316 + *(u8 *)req->buf = 0;
1317 + value = min (ctrl->wLength, (u16) 1);
1322 + * These are the same vendor-specific requests supported by
1323 + * Intel's USB 2.0 compliance test devices. We exceed that
1324 + * device spec by allowing multiple-packet requests.
1326 + case 0x5b: /* control WRITE test -- fill the buffer */
1327 + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
1329 + if (ctrl->wValue || ctrl->wIndex)
1331 + /* just read that many bytes into the buffer */
1332 + if (ctrl->wLength > USB_BUFSIZ)
1334 + value = ctrl->wLength;
1336 + case 0x5c: /* control READ test -- return the buffer */
1337 + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
1339 + if (ctrl->wValue || ctrl->wIndex)
1341 + /* expect those bytes are still in the buffer; send back */
1342 + if (ctrl->wLength > USB_BUFSIZ
1343 + || ctrl->wLength != req->length)
1345 + value = ctrl->wLength;
1348 + case 0x01: // SET_CUR
1353 + value = ctrl->wLength;
1356 + switch (ctrl->wValue) {
1359 + ((u8*)req->buf)[0] = 0x00;
1360 + ((u8*)req->buf)[1] = 0xe3;
1364 + ((u8*)req->buf)[0] = 0x00;
1367 + //((u8*)req->buf)[0] = 0x81;
1368 + //((u8*)req->buf)[1] = 0x81;
1369 + value = ctrl->wLength;
1372 + switch (ctrl->wValue) {
1375 + ((u8*)req->buf)[0] = 0x00;
1376 + ((u8*)req->buf)[1] = 0xc3;
1380 + ((u8*)req->buf)[0] = 0x00;
1383 + //((u8*)req->buf)[0] = 0x82;
1384 + //((u8*)req->buf)[1] = 0x82;
1385 + value = ctrl->wLength;
1388 + switch (ctrl->wValue) {
1391 + ((u8*)req->buf)[0] = 0x00;
1392 + ((u8*)req->buf)[1] = 0x00;
1395 + ((u8*)req->buf)[0] = 0x60;
1398 + ((u8*)req->buf)[0] = 0x18;
1401 + //((u8*)req->buf)[0] = 0x83;
1402 + //((u8*)req->buf)[1] = 0x83;
1403 + value = ctrl->wLength;
1406 + switch (ctrl->wValue) {
1409 + ((u8*)req->buf)[0] = 0x00;
1410 + ((u8*)req->buf)[1] = 0x01;
1414 + ((u8*)req->buf)[0] = 0x08;
1417 + //((u8*)req->buf)[0] = 0x84;
1418 + //((u8*)req->buf)[1] = 0x84;
1419 + value = ctrl->wLength;
1422 + ((u8*)req->buf)[0] = 0x85;
1423 + ((u8*)req->buf)[1] = 0x85;
1424 + value = ctrl->wLength;
1430 + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
1431 + ctrl->bRequestType, ctrl->bRequest,
1432 + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
1435 + /* respond with data transfer before status phase? */
1437 + req->length = value;
1438 + req->zero = value < ctrl->wLength
1439 + && (value % gadget->ep0->maxpacket) == 0;
1440 + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
1442 + DBG (dev, "ep_queue < 0 --> %d\n", value);
1444 + zero_setup_complete (gadget->ep0, req);
1448 + /* device either stalls (value < 0) or reports success */
1453 +zero_disconnect (struct usb_gadget *gadget)
1455 + struct zero_dev *dev = get_gadget_data (gadget);
1456 + unsigned long flags;
1458 + spin_lock_irqsave (&dev->lock, flags);
1459 + zero_reset_config (dev);
1461 + /* a more significant application might have some non-usb
1462 + * activities to quiesce here, saving resources like power
1463 + * or pushing the notification up a network stack.
1465 + spin_unlock_irqrestore (&dev->lock, flags);
1467 + /* next we may get setup() calls to enumerate new connections;
1468 + * or an unbind() during shutdown (including removing module).
1473 +zero_autoresume (unsigned long _dev)
1475 + struct zero_dev *dev = (struct zero_dev *) _dev;
1478 + /* normally the host would be woken up for something
1479 + * more significant than just a timer firing...
1481 + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
1482 + status = usb_gadget_wakeup (dev->gadget);
1483 + DBG (dev, "wakeup --> %d\n", status);
1487 +/*-------------------------------------------------------------------------*/
1490 +zero_unbind (struct usb_gadget *gadget)
1492 + struct zero_dev *dev = get_gadget_data (gadget);
1494 + DBG (dev, "unbind\n");
1496 + /* we've already been disconnected ... no i/o is active */
1498 + free_ep_req (gadget->ep0, dev->req);
1499 + del_timer_sync (&dev->resume);
1501 + set_gadget_data (gadget, NULL);
1505 +zero_bind (struct usb_gadget *gadget)
1507 + struct zero_dev *dev;
1508 + //struct usb_ep *ep;
1510 + printk("binding\n");
1512 + * DRIVER POLICY CHOICE: you may want to do this differently.
1513 + * One thing to avoid is reusing a bcdDevice revision code
1514 + * with different host-visible configurations or behavior
1515 + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
1517 + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
1520 + /* ok, we made sense of the hardware ... */
1521 + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
1524 + memset (dev, 0, sizeof *dev);
1525 + spin_lock_init (&dev->lock);
1526 + dev->gadget = gadget;
1527 + set_gadget_data (gadget, dev);
1529 + /* preallocate control response and buffer */
1530 + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
1533 + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
1534 + &dev->req->dma, GFP_KERNEL);
1535 + if (!dev->req->buf)
1538 + dev->req->complete = zero_setup_complete;
1540 + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1542 +#ifdef CONFIG_USB_GADGET_DUALSPEED
1543 + /* assume ep0 uses the same value for both speeds ... */
1544 + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
1546 + /* and that all endpoints are dual-speed */
1547 + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
1548 + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
1551 + usb_gadget_set_selfpowered (gadget);
1553 + init_timer (&dev->resume);
1554 + dev->resume.function = zero_autoresume;
1555 + dev->resume.data = (unsigned long) dev;
1557 + gadget->ep0->driver_data = dev;
1559 + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
1560 + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
1561 + EP_OUT_NAME, EP_IN_NAME);
1563 + snprintf (manufacturer, sizeof manufacturer,
1564 + UTS_SYSNAME " " UTS_RELEASE " with %s",
1570 + zero_unbind (gadget);
1574 +/*-------------------------------------------------------------------------*/
1577 +zero_suspend (struct usb_gadget *gadget)
1579 + struct zero_dev *dev = get_gadget_data (gadget);
1581 + if (gadget->speed == USB_SPEED_UNKNOWN)
1585 + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
1586 + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
1588 + DBG (dev, "suspend\n");
1592 +zero_resume (struct usb_gadget *gadget)
1594 + struct zero_dev *dev = get_gadget_data (gadget);
1596 + DBG (dev, "resume\n");
1597 + del_timer (&dev->resume);
1601 +/*-------------------------------------------------------------------------*/
1603 +static struct usb_gadget_driver zero_driver = {
1604 +#ifdef CONFIG_USB_GADGET_DUALSPEED
1605 + .speed = USB_SPEED_HIGH,
1607 + .speed = USB_SPEED_FULL,
1609 + .function = (char *) longname,
1610 + .bind = zero_bind,
1611 + .unbind = zero_unbind,
1613 + .setup = zero_setup,
1614 + .disconnect = zero_disconnect,
1616 + .suspend = zero_suspend,
1617 + .resume = zero_resume,
1620 + .name = (char *) shortname,
1621 + // .shutdown = ...
1627 +MODULE_AUTHOR ("David Brownell");
1628 +MODULE_LICENSE ("Dual BSD/GPL");
1630 +static struct proc_dir_entry *pdir, *pfile;
1632 +static int isoc_read_data (char *page, char **start,
1633 + off_t off, int count,
1634 + int *eof, void *data)
1638 + static int done = 0;
1642 + printk ("\ncount: %d\n", count);
1643 + printk ("rbuf_start: %d\n", rbuf_start);
1644 + printk ("rbuf_len: %d\n", rbuf_len);
1645 + printk ("off: %d\n", off);
1646 + printk ("start: %p\n\n", *start);
1656 + if (rbuf_len == RBUF_LEN)
1661 + for (i=0; i<count && c<rbuf_len; i++, c++) {
1662 + page[i] = rbuf[(c+s) % RBUF_LEN];
1666 + if (c >= rbuf_len) {
1675 +static int __init init (void)
1680 + pdir = proc_mkdir("isoc_test", NULL);
1681 + if(pdir == NULL) {
1683 + printk("Error creating dir\n");
1686 + pdir->owner = THIS_MODULE;
1688 + pfile = create_proc_read_entry("isoc_data",
1692 + if (pfile == NULL) {
1694 + printk("Error creating file\n");
1697 + pfile->owner = THIS_MODULE;
1699 + return usb_gadget_register_driver (&zero_driver);
1702 + remove_proc_entry("isoc_data", NULL);
1706 +module_init (init);
1708 +static void __exit cleanup (void)
1711 + usb_gadget_unregister_driver (&zero_driver);
1713 + remove_proc_entry("isoc_data", pdir);
1714 + remove_proc_entry("isoc_test", NULL);
1716 +module_exit (cleanup);
1717 diff --git a/drivers/usb/dwc_otg/dwc_otg_attr.c b/drivers/usb/dwc_otg/dwc_otg_attr.c
1718 new file mode 100644
1719 index 0000000..8543537
1721 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.c
1723 +/* ==========================================================================
1724 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
1725 + * $Revision: 1.2 $
1726 + * $Date: 2008-11-21 05:39:15 $
1727 + * $Change: 1064918 $
1729 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
1730 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
1731 + * otherwise expressly agreed to in writing between Synopsys and you.
1733 + * The Software IS NOT an item of Licensed Software or Licensed Product under
1734 + * any End User Software License Agreement or Agreement for Licensed Product
1735 + * with Synopsys or any supplement thereto. You are permitted to use and
1736 + * redistribute this Software in source and binary forms, with or without
1737 + * modification, provided that redistributions of source code must retain this
1738 + * notice. You may not view, use, disclose, copy or distribute this file or
1739 + * any information contained herein except pursuant to this license grant from
1740 + * Synopsys. If you do not agree with this notice, including the disclaimer
1741 + * below, then you are not authorized to use the Software.
1743 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
1744 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1745 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1746 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
1747 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1748 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1749 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1750 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1751 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1752 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1754 + * ========================================================================== */
1758 + * The diagnostic interface will provide access to the controller for
1759 + * bringing up the hardware and testing. The Linux driver attributes
1760 + * feature will be used to provide the Linux Diagnostic
1761 + * Interface. These attributes are accessed through sysfs.
1764 +/** @page "Linux Module Attributes"
1766 + * The Linux module attributes feature is used to provide the Linux
1767 + * Diagnostic Interface. These attributes are accessed through sysfs.
1768 + * The diagnostic interface will provide access to the controller for
1769 + * bringing up the hardware and testing.
1772 + The following table shows the attributes.
1775 + <td><b> Name</b></td>
1776 + <td><b> Description</b></td>
1777 + <td><b> Access</b></td>
1782 + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
1787 + <td> hnpcapable </td>
1788 + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
1789 + Read returns the current value.</td>
1790 + <td> Read/Write</td>
1794 + <td> srpcapable </td>
1795 + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
1796 + Read returns the current value.</td>
1797 + <td> Read/Write</td>
1802 + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
1803 + <td> Read/Write</td>
1808 + <td> Initiates the Session Request Protocol. Read returns the status.</td>
1809 + <td> Read/Write</td>
1813 + <td> buspower </td>
1814 + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
1815 + <td> Read/Write</td>
1819 + <td> bussuspend </td>
1820 + <td> Suspends the USB bus.</td>
1821 + <td> Read/Write</td>
1825 + <td> busconnected </td>
1826 + <td> Gets the connection status of the bus</td>
1831 + <td> gotgctl </td>
1832 + <td> Gets or sets the Core Control Status Register.</td>
1833 + <td> Read/Write</td>
1837 + <td> gusbcfg </td>
1838 + <td> Gets or sets the Core USB Configuration Register</td>
1839 + <td> Read/Write</td>
1843 + <td> grxfsiz </td>
1844 + <td> Gets or sets the Receive FIFO Size Register</td>
1845 + <td> Read/Write</td>
1849 + <td> gnptxfsiz </td>
1850 + <td> Gets or sets the non-periodic Transmit Size Register</td>
1851 + <td> Read/Write</td>
1855 + <td> gpvndctl </td>
1856 + <td> Gets or sets the PHY Vendor Control Register</td>
1857 + <td> Read/Write</td>
1862 + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
1863 + or sets the upper 16 bits.</td>
1864 + <td> Read/Write</td>
1869 + <td> Gets or sets the value of the User ID Register</td>
1870 + <td> Read/Write</td>
1874 + <td> gsnpsid </td>
1875 + <td> Gets the value of the Synopsys ID Regester</td>
1880 + <td> devspeed </td>
1881 + <td> Gets or sets the device speed setting in the DCFG register</td>
1882 + <td> Read/Write</td>
1886 + <td> enumspeed </td>
1887 + <td> Gets the device enumeration Speed.</td>
1892 + <td> hptxfsiz </td>
1893 + <td> Gets the value of the Host Periodic Transmit FIFO</td>
1899 + <td> Gets or sets the value in the Host Port Control and Status Register</td>
1900 + <td> Read/Write</td>
1904 + <td> regoffset </td>
1905 + <td> Sets the register offset for the next Register Access</td>
1906 + <td> Read/Write</td>
1910 + <td> regvalue </td>
1911 + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
1912 + <td> Read/Write</td>
1916 + <td> remote_wakeup </td>
1917 + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
1918 + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
1919 + Wakeup signalling bit in the Device Control Register is set for 1
1920 + milli-second.</td>
1921 + <td> Read/Write</td>
1925 + <td> regdump </td>
1926 + <td> Dumps the contents of core registers.</td>
1931 + <td> spramdump </td>
1932 + <td> Dumps the contents of core registers.</td>
1937 + <td> hcddump </td>
1938 + <td> Dumps the current HCD state.</td>
1943 + <td> hcd_frrem </td>
1944 + <td> Shows the average value of the Frame Remaining
1945 + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
1946 + occurs. This can be used to determine the average interrupt latency. Also
1947 + shows the average Frame Remaining value for start_transfer and the "a" and
1948 + "b" sample points. The "a" and "b" sample points may be used during debugging
1949 + bto determine how long it takes to execute a section of the HCD code.</td>
1954 + <td> rd_reg_test </td>
1955 + <td> Displays the time required to read the GNPTXFSIZ register many times
1956 + (the output shows the number of times the register is read).
1961 + <td> wr_reg_test </td>
1962 + <td> Displays the time required to write the GNPTXFSIZ register many times
1963 + (the output shows the number of times the register is written).
1970 + To get the current mode:
1971 + cat /sys/devices/lm0/mode
1973 + To power down the USB:
1974 + echo 0 > /sys/devices/lm0/buspower
1977 +#include <linux/kernel.h>
1978 +#include <linux/module.h>
1979 +#include <linux/moduleparam.h>
1980 +#include <linux/init.h>
1981 +#include <linux/device.h>
1982 +#include <linux/errno.h>
1983 +#include <linux/types.h>
1984 +#include <linux/stat.h> /* permission constants */
1985 +#include <linux/version.h>
1987 +#include <asm/io.h>
1989 +#include "linux/dwc_otg_plat.h"
1990 +#include "dwc_otg_attr.h"
1991 +#include "dwc_otg_driver.h"
1992 +#include "dwc_otg_pcd.h"
1993 +#include "dwc_otg_hcd.h"
1995 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1997 + * MACROs for defining sysfs attribute
1999 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2000 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
2002 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
2004 + val = dwc_read_reg32 (_addr_); \
2005 + val = (val & (_mask_)) >> _shift_; \
2006 + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
2008 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2009 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
2010 + const char *buf, size_t count) \
2012 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
2013 + uint32_t set = simple_strtoul(buf, NULL, 16); \
2014 + uint32_t clear = set; \
2015 + clear = ((~clear) << _shift_) & _mask_; \
2016 + set = (set << _shift_) & _mask_; \
2017 + dev_dbg(_dev, "Storing Address=0x%08x Set=0x%08x Clear=0x%08x\n", (uint32_t)_addr_, set, clear); \
2018 + dwc_modify_reg32(_addr_, clear, set); \
2023 + * MACROs for defining sysfs attribute for 32-bit registers
2025 +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2026 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
2028 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
2030 + val = dwc_read_reg32 (_addr_); \
2031 + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
2033 +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
2034 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
2035 + const char *buf, size_t count) \
2037 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
2038 + uint32_t val = simple_strtoul(buf, NULL, 16); \
2039 + dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \
2040 + dwc_write_reg32(_addr_, val); \
2047 + * MACROs for defining sysfs attribute
2049 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2050 +static ssize_t _otg_attr_name_##_show (struct device *_dev, char *buf) \
2052 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2054 + val = dwc_read_reg32 (_addr_); \
2055 + val = (val & (_mask_)) >> _shift_; \
2056 + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
2058 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2059 +static ssize_t _otg_attr_name_##_store (struct device *_dev, const char *buf, size_t count) \
2061 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2062 + uint32_t set = simple_strtoul(buf, NULL, 16); \
2063 + uint32_t clear = set; \
2064 + clear = ((~clear) << _shift_) & _mask_; \
2065 + set = (set << _shift_) & _mask_; \
2066 + dev_dbg(_dev, "Storing Address=0x%08x Set=0x%08x Clear=0x%08x\n", (uint32_t)_addr_, set, clear); \
2067 + dwc_modify_reg32(_addr_, clear, set); \
2072 + * MACROs for defining sysfs attribute for 32-bit registers
2074 +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2075 +static ssize_t _otg_attr_name_##_show (struct device *_dev, char *buf) \
2077 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2079 + val = dwc_read_reg32 (_addr_); \
2080 + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
2082 +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
2083 +static ssize_t _otg_attr_name_##_store (struct device *_dev, const char *buf, size_t count) \
2085 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2086 + uint32_t val = simple_strtoul(buf, NULL, 16); \
2087 + dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \
2088 + dwc_write_reg32(_addr_, val); \
2094 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2095 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2096 +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2097 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
2099 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2100 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2101 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
2103 +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
2104 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2105 +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
2106 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
2108 +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
2109 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2110 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
2113 +/** @name Functions for Show/Store of Attributes */
2117 + * Show the register offset of the Register Access.
2119 +static ssize_t regoffset_show( struct device *_dev,
2120 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2121 + struct device_attribute *attr,
2125 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2126 + return snprintf(buf, sizeof("0xFFFFFFFF\n")+1,"0x%08x\n", otg_dev->reg_offset);
2130 + * Set the register offset for the next Register Access Read/Write
2132 +static ssize_t regoffset_store( struct device *_dev,
2133 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2134 + struct device_attribute *attr,
2139 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2141 + uint32_t offset = simple_strtoul(buf, NULL, 16);
2142 + //dev_dbg(_dev, "Offset=0x%08x\n", offset);
2143 + if (offset < 0x00040000 ) {
2144 + otg_dev->reg_offset = offset;
2147 + dev_err( _dev, "invalid offset\n" );
2152 +DEVICE_ATTR(regoffset, S_IRUGO|S_IWUSR, (void *)regoffset_show, regoffset_store);
2156 + * Show the value of the register at the offset in the reg_offset
2159 +static ssize_t regvalue_show( struct device *_dev,
2160 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2161 + struct device_attribute *attr,
2165 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2168 + volatile uint32_t *addr;
2170 + if (otg_dev->reg_offset != 0xFFFFFFFF &&
2171 + 0 != otg_dev->base) {
2172 + /* Calculate the address */
2173 + addr = (uint32_t*)(otg_dev->reg_offset +
2174 + (uint8_t*)otg_dev->base);
2175 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
2176 + val = dwc_read_reg32( addr );
2177 + return snprintf(buf, sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n")+1,
2178 + "Reg@0x%06x = 0x%08x\n",
2179 + otg_dev->reg_offset, val);
2182 + dev_err(_dev, "Invalid offset (0x%0x)\n",
2183 + otg_dev->reg_offset);
2184 + return sprintf(buf, "invalid offset\n" );
2189 + * Store the value in the register at the offset in the reg_offset
2193 +static ssize_t regvalue_store( struct device *_dev,
2194 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2195 + struct device_attribute *attr,
2200 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2202 + volatile uint32_t * addr;
2203 + uint32_t val = simple_strtoul(buf, NULL, 16);
2204 + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
2205 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
2206 + /* Calculate the address */
2207 + addr = (uint32_t*)(otg_dev->reg_offset +
2208 + (uint8_t*)otg_dev->base);
2209 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
2210 + dwc_write_reg32( addr, val );
2213 + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
2214 + otg_dev->reg_offset);
2218 +DEVICE_ATTR(regvalue, S_IRUGO|S_IWUSR, regvalue_show, regvalue_store);
2223 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<20),20,"Mode");
2224 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<9),9,"Mode");
2225 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<8),8,"Mode");
2227 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
2228 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
2229 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected,otg_dev->core_if->host_if->hprt0,0x01,0,"Bus Connected");
2231 +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl,&(otg_dev->core_if->core_global_regs->gotgctl),"GOTGCTL");
2232 +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,&(otg_dev->core_if->core_global_regs->gusbcfg),"GUSBCFG");
2233 +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,&(otg_dev->core_if->core_global_regs->grxfsiz),"GRXFSIZ");
2234 +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,&(otg_dev->core_if->core_global_regs->gnptxfsiz),"GNPTXFSIZ");
2235 +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,&(otg_dev->core_if->core_global_regs->gpvndctl),"GPVNDCTL");
2236 +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,&(otg_dev->core_if->core_global_regs->ggpio),"GGPIO");
2237 +DWC_OTG_DEVICE_ATTR_REG32_RW(guid,&(otg_dev->core_if->core_global_regs->guid),"GUID");
2238 +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,&(otg_dev->core_if->core_global_regs->gsnpsid),"GSNPSID");
2239 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dcfg),0x3,0,"Device Speed");
2240 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dsts),0x6,1,"Device Enumeration Speed");
2242 +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,&(otg_dev->core_if->core_global_regs->hptxfsiz),"HPTXFSIZ");
2243 +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0,otg_dev->core_if->host_if->hprt0,"HPRT0");
2247 + * @todo Add code to initiate the HNP.
2250 + * Show the HNP status bit
2252 +static ssize_t hnp_show( struct device *_dev,
2253 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2254 + struct device_attribute *attr,
2258 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2260 + gotgctl_data_t val;
2261 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
2262 + return sprintf (buf, "HstNegScs = 0x%x\n", val.b.hstnegscs);
2266 + * Set the HNP Request bit
2268 +static ssize_t hnp_store( struct device *_dev,
2269 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2270 + struct device_attribute *attr,
2275 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2277 + uint32_t in = simple_strtoul(buf, NULL, 16);
2278 + uint32_t *addr = (uint32_t *)&(otg_dev->core_if->core_global_regs->gotgctl);
2279 + gotgctl_data_t mem;
2280 + mem.d32 = dwc_read_reg32(addr);
2281 + mem.b.hnpreq = in;
2282 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
2283 + dwc_write_reg32(addr, mem.d32);
2286 +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
2289 + * @todo Add code to initiate the SRP.
2292 + * Show the SRP status bit
2294 +static ssize_t srp_show( struct device *_dev,
2295 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2296 + struct device_attribute *attr,
2300 +#ifndef DWC_HOST_ONLY
2301 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2303 + gotgctl_data_t val;
2304 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
2305 + return sprintf (buf, "SesReqScs = 0x%x\n", val.b.sesreqscs);
2307 + return sprintf(buf, "Host Only Mode!\n");
2314 + * Set the SRP Request bit
2316 +static ssize_t srp_store( struct device *_dev,
2317 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2318 + struct device_attribute *attr,
2323 +#ifndef DWC_HOST_ONLY
2324 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2326 + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
2330 +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
2333 + * @todo Need to do more for power on/off?
2336 + * Show the Bus Power status
2338 +static ssize_t buspower_show( struct device *_dev,
2339 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2340 + struct device_attribute *attr,
2344 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2347 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
2348 + return sprintf (buf, "Bus Power = 0x%x\n", val.b.prtpwr);
2353 + * Set the Bus Power status
2355 +static ssize_t buspower_store( struct device *_dev,
2356 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2357 + struct device_attribute *attr,
2362 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2364 + uint32_t on = simple_strtoul(buf, NULL, 16);
2365 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
2368 + mem.d32 = dwc_read_reg32(addr);
2369 + mem.b.prtpwr = on;
2371 + //dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
2372 + dwc_write_reg32(addr, mem.d32);
2376 +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
2379 + * @todo Need to do more for suspend?
2382 + * Show the Bus Suspend status
2384 +static ssize_t bussuspend_show( struct device *_dev,
2385 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2386 + struct device_attribute *attr,
2390 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2393 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
2394 + return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
2398 + * Set the Bus Suspend status
2400 +static ssize_t bussuspend_store( struct device *_dev,
2401 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2402 + struct device_attribute *attr,
2407 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2409 + uint32_t in = simple_strtoul(buf, NULL, 16);
2410 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
2412 + mem.d32 = dwc_read_reg32(addr);
2413 + mem.b.prtsusp = in;
2414 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
2415 + dwc_write_reg32(addr, mem.d32);
2418 +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
2421 + * Show the status of Remote Wakeup.
2423 +static ssize_t remote_wakeup_show( struct device *_dev,
2424 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2425 + struct device_attribute *attr,
2429 +#ifndef DWC_HOST_ONLY
2430 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2434 + dwc_read_reg32( &otg_dev->core_if->dev_if->dev_global_regs->dctl);
2435 + return sprintf( buf, "Remote Wakeup = %d Enabled = %d\n",
2436 + val.b.rmtwkupsig, otg_dev->pcd->remote_wakeup_enable);
2438 + return sprintf(buf, "Host Only Mode!\n");
2442 + * Initiate a remote wakeup of the host. The Device control register
2443 + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
2447 +static ssize_t remote_wakeup_store( struct device *_dev,
2448 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2449 + struct device_attribute *attr,
2454 +#ifndef DWC_HOST_ONLY
2455 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2457 + uint32_t val = simple_strtoul(buf, NULL, 16);
2459 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
2462 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
2467 +DEVICE_ATTR(remote_wakeup, S_IRUGO|S_IWUSR, remote_wakeup_show,
2468 + remote_wakeup_store);
2471 + * Dump global registers and either host or device registers (depending on the
2472 + * current mode of the core).
2474 +static ssize_t regdump_show( struct device *_dev,
2475 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2476 + struct device_attribute *attr,
2480 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2482 + dwc_otg_dump_global_registers( otg_dev->core_if);
2483 + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
2484 + dwc_otg_dump_host_registers( otg_dev->core_if);
2486 + dwc_otg_dump_dev_registers( otg_dev->core_if);
2489 + return sprintf( buf, "Register Dump\n" );
2492 +DEVICE_ATTR(regdump, S_IRUGO|S_IWUSR, regdump_show, 0);
2495 + * Dump global registers and either host or device registers (depending on the
2496 + * current mode of the core).
2498 +static ssize_t spramdump_show( struct device *_dev,
2499 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2500 + struct device_attribute *attr,
2504 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2506 + dwc_otg_dump_spram( otg_dev->core_if);
2508 + return sprintf( buf, "SPRAM Dump\n" );
2511 +DEVICE_ATTR(spramdump, S_IRUGO|S_IWUSR, spramdump_show, 0);
2514 + * Dump the current hcd state.
2516 +static ssize_t hcddump_show( struct device *_dev,
2517 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2518 + struct device_attribute *attr,
2522 +#ifndef DWC_DEVICE_ONLY
2523 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2525 + dwc_otg_hcd_dump_state(otg_dev->hcd);
2527 + return sprintf( buf, "HCD Dump\n" );
2530 +DEVICE_ATTR(hcddump, S_IRUGO|S_IWUSR, hcddump_show, 0);
2533 + * Dump the average frame remaining at SOF. This can be used to
2534 + * determine average interrupt latency. Frame remaining is also shown for
2535 + * start transfer and two additional sample points.
2537 +static ssize_t hcd_frrem_show( struct device *_dev,
2538 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2539 + struct device_attribute *attr,
2543 +#ifndef DWC_DEVICE_ONLY
2544 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2546 + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
2548 + return sprintf( buf, "HCD Dump Frame Remaining\n" );
2551 +DEVICE_ATTR(hcd_frrem, S_IRUGO|S_IWUSR, hcd_frrem_show, 0);
2554 + * Displays the time required to read the GNPTXFSIZ register many times (the
2555 + * output shows the number of times the register is read).
2557 +#define RW_REG_COUNT 10000000
2558 +#define MSEC_PER_JIFFIE 1000/HZ
2559 +static ssize_t rd_reg_test_show( struct device *_dev,
2560 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2561 + struct device_attribute *attr,
2565 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2569 + int start_jiffies;
2571 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
2572 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
2573 + start_jiffies = jiffies;
2574 + for (i = 0; i < RW_REG_COUNT; i++) {
2575 + dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
2577 + time = jiffies - start_jiffies;
2578 + return sprintf( buf, "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
2579 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time );
2582 +DEVICE_ATTR(rd_reg_test, S_IRUGO|S_IWUSR, rd_reg_test_show, 0);
2585 + * Displays the time required to write the GNPTXFSIZ register many times (the
2586 + * output shows the number of times the register is written).
2588 +static ssize_t wr_reg_test_show( struct device *_dev,
2589 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2590 + struct device_attribute *attr,
2594 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2599 + int start_jiffies;
2601 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
2602 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
2603 + reg_val = dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
2604 + start_jiffies = jiffies;
2605 + for (i = 0; i < RW_REG_COUNT; i++) {
2606 + dwc_write_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz, reg_val);
2608 + time = jiffies - start_jiffies;
2609 + return sprintf( buf, "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
2610 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
2613 +DEVICE_ATTR(wr_reg_test, S_IRUGO|S_IWUSR, wr_reg_test_show, 0);
2617 + * Create the device files
2619 +void dwc_otg_attr_create (struct device *dev)
2623 + error = device_create_file(dev, &dev_attr_regoffset);
2624 + error = device_create_file(dev, &dev_attr_regvalue);
2625 + error = device_create_file(dev, &dev_attr_mode);
2626 + error = device_create_file(dev, &dev_attr_hnpcapable);
2627 + error = device_create_file(dev, &dev_attr_srpcapable);
2628 + error = device_create_file(dev, &dev_attr_hnp);
2629 + error = device_create_file(dev, &dev_attr_srp);
2630 + error = device_create_file(dev, &dev_attr_buspower);
2631 + error = device_create_file(dev, &dev_attr_bussuspend);
2632 + error = device_create_file(dev, &dev_attr_busconnected);
2633 + error = device_create_file(dev, &dev_attr_gotgctl);
2634 + error = device_create_file(dev, &dev_attr_gusbcfg);
2635 + error = device_create_file(dev, &dev_attr_grxfsiz);
2636 + error = device_create_file(dev, &dev_attr_gnptxfsiz);
2637 + error = device_create_file(dev, &dev_attr_gpvndctl);
2638 + error = device_create_file(dev, &dev_attr_ggpio);
2639 + error = device_create_file(dev, &dev_attr_guid);
2640 + error = device_create_file(dev, &dev_attr_gsnpsid);
2641 + error = device_create_file(dev, &dev_attr_devspeed);
2642 + error = device_create_file(dev, &dev_attr_enumspeed);
2643 + error = device_create_file(dev, &dev_attr_hptxfsiz);
2644 + error = device_create_file(dev, &dev_attr_hprt0);
2645 + error = device_create_file(dev, &dev_attr_remote_wakeup);
2646 + error = device_create_file(dev, &dev_attr_regdump);
2647 + error = device_create_file(dev, &dev_attr_spramdump);
2648 + error = device_create_file(dev, &dev_attr_hcddump);
2649 + error = device_create_file(dev, &dev_attr_hcd_frrem);
2650 + error = device_create_file(dev, &dev_attr_rd_reg_test);
2651 + error = device_create_file(dev, &dev_attr_wr_reg_test);
2655 + * Remove the device files
2657 +void dwc_otg_attr_remove (struct device *dev)
2659 + device_remove_file(dev, &dev_attr_regoffset);
2660 + device_remove_file(dev, &dev_attr_regvalue);
2661 + device_remove_file(dev, &dev_attr_mode);
2662 + device_remove_file(dev, &dev_attr_hnpcapable);
2663 + device_remove_file(dev, &dev_attr_srpcapable);
2664 + device_remove_file(dev, &dev_attr_hnp);
2665 + device_remove_file(dev, &dev_attr_srp);
2666 + device_remove_file(dev, &dev_attr_buspower);
2667 + device_remove_file(dev, &dev_attr_bussuspend);
2668 + device_remove_file(dev, &dev_attr_busconnected);
2669 + device_remove_file(dev, &dev_attr_gotgctl);
2670 + device_remove_file(dev, &dev_attr_gusbcfg);
2671 + device_remove_file(dev, &dev_attr_grxfsiz);
2672 + device_remove_file(dev, &dev_attr_gnptxfsiz);
2673 + device_remove_file(dev, &dev_attr_gpvndctl);
2674 + device_remove_file(dev, &dev_attr_ggpio);
2675 + device_remove_file(dev, &dev_attr_guid);
2676 + device_remove_file(dev, &dev_attr_gsnpsid);
2677 + device_remove_file(dev, &dev_attr_devspeed);
2678 + device_remove_file(dev, &dev_attr_enumspeed);
2679 + device_remove_file(dev, &dev_attr_hptxfsiz);
2680 + device_remove_file(dev, &dev_attr_hprt0);
2681 + device_remove_file(dev, &dev_attr_remote_wakeup);
2682 + device_remove_file(dev, &dev_attr_regdump);
2683 + device_remove_file(dev, &dev_attr_spramdump);
2684 + device_remove_file(dev, &dev_attr_hcddump);
2685 + device_remove_file(dev, &dev_attr_hcd_frrem);
2686 + device_remove_file(dev, &dev_attr_rd_reg_test);
2687 + device_remove_file(dev, &dev_attr_wr_reg_test);
2689 diff --git a/drivers/usb/dwc_otg/dwc_otg_attr.h b/drivers/usb/dwc_otg/dwc_otg_attr.h
2690 new file mode 100644
2691 index 0000000..0862b27
2693 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.h
2695 +/* ==========================================================================
2696 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
2697 + * $Revision: 1.2 $
2698 + * $Date: 2008-11-21 05:39:15 $
2699 + * $Change: 477051 $
2701 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
2702 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
2703 + * otherwise expressly agreed to in writing between Synopsys and you.
2705 + * The Software IS NOT an item of Licensed Software or Licensed Product under
2706 + * any End User Software License Agreement or Agreement for Licensed Product
2707 + * with Synopsys or any supplement thereto. You are permitted to use and
2708 + * redistribute this Software in source and binary forms, with or without
2709 + * modification, provided that redistributions of source code must retain this
2710 + * notice. You may not view, use, disclose, copy or distribute this file or
2711 + * any information contained herein except pursuant to this license grant from
2712 + * Synopsys. If you do not agree with this notice, including the disclaimer
2713 + * below, then you are not authorized to use the Software.
2715 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
2716 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2717 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2718 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
2719 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2720 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2721 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2722 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2723 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2724 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2726 + * ========================================================================== */
2728 +#if !defined(__DWC_OTG_ATTR_H__)
2729 +#define __DWC_OTG_ATTR_H__
2732 + * This file contains the interface to the Linux device attributes.
2734 +extern struct device_attribute dev_attr_regoffset;
2735 +extern struct device_attribute dev_attr_regvalue;
2737 +extern struct device_attribute dev_attr_mode;
2738 +extern struct device_attribute dev_attr_hnpcapable;
2739 +extern struct device_attribute dev_attr_srpcapable;
2740 +extern struct device_attribute dev_attr_hnp;
2741 +extern struct device_attribute dev_attr_srp;
2742 +extern struct device_attribute dev_attr_buspower;
2743 +extern struct device_attribute dev_attr_bussuspend;
2744 +extern struct device_attribute dev_attr_busconnected;
2745 +extern struct device_attribute dev_attr_gotgctl;
2746 +extern struct device_attribute dev_attr_gusbcfg;
2747 +extern struct device_attribute dev_attr_grxfsiz;
2748 +extern struct device_attribute dev_attr_gnptxfsiz;
2749 +extern struct device_attribute dev_attr_gpvndctl;
2750 +extern struct device_attribute dev_attr_ggpio;
2751 +extern struct device_attribute dev_attr_guid;
2752 +extern struct device_attribute dev_attr_gsnpsid;
2753 +extern struct device_attribute dev_attr_devspeed;
2754 +extern struct device_attribute dev_attr_enumspeed;
2755 +extern struct device_attribute dev_attr_hptxfsiz;
2756 +extern struct device_attribute dev_attr_hprt0;
2758 +void dwc_otg_attr_create (struct device *dev);
2759 +void dwc_otg_attr_remove (struct device *dev);
2762 diff --git a/drivers/usb/dwc_otg/dwc_otg_cil.c b/drivers/usb/dwc_otg/dwc_otg_cil.c
2763 new file mode 100644
2764 index 0000000..89aa83e
2766 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.c
2768 +/* ==========================================================================
2769 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
2770 + * $Revision: 1.7 $
2771 + * $Date: 2008-12-22 11:43:05 $
2772 + * $Change: 1117667 $
2774 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
2775 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
2776 + * otherwise expressly agreed to in writing between Synopsys and you.
2778 + * The Software IS NOT an item of Licensed Software or Licensed Product under
2779 + * any End User Software License Agreement or Agreement for Licensed Product
2780 + * with Synopsys or any supplement thereto. You are permitted to use and
2781 + * redistribute this Software in source and binary forms, with or without
2782 + * modification, provided that redistributions of source code must retain this
2783 + * notice. You may not view, use, disclose, copy or distribute this file or
2784 + * any information contained herein except pursuant to this license grant from
2785 + * Synopsys. If you do not agree with this notice, including the disclaimer
2786 + * below, then you are not authorized to use the Software.
2788 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
2789 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2790 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2791 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
2792 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2793 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2794 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2795 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2796 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2797 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2799 + * ========================================================================== */
2803 + * The Core Interface Layer provides basic services for accessing and
2804 + * managing the DWC_otg hardware. These services are used by both the
2805 + * Host Controller Driver and the Peripheral Controller Driver.
2807 + * The CIL manages the memory map for the core so that the HCD and PCD
2808 + * don't have to do this separately. It also handles basic tasks like
2809 + * reading/writing the registers and data FIFOs in the controller.
2810 + * Some of the data access functions provide encapsulation of several
2811 + * operations required to perform a task, such as writing multiple
2812 + * registers to start a transfer. Finally, the CIL performs basic
2813 + * services that are not specific to either the host or device modes
2814 + * of operation. These services include management of the OTG Host
2815 + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
2816 + * Diagnostic API is also provided to allow testing of the controller
2819 + * The Core Interface Layer has the following requirements:
2820 + * - Provides basic controller operations.
2821 + * - Minimal use of OS services.
2822 + * - The OS services used will be abstracted by using inline functions
2826 +#include <asm/unaligned.h>
2827 +#include <linux/dma-mapping.h>
2829 +#include <linux/jiffies.h>
2832 +#include "linux/dwc_otg_plat.h"
2833 +#include "dwc_otg_regs.h"
2834 +#include "dwc_otg_cil.h"
2836 +/* Included only to access hc->qh for non-dword buffer handling
2837 + * TODO: account it
2839 +#include "dwc_otg_hcd.h"
2842 + * This function is called to initialize the DWC_otg CSR data
2843 + * structures. The register addresses in the device and host
2844 + * structures are initialized from the base address supplied by the
2845 + * caller. The calling function must make the OS calls to get the
2846 + * base address of the DWC_otg controller registers. The core_params
2847 + * argument holds the parameters that specify how the core should be
2850 + * @param[in] reg_base_addr Base address of DWC_otg core registers
2851 + * @param[in] core_params Pointer to the core configuration parameters
2854 +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *reg_base_addr,
2855 + dwc_otg_core_params_t *core_params)
2857 + dwc_otg_core_if_t *core_if = 0;
2858 + dwc_otg_dev_if_t *dev_if = 0;
2859 + dwc_otg_host_if_t *host_if = 0;
2860 + uint8_t *reg_base = (uint8_t *)reg_base_addr;
2863 + DWC_DEBUGPL(DBG_CILV, "%s(%p,%p)\n", __func__, reg_base_addr, core_params);
2865 + core_if = kmalloc(sizeof(dwc_otg_core_if_t), GFP_KERNEL);
2867 + if (core_if == 0) {
2868 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_core_if_t failed\n");
2872 + memset(core_if, 0, sizeof(dwc_otg_core_if_t));
2874 + core_if->core_params = core_params;
2875 + core_if->core_global_regs = (dwc_otg_core_global_regs_t *)reg_base;
2878 + * Allocate the Device Mode structures.
2880 + dev_if = kmalloc(sizeof(dwc_otg_dev_if_t), GFP_KERNEL);
2882 + if (dev_if == 0) {
2883 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
2888 + dev_if->dev_global_regs =
2889 + (dwc_otg_device_global_regs_t *)(reg_base + DWC_DEV_GLOBAL_REG_OFFSET);
2891 + for (i=0; i<MAX_EPS_CHANNELS; i++)
2893 + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
2894 + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
2895 + (i * DWC_EP_REG_OFFSET));
2897 + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
2898 + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
2899 + (i * DWC_EP_REG_OFFSET));
2900 + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
2901 + i, &dev_if->in_ep_regs[i]->diepctl);
2902 + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
2903 + i, &dev_if->out_ep_regs[i]->doepctl);
2906 + dev_if->speed = 0; // unknown
2908 + core_if->dev_if = dev_if;
2911 + * Allocate the Host Mode structures.
2913 + host_if = kmalloc(sizeof(dwc_otg_host_if_t), GFP_KERNEL);
2915 + if (host_if == 0) {
2916 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_host_if_t failed\n");
2922 + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
2923 + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
2925 + host_if->hprt0 = (uint32_t*)(reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
2927 + for (i=0; i<MAX_EPS_CHANNELS; i++)
2929 + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
2930 + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
2931 + (i * DWC_OTG_CHAN_REGS_OFFSET));
2932 + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
2933 + i, &host_if->hc_regs[i]->hcchar);
2936 + host_if->num_host_channels = MAX_EPS_CHANNELS;
2937 + core_if->host_if = host_if;
2939 + for (i=0; i<MAX_EPS_CHANNELS; i++)
2941 + core_if->data_fifo[i] =
2942 + (uint32_t *)(reg_base + DWC_OTG_DATA_FIFO_OFFSET +
2943 + (i * DWC_OTG_DATA_FIFO_SIZE));
2944 + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08x\n",
2945 + i, (unsigned)core_if->data_fifo[i]);
2948 + core_if->pcgcctl = (uint32_t*)(reg_base + DWC_OTG_PCGCCTL_OFFSET);
2951 + * Store the contents of the hardware configuration registers here for
2952 + * easy access later.
2954 + core_if->hwcfg1.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg1);
2955 + core_if->hwcfg2.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg2);
2956 + core_if->hwcfg3.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg3);
2957 + core_if->hwcfg4.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg4);
2959 + DWC_DEBUGPL(DBG_CILV,"hwcfg1=%08x\n",core_if->hwcfg1.d32);
2960 + DWC_DEBUGPL(DBG_CILV,"hwcfg2=%08x\n",core_if->hwcfg2.d32);
2961 + DWC_DEBUGPL(DBG_CILV,"hwcfg3=%08x\n",core_if->hwcfg3.d32);
2962 + DWC_DEBUGPL(DBG_CILV,"hwcfg4=%08x\n",core_if->hwcfg4.d32);
2964 + core_if->hcfg.d32 = dwc_read_reg32(&core_if->host_if->host_global_regs->hcfg);
2965 + core_if->dcfg.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dcfg);
2967 + DWC_DEBUGPL(DBG_CILV,"hcfg=%08x\n",core_if->hcfg.d32);
2968 + DWC_DEBUGPL(DBG_CILV,"dcfg=%08x\n",core_if->dcfg.d32);
2970 + DWC_DEBUGPL(DBG_CILV,"op_mode=%0x\n",core_if->hwcfg2.b.op_mode);
2971 + DWC_DEBUGPL(DBG_CILV,"arch=%0x\n",core_if->hwcfg2.b.architecture);
2972 + DWC_DEBUGPL(DBG_CILV,"num_dev_ep=%d\n",core_if->hwcfg2.b.num_dev_ep);
2973 + DWC_DEBUGPL(DBG_CILV,"num_host_chan=%d\n",core_if->hwcfg2.b.num_host_chan);
2974 + DWC_DEBUGPL(DBG_CILV,"nonperio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.nonperio_tx_q_depth);
2975 + DWC_DEBUGPL(DBG_CILV,"host_perio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.host_perio_tx_q_depth);
2976 + DWC_DEBUGPL(DBG_CILV,"dev_token_q_depth=0x%0x\n",core_if->hwcfg2.b.dev_token_q_depth);
2978 + DWC_DEBUGPL(DBG_CILV,"Total FIFO SZ=%d\n", core_if->hwcfg3.b.dfifo_depth);
2979 + DWC_DEBUGPL(DBG_CILV,"xfer_size_cntr_width=%0x\n", core_if->hwcfg3.b.xfer_size_cntr_width);
2982 + * Set the SRP sucess bit for FS-I2c
2984 + core_if->srp_success = 0;
2985 + core_if->srp_timer_started = 0;
2989 + * Create new workqueue and init works
2991 + core_if->wq_otg = create_singlethread_workqueue("dwc_otg");
2992 + if(core_if->wq_otg == 0) {
2993 + DWC_DEBUGPL(DBG_CIL, "Creation of wq_otg failed\n");
3002 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
3004 + INIT_WORK(&core_if->w_conn_id, w_conn_id_status_change, core_if);
3005 + INIT_WORK(&core_if->w_wkp, w_wakeup_detected, core_if);
3009 + INIT_WORK(&core_if->w_conn_id, w_conn_id_status_change);
3010 + INIT_DELAYED_WORK(&core_if->w_wkp, w_wakeup_detected);
3017 + * This function frees the structures allocated by dwc_otg_cil_init().
3019 + * @param[in] core_if The core interface pointer returned from
3020 + * dwc_otg_cil_init().
3023 +void dwc_otg_cil_remove(dwc_otg_core_if_t *core_if)
3025 + /* Disable all interrupts */
3026 + dwc_modify_reg32(&core_if->core_global_regs->gahbcfg, 1, 0);
3027 + dwc_write_reg32(&core_if->core_global_regs->gintmsk, 0);
3029 + if (core_if->wq_otg) {
3030 + destroy_workqueue(core_if->wq_otg);
3032 + if (core_if->dev_if) {
3033 + kfree(core_if->dev_if);
3035 + if (core_if->host_if) {
3036 + kfree(core_if->host_if);
3042 + * This function enables the controller's Global Interrupt in the AHB Config
3045 + * @param[in] core_if Programming view of DWC_otg controller.
3047 +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t *core_if)
3049 + gahbcfg_data_t ahbcfg = { .d32 = 0};
3050 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
3051 + dwc_modify_reg32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
3055 + * This function disables the controller's Global Interrupt in the AHB Config
3058 + * @param[in] core_if Programming view of DWC_otg controller.
3060 +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t *core_if)
3062 + gahbcfg_data_t ahbcfg = { .d32 = 0};
3063 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
3064 + dwc_modify_reg32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
3068 + * This function initializes the commmon interrupts, used in both
3069 + * device and host modes.
3071 + * @param[in] core_if Programming view of the DWC_otg controller
3074 +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t *core_if)
3076 + dwc_otg_core_global_regs_t *global_regs =
3077 + core_if->core_global_regs;
3078 + gintmsk_data_t intr_mask = { .d32 = 0};
3080 + /* Clear any pending OTG Interrupts */
3081 + dwc_write_reg32(&global_regs->gotgint, 0xFFFFFFFF);
3083 + /* Clear any pending interrupts */
3084 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
3087 + * Enable the interrupts in the GINTMSK.
3089 + intr_mask.b.modemismatch = 1;
3090 + intr_mask.b.otgintr = 1;
3092 + if (!core_if->dma_enable) {
3093 + intr_mask.b.rxstsqlvl = 1;
3096 + intr_mask.b.conidstschng = 1;
3097 + intr_mask.b.wkupintr = 1;
3098 + intr_mask.b.disconnect = 1;
3099 + intr_mask.b.usbsuspend = 1;
3100 + intr_mask.b.sessreqintr = 1;
3101 + dwc_write_reg32(&global_regs->gintmsk, intr_mask.d32);
3105 + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
3108 +static void init_fslspclksel(dwc_otg_core_if_t *core_if)
3113 + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
3114 + (core_if->hwcfg2.b.fs_phy_type == 1) &&
3115 + (core_if->core_params->ulpi_fs_ls)) ||
3116 + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
3117 + /* Full speed PHY */
3118 + val = DWC_HCFG_48_MHZ;
3121 + /* High speed PHY running at full speed or high speed */
3122 + val = DWC_HCFG_30_60_MHZ;
3125 + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
3126 + hcfg.d32 = dwc_read_reg32(&core_if->host_if->host_global_regs->hcfg);
3127 + hcfg.b.fslspclksel = val;
3128 + dwc_write_reg32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
3132 + * Initializes the DevSpd field of the DCFG register depending on the PHY type
3133 + * and the enumeration speed of the device.
3135 +static void init_devspd(dwc_otg_core_if_t *core_if)
3140 + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
3141 + (core_if->hwcfg2.b.fs_phy_type == 1) &&
3142 + (core_if->core_params->ulpi_fs_ls)) ||
3143 + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
3144 + /* Full speed PHY */
3147 + else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
3148 + /* High speed PHY running at full speed */
3152 + /* High speed PHY running at high speed */
3156 + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
3158 + dcfg.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dcfg);
3159 + dcfg.b.devspd = val;
3160 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
3164 + * This function calculates the number of IN EPS
3165 + * using GHWCFG1 and GHWCFG2 registers values
3167 + * @param core_if Programming view of the DWC_otg controller
3169 +static uint32_t calc_num_in_eps(dwc_otg_core_if_t *core_if)
3171 + uint32_t num_in_eps = 0;
3172 + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
3173 + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
3174 + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
3178 + for(i = 0; i < num_eps; ++i)
3180 + if(!(hwcfg1 & 0x1))
3186 + if(core_if->hwcfg4.b.ded_fifo_en) {
3187 + num_in_eps = (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
3190 + return num_in_eps;
3195 + * This function calculates the number of OUT EPS
3196 + * using GHWCFG1 and GHWCFG2 registers values
3198 + * @param core_if Programming view of the DWC_otg controller
3200 +static uint32_t calc_num_out_eps(dwc_otg_core_if_t *core_if)
3202 + uint32_t num_out_eps = 0;
3203 + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
3204 + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
3207 + for(i = 0; i < num_eps; ++i)
3209 + if(!(hwcfg1 & 0x2))
3214 + return num_out_eps;
3217 + * This function initializes the DWC_otg controller registers and
3218 + * prepares the core for device mode or host mode operation.
3220 + * @param core_if Programming view of the DWC_otg controller
3223 +void dwc_otg_core_init(dwc_otg_core_if_t *core_if)
3226 + dwc_otg_core_global_regs_t *global_regs =
3227 + core_if->core_global_regs;
3228 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
3229 + gahbcfg_data_t ahbcfg = { .d32 = 0 };
3230 + gusbcfg_data_t usbcfg = { .d32 = 0 };
3231 + gi2cctl_data_t i2cctl = { .d32 = 0 };
3233 + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p)\n", core_if);
3235 + /* Common Initialization */
3237 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3239 +// usbcfg.b.tx_end_delay = 1;
3240 + /* Program the ULPI External VBUS bit if needed */
3241 + usbcfg.b.ulpi_ext_vbus_drv =
3242 + (core_if->core_params->phy_ulpi_ext_vbus == DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
3244 + /* Set external TS Dline pulsing */
3245 + usbcfg.b.term_sel_dl_pulse = (core_if->core_params->ts_dline == 1) ? 1 : 0;
3246 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
3249 + /* Reset the Controller */
3250 + dwc_otg_core_reset(core_if);
3252 + /* Initialize parameters from Hardware configuration registers. */
3253 + dev_if->num_in_eps = calc_num_in_eps(core_if);
3254 + dev_if->num_out_eps = calc_num_out_eps(core_if);
3257 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n", core_if->hwcfg4.b.num_dev_perio_in_ep);
3259 + for (i=0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
3261 + dev_if->perio_tx_fifo_size[i] =
3262 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
3263 + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
3264 + i, dev_if->perio_tx_fifo_size[i]);
3267 + for (i=0; i < core_if->hwcfg4.b.num_in_eps; i++)
3269 + dev_if->tx_fifo_size[i] =
3270 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
3271 + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
3272 + i, dev_if->perio_tx_fifo_size[i]);
3275 + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
3276 + core_if->rx_fifo_size =
3277 + dwc_read_reg32(&global_regs->grxfsiz);
3278 + core_if->nperio_tx_fifo_size =
3279 + dwc_read_reg32(&global_regs->gnptxfsiz) >> 16;
3281 + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
3282 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
3283 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n", core_if->nperio_tx_fifo_size);
3285 + /* This programming sequence needs to happen in FS mode before any other
3286 + * programming occurs */
3287 + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
3288 + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
3289 + /* If FS mode with FS PHY */
3291 + /* core_init() is now called on every switch so only call the
3292 + * following for the first time through. */
3293 + if (!core_if->phy_init_done) {
3294 + core_if->phy_init_done = 1;
3295 + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
3296 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3297 + usbcfg.b.physel = 1;
3298 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
3300 + /* Reset after a PHY select */
3301 + dwc_otg_core_reset(core_if);
3304 + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
3305 + * do this on HNP Dev/Host mode switches (done in dev_init and
3307 + if (dwc_otg_is_host_mode(core_if)) {
3308 + init_fslspclksel(core_if);
3311 + init_devspd(core_if);
3314 + if (core_if->core_params->i2c_enable) {
3315 + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
3316 + /* Program GUSBCFG.OtgUtmifsSel to I2C */
3317 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3318 + usbcfg.b.otgutmifssel = 1;
3319 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
3321 + /* Program GI2CCTL.I2CEn */
3322 + i2cctl.d32 = dwc_read_reg32(&global_regs->gi2cctl);
3323 + i2cctl.b.i2cdevaddr = 1;
3324 + i2cctl.b.i2cen = 0;
3325 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
3326 + i2cctl.b.i2cen = 1;
3327 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
3330 + } /* endif speed == DWC_SPEED_PARAM_FULL */
3333 + /* High speed PHY. */
3334 + if (!core_if->phy_init_done) {
3335 + core_if->phy_init_done = 1;
3336 + /* HS PHY parameters. These parameters are preserved
3337 + * during soft reset so only program the first time. Do
3338 + * a soft reset immediately after setting phyif. */
3339 + usbcfg.b.ulpi_utmi_sel = core_if->core_params->phy_type;
3340 + if (usbcfg.b.ulpi_utmi_sel == 1) {
3341 + /* ULPI interface */
3342 + usbcfg.b.phyif = 0;
3343 + usbcfg.b.ddrsel = core_if->core_params->phy_ulpi_ddr;
3346 + /* UTMI+ interface */
3347 + if (core_if->core_params->phy_utmi_width == 16) {
3348 + usbcfg.b.phyif = 1;
3351 + usbcfg.b.phyif = 0;
3355 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3357 + /* Reset after setting the PHY parameters */
3358 + dwc_otg_core_reset(core_if);
3362 + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
3363 + (core_if->hwcfg2.b.fs_phy_type == 1) &&
3364 + (core_if->core_params->ulpi_fs_ls)) {
3365 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
3366 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3367 + usbcfg.b.ulpi_fsls = 1;
3368 + usbcfg.b.ulpi_clk_sus_m = 1;
3369 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3372 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3373 + usbcfg.b.ulpi_fsls = 0;
3374 + usbcfg.b.ulpi_clk_sus_m = 0;
3375 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3378 + /* Program the GAHBCFG Register.*/
3379 + switch (core_if->hwcfg2.b.architecture) {
3381 + case DWC_SLAVE_ONLY_ARCH:
3382 + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
3383 + ahbcfg.b.nptxfemplvl_txfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
3384 + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
3385 + core_if->dma_enable = 0;
3386 + core_if->dma_desc_enable = 0;
3389 + case DWC_EXT_DMA_ARCH:
3390 + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
3391 + ahbcfg.b.hburstlen = core_if->core_params->dma_burst_size;
3392 + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
3393 + core_if->dma_desc_enable = (core_if->core_params->dma_desc_enable != 0);
3396 + case DWC_INT_DMA_ARCH:
3397 + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
3398 + ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR;
3399 + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
3400 + core_if->dma_desc_enable = (core_if->core_params->dma_desc_enable != 0);
3404 + ahbcfg.b.dmaenable = core_if->dma_enable;
3405 + dwc_write_reg32(&global_regs->gahbcfg, ahbcfg.d32);
3407 + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
3409 + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
3410 + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
3411 + DWC_PRINT("Periodic Transfer Interrupt Enhancement - %s\n", ((core_if->pti_enh_enable) ? "enabled": "disabled"));
3412 + DWC_PRINT("Multiprocessor Interrupt Enhancement - %s\n", ((core_if->multiproc_int_enable) ? "enabled": "disabled"));
3415 + * Program the GUSBCFG register.
3417 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3419 + switch (core_if->hwcfg2.b.op_mode) {
3420 + case DWC_MODE_HNP_SRP_CAPABLE:
3421 + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
3422 + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
3423 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3424 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3427 + case DWC_MODE_SRP_ONLY_CAPABLE:
3428 + usbcfg.b.hnpcap = 0;
3429 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3430 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3433 + case DWC_MODE_NO_HNP_SRP_CAPABLE:
3434 + usbcfg.b.hnpcap = 0;
3435 + usbcfg.b.srpcap = 0;
3438 + case DWC_MODE_SRP_CAPABLE_DEVICE:
3439 + usbcfg.b.hnpcap = 0;
3440 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3441 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3444 + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
3445 + usbcfg.b.hnpcap = 0;
3446 + usbcfg.b.srpcap = 0;
3449 + case DWC_MODE_SRP_CAPABLE_HOST:
3450 + usbcfg.b.hnpcap = 0;
3451 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3452 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3455 + case DWC_MODE_NO_SRP_CAPABLE_HOST:
3456 + usbcfg.b.hnpcap = 0;
3457 + usbcfg.b.srpcap = 0;
3461 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3463 + /* Enable common interrupts */
3464 + dwc_otg_enable_common_interrupts(core_if);
3466 + /* Do device or host intialization based on mode during PCD
3467 + * and HCD initialization */
3468 + if (dwc_otg_is_host_mode(core_if)) {
3469 + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
3470 + core_if->op_state = A_HOST;
3473 + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
3474 + core_if->op_state = B_PERIPHERAL;
3475 +#ifdef DWC_DEVICE_ONLY
3476 + dwc_otg_core_dev_init(core_if);
3483 + * This function enables the Device mode interrupts.
3485 + * @param core_if Programming view of DWC_otg controller
3487 +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *core_if)
3489 + gintmsk_data_t intr_mask = { .d32 = 0};
3490 + dwc_otg_core_global_regs_t *global_regs =
3491 + core_if->core_global_regs;
3493 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
3495 + /* Disable all interrupts. */
3496 + dwc_write_reg32(&global_regs->gintmsk, 0);
3498 + /* Clear any pending interrupts */
3499 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
3501 + /* Enable the common interrupts */
3502 + dwc_otg_enable_common_interrupts(core_if);
3504 + /* Enable interrupts */
3505 + intr_mask.b.usbreset = 1;
3506 + intr_mask.b.enumdone = 1;
3508 + if(!core_if->multiproc_int_enable) {
3509 + intr_mask.b.inepintr = 1;
3510 + intr_mask.b.outepintr = 1;
3513 + intr_mask.b.erlysuspend = 1;
3515 + if(core_if->en_multiple_tx_fifo == 0) {
3516 + intr_mask.b.epmismatch = 1;
3521 + if(core_if->dma_enable) {
3522 + if(core_if->dma_desc_enable == 0) {
3523 + if(core_if->pti_enh_enable) {
3524 + dctl_data_t dctl = { .d32 = 0 };
3525 + dctl.b.ifrmnum = 1;
3526 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
3528 + intr_mask.b.incomplisoin = 1;
3529 + intr_mask.b.incomplisoout = 1;
3533 + intr_mask.b.incomplisoin = 1;
3534 + intr_mask.b.incomplisoout = 1;
3536 +#endif // DWC_EN_ISOC
3538 +/** @todo NGS: Should this be a module parameter? */
3539 +#ifdef USE_PERIODIC_EP
3540 + intr_mask.b.isooutdrop = 1;
3541 + intr_mask.b.eopframe = 1;
3542 + intr_mask.b.incomplisoin = 1;
3543 + intr_mask.b.incomplisoout = 1;
3546 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
3548 + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
3549 + dwc_read_reg32(&global_regs->gintmsk));
3553 + * This function initializes the DWC_otg controller registers for
3556 + * @param core_if Programming view of DWC_otg controller
3559 +void dwc_otg_core_dev_init(dwc_otg_core_if_t *core_if)
3562 + dwc_otg_core_global_regs_t *global_regs =
3563 + core_if->core_global_regs;
3564 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
3565 + dwc_otg_core_params_t *params = core_if->core_params;
3566 + dcfg_data_t dcfg = { .d32 = 0};
3567 + grstctl_t resetctl = { .d32 = 0 };
3568 + uint32_t rx_fifo_size;
3569 + fifosize_data_t nptxfifosize;
3570 + fifosize_data_t txfifosize;
3571 + dthrctl_data_t dthrctl;
3572 + fifosize_data_t ptxfifosize;
3574 + /* Restart the Phy Clock */
3575 + dwc_write_reg32(core_if->pcgcctl, 0);
3577 + /* Device configuration register */
3578 + init_devspd(core_if);
3579 + dcfg.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dcfg);
3580 + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
3581 + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
3583 + dwc_write_reg32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
3585 + /* Configure data FIFO sizes */
3586 + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
3587 + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n", core_if->total_fifo_size);
3588 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n", params->dev_rx_fifo_size);
3589 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n", params->dev_nperio_tx_fifo_size);
3592 + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
3593 + dwc_read_reg32(&global_regs->grxfsiz));
3595 + rx_fifo_size = params->dev_rx_fifo_size;
3596 + dwc_write_reg32(&global_regs->grxfsiz, rx_fifo_size);
3598 + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
3599 + dwc_read_reg32(&global_regs->grxfsiz));
3601 + /** Set Periodic Tx FIFO Mask all bits 0 */
3602 + core_if->p_tx_msk = 0;
3604 + /** Set Tx FIFO Mask all bits 0 */
3605 + core_if->tx_msk = 0;
3607 + if(core_if->en_multiple_tx_fifo == 0) {
3608 + /* Non-periodic Tx FIFO */
3609 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
3610 + dwc_read_reg32(&global_regs->gnptxfsiz));
3612 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
3613 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
3615 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
3617 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
3618 + dwc_read_reg32(&global_regs->gnptxfsiz));
3620 + /**@todo NGS: Fix Periodic FIFO Sizing! */
3622 + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
3623 + * Indexes of the FIFO size module parameters in the
3624 + * dev_perio_tx_fifo_size array and the FIFO size registers in
3625 + * the dptxfsiz array run from 0 to 14.
3627 + /** @todo Finish debug of this */
3628 + ptxfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
3629 + for (i=0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
3631 + ptxfifosize.b.depth = params->dev_perio_tx_fifo_size[i];
3632 + DWC_DEBUGPL(DBG_CIL, "initial dptxfsiz_dieptxf[%d]=%08x\n", i,
3633 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
3634 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i],
3636 + DWC_DEBUGPL(DBG_CIL, "new dptxfsiz_dieptxf[%d]=%08x\n", i,
3637 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
3638 + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
3643 + * Tx FIFOs These FIFOs are numbered from 1 to 15.
3644 + * Indexes of the FIFO size module parameters in the
3645 + * dev_tx_fifo_size array and the FIFO size registers in
3646 + * the dptxfsiz_dieptxf array run from 0 to 14.
3650 + /* Non-periodic Tx FIFO */
3651 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
3652 + dwc_read_reg32(&global_regs->gnptxfsiz));
3654 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
3655 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
3657 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
3659 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
3660 + dwc_read_reg32(&global_regs->gnptxfsiz));
3662 + txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
3664 + Modify by kaiker ,for RT3052 device mode config
3666 + In RT3052,Since the _core_if->hwcfg4.b.num_dev_perio_in_ep is
3667 + configed to 0 so these TX_FIF0 not config.IN EP will can't
3668 + more than 1 if not modify it.
3672 + for (i=1 ; i <= dev_if->num_in_eps; i++)
3674 + for (i=1; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
3678 + txfifosize.b.depth = params->dev_tx_fifo_size[i];
3680 + DWC_DEBUGPL(DBG_CIL, "initial dptxfsiz_dieptxf[%d]=%08x\n", i,
3681 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
3683 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i-1],
3686 + DWC_DEBUGPL(DBG_CIL, "new dptxfsiz_dieptxf[%d]=%08x\n", i,
3687 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i-1]));
3689 + txfifosize.b.startaddr += txfifosize.b.depth;
3693 + /* Flush the FIFOs */
3694 + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
3695 + dwc_otg_flush_rx_fifo(core_if);
3697 + /* Flush the Learning Queue. */
3698 + resetctl.b.intknqflsh = 1;
3699 + dwc_write_reg32(&core_if->core_global_regs->grstctl, resetctl.d32);
3701 + /* Clear all pending Device Interrupts */
3703 + if(core_if->multiproc_int_enable) {
3706 + /** @todo - if the condition needed to be checked
3707 + * or in any case all pending interrutps should be cleared?
3709 + if(core_if->multiproc_int_enable) {
3710 + for(i = 0; i < core_if->dev_if->num_in_eps; ++i) {
3711 + dwc_write_reg32(&dev_if->dev_global_regs->diepeachintmsk[i], 0);
3714 + for(i = 0; i < core_if->dev_if->num_out_eps; ++i) {
3715 + dwc_write_reg32(&dev_if->dev_global_regs->doepeachintmsk[i], 0);
3718 + dwc_write_reg32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
3719 + dwc_write_reg32(&dev_if->dev_global_regs->deachintmsk, 0);
3721 + dwc_write_reg32(&dev_if->dev_global_regs->diepmsk, 0);
3722 + dwc_write_reg32(&dev_if->dev_global_regs->doepmsk, 0);
3723 + dwc_write_reg32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
3724 + dwc_write_reg32(&dev_if->dev_global_regs->daintmsk, 0);
3727 + for (i=0; i <= dev_if->num_in_eps; i++)
3729 + depctl_data_t depctl;
3730 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
3731 + if (depctl.b.epena) {
3733 + depctl.b.epdis = 1;
3734 + depctl.b.snak = 1;
3740 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
3743 + dwc_write_reg32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
3744 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepdma, 0);
3745 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
3748 + for (i=0; i <= dev_if->num_out_eps; i++)
3750 + depctl_data_t depctl;
3751 + depctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doepctl);
3752 + if (depctl.b.epena) {
3754 + depctl.b.epdis = 1;
3755 + depctl.b.snak = 1;
3761 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
3763 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
3764 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepdma, 0);
3765 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
3768 + if(core_if->en_multiple_tx_fifo && core_if->dma_enable) {
3769 + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
3770 + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
3771 + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
3773 + dev_if->rx_thr_length = params->rx_thr_length;
3774 + dev_if->tx_thr_length = params->tx_thr_length;
3776 + dev_if->setup_desc_index = 0;
3779 + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
3780 + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
3781 + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
3782 + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
3783 + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
3785 + dwc_write_reg32(&dev_if->dev_global_regs->dtknqr3_dthrctl, dthrctl.d32);
3787 + DWC_DEBUGPL(DBG_CIL, "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
3788 + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en, dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len, dthrctl.b.rx_thr_len);
3792 + dwc_otg_enable_device_interrupts(core_if);
3795 + diepmsk_data_t msk = { .d32 = 0 };
3796 + msk.b.txfifoundrn = 1;
3797 + if(core_if->multiproc_int_enable) {
3798 + dwc_modify_reg32(&dev_if->dev_global_regs->diepeachintmsk[0], msk.d32, msk.d32);
3800 + dwc_modify_reg32(&dev_if->dev_global_regs->diepmsk, msk.d32, msk.d32);
3805 + if(core_if->multiproc_int_enable) {
3806 + /* Set NAK on Babble */
3807 + dctl_data_t dctl = { .d32 = 0};
3808 + dctl.b.nakonbble = 1;
3809 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
3814 + * This function enables the Host mode interrupts.
3816 + * @param core_if Programming view of DWC_otg controller
3818 +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *core_if)
3820 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
3821 + gintmsk_data_t intr_mask = { .d32 = 0 };
3823 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
3825 + /* Disable all interrupts. */
3826 + dwc_write_reg32(&global_regs->gintmsk, 0);
3828 + /* Clear any pending interrupts. */
3829 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
3831 + /* Enable the common interrupts */
3832 + dwc_otg_enable_common_interrupts(core_if);
3835 + * Enable host mode interrupts without disturbing common
3838 + intr_mask.b.sofintr = 1;
3839 + intr_mask.b.portintr = 1;
3840 + intr_mask.b.hcintr = 1;
3842 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
3846 + * This function disables the Host Mode interrupts.
3848 + * @param core_if Programming view of DWC_otg controller
3850 +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *core_if)
3852 + dwc_otg_core_global_regs_t *global_regs =
3853 + core_if->core_global_regs;
3854 + gintmsk_data_t intr_mask = { .d32 = 0 };
3856 + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
3859 + * Disable host mode interrupts without disturbing common
3862 + intr_mask.b.sofintr = 1;
3863 + intr_mask.b.portintr = 1;
3864 + intr_mask.b.hcintr = 1;
3865 + intr_mask.b.ptxfempty = 1;
3866 + intr_mask.b.nptxfempty = 1;
3868 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
3872 + * This function initializes the DWC_otg controller registers for
3875 + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
3876 + * request queues. Host channels are reset to ensure that they are ready for
3877 + * performing transfers.
3879 + * @param core_if Programming view of DWC_otg controller
3882 +void dwc_otg_core_host_init(dwc_otg_core_if_t *core_if)
3884 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
3885 + dwc_otg_host_if_t *host_if = core_if->host_if;
3886 + dwc_otg_core_params_t *params = core_if->core_params;
3887 + hprt0_data_t hprt0 = { .d32 = 0 };
3888 + fifosize_data_t nptxfifosize;
3889 + fifosize_data_t ptxfifosize;
3891 + hcchar_data_t hcchar;
3893 + dwc_otg_hc_regs_t *hc_regs;
3895 + gotgctl_data_t gotgctl = { .d32 = 0 };
3897 + DWC_DEBUGPL(DBG_CILV,"%s(%p)\n", __func__, core_if);
3899 + /* Restart the Phy Clock */
3900 + dwc_write_reg32(core_if->pcgcctl, 0);
3902 + /* Initialize Host Configuration Register */
3903 + init_fslspclksel(core_if);
3904 + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL)
3906 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
3907 + hcfg.b.fslssupp = 1;
3908 + dwc_write_reg32(&host_if->host_global_regs->hcfg, hcfg.d32);
3911 + /* Configure data FIFO sizes */
3912 + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
3913 + DWC_DEBUGPL(DBG_CIL,"Total FIFO Size=%d\n", core_if->total_fifo_size);
3914 + DWC_DEBUGPL(DBG_CIL,"Rx FIFO Size=%d\n", params->host_rx_fifo_size);
3915 + DWC_DEBUGPL(DBG_CIL,"NP Tx FIFO Size=%d\n", params->host_nperio_tx_fifo_size);
3916 + DWC_DEBUGPL(DBG_CIL,"P Tx FIFO Size=%d\n", params->host_perio_tx_fifo_size);
3919 + DWC_DEBUGPL(DBG_CIL,"initial grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
3920 + dwc_write_reg32(&global_regs->grxfsiz, params->host_rx_fifo_size);
3921 + DWC_DEBUGPL(DBG_CIL,"new grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
3923 + /* Non-periodic Tx FIFO */
3924 + DWC_DEBUGPL(DBG_CIL,"initial gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
3925 + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
3926 + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
3927 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
3928 + DWC_DEBUGPL(DBG_CIL,"new gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
3930 + /* Periodic Tx FIFO */
3931 + DWC_DEBUGPL(DBG_CIL,"initial hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
3932 + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
3933 + ptxfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
3934 + dwc_write_reg32(&global_regs->hptxfsiz, ptxfifosize.d32);
3935 + DWC_DEBUGPL(DBG_CIL,"new hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
3938 + /* Clear Host Set HNP Enable in the OTG Control Register */
3939 + gotgctl.b.hstsethnpen = 1;
3940 + dwc_modify_reg32(&global_regs->gotgctl, gotgctl.d32, 0);
3942 + /* Make sure the FIFOs are flushed. */
3943 + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all Tx FIFOs */);
3944 + dwc_otg_flush_rx_fifo(core_if);
3946 + /* Flush out any leftover queued requests. */
3947 + num_channels = core_if->core_params->host_channels;
3948 + for (i = 0; i < num_channels; i++)
3950 + hc_regs = core_if->host_if->hc_regs[i];
3951 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
3952 + hcchar.b.chen = 0;
3953 + hcchar.b.chdis = 1;
3954 + hcchar.b.epdir = 0;
3955 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
3958 + /* Halt all channels to put them into a known state. */
3959 + for (i = 0; i < num_channels; i++)
3962 + hc_regs = core_if->host_if->hc_regs[i];
3963 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
3964 + hcchar.b.chen = 1;
3965 + hcchar.b.chdis = 1;
3966 + hcchar.b.epdir = 0;
3967 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
3968 + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d\n", __func__, i);
3970 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
3971 + if (++count > 1000)
3973 + DWC_ERROR("%s: Unable to clear halt on channel %d\n",
3978 + while (hcchar.b.chen);
3981 + /* Turn on the vbus power. */
3982 + DWC_PRINT("Init: Port Power? op_state=%d\n", core_if->op_state);
3983 + if (core_if->op_state == A_HOST) {
3984 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
3985 + DWC_PRINT("Init: Power Port (%d)\n", hprt0.b.prtpwr);
3986 + if (hprt0.b.prtpwr == 0) {
3987 + hprt0.b.prtpwr = 1;
3988 + dwc_write_reg32(host_if->hprt0, hprt0.d32);
3992 + dwc_otg_enable_host_interrupts(core_if);
3996 + * Prepares a host channel for transferring packets to/from a specific
3997 + * endpoint. The HCCHARn register is set up with the characteristics specified
3998 + * in _hc. Host channel interrupts that may need to be serviced while this
3999 + * transfer is in progress are enabled.
4001 + * @param core_if Programming view of DWC_otg controller
4002 + * @param hc Information needed to initialize the host channel
4004 +void dwc_otg_hc_init(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4006 + uint32_t intr_enable;
4007 + hcintmsk_data_t hc_intr_mask;
4008 + gintmsk_data_t gintmsk = { .d32 = 0 };
4009 + hcchar_data_t hcchar;
4010 + hcsplt_data_t hcsplt;
4012 + uint8_t hc_num = hc->hc_num;
4013 + dwc_otg_host_if_t *host_if = core_if->host_if;
4014 + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
4016 + /* Clear old interrupt conditions for this host channel. */
4017 + hc_intr_mask.d32 = 0xFFFFFFFF;
4018 + hc_intr_mask.b.reserved = 0;
4019 + dwc_write_reg32(&hc_regs->hcint, hc_intr_mask.d32);
4021 + /* Enable channel interrupts required for this transfer. */
4022 + hc_intr_mask.d32 = 0;
4023 + hc_intr_mask.b.chhltd = 1;
4024 + if (core_if->dma_enable) {
4025 + hc_intr_mask.b.ahberr = 1;
4026 + if (hc->error_state && !hc->do_split &&
4027 + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
4028 + hc_intr_mask.b.ack = 1;
4029 + if (hc->ep_is_in) {
4030 + hc_intr_mask.b.datatglerr = 1;
4031 + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
4032 + hc_intr_mask.b.nak = 1;
4038 + switch (hc->ep_type) {
4039 + case DWC_OTG_EP_TYPE_CONTROL:
4040 + case DWC_OTG_EP_TYPE_BULK:
4041 + hc_intr_mask.b.xfercompl = 1;
4042 + hc_intr_mask.b.stall = 1;
4043 + hc_intr_mask.b.xacterr = 1;
4044 + hc_intr_mask.b.datatglerr = 1;
4045 + if (hc->ep_is_in) {
4046 + hc_intr_mask.b.bblerr = 1;
4049 + hc_intr_mask.b.nak = 1;
4050 + hc_intr_mask.b.nyet = 1;
4051 + if (hc->do_ping) {
4052 + hc_intr_mask.b.ack = 1;
4056 + if (hc->do_split) {
4057 + hc_intr_mask.b.nak = 1;
4058 + if (hc->complete_split) {
4059 + hc_intr_mask.b.nyet = 1;
4062 + hc_intr_mask.b.ack = 1;
4066 + if (hc->error_state) {
4067 + hc_intr_mask.b.ack = 1;
4070 + case DWC_OTG_EP_TYPE_INTR:
4071 + hc_intr_mask.b.xfercompl = 1;
4072 + hc_intr_mask.b.nak = 1;
4073 + hc_intr_mask.b.stall = 1;
4074 + hc_intr_mask.b.xacterr = 1;
4075 + hc_intr_mask.b.datatglerr = 1;
4076 + hc_intr_mask.b.frmovrun = 1;
4078 + if (hc->ep_is_in) {
4079 + hc_intr_mask.b.bblerr = 1;
4081 + if (hc->error_state) {
4082 + hc_intr_mask.b.ack = 1;
4084 + if (hc->do_split) {
4085 + if (hc->complete_split) {
4086 + hc_intr_mask.b.nyet = 1;
4089 + hc_intr_mask.b.ack = 1;
4093 + case DWC_OTG_EP_TYPE_ISOC:
4094 + hc_intr_mask.b.xfercompl = 1;
4095 + hc_intr_mask.b.frmovrun = 1;
4096 + hc_intr_mask.b.ack = 1;
4098 + if (hc->ep_is_in) {
4099 + hc_intr_mask.b.xacterr = 1;
4100 + hc_intr_mask.b.bblerr = 1;
4105 + dwc_write_reg32(&hc_regs->hcintmsk, hc_intr_mask.d32);
4107 +// if(hc->ep_type == DWC_OTG_EP_TYPE_BULK && !hc->ep_is_in)
4108 +// hc->max_packet = 512;
4109 + /* Enable the top level host channel interrupt. */
4110 + intr_enable = (1 << hc_num);
4111 + dwc_modify_reg32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
4113 + /* Make sure host channel interrupts are enabled. */
4114 + gintmsk.b.hcintr = 1;
4115 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
4118 + * Program the HCCHARn register with the endpoint characteristics for
4119 + * the current transfer.
4122 + hcchar.b.devaddr = hc->dev_addr;
4123 + hcchar.b.epnum = hc->ep_num;
4124 + hcchar.b.epdir = hc->ep_is_in;
4125 + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
4126 + hcchar.b.eptype = hc->ep_type;
4127 + hcchar.b.mps = hc->max_packet;
4129 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
4131 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
4132 + DWC_DEBUGPL(DBG_HCDV, " Dev Addr: %d\n", hcchar.b.devaddr);
4133 + DWC_DEBUGPL(DBG_HCDV, " Ep Num: %d\n", hcchar.b.epnum);
4134 + DWC_DEBUGPL(DBG_HCDV, " Is In: %d\n", hcchar.b.epdir);
4135 + DWC_DEBUGPL(DBG_HCDV, " Is Low Speed: %d\n", hcchar.b.lspddev);
4136 + DWC_DEBUGPL(DBG_HCDV, " Ep Type: %d\n", hcchar.b.eptype);
4137 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
4138 + DWC_DEBUGPL(DBG_HCDV, " Multi Cnt: %d\n", hcchar.b.multicnt);
4141 + * Program the HCSPLIT register for SPLITs
4144 + if (hc->do_split) {
4145 + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n", hc->hc_num,
4146 + hc->complete_split ? "CSPLIT" : "SSPLIT");
4147 + hcsplt.b.compsplt = hc->complete_split;
4148 + hcsplt.b.xactpos = hc->xact_pos;
4149 + hcsplt.b.hubaddr = hc->hub_addr;
4150 + hcsplt.b.prtaddr = hc->port_addr;
4151 + DWC_DEBUGPL(DBG_HCDV, " comp split %d\n", hc->complete_split);
4152 + DWC_DEBUGPL(DBG_HCDV, " xact pos %d\n", hc->xact_pos);
4153 + DWC_DEBUGPL(DBG_HCDV, " hub addr %d\n", hc->hub_addr);
4154 + DWC_DEBUGPL(DBG_HCDV, " port addr %d\n", hc->port_addr);
4155 + DWC_DEBUGPL(DBG_HCDV, " is_in %d\n", hc->ep_is_in);
4156 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
4157 + DWC_DEBUGPL(DBG_HCDV, " xferlen: %d\n", hc->xfer_len);
4159 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
4164 + * Attempts to halt a host channel. This function should only be called in
4165 + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
4166 + * normal circumstances in DMA mode, the controller halts the channel when the
4167 + * transfer is complete or a condition occurs that requires application
4170 + * In slave mode, checks for a free request queue entry, then sets the Channel
4171 + * Enable and Channel Disable bits of the Host Channel Characteristics
4172 + * register of the specified channel to intiate the halt. If there is no free
4173 + * request queue entry, sets only the Channel Disable bit of the HCCHARn
4174 + * register to flush requests for this channel. In the latter case, sets a
4175 + * flag to indicate that the host channel needs to be halted when a request
4176 + * queue slot is open.
4178 + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
4179 + * HCCHARn register. The controller ensures there is space in the request
4180 + * queue before submitting the halt request.
4182 + * Some time may elapse before the core flushes any posted requests for this
4183 + * host channel and halts. The Channel Halted interrupt handler completes the
4184 + * deactivation of the host channel.
4186 + * @param core_if Controller register interface.
4187 + * @param hc Host channel to halt.
4188 + * @param halt_status Reason for halting the channel.
4190 +void dwc_otg_hc_halt(dwc_otg_core_if_t *core_if,
4192 + dwc_otg_halt_status_e halt_status)
4194 + gnptxsts_data_t nptxsts;
4195 + hptxsts_data_t hptxsts;
4196 + hcchar_data_t hcchar;
4197 + dwc_otg_hc_regs_t *hc_regs;
4198 + dwc_otg_core_global_regs_t *global_regs;
4199 + dwc_otg_host_global_regs_t *host_global_regs;
4201 + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4202 + global_regs = core_if->core_global_regs;
4203 + host_global_regs = core_if->host_if->host_global_regs;
4205 + WARN_ON(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS);
4207 + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
4208 + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
4210 + * Disable all channel interrupts except Ch Halted. The QTD
4211 + * and QH state associated with this transfer has been cleared
4212 + * (in the case of URB_DEQUEUE), so the channel needs to be
4213 + * shut down carefully to prevent crashes.
4215 + hcintmsk_data_t hcintmsk;
4217 + hcintmsk.b.chhltd = 1;
4218 + dwc_write_reg32(&hc_regs->hcintmsk, hcintmsk.d32);
4221 + * Make sure no other interrupts besides halt are currently
4222 + * pending. Handling another interrupt could cause a crash due
4223 + * to the QTD and QH state.
4225 + dwc_write_reg32(&hc_regs->hcint, ~hcintmsk.d32);
4228 + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
4229 + * even if the channel was already halted for some other
4232 + hc->halt_status = halt_status;
4234 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4235 + if (hcchar.b.chen == 0) {
4237 + * The channel is either already halted or it hasn't
4238 + * started yet. In DMA mode, the transfer may halt if
4239 + * it finishes normally or a condition occurs that
4240 + * requires driver intervention. Don't want to halt
4241 + * the channel again. In either Slave or DMA mode,
4242 + * it's possible that the transfer has been assigned
4243 + * to a channel, but not started yet when an URB is
4244 + * dequeued. Don't want to halt a channel that hasn't
4251 + if (hc->halt_pending) {
4253 + * A halt has already been issued for this channel. This might
4254 + * happen when a transfer is aborted by a higher level in
4258 + DWC_PRINT("*** %s: Channel %d, _hc->halt_pending already set ***\n",
4259 + __func__, hc->hc_num);
4261 +/* dwc_otg_dump_global_registers(core_if); */
4262 +/* dwc_otg_dump_host_registers(core_if); */
4267 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4268 + hcchar.b.chen = 1;
4269 + hcchar.b.chdis = 1;
4271 + if (!core_if->dma_enable) {
4272 + /* Check for space in the request queue to issue the halt. */
4273 + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
4274 + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
4275 + nptxsts.d32 = dwc_read_reg32(&global_regs->gnptxsts);
4276 + if (nptxsts.b.nptxqspcavail == 0) {
4277 + hcchar.b.chen = 0;
4281 + hptxsts.d32 = dwc_read_reg32(&host_global_regs->hptxsts);
4282 + if ((hptxsts.b.ptxqspcavail == 0) || (core_if->queuing_high_bandwidth)) {
4283 + hcchar.b.chen = 0;
4288 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
4290 + hc->halt_status = halt_status;
4292 + if (hcchar.b.chen) {
4293 + hc->halt_pending = 1;
4294 + hc->halt_on_queue = 0;
4297 + hc->halt_on_queue = 1;
4300 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
4301 + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
4302 + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
4303 + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
4304 + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
4310 + * Clears the transfer state for a host channel. This function is normally
4311 + * called after a transfer is done and the host channel is being released.
4313 + * @param core_if Programming view of DWC_otg controller.
4314 + * @param hc Identifies the host channel to clean up.
4316 +void dwc_otg_hc_cleanup(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4318 + dwc_otg_hc_regs_t *hc_regs;
4320 + hc->xfer_started = 0;
4323 + * Clear channel interrupt enables and any unhandled channel interrupt
4326 + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4327 + dwc_write_reg32(&hc_regs->hcintmsk, 0);
4328 + dwc_write_reg32(&hc_regs->hcint, 0xFFFFFFFF);
4331 + del_timer(&core_if->hc_xfer_timer[hc->hc_num]);
4333 + hcchar_data_t hcchar;
4334 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4335 + if (hcchar.b.chdis) {
4336 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
4337 + __func__, hc->hc_num, hcchar.d32);
4344 + * Sets the channel property that indicates in which frame a periodic transfer
4345 + * should occur. This is always set to the _next_ frame. This function has no
4346 + * effect on non-periodic transfers.
4348 + * @param core_if Programming view of DWC_otg controller.
4349 + * @param hc Identifies the host channel to set up and its properties.
4350 + * @param hcchar Current value of the HCCHAR register for the specified host
4353 +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t *core_if,
4355 + hcchar_data_t *hcchar)
4357 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
4358 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4359 + hfnum_data_t hfnum;
4360 + hfnum.d32 = dwc_read_reg32(&core_if->host_if->host_global_regs->hfnum);
4362 + /* 1 if _next_ frame is odd, 0 if it's even */
4363 + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
4365 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split && !hc->complete_split) {
4366 + switch (hfnum.b.frnum & 0x7) {
4368 + core_if->hfnum_7_samples++;
4369 + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
4372 + core_if->hfnum_0_samples++;
4373 + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
4376 + core_if->hfnum_other_samples++;
4377 + core_if->hfnum_other_frrem_accum += hfnum.b.frrem;
4386 +static void hc_xfer_timeout(unsigned long ptr)
4388 + hc_xfer_info_t *xfer_info = (hc_xfer_info_t *)ptr;
4389 + int hc_num = xfer_info->hc->hc_num;
4390 + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
4391 + DWC_WARN(" start_hcchar_val 0x%08x\n", xfer_info->core_if->start_hcchar_val[hc_num]);
4396 + * This function does the setup for a data transfer for a host channel and
4397 + * starts the transfer. May be called in either Slave mode or DMA mode. In
4398 + * Slave mode, the caller must ensure that there is sufficient space in the
4399 + * request queue and Tx Data FIFO.
4401 + * For an OUT transfer in Slave mode, it loads a data packet into the
4402 + * appropriate FIFO. If necessary, additional data packets will be loaded in
4405 + * For an IN transfer in Slave mode, a data packet is requested. The data
4406 + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
4407 + * additional data packets are requested in the Host ISR.
4409 + * For a PING transfer in Slave mode, the Do Ping bit is set in the egards,
4413 + * register along with a packet count of 1 and the channel is enabled. This
4414 + * causes a single PING transaction to occur. Other fields in HCTSIZ are
4415 + * simply set to 0 since no data transfer occurs in this case.
4417 + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
4418 + * all the information required to perform the subsequent data transfer. In
4419 + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
4420 + * controller performs the entire PING protocol, then starts the data
4423 + * @param core_if Programming view of DWC_otg controller.
4424 + * @param hc Information needed to initialize the host channel. The xfer_len
4425 + * value may be reduced to accommodate the max widths of the XferSize and
4426 + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
4427 + * to reflect the final xfer_len value.
4429 +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4431 + hcchar_data_t hcchar;
4432 + hctsiz_data_t hctsiz;
4433 + uint16_t num_packets;
4434 + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
4435 + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
4436 + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4440 + if (hc->do_ping) {
4441 + if (!core_if->dma_enable) {
4442 + dwc_otg_hc_do_ping(core_if, hc);
4443 + hc->xfer_started = 1;
4447 + hctsiz.b.dopng = 1;
4451 + if (hc->do_split) {
4454 + if (hc->complete_split && !hc->ep_is_in) {
4455 + /* For CSPLIT OUT Transfer, set the size to 0 so the
4456 + * core doesn't expect any data written to the FIFO */
4459 + else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
4460 + hc->xfer_len = hc->max_packet;
4462 + else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
4463 + hc->xfer_len = 188;
4466 + hctsiz.b.xfersize = hc->xfer_len;
4470 + * Ensure that the transfer length and packet count will fit
4471 + * in the widths allocated for them in the HCTSIZn register.
4473 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
4474 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4476 + * Make sure the transfer size is no larger than one
4477 + * (micro)frame's worth of data. (A check was done
4478 + * when the periodic transfer was accepted to ensure
4479 + * that a (micro)frame's worth of data can be
4480 + * programmed into a channel.)
4482 + uint32_t max_periodic_len = hc->multi_count * hc->max_packet;
4483 + if (hc->xfer_len > max_periodic_len) {
4484 + hc->xfer_len = max_periodic_len;
4490 + else if (hc->xfer_len > max_hc_xfer_size) {
4491 + /* Make sure that xfer_len is a multiple of max packet size. */
4492 + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
4495 + if (hc->xfer_len > 0) {
4496 + num_packets = (hc->xfer_len + hc->max_packet - 1) / hc->max_packet;
4497 + if (num_packets > max_hc_pkt_count) {
4498 + num_packets = max_hc_pkt_count;
4499 + hc->xfer_len = num_packets * hc->max_packet;
4503 + /* Need 1 packet for transfer length of 0. */
4507 + if (hc->ep_is_in) {
4508 + /* Always program an integral # of max packets for IN transfers. */
4509 + hc->xfer_len = num_packets * hc->max_packet;
4512 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
4513 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4515 + * Make sure that the multi_count field matches the
4516 + * actual transfer length.
4518 + hc->multi_count = num_packets;
4521 + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4522 + /* Set up the initial PID for the transfer. */
4523 + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
4524 + if (hc->ep_is_in) {
4525 + if (hc->multi_count == 1) {
4526 + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
4528 + else if (hc->multi_count == 2) {
4529 + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
4532 + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
4536 + if (hc->multi_count == 1) {
4537 + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
4540 + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
4545 + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
4549 + hctsiz.b.xfersize = hc->xfer_len;
4552 + hc->start_pkt_count = num_packets;
4553 + hctsiz.b.pktcnt = num_packets;
4554 + hctsiz.b.pid = hc->data_pid_start;
4555 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
4557 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
4558 + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
4559 + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
4560 + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
4562 + if (core_if->dma_enable) {
4563 +#if defined (CONFIG_DWC_OTG_HOST_ONLY)
4564 + if ((uint32_t)hc->xfer_buff & 0x3) {
4565 + /* non DWORD-aligned buffer case*/
4566 + if(!hc->qh->dw_align_buf) {
4567 + hc->qh->dw_align_buf =
4568 + dma_alloc_coherent(NULL,
4569 + core_if->core_params->max_transfer_size,
4570 + &hc->qh->dw_align_buf_dma,
4571 + GFP_ATOMIC | GFP_DMA);
4572 + if (!hc->qh->dw_align_buf) {
4574 + DWC_ERROR("%s: Failed to allocate memory to handle "
4575 + "non-dword aligned buffer case\n", __func__);
4580 + if (!hc->ep_is_in) {
4581 + memcpy(hc->qh->dw_align_buf, phys_to_virt((uint32_t)hc->xfer_buff), hc->xfer_len);
4584 + dwc_write_reg32(&hc_regs->hcdma, hc->qh->dw_align_buf_dma);
4588 + dwc_write_reg32(&hc_regs->hcdma, (uint32_t)hc->xfer_buff);
4591 + /* Start the split */
4592 + if (hc->do_split) {
4593 + hcsplt_data_t hcsplt;
4594 + hcsplt.d32 = dwc_read_reg32 (&hc_regs->hcsplt);
4595 + hcsplt.b.spltena = 1;
4596 + dwc_write_reg32(&hc_regs->hcsplt, hcsplt.d32);
4599 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4600 + hcchar.b.multicnt = hc->multi_count;
4601 + hc_set_even_odd_frame(core_if, hc, &hcchar);
4603 + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
4604 + if (hcchar.b.chdis) {
4605 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
4606 + __func__, hc->hc_num, hcchar.d32);
4610 + /* Set host channel enable after all other setup is complete. */
4611 + hcchar.b.chen = 1;
4612 + hcchar.b.chdis = 0;
4613 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
4615 + hc->xfer_started = 1;
4618 + if (!core_if->dma_enable &&
4619 + !hc->ep_is_in && hc->xfer_len > 0) {
4620 + /* Load OUT packet into the appropriate Tx FIFO. */
4621 + dwc_otg_hc_write_packet(core_if, hc);
4625 + /* Start a timer for this transfer. */
4626 + core_if->hc_xfer_timer[hc->hc_num].function = hc_xfer_timeout;
4627 + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
4628 + core_if->hc_xfer_info[hc->hc_num].hc = hc;
4629 + core_if->hc_xfer_timer[hc->hc_num].data = (unsigned long)(&core_if->hc_xfer_info[hc->hc_num]);
4630 + core_if->hc_xfer_timer[hc->hc_num].expires = jiffies + (HZ*10);
4631 + add_timer(&core_if->hc_xfer_timer[hc->hc_num]);
4636 + * This function continues a data transfer that was started by previous call
4637 + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
4638 + * sufficient space in the request queue and Tx Data FIFO. This function
4639 + * should only be called in Slave mode. In DMA mode, the controller acts
4640 + * autonomously to complete transfers programmed to a host channel.
4642 + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
4643 + * if there is any data remaining to be queued. For an IN transfer, another
4644 + * data packet is always requested. For the SETUP phase of a control transfer,
4645 + * this function does nothing.
4647 + * @return 1 if a new request is queued, 0 if no more requests are required
4648 + * for this transfer.
4650 +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4652 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
4654 + if (hc->do_split) {
4655 + /* SPLITs always queue just once per channel */
4658 + else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
4659 + /* SETUPs are queued only once since they can't be NAKed. */
4662 + else if (hc->ep_is_in) {
4664 + * Always queue another request for other IN transfers. If
4665 + * back-to-back INs are issued and NAKs are received for both,
4666 + * the driver may still be processing the first NAK when the
4667 + * second NAK is received. When the interrupt handler clears
4668 + * the NAK interrupt for the first NAK, the second NAK will
4669 + * not be seen. So we can't depend on the NAK interrupt
4670 + * handler to requeue a NAKed request. Instead, IN requests
4671 + * are issued each time this function is called. When the
4672 + * transfer completes, the extra requests for the channel will
4675 + hcchar_data_t hcchar;
4676 + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4678 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4679 + hc_set_even_odd_frame(core_if, hc, &hcchar);
4680 + hcchar.b.chen = 1;
4681 + hcchar.b.chdis = 0;
4682 + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n", hcchar.d32);
4683 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
4688 + /* OUT transfers. */
4689 + if (hc->xfer_count < hc->xfer_len) {
4690 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
4691 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4692 + hcchar_data_t hcchar;
4693 + dwc_otg_hc_regs_t *hc_regs;
4694 + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4695 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4696 + hc_set_even_odd_frame(core_if, hc, &hcchar);
4699 + /* Load OUT packet into the appropriate Tx FIFO. */
4700 + dwc_otg_hc_write_packet(core_if, hc);
4711 + * Starts a PING transfer. This function should only be called in Slave mode.
4712 + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
4714 +void dwc_otg_hc_do_ping(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4716 + hcchar_data_t hcchar;
4717 + hctsiz_data_t hctsiz;
4718 + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4720 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
4723 + hctsiz.b.dopng = 1;
4724 + hctsiz.b.pktcnt = 1;
4725 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
4727 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4728 + hcchar.b.chen = 1;
4729 + hcchar.b.chdis = 0;
4730 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
4734 + * This function writes a packet into the Tx FIFO associated with the Host
4735 + * Channel. For a channel associated with a non-periodic EP, the non-periodic
4736 + * Tx FIFO is written. For a channel associated with a periodic EP, the
4737 + * periodic Tx FIFO is written. This function should only be called in Slave
4740 + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
4741 + * then number of bytes written to the Tx FIFO.
4743 +void dwc_otg_hc_write_packet(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4746 + uint32_t remaining_count;
4747 + uint32_t byte_count;
4748 + uint32_t dword_count;
4750 + uint32_t *data_buff = (uint32_t *)(hc->xfer_buff);
4751 + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
4753 + remaining_count = hc->xfer_len - hc->xfer_count;
4754 + if (remaining_count > hc->max_packet) {
4755 + byte_count = hc->max_packet;
4758 + byte_count = remaining_count;
4761 + dword_count = (byte_count + 3) / 4;
4763 + if ((((unsigned long)data_buff) & 0x3) == 0) {
4764 + /* xfer_buff is DWORD aligned. */
4765 + for (i = 0; i < dword_count; i++, data_buff++)
4767 + dwc_write_reg32(data_fifo, *data_buff);
4771 + /* xfer_buff is not DWORD aligned. */
4772 + for (i = 0; i < dword_count; i++, data_buff++)
4774 + dwc_write_reg32(data_fifo, get_unaligned(data_buff));
4778 + hc->xfer_count += byte_count;
4779 + hc->xfer_buff += byte_count;
4783 + * Gets the current USB frame number. This is the frame number from the last
4786 +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *core_if)
4789 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
4791 + /* read current frame/microframe number from DSTS register */
4792 + return dsts.b.soffn;
4796 + * This function reads a setup packet from the Rx FIFO into the destination
4797 + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
4798 + * Interrupt routine when a SETUP packet has been received in Slave mode.
4800 + * @param core_if Programming view of DWC_otg controller.
4801 + * @param dest Destination buffer for packet data.
4803 +void dwc_otg_read_setup_packet(dwc_otg_core_if_t *core_if, uint32_t *dest)
4805 + /* Get the 8 bytes of a setup transaction data */
4807 + /* Pop 2 DWORDS off the receive data FIFO into memory */
4808 + dest[0] = dwc_read_reg32(core_if->data_fifo[0]);
4809 + dest[1] = dwc_read_reg32(core_if->data_fifo[0]);
4814 + * This function enables EP0 OUT to receive SETUP packets and configures EP0
4815 + * IN for transmitting packets. It is normally called when the
4816 + * "Enumeration Done" interrupt occurs.
4818 + * @param core_if Programming view of DWC_otg controller.
4819 + * @param ep The EP0 data.
4821 +void dwc_otg_ep0_activate(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
4823 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
4825 + depctl_data_t diepctl;
4826 + depctl_data_t doepctl;
4827 + dctl_data_t dctl = { .d32 = 0 };
4829 + /* Read the Device Status and Endpoint 0 Control registers */
4830 + dsts.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dsts);
4831 + diepctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl);
4832 + doepctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl);
4834 + /* Set the MPS of the IN EP based on the enumeration speed */
4835 + switch (dsts.b.enumspd) {
4836 + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
4837 + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
4838 + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
4839 + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
4841 + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
4842 + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
4846 + dwc_write_reg32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
4848 + /* Enable OUT EP for receive */
4849 + doepctl.b.epena = 1;
4850 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
4853 + DWC_DEBUGPL(DBG_PCDV,"doepctl0=%0x\n",
4854 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
4855 + DWC_DEBUGPL(DBG_PCDV,"diepctl0=%0x\n",
4856 + dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl));
4858 + dctl.b.cgnpinnak = 1;
4860 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
4861 + DWC_DEBUGPL(DBG_PCDV,"dctl=%0x\n",
4862 + dwc_read_reg32(&dev_if->dev_global_regs->dctl));
4866 + * This function activates an EP. The Device EP control register for
4867 + * the EP is configured as defined in the ep structure. Note: This
4868 + * function is not used for EP0.
4870 + * @param core_if Programming view of DWC_otg controller.
4871 + * @param ep The EP to activate.
4873 +void dwc_otg_ep_activate(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
4875 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
4876 + depctl_data_t depctl;
4877 + volatile uint32_t *addr;
4878 + daint_data_t daintmsk = { .d32 = 0 };
4880 + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
4881 + (ep->is_in?"IN":"OUT"));
4883 + /* Read DEPCTLn register */
4884 + if (ep->is_in == 1) {
4885 + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
4886 + daintmsk.ep.in = 1<<ep->num;
4889 + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
4890 + daintmsk.ep.out = 1<<ep->num;
4893 + /* If the EP is already active don't change the EP Control
4895 + depctl.d32 = dwc_read_reg32(addr);
4896 + if (!depctl.b.usbactep) {
4897 + depctl.b.mps = ep->maxpacket;
4898 + depctl.b.eptype = ep->type;
4899 + depctl.b.txfnum = ep->tx_fifo_num;
4901 + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
4902 + depctl.b.setd0pid = 1; // ???
4905 + depctl.b.setd0pid = 1;
4907 + depctl.b.usbactep = 1;
4909 + dwc_write_reg32(addr, depctl.d32);
4910 + DWC_DEBUGPL(DBG_PCDV,"DEPCTL=%08x\n", dwc_read_reg32(addr));
4913 + /* Enable the Interrupt for this EP */
4914 + if(core_if->multiproc_int_enable) {
4915 + if (ep->is_in == 1) {
4916 + diepmsk_data_t diepmsk = { .d32 = 0};
4917 + diepmsk.b.xfercompl = 1;
4918 + diepmsk.b.timeout = 1;
4919 + diepmsk.b.epdisabled = 1;
4920 + diepmsk.b.ahberr = 1;
4921 + diepmsk.b.intknepmis = 1;
4922 + diepmsk.b.txfifoundrn = 1; //?????
4925 + if(core_if->dma_desc_enable) {
4926 + diepmsk.b.bna = 1;
4929 + if(core_if->dma_enable) {
4930 + doepmsk.b.nak = 1;
4933 + dwc_write_reg32(&dev_if->dev_global_regs->diepeachintmsk[ep->num], diepmsk.d32);
4936 + doepmsk_data_t doepmsk = { .d32 = 0};
4937 + doepmsk.b.xfercompl = 1;
4938 + doepmsk.b.ahberr = 1;
4939 + doepmsk.b.epdisabled = 1;
4942 + if(core_if->dma_desc_enable) {
4943 + doepmsk.b.bna = 1;
4946 + doepmsk.b.babble = 1;
4947 + doepmsk.b.nyet = 1;
4948 + doepmsk.b.nak = 1;
4950 + dwc_write_reg32(&dev_if->dev_global_regs->doepeachintmsk[ep->num], doepmsk.d32);
4952 + dwc_modify_reg32(&dev_if->dev_global_regs->deachintmsk,
4955 + dwc_modify_reg32(&dev_if->dev_global_regs->daintmsk,
4959 + DWC_DEBUGPL(DBG_PCDV,"DAINTMSK=%0x\n",
4960 + dwc_read_reg32(&dev_if->dev_global_regs->daintmsk));
4962 + ep->stall_clear_flag = 0;
4967 + * This function deactivates an EP. This is done by clearing the USB Active
4968 + * EP bit in the Device EP control register. Note: This function is not used
4969 + * for EP0. EP0 cannot be deactivated.
4971 + * @param core_if Programming view of DWC_otg controller.
4972 + * @param ep The EP to deactivate.
4974 +void dwc_otg_ep_deactivate(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
4976 + depctl_data_t depctl = { .d32 = 0 };
4977 + volatile uint32_t *addr;
4978 + daint_data_t daintmsk = { .d32 = 0};
4980 + /* Read DEPCTLn register */
4981 + if (ep->is_in == 1) {
4982 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
4983 + daintmsk.ep.in = 1<<ep->num;
4986 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
4987 + daintmsk.ep.out = 1<<ep->num;
4990 + depctl.b.usbactep = 0;
4992 + if(core_if->dma_desc_enable)
4993 + depctl.b.epdis = 1;
4995 + dwc_write_reg32(addr, depctl.d32);
4997 + /* Disable the Interrupt for this EP */
4998 + if(core_if->multiproc_int_enable) {
4999 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->deachintmsk,
5002 + if (ep->is_in == 1) {
5003 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->diepeachintmsk[ep->num], 0);
5005 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[ep->num], 0);
5008 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->daintmsk,
5014 + * This function does the setup for a data transfer for an EP and
5015 + * starts the transfer. For an IN transfer, the packets will be
5016 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
5017 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
5019 + * @param core_if Programming view of DWC_otg controller.
5020 + * @param ep The EP to start the transfer on.
5022 +static void init_dma_desc_chain(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5024 + dwc_otg_dma_desc_t* dma_desc;
5026 + uint32_t xfer_est;
5029 + ep->desc_cnt = ( ep->total_len / ep->maxxfer) +
5030 + ((ep->total_len % ep->maxxfer) ? 1 : 0);
5034 + dma_desc = ep->desc_addr;
5035 + xfer_est = ep->total_len;
5037 + for( i = 0; i < ep->desc_cnt; ++i) {
5038 + /** DMA Descriptor Setup */
5039 + if(xfer_est > ep->maxxfer) {
5040 + dma_desc->status.b.bs = BS_HOST_BUSY;
5041 + dma_desc->status.b.l = 0;
5042 + dma_desc->status.b.ioc = 0;
5043 + dma_desc->status.b.sp = 0;
5044 + dma_desc->status.b.bytes = ep->maxxfer;
5045 + dma_desc->buf = ep->dma_addr + offset;
5046 + dma_desc->status.b.bs = BS_HOST_READY;
5048 + xfer_est -= ep->maxxfer;
5049 + offset += ep->maxxfer;
5051 + dma_desc->status.b.bs = BS_HOST_BUSY;
5052 + dma_desc->status.b.l = 1;
5053 + dma_desc->status.b.ioc = 1;
5055 + dma_desc->status.b.sp = (xfer_est % ep->maxpacket) ?
5056 + 1 : ((ep->sent_zlp) ? 1 : 0);
5057 + dma_desc->status.b.bytes = xfer_est;
5059 + dma_desc->status.b.bytes = xfer_est + ((4 - (xfer_est & 0x3)) & 0x3) ;
5062 + dma_desc->buf = ep->dma_addr + offset;
5063 + dma_desc->status.b.bs = BS_HOST_READY;
5070 + * This function does the setup for a data transfer for an EP and
5071 + * starts the transfer. For an IN transfer, the packets will be
5072 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
5073 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
5075 + * @param core_if Programming view of DWC_otg controller.
5076 + * @param ep The EP to start the transfer on.
5079 +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5081 + depctl_data_t depctl;
5082 + deptsiz_data_t deptsiz;
5083 + gintmsk_data_t intr_mask = { .d32 = 0};
5085 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
5087 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
5088 + "xfer_buff=%p start_xfer_buff=%p\n",
5089 + ep->num, (ep->is_in?"IN":"OUT"), ep->xfer_len,
5090 + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
5093 + if (ep->is_in == 1) {
5094 + dwc_otg_dev_in_ep_regs_t *in_regs =
5095 + core_if->dev_if->in_ep_regs[ep->num];
5097 + gnptxsts_data_t gtxstatus;
5100 + dwc_read_reg32(&core_if->core_global_regs->gnptxsts);
5102 + if(core_if->en_multiple_tx_fifo == 0 && gtxstatus.b.nptxqspcavail == 0) {
5104 + DWC_PRINT("TX Queue Full (0x%0x)\n", gtxstatus.d32);
5109 + depctl.d32 = dwc_read_reg32(&(in_regs->diepctl));
5110 + deptsiz.d32 = dwc_read_reg32(&(in_regs->dieptsiz));
5112 + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
5113 + ep->maxxfer : (ep->total_len - ep->xfer_len);
5115 + /* Zero Length Packet? */
5116 + if ((ep->xfer_len - ep->xfer_count) == 0) {
5117 + deptsiz.b.xfersize = 0;
5118 + deptsiz.b.pktcnt = 1;
5121 + /* Program the transfer size and packet count
5122 + * as follows: xfersize = N * maxpacket +
5123 + * short_packet pktcnt = N + (short_packet
5126 + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
5127 + deptsiz.b.pktcnt =
5128 + (ep->xfer_len - ep->xfer_count - 1 + ep->maxpacket) /
5133 + /* Write the DMA register */
5134 + if (core_if->dma_enable) {
5135 + if (core_if->dma_desc_enable == 0) {
5136 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5137 + dwc_write_reg32 (&(in_regs->diepdma),
5138 + (uint32_t)ep->dma_addr);
5141 + init_dma_desc_chain(core_if, ep);
5142 + /** DIEPDMAn Register write */
5143 + dwc_write_reg32(&in_regs->diepdma, ep->dma_desc_addr);
5147 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5148 + if(ep->type != DWC_OTG_EP_TYPE_ISOC) {
5150 + * Enable the Non-Periodic Tx FIFO empty interrupt,
5151 + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
5152 + * the data will be written into the fifo by the ISR.
5154 + if(core_if->en_multiple_tx_fifo == 0) {
5155 + intr_mask.b.nptxfempty = 1;
5156 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
5157 + intr_mask.d32, intr_mask.d32);
5160 + /* Enable the Tx FIFO Empty Interrupt for this EP */
5161 + if(ep->xfer_len > 0) {
5162 + uint32_t fifoemptymsk = 0;
5163 + fifoemptymsk = 1 << ep->num;
5164 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
5172 + /* EP enable, IN data in FIFO */
5173 + depctl.b.cnak = 1;
5174 + depctl.b.epena = 1;
5175 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
5177 + depctl.d32 = dwc_read_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl);
5178 + depctl.b.nextep = ep->num;
5179 + dwc_write_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl, depctl.d32);
5183 + /* OUT endpoint */
5184 + dwc_otg_dev_out_ep_regs_t *out_regs =
5185 + core_if->dev_if->out_ep_regs[ep->num];
5187 + depctl.d32 = dwc_read_reg32(&(out_regs->doepctl));
5188 + deptsiz.d32 = dwc_read_reg32(&(out_regs->doeptsiz));
5190 + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
5191 + ep->maxxfer : (ep->total_len - ep->xfer_len);
5193 + /* Program the transfer size and packet count as follows:
5196 + * xfersize = N * maxpacket
5198 + if ((ep->xfer_len - ep->xfer_count) == 0) {
5199 + /* Zero Length Packet */
5200 + deptsiz.b.xfersize = ep->maxpacket;
5201 + deptsiz.b.pktcnt = 1;
5204 + deptsiz.b.pktcnt =
5205 + (ep->xfer_len - ep->xfer_count + (ep->maxpacket - 1)) /
5207 + ep->xfer_len = deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
5208 + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
5211 + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
5213 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
5215 + if (core_if->dma_enable) {
5216 + if (!core_if->dma_desc_enable) {
5217 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5219 + dwc_write_reg32 (&(out_regs->doepdma),
5220 + (uint32_t)ep->dma_addr);
5223 + init_dma_desc_chain(core_if, ep);
5225 + /** DOEPDMAn Register write */
5226 + dwc_write_reg32(&out_regs->doepdma, ep->dma_desc_addr);
5230 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5234 + depctl.b.cnak = 1;
5235 + depctl.b.epena = 1;
5237 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
5239 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
5240 + dwc_read_reg32(&out_regs->doepctl),
5241 + dwc_read_reg32(&out_regs->doeptsiz));
5242 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
5243 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk),
5244 + dwc_read_reg32(&core_if->core_global_regs->gintmsk));
5249 + * This function setup a zero length transfer in Buffer DMA and
5250 + * Slave modes for usb requests with zero field set
5252 + * @param core_if Programming view of DWC_otg controller.
5253 + * @param ep The EP to start the transfer on.
5256 +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5259 + depctl_data_t depctl;
5260 + deptsiz_data_t deptsiz;
5261 + gintmsk_data_t intr_mask = { .d32 = 0};
5263 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
5266 + if (ep->is_in == 1) {
5267 + dwc_otg_dev_in_ep_regs_t *in_regs =
5268 + core_if->dev_if->in_ep_regs[ep->num];
5270 + depctl.d32 = dwc_read_reg32(&(in_regs->diepctl));
5271 + deptsiz.d32 = dwc_read_reg32(&(in_regs->dieptsiz));
5273 + deptsiz.b.xfersize = 0;
5274 + deptsiz.b.pktcnt = 1;
5277 + /* Write the DMA register */
5278 + if (core_if->dma_enable) {
5279 + if (core_if->dma_desc_enable == 0) {
5280 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5281 + dwc_write_reg32 (&(in_regs->diepdma),
5282 + (uint32_t)ep->dma_addr);
5286 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5288 + * Enable the Non-Periodic Tx FIFO empty interrupt,
5289 + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
5290 + * the data will be written into the fifo by the ISR.
5292 + if(core_if->en_multiple_tx_fifo == 0) {
5293 + intr_mask.b.nptxfempty = 1;
5294 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
5295 + intr_mask.d32, intr_mask.d32);
5298 + /* Enable the Tx FIFO Empty Interrupt for this EP */
5299 + if(ep->xfer_len > 0) {
5300 + uint32_t fifoemptymsk = 0;
5301 + fifoemptymsk = 1 << ep->num;
5302 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
5308 + /* EP enable, IN data in FIFO */
5309 + depctl.b.cnak = 1;
5310 + depctl.b.epena = 1;
5311 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
5313 + depctl.d32 = dwc_read_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl);
5314 + depctl.b.nextep = ep->num;
5315 + dwc_write_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl, depctl.d32);
5319 + /* OUT endpoint */
5320 + dwc_otg_dev_out_ep_regs_t *out_regs =
5321 + core_if->dev_if->out_ep_regs[ep->num];
5323 + depctl.d32 = dwc_read_reg32(&(out_regs->doepctl));
5324 + deptsiz.d32 = dwc_read_reg32(&(out_regs->doeptsiz));
5326 + /* Zero Length Packet */
5327 + deptsiz.b.xfersize = ep->maxpacket;
5328 + deptsiz.b.pktcnt = 1;
5330 + if (core_if->dma_enable) {
5331 + if (!core_if->dma_desc_enable) {
5332 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5334 + dwc_write_reg32 (&(out_regs->doepdma),
5335 + (uint32_t)ep->dma_addr);
5339 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5343 + depctl.b.cnak = 1;
5344 + depctl.b.epena = 1;
5346 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
5352 + * This function does the setup for a data transfer for EP0 and starts
5353 + * the transfer. For an IN transfer, the packets will be loaded into
5354 + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
5355 + * unloaded from the Rx FIFO in the ISR.
5357 + * @param core_if Programming view of DWC_otg controller.
5358 + * @param ep The EP0 data.
5360 +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5362 + depctl_data_t depctl;
5363 + deptsiz0_data_t deptsiz;
5364 + gintmsk_data_t intr_mask = { .d32 = 0};
5365 + dwc_otg_dma_desc_t* dma_desc;
5367 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
5368 + "xfer_buff=%p start_xfer_buff=%p \n",
5369 + ep->num, (ep->is_in?"IN":"OUT"), ep->xfer_len,
5370 + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
5372 + ep->total_len = ep->xfer_len;
5375 + if (ep->is_in == 1) {
5376 + dwc_otg_dev_in_ep_regs_t *in_regs =
5377 + core_if->dev_if->in_ep_regs[0];
5379 + gnptxsts_data_t gtxstatus;
5382 + dwc_read_reg32(&core_if->core_global_regs->gnptxsts);
5384 + if(core_if->en_multiple_tx_fifo == 0 && gtxstatus.b.nptxqspcavail == 0) {
5386 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
5387 + DWC_DEBUGPL(DBG_PCD,"DIEPCTL0=%0x\n",
5388 + dwc_read_reg32(&in_regs->diepctl));
5389 + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
5391 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
5392 + DWC_PRINT("TX Queue or FIFO Full (0x%0x)\n",
5399 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
5400 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
5402 + /* Zero Length Packet? */
5403 + if (ep->xfer_len == 0) {
5404 + deptsiz.b.xfersize = 0;
5405 + deptsiz.b.pktcnt = 1;
5408 + /* Program the transfer size and packet count
5409 + * as follows: xfersize = N * maxpacket +
5410 + * short_packet pktcnt = N + (short_packet
5413 + if (ep->xfer_len > ep->maxpacket) {
5414 + ep->xfer_len = ep->maxpacket;
5415 + deptsiz.b.xfersize = ep->maxpacket;
5418 + deptsiz.b.xfersize = ep->xfer_len;
5420 + deptsiz.b.pktcnt = 1;
5423 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
5425 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
5427 + /* Write the DMA register */
5428 + if (core_if->dma_enable) {
5429 + if(core_if->dma_desc_enable == 0) {
5430 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5432 + dwc_write_reg32 (&(in_regs->diepdma),
5433 + (uint32_t)ep->dma_addr);
5436 + dma_desc = core_if->dev_if->in_desc_addr;
5438 + /** DMA Descriptor Setup */
5439 + dma_desc->status.b.bs = BS_HOST_BUSY;
5440 + dma_desc->status.b.l = 1;
5441 + dma_desc->status.b.ioc = 1;
5442 + dma_desc->status.b.sp = (ep->xfer_len == ep->maxpacket) ? 0 : 1;
5443 + dma_desc->status.b.bytes = ep->xfer_len;
5444 + dma_desc->buf = ep->dma_addr;
5445 + dma_desc->status.b.bs = BS_HOST_READY;
5447 + /** DIEPDMA0 Register write */
5448 + dwc_write_reg32(&in_regs->diepdma, core_if->dev_if->dma_in_desc_addr);
5452 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5455 + /* EP enable, IN data in FIFO */
5456 + depctl.b.cnak = 1;
5457 + depctl.b.epena = 1;
5458 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
5461 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
5462 + * data will be written into the fifo by the ISR.
5464 + if (!core_if->dma_enable) {
5465 + if(core_if->en_multiple_tx_fifo == 0) {
5466 + intr_mask.b.nptxfempty = 1;
5467 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
5468 + intr_mask.d32, intr_mask.d32);
5471 + /* Enable the Tx FIFO Empty Interrupt for this EP */
5472 + if(ep->xfer_len > 0) {
5473 + uint32_t fifoemptymsk = 0;
5474 + fifoemptymsk |= 1 << ep->num;
5475 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
5482 + /* OUT endpoint */
5483 + dwc_otg_dev_out_ep_regs_t *out_regs =
5484 + core_if->dev_if->out_ep_regs[0];
5486 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
5487 + deptsiz.d32 = dwc_read_reg32(&out_regs->doeptsiz);
5489 + /* Program the transfer size and packet count as follows:
5490 + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
5492 + /* Zero Length Packet */
5493 + deptsiz.b.xfersize = ep->maxpacket;
5494 + deptsiz.b.pktcnt = 1;
5496 + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
5498 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
5500 + if (core_if->dma_enable) {
5501 + if(!core_if->dma_desc_enable) {
5502 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5504 + dwc_write_reg32 (&(out_regs->doepdma),
5505 + (uint32_t)ep->dma_addr);
5508 + dma_desc = core_if->dev_if->out_desc_addr;
5510 + /** DMA Descriptor Setup */
5511 + dma_desc->status.b.bs = BS_HOST_BUSY;
5512 + dma_desc->status.b.l = 1;
5513 + dma_desc->status.b.ioc = 1;
5514 + dma_desc->status.b.bytes = ep->maxpacket;
5515 + dma_desc->buf = ep->dma_addr;
5516 + dma_desc->status.b.bs = BS_HOST_READY;
5518 + /** DOEPDMA0 Register write */
5519 + dwc_write_reg32(&out_regs->doepdma, core_if->dev_if->dma_out_desc_addr);
5523 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5527 + depctl.b.cnak = 1;
5528 + depctl.b.epena = 1;
5529 + dwc_write_reg32 (&(out_regs->doepctl), depctl.d32);
5534 + * This function continues control IN transfers started by
5535 + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
5536 + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
5537 + * bit for the packet count.
5539 + * @param core_if Programming view of DWC_otg controller.
5540 + * @param ep The EP0 data.
5542 +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5544 + depctl_data_t depctl;
5545 + deptsiz0_data_t deptsiz;
5546 + gintmsk_data_t intr_mask = { .d32 = 0};
5547 + dwc_otg_dma_desc_t* dma_desc;
5549 + if (ep->is_in == 1) {
5550 + dwc_otg_dev_in_ep_regs_t *in_regs =
5551 + core_if->dev_if->in_ep_regs[0];
5552 + gnptxsts_data_t tx_status = { .d32 = 0 };
5554 + tx_status.d32 = dwc_read_reg32(&core_if->core_global_regs->gnptxsts);
5555 + /** @todo Should there be check for room in the Tx
5556 + * Status Queue. If not remove the code above this comment. */
5558 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
5559 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
5561 + /* Program the transfer size and packet count
5562 + * as follows: xfersize = N * maxpacket +
5563 + * short_packet pktcnt = N + (short_packet
5568 + if(core_if->dma_desc_enable == 0) {
5569 + deptsiz.b.xfersize = (ep->total_len - ep->xfer_count) > ep->maxpacket ? ep->maxpacket :
5570 + (ep->total_len - ep->xfer_count);
5571 + deptsiz.b.pktcnt = 1;
5572 + if(core_if->dma_enable == 0) {
5573 + ep->xfer_len += deptsiz.b.xfersize;
5575 + ep->xfer_len = deptsiz.b.xfersize;
5577 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5580 + ep->xfer_len = (ep->total_len - ep->xfer_count) > ep->maxpacket ? ep->maxpacket :
5581 + (ep->total_len - ep->xfer_count);
5583 + dma_desc = core_if->dev_if->in_desc_addr;
5585 + /** DMA Descriptor Setup */
5586 + dma_desc->status.b.bs = BS_HOST_BUSY;
5587 + dma_desc->status.b.l = 1;
5588 + dma_desc->status.b.ioc = 1;
5589 + dma_desc->status.b.sp = (ep->xfer_len == ep->maxpacket) ? 0 : 1;
5590 + dma_desc->status.b.bytes = ep->xfer_len;
5591 + dma_desc->buf = ep->dma_addr;
5592 + dma_desc->status.b.bs = BS_HOST_READY;
5594 + /** DIEPDMA0 Register write */
5595 + dwc_write_reg32(&in_regs->diepdma, core_if->dev_if->dma_in_desc_addr);
5599 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
5601 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
5603 + /* Write the DMA register */
5604 + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
5605 + if(core_if->dma_desc_enable == 0)
5606 + dwc_write_reg32 (&(in_regs->diepdma), (uint32_t)ep->dma_addr);
5609 + /* EP enable, IN data in FIFO */
5610 + depctl.b.cnak = 1;
5611 + depctl.b.epena = 1;
5612 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
5615 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
5616 + * data will be written into the fifo by the ISR.
5618 + if (!core_if->dma_enable) {
5619 + if(core_if->en_multiple_tx_fifo == 0) {
5620 + /* First clear it from GINTSTS */
5621 + intr_mask.b.nptxfempty = 1;
5622 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
5623 + intr_mask.d32, intr_mask.d32);
5627 + /* Enable the Tx FIFO Empty Interrupt for this EP */
5628 + if(ep->xfer_len > 0) {
5629 + uint32_t fifoemptymsk = 0;
5630 + fifoemptymsk |= 1 << ep->num;
5631 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
5638 + dwc_otg_dev_out_ep_regs_t *out_regs =
5639 + core_if->dev_if->out_ep_regs[0];
5642 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
5643 + deptsiz.d32 = dwc_read_reg32(&out_regs->doeptsiz);
5645 + /* Program the transfer size and packet count
5646 + * as follows: xfersize = N * maxpacket +
5647 + * short_packet pktcnt = N + (short_packet
5650 + deptsiz.b.xfersize = ep->maxpacket;
5651 + deptsiz.b.pktcnt = 1;
5654 + if(core_if->dma_desc_enable == 0) {
5655 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5658 + dma_desc = core_if->dev_if->out_desc_addr;
5660 + /** DMA Descriptor Setup */
5661 + dma_desc->status.b.bs = BS_HOST_BUSY;
5662 + dma_desc->status.b.l = 1;
5663 + dma_desc->status.b.ioc = 1;
5664 + dma_desc->status.b.bytes = ep->maxpacket;
5665 + dma_desc->buf = ep->dma_addr;
5666 + dma_desc->status.b.bs = BS_HOST_READY;
5668 + /** DOEPDMA0 Register write */
5669 + dwc_write_reg32(&out_regs->doepdma, core_if->dev_if->dma_out_desc_addr);
5673 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
5675 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
5677 + /* Write the DMA register */
5678 + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
5679 + if(core_if->dma_desc_enable == 0)
5680 + dwc_write_reg32 (&(out_regs->doepdma), (uint32_t)ep->dma_addr);
5683 + /* EP enable, IN data in FIFO */
5684 + depctl.b.cnak = 1;
5685 + depctl.b.epena = 1;
5686 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
5692 +void dump_msg(const u8 *buf, unsigned int length)
5694 + unsigned int start, num, i;
5695 + char line[52], *p;
5697 + if (length >= 512)
5700 + while (length > 0) {
5701 + num = min(length, 16u);
5703 + for (i = 0; i < num; ++i)
5707 + sprintf(p, " %02x", buf[i]);
5711 + DWC_PRINT("%6x: %s\n", start, line);
5718 +static inline void dump_msg(const u8 *buf, unsigned int length)
5724 + * This function writes a packet into the Tx FIFO associated with the
5725 + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
5726 + * periodic EPs the periodic Tx FIFO associated with the EP is written
5727 + * with all packets for the next micro-frame.
5729 + * @param core_if Programming view of DWC_otg controller.
5730 + * @param ep The EP to write packet for.
5731 + * @param dma Indicates if DMA is being used.
5733 +void dwc_otg_ep_write_packet(dwc_otg_core_if_t *core_if, dwc_ep_t *ep, int dma)
5736 + * The buffer is padded to DWORD on a per packet basis in
5737 + * slave/dma mode if the MPS is not DWORD aligned. The last
5738 + * packet, if short, is also padded to a multiple of DWORD.
5740 + * ep->xfer_buff always starts DWORD aligned in memory and is a
5741 + * multiple of DWORD in length
5743 + * ep->xfer_len can be any number of bytes
5745 + * ep->xfer_count is a multiple of ep->maxpacket until the last
5748 + * FIFO access is DWORD */
5751 + uint32_t byte_count;
5752 + uint32_t dword_count;
5754 + uint32_t *data_buff = (uint32_t *)ep->xfer_buff;
5756 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if, ep);
5757 + if (ep->xfer_count >= ep->xfer_len) {
5758 + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
5762 + /* Find the byte length of the packet either short packet or MPS */
5763 + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
5764 + byte_count = ep->xfer_len - ep->xfer_count;
5767 + byte_count = ep->maxpacket;
5770 + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
5771 + * is not a multiple of DWORD */
5772 + dword_count = (byte_count + 3) / 4;
5775 + dump_msg(ep->xfer_buff, byte_count);
5778 + /**@todo NGS Where are the Periodic Tx FIFO addresses
5779 + * intialized? What should this be? */
5781 + fifo = core_if->data_fifo[ep->num];
5784 + DWC_DEBUGPL((DBG_PCDV|DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n", fifo, data_buff, *data_buff, byte_count);
5787 + for (i=0; i<dword_count; i++, data_buff++) {
5788 + dwc_write_reg32(fifo, *data_buff);
5792 + ep->xfer_count += byte_count;
5793 + ep->xfer_buff += byte_count;
5794 + ep->dma_addr += byte_count;
5798 + * Set the EP STALL.
5800 + * @param core_if Programming view of DWC_otg controller.
5801 + * @param ep The EP to set the stall on.
5803 +void dwc_otg_ep_set_stall(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5805 + depctl_data_t depctl;
5806 + volatile uint32_t *depctl_addr;
5808 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
5809 + (ep->is_in?"IN":"OUT"));
5811 + DWC_PRINT("%s ep%d-%s\n", __func__, ep->num,
5812 + (ep->is_in?"in":"out"));
5814 + if (ep->is_in == 1) {
5815 + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
5816 + depctl.d32 = dwc_read_reg32(depctl_addr);
5818 + /* set the disable and stall bits */
5819 + if (depctl.b.epena) {
5820 + depctl.b.epdis = 1;
5822 + depctl.b.stall = 1;
5823 + dwc_write_reg32(depctl_addr, depctl.d32);
5826 + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
5827 + depctl.d32 = dwc_read_reg32(depctl_addr);
5829 + /* set the stall bit */
5830 + depctl.b.stall = 1;
5831 + dwc_write_reg32(depctl_addr, depctl.d32);
5834 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
5840 + * Clear the EP STALL.
5842 + * @param core_if Programming view of DWC_otg controller.
5843 + * @param ep The EP to clear stall from.
5845 +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5847 + depctl_data_t depctl;
5848 + volatile uint32_t *depctl_addr;
5850 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
5851 + (ep->is_in?"IN":"OUT"));
5853 + if (ep->is_in == 1) {
5854 + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
5857 + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
5860 + depctl.d32 = dwc_read_reg32(depctl_addr);
5862 + /* clear the stall bits */
5863 + depctl.b.stall = 0;
5866 + * USB Spec 9.4.5: For endpoints using data toggle, regardless
5867 + * of whether an endpoint has the Halt feature set, a
5868 + * ClearFeature(ENDPOINT_HALT) request always results in the
5869 + * data toggle being reinitialized to DATA0.
5871 + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
5872 + ep->type == DWC_OTG_EP_TYPE_BULK) {
5873 + depctl.b.setd0pid = 1; /* DATA0 */
5876 + dwc_write_reg32(depctl_addr, depctl.d32);
5877 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
5882 + * This function reads a packet from the Rx FIFO into the destination
5883 + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
5885 + * @param core_if Programming view of DWC_otg controller.
5886 + * @param dest Destination buffer for the packet.
5887 + * @param bytes Number of bytes to copy to the destination.
5889 +void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
5894 + int word_count = (bytes + 3) / 4;
5896 + volatile uint32_t *fifo = core_if->data_fifo[0];
5897 + uint32_t *data_buff = (uint32_t *)dest;
5900 + * @todo Account for the case where _dest is not dword aligned. This
5901 + * requires reading data from the FIFO into a uint32_t temp buffer,
5902 + * then moving it into the data buffer.
5905 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
5906 + core_if, dest, bytes);
5908 + for (i=0; i<word_count; i++, data_buff++)
5910 + *data_buff = dwc_read_reg32(fifo);
5919 + * This functions reads the device registers and prints them
5921 + * @param core_if Programming view of DWC_otg controller.
5923 +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *core_if)
5926 + volatile uint32_t *addr;
5928 + DWC_PRINT("Device Global Registers\n");
5929 + addr=&core_if->dev_if->dev_global_regs->dcfg;
5930 + DWC_PRINT("DCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5931 + addr=&core_if->dev_if->dev_global_regs->dctl;
5932 + DWC_PRINT("DCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5933 + addr=&core_if->dev_if->dev_global_regs->dsts;
5934 + DWC_PRINT("DSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5935 + addr=&core_if->dev_if->dev_global_regs->diepmsk;
5936 + DWC_PRINT("DIEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5937 + addr=&core_if->dev_if->dev_global_regs->doepmsk;
5938 + DWC_PRINT("DOEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5939 + addr=&core_if->dev_if->dev_global_regs->daint;
5940 + DWC_PRINT("DAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5941 + addr=&core_if->dev_if->dev_global_regs->daintmsk;
5942 + DWC_PRINT("DAINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5943 + addr=&core_if->dev_if->dev_global_regs->dtknqr1;
5944 + DWC_PRINT("DTKNQR1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5945 + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
5946 + addr=&core_if->dev_if->dev_global_regs->dtknqr2;
5947 + DWC_PRINT("DTKNQR2 @0x%08X : 0x%08X\n",
5948 + (uint32_t)addr,dwc_read_reg32(addr));
5951 + addr=&core_if->dev_if->dev_global_regs->dvbusdis;
5952 + DWC_PRINT("DVBUSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5954 + addr=&core_if->dev_if->dev_global_regs->dvbuspulse;
5955 + DWC_PRINT("DVBUSPULSE @0x%08X : 0x%08X\n",
5956 + (uint32_t)addr,dwc_read_reg32(addr));
5958 + if (core_if->hwcfg2.b.dev_token_q_depth > 14) {
5959 + addr=&core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
5960 + DWC_PRINT("DTKNQR3_DTHRCTL @0x%08X : 0x%08X\n",
5961 + (uint32_t)addr, dwc_read_reg32(addr));
5964 + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
5965 + addr=&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
5966 + DWC_PRINT("DTKNQR4 @0x%08X : 0x%08X\n",
5967 + (uint32_t)addr, dwc_read_reg32(addr));
5970 + addr=&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
5971 + DWC_PRINT("FIFOEMPMSK @0x%08X : 0x%08X\n", (uint32_t)addr, dwc_read_reg32(addr));
5973 + addr=&core_if->dev_if->dev_global_regs->deachint;
5974 + DWC_PRINT("DEACHINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5975 + addr=&core_if->dev_if->dev_global_regs->deachintmsk;
5976 + DWC_PRINT("DEACHINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5978 + for (i=0; i<= core_if->dev_if->num_in_eps; i++) {
5979 + addr=&core_if->dev_if->dev_global_regs->diepeachintmsk[i];
5980 + DWC_PRINT("DIEPEACHINTMSK[%d] @0x%08X : 0x%08X\n", i, (uint32_t)addr, dwc_read_reg32(addr));
5984 + for (i=0; i<= core_if->dev_if->num_out_eps; i++) {
5985 + addr=&core_if->dev_if->dev_global_regs->doepeachintmsk[i];
5986 + DWC_PRINT("DOEPEACHINTMSK[%d] @0x%08X : 0x%08X\n", i, (uint32_t)addr, dwc_read_reg32(addr));
5989 + for (i=0; i<= core_if->dev_if->num_in_eps; i++) {
5990 + DWC_PRINT("Device IN EP %d Registers\n", i);
5991 + addr=&core_if->dev_if->in_ep_regs[i]->diepctl;
5992 + DWC_PRINT("DIEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5993 + addr=&core_if->dev_if->in_ep_regs[i]->diepint;
5994 + DWC_PRINT("DIEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5995 + addr=&core_if->dev_if->in_ep_regs[i]->dieptsiz;
5996 + DWC_PRINT("DIETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5997 + addr=&core_if->dev_if->in_ep_regs[i]->diepdma;
5998 + DWC_PRINT("DIEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
5999 + addr=&core_if->dev_if->in_ep_regs[i]->dtxfsts;
6000 + DWC_PRINT("DTXFSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6001 + addr=&core_if->dev_if->in_ep_regs[i]->diepdmab;
6002 + DWC_PRINT("DIEPDMAB @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6006 + for (i=0; i<= core_if->dev_if->num_out_eps; i++) {
6007 + DWC_PRINT("Device OUT EP %d Registers\n", i);
6008 + addr=&core_if->dev_if->out_ep_regs[i]->doepctl;
6009 + DWC_PRINT("DOEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6010 + addr=&core_if->dev_if->out_ep_regs[i]->doepfn;
6011 + DWC_PRINT("DOEPFN @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6012 + addr=&core_if->dev_if->out_ep_regs[i]->doepint;
6013 + DWC_PRINT("DOEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6014 + addr=&core_if->dev_if->out_ep_regs[i]->doeptsiz;
6015 + DWC_PRINT("DOETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6016 + addr=&core_if->dev_if->out_ep_regs[i]->doepdma;
6017 + DWC_PRINT("DOEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6018 + addr=&core_if->dev_if->out_ep_regs[i]->doepdmab;
6019 + DWC_PRINT("DOEPDMAB @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6029 + * This functions reads the SPRAM and prints its content
6031 + * @param core_if Programming view of DWC_otg controller.
6033 +void dwc_otg_dump_spram(dwc_otg_core_if_t *core_if)
6035 + volatile uint8_t *addr, *start_addr, *end_addr;
6037 + DWC_PRINT("SPRAM Data:\n");
6038 + start_addr = (void*)core_if->core_global_regs;
6039 + DWC_PRINT("Base Address: 0x%8X\n", (uint32_t)start_addr);
6040 + start_addr += 0x00028000;
6041 + end_addr=(void*)core_if->core_global_regs;
6042 + end_addr += 0x000280e0;
6044 + for(addr = start_addr; addr < end_addr; addr+=16)
6046 + DWC_PRINT("0x%8X:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n", (uint32_t)addr,
6069 + * This function reads the host registers and prints them
6071 + * @param core_if Programming view of DWC_otg controller.
6073 +void dwc_otg_dump_host_registers(dwc_otg_core_if_t *core_if)
6076 + volatile uint32_t *addr;
6078 + DWC_PRINT("Host Global Registers\n");
6079 + addr=&core_if->host_if->host_global_regs->hcfg;
6080 + DWC_PRINT("HCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6081 + addr=&core_if->host_if->host_global_regs->hfir;
6082 + DWC_PRINT("HFIR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6083 + addr=&core_if->host_if->host_global_regs->hfnum;
6084 + DWC_PRINT("HFNUM @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6085 + addr=&core_if->host_if->host_global_regs->hptxsts;
6086 + DWC_PRINT("HPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6087 + addr=&core_if->host_if->host_global_regs->haint;
6088 + DWC_PRINT("HAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6089 + addr=&core_if->host_if->host_global_regs->haintmsk;
6090 + DWC_PRINT("HAINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6091 + addr=core_if->host_if->hprt0;
6092 + DWC_PRINT("HPRT0 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6094 + for (i=0; i<core_if->core_params->host_channels; i++)
6096 + DWC_PRINT("Host Channel %d Specific Registers\n", i);
6097 + addr=&core_if->host_if->hc_regs[i]->hcchar;
6098 + DWC_PRINT("HCCHAR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6099 + addr=&core_if->host_if->hc_regs[i]->hcsplt;
6100 + DWC_PRINT("HCSPLT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6101 + addr=&core_if->host_if->hc_regs[i]->hcint;
6102 + DWC_PRINT("HCINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6103 + addr=&core_if->host_if->hc_regs[i]->hcintmsk;
6104 + DWC_PRINT("HCINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6105 + addr=&core_if->host_if->hc_regs[i]->hctsiz;
6106 + DWC_PRINT("HCTSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6107 + addr=&core_if->host_if->hc_regs[i]->hcdma;
6108 + DWC_PRINT("HCDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6114 + * This function reads the core global registers and prints them
6116 + * @param core_if Programming view of DWC_otg controller.
6118 +void dwc_otg_dump_global_registers(dwc_otg_core_if_t *core_if)
6121 + volatile uint32_t *addr;
6123 + DWC_PRINT("Core Global Registers\n");
6124 + addr=&core_if->core_global_regs->gotgctl;
6125 + DWC_PRINT("GOTGCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6126 + addr=&core_if->core_global_regs->gotgint;
6127 + DWC_PRINT("GOTGINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6128 + addr=&core_if->core_global_regs->gahbcfg;
6129 + DWC_PRINT("GAHBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6130 + addr=&core_if->core_global_regs->gusbcfg;
6131 + DWC_PRINT("GUSBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6132 + addr=&core_if->core_global_regs->grstctl;
6133 + DWC_PRINT("GRSTCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6134 + addr=&core_if->core_global_regs->gintsts;
6135 + DWC_PRINT("GINTSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6136 + addr=&core_if->core_global_regs->gintmsk;
6137 + DWC_PRINT("GINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6138 + addr=&core_if->core_global_regs->grxstsr;
6139 + DWC_PRINT("GRXSTSR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6140 + //addr=&core_if->core_global_regs->grxstsp;
6141 + //DWC_PRINT("GRXSTSP @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6142 + addr=&core_if->core_global_regs->grxfsiz;
6143 + DWC_PRINT("GRXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6144 + addr=&core_if->core_global_regs->gnptxfsiz;
6145 + DWC_PRINT("GNPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6146 + addr=&core_if->core_global_regs->gnptxsts;
6147 + DWC_PRINT("GNPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6148 + addr=&core_if->core_global_regs->gi2cctl;
6149 + DWC_PRINT("GI2CCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6150 + addr=&core_if->core_global_regs->gpvndctl;
6151 + DWC_PRINT("GPVNDCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6152 + addr=&core_if->core_global_regs->ggpio;
6153 + DWC_PRINT("GGPIO @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6154 + addr=&core_if->core_global_regs->guid;
6155 + DWC_PRINT("GUID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6156 + addr=&core_if->core_global_regs->gsnpsid;
6157 + DWC_PRINT("GSNPSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6158 + addr=&core_if->core_global_regs->ghwcfg1;
6159 + DWC_PRINT("GHWCFG1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6160 + addr=&core_if->core_global_regs->ghwcfg2;
6161 + DWC_PRINT("GHWCFG2 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6162 + addr=&core_if->core_global_regs->ghwcfg3;
6163 + DWC_PRINT("GHWCFG3 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6164 + addr=&core_if->core_global_regs->ghwcfg4;
6165 + DWC_PRINT("GHWCFG4 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6166 + addr=&core_if->core_global_regs->hptxfsiz;
6167 + DWC_PRINT("HPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6169 + for (i=0; i<core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
6171 + addr=&core_if->core_global_regs->dptxfsiz_dieptxf[i];
6172 + DWC_PRINT("DPTXFSIZ[%d] @0x%08X : 0x%08X\n",i,(uint32_t)addr,dwc_read_reg32(addr));
6177 + * Flush a Tx FIFO.
6179 + * @param core_if Programming view of DWC_otg controller.
6180 + * @param num Tx FIFO to flush.
6182 +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t *core_if,
6185 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
6186 + volatile grstctl_t greset = { .d32 = 0};
6189 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "Flush Tx FIFO %d\n", num);
6191 + greset.b.txfflsh = 1;
6192 + greset.b.txfnum = num;
6193 + dwc_write_reg32(&global_regs->grstctl, greset.d32);
6196 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6197 + if (++count > 10000) {
6198 + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
6199 + __func__, greset.d32,
6200 + dwc_read_reg32(&global_regs->gnptxsts));
6204 + while (greset.b.txfflsh == 1);
6206 + /* Wait for 3 PHY Clocks*/
6213 + * @param core_if Programming view of DWC_otg controller.
6215 +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t *core_if)
6217 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
6218 + volatile grstctl_t greset = { .d32 = 0};
6221 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "%s\n", __func__);
6225 + greset.b.rxfflsh = 1;
6226 + dwc_write_reg32(&global_regs->grstctl, greset.d32);
6229 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6230 + if (++count > 10000) {
6231 + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
6236 + while (greset.b.rxfflsh == 1);
6238 + /* Wait for 3 PHY Clocks*/
6243 + * Do core a soft reset of the core. Be careful with this because it
6244 + * resets all the internal state machines of the core.
6246 +void dwc_otg_core_reset(dwc_otg_core_if_t *core_if)
6248 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
6249 + volatile grstctl_t greset = { .d32 = 0};
6252 + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
6253 + /* Wait for AHB master IDLE state. */
6256 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6257 + if (++count > 100000) {
6258 + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
6263 + while (greset.b.ahbidle == 0);
6265 + /* Core Soft Reset */
6267 + greset.b.csftrst = 1;
6268 + dwc_write_reg32(&global_regs->grstctl, greset.d32);
6270 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6271 + if (++count > 10000) {
6272 + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n", __func__,
6277 + while (greset.b.csftrst == 1);
6279 + /* Wait for 3 PHY Clocks*/
6286 + * Register HCD callbacks. The callbacks are used to start and stop
6287 + * the HCD for interrupt processing.
6289 + * @param core_if Programming view of DWC_otg controller.
6290 + * @param cb the HCD callback structure.
6291 + * @param p pointer to be passed to callback function (usb_hcd*).
6293 +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t *core_if,
6294 + dwc_otg_cil_callbacks_t *cb,
6297 + core_if->hcd_cb = cb;
6302 + * Register PCD callbacks. The callbacks are used to start and stop
6303 + * the PCD for interrupt processing.
6305 + * @param core_if Programming view of DWC_otg controller.
6306 + * @param cb the PCD callback structure.
6307 + * @param p pointer to be passed to callback function (pcd*).
6309 +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t *core_if,
6310 + dwc_otg_cil_callbacks_t *cb,
6313 + core_if->pcd_cb = cb;
6320 + * This function writes isoc data per 1 (micro)frame into tx fifo
6322 + * @param core_if Programming view of DWC_otg controller.
6323 + * @param ep The EP to start the transfer on.
6326 +void write_isoc_frame_data(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
6328 + dwc_otg_dev_in_ep_regs_t *ep_regs;
6329 + dtxfsts_data_t txstatus = {.d32 = 0};
6333 + ep->xfer_len = ep->data_per_frame;
6334 + ep->xfer_count = 0;
6336 + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
6338 + len = ep->xfer_len - ep->xfer_count;
6340 + if (len > ep->maxpacket) {
6341 + len = ep->maxpacket;
6344 + dwords = (len + 3)/4;
6346 + /* While there is space in the queue and space in the FIFO and
6347 + * More data to tranfer, Write packets to the Tx FIFO */
6348 + txstatus.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
6349 + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n",ep->num,txstatus.d32);
6351 + while (txstatus.b.txfspcavail > dwords &&
6352 + ep->xfer_count < ep->xfer_len &&
6353 + ep->xfer_len != 0) {
6354 + /* Write the FIFO */
6355 + dwc_otg_ep_write_packet(core_if, ep, 0);
6357 + len = ep->xfer_len - ep->xfer_count;
6358 + if (len > ep->maxpacket) {
6359 + len = ep->maxpacket;
6362 + dwords = (len + 3)/4;
6363 + txstatus.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
6364 + DWC_DEBUGPL(DBG_PCDV,"dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
6370 + * This function initializes a descriptor chain for Isochronous transfer
6372 + * @param core_if Programming view of DWC_otg controller.
6373 + * @param ep The EP to start the transfer on.
6376 +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
6378 + deptsiz_data_t deptsiz = { .d32 = 0 };
6379 + depctl_data_t depctl = { .d32 = 0 };
6380 + dsts_data_t dsts = { .d32 = 0 };
6381 + volatile uint32_t *addr;
6384 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
6386 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
6389 + ep->xfer_len = ep->data_per_frame;
6390 + ep->xfer_count = 0;
6391 + ep->xfer_buff = ep->cur_pkt_addr;
6392 + ep->dma_addr = ep->cur_pkt_dma_addr;
6395 + /* Program the transfer size and packet count
6396 + * as follows: xfersize = N * maxpacket +
6397 + * short_packet pktcnt = N + (short_packet
6400 + deptsiz.b.xfersize = ep->xfer_len;
6401 + deptsiz.b.pktcnt =
6402 + (ep->xfer_len - 1 + ep->maxpacket) /
6404 + deptsiz.b.mc = deptsiz.b.pktcnt;
6405 + dwc_write_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz, deptsiz.d32);
6407 + /* Write the DMA register */
6408 + if (core_if->dma_enable) {
6409 + dwc_write_reg32 (&(core_if->dev_if->in_ep_regs[ep->num]->diepdma), (uint32_t)ep->dma_addr);
6412 + deptsiz.b.pktcnt =
6413 + (ep->xfer_len + (ep->maxpacket - 1)) /
6415 + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
6417 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
6419 + if (core_if->dma_enable) {
6420 + dwc_write_reg32 (&(core_if->dev_if->out_ep_regs[ep->num]->doepdma),
6421 + (uint32_t)ep->dma_addr);
6426 + /** Enable endpoint, clear nak */
6429 + if(ep->bInterval == 1) {
6430 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
6431 + ep->next_frame = dsts.b.soffn + ep->bInterval;
6433 + if(ep->next_frame & 0x1) {
6434 + depctl.b.setd1pid = 1;
6436 + depctl.b.setd0pid = 1;
6439 + ep->next_frame += ep->bInterval;
6441 + if(ep->next_frame & 0x1) {
6442 + depctl.b.setd1pid = 1;
6444 + depctl.b.setd0pid = 1;
6447 + depctl.b.epena = 1;
6448 + depctl.b.cnak = 1;
6450 + dwc_modify_reg32(addr, 0, depctl.d32);
6451 + depctl.d32 = dwc_read_reg32(addr);
6453 + if(ep->is_in && core_if->dma_enable == 0) {
6454 + write_isoc_frame_data(core_if, ep);
6459 +#endif //DWC_EN_ISOC
6460 diff --git a/drivers/usb/dwc_otg/dwc_otg_cil.h b/drivers/usb/dwc_otg/dwc_otg_cil.h
6461 new file mode 100644
6462 index 0000000..9507992
6464 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.h
6466 +/* ==========================================================================
6467 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
6468 + * $Revision: 1.2 $
6469 + * $Date: 2008-11-21 05:39:15 $
6470 + * $Change: 1099526 $
6472 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
6473 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
6474 + * otherwise expressly agreed to in writing between Synopsys and you.
6476 + * The Software IS NOT an item of Licensed Software or Licensed Product under
6477 + * any End User Software License Agreement or Agreement for Licensed Product
6478 + * with Synopsys or any supplement thereto. You are permitted to use and
6479 + * redistribute this Software in source and binary forms, with or without
6480 + * modification, provided that redistributions of source code must retain this
6481 + * notice. You may not view, use, disclose, copy or distribute this file or
6482 + * any information contained herein except pursuant to this license grant from
6483 + * Synopsys. If you do not agree with this notice, including the disclaimer
6484 + * below, then you are not authorized to use the Software.
6486 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
6487 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6488 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6489 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
6490 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
6491 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
6492 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
6493 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6494 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6495 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
6497 + * ========================================================================== */
6499 +#if !defined(__DWC_CIL_H__)
6500 +#define __DWC_CIL_H__
6502 +#include <linux/workqueue.h>
6503 +#include <linux/version.h>
6504 +#include <asm/param.h>
6506 +#include "linux/dwc_otg_plat.h"
6507 +#include "dwc_otg_regs.h"
6509 +#include "linux/timer.h"
6514 + * This file contains the interface to the Core Interface Layer.
6518 +/** Macros defined for DWC OTG HW Release verison */
6519 +#define OTG_CORE_REV_2_00 0x4F542000
6520 +#define OTG_CORE_REV_2_60a 0x4F54260A
6521 +#define OTG_CORE_REV_2_71a 0x4F54271A
6522 +#define OTG_CORE_REV_2_72a 0x4F54272A
6526 +typedef struct iso_pkt_info
6533 + * The <code>dwc_ep</code> structure represents the state of a single
6534 + * endpoint when acting in device mode. It contains the data items
6535 + * needed for an endpoint to be activated and transfer packets.
6537 +typedef struct dwc_ep
6539 + /** EP number used for register address lookup */
6541 + /** EP direction 0 = OUT */
6542 + unsigned is_in : 1;
6544 + unsigned active : 1;
6546 + /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
6547 + If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
6548 + unsigned tx_fifo_num : 4;
6549 + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
6550 + unsigned type : 2;
6551 +#define DWC_OTG_EP_TYPE_CONTROL 0
6552 +#define DWC_OTG_EP_TYPE_ISOC 1
6553 +#define DWC_OTG_EP_TYPE_BULK 2
6554 +#define DWC_OTG_EP_TYPE_INTR 3
6556 + /** DATA start PID for INTR and BULK EP */
6557 + unsigned data_pid_start : 1;
6558 + /** Frame (even/odd) for ISOC EP */
6559 + unsigned even_odd_frame : 1;
6560 + /** Max Packet bytes */
6561 + unsigned maxpacket : 11;
6563 + /** Max Transfer size */
6564 + unsigned maxxfer : 16;
6566 + /** @name Transfer state */
6570 + * Pointer to the beginning of the transfer buffer -- do not modify
6571 + * during transfer.
6574 + uint32_t dma_addr;
6576 + uint32_t dma_desc_addr;
6577 + dwc_otg_dma_desc_t* desc_addr;
6580 + uint8_t *start_xfer_buff;
6581 + /** pointer to the transfer buffer */
6582 + uint8_t *xfer_buff;
6583 + /** Number of bytes to transfer */
6584 + unsigned xfer_len : 19;
6585 + /** Number of bytes transferred. */
6586 + unsigned xfer_count : 19;
6588 + unsigned sent_zlp : 1;
6589 + /** Total len for control transfer */
6590 + unsigned total_len : 19;
6592 + /** stall clear flag */
6593 + unsigned stall_clear_flag : 1;
6595 + /** Allocated DMA Desc count */
6596 + uint32_t desc_cnt;
6600 + * Variables specific for ISOC EPs
6603 + /** DMA addresses of ISOC buffers */
6604 + uint32_t dma_addr0;
6605 + uint32_t dma_addr1;
6607 + uint32_t iso_dma_desc_addr;
6608 + dwc_otg_dma_desc_t* iso_desc_addr;
6610 + /** pointer to the transfer buffers */
6611 + uint8_t *xfer_buff0;
6612 + uint8_t *xfer_buff1;
6614 + /** number of ISOC Buffer is processing */
6615 + uint32_t proc_buf_num;
6616 + /** Interval of ISOC Buffer processing */
6617 + uint32_t buf_proc_intrvl;
6618 + /** Data size for regular frame */
6619 + uint32_t data_per_frame;
6621 + /* todo - pattern data support is to be implemented in the future */
6622 + /** Data size for pattern frame */
6623 + uint32_t data_pattern_frame;
6624 + /** Frame number of pattern data */
6625 + uint32_t sync_frame;
6628 + uint32_t bInterval;
6629 + /** ISO Packet number per frame */
6630 + uint32_t pkt_per_frm;
6631 + /** Next frame num for which will be setup DMA Desc */
6632 + uint32_t next_frame;
6633 + /** Number of packets per buffer processing */
6635 + /** Info for all isoc packets */
6636 + iso_pkt_info_t *pkt_info;
6637 + /** current pkt number */
6639 + /** current pkt number */
6640 + uint8_t *cur_pkt_addr;
6641 + /** current pkt number */
6642 + uint32_t cur_pkt_dma_addr;
6643 +#endif //DWC_EN_ISOC
6648 + * Reasons for halting a host channel.
6650 +typedef enum dwc_otg_halt_status
6652 + DWC_OTG_HC_XFER_NO_HALT_STATUS,
6653 + DWC_OTG_HC_XFER_COMPLETE,
6654 + DWC_OTG_HC_XFER_URB_COMPLETE,
6655 + DWC_OTG_HC_XFER_ACK,
6656 + DWC_OTG_HC_XFER_NAK,
6657 + DWC_OTG_HC_XFER_NYET,
6658 + DWC_OTG_HC_XFER_STALL,
6659 + DWC_OTG_HC_XFER_XACT_ERR,
6660 + DWC_OTG_HC_XFER_FRAME_OVERRUN,
6661 + DWC_OTG_HC_XFER_BABBLE_ERR,
6662 + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
6663 + DWC_OTG_HC_XFER_AHB_ERR,
6664 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
6665 + DWC_OTG_HC_XFER_URB_DEQUEUE
6666 +} dwc_otg_halt_status_e;
6669 + * Host channel descriptor. This structure represents the state of a single
6670 + * host channel when acting in host mode. It contains the data items needed to
6671 + * transfer packets to an endpoint via a host channel.
6673 +typedef struct dwc_hc
6675 + /** Host channel number used for register address lookup */
6678 + /** Device to access */
6679 + unsigned dev_addr : 7;
6681 + /** EP to access */
6682 + unsigned ep_num : 4;
6684 + /** EP direction. 0: OUT, 1: IN */
6685 + unsigned ep_is_in : 1;
6689 + * One of the following values:
6690 + * - DWC_OTG_EP_SPEED_LOW
6691 + * - DWC_OTG_EP_SPEED_FULL
6692 + * - DWC_OTG_EP_SPEED_HIGH
6694 + unsigned speed : 2;
6695 +#define DWC_OTG_EP_SPEED_LOW 0
6696 +#define DWC_OTG_EP_SPEED_FULL 1
6697 +#define DWC_OTG_EP_SPEED_HIGH 2
6701 + * One of the following values:
6702 + * - DWC_OTG_EP_TYPE_CONTROL: 0
6703 + * - DWC_OTG_EP_TYPE_ISOC: 1
6704 + * - DWC_OTG_EP_TYPE_BULK: 2
6705 + * - DWC_OTG_EP_TYPE_INTR: 3
6707 + unsigned ep_type : 2;
6709 + /** Max packet size in bytes */
6710 + unsigned max_packet : 11;
6713 + * PID for initial transaction.
6717 + * 3: MDATA (non-Control EP),
6718 + * SETUP (Control EP)
6720 + unsigned data_pid_start : 2;
6721 +#define DWC_OTG_HC_PID_DATA0 0
6722 +#define DWC_OTG_HC_PID_DATA2 1
6723 +#define DWC_OTG_HC_PID_DATA1 2
6724 +#define DWC_OTG_HC_PID_MDATA 3
6725 +#define DWC_OTG_HC_PID_SETUP 3
6727 + /** Number of periodic transactions per (micro)frame */
6728 + unsigned multi_count: 2;
6730 + /** @name Transfer State */
6733 + /** Pointer to the current transfer buffer position. */
6734 + uint8_t *xfer_buff;
6735 + /** Total number of bytes to transfer. */
6736 + uint32_t xfer_len;
6737 + /** Number of bytes transferred so far. */
6738 + uint32_t xfer_count;
6739 + /** Packet count at start of transfer.*/
6740 + uint16_t start_pkt_count;
6743 + * Flag to indicate whether the transfer has been started. Set to 1 if
6744 + * it has been started, 0 otherwise.
6746 + uint8_t xfer_started;
6749 + * Set to 1 to indicate that a PING request should be issued on this
6750 + * channel. If 0, process normally.
6755 + * Set to 1 to indicate that the error count for this transaction is
6756 + * non-zero. Set to 0 if the error count is 0.
6758 + uint8_t error_state;
6761 + * Set to 1 to indicate that this channel should be halted the next
6762 + * time a request is queued for the channel. This is necessary in
6763 + * slave mode if no request queue space is available when an attempt
6764 + * is made to halt the channel.
6766 + uint8_t halt_on_queue;
6769 + * Set to 1 if the host channel has been halted, but the core is not
6770 + * finished flushing queued requests. Otherwise 0.
6772 + uint8_t halt_pending;
6775 + * Reason for halting the host channel.
6777 + dwc_otg_halt_status_e halt_status;
6780 + * Split settings for the host channel
6782 + uint8_t do_split; /**< Enable split for the channel */
6783 + uint8_t complete_split; /**< Enable complete split */
6784 + uint8_t hub_addr; /**< Address of high speed hub */
6786 + uint8_t port_addr; /**< Port of the low/full speed device */
6787 + /** Split transaction position
6788 + * One of the following values:
6789 + * - DWC_HCSPLIT_XACTPOS_MID
6790 + * - DWC_HCSPLIT_XACTPOS_BEGIN
6791 + * - DWC_HCSPLIT_XACTPOS_END
6792 + * - DWC_HCSPLIT_XACTPOS_ALL */
6795 + /** Set when the host channel does a short read. */
6796 + uint8_t short_read;
6799 + * Number of requests issued for this channel since it was assigned to
6800 + * the current transfer (not counting PINGs).
6805 + * Queue Head for the transfer being processed by this channel.
6807 + struct dwc_otg_qh *qh;
6811 + /** Entry in list of host channels. */
6812 + struct list_head hc_list_entry;
6816 + * The following parameters may be specified when starting the module. These
6817 + * parameters define how the DWC_otg controller should be configured.
6818 + * Parameter values are passed to the CIL initialization function
6819 + * dwc_otg_cil_init.
6821 +typedef struct dwc_otg_core_params
6824 +#define dwc_param_opt_default 1
6827 + * Specifies the OTG capabilities. The driver will automatically
6828 + * detect the value for this parameter if none is specified.
6829 + * 0 - HNP and SRP capable (default)
6830 + * 1 - SRP Only capable
6831 + * 2 - No HNP/SRP capable
6834 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
6835 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
6836 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
6837 +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
6840 + * Specifies whether to use slave or DMA mode for accessing the data
6841 + * FIFOs. The driver will automatically detect the value for this
6842 + * parameter if none is specified.
6844 + * 1 - DMA (default, if available)
6846 + int32_t dma_enable;
6847 +#define dwc_param_dma_enable_default 1
6850 + * When DMA mode is enabled specifies whether to use address DMA or DMA Descritor mode for accessing the data
6851 + * FIFOs in device mode. The driver will automatically detect the value for this
6852 + * parameter if none is specified.
6854 + * 1 - DMA Descriptor(default, if available)
6856 + int32_t dma_desc_enable;
6857 +#define dwc_param_dma_desc_enable_default 0
6858 + /** The DMA Burst size (applicable only for External DMA
6859 + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
6861 + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
6862 +#define dwc_param_dma_burst_size_default 32
6865 + * Specifies the maximum speed of operation in host and device mode.
6866 + * The actual speed depends on the speed of the attached device and
6867 + * the value of phy_type. The actual speed depends on the speed of the
6868 + * attached device.
6869 + * 0 - High Speed (default)
6873 +#define dwc_param_speed_default 0
6874 +#define DWC_SPEED_PARAM_HIGH 0
6875 +#define DWC_SPEED_PARAM_FULL 1
6877 + /** Specifies whether low power mode is supported when attached
6878 + * to a Full Speed or Low Speed device in host mode.
6879 + * 0 - Don't support low power mode (default)
6880 + * 1 - Support low power mode
6882 + int32_t host_support_fs_ls_low_power;
6883 +#define dwc_param_host_support_fs_ls_low_power_default 0
6885 + /** Specifies the PHY clock rate in low power mode when connected to a
6886 + * Low Speed device in host mode. This parameter is applicable only if
6887 + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
6888 + * then defaults to 6 MHZ otherwise 48 MHZ.
6893 + int32_t host_ls_low_power_phy_clk;
6894 +#define dwc_param_host_ls_low_power_phy_clk_default 0
6895 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
6896 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
6899 + * 0 - Use cC FIFO size parameters
6900 + * 1 - Allow dynamic FIFO sizing (default)
6902 + int32_t enable_dynamic_fifo;
6903 +#define dwc_param_enable_dynamic_fifo_default 1
6905 + /** Total number of 4-byte words in the data FIFO memory. This
6906 + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
6908 + * 32 to 32768 (default 8192)
6909 + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
6911 + int32_t data_fifo_size;
6912 +#define dwc_param_data_fifo_size_default 8192
6914 + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
6915 + * FIFO sizing is enabled.
6916 + * 16 to 32768 (default 1064)
6918 + int32_t dev_rx_fifo_size;
6919 +#define dwc_param_dev_rx_fifo_size_default 1064
6921 + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
6922 + * when dynamic FIFO sizing is enabled.
6923 + * 16 to 32768 (default 1024)
6925 + int32_t dev_nperio_tx_fifo_size;
6926 +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
6928 + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
6929 + * mode when dynamic FIFO sizing is enabled.
6930 + * 4 to 768 (default 256)
6932 + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
6933 +#define dwc_param_dev_perio_tx_fifo_size_default 256
6935 + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
6936 + * FIFO sizing is enabled.
6937 + * 16 to 32768 (default 1024)
6939 + int32_t host_rx_fifo_size;
6940 +#define dwc_param_host_rx_fifo_size_default 1024
6942 + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
6943 + * when Dynamic FIFO sizing is enabled in the core.
6944 + * 16 to 32768 (default 1024)
6946 + int32_t host_nperio_tx_fifo_size;
6947 +#define dwc_param_host_nperio_tx_fifo_size_default 1024
6949 + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
6950 + * FIFO sizing is enabled.
6951 + * 16 to 32768 (default 1024)
6953 + int32_t host_perio_tx_fifo_size;
6954 +#define dwc_param_host_perio_tx_fifo_size_default 1024
6956 + /** The maximum transfer size supported in bytes.
6957 + * 2047 to 65,535 (default 65,535)
6959 + int32_t max_transfer_size;
6960 +#define dwc_param_max_transfer_size_default 65535
6962 + /** The maximum number of packets in a transfer.
6963 + * 15 to 511 (default 511)
6965 + int32_t max_packet_count;
6966 +#define dwc_param_max_packet_count_default 511
6968 + /** The number of host channel registers to use.
6969 + * 1 to 16 (default 12)
6970 + * Note: The FPGA configuration supports a maximum of 12 host channels.
6972 + int32_t host_channels;
6973 +#define dwc_param_host_channels_default 12
6975 + /** The number of endpoints in addition to EP0 available for device
6976 + * mode operations.
6977 + * 1 to 15 (default 6 IN and OUT)
6978 + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
6979 + * endpoints in addition to EP0.
6981 + int32_t dev_endpoints;
6982 +#define dwc_param_dev_endpoints_default 6
6985 + * Specifies the type of PHY interface to use. By default, the driver
6986 + * will automatically detect the phy_type.
6988 + * 0 - Full Speed PHY
6989 + * 1 - UTMI+ (default)
6993 +#define DWC_PHY_TYPE_PARAM_FS 0
6994 +#define DWC_PHY_TYPE_PARAM_UTMI 1
6995 +#define DWC_PHY_TYPE_PARAM_ULPI 2
6996 +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
6999 + * Specifies the UTMI+ Data Width. This parameter is
7000 + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
7001 + * PHY_TYPE, this parameter indicates the data width between
7002 + * the MAC and the ULPI Wrapper.) Also, this parameter is
7003 + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
7004 + * to "8 and 16 bits", meaning that the core has been
7005 + * configured to work at either data path width.
7007 + * 8 or 16 bits (default 16)
7009 + int32_t phy_utmi_width;
7010 +#define dwc_param_phy_utmi_width_default 16
7013 + * Specifies whether the ULPI operates at double or single
7014 + * data rate. This parameter is only applicable if PHY_TYPE is
7017 + * 0 - single data rate ULPI interface with 8 bit wide data
7019 + * 1 - double data rate ULPI interface with 4 bit wide data
7022 + int32_t phy_ulpi_ddr;
7023 +#define dwc_param_phy_ulpi_ddr_default 0
7026 + * Specifies whether to use the internal or external supply to
7027 + * drive the vbus with a ULPI phy.
7029 + int32_t phy_ulpi_ext_vbus;
7030 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
7031 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
7032 +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
7035 + * Specifies whether to use the I2Cinterface for full speed PHY. This
7036 + * parameter is only applicable if PHY_TYPE is FS.
7037 + * 0 - No (default)
7040 + int32_t i2c_enable;
7041 +#define dwc_param_i2c_enable_default 0
7043 + int32_t ulpi_fs_ls;
7044 +#define dwc_param_ulpi_fs_ls_default 0
7047 +#define dwc_param_ts_dline_default 0
7050 + * Specifies whether dedicated transmit FIFOs are
7051 + * enabled for non periodic IN endpoints in device mode
7055 + int32_t en_multiple_tx_fifo;
7056 +#define dwc_param_en_multiple_tx_fifo_default 1
7058 + /** Number of 4-byte words in each of the Tx FIFOs in device
7059 + * mode when dynamic FIFO sizing is enabled.
7060 + * 4 to 768 (default 256)
7062 + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
7063 +#define dwc_param_dev_tx_fifo_size_default 256
7065 + /** Thresholding enable flag-
7066 + * bit 0 - enable non-ISO Tx thresholding
7067 + * bit 1 - enable ISO Tx thresholding
7068 + * bit 2 - enable Rx thresholding
7071 +#define dwc_param_thr_ctl_default 0
7073 + /** Thresholding length for Tx
7074 + * FIFOs in 32 bit DWORDs
7076 + uint32_t tx_thr_length;
7077 +#define dwc_param_tx_thr_length_default 64
7079 + /** Thresholding length for Rx
7080 + * FIFOs in 32 bit DWORDs
7082 + uint32_t rx_thr_length;
7083 +#define dwc_param_rx_thr_length_default 64
7085 + /** Per Transfer Interrupt
7086 + * mode enable flag
7090 + uint32_t pti_enable;
7091 +#define dwc_param_pti_enable_default 0
7093 + /** Molti Processor Interrupt
7094 + * mode enable flag
7098 + uint32_t mpi_enable;
7099 +#define dwc_param_mpi_enable_default 0
7101 +} dwc_otg_core_params_t;
7104 +struct dwc_otg_core_if;
7105 +typedef struct hc_xfer_info
7107 + struct dwc_otg_core_if *core_if;
7113 + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
7114 + * the DWC_otg controller acting in either host or device mode. It
7115 + * represents the programming view of the controller as a whole.
7117 +typedef struct dwc_otg_core_if
7119 + /** Parameters that define how the core should be configured.*/
7120 + dwc_otg_core_params_t *core_params;
7122 + /** Core Global registers starting at offset 000h. */
7123 + dwc_otg_core_global_regs_t *core_global_regs;
7125 + /** Device-specific information */
7126 + dwc_otg_dev_if_t *dev_if;
7127 + /** Host-specific information */
7128 + dwc_otg_host_if_t *host_if;
7130 + /** Value from SNPSID register */
7134 + * Set to 1 if the core PHY interface bits in USBCFG have been
7137 + uint8_t phy_init_done;
7140 + * SRP Success flag, set by srp success interrupt in FS I2C mode
7142 + uint8_t srp_success;
7143 + uint8_t srp_timer_started;
7145 + /* Common configuration information */
7146 + /** Power and Clock Gating Control Register */
7147 + volatile uint32_t *pcgcctl;
7148 +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
7150 + /** Push/pop addresses for endpoints or host channels.*/
7151 + uint32_t *data_fifo[MAX_EPS_CHANNELS];
7152 +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
7153 +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
7155 + /** Total RAM for FIFOs (Bytes) */
7156 + uint16_t total_fifo_size;
7157 + /** Size of Rx FIFO (Bytes) */
7158 + uint16_t rx_fifo_size;
7159 + /** Size of Non-periodic Tx FIFO (Bytes) */
7160 + uint16_t nperio_tx_fifo_size;
7163 + /** 1 if DMA is enabled, 0 otherwise. */
7164 + uint8_t dma_enable;
7166 + /** 1 if Descriptor DMA mode is enabled, 0 otherwise. */
7167 + uint8_t dma_desc_enable;
7169 + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
7170 + uint8_t pti_enh_enable;
7172 + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
7173 + uint8_t multiproc_int_enable;
7175 + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
7176 + uint8_t en_multiple_tx_fifo;
7178 + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
7179 + * process of being queued */
7180 + uint8_t queuing_high_bandwidth;
7182 + /** Hardware Configuration -- stored here for convenience.*/
7183 + hwcfg1_data_t hwcfg1;
7184 + hwcfg2_data_t hwcfg2;
7185 + hwcfg3_data_t hwcfg3;
7186 + hwcfg4_data_t hwcfg4;
7188 + /** Host and Device Configuration -- stored here for convenience.*/
7192 + /** The operational State, during transations
7193 + * (a_host>>a_peripherial and b_device=>b_host) this may not
7194 + * match the core but allows the software to determine
7200 + * Set to 1 if the HCD needs to be restarted on a session request
7201 + * interrupt. This is required if no connector ID status change has
7202 + * occurred since the HCD was last disconnected.
7204 + uint8_t restart_hcd_on_session_req;
7206 + /** HCD callbacks */
7207 + /** A-Device is a_host */
7209 + /** A-Device is a_suspend */
7210 +#define A_SUSPEND (2)
7211 + /** A-Device is a_peripherial */
7212 +#define A_PERIPHERAL (3)
7213 + /** B-Device is operating as a Peripheral. */
7214 +#define B_PERIPHERAL (4)
7215 + /** B-Device is operating as a Host. */
7218 + /** HCD callbacks */
7219 + struct dwc_otg_cil_callbacks *hcd_cb;
7220 + /** PCD callbacks */
7221 + struct dwc_otg_cil_callbacks *pcd_cb;
7223 + /** Device mode Periodic Tx FIFO Mask */
7224 + uint32_t p_tx_msk;
7225 + /** Device mode Periodic Tx FIFO Mask */
7228 + /** Workqueue object used for handling several interrupts */
7229 + struct workqueue_struct *wq_otg;
7231 + /** Work object used for handling "Connector ID Status Change" Interrupt */
7232 + struct work_struct w_conn_id;
7234 + /** Work object used for handling "Wakeup Detected" Interrupt */
7235 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7236 + struct work_struct w_wkp;
7238 + struct delayed_work w_wkp;
7242 + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
7244 + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
7245 + struct timer_list hc_xfer_timer[MAX_EPS_CHANNELS];
7247 + uint32_t hfnum_7_samples;
7248 + uint64_t hfnum_7_frrem_accum;
7249 + uint32_t hfnum_0_samples;
7250 + uint64_t hfnum_0_frrem_accum;
7251 + uint32_t hfnum_other_samples;
7252 + uint64_t hfnum_other_frrem_accum;
7256 +} dwc_otg_core_if_t;
7258 +/*We must clear S3C24XX_EINTPEND external interrupt register
7259 + * because after clearing in this register trigerred IRQ from
7260 + * H/W core in kernel interrupt can be occured again before OTG
7261 + * handlers clear all IRQ sources of Core registers because of
7262 + * timing latencies and Low Level IRQ Type.
7265 +#ifdef CONFIG_MACH_IPMATE
7266 +#define S3C2410X_CLEAR_EINTPEND() \
7268 + if (!dwc_otg_read_core_intr(core_if)) { \
7269 + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
7273 +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
7277 + * The following functions are functions for works
7278 + * using during handling some interrupts
7280 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7282 +extern void w_conn_id_status_change(void *p);
7283 +extern void w_wakeup_detected(void *p);
7287 +extern void w_conn_id_status_change(struct work_struct *p);
7288 +extern void w_wakeup_detected(struct work_struct *p);
7294 + * The following functions support initialization of the CIL driver component
7295 + * and the DWC_otg controller.
7297 +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
7298 + dwc_otg_core_params_t *_core_params);
7299 +extern void dwc_otg_cil_remove(dwc_otg_core_if_t *_core_if);
7300 +extern void dwc_otg_core_init(dwc_otg_core_if_t *_core_if);
7301 +extern void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if);
7302 +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if);
7303 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if );
7304 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if );
7306 +/** @name Device CIL Functions
7307 + * The following functions support managing the DWC_otg controller in device
7311 +extern void dwc_otg_wakeup(dwc_otg_core_if_t *_core_if);
7312 +extern void dwc_otg_read_setup_packet (dwc_otg_core_if_t *_core_if, uint32_t *_dest);
7313 +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if);
7314 +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7315 +extern void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7316 +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7317 +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7318 +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7319 +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7320 +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7321 +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma);
7322 +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7323 +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7324 +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if);
7325 +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if);
7326 +extern void dwc_otg_dump_spram(dwc_otg_core_if_t *_core_if);
7328 +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep);
7329 +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep);
7330 +#endif //DWC_EN_ISOC
7333 +/** @name Host CIL Functions
7334 + * The following functions support managing the DWC_otg controller in host
7338 +extern void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7339 +extern void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
7341 + dwc_otg_halt_status_e _halt_status);
7342 +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7343 +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7344 +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7345 +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7346 +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7347 +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if);
7348 +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if);
7351 + * This function Reads HPRT0 in preparation to modify. It keeps the
7352 + * WC bits 0 so that if they are read as 1, they won't clear when you
7355 +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t *_core_if)
7357 + hprt0_data_t hprt0;
7358 + hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
7359 + hprt0.b.prtena = 0;
7360 + hprt0.b.prtconndet = 0;
7361 + hprt0.b.prtenchng = 0;
7362 + hprt0.b.prtovrcurrchng = 0;
7366 +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if);
7369 +/** @name Common CIL Functions
7370 + * The following functions support managing the DWC_otg controller in either
7371 + * device or host mode.
7375 +extern void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
7379 +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if);
7381 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
7383 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if );
7384 +extern void dwc_otg_core_reset( dwc_otg_core_if_t *_core_if );
7386 +extern dwc_otg_dma_desc_t* dwc_otg_ep_alloc_desc_chain(uint32_t * dma_desc_addr, uint32_t count);
7387 +extern void dwc_otg_ep_free_desc_chain(dwc_otg_dma_desc_t* desc_addr, uint32_t dma_desc_addr, uint32_t count);
7390 + * This function returns the Core Interrupt register.
7392 +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t *_core_if)
7394 + return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) &
7395 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
7399 + * This function returns the OTG Interrupt register.
7401 +static inline uint32_t dwc_otg_read_otg_intr (dwc_otg_core_if_t *_core_if)
7403 + return (dwc_read_reg32 (&_core_if->core_global_regs->gotgint));
7407 + * This function reads the Device All Endpoints Interrupt register and
7408 + * returns the IN endpoint interrupt bits.
7410 +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *core_if)
7414 + if(core_if->multiproc_int_enable) {
7415 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachint) &
7416 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachintmsk);
7418 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->daint) &
7419 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk);
7421 + return (v & 0xffff);
7426 + * This function reads the Device All Endpoints Interrupt register and
7427 + * returns the OUT endpoint interrupt bits.
7429 +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *core_if)
7433 + if(core_if->multiproc_int_enable) {
7434 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachint) &
7435 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachintmsk);
7437 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->daint) &
7438 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk);
7441 + return ((v & 0xffff0000) >> 16);
7445 + * This function returns the Device IN EP Interrupt register
7447 +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t *core_if,
7450 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
7451 + uint32_t v, msk, emp;
7453 + if(core_if->multiproc_int_enable) {
7454 + msk = dwc_read_reg32(&dev_if->dev_global_regs->diepeachintmsk[ep->num]);
7455 + emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
7456 + msk |= ((emp >> ep->num) & 0x1) << 7;
7457 + v = dwc_read_reg32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
7459 + msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
7460 + emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
7461 + msk |= ((emp >> ep->num) & 0x1) << 7;
7462 + v = dwc_read_reg32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
7469 + * This function returns the Device OUT EP Interrupt register
7471 +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *_core_if,
7474 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
7476 + doepmsk_data_t msk = { .d32 = 0 };
7478 + if(_core_if->multiproc_int_enable) {
7479 + msk.d32 = dwc_read_reg32(&dev_if->dev_global_regs->doepeachintmsk[_ep->num]);
7480 + if(_core_if->pti_enh_enable) {
7481 + msk.b.pktdrpsts = 1;
7483 + v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) & msk.d32;
7485 + msk.d32 = dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
7486 + if(_core_if->pti_enh_enable) {
7487 + msk.b.pktdrpsts = 1;
7489 + v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) & msk.d32;
7495 + * This function returns the Host All Channel Interrupt register
7497 +static inline uint32_t dwc_otg_read_host_all_channels_intr (dwc_otg_core_if_t *_core_if)
7499 + return (dwc_read_reg32 (&_core_if->host_if->host_global_regs->haint));
7502 +static inline uint32_t dwc_otg_read_host_channel_intr (dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
7504 + return (dwc_read_reg32 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
7509 + * This function returns the mode of the operation, host or device.
7511 + * @return 0 - Device Mode, 1 - Host Mode
7513 +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t *_core_if)
7515 + return (dwc_read_reg32( &_core_if->core_global_regs->gintsts ) & 0x1);
7518 +static inline uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t *_core_if)
7520 + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
7522 +static inline uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t *_core_if)
7524 + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
7527 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if );
7533 + * DWC_otg CIL callback structure. This structure allows the HCD and
7534 + * PCD to register functions used for starting and stopping the PCD
7535 + * and HCD for role change on for a DRD.
7537 +typedef struct dwc_otg_cil_callbacks
7539 + /** Start function for role change */
7540 + int (*start) (void *_p);
7541 + /** Stop Function for role change */
7542 + int (*stop) (void *_p);
7543 + /** Disconnect Function for role change */
7544 + int (*disconnect) (void *_p);
7545 + /** Resume/Remote wakeup Function */
7546 + int (*resume_wakeup) (void *_p);
7547 + /** Suspend function */
7548 + int (*suspend) (void *_p);
7549 + /** Session Start (SRP) */
7550 + int (*session_start) (void *_p);
7551 + /** Pointer passed to start() and stop() */
7553 +} dwc_otg_cil_callbacks_t;
7555 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
7556 + dwc_otg_cil_callbacks_t *_cb,
7558 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
7559 + dwc_otg_cil_callbacks_t *_cb,
7564 diff --git a/drivers/usb/dwc_otg/dwc_otg_cil_intr.c b/drivers/usb/dwc_otg/dwc_otg_cil_intr.c
7565 new file mode 100644
7566 index 0000000..61b17b3
7568 +++ b/drivers/usb/dwc_otg/dwc_otg_cil_intr.c
7570 +/* ==========================================================================
7571 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
7572 + * $Revision: 1.2 $
7573 + * $Date: 2008-11-21 05:39:15 $
7574 + * $Change: 1065567 $
7576 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
7577 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
7578 + * otherwise expressly agreed to in writing between Synopsys and you.
7580 + * The Software IS NOT an item of Licensed Software or Licensed Product under
7581 + * any End User Software License Agreement or Agreement for Licensed Product
7582 + * with Synopsys or any supplement thereto. You are permitted to use and
7583 + * redistribute this Software in source and binary forms, with or without
7584 + * modification, provided that redistributions of source code must retain this
7585 + * notice. You may not view, use, disclose, copy or distribute this file or
7586 + * any information contained herein except pursuant to this license grant from
7587 + * Synopsys. If you do not agree with this notice, including the disclaimer
7588 + * below, then you are not authorized to use the Software.
7590 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
7591 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7592 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7593 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
7594 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7595 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7596 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7597 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7598 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7599 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
7601 + * ========================================================================== */
7605 + * The Core Interface Layer provides basic services for accessing and
7606 + * managing the DWC_otg hardware. These services are used by both the
7607 + * Host Controller Driver and the Peripheral Controller Driver.
7609 + * This file contains the Common Interrupt handlers.
7611 +#include "linux/dwc_otg_plat.h"
7612 +#include "dwc_otg_regs.h"
7613 +#include "dwc_otg_cil.h"
7616 +inline const char *op_state_str(dwc_otg_core_if_t *core_if)
7618 + return (core_if->op_state==A_HOST?"a_host":
7619 + (core_if->op_state==A_SUSPEND?"a_suspend":
7620 + (core_if->op_state==A_PERIPHERAL?"a_peripheral":
7621 + (core_if->op_state==B_PERIPHERAL?"b_peripheral":
7622 + (core_if->op_state==B_HOST?"b_host":
7627 +/** This function will log a debug message
7629 + * @param core_if Programming view of DWC_otg controller.
7631 +int32_t dwc_otg_handle_mode_mismatch_intr (dwc_otg_core_if_t *core_if)
7633 + gintsts_data_t gintsts;
7634 + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
7635 + dwc_otg_mode(core_if) ? "Host" : "Device");
7637 + /* Clear interrupt */
7639 + gintsts.b.modemismatch = 1;
7640 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
7644 +/** Start the HCD. Helper function for using the HCD callbacks.
7646 + * @param core_if Programming view of DWC_otg controller.
7648 +static inline void hcd_start(dwc_otg_core_if_t *core_if)
7650 + if (core_if->hcd_cb && core_if->hcd_cb->start) {
7651 + core_if->hcd_cb->start(core_if->hcd_cb->p);
7654 +/** Stop the HCD. Helper function for using the HCD callbacks.
7656 + * @param core_if Programming view of DWC_otg controller.
7658 +static inline void hcd_stop(dwc_otg_core_if_t *core_if)
7660 + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
7661 + core_if->hcd_cb->stop(core_if->hcd_cb->p);
7664 +/** Disconnect the HCD. Helper function for using the HCD callbacks.
7666 + * @param core_if Programming view of DWC_otg controller.
7668 +static inline void hcd_disconnect(dwc_otg_core_if_t *core_if)
7670 + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
7671 + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
7674 +/** Inform the HCD the a New Session has begun. Helper function for
7675 + * using the HCD callbacks.
7677 + * @param core_if Programming view of DWC_otg controller.
7679 +static inline void hcd_session_start(dwc_otg_core_if_t *core_if)
7681 + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
7682 + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
7686 +/** Start the PCD. Helper function for using the PCD callbacks.
7688 + * @param core_if Programming view of DWC_otg controller.
7690 +static inline void pcd_start(dwc_otg_core_if_t *core_if)
7692 + if (core_if->pcd_cb && core_if->pcd_cb->start) {
7693 + core_if->pcd_cb->start(core_if->pcd_cb->p);
7696 +/** Stop the PCD. Helper function for using the PCD callbacks.
7698 + * @param core_if Programming view of DWC_otg controller.
7700 +static inline void pcd_stop(dwc_otg_core_if_t *core_if)
7702 + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
7703 + core_if->pcd_cb->stop(core_if->pcd_cb->p);
7706 +/** Suspend the PCD. Helper function for using the PCD callbacks.
7708 + * @param core_if Programming view of DWC_otg controller.
7710 +static inline void pcd_suspend(dwc_otg_core_if_t *core_if)
7712 + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
7713 + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
7716 +/** Resume the PCD. Helper function for using the PCD callbacks.
7718 + * @param core_if Programming view of DWC_otg controller.
7720 +static inline void pcd_resume(dwc_otg_core_if_t *core_if)
7722 + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
7723 + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
7728 + * This function handles the OTG Interrupts. It reads the OTG
7729 + * Interrupt Register (GOTGINT) to determine what interrupt has
7732 + * @param core_if Programming view of DWC_otg controller.
7734 +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t *core_if)
7736 + dwc_otg_core_global_regs_t *global_regs =
7737 + core_if->core_global_regs;
7738 + gotgint_data_t gotgint;
7739 + gotgctl_data_t gotgctl;
7740 + gintmsk_data_t gintmsk;
7742 + gotgint.d32 = dwc_read_reg32(&global_regs->gotgint);
7743 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
7744 + DWC_DEBUGPL(DBG_CIL, "gotgctl=%08x\n", gotgctl.d32);
7746 + if (gotgint.b.sesenddet) {
7747 + DWC_DEBUGPL(DBG_ANY, "OTG Interrupt: "
7748 + "Session End Detected++ (%s)\n",
7749 + op_state_str(core_if));
7750 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
7752 + if (core_if->op_state == B_HOST) {
7753 + pcd_start(core_if);
7754 + core_if->op_state = B_PERIPHERAL;
7756 + /* If not B_HOST and Device HNP still set. HNP
7757 + * Did not succeed!*/
7758 + if (gotgctl.b.devhnpen) {
7759 + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
7760 + DWC_ERROR("Device Not Connected/Responding!\n");
7763 + /* If Session End Detected the B-Cable has
7764 + * been disconnected. */
7765 + /* Reset PCD and Gadget driver to a
7767 + pcd_stop(core_if);
7770 + gotgctl.b.devhnpen = 1;
7771 + dwc_modify_reg32(&global_regs->gotgctl,
7774 + if (gotgint.b.sesreqsucstschng) {
7775 + DWC_DEBUGPL(DBG_ANY, " OTG Interrupt: "
7776 + "Session Reqeust Success Status Change++\n");
7777 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
7778 + if (gotgctl.b.sesreqscs) {
7779 + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
7780 + (core_if->core_params->i2c_enable)) {
7781 + core_if->srp_success = 1;
7784 + pcd_resume(core_if);
7785 + /* Clear Session Request */
7787 + gotgctl.b.sesreq = 1;
7788 + dwc_modify_reg32(&global_regs->gotgctl,
7793 + if (gotgint.b.hstnegsucstschng) {
7794 + /* Print statements during the HNP interrupt handling
7795 + * can cause it to fail.*/
7796 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
7797 + if (gotgctl.b.hstnegscs) {
7798 + if (dwc_otg_is_host_mode(core_if)) {
7799 + core_if->op_state = B_HOST;
7801 + * Need to disable SOF interrupt immediately.
7802 + * When switching from device to host, the PCD
7803 + * interrupt handler won't handle the
7804 + * interrupt if host mode is already set. The
7805 + * HCD interrupt handler won't get called if
7806 + * the HCD state is HALT. This means that the
7807 + * interrupt does not get handled and Linux
7808 + * complains loudly.
7811 + gintmsk.b.sofintr = 1;
7812 + dwc_modify_reg32(&global_regs->gintmsk,
7814 + pcd_stop(core_if);
7816 + * Initialize the Core for Host mode.
7818 + hcd_start(core_if);
7819 + core_if->op_state = B_HOST;
7823 + gotgctl.b.hnpreq = 1;
7824 + gotgctl.b.devhnpen = 1;
7825 + dwc_modify_reg32(&global_regs->gotgctl,
7827 + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
7828 + DWC_ERROR("Device Not Connected/Responding\n");
7831 + if (gotgint.b.hstnegdet) {
7832 + /* The disconnect interrupt is set at the same time as
7833 + * Host Negotiation Detected. During the mode
7834 + * switch all interrupts are cleared so the disconnect
7835 + * interrupt handler will not get executed.
7837 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
7838 + "Host Negotiation Detected++ (%s)\n",
7839 + (dwc_otg_is_host_mode(core_if)?"Host":"Device"));
7840 + if (dwc_otg_is_device_mode(core_if)){
7841 + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n", core_if->op_state);
7842 + hcd_disconnect(core_if);
7843 + pcd_start(core_if);
7844 + core_if->op_state = A_PERIPHERAL;
7847 + * Need to disable SOF interrupt immediately. When
7848 + * switching from device to host, the PCD interrupt
7849 + * handler won't handle the interrupt if host mode is
7850 + * already set. The HCD interrupt handler won't get
7851 + * called if the HCD state is HALT. This means that
7852 + * the interrupt does not get handled and Linux
7853 + * complains loudly.
7856 + gintmsk.b.sofintr = 1;
7857 + dwc_modify_reg32(&global_regs->gintmsk,
7859 + pcd_stop(core_if);
7860 + hcd_start(core_if);
7861 + core_if->op_state = A_HOST;
7864 + if (gotgint.b.adevtoutchng) {
7865 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
7866 + "A-Device Timeout Change++\n");
7868 + if (gotgint.b.debdone) {
7869 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
7870 + "Debounce Done++\n");
7873 + /* Clear GOTGINT */
7874 + dwc_write_reg32 (&core_if->core_global_regs->gotgint, gotgint.d32);
7880 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7882 +void w_conn_id_status_change(void *p)
7884 + dwc_otg_core_if_t *core_if = p;
7888 +void w_conn_id_status_change(struct work_struct *p)
7890 + dwc_otg_core_if_t *core_if = container_of(p, dwc_otg_core_if_t, w_conn_id);
7895 + uint32_t count = 0;
7896 + gotgctl_data_t gotgctl = { .d32 = 0 };
7898 + gotgctl.d32 = dwc_read_reg32(&core_if->core_global_regs->gotgctl);
7899 + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
7900 + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
7902 + /* B-Device connector (Device Mode) */
7903 + if (gotgctl.b.conidsts) {
7904 + /* Wait for switch to device mode. */
7905 + while (!dwc_otg_is_device_mode(core_if)){
7906 + DWC_PRINT("Waiting for Peripheral Mode, Mode=%s\n",
7907 + (dwc_otg_is_host_mode(core_if)?"Host":"Peripheral"));
7909 + if (++count > 10000) *(uint32_t*)NULL=0;
7911 + core_if->op_state = B_PERIPHERAL;
7912 + dwc_otg_core_init(core_if);
7913 + dwc_otg_enable_global_interrupts(core_if);
7914 + pcd_start(core_if);
7916 + /* A-Device connector (Host Mode) */
7917 + while (!dwc_otg_is_host_mode(core_if)) {
7918 + DWC_PRINT("Waiting for Host Mode, Mode=%s\n",
7919 + (dwc_otg_is_host_mode(core_if)?"Host":"Peripheral"));
7921 + if (++count > 10000) *(uint32_t*)NULL=0;
7923 + core_if->op_state = A_HOST;
7925 + * Initialize the Core for Host mode.
7927 + dwc_otg_core_init(core_if);
7928 + dwc_otg_enable_global_interrupts(core_if);
7929 + hcd_start(core_if);
7935 + * This function handles the Connector ID Status Change Interrupt. It
7936 + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
7937 + * is a Device to Host Mode transition or a Host Mode to Device
7940 + * This only occurs when the cable is connected/removed from the PHY
7943 + * @param core_if Programming view of DWC_otg controller.
7945 +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t *core_if)
7949 + * Need to disable SOF interrupt immediately. If switching from device
7950 + * to host, the PCD interrupt handler won't handle the interrupt if
7951 + * host mode is already set. The HCD interrupt handler won't get
7952 + * called if the HCD state is HALT. This means that the interrupt does
7953 + * not get handled and Linux complains loudly.
7955 + gintmsk_data_t gintmsk = { .d32 = 0 };
7956 + gintsts_data_t gintsts = { .d32 = 0 };
7958 + gintmsk.b.sofintr = 1;
7959 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
7961 + DWC_DEBUGPL(DBG_CIL, " ++Connector ID Status Change Interrupt++ (%s)\n",
7962 + (dwc_otg_is_host_mode(core_if)?"Host":"Device"));
7965 + * Need to schedule a work, as there are possible DELAY function calls
7967 + queue_work(core_if->wq_otg, &core_if->w_conn_id);
7969 + /* Set flag and clear interrupt */
7970 + gintsts.b.conidstschng = 1;
7971 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
7977 + * This interrupt indicates that a device is initiating the Session
7978 + * Request Protocol to request the host to turn on bus power so a new
7979 + * session can begin. The handler responds by turning on bus power. If
7980 + * the DWC_otg controller is in low power mode, the handler brings the
7981 + * controller out of low power mode before turning on bus power.
7983 + * @param core_if Programming view of DWC_otg controller.
7985 +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t *core_if)
7987 + gintsts_data_t gintsts;
7989 +#ifndef DWC_HOST_ONLY
7990 + hprt0_data_t hprt0;
7991 + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
7993 + if (dwc_otg_is_device_mode(core_if)) {
7994 + DWC_PRINT("SRP: Device mode\n");
7996 + DWC_PRINT("SRP: Host mode\n");
7998 + /* Turn on the port power bit. */
7999 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
8000 + hprt0.b.prtpwr = 1;
8001 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8003 + /* Start the Connection timer. So a message can be displayed
8004 + * if connect does not occur within 10 seconds. */
8005 + hcd_session_start(core_if);
8009 + /* Clear interrupt */
8011 + gintsts.b.sessreqintr = 1;
8012 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8018 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
8019 +void w_wakeup_detected(void *p)
8021 + dwc_otg_core_if_t* core_if = p;
8025 +void w_wakeup_detected(struct work_struct *p)
8027 + struct delayed_work *dw = container_of(p, struct delayed_work, work);
8028 + dwc_otg_core_if_t *core_if = container_of(dw, dwc_otg_core_if_t, w_wkp);
8032 + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
8033 + * so that OPT tests pass with all PHYs).
8035 + hprt0_data_t hprt0 = {.d32=0};
8037 + pcgcctl_data_t pcgcctl = {.d32=0};
8038 + /* Restart the Phy Clock */
8039 + pcgcctl.b.stoppclk = 1;
8040 + dwc_modify_reg32(core_if->pcgcctl, pcgcctl.d32, 0);
8043 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
8044 + DWC_DEBUGPL(DBG_ANY,"Resume: HPRT0=%0x\n", hprt0.d32);
8046 + hprt0.b.prtres = 0; /* Resume */
8047 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8048 + DWC_DEBUGPL(DBG_ANY,"Clear Resume: HPRT0=%0x\n", dwc_read_reg32(core_if->host_if->hprt0));
8051 + * This interrupt indicates that the DWC_otg controller has detected a
8052 + * resume or remote wakeup sequence. If the DWC_otg controller is in
8053 + * low power mode, the handler must brings the controller out of low
8054 + * power mode. The controller automatically begins resume
8055 + * signaling. The handler schedules a time to stop resume signaling.
8057 +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t *core_if)
8059 + gintsts_data_t gintsts;
8061 + DWC_DEBUGPL(DBG_ANY, "++Resume and Remote Wakeup Detected Interrupt++\n");
8063 + if (dwc_otg_is_device_mode(core_if)) {
8064 + dctl_data_t dctl = {.d32=0};
8065 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
8066 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts));
8067 +#ifdef PARTIAL_POWER_DOWN
8068 + if (core_if->hwcfg4.b.power_optimiz) {
8069 + pcgcctl_data_t power = {.d32=0};
8071 + power.d32 = dwc_read_reg32(core_if->pcgcctl);
8072 + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n", power.d32);
8074 + power.b.stoppclk = 0;
8075 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8077 + power.b.pwrclmp = 0;
8078 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8080 + power.b.rstpdwnmodule = 0;
8081 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8084 + /* Clear the Remote Wakeup Signalling */
8085 + dctl.b.rmtwkupsig = 1;
8086 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dctl,
8089 + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
8090 + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
8094 + pcgcctl_data_t pcgcctl = {.d32=0};
8096 + /* Restart the Phy Clock */
8097 + pcgcctl.b.stoppclk = 1;
8098 + dwc_modify_reg32(core_if->pcgcctl, pcgcctl.d32, 0);
8100 + queue_delayed_work(core_if->wq_otg, &core_if->w_wkp, ((70 * HZ / 1000) + 1));
8103 + /* Clear interrupt */
8105 + gintsts.b.wkupintr = 1;
8106 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8112 + * This interrupt indicates that a device has been disconnected from
8115 +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t *core_if)
8117 + gintsts_data_t gintsts;
8119 + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
8120 + (dwc_otg_is_host_mode(core_if)?"Host":"Device"),
8121 + op_state_str(core_if));
8123 +/** @todo Consolidate this if statement. */
8124 +#ifndef DWC_HOST_ONLY
8125 + if (core_if->op_state == B_HOST) {
8126 + /* If in device mode Disconnect and stop the HCD, then
8127 + * start the PCD. */
8128 + hcd_disconnect(core_if);
8129 + pcd_start(core_if);
8130 + core_if->op_state = B_PERIPHERAL;
8131 + } else if (dwc_otg_is_device_mode(core_if)) {
8132 + gotgctl_data_t gotgctl = { .d32 = 0 };
8133 + gotgctl.d32 = dwc_read_reg32(&core_if->core_global_regs->gotgctl);
8134 + if (gotgctl.b.hstsethnpen==1) {
8135 + /* Do nothing, if HNP in process the OTG
8136 + * interrupt "Host Negotiation Detected"
8137 + * interrupt will do the mode switch.
8139 + } else if (gotgctl.b.devhnpen == 0) {
8140 + /* If in device mode Disconnect and stop the HCD, then
8141 + * start the PCD. */
8142 + hcd_disconnect(core_if);
8143 + pcd_start(core_if);
8144 + core_if->op_state = B_PERIPHERAL;
8146 + DWC_DEBUGPL(DBG_ANY,"!a_peripheral && !devhnpen\n");
8149 + if (core_if->op_state == A_HOST) {
8150 + /* A-Cable still connected but device disconnected. */
8151 + hcd_disconnect(core_if);
8157 + gintsts.b.disconnect = 1;
8158 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8162 + * This interrupt indicates that SUSPEND state has been detected on
8165 + * For HNP the USB Suspend interrupt signals the change from
8166 + * "a_peripheral" to "a_host".
8168 + * When power management is enabled the core will be put in low power
8171 +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t *core_if)
8174 + gintsts_data_t gintsts;
8176 + DWC_DEBUGPL(DBG_ANY,"USB SUSPEND\n");
8178 + if (dwc_otg_is_device_mode(core_if)) {
8179 + /* Check the Device status register to determine if the Suspend
8180 + * state is active. */
8181 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
8182 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
8183 + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
8184 + "HWCFG4.power Optimize=%d\n",
8185 + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
8188 +#ifdef PARTIAL_POWER_DOWN
8189 +/** @todo Add a module parameter for power management. */
8191 + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
8192 + pcgcctl_data_t power = {.d32=0};
8193 + DWC_DEBUGPL(DBG_CIL, "suspend\n");
8195 + power.b.pwrclmp = 1;
8196 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8198 + power.b.rstpdwnmodule = 1;
8199 + dwc_modify_reg32(core_if->pcgcctl, 0, power.d32);
8201 + power.b.stoppclk = 1;
8202 + dwc_modify_reg32(core_if->pcgcctl, 0, power.d32);
8205 + DWC_DEBUGPL(DBG_ANY,"disconnect?\n");
8208 + /* PCD callback for suspend. */
8209 + pcd_suspend(core_if);
8211 + if (core_if->op_state == A_PERIPHERAL) {
8212 + DWC_DEBUGPL(DBG_ANY,"a_peripheral->a_host\n");
8213 + /* Clear the a_peripheral flag, back to a_host. */
8214 + pcd_stop(core_if);
8215 + hcd_start(core_if);
8216 + core_if->op_state = A_HOST;
8220 + /* Clear interrupt */
8222 + gintsts.b.usbsuspend = 1;
8223 + dwc_write_reg32(&core_if->core_global_regs->gintsts, gintsts.d32);
8230 + * This function returns the Core Interrupt register.
8232 +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t *core_if)
8234 + gintsts_data_t gintsts;
8235 + gintmsk_data_t gintmsk;
8236 + gintmsk_data_t gintmsk_common = {.d32=0};
8237 + gintmsk_common.b.wkupintr = 1;
8238 + gintmsk_common.b.sessreqintr = 1;
8239 + gintmsk_common.b.conidstschng = 1;
8240 + gintmsk_common.b.otgintr = 1;
8241 + gintmsk_common.b.modemismatch = 1;
8242 + gintmsk_common.b.disconnect = 1;
8243 + gintmsk_common.b.usbsuspend = 1;
8244 + /** @todo: The port interrupt occurs while in device
8245 + * mode. Added code to CIL to clear the interrupt for now!
8247 + gintmsk_common.b.portintr = 1;
8249 + gintsts.d32 = dwc_read_reg32(&core_if->core_global_regs->gintsts);
8250 + gintmsk.d32 = dwc_read_reg32(&core_if->core_global_regs->gintmsk);
8252 + /* if any common interrupts set */
8253 + if (gintsts.d32 & gintmsk_common.d32) {
8254 + DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
8255 + gintsts.d32, gintmsk.d32);
8259 + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
8264 + * Common interrupt handler.
8266 + * The common interrupts are those that occur in both Host and Device mode.
8267 + * This handler handles the following interrupts:
8268 + * - Mode Mismatch Interrupt
8269 + * - Disconnect Interrupt
8271 + * - Connector ID Status Change Interrupt
8272 + * - Session Request Interrupt.
8273 + * - Resume / Remote Wakeup Detected Interrupt.
8276 +int32_t dwc_otg_handle_common_intr(dwc_otg_core_if_t *core_if)
8279 + gintsts_data_t gintsts;
8281 + gintsts.d32 = dwc_otg_read_common_intr(core_if);
8283 + if (gintsts.b.modemismatch) {
8284 + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
8286 + if (gintsts.b.otgintr) {
8287 + retval |= dwc_otg_handle_otg_intr(core_if);
8289 + if (gintsts.b.conidstschng) {
8290 + retval |= dwc_otg_handle_conn_id_status_change_intr(core_if);
8292 + if (gintsts.b.disconnect) {
8293 + retval |= dwc_otg_handle_disconnect_intr(core_if);
8295 + if (gintsts.b.sessreqintr) {
8296 + retval |= dwc_otg_handle_session_req_intr(core_if);
8298 + if (gintsts.b.wkupintr) {
8299 + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
8301 + if (gintsts.b.usbsuspend) {
8302 + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
8304 + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
8305 + /* The port interrupt occurs while in device mode with HPRT0
8306 + * Port Enable/Disable.
8309 + gintsts.b.portintr = 1;
8310 + dwc_write_reg32(&core_if->core_global_regs->gintsts,
8316 + S3C2410X_CLEAR_EINTPEND();
8320 diff --git a/drivers/usb/dwc_otg/dwc_otg_driver.c b/drivers/usb/dwc_otg/dwc_otg_driver.c
8321 new file mode 100644
8322 index 0000000..63272d0
8324 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.c
8326 +/* ==========================================================================
8327 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.c $
8328 + * $Revision: 1.7 $
8329 + * $Date: 2008-11-21 05:39:15 $
8330 + * $Change: 791271 $
8332 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8333 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
8334 + * otherwise expressly agreed to in writing between Synopsys and you.
8336 + * The Software IS NOT an item of Licensed Software or Licensed Product under
8337 + * any End User Software License Agreement or Agreement for Licensed Product
8338 + * with Synopsys or any supplement thereto. You are permitted to use and
8339 + * redistribute this Software in source and binary forms, with or without
8340 + * modification, provided that redistributions of source code must retain this
8341 + * notice. You may not view, use, disclose, copy or distribute this file or
8342 + * any information contained herein except pursuant to this license grant from
8343 + * Synopsys. If you do not agree with this notice, including the disclaimer
8344 + * below, then you are not authorized to use the Software.
8346 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
8347 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8348 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8349 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
8350 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8351 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
8352 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
8353 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
8354 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
8355 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
8357 + * ========================================================================== */
8360 + * The dwc_otg_driver module provides the initialization and cleanup entry
8361 + * points for the DWC_otg driver. This module will be dynamically installed
8362 + * after Linux is booted using the insmod command. When the module is
8363 + * installed, the dwc_otg_driver_init function is called. When the module is
8364 + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
8366 + * This module also defines a data structure for the dwc_otg_driver, which is
8367 + * used in conjunction with the standard ARM platform_device structure. These
8368 + * structures allow the OTG driver to comply with the standard Linux driver
8369 + * model in which devices and drivers are registered with a bus driver. This
8370 + * has the benefit that Linux can expose attributes of the driver and device
8371 + * in its special sysfs file system. Users can then read or write files in
8372 + * this file system to perform diagnostics on the driver components or the
8376 +#include <linux/kernel.h>
8377 +#include <linux/module.h>
8378 +#include <linux/moduleparam.h>
8379 +#include <linux/init.h>
8380 +#include <linux/device.h>
8381 +#include <linux/errno.h>
8382 +#include <linux/types.h>
8383 +#include <linux/stat.h> /* permission constants */
8384 +#include <linux/version.h>
8385 +#include <linux/platform_device.h>
8387 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
8388 +# include <linux/irq.h>
8391 +#include <asm/io.h>
8393 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
8394 +# include <asm/irq.h>
8397 +#include "linux/dwc_otg_plat.h"
8398 +#include "dwc_otg_attr.h"
8399 +#include "dwc_otg_driver.h"
8400 +#include "dwc_otg_cil.h"
8401 +#include "dwc_otg_pcd.h"
8402 +#include "dwc_otg_hcd.h"
8404 +#define DWC_DRIVER_VERSION "2.72a 24-JUN-2008"
8405 +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
8407 +static const char dwc_driver_name[] = "dwc_otg";
8409 +/*-------------------------------------------------------------------------*/
8410 +/* Encapsulate the module parameter settings */
8412 +static dwc_otg_core_params_t dwc_otg_module_params = {
8416 + .dma_desc_enable = -1,
8417 + .dma_burst_size = -1,
8419 + .host_support_fs_ls_low_power = -1,
8420 + .host_ls_low_power_phy_clk = -1,
8421 + .enable_dynamic_fifo = -1,
8422 + .data_fifo_size = -1,
8423 + .dev_rx_fifo_size = -1,
8424 + .dev_nperio_tx_fifo_size = -1,
8425 + .dev_perio_tx_fifo_size = {
8426 + /* dev_perio_tx_fifo_size_1 */
8444 + .host_rx_fifo_size = -1,
8445 + .host_nperio_tx_fifo_size = -1,
8446 + .host_perio_tx_fifo_size = -1,
8447 + .max_transfer_size = -1,
8448 + .max_packet_count = -1,
8449 + .host_channels = -1,
8450 + .dev_endpoints = -1,
8452 + .phy_utmi_width = -1,
8453 + .phy_ulpi_ddr = -1,
8454 + .phy_ulpi_ext_vbus = -1,
8458 + .en_multiple_tx_fifo = -1,
8459 + .dev_tx_fifo_size = {
8460 + /* dev_tx_fifo_size */
8479 + .tx_thr_length = -1,
8480 + .rx_thr_length = -1,
8486 + * This function shows the Driver Version.
8488 +static ssize_t version_show(struct device_driver *dev, char *buf)
8490 + return snprintf(buf, sizeof(DWC_DRIVER_VERSION)+2, "%s\n",
8491 + DWC_DRIVER_VERSION);
8493 +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
8496 + * Global Debug Level Mask.
8498 +uint32_t g_dbg_lvl = 0; /* OFF */
8501 + * This function shows the driver Debug Level.
8503 +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
8505 + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
8509 + * This function stores the driver Debug Level.
8511 +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
8514 + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
8517 +static DRIVER_ATTR(debuglevel, S_IRUGO|S_IWUSR, dbg_level_show, dbg_level_store);
8520 + * This function is called during module intialization to verify that
8521 + * the module parameters are in a valid state.
8523 +static int check_parameters(dwc_otg_core_if_t *core_if)
8528 +/* Checks if the parameter is outside of its valid range of values */
8529 +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
8530 + ((dwc_otg_module_params._param_ < (_low_)) || \
8531 + (dwc_otg_module_params._param_ > (_high_)))
8533 +/* If the parameter has been set by the user, check that the parameter value is
8534 + * within the value range of values. If not, report a module error. */
8535 +#define DWC_OTG_PARAM_ERR(_param_, _low_, _high_, _string_) \
8537 + if (dwc_otg_module_params._param_ != -1) { \
8538 + if (DWC_OTG_PARAM_TEST(_param_, (_low_), (_high_))) { \
8539 + DWC_ERROR("`%d' invalid for parameter `%s'\n", \
8540 + dwc_otg_module_params._param_, _string_); \
8541 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
8547 + DWC_OTG_PARAM_ERR(opt,0,1,"opt");
8548 + DWC_OTG_PARAM_ERR(otg_cap,0,2,"otg_cap");
8549 + DWC_OTG_PARAM_ERR(dma_enable,0,1,"dma_enable");
8550 + DWC_OTG_PARAM_ERR(dma_desc_enable,0,1,"dma_desc_enable");
8551 + DWC_OTG_PARAM_ERR(speed,0,1,"speed");
8552 + DWC_OTG_PARAM_ERR(host_support_fs_ls_low_power,0,1,"host_support_fs_ls_low_power");
8553 + DWC_OTG_PARAM_ERR(host_ls_low_power_phy_clk,0,1,"host_ls_low_power_phy_clk");
8554 + DWC_OTG_PARAM_ERR(enable_dynamic_fifo,0,1,"enable_dynamic_fifo");
8555 + DWC_OTG_PARAM_ERR(data_fifo_size,32,32768,"data_fifo_size");
8556 + DWC_OTG_PARAM_ERR(dev_rx_fifo_size,16,32768,"dev_rx_fifo_size");
8557 + DWC_OTG_PARAM_ERR(dev_nperio_tx_fifo_size,16,32768,"dev_nperio_tx_fifo_size");
8558 + DWC_OTG_PARAM_ERR(host_rx_fifo_size,16,32768,"host_rx_fifo_size");
8559 + DWC_OTG_PARAM_ERR(host_nperio_tx_fifo_size,16,32768,"host_nperio_tx_fifo_size");
8560 + DWC_OTG_PARAM_ERR(host_perio_tx_fifo_size,16,32768,"host_perio_tx_fifo_size");
8561 + DWC_OTG_PARAM_ERR(max_transfer_size,2047,524288,"max_transfer_size");
8562 + DWC_OTG_PARAM_ERR(max_packet_count,15,511,"max_packet_count");
8563 + DWC_OTG_PARAM_ERR(host_channels,1,16,"host_channels");
8564 + DWC_OTG_PARAM_ERR(dev_endpoints,1,15,"dev_endpoints");
8565 + DWC_OTG_PARAM_ERR(phy_type,0,2,"phy_type");
8566 + DWC_OTG_PARAM_ERR(phy_ulpi_ddr,0,1,"phy_ulpi_ddr");
8567 + DWC_OTG_PARAM_ERR(phy_ulpi_ext_vbus,0,1,"phy_ulpi_ext_vbus");
8568 + DWC_OTG_PARAM_ERR(i2c_enable,0,1,"i2c_enable");
8569 + DWC_OTG_PARAM_ERR(ulpi_fs_ls,0,1,"ulpi_fs_ls");
8570 + DWC_OTG_PARAM_ERR(ts_dline,0,1,"ts_dline");
8572 + if (dwc_otg_module_params.dma_burst_size != -1) {
8573 + if (DWC_OTG_PARAM_TEST(dma_burst_size,1,1) &&
8574 + DWC_OTG_PARAM_TEST(dma_burst_size,4,4) &&
8575 + DWC_OTG_PARAM_TEST(dma_burst_size,8,8) &&
8576 + DWC_OTG_PARAM_TEST(dma_burst_size,16,16) &&
8577 + DWC_OTG_PARAM_TEST(dma_burst_size,32,32) &&
8578 + DWC_OTG_PARAM_TEST(dma_burst_size,64,64) &&
8579 + DWC_OTG_PARAM_TEST(dma_burst_size,128,128) &&
8580 + DWC_OTG_PARAM_TEST(dma_burst_size,256,256)) {
8581 + DWC_ERROR("`%d' invalid for parameter `dma_burst_size'\n",
8582 + dwc_otg_module_params.dma_burst_size);
8583 + dwc_otg_module_params.dma_burst_size = 32;
8588 + uint8_t brst_sz = 0;
8589 + while(dwc_otg_module_params.dma_burst_size > 1) {
8591 + dwc_otg_module_params.dma_burst_size >>= 1;
8593 + dwc_otg_module_params.dma_burst_size = brst_sz;
8597 + if (dwc_otg_module_params.phy_utmi_width != -1) {
8598 + if (DWC_OTG_PARAM_TEST(phy_utmi_width, 8, 8) &&
8599 + DWC_OTG_PARAM_TEST(phy_utmi_width, 16, 16)) {
8600 + DWC_ERROR("`%d' invalid for parameter `phy_utmi_width'\n",
8601 + dwc_otg_module_params.phy_utmi_width);
8602 + dwc_otg_module_params.phy_utmi_width = 16;
8607 + for (i = 0; i < 15; i++) {
8608 + /** @todo should be like above */
8609 + //DWC_OTG_PARAM_ERR(dev_perio_tx_fifo_size[i], 4, 768, "dev_perio_tx_fifo_size");
8610 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
8611 + if (DWC_OTG_PARAM_TEST(dev_perio_tx_fifo_size[i], 4, 768)) {
8612 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
8613 + dwc_otg_module_params.dev_perio_tx_fifo_size[i], "dev_perio_tx_fifo_size", i);
8614 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
8620 + DWC_OTG_PARAM_ERR(en_multiple_tx_fifo, 0, 1, "en_multiple_tx_fifo");
8622 + for (i = 0; i < 15; i++) {
8623 + /** @todo should be like above */
8624 + //DWC_OTG_PARAM_ERR(dev_tx_fifo_size[i], 4, 768, "dev_tx_fifo_size");
8625 + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
8626 + if (DWC_OTG_PARAM_TEST(dev_tx_fifo_size[i], 4, 768)) {
8627 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
8628 + dwc_otg_module_params.dev_tx_fifo_size[i], "dev_tx_fifo_size", i);
8629 + dwc_otg_module_params.dev_tx_fifo_size[i] = dwc_param_dev_tx_fifo_size_default;
8635 + DWC_OTG_PARAM_ERR(thr_ctl, 0, 7, "thr_ctl");
8636 + DWC_OTG_PARAM_ERR(tx_thr_length, 8, 128, "tx_thr_length");
8637 + DWC_OTG_PARAM_ERR(rx_thr_length, 8, 128, "rx_thr_length");
8639 + DWC_OTG_PARAM_ERR(pti_enable,0,1,"pti_enable");
8640 + DWC_OTG_PARAM_ERR(mpi_enable,0,1,"mpi_enable");
8642 + /* At this point, all module parameters that have been set by the user
8643 + * are valid, and those that have not are left unset. Now set their
8644 + * default values and/or check the parameters against the hardware
8645 + * configurations of the OTG core. */
8647 +/* This sets the parameter to the default value if it has not been set by the
8649 +#define DWC_OTG_PARAM_SET_DEFAULT(_param_) \
8651 + int changed = 1; \
8652 + if (dwc_otg_module_params._param_ == -1) { \
8654 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
8659 +/* This checks the macro agains the hardware configuration to see if it is
8660 + * valid. It is possible that the default value could be invalid. In this
8661 + * case, it will report a module error if the user touched the parameter.
8662 + * Otherwise it will adjust the value without any error. */
8663 +#define DWC_OTG_PARAM_CHECK_VALID(_param_, _str_, _is_valid_, _set_valid_) \
8665 + int changed = DWC_OTG_PARAM_SET_DEFAULT(_param_); \
8667 + if (!(_is_valid_)) { \
8669 + DWC_ERROR("`%d' invalid for parameter `%s'. Check HW configuration.\n", dwc_otg_module_params._param_, _str_); \
8672 + dwc_otg_module_params._param_ = (_set_valid_); \
8678 + retval += DWC_OTG_PARAM_CHECK_VALID(otg_cap, "otg_cap",
8682 + switch (dwc_otg_module_params.otg_cap) {
8683 + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
8684 + if (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
8687 + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
8688 + if ((core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) &&
8689 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) &&
8690 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) &&
8691 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
8695 + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
8696 + /* always valid */
8701 + (((core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) ||
8702 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) ||
8703 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
8704 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
8705 + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
8706 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE));
8708 + retval += DWC_OTG_PARAM_CHECK_VALID(dma_enable, "dma_enable",
8709 + ((dwc_otg_module_params.dma_enable == 1) && (core_if->hwcfg2.b.architecture == 0)) ? 0 : 1,
8712 + retval += DWC_OTG_PARAM_CHECK_VALID(dma_desc_enable, "dma_desc_enable",
8713 + ((dwc_otg_module_params.dma_desc_enable == 1) &&
8714 + ((dwc_otg_module_params.dma_enable == 0) || (core_if->hwcfg4.b.desc_dma == 0))) ? 0 : 1,
8717 + retval += DWC_OTG_PARAM_CHECK_VALID(opt, "opt", 1, 0);
8719 + DWC_OTG_PARAM_SET_DEFAULT(dma_burst_size);
8721 + retval += DWC_OTG_PARAM_CHECK_VALID(host_support_fs_ls_low_power,
8722 + "host_support_fs_ls_low_power",
8725 + retval += DWC_OTG_PARAM_CHECK_VALID(enable_dynamic_fifo,
8726 + "enable_dynamic_fifo",
8727 + ((dwc_otg_module_params.enable_dynamic_fifo == 0) ||
8728 + (core_if->hwcfg2.b.dynamic_fifo == 1)), 0);
8730 + retval += DWC_OTG_PARAM_CHECK_VALID(data_fifo_size,
8732 + (dwc_otg_module_params.data_fifo_size <= core_if->hwcfg3.b.dfifo_depth),
8733 + core_if->hwcfg3.b.dfifo_depth);
8735 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_rx_fifo_size,
8736 + "dev_rx_fifo_size",
8737 + (dwc_otg_module_params.dev_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
8738 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
8740 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_nperio_tx_fifo_size,
8741 + "dev_nperio_tx_fifo_size",
8742 + (dwc_otg_module_params.dev_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
8743 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
8745 + retval += DWC_OTG_PARAM_CHECK_VALID(host_rx_fifo_size,
8746 + "host_rx_fifo_size",
8747 + (dwc_otg_module_params.host_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
8748 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
8750 + retval += DWC_OTG_PARAM_CHECK_VALID(host_nperio_tx_fifo_size,
8751 + "host_nperio_tx_fifo_size",
8752 + (dwc_otg_module_params.host_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
8753 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
8755 + retval += DWC_OTG_PARAM_CHECK_VALID(host_perio_tx_fifo_size,
8756 + "host_perio_tx_fifo_size",
8757 + (dwc_otg_module_params.host_perio_tx_fifo_size <= ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16))),
8758 + ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16)));
8760 + retval += DWC_OTG_PARAM_CHECK_VALID(max_transfer_size,
8761 + "max_transfer_size",
8762 + (dwc_otg_module_params.max_transfer_size < (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))),
8763 + ((1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1));
8765 + retval += DWC_OTG_PARAM_CHECK_VALID(max_packet_count,
8766 + "max_packet_count",
8767 + (dwc_otg_module_params.max_packet_count < (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))),
8768 + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1));
8770 + retval += DWC_OTG_PARAM_CHECK_VALID(host_channels,
8772 + (dwc_otg_module_params.host_channels <= (core_if->hwcfg2.b.num_host_chan + 1)),
8773 + (core_if->hwcfg2.b.num_host_chan + 1));
8775 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_endpoints,
8777 + (dwc_otg_module_params.dev_endpoints <= (core_if->hwcfg2.b.num_dev_ep)),
8778 + core_if->hwcfg2.b.num_dev_ep);
8781 + * Define the following to disable the FS PHY Hardware checking. This is for
8782 + * internal testing only.
8784 + * #define NO_FS_PHY_HW_CHECKS
8787 +#ifdef NO_FS_PHY_HW_CHECKS
8788 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
8789 + "phy_type", 1, 0);
8791 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
8795 + if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_UTMI) &&
8796 + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
8797 + (core_if->hwcfg2.b.hs_phy_type == 3))) {
8800 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_ULPI) &&
8801 + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
8802 + (core_if->hwcfg2.b.hs_phy_type == 3))) {
8805 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) &&
8806 + (core_if->hwcfg2.b.fs_phy_type == 1)) {
8812 + int set = DWC_PHY_TYPE_PARAM_FS;
8813 + if (core_if->hwcfg2.b.hs_phy_type) {
8814 + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
8815 + (core_if->hwcfg2.b.hs_phy_type == 1)) {
8816 + set = DWC_PHY_TYPE_PARAM_UTMI;
8819 + set = DWC_PHY_TYPE_PARAM_ULPI;
8826 + retval += DWC_OTG_PARAM_CHECK_VALID(speed, "speed",
8827 + (dwc_otg_module_params.speed == 0) && (dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1,
8828 + dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
8830 + retval += DWC_OTG_PARAM_CHECK_VALID(host_ls_low_power_phy_clk,
8831 + "host_ls_low_power_phy_clk",
8832 + ((dwc_otg_module_params.host_ls_low_power_phy_clk == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ) && (dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1),
8833 + ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) ? DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ : DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ));
8835 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ddr);
8836 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ext_vbus);
8837 + DWC_OTG_PARAM_SET_DEFAULT(phy_utmi_width);
8838 + DWC_OTG_PARAM_SET_DEFAULT(ulpi_fs_ls);
8839 + DWC_OTG_PARAM_SET_DEFAULT(ts_dline);
8841 +#ifdef NO_FS_PHY_HW_CHECKS
8842 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable, "i2c_enable", 1, 0);
8844 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
8846 + (dwc_otg_module_params.i2c_enable == 1) && (core_if->hwcfg3.b.i2c == 0) ? 0 : 1,
8850 + for (i = 0; i < 15; i++) {
8854 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] == -1) {
8856 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
8858 + if (!(dwc_otg_module_params.dev_perio_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
8860 + DWC_ERROR("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n", dwc_otg_module_params.dev_perio_tx_fifo_size[i], i);
8863 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
8868 + retval += DWC_OTG_PARAM_CHECK_VALID(en_multiple_tx_fifo, "en_multiple_tx_fifo",
8869 + ((dwc_otg_module_params.en_multiple_tx_fifo == 1) && (core_if->hwcfg4.b.ded_fifo_en == 0)) ? 0 : 1,
8872 + for (i = 0; i < 15; i++) {
8876 + if (dwc_otg_module_params.dev_tx_fifo_size[i] == -1) {
8878 + dwc_otg_module_params.dev_tx_fifo_size[i] = dwc_param_dev_tx_fifo_size_default;
8880 + if (!(dwc_otg_module_params.dev_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
8882 + DWC_ERROR("%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n", dwc_otg_module_params.dev_tx_fifo_size[i], i);
8885 + dwc_otg_module_params.dev_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
8890 + retval += DWC_OTG_PARAM_CHECK_VALID(thr_ctl, "thr_ctl",
8891 + ((dwc_otg_module_params.thr_ctl != 0) && ((dwc_otg_module_params.dma_enable == 0) || (core_if->hwcfg4.b.ded_fifo_en == 0))) ? 0 : 1,
8894 + DWC_OTG_PARAM_SET_DEFAULT(tx_thr_length);
8895 + DWC_OTG_PARAM_SET_DEFAULT(rx_thr_length);
8897 + retval += DWC_OTG_PARAM_CHECK_VALID(pti_enable, "pti_enable",
8898 + ((dwc_otg_module_params.pti_enable == 0) || ((dwc_otg_module_params.pti_enable == 1) && (core_if->snpsid >= 0x4F54272A))) ? 1 : 0,
8901 + retval += DWC_OTG_PARAM_CHECK_VALID(mpi_enable, "mpi_enable",
8902 + ((dwc_otg_module_params.mpi_enable == 0) || ((dwc_otg_module_params.mpi_enable == 1) && (core_if->hwcfg2.b.multi_proc_int == 1))) ? 1 : 0,
8908 + * This function is the top level interrupt handler for the Common
8909 + * (Device and host modes) interrupts.
8911 +static irqreturn_t dwc_otg_common_irq(int irq, void *dev
8912 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
8913 + , struct pt_regs *r
8917 + dwc_otg_device_t *otg_dev = dev;
8918 + int32_t retval = IRQ_NONE;
8920 + retval = dwc_otg_handle_common_intr(otg_dev->core_if);
8921 + return IRQ_RETVAL(retval);
8925 + * This function is called when a platform_device is unregistered with the
8926 + * dwc_otg_driver. This happens, for example, when the rmmod command is
8927 + * executed. The device may or may not be electrically present. If it is
8928 + * present, the driver stops device processing. Any resources used on behalf
8929 + * of this device are freed.
8933 +static int dwc_otg_driver_remove(struct platform_device *pdev)
8935 + dwc_otg_device_t *otg_dev = platform_get_drvdata(pdev);
8936 + DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, pdev);
8939 + /* Memory allocation for the dwc_otg_device failed. */
8940 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
8947 + if (otg_dev->common_irq_installed) {
8948 + free_irq(otg_dev->irq, otg_dev);
8951 +#ifndef DWC_DEVICE_ONLY
8952 + if (otg_dev->hcd) {
8953 + dwc_otg_hcd_remove(&pdev->dev);
8955 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
8960 +#ifndef DWC_HOST_ONLY
8961 + if (otg_dev->pcd) {
8962 + dwc_otg_pcd_remove(&pdev->dev);
8965 + if (otg_dev->core_if) {
8966 + dwc_otg_cil_remove(otg_dev->core_if);
8970 + * Remove the device attributes
8972 + dwc_otg_attr_remove(otg_dev->parent);
8974 + /* Disable USB port */
8975 + dwc_write_reg32((uint32_t *)((uint8_t *)otg_dev->base + 0xe00), 0xf);
8978 + * Return the memory.
8980 + if (otg_dev->base) {
8981 + iounmap(otg_dev->base);
8984 + if (otg_dev->phys_addr != 0) {
8985 + release_mem_region(otg_dev->phys_addr, otg_dev->base_len);
8991 + * Clear the drvdata pointer.
8993 + platform_set_drvdata(pdev, NULL);
8999 + * This function is called when an platform_device is bound to a
9000 + * dwc_otg_driver. It creates the driver components required to
9001 + * control the device (CIL, HCD, and PCD) and it initializes the
9002 + * device. The driver components are stored in a dwc_otg_device
9003 + * structure. A reference to the dwc_otg_device is saved in the
9004 + * platform_device. This allows the driver to access the dwc_otg_device
9005 + * structure on subsequent calls to driver methods for this device.
9007 + * @param[in] pdev platform_device definition
9009 +static int dwc_otg_driver_probe(struct platform_device *pdev)
9013 + dwc_otg_device_t *otg_dev;
9014 + struct resource *res;
9016 + dev_dbg(&pdev->dev, "dwc_otg_driver_probe(%p)\n", pdev);
9018 + otg_dev= kzalloc(sizeof(dwc_otg_device_t), GFP_KERNEL);
9020 + dev_err(&pdev->dev, "kmalloc of dwc_otg_device failed\n");
9025 + otg_dev->reg_offset = 0xFFFFFFFF;
9028 + * Retrieve the memory and IRQ resources.
9030 + otg_dev->irq = platform_get_irq(pdev, 0);
9031 + if (otg_dev->irq <= 0) {
9032 + dev_err(&pdev->dev, "no device irq\n");
9037 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
9038 + if (res == NULL) {
9039 + dev_err(&pdev->dev, "no CSR address\n");
9044 + otg_dev->parent = &pdev->dev;
9045 + otg_dev->phys_addr = res->start;
9046 + otg_dev->base_len = res->end - res->start + 1;
9047 + if (request_mem_region(otg_dev->phys_addr,
9048 + otg_dev->base_len,
9049 + dwc_driver_name) == NULL) {
9050 + dev_err(&pdev->dev, "request_mem_region failed\n");
9056 + * Map the DWC_otg Core memory into virtual address space.
9058 + otg_dev->base = ioremap(otg_dev->phys_addr, otg_dev->base_len);
9059 + if (!otg_dev->base) {
9060 + dev_err(&pdev->dev, "ioremap() failed\n");
9064 + dev_dbg(&pdev->dev, "mapped base=0x%08x\n", (unsigned) otg_dev->base);
9066 + /* Enable USB Port */
9067 + dwc_write_reg32((uint32_t *)((uint8_t *)otg_dev->base + 0xe00), 0);
9070 + * Attempt to ensure this device is really a DWC_otg Controller.
9071 + * Read and verify the SNPSID register contents. The value should be
9072 + * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
9074 + snpsid = dwc_read_reg32((uint32_t *)((uint8_t *)otg_dev->base + 0x40));
9076 + if ((snpsid & 0xFFFFF000) != OTG_CORE_REV_2_00) {
9077 + dev_err(&pdev->dev, "Bad value for SNPSID: 0x%08x\n", snpsid);
9082 + DWC_PRINT("Core Release: %x.%x%x%x\n",
9083 + (snpsid >> 12 & 0xF),
9084 + (snpsid >> 8 & 0xF),
9085 + (snpsid >> 4 & 0xF),
9089 + * Initialize driver data to point to the global DWC_otg
9090 + * Device structure.
9092 + platform_set_drvdata(pdev, otg_dev);
9093 + dev_dbg(&pdev->dev, "dwc_otg_device=0x%p\n", otg_dev);
9096 + otg_dev->core_if = dwc_otg_cil_init(otg_dev->base,
9097 + &dwc_otg_module_params);
9099 + otg_dev->core_if->snpsid = snpsid;
9101 + if (!otg_dev->core_if) {
9102 + dev_err(&pdev->dev, "CIL initialization failed!\n");
9108 + * Validate parameter values.
9110 + if (check_parameters(otg_dev->core_if)) {
9116 + * Create Device Attributes in sysfs
9118 + dwc_otg_attr_create(&pdev->dev);
9121 + * Disable the global interrupt until all the interrupt
9122 + * handlers are installed.
9124 + dwc_otg_disable_global_interrupts(otg_dev->core_if);
9127 + * Install the interrupt handler for the common interrupts before
9128 + * enabling common interrupts in core_init below.
9130 + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
9132 + retval = request_irq(otg_dev->irq, dwc_otg_common_irq,
9133 + IRQF_SHARED, "dwc_otg", otg_dev);
9135 + DWC_ERROR("request of irq%d failed\n", otg_dev->irq);
9139 + otg_dev->common_irq_installed = 1;
9143 + * Initialize the DWC_otg core.
9145 + dwc_otg_core_init(otg_dev->core_if);
9147 +#ifndef DWC_HOST_ONLY
9149 + * Initialize the PCD
9151 + retval = dwc_otg_pcd_init(&pdev->dev);
9152 + if (retval != 0) {
9153 + DWC_ERROR("dwc_otg_pcd_init failed\n");
9154 + otg_dev->pcd = NULL;
9158 +#ifndef DWC_DEVICE_ONLY
9160 + * Initialize the HCD
9162 + retval = dwc_otg_hcd_init(&pdev->dev);
9163 + if (retval != 0) {
9164 + DWC_ERROR("dwc_otg_hcd_init failed\n");
9165 + otg_dev->hcd = NULL;
9171 + * Enable the global interrupt after all the interrupt
9172 + * handlers are installed.
9174 + dwc_otg_enable_global_interrupts(otg_dev->core_if);
9179 + dwc_otg_driver_remove(pdev);
9184 + * This structure defines the methods to be called by a bus driver
9185 + * during the lifecycle of a device on that bus. Both drivers and
9186 + * devices are registered with a bus driver. The bus driver matches
9187 + * devices to drivers based on information in the device and driver
9190 + * The probe function is called when the bus driver matches a device
9191 + * to this driver. The remove function is called when a device is
9192 + * unregistered with the bus driver.
9195 +static const struct of_device_id ralink_otg_match[] = {
9196 + { .compatible = "ralink,rt3050-otg" },
9199 +MODULE_DEVICE_TABLE(of, ralink_otg_match);
9201 +static struct platform_driver dwc_otg_driver = {
9203 + .name = (char *)dwc_driver_name,
9204 + .of_match_table = ralink_otg_match,
9206 + .probe = dwc_otg_driver_probe,
9207 + .remove = dwc_otg_driver_remove,
9211 + * This function is called when the dwc_otg_driver is installed with the
9212 + * insmod command. It registers the dwc_otg_driver structure with the
9213 + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
9214 + * to be called. In addition, the bus driver will automatically expose
9215 + * attributes defined for the device and driver in the special sysfs file
9220 +static int __init dwc_otg_driver_init(void)
9225 + printk(KERN_INFO "%s: version %s\n", dwc_driver_name, DWC_DRIVER_VERSION);
9227 + retval = platform_driver_register(&dwc_otg_driver);
9229 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
9233 + error = driver_create_file(&dwc_otg_driver.driver, &driver_attr_version);
9234 + error = driver_create_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
9238 +module_init(dwc_otg_driver_init);
9241 + * This function is called when the driver is removed from the kernel
9242 + * with the rmmod command. The driver unregisters itself with its bus
9246 +static void __exit dwc_otg_driver_cleanup(void)
9248 + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
9250 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
9251 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
9253 + platform_driver_unregister(&dwc_otg_driver);
9255 + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
9257 +module_exit(dwc_otg_driver_cleanup);
9259 +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
9260 +MODULE_AUTHOR("Synopsys Inc.");
9261 +MODULE_LICENSE("GPL");
9263 +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
9264 +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
9265 +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
9266 +MODULE_PARM_DESC(opt, "OPT Mode");
9267 +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
9268 +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
9270 +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int, 0444);
9271 +MODULE_PARM_DESC(dma_desc_enable, "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
9273 +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int, 0444);
9274 +MODULE_PARM_DESC(dma_burst_size, "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
9275 +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
9276 +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
9277 +module_param_named(host_support_fs_ls_low_power, dwc_otg_module_params.host_support_fs_ls_low_power, int, 0444);
9278 +MODULE_PARM_DESC(host_support_fs_ls_low_power, "Support Low Power w/FS or LS 0=Support 1=Don't Support");
9279 +module_param_named(host_ls_low_power_phy_clk, dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
9280 +MODULE_PARM_DESC(host_ls_low_power_phy_clk, "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
9281 +module_param_named(enable_dynamic_fifo, dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
9282 +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
9283 +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int, 0444);
9284 +MODULE_PARM_DESC(data_fifo_size, "Total number of words in the data FIFO memory 32-32768");
9285 +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size, int, 0444);
9286 +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
9287 +module_param_named(dev_nperio_tx_fifo_size, dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
9288 +MODULE_PARM_DESC(dev_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
9289 +module_param_named(dev_perio_tx_fifo_size_1, dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
9290 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1, "Number of words in the periodic Tx FIFO 4-768");
9291 +module_param_named(dev_perio_tx_fifo_size_2, dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
9292 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2, "Number of words in the periodic Tx FIFO 4-768");
9293 +module_param_named(dev_perio_tx_fifo_size_3, dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
9294 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3, "Number of words in the periodic Tx FIFO 4-768");
9295 +module_param_named(dev_perio_tx_fifo_size_4, dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
9296 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4, "Number of words in the periodic Tx FIFO 4-768");
9297 +module_param_named(dev_perio_tx_fifo_size_5, dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
9298 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5, "Number of words in the periodic Tx FIFO 4-768");
9299 +module_param_named(dev_perio_tx_fifo_size_6, dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
9300 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6, "Number of words in the periodic Tx FIFO 4-768");
9301 +module_param_named(dev_perio_tx_fifo_size_7, dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
9302 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7, "Number of words in the periodic Tx FIFO 4-768");
9303 +module_param_named(dev_perio_tx_fifo_size_8, dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
9304 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8, "Number of words in the periodic Tx FIFO 4-768");
9305 +module_param_named(dev_perio_tx_fifo_size_9, dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
9306 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9, "Number of words in the periodic Tx FIFO 4-768");
9307 +module_param_named(dev_perio_tx_fifo_size_10, dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
9308 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10, "Number of words in the periodic Tx FIFO 4-768");
9309 +module_param_named(dev_perio_tx_fifo_size_11, dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
9310 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11, "Number of words in the periodic Tx FIFO 4-768");
9311 +module_param_named(dev_perio_tx_fifo_size_12, dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
9312 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12, "Number of words in the periodic Tx FIFO 4-768");
9313 +module_param_named(dev_perio_tx_fifo_size_13, dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
9314 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13, "Number of words in the periodic Tx FIFO 4-768");
9315 +module_param_named(dev_perio_tx_fifo_size_14, dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
9316 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14, "Number of words in the periodic Tx FIFO 4-768");
9317 +module_param_named(dev_perio_tx_fifo_size_15, dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
9318 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15, "Number of words in the periodic Tx FIFO 4-768");
9319 +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size, int, 0444);
9320 +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
9321 +module_param_named(host_nperio_tx_fifo_size, dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
9322 +MODULE_PARM_DESC(host_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
9323 +module_param_named(host_perio_tx_fifo_size, dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
9324 +MODULE_PARM_DESC(host_perio_tx_fifo_size, "Number of words in the host periodic Tx FIFO 16-32768");
9325 +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size, int, 0444);
9326 +/** @todo Set the max to 512K, modify checks */
9327 +MODULE_PARM_DESC(max_transfer_size, "The maximum transfer size supported in bytes 2047-65535");
9328 +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count, int, 0444);
9329 +MODULE_PARM_DESC(max_packet_count, "The maximum number of packets in a transfer 15-511");
9330 +module_param_named(host_channels, dwc_otg_module_params.host_channels, int, 0444);
9331 +MODULE_PARM_DESC(host_channels, "The number of host channel registers to use 1-16");
9332 +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int, 0444);
9333 +MODULE_PARM_DESC(dev_endpoints, "The number of endpoints in addition to EP0 available for device mode 1-15");
9334 +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
9335 +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
9336 +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int, 0444);
9337 +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
9338 +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
9339 +MODULE_PARM_DESC(phy_ulpi_ddr, "ULPI at double or single data rate 0=Single 1=Double");
9340 +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus, int, 0444);
9341 +MODULE_PARM_DESC(phy_ulpi_ext_vbus, "ULPI PHY using internal or external vbus 0=Internal");
9342 +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
9343 +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
9344 +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
9345 +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
9346 +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
9347 +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
9348 +module_param_named(debug, g_dbg_lvl, int, 0444);
9349 +MODULE_PARM_DESC(debug, "");
9351 +module_param_named(en_multiple_tx_fifo, dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
9352 +MODULE_PARM_DESC(en_multiple_tx_fifo, "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
9353 +module_param_named(dev_tx_fifo_size_1, dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
9354 +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
9355 +module_param_named(dev_tx_fifo_size_2, dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
9356 +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
9357 +module_param_named(dev_tx_fifo_size_3, dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
9358 +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
9359 +module_param_named(dev_tx_fifo_size_4, dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
9360 +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
9361 +module_param_named(dev_tx_fifo_size_5, dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
9362 +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
9363 +module_param_named(dev_tx_fifo_size_6, dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
9364 +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
9365 +module_param_named(dev_tx_fifo_size_7, dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
9366 +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
9367 +module_param_named(dev_tx_fifo_size_8, dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
9368 +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
9369 +module_param_named(dev_tx_fifo_size_9, dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
9370 +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
9371 +module_param_named(dev_tx_fifo_size_10, dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
9372 +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
9373 +module_param_named(dev_tx_fifo_size_11, dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
9374 +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
9375 +module_param_named(dev_tx_fifo_size_12, dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
9376 +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
9377 +module_param_named(dev_tx_fifo_size_13, dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
9378 +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
9379 +module_param_named(dev_tx_fifo_size_14, dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
9380 +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
9381 +module_param_named(dev_tx_fifo_size_15, dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
9382 +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
9384 +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
9385 +MODULE_PARM_DESC(thr_ctl, "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
9386 +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int, 0444);
9387 +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
9388 +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int, 0444);
9389 +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
9391 +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
9392 +MODULE_PARM_DESC(pti_enable, "Per Transfer Interrupt mode 0=disabled 1=enabled");
9394 +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
9395 +MODULE_PARM_DESC(mpi_enable, "Multiprocessor Interrupt mode 0=disabled 1=enabled");
9397 +/** @page "Module Parameters"
9399 + * The following parameters may be specified when starting the module.
9400 + * These parameters define how the DWC_otg controller should be
9401 + * configured. Parameter values are passed to the CIL initialization
9402 + * function dwc_otg_cil_init
9404 + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
9408 + <tr><td>Parameter Name</td><td>Meaning</td></tr>
9412 + <td>Specifies the OTG capabilities. The driver will automatically detect the
9413 + value for this parameter if none is specified.
9414 + - 0: HNP and SRP capable (default, if available)
9415 + - 1: SRP Only capable
9416 + - 2: No HNP/SRP capable
9420 + <td>dma_enable</td>
9421 + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
9422 + The driver will automatically detect the value for this parameter if none is
9425 + - 1: DMA (default, if available)
9429 + <td>dma_burst_size</td>
9430 + <td>The DMA Burst size (applicable only for External DMA Mode).
9431 + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
9436 + <td>Specifies the maximum speed of operation in host and device mode. The
9437 + actual speed depends on the speed of the attached device and the value of
9439 + - 0: High Speed (default)
9444 + <td>host_support_fs_ls_low_power</td>
9445 + <td>Specifies whether low power mode is supported when attached to a Full
9446 + Speed or Low Speed device in host mode.
9447 + - 0: Don't support low power mode (default)
9448 + - 1: Support low power mode
9452 + <td>host_ls_low_power_phy_clk</td>
9453 + <td>Specifies the PHY clock rate in low power mode when connected to a Low
9454 + Speed device in host mode. This parameter is applicable only if
9455 + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
9456 + - 0: 48 MHz (default)
9461 + <td>enable_dynamic_fifo</td>
9462 + <td> Specifies whether FIFOs may be resized by the driver software.
9463 + - 0: Use cC FIFO size parameters
9464 + - 1: Allow dynamic FIFO sizing (default)
9468 + <td>data_fifo_size</td>
9469 + <td>Total number of 4-byte words in the data FIFO memory. This memory
9470 + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
9471 + - Values: 32 to 32768 (default 8192)
9473 + Note: The total FIFO memory depth in the FPGA configuration is 8192.
9477 + <td>dev_rx_fifo_size</td>
9478 + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
9479 + FIFO sizing is enabled.
9480 + - Values: 16 to 32768 (default 1064)
9484 + <td>dev_nperio_tx_fifo_size</td>
9485 + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
9486 + dynamic FIFO sizing is enabled.
9487 + - Values: 16 to 32768 (default 1024)
9491 + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
9492 + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
9493 + when dynamic FIFO sizing is enabled.
9494 + - Values: 4 to 768 (default 256)
9498 + <td>host_rx_fifo_size</td>
9499 + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
9500 + sizing is enabled.
9501 + - Values: 16 to 32768 (default 1024)
9505 + <td>host_nperio_tx_fifo_size</td>
9506 + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
9507 + dynamic FIFO sizing is enabled in the core.
9508 + - Values: 16 to 32768 (default 1024)
9512 + <td>host_perio_tx_fifo_size</td>
9513 + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
9514 + sizing is enabled.
9515 + - Values: 16 to 32768 (default 1024)
9519 + <td>max_transfer_size</td>
9520 + <td>The maximum transfer size supported in bytes.
9521 + - Values: 2047 to 65,535 (default 65,535)
9525 + <td>max_packet_count</td>
9526 + <td>The maximum number of packets in a transfer.
9527 + - Values: 15 to 511 (default 511)
9531 + <td>host_channels</td>
9532 + <td>The number of host channel registers to use.
9533 + - Values: 1 to 16 (default 12)
9535 + Note: The FPGA configuration supports a maximum of 12 host channels.
9539 + <td>dev_endpoints</td>
9540 + <td>The number of endpoints in addition to EP0 available for device mode
9542 + - Values: 1 to 15 (default 6 IN and OUT)
9544 + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
9550 + <td>Specifies the type of PHY interface to use. By default, the driver will
9551 + automatically detect the phy_type.
9553 + - 1: UTMI+ (default, if available)
9558 + <td>phy_utmi_width</td>
9559 + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
9560 + phy_type of UTMI+. Also, this parameter is applicable only if the
9561 + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
9562 + core has been configured to work at either data path width.
9563 + - Values: 8 or 16 bits (default 16)
9567 + <td>phy_ulpi_ddr</td>
9568 + <td>Specifies whether the ULPI operates at double or single data rate. This
9569 + parameter is only applicable if phy_type is ULPI.
9570 + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
9571 + - 1: double data rate ULPI interface with 4 bit wide data bus
9575 + <td>i2c_enable</td>
9576 + <td>Specifies whether to use the I2C interface for full speed PHY. This
9577 + parameter is only applicable if PHY_TYPE is FS.
9578 + - 0: Disabled (default)
9583 + <td>otg_en_multiple_tx_fifo</td>
9584 + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
9585 + The driver will automatically detect the value for this parameter if none is
9588 + - 1: Enabled (default, if available)
9592 + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
9593 + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
9594 + when dynamic FIFO sizing is enabled.
9595 + - Values: 4 to 768 (default 256)
9599 diff --git a/drivers/usb/dwc_otg/dwc_otg_driver.h b/drivers/usb/dwc_otg/dwc_otg_driver.h
9600 new file mode 100644
9601 index 0000000..fd7f0a4
9603 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.h
9605 +/* ==========================================================================
9606 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
9607 + * $Revision: 1.2 $
9608 + * $Date: 2008-11-21 05:39:15 $
9609 + * $Change: 1064918 $
9611 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
9612 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9613 + * otherwise expressly agreed to in writing between Synopsys and you.
9615 + * The Software IS NOT an item of Licensed Software or Licensed Product under
9616 + * any End User Software License Agreement or Agreement for Licensed Product
9617 + * with Synopsys or any supplement thereto. You are permitted to use and
9618 + * redistribute this Software in source and binary forms, with or without
9619 + * modification, provided that redistributions of source code must retain this
9620 + * notice. You may not view, use, disclose, copy or distribute this file or
9621 + * any information contained herein except pursuant to this license grant from
9622 + * Synopsys. If you do not agree with this notice, including the disclaimer
9623 + * below, then you are not authorized to use the Software.
9625 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
9626 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9627 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9628 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
9629 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9630 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
9631 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
9632 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9633 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9634 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
9636 + * ========================================================================== */
9638 +#ifndef __DWC_OTG_DRIVER_H__
9639 +#define __DWC_OTG_DRIVER_H__
9642 + * This file contains the interface to the Linux driver.
9644 +#include "dwc_otg_cil.h"
9646 +/* Type declarations */
9647 +struct dwc_otg_pcd;
9648 +struct dwc_otg_hcd;
9651 + * This structure is a wrapper that encapsulates the driver components used to
9652 + * manage a single DWC_otg controller.
9654 +typedef struct dwc_otg_device {
9655 + /** Base address returned from ioremap() */
9658 + struct device *parent;
9660 + /** Pointer to the core interface structure. */
9661 + dwc_otg_core_if_t *core_if;
9663 + /** Register offset for Diagnostic API. */
9664 + uint32_t reg_offset;
9666 + /** Pointer to the PCD structure. */
9667 + struct dwc_otg_pcd *pcd;
9669 + /** Pointer to the HCD structure. */
9670 + struct dwc_otg_hcd *hcd;
9672 + /** Flag to indicate whether the common IRQ handler is installed. */
9673 + uint8_t common_irq_installed;
9675 + /* Interrupt request number. */
9678 + /* Physical address of Control and Status registers, used by
9679 + * release_mem_region().
9681 + resource_size_t phys_addr;
9683 + /* Length of memory region, used by release_mem_region(). */
9684 + unsigned long base_len;
9685 +} dwc_otg_device_t;
9688 diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd.c b/drivers/usb/dwc_otg/dwc_otg_hcd.c
9689 new file mode 100644
9690 index 0000000..fe643b6
9692 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.c
9694 +/* ==========================================================================
9695 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
9696 + * $Revision: 1.4 $
9697 + * $Date: 2008-11-21 05:39:15 $
9698 + * $Change: 1064940 $
9700 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
9701 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9702 + * otherwise expressly agreed to in writing between Synopsys and you.
9704 + * The Software IS NOT an item of Licensed Software or Licensed Product under
9705 + * any End User Software License Agreement or Agreement for Licensed Product
9706 + * with Synopsys or any supplement thereto. You are permitted to use and
9707 + * redistribute this Software in source and binary forms, with or without
9708 + * modification, provided that redistributions of source code must retain this
9709 + * notice. You may not view, use, disclose, copy or distribute this file or
9710 + * any information contained herein except pursuant to this license grant from
9711 + * Synopsys. If you do not agree with this notice, including the disclaimer
9712 + * below, then you are not authorized to use the Software.
9714 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
9715 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9716 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9717 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
9718 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9719 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
9720 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
9721 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9722 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9723 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
9725 + * ========================================================================== */
9726 +#ifndef DWC_DEVICE_ONLY
9731 + * This file contains the implementation of the HCD. In Linux, the HCD
9732 + * implements the hc_driver API.
9734 +#include <linux/kernel.h>
9735 +#include <linux/module.h>
9736 +#include <linux/moduleparam.h>
9737 +#include <linux/init.h>
9738 +#include <linux/device.h>
9739 +#include <linux/errno.h>
9740 +#include <linux/list.h>
9741 +#include <linux/interrupt.h>
9742 +#include <linux/string.h>
9743 +#include <linux/dma-mapping.h>
9744 +#include <linux/version.h>
9746 +#include "dwc_otg_driver.h"
9747 +#include "dwc_otg_hcd.h"
9748 +#include "dwc_otg_regs.h"
9750 +static const char dwc_otg_hcd_name[] = "dwc_otg";
9752 +static const struct hc_driver dwc_otg_hc_driver = {
9754 + .description = dwc_otg_hcd_name,
9755 + .product_desc = "DWC OTG Controller",
9756 + .hcd_priv_size = sizeof(dwc_otg_hcd_t),
9758 + .irq = dwc_otg_hcd_irq,
9760 + .flags = HCD_MEMORY | HCD_USB2,
9763 + .start = dwc_otg_hcd_start,
9766 + .stop = dwc_otg_hcd_stop,
9768 + .urb_enqueue = dwc_otg_hcd_urb_enqueue,
9769 + .urb_dequeue = dwc_otg_hcd_urb_dequeue,
9770 + .endpoint_disable = dwc_otg_hcd_endpoint_disable,
9772 + .get_frame_number = dwc_otg_hcd_get_frame_number,
9774 + .hub_status_data = dwc_otg_hcd_hub_status_data,
9775 + .hub_control = dwc_otg_hcd_hub_control,
9781 + * Work queue function for starting the HCD when A-Cable is connected.
9782 + * The dwc_otg_hcd_start() must be called in a process context.
9784 +static void hcd_start_func(
9785 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
9788 + struct work_struct *_work
9792 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
9793 + struct usb_hcd *usb_hcd = (struct usb_hcd *)_vp;
9795 + struct delayed_work *dw = container_of(_work, struct delayed_work, work);
9796 + struct dwc_otg_hcd *otg_hcd = container_of(dw, struct dwc_otg_hcd, start_work);
9797 + struct usb_hcd *usb_hcd = container_of((void *)otg_hcd, struct usb_hcd, hcd_priv);
9799 + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, usb_hcd);
9801 + dwc_otg_hcd_start(usb_hcd);
9806 + * HCD Callback function for starting the HCD when A-Cable is
9809 + * @param p void pointer to the <code>struct usb_hcd</code>
9811 +static int32_t dwc_otg_hcd_start_cb(void *p)
9813 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(p);
9814 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
9815 + hprt0_data_t hprt0;
9817 + if (core_if->op_state == B_HOST) {
9819 + * Reset the port. During a HNP mode switch the reset
9820 + * needs to occur within 1ms and have a duration of at
9823 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
9824 + hprt0.b.prtrst = 1;
9825 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
9826 + ((struct usb_hcd *)p)->self.is_b_host = 1;
9828 + ((struct usb_hcd *)p)->self.is_b_host = 0;
9831 + /* Need to start the HCD in a non-interrupt context. */
9832 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
9833 + INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func, p);
9834 +// INIT_DELAYED_WORK(&dwc_otg_hcd->start_work, hcd_start_func, p);
9836 +// INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
9837 + INIT_DELAYED_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
9839 +// schedule_work(&dwc_otg_hcd->start_work);
9840 + queue_delayed_work(core_if->wq_otg, &dwc_otg_hcd->start_work, 50 * HZ / 1000);
9846 + * HCD Callback function for stopping the HCD.
9848 + * @param p void pointer to the <code>struct usb_hcd</code>
9850 +static int32_t dwc_otg_hcd_stop_cb(void *p)
9852 + struct usb_hcd *usb_hcd = (struct usb_hcd *)p;
9853 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
9854 + dwc_otg_hcd_stop(usb_hcd);
9858 +static void del_xfer_timers(dwc_otg_hcd_t *hcd)
9862 + int num_channels = hcd->core_if->core_params->host_channels;
9863 + for (i = 0; i < num_channels; i++) {
9864 + del_timer(&hcd->core_if->hc_xfer_timer[i]);
9869 +static void del_timers(dwc_otg_hcd_t *hcd)
9871 + del_xfer_timers(hcd);
9872 + del_timer(&hcd->conn_timer);
9876 + * Processes all the URBs in a single list of QHs. Completes them with
9877 + * -ETIMEDOUT and frees the QTD.
9879 +static void kill_urbs_in_qh_list(dwc_otg_hcd_t *hcd, struct list_head *qh_list)
9881 + struct list_head *qh_item;
9883 + struct list_head *qtd_item;
9884 + dwc_otg_qtd_t *qtd;
9886 + list_for_each(qh_item, qh_list) {
9887 + qh = list_entry(qh_item, dwc_otg_qh_t, qh_list_entry);
9888 + for (qtd_item = qh->qtd_list.next;
9889 + qtd_item != &qh->qtd_list;
9890 + qtd_item = qh->qtd_list.next) {
9891 + qtd = list_entry(qtd_item, dwc_otg_qtd_t, qtd_list_entry);
9892 + if (qtd->urb != NULL) {
9893 + dwc_otg_hcd_complete_urb(hcd, qtd->urb,
9896 + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd);
9902 + * Responds with an error status of ETIMEDOUT to all URBs in the non-periodic
9903 + * and periodic schedules. The QTD associated with each URB is removed from
9904 + * the schedule and freed. This function may be called when a disconnect is
9905 + * detected or when the HCD is being stopped.
9907 +static void kill_all_urbs(dwc_otg_hcd_t *hcd)
9909 + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
9910 + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
9911 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
9912 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
9913 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
9914 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
9918 + * HCD Callback function for disconnect of the HCD.
9920 + * @param p void pointer to the <code>struct usb_hcd</code>
9922 +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
9924 + gintsts_data_t intr;
9925 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(p);
9927 + //DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
9930 + * Set status flags for the hub driver.
9932 + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
9933 + dwc_otg_hcd->flags.b.port_connect_status = 0;
9936 + * Shutdown any transfers in process by clearing the Tx FIFO Empty
9937 + * interrupt mask and status bits and disabling subsequent host
9938 + * channel interrupts.
9941 + intr.b.nptxfempty = 1;
9942 + intr.b.ptxfempty = 1;
9943 + intr.b.hcintr = 1;
9944 + dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, intr.d32, 0);
9945 + dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintsts, intr.d32, 0);
9947 + del_timers(dwc_otg_hcd);
9950 + * Turn off the vbus power only if the core has transitioned to device
9951 + * mode. If still in host mode, need to keep power on to detect a
9954 + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
9955 + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
9956 + hprt0_data_t hprt0 = { .d32=0 };
9957 + DWC_PRINT("Disconnect: PortPower off\n");
9958 + hprt0.b.prtpwr = 0;
9959 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
9962 + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
9965 + /* Respond with an error status to all URBs in the schedule. */
9966 + kill_all_urbs(dwc_otg_hcd);
9968 + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
9969 + /* Clean up any host channels that were in use. */
9972 + dwc_hc_t *channel;
9973 + dwc_otg_hc_regs_t *hc_regs;
9974 + hcchar_data_t hcchar;
9976 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
9978 + if (!dwc_otg_hcd->core_if->dma_enable) {
9979 + /* Flush out any channel requests in slave mode. */
9980 + for (i = 0; i < num_channels; i++) {
9981 + channel = dwc_otg_hcd->hc_ptr_array[i];
9982 + if (list_empty(&channel->hc_list_entry)) {
9983 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
9984 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
9985 + if (hcchar.b.chen) {
9986 + hcchar.b.chen = 0;
9987 + hcchar.b.chdis = 1;
9988 + hcchar.b.epdir = 0;
9989 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
9995 + for (i = 0; i < num_channels; i++) {
9996 + channel = dwc_otg_hcd->hc_ptr_array[i];
9997 + if (list_empty(&channel->hc_list_entry)) {
9998 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
9999 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10000 + if (hcchar.b.chen) {
10001 + /* Halt the channel. */
10002 + hcchar.b.chdis = 1;
10003 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
10006 + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if, channel);
10007 + list_add_tail(&channel->hc_list_entry,
10008 + &dwc_otg_hcd->free_hc_list);
10013 + /* A disconnect will end the session so the B-Device is no
10014 + * longer a B-host. */
10015 + ((struct usb_hcd *)p)->self.is_b_host = 0;
10020 + * Connection timeout function. An OTG host is required to display a
10021 + * message if the device does not connect within 10 seconds.
10023 +void dwc_otg_hcd_connect_timeout(unsigned long ptr)
10025 + DWC_DEBUGPL(DBG_HCDV, "%s(%x)\n", __func__, (int)ptr);
10026 + DWC_PRINT("Connect Timeout\n");
10027 + DWC_ERROR("Device Not Connected/Responding\n");
10031 + * Start the connection timer. An OTG host is required to display a
10032 + * message if the device does not connect within 10 seconds. The
10033 + * timer is deleted if a port connect interrupt occurs before the
10036 +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t *hcd)
10038 + init_timer(&hcd->conn_timer);
10039 + hcd->conn_timer.function = dwc_otg_hcd_connect_timeout;
10040 + hcd->conn_timer.data = 0;
10041 + hcd->conn_timer.expires = jiffies + (HZ * 10);
10042 + add_timer(&hcd->conn_timer);
10046 + * HCD Callback function for disconnect of the HCD.
10048 + * @param p void pointer to the <code>struct usb_hcd</code>
10050 +static int32_t dwc_otg_hcd_session_start_cb(void *p)
10052 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(p);
10053 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
10054 + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
10059 + * HCD Callback structure for handling mode switching.
10061 +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
10062 + .start = dwc_otg_hcd_start_cb,
10063 + .stop = dwc_otg_hcd_stop_cb,
10064 + .disconnect = dwc_otg_hcd_disconnect_cb,
10065 + .session_start = dwc_otg_hcd_session_start_cb,
10070 + * Reset tasklet function
10072 +static void reset_tasklet_func(unsigned long data)
10074 + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *)data;
10075 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
10076 + hprt0_data_t hprt0;
10078 + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
10080 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
10081 + hprt0.b.prtrst = 1;
10082 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
10085 + hprt0.b.prtrst = 0;
10086 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
10087 + dwc_otg_hcd->flags.b.port_reset_change = 1;
10090 +static struct tasklet_struct reset_tasklet = {
10093 + .count = ATOMIC_INIT(0),
10094 + .func = reset_tasklet_func,
10099 + * Initializes the HCD. This function allocates memory for and initializes the
10100 + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
10101 + * USB bus with the core and calls the hc_driver->start() function. It returns
10102 + * a negative error on failure.
10104 +int dwc_otg_hcd_init(struct device *dev)
10106 + dwc_otg_device_t *otg_dev = dev_get_drvdata(dev);
10107 + struct usb_hcd *hcd = NULL;
10108 + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
10110 + int num_channels;
10112 + dwc_hc_t *channel;
10116 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
10118 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
10119 + /* 2.6.20+ requires dev.dma_mask to be set prior to calling usb_create_hcd() */
10121 + /* Set device flags indicating whether the HCD supports DMA. */
10122 + if (otg_dev->core_if->dma_enable) {
10123 + DWC_PRINT("Using DMA mode\n");
10124 + dev->dma_mask = (void *)~0;
10125 + dev->coherent_dma_mask = ~0;
10127 + if (otg_dev->core_if->dma_desc_enable) {
10128 + DWC_PRINT("Device using Descriptor DMA mode\n");
10130 + DWC_PRINT("Device using Buffer DMA mode\n");
10133 + DWC_PRINT("Using Slave mode\n");
10134 + dev->dma_mask = (void *)0;
10135 + dev->coherent_dma_mask = 0;
10139 + * Allocate memory for the base HCD plus the DWC OTG HCD.
10140 + * Initialize the base HCD.
10142 + hcd = usb_create_hcd(&dwc_otg_hc_driver, dev, dev_name(dev));
10144 + retval = -ENOMEM;
10148 + dev_set_drvdata(dev, otg_dev);
10149 + hcd->regs = otg_dev->base;
10150 + hcd->rsrc_start = otg_dev->phys_addr;
10151 + hcd->rsrc_len = otg_dev->base_len;
10152 + hcd->self.otg_port = 1;
10155 + /* Initialize the DWC OTG HCD. */
10156 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10157 + dwc_otg_hcd->core_if = otg_dev->core_if;
10158 + otg_dev->hcd = dwc_otg_hcd;
10161 + spin_lock_init(&dwc_otg_hcd->lock);
10163 + /* Register the HCD CIL Callbacks */
10164 + dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
10165 + &hcd_cil_callbacks, hcd);
10167 + /* Initialize the non-periodic schedule. */
10168 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
10169 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
10171 + /* Initialize the periodic schedule. */
10172 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
10173 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
10174 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
10175 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
10178 + * Create a host channel descriptor for each host channel implemented
10179 + * in the controller. Initialize the channel descriptor array.
10181 + INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
10182 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
10183 + memset(dwc_otg_hcd->hc_ptr_array, 0, sizeof(dwc_otg_hcd->hc_ptr_array));
10184 + for (i = 0; i < num_channels; i++) {
10185 + channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
10186 + if (channel == NULL) {
10187 + retval = -ENOMEM;
10188 + DWC_ERROR("%s: host channel allocation failed\n", __func__);
10191 + memset(channel, 0, sizeof(dwc_hc_t));
10192 + channel->hc_num = i;
10193 + dwc_otg_hcd->hc_ptr_array[i] = channel;
10195 + init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
10197 + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
10200 + /* Initialize the Connection timeout timer. */
10201 + init_timer(&dwc_otg_hcd->conn_timer);
10203 + /* Initialize reset tasklet. */
10204 + reset_tasklet.data = (unsigned long) dwc_otg_hcd;
10205 + dwc_otg_hcd->reset_tasklet = &reset_tasklet;
10207 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10208 + /* Set device flags indicating whether the HCD supports DMA. */
10209 + if (otg_dev->core_if->dma_enable) {
10210 + DWC_PRINT("Using DMA mode\n");
10211 + dev->dma_mask = (void *)~0;
10212 + dev->coherent_dma_mask = ~0;
10214 + if (otg_dev->core_if->dma_desc_enable){
10215 + DWC_PRINT("Device using Descriptor DMA mode\n");
10217 + DWC_PRINT("Device using Buffer DMA mode\n");
10220 + DWC_PRINT("Using Slave mode\n");
10221 + dev->dma_mask = (void *)0;
10222 + dev->dev.coherent_dma_mask = 0;
10226 + * Finish generic HCD initialization and start the HCD. This function
10227 + * allocates the DMA buffer pool, registers the USB bus, requests the
10228 + * IRQ line, and calls dwc_otg_hcd_start method.
10230 + retval = usb_add_hcd(hcd, otg_dev->irq, IRQF_SHARED);
10231 + if (retval < 0) {
10236 + * Allocate space for storing data on status transactions. Normally no
10237 + * data is sent, but this space acts as a bit bucket. This must be
10238 + * done after usb_add_hcd since that function allocates the DMA buffer
10241 + if (otg_dev->core_if->dma_enable) {
10242 + dwc_otg_hcd->status_buf =
10243 + dma_alloc_coherent(dev,
10244 + DWC_OTG_HCD_STATUS_BUF_SIZE,
10245 + &dwc_otg_hcd->status_buf_dma,
10246 + GFP_KERNEL | GFP_DMA);
10248 + dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
10251 + if (!dwc_otg_hcd->status_buf) {
10252 + retval = -ENOMEM;
10253 + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
10257 + dwc_otg_hcd->otg_dev = otg_dev;
10259 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
10260 + dev_name(dev), hcd->self.busnum);
10264 + /* Error conditions */
10266 + usb_remove_hcd(hcd);
10268 + dwc_otg_hcd_free(hcd);
10269 + usb_put_hcd(hcd);
10271 + /* FIXME: 2008/05/03 by Steven
10272 + * write back to device:
10273 + * dwc_otg_hcd has already been released by dwc_otg_hcd_free()
10275 + dev_set_drvdata(dev, otg_dev);
10282 + * Removes the HCD.
10283 + * Frees memory and resources associated with the HCD and deregisters the bus.
10285 +void dwc_otg_hcd_remove(struct device *dev)
10287 + dwc_otg_device_t *otg_dev = dev_get_drvdata(dev);
10288 + dwc_otg_hcd_t *dwc_otg_hcd;
10289 + struct usb_hcd *hcd;
10291 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE\n");
10294 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
10298 + dwc_otg_hcd = otg_dev->hcd;
10300 + if (!dwc_otg_hcd) {
10301 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
10305 + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
10308 + DWC_DEBUGPL(DBG_ANY, "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n", __func__);
10312 + /* Turn off all interrupts */
10313 + dwc_write_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0);
10314 + dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gahbcfg, 1, 0);
10316 + usb_remove_hcd(hcd);
10317 + dwc_otg_hcd_free(hcd);
10318 + usb_put_hcd(hcd);
10321 +/* =========================================================================
10322 + * Linux HC Driver Functions
10323 + * ========================================================================= */
10326 + * Initializes dynamic portions of the DWC_otg HCD state.
10328 +static void hcd_reinit(dwc_otg_hcd_t *hcd)
10330 + struct list_head *item;
10331 + int num_channels;
10333 + dwc_hc_t *channel;
10335 + hcd->flags.d32 = 0;
10337 + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
10338 + hcd->non_periodic_channels = 0;
10339 + hcd->periodic_channels = 0;
10342 + * Put all channels in the free channel list and clean up channel
10345 + item = hcd->free_hc_list.next;
10346 + while (item != &hcd->free_hc_list) {
10348 + item = hcd->free_hc_list.next;
10350 + num_channels = hcd->core_if->core_params->host_channels;
10351 + for (i = 0; i < num_channels; i++) {
10352 + channel = hcd->hc_ptr_array[i];
10353 + list_add_tail(&channel->hc_list_entry, &hcd->free_hc_list);
10354 + dwc_otg_hc_cleanup(hcd->core_if, channel);
10357 + /* Initialize the DWC core for host mode operation. */
10358 + dwc_otg_core_host_init(hcd->core_if);
10361 +/** Initializes the DWC_otg controller and its root hub and prepares it for host
10362 + * mode operation. Activates the root port. Returns 0 on success and a negative
10363 + * error code on failure. */
10364 +int dwc_otg_hcd_start(struct usb_hcd *hcd)
10366 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10367 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
10368 + struct usb_bus *bus;
10370 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10371 + struct usb_device *udev;
10375 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
10377 + bus = hcd_to_bus(hcd);
10379 + /* Initialize the bus state. If the core is in Device Mode
10380 + * HALT the USB bus and return. */
10381 + if (dwc_otg_is_device_mode(core_if)) {
10382 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10383 + hcd->state = HC_STATE_HALT;
10385 + hcd->state = HC_STATE_RUNNING;
10389 + hcd->state = HC_STATE_RUNNING;
10391 + /* Initialize and connect root hub if one is not already attached */
10392 + if (bus->root_hub) {
10393 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
10394 + /* Inform the HUB driver to resume. */
10395 + usb_hcd_resume_root_hub(hcd);
10398 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Does Not Have Root Hub\n");
10400 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10401 + udev = usb_alloc_dev(NULL, bus, 0);
10402 + udev->speed = USB_SPEED_HIGH;
10404 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
10407 + if ((retval = usb_hcd_register_root_hub(udev, hcd)) != 0) {
10408 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error registering %d\n", retval);
10414 + hcd_reinit(dwc_otg_hcd);
10419 +static void qh_list_free(dwc_otg_hcd_t *hcd, struct list_head *qh_list)
10421 + struct list_head *item;
10422 + dwc_otg_qh_t *qh;
10424 + if (!qh_list->next) {
10425 + /* The list hasn't been initialized yet. */
10429 + /* Ensure there are no QTDs or URBs left. */
10430 + kill_urbs_in_qh_list(hcd, qh_list);
10432 + for (item = qh_list->next; item != qh_list; item = qh_list->next) {
10433 + qh = list_entry(item, dwc_otg_qh_t, qh_list_entry);
10434 + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
10439 + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
10442 +void dwc_otg_hcd_stop(struct usb_hcd *hcd)
10444 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10445 + hprt0_data_t hprt0 = { .d32=0 };
10447 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
10449 + /* Turn off all host-specific interrupts. */
10450 + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
10453 + * The root hub should be disconnected before this function is called.
10454 + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
10455 + * and the QH lists (via ..._hcd_endpoint_disable).
10458 + /* Turn off the vbus power */
10459 + DWC_PRINT("PortPower off\n");
10460 + hprt0.b.prtpwr = 0;
10461 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
10464 +/** Returns the current frame number. */
10465 +int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd)
10467 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10468 + hfnum_data_t hfnum;
10470 + hfnum.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->
10471 + host_if->host_global_regs->hfnum);
10474 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n", hfnum.b.frnum);
10476 + return hfnum.b.frnum;
10480 + * Frees secondary storage associated with the dwc_otg_hcd structure contained
10481 + * in the struct usb_hcd field.
10483 +void dwc_otg_hcd_free(struct usb_hcd *hcd)
10485 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10488 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
10490 + del_timers(dwc_otg_hcd);
10492 + /* Free memory for QH/QTD lists */
10493 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
10494 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
10495 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
10496 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
10497 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
10498 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
10500 + /* Free memory for the host channels. */
10501 + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
10502 + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
10503 + if (hc != NULL) {
10504 + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n", i, hc);
10509 + if (dwc_otg_hcd->core_if->dma_enable) {
10510 + if (dwc_otg_hcd->status_buf_dma) {
10511 + dma_free_coherent(hcd->self.controller,
10512 + DWC_OTG_HCD_STATUS_BUF_SIZE,
10513 + dwc_otg_hcd->status_buf,
10514 + dwc_otg_hcd->status_buf_dma);
10516 + } else if (dwc_otg_hcd->status_buf != NULL) {
10517 + kfree(dwc_otg_hcd->status_buf);
10522 +static void dump_urb_info(struct urb *urb, char* fn_name)
10524 + DWC_PRINT("%s, urb %p\n", fn_name, urb);
10525 + DWC_PRINT(" Device address: %d\n", usb_pipedevice(urb->pipe));
10526 + DWC_PRINT(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
10527 + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
10528 + DWC_PRINT(" Endpoint type: %s\n",
10529 + ({char *pipetype;
10530 + switch (usb_pipetype(urb->pipe)) {
10531 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
10532 + case PIPE_BULK: pipetype = "BULK"; break;
10533 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
10534 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
10535 + default: pipetype = "UNKNOWN"; break;
10537 + DWC_PRINT(" Speed: %s\n",
10539 + switch (urb->dev->speed) {
10540 + case USB_SPEED_HIGH: speed = "HIGH"; break;
10541 + case USB_SPEED_FULL: speed = "FULL"; break;
10542 + case USB_SPEED_LOW: speed = "LOW"; break;
10543 + default: speed = "UNKNOWN"; break;
10545 + DWC_PRINT(" Max packet size: %d\n",
10546 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
10547 + DWC_PRINT(" Data buffer length: %d\n", urb->transfer_buffer_length);
10548 + DWC_PRINT(" Transfer buffer: %p, Transfer DMA: %p\n",
10549 + urb->transfer_buffer, (void *)urb->transfer_dma);
10550 + DWC_PRINT(" Setup buffer: %p, Setup DMA: %p\n",
10551 + urb->setup_packet, (void *)urb->setup_dma);
10552 + DWC_PRINT(" Interval: %d\n", urb->interval);
10553 + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
10555 + for (i = 0; i < urb->number_of_packets; i++) {
10556 + DWC_PRINT(" ISO Desc %d:\n", i);
10557 + DWC_PRINT(" offset: %d, length %d\n",
10558 + urb->iso_frame_desc[i].offset,
10559 + urb->iso_frame_desc[i].length);
10564 +static void dump_channel_info(dwc_otg_hcd_t *hcd,
10565 + dwc_otg_qh_t *qh)
10567 + if (qh->channel != NULL) {
10568 + dwc_hc_t *hc = qh->channel;
10569 + struct list_head *item;
10570 + dwc_otg_qh_t *qh_item;
10571 + int num_channels = hcd->core_if->core_params->host_channels;
10574 + dwc_otg_hc_regs_t *hc_regs;
10575 + hcchar_data_t hcchar;
10576 + hcsplt_data_t hcsplt;
10577 + hctsiz_data_t hctsiz;
10580 + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
10581 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10582 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
10583 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
10584 + hcdma = dwc_read_reg32(&hc_regs->hcdma);
10586 + DWC_PRINT(" Assigned to channel %p:\n", hc);
10587 + DWC_PRINT(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
10588 + DWC_PRINT(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
10589 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
10590 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
10591 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
10592 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
10593 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
10594 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
10595 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
10596 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
10597 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
10598 + DWC_PRINT(" qh: %p\n", hc->qh);
10599 + DWC_PRINT(" NP inactive sched:\n");
10600 + list_for_each(item, &hcd->non_periodic_sched_inactive) {
10601 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
10602 + DWC_PRINT(" %p\n", qh_item);
10604 + DWC_PRINT(" NP active sched:\n");
10605 + list_for_each(item, &hcd->non_periodic_sched_active) {
10606 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
10607 + DWC_PRINT(" %p\n", qh_item);
10609 + DWC_PRINT(" Channels: \n");
10610 + for (i = 0; i < num_channels; i++) {
10611 + dwc_hc_t *hc = hcd->hc_ptr_array[i];
10612 + DWC_PRINT(" %2d: %p\n", i, hc);
10618 +/** Starts processing a USB transfer request specified by a USB Request Block
10619 + * (URB). mem_flags indicates the type of memory allocation to use while
10620 + * processing this URB. */
10621 +int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
10623 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10631 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10632 + dwc_otg_qtd_t *qtd;
10635 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
10636 + dump_urb_info(urb, "dwc_otg_hcd_urb_enqueue");
10639 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
10640 + /* No longer connected. */
10644 + qtd = dwc_otg_hcd_qtd_create(urb);
10645 + if (qtd == NULL) {
10646 + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
10650 + retval = dwc_otg_hcd_qtd_add(qtd, dwc_otg_hcd);
10651 + if (retval < 0) {
10652 + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
10653 + "Error status %d\n", retval);
10654 + dwc_otg_hcd_qtd_free(qtd);
10660 +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
10662 +int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
10666 + unsigned long flags;
10667 + dwc_otg_hcd_t *dwc_otg_hcd;
10668 + dwc_otg_qtd_t *urb_qtd;
10669 + dwc_otg_qh_t *qh;
10670 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
10671 + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
10674 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
10676 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10678 + SPIN_LOCK_IRQSAVE(&dwc_otg_hcd->lock, flags);
10680 + urb_qtd = (dwc_otg_qtd_t *)urb->hcpriv;
10681 + qh = (dwc_otg_qh_t *)ep->hcpriv;
10684 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
10685 + dump_urb_info(urb, "dwc_otg_hcd_urb_dequeue");
10686 + if (urb_qtd == qh->qtd_in_process) {
10687 + dump_channel_info(dwc_otg_hcd, qh);
10692 + if (urb_qtd == qh->qtd_in_process) {
10693 + /* The QTD is in process (it has been assigned to a channel). */
10695 + if (dwc_otg_hcd->flags.b.port_connect_status) {
10697 + * If still connected (i.e. in host mode), halt the
10698 + * channel so it can be used for other transfers. If
10699 + * no longer connected, the host registers can't be
10700 + * written to halt the channel since the core is in
10703 + dwc_otg_hc_halt(dwc_otg_hcd->core_if, qh->channel,
10704 + DWC_OTG_HC_XFER_URB_DEQUEUE);
10709 + * Free the QTD and clean up the associated QH. Leave the QH in the
10710 + * schedule if it has any remaining QTDs.
10712 + dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd, urb_qtd);
10713 + if (urb_qtd == qh->qtd_in_process) {
10714 + dwc_otg_hcd_qh_deactivate(dwc_otg_hcd, qh, 0);
10715 + qh->channel = NULL;
10716 + qh->qtd_in_process = NULL;
10717 + } else if (list_empty(&qh->qtd_list)) {
10718 + dwc_otg_hcd_qh_remove(dwc_otg_hcd, qh);
10721 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
10723 + urb->hcpriv = NULL;
10725 + /* Higher layer software sets URB status. */
10726 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
10727 + usb_hcd_giveback_urb(hcd, urb, status);
10729 + usb_hcd_giveback_urb(hcd, urb, NULL);
10731 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
10732 + DWC_PRINT("Called usb_hcd_giveback_urb()\n");
10733 + DWC_PRINT(" urb->status = %d\n", urb->status);
10739 +/** Frees resources in the DWC_otg controller related to a given endpoint. Also
10740 + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
10741 + * must already be dequeued. */
10742 +void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
10743 + struct usb_host_endpoint *ep)
10745 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10746 + dwc_otg_qh_t *qh;
10748 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
10749 + unsigned long flags;
10753 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
10754 + "endpoint=%d\n", ep->desc.bEndpointAddress,
10755 + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
10757 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
10759 + SPIN_LOCK_IRQSAVE(&dwc_otg_hcd->lock, flags);
10760 + qh = (dwc_otg_qh_t *)(ep->hcpriv);
10764 + /** Check that the QTD list is really empty */
10765 + if (!list_empty(&qh->qtd_list)) {
10766 + if (retry++ < 250) {
10767 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
10768 + schedule_timeout_uninterruptible(1);
10772 + DWC_WARN("DWC OTG HCD EP DISABLE:"
10773 + " QTD List for this endpoint is not empty\n");
10776 + dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
10777 + ep->hcpriv = NULL;
10779 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
10781 +#else // LINUX_VERSION_CODE
10783 + qh = (dwc_otg_qh_t *)(ep->hcpriv);
10784 + if (qh != NULL) {
10786 + /** Check that the QTD list is really empty */
10787 + if (!list_empty(&qh->qtd_list)) {
10788 + DWC_WARN("DWC OTG HCD EP DISABLE:"
10789 + " QTD List for this endpoint is not empty\n");
10792 + dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
10793 + ep->hcpriv = NULL;
10795 +#endif // LINUX_VERSION_CODE
10798 +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
10799 + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
10802 + * This function is called by the USB core when an interrupt occurs */
10803 +irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd
10804 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
10805 + , struct pt_regs *regs
10809 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10810 + return IRQ_RETVAL(dwc_otg_hcd_handle_intr(dwc_otg_hcd));
10813 +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
10814 + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
10815 + * is the status change indicator for the single root port. Returns 1 if either
10816 + * change indicator is 1, otherwise returns 0. */
10817 +int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd, char *buf)
10819 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10822 + buf[0] |= (dwc_otg_hcd->flags.b.port_connect_status_change ||
10823 + dwc_otg_hcd->flags.b.port_reset_change ||
10824 + dwc_otg_hcd->flags.b.port_enable_change ||
10825 + dwc_otg_hcd->flags.b.port_suspend_change ||
10826 + dwc_otg_hcd->flags.b.port_over_current_change) << 1;
10830 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
10831 + " Root port status changed\n");
10832 + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
10833 + dwc_otg_hcd->flags.b.port_connect_status_change);
10834 + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
10835 + dwc_otg_hcd->flags.b.port_reset_change);
10836 + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
10837 + dwc_otg_hcd->flags.b.port_enable_change);
10838 + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
10839 + dwc_otg_hcd->flags.b.port_suspend_change);
10840 + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
10841 + dwc_otg_hcd->flags.b.port_over_current_change);
10844 + return (buf[0] != 0);
10847 +#ifdef DWC_HS_ELECT_TST
10849 + * Quick and dirty hack to implement the HS Electrical Test
10850 + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
10852 + * This code was copied from our userspace app "hset". It sends a
10853 + * Get Device Descriptor control sequence in two parts, first the
10854 + * Setup packet by itself, followed some time later by the In and
10855 + * Ack packets. Rather than trying to figure out how to add this
10856 + * functionality to the normal driver code, we just hijack the
10857 + * hardware, using these two function to drive the hardware
10861 +dwc_otg_core_global_regs_t *global_regs;
10862 +dwc_otg_host_global_regs_t *hc_global_regs;
10863 +dwc_otg_hc_regs_t *hc_regs;
10864 +uint32_t *data_fifo;
10866 +static void do_setup(void)
10868 + gintsts_data_t gintsts;
10869 + hctsiz_data_t hctsiz;
10870 + hcchar_data_t hcchar;
10871 + haint_data_t haint;
10872 + hcint_data_t hcint;
10874 + /* Enable HAINTs */
10875 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
10877 + /* Enable HCINTs */
10878 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
10880 + /* Read GINTSTS */
10881 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
10882 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
10885 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
10886 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
10889 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
10890 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
10892 + /* Read HCCHAR */
10893 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10894 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
10896 + /* Clear HCINT */
10897 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
10899 + /* Clear HAINT */
10900 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
10902 + /* Clear GINTSTS */
10903 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
10905 + /* Read GINTSTS */
10906 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
10907 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
10910 + * Send Setup packet (Get Device Descriptor)
10913 + /* Make sure channel is disabled */
10914 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10915 + if (hcchar.b.chen) {
10916 + //fprintf(stderr, "Channel already enabled 1, HCCHAR = %08x\n", hcchar.d32);
10917 + hcchar.b.chdis = 1;
10918 +// hcchar.b.chen = 1;
10919 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
10923 + /* Read GINTSTS */
10924 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
10925 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
10928 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
10929 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
10932 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
10933 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
10935 + /* Read HCCHAR */
10936 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10937 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
10939 + /* Clear HCINT */
10940 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
10942 + /* Clear HAINT */
10943 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
10945 + /* Clear GINTSTS */
10946 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
10948 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10949 + //if (hcchar.b.chen) {
10950 + // fprintf(stderr, "** Channel _still_ enabled 1, HCCHAR = %08x **\n", hcchar.d32);
10956 + hctsiz.b.xfersize = 8;
10957 + hctsiz.b.pktcnt = 1;
10958 + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
10959 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
10962 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10963 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
10964 + hcchar.b.epdir = 0;
10965 + hcchar.b.epnum = 0;
10966 + hcchar.b.mps = 8;
10967 + hcchar.b.chen = 1;
10968 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
10970 + /* Fill FIFO with Setup data for Get Device Descriptor */
10971 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
10972 + dwc_write_reg32(data_fifo++, 0x01000680);
10973 + dwc_write_reg32(data_fifo++, 0x00080000);
10975 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
10976 + //fprintf(stderr, "Waiting for HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
10978 + /* Wait for host channel interrupt */
10980 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
10981 + } while (gintsts.b.hcintr == 0);
10983 + //fprintf(stderr, "Got HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
10985 + /* Disable HCINTs */
10986 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
10988 + /* Disable HAINTs */
10989 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
10992 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
10993 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
10996 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
10997 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
10999 + /* Read HCCHAR */
11000 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11001 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11003 + /* Clear HCINT */
11004 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11006 + /* Clear HAINT */
11007 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11009 + /* Clear GINTSTS */
11010 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11012 + /* Read GINTSTS */
11013 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11014 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11017 +static void do_in_ack(void)
11019 + gintsts_data_t gintsts;
11020 + hctsiz_data_t hctsiz;
11021 + hcchar_data_t hcchar;
11022 + haint_data_t haint;
11023 + hcint_data_t hcint;
11024 + host_grxsts_data_t grxsts;
11026 + /* Enable HAINTs */
11027 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
11029 + /* Enable HCINTs */
11030 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
11032 + /* Read GINTSTS */
11033 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11034 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11037 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11038 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11041 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11042 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11044 + /* Read HCCHAR */
11045 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11046 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11048 + /* Clear HCINT */
11049 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11051 + /* Clear HAINT */
11052 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11054 + /* Clear GINTSTS */
11055 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11057 + /* Read GINTSTS */
11058 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11059 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11062 + * Receive Control In packet
11065 + /* Make sure channel is disabled */
11066 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11067 + if (hcchar.b.chen) {
11068 + //fprintf(stderr, "Channel already enabled 2, HCCHAR = %08x\n", hcchar.d32);
11069 + hcchar.b.chdis = 1;
11070 + hcchar.b.chen = 1;
11071 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11075 + /* Read GINTSTS */
11076 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11077 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11080 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11081 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11084 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11085 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11087 + /* Read HCCHAR */
11088 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11089 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11091 + /* Clear HCINT */
11092 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11094 + /* Clear HAINT */
11095 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11097 + /* Clear GINTSTS */
11098 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11100 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11101 + //if (hcchar.b.chen) {
11102 + // fprintf(stderr, "** Channel _still_ enabled 2, HCCHAR = %08x **\n", hcchar.d32);
11108 + hctsiz.b.xfersize = 8;
11109 + hctsiz.b.pktcnt = 1;
11110 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
11111 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
11114 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11115 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
11116 + hcchar.b.epdir = 1;
11117 + hcchar.b.epnum = 0;
11118 + hcchar.b.mps = 8;
11119 + hcchar.b.chen = 1;
11120 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11122 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11123 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
11125 + /* Wait for receive status queue interrupt */
11127 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11128 + } while (gintsts.b.rxstsqlvl == 0);
11130 + //fprintf(stderr, "Got RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
11133 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
11134 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
11136 + /* Clear RXSTSQLVL in GINTSTS */
11138 + gintsts.b.rxstsqlvl = 1;
11139 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11141 + switch (grxsts.b.pktsts) {
11142 + case DWC_GRXSTS_PKTSTS_IN:
11143 + /* Read the data into the host buffer */
11144 + if (grxsts.b.bcnt > 0) {
11146 + int word_count = (grxsts.b.bcnt + 3) / 4;
11148 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
11150 + for (i = 0; i < word_count; i++) {
11151 + (void)dwc_read_reg32(data_fifo++);
11155 + //fprintf(stderr, "Received %u bytes\n", (unsigned)grxsts.b.bcnt);
11159 + //fprintf(stderr, "** Unexpected GRXSTS packet status 1 **\n");
11163 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11164 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
11166 + /* Wait for receive status queue interrupt */
11168 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11169 + } while (gintsts.b.rxstsqlvl == 0);
11171 + //fprintf(stderr, "Got RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
11174 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
11175 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
11177 + /* Clear RXSTSQLVL in GINTSTS */
11179 + gintsts.b.rxstsqlvl = 1;
11180 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11182 + switch (grxsts.b.pktsts) {
11183 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
11187 + //fprintf(stderr, "** Unexpected GRXSTS packet status 2 **\n");
11191 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11192 + //fprintf(stderr, "Waiting for HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
11194 + /* Wait for host channel interrupt */
11196 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11197 + } while (gintsts.b.hcintr == 0);
11199 + //fprintf(stderr, "Got HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
11202 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11203 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11206 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11207 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11209 + /* Read HCCHAR */
11210 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11211 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11213 + /* Clear HCINT */
11214 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11216 + /* Clear HAINT */
11217 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11219 + /* Clear GINTSTS */
11220 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11222 + /* Read GINTSTS */
11223 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11224 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11226 +// usleep(100000);
11231 + * Send handshake packet
11235 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11236 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11239 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11240 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11242 + /* Read HCCHAR */
11243 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11244 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11246 + /* Clear HCINT */
11247 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11249 + /* Clear HAINT */
11250 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11252 + /* Clear GINTSTS */
11253 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11255 + /* Read GINTSTS */
11256 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11257 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11259 + /* Make sure channel is disabled */
11260 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11261 + if (hcchar.b.chen) {
11262 + //fprintf(stderr, "Channel already enabled 3, HCCHAR = %08x\n", hcchar.d32);
11263 + hcchar.b.chdis = 1;
11264 + hcchar.b.chen = 1;
11265 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11269 + /* Read GINTSTS */
11270 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11271 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11274 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11275 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11278 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11279 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11281 + /* Read HCCHAR */
11282 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11283 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11285 + /* Clear HCINT */
11286 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11288 + /* Clear HAINT */
11289 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11291 + /* Clear GINTSTS */
11292 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11294 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11295 + //if (hcchar.b.chen) {
11296 + // fprintf(stderr, "** Channel _still_ enabled 3, HCCHAR = %08x **\n", hcchar.d32);
11302 + hctsiz.b.xfersize = 0;
11303 + hctsiz.b.pktcnt = 1;
11304 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
11305 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
11308 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11309 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
11310 + hcchar.b.epdir = 0;
11311 + hcchar.b.epnum = 0;
11312 + hcchar.b.mps = 8;
11313 + hcchar.b.chen = 1;
11314 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11316 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11317 + //fprintf(stderr, "Waiting for HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
11319 + /* Wait for host channel interrupt */
11321 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11322 + } while (gintsts.b.hcintr == 0);
11324 + //fprintf(stderr, "Got HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
11326 + /* Disable HCINTs */
11327 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
11329 + /* Disable HAINTs */
11330 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
11333 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11334 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11337 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11338 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11340 + /* Read HCCHAR */
11341 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11342 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11344 + /* Clear HCINT */
11345 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11347 + /* Clear HAINT */
11348 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11350 + /* Clear GINTSTS */
11351 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11353 + /* Read GINTSTS */
11354 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11355 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11357 +#endif /* DWC_HS_ELECT_TST */
11359 +/** Handles hub class-specific requests. */
11360 +int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
11369 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11370 + dwc_otg_core_if_t *core_if = hcd_to_dwc_otg_hcd(hcd)->core_if;
11371 + struct usb_hub_descriptor *desc;
11372 + hprt0_data_t hprt0 = {.d32 = 0};
11374 + uint32_t port_status;
11376 + switch (typeReq) {
11377 + case ClearHubFeature:
11378 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11379 + "ClearHubFeature 0x%x\n", wValue);
11380 + switch (wValue) {
11381 + case C_HUB_LOCAL_POWER:
11382 + case C_HUB_OVER_CURRENT:
11383 + /* Nothing required here */
11386 + retval = -EINVAL;
11387 + DWC_ERROR("DWC OTG HCD - "
11388 + "ClearHubFeature request %xh unknown\n", wValue);
11391 + case ClearPortFeature:
11392 + if (!wIndex || wIndex > 1)
11395 + switch (wValue) {
11396 + case USB_PORT_FEAT_ENABLE:
11397 + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
11398 + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
11399 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11400 + hprt0.b.prtena = 1;
11401 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11403 + case USB_PORT_FEAT_SUSPEND:
11404 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11405 + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
11406 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11407 + hprt0.b.prtres = 1;
11408 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11409 + /* Clear Resume bit */
11411 + hprt0.b.prtres = 0;
11412 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11414 + case USB_PORT_FEAT_POWER:
11415 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11416 + "ClearPortFeature USB_PORT_FEAT_POWER\n");
11417 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11418 + hprt0.b.prtpwr = 0;
11419 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11421 + case USB_PORT_FEAT_INDICATOR:
11422 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11423 + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
11424 + /* Port inidicator not supported */
11426 + case USB_PORT_FEAT_C_CONNECTION:
11427 + /* Clears drivers internal connect status change
11429 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11430 + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
11431 + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
11433 + case USB_PORT_FEAT_C_RESET:
11434 + /* Clears the driver's internal Port Reset Change
11436 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11437 + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
11438 + dwc_otg_hcd->flags.b.port_reset_change = 0;
11440 + case USB_PORT_FEAT_C_ENABLE:
11441 + /* Clears the driver's internal Port
11442 + * Enable/Disable Change flag */
11443 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11444 + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
11445 + dwc_otg_hcd->flags.b.port_enable_change = 0;
11447 + case USB_PORT_FEAT_C_SUSPEND:
11448 + /* Clears the driver's internal Port Suspend
11449 + * Change flag, which is set when resume signaling on
11450 + * the host port is complete */
11451 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11452 + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
11453 + dwc_otg_hcd->flags.b.port_suspend_change = 0;
11455 + case USB_PORT_FEAT_C_OVER_CURRENT:
11456 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11457 + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
11458 + dwc_otg_hcd->flags.b.port_over_current_change = 0;
11461 + retval = -EINVAL;
11462 + DWC_ERROR("DWC OTG HCD - "
11463 + "ClearPortFeature request %xh "
11464 + "unknown or unsupported\n", wValue);
11467 + case GetHubDescriptor:
11468 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11469 + "GetHubDescriptor\n");
11470 + desc = (struct usb_hub_descriptor *)buf;
11471 + desc->bDescLength = 9;
11472 + desc->bDescriptorType = 0x29;
11473 + desc->bNbrPorts = 1;
11474 + desc->wHubCharacteristics = 0x08;
11475 + desc->bPwrOn2PwrGood = 1;
11476 + desc->bHubContrCurrent = 0;
11477 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
11478 + desc->u.hs.DeviceRemovable[0] = 0;
11479 + desc->u.hs.DeviceRemovable[1] = 0xff;
11482 + case GetHubStatus:
11483 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11484 + "GetHubStatus\n");
11485 + memset(buf, 0, 4);
11487 + case GetPortStatus:
11488 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11489 + "GetPortStatus\n");
11491 + if (!wIndex || wIndex > 1)
11496 + if (dwc_otg_hcd->flags.b.port_connect_status_change)
11497 + port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
11499 + if (dwc_otg_hcd->flags.b.port_enable_change)
11500 + port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
11502 + if (dwc_otg_hcd->flags.b.port_suspend_change)
11503 + port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
11505 + if (dwc_otg_hcd->flags.b.port_reset_change)
11506 + port_status |= (1 << USB_PORT_FEAT_C_RESET);
11508 + if (dwc_otg_hcd->flags.b.port_over_current_change) {
11509 + DWC_ERROR("Device Not Supported\n");
11510 + port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
11513 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
11515 + * The port is disconnected, which means the core is
11516 + * either in device mode or it soon will be. Just
11517 + * return 0's for the remainder of the port status
11518 + * since the port register can't be read if the core
11519 + * is in device mode.
11521 + *((__le32 *) buf) = cpu_to_le32(port_status);
11525 + hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
11526 + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
11528 + if (hprt0.b.prtconnsts)
11529 + port_status |= (1 << USB_PORT_FEAT_CONNECTION);
11531 + if (hprt0.b.prtena)
11532 + port_status |= (1 << USB_PORT_FEAT_ENABLE);
11534 + if (hprt0.b.prtsusp)
11535 + port_status |= (1 << USB_PORT_FEAT_SUSPEND);
11537 + if (hprt0.b.prtovrcurract)
11538 + port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
11540 + if (hprt0.b.prtrst)
11541 + port_status |= (1 << USB_PORT_FEAT_RESET);
11543 + if (hprt0.b.prtpwr)
11544 + port_status |= (1 << USB_PORT_FEAT_POWER);
11546 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
11547 + port_status |= USB_PORT_STAT_HIGH_SPEED;
11548 + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
11549 + port_status |= USB_PORT_STAT_LOW_SPEED;
11551 + if (hprt0.b.prttstctl)
11552 + port_status |= (1 << USB_PORT_FEAT_TEST);
11554 + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
11556 + *((__le32 *) buf) = cpu_to_le32(port_status);
11559 + case SetHubFeature:
11560 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11561 + "SetHubFeature\n");
11562 + /* No HUB features supported */
11564 + case SetPortFeature:
11565 + if (wValue != USB_PORT_FEAT_TEST && (!wIndex || wIndex > 1))
11568 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
11570 + * The port is disconnected, which means the core is
11571 + * either in device mode or it soon will be. Just
11572 + * return without doing anything since the port
11573 + * register can't be written if the core is in device
11579 + switch (wValue) {
11580 + case USB_PORT_FEAT_SUSPEND:
11581 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11582 + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
11583 + if (hcd->self.otg_port == wIndex &&
11584 + hcd->self.b_hnp_enable) {
11585 + gotgctl_data_t gotgctl = {.d32=0};
11586 + gotgctl.b.hstsethnpen = 1;
11587 + dwc_modify_reg32(&core_if->core_global_regs->gotgctl,
11589 + core_if->op_state = A_SUSPEND;
11591 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11592 + hprt0.b.prtsusp = 1;
11593 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11594 + //DWC_PRINT("SUSPEND: HPRT0=%0x\n", hprt0.d32);
11595 + /* Suspend the Phy Clock */
11597 + pcgcctl_data_t pcgcctl = {.d32=0};
11598 + pcgcctl.b.stoppclk = 1;
11599 + dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
11602 + /* For HNP the bus must be suspended for at least 200ms. */
11603 + if (hcd->self.b_hnp_enable) {
11605 + //DWC_PRINT("SUSPEND: wait complete! (%d)\n", _hcd->state);
11608 + case USB_PORT_FEAT_POWER:
11609 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11610 + "SetPortFeature - USB_PORT_FEAT_POWER\n");
11611 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11612 + hprt0.b.prtpwr = 1;
11613 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11615 + case USB_PORT_FEAT_RESET:
11616 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11617 + "SetPortFeature - USB_PORT_FEAT_RESET\n");
11618 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11619 + /* When B-Host the Port reset bit is set in
11620 + * the Start HCD Callback function, so that
11621 + * the reset is started within 1ms of the HNP
11622 + * success interrupt. */
11623 + if (!hcd->self.is_b_host) {
11624 + hprt0.b.prtrst = 1;
11625 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11627 + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
11629 + hprt0.b.prtrst = 0;
11630 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11633 +#ifdef DWC_HS_ELECT_TST
11634 + case USB_PORT_FEAT_TEST:
11637 + gintmsk_data_t gintmsk;
11639 + t = (wIndex >> 8); /* MSB wIndex USB */
11640 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11641 + "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
11642 + warn("USB_PORT_FEAT_TEST %d\n", t);
11644 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11645 + hprt0.b.prttstctl = t;
11646 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11648 + /* Setup global vars with reg addresses (quick and
11649 + * dirty hack, should be cleaned up)
11651 + global_regs = core_if->core_global_regs;
11652 + hc_global_regs = core_if->host_if->host_global_regs;
11653 + hc_regs = (dwc_otg_hc_regs_t *)((char *)global_regs + 0x500);
11654 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
11656 + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
11657 + /* Save current interrupt mask */
11658 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
11660 + /* Disable all interrupts while we muck with
11661 + * the hardware directly
11663 + dwc_write_reg32(&global_regs->gintmsk, 0);
11665 + /* 15 second delay per the test spec */
11668 + /* Drive suspend on the root port */
11669 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11670 + hprt0.b.prtsusp = 1;
11671 + hprt0.b.prtres = 0;
11672 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11674 + /* 15 second delay per the test spec */
11677 + /* Drive resume on the root port */
11678 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
11679 + hprt0.b.prtsusp = 0;
11680 + hprt0.b.prtres = 1;
11681 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11684 + /* Clear the resume bit */
11685 + hprt0.b.prtres = 0;
11686 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
11688 + /* Restore interrupts */
11689 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
11690 + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
11691 + /* Save current interrupt mask */
11692 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
11694 + /* Disable all interrupts while we muck with
11695 + * the hardware directly
11697 + dwc_write_reg32(&global_regs->gintmsk, 0);
11699 + /* 15 second delay per the test spec */
11702 + /* Send the Setup packet */
11705 + /* 15 second delay so nothing else happens for awhile */
11708 + /* Restore interrupts */
11709 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
11710 + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
11711 + /* Save current interrupt mask */
11712 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
11714 + /* Disable all interrupts while we muck with
11715 + * the hardware directly
11717 + dwc_write_reg32(&global_regs->gintmsk, 0);
11719 + /* Send the Setup packet */
11722 + /* 15 second delay so nothing else happens for awhile */
11725 + /* Send the In and Ack packets */
11728 + /* 15 second delay so nothing else happens for awhile */
11731 + /* Restore interrupts */
11732 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
11737 +#endif /* DWC_HS_ELECT_TST */
11739 + case USB_PORT_FEAT_INDICATOR:
11740 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
11741 + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
11742 + /* Not supported */
11745 + retval = -EINVAL;
11746 + DWC_ERROR("DWC OTG HCD - "
11747 + "SetPortFeature request %xh "
11748 + "unknown or unsupported\n", wValue);
11754 + retval = -EINVAL;
11755 + DWC_WARN("DWC OTG HCD - "
11756 + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
11757 + typeReq, wIndex, wValue);
11765 + * Assigns transactions from a QTD to a free host channel and initializes the
11766 + * host channel to perform the transactions. The host channel is removed from
11769 + * @param hcd The HCD state structure.
11770 + * @param qh Transactions from the first QTD for this QH are selected and
11771 + * assigned to a free host channel.
11773 +static void assign_and_init_hc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
11776 + dwc_otg_qtd_t *qtd;
11779 + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p)\n", __func__, hcd, qh);
11781 + hc = list_entry(hcd->free_hc_list.next, dwc_hc_t, hc_list_entry);
11783 + /* Remove the host channel from the free list. */
11784 + list_del_init(&hc->hc_list_entry);
11786 + qtd = list_entry(qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
11788 + qh->channel = hc;
11789 + qh->qtd_in_process = qtd;
11792 + * Use usb_pipedevice to determine device address. This address is
11793 + * 0 before the SET_ADDRESS command and the correct address afterward.
11795 + hc->dev_addr = usb_pipedevice(urb->pipe);
11796 + hc->ep_num = usb_pipeendpoint(urb->pipe);
11798 + if (urb->dev->speed == USB_SPEED_LOW) {
11799 + hc->speed = DWC_OTG_EP_SPEED_LOW;
11800 + } else if (urb->dev->speed == USB_SPEED_FULL) {
11801 + hc->speed = DWC_OTG_EP_SPEED_FULL;
11803 + hc->speed = DWC_OTG_EP_SPEED_HIGH;
11806 + hc->max_packet = dwc_max_packet(qh->maxp);
11808 + hc->xfer_started = 0;
11809 + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
11810 + hc->error_state = (qtd->error_count > 0);
11811 + hc->halt_on_queue = 0;
11812 + hc->halt_pending = 0;
11813 + hc->requests = 0;
11816 + * The following values may be modified in the transfer type section
11817 + * below. The xfer_len value may be reduced when the transfer is
11818 + * started to accommodate the max widths of the XferSize and PktCnt
11819 + * fields in the HCTSIZn register.
11821 + hc->do_ping = qh->ping_state;
11822 + hc->ep_is_in = (usb_pipein(urb->pipe) != 0);
11823 + hc->data_pid_start = qh->data_toggle;
11824 + hc->multi_count = 1;
11826 + if (hcd->core_if->dma_enable) {
11827 + hc->xfer_buff = (uint8_t *)urb->transfer_dma + urb->actual_length;
11829 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer + urb->actual_length;
11831 + hc->xfer_len = urb->transfer_buffer_length - urb->actual_length;
11832 + hc->xfer_count = 0;
11835 + * Set the split attributes
11837 + hc->do_split = 0;
11838 + if (qh->do_split) {
11839 + hc->do_split = 1;
11840 + hc->xact_pos = qtd->isoc_split_pos;
11841 + hc->complete_split = qtd->complete_split;
11842 + hc->hub_addr = urb->dev->tt->hub->devnum;
11843 + hc->port_addr = urb->dev->ttport;
11846 + switch (usb_pipetype(urb->pipe)) {
11847 + case PIPE_CONTROL:
11848 + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
11849 + switch (qtd->control_phase) {
11850 + case DWC_OTG_CONTROL_SETUP:
11851 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
11853 + hc->ep_is_in = 0;
11854 + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
11855 + if (hcd->core_if->dma_enable) {
11856 + hc->xfer_buff = (uint8_t *)urb->setup_dma;
11858 + hc->xfer_buff = (uint8_t *)urb->setup_packet;
11860 + hc->xfer_len = 8;
11862 + case DWC_OTG_CONTROL_DATA:
11863 + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
11864 + hc->data_pid_start = qtd->data_toggle;
11866 + case DWC_OTG_CONTROL_STATUS:
11868 + * Direction is opposite of data direction or IN if no
11871 + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
11872 + if (urb->transfer_buffer_length == 0) {
11873 + hc->ep_is_in = 1;
11875 + hc->ep_is_in = (usb_pipein(urb->pipe) != USB_DIR_IN);
11877 + if (hc->ep_is_in) {
11880 + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
11881 + hc->xfer_len = 0;
11882 + if (hcd->core_if->dma_enable) {
11883 + hc->xfer_buff = (uint8_t *)hcd->status_buf_dma;
11885 + hc->xfer_buff = (uint8_t *)hcd->status_buf;
11891 + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
11893 + case PIPE_INTERRUPT:
11894 + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
11896 + case PIPE_ISOCHRONOUS:
11898 + struct usb_iso_packet_descriptor *frame_desc;
11899 + frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
11900 + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
11901 + if (hcd->core_if->dma_enable) {
11902 + hc->xfer_buff = (uint8_t *)urb->transfer_dma;
11904 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer;
11906 + hc->xfer_buff += frame_desc->offset + qtd->isoc_split_offset;
11907 + hc->xfer_len = frame_desc->length - qtd->isoc_split_offset;
11909 + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
11910 + if (hc->xfer_len <= 188) {
11911 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
11914 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_BEGIN;
11921 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
11922 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
11924 + * This value may be modified when the transfer is started to
11925 + * reflect the actual transfer length.
11927 + hc->multi_count = dwc_hb_mult(qh->maxp);
11930 + dwc_otg_hc_init(hcd->core_if, hc);
11935 + * This function selects transactions from the HCD transfer schedule and
11936 + * assigns them to available host channels. It is called from HCD interrupt
11937 + * handler functions.
11939 + * @param hcd The HCD state structure.
11941 + * @return The types of new transactions that were assigned to host channels.
11943 +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *hcd)
11945 + struct list_head *qh_ptr;
11946 + dwc_otg_qh_t *qh;
11947 + int num_channels;
11948 + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
11951 + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
11954 + /* Process entries in the periodic ready list. */
11955 + qh_ptr = hcd->periodic_sched_ready.next;
11956 + while (qh_ptr != &hcd->periodic_sched_ready &&
11957 + !list_empty(&hcd->free_hc_list)) {
11959 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
11960 + assign_and_init_hc(hcd, qh);
11963 + * Move the QH from the periodic ready schedule to the
11964 + * periodic assigned schedule.
11966 + qh_ptr = qh_ptr->next;
11967 + list_move(&qh->qh_list_entry, &hcd->periodic_sched_assigned);
11969 + ret_val = DWC_OTG_TRANSACTION_PERIODIC;
11973 + * Process entries in the inactive portion of the non-periodic
11974 + * schedule. Some free host channels may not be used if they are
11975 + * reserved for periodic transfers.
11977 + qh_ptr = hcd->non_periodic_sched_inactive.next;
11978 + num_channels = hcd->core_if->core_params->host_channels;
11979 + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
11980 + (hcd->non_periodic_channels <
11981 + num_channels - hcd->periodic_channels) &&
11982 + !list_empty(&hcd->free_hc_list)) {
11984 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
11985 + assign_and_init_hc(hcd, qh);
11988 + * Move the QH from the non-periodic inactive schedule to the
11989 + * non-periodic active schedule.
11991 + qh_ptr = qh_ptr->next;
11992 + list_move(&qh->qh_list_entry, &hcd->non_periodic_sched_active);
11994 + if (ret_val == DWC_OTG_TRANSACTION_NONE) {
11995 + ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
11997 + ret_val = DWC_OTG_TRANSACTION_ALL;
12000 + hcd->non_periodic_channels++;
12007 + * Attempts to queue a single transaction request for a host channel
12008 + * associated with either a periodic or non-periodic transfer. This function
12009 + * assumes that there is space available in the appropriate request queue. For
12010 + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
12011 + * is available in the appropriate Tx FIFO.
12013 + * @param hcd The HCD state structure.
12014 + * @param hc Host channel descriptor associated with either a periodic or
12015 + * non-periodic transfer.
12016 + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
12017 + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
12020 + * @return 1 if a request is queued and more requests may be needed to
12021 + * complete the transfer, 0 if no more requests are required for this
12022 + * transfer, -1 if there is insufficient space in the Tx FIFO.
12024 +static int queue_transaction(dwc_otg_hcd_t *hcd,
12026 + uint16_t fifo_dwords_avail)
12030 + if (hcd->core_if->dma_enable) {
12031 + if (!hc->xfer_started) {
12032 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12033 + hc->qh->ping_state = 0;
12036 + } else if (hc->halt_pending) {
12037 + /* Don't queue a request if the channel has been halted. */
12039 + } else if (hc->halt_on_queue) {
12040 + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
12042 + } else if (hc->do_ping) {
12043 + if (!hc->xfer_started) {
12044 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12047 + } else if (!hc->ep_is_in ||
12048 + hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
12049 + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
12050 + if (!hc->xfer_started) {
12051 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12054 + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
12060 + if (!hc->xfer_started) {
12061 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12064 + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
12072 + * Processes active non-periodic channels and queues transactions for these
12073 + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
12074 + * FIFO Empty interrupt is enabled if there are more transactions to queue as
12075 + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
12076 + * FIFO Empty interrupt is disabled.
12078 +static void process_non_periodic_channels(dwc_otg_hcd_t *hcd)
12080 + gnptxsts_data_t tx_status;
12081 + struct list_head *orig_qh_ptr;
12082 + dwc_otg_qh_t *qh;
12084 + int no_queue_space = 0;
12085 + int no_fifo_space = 0;
12086 + int more_to_do = 0;
12088 + dwc_otg_core_global_regs_t *global_regs = hcd->core_if->core_global_regs;
12090 + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
12092 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
12093 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (before queue): %d\n",
12094 + tx_status.b.nptxqspcavail);
12095 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
12096 + tx_status.b.nptxfspcavail);
12099 + * Keep track of the starting point. Skip over the start-of-list
12102 + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
12103 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
12105 + orig_qh_ptr = hcd->non_periodic_qh_ptr;
12108 + * Process once through the active list or until no more space is
12109 + * available in the request queue or the Tx FIFO.
12112 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
12113 + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
12114 + no_queue_space = 1;
12118 + qh = list_entry(hcd->non_periodic_qh_ptr, dwc_otg_qh_t, qh_list_entry);
12119 + status = queue_transaction(hcd, qh->channel, tx_status.b.nptxfspcavail);
12121 + if (status > 0) {
12123 + } else if (status < 0) {
12124 + no_fifo_space = 1;
12128 + /* Advance to next QH, skipping start-of-list entry. */
12129 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
12130 + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
12131 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
12134 + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
12136 + if (!hcd->core_if->dma_enable) {
12137 + gintmsk_data_t intr_mask = {.d32 = 0};
12138 + intr_mask.b.nptxfempty = 1;
12141 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
12142 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (after queue): %d\n",
12143 + tx_status.b.nptxqspcavail);
12144 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (after queue): %d\n",
12145 + tx_status.b.nptxfspcavail);
12147 + if (more_to_do || no_queue_space || no_fifo_space) {
12149 + * May need to queue more transactions as the request
12150 + * queue or Tx FIFO empties. Enable the non-periodic
12151 + * Tx FIFO empty interrupt. (Always use the half-empty
12152 + * level to ensure that new requests are loaded as
12153 + * soon as possible.)
12155 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
12158 + * Disable the Tx FIFO empty interrupt since there are
12159 + * no more transactions that need to be queued right
12160 + * now. This function is called from interrupt
12161 + * handlers to queue more transactions as transfer
12164 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
12170 + * Processes periodic channels for the next frame and queues transactions for
12171 + * these channels to the DWC_otg controller. After queueing transactions, the
12172 + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
12173 + * to queue as Periodic Tx FIFO or request queue space becomes available.
12174 + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
12176 +static void process_periodic_channels(dwc_otg_hcd_t *hcd)
12178 + hptxsts_data_t tx_status;
12179 + struct list_head *qh_ptr;
12180 + dwc_otg_qh_t *qh;
12182 + int no_queue_space = 0;
12183 + int no_fifo_space = 0;
12185 + dwc_otg_host_global_regs_t *host_regs;
12186 + host_regs = hcd->core_if->host_if->host_global_regs;
12188 + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
12190 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
12191 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (before queue): %d\n",
12192 + tx_status.b.ptxqspcavail);
12193 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
12194 + tx_status.b.ptxfspcavail);
12197 + qh_ptr = hcd->periodic_sched_assigned.next;
12198 + while (qh_ptr != &hcd->periodic_sched_assigned) {
12199 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
12200 + if (tx_status.b.ptxqspcavail == 0) {
12201 + no_queue_space = 1;
12205 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
12208 + * Set a flag if we're queuing high-bandwidth in slave mode.
12209 + * The flag prevents any halts to get into the request queue in
12210 + * the middle of multiple high-bandwidth packets getting queued.
12212 + if (!hcd->core_if->dma_enable &&
12213 + qh->channel->multi_count > 1)
12215 + hcd->core_if->queuing_high_bandwidth = 1;
12218 + status = queue_transaction(hcd, qh->channel, tx_status.b.ptxfspcavail);
12219 + if (status < 0) {
12220 + no_fifo_space = 1;
12225 + * In Slave mode, stay on the current transfer until there is
12226 + * nothing more to do or the high-bandwidth request count is
12227 + * reached. In DMA mode, only need to queue one request. The
12228 + * controller automatically handles multiple packets for
12229 + * high-bandwidth transfers.
12231 + if (hcd->core_if->dma_enable || status == 0 ||
12232 + qh->channel->requests == qh->channel->multi_count) {
12233 + qh_ptr = qh_ptr->next;
12235 + * Move the QH from the periodic assigned schedule to
12236 + * the periodic queued schedule.
12238 + list_move(&qh->qh_list_entry, &hcd->periodic_sched_queued);
12240 + /* done queuing high bandwidth */
12241 + hcd->core_if->queuing_high_bandwidth = 0;
12245 + if (!hcd->core_if->dma_enable) {
12246 + dwc_otg_core_global_regs_t *global_regs;
12247 + gintmsk_data_t intr_mask = {.d32 = 0};
12249 + global_regs = hcd->core_if->core_global_regs;
12250 + intr_mask.b.ptxfempty = 1;
12252 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
12253 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (after queue): %d\n",
12254 + tx_status.b.ptxqspcavail);
12255 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (after queue): %d\n",
12256 + tx_status.b.ptxfspcavail);
12258 + if (!list_empty(&hcd->periodic_sched_assigned) ||
12259 + no_queue_space || no_fifo_space) {
12261 + * May need to queue more transactions as the request
12262 + * queue or Tx FIFO empties. Enable the periodic Tx
12263 + * FIFO empty interrupt. (Always use the half-empty
12264 + * level to ensure that new requests are loaded as
12265 + * soon as possible.)
12267 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
12270 + * Disable the Tx FIFO empty interrupt since there are
12271 + * no more transactions that need to be queued right
12272 + * now. This function is called from interrupt
12273 + * handlers to queue more transactions as transfer
12276 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
12282 + * This function processes the currently active host channels and queues
12283 + * transactions for these channels to the DWC_otg controller. It is called
12284 + * from HCD interrupt handler functions.
12286 + * @param hcd The HCD state structure.
12287 + * @param tr_type The type(s) of transactions to queue (non-periodic,
12288 + * periodic, or both).
12290 +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *hcd,
12291 + dwc_otg_transaction_type_e tr_type)
12294 + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
12296 + /* Process host channels associated with periodic transfers. */
12297 + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
12298 + tr_type == DWC_OTG_TRANSACTION_ALL) &&
12299 + !list_empty(&hcd->periodic_sched_assigned)) {
12301 + process_periodic_channels(hcd);
12304 + /* Process host channels associated with non-periodic transfers. */
12305 + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
12306 + tr_type == DWC_OTG_TRANSACTION_ALL) {
12307 + if (!list_empty(&hcd->non_periodic_sched_active)) {
12308 + process_non_periodic_channels(hcd);
12311 + * Ensure NP Tx FIFO empty interrupt is disabled when
12312 + * there are no non-periodic transfers to process.
12314 + gintmsk_data_t gintmsk = {.d32 = 0};
12315 + gintmsk.b.nptxfempty = 1;
12316 + dwc_modify_reg32(&hcd->core_if->core_global_regs->gintmsk,
12323 + * Sets the final status of an URB and returns it to the device driver. Any
12324 + * required cleanup of the URB is performed.
12326 +void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *hcd, struct urb *urb, int status)
12329 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
12330 + DWC_PRINT("%s: urb %p, device %d, ep %d %s, status=%d\n",
12331 + __func__, urb, usb_pipedevice(urb->pipe),
12332 + usb_pipeendpoint(urb->pipe),
12333 + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
12334 + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
12336 + for (i = 0; i < urb->number_of_packets; i++) {
12337 + DWC_PRINT(" ISO Desc %d status: %d\n",
12338 + i, urb->iso_frame_desc[i].status);
12344 + urb->status = status;
12345 + urb->hcpriv = NULL;
12346 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
12347 + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, status);
12349 + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, NULL);
12354 + * Returns the Queue Head for an URB.
12356 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *urb)
12358 + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
12359 + return (dwc_otg_qh_t *)ep->hcpriv;
12363 +void dwc_print_setup_data(uint8_t *setup)
12366 + if (CHK_DEBUG_LEVEL(DBG_HCD)){
12367 + DWC_PRINT("Setup Data = MSB ");
12368 + for (i = 7; i >= 0; i--) DWC_PRINT("%02x ", setup[i]);
12370 + DWC_PRINT(" bmRequestType Tranfer = %s\n", (setup[0] & 0x80) ? "Device-to-Host" : "Host-to-Device");
12371 + DWC_PRINT(" bmRequestType Type = ");
12372 + switch ((setup[0] & 0x60) >> 5) {
12373 + case 0: DWC_PRINT("Standard\n"); break;
12374 + case 1: DWC_PRINT("Class\n"); break;
12375 + case 2: DWC_PRINT("Vendor\n"); break;
12376 + case 3: DWC_PRINT("Reserved\n"); break;
12378 + DWC_PRINT(" bmRequestType Recipient = ");
12379 + switch (setup[0] & 0x1f) {
12380 + case 0: DWC_PRINT("Device\n"); break;
12381 + case 1: DWC_PRINT("Interface\n"); break;
12382 + case 2: DWC_PRINT("Endpoint\n"); break;
12383 + case 3: DWC_PRINT("Other\n"); break;
12384 + default: DWC_PRINT("Reserved\n"); break;
12386 + DWC_PRINT(" bRequest = 0x%0x\n", setup[1]);
12387 + DWC_PRINT(" wValue = 0x%0x\n", *((uint16_t *)&setup[2]));
12388 + DWC_PRINT(" wIndex = 0x%0x\n", *((uint16_t *)&setup[4]));
12389 + DWC_PRINT(" wLength = 0x%0x\n\n", *((uint16_t *)&setup[6]));
12394 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *hcd) {
12395 +#if defined(DEBUG) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
12396 + DWC_PRINT("Frame remaining at SOF:\n");
12397 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12398 + hcd->frrem_samples, hcd->frrem_accum,
12399 + (hcd->frrem_samples > 0) ?
12400 + hcd->frrem_accum/hcd->frrem_samples : 0);
12403 + DWC_PRINT("Frame remaining at start_transfer (uframe 7):\n");
12404 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12405 + hcd->core_if->hfnum_7_samples, hcd->core_if->hfnum_7_frrem_accum,
12406 + (hcd->core_if->hfnum_7_samples > 0) ?
12407 + hcd->core_if->hfnum_7_frrem_accum/hcd->core_if->hfnum_7_samples : 0);
12408 + DWC_PRINT("Frame remaining at start_transfer (uframe 0):\n");
12409 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12410 + hcd->core_if->hfnum_0_samples, hcd->core_if->hfnum_0_frrem_accum,
12411 + (hcd->core_if->hfnum_0_samples > 0) ?
12412 + hcd->core_if->hfnum_0_frrem_accum/hcd->core_if->hfnum_0_samples : 0);
12413 + DWC_PRINT("Frame remaining at start_transfer (uframe 1-6):\n");
12414 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12415 + hcd->core_if->hfnum_other_samples, hcd->core_if->hfnum_other_frrem_accum,
12416 + (hcd->core_if->hfnum_other_samples > 0) ?
12417 + hcd->core_if->hfnum_other_frrem_accum/hcd->core_if->hfnum_other_samples : 0);
12420 + DWC_PRINT("Frame remaining at sample point A (uframe 7):\n");
12421 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12422 + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
12423 + (hcd->hfnum_7_samples_a > 0) ?
12424 + hcd->hfnum_7_frrem_accum_a/hcd->hfnum_7_samples_a : 0);
12425 + DWC_PRINT("Frame remaining at sample point A (uframe 0):\n");
12426 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12427 + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
12428 + (hcd->hfnum_0_samples_a > 0) ?
12429 + hcd->hfnum_0_frrem_accum_a/hcd->hfnum_0_samples_a : 0);
12430 + DWC_PRINT("Frame remaining at sample point A (uframe 1-6):\n");
12431 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12432 + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
12433 + (hcd->hfnum_other_samples_a > 0) ?
12434 + hcd->hfnum_other_frrem_accum_a/hcd->hfnum_other_samples_a : 0);
12437 + DWC_PRINT("Frame remaining at sample point B (uframe 7):\n");
12438 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12439 + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
12440 + (hcd->hfnum_7_samples_b > 0) ?
12441 + hcd->hfnum_7_frrem_accum_b/hcd->hfnum_7_samples_b : 0);
12442 + DWC_PRINT("Frame remaining at sample point B (uframe 0):\n");
12443 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12444 + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
12445 + (hcd->hfnum_0_samples_b > 0) ?
12446 + hcd->hfnum_0_frrem_accum_b/hcd->hfnum_0_samples_b : 0);
12447 + DWC_PRINT("Frame remaining at sample point B (uframe 1-6):\n");
12448 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
12449 + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
12450 + (hcd->hfnum_other_samples_b > 0) ?
12451 + hcd->hfnum_other_frrem_accum_b/hcd->hfnum_other_samples_b : 0);
12455 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *hcd)
12458 + int num_channels;
12460 + gnptxsts_data_t np_tx_status;
12461 + hptxsts_data_t p_tx_status;
12463 + num_channels = hcd->core_if->core_params->host_channels;
12465 + DWC_PRINT("************************************************************\n");
12466 + DWC_PRINT("HCD State:\n");
12467 + DWC_PRINT(" Num channels: %d\n", num_channels);
12468 + for (i = 0; i < num_channels; i++) {
12469 + dwc_hc_t *hc = hcd->hc_ptr_array[i];
12470 + DWC_PRINT(" Channel %d:\n", i);
12471 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
12472 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
12473 + DWC_PRINT(" speed: %d\n", hc->speed);
12474 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
12475 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
12476 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
12477 + DWC_PRINT(" multi_count: %d\n", hc->multi_count);
12478 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
12479 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
12480 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
12481 + DWC_PRINT(" xfer_count: %d\n", hc->xfer_count);
12482 + DWC_PRINT(" halt_on_queue: %d\n", hc->halt_on_queue);
12483 + DWC_PRINT(" halt_pending: %d\n", hc->halt_pending);
12484 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
12485 + DWC_PRINT(" do_split: %d\n", hc->do_split);
12486 + DWC_PRINT(" complete_split: %d\n", hc->complete_split);
12487 + DWC_PRINT(" hub_addr: %d\n", hc->hub_addr);
12488 + DWC_PRINT(" port_addr: %d\n", hc->port_addr);
12489 + DWC_PRINT(" xact_pos: %d\n", hc->xact_pos);
12490 + DWC_PRINT(" requests: %d\n", hc->requests);
12491 + DWC_PRINT(" qh: %p\n", hc->qh);
12492 + if (hc->xfer_started) {
12493 + hfnum_data_t hfnum;
12494 + hcchar_data_t hcchar;
12495 + hctsiz_data_t hctsiz;
12496 + hcint_data_t hcint;
12497 + hcintmsk_data_t hcintmsk;
12498 + hfnum.d32 = dwc_read_reg32(&hcd->core_if->host_if->host_global_regs->hfnum);
12499 + hcchar.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hcchar);
12500 + hctsiz.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hctsiz);
12501 + hcint.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hcint);
12502 + hcintmsk.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hcintmsk);
12503 + DWC_PRINT(" hfnum: 0x%08x\n", hfnum.d32);
12504 + DWC_PRINT(" hcchar: 0x%08x\n", hcchar.d32);
12505 + DWC_PRINT(" hctsiz: 0x%08x\n", hctsiz.d32);
12506 + DWC_PRINT(" hcint: 0x%08x\n", hcint.d32);
12507 + DWC_PRINT(" hcintmsk: 0x%08x\n", hcintmsk.d32);
12509 + if (hc->xfer_started && hc->qh && hc->qh->qtd_in_process) {
12510 + dwc_otg_qtd_t *qtd;
12512 + qtd = hc->qh->qtd_in_process;
12514 + DWC_PRINT(" URB Info:\n");
12515 + DWC_PRINT(" qtd: %p, urb: %p\n", qtd, urb);
12517 + DWC_PRINT(" Dev: %d, EP: %d %s\n",
12518 + usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe),
12519 + usb_pipein(urb->pipe) ? "IN" : "OUT");
12520 + DWC_PRINT(" Max packet size: %d\n",
12521 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
12522 + DWC_PRINT(" transfer_buffer: %p\n", urb->transfer_buffer);
12523 + DWC_PRINT(" transfer_dma: %p\n", (void *)urb->transfer_dma);
12524 + DWC_PRINT(" transfer_buffer_length: %d\n", urb->transfer_buffer_length);
12525 + DWC_PRINT(" actual_length: %d\n", urb->actual_length);
12529 + DWC_PRINT(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
12530 + DWC_PRINT(" periodic_channels: %d\n", hcd->periodic_channels);
12531 + DWC_PRINT(" periodic_usecs: %d\n", hcd->periodic_usecs);
12532 + np_tx_status.d32 = dwc_read_reg32(&hcd->core_if->core_global_regs->gnptxsts);
12533 + DWC_PRINT(" NP Tx Req Queue Space Avail: %d\n", np_tx_status.b.nptxqspcavail);
12534 + DWC_PRINT(" NP Tx FIFO Space Avail: %d\n", np_tx_status.b.nptxfspcavail);
12535 + p_tx_status.d32 = dwc_read_reg32(&hcd->core_if->host_if->host_global_regs->hptxsts);
12536 + DWC_PRINT(" P Tx Req Queue Space Avail: %d\n", p_tx_status.b.ptxqspcavail);
12537 + DWC_PRINT(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
12538 + dwc_otg_hcd_dump_frrem(hcd);
12539 + dwc_otg_dump_global_registers(hcd->core_if);
12540 + dwc_otg_dump_host_registers(hcd->core_if);
12541 + DWC_PRINT("************************************************************\n");
12545 +#endif /* DWC_DEVICE_ONLY */
12546 diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd.h b/drivers/usb/dwc_otg/dwc_otg_hcd.h
12547 new file mode 100644
12548 index 0000000..ee41dc9
12550 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.h
12552 +/* ==========================================================================
12553 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
12554 + * $Revision: 1.3 $
12555 + * $Date: 2008-12-15 06:51:32 $
12556 + * $Change: 1064918 $
12558 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
12559 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
12560 + * otherwise expressly agreed to in writing between Synopsys and you.
12562 + * The Software IS NOT an item of Licensed Software or Licensed Product under
12563 + * any End User Software License Agreement or Agreement for Licensed Product
12564 + * with Synopsys or any supplement thereto. You are permitted to use and
12565 + * redistribute this Software in source and binary forms, with or without
12566 + * modification, provided that redistributions of source code must retain this
12567 + * notice. You may not view, use, disclose, copy or distribute this file or
12568 + * any information contained herein except pursuant to this license grant from
12569 + * Synopsys. If you do not agree with this notice, including the disclaimer
12570 + * below, then you are not authorized to use the Software.
12572 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
12573 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12574 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
12575 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
12576 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
12577 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12578 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
12579 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
12580 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
12581 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
12583 + * ========================================================================== */
12584 +#ifndef DWC_DEVICE_ONLY
12585 +#ifndef __DWC_HCD_H__
12586 +#define __DWC_HCD_H__
12588 +#include <linux/list.h>
12589 +#include <linux/usb.h>
12590 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
12591 +#include <linux/usb/hcd.h>
12593 +#include <../drivers/usb/core/hcd.h>
12596 +struct dwc_otg_device;
12598 +#include "dwc_otg_cil.h"
12603 + * This file contains the structures, constants, and interfaces for
12604 + * the Host Contoller Driver (HCD).
12606 + * The Host Controller Driver (HCD) is responsible for translating requests
12607 + * from the USB Driver into the appropriate actions on the DWC_otg controller.
12608 + * It isolates the USBD from the specifics of the controller by providing an
12609 + * API to the USBD.
12613 + * Phases for control transfers.
12615 +typedef enum dwc_otg_control_phase {
12616 + DWC_OTG_CONTROL_SETUP,
12617 + DWC_OTG_CONTROL_DATA,
12618 + DWC_OTG_CONTROL_STATUS
12619 +} dwc_otg_control_phase_e;
12621 +/** Transaction types. */
12622 +typedef enum dwc_otg_transaction_type {
12623 + DWC_OTG_TRANSACTION_NONE,
12624 + DWC_OTG_TRANSACTION_PERIODIC,
12625 + DWC_OTG_TRANSACTION_NON_PERIODIC,
12626 + DWC_OTG_TRANSACTION_ALL
12627 +} dwc_otg_transaction_type_e;
12630 + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
12631 + * interrupt, or isochronous transfer. A single QTD is created for each URB
12632 + * (of one of these types) submitted to the HCD. The transfer associated with
12633 + * a QTD may require one or multiple transactions.
12635 + * A QTD is linked to a Queue Head, which is entered in either the
12636 + * non-periodic or periodic schedule for execution. When a QTD is chosen for
12637 + * execution, some or all of its transactions may be executed. After
12638 + * execution, the state of the QTD is updated. The QTD may be retired if all
12639 + * its transactions are complete or if an error occurred. Otherwise, it
12640 + * remains in the schedule so more transactions can be executed later.
12642 +typedef struct dwc_otg_qtd {
12644 + * Determines the PID of the next data packet for the data phase of
12645 + * control transfers. Ignored for other transfer types.<br>
12646 + * One of the following values:
12647 + * - DWC_OTG_HC_PID_DATA0
12648 + * - DWC_OTG_HC_PID_DATA1
12650 + uint8_t data_toggle;
12652 + /** Current phase for control transfers (Setup, Data, or Status). */
12653 + dwc_otg_control_phase_e control_phase;
12655 + /** Keep track of the current split type
12656 + * for FS/LS endpoints on a HS Hub */
12657 + uint8_t complete_split;
12659 + /** How many bytes transferred during SSPLIT OUT */
12660 + uint32_t ssplit_out_xfer_count;
12663 + * Holds the number of bus errors that have occurred for a transaction
12664 + * within this transfer.
12666 + uint8_t error_count;
12669 + * Index of the next frame descriptor for an isochronous transfer. A
12670 + * frame descriptor describes the buffer position and length of the
12671 + * data to be transferred in the next scheduled (micro)frame of an
12672 + * isochronous transfer. It also holds status for that transaction.
12673 + * The frame index starts at 0.
12675 + int isoc_frame_index;
12677 + /** Position of the ISOC split on full/low speed */
12678 + uint8_t isoc_split_pos;
12680 + /** Position of the ISOC split in the buffer for the current frame */
12681 + uint16_t isoc_split_offset;
12683 + /** URB for this transfer */
12686 + /** This list of QTDs */
12687 + struct list_head qtd_list_entry;
12692 + * A Queue Head (QH) holds the static characteristics of an endpoint and
12693 + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
12694 + * be entered in either the non-periodic or periodic schedule.
12696 +typedef struct dwc_otg_qh {
12699 + * One of the following values:
12700 + * - USB_ENDPOINT_XFER_CONTROL
12701 + * - USB_ENDPOINT_XFER_ISOC
12702 + * - USB_ENDPOINT_XFER_BULK
12703 + * - USB_ENDPOINT_XFER_INT
12706 + uint8_t ep_is_in;
12708 + /** wMaxPacketSize Field of Endpoint Descriptor. */
12712 + * Determines the PID of the next data packet for non-control
12713 + * transfers. Ignored for control transfers.<br>
12714 + * One of the following values:
12715 + * - DWC_OTG_HC_PID_DATA0
12716 + * - DWC_OTG_HC_PID_DATA1
12718 + uint8_t data_toggle;
12720 + /** Ping state if 1. */
12721 + uint8_t ping_state;
12724 + * List of QTDs for this QH.
12726 + struct list_head qtd_list;
12728 + /** Host channel currently processing transfers for this QH. */
12729 + dwc_hc_t *channel;
12731 + /** QTD currently assigned to a host channel for this QH. */
12732 + dwc_otg_qtd_t *qtd_in_process;
12734 + /** Full/low speed endpoint on high-speed hub requires split. */
12735 + uint8_t do_split;
12737 + /** @name Periodic schedule information */
12740 + /** Bandwidth in microseconds per (micro)frame. */
12743 + /** Interval between transfers in (micro)frames. */
12744 + uint16_t interval;
12747 + * (micro)frame to initialize a periodic transfer. The transfer
12748 + * executes in the following (micro)frame.
12750 + uint16_t sched_frame;
12752 + /** (micro)frame at which last start split was initialized. */
12753 + uint16_t start_split_frame;
12757 + /** Entry for QH in either the periodic or non-periodic schedule. */
12758 + struct list_head qh_list_entry;
12760 + /* For non-dword aligned buffer support */
12761 + uint8_t *dw_align_buf;
12762 + dma_addr_t dw_align_buf_dma;
12766 + * This structure holds the state of the HCD, including the non-periodic and
12767 + * periodic schedules.
12769 +typedef struct dwc_otg_hcd {
12770 + /** The DWC otg device pointer */
12771 + struct dwc_otg_device *otg_dev;
12773 + /** DWC OTG Core Interface Layer */
12774 + dwc_otg_core_if_t *core_if;
12776 + /** Internal DWC HCD Flags */
12777 + volatile union dwc_otg_hcd_internal_flags {
12780 + unsigned port_connect_status_change : 1;
12781 + unsigned port_connect_status : 1;
12782 + unsigned port_reset_change : 1;
12783 + unsigned port_enable_change : 1;
12784 + unsigned port_suspend_change : 1;
12785 + unsigned port_over_current_change : 1;
12786 + unsigned reserved : 27;
12791 + * Inactive items in the non-periodic schedule. This is a list of
12792 + * Queue Heads. Transfers associated with these Queue Heads are not
12793 + * currently assigned to a host channel.
12795 + struct list_head non_periodic_sched_inactive;
12798 + * Active items in the non-periodic schedule. This is a list of
12799 + * Queue Heads. Transfers associated with these Queue Heads are
12800 + * currently assigned to a host channel.
12802 + struct list_head non_periodic_sched_active;
12805 + * Pointer to the next Queue Head to process in the active
12806 + * non-periodic schedule.
12808 + struct list_head *non_periodic_qh_ptr;
12811 + * Inactive items in the periodic schedule. This is a list of QHs for
12812 + * periodic transfers that are _not_ scheduled for the next frame.
12813 + * Each QH in the list has an interval counter that determines when it
12814 + * needs to be scheduled for execution. This scheduling mechanism
12815 + * allows only a simple calculation for periodic bandwidth used (i.e.
12816 + * must assume that all periodic transfers may need to execute in the
12817 + * same frame). However, it greatly simplifies scheduling and should
12818 + * be sufficient for the vast majority of OTG hosts, which need to
12819 + * connect to a small number of peripherals at one time.
12821 + * Items move from this list to periodic_sched_ready when the QH
12822 + * interval counter is 0 at SOF.
12824 + struct list_head periodic_sched_inactive;
12827 + * List of periodic QHs that are ready for execution in the next
12828 + * frame, but have not yet been assigned to host channels.
12830 + * Items move from this list to periodic_sched_assigned as host
12831 + * channels become available during the current frame.
12833 + struct list_head periodic_sched_ready;
12836 + * List of periodic QHs to be executed in the next frame that are
12837 + * assigned to host channels.
12839 + * Items move from this list to periodic_sched_queued as the
12840 + * transactions for the QH are queued to the DWC_otg controller.
12842 + struct list_head periodic_sched_assigned;
12845 + * List of periodic QHs that have been queued for execution.
12847 + * Items move from this list to either periodic_sched_inactive or
12848 + * periodic_sched_ready when the channel associated with the transfer
12849 + * is released. If the interval for the QH is 1, the item moves to
12850 + * periodic_sched_ready because it must be rescheduled for the next
12851 + * frame. Otherwise, the item moves to periodic_sched_inactive.
12853 + struct list_head periodic_sched_queued;
12856 + * Total bandwidth claimed so far for periodic transfers. This value
12857 + * is in microseconds per (micro)frame. The assumption is that all
12858 + * periodic transfers may occur in the same (micro)frame.
12860 + uint16_t periodic_usecs;
12863 + * Frame number read from the core at SOF. The value ranges from 0 to
12864 + * DWC_HFNUM_MAX_FRNUM.
12866 + uint16_t frame_number;
12869 + * Free host channels in the controller. This is a list of
12870 + * dwc_hc_t items.
12872 + struct list_head free_hc_list;
12875 + * Number of host channels assigned to periodic transfers. Currently
12876 + * assuming that there is a dedicated host channel for each periodic
12877 + * transaction and at least one host channel available for
12878 + * non-periodic transactions.
12880 + int periodic_channels;
12883 + * Number of host channels assigned to non-periodic transfers.
12885 + int non_periodic_channels;
12888 + * Array of pointers to the host channel descriptors. Allows accessing
12889 + * a host channel descriptor given the host channel number. This is
12890 + * useful in interrupt handlers.
12892 + dwc_hc_t *hc_ptr_array[MAX_EPS_CHANNELS];
12895 + * Buffer to use for any data received during the status phase of a
12896 + * control transfer. Normally no data is transferred during the status
12897 + * phase. This buffer is used as a bit bucket.
12899 + uint8_t *status_buf;
12902 + * DMA address for status_buf.
12904 + dma_addr_t status_buf_dma;
12905 +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
12908 + * Structure to allow starting the HCD in a non-interrupt context
12909 + * during an OTG role change.
12911 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
12912 + struct work_struct start_work;
12914 + struct delayed_work start_work;
12918 + * Connection timer. An OTG host must display a message if the device
12919 + * does not connect. Started when the VBus power is turned on via
12920 + * sysfs attribute "buspower".
12922 + struct timer_list conn_timer;
12924 + /* Tasket to do a reset */
12925 + struct tasklet_struct *reset_tasklet;
12931 + uint32_t frrem_samples;
12932 + uint64_t frrem_accum;
12934 + uint32_t hfnum_7_samples_a;
12935 + uint64_t hfnum_7_frrem_accum_a;
12936 + uint32_t hfnum_0_samples_a;
12937 + uint64_t hfnum_0_frrem_accum_a;
12938 + uint32_t hfnum_other_samples_a;
12939 + uint64_t hfnum_other_frrem_accum_a;
12941 + uint32_t hfnum_7_samples_b;
12942 + uint64_t hfnum_7_frrem_accum_b;
12943 + uint32_t hfnum_0_samples_b;
12944 + uint64_t hfnum_0_frrem_accum_b;
12945 + uint32_t hfnum_other_samples_b;
12946 + uint64_t hfnum_other_frrem_accum_b;
12950 +/** Gets the dwc_otg_hcd from a struct usb_hcd */
12951 +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
12953 + return (dwc_otg_hcd_t *)(hcd->hcd_priv);
12956 +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
12957 +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t *dwc_otg_hcd)
12959 + return container_of((void *)dwc_otg_hcd, struct usb_hcd, hcd_priv);
12962 +/** @name HCD Create/Destroy Functions */
12964 +extern int dwc_otg_hcd_init(struct device *dev);
12965 +extern void dwc_otg_hcd_remove(struct device *dev);
12968 +/** @name Linux HC Driver API Functions */
12971 +extern int dwc_otg_hcd_start(struct usb_hcd *hcd);
12972 +extern void dwc_otg_hcd_stop(struct usb_hcd *hcd);
12973 +extern int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd);
12974 +extern void dwc_otg_hcd_free(struct usb_hcd *hcd);
12975 +extern int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
12977 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
12983 +extern int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
12984 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
12986 + struct urb *urb, int status);
12987 +extern void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
12988 + struct usb_host_endpoint *ep);
12989 +extern irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd
12990 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
12991 + , struct pt_regs *regs
12994 +extern int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd,
12996 +extern int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
13005 +/** @name Transaction Execution Functions */
13007 +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *hcd);
13008 +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *hcd,
13009 + dwc_otg_transaction_type_e tr_type);
13010 +extern void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *_hcd, struct urb *urb,
13014 +/** @name Interrupt Handler Functions */
13016 +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13017 +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13018 +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13019 +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13020 +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13021 +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13022 +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13023 +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13024 +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13025 +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13026 +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t *dwc_otg_hcd, uint32_t num);
13027 +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13028 +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13032 +/** @name Schedule Queue Functions */
13035 +/* Implemented in dwc_otg_hcd_queue.c */
13036 +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t *hcd, struct urb *urb);
13037 +extern void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, struct urb *urb);
13038 +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
13039 +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
13040 +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
13041 +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, int sched_csplit);
13043 +/** Remove and free a QH */
13044 +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t *hcd,
13045 + dwc_otg_qh_t *qh)
13047 + dwc_otg_hcd_qh_remove(hcd, qh);
13048 + dwc_otg_hcd_qh_free(hcd, qh);
13051 +/** Allocates memory for a QH structure.
13052 + * @return Returns the memory allocate or NULL on error. */
13053 +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(void)
13055 + return (dwc_otg_qh_t *) kmalloc(sizeof(dwc_otg_qh_t), GFP_KERNEL);
13058 +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(struct urb *urb);
13059 +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t *qtd, struct urb *urb);
13060 +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t *qtd, dwc_otg_hcd_t *dwc_otg_hcd);
13062 +/** Allocates memory for a QTD structure.
13063 + * @return Returns the memory allocate or NULL on error. */
13064 +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(void)
13066 + return (dwc_otg_qtd_t *) kmalloc(sizeof(dwc_otg_qtd_t), GFP_KERNEL);
13069 +/** Frees the memory for a QTD structure. QTD should already be removed from
13071 + * @param[in] qtd QTD to free.*/
13072 +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t *qtd)
13077 +/** Removes a QTD from list.
13078 + * @param[in] hcd HCD instance.
13079 + * @param[in] qtd QTD to remove from list. */
13080 +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t *hcd, dwc_otg_qtd_t *qtd)
13082 + unsigned long flags;
13083 + SPIN_LOCK_IRQSAVE(&hcd->lock, flags);
13084 + list_del(&qtd->qtd_list_entry);
13085 + SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags);
13088 +/** Remove and free a QTD */
13089 +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t *hcd, dwc_otg_qtd_t *qtd)
13091 + dwc_otg_hcd_qtd_remove(hcd, qtd);
13092 + dwc_otg_hcd_qtd_free(qtd);
13098 +/** @name Internal Functions */
13100 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *urb);
13101 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *hcd);
13102 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *hcd);
13105 +/** Gets the usb_host_endpoint associated with an URB. */
13106 +static inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
13108 + struct usb_device *dev = urb->dev;
13109 + int ep_num = usb_pipeendpoint(urb->pipe);
13111 + if (usb_pipein(urb->pipe))
13112 + return dev->ep_in[ep_num];
13114 + return dev->ep_out[ep_num];
13118 + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
13119 + * qualified with its direction (possible 32 endpoints per device).
13121 +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
13122 + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
13124 +/** Gets the QH that contains the list_head */
13125 +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
13127 +/** Gets the QTD that contains the list_head */
13128 +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
13130 +/** Check if QH is non-periodic */
13131 +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == USB_ENDPOINT_XFER_BULK) || \
13132 + (_qh_ptr_->ep_type == USB_ENDPOINT_XFER_CONTROL))
13134 +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
13135 +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
13137 +/** Packet size for any kind of endpoint descriptor */
13138 +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
13141 + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
13142 + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
13143 + * frame number when the max frame number is reached.
13145 +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
13147 + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
13148 + (DWC_HFNUM_MAX_FRNUM >> 1);
13152 + * Returns true if _frame1 is greater than _frame2. The comparison is done
13153 + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
13154 + * number when the max frame number is reached.
13156 +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
13158 + return (frame1 != frame2) &&
13159 + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
13160 + (DWC_HFNUM_MAX_FRNUM >> 1));
13164 + * Increments _frame by the amount specified by _inc. The addition is done
13165 + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
13167 +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
13169 + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
13172 +static inline uint16_t dwc_full_frame_num(uint16_t frame)
13174 + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
13177 +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
13179 + return frame & 0x7;
13184 + * Macro to sample the remaining PHY clocks left in the current frame. This
13185 + * may be used during debugging to determine the average time it takes to
13186 + * execute sections of code. There are two possible sample points, "a" and
13187 + * "b", so the _letter argument must be one of these values.
13189 + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
13190 + * example, "cat /sys/devices/lm0/hcd_frrem".
13192 +#define dwc_sample_frrem(_hcd, _qh, _letter) \
13194 + hfnum_data_t hfnum; \
13195 + dwc_otg_qtd_t *qtd; \
13196 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
13197 + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
13198 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
13199 + switch (hfnum.b.frnum & 0x7) { \
13201 + _hcd->hfnum_7_samples_##_letter++; \
13202 + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
13205 + _hcd->hfnum_0_samples_##_letter++; \
13206 + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
13209 + _hcd->hfnum_other_samples_##_letter++; \
13210 + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
13216 +#define dwc_sample_frrem(_hcd, _qh, _letter)
13219 +#endif /* DWC_DEVICE_ONLY */
13220 diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
13221 new file mode 100644
13222 index 0000000..bdf2db9
13224 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
13226 +/* ==========================================================================
13227 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
13228 + * $Revision: 1.6.2.1 $
13229 + * $Date: 2009-04-22 03:48:22 $
13230 + * $Change: 1117667 $
13232 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13233 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13234 + * otherwise expressly agreed to in writing between Synopsys and you.
13236 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13237 + * any End User Software License Agreement or Agreement for Licensed Product
13238 + * with Synopsys or any supplement thereto. You are permitted to use and
13239 + * redistribute this Software in source and binary forms, with or without
13240 + * modification, provided that redistributions of source code must retain this
13241 + * notice. You may not view, use, disclose, copy or distribute this file or
13242 + * any information contained herein except pursuant to this license grant from
13243 + * Synopsys. If you do not agree with this notice, including the disclaimer
13244 + * below, then you are not authorized to use the Software.
13246 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13247 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13248 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13249 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13250 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13251 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13252 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13253 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13254 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13255 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13257 + * ========================================================================== */
13258 +#ifndef DWC_DEVICE_ONLY
13260 +#include <linux/version.h>
13262 +#include "dwc_otg_driver.h"
13263 +#include "dwc_otg_hcd.h"
13264 +#include "dwc_otg_regs.h"
13267 + * This file contains the implementation of the HCD Interrupt handlers.
13270 +/** This function handles interrupts for the HCD. */
13271 +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t *dwc_otg_hcd)
13275 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
13276 + gintsts_data_t gintsts;
13278 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
13281 + /* Check if HOST Mode */
13282 + if (dwc_otg_is_host_mode(core_if)) {
13283 + gintsts.d32 = dwc_otg_read_core_intr(core_if);
13284 + if (!gintsts.d32) {
13289 + /* Don't print debug message in the interrupt handler on SOF */
13290 +# ifndef DEBUG_SOF
13291 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
13293 + DWC_DEBUGPL(DBG_HCD, "\n");
13297 +# ifndef DEBUG_SOF
13298 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
13300 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n", gintsts.d32);
13302 + if (gintsts.b.usbreset) {
13303 + DWC_PRINT("Usb Reset In Host Mode\n");
13307 + if (gintsts.b.sofintr) {
13308 + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
13310 + if (gintsts.b.rxstsqlvl) {
13311 + retval |= dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd);
13313 + if (gintsts.b.nptxfempty) {
13314 + retval |= dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd);
13316 + if (gintsts.b.i2cintr) {
13317 + /** @todo Implement i2cintr handler. */
13319 + if (gintsts.b.portintr) {
13320 + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
13322 + if (gintsts.b.hcintr) {
13323 + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
13325 + if (gintsts.b.ptxfempty) {
13326 + retval |= dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd);
13329 +# ifndef DEBUG_SOF
13330 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
13333 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Finished Servicing Interrupts\n");
13334 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
13335 + dwc_read_reg32(&global_regs->gintsts));
13336 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
13337 + dwc_read_reg32(&global_regs->gintmsk));
13342 +# ifndef DEBUG_SOF
13343 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
13345 + DWC_DEBUGPL(DBG_HCD, "\n");
13350 + S3C2410X_CLEAR_EINTPEND();
13355 +#ifdef DWC_TRACK_MISSED_SOFS
13356 +#warning Compiling code to track missed SOFs
13357 +#define FRAME_NUM_ARRAY_SIZE 1000
13359 + * This function is for debug only.
13361 +static inline void track_missed_sofs(uint16_t curr_frame_number)
13363 + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
13364 + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
13365 + static int frame_num_idx = 0;
13366 + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
13367 + static int dumped_frame_num_array = 0;
13369 + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
13370 + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) != curr_frame_number) {
13371 + frame_num_array[frame_num_idx] = curr_frame_number;
13372 + last_frame_num_array[frame_num_idx++] = last_frame_num;
13374 + } else if (!dumped_frame_num_array) {
13376 + printk(KERN_EMERG USB_DWC "Frame Last Frame\n");
13377 + printk(KERN_EMERG USB_DWC "----- ----------\n");
13378 + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
13379 + printk(KERN_EMERG USB_DWC "0x%04x 0x%04x\n",
13380 + frame_num_array[i], last_frame_num_array[i]);
13382 + dumped_frame_num_array = 1;
13384 + last_frame_num = curr_frame_number;
13389 + * Handles the start-of-frame interrupt in host mode. Non-periodic
13390 + * transactions may be queued to the DWC_otg controller for the current
13391 + * (micro)frame. Periodic transactions may be queued to the controller for the
13392 + * next (micro)frame.
13394 +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t *hcd)
13396 + hfnum_data_t hfnum;
13397 + struct list_head *qh_entry;
13398 + dwc_otg_qh_t *qh;
13399 + dwc_otg_transaction_type_e tr_type;
13400 + gintsts_data_t gintsts = {.d32 = 0};
13402 + hfnum.d32 = dwc_read_reg32(&hcd->core_if->host_if->host_global_regs->hfnum);
13405 + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
13407 + hcd->frame_number = hfnum.b.frnum;
13410 + hcd->frrem_accum += hfnum.b.frrem;
13411 + hcd->frrem_samples++;
13414 +#ifdef DWC_TRACK_MISSED_SOFS
13415 + track_missed_sofs(hcd->frame_number);
13418 + /* Determine whether any periodic QHs should be executed. */
13419 + qh_entry = hcd->periodic_sched_inactive.next;
13420 + while (qh_entry != &hcd->periodic_sched_inactive) {
13421 + qh = list_entry(qh_entry, dwc_otg_qh_t, qh_list_entry);
13422 + qh_entry = qh_entry->next;
13423 + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
13425 + * Move QH to the ready list to be executed next
13428 + list_move(&qh->qh_list_entry, &hcd->periodic_sched_ready);
13432 + tr_type = dwc_otg_hcd_select_transactions(hcd);
13433 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
13434 + dwc_otg_hcd_queue_transactions(hcd, tr_type);
13437 + /* Clear interrupt */
13438 + gintsts.b.sofintr = 1;
13439 + dwc_write_reg32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
13444 +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
13445 + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
13446 + * memory if the DWC_otg controller is operating in Slave mode. */
13447 +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *dwc_otg_hcd)
13449 + host_grxsts_data_t grxsts;
13450 + dwc_hc_t *hc = NULL;
13452 + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
13454 + grxsts.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
13456 + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
13458 + /* Packet Status */
13459 + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
13460 + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
13461 + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid, hc->data_pid_start);
13462 + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
13464 + switch (grxsts.b.pktsts) {
13465 + case DWC_GRXSTS_PKTSTS_IN:
13466 + /* Read the data into the host buffer. */
13467 + if (grxsts.b.bcnt > 0) {
13468 + dwc_otg_read_packet(dwc_otg_hcd->core_if,
13472 + /* Update the HC fields for the next packet received. */
13473 + hc->xfer_count += grxsts.b.bcnt;
13474 + hc->xfer_buff += grxsts.b.bcnt;
13477 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
13478 + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
13479 + case DWC_GRXSTS_PKTSTS_CH_HALTED:
13480 + /* Handled in interrupt, just ignore data */
13483 + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n", grxsts.b.pktsts);
13490 +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
13491 + * data packets may be written to the FIFO for OUT transfers. More requests
13492 + * may be written to the non-periodic request queue for IN transfers. This
13493 + * interrupt is enabled only in Slave mode. */
13494 +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd)
13496 + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
13497 + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
13498 + DWC_OTG_TRANSACTION_NON_PERIODIC);
13502 +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
13503 + * packets may be written to the FIFO for OUT transfers. More requests may be
13504 + * written to the periodic request queue for IN transfers. This interrupt is
13505 + * enabled only in Slave mode. */
13506 +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd)
13508 + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
13509 + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
13510 + DWC_OTG_TRANSACTION_PERIODIC);
13514 +/** There are multiple conditions that can cause a port interrupt. This function
13515 + * determines which interrupt conditions have occurred and handles them
13516 + * appropriately. */
13517 +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t *dwc_otg_hcd)
13520 + hprt0_data_t hprt0;
13521 + hprt0_data_t hprt0_modify;
13523 + hprt0.d32 = dwc_read_reg32(dwc_otg_hcd->core_if->host_if->hprt0);
13524 + hprt0_modify.d32 = dwc_read_reg32(dwc_otg_hcd->core_if->host_if->hprt0);
13526 + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
13529 + hprt0_modify.b.prtena = 0;
13530 + hprt0_modify.b.prtconndet = 0;
13531 + hprt0_modify.b.prtenchng = 0;
13532 + hprt0_modify.b.prtovrcurrchng = 0;
13534 + /* Port Connect Detected
13535 + * Set flag and clear if detected */
13536 + if (hprt0.b.prtconndet) {
13537 + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
13538 + "Port Connect Detected--\n", hprt0.d32);
13539 + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
13540 + dwc_otg_hcd->flags.b.port_connect_status = 1;
13541 + hprt0_modify.b.prtconndet = 1;
13543 + /* B-Device has connected, Delete the connection timer. */
13544 + del_timer( &dwc_otg_hcd->conn_timer );
13546 + /* The Hub driver asserts a reset when it sees port connect
13547 + * status change flag */
13551 + /* Port Enable Changed
13552 + * Clear if detected - Set internal flag if disabled */
13553 + if (hprt0.b.prtenchng) {
13554 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
13555 + "Port Enable Changed--\n", hprt0.d32);
13556 + hprt0_modify.b.prtenchng = 1;
13557 + if (hprt0.b.prtena == 1) {
13558 + int do_reset = 0;
13559 + dwc_otg_core_params_t *params = dwc_otg_hcd->core_if->core_params;
13560 + dwc_otg_core_global_regs_t *global_regs = dwc_otg_hcd->core_if->core_global_regs;
13561 + dwc_otg_host_if_t *host_if = dwc_otg_hcd->core_if->host_if;
13563 + /* Check if we need to adjust the PHY clock speed for
13564 + * low power and adjust it */
13565 + if (params->host_support_fs_ls_low_power) {
13566 + gusbcfg_data_t usbcfg;
13568 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
13570 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED ||
13571 + hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
13575 + hcfg_data_t hcfg;
13576 + if (usbcfg.b.phylpwrclksel == 0) {
13577 + /* Set PHY low power clock select for FS/LS devices */
13578 + usbcfg.b.phylpwrclksel = 1;
13579 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
13583 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
13585 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED &&
13586 + params->host_ls_low_power_phy_clk ==
13587 + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ) {
13589 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
13590 + if (hcfg.b.fslspclksel != DWC_HCFG_6_MHZ) {
13591 + hcfg.b.fslspclksel = DWC_HCFG_6_MHZ;
13592 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
13598 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 48 MHz ()\n");
13599 + if (hcfg.b.fslspclksel != DWC_HCFG_48_MHZ) {
13600 + hcfg.b.fslspclksel = DWC_HCFG_48_MHZ;
13601 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
13610 + if (usbcfg.b.phylpwrclksel == 1) {
13611 + usbcfg.b.phylpwrclksel = 0;
13612 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
13618 + tasklet_schedule(dwc_otg_hcd->reset_tasklet);
13623 + /* Port has been enabled set the reset change flag */
13624 + dwc_otg_hcd->flags.b.port_reset_change = 1;
13627 + dwc_otg_hcd->flags.b.port_enable_change = 1;
13632 + /** Overcurrent Change Interrupt */
13633 + if (hprt0.b.prtovrcurrchng) {
13634 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
13635 + "Port Overcurrent Changed--\n", hprt0.d32);
13636 + dwc_otg_hcd->flags.b.port_over_current_change = 1;
13637 + hprt0_modify.b.prtovrcurrchng = 1;
13641 + /* Clear Port Interrupts */
13642 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
13647 +/** This interrupt indicates that one or more host channels has a pending
13648 + * interrupt. There are multiple conditions that can cause each host channel
13649 + * interrupt. This function determines which conditions have occurred for each
13650 + * host channel interrupt and handles them appropriately. */
13651 +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t *dwc_otg_hcd)
13655 + haint_data_t haint;
13657 + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
13660 + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
13662 + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
13663 + if (haint.b2.chint & (1 << i)) {
13664 + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
13671 +/* Macro used to clear one channel interrupt */
13672 +#define clear_hc_int(_hc_regs_, _intr_) \
13674 + hcint_data_t hcint_clear = {.d32 = 0}; \
13675 + hcint_clear.b._intr_ = 1; \
13676 + dwc_write_reg32(&(_hc_regs_)->hcint, hcint_clear.d32); \
13680 + * Macro used to disable one channel interrupt. Channel interrupts are
13681 + * disabled when the channel is halted or released by the interrupt handler.
13682 + * There is no need to handle further interrupts of that type until the
13683 + * channel is re-assigned. In fact, subsequent handling may cause crashes
13684 + * because the channel structures are cleaned up when the channel is released.
13686 +#define disable_hc_int(_hc_regs_, _intr_) \
13688 + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
13689 + hcintmsk.b._intr_ = 1; \
13690 + dwc_modify_reg32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
13694 + * Gets the actual length of a transfer after the transfer halts. _halt_status
13695 + * holds the reason for the halt.
13697 + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
13698 + * *short_read is set to 1 upon return if less than the requested
13699 + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
13700 + * return. short_read may also be NULL on entry, in which case it remains
13703 +static uint32_t get_actual_xfer_length(dwc_hc_t *hc,
13704 + dwc_otg_hc_regs_t *hc_regs,
13705 + dwc_otg_qtd_t *qtd,
13706 + dwc_otg_halt_status_e halt_status,
13709 + hctsiz_data_t hctsiz;
13712 + if (short_read != NULL) {
13715 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
13717 + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
13718 + if (hc->ep_is_in) {
13719 + length = hc->xfer_len - hctsiz.b.xfersize;
13720 + if (short_read != NULL) {
13721 + *short_read = (hctsiz.b.xfersize != 0);
13723 + } else if (hc->qh->do_split) {
13724 + length = qtd->ssplit_out_xfer_count;
13726 + length = hc->xfer_len;
13730 + * Must use the hctsiz.pktcnt field to determine how much data
13731 + * has been transferred. This field reflects the number of
13732 + * packets that have been transferred via the USB. This is
13733 + * always an integral number of packets if the transfer was
13734 + * halted before its normal completion. (Can't use the
13735 + * hctsiz.xfersize field because that reflects the number of
13736 + * bytes transferred via the AHB, not the USB).
13738 + length = (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
13745 + * Updates the state of the URB after a Transfer Complete interrupt on the
13746 + * host channel. Updates the actual_length field of the URB based on the
13747 + * number of bytes transferred via the host channel. Sets the URB status
13748 + * if the data transfer is finished.
13750 + * @return 1 if the data transfer specified by the URB is completely finished,
13753 +static int update_urb_state_xfer_comp(dwc_hc_t *hc,
13754 + dwc_otg_hc_regs_t *hc_regs,
13756 + dwc_otg_qtd_t *qtd)
13758 + int xfer_done = 0;
13759 + int short_read = 0;
13760 + int overflow_read=0;
13761 + uint32_t len = 0;
13764 + len = get_actual_xfer_length(hc, hc_regs, qtd,
13765 + DWC_OTG_HC_XFER_COMPLETE,
13768 + /* Data overflow case: by Steven */
13769 + if (len > urb->transfer_buffer_length) {
13770 + len = urb->transfer_buffer_length;
13771 + overflow_read = 1;
13774 + /* non DWORD-aligned buffer case handling. */
13775 + if (((uint32_t)hc->xfer_buff & 0x3) && len && hc->qh->dw_align_buf && hc->ep_is_in) {
13776 + memcpy(urb->transfer_buffer + urb->actual_length, hc->qh->dw_align_buf, len);
13778 + urb->actual_length +=len;
13780 + max_packet = usb_maxpacket(urb->dev, urb->pipe, !usb_pipein(urb->pipe));
13781 + if((len) && usb_pipebulk(urb->pipe) &&
13782 + (urb->transfer_flags & URB_ZERO_PACKET) &&
13783 + (urb->actual_length == urb->transfer_buffer_length) &&
13784 + (!(urb->transfer_buffer_length % max_packet))) {
13785 + } else if (short_read || urb->actual_length == urb->transfer_buffer_length) {
13787 + if (short_read && (urb->transfer_flags & URB_SHORT_NOT_OK)) {
13788 + urb->status = -EREMOTEIO;
13789 + } else if (overflow_read) {
13790 + urb->status = -EOVERFLOW;
13798 + hctsiz_data_t hctsiz;
13799 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
13800 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
13801 + __func__, (hc->ep_is_in ? "IN" : "OUT"), hc->hc_num);
13802 + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
13803 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n", hctsiz.b.xfersize);
13804 + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
13805 + urb->transfer_buffer_length);
13806 + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n", urb->actual_length);
13807 + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
13808 + short_read, xfer_done);
13812 + return xfer_done;
13816 + * Save the starting data toggle for the next transfer. The data toggle is
13817 + * saved in the QH for non-control transfers and it's saved in the QTD for
13818 + * control transfers.
13820 +static void save_data_toggle(dwc_hc_t *hc,
13821 + dwc_otg_hc_regs_t *hc_regs,
13822 + dwc_otg_qtd_t *qtd)
13824 + hctsiz_data_t hctsiz;
13825 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
13827 + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
13828 + dwc_otg_qh_t *qh = hc->qh;
13829 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
13830 + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
13832 + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
13835 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
13836 + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
13838 + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
13844 + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
13845 + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
13846 + * still linked to the QH, the QH is added to the end of the inactive
13847 + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
13848 + * schedule if no more QTDs are linked to the QH.
13850 +static void deactivate_qh(dwc_otg_hcd_t *hcd,
13851 + dwc_otg_qh_t *qh,
13854 + int continue_split = 0;
13855 + dwc_otg_qtd_t *qtd;
13857 + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
13859 + qtd = list_entry(qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
13861 + if (qtd->complete_split) {
13862 + continue_split = 1;
13863 + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
13864 + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
13865 + continue_split = 1;
13869 + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd);
13870 + continue_split = 0;
13873 + qh->channel = NULL;
13874 + qh->qtd_in_process = NULL;
13875 + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
13879 + * Updates the state of an Isochronous URB when the transfer is stopped for
13880 + * any reason. The fields of the current entry in the frame descriptor array
13881 + * are set based on the transfer state and the input _halt_status. Completes
13882 + * the Isochronous URB if all the URB frames have been completed.
13884 + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
13885 + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
13887 +static dwc_otg_halt_status_e
13888 +update_isoc_urb_state(dwc_otg_hcd_t *hcd,
13890 + dwc_otg_hc_regs_t *hc_regs,
13891 + dwc_otg_qtd_t *qtd,
13892 + dwc_otg_halt_status_e halt_status)
13894 + struct urb *urb = qtd->urb;
13895 + dwc_otg_halt_status_e ret_val = halt_status;
13896 + struct usb_iso_packet_descriptor *frame_desc;
13898 + frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
13899 + switch (halt_status) {
13900 + case DWC_OTG_HC_XFER_COMPLETE:
13901 + frame_desc->status = 0;
13902 + frame_desc->actual_length =
13903 + get_actual_xfer_length(hc, hc_regs, qtd,
13904 + halt_status, NULL);
13906 + /* non DWORD-aligned buffer case handling. */
13907 + if (frame_desc->actual_length && ((uint32_t)hc->xfer_buff & 0x3) &&
13908 + hc->qh->dw_align_buf && hc->ep_is_in) {
13909 + memcpy(urb->transfer_buffer + frame_desc->offset + qtd->isoc_split_offset,
13910 + hc->qh->dw_align_buf, frame_desc->actual_length);
13915 + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
13916 + printk("DWC_OTG_HC_XFER_FRAME_OVERRUN: %d\n", halt_status);
13917 + urb->error_count++;
13918 + if (hc->ep_is_in) {
13919 + frame_desc->status = -ENOSR;
13921 + frame_desc->status = -ECOMM;
13923 + frame_desc->actual_length = 0;
13925 + case DWC_OTG_HC_XFER_BABBLE_ERR:
13926 + printk("DWC_OTG_HC_XFER_BABBLE_ERR: %d\n", halt_status);
13927 + urb->error_count++;
13928 + frame_desc->status = -EOVERFLOW;
13929 + /* Don't need to update actual_length in this case. */
13931 + case DWC_OTG_HC_XFER_XACT_ERR:
13932 + printk("DWC_OTG_HC_XFER_XACT_ERR: %d\n", halt_status);
13933 + urb->error_count++;
13934 + frame_desc->status = -EPROTO;
13935 + frame_desc->actual_length =
13936 + get_actual_xfer_length(hc, hc_regs, qtd,
13937 + halt_status, NULL);
13939 + /* non DWORD-aligned buffer case handling. */
13940 + if (frame_desc->actual_length && ((uint32_t)hc->xfer_buff & 0x3) &&
13941 + hc->qh->dw_align_buf && hc->ep_is_in) {
13942 + memcpy(urb->transfer_buffer + frame_desc->offset + qtd->isoc_split_offset,
13943 + hc->qh->dw_align_buf, frame_desc->actual_length);
13949 + DWC_ERROR("%s: Unhandled _halt_status (%d)\n", __func__,
13955 + if (++qtd->isoc_frame_index == urb->number_of_packets) {
13957 + * urb->status is not used for isoc transfers.
13958 + * The individual frame_desc statuses are used instead.
13960 + dwc_otg_hcd_complete_urb(hcd, urb, 0);
13961 + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
13963 + ret_val = DWC_OTG_HC_XFER_COMPLETE;
13970 + * Releases a host channel for use by other transfers. Attempts to select and
13971 + * queue more transactions since at least one host channel is available.
13973 + * @param hcd The HCD state structure.
13974 + * @param hc The host channel to release.
13975 + * @param qtd The QTD associated with the host channel. This QTD may be freed
13976 + * if the transfer is complete or an error has occurred.
13977 + * @param halt_status Reason the channel is being released. This status
13978 + * determines the actions taken by this function.
13980 +static void release_channel(dwc_otg_hcd_t *hcd,
13982 + dwc_otg_qtd_t *qtd,
13983 + dwc_otg_halt_status_e halt_status)
13985 + dwc_otg_transaction_type_e tr_type;
13988 + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d\n",
13989 + __func__, hc->hc_num, halt_status);
13991 + switch (halt_status) {
13992 + case DWC_OTG_HC_XFER_URB_COMPLETE:
13995 + case DWC_OTG_HC_XFER_AHB_ERR:
13996 + case DWC_OTG_HC_XFER_STALL:
13997 + case DWC_OTG_HC_XFER_BABBLE_ERR:
14000 + case DWC_OTG_HC_XFER_XACT_ERR:
14001 + if (qtd->error_count >= 3) {
14002 + DWC_DEBUGPL(DBG_HCDV, " Complete URB with transaction error\n");
14004 + qtd->urb->status = -EPROTO;
14005 + dwc_otg_hcd_complete_urb(hcd, qtd->urb, -EPROTO);
14010 + case DWC_OTG_HC_XFER_URB_DEQUEUE:
14012 + * The QTD has already been removed and the QH has been
14013 + * deactivated. Don't want to do anything except release the
14014 + * host channel and try to queue more transfers.
14017 + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
14018 + DWC_ERROR("%s: No halt_status, channel %d\n", __func__, hc->hc_num);
14026 + deactivate_qh(hcd, hc->qh, free_qtd);
14030 + * Release the host channel for use by other transfers. The cleanup
14031 + * function clears the channel interrupt enables and conditions, so
14032 + * there's no need to clear the Channel Halted interrupt separately.
14034 + dwc_otg_hc_cleanup(hcd->core_if, hc);
14035 + list_add_tail(&hc->hc_list_entry, &hcd->free_hc_list);
14037 + switch (hc->ep_type) {
14038 + case DWC_OTG_EP_TYPE_CONTROL:
14039 + case DWC_OTG_EP_TYPE_BULK:
14040 + hcd->non_periodic_channels--;
14045 + * Don't release reservations for periodic channels here.
14046 + * That's done when a periodic transfer is descheduled (i.e.
14047 + * when the QH is removed from the periodic schedule).
14052 + /* Try to queue more transfers now that there's a free channel. */
14053 + tr_type = dwc_otg_hcd_select_transactions(hcd);
14054 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
14055 + dwc_otg_hcd_queue_transactions(hcd, tr_type);
14060 + * Halts a host channel. If the channel cannot be halted immediately because
14061 + * the request queue is full, this function ensures that the FIFO empty
14062 + * interrupt for the appropriate queue is enabled so that the halt request can
14063 + * be queued when there is space in the request queue.
14065 + * This function may also be called in DMA mode. In that case, the channel is
14066 + * simply released since the core always halts the channel automatically in
14069 +static void halt_channel(dwc_otg_hcd_t *hcd,
14071 + dwc_otg_qtd_t *qtd,
14072 + dwc_otg_halt_status_e halt_status)
14074 + if (hcd->core_if->dma_enable) {
14075 + release_channel(hcd, hc, qtd, halt_status);
14079 + /* Slave mode processing... */
14080 + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
14082 + if (hc->halt_on_queue) {
14083 + gintmsk_data_t gintmsk = {.d32 = 0};
14084 + dwc_otg_core_global_regs_t *global_regs;
14085 + global_regs = hcd->core_if->core_global_regs;
14087 + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
14088 + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
14090 + * Make sure the Non-periodic Tx FIFO empty interrupt
14091 + * is enabled so that the non-periodic schedule will
14094 + gintmsk.b.nptxfempty = 1;
14095 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
14098 + * Move the QH from the periodic queued schedule to
14099 + * the periodic assigned schedule. This allows the
14100 + * halt to be queued when the periodic schedule is
14103 + list_move(&hc->qh->qh_list_entry,
14104 + &hcd->periodic_sched_assigned);
14107 + * Make sure the Periodic Tx FIFO Empty interrupt is
14108 + * enabled so that the periodic schedule will be
14111 + gintmsk.b.ptxfempty = 1;
14112 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
14118 + * Performs common cleanup for non-periodic transfers after a Transfer
14119 + * Complete interrupt. This function should be called after any endpoint type
14120 + * specific handling is finished to release the host channel.
14122 +static void complete_non_periodic_xfer(dwc_otg_hcd_t *hcd,
14124 + dwc_otg_hc_regs_t *hc_regs,
14125 + dwc_otg_qtd_t *qtd,
14126 + dwc_otg_halt_status_e halt_status)
14128 + hcint_data_t hcint;
14130 + qtd->error_count = 0;
14132 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
14133 + if (hcint.b.nyet) {
14135 + * Got a NYET on the last transaction of the transfer. This
14136 + * means that the endpoint should be in the PING state at the
14137 + * beginning of the next transfer.
14139 + hc->qh->ping_state = 1;
14140 + clear_hc_int(hc_regs, nyet);
14144 + * Always halt and release the host channel to make it available for
14145 + * more transfers. There may still be more phases for a control
14146 + * transfer or more data packets for a bulk transfer at this point,
14147 + * but the host channel is still halted. A channel will be reassigned
14148 + * to the transfer when the non-periodic schedule is processed after
14149 + * the channel is released. This allows transactions to be queued
14150 + * properly via dwc_otg_hcd_queue_transactions, which also enables the
14151 + * Tx FIFO Empty interrupt if necessary.
14153 + if (hc->ep_is_in) {
14155 + * IN transfers in Slave mode require an explicit disable to
14156 + * halt the channel. (In DMA mode, this call simply releases
14159 + halt_channel(hcd, hc, qtd, halt_status);
14162 + * The channel is automatically disabled by the core for OUT
14163 + * transfers in Slave mode.
14165 + release_channel(hcd, hc, qtd, halt_status);
14170 + * Performs common cleanup for periodic transfers after a Transfer Complete
14171 + * interrupt. This function should be called after any endpoint type specific
14172 + * handling is finished to release the host channel.
14174 +static void complete_periodic_xfer(dwc_otg_hcd_t *hcd,
14176 + dwc_otg_hc_regs_t *hc_regs,
14177 + dwc_otg_qtd_t *qtd,
14178 + dwc_otg_halt_status_e halt_status)
14180 + hctsiz_data_t hctsiz;
14181 + qtd->error_count = 0;
14183 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14184 + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
14185 + /* Core halts channel in these cases. */
14186 + release_channel(hcd, hc, qtd, halt_status);
14188 + /* Flush any outstanding requests from the Tx queue. */
14189 + halt_channel(hcd, hc, qtd, halt_status);
14194 + * Handles a host channel Transfer Complete interrupt. This handler may be
14195 + * called in either DMA mode or Slave mode.
14197 +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t *hcd,
14199 + dwc_otg_hc_regs_t *hc_regs,
14200 + dwc_otg_qtd_t *qtd)
14202 + int urb_xfer_done;
14203 + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
14204 + struct urb *urb = qtd->urb;
14205 + int pipe_type = usb_pipetype(urb->pipe);
14207 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14208 + "Transfer Complete--\n", hc->hc_num);
14211 + * Handle xfer complete on CSPLIT.
14213 + if (hc->qh->do_split) {
14214 + qtd->complete_split = 0;
14217 + /* Update the QTD and URB states. */
14218 + switch (pipe_type) {
14219 + case PIPE_CONTROL:
14220 + switch (qtd->control_phase) {
14221 + case DWC_OTG_CONTROL_SETUP:
14222 + if (urb->transfer_buffer_length > 0) {
14223 + qtd->control_phase = DWC_OTG_CONTROL_DATA;
14225 + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
14227 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
14228 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
14230 + case DWC_OTG_CONTROL_DATA: {
14231 + urb_xfer_done = update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
14232 + if (urb_xfer_done) {
14233 + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
14234 + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
14236 + save_data_toggle(hc, hc_regs, qtd);
14238 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
14241 + case DWC_OTG_CONTROL_STATUS:
14242 + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
14243 + if (urb->status == -EINPROGRESS) {
14246 + dwc_otg_hcd_complete_urb(hcd, urb, urb->status);
14247 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
14251 + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
14254 + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
14255 + urb_xfer_done = update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
14256 + if (urb_xfer_done) {
14257 + dwc_otg_hcd_complete_urb(hcd, urb, urb->status);
14258 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
14260 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
14263 + save_data_toggle(hc, hc_regs, qtd);
14264 + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
14266 + case PIPE_INTERRUPT:
14267 + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
14268 + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
14271 + * Interrupt URB is done on the first transfer complete
14274 + dwc_otg_hcd_complete_urb(hcd, urb, urb->status);
14275 + save_data_toggle(hc, hc_regs, qtd);
14276 + complete_periodic_xfer(hcd, hc, hc_regs, qtd,
14277 + DWC_OTG_HC_XFER_URB_COMPLETE);
14279 + case PIPE_ISOCHRONOUS:
14280 + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
14281 + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
14282 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
14283 + DWC_OTG_HC_XFER_COMPLETE);
14285 + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
14289 + disable_hc_int(hc_regs, xfercompl);
14295 + * Handles a host channel STALL interrupt. This handler may be called in
14296 + * either DMA mode or Slave mode.
14298 +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t *hcd,
14300 + dwc_otg_hc_regs_t *hc_regs,
14301 + dwc_otg_qtd_t *qtd)
14303 + struct urb *urb = qtd->urb;
14304 + int pipe_type = usb_pipetype(urb->pipe);
14306 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14307 + "STALL Received--\n", hc->hc_num);
14309 + if (pipe_type == PIPE_CONTROL) {
14310 + dwc_otg_hcd_complete_urb(hcd, urb, -EPIPE);
14313 + if (pipe_type == PIPE_BULK || pipe_type == PIPE_INTERRUPT) {
14314 + dwc_otg_hcd_complete_urb(hcd, urb, -EPIPE);
14316 + * USB protocol requires resetting the data toggle for bulk
14317 + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
14318 + * setup command is issued to the endpoint. Anticipate the
14319 + * CLEAR_FEATURE command since a STALL has occurred and reset
14320 + * the data toggle now.
14322 + hc->qh->data_toggle = 0;
14325 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
14327 + disable_hc_int(hc_regs, stall);
14333 + * Updates the state of the URB when a transfer has been stopped due to an
14334 + * abnormal condition before the transfer completes. Modifies the
14335 + * actual_length field of the URB to reflect the number of bytes that have
14336 + * actually been transferred via the host channel.
14338 +static void update_urb_state_xfer_intr(dwc_hc_t *hc,
14339 + dwc_otg_hc_regs_t *hc_regs,
14341 + dwc_otg_qtd_t *qtd,
14342 + dwc_otg_halt_status_e halt_status)
14344 + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
14345 + halt_status, NULL);
14346 + urb->actual_length += bytes_transferred;
14350 + hctsiz_data_t hctsiz;
14351 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14352 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
14353 + __func__, (hc->ep_is_in ? "IN" : "OUT"), hc->hc_num);
14354 + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n", hc->start_pkt_count);
14355 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
14356 + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
14357 + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n", bytes_transferred);
14358 + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n", urb->actual_length);
14359 + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
14360 + urb->transfer_buffer_length);
14366 + * Handles a host channel NAK interrupt. This handler may be called in either
14367 + * DMA mode or Slave mode.
14369 +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t *hcd,
14371 + dwc_otg_hc_regs_t *hc_regs,
14372 + dwc_otg_qtd_t *qtd)
14374 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14375 + "NAK Received--\n", hc->hc_num);
14378 + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
14379 + * interrupt. Re-start the SSPLIT transfer.
14381 + if (hc->do_split) {
14382 + if (hc->complete_split) {
14383 + qtd->error_count = 0;
14385 + qtd->complete_split = 0;
14386 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
14387 + goto handle_nak_done;
14390 + switch (usb_pipetype(qtd->urb->pipe)) {
14391 + case PIPE_CONTROL:
14393 + if (hcd->core_if->dma_enable && hc->ep_is_in) {
14395 + * NAK interrupts are enabled on bulk/control IN
14396 + * transfers in DMA mode for the sole purpose of
14397 + * resetting the error count after a transaction error
14398 + * occurs. The core will continue transferring data.
14400 + qtd->error_count = 0;
14401 + goto handle_nak_done;
14405 + * NAK interrupts normally occur during OUT transfers in DMA
14406 + * or Slave mode. For IN transfers, more requests will be
14407 + * queued as request queue space is available.
14409 + qtd->error_count = 0;
14411 + if (!hc->qh->ping_state) {
14412 + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb,
14413 + qtd, DWC_OTG_HC_XFER_NAK);
14414 + save_data_toggle(hc, hc_regs, qtd);
14415 + if (qtd->urb->dev->speed == USB_SPEED_HIGH) {
14416 + hc->qh->ping_state = 1;
14421 + * Halt the channel so the transfer can be re-started from
14422 + * the appropriate point or the PING protocol will
14423 + * start/continue.
14425 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
14427 + case PIPE_INTERRUPT:
14428 + qtd->error_count = 0;
14429 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
14431 + case PIPE_ISOCHRONOUS:
14432 + /* Should never get called for isochronous transfers. */
14438 + disable_hc_int(hc_regs, nak);
14444 + * Handles a host channel ACK interrupt. This interrupt is enabled when
14445 + * performing the PING protocol in Slave mode, when errors occur during
14446 + * either Slave mode or DMA mode, and during Start Split transactions.
14448 +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t *hcd,
14450 + dwc_otg_hc_regs_t *hc_regs,
14451 + dwc_otg_qtd_t *qtd)
14453 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14454 + "ACK Received--\n", hc->hc_num);
14456 + if (hc->do_split) {
14458 + * Handle ACK on SSPLIT.
14459 + * ACK should not occur in CSPLIT.
14461 + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
14462 + qtd->ssplit_out_xfer_count = hc->xfer_len;
14464 + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
14465 + /* Don't need complete for isochronous out transfers. */
14466 + qtd->complete_split = 1;
14470 + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
14471 + switch (hc->xact_pos) {
14472 + case DWC_HCSPLIT_XACTPOS_ALL:
14474 + case DWC_HCSPLIT_XACTPOS_END:
14475 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
14476 + qtd->isoc_split_offset = 0;
14478 + case DWC_HCSPLIT_XACTPOS_BEGIN:
14479 + case DWC_HCSPLIT_XACTPOS_MID:
14481 + * For BEGIN or MID, calculate the length for
14482 + * the next microframe to determine the correct
14483 + * SSPLIT token, either MID or END.
14486 + struct usb_iso_packet_descriptor *frame_desc;
14488 + frame_desc = &qtd->urb->iso_frame_desc[qtd->isoc_frame_index];
14489 + qtd->isoc_split_offset += 188;
14491 + if ((frame_desc->length - qtd->isoc_split_offset) <= 188) {
14492 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_END;
14494 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_MID;
14501 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
14504 + qtd->error_count = 0;
14506 + if (hc->qh->ping_state) {
14507 + hc->qh->ping_state = 0;
14509 + * Halt the channel so the transfer can be re-started
14510 + * from the appropriate point. This only happens in
14511 + * Slave mode. In DMA mode, the ping_state is cleared
14512 + * when the transfer is started because the core
14513 + * automatically executes the PING, then the transfer.
14515 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
14520 + * If the ACK occurred when _not_ in the PING state, let the channel
14521 + * continue transferring data after clearing the error count.
14524 + disable_hc_int(hc_regs, ack);
14530 + * Handles a host channel NYET interrupt. This interrupt should only occur on
14531 + * Bulk and Control OUT endpoints and for complete split transactions. If a
14532 + * NYET occurs at the same time as a Transfer Complete interrupt, it is
14533 + * handled in the xfercomp interrupt handler, not here. This handler may be
14534 + * called in either DMA mode or Slave mode.
14536 +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t *hcd,
14538 + dwc_otg_hc_regs_t *hc_regs,
14539 + dwc_otg_qtd_t *qtd)
14541 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14542 + "NYET Received--\n", hc->hc_num);
14546 + * re-do the CSPLIT immediately on non-periodic
14548 + if (hc->do_split && hc->complete_split) {
14549 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
14550 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
14551 + int frnum = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(hcd));
14553 + if (dwc_full_frame_num(frnum) !=
14554 + dwc_full_frame_num(hc->qh->sched_frame)) {
14556 + * No longer in the same full speed frame.
14557 + * Treat this as a transaction error.
14560 + /** @todo Fix system performance so this can
14561 + * be treated as an error. Right now complete
14562 + * splits cannot be scheduled precisely enough
14563 + * due to other system activity, so this error
14564 + * occurs regularly in Slave mode.
14566 + qtd->error_count++;
14568 + qtd->complete_split = 0;
14569 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
14570 + /** @todo add support for isoc release */
14571 + goto handle_nyet_done;
14575 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
14576 + goto handle_nyet_done;
14579 + hc->qh->ping_state = 1;
14580 + qtd->error_count = 0;
14582 + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
14583 + DWC_OTG_HC_XFER_NYET);
14584 + save_data_toggle(hc, hc_regs, qtd);
14587 + * Halt the channel and re-start the transfer so the PING
14588 + * protocol will start.
14590 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
14593 + disable_hc_int(hc_regs, nyet);
14598 + * Handles a host channel babble interrupt. This handler may be called in
14599 + * either DMA mode or Slave mode.
14601 +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t *hcd,
14603 + dwc_otg_hc_regs_t *hc_regs,
14604 + dwc_otg_qtd_t *qtd)
14606 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14607 + "Babble Error--\n", hc->hc_num);
14608 + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
14609 + dwc_otg_hcd_complete_urb(hcd, qtd->urb, -EOVERFLOW);
14610 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
14612 + dwc_otg_halt_status_e halt_status;
14613 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
14614 + DWC_OTG_HC_XFER_BABBLE_ERR);
14615 + halt_channel(hcd, hc, qtd, halt_status);
14617 + disable_hc_int(hc_regs, bblerr);
14622 + * Handles a host channel AHB error interrupt. This handler is only called in
14625 +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t *hcd,
14627 + dwc_otg_hc_regs_t *hc_regs,
14628 + dwc_otg_qtd_t *qtd)
14630 + hcchar_data_t hcchar;
14631 + hcsplt_data_t hcsplt;
14632 + hctsiz_data_t hctsiz;
14634 + struct urb *urb = qtd->urb;
14636 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14637 + "AHB Error--\n", hc->hc_num);
14639 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
14640 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
14641 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14642 + hcdma = dwc_read_reg32(&hc_regs->hcdma);
14644 + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
14645 + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
14646 + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
14647 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
14648 + DWC_ERROR(" Device address: %d\n", usb_pipedevice(urb->pipe));
14649 + DWC_ERROR(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
14650 + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
14651 + DWC_ERROR(" Endpoint type: %s\n",
14652 + ({char *pipetype;
14653 + switch (usb_pipetype(urb->pipe)) {
14654 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
14655 + case PIPE_BULK: pipetype = "BULK"; break;
14656 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
14657 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
14658 + default: pipetype = "UNKNOWN"; break;
14660 + DWC_ERROR(" Speed: %s\n",
14662 + switch (urb->dev->speed) {
14663 + case USB_SPEED_HIGH: speed = "HIGH"; break;
14664 + case USB_SPEED_FULL: speed = "FULL"; break;
14665 + case USB_SPEED_LOW: speed = "LOW"; break;
14666 + default: speed = "UNKNOWN"; break;
14668 + DWC_ERROR(" Max packet size: %d\n",
14669 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
14670 + DWC_ERROR(" Data buffer length: %d\n", urb->transfer_buffer_length);
14671 + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
14672 + urb->transfer_buffer, (void *)urb->transfer_dma);
14673 + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
14674 + urb->setup_packet, (void *)urb->setup_dma);
14675 + DWC_ERROR(" Interval: %d\n", urb->interval);
14677 + dwc_otg_hcd_complete_urb(hcd, urb, -EIO);
14680 + * Force a channel halt. Don't call halt_channel because that won't
14681 + * write to the HCCHARn register in DMA mode to force the halt.
14683 + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
14685 + disable_hc_int(hc_regs, ahberr);
14690 + * Handles a host channel transaction error interrupt. This handler may be
14691 + * called in either DMA mode or Slave mode.
14693 +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t *hcd,
14695 + dwc_otg_hc_regs_t *hc_regs,
14696 + dwc_otg_qtd_t *qtd)
14698 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14699 + "Transaction Error--\n", hc->hc_num);
14701 + switch (usb_pipetype(qtd->urb->pipe)) {
14702 + case PIPE_CONTROL:
14704 + qtd->error_count++;
14705 + if (!hc->qh->ping_state) {
14706 + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb,
14707 + qtd, DWC_OTG_HC_XFER_XACT_ERR);
14708 + save_data_toggle(hc, hc_regs, qtd);
14709 + if (!hc->ep_is_in && qtd->urb->dev->speed == USB_SPEED_HIGH) {
14710 + hc->qh->ping_state = 1;
14715 + * Halt the channel so the transfer can be re-started from
14716 + * the appropriate point or the PING protocol will start.
14718 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
14720 + case PIPE_INTERRUPT:
14721 + qtd->error_count++;
14722 + if (hc->do_split && hc->complete_split) {
14723 + qtd->complete_split = 0;
14725 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
14727 + case PIPE_ISOCHRONOUS:
14729 + dwc_otg_halt_status_e halt_status;
14730 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
14731 + DWC_OTG_HC_XFER_XACT_ERR);
14733 + halt_channel(hcd, hc, qtd, halt_status);
14738 + disable_hc_int(hc_regs, xacterr);
14744 + * Handles a host channel frame overrun interrupt. This handler may be called
14745 + * in either DMA mode or Slave mode.
14747 +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t *hcd,
14749 + dwc_otg_hc_regs_t *hc_regs,
14750 + dwc_otg_qtd_t *qtd)
14752 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14753 + "Frame Overrun--\n", hc->hc_num);
14755 + switch (usb_pipetype(qtd->urb->pipe)) {
14756 + case PIPE_CONTROL:
14759 + case PIPE_INTERRUPT:
14760 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
14762 + case PIPE_ISOCHRONOUS:
14764 + dwc_otg_halt_status_e halt_status;
14765 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
14766 + DWC_OTG_HC_XFER_FRAME_OVERRUN);
14768 + halt_channel(hcd, hc, qtd, halt_status);
14773 + disable_hc_int(hc_regs, frmovrun);
14779 + * Handles a host channel data toggle error interrupt. This handler may be
14780 + * called in either DMA mode or Slave mode.
14782 +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t *hcd,
14784 + dwc_otg_hc_regs_t *hc_regs,
14785 + dwc_otg_qtd_t *qtd)
14787 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14788 + "Data Toggle Error--\n", hc->hc_num);
14790 + if (hc->ep_is_in) {
14791 + qtd->error_count = 0;
14793 + DWC_ERROR("Data Toggle Error on OUT transfer,"
14794 + "channel %d\n", hc->hc_num);
14797 + disable_hc_int(hc_regs, datatglerr);
14804 + * This function is for debug only. It checks that a valid halt status is set
14805 + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
14806 + * taken and a warning is issued.
14807 + * @return 1 if halt status is ok, 0 otherwise.
14809 +static inline int halt_status_ok(dwc_otg_hcd_t *hcd,
14811 + dwc_otg_hc_regs_t *hc_regs,
14812 + dwc_otg_qtd_t *qtd)
14814 + hcchar_data_t hcchar;
14815 + hctsiz_data_t hctsiz;
14816 + hcint_data_t hcint;
14817 + hcintmsk_data_t hcintmsk;
14818 + hcsplt_data_t hcsplt;
14820 + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
14822 + * This code is here only as a check. This condition should
14823 + * never happen. Ignore the halt if it does occur.
14825 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
14826 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14827 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
14828 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
14829 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
14830 + DWC_WARN("%s: hc->halt_status == DWC_OTG"
14831 + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
14832 + "hcint 0x%08x, hcintmsk 0x%08x, "
14833 + "hcsplt 0x%08x, qtd->complete_split %d\n",
14834 + __func__, hc->hc_num, hcchar.d32, hctsiz.d32,
14835 + hcint.d32, hcintmsk.d32,
14836 + hcsplt.d32, qtd->complete_split);
14838 + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
14839 + __func__, hc->hc_num);
14841 + clear_hc_int(hc_regs, chhltd);
14846 + * This code is here only as a check. hcchar.chdis should
14847 + * never be set when the halt interrupt occurs. Halt the
14848 + * channel again if it does occur.
14850 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
14851 + if (hcchar.b.chdis) {
14852 + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
14853 + "hcchar 0x%08x, trying to halt again\n",
14854 + __func__, hcchar.d32);
14855 + clear_hc_int(hc_regs, chhltd);
14856 + hc->halt_pending = 0;
14857 + halt_channel(hcd, hc, qtd, hc->halt_status);
14866 + * Handles a host Channel Halted interrupt in DMA mode. This handler
14867 + * determines the reason the channel halted and proceeds accordingly.
14869 +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t *hcd,
14871 + dwc_otg_hc_regs_t *hc_regs,
14872 + dwc_otg_qtd_t *qtd)
14874 + hcint_data_t hcint;
14875 + hcintmsk_data_t hcintmsk;
14876 + int out_nak_enh = 0;
14878 + /* For core with OUT NAK enhancement, the flow for high-
14879 + * speed CONTROL/BULK OUT is handled a little differently.
14881 + if (hcd->core_if->snpsid >= 0x4F54271A) {
14882 + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
14883 + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
14884 + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
14885 + printk(KERN_DEBUG "OUT NAK enhancement enabled\n");
14888 + printk(KERN_DEBUG "OUT NAK enhancement disabled, not HS Ctrl/Bulk OUT EP\n");
14891 +// printk(KERN_DEBUG "OUT NAK enhancement disabled, no core support\n");
14894 + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
14895 + hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
14897 + * Just release the channel. A dequeue can happen on a
14898 + * transfer timeout. In the case of an AHB Error, the channel
14899 + * was forced to halt because there's no way to gracefully
14902 + release_channel(hcd, hc, qtd, hc->halt_status);
14906 + /* Read the HCINTn register to determine the cause for the halt. */
14907 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
14908 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
14910 + if (hcint.b.xfercomp) {
14911 + /** @todo This is here because of a possible hardware bug. Spec
14912 + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
14913 + * interrupt w/ACK bit set should occur, but I only see the
14914 + * XFERCOMP bit, even with it masked out. This is a workaround
14915 + * for that behavior. Should fix this when hardware is fixed.
14917 + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
14918 + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
14920 + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
14921 + } else if (hcint.b.stall) {
14922 + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
14923 + } else if (hcint.b.xacterr) {
14924 + if (out_nak_enh) {
14925 + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
14926 + printk(KERN_DEBUG "XactErr with NYET/NAK/ACK\n");
14927 + qtd->error_count = 0;
14929 + printk(KERN_DEBUG "XactErr without NYET/NAK/ACK\n");
14934 + * Must handle xacterr before nak or ack. Could get a xacterr
14935 + * at the same time as either of these on a BULK/CONTROL OUT
14936 + * that started with a PING. The xacterr takes precedence.
14938 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
14939 + } else if (!out_nak_enh) {
14940 + if (hcint.b.nyet) {
14942 + * Must handle nyet before nak or ack. Could get a nyet at the
14943 + * same time as either of those on a BULK/CONTROL OUT that
14944 + * started with a PING. The nyet takes precedence.
14946 + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
14947 + } else if (hcint.b.bblerr) {
14948 + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
14949 + } else if (hcint.b.frmovrun) {
14950 + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
14951 + } else if (hcint.b.nak && !hcintmsk.b.nak) {
14953 + * If nak is not masked, it's because a non-split IN transfer
14954 + * is in an error state. In that case, the nak is handled by
14955 + * the nak interrupt handler, not here. Handle nak here for
14956 + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
14957 + * rewinding the buffer pointer.
14959 + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
14960 + } else if (hcint.b.ack && !hcintmsk.b.ack) {
14962 + * If ack is not masked, it's because a non-split IN transfer
14963 + * is in an error state. In that case, the ack is handled by
14964 + * the ack interrupt handler, not here. Handle ack here for
14965 + * split transfers. Start splits halt on ACK.
14967 + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
14969 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
14970 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
14972 + * A periodic transfer halted with no other channel
14973 + * interrupts set. Assume it was halted by the core
14974 + * because it could not be completed in its scheduled
14978 + DWC_PRINT("%s: Halt channel %d (assume incomplete periodic transfer)\n",
14979 + __func__, hc->hc_num);
14981 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
14983 + DWC_ERROR("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
14984 + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
14985 + __func__, hc->hc_num, hcint.d32,
14986 + dwc_read_reg32(&hcd->core_if->core_global_regs->gintsts));
14990 + printk(KERN_DEBUG "NYET/NAK/ACK/other in non-error case, 0x%08x\n", hcint.d32);
14995 + * Handles a host channel Channel Halted interrupt.
14997 + * In slave mode, this handler is called only when the driver specifically
14998 + * requests a halt. This occurs during handling other host channel interrupts
14999 + * (e.g. nak, xacterr, stall, nyet, etc.).
15001 + * In DMA mode, this is the interrupt that occurs when the core has finished
15002 + * processing a transfer on a channel. Other host channel interrupts (except
15003 + * ahberr) are disabled in DMA mode.
15005 +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t *hcd,
15007 + dwc_otg_hc_regs_t *hc_regs,
15008 + dwc_otg_qtd_t *qtd)
15010 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15011 + "Channel Halted--\n", hc->hc_num);
15013 + if (hcd->core_if->dma_enable) {
15014 + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
15017 + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
15021 + release_channel(hcd, hc, qtd, hc->halt_status);
15027 +/** Handles interrupt for a specific Host Channel */
15028 +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t *dwc_otg_hcd, uint32_t num)
15031 + hcint_data_t hcint;
15032 + hcintmsk_data_t hcintmsk;
15034 + dwc_otg_hc_regs_t *hc_regs;
15035 + dwc_otg_qtd_t *qtd;
15037 + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
15039 + hc = dwc_otg_hcd->hc_ptr_array[num];
15040 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
15041 + qtd = list_entry(hc->qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
15043 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
15044 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
15045 + DWC_DEBUGPL(DBG_HCDV, " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
15046 + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
15047 + hcint.d32 = hcint.d32 & hcintmsk.d32;
15049 + if (!dwc_otg_hcd->core_if->dma_enable) {
15050 + if (hcint.b.chhltd && hcint.d32 != 0x2) {
15051 + hcint.b.chhltd = 0;
15055 + if (hcint.b.xfercomp) {
15056 + retval |= handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15058 + * If NYET occurred at same time as Xfer Complete, the NYET is
15059 + * handled by the Xfer Complete interrupt handler. Don't want
15060 + * to call the NYET interrupt handler in this case.
15062 + hcint.b.nyet = 0;
15064 + if (hcint.b.chhltd) {
15065 + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15067 + if (hcint.b.ahberr) {
15068 + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15070 + if (hcint.b.stall) {
15071 + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15073 + if (hcint.b.nak) {
15074 + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15076 + if (hcint.b.ack) {
15077 + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15079 + if (hcint.b.nyet) {
15080 + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15082 + if (hcint.b.xacterr) {
15083 + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15085 + if (hcint.b.bblerr) {
15086 + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15088 + if (hcint.b.frmovrun) {
15089 + retval |= handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15091 + if (hcint.b.datatglerr) {
15092 + retval |= handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15098 +#endif /* DWC_DEVICE_ONLY */
15099 diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
15100 new file mode 100644
15101 index 0000000..cfb1f16
15103 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
15105 +/* ==========================================================================
15106 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd_queue.c $
15107 + * $Revision: 1.5 $
15108 + * $Date: 2008-12-15 06:51:32 $
15109 + * $Change: 537387 $
15111 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
15112 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
15113 + * otherwise expressly agreed to in writing between Synopsys and you.
15115 + * The Software IS NOT an item of Licensed Software or Licensed Product under
15116 + * any End User Software License Agreement or Agreement for Licensed Product
15117 + * with Synopsys or any supplement thereto. You are permitted to use and
15118 + * redistribute this Software in source and binary forms, with or without
15119 + * modification, provided that redistributions of source code must retain this
15120 + * notice. You may not view, use, disclose, copy or distribute this file or
15121 + * any information contained herein except pursuant to this license grant from
15122 + * Synopsys. If you do not agree with this notice, including the disclaimer
15123 + * below, then you are not authorized to use the Software.
15125 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
15126 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15127 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15128 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
15129 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15130 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
15131 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
15132 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
15133 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15134 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
15136 + * ========================================================================== */
15137 +#ifndef DWC_DEVICE_ONLY
15142 + * This file contains the functions to manage Queue Heads and Queue
15143 + * Transfer Descriptors.
15145 +#include <linux/kernel.h>
15146 +#include <linux/module.h>
15147 +#include <linux/moduleparam.h>
15148 +#include <linux/init.h>
15149 +#include <linux/device.h>
15150 +#include <linux/errno.h>
15151 +#include <linux/list.h>
15152 +#include <linux/interrupt.h>
15153 +#include <linux/string.h>
15154 +#include <linux/dma-mapping.h>
15156 +#include "dwc_otg_driver.h"
15157 +#include "dwc_otg_hcd.h"
15158 +#include "dwc_otg_regs.h"
15161 + * This function allocates and initializes a QH.
15163 + * @param hcd The HCD state structure for the DWC OTG controller.
15164 + * @param[in] urb Holds the information about the device/endpoint that we need
15165 + * to initialize the QH.
15167 + * @return Returns pointer to the newly allocated QH, or NULL on error. */
15168 +dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *hcd, struct urb *urb)
15170 + dwc_otg_qh_t *qh;
15172 + /* Allocate memory */
15173 + /** @todo add memflags argument */
15174 + qh = dwc_otg_hcd_qh_alloc ();
15175 + if (qh == NULL) {
15179 + dwc_otg_hcd_qh_init (hcd, qh, urb);
15183 +/** Free each QTD in the QH's QTD-list then free the QH. QH should already be
15184 + * removed from a list. QTD list should already be empty if called from URB
15187 + * @param[in] hcd HCD instance.
15188 + * @param[in] qh The QH to free.
15190 +void dwc_otg_hcd_qh_free (dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15192 + dwc_otg_qtd_t *qtd;
15193 + struct list_head *pos;
15194 + unsigned long flags;
15196 + /* Free each QTD in the QTD list */
15197 + SPIN_LOCK_IRQSAVE(&hcd->lock, flags)
15198 + for (pos = qh->qtd_list.next;
15199 + pos != &qh->qtd_list;
15200 + pos = qh->qtd_list.next)
15203 + qtd = dwc_list_to_qtd (pos);
15204 + dwc_otg_hcd_qtd_free (qtd);
15206 + SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags)
15208 + if (qh->dw_align_buf) {
15209 + dma_free_coherent((dwc_otg_hcd_to_hcd(hcd))->self.controller,
15210 + hcd->core_if->core_params->max_transfer_size,
15211 + qh->dw_align_buf,
15212 + qh->dw_align_buf_dma);
15219 +/** Initializes a QH structure.
15221 + * @param[in] hcd The HCD state structure for the DWC OTG controller.
15222 + * @param[in] qh The QH to init.
15223 + * @param[in] urb Holds the information about the device/endpoint that we need
15224 + * to initialize the QH. */
15225 +#define SCHEDULE_SLOP 10
15226 +void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, struct urb *urb)
15228 + char *speed, *type;
15229 + memset (qh, 0, sizeof (dwc_otg_qh_t));
15231 + /* Initialize QH */
15232 + switch (usb_pipetype(urb->pipe)) {
15233 + case PIPE_CONTROL:
15234 + qh->ep_type = USB_ENDPOINT_XFER_CONTROL;
15237 + qh->ep_type = USB_ENDPOINT_XFER_BULK;
15239 + case PIPE_ISOCHRONOUS:
15240 + qh->ep_type = USB_ENDPOINT_XFER_ISOC;
15242 + case PIPE_INTERRUPT:
15243 + qh->ep_type = USB_ENDPOINT_XFER_INT;
15247 + qh->ep_is_in = usb_pipein(urb->pipe) ? 1 : 0;
15249 + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
15250 + qh->maxp = usb_maxpacket(urb->dev, urb->pipe, !(usb_pipein(urb->pipe)));
15251 + INIT_LIST_HEAD(&qh->qtd_list);
15252 + INIT_LIST_HEAD(&qh->qh_list_entry);
15253 + qh->channel = NULL;
15255 + /* FS/LS Enpoint on HS Hub
15256 + * NOT virtual root hub */
15257 + qh->do_split = 0;
15258 + if (((urb->dev->speed == USB_SPEED_LOW) ||
15259 + (urb->dev->speed == USB_SPEED_FULL)) &&
15260 + (urb->dev->tt) && (urb->dev->tt->hub) && (urb->dev->tt->hub->devnum != 1))
15262 + DWC_DEBUGPL(DBG_HCD, "QH init: EP %d: TT found at hub addr %d, for port %d\n",
15263 + usb_pipeendpoint(urb->pipe), urb->dev->tt->hub->devnum,
15264 + urb->dev->ttport);
15265 + qh->do_split = 1;
15268 + if (qh->ep_type == USB_ENDPOINT_XFER_INT ||
15269 + qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
15270 + /* Compute scheduling parameters once and save them. */
15271 + hprt0_data_t hprt;
15273 + /** @todo Account for split transfers in the bus time. */
15274 + int bytecount = dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
15276 + /* FIXME: work-around patch by Steven */
15277 + qh->usecs = NS_TO_US(usb_calc_bus_time(urb->dev->speed,
15278 + usb_pipein(urb->pipe),
15279 + (qh->ep_type == USB_ENDPOINT_XFER_ISOC),
15282 + /* Start in a slightly future (micro)frame. */
15283 + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
15285 + qh->interval = urb->interval;
15287 + /* Increase interrupt polling rate for debugging. */
15288 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
15289 + qh->interval = 8;
15292 + hprt.d32 = dwc_read_reg32(hcd->core_if->host_if->hprt0);
15293 + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
15294 + ((urb->dev->speed == USB_SPEED_LOW) ||
15295 + (urb->dev->speed == USB_SPEED_FULL))) {
15296 + qh->interval *= 8;
15297 + qh->sched_frame |= 0x7;
15298 + qh->start_split_frame = qh->sched_frame;
15303 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
15304 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
15305 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
15306 + urb->dev->devnum);
15307 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
15308 + usb_pipeendpoint(urb->pipe),
15309 + usb_pipein(urb->pipe) == USB_DIR_IN ? "IN" : "OUT");
15311 + switch(urb->dev->speed) {
15312 + case USB_SPEED_LOW:
15315 + case USB_SPEED_FULL:
15318 + case USB_SPEED_HIGH:
15325 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
15327 + switch (qh->ep_type) {
15328 + case USB_ENDPOINT_XFER_ISOC:
15329 + type = "isochronous";
15331 + case USB_ENDPOINT_XFER_INT:
15332 + type = "interrupt";
15334 + case USB_ENDPOINT_XFER_CONTROL:
15335 + type = "control";
15337 + case USB_ENDPOINT_XFER_BULK:
15344 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n",type);
15347 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
15348 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
15350 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
15354 + qh->dw_align_buf = NULL;
15359 + * Checks that a channel is available for a periodic transfer.
15361 + * @return 0 if successful, negative error code otherise.
15363 +static int periodic_channel_available(dwc_otg_hcd_t *hcd)
15366 + * Currently assuming that there is a dedicated host channnel for each
15367 + * periodic transaction plus at least one host channel for
15368 + * non-periodic transactions.
15371 + int num_channels;
15373 + num_channels = hcd->core_if->core_params->host_channels;
15374 + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels) &&
15375 + (hcd->periodic_channels < num_channels - 1)) {
15379 + DWC_NOTICE("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
15380 + __func__, num_channels, hcd->periodic_channels,
15381 + hcd->non_periodic_channels);
15382 + status = -ENOSPC;
15389 + * Checks that there is sufficient bandwidth for the specified QH in the
15390 + * periodic schedule. For simplicity, this calculation assumes that all the
15391 + * transfers in the periodic schedule may occur in the same (micro)frame.
15393 + * @param hcd The HCD state structure for the DWC OTG controller.
15394 + * @param qh QH containing periodic bandwidth required.
15396 + * @return 0 if successful, negative error code otherwise.
15398 +static int check_periodic_bandwidth(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15401 + uint16_t max_claimed_usecs;
15405 + if (hcd->core_if->core_params->speed == DWC_SPEED_PARAM_HIGH) {
15407 + * High speed mode.
15408 + * Max periodic usecs is 80% x 125 usec = 100 usec.
15410 + max_claimed_usecs = 100 - qh->usecs;
15413 + * Full speed mode.
15414 + * Max periodic usecs is 90% x 1000 usec = 900 usec.
15416 + max_claimed_usecs = 900 - qh->usecs;
15419 + if (hcd->periodic_usecs > max_claimed_usecs) {
15420 + DWC_NOTICE("%s: already claimed usecs %d, required usecs %d\n",
15421 + __func__, hcd->periodic_usecs, qh->usecs);
15422 + status = -ENOSPC;
15429 + * Checks that the max transfer size allowed in a host channel is large enough
15430 + * to handle the maximum data transfer in a single (micro)frame for a periodic
15433 + * @param hcd The HCD state structure for the DWC OTG controller.
15434 + * @param qh QH for a periodic endpoint.
15436 + * @return 0 if successful, negative error code otherwise.
15438 +static int check_max_xfer_size(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15441 + uint32_t max_xfer_size;
15442 + uint32_t max_channel_xfer_size;
15446 + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
15447 + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
15449 + if (max_xfer_size > max_channel_xfer_size) {
15450 + DWC_NOTICE("%s: Periodic xfer length %d > "
15451 + "max xfer length for channel %d\n",
15452 + __func__, max_xfer_size, max_channel_xfer_size);
15453 + status = -ENOSPC;
15460 + * Schedules an interrupt or isochronous transfer in the periodic schedule.
15462 + * @param hcd The HCD state structure for the DWC OTG controller.
15463 + * @param qh QH for the periodic transfer. The QH should already contain the
15464 + * scheduling information.
15466 + * @return 0 if successful, negative error code otherwise.
15468 +static int schedule_periodic(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15472 + status = periodic_channel_available(hcd);
15474 + DWC_NOTICE("%s: No host channel available for periodic "
15475 + "transfer.\n", __func__);
15479 + status = check_periodic_bandwidth(hcd, qh);
15481 + DWC_NOTICE("%s: Insufficient periodic bandwidth for "
15482 + "periodic transfer.\n", __func__);
15486 + status = check_max_xfer_size(hcd, qh);
15488 + DWC_NOTICE("%s: Channel max transfer size too small "
15489 + "for periodic transfer.\n", __func__);
15493 + /* Always start in the inactive schedule. */
15494 + list_add_tail(&qh->qh_list_entry, &hcd->periodic_sched_inactive);
15496 + /* Reserve the periodic channel. */
15497 + hcd->periodic_channels++;
15499 + /* Update claimed usecs per (micro)frame. */
15500 + hcd->periodic_usecs += qh->usecs;
15502 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
15503 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_allocated += qh->usecs / qh->interval;
15504 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
15505 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_int_reqs++;
15506 + DWC_DEBUGPL(DBG_HCD, "Scheduled intr: qh %p, usecs %d, period %d\n",
15507 + qh, qh->usecs, qh->interval);
15509 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_isoc_reqs++;
15510 + DWC_DEBUGPL(DBG_HCD, "Scheduled isoc: qh %p, usecs %d, period %d\n",
15511 + qh, qh->usecs, qh->interval);
15518 + * This function adds a QH to either the non periodic or periodic schedule if
15519 + * it is not already in the schedule. If the QH is already in the schedule, no
15520 + * action is taken.
15522 + * @return 0 if successful, negative error code otherwise.
15524 +int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15526 + unsigned long flags;
15529 + SPIN_LOCK_IRQSAVE(&hcd->lock, flags)
15531 + if (!list_empty(&qh->qh_list_entry)) {
15532 + /* QH already in a schedule. */
15536 + /* Add the new QH to the appropriate schedule */
15537 + if (dwc_qh_is_non_per(qh)) {
15538 + /* Always start in the inactive schedule. */
15539 + list_add_tail(&qh->qh_list_entry, &hcd->non_periodic_sched_inactive);
15541 + status = schedule_periodic(hcd, qh);
15545 + SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags)
15551 + * Removes an interrupt or isochronous transfer from the periodic schedule.
15553 + * @param hcd The HCD state structure for the DWC OTG controller.
15554 + * @param qh QH for the periodic transfer.
15556 +static void deschedule_periodic(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15558 + list_del_init(&qh->qh_list_entry);
15560 + /* Release the periodic channel reservation. */
15561 + hcd->periodic_channels--;
15563 + /* Update claimed usecs per (micro)frame. */
15564 + hcd->periodic_usecs -= qh->usecs;
15566 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
15567 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_allocated -= qh->usecs / qh->interval;
15569 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
15570 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_int_reqs--;
15571 + DWC_DEBUGPL(DBG_HCD, "Descheduled intr: qh %p, usecs %d, period %d\n",
15572 + qh, qh->usecs, qh->interval);
15574 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_isoc_reqs--;
15575 + DWC_DEBUGPL(DBG_HCD, "Descheduled isoc: qh %p, usecs %d, period %d\n",
15576 + qh, qh->usecs, qh->interval);
15581 + * Removes a QH from either the non-periodic or periodic schedule. Memory is
15584 + * @param[in] hcd The HCD state structure.
15585 + * @param[in] qh QH to remove from schedule. */
15586 +void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15588 + unsigned long flags;
15590 + SPIN_LOCK_IRQSAVE(&hcd->lock, flags);
15592 + if (list_empty(&qh->qh_list_entry)) {
15593 + /* QH is not in a schedule. */
15597 + if (dwc_qh_is_non_per(qh)) {
15598 + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
15599 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
15601 + list_del_init(&qh->qh_list_entry);
15603 + deschedule_periodic(hcd, qh);
15607 + SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags)
15611 + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
15612 + * non-periodic schedule. The QH is added to the inactive non-periodic
15613 + * schedule if any QTDs are still attached to the QH.
15615 + * For periodic QHs, the QH is removed from the periodic queued schedule. If
15616 + * there are any QTDs still attached to the QH, the QH is added to either the
15617 + * periodic inactive schedule or the periodic ready schedule and its next
15618 + * scheduled frame is calculated. The QH is placed in the ready schedule if
15619 + * the scheduled frame has been reached already. Otherwise it's placed in the
15620 + * inactive schedule. If there are no QTDs attached to the QH, the QH is
15621 + * completely removed from the periodic schedule.
15623 +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, int sched_next_periodic_split)
15625 + unsigned long flags;
15626 + SPIN_LOCK_IRQSAVE(&hcd->lock, flags);
15628 + if (dwc_qh_is_non_per(qh)) {
15629 + dwc_otg_hcd_qh_remove(hcd, qh);
15630 + if (!list_empty(&qh->qtd_list)) {
15631 + /* Add back to inactive non-periodic schedule. */
15632 + dwc_otg_hcd_qh_add(hcd, qh);
15635 + uint16_t frame_number = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(hcd));
15637 + if (qh->do_split) {
15638 + /* Schedule the next continuing periodic split transfer */
15639 + if (sched_next_periodic_split) {
15641 + qh->sched_frame = frame_number;
15642 + if (dwc_frame_num_le(frame_number,
15643 + dwc_frame_num_inc(qh->start_split_frame, 1))) {
15645 + * Allow one frame to elapse after start
15646 + * split microframe before scheduling
15647 + * complete split, but DONT if we are
15648 + * doing the next start split in the
15649 + * same frame for an ISOC out.
15651 + if ((qh->ep_type != USB_ENDPOINT_XFER_ISOC) || (qh->ep_is_in != 0)) {
15652 + qh->sched_frame = dwc_frame_num_inc(qh->sched_frame, 1);
15656 + qh->sched_frame = dwc_frame_num_inc(qh->start_split_frame,
15658 + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
15659 + qh->sched_frame = frame_number;
15661 + qh->sched_frame |= 0x7;
15662 + qh->start_split_frame = qh->sched_frame;
15665 + qh->sched_frame = dwc_frame_num_inc(qh->sched_frame, qh->interval);
15666 + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
15667 + qh->sched_frame = frame_number;
15671 + if (list_empty(&qh->qtd_list)) {
15672 + dwc_otg_hcd_qh_remove(hcd, qh);
15675 + * Remove from periodic_sched_queued and move to
15676 + * appropriate queue.
15678 + if (qh->sched_frame == frame_number) {
15679 + list_move(&qh->qh_list_entry,
15680 + &hcd->periodic_sched_ready);
15682 + list_move(&qh->qh_list_entry,
15683 + &hcd->periodic_sched_inactive);
15688 + SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags);
15692 + * This function allocates and initializes a QTD.
15694 + * @param[in] urb The URB to create a QTD from. Each URB-QTD pair will end up
15695 + * pointing to each other so each pair should have a unique correlation.
15697 + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
15698 +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *urb)
15700 + dwc_otg_qtd_t *qtd;
15702 + qtd = dwc_otg_hcd_qtd_alloc ();
15703 + if (qtd == NULL) {
15707 + dwc_otg_hcd_qtd_init (qtd, urb);
15712 + * Initializes a QTD structure.
15714 + * @param[in] qtd The QTD to initialize.
15715 + * @param[in] urb The URB to use for initialization. */
15716 +void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *qtd, struct urb *urb)
15718 + memset (qtd, 0, sizeof (dwc_otg_qtd_t));
15720 + if (usb_pipecontrol(urb->pipe)) {
15722 + * The only time the QTD data toggle is used is on the data
15723 + * phase of control transfers. This phase always starts with
15726 + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
15727 + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
15730 + /* start split */
15731 + qtd->complete_split = 0;
15732 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
15733 + qtd->isoc_split_offset = 0;
15735 + /* Store the qtd ptr in the urb to reference what QTD. */
15736 + urb->hcpriv = qtd;
15741 + * This function adds a QTD to the QTD-list of a QH. It will find the correct
15742 + * QH to place the QTD into. If it does not find a QH, then it will create a
15743 + * new QH. If the QH to which the QTD is added is not currently scheduled, it
15744 + * is placed into the proper schedule based on its EP type.
15746 + * @param[in] qtd The QTD to add
15747 + * @param[in] dwc_otg_hcd The DWC HCD structure
15749 + * @return 0 if successful, negative error code otherwise.
15751 +int dwc_otg_hcd_qtd_add (dwc_otg_qtd_t *qtd,
15752 + dwc_otg_hcd_t *dwc_otg_hcd)
15754 + struct usb_host_endpoint *ep;
15755 + dwc_otg_qh_t *qh;
15756 + unsigned long flags;
15759 + struct urb *urb = qtd->urb;
15761 + SPIN_LOCK_IRQSAVE(&dwc_otg_hcd->lock, flags);
15764 + * Get the QH which holds the QTD-list to insert to. Create QH if it
15767 + ep = dwc_urb_to_endpoint(urb);
15768 + qh = (dwc_otg_qh_t *)ep->hcpriv;
15769 + if (qh == NULL) {
15770 + qh = dwc_otg_hcd_qh_create (dwc_otg_hcd, urb);
15771 + if (qh == NULL) {
15777 + retval = dwc_otg_hcd_qh_add(dwc_otg_hcd, qh);
15778 + if (retval == 0) {
15779 + list_add_tail(&qtd->qtd_list_entry, &qh->qtd_list);
15783 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
15788 +#endif /* DWC_DEVICE_ONLY */
15789 diff --git a/drivers/usb/dwc_otg/dwc_otg_pcd.c b/drivers/usb/dwc_otg/dwc_otg_pcd.c
15790 new file mode 100644
15791 index 0000000..030a3f2
15793 +++ b/drivers/usb/dwc_otg/dwc_otg_pcd.c
15795 +/* ==========================================================================
15796 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
15797 + * $Revision: 1.5 $
15798 + * $Date: 2008-11-27 09:21:25 $
15799 + * $Change: 1115682 $
15801 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
15802 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
15803 + * otherwise expressly agreed to in writing between Synopsys and you.
15805 + * The Software IS NOT an item of Licensed Software or Licensed Product under
15806 + * any End User Software License Agreement or Agreement for Licensed Product
15807 + * with Synopsys or any supplement thereto. You are permitted to use and
15808 + * redistribute this Software in source and binary forms, with or without
15809 + * modification, provided that redistributions of source code must retain this
15810 + * notice. You may not view, use, disclose, copy or distribute this file or
15811 + * any information contained herein except pursuant to this license grant from
15812 + * Synopsys. If you do not agree with this notice, including the disclaimer
15813 + * below, then you are not authorized to use the Software.
15815 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
15816 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15817 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15818 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
15819 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15820 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
15821 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
15822 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
15823 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15824 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
15826 + * ========================================================================== */
15827 +#ifndef DWC_HOST_ONLY
15830 + * This file implements the Peripheral Controller Driver.
15832 + * The Peripheral Controller Driver (PCD) is responsible for
15833 + * translating requests from the Function Driver into the appropriate
15834 + * actions on the DWC_otg controller. It isolates the Function Driver
15835 + * from the specifics of the controller by providing an API to the
15836 + * Function Driver.
15838 + * The Peripheral Controller Driver for Linux will implement the
15839 + * Gadget API, so that the existing Gadget drivers can be used.
15840 + * (Gadget Driver is the Linux terminology for a Function Driver.)
15842 + * The Linux Gadget API is defined in the header file
15843 + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
15844 + * defined in the structure <code>usb_ep_ops</code> and the USB
15845 + * Controller API is defined in the structure
15846 + * <code>usb_gadget_ops</code>.
15848 + * An important function of the PCD is managing interrupts generated
15849 + * by the DWC_otg controller. The implementation of the DWC_otg device
15850 + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
15852 + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
15853 + * @todo Does it work when the request size is greater than DEPTSIZ
15859 +#include <linux/kernel.h>
15860 +#include <linux/module.h>
15861 +#include <linux/moduleparam.h>
15862 +#include <linux/init.h>
15863 +#include <linux/device.h>
15864 +#include <linux/errno.h>
15865 +#include <linux/list.h>
15866 +#include <linux/interrupt.h>
15867 +#include <linux/string.h>
15868 +#include <linux/dma-mapping.h>
15869 +#include <linux/version.h>
15871 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
15872 +# include <linux/usb/ch9.h>
15874 +# include <linux/usb_ch9.h>
15877 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
15878 +#include <linux/usb/gadget.h>
15880 +#include <linux/usb_gadget.h>
15883 +#include "dwc_otg_driver.h"
15884 +#include "dwc_otg_pcd.h"
15888 + * Static PCD pointer for use in usb_gadget_register_driver and
15889 + * usb_gadget_unregister_driver. Initialized in dwc_otg_pcd_init.
15891 +static dwc_otg_pcd_t *s_pcd = 0;
15894 +/* Display the contents of the buffer */
15895 +extern void dump_msg(const u8 *buf, unsigned int length);
15899 + * This function completes a request. It call's the request call back.
15901 +void dwc_otg_request_done(dwc_otg_pcd_ep_t *ep, dwc_otg_pcd_request_t *req,
15904 + unsigned stopped = ep->stopped;
15906 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, ep);
15907 + list_del_init(&req->queue);
15909 + if (req->req.status == -EINPROGRESS) {
15910 + req->req.status = status;
15912 + status = req->req.status;
15915 + /* don't modify queue heads during completion callback */
15917 + SPIN_UNLOCK(&ep->pcd->lock);
15918 + req->req.complete(&ep->ep, &req->req);
15919 + SPIN_LOCK(&ep->pcd->lock);
15921 + if (ep->pcd->request_pending > 0) {
15922 + --ep->pcd->request_pending;
15925 + ep->stopped = stopped;
15929 + * This function terminates all the requsts in the EP request queue.
15931 +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t *ep)
15933 + dwc_otg_pcd_request_t *req;
15937 + /* called with irqs blocked?? */
15938 + while (!list_empty(&ep->queue)) {
15939 + req = list_entry(ep->queue.next, dwc_otg_pcd_request_t,
15941 + dwc_otg_request_done(ep, req, -ESHUTDOWN);
15945 +/* USB Endpoint Operations */
15947 + * The following sections briefly describe the behavior of the Gadget
15948 + * API endpoint operations implemented in the DWC_otg driver
15949 + * software. Detailed descriptions of the generic behavior of each of
15950 + * these functions can be found in the Linux header file
15951 + * include/linux/usb_gadget.h.
15953 + * The Gadget API provides wrapper functions for each of the function
15954 + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
15955 + * function, which then calls the underlying PCD function. The
15956 + * following sections are named according to the wrapper
15957 + * functions. Within each section, the corresponding DWC_otg PCD
15958 + * function name is specified.
15963 + * This function assigns periodic Tx FIFO to an periodic EP
15964 + * in shared Tx FIFO mode
15966 +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t *core_if)
15968 + uint32_t PerTxMsk = 1;
15970 + for(i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i)
15972 + if((PerTxMsk & core_if->p_tx_msk) == 0) {
15973 + core_if->p_tx_msk |= PerTxMsk;
15981 + * This function releases periodic Tx FIFO
15982 + * in shared Tx FIFO mode
15984 +static void release_perio_tx_fifo(dwc_otg_core_if_t *core_if, uint32_t fifo_num)
15986 + core_if->p_tx_msk = (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
15989 + * This function assigns periodic Tx FIFO to an periodic EP
15990 + * in shared Tx FIFO mode
15992 +static uint32_t assign_tx_fifo(dwc_otg_core_if_t *core_if)
15994 + uint32_t TxMsk = 1;
15997 + for(i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i)
15999 + if((TxMsk & core_if->tx_msk) == 0) {
16000 + core_if->tx_msk |= TxMsk;
16008 + * This function releases periodic Tx FIFO
16009 + * in shared Tx FIFO mode
16011 +static void release_tx_fifo(dwc_otg_core_if_t *core_if, uint32_t fifo_num)
16013 + core_if->tx_msk = (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
16017 + * This function is called by the Gadget Driver for each EP to be
16018 + * configured for the current configuration (SET_CONFIGURATION).
16020 + * This function initializes the dwc_otg_ep_t data structure, and then
16021 + * calls dwc_otg_ep_activate.
16023 +static int dwc_otg_pcd_ep_enable(struct usb_ep *usb_ep,
16024 + const struct usb_endpoint_descriptor *ep_desc)
16026 + dwc_otg_pcd_ep_t *ep = 0;
16027 + dwc_otg_pcd_t *pcd = 0;
16028 + unsigned long flags;
16030 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p)\n", __func__, usb_ep, ep_desc);
16032 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16033 + if (!usb_ep || !ep_desc || ep->desc ||
16034 + ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
16035 + DWC_WARN("%s, bad ep or descriptor\n", __func__);
16038 + if (ep == &ep->pcd->ep0) {
16039 + DWC_WARN("%s, bad ep(0)\n", __func__);
16043 + /* Check FIFO size? */
16044 + if (!ep_desc->wMaxPacketSize) {
16045 + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
16050 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
16051 + DWC_WARN("%s, bogus device state\n", __func__);
16052 + return -ESHUTDOWN;
16055 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
16057 + ep->desc = ep_desc;
16058 + ep->ep.maxpacket = le16_to_cpu (ep_desc->wMaxPacketSize);
16061 + * Activate the EP
16065 + ep->dwc_ep.is_in = (USB_DIR_IN & ep_desc->bEndpointAddress) != 0;
16066 + ep->dwc_ep.maxpacket = ep->ep.maxpacket;
16068 + ep->dwc_ep.type = ep_desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
16070 + if(ep->dwc_ep.is_in) {
16071 + if(!pcd->otg_dev->core_if->en_multiple_tx_fifo) {
16072 + ep->dwc_ep.tx_fifo_num = 0;
16074 + if (ep->dwc_ep.type == USB_ENDPOINT_XFER_ISOC) {
16076 + * if ISOC EP then assign a Periodic Tx FIFO.
16078 + ep->dwc_ep.tx_fifo_num = assign_perio_tx_fifo(pcd->otg_dev->core_if);
16082 + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
16084 + ep->dwc_ep.tx_fifo_num = assign_tx_fifo(pcd->otg_dev->core_if);
16088 + /* Set initial data PID. */
16089 + if (ep->dwc_ep.type == USB_ENDPOINT_XFER_BULK) {
16090 + ep->dwc_ep.data_pid_start = 0;
16093 + DWC_DEBUGPL(DBG_PCD, "Activate %s-%s: type=%d, mps=%d desc=%p\n",
16094 + ep->ep.name, (ep->dwc_ep.is_in ?"IN":"OUT"),
16095 + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
16097 + if(ep->dwc_ep.type != USB_ENDPOINT_XFER_ISOC) {
16098 + ep->dwc_ep.desc_addr = dwc_otg_ep_alloc_desc_chain(&ep->dwc_ep.dma_desc_addr, MAX_DMA_DESC_CNT);
16101 + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
16102 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
16108 + * This function is called when an EP is disabled due to disconnect or
16109 + * change in configuration. Any pending requests will terminate with a
16110 + * status of -ESHUTDOWN.
16112 + * This function modifies the dwc_otg_ep_t data structure for this EP,
16113 + * and then calls dwc_otg_ep_deactivate.
16115 +static int dwc_otg_pcd_ep_disable(struct usb_ep *usb_ep)
16117 + dwc_otg_pcd_ep_t *ep;
16118 + dwc_otg_pcd_t *pcd = 0;
16119 + unsigned long flags;
16121 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, usb_ep);
16122 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16123 + if (!usb_ep || !ep->desc) {
16124 + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
16125 + usb_ep ? ep->ep.name : NULL);
16129 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
16131 + dwc_otg_request_nuke(ep);
16133 + dwc_otg_ep_deactivate(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
16137 + if(ep->dwc_ep.is_in) {
16138 + dwc_otg_flush_tx_fifo(GET_CORE_IF(ep->pcd), ep->dwc_ep.tx_fifo_num);
16139 + release_perio_tx_fifo(GET_CORE_IF(ep->pcd), ep->dwc_ep.tx_fifo_num);
16140 + release_tx_fifo(GET_CORE_IF(ep->pcd), ep->dwc_ep.tx_fifo_num);
16143 + /* Free DMA Descriptors */
16146 + SPIN_UNLOCK_IRQRESTORE(&ep->pcd->lock, flags);
16148 + if(ep->dwc_ep.type != USB_ENDPOINT_XFER_ISOC && ep->dwc_ep.desc_addr) {
16149 + dwc_otg_ep_free_desc_chain(ep->dwc_ep.desc_addr, ep->dwc_ep.dma_desc_addr, MAX_DMA_DESC_CNT);
16152 + DWC_DEBUGPL(DBG_PCD, "%s disabled\n", usb_ep->name);
16158 + * This function allocates a request object to use with the specified
16161 + * @param ep The endpoint to be used with with the request
16162 + * @param gfp_flags the GFP_* flags to use.
16164 +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
16165 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
16172 + dwc_otg_pcd_request_t *req;
16174 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%d)\n", __func__, ep, gfp_flags);
16176 + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
16179 + req = kmalloc(sizeof(dwc_otg_pcd_request_t), gfp_flags);
16181 + DWC_WARN("%s() %s\n", __func__,
16182 + "request allocation failed!\n");
16185 + memset(req, 0, sizeof(dwc_otg_pcd_request_t));
16186 + req->req.dma = DMA_ADDR_INVALID;
16187 + INIT_LIST_HEAD(&req->queue);
16188 + return &req->req;
16192 + * This function frees a request object.
16194 + * @param ep The endpoint associated with the request
16195 + * @param req The request being freed
16197 +static void dwc_otg_pcd_free_request(struct usb_ep *ep,
16198 + struct usb_request *req)
16200 + dwc_otg_pcd_request_t *request;
16201 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p)\n", __func__, ep, req);
16203 + if (0 == ep || 0 == req) {
16204 + DWC_WARN("%s() %s\n", __func__,
16205 + "Invalid ep or req argument!\n");
16209 + request = container_of(req, dwc_otg_pcd_request_t, req);
16213 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
16215 + * This function allocates an I/O buffer to be used for a transfer
16216 + * to/from the specified endpoint.
16218 + * @param usb_ep The endpoint to be used with with the request
16219 + * @param bytes The desired number of bytes for the buffer
16220 + * @param dma Pointer to the buffer's DMA address; must be valid
16221 + * @param gfp_flags the GFP_* flags to use.
16222 + * @return address of a new buffer or null is buffer could not be allocated.
16224 +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
16226 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
16234 + dwc_otg_pcd_ep_t *ep;
16235 + dwc_otg_pcd_t *pcd = 0;
16237 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16240 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
16243 + /* Check dword alignment */
16244 + if ((bytes & 0x3UL) != 0) {
16245 + DWC_WARN("%s() Buffer size is not a multiple of"
16246 + "DWORD size (%d)",__func__, bytes);
16249 + if (GET_CORE_IF(pcd)->dma_enable) {
16250 + buf = dma_alloc_coherent (NULL, bytes, dma, gfp_flags);
16253 + buf = kmalloc(bytes, gfp_flags);
16256 + /* Check dword alignment */
16257 + if (((int)buf & 0x3UL) != 0) {
16258 + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
16266 + * This function frees an I/O buffer that was allocated by alloc_buffer.
16268 + * @param usb_ep the endpoint associated with the buffer
16269 + * @param buf address of the buffer
16270 + * @param dma The buffer's DMA address
16271 + * @param bytes The number of bytes of the buffer
16273 +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
16274 + dma_addr_t dma, unsigned bytes)
16276 + dwc_otg_pcd_ep_t *ep;
16277 + dwc_otg_pcd_t *pcd = 0;
16279 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16282 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p,%0x,%d)\n", __func__, ep, buf, dma, bytes);
16284 + if (GET_CORE_IF(pcd)->dma_enable) {
16285 + dma_free_coherent (NULL, bytes, buf, dma);
16295 + * This function is used to submit an I/O Request to an EP.
16297 + * - When the request completes the request's completion callback
16298 + * is called to return the request to the driver.
16299 + * - An EP, except control EPs, may have multiple requests
16301 + * - Once submitted the request cannot be examined or modified.
16302 + * - Each request is turned into one or more packets.
16303 + * - A BULK EP can queue any amount of data; the transfer is
16305 + * - Zero length Packets are specified with the request 'zero'
16308 +static int dwc_otg_pcd_ep_queue(struct usb_ep *usb_ep,
16309 + struct usb_request *usb_req,
16310 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
16317 + int prevented = 0;
16318 + dwc_otg_pcd_request_t *req;
16319 + dwc_otg_pcd_ep_t *ep;
16320 + dwc_otg_pcd_t *pcd;
16321 + unsigned long flags = 0;
16322 + dwc_otg_core_if_t *_core_if;
16324 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p,%d)\n",
16325 + __func__, usb_ep, usb_req, gfp_flags);
16327 + req = container_of(usb_req, dwc_otg_pcd_request_t, req);
16328 + if (!usb_req || !usb_req->complete || !usb_req->buf ||
16329 + !list_empty(&req->queue)) {
16330 + DWC_WARN("%s, bad params\n", __func__);
16334 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16335 + if (!usb_ep || (!ep->desc && ep->dwc_ep.num != 0)/* || ep->stopped != 0*/) {
16336 + DWC_WARN("%s, bad ep\n", __func__);
16341 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
16342 + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n", pcd->gadget.speed);
16343 + DWC_WARN("%s, bogus device state\n", __func__);
16344 + return -ESHUTDOWN;
16348 + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
16349 + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
16351 + if (!GET_CORE_IF(pcd)->core_params->opt) {
16352 + if (ep->dwc_ep.num != 0) {
16353 + DWC_ERROR("%s queue req %p, len %d buf %p\n",
16354 + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
16358 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
16361 + /**************************************************
16362 + New add by kaiker ,for DMA mode bug
16363 + ************************************************/
16364 + //by kaiker ,for RT3052 USB OTG device mode
16366 + _core_if = GET_CORE_IF(pcd);
16368 + if (_core_if->dma_enable)
16370 + usb_req->dma = virt_to_phys((void *)usb_req->buf);
16372 + if(ep->dwc_ep.is_in)
16374 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) || defined(CONFIG_MIPS)
16375 + if(usb_req->length)
16376 + dma_cache_wback_inv((unsigned long)usb_req->buf, usb_req->length + 2);
16383 +#if defined(DEBUG) & defined(VERBOSE)
16384 + dump_msg(usb_req->buf, usb_req->length);
16387 + usb_req->status = -EINPROGRESS;
16388 + usb_req->actual = 0;
16391 + * For EP0 IN without premature status, zlp is required?
16393 + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
16394 + DWC_DEBUGPL(DBG_PCDV, "%s-OUT ZLP\n", usb_ep->name);
16395 + //_req->zero = 1;
16398 + /* Start the transfer */
16399 + if (list_empty(&ep->queue) && !ep->stopped) {
16400 + /* EP0 Transfer? */
16401 + if (ep->dwc_ep.num == 0) {
16402 + switch (pcd->ep0state) {
16403 + case EP0_IN_DATA_PHASE:
16404 + DWC_DEBUGPL(DBG_PCD,
16405 + "%s ep0: EP0_IN_DATA_PHASE\n",
16409 + case EP0_OUT_DATA_PHASE:
16410 + DWC_DEBUGPL(DBG_PCD,
16411 + "%s ep0: EP0_OUT_DATA_PHASE\n",
16413 + if (pcd->request_config) {
16414 + /* Complete STATUS PHASE */
16415 + ep->dwc_ep.is_in = 1;
16416 + pcd->ep0state = EP0_IN_STATUS_PHASE;
16420 + case EP0_IN_STATUS_PHASE:
16421 + DWC_DEBUGPL(DBG_PCD,
16422 + "%s ep0: EP0_IN_STATUS_PHASE\n",
16427 + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
16429 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
16432 + ep->dwc_ep.dma_addr = usb_req->dma;
16433 + ep->dwc_ep.start_xfer_buff = usb_req->buf;
16434 + ep->dwc_ep.xfer_buff = usb_req->buf;
16435 + ep->dwc_ep.xfer_len = usb_req->length;
16436 + ep->dwc_ep.xfer_count = 0;
16437 + ep->dwc_ep.sent_zlp = 0;
16438 + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
16440 + if(usb_req->zero) {
16441 + if((ep->dwc_ep.xfer_len % ep->dwc_ep.maxpacket == 0)
16442 + && (ep->dwc_ep.xfer_len != 0)) {
16443 + ep->dwc_ep.sent_zlp = 1;
16448 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep->dwc_ep);
16452 + uint32_t max_transfer = GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
16454 + /* Setup and start the Transfer */
16455 + ep->dwc_ep.dma_addr = usb_req->dma;
16456 + ep->dwc_ep.start_xfer_buff = usb_req->buf;
16457 + ep->dwc_ep.xfer_buff = usb_req->buf;
16458 + ep->dwc_ep.sent_zlp = 0;
16459 + ep->dwc_ep.total_len = usb_req->length;
16460 + ep->dwc_ep.xfer_len = 0;
16461 + ep->dwc_ep.xfer_count = 0;
16463 + if(max_transfer > MAX_TRANSFER_SIZE) {
16464 + ep->dwc_ep.maxxfer = max_transfer - (max_transfer % ep->dwc_ep.maxpacket);
16466 + ep->dwc_ep.maxxfer = max_transfer;
16469 + if(usb_req->zero) {
16470 + if((ep->dwc_ep.total_len % ep->dwc_ep.maxpacket == 0)
16471 + && (ep->dwc_ep.total_len != 0)) {
16472 + ep->dwc_ep.sent_zlp = 1;
16476 + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd), &ep->dwc_ep);
16480 + if ((req != 0) || prevented) {
16481 + ++pcd->request_pending;
16482 + list_add_tail(&req->queue, &ep->queue);
16483 + if (ep->dwc_ep.is_in && ep->stopped && !(GET_CORE_IF(pcd)->dma_enable)) {
16484 + /** @todo NGS Create a function for this. */
16485 + diepmsk_data_t diepmsk = { .d32 = 0};
16486 + diepmsk.b.intktxfemp = 1;
16487 + if(&GET_CORE_IF(pcd)->multiproc_int_enable) {
16488 + dwc_modify_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->diepeachintmsk[ep->dwc_ep.num],
16491 + dwc_modify_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
16496 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
16501 + * This function cancels an I/O request from an EP.
16503 +static int dwc_otg_pcd_ep_dequeue(struct usb_ep *usb_ep,
16504 + struct usb_request *usb_req)
16506 + dwc_otg_pcd_request_t *req;
16507 + dwc_otg_pcd_ep_t *ep;
16508 + dwc_otg_pcd_t *pcd;
16509 + unsigned long flags;
16511 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p)\n", __func__, usb_ep, usb_req);
16513 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16514 + if (!usb_ep || !usb_req || (!ep->desc && ep->dwc_ep.num != 0)) {
16515 + DWC_WARN("%s, bad argument\n", __func__);
16519 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
16520 + DWC_WARN("%s, bogus device state\n", __func__);
16521 + return -ESHUTDOWN;
16524 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
16525 + DWC_DEBUGPL(DBG_PCDV, "%s %s %s %p\n", __func__, usb_ep->name,
16526 + ep->dwc_ep.is_in ? "IN" : "OUT",
16529 + /* make sure it's actually queued on this endpoint */
16530 + list_for_each_entry(req, &ep->queue, queue)
16532 + if (&req->req == usb_req) {
16537 + if (&req->req != usb_req) {
16538 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
16542 + if (!list_empty(&req->queue)) {
16543 + dwc_otg_request_done(ep, req, -ECONNRESET);
16549 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
16551 + return req ? 0 : -EOPNOTSUPP;
16555 + * usb_ep_set_halt stalls an endpoint.
16557 + * usb_ep_clear_halt clears an endpoint halt and resets its data
16560 + * Both of these functions are implemented with the same underlying
16561 + * function. The behavior depends on the value argument.
16563 + * @param[in] usb_ep the Endpoint to halt or clear halt.
16564 + * @param[in] value
16565 + * - 0 means clear_halt.
16566 + * - 1 means set_halt,
16567 + * - 2 means clear stall lock flag.
16568 + * - 3 means set stall lock flag.
16570 +static int dwc_otg_pcd_ep_set_halt(struct usb_ep *usb_ep, int value)
16573 + unsigned long flags;
16574 + dwc_otg_pcd_ep_t *ep = 0;
16577 + DWC_DEBUGPL(DBG_PCD,"HALT %s %d\n", usb_ep->name, value);
16579 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16581 + if (!usb_ep || (!ep->desc && ep != &ep->pcd->ep0) ||
16582 + ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
16583 + DWC_WARN("%s, bad ep\n", __func__);
16587 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
16588 + if (!list_empty(&ep->queue)) {
16589 + DWC_WARN("%s() %s XFer In process\n", __func__, usb_ep->name);
16590 + retval = -EAGAIN;
16592 + else if (value == 0) {
16593 + dwc_otg_ep_clear_stall(ep->pcd->otg_dev->core_if,
16596 + else if(value == 1) {
16597 + if (ep->dwc_ep.is_in == 1 && ep->pcd->otg_dev->core_if->dma_desc_enable) {
16598 + dtxfsts_data_t txstatus;
16599 + fifosize_data_t txfifosize;
16601 + txfifosize.d32 = dwc_read_reg32(&ep->pcd->otg_dev->core_if->core_global_regs->dptxfsiz_dieptxf[ep->dwc_ep.tx_fifo_num]);
16602 + txstatus.d32 = dwc_read_reg32(&ep->pcd->otg_dev->core_if->dev_if->in_ep_regs[ep->dwc_ep.num]->dtxfsts);
16604 + if(txstatus.b.txfspcavail < txfifosize.b.depth) {
16605 + DWC_WARN("%s() %s Data In Tx Fifo\n", __func__, usb_ep->name);
16606 + retval = -EAGAIN;
16609 + if (ep->dwc_ep.num == 0) {
16610 + ep->pcd->ep0state = EP0_STALL;
16614 + dwc_otg_ep_set_stall(ep->pcd->otg_dev->core_if,
16619 + if (ep->dwc_ep.num == 0) {
16620 + ep->pcd->ep0state = EP0_STALL;
16624 + dwc_otg_ep_set_stall(ep->pcd->otg_dev->core_if,
16628 + else if (value == 2) {
16629 + ep->dwc_ep.stall_clear_flag = 0;
16631 + else if (value == 3) {
16632 + ep->dwc_ep.stall_clear_flag = 1;
16635 + SPIN_UNLOCK_IRQRESTORE(&ep->pcd->lock, flags);
16640 + * This function allocates a DMA Descriptor chain for the Endpoint
16641 + * buffer to be used for a transfer to/from the specified endpoint.
16643 +dwc_otg_dma_desc_t* dwc_otg_ep_alloc_desc_chain(uint32_t * dma_desc_addr, uint32_t count)
16646 + return dma_alloc_coherent(NULL, count * sizeof(dwc_otg_dma_desc_t), dma_desc_addr, GFP_KERNEL);
16650 + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
16652 +void dwc_otg_ep_free_desc_chain(dwc_otg_dma_desc_t* desc_addr, uint32_t dma_desc_addr, uint32_t count)
16654 + dma_free_coherent(NULL, count * sizeof(dwc_otg_dma_desc_t), desc_addr, dma_desc_addr);
16657 +#ifdef DWC_EN_ISOC
16660 + * This function initializes a descriptor chain for Isochronous transfer
16662 + * @param core_if Programming view of DWC_otg controller.
16663 + * @param dwc_ep The EP to start the transfer on.
16666 +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
16669 + dsts_data_t dsts = { .d32 = 0};
16670 + depctl_data_t depctl = { .d32 = 0 };
16671 + volatile uint32_t *addr;
16674 + if(dwc_ep->is_in)
16675 + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
16677 + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm / dwc_ep->bInterval;
16680 + /** Allocate descriptors for double buffering */
16681 + dwc_ep->iso_desc_addr = dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,dwc_ep->desc_cnt*2);
16682 + if(dwc_ep->desc_addr) {
16683 + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
16687 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
16689 + /** ISO OUT EP */
16690 + if(dwc_ep->is_in == 0) {
16691 + desc_sts_data_t sts = { .d32 =0 };
16692 + dwc_otg_dma_desc_t* dma_desc = dwc_ep->iso_desc_addr;
16693 + dma_addr_t dma_ad;
16694 + uint32_t data_per_desc;
16695 + dwc_otg_dev_out_ep_regs_t *out_regs =
16696 + core_if->dev_if->out_ep_regs[dwc_ep->num];
16699 + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
16700 + dma_ad = (dma_addr_t)dwc_read_reg32(&(out_regs->doepdma));
16702 + /** Buffer 0 descriptors setup */
16703 + dma_ad = dwc_ep->dma_addr0;
16705 + sts.b_iso_out.bs = BS_HOST_READY;
16706 + sts.b_iso_out.rxsts = 0;
16707 + sts.b_iso_out.l = 0;
16708 + sts.b_iso_out.sp = 0;
16709 + sts.b_iso_out.ioc = 0;
16710 + sts.b_iso_out.pid = 0;
16711 + sts.b_iso_out.framenum = 0;
16714 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
16717 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
16719 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
16720 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
16722 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
16723 + sts.b_iso_out.rxbytes = data_per_desc;
16724 + writel((uint32_t)dma_ad, &dma_desc->buf);
16725 + writel(sts.d32, &dma_desc->status);
16727 + offset += data_per_desc;
16729 + (uint32_t)dma_ad += data_per_desc;
16733 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
16735 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
16736 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
16737 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
16738 + sts.b_iso_out.rxbytes = data_per_desc;
16739 + writel((uint32_t)dma_ad, &dma_desc->buf);
16740 + writel(sts.d32, &dma_desc->status);
16742 + offset += data_per_desc;
16744 + (uint32_t)dma_ad += data_per_desc;
16747 + sts.b_iso_out.ioc = 1;
16748 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
16749 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
16750 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
16751 + sts.b_iso_out.rxbytes = data_per_desc;
16753 + writel((uint32_t)dma_ad, &dma_desc->buf);
16754 + writel(sts.d32, &dma_desc->status);
16757 + /** Buffer 1 descriptors setup */
16758 + sts.b_iso_out.ioc = 0;
16759 + dma_ad = dwc_ep->dma_addr1;
16762 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
16764 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
16766 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
16767 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
16768 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
16769 + sts.b_iso_out.rxbytes = data_per_desc;
16770 + writel((uint32_t)dma_ad, &dma_desc->buf);
16771 + writel(sts.d32, &dma_desc->status);
16773 + offset += data_per_desc;
16775 + (uint32_t)dma_ad += data_per_desc;
16778 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
16780 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
16781 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
16782 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
16783 + sts.b_iso_out.rxbytes = data_per_desc;
16784 + writel((uint32_t)dma_ad, &dma_desc->buf);
16785 + writel(sts.d32, &dma_desc->status);
16787 + offset += data_per_desc;
16789 + (uint32_t)dma_ad += data_per_desc;
16792 + sts.b_iso_out.ioc = 1;
16793 + sts.b_iso_out.l = 1;
16794 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
16795 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
16796 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
16797 + sts.b_iso_out.rxbytes = data_per_desc;
16799 + writel((uint32_t)dma_ad, &dma_desc->buf);
16800 + writel(sts.d32, &dma_desc->status);
16802 + dwc_ep->next_frame = 0;
16804 + /** Write dma_ad into DOEPDMA register */
16805 + dwc_write_reg32(&(out_regs->doepdma),(uint32_t)dwc_ep->iso_dma_desc_addr);
16810 + desc_sts_data_t sts = { .d32 =0 };
16811 + dwc_otg_dma_desc_t* dma_desc = dwc_ep->iso_desc_addr;
16812 + dma_addr_t dma_ad;
16813 + dwc_otg_dev_in_ep_regs_t *in_regs =
16814 + core_if->dev_if->in_ep_regs[dwc_ep->num];
16815 + unsigned int frmnumber;
16816 + fifosize_data_t txfifosize,rxfifosize;
16818 + txfifosize.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->dtxfsts);
16819 + rxfifosize.d32 = dwc_read_reg32(&core_if->core_global_regs->grxfsiz);
16822 + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
16824 + dma_ad = dwc_ep->dma_addr0;
16826 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
16828 + sts.b_iso_in.bs = BS_HOST_READY;
16829 + sts.b_iso_in.txsts = 0;
16830 + sts.b_iso_in.sp = (dwc_ep->data_per_frame % dwc_ep->maxpacket)? 1 : 0;
16831 + sts.b_iso_in.ioc = 0;
16832 + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
16835 + frmnumber = dwc_ep->next_frame;
16837 + sts.b_iso_in.framenum = frmnumber;
16838 + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
16839 + sts.b_iso_in.l = 0;
16841 + /** Buffer 0 descriptors setup */
16842 + for(i = 0; i < dwc_ep->desc_cnt - 1; i++)
16844 + writel((uint32_t)dma_ad, &dma_desc->buf);
16845 + writel(sts.d32, &dma_desc->status);
16848 + (uint32_t)dma_ad += dwc_ep->data_per_frame;
16849 + sts.b_iso_in.framenum += dwc_ep->bInterval;
16852 + sts.b_iso_in.ioc = 1;
16853 + writel((uint32_t)dma_ad, &dma_desc->buf);
16854 + writel(sts.d32, &dma_desc->status);
16857 + /** Buffer 1 descriptors setup */
16858 + sts.b_iso_in.ioc = 0;
16859 + dma_ad = dwc_ep->dma_addr1;
16861 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
16863 + writel((uint32_t)dma_ad, &dma_desc->buf);
16864 + writel(sts.d32, &dma_desc->status);
16867 + (uint32_t)dma_ad += dwc_ep->data_per_frame;
16868 + sts.b_iso_in.framenum += dwc_ep->bInterval;
16870 + sts.b_iso_in.ioc = 0;
16872 + sts.b_iso_in.ioc = 1;
16873 + sts.b_iso_in.l = 1;
16875 + writel((uint32_t)dma_ad, &dma_desc->buf);
16876 + writel(sts.d32, &dma_desc->status);
16878 + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
16880 + /** Write dma_ad into diepdma register */
16881 + dwc_write_reg32(&(in_regs->diepdma),(uint32_t)dwc_ep->iso_dma_desc_addr);
16883 + /** Enable endpoint, clear nak */
16885 + depctl.b.epena = 1;
16886 + depctl.b.usbactep = 1;
16887 + depctl.b.cnak = 1;
16889 + dwc_modify_reg32(addr, depctl.d32,depctl.d32);
16890 + depctl.d32 = dwc_read_reg32(addr);
16894 + * This function initializes a descriptor chain for Isochronous transfer
16896 + * @param core_if Programming view of DWC_otg controller.
16897 + * @param ep The EP to start the transfer on.
16901 +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
16903 + depctl_data_t depctl = { .d32 = 0 };
16904 + volatile uint32_t *addr;
16908 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
16910 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
16914 + if(core_if->dma_enable == 0 || core_if->dma_desc_enable!= 0) {
16917 + deptsiz_data_t deptsiz = { .d32 = 0 };
16919 + ep->xfer_len = ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
16920 + ep->pkt_cnt = (ep->xfer_len - 1 + ep->maxpacket) /
16922 + ep->xfer_count = 0;
16923 + ep->xfer_buff = (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
16924 + ep->dma_addr = (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
16927 + /* Program the transfer size and packet count
16928 + * as follows: xfersize = N * maxpacket +
16929 + * short_packet pktcnt = N + (short_packet
16932 + deptsiz.b.mc = ep->pkt_per_frm;
16933 + deptsiz.b.xfersize = ep->xfer_len;
16934 + deptsiz.b.pktcnt =
16935 + (ep->xfer_len - 1 + ep->maxpacket) /
16937 + dwc_write_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz, deptsiz.d32);
16939 + /* Write the DMA register */
16940 + dwc_write_reg32 (&(core_if->dev_if->in_ep_regs[ep->num]->diepdma), (uint32_t)ep->dma_addr);
16943 + deptsiz.b.pktcnt =
16944 + (ep->xfer_len + (ep->maxpacket - 1)) /
16946 + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
16948 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
16950 + /* Write the DMA register */
16951 + dwc_write_reg32 (&(core_if->dev_if->out_ep_regs[ep->num]->doepdma), (uint32_t)ep->dma_addr);
16954 + /** Enable endpoint, clear nak */
16956 + dwc_modify_reg32(addr, depctl.d32,depctl.d32);
16958 + depctl.b.epena = 1;
16959 + depctl.b.cnak = 1;
16961 + dwc_modify_reg32(addr, depctl.d32,depctl.d32);
16967 + * This function does the setup for a data transfer for an EP and
16968 + * starts the transfer. For an IN transfer, the packets will be
16969 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
16970 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
16972 + * @param core_if Programming view of DWC_otg controller.
16973 + * @param ep The EP to start the transfer on.
16976 +void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
16978 + if(core_if->dma_enable) {
16979 + if(core_if->dma_desc_enable) {
16981 + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
16983 + ep->desc_cnt = ep->pkt_cnt;
16985 + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
16987 + if(core_if->pti_enh_enable) {
16988 + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
16990 + ep->cur_pkt_addr = (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
16991 + ep->cur_pkt_dma_addr = (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
16992 + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
16996 + ep->cur_pkt_addr = (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
16997 + ep->cur_pkt_dma_addr = (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
16998 + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
17003 + * This function does the setup for a data transfer for an EP and
17004 + * starts the transfer. For an IN transfer, the packets will be
17005 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
17006 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
17008 + * @param core_if Programming view of DWC_otg controller.
17009 + * @param ep The EP to start the transfer on.
17012 +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
17014 + depctl_data_t depctl = { .d32 = 0 };
17015 + volatile uint32_t *addr;
17017 + if(ep->is_in == 1) {
17018 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
17021 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
17024 + /* disable the ep */
17025 + depctl.d32 = dwc_read_reg32(addr);
17027 + depctl.b.epdis = 1;
17028 + depctl.b.snak = 1;
17030 + dwc_write_reg32(addr, depctl.d32);
17032 + if(core_if->dma_desc_enable &&
17033 + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
17034 + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,ep->iso_dma_desc_addr,ep->desc_cnt * 2);
17037 + /* reset varibales */
17038 + ep->dma_addr0 = 0;
17039 + ep->dma_addr1 = 0;
17040 + ep->xfer_buff0 = 0;
17041 + ep->xfer_buff1 = 0;
17042 + ep->data_per_frame = 0;
17043 + ep->data_pattern_frame = 0;
17044 + ep->sync_frame = 0;
17045 + ep->buf_proc_intrvl = 0;
17046 + ep->bInterval = 0;
17047 + ep->proc_buf_num = 0;
17048 + ep->pkt_per_frm = 0;
17049 + ep->pkt_per_frm = 0;
17050 + ep->desc_cnt = 0;
17051 + ep->iso_desc_addr = 0;
17052 + ep->iso_dma_desc_addr = 0;
17057 + * This function is used to submit an ISOC Transfer Request to an EP.
17059 + * - Every time a sync period completes the request's completion callback
17060 + * is called to provide data to the gadget driver.
17061 + * - Once submitted the request cannot be modified.
17062 + * - Each request is turned into periodic data packets untill ISO
17063 + * Transfer is stopped..
17065 +static int dwc_otg_pcd_iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
17066 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
17073 + dwc_otg_pcd_ep_t *ep;
17074 + dwc_otg_pcd_t *pcd;
17075 + dwc_ep_t *dwc_ep;
17076 + unsigned long flags = 0;
17077 + int32_t frm_data;
17078 + dwc_otg_core_if_t *core_if;
17079 + dcfg_data_t dcfg;
17080 + dsts_data_t dsts;
17083 + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
17084 + DWC_WARN("%s, bad params\n", __func__);
17088 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17090 + if (!usb_ep || !ep->desc || ep->dwc_ep.num == 0) {
17091 + DWC_WARN("%s, bad ep\n", __func__);
17096 + core_if = GET_CORE_IF(pcd);
17098 + dcfg.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dcfg);
17100 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
17101 + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n", pcd->gadget.speed);
17102 + DWC_WARN("%s, bogus device state\n", __func__);
17103 + return -ESHUTDOWN;
17106 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
17108 + dwc_ep = &ep->dwc_ep;
17110 + if(ep->iso_req) {
17111 + DWC_WARN("%s, iso request in progress\n", __func__);
17113 + req->status = -EINPROGRESS;
17115 + dwc_ep->dma_addr0 = req->dma0;
17116 + dwc_ep->dma_addr1 = req->dma1;
17118 + dwc_ep->xfer_buff0 = req->buf0;
17119 + dwc_ep->xfer_buff1 = req->buf1;
17121 + ep->iso_req = req;
17123 + dwc_ep->data_per_frame = req->data_per_frame;
17125 + /** @todo - pattern data support is to be implemented in the future */
17126 + dwc_ep->data_pattern_frame = req->data_pattern_frame;
17127 + dwc_ep->sync_frame = req->sync_frame;
17129 + dwc_ep->buf_proc_intrvl = req->buf_proc_intrvl;
17131 + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
17133 + dwc_ep->proc_buf_num = 0;
17135 + dwc_ep->pkt_per_frm = 0;
17136 + frm_data = ep->dwc_ep.data_per_frame;
17137 + while(frm_data > 0) {
17138 + dwc_ep->pkt_per_frm++;
17139 + frm_data -= ep->dwc_ep.maxpacket;
17142 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
17144 + if(req->flags & USB_REQ_ISO_ASAP) {
17145 + dwc_ep->next_frame = dsts.b.soffn + 1;
17146 + if(dwc_ep->bInterval != 1){
17147 + dwc_ep->next_frame = dwc_ep->next_frame + (dwc_ep->bInterval - 1 - dwc_ep->next_frame % dwc_ep->bInterval);
17150 + dwc_ep->next_frame = req->start_frame;
17154 + if(!core_if->pti_enh_enable) {
17155 + dwc_ep->pkt_cnt = dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm / dwc_ep->bInterval;
17157 + dwc_ep->pkt_cnt =
17158 + (dwc_ep->data_per_frame * (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
17159 + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
17162 + if(core_if->dma_desc_enable) {
17163 + dwc_ep->desc_cnt =
17164 + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm / dwc_ep->bInterval;
17167 + dwc_ep->pkt_info = kmalloc(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt, GFP_KERNEL);
17168 + if(!dwc_ep->pkt_info) {
17171 + if(core_if->pti_enh_enable) {
17172 + memset(dwc_ep->pkt_info, 0, sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
17175 + dwc_ep->cur_pkt = 0;
17177 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
17179 + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
17185 + * This function stops ISO EP Periodic Data Transfer.
17187 +static int dwc_otg_pcd_iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
17189 + dwc_otg_pcd_ep_t *ep;
17190 + dwc_otg_pcd_t *pcd;
17191 + dwc_ep_t *dwc_ep;
17192 + unsigned long flags;
17194 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17196 + if (!usb_ep || !ep->desc || ep->dwc_ep.num == 0) {
17197 + DWC_WARN("%s, bad ep\n", __func__);
17203 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
17204 + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n", pcd->gadget.speed);
17205 + DWC_WARN("%s, bogus device state\n", __func__);
17206 + return -ESHUTDOWN;
17209 + dwc_ep = &ep->dwc_ep;
17211 + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
17213 + kfree(dwc_ep->pkt_info);
17215 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
17217 + if(ep->iso_req != req) {
17221 + req->status = -ECONNRESET;
17223 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
17232 + * This function is used for perodical data exchnage between PCD and gadget drivers.
17233 + * for Isochronous EPs
17235 + * - Every time a sync period completes this function is called to
17236 + * perform data exchange between PCD and gadget
17238 +void dwc_otg_iso_buffer_done(dwc_otg_pcd_ep_t *ep, dwc_otg_pcd_iso_request_t *req)
17241 + struct usb_gadget_iso_packet_descriptor *iso_packet;
17242 + dwc_ep_t *dwc_ep;
17244 + dwc_ep = &ep->dwc_ep;
17246 + if(ep->iso_req->status == -ECONNRESET) {
17247 + DWC_PRINT("Device has already disconnected\n");
17248 + /*Device has been disconnected*/
17252 + if(dwc_ep->proc_buf_num != 0) {
17253 + iso_packet = ep->iso_req->iso_packet_desc0;
17257 + iso_packet = ep->iso_req->iso_packet_desc1;
17260 + /* Fill in ISOC packets descriptors & pass to gadget driver*/
17262 + for(i = 0; i < dwc_ep->pkt_cnt; ++i) {
17263 + iso_packet[i].status = dwc_ep->pkt_info[i].status;
17264 + iso_packet[i].offset = dwc_ep->pkt_info[i].offset;
17265 + iso_packet[i].actual_length = dwc_ep->pkt_info[i].length;
17266 + dwc_ep->pkt_info[i].status = 0;
17267 + dwc_ep->pkt_info[i].offset = 0;
17268 + dwc_ep->pkt_info[i].length = 0;
17271 + /* Call callback function to process data buffer */
17272 + ep->iso_req->status = 0;/* success */
17274 + SPIN_UNLOCK(&ep->pcd->lock);
17275 + ep->iso_req->process_buffer(&ep->ep, ep->iso_req);
17276 + SPIN_LOCK(&ep->pcd->lock);
17280 +static struct usb_iso_request *dwc_otg_pcd_alloc_iso_request(struct usb_ep *ep,int packets,
17281 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
17288 + struct usb_iso_request *pReq = NULL;
17289 + uint32_t req_size;
17292 + req_size = sizeof(struct usb_iso_request);
17293 + req_size += (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
17296 + pReq = kmalloc(req_size, gfp_flags);
17298 + DWC_WARN("%s, can't allocate Iso Request\n", __func__);
17301 + pReq->iso_packet_desc0 = (void*) (pReq + 1);
17303 + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
17308 +static void dwc_otg_pcd_free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
17313 +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops =
17317 + .enable = dwc_otg_pcd_ep_enable,
17318 + .disable = dwc_otg_pcd_ep_disable,
17320 + .alloc_request = dwc_otg_pcd_alloc_request,
17321 + .free_request = dwc_otg_pcd_free_request,
17323 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
17324 + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
17325 + .free_buffer = dwc_otg_pcd_free_buffer,
17328 + .queue = dwc_otg_pcd_ep_queue,
17329 + .dequeue = dwc_otg_pcd_ep_dequeue,
17331 + .set_halt = dwc_otg_pcd_ep_set_halt,
17332 + .fifo_status = 0,
17335 + .iso_ep_start = dwc_otg_pcd_iso_ep_start,
17336 + .iso_ep_stop = dwc_otg_pcd_iso_ep_stop,
17337 + .alloc_iso_request = dwc_otg_pcd_alloc_iso_request,
17338 + .free_iso_request = dwc_otg_pcd_free_iso_request,
17344 +static struct usb_ep_ops dwc_otg_pcd_ep_ops =
17346 + .enable = dwc_otg_pcd_ep_enable,
17347 + .disable = dwc_otg_pcd_ep_disable,
17349 + .alloc_request = dwc_otg_pcd_alloc_request,
17350 + .free_request = dwc_otg_pcd_free_request,
17352 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
17353 + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
17354 + .free_buffer = dwc_otg_pcd_free_buffer,
17357 + .queue = dwc_otg_pcd_ep_queue,
17358 + .dequeue = dwc_otg_pcd_ep_dequeue,
17360 + .set_halt = dwc_otg_pcd_ep_set_halt,
17361 + .fifo_status = 0,
17367 +#endif /* DWC_EN_ISOC */
17368 +/* Gadget Operations */
17370 + * The following gadget operations will be implemented in the DWC_otg
17371 + * PCD. Functions in the API that are not described below are not
17374 + * The Gadget API provides wrapper functions for each of the function
17375 + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
17376 + * wrapper function, which then calls the underlying PCD function. The
17377 + * following sections are named according to the wrapper functions
17378 + * (except for ioctl, which doesn't have a wrapper function). Within
17379 + * each section, the corresponding DWC_otg PCD function name is
17385 + *Gets the USB Frame number of the last SOF.
17387 +static int dwc_otg_pcd_get_frame(struct usb_gadget *gadget)
17389 + dwc_otg_pcd_t *pcd;
17391 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, gadget);
17393 + if (gadget == 0) {
17397 + pcd = container_of(gadget, dwc_otg_pcd_t, gadget);
17398 + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
17404 +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t *pcd)
17406 + uint32_t *addr = (uint32_t *)&(GET_CORE_IF(pcd)->core_global_regs->gotgctl);
17407 + gotgctl_data_t mem;
17408 + gotgctl_data_t val;
17410 + val.d32 = dwc_read_reg32(addr);
17411 + if (val.b.sesreq) {
17412 + DWC_ERROR("Session Request Already active!\n");
17416 + DWC_NOTICE("Session Request Initated\n");
17417 + mem.d32 = dwc_read_reg32(addr);
17418 + mem.b.sesreq = 1;
17419 + dwc_write_reg32(addr, mem.d32);
17421 + /* Start the SRP timer */
17422 + dwc_otg_pcd_start_srp_timer(pcd);
17426 +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t *pcd, int set)
17428 + dctl_data_t dctl = {.d32=0};
17429 + volatile uint32_t *addr = &(GET_CORE_IF(pcd)->dev_if->dev_global_regs->dctl);
17431 + if (dwc_otg_is_device_mode(GET_CORE_IF(pcd))) {
17432 + if (pcd->remote_wakeup_enable) {
17434 + dctl.b.rmtwkupsig = 1;
17435 + dwc_modify_reg32(addr, 0, dctl.d32);
17436 + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
17438 + dwc_modify_reg32(addr, dctl.d32, 0);
17439 + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
17445 + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
17452 + * Initiates Session Request Protocol (SRP) to wakeup the host if no
17453 + * session is in progress. If a session is already in progress, but
17454 + * the device is suspended, remote wakeup signaling is started.
17457 +static int dwc_otg_pcd_wakeup(struct usb_gadget *gadget)
17459 + unsigned long flags;
17460 + dwc_otg_pcd_t *pcd;
17461 + dsts_data_t dsts;
17462 + gotgctl_data_t gotgctl;
17464 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, gadget);
17466 + if (gadget == 0) {
17470 + pcd = container_of(gadget, dwc_otg_pcd_t, gadget);
17472 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
17475 + * This function starts the Protocol if no session is in progress. If
17476 + * a session is already in progress, but the device is suspended,
17477 + * remote wakeup signaling is started.
17480 + /* Check if valid session */
17481 + gotgctl.d32 = dwc_read_reg32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
17482 + if (gotgctl.b.bsesvld) {
17483 + /* Check if suspend state */
17484 + dsts.d32 = dwc_read_reg32(&(GET_CORE_IF(pcd)->dev_if->dev_global_regs->dsts));
17485 + if (dsts.b.suspsts) {
17486 + dwc_otg_pcd_remote_wakeup(pcd, 1);
17490 + dwc_otg_pcd_initiate_srp(pcd);
17493 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
17497 +static const struct usb_gadget_ops dwc_otg_pcd_ops =
17499 + .get_frame = dwc_otg_pcd_get_frame,
17500 + .wakeup = dwc_otg_pcd_wakeup,
17501 + // current versions must always be self-powered
17505 + * This function updates the otg values in the gadget structure.
17507 +void dwc_otg_pcd_update_otg(dwc_otg_pcd_t *pcd, const unsigned reset)
17510 + if (!pcd->gadget.is_otg)
17514 + pcd->b_hnp_enable = 0;
17515 + pcd->a_hnp_support = 0;
17516 + pcd->a_alt_hnp_support = 0;
17519 + pcd->gadget.b_hnp_enable = pcd->b_hnp_enable;
17520 + pcd->gadget.a_hnp_support = pcd->a_hnp_support;
17521 + pcd->gadget.a_alt_hnp_support = pcd->a_alt_hnp_support;
17525 + * This function is the top level PCD interrupt handler.
17527 +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev
17528 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
17529 + , struct pt_regs *r
17533 + dwc_otg_pcd_t *pcd = dev;
17534 + int32_t retval = IRQ_NONE;
17536 + retval = dwc_otg_pcd_handle_intr(pcd);
17537 + return IRQ_RETVAL(retval);
17541 + * PCD Callback function for initializing the PCD when switching to
17544 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
17546 +static int32_t dwc_otg_pcd_start_cb(void *p)
17548 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
17551 + * Initialized the Core for Device mode.
17553 + if (dwc_otg_is_device_mode(GET_CORE_IF(pcd))) {
17554 + dwc_otg_core_dev_init(GET_CORE_IF(pcd));
17560 + * PCD Callback function for stopping the PCD when switching to Host
17563 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
17565 +static int32_t dwc_otg_pcd_stop_cb(void *p)
17567 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
17568 + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t *_pcd);
17570 + dwc_otg_pcd_stop(pcd);
17576 + * PCD Callback function for notifying the PCD when resuming from
17579 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
17581 +static int32_t dwc_otg_pcd_suspend_cb(void *p)
17583 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
17585 + if (pcd->driver && pcd->driver->resume) {
17586 + SPIN_UNLOCK(&pcd->lock);
17587 + pcd->driver->suspend(&pcd->gadget);
17588 + SPIN_LOCK(&pcd->lock);
17596 + * PCD Callback function for notifying the PCD when resuming from
17599 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
17601 +static int32_t dwc_otg_pcd_resume_cb(void *p)
17603 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
17605 + if (pcd->driver && pcd->driver->resume) {
17606 + SPIN_UNLOCK(&pcd->lock);
17607 + pcd->driver->resume(&pcd->gadget);
17608 + SPIN_LOCK(&pcd->lock);
17611 + /* Stop the SRP timeout timer. */
17612 + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS) ||
17613 + (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
17614 + if (GET_CORE_IF(pcd)->srp_timer_started) {
17615 + GET_CORE_IF(pcd)->srp_timer_started = 0;
17616 + del_timer(&pcd->srp_timer);
17624 + * PCD Callback structure for handling mode switching.
17626 +static dwc_otg_cil_callbacks_t pcd_callbacks =
17628 + .start = dwc_otg_pcd_start_cb,
17629 + .stop = dwc_otg_pcd_stop_cb,
17630 + .suspend = dwc_otg_pcd_suspend_cb,
17631 + .resume_wakeup = dwc_otg_pcd_resume_cb,
17632 + .p = 0, /* Set at registration */
17636 + * This function is called when the SRP timer expires. The SRP should
17637 + * complete within 6 seconds.
17639 +static void srp_timeout(unsigned long ptr)
17641 + gotgctl_data_t gotgctl;
17642 + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *)ptr;
17643 + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
17645 + gotgctl.d32 = dwc_read_reg32(addr);
17647 + core_if->srp_timer_started = 0;
17649 + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
17650 + (core_if->core_params->i2c_enable)) {
17651 + DWC_PRINT("SRP Timeout\n");
17653 + if ((core_if->srp_success) &&
17654 + (gotgctl.b.bsesvld)) {
17655 + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
17656 + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
17659 + /* Clear Session Request */
17661 + gotgctl.b.sesreq = 1;
17662 + dwc_modify_reg32(&core_if->core_global_regs->gotgctl,
17665 + core_if->srp_success = 0;
17668 + DWC_ERROR("Device not connected/responding\n");
17669 + gotgctl.b.sesreq = 0;
17670 + dwc_write_reg32(addr, gotgctl.d32);
17673 + else if (gotgctl.b.sesreq) {
17674 + DWC_PRINT("SRP Timeout\n");
17676 + DWC_ERROR("Device not connected/responding\n");
17677 + gotgctl.b.sesreq = 0;
17678 + dwc_write_reg32(addr, gotgctl.d32);
17681 + DWC_PRINT(" SRP GOTGCTL=%0x\n", gotgctl.d32);
17686 + * Start the SRP timer to detect when the SRP does not complete within
17689 + * @param pcd the pcd structure.
17691 +void dwc_otg_pcd_start_srp_timer(dwc_otg_pcd_t *pcd)
17693 + struct timer_list *srp_timer = &pcd->srp_timer;
17694 + GET_CORE_IF(pcd)->srp_timer_started = 1;
17695 + init_timer(srp_timer);
17696 + srp_timer->function = srp_timeout;
17697 + srp_timer->data = (unsigned long)GET_CORE_IF(pcd);
17698 + srp_timer->expires = jiffies + (HZ*6);
17699 + add_timer(srp_timer);
17706 +extern void start_next_request(dwc_otg_pcd_ep_t *ep);
17708 +static void start_xfer_tasklet_func (unsigned long data)
17710 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t*)data;
17711 + dwc_otg_core_if_t *core_if = pcd->otg_dev->core_if;
17714 + depctl_data_t diepctl;
17716 + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
17718 + diepctl.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[0]->diepctl);
17720 + if (pcd->ep0.queue_sof) {
17721 + pcd->ep0.queue_sof = 0;
17722 + start_next_request (&pcd->ep0);
17726 + for (i=0; i<core_if->dev_if->num_in_eps; i++)
17728 + depctl_data_t diepctl;
17729 + diepctl.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[i]->diepctl);
17731 + if (pcd->in_ep[i].queue_sof) {
17732 + pcd->in_ep[i].queue_sof = 0;
17733 + start_next_request (&pcd->in_ep[i]);
17747 +static struct tasklet_struct start_xfer_tasklet = {
17750 + .count = ATOMIC_INIT(0),
17751 + .func = start_xfer_tasklet_func,
17755 + * This function initialized the pcd Dp structures to there default
17758 + * @param pcd the pcd structure.
17760 +void dwc_otg_pcd_reinit(dwc_otg_pcd_t *pcd)
17762 + static const char * names[] =
17800 + int in_ep_cntr, out_ep_cntr;
17802 + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
17803 + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
17804 + dwc_otg_pcd_ep_t *ep;
17806 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
17808 + INIT_LIST_HEAD (&pcd->gadget.ep_list);
17809 + pcd->gadget.ep0 = &pcd->ep0.ep;
17810 + pcd->gadget.speed = USB_SPEED_UNKNOWN;
17812 + INIT_LIST_HEAD (&pcd->gadget.ep0->ep_list);
17815 + * Initialize the EP0 structure.
17819 + /* Init EP structure */
17824 + /* Init DWC ep structure */
17825 + ep->dwc_ep.num = 0;
17826 + ep->dwc_ep.active = 0;
17827 + ep->dwc_ep.tx_fifo_num = 0;
17828 + /* Control until ep is actvated */
17829 + ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
17830 + ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
17831 + ep->dwc_ep.dma_addr = 0;
17832 + ep->dwc_ep.start_xfer_buff = 0;
17833 + ep->dwc_ep.xfer_buff = 0;
17834 + ep->dwc_ep.xfer_len = 0;
17835 + ep->dwc_ep.xfer_count = 0;
17836 + ep->dwc_ep.sent_zlp = 0;
17837 + ep->dwc_ep.total_len = 0;
17838 + ep->queue_sof = 0;
17839 + ep->dwc_ep.desc_addr = 0;
17840 + ep->dwc_ep.dma_desc_addr = 0;
17843 + /* Init the usb_ep structure. */
17844 + ep->ep.name = names[0];
17845 + ep->ep.ops = (struct usb_ep_ops*)&dwc_otg_pcd_ep_ops;
17848 + * @todo NGS: What should the max packet size be set to
17849 + * here? Before EP type is set?
17851 + ep->ep.maxpacket = MAX_PACKET_SIZE;
17853 + list_add_tail (&ep->ep.ep_list, &pcd->gadget.ep_list);
17855 + INIT_LIST_HEAD (&ep->queue);
17857 + * Initialize the EP structures.
17860 + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
17862 + for (i = 1; in_ep_cntr < num_in_eps; i++)
17864 + if((hwcfg1 & 0x1) == 0) {
17865 + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
17868 + /* Init EP structure */
17873 + /* Init DWC ep structure */
17874 + ep->dwc_ep.is_in = 1;
17875 + ep->dwc_ep.num = i;
17876 + ep->dwc_ep.active = 0;
17877 + ep->dwc_ep.tx_fifo_num = 0;
17879 + /* Control until ep is actvated */
17880 + ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
17881 + ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
17882 + ep->dwc_ep.dma_addr = 0;
17883 + ep->dwc_ep.start_xfer_buff = 0;
17884 + ep->dwc_ep.xfer_buff = 0;
17885 + ep->dwc_ep.xfer_len = 0;
17886 + ep->dwc_ep.xfer_count = 0;
17887 + ep->dwc_ep.sent_zlp = 0;
17888 + ep->dwc_ep.total_len = 0;
17889 + ep->queue_sof = 0;
17890 + ep->dwc_ep.desc_addr = 0;
17891 + ep->dwc_ep.dma_desc_addr = 0;
17893 + /* Init the usb_ep structure. */
17894 + ep->ep.name = names[i];
17895 + ep->ep.ops = (struct usb_ep_ops*)&dwc_otg_pcd_ep_ops;
17898 + * @todo NGS: What should the max packet size be set to
17899 + * here? Before EP type is set?
17901 + ep->ep.maxpacket = MAX_PACKET_SIZE;
17903 + list_add_tail (&ep->ep.ep_list, &pcd->gadget.ep_list);
17905 + INIT_LIST_HEAD (&ep->queue);
17911 + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
17913 + for (i = 1; out_ep_cntr < num_out_eps; i++)
17915 + if((hwcfg1 & 0x1) == 0) {
17916 + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
17919 + /* Init EP structure */
17924 + /* Init DWC ep structure */
17925 + ep->dwc_ep.is_in = 0;
17926 + ep->dwc_ep.num = i;
17927 + ep->dwc_ep.active = 0;
17928 + ep->dwc_ep.tx_fifo_num = 0;
17929 + /* Control until ep is actvated */
17930 + ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
17931 + ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
17932 + ep->dwc_ep.dma_addr = 0;
17933 + ep->dwc_ep.start_xfer_buff = 0;
17934 + ep->dwc_ep.xfer_buff = 0;
17935 + ep->dwc_ep.xfer_len = 0;
17936 + ep->dwc_ep.xfer_count = 0;
17937 + ep->dwc_ep.sent_zlp = 0;
17938 + ep->dwc_ep.total_len = 0;
17939 + ep->queue_sof = 0;
17941 + /* Init the usb_ep structure. */
17942 + ep->ep.name = names[15 + i];
17943 + ep->ep.ops = (struct usb_ep_ops*)&dwc_otg_pcd_ep_ops;
17945 + * @todo NGS: What should the max packet size be set to
17946 + * here? Before EP type is set?
17948 + ep->ep.maxpacket = MAX_PACKET_SIZE;
17950 + list_add_tail (&ep->ep.ep_list, &pcd->gadget.ep_list);
17952 + INIT_LIST_HEAD (&ep->queue);
17957 + /* remove ep0 from the list. There is a ep0 pointer.*/
17958 + list_del_init (&pcd->ep0.ep.ep_list);
17960 + pcd->ep0state = EP0_DISCONNECT;
17961 + pcd->ep0.ep.maxpacket = MAX_EP0_SIZE;
17962 + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
17963 + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
17967 + * This function releases the Gadget device.
17968 + * required by device_unregister().
17970 + * @todo Should this do something? Should it free the PCD?
17972 +static void dwc_otg_pcd_gadget_release(struct device *dev)
17974 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, dev);
17980 + * This function initialized the PCD portion of the driver.
17984 +int dwc_otg_pcd_init(struct device *dev)
17986 + static char pcd_name[] = "dwc_otg_pcd";
17987 + dwc_otg_pcd_t *pcd;
17988 + dwc_otg_core_if_t* core_if;
17989 + dwc_otg_dev_if_t* dev_if;
17990 + dwc_otg_device_t *otg_dev = dev_get_drvdata(dev);
17994 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n",__func__, dev);
17996 + * Allocate PCD structure
17998 + pcd = kmalloc(sizeof(dwc_otg_pcd_t), GFP_KERNEL);
18004 + memset(pcd, 0, sizeof(dwc_otg_pcd_t));
18005 + spin_lock_init(&pcd->lock);
18007 + otg_dev->pcd = pcd;
18009 + pcd->gadget.name = pcd_name;
18010 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
18011 + strcpy(pcd->gadget.dev.bus_id, "gadget");
18013 + dev_set_name(&pcd->gadget.dev, "%s", "gadget");
18016 + pcd->otg_dev = dev_get_drvdata(dev);
18018 + pcd->gadget.dev.parent = dev;
18019 + pcd->gadget.dev.release = dwc_otg_pcd_gadget_release;
18020 + pcd->gadget.ops = &dwc_otg_pcd_ops;
18022 + core_if = GET_CORE_IF(pcd);
18023 + dev_if = core_if->dev_if;
18025 + if(core_if->hwcfg4.b.ded_fifo_en) {
18026 + DWC_PRINT("Dedicated Tx FIFOs mode\n");
18029 + DWC_PRINT("Shared Tx FIFO mode\n");
18032 + /* If the module is set to FS or if the PHY_TYPE is FS then the gadget
18033 + * should not report as dual-speed capable. replace the following line
18034 + * with the block of code below it once the software is debugged for
18035 + * this. If is_dualspeed = 0 then the gadget driver should not report
18036 + * a device qualifier descriptor when queried. */
18037 + if ((GET_CORE_IF(pcd)->core_params->speed == DWC_SPEED_PARAM_FULL) ||
18038 + ((GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == 2) &&
18039 + (GET_CORE_IF(pcd)->hwcfg2.b.fs_phy_type == 1) &&
18040 + (GET_CORE_IF(pcd)->core_params->ulpi_fs_ls))) {
18041 + pcd->gadget.is_dualspeed = 0;
18044 + pcd->gadget.is_dualspeed = 1;
18047 + if ((otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE) ||
18048 + (otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST) ||
18049 + (otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
18050 + (otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
18051 + pcd->gadget.is_otg = 0;
18054 + pcd->gadget.is_otg = 1;
18059 + /* Register the gadget device */
18060 + retval = device_register(&pcd->gadget.dev);
18061 + if (retval != 0) {
18068 + * Initialized the Core for Device mode.
18070 + if (dwc_otg_is_device_mode(core_if)) {
18071 + dwc_otg_core_dev_init(core_if);
18075 + * Initialize EP structures
18077 + dwc_otg_pcd_reinit(pcd);
18080 + * Register the PCD Callbacks.
18082 + dwc_otg_cil_register_pcd_callbacks(otg_dev->core_if, &pcd_callbacks,
18085 + * Setup interupt handler
18087 + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n", otg_dev->irq);
18088 + retval = request_irq(otg_dev->irq, dwc_otg_pcd_irq,
18089 + IRQF_SHARED, pcd->gadget.name, pcd);
18090 + if (retval != 0) {
18091 + DWC_ERROR("request of irq%d failed\n", otg_dev->irq);
18092 + device_unregister(&pcd->gadget.dev);
18098 + * Initialize the DMA buffer for SETUP packets
18100 + if (GET_CORE_IF(pcd)->dma_enable) {
18101 + pcd->setup_pkt = dma_alloc_coherent (NULL, sizeof (*pcd->setup_pkt) * 5, &pcd->setup_pkt_dma_handle, 0);
18102 + if (pcd->setup_pkt == 0) {
18103 + free_irq(otg_dev->irq, pcd);
18104 + device_unregister(&pcd->gadget.dev);
18109 + pcd->status_buf = dma_alloc_coherent (NULL, sizeof (uint16_t), &pcd->status_buf_dma_handle, 0);
18110 + if (pcd->status_buf == 0) {
18111 + dma_free_coherent(NULL, sizeof(*pcd->setup_pkt), pcd->setup_pkt, pcd->setup_pkt_dma_handle);
18112 + free_irq(otg_dev->irq, pcd);
18113 + device_unregister(&pcd->gadget.dev);
18118 + if (GET_CORE_IF(pcd)->dma_desc_enable) {
18119 + dev_if->setup_desc_addr[0] = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_setup_desc_addr[0], 1);
18120 + dev_if->setup_desc_addr[1] = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_setup_desc_addr[1], 1);
18121 + dev_if->in_desc_addr = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_in_desc_addr, 1);
18122 + dev_if->out_desc_addr = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_out_desc_addr, 1);
18124 + if(dev_if->setup_desc_addr[0] == 0
18125 + || dev_if->setup_desc_addr[1] == 0
18126 + || dev_if->in_desc_addr == 0
18127 + || dev_if->out_desc_addr == 0 ) {
18129 + if(dev_if->out_desc_addr)
18130 + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr, dev_if->dma_out_desc_addr, 1);
18131 + if(dev_if->in_desc_addr)
18132 + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr, dev_if->dma_in_desc_addr, 1);
18133 + if(dev_if->setup_desc_addr[1])
18134 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1], dev_if->dma_setup_desc_addr[1], 1);
18135 + if(dev_if->setup_desc_addr[0])
18136 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0], dev_if->dma_setup_desc_addr[0], 1);
18139 + dma_free_coherent(NULL, sizeof(*pcd->status_buf), pcd->status_buf, pcd->setup_pkt_dma_handle);
18140 + dma_free_coherent(NULL, sizeof(*pcd->setup_pkt), pcd->setup_pkt, pcd->setup_pkt_dma_handle);
18142 + free_irq(otg_dev->irq, pcd);
18143 + device_unregister(&pcd->gadget.dev);
18151 + pcd->setup_pkt = kmalloc (sizeof (*pcd->setup_pkt) * 5, GFP_KERNEL);
18152 + if (pcd->setup_pkt == 0) {
18153 + free_irq(otg_dev->irq, pcd);
18154 + device_unregister(&pcd->gadget.dev);
18159 + pcd->status_buf = kmalloc (sizeof (uint16_t), GFP_KERNEL);
18160 + if (pcd->status_buf == 0) {
18161 + kfree(pcd->setup_pkt);
18162 + free_irq(otg_dev->irq, pcd);
18163 + device_unregister(&pcd->gadget.dev);
18170 + /* Initialize tasklet */
18171 + start_xfer_tasklet.data = (unsigned long)pcd;
18172 + pcd->start_xfer_tasklet = &start_xfer_tasklet;
18178 + * Cleanup the PCD.
18180 +void dwc_otg_pcd_remove(struct device *dev)
18182 + dwc_otg_device_t *otg_dev = dev_get_drvdata(dev);
18183 + dwc_otg_pcd_t *pcd = otg_dev->pcd;
18184 + dwc_otg_dev_if_t* dev_if = GET_CORE_IF(pcd)->dev_if;
18186 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
18191 + free_irq(otg_dev->irq, pcd);
18193 + /* start with the driver above us */
18194 + if (pcd->driver) {
18195 + /* should have been done already by driver model core */
18196 + DWC_WARN("driver '%s' is still registered\n",
18197 + pcd->driver->driver.name);
18198 + usb_gadget_unregister_driver(pcd->driver);
18200 + device_unregister(&pcd->gadget.dev);
18202 + if (GET_CORE_IF(pcd)->dma_enable) {
18203 + dma_free_coherent (NULL, sizeof (*pcd->setup_pkt) * 5, pcd->setup_pkt, pcd->setup_pkt_dma_handle);
18204 + dma_free_coherent (NULL, sizeof (uint16_t), pcd->status_buf, pcd->status_buf_dma_handle);
18205 + if (GET_CORE_IF(pcd)->dma_desc_enable) {
18206 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0], dev_if->dma_setup_desc_addr[0], 1);
18207 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1], dev_if->dma_setup_desc_addr[1], 1);
18208 + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr, dev_if->dma_in_desc_addr, 1);
18209 + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr, dev_if->dma_out_desc_addr, 1);
18213 + kfree (pcd->setup_pkt);
18214 + kfree (pcd->status_buf);
18218 + otg_dev->pcd = 0;
18222 + * This function registers a gadget driver with the PCD.
18224 + * When a driver is successfully registered, it will receive control
18225 + * requests including set_configuration(), which enables non-control
18226 + * requests. then usb traffic follows until a disconnect is reported.
18227 + * then a host may connect again, or the driver might get unbound.
18229 + * @param driver The driver being registered
18231 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
18232 +int usb_gadget_probe_driver(struct usb_gadget_driver *driver, int (*bind)(struct usb_gadget *))
18234 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
18238 + int (*d_bind)(struct usb_gadget *);
18239 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
18242 + d_bind = driver->bind;
18245 + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n", driver->driver.name);
18247 + if (!driver || driver->speed == USB_SPEED_UNKNOWN ||
18249 + !driver->unbind ||
18250 + !driver->disconnect ||
18251 + !driver->setup) {
18252 + DWC_DEBUGPL(DBG_PCDV,"EINVAL\n");
18255 + if (s_pcd == 0) {
18256 + DWC_DEBUGPL(DBG_PCDV,"ENODEV\n");
18259 + if (s_pcd->driver != 0) {
18260 + DWC_DEBUGPL(DBG_PCDV,"EBUSY (%p)\n", s_pcd->driver);
18264 + /* hook up the driver */
18265 + s_pcd->driver = driver;
18266 + s_pcd->gadget.dev.driver = &driver->driver;
18268 + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
18269 + retval = d_bind(&s_pcd->gadget);
18271 + DWC_ERROR("bind to driver %s --> error %d\n",
18272 + driver->driver.name, retval);
18273 + s_pcd->driver = 0;
18274 + s_pcd->gadget.dev.driver = 0;
18277 + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
18278 + driver->driver.name);
18282 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
18283 +EXPORT_SYMBOL(usb_gadget_probe_driver);
18285 +EXPORT_SYMBOL(usb_gadget_register_driver);
18289 + * This function unregisters a gadget driver
18291 + * @param driver The driver being unregistered
18293 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
18295 + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
18297 + if (s_pcd == 0) {
18298 + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
18302 + if (driver == 0 || driver != s_pcd->driver) {
18303 + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
18308 + driver->unbind(&s_pcd->gadget);
18309 + s_pcd->driver = 0;
18311 + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n",
18312 + driver->driver.name);
18315 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
18317 +#endif /* DWC_HOST_ONLY */
18318 diff --git a/drivers/usb/dwc_otg/dwc_otg_pcd.h b/drivers/usb/dwc_otg/dwc_otg_pcd.h
18319 new file mode 100644
18320 index 0000000..48de957
18322 +++ b/drivers/usb/dwc_otg/dwc_otg_pcd.h
18324 +/* ==========================================================================
18325 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
18326 + * $Revision: 1.2 $
18327 + * $Date: 2008-11-21 05:39:15 $
18328 + * $Change: 1103515 $
18330 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
18331 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
18332 + * otherwise expressly agreed to in writing between Synopsys and you.
18334 + * The Software IS NOT an item of Licensed Software or Licensed Product under
18335 + * any End User Software License Agreement or Agreement for Licensed Product
18336 + * with Synopsys or any supplement thereto. You are permitted to use and
18337 + * redistribute this Software in source and binary forms, with or without
18338 + * modification, provided that redistributions of source code must retain this
18339 + * notice. You may not view, use, disclose, copy or distribute this file or
18340 + * any information contained herein except pursuant to this license grant from
18341 + * Synopsys. If you do not agree with this notice, including the disclaimer
18342 + * below, then you are not authorized to use the Software.
18344 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
18345 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18346 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18347 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
18348 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18349 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18350 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
18351 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18352 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
18353 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
18355 + * ========================================================================== */
18356 +#ifndef DWC_HOST_ONLY
18357 +#if !defined(__DWC_PCD_H__)
18358 +#define __DWC_PCD_H__
18360 +#include <linux/types.h>
18361 +#include <linux/list.h>
18362 +#include <linux/errno.h>
18363 +#include <linux/device.h>
18365 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
18366 +# include <linux/usb/ch9.h>
18368 +# include <linux/usb_ch9.h>
18371 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
18372 +#include <linux/usb/gadget.h>
18374 +#include <linux/usb_gadget.h>
18376 +#include <linux/interrupt.h>
18377 +#include <linux/dma-mapping.h>
18379 +struct dwc_otg_device;
18381 +#include "dwc_otg_cil.h"
18386 + * This file contains the structures, constants, and interfaces for
18387 + * the Perpherial Contoller Driver (PCD).
18389 + * The Peripheral Controller Driver (PCD) for Linux will implement the
18390 + * Gadget API, so that the existing Gadget drivers can be used. For
18391 + * the Mass Storage Function driver the File-backed USB Storage Gadget
18392 + * (FBS) driver will be used. The FBS driver supports the
18393 + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
18398 +/** Invalid DMA Address */
18399 +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
18400 +/** Maxpacket size for EP0 */
18401 +#define MAX_EP0_SIZE 64
18402 +/** Maxpacket size for any EP */
18403 +#define MAX_PACKET_SIZE 1024
18405 +/** Max Transfer size for any EP */
18406 +#define MAX_TRANSFER_SIZE 65535
18408 +/** Max DMA Descriptor count for any EP */
18409 +#define MAX_DMA_DESC_CNT 64
18412 + * Get the pointer to the core_if from the pcd pointer.
18414 +#define GET_CORE_IF( _pcd ) (_pcd->otg_dev->core_if)
18419 +typedef enum ep0_state
18421 + EP0_DISCONNECT, /* no host */
18423 + EP0_IN_DATA_PHASE,
18424 + EP0_OUT_DATA_PHASE,
18425 + EP0_IN_STATUS_PHASE,
18426 + EP0_OUT_STATUS_PHASE,
18430 +/** Fordward declaration.*/
18431 +struct dwc_otg_pcd;
18433 +/** DWC_otg iso request structure.
18436 +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
18438 +/** PCD EP structure.
18439 + * This structure describes an EP, there is an array of EPs in the PCD
18442 +typedef struct dwc_otg_pcd_ep
18444 + /** USB EP data */
18445 + struct usb_ep ep;
18446 + /** USB EP Descriptor */
18447 + const struct usb_endpoint_descriptor *desc;
18449 + /** queue of dwc_otg_pcd_requests. */
18450 + struct list_head queue;
18451 + unsigned stopped : 1;
18452 + unsigned disabling : 1;
18453 + unsigned dma : 1;
18454 + unsigned queue_sof : 1;
18456 +#ifdef DWC_EN_ISOC
18457 + /** DWC_otg Isochronous Transfer */
18458 + struct usb_iso_request* iso_req;
18459 +#endif //DWC_EN_ISOC
18461 + /** DWC_otg ep data. */
18464 + /** Pointer to PCD */
18465 + struct dwc_otg_pcd *pcd;
18466 +}dwc_otg_pcd_ep_t;
18470 +/** DWC_otg PCD Structure.
18471 + * This structure encapsulates the data for the dwc_otg PCD.
18473 +typedef struct dwc_otg_pcd
18475 + /** USB gadget */
18476 + struct usb_gadget gadget;
18477 + /** USB gadget driver pointer*/
18478 + struct usb_gadget_driver *driver;
18479 + /** The DWC otg device pointer. */
18480 + struct dwc_otg_device *otg_dev;
18482 + /** State of EP0 */
18483 + ep0state_e ep0state;
18484 + /** EP0 Request is pending */
18485 + unsigned ep0_pending : 1;
18486 + /** Indicates when SET CONFIGURATION Request is in process */
18487 + unsigned request_config : 1;
18488 + /** The state of the Remote Wakeup Enable. */
18489 + unsigned remote_wakeup_enable : 1;
18490 + /** The state of the B-Device HNP Enable. */
18491 + unsigned b_hnp_enable : 1;
18492 + /** The state of A-Device HNP Support. */
18493 + unsigned a_hnp_support : 1;
18494 + /** The state of the A-Device Alt HNP support. */
18495 + unsigned a_alt_hnp_support : 1;
18496 + /** Count of pending Requests */
18497 + unsigned request_pending;
18499 + /** SETUP packet for EP0
18500 + * This structure is allocated as a DMA buffer on PCD initialization
18501 + * with enough space for up to 3 setup packets.
18505 + struct usb_ctrlrequest req;
18509 + dma_addr_t setup_pkt_dma_handle;
18511 + /** 2-byte dma buffer used to return status from GET_STATUS */
18512 + uint16_t *status_buf;
18513 + dma_addr_t status_buf_dma_handle;
18516 + dwc_otg_pcd_ep_t ep0;
18518 + /** Array of IN EPs. */
18519 + dwc_otg_pcd_ep_t in_ep[ MAX_EPS_CHANNELS - 1];
18520 + /** Array of OUT EPs. */
18521 + dwc_otg_pcd_ep_t out_ep[ MAX_EPS_CHANNELS - 1];
18522 + /** number of valid EPs in the above array. */
18523 +// unsigned num_eps : 4;
18525 + /** Timer for SRP. If it expires before SRP is successful
18526 + * clear the SRP. */
18527 + struct timer_list srp_timer;
18529 + /** Tasklet to defer starting of TEST mode transmissions until
18530 + * Status Phase has been completed.
18532 + struct tasklet_struct test_mode_tasklet;
18534 + /** Tasklet to delay starting of xfer in DMA mode */
18535 + struct tasklet_struct *start_xfer_tasklet;
18537 + /** The test mode to enter when the tasklet is executed. */
18538 + unsigned test_mode;
18543 +/** DWC_otg request structure.
18544 + * This structure is a list of requests.
18548 + struct usb_request req; /**< USB Request. */
18549 + struct list_head queue; /**< queue of these requests. */
18550 +} dwc_otg_pcd_request_t;
18553 +extern int dwc_otg_pcd_init(struct device *dev);
18555 +//extern void dwc_otg_pcd_remove( struct dwc_otg_device *_otg_dev );
18556 +extern void dwc_otg_pcd_remove( struct device *dev);
18557 +extern int32_t dwc_otg_pcd_handle_intr( dwc_otg_pcd_t *pcd );
18558 +extern void dwc_otg_pcd_start_srp_timer(dwc_otg_pcd_t *pcd );
18560 +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t *pcd);
18561 +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t *pcd, int set);
18563 +extern void dwc_otg_iso_buffer_done(dwc_otg_pcd_ep_t *ep, dwc_otg_pcd_iso_request_t *req);
18564 +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t *_ep, dwc_otg_pcd_request_t *req,
18566 +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t *_ep);
18567 +extern void dwc_otg_pcd_update_otg(dwc_otg_pcd_t *_pcd,
18568 + const unsigned reset);
18571 +#endif /* DWC_HOST_ONLY */
18572 diff --git a/drivers/usb/dwc_otg/dwc_otg_pcd_intr.c b/drivers/usb/dwc_otg/dwc_otg_pcd_intr.c
18573 new file mode 100644
18574 index 0000000..fd44fd8
18576 +++ b/drivers/usb/dwc_otg/dwc_otg_pcd_intr.c
18578 +/* ==========================================================================
18579 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
18580 + * $Revision: 1.2 $
18581 + * $Date: 2008-11-21 05:39:15 $
18582 + * $Change: 1115682 $
18584 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
18585 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
18586 + * otherwise expressly agreed to in writing between Synopsys and you.
18588 + * The Software IS NOT an item of Licensed Software or Licensed Product under
18589 + * any End User Software License Agreement or Agreement for Licensed Product
18590 + * with Synopsys or any supplement thereto. You are permitted to use and
18591 + * redistribute this Software in source and binary forms, with or without
18592 + * modification, provided that redistributions of source code must retain this
18593 + * notice. You may not view, use, disclose, copy or distribute this file or
18594 + * any information contained herein except pursuant to this license grant from
18595 + * Synopsys. If you do not agree with this notice, including the disclaimer
18596 + * below, then you are not authorized to use the Software.
18598 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
18599 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18600 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18601 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
18602 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18603 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18604 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
18605 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18606 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
18607 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
18609 + * ========================================================================== */
18610 +#ifndef DWC_HOST_ONLY
18611 +#include <linux/interrupt.h>
18612 +#include <linux/dma-mapping.h>
18613 +#include <linux/version.h>
18615 +#include "dwc_otg_driver.h"
18616 +#include "dwc_otg_pcd.h"
18621 +/* request functions defined in "dwc_otg_pcd.c" */
18624 + * This file contains the implementation of the PCD Interrupt handlers.
18626 + * The PCD handles the device interrupts. Many conditions can cause a
18627 + * device interrupt. When an interrupt occurs, the device interrupt
18628 + * service routine determines the cause of the interrupt and
18629 + * dispatches handling to the appropriate function. These interrupt
18630 + * handling functions are described below.
18631 + * All interrupt registers are processed from LSB to MSB.
18636 + * This function prints the ep0 state for debug purposes.
18638 +static inline void print_ep0_state(dwc_otg_pcd_t *pcd)
18643 + switch (pcd->ep0state) {
18644 + case EP0_DISCONNECT:
18645 + strcpy(str, "EP0_DISCONNECT");
18648 + strcpy(str, "EP0_IDLE");
18650 + case EP0_IN_DATA_PHASE:
18651 + strcpy(str, "EP0_IN_DATA_PHASE");
18653 + case EP0_OUT_DATA_PHASE:
18654 + strcpy(str, "EP0_OUT_DATA_PHASE");
18656 + case EP0_IN_STATUS_PHASE:
18657 + strcpy(str,"EP0_IN_STATUS_PHASE");
18659 + case EP0_OUT_STATUS_PHASE:
18660 + strcpy(str,"EP0_OUT_STATUS_PHASE");
18663 + strcpy(str,"EP0_STALL");
18666 + strcpy(str,"EP0_INVALID");
18669 + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
18674 + * This function returns pointer to in ep struct with number ep_num
18676 +static inline dwc_otg_pcd_ep_t* get_in_ep(dwc_otg_pcd_t *pcd, uint32_t ep_num)
18679 + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
18680 + if(ep_num == 0) {
18681 + return &pcd->ep0;
18684 + for(i = 0; i < num_in_eps; ++i)
18686 + if(pcd->in_ep[i].dwc_ep.num == ep_num)
18687 + return &pcd->in_ep[i];
18693 + * This function returns pointer to out ep struct with number ep_num
18695 +static inline dwc_otg_pcd_ep_t* get_out_ep(dwc_otg_pcd_t *pcd, uint32_t ep_num)
18698 + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
18699 + if(ep_num == 0) {
18700 + return &pcd->ep0;
18703 + for(i = 0; i < num_out_eps; ++i)
18705 + if(pcd->out_ep[i].dwc_ep.num == ep_num)
18706 + return &pcd->out_ep[i];
18712 + * This functions gets a pointer to an EP from the wIndex address
18713 + * value of the control request.
18715 +static dwc_otg_pcd_ep_t *get_ep_by_addr (dwc_otg_pcd_t *pcd, u16 wIndex)
18717 + dwc_otg_pcd_ep_t *ep;
18719 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
18720 + return &pcd->ep0;
18721 + list_for_each_entry(ep, &pcd->gadget.ep_list, ep.ep_list)
18723 + u8 bEndpointAddress;
18728 + bEndpointAddress = ep->desc->bEndpointAddress;
18729 + if((wIndex & (USB_DIR_IN | USB_ENDPOINT_NUMBER_MASK))
18730 + == (bEndpointAddress & (USB_DIR_IN | USB_ENDPOINT_NUMBER_MASK)))
18737 + * This function checks the EP request queue, if the queue is not
18738 + * empty the next request is started.
18740 +void start_next_request(dwc_otg_pcd_ep_t *ep)
18742 + dwc_otg_pcd_request_t *req = 0;
18743 + uint32_t max_transfer = GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
18745 + if (!list_empty(&ep->queue)) {
18746 + req = list_entry(ep->queue.next,
18747 + dwc_otg_pcd_request_t, queue);
18749 + /* Setup and start the Transfer */
18750 + ep->dwc_ep.dma_addr = req->req.dma;
18751 + ep->dwc_ep.start_xfer_buff = req->req.buf;
18752 + ep->dwc_ep.xfer_buff = req->req.buf;
18753 + ep->dwc_ep.sent_zlp = 0;
18754 + ep->dwc_ep.total_len = req->req.length;
18755 + ep->dwc_ep.xfer_len = 0;
18756 + ep->dwc_ep.xfer_count = 0;
18758 + if(max_transfer > MAX_TRANSFER_SIZE) {
18759 + ep->dwc_ep.maxxfer = max_transfer - (max_transfer % ep->dwc_ep.maxpacket);
18761 + ep->dwc_ep.maxxfer = max_transfer;
18764 + if(req->req.zero) {
18765 + if((ep->dwc_ep.total_len % ep->dwc_ep.maxpacket == 0)
18766 + && (ep->dwc_ep.total_len != 0)) {
18767 + ep->dwc_ep.sent_zlp = 1;
18772 + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
18777 + * This function handles the SOF Interrupts. At this time the SOF
18778 + * Interrupt is disabled.
18780 +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t *pcd)
18782 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
18784 + gintsts_data_t gintsts;
18786 + DWC_DEBUGPL(DBG_PCD, "SOF\n");
18788 + /* Clear interrupt */
18790 + gintsts.b.sofintr = 1;
18791 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
18798 + * This function handles the Rx Status Queue Level Interrupt, which
18799 + * indicates that there is a least one packet in the Rx FIFO. The
18800 + * packets are moved from the FIFO to memory, where they will be
18801 + * processed when the Endpoint Interrupt Register indicates Transfer
18802 + * Complete or SETUP Phase Done.
18804 + * Repeat the following until the Rx Status Queue is empty:
18805 + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
18807 + * -# If Receive FIFO is empty then skip to step Clear the interrupt
18809 + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
18810 + * SETUP data to the buffer
18811 + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
18812 + * to the destination buffer
18814 +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t *pcd)
18816 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
18817 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
18818 + gintmsk_data_t gintmask = {.d32=0};
18819 + device_grxsts_data_t status;
18820 + dwc_otg_pcd_ep_t *ep;
18821 + gintsts_data_t gintsts;
18823 + static char *dpid_str[] ={ "D0", "D2", "D1", "MDATA" };
18826 + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
18827 + /* Disable the Rx Status Queue Level interrupt */
18828 + gintmask.b.rxstsqlvl= 1;
18829 + dwc_modify_reg32(&global_regs->gintmsk, gintmask.d32, 0);
18831 + /* Get the Status from the top of the FIFO */
18832 + status.d32 = dwc_read_reg32(&global_regs->grxstsp);
18834 + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
18835 + "pktsts:%x Frame:%d(0x%0x)\n",
18836 + status.b.epnum, status.b.bcnt,
18837 + dpid_str[status.b.dpid],
18838 + status.b.pktsts, status.b.fn, status.b.fn);
18839 + /* Get pointer to EP structure */
18840 + ep = get_out_ep(pcd, status.b.epnum);
18842 + switch (status.b.pktsts) {
18843 + case DWC_DSTS_GOUT_NAK:
18844 + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
18846 + case DWC_STS_DATA_UPDT:
18847 + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
18848 + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
18849 + /** @todo NGS Check for buffer overflow? */
18850 + dwc_otg_read_packet(core_if,
18851 + ep->dwc_ep.xfer_buff,
18853 + ep->dwc_ep.xfer_count += status.b.bcnt;
18854 + ep->dwc_ep.xfer_buff += status.b.bcnt;
18857 + case DWC_STS_XFER_COMP:
18858 + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
18860 + case DWC_DSTS_SETUP_COMP:
18862 + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
18865 +case DWC_DSTS_SETUP_UPDT:
18866 + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
18868 + DWC_DEBUGPL(DBG_PCD,
18869 + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
18870 + pcd->setup_pkt->req.bRequestType,
18871 + pcd->setup_pkt->req.bRequest,
18872 + pcd->setup_pkt->req.wValue,
18873 + pcd->setup_pkt->req.wIndex,
18874 + pcd->setup_pkt->req.wLength);
18876 + ep->dwc_ep.xfer_count += status.b.bcnt;
18879 + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
18880 + status.b.pktsts);
18884 + /* Enable the Rx Status Queue Level interrupt */
18885 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmask.d32);
18886 + /* Clear interrupt */
18888 + gintsts.b.rxstsqlvl = 1;
18889 + dwc_write_reg32 (&global_regs->gintsts, gintsts.d32);
18891 + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
18895 + * This function examines the Device IN Token Learning Queue to
18896 + * determine the EP number of the last IN token received. This
18897 + * implementation is for the Mass Storage device where there are only
18898 + * 2 IN EPs (Control-IN and BULK-IN).
18900 + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
18901 + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
18903 + * @param core_if Programming view of DWC_otg controller.
18906 +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t *core_if)
18908 + dwc_otg_device_global_regs_t *dev_global_regs =
18909 + core_if->dev_if->dev_global_regs;
18910 + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
18911 + /* Number of Token Queue Registers */
18912 + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
18913 + dtknq1_data_t dtknqr1;
18914 + uint32_t in_tkn_epnums[4];
18917 + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
18920 + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
18923 + /* Read the DTKNQ Registers */
18924 + for (i = 0; i < DTKNQ_REG_CNT; i++)
18926 + in_tkn_epnums[ i ] = dwc_read_reg32(addr);
18927 + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i+1,
18928 + in_tkn_epnums[i]);
18929 + if (addr == &dev_global_regs->dvbusdis) {
18930 + addr = &dev_global_regs->dtknqr3_dthrctl;
18938 + /* Copy the DTKNQR1 data to the bit field. */
18939 + dtknqr1.d32 = in_tkn_epnums[0];
18940 + /* Get the EP numbers */
18941 + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
18942 + ndx = dtknqr1.b.intknwptr - 1;
18944 + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
18946 + /** @todo Find a simpler way to calculate the max
18947 + * queue position.*/
18948 + int cnt = TOKEN_Q_DEPTH;
18949 + if (TOKEN_Q_DEPTH <= 6) {
18950 + cnt = TOKEN_Q_DEPTH - 1;
18952 + else if (TOKEN_Q_DEPTH <= 14) {
18953 + cnt = TOKEN_Q_DEPTH - 7;
18955 + else if (TOKEN_Q_DEPTH <= 22) {
18956 + cnt = TOKEN_Q_DEPTH - 15;
18959 + cnt = TOKEN_Q_DEPTH - 23;
18961 + epnum = (in_tkn_epnums[ DTKNQ_REG_CNT - 1 ] >> (cnt * 4)) & 0xF;
18965 + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
18967 + else if (ndx <= 13) {
18969 + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
18971 + else if (ndx <= 21) {
18973 + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
18975 + else if (ndx <= 29) {
18977 + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
18980 + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
18985 + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
18986 + * The active request is checked for the next packet to be loaded into
18987 + * the non-periodic Tx FIFO.
18989 +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t *pcd)
18991 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
18992 + dwc_otg_core_global_regs_t *global_regs =
18993 + core_if->core_global_regs;
18994 + dwc_otg_dev_in_ep_regs_t *ep_regs;
18995 + gnptxsts_data_t txstatus = {.d32 = 0};
18996 + gintsts_data_t gintsts;
18999 + dwc_otg_pcd_ep_t *ep = 0;
19000 + uint32_t len = 0;
19003 + /* Get the epnum from the IN Token Learning Queue. */
19004 + epnum = get_ep_of_last_in_token(core_if);
19005 + ep = get_in_ep(pcd, epnum);
19007 + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %s(%d) \n", ep->ep.name, epnum);
19008 + ep_regs = core_if->dev_if->in_ep_regs[epnum];
19010 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19011 + if (len > ep->dwc_ep.maxpacket) {
19012 + len = ep->dwc_ep.maxpacket;
19014 + dwords = (len + 3)/4;
19017 + /* While there is space in the queue and space in the FIFO and
19018 + * More data to tranfer, Write packets to the Tx FIFO */
19019 + txstatus.d32 = dwc_read_reg32(&global_regs->gnptxsts);
19020 + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n",txstatus.d32);
19022 + while (txstatus.b.nptxqspcavail > 0 &&
19023 + txstatus.b.nptxfspcavail > dwords &&
19024 + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
19025 + /* Write the FIFO */
19026 + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
19027 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19029 + if (len > ep->dwc_ep.maxpacket) {
19030 + len = ep->dwc_ep.maxpacket;
19033 + dwords = (len + 3)/4;
19034 + txstatus.d32 = dwc_read_reg32(&global_regs->gnptxsts);
19035 + DWC_DEBUGPL(DBG_PCDV,"GNPTXSTS=0x%08x\n",txstatus.d32);
19038 + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
19039 + dwc_read_reg32(&global_regs->gnptxsts));
19041 + /* Clear interrupt */
19043 + gintsts.b.nptxfempty = 1;
19044 + dwc_write_reg32 (&global_regs->gintsts, gintsts.d32);
19050 + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
19051 + * The active request is checked for the next packet to be loaded into
19052 + * apropriate Tx FIFO.
19054 +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t *pcd, uint32_t epnum)
19056 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19057 + dwc_otg_dev_if_t* dev_if = core_if->dev_if;
19058 + dwc_otg_dev_in_ep_regs_t *ep_regs;
19059 + dtxfsts_data_t txstatus = {.d32 = 0};
19060 + dwc_otg_pcd_ep_t *ep = 0;
19061 + uint32_t len = 0;
19064 + ep = get_in_ep(pcd, epnum);
19066 + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %s(%d) \n", ep->ep.name, epnum);
19068 + ep_regs = core_if->dev_if->in_ep_regs[epnum];
19070 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19072 + if (len > ep->dwc_ep.maxpacket) {
19073 + len = ep->dwc_ep.maxpacket;
19076 + dwords = (len + 3)/4;
19078 + /* While there is space in the queue and space in the FIFO and
19079 + * More data to tranfer, Write packets to the Tx FIFO */
19080 + txstatus.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dtxfsts);
19081 + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n",epnum,txstatus.d32);
19083 + while (txstatus.b.txfspcavail > dwords &&
19084 + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
19085 + ep->dwc_ep.xfer_len != 0) {
19086 + /* Write the FIFO */
19087 + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
19089 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19090 + if (len > ep->dwc_ep.maxpacket) {
19091 + len = ep->dwc_ep.maxpacket;
19094 + dwords = (len + 3)/4;
19095 + txstatus.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dtxfsts);
19096 + DWC_DEBUGPL(DBG_PCDV,"dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
19099 + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n",epnum,dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dtxfsts));
19106 + * This function is called when the Device is disconnected. It stops
19107 + * any active requests and informs the Gadget driver of the
19110 +void dwc_otg_pcd_stop(dwc_otg_pcd_t *pcd)
19112 + int i, num_in_eps, num_out_eps;
19113 + dwc_otg_pcd_ep_t *ep;
19115 + gintmsk_data_t intr_mask = {.d32 = 0};
19117 + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
19118 + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
19120 + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
19121 + /* don't disconnect drivers more than once */
19122 + if (pcd->ep0state == EP0_DISCONNECT) {
19123 + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
19126 + pcd->ep0state = EP0_DISCONNECT;
19128 + /* Reset the OTG state. */
19129 + dwc_otg_pcd_update_otg(pcd, 1);
19131 + /* Disable the NP Tx Fifo Empty Interrupt. */
19132 + intr_mask.b.nptxfempty = 1;
19133 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
19134 + intr_mask.d32, 0);
19136 + /* Flush the FIFOs */
19137 + /**@todo NGS Flush Periodic FIFOs */
19138 + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
19139 + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
19141 + /* prevent new request submissions, kill any outstanding requests */
19143 + dwc_otg_request_nuke(ep);
19144 + /* prevent new request submissions, kill any outstanding requests */
19145 + for (i = 0; i < num_in_eps; i++)
19147 + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
19148 + dwc_otg_request_nuke(ep);
19150 + /* prevent new request submissions, kill any outstanding requests */
19151 + for (i = 0; i < num_out_eps; i++)
19153 + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
19154 + dwc_otg_request_nuke(ep);
19157 + /* report disconnect; the driver is already quiesced */
19158 + if (pcd->driver && pcd->driver->disconnect) {
19159 + SPIN_UNLOCK(&pcd->lock);
19160 + pcd->driver->disconnect(&pcd->gadget);
19161 + SPIN_LOCK(&pcd->lock);
19166 + * This interrupt indicates that ...
19168 +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t *pcd)
19170 + gintmsk_data_t intr_mask = { .d32 = 0};
19171 + gintsts_data_t gintsts;
19173 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "i2cintr");
19174 + intr_mask.b.i2cintr = 1;
19175 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
19176 + intr_mask.d32, 0);
19178 + /* Clear interrupt */
19180 + gintsts.b.i2cintr = 1;
19181 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
19188 + * This interrupt indicates that ...
19190 +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t *pcd)
19192 + gintsts_data_t gintsts;
19193 +#if defined(VERBOSE)
19194 + DWC_PRINT("Early Suspend Detected\n");
19196 + /* Clear interrupt */
19198 + gintsts.b.erlysuspend = 1;
19199 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
19205 + * This function configures EPO to receive SETUP packets.
19207 + * @todo NGS: Update the comments from the HW FS.
19209 + * -# Program the following fields in the endpoint specific registers
19210 + * for Control OUT EP 0, in order to receive a setup packet
19211 + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
19213 + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
19214 + * to back setup packets)
19215 + * - In DMA mode, DOEPDMA0 Register with a memory address to
19216 + * store any setup packets received
19218 + * @param core_if Programming view of DWC_otg controller.
19219 + * @param pcd Programming view of the PCD.
19221 +static inline void ep0_out_start(dwc_otg_core_if_t *core_if, dwc_otg_pcd_t *pcd)
19223 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
19224 + deptsiz0_data_t doeptsize0 = { .d32 = 0};
19225 + dwc_otg_dma_desc_t* dma_desc;
19226 + depctl_data_t doepctl = { .d32 = 0 };
19229 + DWC_DEBUGPL(DBG_PCDV,"%s() doepctl0=%0x\n", __func__,
19230 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
19233 + doeptsize0.b.supcnt = 3;
19234 + doeptsize0.b.pktcnt = 1;
19235 + doeptsize0.b.xfersize = 8*3;
19238 + if (core_if->dma_enable) {
19239 + if (!core_if->dma_desc_enable) {
19240 + /** put here as for Hermes mode deptisz register should not be written */
19241 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doeptsiz,
19244 + /** @todo dma needs to handle multiple setup packets (up to 3) */
19245 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepdma,
19246 + pcd->setup_pkt_dma_handle);
19248 + dev_if->setup_desc_index = (dev_if->setup_desc_index + 1) & 1;
19249 + dma_desc = dev_if->setup_desc_addr[dev_if->setup_desc_index];
19251 + /** DMA Descriptor Setup */
19252 + dma_desc->status.b.bs = BS_HOST_BUSY;
19253 + dma_desc->status.b.l = 1;
19254 + dma_desc->status.b.ioc = 1;
19255 + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
19256 + dma_desc->buf = pcd->setup_pkt_dma_handle;
19257 + dma_desc->status.b.bs = BS_HOST_READY;
19259 + /** DOEPDMA0 Register write */
19260 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepdma, dev_if->dma_setup_desc_addr[dev_if->setup_desc_index]);
19264 + /** put here as for Hermes mode deptisz register should not be written */
19265 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doeptsiz,
19269 + /** DOEPCTL0 Register write */
19270 + doepctl.b.epena = 1;
19271 + doepctl.b.cnak = 1;
19272 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
19275 + DWC_DEBUGPL(DBG_PCDV,"doepctl0=%0x\n",
19276 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
19277 + DWC_DEBUGPL(DBG_PCDV,"diepctl0=%0x\n",
19278 + dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl));
19284 + * This interrupt occurs when a USB Reset is detected. When the USB
19285 + * Reset Interrupt occurs the device state is set to DEFAULT and the
19286 + * EP0 state is set to IDLE.
19287 + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
19288 + * -# Unmask the following interrupt bits
19289 + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
19290 + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
19291 + * - DOEPMSK.SETUP = 1
19292 + * - DOEPMSK.XferCompl = 1
19293 + * - DIEPMSK.XferCompl = 1
19294 + * - DIEPMSK.TimeOut = 1
19295 + * -# Program the following fields in the endpoint specific registers
19296 + * for Control OUT EP 0, in order to receive a setup packet
19297 + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
19299 + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
19300 + * to back setup packets)
19301 + * - In DMA mode, DOEPDMA0 Register with a memory address to
19302 + * store any setup packets received
19303 + * At this point, all the required initialization, except for enabling
19304 + * the control 0 OUT endpoint is done, for receiving SETUP packets.
19306 +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
19308 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19309 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
19310 + depctl_data_t doepctl = { .d32 = 0};
19312 + daint_data_t daintmsk = { .d32 = 0};
19313 + doepmsk_data_t doepmsk = { .d32 = 0};
19314 + diepmsk_data_t diepmsk = { .d32 = 0};
19316 + dcfg_data_t dcfg = { .d32=0 };
19317 + grstctl_t resetctl = { .d32=0 };
19318 + dctl_data_t dctl = {.d32=0};
19320 + gintsts_data_t gintsts;
19322 + DWC_PRINT("USB RESET\n");
19323 +#ifdef DWC_EN_ISOC
19324 + for(i = 1;i < 16; ++i)
19326 + dwc_otg_pcd_ep_t *ep;
19327 + dwc_ep_t *dwc_ep;
19328 + ep = get_in_ep(pcd,i);
19330 + dwc_ep = &ep->dwc_ep;
19331 + dwc_ep->next_frame = 0xffffffff;
19334 +#endif /* DWC_EN_ISOC */
19336 + /* reset the HNP settings */
19337 + dwc_otg_pcd_update_otg(pcd, 1);
19339 + /* Clear the Remote Wakeup Signalling */
19340 + dctl.b.rmtwkupsig = 1;
19341 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dctl,
19344 + /* Set NAK for all OUT EPs */
19345 + doepctl.b.snak = 1;
19346 + for (i=0; i <= dev_if->num_out_eps; i++)
19348 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepctl,
19352 + /* Flush the NP Tx FIFO */
19353 + dwc_otg_flush_tx_fifo(core_if, 0x10);
19354 + /* Flush the Learning Queue */
19355 + resetctl.b.intknqflsh = 1;
19356 + dwc_write_reg32(&core_if->core_global_regs->grstctl, resetctl.d32);
19358 + if(core_if->multiproc_int_enable) {
19359 + daintmsk.b.inep0 = 1;
19360 + daintmsk.b.outep0 = 1;
19361 + dwc_write_reg32(&dev_if->dev_global_regs->deachintmsk, daintmsk.d32);
19363 + doepmsk.b.setup = 1;
19364 + doepmsk.b.xfercompl = 1;
19365 + doepmsk.b.ahberr = 1;
19366 + doepmsk.b.epdisabled = 1;
19368 + if(core_if->dma_desc_enable) {
19369 + doepmsk.b.stsphsercvd = 1;
19370 + doepmsk.b.bna = 1;
19373 + doepmsk.b.babble = 1;
19374 + doepmsk.b.nyet = 1;
19376 + if(core_if->dma_enable) {
19377 + doepmsk.b.nak = 1;
19380 + dwc_write_reg32(&dev_if->dev_global_regs->doepeachintmsk[0], doepmsk.d32);
19382 + diepmsk.b.xfercompl = 1;
19383 + diepmsk.b.timeout = 1;
19384 + diepmsk.b.epdisabled = 1;
19385 + diepmsk.b.ahberr = 1;
19386 + diepmsk.b.intknepmis = 1;
19388 + if(core_if->dma_desc_enable) {
19389 + diepmsk.b.bna = 1;
19392 + if(core_if->dma_enable) {
19393 + diepmsk.b.nak = 1;
19396 + dwc_write_reg32(&dev_if->dev_global_regs->diepeachintmsk[0], diepmsk.d32);
19398 + daintmsk.b.inep0 = 1;
19399 + daintmsk.b.outep0 = 1;
19400 + dwc_write_reg32(&dev_if->dev_global_regs->daintmsk, daintmsk.d32);
19402 + doepmsk.b.setup = 1;
19403 + doepmsk.b.xfercompl = 1;
19404 + doepmsk.b.ahberr = 1;
19405 + doepmsk.b.epdisabled = 1;
19407 + if(core_if->dma_desc_enable) {
19408 + doepmsk.b.stsphsercvd = 1;
19409 + doepmsk.b.bna = 1;
19412 + doepmsk.b.babble = 1;
19413 + doepmsk.b.nyet = 1;
19414 + doepmsk.b.nak = 1;
19416 + dwc_write_reg32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
19418 + diepmsk.b.xfercompl = 1;
19419 + diepmsk.b.timeout = 1;
19420 + diepmsk.b.epdisabled = 1;
19421 + diepmsk.b.ahberr = 1;
19422 + diepmsk.b.intknepmis = 1;
19424 + if(core_if->dma_desc_enable) {
19425 + diepmsk.b.bna = 1;
19428 +// diepmsk.b.nak = 1;
19430 + dwc_write_reg32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
19433 + /* Reset Device Address */
19434 + dcfg.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dcfg);
19435 + dcfg.b.devaddr = 0;
19436 + dwc_write_reg32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
19438 + /* setup EP0 to receive SETUP packets */
19439 + ep0_out_start(core_if, pcd);
19441 + /* Clear interrupt */
19443 + gintsts.b.usbreset = 1;
19444 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
19450 + * Get the device speed from the device status register and convert it
19451 + * to USB speed constant.
19453 + * @param core_if Programming view of DWC_otg controller.
19455 +static int get_device_speed(dwc_otg_core_if_t *core_if)
19457 + dsts_data_t dsts;
19458 + enum usb_device_speed speed = USB_SPEED_UNKNOWN;
19459 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
19461 + switch (dsts.b.enumspd) {
19462 + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
19463 + speed = USB_SPEED_HIGH;
19465 + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
19466 + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
19467 + speed = USB_SPEED_FULL;
19470 + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
19471 + speed = USB_SPEED_LOW;
19479 + * Read the device status register and set the device speed in the
19480 + * data structure.
19481 + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
19483 +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t *pcd)
19485 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
19486 + gintsts_data_t gintsts;
19487 + gusbcfg_data_t gusbcfg;
19488 + dwc_otg_core_global_regs_t *global_regs =
19489 + GET_CORE_IF(pcd)->core_global_regs;
19490 + uint8_t utmi16b, utmi8b;
19491 + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
19493 + if (GET_CORE_IF(pcd)->snpsid >= 0x4F54260A) {
19500 + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
19503 + print_ep0_state(pcd);
19506 + if (pcd->ep0state == EP0_DISCONNECT) {
19507 + pcd->ep0state = EP0_IDLE;
19509 + else if (pcd->ep0state == EP0_STALL) {
19510 + pcd->ep0state = EP0_IDLE;
19513 + pcd->ep0state = EP0_IDLE;
19515 + ep0->stopped = 0;
19517 + pcd->gadget.speed = get_device_speed(GET_CORE_IF(pcd));
19519 + /* Set USB turnaround time based on device speed and PHY interface. */
19520 + gusbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
19521 + if (pcd->gadget.speed == USB_SPEED_HIGH) {
19522 + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
19523 + /* ULPI interface */
19524 + gusbcfg.b.usbtrdtim = 9;
19526 + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
19527 + /* UTMI+ interface */
19528 + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
19529 + gusbcfg.b.usbtrdtim = utmi8b;
19531 + else if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 1) {
19532 + gusbcfg.b.usbtrdtim = utmi16b;
19534 + else if (GET_CORE_IF(pcd)->core_params->phy_utmi_width == 8) {
19535 + gusbcfg.b.usbtrdtim = utmi8b;
19538 + gusbcfg.b.usbtrdtim = utmi16b;
19541 + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
19542 + /* UTMI+ OR ULPI interface */
19543 + if (gusbcfg.b.ulpi_utmi_sel == 1) {
19544 + /* ULPI interface */
19545 + gusbcfg.b.usbtrdtim = 9;
19548 + /* UTMI+ interface */
19549 + if (GET_CORE_IF(pcd)->core_params->phy_utmi_width == 16) {
19550 + gusbcfg.b.usbtrdtim = utmi16b;
19553 + gusbcfg.b.usbtrdtim = utmi8b;
19559 + /* Full or low speed */
19560 + gusbcfg.b.usbtrdtim = 9;
19562 + dwc_write_reg32(&global_regs->gusbcfg, gusbcfg.d32);
19564 + /* Clear interrupt */
19566 + gintsts.b.enumdone = 1;
19567 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
19573 + * This interrupt indicates that the ISO OUT Packet was dropped due to
19574 + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
19575 + * read all the data from the Rx FIFO.
19577 +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t *pcd)
19579 + gintmsk_data_t intr_mask = { .d32 = 0};
19580 + gintsts_data_t gintsts;
19582 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
19583 + "ISOC Out Dropped");
19585 + intr_mask.b.isooutdrop = 1;
19586 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
19587 + intr_mask.d32, 0);
19589 + /* Clear interrupt */
19592 + gintsts.b.isooutdrop = 1;
19593 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
19600 + * This interrupt indicates the end of the portion of the micro-frame
19601 + * for periodic transactions. If there is a periodic transaction for
19602 + * the next frame, load the packets into the EP periodic Tx FIFO.
19604 +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t *pcd)
19606 + gintmsk_data_t intr_mask = { .d32 = 0};
19607 + gintsts_data_t gintsts;
19608 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "EOP");
19610 + intr_mask.b.eopframe = 1;
19611 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
19612 + intr_mask.d32, 0);
19614 + /* Clear interrupt */
19616 + gintsts.b.eopframe = 1;
19617 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts, gintsts.d32);
19623 + * This interrupt indicates that EP of the packet on the top of the
19624 + * non-periodic Tx FIFO does not match EP of the IN Token received.
19626 + * The "Device IN Token Queue" Registers are read to determine the
19627 + * order the IN Tokens have been received. The non-periodic Tx FIFO
19628 + * is flushed, so it can be reloaded in the order seen in the IN Token
19631 +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_core_if_t *core_if)
19633 + gintsts_data_t gintsts;
19634 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
19636 + /* Clear interrupt */
19638 + gintsts.b.epmismatch = 1;
19639 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
19645 + * This funcion stalls EP0.
19647 +static inline void ep0_do_stall(dwc_otg_pcd_t *pcd, const int err_val)
19649 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
19650 + struct usb_ctrlrequest *ctrl = &pcd->setup_pkt->req;
19651 + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
19652 + ctrl->bRequestType, ctrl->bRequest, err_val);
19654 + ep0->dwc_ep.is_in = 1;
19655 + dwc_otg_ep_set_stall(pcd->otg_dev->core_if, &ep0->dwc_ep);
19656 + pcd->ep0.stopped = 1;
19657 + pcd->ep0state = EP0_IDLE;
19658 + ep0_out_start(GET_CORE_IF(pcd), pcd);
19662 + * This functions delegates the setup command to the gadget driver.
19664 +static inline void do_gadget_setup(dwc_otg_pcd_t *pcd,
19665 + struct usb_ctrlrequest * ctrl)
19668 + if (pcd->driver && pcd->driver->setup) {
19669 + SPIN_UNLOCK(&pcd->lock);
19670 + ret = pcd->driver->setup(&pcd->gadget, ctrl);
19671 + SPIN_LOCK(&pcd->lock);
19673 + ep0_do_stall(pcd, ret);
19676 + /** @todo This is a g_file_storage gadget driver specific
19677 + * workaround: a DELAYED_STATUS result from the fsg_setup
19678 + * routine will result in the gadget queueing a EP0 IN status
19679 + * phase for a two-stage control transfer. Exactly the same as
19680 + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
19681 + * specific request. Need a generic way to know when the gadget
19682 + * driver will queue the status phase. Can we assume when we
19683 + * call the gadget driver setup() function that it will always
19684 + * queue and require the following flag? Need to look into
19688 + if (ret == 256 + 999) {
19689 + pcd->request_config = 1;
19695 + * This function starts the Zero-Length Packet for the IN status phase
19696 + * of a 2 stage control transfer.
19698 +static inline void do_setup_in_status_phase(dwc_otg_pcd_t *pcd)
19700 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
19701 + if (pcd->ep0state == EP0_STALL) {
19705 + pcd->ep0state = EP0_IN_STATUS_PHASE;
19707 + /* Prepare for more SETUP Packets */
19708 + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
19709 + ep0->dwc_ep.xfer_len = 0;
19710 + ep0->dwc_ep.xfer_count = 0;
19711 + ep0->dwc_ep.is_in = 1;
19712 + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
19713 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
19715 + /* Prepare for more SETUP Packets */
19716 +// if(GET_CORE_IF(pcd)->dma_enable == 0) ep0_out_start(GET_CORE_IF(pcd), pcd);
19720 + * This function starts the Zero-Length Packet for the OUT status phase
19721 + * of a 2 stage control transfer.
19723 +static inline void do_setup_out_status_phase(dwc_otg_pcd_t *pcd)
19725 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
19726 + if (pcd->ep0state == EP0_STALL) {
19727 + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
19730 + pcd->ep0state = EP0_OUT_STATUS_PHASE;
19732 + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
19733 + ep0->dwc_ep.xfer_len = 0;
19734 + ep0->dwc_ep.xfer_count = 0;
19735 + ep0->dwc_ep.is_in = 0;
19736 + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
19737 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
19739 + /* Prepare for more SETUP Packets */
19740 + if(GET_CORE_IF(pcd)->dma_enable == 0) {
19741 + ep0_out_start(GET_CORE_IF(pcd), pcd);
19746 + * Clear the EP halt (STALL) and if pending requests start the
19749 +static inline void pcd_clear_halt(dwc_otg_pcd_t *pcd, dwc_otg_pcd_ep_t *ep)
19751 + if(ep->dwc_ep.stall_clear_flag == 0)
19752 + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
19754 + /* Reactive the EP */
19755 + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
19756 + if (ep->stopped) {
19758 + /* If there is a request in the EP queue start it */
19760 + /** @todo FIXME: this causes an EP mismatch in DMA mode.
19761 + * epmismatch not yet implemented. */
19764 + * Above fixme is solved by implmenting a tasklet to call the
19765 + * start_next_request(), outside of interrupt context at some
19766 + * time after the current time, after a clear-halt setup packet.
19767 + * Still need to implement ep mismatch in the future if a gadget
19768 + * ever uses more than one endpoint at once
19770 + ep->queue_sof = 1;
19771 + tasklet_schedule (pcd->start_xfer_tasklet);
19773 + /* Start Control Status Phase */
19774 + do_setup_in_status_phase(pcd);
19778 + * This function is called when the SET_FEATURE TEST_MODE Setup packet
19779 + * is sent from the host. The Device Control register is written with
19780 + * the Test Mode bits set to the specified Test Mode. This is done as
19781 + * a tasklet so that the "Status" phase of the control transfer
19782 + * completes before transmitting the TEST packets.
19784 + * @todo This has not been tested since the tasklet struct was put
19785 + * into the PCD struct!
19788 +static void do_test_mode(unsigned long data)
19790 + dctl_data_t dctl;
19791 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)data;
19792 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19793 + int test_mode = pcd->test_mode;
19796 +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
19798 + dctl.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dctl);
19799 + switch (test_mode) {
19800 + case 1: // TEST_J
19801 + dctl.b.tstctl = 1;
19804 + case 2: // TEST_K
19805 + dctl.b.tstctl = 2;
19808 + case 3: // TEST_SE0_NAK
19809 + dctl.b.tstctl = 3;
19812 + case 4: // TEST_PACKET
19813 + dctl.b.tstctl = 4;
19816 + case 5: // TEST_FORCE_ENABLE
19817 + dctl.b.tstctl = 5;
19820 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
19824 + * This function process the GET_STATUS Setup Commands.
19826 +static inline void do_get_status(dwc_otg_pcd_t *pcd)
19828 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
19829 + dwc_otg_pcd_ep_t *ep;
19830 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
19831 + uint16_t *status = pcd->status_buf;
19834 + DWC_DEBUGPL(DBG_PCD,
19835 + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
19836 + ctrl.bRequestType, ctrl.bRequest,
19837 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
19840 + switch (ctrl.bRequestType & USB_RECIP_MASK) {
19841 + case USB_RECIP_DEVICE:
19842 + *status = 0x1; /* Self powered */
19843 + *status |= pcd->remote_wakeup_enable << 1;
19846 + case USB_RECIP_INTERFACE:
19850 + case USB_RECIP_ENDPOINT:
19851 + ep = get_ep_by_addr(pcd, ctrl.wIndex);
19852 + if (ep == 0 || ctrl.wLength > 2) {
19853 + ep0_do_stall(pcd, -EOPNOTSUPP);
19856 + /** @todo check for EP stall */
19857 + *status = ep->stopped;
19860 + pcd->ep0_pending = 1;
19861 + ep0->dwc_ep.start_xfer_buff = (uint8_t *)status;
19862 + ep0->dwc_ep.xfer_buff = (uint8_t *)status;
19863 + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
19864 + ep0->dwc_ep.xfer_len = 2;
19865 + ep0->dwc_ep.xfer_count = 0;
19866 + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
19867 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
19870 + * This function process the SET_FEATURE Setup Commands.
19872 +static inline void do_set_feature(dwc_otg_pcd_t *pcd)
19874 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19875 + dwc_otg_core_global_regs_t *global_regs =
19876 + core_if->core_global_regs;
19877 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
19878 + dwc_otg_pcd_ep_t *ep = 0;
19879 + int32_t otg_cap_param = core_if->core_params->otg_cap;
19880 + gotgctl_data_t gotgctl = { .d32 = 0 };
19882 + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
19883 + ctrl.bRequestType, ctrl.bRequest,
19884 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
19885 + DWC_DEBUGPL(DBG_PCD,"otg_cap=%d\n", otg_cap_param);
19888 + switch (ctrl.bRequestType & USB_RECIP_MASK) {
19889 + case USB_RECIP_DEVICE:
19890 + switch (ctrl.wValue) {
19891 + case USB_DEVICE_REMOTE_WAKEUP:
19892 + pcd->remote_wakeup_enable = 1;
19895 + case USB_DEVICE_TEST_MODE:
19896 + /* Setup the Test Mode tasklet to do the Test
19897 + * Packet generation after the SETUP Status
19898 + * phase has completed. */
19900 + /** @todo This has not been tested since the
19901 + * tasklet struct was put into the PCD
19903 + pcd->test_mode_tasklet.next = 0;
19904 + pcd->test_mode_tasklet.state = 0;
19905 + atomic_set(&pcd->test_mode_tasklet.count, 0);
19906 + pcd->test_mode_tasklet.func = do_test_mode;
19907 + pcd->test_mode_tasklet.data = (unsigned long)pcd;
19908 + pcd->test_mode = ctrl.wIndex >> 8;
19909 + tasklet_schedule(&pcd->test_mode_tasklet);
19912 + case USB_DEVICE_B_HNP_ENABLE:
19913 + DWC_DEBUGPL(DBG_PCDV, "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
19915 + /* dev may initiate HNP */
19916 + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
19917 + pcd->b_hnp_enable = 1;
19918 + dwc_otg_pcd_update_otg(pcd, 0);
19919 + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
19920 + /**@todo Is the gotgctl.devhnpen cleared
19921 + * by a USB Reset? */
19922 + gotgctl.b.devhnpen = 1;
19923 + gotgctl.b.hnpreq = 1;
19924 + dwc_write_reg32(&global_regs->gotgctl, gotgctl.d32);
19927 + ep0_do_stall(pcd, -EOPNOTSUPP);
19931 + case USB_DEVICE_A_HNP_SUPPORT:
19932 + /* RH port supports HNP */
19933 + DWC_DEBUGPL(DBG_PCDV, "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
19934 + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
19935 + pcd->a_hnp_support = 1;
19936 + dwc_otg_pcd_update_otg(pcd, 0);
19939 + ep0_do_stall(pcd, -EOPNOTSUPP);
19943 + case USB_DEVICE_A_ALT_HNP_SUPPORT:
19944 + /* other RH port does */
19945 + DWC_DEBUGPL(DBG_PCDV, "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
19946 + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
19947 + pcd->a_alt_hnp_support = 1;
19948 + dwc_otg_pcd_update_otg(pcd, 0);
19951 + ep0_do_stall(pcd, -EOPNOTSUPP);
19955 + do_setup_in_status_phase(pcd);
19958 + case USB_RECIP_INTERFACE:
19959 + do_gadget_setup(pcd, &ctrl);
19962 + case USB_RECIP_ENDPOINT:
19963 + if (ctrl.wValue == USB_ENDPOINT_HALT) {
19964 + ep = get_ep_by_addr(pcd, ctrl.wIndex);
19966 + ep0_do_stall(pcd, -EOPNOTSUPP);
19970 + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
19972 + do_setup_in_status_phase(pcd);
19978 + * This function process the CLEAR_FEATURE Setup Commands.
19980 +static inline void do_clear_feature(dwc_otg_pcd_t *pcd)
19982 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
19983 + dwc_otg_pcd_ep_t *ep = 0;
19985 + DWC_DEBUGPL(DBG_PCD,
19986 + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
19987 + ctrl.bRequestType, ctrl.bRequest,
19988 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
19990 + switch (ctrl.bRequestType & USB_RECIP_MASK) {
19991 + case USB_RECIP_DEVICE:
19992 + switch (ctrl.wValue) {
19993 + case USB_DEVICE_REMOTE_WAKEUP:
19994 + pcd->remote_wakeup_enable = 0;
19997 + case USB_DEVICE_TEST_MODE:
19998 + /** @todo Add CLEAR_FEATURE for TEST modes. */
20001 + do_setup_in_status_phase(pcd);
20004 + case USB_RECIP_ENDPOINT:
20005 + ep = get_ep_by_addr(pcd, ctrl.wIndex);
20007 + ep0_do_stall(pcd, -EOPNOTSUPP);
20011 + pcd_clear_halt(pcd, ep);
20018 + * This function process the SET_ADDRESS Setup Commands.
20020 +static inline void do_set_address(dwc_otg_pcd_t *pcd)
20022 + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
20023 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
20025 + if (ctrl.bRequestType == USB_RECIP_DEVICE) {
20026 + dcfg_data_t dcfg = {.d32=0};
20029 +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
20031 + dcfg.b.devaddr = ctrl.wValue;
20032 + dwc_modify_reg32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
20033 + do_setup_in_status_phase(pcd);
20038 + * This function processes SETUP commands. In Linux, the USB Command
20039 + * processing is done in two places - the first being the PCD and the
20040 + * second in the Gadget Driver (for example, the File-Backed Storage
20041 + * Gadget Driver).
20044 + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
20046 + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
20047 + * defined in chapter 9 of the USB 2.0 Specification chapter 9
20050 + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
20051 + * requests are the ENDPOINT_HALT feature is procesed, all others the
20052 + * interface requests are ignored.</td></tr>
20054 + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
20055 + * requests are processed by the PCD. Interface requests are passed
20056 + * to the Gadget Driver.</td></tr>
20058 + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
20059 + * with device address received </td></tr>
20061 + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
20062 + * requested descriptor</td></tr>
20064 + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
20065 + * not implemented by any of the existing Gadget Drivers.</td></tr>
20067 + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
20068 + * all EPs and enable EPs for new configuration.</td></tr>
20070 + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
20071 + * the current configuration</td></tr>
20073 + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
20074 + * EPs and enable EPs for new configuration.</td></tr>
20076 + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
20077 + * current interface.</td></tr>
20079 + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
20080 + * message.</td></tr>
20083 + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
20084 + * processed by pcd_setup. Calling the Function Driver's setup function from
20085 + * pcd_setup processes the gadget SETUP commands.
20087 +static inline void pcd_setup(dwc_otg_pcd_t *pcd)
20089 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
20090 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
20091 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
20092 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
20094 + deptsiz0_data_t doeptsize0 = { .d32 = 0};
20097 + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
20098 + ctrl.bRequestType, ctrl.bRequest,
20099 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
20102 + doeptsize0.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doeptsiz);
20104 + /** @todo handle > 1 setup packet , assert error for now */
20106 + if (core_if->dma_enable && core_if->dma_desc_enable == 0 && (doeptsize0.b.supcnt < 2)) {
20107 + DWC_ERROR ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
20110 + /* Clean up the request queue */
20111 + dwc_otg_request_nuke(ep0);
20112 + ep0->stopped = 0;
20114 + if (ctrl.bRequestType & USB_DIR_IN) {
20115 + ep0->dwc_ep.is_in = 1;
20116 + pcd->ep0state = EP0_IN_DATA_PHASE;
20119 + ep0->dwc_ep.is_in = 0;
20120 + pcd->ep0state = EP0_OUT_DATA_PHASE;
20123 + if(ctrl.wLength == 0) {
20124 + ep0->dwc_ep.is_in = 1;
20125 + pcd->ep0state = EP0_IN_STATUS_PHASE;
20128 + if ((ctrl.bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) {
20129 + /* handle non-standard (class/vendor) requests in the gadget driver */
20130 + do_gadget_setup(pcd, &ctrl);
20134 + /** @todo NGS: Handle bad setup packet? */
20136 +///////////////////////////////////////////
20137 +//// --- Standard Request handling --- ////
20139 + switch (ctrl.bRequest) {
20140 + case USB_REQ_GET_STATUS:
20141 + do_get_status(pcd);
20144 + case USB_REQ_CLEAR_FEATURE:
20145 + do_clear_feature(pcd);
20148 + case USB_REQ_SET_FEATURE:
20149 + do_set_feature(pcd);
20152 + case USB_REQ_SET_ADDRESS:
20153 + do_set_address(pcd);
20156 + case USB_REQ_SET_INTERFACE:
20157 + case USB_REQ_SET_CONFIGURATION:
20158 +// _pcd->request_config = 1; /* Configuration changed */
20159 + do_gadget_setup(pcd, &ctrl);
20162 + case USB_REQ_SYNCH_FRAME:
20163 + do_gadget_setup(pcd, &ctrl);
20167 + /* Call the Gadget Driver's setup functions */
20168 + do_gadget_setup(pcd, &ctrl);
20174 + * This function completes the ep0 control transfer.
20176 +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t *ep)
20178 + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
20179 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
20180 + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
20181 + dev_if->in_ep_regs[ep->dwc_ep.num];
20183 + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
20184 + dev_if->out_ep_regs[ep->dwc_ep.num];
20186 + deptsiz0_data_t deptsiz;
20187 + desc_sts_data_t desc_sts;
20188 + dwc_otg_pcd_request_t *req;
20190 + dwc_otg_pcd_t *pcd = ep->pcd;
20192 + //DWC_DEBUGPL(DBG_PCDV, "%s() %s\n", __func__, _ep->ep.name);
20194 + if (pcd->ep0_pending && list_empty(&ep->queue)) {
20195 + if (ep->dwc_ep.is_in) {
20197 + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
20199 + do_setup_out_status_phase(pcd);
20203 + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
20205 + do_setup_in_status_phase(pcd);
20207 + pcd->ep0_pending = 0;
20211 + if (list_empty(&ep->queue)) {
20214 + req = list_entry(ep->queue.next, dwc_otg_pcd_request_t, queue);
20217 + if (pcd->ep0state == EP0_OUT_STATUS_PHASE || pcd->ep0state == EP0_IN_STATUS_PHASE) {
20220 + else if (ep->dwc_ep.is_in) {
20221 + deptsiz.d32 = dwc_read_reg32(&in_ep_regs->dieptsiz);
20222 + if(core_if->dma_desc_enable != 0)
20223 + desc_sts.d32 = readl(dev_if->in_desc_addr);
20225 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xfersize=%d pktcnt=%d\n",
20226 + ep->ep.name, ep->dwc_ep.xfer_len,
20227 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
20230 + if (((core_if->dma_desc_enable == 0) && (deptsiz.b.xfersize == 0)) ||
20231 + ((core_if->dma_desc_enable != 0) && (desc_sts.b.bytes == 0))) {
20232 + req->req.actual = ep->dwc_ep.xfer_count;
20233 + /* Is a Zero Len Packet needed? */
20234 + if (req->req.zero) {
20236 + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
20238 + req->req.zero = 0;
20240 + do_setup_out_status_phase(pcd);
20246 + deptsiz.d32 = dwc_read_reg32(&out_ep_regs->doeptsiz);
20247 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xsize=%d pktcnt=%d\n",
20248 + ep->ep.name, ep->dwc_ep.xfer_len,
20249 + deptsiz.b.xfersize,
20250 + deptsiz.b.pktcnt);
20252 + req->req.actual = ep->dwc_ep.xfer_count;
20253 + /* Is a Zero Len Packet needed? */
20254 + if (req->req.zero) {
20256 + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
20258 + req->req.zero = 0;
20260 + if(core_if->dma_desc_enable == 0)
20261 + do_setup_in_status_phase(pcd);
20264 + /* Complete the request */
20266 + dwc_otg_request_done(ep, req, 0);
20267 + ep->dwc_ep.start_xfer_buff = 0;
20268 + ep->dwc_ep.xfer_buff = 0;
20269 + ep->dwc_ep.xfer_len = 0;
20276 + * This function completes the request for the EP. If there are
20277 + * additional requests for the EP in the queue they will be started.
20279 +static void complete_ep(dwc_otg_pcd_ep_t *ep)
20281 + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
20282 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
20283 + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
20284 + dev_if->in_ep_regs[ep->dwc_ep.num];
20285 + deptsiz_data_t deptsiz;
20286 + desc_sts_data_t desc_sts;
20287 + dwc_otg_pcd_request_t *req = 0;
20288 + dwc_otg_dma_desc_t* dma_desc;
20289 + uint32_t byte_count = 0;
20293 + DWC_DEBUGPL(DBG_PCDV,"%s() %s-%s\n", __func__, ep->ep.name,
20294 + (ep->dwc_ep.is_in?"IN":"OUT"));
20296 + /* Get any pending requests */
20297 + if (!list_empty(&ep->queue)) {
20298 + req = list_entry(ep->queue.next, dwc_otg_pcd_request_t,
20301 + printk("complete_ep 0x%p, req = NULL!\n", ep);
20306 + printk("complete_ep 0x%p, ep->queue empty!\n", ep);
20309 + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
20311 + if (ep->dwc_ep.is_in) {
20312 + deptsiz.d32 = dwc_read_reg32(&in_ep_regs->dieptsiz);
20314 + if (core_if->dma_enable) {
20315 + if(core_if->dma_desc_enable == 0) {
20316 + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
20317 + byte_count = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
20319 + ep->dwc_ep.xfer_buff += byte_count;
20320 + ep->dwc_ep.dma_addr += byte_count;
20321 + ep->dwc_ep.xfer_count += byte_count;
20323 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xfersize=%d pktcnt=%d\n",
20324 + ep->ep.name, ep->dwc_ep.xfer_len,
20325 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
20328 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
20329 + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
20330 + } else if(ep->dwc_ep.sent_zlp) {
20332 + * This fragment of code should initiate 0
20333 + * length trasfer in case if it is queued
20334 + * a trasfer with size divisible to EPs max
20335 + * packet size and with usb_request zero field
20336 + * is set, which means that after data is transfered,
20337 + * it is also should be transfered
20338 + * a 0 length packet at the end. For Slave and
20339 + * Buffer DMA modes in this case SW has
20340 + * to initiate 2 transfers one with transfer size,
20341 + * and the second with 0 size. For Desriptor
20342 + * DMA mode SW is able to initiate a transfer,
20343 + * which will handle all the packets including
20344 + * the last 0 legth.
20346 + ep->dwc_ep.sent_zlp = 0;
20347 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
20352 + DWC_WARN("Incomplete transfer (%s-%s [siz=%d pkt=%d])\n",
20353 + ep->ep.name, (ep->dwc_ep.is_in?"IN":"OUT"),
20354 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
20357 + dma_desc = ep->dwc_ep.desc_addr;
20359 + ep->dwc_ep.sent_zlp = 0;
20361 + for(i = 0; i < ep->dwc_ep.desc_cnt; ++i) {
20362 + desc_sts.d32 = readl(dma_desc);
20363 + byte_count += desc_sts.b.bytes;
20367 + if(byte_count == 0) {
20368 + ep->dwc_ep.xfer_count = ep->dwc_ep.total_len;
20371 + DWC_WARN("Incomplete transfer\n");
20375 + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
20376 + /* Check if the whole transfer was completed,
20377 + * if no, setup transfer for next portion of data
20379 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xfersize=%d pktcnt=%d\n",
20380 + ep->ep.name, ep->dwc_ep.xfer_len,
20381 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
20382 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
20383 + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
20384 + } else if(ep->dwc_ep.sent_zlp) {
20386 + * This fragment of code should initiate 0
20387 + * length trasfer in case if it is queued
20388 + * a trasfer with size divisible to EPs max
20389 + * packet size and with usb_request zero field
20390 + * is set, which means that after data is transfered,
20391 + * it is also should be transfered
20392 + * a 0 length packet at the end. For Slave and
20393 + * Buffer DMA modes in this case SW has
20394 + * to initiate 2 transfers one with transfer size,
20395 + * and the second with 0 size. For Desriptor
20396 + * DMA mode SW is able to initiate a transfer,
20397 + * which will handle all the packets including
20398 + * the last 0 legth.
20400 + ep->dwc_ep.sent_zlp = 0;
20401 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
20407 + DWC_WARN("Incomplete transfer (%s-%s [siz=%d pkt=%d])\n",
20408 + ep->ep.name, (ep->dwc_ep.is_in?"IN":"OUT"),
20409 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
20413 + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
20414 + dev_if->out_ep_regs[ep->dwc_ep.num];
20415 + desc_sts.d32 = 0;
20416 + if(core_if->dma_enable) {
20417 + if(core_if->dma_desc_enable) {
20418 + dma_desc = ep->dwc_ep.desc_addr;
20420 + ep->dwc_ep.sent_zlp = 0;
20421 + for(i = 0; i < ep->dwc_ep.desc_cnt; ++i) {
20422 + desc_sts.d32 = readl(dma_desc);
20423 + byte_count += desc_sts.b.bytes;
20427 + ep->dwc_ep.xfer_count = ep->dwc_ep.total_len
20428 + - byte_count + ((4 - (ep->dwc_ep.total_len & 0x3)) & 0x3);
20432 + deptsiz.d32 = dwc_read_reg32(&out_ep_regs->doeptsiz);
20434 + byte_count = (ep->dwc_ep.xfer_len -
20435 + ep->dwc_ep.xfer_count - deptsiz.b.xfersize);
20436 + ep->dwc_ep.xfer_buff += byte_count;
20437 + ep->dwc_ep.dma_addr += byte_count;
20438 + ep->dwc_ep.xfer_count += byte_count;
20440 + /* Check if the whole transfer was completed,
20441 + * if no, setup transfer for next portion of data
20443 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
20444 + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
20446 + else if(ep->dwc_ep.sent_zlp) {
20448 + * This fragment of code should initiate 0
20449 + * length trasfer in case if it is queued
20450 + * a trasfer with size divisible to EPs max
20451 + * packet size and with usb_request zero field
20452 + * is set, which means that after data is transfered,
20453 + * it is also should be transfered
20454 + * a 0 length packet at the end. For Slave and
20455 + * Buffer DMA modes in this case SW has
20456 + * to initiate 2 transfers one with transfer size,
20457 + * and the second with 0 size. For Desriptor
20458 + * DMA mode SW is able to initiate a transfer,
20459 + * which will handle all the packets including
20460 + * the last 0 legth.
20462 + ep->dwc_ep.sent_zlp = 0;
20463 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
20469 + /* Check if the whole transfer was completed,
20470 + * if no, setup transfer for next portion of data
20472 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
20473 + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
20475 + else if(ep->dwc_ep.sent_zlp) {
20477 + * This fragment of code should initiate 0
20478 + * length trasfer in case if it is queued
20479 + * a trasfer with size divisible to EPs max
20480 + * packet size and with usb_request zero field
20481 + * is set, which means that after data is transfered,
20482 + * it is also should be transfered
20483 + * a 0 length packet at the end. For Slave and
20484 + * Buffer DMA modes in this case SW has
20485 + * to initiate 2 transfers one with transfer size,
20486 + * and the second with 0 size. For Desriptor
20487 + * DMA mode SW is able to initiate a transfer,
20488 + * which will handle all the packets including
20489 + * the last 0 legth.
20491 + ep->dwc_ep.sent_zlp = 0;
20492 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
20500 + DWC_DEBUGPL(DBG_PCDV, "addr %p, %s len=%d cnt=%d xsize=%d pktcnt=%d\n",
20501 + &out_ep_regs->doeptsiz, ep->ep.name, ep->dwc_ep.xfer_len,
20502 + ep->dwc_ep.xfer_count,
20503 + deptsiz.b.xfersize,
20504 + deptsiz.b.pktcnt);
20508 + /* Complete the request */
20510 + req->req.actual = ep->dwc_ep.xfer_count;
20512 + dwc_otg_request_done(ep, req, 0);
20514 + ep->dwc_ep.start_xfer_buff = 0;
20515 + ep->dwc_ep.xfer_buff = 0;
20516 + ep->dwc_ep.xfer_len = 0;
20518 + /* If there is a request in the queue start it.*/
20519 + start_next_request(ep);
20524 +#ifdef DWC_EN_ISOC
20527 + * This function BNA interrupt for Isochronous EPs
20530 +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t *ep)
20532 + dwc_ep_t *dwc_ep = &ep->dwc_ep;
20533 + volatile uint32_t *addr;
20534 + depctl_data_t depctl = {.d32 = 0};
20535 + dwc_otg_pcd_t *pcd = ep->pcd;
20536 + dwc_otg_dma_desc_t *dma_desc;
20539 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
20541 + if(dwc_ep->is_in) {
20542 + desc_sts_data_t sts = {.d32 = 0};
20543 + for(i = 0;i < dwc_ep->desc_cnt; ++i, ++dma_desc)
20545 + sts.d32 = readl(&dma_desc->status);
20546 + sts.b_iso_in.bs = BS_HOST_READY;
20547 + writel(sts.d32,&dma_desc->status);
20551 + desc_sts_data_t sts = {.d32 = 0};
20552 + for(i = 0;i < dwc_ep->desc_cnt; ++i, ++dma_desc)
20554 + sts.d32 = readl(&dma_desc->status);
20555 + sts.b_iso_out.bs = BS_HOST_READY;
20556 + writel(sts.d32,&dma_desc->status);
20560 + if(dwc_ep->is_in == 0){
20561 + addr = &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
20564 + addr = &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
20566 + depctl.b.epena = 1;
20567 + dwc_modify_reg32(addr,depctl.d32,depctl.d32);
20571 + * This function sets latest iso packet information(non-PTI mode)
20573 + * @param core_if Programming view of DWC_otg controller.
20574 + * @param ep The EP to start the transfer on.
20577 +void set_current_pkt_info(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
20579 + deptsiz_data_t deptsiz = { .d32 = 0 };
20580 + dma_addr_t dma_addr;
20583 + if(ep->proc_buf_num)
20584 + dma_addr = ep->dma_addr1;
20586 + dma_addr = ep->dma_addr0;
20590 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz);
20591 + offset = ep->data_per_frame;
20593 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz);
20594 + offset = ep->data_per_frame + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
20597 + if(!deptsiz.b.xfersize) {
20598 + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
20599 + ep->pkt_info[ep->cur_pkt].offset = ep->cur_pkt_dma_addr - dma_addr;
20600 + ep->pkt_info[ep->cur_pkt].status = 0;
20602 + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
20603 + ep->pkt_info[ep->cur_pkt].offset = ep->cur_pkt_dma_addr - dma_addr;
20604 + ep->pkt_info[ep->cur_pkt].status = -ENODATA;
20606 + ep->cur_pkt_addr += offset;
20607 + ep->cur_pkt_dma_addr += offset;
20612 + * This function sets latest iso packet information(DDMA mode)
20614 + * @param core_if Programming view of DWC_otg controller.
20615 + * @param dwc_ep The EP to start the transfer on.
20618 +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
20620 + dwc_otg_dma_desc_t* dma_desc;
20621 + desc_sts_data_t sts = {.d32 = 0};
20622 + iso_pkt_info_t *iso_packet;
20623 + uint32_t data_per_desc;
20627 + iso_packet = dwc_ep->pkt_info;
20629 + /** Reinit closed DMA Descriptors*/
20630 + /** ISO OUT EP */
20631 + if(dwc_ep->is_in == 0) {
20632 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
20635 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
20637 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
20639 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
20640 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
20641 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
20643 + sts.d32 = readl(&dma_desc->status);
20645 + /* Write status in iso_packet_decsriptor */
20646 + iso_packet->status = sts.b_iso_out.rxsts + (sts.b_iso_out.bs^BS_DMA_DONE);
20647 + if(iso_packet->status) {
20648 + iso_packet->status = -ENODATA;
20651 + /* Received data length */
20652 + if(!sts.b_iso_out.rxbytes){
20653 + iso_packet->length = data_per_desc - sts.b_iso_out.rxbytes;
20655 + iso_packet->length = data_per_desc - sts.b_iso_out.rxbytes +
20656 + (4 - dwc_ep->data_per_frame % 4);
20659 + iso_packet->offset = offset;
20661 + offset += data_per_desc;
20667 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
20669 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
20670 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
20671 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
20673 + sts.d32 = readl(&dma_desc->status);
20675 + /* Write status in iso_packet_decsriptor */
20676 + iso_packet->status = sts.b_iso_out.rxsts + (sts.b_iso_out.bs^BS_DMA_DONE);
20677 + if(iso_packet->status) {
20678 + iso_packet->status = -ENODATA;
20681 + /* Received data length */
20682 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
20684 + iso_packet->offset = offset;
20686 + offset += data_per_desc;
20691 + sts.d32 = readl(&dma_desc->status);
20693 + /* Write status in iso_packet_decsriptor */
20694 + iso_packet->status = sts.b_iso_out.rxsts + (sts.b_iso_out.bs^BS_DMA_DONE);
20695 + if(iso_packet->status) {
20696 + iso_packet->status = -ENODATA;
20698 + /* Received data length */
20699 + if(!sts.b_iso_out.rxbytes){
20700 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
20702 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
20703 + (4 - dwc_ep->data_per_frame % 4);
20706 + iso_packet->offset = offset;
20708 + else /** ISO IN EP */
20710 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
20712 + for(i = 0; i < dwc_ep->desc_cnt - 1; i++)
20714 + sts.d32 = readl(&dma_desc->status);
20716 + /* Write status in iso packet descriptor */
20717 + iso_packet->status = sts.b_iso_in.txsts + (sts.b_iso_in.bs^BS_DMA_DONE);
20718 + if(iso_packet->status != 0) {
20719 + iso_packet->status = -ENODATA;
20722 + /* Bytes has been transfered */
20723 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
20729 + sts.d32 = readl(&dma_desc->status);
20730 + while(sts.b_iso_in.bs == BS_DMA_BUSY) {
20731 + sts.d32 = readl(&dma_desc->status);
20734 + /* Write status in iso packet descriptor ??? do be done with ERROR codes*/
20735 + iso_packet->status = sts.b_iso_in.txsts + (sts.b_iso_in.bs^BS_DMA_DONE);
20736 + if(iso_packet->status != 0) {
20737 + iso_packet->status = -ENODATA;
20740 + /* Bytes has been transfered */
20741 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
20746 + * This function reinitialize DMA Descriptors for Isochronous transfer
20748 + * @param core_if Programming view of DWC_otg controller.
20749 + * @param dwc_ep The EP to start the transfer on.
20752 +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
20755 + dwc_otg_dma_desc_t* dma_desc;
20756 + dma_addr_t dma_ad;
20757 + volatile uint32_t *addr;
20758 + desc_sts_data_t sts = { .d32 =0 };
20759 + uint32_t data_per_desc;
20761 + if(dwc_ep->is_in == 0) {
20762 + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
20765 + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
20769 + if(dwc_ep->proc_buf_num == 0) {
20770 + /** Buffer 0 descriptors setup */
20771 + dma_ad = dwc_ep->dma_addr0;
20774 + /** Buffer 1 descriptors setup */
20775 + dma_ad = dwc_ep->dma_addr1;
20779 + /** Reinit closed DMA Descriptors*/
20780 + /** ISO OUT EP */
20781 + if(dwc_ep->is_in == 0) {
20782 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
20784 + sts.b_iso_out.bs = BS_HOST_READY;
20785 + sts.b_iso_out.rxsts = 0;
20786 + sts.b_iso_out.l = 0;
20787 + sts.b_iso_out.sp = 0;
20788 + sts.b_iso_out.ioc = 0;
20789 + sts.b_iso_out.pid = 0;
20790 + sts.b_iso_out.framenum = 0;
20792 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
20794 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
20796 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
20797 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
20798 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
20799 + sts.b_iso_out.rxbytes = data_per_desc;
20800 + writel((uint32_t)dma_ad, &dma_desc->buf);
20801 + writel(sts.d32, &dma_desc->status);
20803 + (uint32_t)dma_ad += data_per_desc;
20808 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
20811 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
20812 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
20813 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
20814 + sts.b_iso_out.rxbytes = data_per_desc;
20816 + writel((uint32_t)dma_ad, &dma_desc->buf);
20817 + writel(sts.d32, &dma_desc->status);
20820 + (uint32_t)dma_ad += data_per_desc;
20823 + sts.b_iso_out.ioc = 1;
20824 + sts.b_iso_out.l = dwc_ep->proc_buf_num;
20826 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
20827 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
20828 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
20829 + sts.b_iso_out.rxbytes = data_per_desc;
20831 + writel((uint32_t)dma_ad, &dma_desc->buf);
20832 + writel(sts.d32, &dma_desc->status);
20834 + else /** ISO IN EP */
20836 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
20838 + sts.b_iso_in.bs = BS_HOST_READY;
20839 + sts.b_iso_in.txsts = 0;
20840 + sts.b_iso_in.sp = 0;
20841 + sts.b_iso_in.ioc = 0;
20842 + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
20843 + sts.b_iso_in.framenum = dwc_ep->next_frame;
20844 + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
20845 + sts.b_iso_in.l = 0;
20847 + for(i = 0; i < dwc_ep->desc_cnt - 1; i++)
20849 + writel((uint32_t)dma_ad, &dma_desc->buf);
20850 + writel(sts.d32, &dma_desc->status);
20852 + sts.b_iso_in.framenum += dwc_ep->bInterval;
20853 + (uint32_t)dma_ad += dwc_ep->data_per_frame;
20857 + sts.b_iso_in.ioc = 1;
20858 + sts.b_iso_in.l = dwc_ep->proc_buf_num;
20860 + writel((uint32_t)dma_ad, &dma_desc->buf);
20861 + writel(sts.d32, &dma_desc->status);
20863 + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
20865 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
20870 + * This function is to handle Iso EP transfer complete interrupt
20871 + * in case Iso out packet was dropped
20873 + * @param core_if Programming view of DWC_otg controller.
20874 + * @param dwc_ep The EP for wihich transfer complete was asserted
20877 +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
20879 + uint32_t dma_addr;
20880 + uint32_t drp_pkt;
20881 + uint32_t drp_pkt_cnt;
20882 + deptsiz_data_t deptsiz = { .d32 = 0 };
20883 + depctl_data_t depctl = { .d32 = 0 };
20886 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
20888 + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
20889 + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
20891 + /* Setting dropped packets status */
20892 + for(i = 0; i < drp_pkt_cnt; ++i) {
20893 + dwc_ep->pkt_info[drp_pkt].status = -ENODATA;
20895 + deptsiz.b.pktcnt--;
20899 + if(deptsiz.b.pktcnt > 0) {
20900 + deptsiz.b.xfersize = dwc_ep->xfer_len - (dwc_ep->pkt_cnt - deptsiz.b.pktcnt) * dwc_ep->maxpacket;
20902 + deptsiz.b.xfersize = 0;
20903 + deptsiz.b.pktcnt = 0;
20906 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz, deptsiz.d32);
20908 + if(deptsiz.b.pktcnt > 0) {
20909 + if(dwc_ep->proc_buf_num) {
20910 + dma_addr = dwc_ep->dma_addr1 + dwc_ep->xfer_len - deptsiz.b.xfersize;
20912 + dma_addr = dwc_ep->dma_addr0 + dwc_ep->xfer_len - deptsiz.b.xfersize;;
20915 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
20917 + /** Re-enable endpoint, clear nak */
20919 + depctl.b.epena = 1;
20920 + depctl.b.cnak = 1;
20922 + dwc_modify_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl,
20923 + depctl.d32,depctl.d32);
20931 + * This function sets iso packets information(PTI mode)
20933 + * @param core_if Programming view of DWC_otg controller.
20934 + * @param ep The EP to start the transfer on.
20937 +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
20940 + dma_addr_t dma_ad;
20941 + iso_pkt_info_t *packet_info = ep->pkt_info;
20943 + uint32_t frame_data;
20944 + deptsiz_data_t deptsiz;
20946 + if(ep->proc_buf_num == 0) {
20947 + /** Buffer 0 descriptors setup */
20948 + dma_ad = ep->dma_addr0;
20951 + /** Buffer 1 descriptors setup */
20952 + dma_ad = ep->dma_addr1;
20957 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz);
20959 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz);
20962 + if(!deptsiz.b.xfersize) {
20964 + for(i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm)
20966 + frame_data = ep->data_per_frame;
20967 + for(j = 0; j < ep->pkt_per_frm; ++j) {
20969 + /* Packet status - is not set as initially
20970 + * it is set to 0 and if packet was sent
20971 + successfully, status field will remain 0*/
20974 + /* Bytes has been transfered */
20975 + packet_info->length = (ep->maxpacket < frame_data) ?
20976 + ep->maxpacket : frame_data;
20978 + /* Received packet offset */
20979 + packet_info->offset = offset;
20980 + offset += packet_info->length;
20981 + frame_data -= packet_info->length;
20988 + /* This is a workaround for in case of Transfer Complete with
20989 + * PktDrpSts interrupts merging - in this case Transfer complete
20990 + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
20991 + * set and with DOEPTSIZ register non zero. Investigations showed,
20992 + * that this happens when Out packet is dropped, but because of
20993 + * interrupts merging during first interrupt handling PktDrpSts
20994 + * bit is cleared and for next merged interrupts it is not reset.
20995 + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
21000 + return handle_iso_out_pkt_dropped(core_if, ep);
21006 + * This function is to handle Iso EP transfer complete interrupt
21008 + * @param ep The EP for which transfer complete was asserted
21011 +static void complete_iso_ep(dwc_otg_pcd_ep_t *ep)
21013 + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
21014 + dwc_ep_t *dwc_ep = &ep->dwc_ep;
21015 + uint8_t is_last = 0;
21017 + if(core_if->dma_enable) {
21018 + if(core_if->dma_desc_enable) {
21019 + set_ddma_iso_pkts_info(core_if, dwc_ep);
21020 + reinit_ddma_iso_xfer(core_if, dwc_ep);
21023 + if(core_if->pti_enh_enable) {
21024 + if(set_iso_pkts_info(core_if, dwc_ep)) {
21025 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21026 + dwc_otg_iso_ep_start_buf_transfer(core_if, dwc_ep);
21030 + set_current_pkt_info(core_if, dwc_ep);
21031 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
21033 + dwc_ep->cur_pkt = 0;
21034 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21035 + if(dwc_ep->proc_buf_num) {
21036 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
21037 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
21039 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
21040 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
21044 + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
21048 + set_current_pkt_info(core_if, dwc_ep);
21049 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
21051 + dwc_ep->cur_pkt = 0;
21052 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21053 + if(dwc_ep->proc_buf_num) {
21054 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
21055 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
21057 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
21058 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
21062 + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
21065 + dwc_otg_iso_buffer_done(ep, ep->iso_req);
21068 +#endif //DWC_EN_ISOC
21072 + * This function handles EP0 Control transfers.
21074 + * The state of the control tranfers are tracked in
21075 + * <code>ep0state</code>.
21077 +static void handle_ep0(dwc_otg_pcd_t *pcd)
21079 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
21080 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
21081 + desc_sts_data_t desc_sts;
21082 + deptsiz0_data_t deptsiz;
21083 + uint32_t byte_count;
21086 + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
21087 + print_ep0_state(pcd);
21090 + switch (pcd->ep0state) {
21091 + case EP0_DISCONNECT:
21095 + pcd->request_config = 0;
21100 + case EP0_IN_DATA_PHASE:
21102 + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
21103 + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ?"IN":"OUT"),
21104 + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
21107 + if (core_if->dma_enable != 0) {
21109 + * For EP0 we can only program 1 packet at a time so we
21110 + * need to do the make calculations after each complete.
21111 + * Call write_packet to make the calculations, as in
21112 + * slave mode, and use those values to determine if we
21115 + if(core_if->dma_desc_enable == 0) {
21116 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[0]->dieptsiz);
21117 + byte_count = ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
21120 + desc_sts.d32 = readl(core_if->dev_if->in_desc_addr);
21121 + byte_count = ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
21123 + ep0->dwc_ep.xfer_count += byte_count;
21124 + ep0->dwc_ep.xfer_buff += byte_count;
21125 + ep0->dwc_ep.dma_addr += byte_count;
21127 + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
21128 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
21129 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
21131 + else if(ep0->dwc_ep.sent_zlp) {
21132 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
21133 + ep0->dwc_ep.sent_zlp = 0;
21134 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
21137 + ep0_complete_request(ep0);
21138 + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
21141 + case EP0_OUT_DATA_PHASE:
21143 + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
21144 + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ?"IN":"OUT"),
21145 + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
21147 + if (core_if->dma_enable != 0) {
21148 + if(core_if->dma_desc_enable == 0) {
21149 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[0]->doeptsiz);
21150 + byte_count = ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
21153 + desc_sts.d32 = readl(core_if->dev_if->out_desc_addr);
21154 + byte_count = ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
21156 + ep0->dwc_ep.xfer_count += byte_count;
21157 + ep0->dwc_ep.xfer_buff += byte_count;
21158 + ep0->dwc_ep.dma_addr += byte_count;
21160 + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
21161 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
21162 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
21164 + else if(ep0->dwc_ep.sent_zlp) {
21165 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
21166 + ep0->dwc_ep.sent_zlp = 0;
21167 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
21170 + ep0_complete_request(ep0);
21171 + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
21176 + case EP0_IN_STATUS_PHASE:
21177 + case EP0_OUT_STATUS_PHASE:
21178 + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
21179 + ep0_complete_request(ep0);
21180 + pcd->ep0state = EP0_IDLE;
21181 + ep0->stopped = 1;
21182 + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
21184 + /* Prepare for more SETUP Packets */
21185 + if(core_if->dma_enable) {
21186 + ep0_out_start(core_if, pcd);
21191 + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
21195 + print_ep0_state(pcd);
21201 + * Restart transfer
21203 +static void restart_transfer(dwc_otg_pcd_t *pcd, const uint32_t epnum)
21205 + dwc_otg_core_if_t *core_if;
21206 + dwc_otg_dev_if_t *dev_if;
21207 + deptsiz_data_t dieptsiz = {.d32=0};
21208 + dwc_otg_pcd_ep_t *ep;
21210 + ep = get_in_ep(pcd, epnum);
21212 +#ifdef DWC_EN_ISOC
21213 + if(ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
21216 +#endif /* DWC_EN_ISOC */
21218 + core_if = GET_CORE_IF(pcd);
21219 + dev_if = core_if->dev_if;
21221 + dieptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dieptsiz);
21223 + DWC_DEBUGPL(DBG_PCD,"xfer_buff=%p xfer_count=%0x xfer_len=%0x"
21224 + " stopped=%d\n", ep->dwc_ep.xfer_buff,
21225 + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len ,
21228 + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
21230 + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
21231 + ep->dwc_ep.start_xfer_buff != 0) {
21232 + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
21233 + ep->dwc_ep.xfer_count = 0;
21234 + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
21235 + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
21238 + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
21239 + /* convert packet size to dwords. */
21240 + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
21241 + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
21244 + DWC_DEBUGPL(DBG_PCD,"xfer_buff=%p xfer_count=%0x "
21245 + "xfer_len=%0x stopped=%d\n",
21246 + ep->dwc_ep.xfer_buff,
21247 + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len ,
21250 + if (epnum == 0) {
21251 + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
21254 + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
21261 + * handle the IN EP disable interrupt.
21263 +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t *pcd,
21264 + const uint32_t epnum)
21266 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
21267 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
21268 + deptsiz_data_t dieptsiz = {.d32=0};
21269 + dctl_data_t dctl = {.d32=0};
21270 + dwc_otg_pcd_ep_t *ep;
21271 + dwc_ep_t *dwc_ep;
21273 + ep = get_in_ep(pcd, epnum);
21274 + dwc_ep = &ep->dwc_ep;
21276 + if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
21277 + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
21281 + DWC_DEBUGPL(DBG_PCD,"diepctl%d=%0x\n", epnum,
21282 + dwc_read_reg32(&dev_if->in_ep_regs[epnum]->diepctl));
21283 + dieptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dieptsiz);
21285 + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
21286 + dieptsiz.b.pktcnt,
21287 + dieptsiz.b.xfersize);
21289 + if (ep->stopped) {
21290 + /* Flush the Tx FIFO */
21291 + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
21292 + /* Clear the Global IN NP NAK */
21294 + dctl.b.cgnpinnak = 1;
21295 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl,
21297 + /* Restart the transaction */
21298 + if (dieptsiz.b.pktcnt != 0 ||
21299 + dieptsiz.b.xfersize != 0) {
21300 + restart_transfer(pcd, epnum);
21304 + /* Restart the transaction */
21305 + if (dieptsiz.b.pktcnt != 0 ||
21306 + dieptsiz.b.xfersize != 0) {
21307 + restart_transfer(pcd, epnum);
21309 + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
21314 + * Handler for the IN EP timeout handshake interrupt.
21316 +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t *pcd,
21317 + const uint32_t epnum)
21319 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
21320 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
21323 + deptsiz_data_t dieptsiz = {.d32=0};
21324 + uint32_t num = 0;
21326 + dctl_data_t dctl = {.d32=0};
21327 + dwc_otg_pcd_ep_t *ep;
21329 + gintmsk_data_t intr_mask = {.d32 = 0};
21331 + ep = get_in_ep(pcd, epnum);
21333 + /* Disable the NP Tx Fifo Empty Interrrupt */
21334 + if (!core_if->dma_enable) {
21335 + intr_mask.b.nptxfempty = 1;
21336 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
21338 + /** @todo NGS Check EP type.
21339 + * Implement for Periodic EPs */
21341 + * Non-periodic EP
21343 + /* Enable the Global IN NAK Effective Interrupt */
21344 + intr_mask.b.ginnakeff = 1;
21345 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
21346 + 0, intr_mask.d32);
21348 + /* Set Global IN NAK */
21349 + dctl.b.sgnpinnak = 1;
21350 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl,
21351 + dctl.d32, dctl.d32);
21356 + dieptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[num]->dieptsiz);
21357 + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
21358 + dieptsiz.b.pktcnt,
21359 + dieptsiz.b.xfersize);
21362 +#ifdef DISABLE_PERIODIC_EP
21364 + * Set the NAK bit for this EP to
21365 + * start the disable process.
21368 + diepctl.b.snak = 1;
21369 + dwc_modify_reg32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32, diepctl.d32);
21370 + ep->disabling = 1;
21376 + * Handler for the IN EP NAK interrupt.
21378 +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t *pcd,
21379 + const uint32_t epnum)
21381 + /** @todo implement ISR */
21382 + dwc_otg_core_if_t* core_if;
21383 + diepmsk_data_t intr_mask = { .d32 = 0};
21385 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
21386 + core_if = GET_CORE_IF(pcd);
21387 + intr_mask.b.nak = 1;
21389 + if(core_if->multiproc_int_enable) {
21390 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->diepeachintmsk[epnum],
21391 + intr_mask.d32, 0);
21393 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->diepmsk,
21394 + intr_mask.d32, 0);
21401 + * Handler for the OUT EP Babble interrupt.
21403 +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t *pcd,
21404 + const uint32_t epnum)
21406 + /** @todo implement ISR */
21407 + dwc_otg_core_if_t* core_if;
21408 + doepmsk_data_t intr_mask = { .d32 = 0};
21410 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "OUT EP Babble");
21411 + core_if = GET_CORE_IF(pcd);
21412 + intr_mask.b.babble = 1;
21414 + if(core_if->multiproc_int_enable) {
21415 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[epnum],
21416 + intr_mask.d32, 0);
21418 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepmsk,
21419 + intr_mask.d32, 0);
21426 + * Handler for the OUT EP NAK interrupt.
21428 +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t *pcd,
21429 + const uint32_t epnum)
21431 + /** @todo implement ISR */
21432 + dwc_otg_core_if_t* core_if;
21433 + doepmsk_data_t intr_mask = { .d32 = 0};
21435 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
21436 + core_if = GET_CORE_IF(pcd);
21437 + intr_mask.b.nak = 1;
21439 + if(core_if->multiproc_int_enable) {
21440 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[epnum],
21441 + intr_mask.d32, 0);
21443 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepmsk,
21444 + intr_mask.d32, 0);
21451 + * Handler for the OUT EP NYET interrupt.
21453 +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t *pcd,
21454 + const uint32_t epnum)
21456 + /** @todo implement ISR */
21457 + dwc_otg_core_if_t* core_if;
21458 + doepmsk_data_t intr_mask = { .d32 = 0};
21460 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
21461 + core_if = GET_CORE_IF(pcd);
21462 + intr_mask.b.nyet = 1;
21464 + if(core_if->multiproc_int_enable) {
21465 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[epnum],
21466 + intr_mask.d32, 0);
21468 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepmsk,
21469 + intr_mask.d32, 0);
21476 + * This interrupt indicates that an IN EP has a pending Interrupt.
21477 + * The sequence for handling the IN EP interrupt is shown below:
21478 + * -# Read the Device All Endpoint Interrupt register
21479 + * -# Repeat the following for each IN EP interrupt bit set (from
21481 + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
21482 + * -# If "Transfer Complete" call the request complete function
21483 + * -# If "Endpoint Disabled" complete the EP disable procedure.
21484 + * -# If "AHB Error Interrupt" log error
21485 + * -# If "Time-out Handshake" log error
21486 + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
21488 + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
21489 + * Mismatch Interrupt)
21491 +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t *pcd)
21493 +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
21495 + diepint_data_t diepint = {.d32=0}; \
21496 + diepint.b.__intr = 1; \
21497 + dwc_write_reg32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
21501 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
21502 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
21503 + diepint_data_t diepint = {.d32=0};
21504 + dctl_data_t dctl = {.d32=0};
21505 + depctl_data_t depctl = {.d32=0};
21506 + uint32_t ep_intr;
21507 + uint32_t epnum = 0;
21508 + dwc_otg_pcd_ep_t *ep;
21509 + dwc_ep_t *dwc_ep;
21510 + gintmsk_data_t intr_mask = {.d32 = 0};
21514 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
21516 + /* Read in the device interrupt bits */
21517 + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
21519 + /* Service the Device IN interrupts for each endpoint */
21521 + if (ep_intr&0x1) {
21522 + uint32_t empty_msk;
21523 + /* Get EP pointer */
21524 + ep = get_in_ep(pcd, epnum);
21525 + dwc_ep = &ep->dwc_ep;
21527 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->diepctl);
21528 + empty_msk = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
21530 + DWC_DEBUGPL(DBG_PCDV,
21531 + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
21536 + DWC_DEBUGPL(DBG_PCD,
21537 + "EP%d-%s: type=%d, mps=%d\n",
21538 + dwc_ep->num, (dwc_ep->is_in ?"IN":"OUT"),
21539 + dwc_ep->type, dwc_ep->maxpacket);
21541 + diepint.d32 = dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
21543 + DWC_DEBUGPL(DBG_PCDV, "EP %d Interrupt Register - 0x%x\n", epnum, diepint.d32);
21544 + /* Transfer complete */
21545 + if (diepint.b.xfercompl) {
21546 + /* Disable the NP Tx FIFO Empty
21548 + if(core_if->en_multiple_tx_fifo == 0) {
21549 + intr_mask.b.nptxfempty = 1;
21550 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
21553 + /* Disable the Tx FIFO Empty Interrupt for this EP */
21554 + uint32_t fifoemptymsk = 0x1 << dwc_ep->num;
21555 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
21556 + fifoemptymsk, 0);
21558 + /* Clear the bit in DIEPINTn for this interrupt */
21559 + CLEAR_IN_EP_INTR(core_if,epnum,xfercompl);
21561 + /* Complete the transfer */
21562 + if (epnum == 0) {
21565 +#ifdef DWC_EN_ISOC
21566 + else if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
21568 + complete_iso_ep(ep);
21570 +#endif //DWC_EN_ISOC
21576 + /* Endpoint disable */
21577 + if (diepint.b.epdisabled) {
21578 + DWC_DEBUGPL(DBG_ANY,"EP%d IN disabled\n", epnum);
21579 + handle_in_ep_disable_intr(pcd, epnum);
21581 + /* Clear the bit in DIEPINTn for this interrupt */
21582 + CLEAR_IN_EP_INTR(core_if,epnum,epdisabled);
21585 + if (diepint.b.ahberr) {
21586 + DWC_DEBUGPL(DBG_ANY,"EP%d IN AHB Error\n", epnum);
21587 + /* Clear the bit in DIEPINTn for this interrupt */
21588 + CLEAR_IN_EP_INTR(core_if,epnum,ahberr);
21590 + /* TimeOUT Handshake (non-ISOC IN EPs) */
21591 + if (diepint.b.timeout) {
21592 + DWC_DEBUGPL(DBG_ANY,"EP%d IN Time-out\n", epnum);
21593 + handle_in_ep_timeout_intr(pcd, epnum);
21595 + CLEAR_IN_EP_INTR(core_if,epnum,timeout);
21597 + /** IN Token received with TxF Empty */
21598 + if (diepint.b.intktxfemp) {
21599 + DWC_DEBUGPL(DBG_ANY,"EP%d IN TKN TxFifo Empty\n",
21601 + if (!ep->stopped && epnum != 0) {
21603 + diepmsk_data_t diepmsk = { .d32 = 0};
21604 + diepmsk.b.intktxfemp = 1;
21606 + if(core_if->multiproc_int_enable) {
21607 + dwc_modify_reg32(&dev_if->dev_global_regs->diepeachintmsk[epnum],
21610 + dwc_modify_reg32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32, 0);
21612 + start_next_request(ep);
21614 + else if(core_if->dma_desc_enable && epnum == 0 &&
21615 + pcd->ep0state == EP0_OUT_STATUS_PHASE) {
21616 + // EP0 IN set STALL
21617 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->diepctl);
21619 + /* set the disable and stall bits */
21620 + if (depctl.b.epena) {
21621 + depctl.b.epdis = 1;
21623 + depctl.b.stall = 1;
21624 + dwc_write_reg32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
21626 + CLEAR_IN_EP_INTR(core_if,epnum,intktxfemp);
21628 + /** IN Token Received with EP mismatch */
21629 + if (diepint.b.intknepmis) {
21630 + DWC_DEBUGPL(DBG_ANY,"EP%d IN TKN EP Mismatch\n", epnum);
21631 + CLEAR_IN_EP_INTR(core_if,epnum,intknepmis);
21633 + /** IN Endpoint NAK Effective */
21634 + if (diepint.b.inepnakeff) {
21635 + DWC_DEBUGPL(DBG_ANY,"EP%d IN EP NAK Effective\n", epnum);
21636 + /* Periodic EP */
21637 + if (ep->disabling) {
21639 + depctl.b.snak = 1;
21640 + depctl.b.epdis = 1;
21641 + dwc_modify_reg32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32, depctl.d32);
21643 + CLEAR_IN_EP_INTR(core_if,epnum,inepnakeff);
21647 + /** IN EP Tx FIFO Empty Intr */
21648 + if (diepint.b.emptyintr) {
21649 + DWC_DEBUGPL(DBG_ANY,"EP%d Tx FIFO Empty Intr \n", epnum);
21650 + write_empty_tx_fifo(pcd, epnum);
21652 + CLEAR_IN_EP_INTR(core_if,epnum,emptyintr);
21656 + /** IN EP BNA Intr */
21657 + if (diepint.b.bna) {
21658 + CLEAR_IN_EP_INTR(core_if,epnum,bna);
21659 + if(core_if->dma_desc_enable) {
21660 +#ifdef DWC_EN_ISOC
21661 + if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
21663 + * This checking is performed to prevent first "false" BNA
21664 + * handling occuring right after reconnect
21666 + if(dwc_ep->next_frame != 0xffffffff)
21667 + dwc_otg_pcd_handle_iso_bna(ep);
21670 +#endif //DWC_EN_ISOC
21672 + dctl.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dctl);
21674 + /* If Global Continue on BNA is disabled - disable EP */
21675 + if(!dctl.b.gcontbna) {
21677 + depctl.b.snak = 1;
21678 + depctl.b.epdis = 1;
21679 + dwc_modify_reg32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32, depctl.d32);
21681 + start_next_request(ep);
21686 + /* NAK Interrutp */
21687 + if (diepint.b.nak) {
21688 + DWC_DEBUGPL(DBG_ANY,"EP%d IN NAK Interrupt\n", epnum);
21689 + handle_in_ep_nak_intr(pcd, epnum);
21691 + CLEAR_IN_EP_INTR(core_if,epnum,nak);
21699 +#undef CLEAR_IN_EP_INTR
21703 + * This interrupt indicates that an OUT EP has a pending Interrupt.
21704 + * The sequence for handling the OUT EP interrupt is shown below:
21705 + * -# Read the Device All Endpoint Interrupt register
21706 + * -# Repeat the following for each OUT EP interrupt bit set (from
21708 + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
21709 + * -# If "Transfer Complete" call the request complete function
21710 + * -# If "Endpoint Disabled" complete the EP disable procedure.
21711 + * -# If "AHB Error Interrupt" log error
21712 + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
21713 + * Command Processing)
21715 +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t *pcd)
21717 +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
21719 + doepint_data_t doepint = {.d32=0}; \
21720 + doepint.b.__intr = 1; \
21721 + dwc_write_reg32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
21725 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
21726 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
21727 + uint32_t ep_intr;
21728 + doepint_data_t doepint = {.d32=0};
21729 + dctl_data_t dctl = {.d32=0};
21730 + depctl_data_t doepctl = {.d32=0};
21731 + uint32_t epnum = 0;
21732 + dwc_otg_pcd_ep_t *ep;
21733 + dwc_ep_t *dwc_ep;
21735 + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
21737 + /* Read in the device interrupt bits */
21738 + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
21741 + if (ep_intr&0x1) {
21742 + /* Get EP pointer */
21743 + ep = get_out_ep(pcd, epnum);
21744 + dwc_ep = &ep->dwc_ep;
21747 + DWC_DEBUGPL(DBG_PCDV,
21748 + "EP%d-%s: type=%d, mps=%d\n",
21749 + dwc_ep->num, (dwc_ep->is_in ?"IN":"OUT"),
21750 + dwc_ep->type, dwc_ep->maxpacket);
21752 + doepint.d32 = dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
21754 + /* Transfer complete */
21755 + if (doepint.b.xfercompl) {
21757 + if (epnum == 0) {
21758 + /* Clear the bit in DOEPINTn for this interrupt */
21759 + CLEAR_OUT_EP_INTR(core_if,epnum,xfercompl);
21760 + if(core_if->dma_desc_enable == 0 || pcd->ep0state != EP0_IDLE)
21762 +#ifdef DWC_EN_ISOC
21763 + } else if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
21764 + if (doepint.b.pktdrpsts == 0) {
21765 + /* Clear the bit in DOEPINTn for this interrupt */
21766 + CLEAR_OUT_EP_INTR(core_if,epnum,xfercompl);
21767 + complete_iso_ep(ep);
21770 + doepint_data_t doepint = {.d32=0};
21771 + doepint.b.xfercompl = 1;
21772 + doepint.b.pktdrpsts = 1;
21773 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[epnum]->doepint,
21775 + if(handle_iso_out_pkt_dropped(core_if,dwc_ep)) {
21776 + complete_iso_ep(ep);
21779 +#endif //DWC_EN_ISOC
21781 + /* Clear the bit in DOEPINTn for this interrupt */
21782 + CLEAR_OUT_EP_INTR(core_if,epnum,xfercompl);
21788 + /* Endpoint disable */
21789 + if (doepint.b.epdisabled) {
21791 + /* Clear the bit in DOEPINTn for this interrupt */
21792 + CLEAR_OUT_EP_INTR(core_if,epnum,epdisabled);
21795 + if (doepint.b.ahberr) {
21796 + DWC_DEBUGPL(DBG_PCD,"EP%d OUT AHB Error\n", epnum);
21797 + DWC_DEBUGPL(DBG_PCD,"EP DMA REG %d \n", core_if->dev_if->out_ep_regs[epnum]->doepdma);
21798 + CLEAR_OUT_EP_INTR(core_if,epnum,ahberr);
21800 + /* Setup Phase Done (contorl EPs) */
21801 + if (doepint.b.setup) {
21803 + DWC_DEBUGPL(DBG_PCD,"EP%d SETUP Done\n",
21806 + CLEAR_OUT_EP_INTR(core_if,epnum,setup);
21811 + /** OUT EP BNA Intr */
21812 + if (doepint.b.bna) {
21813 + CLEAR_OUT_EP_INTR(core_if,epnum,bna);
21814 + if(core_if->dma_desc_enable) {
21815 +#ifdef DWC_EN_ISOC
21816 + if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
21818 + * This checking is performed to prevent first "false" BNA
21819 + * handling occuring right after reconnect
21821 + if(dwc_ep->next_frame != 0xffffffff)
21822 + dwc_otg_pcd_handle_iso_bna(ep);
21825 +#endif //DWC_EN_ISOC
21827 + dctl.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dctl);
21829 + /* If Global Continue on BNA is disabled - disable EP*/
21830 + if(!dctl.b.gcontbna) {
21832 + doepctl.b.snak = 1;
21833 + doepctl.b.epdis = 1;
21834 + dwc_modify_reg32(&dev_if->out_ep_regs[epnum]->doepctl, doepctl.d32, doepctl.d32);
21836 + start_next_request(ep);
21841 + if (doepint.b.stsphsercvd) {
21842 + CLEAR_OUT_EP_INTR(core_if,epnum,stsphsercvd);
21843 + if(core_if->dma_desc_enable) {
21844 + do_setup_in_status_phase(pcd);
21847 + /* Babble Interrutp */
21848 + if (doepint.b.babble) {
21849 + DWC_DEBUGPL(DBG_ANY,"EP%d OUT Babble\n", epnum);
21850 + handle_out_ep_babble_intr(pcd, epnum);
21852 + CLEAR_OUT_EP_INTR(core_if,epnum,babble);
21854 + /* NAK Interrutp */
21855 + if (doepint.b.nak) {
21856 + DWC_DEBUGPL(DBG_ANY,"EP%d OUT NAK\n", epnum);
21857 + handle_out_ep_nak_intr(pcd, epnum);
21859 + CLEAR_OUT_EP_INTR(core_if,epnum,nak);
21861 + /* NYET Interrutp */
21862 + if (doepint.b.nyet) {
21863 + DWC_DEBUGPL(DBG_ANY,"EP%d OUT NYET\n", epnum);
21864 + handle_out_ep_nyet_intr(pcd, epnum);
21866 + CLEAR_OUT_EP_INTR(core_if,epnum,nyet);
21876 +#undef CLEAR_OUT_EP_INTR
21881 + * Incomplete ISO IN Transfer Interrupt.
21882 + * This interrupt indicates one of the following conditions occurred
21883 + * while transmitting an ISOC transaction.
21884 + * - Corrupted IN Token for ISOC EP.
21885 + * - Packet not complete in FIFO.
21886 + * The follow actions will be taken:
21887 + * -# Determine the EP
21888 + * -# Set incomplete flag in dwc_ep structure
21889 + * -# Disable EP; when "Endpoint Disabled" interrupt is received
21892 +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t *pcd)
21894 + gintsts_data_t gintsts;
21897 +#ifdef DWC_EN_ISOC
21898 + dwc_otg_dev_if_t *dev_if;
21899 + deptsiz_data_t deptsiz = { .d32 = 0};
21900 + depctl_data_t depctl = { .d32 = 0};
21901 + dsts_data_t dsts = { .d32 = 0};
21902 + dwc_ep_t *dwc_ep;
21905 + dev_if = GET_CORE_IF(pcd)->dev_if;
21907 + for(i = 1; i <= dev_if->num_in_eps; ++i) {
21908 + dwc_ep = &pcd->in_ep[i].dwc_ep;
21909 + if(dwc_ep->active &&
21910 + dwc_ep->type == USB_ENDPOINT_XFER_ISOC)
21912 + deptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->dieptsiz);
21913 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
21915 + if(depctl.b.epdis && deptsiz.d32) {
21916 + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
21917 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
21918 + dwc_ep->cur_pkt = 0;
21919 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21921 + if(dwc_ep->proc_buf_num) {
21922 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
21923 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
21925 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
21926 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
21931 + dsts.d32 = dwc_read_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->dsts);
21932 + dwc_ep->next_frame = dsts.b.soffn;
21934 + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF(pcd), dwc_ep);
21940 + gintmsk_data_t intr_mask = { .d32 = 0};
21941 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
21942 + "IN ISOC Incomplete");
21944 + intr_mask.b.incomplisoin = 1;
21945 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
21946 + intr_mask.d32, 0);
21947 +#endif //DWC_EN_ISOC
21949 + /* Clear interrupt */
21951 + gintsts.b.incomplisoin = 1;
21952 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
21959 + * Incomplete ISO OUT Transfer Interrupt.
21961 + * This interrupt indicates that the core has dropped an ISO OUT
21962 + * packet. The following conditions can be the cause:
21963 + * - FIFO Full, the entire packet would not fit in the FIFO.
21965 + * - Corrupted Token
21966 + * The follow actions will be taken:
21967 + * -# Determine the EP
21968 + * -# Set incomplete flag in dwc_ep structure
21969 + * -# Read any data from the FIFO
21970 + * -# Disable EP. when "Endpoint Disabled" interrupt is received
21973 +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t *pcd)
21975 + /* @todo implement ISR */
21976 + gintsts_data_t gintsts;
21978 +#ifdef DWC_EN_ISOC
21979 + dwc_otg_dev_if_t *dev_if;
21980 + deptsiz_data_t deptsiz = { .d32 = 0};
21981 + depctl_data_t depctl = { .d32 = 0};
21982 + dsts_data_t dsts = { .d32 = 0};
21983 + dwc_ep_t *dwc_ep;
21986 + dev_if = GET_CORE_IF(pcd)->dev_if;
21988 + for(i = 1; i <= dev_if->num_out_eps; ++i) {
21989 + dwc_ep = &pcd->in_ep[i].dwc_ep;
21990 + if(pcd->out_ep[i].dwc_ep.active &&
21991 + pcd->out_ep[i].dwc_ep.type == USB_ENDPOINT_XFER_ISOC)
21993 + deptsiz.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doeptsiz);
21994 + depctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doepctl);
21996 + if(depctl.b.epdis && deptsiz.d32) {
21997 + set_current_pkt_info(GET_CORE_IF(pcd), &pcd->out_ep[i].dwc_ep);
21998 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
21999 + dwc_ep->cur_pkt = 0;
22000 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
22002 + if(dwc_ep->proc_buf_num) {
22003 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
22004 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
22006 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
22007 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
22012 + dsts.d32 = dwc_read_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->dsts);
22013 + dwc_ep->next_frame = dsts.b.soffn;
22015 + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF(pcd), dwc_ep);
22020 + /** @todo implement ISR */
22021 + gintmsk_data_t intr_mask = { .d32 = 0};
22023 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
22024 + "OUT ISOC Incomplete");
22026 + intr_mask.b.incomplisoout = 1;
22027 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
22028 + intr_mask.d32, 0);
22030 +#endif // DWC_EN_ISOC
22032 + /* Clear interrupt */
22034 + gintsts.b.incomplisoout = 1;
22035 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
22042 + * This function handles the Global IN NAK Effective interrupt.
22045 +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t *pcd)
22047 + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
22048 + depctl_data_t diepctl = { .d32 = 0};
22049 + depctl_data_t diepctl_rd = { .d32 = 0};
22050 + gintmsk_data_t intr_mask = { .d32 = 0};
22051 + gintsts_data_t gintsts;
22054 + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
22056 + /* Disable all active IN EPs */
22057 + diepctl.b.epdis = 1;
22058 + diepctl.b.snak = 1;
22060 + for (i=0; i <= dev_if->num_in_eps; i++)
22062 + diepctl_rd.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
22063 + if (diepctl_rd.b.epena) {
22064 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepctl,
22068 + /* Disable the Global IN NAK Effective Interrupt */
22069 + intr_mask.b.ginnakeff = 1;
22070 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
22071 + intr_mask.d32, 0);
22073 + /* Clear interrupt */
22075 + gintsts.b.ginnakeff = 1;
22076 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
22083 + * OUT NAK Effective.
22086 +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t *pcd)
22088 + gintmsk_data_t intr_mask = { .d32 = 0};
22089 + gintsts_data_t gintsts;
22091 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
22092 + "Global IN NAK Effective\n");
22093 + /* Disable the Global IN NAK Effective Interrupt */
22094 + intr_mask.b.goutnakeff = 1;
22095 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
22096 + intr_mask.d32, 0);
22098 + /* Clear interrupt */
22100 + gintsts.b.goutnakeff = 1;
22101 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
22109 + * PCD interrupt handler.
22111 + * The PCD handles the device interrupts. Many conditions can cause a
22112 + * device interrupt. When an interrupt occurs, the device interrupt
22113 + * service routine determines the cause of the interrupt and
22114 + * dispatches handling to the appropriate function. These interrupt
22115 + * handling functions are described below.
22117 + * All interrupt registers are processed from LSB to MSB.
22120 +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t *pcd)
22122 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
22124 + dwc_otg_core_global_regs_t *global_regs =
22125 + core_if->core_global_regs;
22127 + gintsts_data_t gintr_status;
22128 + int32_t retval = 0;
22132 + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
22134 + dwc_read_reg32(&global_regs->gintsts),
22135 + dwc_read_reg32(&global_regs->gintmsk));
22138 + if (dwc_otg_is_device_mode(core_if)) {
22139 + SPIN_LOCK(&pcd->lock);
22141 + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
22143 + dwc_read_reg32(&global_regs->gintsts),
22144 + dwc_read_reg32(&global_regs->gintmsk));
22147 + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
22150 + if (!gintr_status.d32) {
22151 + SPIN_UNLOCK(&pcd->lock);
22155 + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
22156 + __func__, gintr_status.d32);
22158 + if (gintr_status.b.sofintr) {
22159 + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
22161 + if (gintr_status.b.rxstsqlvl) {
22162 + retval |= dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
22164 + if (gintr_status.b.nptxfempty) {
22165 + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
22167 + if (gintr_status.b.ginnakeff) {
22168 + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
22170 + if (gintr_status.b.goutnakeff) {
22171 + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
22173 + if (gintr_status.b.i2cintr) {
22174 + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
22176 + if (gintr_status.b.erlysuspend) {
22177 + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
22179 + if (gintr_status.b.usbreset) {
22180 + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
22182 + if (gintr_status.b.enumdone) {
22183 + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
22185 + if (gintr_status.b.isooutdrop) {
22186 + retval |= dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(pcd);
22188 + if (gintr_status.b.eopframe) {
22189 + retval |= dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
22191 + if (gintr_status.b.epmismatch) {
22192 + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(core_if);
22194 + if (gintr_status.b.inepint) {
22195 + if(!core_if->multiproc_int_enable) {
22196 + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
22199 + if (gintr_status.b.outepintr) {
22200 + if(!core_if->multiproc_int_enable) {
22201 + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
22204 + if (gintr_status.b.incomplisoin) {
22205 + retval |= dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
22207 + if (gintr_status.b.incomplisoout) {
22208 + retval |= dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
22211 + /* In MPI mode De vice Endpoints intterrupts are asserted
22212 + * without setting outepintr and inepint bits set, so these
22213 + * Interrupt handlers are called without checking these bit-fields
22215 + if(core_if->multiproc_int_enable) {
22216 + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
22217 + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
22220 + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
22221 + dwc_read_reg32(&global_regs->gintsts));
22223 + SPIN_UNLOCK(&pcd->lock);
22226 + S3C2410X_CLEAR_EINTPEND();
22231 +#endif /* DWC_HOST_ONLY */
22232 diff --git a/drivers/usb/dwc_otg/dwc_otg_regs.h b/drivers/usb/dwc_otg/dwc_otg_regs.h
22233 new file mode 100644
22234 index 0000000..8265766
22236 +++ b/drivers/usb/dwc_otg/dwc_otg_regs.h
22238 +/* ==========================================================================
22239 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
22240 + * $Revision: 1.2 $
22241 + * $Date: 2008-11-21 05:39:15 $
22242 + * $Change: 1099526 $
22244 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
22245 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
22246 + * otherwise expressly agreed to in writing between Synopsys and you.
22248 + * The Software IS NOT an item of Licensed Software or Licensed Product under
22249 + * any End User Software License Agreement or Agreement for Licensed Product
22250 + * with Synopsys or any supplement thereto. You are permitted to use and
22251 + * redistribute this Software in source and binary forms, with or without
22252 + * modification, provided that redistributions of source code must retain this
22253 + * notice. You may not view, use, disclose, copy or distribute this file or
22254 + * any information contained herein except pursuant to this license grant from
22255 + * Synopsys. If you do not agree with this notice, including the disclaimer
22256 + * below, then you are not authorized to use the Software.
22258 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22259 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22260 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22261 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
22262 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22263 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22264 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22265 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22266 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22267 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
22269 + * ========================================================================== */
22271 +#ifndef __DWC_OTG_REGS_H__
22272 +#define __DWC_OTG_REGS_H__
22277 + * This file contains the data structures for accessing the DWC_otg core registers.
22279 + * The application interfaces with the HS OTG core by reading from and
22280 + * writing to the Control and Status Register (CSR) space through the
22281 + * AHB Slave interface. These registers are 32 bits wide, and the
22282 + * addresses are 32-bit-block aligned.
22283 + * CSRs are classified as follows:
22284 + * - Core Global Registers
22285 + * - Device Mode Registers
22286 + * - Device Global Registers
22287 + * - Device Endpoint Specific Registers
22288 + * - Host Mode Registers
22289 + * - Host Global Registers
22290 + * - Host Port CSRs
22291 + * - Host Channel Specific Registers
22293 + * Only the Core Global registers can be accessed in both Device and
22294 + * Host modes. When the HS OTG core is operating in one mode, either
22295 + * Device or Host, the application must not access registers from the
22296 + * other mode. When the core switches from one mode to another, the
22297 + * registers in the new mode of operation must be reprogrammed as they
22298 + * would be after a power-on reset.
22301 +/** Maximum number of Periodic FIFOs */
22302 +#define MAX_PERIO_FIFOS 15
22303 +/** Maximum number of Transmit FIFOs */
22304 +#define MAX_TX_FIFOS 15
22306 +/** Maximum number of Endpoints/HostChannels */
22307 +#define MAX_EPS_CHANNELS 16
22309 +/****************************************************************************/
22310 +/** DWC_otg Core registers .
22311 + * The dwc_otg_core_global_regs structure defines the size
22312 + * and relative field offsets for the Core Global registers.
22314 +typedef struct dwc_otg_core_global_regs
22316 + /** OTG Control and Status Register. <i>Offset: 000h</i> */
22317 + volatile uint32_t gotgctl;
22318 + /** OTG Interrupt Register. <i>Offset: 004h</i> */
22319 + volatile uint32_t gotgint;
22320 + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
22321 + volatile uint32_t gahbcfg;
22323 +#define DWC_GLBINTRMASK 0x0001
22324 +#define DWC_DMAENABLE 0x0020
22325 +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
22326 +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
22327 +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
22328 +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
22330 + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
22331 + volatile uint32_t gusbcfg;
22332 + /**Core Reset Register. <i>Offset: 010h</i> */
22333 + volatile uint32_t grstctl;
22334 + /**Core Interrupt Register. <i>Offset: 014h</i> */
22335 + volatile uint32_t gintsts;
22336 + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
22337 + volatile uint32_t gintmsk;
22338 + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
22339 + volatile uint32_t grxstsr;
22340 + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
22341 + volatile uint32_t grxstsp;
22342 + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
22343 + volatile uint32_t grxfsiz;
22344 + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
22345 + volatile uint32_t gnptxfsiz;
22346 + /**Non Periodic Transmit FIFO/Queue Status Register (Read
22347 + * Only). <i>Offset: 02Ch</i> */
22348 + volatile uint32_t gnptxsts;
22349 + /**I2C Access Register. <i>Offset: 030h</i> */
22350 + volatile uint32_t gi2cctl;
22351 + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
22352 + volatile uint32_t gpvndctl;
22353 + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
22354 + volatile uint32_t ggpio;
22355 + /**User ID Register. <i>Offset: 03Ch</i> */
22356 + volatile uint32_t guid;
22357 + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
22358 + volatile uint32_t gsnpsid;
22359 + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
22360 + volatile uint32_t ghwcfg1;
22361 + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
22362 + volatile uint32_t ghwcfg2;
22363 +#define DWC_SLAVE_ONLY_ARCH 0
22364 +#define DWC_EXT_DMA_ARCH 1
22365 +#define DWC_INT_DMA_ARCH 2
22367 +#define DWC_MODE_HNP_SRP_CAPABLE 0
22368 +#define DWC_MODE_SRP_ONLY_CAPABLE 1
22369 +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
22370 +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
22371 +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
22372 +#define DWC_MODE_SRP_CAPABLE_HOST 5
22373 +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
22375 + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
22376 + volatile uint32_t ghwcfg3;
22377 + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
22378 + volatile uint32_t ghwcfg4;
22379 + /** Reserved <i>Offset: 054h-0FFh</i> */
22380 + volatile uint32_t reserved[43];
22381 + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
22382 + volatile uint32_t hptxfsiz;
22383 + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
22384 + otherwise Device Transmit FIFO#n Register.
22385 + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
22386 + volatile uint32_t dptxfsiz_dieptxf[15];
22387 +} dwc_otg_core_global_regs_t;
22390 + * This union represents the bit fields of the Core OTG Control
22391 + * and Status Register (GOTGCTL). Set the bits using the bit
22392 + * fields then write the <i>d32</i> value to the register.
22394 +typedef union gotgctl_data
22396 + /** raw register data */
22398 + /** register bits */
22401 + unsigned sesreqscs : 1;
22402 + unsigned sesreq : 1;
22403 + unsigned reserved2_7 : 6;
22404 + unsigned hstnegscs : 1;
22405 + unsigned hnpreq : 1;
22406 + unsigned hstsethnpen : 1;
22407 + unsigned devhnpen : 1;
22408 + unsigned reserved12_15 : 4;
22409 + unsigned conidsts : 1;
22410 + unsigned reserved17 : 1;
22411 + unsigned asesvld : 1;
22412 + unsigned bsesvld : 1;
22413 + unsigned currmod : 1;
22414 + unsigned reserved21_31 : 11;
22419 + * This union represents the bit fields of the Core OTG Interrupt Register
22420 + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
22421 + * value to the register.
22423 +typedef union gotgint_data
22425 + /** raw register data */
22427 + /** register bits */
22430 + /** Current Mode */
22431 + unsigned reserved0_1 : 2;
22433 + /** Session End Detected */
22434 + unsigned sesenddet : 1;
22436 + unsigned reserved3_7 : 5;
22438 + /** Session Request Success Status Change */
22439 + unsigned sesreqsucstschng : 1;
22440 + /** Host Negotiation Success Status Change */
22441 + unsigned hstnegsucstschng : 1;
22443 + unsigned reserver10_16 : 7;
22445 + /** Host Negotiation Detected */
22446 + unsigned hstnegdet : 1;
22447 + /** A-Device Timeout Change */
22448 + unsigned adevtoutchng : 1;
22449 + /** Debounce Done */
22450 + unsigned debdone : 1;
22452 + unsigned reserved31_20 : 12;
22459 + * This union represents the bit fields of the Core AHB Configuration
22460 + * Register (GAHBCFG). Set/clear the bits using the bit fields then
22461 + * write the <i>d32</i> value to the register.
22463 +typedef union gahbcfg_data
22465 + /** raw register data */
22467 + /** register bits */
22470 + unsigned glblintrmsk : 1;
22471 +#define DWC_GAHBCFG_GLBINT_ENABLE 1
22473 + unsigned hburstlen : 4;
22474 +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
22475 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
22476 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
22477 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
22478 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
22480 + unsigned dmaenable : 1;
22481 +#define DWC_GAHBCFG_DMAENABLE 1
22482 + unsigned reserved : 1;
22483 + unsigned nptxfemplvl_txfemplvl : 1;
22484 + unsigned ptxfemplvl : 1;
22485 +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
22486 +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
22487 + unsigned reserved9_31 : 23;
22492 + * This union represents the bit fields of the Core USB Configuration
22493 + * Register (GUSBCFG). Set the bits using the bit fields then write
22494 + * the <i>d32</i> value to the register.
22496 +typedef union gusbcfg_data
22498 + /** raw register data */
22500 + /** register bits */
22503 + unsigned toutcal : 3;
22504 + unsigned phyif : 1;
22505 + unsigned ulpi_utmi_sel : 1;
22506 + unsigned fsintf : 1;
22507 + unsigned physel : 1;
22508 + unsigned ddrsel : 1;
22509 + unsigned srpcap : 1;
22510 + unsigned hnpcap : 1;
22511 + unsigned usbtrdtim : 4;
22512 + unsigned nptxfrwnden : 1;
22513 + unsigned phylpwrclksel : 1;
22514 + unsigned otgutmifssel : 1;
22515 + unsigned ulpi_fsls : 1;
22516 + unsigned ulpi_auto_res : 1;
22517 + unsigned ulpi_clk_sus_m : 1;
22518 + unsigned ulpi_ext_vbus_drv : 1;
22519 + unsigned ulpi_int_vbus_indicator : 1;
22520 + unsigned term_sel_dl_pulse : 1;
22521 + unsigned reserved23_27 : 5;
22522 + unsigned tx_end_delay : 1;
22523 + unsigned reserved29_31 : 3;
22528 + * This union represents the bit fields of the Core Reset Register
22529 + * (GRSTCTL). Set/clear the bits using the bit fields then write the
22530 + * <i>d32</i> value to the register.
22532 +typedef union grstctl_data
22534 + /** raw register data */
22536 + /** register bits */
22539 + /** Core Soft Reset (CSftRst) (Device and Host)
22541 + * The application can flush the control logic in the
22542 + * entire core using this bit. This bit resets the
22543 + * pipelines in the AHB Clock domain as well as the
22544 + * PHY Clock domain.
22546 + * The state machines are reset to an IDLE state, the
22547 + * control bits in the CSRs are cleared, all the
22548 + * transmit FIFOs and the receive FIFO are flushed.
22550 + * The status mask bits that control the generation of
22551 + * the interrupt, are cleared, to clear the
22552 + * interrupt. The interrupt status bits are not
22553 + * cleared, so the application can get the status of
22554 + * any events that occurred in the core after it has
22557 + * Any transactions on the AHB are terminated as soon
22558 + * as possible following the protocol. Any
22559 + * transactions on the USB are terminated immediately.
22561 + * The configuration settings in the CSRs are
22562 + * unchanged, so the software doesn't have to
22563 + * reprogram these registers (Device
22564 + * Configuration/Host Configuration/Core System
22565 + * Configuration/Core PHY Configuration).
22567 + * The application can write to this bit, any time it
22568 + * wants to reset the core. This is a self clearing
22569 + * bit and the core clears this bit after all the
22570 + * necessary logic is reset in the core, which may
22571 + * take several clocks, depending on the current state
22574 + unsigned csftrst : 1;
22575 + /** Hclk Soft Reset
22577 + * The application uses this bit to reset the control logic in
22578 + * the AHB clock domain. Only AHB clock domain pipelines are
22581 + unsigned hsftrst : 1;
22582 + /** Host Frame Counter Reset (Host Only)<br>
22584 + * The application can reset the (micro)frame number
22585 + * counter inside the core, using this bit. When the
22586 + * (micro)frame counter is reset, the subsequent SOF
22587 + * sent out by the core, will have a (micro)frame
22590 + unsigned hstfrm : 1;
22591 + /** In Token Sequence Learning Queue Flush
22592 + * (INTknQFlsh) (Device Only)
22594 + unsigned intknqflsh : 1;
22595 + /** RxFIFO Flush (RxFFlsh) (Device and Host)
22597 + * The application can flush the entire Receive FIFO
22598 + * using this bit. <p>The application must first
22599 + * ensure that the core is not in the middle of a
22600 + * transaction. <p>The application should write into
22601 + * this bit, only after making sure that neither the
22602 + * DMA engine is reading from the RxFIFO nor the MAC
22603 + * is writing the data in to the FIFO. <p>The
22604 + * application should wait until the bit is cleared
22605 + * before performing any other operations. This bit
22606 + * will takes 8 clocks (slowest of PHY or AHB clock)
22609 + unsigned rxfflsh : 1;
22610 + /** TxFIFO Flush (TxFFlsh) (Device and Host).
22612 + * This bit is used to selectively flush a single or
22613 + * all transmit FIFOs. The application must first
22614 + * ensure that the core is not in the middle of a
22615 + * transaction. <p>The application should write into
22616 + * this bit, only after making sure that neither the
22617 + * DMA engine is writing into the TxFIFO nor the MAC
22618 + * is reading the data out of the FIFO. <p>The
22619 + * application should wait until the core clears this
22620 + * bit, before performing any operations. This bit
22621 + * will takes 8 clocks (slowest of PHY or AHB clock)
22624 + unsigned txfflsh : 1;
22626 + /** TxFIFO Number (TxFNum) (Device and Host).
22628 + * This is the FIFO number which needs to be flushed,
22629 + * using the TxFIFO Flush bit. This field should not
22630 + * be changed until the TxFIFO Flush bit is cleared by
22632 + * - 0x0 : Non Periodic TxFIFO Flush
22633 + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
22634 + * or Periodic TxFIFO in host mode
22635 + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
22637 + * - 0xF : Periodic TxFIFO #15 Flush in device mode
22638 + * - 0x10: Flush all the Transmit NonPeriodic and
22639 + * Transmit Periodic FIFOs in the core
22641 + unsigned txfnum : 5;
22643 + unsigned reserved11_29 : 19;
22644 + /** DMA Request Signal. Indicated DMA request is in
22645 + * probress. Used for debug purpose. */
22646 + unsigned dmareq : 1;
22647 + /** AHB Master Idle. Indicates the AHB Master State
22648 + * Machine is in IDLE condition. */
22649 + unsigned ahbidle : 1;
22655 + * This union represents the bit fields of the Core Interrupt Mask
22656 + * Register (GINTMSK). Set/clear the bits using the bit fields then
22657 + * write the <i>d32</i> value to the register.
22659 +typedef union gintmsk_data
22661 + /** raw register data */
22663 + /** register bits */
22666 + unsigned reserved0 : 1;
22667 + unsigned modemismatch : 1;
22668 + unsigned otgintr : 1;
22669 + unsigned sofintr : 1;
22670 + unsigned rxstsqlvl : 1;
22671 + unsigned nptxfempty : 1;
22672 + unsigned ginnakeff : 1;
22673 + unsigned goutnakeff : 1;
22674 + unsigned reserved8 : 1;
22675 + unsigned i2cintr : 1;
22676 + unsigned erlysuspend : 1;
22677 + unsigned usbsuspend : 1;
22678 + unsigned usbreset : 1;
22679 + unsigned enumdone : 1;
22680 + unsigned isooutdrop : 1;
22681 + unsigned eopframe : 1;
22682 + unsigned reserved16 : 1;
22683 + unsigned epmismatch : 1;
22684 + unsigned inepintr : 1;
22685 + unsigned outepintr : 1;
22686 + unsigned incomplisoin : 1;
22687 + unsigned incomplisoout : 1;
22688 + unsigned reserved22_23 : 2;
22689 + unsigned portintr : 1;
22690 + unsigned hcintr : 1;
22691 + unsigned ptxfempty : 1;
22692 + unsigned reserved27 : 1;
22693 + unsigned conidstschng : 1;
22694 + unsigned disconnect : 1;
22695 + unsigned sessreqintr : 1;
22696 + unsigned wkupintr : 1;
22700 + * This union represents the bit fields of the Core Interrupt Register
22701 + * (GINTSTS). Set/clear the bits using the bit fields then write the
22702 + * <i>d32</i> value to the register.
22704 +typedef union gintsts_data
22706 + /** raw register data */
22708 +#define DWC_SOF_INTR_MASK 0x0008
22709 + /** register bits */
22712 +#define DWC_HOST_MODE 1
22713 + unsigned curmode : 1;
22714 + unsigned modemismatch : 1;
22715 + unsigned otgintr : 1;
22716 + unsigned sofintr : 1;
22717 + unsigned rxstsqlvl : 1;
22718 + unsigned nptxfempty : 1;
22719 + unsigned ginnakeff : 1;
22720 + unsigned goutnakeff : 1;
22721 + unsigned reserved8 : 1;
22722 + unsigned i2cintr : 1;
22723 + unsigned erlysuspend : 1;
22724 + unsigned usbsuspend : 1;
22725 + unsigned usbreset : 1;
22726 + unsigned enumdone : 1;
22727 + unsigned isooutdrop : 1;
22728 + unsigned eopframe : 1;
22729 + unsigned intokenrx : 1;
22730 + unsigned epmismatch : 1;
22731 + unsigned inepint: 1;
22732 + unsigned outepintr : 1;
22733 + unsigned incomplisoin : 1;
22734 + unsigned incomplisoout : 1;
22735 + unsigned reserved22_23 : 2;
22736 + unsigned portintr : 1;
22737 + unsigned hcintr : 1;
22738 + unsigned ptxfempty : 1;
22739 + unsigned reserved27 : 1;
22740 + unsigned conidstschng : 1;
22741 + unsigned disconnect : 1;
22742 + unsigned sessreqintr : 1;
22743 + unsigned wkupintr : 1;
22749 + * This union represents the bit fields in the Device Receive Status Read and
22750 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
22751 + * element then read out the bits using the <i>b</i>it elements.
22753 +typedef union device_grxsts_data
22755 + /** raw register data */
22757 + /** register bits */
22760 + unsigned epnum : 4;
22761 + unsigned bcnt : 11;
22762 + unsigned dpid : 2;
22764 +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
22765 +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
22767 +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
22768 +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
22769 +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
22770 + unsigned pktsts : 4;
22772 + unsigned reserved : 7;
22774 +} device_grxsts_data_t;
22777 + * This union represents the bit fields in the Host Receive Status Read and
22778 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
22779 + * element then read out the bits using the <i>b</i>it elements.
22781 +typedef union host_grxsts_data
22783 + /** raw register data */
22785 + /** register bits */
22788 + unsigned chnum : 4;
22789 + unsigned bcnt : 11;
22790 + unsigned dpid : 2;
22792 + unsigned pktsts : 4;
22793 +#define DWC_GRXSTS_PKTSTS_IN 0x2
22794 +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
22795 +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
22796 +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
22798 + unsigned reserved : 11;
22800 +} host_grxsts_data_t;
22803 + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
22804 + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element then
22805 + * read out the bits using the <i>b</i>it elements.
22807 +typedef union fifosize_data
22809 + /** raw register data */
22811 + /** register bits */
22814 + unsigned startaddr : 16;
22815 + unsigned depth : 16;
22817 +} fifosize_data_t;
22820 + * This union represents the bit fields in the Non-Periodic Transmit
22821 + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
22822 + * <i>d32</i> element then read out the bits using the <i>b</i>it
22825 +typedef union gnptxsts_data
22827 + /** raw register data */
22829 + /** register bits */
22832 + unsigned nptxfspcavail : 16;
22833 + unsigned nptxqspcavail : 8;
22834 + /** Top of the Non-Periodic Transmit Request Queue
22835 + * - bit 24 - Terminate (Last entry for the selected
22837 + * - bits 26:25 - Token Type
22838 + * - 2'b00 - IN/OUT
22839 + * - 2'b01 - Zero Length OUT
22840 + * - 2'b10 - PING/Complete Split
22841 + * - 2'b11 - Channel Halt
22842 + * - bits 30:27 - Channel/EP Number
22844 + unsigned nptxqtop_terminate : 1;
22845 + unsigned nptxqtop_token : 2;
22846 + unsigned nptxqtop_chnep : 4;
22847 + unsigned reserved : 1;
22849 +} gnptxsts_data_t;
22852 + * This union represents the bit fields in the Transmit
22853 + * FIFO Status Register (DTXFSTS). Read the register into the
22854 + * <i>d32</i> element then read out the bits using the <i>b</i>it
22857 +typedef union dtxfsts_data
22859 + /** raw register data */
22861 + /** register bits */
22864 + unsigned txfspcavail : 16;
22865 + unsigned reserved : 16;
22870 + * This union represents the bit fields in the I2C Control Register
22871 + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
22872 + * bits using the <i>b</i>it elements.
22874 +typedef union gi2cctl_data
22876 + /** raw register data */
22878 + /** register bits */
22881 + unsigned rwdata : 8;
22882 + unsigned regaddr : 8;
22883 + unsigned addr : 7;
22884 + unsigned i2cen : 1;
22885 + unsigned ack : 1;
22886 + unsigned i2csuspctl : 1;
22887 + unsigned i2cdevaddr : 2;
22888 + unsigned reserved : 2;
22890 + unsigned bsydne : 1;
22895 + * This union represents the bit fields in the User HW Config1
22896 + * Register. Read the register into the <i>d32</i> element then read
22897 + * out the bits using the <i>b</i>it elements.
22899 +typedef union hwcfg1_data
22901 + /** raw register data */
22903 + /** register bits */
22906 + unsigned ep_dir0 : 2;
22907 + unsigned ep_dir1 : 2;
22908 + unsigned ep_dir2 : 2;
22909 + unsigned ep_dir3 : 2;
22910 + unsigned ep_dir4 : 2;
22911 + unsigned ep_dir5 : 2;
22912 + unsigned ep_dir6 : 2;
22913 + unsigned ep_dir7 : 2;
22914 + unsigned ep_dir8 : 2;
22915 + unsigned ep_dir9 : 2;
22916 + unsigned ep_dir10 : 2;
22917 + unsigned ep_dir11 : 2;
22918 + unsigned ep_dir12 : 2;
22919 + unsigned ep_dir13 : 2;
22920 + unsigned ep_dir14 : 2;
22921 + unsigned ep_dir15 : 2;
22926 + * This union represents the bit fields in the User HW Config2
22927 + * Register. Read the register into the <i>d32</i> element then read
22928 + * out the bits using the <i>b</i>it elements.
22930 +typedef union hwcfg2_data
22932 + /** raw register data */
22934 + /** register bits */
22938 + unsigned op_mode : 3;
22939 +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
22940 +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
22941 +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
22942 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
22943 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
22944 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
22945 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
22947 + unsigned architecture : 2;
22948 + unsigned point2point : 1;
22949 + unsigned hs_phy_type : 2;
22950 +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
22951 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
22952 +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
22953 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
22955 + unsigned fs_phy_type : 2;
22956 + unsigned num_dev_ep : 4;
22957 + unsigned num_host_chan : 4;
22958 + unsigned perio_ep_supported : 1;
22959 + unsigned dynamic_fifo : 1;
22960 + unsigned multi_proc_int : 1;
22961 + unsigned reserved21 : 1;
22962 + unsigned nonperio_tx_q_depth : 2;
22963 + unsigned host_perio_tx_q_depth : 2;
22964 + unsigned dev_token_q_depth : 5;
22965 + unsigned reserved31 : 1;
22970 + * This union represents the bit fields in the User HW Config3
22971 + * Register. Read the register into the <i>d32</i> element then read
22972 + * out the bits using the <i>b</i>it elements.
22974 +typedef union hwcfg3_data
22976 + /** raw register data */
22978 + /** register bits */
22982 + unsigned xfer_size_cntr_width : 4;
22983 + unsigned packet_size_cntr_width : 3;
22984 + unsigned otg_func : 1;
22985 + unsigned i2c : 1;
22986 + unsigned vendor_ctrl_if : 1;
22987 + unsigned optional_features : 1;
22988 + unsigned synch_reset_type : 1;
22989 + unsigned ahb_phy_clock_synch : 1;
22990 + unsigned reserved15_13 : 3;
22991 + unsigned dfifo_depth : 16;
22996 + * This union represents the bit fields in the User HW Config4
22997 + * Register. Read the register into the <i>d32</i> element then read
22998 + * out the bits using the <i>b</i>it elements.
23000 +typedef union hwcfg4_data
23002 + /** raw register data */
23004 + /** register bits */
23007 + unsigned num_dev_perio_in_ep : 4;
23008 + unsigned power_optimiz : 1;
23009 + unsigned min_ahb_freq : 9;
23010 + unsigned utmi_phy_data_width : 2;
23011 + unsigned num_dev_mode_ctrl_ep : 4;
23012 + unsigned iddig_filt_en : 1;
23013 + unsigned vbus_valid_filt_en : 1;
23014 + unsigned a_valid_filt_en : 1;
23015 + unsigned b_valid_filt_en : 1;
23016 + unsigned session_end_filt_en : 1;
23017 + unsigned ded_fifo_en : 1;
23018 + unsigned num_in_eps : 4;
23019 + unsigned desc_dma : 1;
23020 + unsigned desc_dma_dyn : 1;
23024 +////////////////////////////////////////////
23025 +// Device Registers
23027 + * Device Global Registers. <i>Offsets 800h-BFFh</i>
23029 + * The following structures define the size and relative field offsets
23030 + * for the Device Mode Registers.
23032 + * <i>These registers are visible only in Device mode and must not be
23033 + * accessed in Host mode, as the results are unknown.</i>
23035 +typedef struct dwc_otg_dev_global_regs
23037 + /** Device Configuration Register. <i>Offset 800h</i> */
23038 + volatile uint32_t dcfg;
23039 + /** Device Control Register. <i>Offset: 804h</i> */
23040 + volatile uint32_t dctl;
23041 + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
23042 + volatile uint32_t dsts;
23043 + /** Reserved. <i>Offset: 80Ch</i> */
23045 + /** Device IN Endpoint Common Interrupt Mask
23046 + * Register. <i>Offset: 810h</i> */
23047 + volatile uint32_t diepmsk;
23048 + /** Device OUT Endpoint Common Interrupt Mask
23049 + * Register. <i>Offset: 814h</i> */
23050 + volatile uint32_t doepmsk;
23051 + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
23052 + volatile uint32_t daint;
23053 + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
23055 + volatile uint32_t daintmsk;
23056 + /** Device IN Token Queue Read Register-1 (Read Only).
23057 + * <i>Offset: 820h</i> */
23058 + volatile uint32_t dtknqr1;
23059 + /** Device IN Token Queue Read Register-2 (Read Only).
23060 + * <i>Offset: 824h</i> */
23061 + volatile uint32_t dtknqr2;
23062 + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
23063 + volatile uint32_t dvbusdis;
23064 + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
23065 + volatile uint32_t dvbuspulse;
23066 + /** Device IN Token Queue Read Register-3 (Read Only). /
23067 + * Device Thresholding control register (Read/Write)
23068 + * <i>Offset: 830h</i> */
23069 + volatile uint32_t dtknqr3_dthrctl;
23070 + /** Device IN Token Queue Read Register-4 (Read Only). /
23071 + * Device IN EPs empty Inr. Mask Register (Read/Write)
23072 + * <i>Offset: 834h</i> */
23073 + volatile uint32_t dtknqr4_fifoemptymsk;
23074 + /** Device Each Endpoint Interrupt Register (Read Only). /
23075 + * <i>Offset: 838h</i> */
23076 + volatile uint32_t deachint;
23077 + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
23078 + * <i>Offset: 83Ch</i> */
23079 + volatile uint32_t deachintmsk;
23080 + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
23081 + * <i>Offset: 840h</i> */
23082 + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
23083 + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
23084 + * <i>Offset: 880h</i> */
23085 + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
23086 +} dwc_otg_device_global_regs_t;
23089 + * This union represents the bit fields in the Device Configuration
23090 + * Register. Read the register into the <i>d32</i> member then
23091 + * set/clear the bits using the <i>b</i>it elements. Write the
23092 + * <i>d32</i> member to the dcfg register.
23094 +typedef union dcfg_data
23096 + /** raw register data */
23098 + /** register bits */
23101 + /** Device Speed */
23102 + unsigned devspd : 2;
23103 + /** Non Zero Length Status OUT Handshake */
23104 + unsigned nzstsouthshk : 1;
23105 +#define DWC_DCFG_SEND_STALL 1
23107 + unsigned reserved3 : 1;
23108 + /** Device Addresses */
23109 + unsigned devaddr : 7;
23110 + /** Periodic Frame Interval */
23111 + unsigned perfrint : 2;
23112 +#define DWC_DCFG_FRAME_INTERVAL_80 0
23113 +#define DWC_DCFG_FRAME_INTERVAL_85 1
23114 +#define DWC_DCFG_FRAME_INTERVAL_90 2
23115 +#define DWC_DCFG_FRAME_INTERVAL_95 3
23117 + unsigned reserved13_17 : 5;
23118 + /** In Endpoint Mis-match count */
23119 + unsigned epmscnt : 5;
23120 + /** Enable Descriptor DMA in Device mode */
23121 + unsigned descdma : 1;
23126 + * This union represents the bit fields in the Device Control
23127 + * Register. Read the register into the <i>d32</i> member then
23128 + * set/clear the bits using the <i>b</i>it elements.
23130 +typedef union dctl_data
23132 + /** raw register data */
23134 + /** register bits */
23137 + /** Remote Wakeup */
23138 + unsigned rmtwkupsig : 1;
23139 + /** Soft Disconnect */
23140 + unsigned sftdiscon : 1;
23141 + /** Global Non-Periodic IN NAK Status */
23142 + unsigned gnpinnaksts : 1;
23143 + /** Global OUT NAK Status */
23144 + unsigned goutnaksts : 1;
23145 + /** Test Control */
23146 + unsigned tstctl : 3;
23147 + /** Set Global Non-Periodic IN NAK */
23148 + unsigned sgnpinnak : 1;
23149 + /** Clear Global Non-Periodic IN NAK */
23150 + unsigned cgnpinnak : 1;
23151 + /** Set Global OUT NAK */
23152 + unsigned sgoutnak : 1;
23153 + /** Clear Global OUT NAK */
23154 + unsigned cgoutnak : 1;
23156 + /** Power-On Programming Done */
23157 + unsigned pwronprgdone : 1;
23158 + /** Global Continue on BNA */
23159 + unsigned gcontbna : 1;
23160 + /** Global Multi Count */
23161 + unsigned gmc : 2;
23162 + /** Ignore Frame Number for ISOC EPs */
23163 + unsigned ifrmnum : 1;
23164 + /** NAK on Babble */
23165 + unsigned nakonbble : 1;
23167 + unsigned reserved16_31 : 16;
23172 + * This union represents the bit fields in the Device Status
23173 + * Register. Read the register into the <i>d32</i> member then
23174 + * set/clear the bits using the <i>b</i>it elements.
23176 +typedef union dsts_data
23178 + /** raw register data */
23180 + /** register bits */
23183 + /** Suspend Status */
23184 + unsigned suspsts : 1;
23185 + /** Enumerated Speed */
23186 + unsigned enumspd : 2;
23187 +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
23188 +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
23189 +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
23190 +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
23191 + /** Erratic Error */
23192 + unsigned errticerr : 1;
23193 + unsigned reserved4_7: 4;
23194 + /** Frame or Microframe Number of the received SOF */
23195 + unsigned soffn : 14;
23196 + unsigned reserved22_31 : 10;
23202 + * This union represents the bit fields in the Device IN EP Interrupt
23203 + * Register and the Device IN EP Common Mask Register.
23205 + * - Read the register into the <i>d32</i> member then set/clear the
23206 + * bits using the <i>b</i>it elements.
23208 +typedef union diepint_data
23210 + /** raw register data */
23212 + /** register bits */
23215 + /** Transfer complete mask */
23216 + unsigned xfercompl : 1;
23217 + /** Endpoint disable mask */
23218 + unsigned epdisabled : 1;
23219 + /** AHB Error mask */
23220 + unsigned ahberr : 1;
23221 + /** TimeOUT Handshake mask (non-ISOC EPs) */
23222 + unsigned timeout : 1;
23223 + /** IN Token received with TxF Empty mask */
23224 + unsigned intktxfemp : 1;
23225 + /** IN Token Received with EP mismatch mask */
23226 + unsigned intknepmis : 1;
23227 + /** IN Endpoint HAK Effective mask */
23228 + unsigned inepnakeff : 1;
23229 + /** IN Endpoint HAK Effective mask */
23230 + unsigned emptyintr : 1;
23232 + unsigned txfifoundrn : 1;
23234 + /** BNA Interrupt mask */
23235 + unsigned bna : 1;
23237 + unsigned reserved10_12 : 3;
23238 + /** BNA Interrupt mask */
23239 + unsigned nak : 1;
23241 + unsigned reserved14_31 : 18;
23246 + * This union represents the bit fields in the Device IN EP
23247 + * Common/Dedicated Interrupt Mask Register.
23249 +typedef union diepint_data diepmsk_data_t;
23252 + * This union represents the bit fields in the Device OUT EP Interrupt
23253 + * Registerand Device OUT EP Common Interrupt Mask Register.
23255 + * - Read the register into the <i>d32</i> member then set/clear the
23256 + * bits using the <i>b</i>it elements.
23258 +typedef union doepint_data
23260 + /** raw register data */
23262 + /** register bits */
23265 + /** Transfer complete */
23266 + unsigned xfercompl : 1;
23267 + /** Endpoint disable */
23268 + unsigned epdisabled : 1;
23270 + unsigned ahberr : 1;
23271 + /** Setup Phase Done (contorl EPs) */
23272 + unsigned setup : 1;
23273 + /** OUT Token Received when Endpoint Disabled */
23274 + unsigned outtknepdis : 1;
23276 + unsigned stsphsercvd : 1;
23277 + /** Back-to-Back SETUP Packets Received */
23278 + unsigned back2backsetup : 1;
23280 + unsigned reserved7 : 1;
23281 + /** OUT packet Error */
23282 + unsigned outpkterr : 1;
23283 + /** BNA Interrupt */
23284 + unsigned bna : 1;
23286 + unsigned reserved10 : 1;
23287 + /** Packet Drop Status */
23288 + unsigned pktdrpsts : 1;
23289 + /** Babble Interrupt */
23290 + unsigned babble : 1;
23291 + /** NAK Interrupt */
23292 + unsigned nak : 1;
23293 + /** NYET Interrupt */
23294 + unsigned nyet : 1;
23296 + unsigned reserved15_31 : 17;
23301 + * This union represents the bit fields in the Device OUT EP
23302 + * Common/Dedicated Interrupt Mask Register.
23304 +typedef union doepint_data doepmsk_data_t;
23307 + * This union represents the bit fields in the Device All EP Interrupt
23308 + * and Mask Registers.
23309 + * - Read the register into the <i>d32</i> member then set/clear the
23310 + * bits using the <i>b</i>it elements.
23312 +typedef union daint_data
23314 + /** raw register data */
23316 + /** register bits */
23319 + /** IN Endpoint bits */
23320 + unsigned in : 16;
23321 + /** OUT Endpoint bits */
23322 + unsigned out : 16;
23326 + /** IN Endpoint bits */
23327 + unsigned inep0 : 1;
23328 + unsigned inep1 : 1;
23329 + unsigned inep2 : 1;
23330 + unsigned inep3 : 1;
23331 + unsigned inep4 : 1;
23332 + unsigned inep5 : 1;
23333 + unsigned inep6 : 1;
23334 + unsigned inep7 : 1;
23335 + unsigned inep8 : 1;
23336 + unsigned inep9 : 1;
23337 + unsigned inep10 : 1;
23338 + unsigned inep11 : 1;
23339 + unsigned inep12 : 1;
23340 + unsigned inep13 : 1;
23341 + unsigned inep14 : 1;
23342 + unsigned inep15 : 1;
23343 + /** OUT Endpoint bits */
23344 + unsigned outep0 : 1;
23345 + unsigned outep1 : 1;
23346 + unsigned outep2 : 1;
23347 + unsigned outep3 : 1;
23348 + unsigned outep4 : 1;
23349 + unsigned outep5 : 1;
23350 + unsigned outep6 : 1;
23351 + unsigned outep7 : 1;
23352 + unsigned outep8 : 1;
23353 + unsigned outep9 : 1;
23354 + unsigned outep10 : 1;
23355 + unsigned outep11 : 1;
23356 + unsigned outep12 : 1;
23357 + unsigned outep13 : 1;
23358 + unsigned outep14 : 1;
23359 + unsigned outep15 : 1;
23364 + * This union represents the bit fields in the Device IN Token Queue
23365 + * Read Registers.
23366 + * - Read the register into the <i>d32</i> member.
23367 + * - READ-ONLY Register
23369 +typedef union dtknq1_data
23371 + /** raw register data */
23373 + /** register bits */
23376 + /** In Token Queue Write Pointer */
23377 + unsigned intknwptr : 5;
23379 + unsigned reserved05_06 : 2;
23380 + /** write pointer has wrapped. */
23381 + unsigned wrap_bit : 1;
23382 + /** EP Numbers of IN Tokens 0 ... 4 */
23383 + unsigned epnums0_5 : 24;
23388 + * This union represents Threshold control Register
23389 + * - Read and write the register into the <i>d32</i> member.
23390 + * - READ-WRITABLE Register
23392 +typedef union dthrctl_data
23394 + /** raw register data */
23396 + /** register bits */
23399 + /** non ISO Tx Thr. Enable */
23400 + unsigned non_iso_thr_en : 1;
23401 + /** ISO Tx Thr. Enable */
23402 + unsigned iso_thr_en : 1;
23403 + /** Tx Thr. Length */
23404 + unsigned tx_thr_len : 9;
23406 + unsigned reserved11_15 : 5;
23407 + /** Rx Thr. Enable */
23408 + unsigned rx_thr_en : 1;
23409 + /** Rx Thr. Length */
23410 + unsigned rx_thr_len : 9;
23412 + unsigned reserved26_31 : 6;
23418 + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
23421 + * There will be one set of endpoint registers per logical endpoint
23424 + * <i>These registers are visible only in Device mode and must not be
23425 + * accessed in Host mode, as the results are unknown.</i>
23427 +typedef struct dwc_otg_dev_in_ep_regs
23429 + /** Device IN Endpoint Control Register. <i>Offset:900h +
23430 + * (ep_num * 20h) + 00h</i> */
23431 + volatile uint32_t diepctl;
23432 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
23433 + uint32_t reserved04;
23434 + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
23435 + * (ep_num * 20h) + 08h</i> */
23436 + volatile uint32_t diepint;
23437 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
23438 + uint32_t reserved0C;
23439 + /** Device IN Endpoint Transfer Size
23440 + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
23441 + volatile uint32_t dieptsiz;
23442 + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
23443 + * (ep_num * 20h) + 14h</i> */
23444 + volatile uint32_t diepdma;
23445 + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
23446 + * (ep_num * 20h) + 18h</i> */
23447 + volatile uint32_t dtxfsts;
23448 + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
23449 + * (ep_num * 20h) + 1Ch</i> */
23450 + volatile uint32_t diepdmab;
23451 +} dwc_otg_dev_in_ep_regs_t;
23454 + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
23457 + * There will be one set of endpoint registers per logical endpoint
23460 + * <i>These registers are visible only in Device mode and must not be
23461 + * accessed in Host mode, as the results are unknown.</i>
23463 +typedef struct dwc_otg_dev_out_ep_regs
23465 + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
23466 + * (ep_num * 20h) + 00h</i> */
23467 + volatile uint32_t doepctl;
23468 + /** Device OUT Endpoint Frame number Register. <i>Offset:
23469 + * B00h + (ep_num * 20h) + 04h</i> */
23470 + volatile uint32_t doepfn;
23471 + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
23472 + * (ep_num * 20h) + 08h</i> */
23473 + volatile uint32_t doepint;
23474 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
23475 + uint32_t reserved0C;
23476 + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
23477 + * B00h + (ep_num * 20h) + 10h</i> */
23478 + volatile uint32_t doeptsiz;
23479 + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
23480 + * + (ep_num * 20h) + 14h</i> */
23481 + volatile uint32_t doepdma;
23482 + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 1Ch</i> */
23484 + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
23485 + * + (ep_num * 20h) + 1Ch</i> */
23486 + uint32_t doepdmab;
23487 +} dwc_otg_dev_out_ep_regs_t;
23490 + * This union represents the bit fields in the Device EP Control
23491 + * Register. Read the register into the <i>d32</i> member then
23492 + * set/clear the bits using the <i>b</i>it elements.
23494 +typedef union depctl_data
23496 + /** raw register data */
23498 + /** register bits */
23501 + /** Maximum Packet Size
23503 + * IN/OUT EP0 - 2 bits
23504 + * 2'b00: 64 Bytes
23508 + unsigned mps : 11;
23509 +#define DWC_DEP0CTL_MPS_64 0
23510 +#define DWC_DEP0CTL_MPS_32 1
23511 +#define DWC_DEP0CTL_MPS_16 2
23512 +#define DWC_DEP0CTL_MPS_8 3
23514 + /** Next Endpoint
23516 + * OUT EPn/OUT EP0 - reserved */
23517 + unsigned nextep : 4;
23519 + /** USB Active Endpoint */
23520 + unsigned usbactep : 1;
23522 + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
23523 + * This field contains the PID of the packet going to
23524 + * be received or transmitted on this endpoint. The
23525 + * application should program the PID of the first
23526 + * packet going to be received or transmitted on this
23527 + * endpoint , after the endpoint is
23528 + * activated. Application use the SetD1PID and
23529 + * SetD0PID fields of this register to program either
23532 + * The encoding for this field is
23536 + unsigned dpid : 1;
23538 + /** NAK Status */
23539 + unsigned naksts : 1;
23541 + /** Endpoint Type
23543 + * 2'b01: Isochronous
23545 + * 2'b11: Interrupt */
23546 + unsigned eptype : 2;
23549 + * OUT EPn/OUT EP0
23550 + * IN EPn/IN EP0 - reserved */
23551 + unsigned snp : 1;
23553 + /** Stall Handshake */
23554 + unsigned stall : 1;
23556 + /** Tx Fifo Number
23558 + * OUT EPn/OUT EP0 - reserved */
23559 + unsigned txfnum : 4;
23562 + unsigned cnak : 1;
23564 + unsigned snak : 1;
23565 + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
23566 + * Writing to this field sets the Endpoint DPID (DPID)
23567 + * field in this register to DATA0. Set Even
23568 + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
23569 + * Writing to this field sets the Even/Odd
23570 + * (micro)frame (EO_FrNum) field to even (micro)
23573 + unsigned setd0pid : 1;
23574 + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
23575 + * Writing to this field sets the Endpoint DPID (DPID)
23576 + * field in this register to DATA1 Set Odd
23577 + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
23578 + * Writing to this field sets the Even/Odd
23579 + * (micro)frame (EO_FrNum) field to odd (micro) frame.
23581 + unsigned setd1pid : 1;
23583 + /** Endpoint Disable */
23584 + unsigned epdis : 1;
23585 + /** Endpoint Enable */
23586 + unsigned epena : 1;
23591 + * This union represents the bit fields in the Device EP Transfer
23592 + * Size Register. Read the register into the <i>d32</i> member then
23593 + * set/clear the bits using the <i>b</i>it elements.
23595 +typedef union deptsiz_data
23597 + /** raw register data */
23599 + /** register bits */
23601 + /** Transfer size */
23602 + unsigned xfersize : 19;
23603 + /** Packet Count */
23604 + unsigned pktcnt : 10;
23605 + /** Multi Count - Periodic IN endpoints */
23607 + unsigned reserved : 1;
23612 + * This union represents the bit fields in the Device EP 0 Transfer
23613 + * Size Register. Read the register into the <i>d32</i> member then
23614 + * set/clear the bits using the <i>b</i>it elements.
23616 +typedef union deptsiz0_data
23618 + /** raw register data */
23620 + /** register bits */
23622 + /** Transfer size */
23623 + unsigned xfersize : 7;
23625 + unsigned reserved7_18 : 12;
23626 + /** Packet Count */
23627 + unsigned pktcnt : 1;
23629 + unsigned reserved20_28 : 9;
23630 + /**Setup Packet Count (DOEPTSIZ0 Only) */
23631 + unsigned supcnt : 2;
23632 + unsigned reserved31;
23634 +} deptsiz0_data_t;
23637 +/////////////////////////////////////////////////
23638 +// DMA Descriptor Specific Structures
23641 +/** Buffer status definitions */
23643 +#define BS_HOST_READY 0x0
23644 +#define BS_DMA_BUSY 0x1
23645 +#define BS_DMA_DONE 0x2
23646 +#define BS_HOST_BUSY 0x3
23648 +/** Receive/Transmit status definitions */
23650 +#define RTS_SUCCESS 0x0
23651 +#define RTS_BUFFLUSH 0x1
23652 +#define RTS_RESERVED 0x2
23653 +#define RTS_BUFERR 0x3
23657 + * This union represents the bit fields in the DMA Descriptor
23658 + * status quadlet. Read the quadlet into the <i>d32</i> member then
23659 + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
23660 + * <i>b_iso_in</i> elements.
23662 +typedef union desc_sts_data
23664 + /** raw register data */
23666 + /** quadlet bits */
23668 + /** Received number of bytes */
23669 + unsigned bytes : 16;
23671 + unsigned reserved16_22 : 7;
23672 + /** Multiple Transfer - only for OUT EPs */
23673 + unsigned mtrf : 1;
23674 + /** Setup Packet received - only for OUT EPs */
23676 + /** Interrupt On Complete */
23677 + unsigned ioc : 1;
23678 + /** Short Packet */
23682 + /** Receive Status */
23683 + unsigned sts : 2;
23684 + /** Buffer Status */
23688 +#ifdef DWC_EN_ISOC
23689 + /** iso out quadlet bits */
23691 + /** Received number of bytes */
23692 + unsigned rxbytes : 11;
23694 + unsigned reserved11 : 1;
23695 + /** Frame Number */
23696 + unsigned framenum : 11;
23697 + /** Received ISO Data PID */
23698 + unsigned pid : 2;
23699 + /** Interrupt On Complete */
23700 + unsigned ioc : 1;
23701 + /** Short Packet */
23705 + /** Receive Status */
23706 + unsigned rxsts : 2;
23707 + /** Buffer Status */
23711 + /** iso in quadlet bits */
23713 + /** Transmited number of bytes */
23714 + unsigned txbytes : 12;
23715 + /** Frame Number */
23716 + unsigned framenum : 11;
23717 + /** Transmited ISO Data PID */
23718 + unsigned pid : 2;
23719 + /** Interrupt On Complete */
23720 + unsigned ioc : 1;
23721 + /** Short Packet */
23725 + /** Transmit Status */
23726 + unsigned txsts : 2;
23727 + /** Buffer Status */
23730 +#endif //DWC_EN_ISOC
23731 +} desc_sts_data_t;
23734 + * DMA Descriptor structure
23736 + * DMA Descriptor structure contains two quadlets:
23737 + * Status quadlet and Data buffer pointer.
23739 +typedef struct dwc_otg_dma_desc
23741 + /** DMA Descriptor status quadlet */
23742 + desc_sts_data_t status;
23743 + /** DMA Descriptor data buffer pointer */
23745 +} dwc_otg_dma_desc_t;
23748 + * The dwc_otg_dev_if structure contains information needed to manage
23749 + * the DWC_otg controller acting in device mode. It represents the
23750 + * programming view of the device-specific aspects of the controller.
23752 +typedef struct dwc_otg_dev_if
23754 + /** Pointer to device Global registers.
23755 + * Device Global Registers starting at offset 800h
23757 + dwc_otg_device_global_regs_t *dev_global_regs;
23758 +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
23761 + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
23763 + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
23764 +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
23765 +#define DWC_EP_REG_OFFSET 0x20
23767 + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
23768 + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
23769 +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
23771 + /* Device configuration information*/
23772 + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
23773 + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
23774 + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
23776 + /** Size of periodic FIFOs (Bytes) */
23777 + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
23779 + /** Size of Tx FIFOs (Bytes) */
23780 + uint16_t tx_fifo_size[MAX_TX_FIFOS];
23782 + /** Thresholding enable flags and length varaiables **/
23783 + uint16_t rx_thr_en;
23784 + uint16_t iso_tx_thr_en;
23785 + uint16_t non_iso_tx_thr_en;
23787 + uint16_t rx_thr_length;
23788 + uint16_t tx_thr_length;
23791 + * Pointers to the DMA Descriptors for EP0 Control
23792 + * transfers (virtual and physical)
23795 + /** 2 descriptors for SETUP packets */
23796 + uint32_t dma_setup_desc_addr[2];
23797 + dwc_otg_dma_desc_t* setup_desc_addr[2];
23799 + /** Pointer to Descriptor with latest SETUP packet */
23800 + dwc_otg_dma_desc_t* psetup;
23802 + /** Index of current SETUP handler descriptor */
23803 + uint32_t setup_desc_index;
23805 + /** Descriptor for Data In or Status In phases */
23806 + uint32_t dma_in_desc_addr;
23807 + dwc_otg_dma_desc_t* in_desc_addr;;
23809 + /** Descriptor for Data Out or Status Out phases */
23810 + uint32_t dma_out_desc_addr;
23811 + dwc_otg_dma_desc_t* out_desc_addr;
23813 +} dwc_otg_dev_if_t;
23818 +/////////////////////////////////////////////////
23819 +// Host Mode Register Structures
23822 + * The Host Global Registers structure defines the size and relative
23823 + * field offsets for the Host Mode Global Registers. Host Global
23824 + * Registers offsets 400h-7FFh.
23826 +typedef struct dwc_otg_host_global_regs
23828 + /** Host Configuration Register. <i>Offset: 400h</i> */
23829 + volatile uint32_t hcfg;
23830 + /** Host Frame Interval Register. <i>Offset: 404h</i> */
23831 + volatile uint32_t hfir;
23832 + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
23833 + volatile uint32_t hfnum;
23834 + /** Reserved. <i>Offset: 40Ch</i> */
23835 + uint32_t reserved40C;
23836 + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
23837 + volatile uint32_t hptxsts;
23838 + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
23839 + volatile uint32_t haint;
23840 + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
23841 + volatile uint32_t haintmsk;
23842 +} dwc_otg_host_global_regs_t;
23845 + * This union represents the bit fields in the Host Configuration Register.
23846 + * Read the register into the <i>d32</i> member then set/clear the bits using
23847 + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
23849 +typedef union hcfg_data
23851 + /** raw register data */
23854 + /** register bits */
23857 + /** FS/LS Phy Clock Select */
23858 + unsigned fslspclksel : 2;
23859 +#define DWC_HCFG_30_60_MHZ 0
23860 +#define DWC_HCFG_48_MHZ 1
23861 +#define DWC_HCFG_6_MHZ 2
23863 + /** FS/LS Only Support */
23864 + unsigned fslssupp : 1;
23869 + * This union represents the bit fields in the Host Frame Remaing/Number
23872 +typedef union hfir_data
23874 + /** raw register data */
23877 + /** register bits */
23880 + unsigned frint : 16;
23881 + unsigned reserved : 16;
23886 + * This union represents the bit fields in the Host Frame Remaing/Number
23889 +typedef union hfnum_data
23891 + /** raw register data */
23894 + /** register bits */
23897 + unsigned frnum : 16;
23898 +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
23899 + unsigned frrem : 16;
23903 +typedef union hptxsts_data
23905 + /** raw register data */
23908 + /** register bits */
23911 + unsigned ptxfspcavail : 16;
23912 + unsigned ptxqspcavail : 8;
23913 + /** Top of the Periodic Transmit Request Queue
23914 + * - bit 24 - Terminate (last entry for the selected channel)
23915 + * - bits 26:25 - Token Type
23916 + * - 2'b00 - Zero length
23918 + * - 2'b10 - Disable
23919 + * - bits 30:27 - Channel Number
23920 + * - bit 31 - Odd/even microframe
23922 + unsigned ptxqtop_terminate : 1;
23923 + unsigned ptxqtop_token : 2;
23924 + unsigned ptxqtop_chnum : 4;
23925 + unsigned ptxqtop_odd : 1;
23930 + * This union represents the bit fields in the Host Port Control and Status
23931 + * Register. Read the register into the <i>d32</i> member then set/clear the
23932 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
23933 + * hprt0 register.
23935 +typedef union hprt0_data
23937 + /** raw register data */
23939 + /** register bits */
23942 + unsigned prtconnsts : 1;
23943 + unsigned prtconndet : 1;
23944 + unsigned prtena : 1;
23945 + unsigned prtenchng : 1;
23946 + unsigned prtovrcurract : 1;
23947 + unsigned prtovrcurrchng : 1;
23948 + unsigned prtres : 1;
23949 + unsigned prtsusp : 1;
23950 + unsigned prtrst : 1;
23951 + unsigned reserved9 : 1;
23952 + unsigned prtlnsts : 2;
23953 + unsigned prtpwr : 1;
23954 + unsigned prttstctl : 4;
23955 + unsigned prtspd : 2;
23956 +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
23957 +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
23958 +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
23959 + unsigned reserved19_31 : 13;
23964 + * This union represents the bit fields in the Host All Interrupt
23967 +typedef union haint_data
23969 + /** raw register data */
23971 + /** register bits */
23974 + unsigned ch0 : 1;
23975 + unsigned ch1 : 1;
23976 + unsigned ch2 : 1;
23977 + unsigned ch3 : 1;
23978 + unsigned ch4 : 1;
23979 + unsigned ch5 : 1;
23980 + unsigned ch6 : 1;
23981 + unsigned ch7 : 1;
23982 + unsigned ch8 : 1;
23983 + unsigned ch9 : 1;
23984 + unsigned ch10 : 1;
23985 + unsigned ch11 : 1;
23986 + unsigned ch12 : 1;
23987 + unsigned ch13 : 1;
23988 + unsigned ch14 : 1;
23989 + unsigned ch15 : 1;
23990 + unsigned reserved : 16;
23995 + unsigned chint : 16;
23996 + unsigned reserved : 16;
24001 + * This union represents the bit fields in the Host All Interrupt
24004 +typedef union haintmsk_data
24006 + /** raw register data */
24008 + /** register bits */
24011 + unsigned ch0 : 1;
24012 + unsigned ch1 : 1;
24013 + unsigned ch2 : 1;
24014 + unsigned ch3 : 1;
24015 + unsigned ch4 : 1;
24016 + unsigned ch5 : 1;
24017 + unsigned ch6 : 1;
24018 + unsigned ch7 : 1;
24019 + unsigned ch8 : 1;
24020 + unsigned ch9 : 1;
24021 + unsigned ch10 : 1;
24022 + unsigned ch11 : 1;
24023 + unsigned ch12 : 1;
24024 + unsigned ch13 : 1;
24025 + unsigned ch14 : 1;
24026 + unsigned ch15 : 1;
24027 + unsigned reserved : 16;
24032 + unsigned chint : 16;
24033 + unsigned reserved : 16;
24035 +} haintmsk_data_t;
24038 + * Host Channel Specific Registers. <i>500h-5FCh</i>
24040 +typedef struct dwc_otg_hc_regs
24042 + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
24043 + volatile uint32_t hcchar;
24044 + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
24045 + volatile uint32_t hcsplt;
24046 + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
24047 + volatile uint32_t hcint;
24048 + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
24049 + volatile uint32_t hcintmsk;
24050 + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
24051 + volatile uint32_t hctsiz;
24052 + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
24053 + volatile uint32_t hcdma;
24054 + /** Reserved. <i>Offset: 500h + (chan_num * 20h) + 18h - 500h + (chan_num * 20h) + 1Ch</i> */
24055 + uint32_t reserved[2];
24056 +} dwc_otg_hc_regs_t;
24059 + * This union represents the bit fields in the Host Channel Characteristics
24060 + * Register. Read the register into the <i>d32</i> member then set/clear the
24061 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
24062 + * hcchar register.
24064 +typedef union hcchar_data
24066 + /** raw register data */
24069 + /** register bits */
24072 + /** Maximum packet size in bytes */
24073 + unsigned mps : 11;
24075 + /** Endpoint number */
24076 + unsigned epnum : 4;
24078 + /** 0: OUT, 1: IN */
24079 + unsigned epdir : 1;
24081 + unsigned reserved : 1;
24083 + /** 0: Full/high speed device, 1: Low speed device */
24084 + unsigned lspddev : 1;
24086 + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
24087 + unsigned eptype : 2;
24089 + /** Packets per frame for periodic transfers. 0 is reserved. */
24090 + unsigned multicnt : 2;
24092 + /** Device address */
24093 + unsigned devaddr : 7;
24096 + * Frame to transmit periodic transaction.
24097 + * 0: even, 1: odd
24099 + unsigned oddfrm : 1;
24101 + /** Channel disable */
24102 + unsigned chdis : 1;
24104 + /** Channel enable */
24105 + unsigned chen : 1;
24109 +typedef union hcsplt_data
24111 + /** raw register data */
24114 + /** register bits */
24117 + /** Port Address */
24118 + unsigned prtaddr : 7;
24120 + /** Hub Address */
24121 + unsigned hubaddr : 7;
24123 + /** Transaction Position */
24124 + unsigned xactpos : 2;
24125 +#define DWC_HCSPLIT_XACTPOS_MID 0
24126 +#define DWC_HCSPLIT_XACTPOS_END 1
24127 +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
24128 +#define DWC_HCSPLIT_XACTPOS_ALL 3
24130 + /** Do Complete Split */
24131 + unsigned compsplt : 1;
24134 + unsigned reserved : 14;
24136 + /** Split Enble */
24137 + unsigned spltena : 1;
24143 + * This union represents the bit fields in the Host All Interrupt
24146 +typedef union hcint_data
24148 + /** raw register data */
24150 + /** register bits */
24153 + /** Transfer Complete */
24154 + unsigned xfercomp : 1;
24155 + /** Channel Halted */
24156 + unsigned chhltd : 1;
24158 + unsigned ahberr : 1;
24159 + /** STALL Response Received */
24160 + unsigned stall : 1;
24161 + /** NAK Response Received */
24162 + unsigned nak : 1;
24163 + /** ACK Response Received */
24164 + unsigned ack : 1;
24165 + /** NYET Response Received */
24166 + unsigned nyet : 1;
24167 + /** Transaction Err */
24168 + unsigned xacterr : 1;
24169 + /** Babble Error */
24170 + unsigned bblerr : 1;
24171 + /** Frame Overrun */
24172 + unsigned frmovrun : 1;
24173 + /** Data Toggle Error */
24174 + unsigned datatglerr : 1;
24176 + unsigned reserved : 21;
24181 + * This union represents the bit fields in the Host Channel Transfer Size
24182 + * Register. Read the register into the <i>d32</i> member then set/clear the
24183 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
24184 + * hcchar register.
24186 +typedef union hctsiz_data
24188 + /** raw register data */
24191 + /** register bits */
24194 + /** Total transfer size in bytes */
24195 + unsigned xfersize : 19;
24197 + /** Data packets to transfer */
24198 + unsigned pktcnt : 10;
24201 + * Packet ID for next data packet
24205 + * 3: MDATA (non-Control), SETUP (Control)
24207 + unsigned pid : 2;
24208 +#define DWC_HCTSIZ_DATA0 0
24209 +#define DWC_HCTSIZ_DATA1 2
24210 +#define DWC_HCTSIZ_DATA2 1
24211 +#define DWC_HCTSIZ_MDATA 3
24212 +#define DWC_HCTSIZ_SETUP 3
24214 + /** Do PING protocol when 1 */
24215 + unsigned dopng : 1;
24220 + * This union represents the bit fields in the Host Channel Interrupt Mask
24221 + * Register. Read the register into the <i>d32</i> member then set/clear the
24222 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
24223 + * hcintmsk register.
24225 +typedef union hcintmsk_data
24227 + /** raw register data */
24230 + /** register bits */
24233 + unsigned xfercompl : 1;
24234 + unsigned chhltd : 1;
24235 + unsigned ahberr : 1;
24236 + unsigned stall : 1;
24237 + unsigned nak : 1;
24238 + unsigned ack : 1;
24239 + unsigned nyet : 1;
24240 + unsigned xacterr : 1;
24241 + unsigned bblerr : 1;
24242 + unsigned frmovrun : 1;
24243 + unsigned datatglerr : 1;
24244 + unsigned reserved : 21;
24246 +} hcintmsk_data_t;
24248 +/** OTG Host Interface Structure.
24250 + * The OTG Host Interface Structure structure contains information
24251 + * needed to manage the DWC_otg controller acting in host mode. It
24252 + * represents the programming view of the host-specific aspects of the
24255 +typedef struct dwc_otg_host_if
24257 + /** Host Global Registers starting at offset 400h.*/
24258 + dwc_otg_host_global_regs_t *host_global_regs;
24259 +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
24261 + /** Host Port 0 Control and Status Register */
24262 + volatile uint32_t *hprt0;
24263 +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
24266 + /** Host Channel Specific Registers at offsets 500h-5FCh. */
24267 + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
24268 +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
24269 +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
24272 + /* Host configuration information */
24273 + /** Number of Host Channels (range: 1-16) */
24274 + uint8_t num_host_channels;
24275 + /** Periodic EPs supported (0: no, 1: yes) */
24276 + uint8_t perio_eps_supported;
24277 + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
24278 + uint16_t perio_tx_fifo_size;
24280 +} dwc_otg_host_if_t;
24284 + * This union represents the bit fields in the Power and Clock Gating Control
24285 + * Register. Read the register into the <i>d32</i> member then set/clear the
24286 + * bits using the <i>b</i>it elements.
24288 +typedef union pcgcctl_data
24290 + /** raw register data */
24293 + /** register bits */
24297 + unsigned stoppclk : 1;
24299 + unsigned gatehclk : 1;
24300 + /** Power Clamp */
24301 + unsigned pwrclmp : 1;
24302 + /** Reset Power Down Modules */
24303 + unsigned rstpdwnmodule : 1;
24304 + /** PHY Suspended */
24305 + unsigned physuspended : 1;
24307 + unsigned reserved : 27;
24313 diff --git a/drivers/usb/dwc_otg/linux/dwc_otg_plat.h b/drivers/usb/dwc_otg/linux/dwc_otg_plat.h
24314 new file mode 100644
24315 index 0000000..618151b
24317 +++ b/drivers/usb/dwc_otg/linux/dwc_otg_plat.h
24319 +/* ==========================================================================
24320 + * $File: //dwh/usb_iip/dev/software/otg/linux/platform/dwc_otg_plat.h $
24321 + * $Revision: 1.2 $
24322 + * $Date: 2008-11-21 05:39:16 $
24323 + * $Change: 1064915 $
24325 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
24326 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
24327 + * otherwise expressly agreed to in writing between Synopsys and you.
24329 + * The Software IS NOT an item of Licensed Software or Licensed Product under
24330 + * any End User Software License Agreement or Agreement for Licensed Product
24331 + * with Synopsys or any supplement thereto. You are permitted to use and
24332 + * redistribute this Software in source and binary forms, with or without
24333 + * modification, provided that redistributions of source code must retain this
24334 + * notice. You may not view, use, disclose, copy or distribute this file or
24335 + * any information contained herein except pursuant to this license grant from
24336 + * Synopsys. If you do not agree with this notice, including the disclaimer
24337 + * below, then you are not authorized to use the Software.
24339 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
24340 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24341 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24342 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
24343 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24344 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24345 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24346 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24347 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24348 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
24350 + * ========================================================================== */
24352 +#if !defined(__DWC_OTG_PLAT_H__)
24353 +#define __DWC_OTG_PLAT_H__
24355 +#include <linux/types.h>
24356 +#include <linux/slab.h>
24357 +#include <linux/list.h>
24358 +#include <linux/delay.h>
24359 +#include <asm/io.h>
24364 + * This file contains the Platform Specific constants, interfaces
24365 + * (functions and macros) for Linux.
24368 +//#if !defined(__LINUX_ARM_ARCH__)
24369 +//#error "The contents of this file is Linux specific!!!"
24373 + * Reads the content of a register.
24375 + * @param reg address of register to read.
24376 + * @return contents of the register.
24380 + * <code>uint32_t dev_ctl = dwc_read_reg32(&dev_regs->dctl);</code>
24382 +static __inline__ uint32_t dwc_read_reg32( volatile uint32_t *reg)
24384 + return readl(reg);
24388 + * Writes a register with a 32 bit value.
24390 + * @param reg address of register to read.
24391 + * @param value to write to _reg.
24394 + * <code>dwc_write_reg32(&dev_regs->dctl, 0); </code>
24396 +static __inline__ void dwc_write_reg32( volatile uint32_t *reg, const uint32_t value)
24398 + writel( value, reg );
24402 + * This function modifies bit values in a register. Using the
24403 + * algorithm: (reg_contents & ~clear_mask) | set_mask.
24405 + * @param reg address of register to read.
24406 + * @param clear_mask bit mask to be cleared.
24407 + * @param set_mask bit mask to be set.
24410 + * <code> // Clear the SOF Interrupt Mask bit and <br>
24411 + * // set the OTG Interrupt mask bit, leaving all others as they were.
24412 + * dwc_modify_reg32(&dev_regs->gintmsk, DWC_SOF_INT, DWC_OTG_INT);</code>
24415 + void dwc_modify_reg32( volatile uint32_t *reg, const uint32_t clear_mask, const uint32_t set_mask)
24417 + writel( (readl(reg) & ~clear_mask) | set_mask, reg );
24422 + * Wrapper for the OS micro-second delay function.
24423 + * @param[in] usecs Microseconds of delay
24425 +static __inline__ void UDELAY( const uint32_t usecs )
24431 + * Wrapper for the OS milli-second delay function.
24432 + * @param[in] msecs milliseconds of delay
24434 +static __inline__ void MDELAY( const uint32_t msecs )
24440 + * Wrapper for the Linux spin_lock. On the ARM (Integrator)
24441 + * spin_lock() is a nop.
24443 + * @param lock Pointer to the spinlock.
24445 +static __inline__ void SPIN_LOCK( spinlock_t *lock )
24451 + * Wrapper for the Linux spin_unlock. On the ARM (Integrator)
24452 + * spin_lock() is a nop.
24454 + * @param lock Pointer to the spinlock.
24456 +static __inline__ void SPIN_UNLOCK( spinlock_t *lock )
24458 + spin_unlock(lock);
24462 + * Wrapper (macro) for the Linux spin_lock_irqsave. On the ARM
24463 + * (Integrator) spin_lock() is a nop.
24465 + * @param l Pointer to the spinlock.
24466 + * @param f unsigned long for irq flags storage.
24468 +#define SPIN_LOCK_IRQSAVE( l, f ) spin_lock_irqsave(l,f);
24471 + * Wrapper (macro) for the Linux spin_unlock_irqrestore. On the ARM
24472 + * (Integrator) spin_lock() is a nop.
24474 + * @param l Pointer to the spinlock.
24475 + * @param f unsigned long for irq flags storage.
24477 +#define SPIN_UNLOCK_IRQRESTORE( l,f ) spin_unlock_irqrestore(l,f);
24480 + * Debugging support vanishes in non-debug builds.
24485 + * The Debug Level bit-mask variable.
24487 +extern uint32_t g_dbg_lvl;
24489 + * Set the Debug Level variable.
24491 +static inline uint32_t SET_DEBUG_LEVEL( const uint32_t new )
24493 + uint32_t old = g_dbg_lvl;
24498 +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
24499 +#define DBG_CIL (0x2)
24500 +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
24502 +#define DBG_CILV (0x20)
24503 +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
24505 +#define DBG_PCD (0x4)
24506 +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
24508 +#define DBG_PCDV (0x40)
24509 +/** When debug level has the DBG_HCD bit set, display Host debug messages */
24510 +#define DBG_HCD (0x8)
24511 +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
24513 +#define DBG_HCDV (0x80)
24514 +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
24516 +#define DBG_HCD_URB (0x800)
24518 +/** When debug level has any bit set, display debug messages */
24519 +#define DBG_ANY (0xFF)
24521 +/** All debug messages off */
24524 +/** Prefix string for DWC_DEBUG print macros. */
24525 +#define USB_DWC "dwc_otg: "
24528 + * Print a debug message when the Global debug level variable contains
24529 + * the bit defined in <code>lvl</code>.
24531 + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
24532 + * @param[in] x - like printf
24536 + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
24539 + * results in:<br>
24541 + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
24546 +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)printk( KERN_DEBUG USB_DWC x ); }while(0)
24547 +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
24549 +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
24553 +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
24554 +# define DWC_DEBUGP(x...)
24556 +# define CHK_DEBUG_LEVEL(level) (0)
24561 + * Print an Error message.
24563 +#define DWC_ERROR(x...) printk( KERN_ERR USB_DWC x )
24565 + * Print a Warning message.
24567 +#define DWC_WARN(x...) printk( KERN_WARNING USB_DWC x )
24569 + * Print a notice (normal but significant message).
24571 +#define DWC_NOTICE(x...) printk( KERN_NOTICE USB_DWC x )
24573 + * Basic message printing.
24575 +#define DWC_PRINT(x...) printk( KERN_INFO USB_DWC x )