1 --- a/drivers/usb/core/Kconfig
2 +++ b/drivers/usb/core/Kconfig
3 @@ -106,11 +106,11 @@ config USB_SUSPEND
5 If you are unsure about this, say N here.
9 - depends on USB && EXPERIMENTAL
14 +# depends on USB && EXPERIMENTAL
19 config USB_OTG_WHITELIST
20 --- a/drivers/usb/core/urb.c
21 +++ b/drivers/usb/core/urb.c
22 @@ -17,7 +17,11 @@ static void urb_destroy(struct kref *kre
24 if (urb->transfer_flags & URB_FREE_BUFFER)
25 kfree(urb->transfer_buffer);
27 + if(urb->aligned_transfer_buffer){
28 + kfree(urb->aligned_transfer_buffer);
29 + urb->aligned_transfer_buffer=0;
30 + urb->aligned_transfer_dma=0;
35 @@ -91,6 +95,7 @@ void usb_free_urb(struct urb *urb)
38 kref_put(&urb->kref, urb_destroy);
41 EXPORT_SYMBOL_GPL(usb_free_urb);
43 --- a/drivers/usb/gadget/file_storage.c
44 +++ b/drivers/usb/gadget/file_storage.c
46 * of the Gadget, USB Mass Storage, and SCSI protocols.
50 -/* #define VERBOSE_DEBUG */
51 -/* #define DUMP_MSGS */
53 +#define VERBOSE_DEBUG
57 #include <linux/blkdev.h>
58 @@ -3086,7 +3086,9 @@ static int received_cbw(struct fsg_dev *
59 if (req->actual != USB_BULK_CB_WRAP_LEN ||
60 cbw->Signature != cpu_to_le32(
62 - DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
63 + DBG(fsg, "invalid CBW: bh %.8x buf %.8x len %u sig 0x%x\n",
67 le32_to_cpu(cbw->Signature));
69 @@ -4097,6 +4099,7 @@ static int __init fsg_bind(struct usb_ga
70 * the buffer will also work with the bulk-out (and
71 * interrupt-in) endpoint. */
72 bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
73 + VDBG(fsg,"%s: %d, bh=%.8x, buf=%.8x\n",__func__,i,bh,bh->buf);
77 --- a/drivers/usb/gadget/Kconfig
78 +++ b/drivers/usb/gadget/Kconfig
79 @@ -495,6 +495,16 @@ config USB_LANGWELL
81 select USB_GADGET_SELECTED
83 +config USB_GADGET_CNS3XXX_OTG
84 + boolean "CNS3XXX peripheral controller"
85 + depends on USB_CNS3XXX_OTG_BOTH || USB_CNS3XXX_OTG_PCD_ONLY
87 + select USB_GADGET_DUALSPEED
88 + select USB_GADGET_SELECTED
89 + select USB_GADGET_SNPS_DWC_OTG
91 + Selects the CNS3XXX Perpheral Controller driver
95 # LAST -- dummy/emulated controller
97 +++ b/drivers/usb/host/ehci-cns3xxx.c
100 +#include <linux/platform_device.h>
101 +#include <mach/board.h>
102 +#include <mach/pm.h>
104 +#define cns3xxx_ioremap ioremap
105 +#define cns3xxx_iounmap(addr) iounmap
107 +static int cns3xxx_ehci_init(struct usb_hcd *hcd)
109 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
112 + printk("%s: !!WARNING!! to verify the following ehci->caps ehci->regs \n",
114 +#ifdef CONFIG_SILICON
116 + //cns3xxx_pwr_power_up(1<<PM_PLL_HM_PD_CTRL_REG_OFFSET_USB_PHY0);
118 + //cns3xxx_pwr_power_up(1<<PM_PLL_HM_PD_CTRL_REG_OFFSET_USB_PHY1);
119 + cns3xxx_pwr_power_up(1<<PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
120 + cns3xxx_pwr_clk_en(1<<PM_CLK_GATE_REG_OFFSET_USB_HOST);
121 + cns3xxx_pwr_soft_rst(1<<PM_SOFT_RST_REG_OFFST_USB_HOST);
122 + //cns3xxx_pwr_clk_en(1<<PM_CLK_GATE_REG_OFFSET_USB_OTG);
123 + //cns3xxx_pwr_soft_rst(1<<PM_SOFT_RST_REG_OFFST_USB_OTG);
124 +#endif //CONFIG_SILICON
126 + ehci->caps = hcd->regs;
127 + ehci->regs = hcd->regs
128 + + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
129 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
134 + retval = ehci_init(hcd);
138 + /* XXX: Only for FPGA, remove it later */
139 + ehci_writel(ehci, 0x00800080, hcd->regs + 0x94);
141 + ehci_port_power(ehci, 0);
146 +static const struct hc_driver cns3xxx_ehci_hc_driver = {
147 + .description = hcd_name,
148 + .product_desc = "CNS3XXX EHCI Host Controller",
149 + .hcd_priv_size = sizeof(struct ehci_hcd),
151 + .flags = HCD_MEMORY | HCD_USB2,
152 + .reset = cns3xxx_ehci_init,
155 + .shutdown = ehci_shutdown,
156 + .urb_enqueue = ehci_urb_enqueue,
157 + .urb_dequeue = ehci_urb_dequeue,
158 + .endpoint_disable = ehci_endpoint_disable,
159 + .get_frame_number = ehci_get_frame,
160 + .hub_status_data = ehci_hub_status_data,
161 + .hub_control = ehci_hub_control,
162 +#if defined(CONFIG_PM)
163 + .bus_suspend = ehci_bus_suspend,
164 + .bus_resume = ehci_bus_resume,
166 + .relinquish_port = ehci_relinquish_port,
167 + .port_handed_over = ehci_port_handed_over,
170 +static int cns3xxx_ehci_probe(struct platform_device *pdev)
172 + struct usb_hcd *hcd;
173 + const struct hc_driver *driver = &cns3xxx_ehci_hc_driver;
174 + struct resource *res;
178 + if (usb_disabled())
181 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
183 + dev_err(&pdev->dev,
184 + "Found HC with no IRQ. Check %s setup!\n",
185 + dev_name(&pdev->dev));
190 + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
193 + goto fail_create_hcd;
196 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
198 + dev_err(&pdev->dev,
199 + "Found HC with no register addr. Check %s setup!\n",
200 + dev_name(&pdev->dev));
202 + goto fail_request_resource;
204 + hcd->rsrc_start = res->start;
205 + hcd->rsrc_len = res->end - res->start + 1;
207 +#ifdef CNS3XXX_USB_BASE_VIRT
208 + hcd->regs = (void __iomem *) CNS3XXX_USB_BASE_VIRT;
210 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
211 + driver->description)) {
212 + dev_dbg(&pdev->dev, "controller already in use\n");
214 + goto fail_request_resource;
217 + hcd->regs = cns3xxx_ioremap(hcd->rsrc_start, hcd->rsrc_len);
219 + if (hcd->regs == NULL) {
220 + dev_dbg(&pdev->dev, "error mapping memory\n");
226 + retval = usb_add_hcd(hcd, irq, IRQF_SHARED); /* TODO: IRQF_DISABLED if any interrupt issues */
232 +#ifndef CNS3XXX_USB_BASE_VIRT
234 + cns3xxx_iounmap(hcd->regs);
236 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
238 +fail_request_resource:
243 + dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
247 +static int cns3xxx_ehci_remove(struct platform_device *pdev)
249 + struct usb_hcd *hcd = platform_get_drvdata(pdev);
251 + usb_remove_hcd(hcd);
252 +#ifndef CNS3XXX_USB_BASE_VIRT
253 + cns3xxx_iounmap(hcd->regs);
254 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
261 +MODULE_ALIAS("platform:cns3xxx-ehci");
263 +static struct platform_driver cns3xxx_ehci_driver = {
264 + .probe = cns3xxx_ehci_probe,
265 + .remove = cns3xxx_ehci_remove,
267 + .name = "cns3xxx-ehci",
270 --- a/drivers/usb/host/ehci.h
271 +++ b/drivers/usb/host/ehci.h
272 @@ -602,6 +602,13 @@ ehci_port_speed(struct ehci_hcd *ehci, u
273 #define writel_be(val, addr) __raw_writel(val, (__force unsigned *)addr)
276 +#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_CNS3XXX)
279 +#define readl(addr) __raw_readl((__force unsigned *)addr)
280 +#define writel(val, addr) __raw_writel(val, (__force unsigned *)addr)
283 static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
284 __u32 __iomem * regs)
286 --- a/drivers/usb/host/ehci-hcd.c
287 +++ b/drivers/usb/host/ehci-hcd.c
288 @@ -1120,6 +1120,11 @@ MODULE_LICENSE ("GPL");
289 #define PLATFORM_DRIVER ixp4xx_ehci_driver
292 +#ifdef CONFIG_USB_CNS3XXX_EHCI
293 +#include "ehci-cns3xxx.c"
294 +#define PLATFORM_DRIVER cns3xxx_ehci_driver
297 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
298 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
299 #error "missing bus glue for ehci-hcd"
300 --- a/drivers/usb/host/Kconfig
301 +++ b/drivers/usb/host/Kconfig
302 @@ -153,6 +153,45 @@ config USB_ISP1760_HCD
303 To compile this driver as a module, choose M here: the
304 module will be called isp1760.
306 +config USB_CNS3XXX_EHCI
307 + bool "Cavium CNS3XXX EHCI Module"
308 + depends on USB && USB_EHCI_HCD
310 + Cavium CNS3XXX USB EHCI Chipset support
312 +config USB_CNS3XXX_OTG
313 + tristate "Cavium CNS3XXX OTG Module"
316 + Cavium CNS3XXX USB OTG Chipset support
319 + prompt "OTG function includes"
320 + depends on USB_CNS3XXX_OTG
321 + default USB_CNS3XXX_OTG_BOTH
323 +config USB_CNS3XXX_OTG_BOTH
324 + bool "both HCD and PCD"
326 +config USB_CNS3XXX_OTG_HCD_ONLY
329 +config USB_CNS3XXX_OTG_PCD_ONLY
333 +config USB_CNS3XXX_OTG_ENABLE_OTG_DRVVBUS
334 + bool "Enable OTG_DRVVBUS"
335 + depends on USB_CNS3XXX_OTG
338 + The Power control IC (FB6862B), which is located around the OTG mini
339 + USB type A/B receptacle, in some early EVB board v1.0/v1.1(#1~#22) is
340 + incorrect(FB6862A), and need to be patched so that VBUS can be applied
341 + properly. In that case, we don't use the OTG_DRVVBUS to control the VBUS.
343 + Check the board that you are using, if the IC is FB6862B, say Y. Otherwise, say N.
346 tristate "OHCI HCD support"
347 depends on USB && USB_ARCH_HAS_OHCI
348 @@ -225,6 +264,12 @@ config USB_OHCI_HCD_SSB
352 +config USB_CNS3XXX_OHCI
353 + bool "Cavium CNS3XXX OHCI Module"
354 + depends on USB_OHCI_HCD
356 + Cavium CNS3XXX USB OHCI Chipset support
358 config USB_OHCI_BIG_ENDIAN_DESC
360 depends on USB_OHCI_HCD
361 --- a/drivers/usb/host/Makefile
362 +++ b/drivers/usb/host/Makefile
363 @@ -31,3 +31,6 @@ obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o
364 obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
365 obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
366 obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
367 +obj-$(CONFIG_USB_CNS3XXX_OTG) += otg/
368 +obj-$(CONFIG_USB_GADGET_CNS3XXX_OTG) += otg/
371 +++ b/drivers/usb/host/ohci-cns3xxx.c
374 +#include <linux/platform_device.h>
375 +#include <mach/board.h>
377 +#define cns3xxx_ioremap ioremap
378 +#define cns3xxx_iounmap(addr) iounmap
380 +static int __devinit
381 +cns3xxx_ohci_start (struct usb_hcd *hcd)
383 + struct ohci_hcd *ohci = hcd_to_ohci (hcd);
386 + if ((ret = ohci_init(ohci)) < 0)
389 + ohci->num_ports = 1;
391 + if ((ret = ohci_run(ohci)) < 0) {
392 + err("can't start %s", hcd->self.bus_name);
399 +static const struct hc_driver cns3xxx_ohci_hc_driver = {
400 + .description = hcd_name,
401 + .product_desc = "CNS3XXX OHCI Host controller",
402 + .hcd_priv_size = sizeof(struct ohci_hcd),
404 + .flags = HCD_USB11 | HCD_MEMORY,
405 + .start = cns3xxx_ohci_start,
407 + .shutdown = ohci_shutdown,
408 + .urb_enqueue = ohci_urb_enqueue,
409 + .urb_dequeue = ohci_urb_dequeue,
410 + .endpoint_disable = ohci_endpoint_disable,
411 + .get_frame_number = ohci_get_frame,
412 + .hub_status_data = ohci_hub_status_data,
413 + .hub_control = ohci_hub_control,
415 + .bus_suspend = ohci_bus_suspend,
416 + .bus_resume = ohci_bus_resume,
418 + .start_port_reset = ohci_start_port_reset,
421 +static int cns3xxx_ohci_probe(struct platform_device *pdev)
423 + struct usb_hcd *hcd = NULL;
424 + const struct hc_driver *driver = &cns3xxx_ohci_hc_driver;
425 + struct resource *res;
429 + if (usb_disabled())
432 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
434 + dev_err(&pdev->dev,
435 + "Found HC with no IRQ. Check %s setup!\n",
436 + dev_name(&pdev->dev));
441 + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
445 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
447 + dev_err(&pdev->dev,
448 + "Found HC with no register addr. Check %s setup!\n",
449 + dev_name(&pdev->dev));
453 + hcd->rsrc_start = res->start;
454 + hcd->rsrc_len = res->end - res->start + 1;
456 +#ifdef CNS3XXX_USB_OHCI_BASE_VIRT
457 + hcd->regs = (void __iomem *) CNS3XXX_USB_OHCI_BASE_VIRT;
459 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
460 + driver->description)) {
461 + dev_dbg(&pdev->dev, "controller already in use\n");
466 + hcd->regs = cns3xxx_ioremap(hcd->rsrc_start, hcd->rsrc_len);
468 + if (hcd->regs == NULL) {
469 + dev_dbg(&pdev->dev, "error mapping memory\n");
475 + ohci_hcd_init(hcd_to_ohci(hcd));
477 + retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
481 +#ifndef CNS3XXX_USB_OHCI_BASE_VIRT
482 + cns3xxx_iounmap(hcd->regs);
485 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
493 +static int cns3xxx_ohci_remove(struct platform_device *pdev)
495 + struct usb_hcd *hcd = platform_get_drvdata(pdev);
497 + usb_remove_hcd(hcd);
498 +#ifndef CNS3XXX_USB_OHCI_BASE_VIRT
499 + cns3xxx_iounmap(hcd->regs);
500 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
507 +MODULE_ALIAS("platform:cns3xxx-ohci");
509 +static struct platform_driver ohci_hcd_cns3xxx_driver = {
510 + .probe = cns3xxx_ohci_probe,
511 + .remove = cns3xxx_ohci_remove,
513 + .name = "cns3xxx-ohci",
516 --- a/drivers/usb/host/ohci.h
517 +++ b/drivers/usb/host/ohci.h
518 @@ -550,6 +550,14 @@ static inline struct usb_hcd *ohci_to_hc
519 * Other arches can be added if/when they're needed.
523 +#if defined(CONFIG_ARM) && defined(CONFIG_ARCH_CNS3XXX)
526 +#define readl(addr) __raw_readl((__force unsigned *)addr)
527 +#define writel(val, addr) __raw_writel(val, (__force unsigned *)addr)
530 static inline unsigned int _ohci_readl (const struct ohci_hcd *ohci,
531 __hc32 __iomem * regs)
533 --- a/drivers/usb/host/ohci-hcd.c
534 +++ b/drivers/usb/host/ohci-hcd.c
535 @@ -1047,6 +1047,11 @@ MODULE_LICENSE ("GPL");
536 #define PLATFORM_DRIVER ohci_hcd_at91_driver
539 +#ifdef CONFIG_USB_CNS3XXX_OHCI
540 +#include "ohci-cns3xxx.c"
541 +#define PLATFORM_DRIVER ohci_hcd_cns3xxx_driver
544 #ifdef CONFIG_ARCH_PNX4008
545 #include "ohci-pnx4008.c"
546 #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
548 +++ b/drivers/usb/host/otg/dummy_audio.c
551 + * zero.c -- Gadget Zero, for USB development
553 + * Copyright (C) 2003-2004 David Brownell
554 + * All rights reserved.
556 + * Redistribution and use in source and binary forms, with or without
557 + * modification, are permitted provided that the following conditions
559 + * 1. Redistributions of source code must retain the above copyright
560 + * notice, this list of conditions, and the following disclaimer,
561 + * without modification.
562 + * 2. Redistributions in binary form must reproduce the above copyright
563 + * notice, this list of conditions and the following disclaimer in the
564 + * documentation and/or other materials provided with the distribution.
565 + * 3. The names of the above-listed copyright holders may not be used
566 + * to endorse or promote products derived from this software without
567 + * specific prior written permission.
569 + * ALTERNATIVELY, this software may be distributed under the terms of the
570 + * GNU General Public License ("GPL") as published by the Free Software
571 + * Foundation, either version 2 of that License or (at your option) any
574 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
575 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
576 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
577 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
578 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
579 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
580 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
581 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
582 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
583 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
584 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
589 + * Gadget Zero only needs two bulk endpoints, and is an example of how you
590 + * can write a hardware-agnostic gadget driver running inside a USB device.
592 + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
593 + * affect most of the driver.
595 + * Use it with the Linux host/master side "usbtest" driver to get a basic
596 + * functional test of your device-side usb stack, or with "usb-skeleton".
598 + * It supports two similar configurations. One sinks whatever the usb host
599 + * writes, and in return sources zeroes. The other loops whatever the host
600 + * writes back, so the host can read it. Module options include:
602 + * buflen=N default N=4096, buffer size used
603 + * qlen=N default N=32, how many buffers in the loopback queue
604 + * loopdefault default false, list loopback config first
606 + * Many drivers will only have one configuration, letting them be much
607 + * simpler if they also don't support high speed operation (like this
611 +#include <linux/config.h>
612 +#include <linux/module.h>
613 +#include <linux/kernel.h>
614 +#include <linux/delay.h>
615 +#include <linux/ioport.h>
616 +#include <linux/sched.h>
617 +#include <linux/slab.h>
618 +#include <linux/smp_lock.h>
619 +#include <linux/errno.h>
620 +#include <linux/init.h>
621 +#include <linux/timer.h>
622 +#include <linux/list.h>
623 +#include <linux/interrupt.h>
624 +#include <linux/uts.h>
625 +#include <linux/version.h>
626 +#include <linux/device.h>
627 +#include <linux/moduleparam.h>
628 +#include <linux/proc_fs.h>
630 +#include <asm/byteorder.h>
632 +#include <asm/irq.h>
633 +#include <asm/system.h>
634 +#include <asm/unaligned.h>
636 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
637 +# include <linux/usb/ch9.h>
639 +# include <linux/usb_ch9.h>
642 +#include <linux/usb_gadget.h>
645 +/*-------------------------------------------------------------------------*/
646 +/*-------------------------------------------------------------------------*/
649 +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
655 + /* this insists on correct encodings, though not minimal ones.
656 + * BUT it currently rejects legit 4-byte UTF-8 code points,
657 + * which need surrogate pairs. (Unicode 3.1 can use them.)
659 + while (len != 0 && (c = (u8) *s++) != 0) {
660 + if (unlikely(c & 0x80)) {
661 + // 2-byte sequence:
662 + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
663 + if ((c & 0xe0) == 0xc0) {
664 + uchar = (c & 0x1f) << 6;
667 + if ((c & 0xc0) != 0xc0)
672 + // 3-byte sequence (most CJKV characters):
673 + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
674 + } else if ((c & 0xf0) == 0xe0) {
675 + uchar = (c & 0x0f) << 12;
678 + if ((c & 0xc0) != 0xc0)
684 + if ((c & 0xc0) != 0xc0)
689 + /* no bogus surrogates */
690 + if (0xd800 <= uchar && uchar <= 0xdfff)
693 + // 4-byte sequence (surrogate pairs, currently rare):
694 + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
695 + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
696 + // (uuuuu = wwww + 1)
697 + // FIXME accept the surrogate code points (only)
703 + put_unaligned (cpu_to_le16 (uchar), cp++);
714 + * usb_gadget_get_string - fill out a string descriptor
715 + * @table: of c strings encoded using UTF-8
716 + * @id: string id, from low byte of wValue in get string descriptor
717 + * @buf: at least 256 bytes
719 + * Finds the UTF-8 string matching the ID, and converts it into a
720 + * string descriptor in utf16-le.
721 + * Returns length of descriptor (always even) or negative errno
723 + * If your driver needs stings in multiple languages, you'll probably
724 + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
725 + * using this routine after choosing which set of UTF-8 strings to use.
726 + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
727 + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
728 + * characters (which are also widely used in C strings).
731 +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
733 + struct usb_string *s;
736 + /* descriptor 0 has the language id */
739 + buf [1] = USB_DT_STRING;
740 + buf [2] = (u8) table->language;
741 + buf [3] = (u8) (table->language >> 8);
744 + for (s = table->strings; s && s->s; s++)
748 + /* unrecognized: stall. */
752 + /* string descriptors have length, tag, then UTF16-LE text */
753 + len = min ((size_t) 126, strlen (s->s));
754 + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
755 + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
758 + buf [0] = (len + 1) * 2;
759 + buf [1] = USB_DT_STRING;
764 +/*-------------------------------------------------------------------------*/
765 +/*-------------------------------------------------------------------------*/
769 + * usb_descriptor_fillbuf - fill buffer with descriptors
770 + * @buf: Buffer to be filled
771 + * @buflen: Size of buf
772 + * @src: Array of descriptor pointers, terminated by null pointer.
774 + * Copies descriptors into the buffer, returning the length or a
775 + * negative error code if they can't all be copied. Useful when
776 + * assembling descriptors for an associated set of interfaces used
777 + * as part of configuring a composite device; or in other cases where
778 + * sets of descriptors need to be marshaled.
781 +usb_descriptor_fillbuf(void *buf, unsigned buflen,
782 + const struct usb_descriptor_header **src)
789 + /* fill buffer from src[] until null descriptor ptr */
790 + for (; 0 != *src; src++) {
791 + unsigned len = (*src)->bLength;
795 + memcpy(dest, *src, len);
799 + return dest - (u8 *)buf;
804 + * usb_gadget_config_buf - builts a complete configuration descriptor
805 + * @config: Header for the descriptor, including characteristics such
806 + * as power requirements and number of interfaces.
807 + * @desc: Null-terminated vector of pointers to the descriptors (interface,
808 + * endpoint, etc) defining all functions in this device configuration.
809 + * @buf: Buffer for the resulting configuration descriptor.
810 + * @length: Length of buffer. If this is not big enough to hold the
811 + * entire configuration descriptor, an error code will be returned.
813 + * This copies descriptors into the response buffer, building a descriptor
814 + * for that configuration. It returns the buffer length or a negative
815 + * status code. The config.wTotalLength field is set to match the length
816 + * of the result, but other descriptor fields (including power usage and
817 + * interface count) must be set by the caller.
819 + * Gadget drivers could use this when constructing a config descriptor
820 + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
821 + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
823 +int usb_gadget_config_buf(
824 + const struct usb_config_descriptor *config,
827 + const struct usb_descriptor_header **desc
830 + struct usb_config_descriptor *cp = buf;
833 + /* config descriptor first */
834 + if (length < USB_DT_CONFIG_SIZE || !desc)
838 + /* then interface/endpoint/class/vendor/... */
839 + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
840 + length - USB_DT_CONFIG_SIZE, desc);
843 + len += USB_DT_CONFIG_SIZE;
847 + /* patch up the config descriptor */
848 + cp->bLength = USB_DT_CONFIG_SIZE;
849 + cp->bDescriptorType = USB_DT_CONFIG;
850 + cp->wTotalLength = cpu_to_le16(len);
851 + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
855 +/*-------------------------------------------------------------------------*/
856 +/*-------------------------------------------------------------------------*/
859 +#define RBUF_LEN (1024*1024)
860 +static int rbuf_start;
861 +static int rbuf_len;
862 +static __u8 rbuf[RBUF_LEN];
864 +/*-------------------------------------------------------------------------*/
866 +#define DRIVER_VERSION "St Patrick's Day 2004"
868 +static const char shortname [] = "zero";
869 +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
871 +static const char source_sink [] = "source and sink data";
872 +static const char loopback [] = "loop input to output";
874 +/*-------------------------------------------------------------------------*/
877 + * driver assumes self-powered hardware, and
878 + * has no way for users to trigger remote wakeup.
880 + * this version autoconfigures as much as possible,
881 + * which is reasonable for most "bulk-only" drivers.
883 +static const char *EP_IN_NAME; /* source */
884 +static const char *EP_OUT_NAME; /* sink */
886 +/*-------------------------------------------------------------------------*/
888 +/* big enough to hold our biggest descriptor */
889 +#define USB_BUFSIZ 512
893 + struct usb_gadget *gadget;
894 + struct usb_request *req; /* for control responses */
896 + /* when configured, we have one of two configs:
897 + * - source data (in to host) and sink it (out from host)
898 + * - or loop it back (out from host back in to host)
901 + struct usb_ep *in_ep, *out_ep;
903 + /* autoresume timer */
904 + struct timer_list resume;
907 +#define xprintk(d,level,fmt,args...) \
908 + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
911 +#define DBG(dev,fmt,args...) \
912 + xprintk(dev , KERN_DEBUG , fmt , ## args)
914 +#define DBG(dev,fmt,args...) \
921 +#define VDBG(dev,fmt,args...) \
923 +#endif /* VERBOSE */
925 +#define ERROR(dev,fmt,args...) \
926 + xprintk(dev , KERN_ERR , fmt , ## args)
927 +#define WARN(dev,fmt,args...) \
928 + xprintk(dev , KERN_WARNING , fmt , ## args)
929 +#define INFO(dev,fmt,args...) \
930 + xprintk(dev , KERN_INFO , fmt , ## args)
932 +/*-------------------------------------------------------------------------*/
934 +static unsigned buflen = 4096;
935 +static unsigned qlen = 32;
936 +static unsigned pattern = 0;
938 +module_param (buflen, uint, S_IRUGO|S_IWUSR);
939 +module_param (qlen, uint, S_IRUGO|S_IWUSR);
940 +module_param (pattern, uint, S_IRUGO|S_IWUSR);
943 + * if it's nonzero, autoresume says how many seconds to wait
944 + * before trying to wake up the host after suspend.
946 +static unsigned autoresume = 0;
947 +module_param (autoresume, uint, 0);
950 + * Normally the "loopback" configuration is second (index 1) so
951 + * it's not the default. Here's where to change that order, to
952 + * work better with hosts where config changes are problematic.
953 + * Or controllers (like superh) that only support one config.
955 +static int loopdefault = 0;
957 +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
959 +/*-------------------------------------------------------------------------*/
961 +/* Thanks to NetChip Technologies for donating this product ID.
963 + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
964 + * Instead: allocate your own, using normal USB-IF procedures.
966 +#ifndef CONFIG_USB_ZERO_HNPTEST
967 +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
968 +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
970 +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
971 +#define DRIVER_PRODUCT_NUM 0xbadd
974 +/*-------------------------------------------------------------------------*/
977 + * DESCRIPTORS ... most are static, but strings and (full)
978 + * configuration descriptors are built on demand.
982 +#define STRING_MANUFACTURER 25
983 +#define STRING_PRODUCT 42
984 +#define STRING_SERIAL 101
986 +#define STRING_MANUFACTURER 1
987 +#define STRING_PRODUCT 2
988 +#define STRING_SERIAL 3
990 +#define STRING_SOURCE_SINK 250
991 +#define STRING_LOOPBACK 251
994 + * This device advertises two configurations; these numbers work
995 + * on a pxa250 as well as more flexible hardware.
997 +#define CONFIG_SOURCE_SINK 3
998 +#define CONFIG_LOOPBACK 2
1001 +static struct usb_device_descriptor
1003 + .bLength = sizeof device_desc,
1004 + .bDescriptorType = USB_DT_DEVICE,
1006 + .bcdUSB = __constant_cpu_to_le16 (0x0200),
1007 + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
1009 + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
1010 + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
1011 + .iManufacturer = STRING_MANUFACTURER,
1012 + .iProduct = STRING_PRODUCT,
1013 + .iSerialNumber = STRING_SERIAL,
1014 + .bNumConfigurations = 2,
1017 +static struct usb_device_descriptor
1019 + .bLength = sizeof device_desc,
1020 + .bDescriptorType = USB_DT_DEVICE,
1021 + .bcdUSB = __constant_cpu_to_le16 (0x0100),
1022 + .bDeviceClass = USB_CLASS_PER_INTERFACE,
1023 + .bDeviceSubClass = 0,
1024 + .bDeviceProtocol = 0,
1025 + .bMaxPacketSize0 = 64,
1026 + .bcdDevice = __constant_cpu_to_le16 (0x0100),
1027 + .idVendor = __constant_cpu_to_le16 (0x0499),
1028 + .idProduct = __constant_cpu_to_le16 (0x3002),
1029 + .iManufacturer = STRING_MANUFACTURER,
1030 + .iProduct = STRING_PRODUCT,
1031 + .iSerialNumber = STRING_SERIAL,
1032 + .bNumConfigurations = 1,
1035 +static struct usb_config_descriptor
1037 + .bLength = sizeof z_config,
1038 + .bDescriptorType = USB_DT_CONFIG,
1040 + /* compute wTotalLength on the fly */
1041 + .bNumInterfaces = 2,
1042 + .bConfigurationValue = 1,
1043 + .iConfiguration = 0,
1044 + .bmAttributes = 0x40,
1045 + .bMaxPower = 0, /* self-powered */
1049 +static struct usb_otg_descriptor
1051 + .bLength = sizeof otg_descriptor,
1052 + .bDescriptorType = USB_DT_OTG,
1054 + .bmAttributes = USB_OTG_SRP,
1057 +/* one interface in each configuration */
1058 +#ifdef CONFIG_USB_GADGET_DUALSPEED
1061 + * usb 2.0 devices need to expose both high speed and full speed
1062 + * descriptors, unless they only run at full speed.
1064 + * that means alternate endpoint descriptors (bigger packets)
1065 + * and a "device qualifier" ... plus more construction options
1066 + * for the config descriptor.
1069 +static struct usb_qualifier_descriptor
1071 + .bLength = sizeof dev_qualifier,
1072 + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
1074 + .bcdUSB = __constant_cpu_to_le16 (0x0200),
1075 + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
1077 + .bNumConfigurations = 2,
1081 +struct usb_cs_as_general_descriptor {
1083 + __u8 bDescriptorType;
1085 + __u8 bDescriptorSubType;
1086 + __u8 bTerminalLink;
1089 +} __attribute__ ((packed));
1091 +struct usb_cs_as_format_descriptor {
1093 + __u8 bDescriptorType;
1095 + __u8 bDescriptorSubType;
1098 + __u8 bSubframeSize;
1099 + __u8 bBitResolution;
1100 + __u8 bSamfreqType;
1101 + __u8 tLowerSamFreq[3];
1102 + __u8 tUpperSamFreq[3];
1103 +} __attribute__ ((packed));
1105 +static const struct usb_interface_descriptor
1106 +z_audio_control_if_desc = {
1107 + .bLength = sizeof z_audio_control_if_desc,
1108 + .bDescriptorType = USB_DT_INTERFACE,
1109 + .bInterfaceNumber = 0,
1110 + .bAlternateSetting = 0,
1111 + .bNumEndpoints = 0,
1112 + .bInterfaceClass = USB_CLASS_AUDIO,
1113 + .bInterfaceSubClass = 0x1,
1114 + .bInterfaceProtocol = 0,
1118 +static const struct usb_interface_descriptor
1119 +z_audio_if_desc = {
1120 + .bLength = sizeof z_audio_if_desc,
1121 + .bDescriptorType = USB_DT_INTERFACE,
1122 + .bInterfaceNumber = 1,
1123 + .bAlternateSetting = 0,
1124 + .bNumEndpoints = 0,
1125 + .bInterfaceClass = USB_CLASS_AUDIO,
1126 + .bInterfaceSubClass = 0x2,
1127 + .bInterfaceProtocol = 0,
1131 +static const struct usb_interface_descriptor
1132 +z_audio_if_desc2 = {
1133 + .bLength = sizeof z_audio_if_desc,
1134 + .bDescriptorType = USB_DT_INTERFACE,
1135 + .bInterfaceNumber = 1,
1136 + .bAlternateSetting = 1,
1137 + .bNumEndpoints = 1,
1138 + .bInterfaceClass = USB_CLASS_AUDIO,
1139 + .bInterfaceSubClass = 0x2,
1140 + .bInterfaceProtocol = 0,
1144 +static const struct usb_cs_as_general_descriptor
1145 +z_audio_cs_as_if_desc = {
1147 + .bDescriptorType = 0x24,
1149 + .bDescriptorSubType = 0x01,
1150 + .bTerminalLink = 0x01,
1152 + .wFormatTag = __constant_cpu_to_le16 (0x0001)
1156 +static const struct usb_cs_as_format_descriptor
1157 +z_audio_cs_as_format_desc = {
1159 + .bDescriptorType = 0x24,
1161 + .bDescriptorSubType = 2,
1164 + .bSubframeSize = 1,
1165 + .bBitResolution = 8,
1166 + .bSamfreqType = 0,
1167 + .tLowerSamFreq = {0x7e, 0x13, 0x00},
1168 + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
1171 +static const struct usb_endpoint_descriptor
1174 + .bDescriptorType = 0x05,
1175 + .bEndpointAddress = 0x04,
1176 + .bmAttributes = 0x09,
1177 + .wMaxPacketSize = 0x0038,
1178 + .bInterval = 0x01,
1180 + .bSynchAddress = 0x00,
1183 +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
1186 +static char z_ac_interface_header_desc[] =
1187 +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
1190 +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
1191 + 0x03, 0x00, 0x00, 0x00};
1193 +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
1194 + 0x02, 0x00, 0x02, 0x00, 0x00};
1196 +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
1199 +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
1202 +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
1204 +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
1205 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
1207 +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
1210 +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
1212 +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
1215 +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
1217 +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
1218 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
1220 +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
1223 +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
1225 +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
1228 +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
1230 +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
1231 + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
1233 +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
1236 +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
1238 +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
1241 +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
1243 +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
1244 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
1246 +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
1249 +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
1251 +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
1254 +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
1256 +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
1257 + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
1259 +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
1262 +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
1266 +static const struct usb_descriptor_header *z_function [] = {
1267 + (struct usb_descriptor_header *) &z_audio_control_if_desc,
1268 + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
1269 + (struct usb_descriptor_header *) &z_0,
1270 + (struct usb_descriptor_header *) &z_1,
1271 + (struct usb_descriptor_header *) &z_2,
1272 + (struct usb_descriptor_header *) &z_audio_if_desc,
1273 + (struct usb_descriptor_header *) &z_audio_if_desc2,
1274 + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
1275 + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
1276 + (struct usb_descriptor_header *) &z_iso_ep,
1277 + (struct usb_descriptor_header *) &z_iso_ep2,
1278 + (struct usb_descriptor_header *) &za_0,
1279 + (struct usb_descriptor_header *) &za_1,
1280 + (struct usb_descriptor_header *) &za_2,
1281 + (struct usb_descriptor_header *) &za_3,
1282 + (struct usb_descriptor_header *) &za_4,
1283 + (struct usb_descriptor_header *) &za_5,
1284 + (struct usb_descriptor_header *) &za_6,
1285 + (struct usb_descriptor_header *) &za_7,
1286 + (struct usb_descriptor_header *) &za_8,
1287 + (struct usb_descriptor_header *) &za_9,
1288 + (struct usb_descriptor_header *) &za_10,
1289 + (struct usb_descriptor_header *) &za_11,
1290 + (struct usb_descriptor_header *) &za_12,
1291 + (struct usb_descriptor_header *) &za_13,
1292 + (struct usb_descriptor_header *) &za_14,
1293 + (struct usb_descriptor_header *) &za_15,
1294 + (struct usb_descriptor_header *) &za_16,
1295 + (struct usb_descriptor_header *) &za_17,
1296 + (struct usb_descriptor_header *) &za_18,
1297 + (struct usb_descriptor_header *) &za_19,
1298 + (struct usb_descriptor_header *) &za_20,
1299 + (struct usb_descriptor_header *) &za_21,
1300 + (struct usb_descriptor_header *) &za_22,
1301 + (struct usb_descriptor_header *) &za_23,
1302 + (struct usb_descriptor_header *) &za_24,
1306 +/* maxpacket and other transfer characteristics vary by speed. */
1307 +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
1311 +/* if there's no high speed support, maxpacket doesn't change. */
1312 +#define ep_desc(g,hs,fs) fs
1314 +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
1316 +static char manufacturer [40];
1317 +//static char serial [40];
1318 +static char serial [] = "Ser 00 em";
1320 +/* static strings, in UTF-8 */
1321 +static struct usb_string strings [] = {
1322 + { STRING_MANUFACTURER, manufacturer, },
1323 + { STRING_PRODUCT, longname, },
1324 + { STRING_SERIAL, serial, },
1325 + { STRING_LOOPBACK, loopback, },
1326 + { STRING_SOURCE_SINK, source_sink, },
1327 + { } /* end of list */
1330 +static struct usb_gadget_strings stringtab = {
1331 + .language = 0x0409, /* en-us */
1332 + .strings = strings,
1336 + * config descriptors are also handcrafted. these must agree with code
1337 + * that sets configurations, and with code managing interfaces and their
1338 + * altsettings. other complexity may come from:
1340 + * - high speed support, including "other speed config" rules
1341 + * - multiple configurations
1342 + * - interfaces with alternate settings
1343 + * - embedded class or vendor-specific descriptors
1345 + * this handles high speed, and has a second config that could as easily
1346 + * have been an alternate interface setting (on most hardware).
1348 + * NOTE: to demonstrate (and test) more USB capabilities, this driver
1349 + * should include an altsetting to test interrupt transfers, including
1350 + * high bandwidth modes at high speed. (Maybe work like Intel's test
1354 +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
1357 + const struct usb_descriptor_header **function;
1359 + function = z_function;
1360 + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
1363 + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
1367 +/*-------------------------------------------------------------------------*/
1369 +static struct usb_request *
1370 +alloc_ep_req (struct usb_ep *ep, unsigned length)
1372 + struct usb_request *req;
1374 + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
1376 + req->length = length;
1377 + req->buf = usb_ep_alloc_buffer (ep, length,
1378 + &req->dma, GFP_ATOMIC);
1380 + usb_ep_free_request (ep, req);
1387 +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
1390 + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
1391 + usb_ep_free_request (ep, req);
1394 +/*-------------------------------------------------------------------------*/
1396 +/* optionally require specific source/sink data patterns */
1400 + struct zero_dev *dev,
1401 + struct usb_ep *ep,
1402 + struct usb_request *req
1406 + u8 *buf = req->buf;
1408 + for (i = 0; i < req->actual; i++, buf++) {
1409 + switch (pattern) {
1410 + /* all-zeroes has no synchronization issues */
1415 + /* mod63 stays in sync with short-terminated transfers,
1416 + * or otherwise when host and gadget agree on how large
1417 + * each usb transfer request should be. resync is done
1418 + * with set_interface or set_config.
1421 + if (*buf == (u8)(i % 63))
1425 + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
1426 + usb_ep_set_halt (ep);
1432 +/*-------------------------------------------------------------------------*/
1434 +static void zero_reset_config (struct zero_dev *dev)
1436 + if (dev->config == 0)
1439 + DBG (dev, "reset config\n");
1441 + /* just disable endpoints, forcing completion of pending i/o.
1442 + * all our completion handlers free their requests in this case.
1445 + usb_ep_disable (dev->in_ep);
1446 + dev->in_ep = NULL;
1448 + if (dev->out_ep) {
1449 + usb_ep_disable (dev->out_ep);
1450 + dev->out_ep = NULL;
1453 + del_timer (&dev->resume);
1456 +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
1459 +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
1461 + struct zero_dev *dev = ep->driver_data;
1462 + int status = req->status;
1467 + case 0: /* normal completion? */
1468 + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
1469 + for (i=0, j=rbuf_start; i<req->actual; i++) {
1470 + //printk ("%02x ", ((__u8*)req->buf)[i]);
1471 + rbuf[j] = ((__u8*)req->buf)[i];
1473 + if (j >= RBUF_LEN) j=0;
1476 + //printk ("\n\n");
1478 + if (rbuf_len < RBUF_LEN) {
1479 + rbuf_len += req->actual;
1480 + if (rbuf_len > RBUF_LEN) {
1481 + rbuf_len = RBUF_LEN;
1487 + /* this endpoint is normally active while we're configured */
1488 + case -ECONNABORTED: /* hardware forced ep reset */
1489 + case -ECONNRESET: /* request dequeued */
1490 + case -ESHUTDOWN: /* disconnect from host */
1491 + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
1492 + req->actual, req->length);
1493 + if (ep == dev->out_ep)
1494 + check_read_data (dev, ep, req);
1495 + free_ep_req (ep, req);
1498 + case -EOVERFLOW: /* buffer overrun on read means that
1499 + * we didn't provide a big enough
1504 + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
1505 + status, req->actual, req->length);
1507 + case -EREMOTEIO: /* short read */
1511 + status = usb_ep_queue (ep, req, GFP_ATOMIC);
1513 + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
1514 + ep->name, req->length, status);
1515 + usb_ep_set_halt (ep);
1516 + /* FIXME recover later ... somehow */
1520 +static struct usb_request *
1521 +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
1523 + struct usb_request *req;
1526 + req = alloc_ep_req (ep, 512);
1530 + req->complete = zero_isoc_complete;
1532 + status = usb_ep_queue (ep, req, gfp_flags);
1534 + struct zero_dev *dev = ep->driver_data;
1536 + ERROR (dev, "start %s --> %d\n", ep->name, status);
1537 + free_ep_req (ep, req);
1544 +/* change our operational config. this code must agree with the code
1545 + * that returns config descriptors, and altsetting code.
1547 + * it's also responsible for power management interactions. some
1548 + * configurations might not work with our current power sources.
1550 + * note that some device controller hardware will constrain what this
1551 + * code can do, perhaps by disallowing more than one configuration or
1552 + * by limiting configuration choices (like the pxa2xx).
1555 +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
1558 + struct usb_gadget *gadget = dev->gadget;
1559 + const struct usb_endpoint_descriptor *d;
1560 + struct usb_ep *ep;
1562 + if (number == dev->config)
1565 + zero_reset_config (dev);
1567 + gadget_for_each_ep (ep, gadget) {
1569 + if (strcmp (ep->name, "ep4") == 0) {
1571 + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
1572 + result = usb_ep_enable (ep, d);
1574 + if (result == 0) {
1575 + ep->driver_data = dev;
1578 + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
1584 + usb_ep_disable (ep);
1591 + dev->config = number;
1595 +/*-------------------------------------------------------------------------*/
1597 +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
1599 + if (req->status || req->actual != req->length)
1600 + DBG ((struct zero_dev *) ep->driver_data,
1601 + "setup complete --> %d, %d/%d\n",
1602 + req->status, req->actual, req->length);
1606 + * The setup() callback implements all the ep0 functionality that's
1607 + * not handled lower down, in hardware or the hardware driver (like
1608 + * device and endpoint feature flags, and their status). It's all
1609 + * housekeeping for the gadget function we're implementing. Most of
1610 + * the work is in config-specific setup.
1613 +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1615 + struct zero_dev *dev = get_gadget_data (gadget);
1616 + struct usb_request *req = dev->req;
1617 + int value = -EOPNOTSUPP;
1619 + /* usually this stores reply data in the pre-allocated ep0 buffer,
1620 + * but config change events will reconfigure hardware.
1623 + switch (ctrl->bRequest) {
1625 + case USB_REQ_GET_DESCRIPTOR:
1627 + switch (ctrl->wValue >> 8) {
1629 + case USB_DT_DEVICE:
1630 + value = min (ctrl->wLength, (u16) sizeof device_desc);
1631 + memcpy (req->buf, &device_desc, value);
1633 +#ifdef CONFIG_USB_GADGET_DUALSPEED
1634 + case USB_DT_DEVICE_QUALIFIER:
1635 + if (!gadget->is_dualspeed)
1637 + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
1638 + memcpy (req->buf, &dev_qualifier, value);
1641 + case USB_DT_OTHER_SPEED_CONFIG:
1642 + if (!gadget->is_dualspeed)
1645 +#endif /* CONFIG_USB_GADGET_DUALSPEED */
1646 + case USB_DT_CONFIG:
1647 + value = config_buf (gadget, req->buf,
1648 + ctrl->wValue >> 8,
1649 + ctrl->wValue & 0xff);
1651 + value = min (ctrl->wLength, (u16) value);
1654 + case USB_DT_STRING:
1655 + /* wIndex == language code.
1656 + * this driver only handles one language, you can
1657 + * add string tables for other languages, using
1658 + * any UTF-8 characters
1660 + value = usb_gadget_get_string (&stringtab,
1661 + ctrl->wValue & 0xff, req->buf);
1663 + value = min (ctrl->wLength, (u16) value);
1669 + /* currently two configs, two speeds */
1670 + case USB_REQ_SET_CONFIGURATION:
1671 + if (ctrl->bRequestType != 0)
1674 + spin_lock (&dev->lock);
1675 + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
1676 + spin_unlock (&dev->lock);
1678 + case USB_REQ_GET_CONFIGURATION:
1679 + if (ctrl->bRequestType != USB_DIR_IN)
1681 + *(u8 *)req->buf = dev->config;
1682 + value = min (ctrl->wLength, (u16) 1);
1685 + /* until we add altsetting support, or other interfaces,
1686 + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
1687 + * and already killed pending endpoint I/O.
1689 + case USB_REQ_SET_INTERFACE:
1691 + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
1693 + spin_lock (&dev->lock);
1694 + if (dev->config) {
1695 + u8 config = dev->config;
1697 + /* resets interface configuration, forgets about
1698 + * previous transaction state (queued bufs, etc)
1699 + * and re-inits endpoint state (toggle etc)
1700 + * no response queued, just zero status == success.
1701 + * if we had more than one interface we couldn't
1702 + * use this "reset the config" shortcut.
1704 + zero_reset_config (dev);
1705 + zero_set_config (dev, config, GFP_ATOMIC);
1708 + spin_unlock (&dev->lock);
1710 + case USB_REQ_GET_INTERFACE:
1711 + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
1712 + value = ctrl->wLength;
1716 + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
1720 + if (ctrl->wIndex != 0) {
1724 + *(u8 *)req->buf = 0;
1725 + value = min (ctrl->wLength, (u16) 1);
1730 + * These are the same vendor-specific requests supported by
1731 + * Intel's USB 2.0 compliance test devices. We exceed that
1732 + * device spec by allowing multiple-packet requests.
1734 + case 0x5b: /* control WRITE test -- fill the buffer */
1735 + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
1737 + if (ctrl->wValue || ctrl->wIndex)
1739 + /* just read that many bytes into the buffer */
1740 + if (ctrl->wLength > USB_BUFSIZ)
1742 + value = ctrl->wLength;
1744 + case 0x5c: /* control READ test -- return the buffer */
1745 + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
1747 + if (ctrl->wValue || ctrl->wIndex)
1749 + /* expect those bytes are still in the buffer; send back */
1750 + if (ctrl->wLength > USB_BUFSIZ
1751 + || ctrl->wLength != req->length)
1753 + value = ctrl->wLength;
1756 + case 0x01: // SET_CUR
1761 + value = ctrl->wLength;
1764 + switch (ctrl->wValue) {
1767 + ((u8*)req->buf)[0] = 0x00;
1768 + ((u8*)req->buf)[1] = 0xe3;
1772 + ((u8*)req->buf)[0] = 0x00;
1775 + //((u8*)req->buf)[0] = 0x81;
1776 + //((u8*)req->buf)[1] = 0x81;
1777 + value = ctrl->wLength;
1780 + switch (ctrl->wValue) {
1783 + ((u8*)req->buf)[0] = 0x00;
1784 + ((u8*)req->buf)[1] = 0xc3;
1788 + ((u8*)req->buf)[0] = 0x00;
1791 + //((u8*)req->buf)[0] = 0x82;
1792 + //((u8*)req->buf)[1] = 0x82;
1793 + value = ctrl->wLength;
1796 + switch (ctrl->wValue) {
1799 + ((u8*)req->buf)[0] = 0x00;
1800 + ((u8*)req->buf)[1] = 0x00;
1803 + ((u8*)req->buf)[0] = 0x60;
1806 + ((u8*)req->buf)[0] = 0x18;
1809 + //((u8*)req->buf)[0] = 0x83;
1810 + //((u8*)req->buf)[1] = 0x83;
1811 + value = ctrl->wLength;
1814 + switch (ctrl->wValue) {
1817 + ((u8*)req->buf)[0] = 0x00;
1818 + ((u8*)req->buf)[1] = 0x01;
1822 + ((u8*)req->buf)[0] = 0x08;
1825 + //((u8*)req->buf)[0] = 0x84;
1826 + //((u8*)req->buf)[1] = 0x84;
1827 + value = ctrl->wLength;
1830 + ((u8*)req->buf)[0] = 0x85;
1831 + ((u8*)req->buf)[1] = 0x85;
1832 + value = ctrl->wLength;
1838 + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
1839 + ctrl->bRequestType, ctrl->bRequest,
1840 + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
1843 + /* respond with data transfer before status phase? */
1845 + req->length = value;
1846 + req->zero = value < ctrl->wLength
1847 + && (value % gadget->ep0->maxpacket) == 0;
1848 + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
1850 + DBG (dev, "ep_queue < 0 --> %d\n", value);
1852 + zero_setup_complete (gadget->ep0, req);
1856 + /* device either stalls (value < 0) or reports success */
1861 +zero_disconnect (struct usb_gadget *gadget)
1863 + struct zero_dev *dev = get_gadget_data (gadget);
1864 + unsigned long flags;
1866 + spin_lock_irqsave (&dev->lock, flags);
1867 + zero_reset_config (dev);
1869 + /* a more significant application might have some non-usb
1870 + * activities to quiesce here, saving resources like power
1871 + * or pushing the notification up a network stack.
1873 + spin_unlock_irqrestore (&dev->lock, flags);
1875 + /* next we may get setup() calls to enumerate new connections;
1876 + * or an unbind() during shutdown (including removing module).
1881 +zero_autoresume (unsigned long _dev)
1883 + struct zero_dev *dev = (struct zero_dev *) _dev;
1886 + /* normally the host would be woken up for something
1887 + * more significant than just a timer firing...
1889 + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
1890 + status = usb_gadget_wakeup (dev->gadget);
1891 + DBG (dev, "wakeup --> %d\n", status);
1895 +/*-------------------------------------------------------------------------*/
1898 +zero_unbind (struct usb_gadget *gadget)
1900 + struct zero_dev *dev = get_gadget_data (gadget);
1902 + DBG (dev, "unbind\n");
1904 + /* we've already been disconnected ... no i/o is active */
1906 + free_ep_req (gadget->ep0, dev->req);
1907 + del_timer_sync (&dev->resume);
1909 + set_gadget_data (gadget, NULL);
1913 +zero_bind (struct usb_gadget *gadget)
1915 + struct zero_dev *dev;
1916 + //struct usb_ep *ep;
1918 + printk("binding\n");
1920 + * DRIVER POLICY CHOICE: you may want to do this differently.
1921 + * One thing to avoid is reusing a bcdDevice revision code
1922 + * with different host-visible configurations or behavior
1923 + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
1925 + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
1928 + /* ok, we made sense of the hardware ... */
1929 + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
1932 + memset (dev, 0, sizeof *dev);
1933 + spin_lock_init (&dev->lock);
1934 + dev->gadget = gadget;
1935 + set_gadget_data (gadget, dev);
1937 + /* preallocate control response and buffer */
1938 + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
1941 + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
1942 + &dev->req->dma, GFP_KERNEL);
1943 + if (!dev->req->buf)
1946 + dev->req->complete = zero_setup_complete;
1948 + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1950 +#ifdef CONFIG_USB_GADGET_DUALSPEED
1951 + /* assume ep0 uses the same value for both speeds ... */
1952 + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
1954 + /* and that all endpoints are dual-speed */
1955 + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
1956 + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
1959 + usb_gadget_set_selfpowered (gadget);
1961 + init_timer (&dev->resume);
1962 + dev->resume.function = zero_autoresume;
1963 + dev->resume.data = (unsigned long) dev;
1965 + gadget->ep0->driver_data = dev;
1967 + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
1968 + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
1969 + EP_OUT_NAME, EP_IN_NAME);
1971 + snprintf (manufacturer, sizeof manufacturer,
1972 + UTS_SYSNAME " " UTS_RELEASE " with %s",
1978 + zero_unbind (gadget);
1982 +/*-------------------------------------------------------------------------*/
1985 +zero_suspend (struct usb_gadget *gadget)
1987 + struct zero_dev *dev = get_gadget_data (gadget);
1989 + if (gadget->speed == USB_SPEED_UNKNOWN)
1993 + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
1994 + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
1996 + DBG (dev, "suspend\n");
2000 +zero_resume (struct usb_gadget *gadget)
2002 + struct zero_dev *dev = get_gadget_data (gadget);
2004 + DBG (dev, "resume\n");
2005 + del_timer (&dev->resume);
2009 +/*-------------------------------------------------------------------------*/
2011 +static struct usb_gadget_driver zero_driver = {
2012 +#ifdef CONFIG_USB_GADGET_DUALSPEED
2013 + .speed = USB_SPEED_HIGH,
2015 + .speed = USB_SPEED_FULL,
2017 + .function = (char *) longname,
2018 + .bind = zero_bind,
2019 + .unbind = zero_unbind,
2021 + .setup = zero_setup,
2022 + .disconnect = zero_disconnect,
2024 + .suspend = zero_suspend,
2025 + .resume = zero_resume,
2028 + .name = (char *) shortname,
2029 + // .shutdown = ...
2035 +MODULE_AUTHOR ("David Brownell");
2036 +MODULE_LICENSE ("Dual BSD/GPL");
2038 +static struct proc_dir_entry *pdir, *pfile;
2040 +static int isoc_read_data (char *page, char **start,
2041 + off_t off, int count,
2042 + int *eof, void *data)
2046 + static int done = 0;
2050 + printk ("\ncount: %d\n", count);
2051 + printk ("rbuf_start: %d\n", rbuf_start);
2052 + printk ("rbuf_len: %d\n", rbuf_len);
2053 + printk ("off: %d\n", off);
2054 + printk ("start: %p\n\n", *start);
2064 + if (rbuf_len == RBUF_LEN)
2069 + for (i=0; i<count && c<rbuf_len; i++, c++) {
2070 + page[i] = rbuf[(c+s) % RBUF_LEN];
2074 + if (c >= rbuf_len) {
2083 +static int __init init (void)
2088 + pdir = proc_mkdir("isoc_test", NULL);
2089 + if(pdir == NULL) {
2091 + printk("Error creating dir\n");
2094 + pdir->owner = THIS_MODULE;
2096 + pfile = create_proc_read_entry("isoc_data",
2100 + if (pfile == NULL) {
2102 + printk("Error creating file\n");
2105 + pfile->owner = THIS_MODULE;
2107 + return usb_gadget_register_driver (&zero_driver);
2110 + remove_proc_entry("isoc_data", NULL);
2114 +module_init (init);
2116 +static void __exit cleanup (void)
2119 + usb_gadget_unregister_driver (&zero_driver);
2121 + remove_proc_entry("isoc_data", pdir);
2122 + remove_proc_entry("isoc_test", NULL);
2124 +module_exit (cleanup);
2126 +++ b/drivers/usb/host/otg/dwc_otg_attr.c
2128 +/* ==========================================================================
2129 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
2130 + * $Revision: #31 $
2131 + * $Date: 2008/07/15 $
2132 + * $Change: 1064918 $
2134 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
2135 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
2136 + * otherwise expressly agreed to in writing between Synopsys and you.
2138 + * The Software IS NOT an item of Licensed Software or Licensed Product under
2139 + * any End User Software License Agreement or Agreement for Licensed Product
2140 + * with Synopsys or any supplement thereto. You are permitted to use and
2141 + * redistribute this Software in source and binary forms, with or without
2142 + * modification, provided that redistributions of source code must retain this
2143 + * notice. You may not view, use, disclose, copy or distribute this file or
2144 + * any information contained herein except pursuant to this license grant from
2145 + * Synopsys. If you do not agree with this notice, including the disclaimer
2146 + * below, then you are not authorized to use the Software.
2148 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
2149 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2150 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2151 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
2152 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2153 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2154 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2155 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2156 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2157 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2159 + * ========================================================================== */
2163 + * The diagnostic interface will provide access to the controller for
2164 + * bringing up the hardware and testing. The Linux driver attributes
2165 + * feature will be used to provide the Linux Diagnostic
2166 + * Interface. These attributes are accessed through sysfs.
2169 +/** @page "Linux Module Attributes"
2171 + * The Linux module attributes feature is used to provide the Linux
2172 + * Diagnostic Interface. These attributes are accessed through sysfs.
2173 + * The diagnostic interface will provide access to the controller for
2174 + * bringing up the hardware and testing.
2177 + The following table shows the attributes.
2180 + <td><b> Name</b></td>
2181 + <td><b> Description</b></td>
2182 + <td><b> Access</b></td>
2187 + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
2192 + <td> hnpcapable </td>
2193 + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
2194 + Read returns the current value.</td>
2195 + <td> Read/Write</td>
2199 + <td> srpcapable </td>
2200 + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
2201 + Read returns the current value.</td>
2202 + <td> Read/Write</td>
2207 + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
2208 + <td> Read/Write</td>
2213 + <td> Initiates the Session Request Protocol. Read returns the status.</td>
2214 + <td> Read/Write</td>
2218 + <td> buspower </td>
2219 + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
2220 + <td> Read/Write</td>
2224 + <td> bussuspend </td>
2225 + <td> Suspends the USB bus.</td>
2226 + <td> Read/Write</td>
2230 + <td> busconnected </td>
2231 + <td> Gets the connection status of the bus</td>
2236 + <td> gotgctl </td>
2237 + <td> Gets or sets the Core Control Status Register.</td>
2238 + <td> Read/Write</td>
2242 + <td> gusbcfg </td>
2243 + <td> Gets or sets the Core USB Configuration Register</td>
2244 + <td> Read/Write</td>
2248 + <td> grxfsiz </td>
2249 + <td> Gets or sets the Receive FIFO Size Register</td>
2250 + <td> Read/Write</td>
2254 + <td> gnptxfsiz </td>
2255 + <td> Gets or sets the non-periodic Transmit Size Register</td>
2256 + <td> Read/Write</td>
2260 + <td> gpvndctl </td>
2261 + <td> Gets or sets the PHY Vendor Control Register</td>
2262 + <td> Read/Write</td>
2267 + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
2268 + or sets the upper 16 bits.</td>
2269 + <td> Read/Write</td>
2274 + <td> Gets or sets the value of the User ID Register</td>
2275 + <td> Read/Write</td>
2279 + <td> gsnpsid </td>
2280 + <td> Gets the value of the Synopsys ID Regester</td>
2285 + <td> devspeed </td>
2286 + <td> Gets or sets the device speed setting in the DCFG register</td>
2287 + <td> Read/Write</td>
2291 + <td> enumspeed </td>
2292 + <td> Gets the device enumeration Speed.</td>
2297 + <td> hptxfsiz </td>
2298 + <td> Gets the value of the Host Periodic Transmit FIFO</td>
2304 + <td> Gets or sets the value in the Host Port Control and Status Register</td>
2305 + <td> Read/Write</td>
2309 + <td> regoffset </td>
2310 + <td> Sets the register offset for the next Register Access</td>
2311 + <td> Read/Write</td>
2315 + <td> regvalue </td>
2316 + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
2317 + <td> Read/Write</td>
2321 + <td> remote_wakeup </td>
2322 + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
2323 + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
2324 + Wakeup signalling bit in the Device Control Register is set for 1
2325 + milli-second.</td>
2326 + <td> Read/Write</td>
2330 + <td> regdump </td>
2331 + <td> Dumps the contents of core registers.</td>
2336 + <td> spramdump </td>
2337 + <td> Dumps the contents of core registers.</td>
2342 + <td> hcddump </td>
2343 + <td> Dumps the current HCD state.</td>
2348 + <td> hcd_frrem </td>
2349 + <td> Shows the average value of the Frame Remaining
2350 + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
2351 + occurs. This can be used to determine the average interrupt latency. Also
2352 + shows the average Frame Remaining value for start_transfer and the "a" and
2353 + "b" sample points. The "a" and "b" sample points may be used during debugging
2354 + bto determine how long it takes to execute a section of the HCD code.</td>
2359 + <td> rd_reg_test </td>
2360 + <td> Displays the time required to read the GNPTXFSIZ register many times
2361 + (the output shows the number of times the register is read).
2366 + <td> wr_reg_test </td>
2367 + <td> Displays the time required to write the GNPTXFSIZ register many times
2368 + (the output shows the number of times the register is written).
2375 + To get the current mode:
2376 + cat /sys/devices/lm0/mode
2378 + To power down the USB:
2379 + echo 0 > /sys/devices/lm0/buspower
2382 +#include <linux/kernel.h>
2383 +#include <linux/module.h>
2384 +#include <linux/moduleparam.h>
2385 +#include <linux/init.h>
2386 +#include <linux/device.h>
2387 +#include <linux/errno.h>
2388 +#include <linux/types.h>
2389 +#include <linux/stat.h> /* permission constants */
2390 +#include <linux/version.h>
2392 +#include <asm/sizes.h>
2393 +#include <asm/io.h>
2394 +//#include <asm/arch/lm.h>
2395 +#include <mach/lm.h>
2396 +#include <asm/sizes.h>
2398 +#include "dwc_otg_plat.h"
2399 +#include "dwc_otg_attr.h"
2400 +#include "dwc_otg_driver.h"
2401 +#include "dwc_otg_pcd.h"
2402 +#include "dwc_otg_hcd.h"
2404 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2406 + * MACROs for defining sysfs attribute
2408 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2409 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
2411 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
2412 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
2414 + val = dwc_read_reg32 (_addr_); \
2415 + val = (val & (_mask_)) >> _shift_; \
2416 + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
2418 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2419 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
2420 + const char *buf, size_t count) \
2422 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
2423 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
2424 + uint32_t set = simple_strtoul(buf, NULL, 16); \
2425 + uint32_t clear = set; \
2426 + clear = ((~clear) << _shift_) & _mask_; \
2427 + set = (set << _shift_) & _mask_; \
2428 + dev_dbg(_dev, "Storing Address=0x%08x Set=0x%08x Clear=0x%08x\n", (uint32_t)_addr_, set, clear); \
2429 + dwc_modify_reg32(_addr_, clear, set); \
2434 + * MACROs for defining sysfs attribute for 32-bit registers
2436 +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2437 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
2439 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
2440 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
2442 + val = dwc_read_reg32 (_addr_); \
2443 + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
2445 +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
2446 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
2447 + const char *buf, size_t count) \
2449 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
2450 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
2451 + uint32_t val = simple_strtoul(buf, NULL, 16); \
2452 + dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \
2453 + dwc_write_reg32(_addr_, val); \
2460 + * MACROs for defining sysfs attribute
2462 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2463 +static ssize_t _otg_attr_name_##_show (struct device *_dev, char *buf) \
2465 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2467 + val = dwc_read_reg32 (_addr_); \
2468 + val = (val & (_mask_)) >> _shift_; \
2469 + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
2471 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2472 +static ssize_t _otg_attr_name_##_store (struct device *_dev, const char *buf, size_t count) \
2474 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2475 + uint32_t set = simple_strtoul(buf, NULL, 16); \
2476 + uint32_t clear = set; \
2477 + clear = ((~clear) << _shift_) & _mask_; \
2478 + set = (set << _shift_) & _mask_; \
2479 + dev_dbg(_dev, "Storing Address=0x%08x Set=0x%08x Clear=0x%08x\n", (uint32_t)_addr_, set, clear); \
2480 + dwc_modify_reg32(_addr_, clear, set); \
2485 + * MACROs for defining sysfs attribute for 32-bit registers
2487 +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2488 +static ssize_t _otg_attr_name_##_show (struct device *_dev, char *buf) \
2490 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2492 + val = dwc_read_reg32 (_addr_); \
2493 + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
2495 +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
2496 +static ssize_t _otg_attr_name_##_store (struct device *_dev, const char *buf, size_t count) \
2498 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
2499 + uint32_t val = simple_strtoul(buf, NULL, 16); \
2500 + dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \
2501 + dwc_write_reg32(_addr_, val); \
2507 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2508 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2509 +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2510 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
2512 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2513 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
2514 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
2516 +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
2517 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2518 +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
2519 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
2521 +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
2522 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
2523 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
2526 +/** @name Functions for Show/Store of Attributes */
2530 + * Show the register offset of the Register Access.
2532 +static ssize_t regoffset_show( struct device *_dev,
2533 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2534 + struct device_attribute *attr,
2538 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2539 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2540 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2542 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2544 + return snprintf(buf, sizeof("0xFFFFFFFF\n")+1,"0x%08x\n", otg_dev->reg_offset);
2548 + * Set the register offset for the next Register Access Read/Write
2550 +static ssize_t regoffset_store( struct device *_dev,
2551 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2552 + struct device_attribute *attr,
2557 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2558 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2559 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2561 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2563 + uint32_t offset = simple_strtoul(buf, NULL, 16);
2564 + //dev_dbg(_dev, "Offset=0x%08x\n", offset);
2565 + if (offset < SZ_256K ) {
2566 + otg_dev->reg_offset = offset;
2569 + dev_err( _dev, "invalid offset\n" );
2574 +DEVICE_ATTR(regoffset, S_IRUGO|S_IWUSR, (void *)regoffset_show, regoffset_store);
2578 + * Show the value of the register at the offset in the reg_offset
2581 +static ssize_t regvalue_show( struct device *_dev,
2582 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2583 + struct device_attribute *attr,
2587 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2588 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2589 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2591 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2594 + volatile uint32_t *addr;
2596 + if (otg_dev->reg_offset != 0xFFFFFFFF &&
2597 + 0 != otg_dev->base) {
2598 + /* Calculate the address */
2599 + addr = (uint32_t*)(otg_dev->reg_offset +
2600 + (uint8_t*)otg_dev->base);
2601 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
2602 + val = dwc_read_reg32( addr );
2603 + return snprintf(buf, sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n")+1,
2604 + "Reg@0x%06x = 0x%08x\n",
2605 + otg_dev->reg_offset, val);
2608 + dev_err(_dev, "Invalid offset (0x%0x)\n",
2609 + otg_dev->reg_offset);
2610 + return sprintf(buf, "invalid offset\n" );
2615 + * Store the value in the register at the offset in the reg_offset
2619 +static ssize_t regvalue_store( struct device *_dev,
2620 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2621 + struct device_attribute *attr,
2626 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2627 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2628 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2630 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2632 + volatile uint32_t * addr;
2633 + uint32_t val = simple_strtoul(buf, NULL, 16);
2634 + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
2635 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
2636 + /* Calculate the address */
2637 + addr = (uint32_t*)(otg_dev->reg_offset +
2638 + (uint8_t*)otg_dev->base);
2639 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
2640 + dwc_write_reg32( addr, val );
2643 + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
2644 + otg_dev->reg_offset);
2648 +DEVICE_ATTR(regvalue, S_IRUGO|S_IWUSR, regvalue_show, regvalue_store);
2653 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<20),20,"Mode");
2654 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<9),9,"Mode");
2655 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<8),8,"Mode");
2657 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
2658 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
2659 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected,otg_dev->core_if->host_if->hprt0,0x01,0,"Bus Connected");
2661 +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl,&(otg_dev->core_if->core_global_regs->gotgctl),"GOTGCTL");
2662 +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,&(otg_dev->core_if->core_global_regs->gusbcfg),"GUSBCFG");
2663 +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,&(otg_dev->core_if->core_global_regs->grxfsiz),"GRXFSIZ");
2664 +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,&(otg_dev->core_if->core_global_regs->gnptxfsiz),"GNPTXFSIZ");
2665 +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,&(otg_dev->core_if->core_global_regs->gpvndctl),"GPVNDCTL");
2666 +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,&(otg_dev->core_if->core_global_regs->ggpio),"GGPIO");
2667 +DWC_OTG_DEVICE_ATTR_REG32_RW(guid,&(otg_dev->core_if->core_global_regs->guid),"GUID");
2668 +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,&(otg_dev->core_if->core_global_regs->gsnpsid),"GSNPSID");
2669 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dcfg),0x3,0,"Device Speed");
2670 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dsts),0x6,1,"Device Enumeration Speed");
2672 +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,&(otg_dev->core_if->core_global_regs->hptxfsiz),"HPTXFSIZ");
2673 +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0,otg_dev->core_if->host_if->hprt0,"HPRT0");
2677 + * @todo Add code to initiate the HNP.
2680 + * Show the HNP status bit
2682 +static ssize_t hnp_show( struct device *_dev,
2683 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2684 + struct device_attribute *attr,
2688 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2689 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2690 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2692 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2694 + gotgctl_data_t val;
2695 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
2696 + return sprintf (buf, "HstNegScs = 0x%x\n", val.b.hstnegscs);
2700 + * Set the HNP Request bit
2702 +static ssize_t hnp_store( struct device *_dev,
2703 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2704 + struct device_attribute *attr,
2709 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2710 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2711 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2713 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2715 + uint32_t in = simple_strtoul(buf, NULL, 16);
2716 + uint32_t *addr = (uint32_t *)&(otg_dev->core_if->core_global_regs->gotgctl);
2717 + gotgctl_data_t mem;
2718 + mem.d32 = dwc_read_reg32(addr);
2719 + mem.b.hnpreq = in;
2720 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
2721 + dwc_write_reg32(addr, mem.d32);
2724 +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
2727 + * @todo Add code to initiate the SRP.
2730 + * Show the SRP status bit
2732 +static ssize_t srp_show( struct device *_dev,
2733 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2734 + struct device_attribute *attr,
2738 +#ifndef DWC_HOST_ONLY
2739 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2740 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2741 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2743 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2745 + gotgctl_data_t val;
2746 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
2747 + return sprintf (buf, "SesReqScs = 0x%x\n", val.b.sesreqscs);
2749 + return sprintf(buf, "Host Only Mode!\n");
2756 + * Set the SRP Request bit
2758 +static ssize_t srp_store( struct device *_dev,
2759 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2760 + struct device_attribute *attr,
2765 +#ifndef DWC_HOST_ONLY
2766 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2767 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2768 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2770 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2772 + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
2776 +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
2779 + * @todo Need to do more for power on/off?
2782 + * Show the Bus Power status
2784 +static ssize_t buspower_show( struct device *_dev,
2785 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2786 + struct device_attribute *attr,
2790 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2791 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2792 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2794 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2797 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
2798 + return sprintf (buf, "Bus Power = 0x%x\n", val.b.prtpwr);
2803 + * Set the Bus Power status
2805 +static ssize_t buspower_store( struct device *_dev,
2806 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2807 + struct device_attribute *attr,
2812 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2813 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2814 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2816 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2818 + uint32_t on = simple_strtoul(buf, NULL, 16);
2819 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
2822 + mem.d32 = dwc_read_reg32(addr);
2823 + mem.b.prtpwr = on;
2825 + //dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
2826 + dwc_write_reg32(addr, mem.d32);
2830 +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
2833 + * @todo Need to do more for suspend?
2836 + * Show the Bus Suspend status
2838 +static ssize_t bussuspend_show( struct device *_dev,
2839 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2840 + struct device_attribute *attr,
2844 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2845 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2846 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2848 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2851 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
2852 + return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
2856 + * Set the Bus Suspend status
2858 +static ssize_t bussuspend_store( struct device *_dev,
2859 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2860 + struct device_attribute *attr,
2865 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2866 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2867 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2869 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2871 + uint32_t in = simple_strtoul(buf, NULL, 16);
2872 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
2874 + mem.d32 = dwc_read_reg32(addr);
2875 + mem.b.prtsusp = in;
2876 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
2877 + dwc_write_reg32(addr, mem.d32);
2880 +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
2883 + * Show the status of Remote Wakeup.
2885 +static ssize_t remote_wakeup_show( struct device *_dev,
2886 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2887 + struct device_attribute *attr,
2891 +#ifndef DWC_HOST_ONLY
2892 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2893 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2894 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2896 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2900 + dwc_read_reg32( &otg_dev->core_if->dev_if->dev_global_regs->dctl);
2901 + return sprintf( buf, "Remote Wakeup = %d Enabled = %d\n",
2902 + val.b.rmtwkupsig, otg_dev->pcd->remote_wakeup_enable);
2904 + return sprintf(buf, "Host Only Mode!\n");
2908 + * Initiate a remote wakeup of the host. The Device control register
2909 + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
2913 +static ssize_t remote_wakeup_store( struct device *_dev,
2914 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2915 + struct device_attribute *attr,
2920 +#ifndef DWC_HOST_ONLY
2921 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2922 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2923 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2925 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2927 + uint32_t val = simple_strtoul(buf, NULL, 16);
2929 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
2932 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
2937 +DEVICE_ATTR(remote_wakeup, S_IRUGO|S_IWUSR, remote_wakeup_show,
2938 + remote_wakeup_store);
2941 + * Dump global registers and either host or device registers (depending on the
2942 + * current mode of the core).
2944 +static ssize_t regdump_show( struct device *_dev,
2945 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2946 + struct device_attribute *attr,
2950 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2951 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2952 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2954 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2956 + dwc_otg_dump_global_registers( otg_dev->core_if);
2957 + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
2958 + dwc_otg_dump_host_registers( otg_dev->core_if);
2960 + dwc_otg_dump_dev_registers( otg_dev->core_if);
2963 + return sprintf( buf, "Register Dump\n" );
2966 +DEVICE_ATTR(regdump, S_IRUGO|S_IWUSR, regdump_show, 0);
2969 + * Dump global registers and either host or device registers (depending on the
2970 + * current mode of the core).
2972 +static ssize_t spramdump_show( struct device *_dev,
2973 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2974 + struct device_attribute *attr,
2978 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2979 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
2980 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
2982 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
2984 + dwc_otg_dump_spram( otg_dev->core_if);
2986 + return sprintf( buf, "SPRAM Dump\n" );
2989 +DEVICE_ATTR(spramdump, S_IRUGO|S_IWUSR, spramdump_show, 0);
2992 + * Dump the current hcd state.
2994 +static ssize_t hcddump_show( struct device *_dev,
2995 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
2996 + struct device_attribute *attr,
3000 +#ifndef DWC_DEVICE_ONLY
3001 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3002 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
3003 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
3005 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
3007 + dwc_otg_hcd_dump_state(otg_dev->hcd);
3009 + return sprintf( buf, "HCD Dump\n" );
3012 +DEVICE_ATTR(hcddump, S_IRUGO|S_IWUSR, hcddump_show, 0);
3015 + * Dump the average frame remaining at SOF. This can be used to
3016 + * determine average interrupt latency. Frame remaining is also shown for
3017 + * start transfer and two additional sample points.
3019 +static ssize_t hcd_frrem_show( struct device *_dev,
3020 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3021 + struct device_attribute *attr,
3025 +#ifndef DWC_DEVICE_ONLY
3026 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3027 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
3028 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
3030 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
3032 + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
3034 + return sprintf( buf, "HCD Dump Frame Remaining\n" );
3037 +DEVICE_ATTR(hcd_frrem, S_IRUGO|S_IWUSR, hcd_frrem_show, 0);
3040 + * Displays the time required to read the GNPTXFSIZ register many times (the
3041 + * output shows the number of times the register is read).
3043 +#define RW_REG_COUNT 10000000
3044 +#define MSEC_PER_JIFFIE 1000/HZ
3045 +static ssize_t rd_reg_test_show( struct device *_dev,
3046 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3047 + struct device_attribute *attr,
3051 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3052 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
3053 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
3055 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
3059 + int start_jiffies;
3061 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
3062 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
3063 + start_jiffies = jiffies;
3064 + for (i = 0; i < RW_REG_COUNT; i++) {
3065 + dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
3067 + time = jiffies - start_jiffies;
3068 + return sprintf( buf, "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
3069 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time );
3072 +DEVICE_ATTR(rd_reg_test, S_IRUGO|S_IWUSR, rd_reg_test_show, 0);
3075 + * Displays the time required to write the GNPTXFSIZ register many times (the
3076 + * output shows the number of times the register is written).
3078 +static ssize_t wr_reg_test_show( struct device *_dev,
3079 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3080 + struct device_attribute *attr,
3084 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3085 + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
3086 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
3088 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
3093 + int start_jiffies;
3095 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
3096 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
3097 + reg_val = dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
3098 + start_jiffies = jiffies;
3099 + for (i = 0; i < RW_REG_COUNT; i++) {
3100 + dwc_write_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz, reg_val);
3102 + time = jiffies - start_jiffies;
3103 + return sprintf( buf, "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
3104 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
3107 +DEVICE_ATTR(wr_reg_test, S_IRUGO|S_IWUSR, wr_reg_test_show, 0);
3111 + * Create the device files
3113 +void dwc_otg_attr_create (struct lm_device *lmdev)
3117 + error = device_create_file(&lmdev->dev, &dev_attr_regoffset);
3118 + error = device_create_file(&lmdev->dev, &dev_attr_regvalue);
3119 + error = device_create_file(&lmdev->dev, &dev_attr_mode);
3120 + error = device_create_file(&lmdev->dev, &dev_attr_hnpcapable);
3121 + error = device_create_file(&lmdev->dev, &dev_attr_srpcapable);
3122 + error = device_create_file(&lmdev->dev, &dev_attr_hnp);
3123 + error = device_create_file(&lmdev->dev, &dev_attr_srp);
3124 + error = device_create_file(&lmdev->dev, &dev_attr_buspower);
3125 + error = device_create_file(&lmdev->dev, &dev_attr_bussuspend);
3126 + error = device_create_file(&lmdev->dev, &dev_attr_busconnected);
3127 + error = device_create_file(&lmdev->dev, &dev_attr_gotgctl);
3128 + error = device_create_file(&lmdev->dev, &dev_attr_gusbcfg);
3129 + error = device_create_file(&lmdev->dev, &dev_attr_grxfsiz);
3130 + error = device_create_file(&lmdev->dev, &dev_attr_gnptxfsiz);
3131 + error = device_create_file(&lmdev->dev, &dev_attr_gpvndctl);
3132 + error = device_create_file(&lmdev->dev, &dev_attr_ggpio);
3133 + error = device_create_file(&lmdev->dev, &dev_attr_guid);
3134 + error = device_create_file(&lmdev->dev, &dev_attr_gsnpsid);
3135 + error = device_create_file(&lmdev->dev, &dev_attr_devspeed);
3136 + error = device_create_file(&lmdev->dev, &dev_attr_enumspeed);
3137 + error = device_create_file(&lmdev->dev, &dev_attr_hptxfsiz);
3138 + error = device_create_file(&lmdev->dev, &dev_attr_hprt0);
3139 + error = device_create_file(&lmdev->dev, &dev_attr_remote_wakeup);
3140 + error = device_create_file(&lmdev->dev, &dev_attr_regdump);
3141 + error = device_create_file(&lmdev->dev, &dev_attr_spramdump);
3142 + error = device_create_file(&lmdev->dev, &dev_attr_hcddump);
3143 + error = device_create_file(&lmdev->dev, &dev_attr_hcd_frrem);
3144 + error = device_create_file(&lmdev->dev, &dev_attr_rd_reg_test);
3145 + error = device_create_file(&lmdev->dev, &dev_attr_wr_reg_test);
3149 + * Remove the device files
3151 +void dwc_otg_attr_remove (struct lm_device *lmdev)
3153 + device_remove_file(&lmdev->dev, &dev_attr_regoffset);
3154 + device_remove_file(&lmdev->dev, &dev_attr_regvalue);
3155 + device_remove_file(&lmdev->dev, &dev_attr_mode);
3156 + device_remove_file(&lmdev->dev, &dev_attr_hnpcapable);
3157 + device_remove_file(&lmdev->dev, &dev_attr_srpcapable);
3158 + device_remove_file(&lmdev->dev, &dev_attr_hnp);
3159 + device_remove_file(&lmdev->dev, &dev_attr_srp);
3160 + device_remove_file(&lmdev->dev, &dev_attr_buspower);
3161 + device_remove_file(&lmdev->dev, &dev_attr_bussuspend);
3162 + device_remove_file(&lmdev->dev, &dev_attr_busconnected);
3163 + device_remove_file(&lmdev->dev, &dev_attr_gotgctl);
3164 + device_remove_file(&lmdev->dev, &dev_attr_gusbcfg);
3165 + device_remove_file(&lmdev->dev, &dev_attr_grxfsiz);
3166 + device_remove_file(&lmdev->dev, &dev_attr_gnptxfsiz);
3167 + device_remove_file(&lmdev->dev, &dev_attr_gpvndctl);
3168 + device_remove_file(&lmdev->dev, &dev_attr_ggpio);
3169 + device_remove_file(&lmdev->dev, &dev_attr_guid);
3170 + device_remove_file(&lmdev->dev, &dev_attr_gsnpsid);
3171 + device_remove_file(&lmdev->dev, &dev_attr_devspeed);
3172 + device_remove_file(&lmdev->dev, &dev_attr_enumspeed);
3173 + device_remove_file(&lmdev->dev, &dev_attr_hptxfsiz);
3174 + device_remove_file(&lmdev->dev, &dev_attr_hprt0);
3175 + device_remove_file(&lmdev->dev, &dev_attr_remote_wakeup);
3176 + device_remove_file(&lmdev->dev, &dev_attr_regdump);
3177 + device_remove_file(&lmdev->dev, &dev_attr_spramdump);
3178 + device_remove_file(&lmdev->dev, &dev_attr_hcddump);
3179 + device_remove_file(&lmdev->dev, &dev_attr_hcd_frrem);
3180 + device_remove_file(&lmdev->dev, &dev_attr_rd_reg_test);
3181 + device_remove_file(&lmdev->dev, &dev_attr_wr_reg_test);
3184 +++ b/drivers/usb/host/otg/dwc_otg_attr.h
3186 +/* ==========================================================================
3187 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
3189 + * $Date: 2005/03/28 $
3190 + * $Change: 477051 $
3192 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
3193 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
3194 + * otherwise expressly agreed to in writing between Synopsys and you.
3196 + * The Software IS NOT an item of Licensed Software or Licensed Product under
3197 + * any End User Software License Agreement or Agreement for Licensed Product
3198 + * with Synopsys or any supplement thereto. You are permitted to use and
3199 + * redistribute this Software in source and binary forms, with or without
3200 + * modification, provided that redistributions of source code must retain this
3201 + * notice. You may not view, use, disclose, copy or distribute this file or
3202 + * any information contained herein except pursuant to this license grant from
3203 + * Synopsys. If you do not agree with this notice, including the disclaimer
3204 + * below, then you are not authorized to use the Software.
3206 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
3207 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3208 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3209 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
3210 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3211 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3212 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3213 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3214 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3215 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
3217 + * ========================================================================== */
3219 +#if !defined(__DWC_OTG_ATTR_H__)
3220 +#define __DWC_OTG_ATTR_H__
3223 + * This file contains the interface to the Linux device attributes.
3225 +extern struct device_attribute dev_attr_regoffset;
3226 +extern struct device_attribute dev_attr_regvalue;
3228 +extern struct device_attribute dev_attr_mode;
3229 +extern struct device_attribute dev_attr_hnpcapable;
3230 +extern struct device_attribute dev_attr_srpcapable;
3231 +extern struct device_attribute dev_attr_hnp;
3232 +extern struct device_attribute dev_attr_srp;
3233 +extern struct device_attribute dev_attr_buspower;
3234 +extern struct device_attribute dev_attr_bussuspend;
3235 +extern struct device_attribute dev_attr_busconnected;
3236 +extern struct device_attribute dev_attr_gotgctl;
3237 +extern struct device_attribute dev_attr_gusbcfg;
3238 +extern struct device_attribute dev_attr_grxfsiz;
3239 +extern struct device_attribute dev_attr_gnptxfsiz;
3240 +extern struct device_attribute dev_attr_gpvndctl;
3241 +extern struct device_attribute dev_attr_ggpio;
3242 +extern struct device_attribute dev_attr_guid;
3243 +extern struct device_attribute dev_attr_gsnpsid;
3244 +extern struct device_attribute dev_attr_devspeed;
3245 +extern struct device_attribute dev_attr_enumspeed;
3246 +extern struct device_attribute dev_attr_hptxfsiz;
3247 +extern struct device_attribute dev_attr_hprt0;
3249 +void dwc_otg_attr_create (struct lm_device *lmdev);
3250 +void dwc_otg_attr_remove (struct lm_device *lmdev);
3254 +++ b/drivers/usb/host/otg/dwc_otg_cil.c
3256 +/* ==========================================================================
3257 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
3258 + * $Revision: #147 $
3259 + * $Date: 2008/10/16 $
3260 + * $Change: 1117667 $
3262 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
3263 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
3264 + * otherwise expressly agreed to in writing between Synopsys and you.
3266 + * The Software IS NOT an item of Licensed Software or Licensed Product under
3267 + * any End User Software License Agreement or Agreement for Licensed Product
3268 + * with Synopsys or any supplement thereto. You are permitted to use and
3269 + * redistribute this Software in source and binary forms, with or without
3270 + * modification, provided that redistributions of source code must retain this
3271 + * notice. You may not view, use, disclose, copy or distribute this file or
3272 + * any information contained herein except pursuant to this license grant from
3273 + * Synopsys. If you do not agree with this notice, including the disclaimer
3274 + * below, then you are not authorized to use the Software.
3276 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
3277 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3278 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3279 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
3280 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3281 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3282 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
3283 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3284 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3285 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
3287 + * ========================================================================== */
3291 + * The Core Interface Layer provides basic services for accessing and
3292 + * managing the DWC_otg hardware. These services are used by both the
3293 + * Host Controller Driver and the Peripheral Controller Driver.
3295 + * The CIL manages the memory map for the core so that the HCD and PCD
3296 + * don't have to do this separately. It also handles basic tasks like
3297 + * reading/writing the registers and data FIFOs in the controller.
3298 + * Some of the data access functions provide encapsulation of several
3299 + * operations required to perform a task, such as writing multiple
3300 + * registers to start a transfer. Finally, the CIL performs basic
3301 + * services that are not specific to either the host or device modes
3302 + * of operation. These services include management of the OTG Host
3303 + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
3304 + * Diagnostic API is also provided to allow testing of the controller
3307 + * The Core Interface Layer has the following requirements:
3308 + * - Provides basic controller operations.
3309 + * - Minimal use of OS services.
3310 + * - The OS services used will be abstracted by using inline functions
3314 +#include <asm/unaligned.h>
3315 +#include <linux/dma-mapping.h>
3317 +#include <linux/jiffies.h>
3320 +#include "dwc_otg_plat.h"
3321 +#include "dwc_otg_regs.h"
3322 +#include "dwc_otg_cil.h"
3323 +#include "dwc_otg_pcd.h"
3327 + * This function is called to initialize the DWC_otg CSR data
3328 + * structures. The register addresses in the device and host
3329 + * structures are initialized from the base address supplied by the
3330 + * caller. The calling function must make the OS calls to get the
3331 + * base address of the DWC_otg controller registers. The core_params
3332 + * argument holds the parameters that specify how the core should be
3335 + * @param[in] reg_base_addr Base address of DWC_otg core registers
3336 + * @param[in] core_params Pointer to the core configuration parameters
3339 +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *reg_base_addr,
3340 + dwc_otg_core_params_t *core_params)
3342 + dwc_otg_core_if_t *core_if = 0;
3343 + dwc_otg_dev_if_t *dev_if = 0;
3344 + dwc_otg_host_if_t *host_if = 0;
3345 + uint8_t *reg_base = (uint8_t *)reg_base_addr;
3348 + DWC_DEBUGPL(DBG_CILV, "%s(%p,%p)\n", __func__, reg_base_addr, core_params);
3350 + core_if = kmalloc(sizeof(dwc_otg_core_if_t), GFP_KERNEL);
3352 + if (core_if == 0) {
3353 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_core_if_t failed\n");
3357 + memset(core_if, 0, sizeof(dwc_otg_core_if_t));
3359 + core_if->core_params = core_params;
3360 + core_if->core_global_regs = (dwc_otg_core_global_regs_t *)reg_base;
3363 + * Allocate the Device Mode structures.
3365 + dev_if = kmalloc(sizeof(dwc_otg_dev_if_t), GFP_KERNEL);
3367 + if (dev_if == 0) {
3368 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
3373 + dev_if->dev_global_regs =
3374 + (dwc_otg_device_global_regs_t *)(reg_base + DWC_DEV_GLOBAL_REG_OFFSET);
3376 + for (i=0; i<MAX_EPS_CHANNELS; i++)
3378 + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
3379 + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
3380 + (i * DWC_EP_REG_OFFSET));
3382 + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
3383 + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
3384 + (i * DWC_EP_REG_OFFSET));
3385 + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
3386 + i, &dev_if->in_ep_regs[i]->diepctl);
3387 + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
3388 + i, &dev_if->out_ep_regs[i]->doepctl);
3391 + dev_if->speed = 0; // unknown
3393 + core_if->dev_if = dev_if;
3396 + * Allocate the Host Mode structures.
3398 + host_if = kmalloc(sizeof(dwc_otg_host_if_t), GFP_KERNEL);
3400 + if (host_if == 0) {
3401 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_host_if_t failed\n");
3407 + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
3408 + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
3410 + host_if->hprt0 = (uint32_t*)(reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
3412 + for (i=0; i<MAX_EPS_CHANNELS; i++)
3414 + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
3415 + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
3416 + (i * DWC_OTG_CHAN_REGS_OFFSET));
3417 + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
3418 + i, &host_if->hc_regs[i]->hcchar);
3421 + host_if->num_host_channels = MAX_EPS_CHANNELS;
3422 + core_if->host_if = host_if;
3424 + for (i=0; i<MAX_EPS_CHANNELS; i++)
3426 + core_if->data_fifo[i] =
3427 + (uint32_t *)(reg_base + DWC_OTG_DATA_FIFO_OFFSET +
3428 + (i * DWC_OTG_DATA_FIFO_SIZE));
3429 + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08x\n",
3430 + i, (unsigned)core_if->data_fifo[i]);
3433 + core_if->pcgcctl = (uint32_t*)(reg_base + DWC_OTG_PCGCCTL_OFFSET);
3436 + * Store the contents of the hardware configuration registers here for
3437 + * easy access later.
3439 + core_if->hwcfg1.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg1);
3440 + core_if->hwcfg2.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg2);
3441 + core_if->hwcfg3.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg3);
3442 + core_if->hwcfg4.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg4);
3444 + DWC_DEBUGPL(DBG_CILV,"hwcfg1=%08x\n",core_if->hwcfg1.d32);
3445 + DWC_DEBUGPL(DBG_CILV,"hwcfg2=%08x\n",core_if->hwcfg2.d32);
3446 + DWC_DEBUGPL(DBG_CILV,"hwcfg3=%08x\n",core_if->hwcfg3.d32);
3447 + DWC_DEBUGPL(DBG_CILV,"hwcfg4=%08x\n",core_if->hwcfg4.d32);
3449 + core_if->hcfg.d32 = dwc_read_reg32(&core_if->host_if->host_global_regs->hcfg);
3450 + core_if->dcfg.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dcfg);
3452 + DWC_DEBUGPL(DBG_CILV,"hcfg=%08x\n",core_if->hcfg.d32);
3453 + DWC_DEBUGPL(DBG_CILV,"dcfg=%08x\n",core_if->dcfg.d32);
3455 + DWC_DEBUGPL(DBG_CILV,"op_mode=%0x\n",core_if->hwcfg2.b.op_mode);
3456 + DWC_DEBUGPL(DBG_CILV,"arch=%0x\n",core_if->hwcfg2.b.architecture);
3457 + DWC_DEBUGPL(DBG_CILV,"num_dev_ep=%d\n",core_if->hwcfg2.b.num_dev_ep);
3458 + DWC_DEBUGPL(DBG_CILV,"num_host_chan=%d\n",core_if->hwcfg2.b.num_host_chan);
3459 + DWC_DEBUGPL(DBG_CILV,"nonperio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.nonperio_tx_q_depth);
3460 + DWC_DEBUGPL(DBG_CILV,"host_perio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.host_perio_tx_q_depth);
3461 + DWC_DEBUGPL(DBG_CILV,"dev_token_q_depth=0x%0x\n",core_if->hwcfg2.b.dev_token_q_depth);
3463 + DWC_DEBUGPL(DBG_CILV,"Total FIFO SZ=%d\n", core_if->hwcfg3.b.dfifo_depth);
3464 + DWC_DEBUGPL(DBG_CILV,"xfer_size_cntr_width=%0x\n", core_if->hwcfg3.b.xfer_size_cntr_width);
3467 + * Set the SRP sucess bit for FS-I2c
3469 + core_if->srp_success = 0;
3470 + core_if->srp_timer_started = 0;
3474 + * Create new workqueue and init works
3476 + core_if->wq_otg = create_singlethread_workqueue("dwc_otg");
3477 + if(core_if->wq_otg == 0) {
3478 + DWC_DEBUGPL(DBG_CIL, "Creation of wq_otg failed\n");
3487 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
3489 + INIT_WORK(&core_if->w_conn_id, w_conn_id_status_change, core_if);
3490 + INIT_WORK(&core_if->w_wkp, w_wakeup_detected, core_if);
3494 + INIT_WORK(&core_if->w_conn_id, w_conn_id_status_change);
3495 + INIT_DELAYED_WORK(&core_if->w_wkp, w_wakeup_detected);
3502 + * This function frees the structures allocated by dwc_otg_cil_init().
3504 + * @param[in] core_if The core interface pointer returned from
3505 + * dwc_otg_cil_init().
3508 +void dwc_otg_cil_remove(dwc_otg_core_if_t *core_if)
3510 + /* Disable all interrupts */
3511 + dwc_modify_reg32(&core_if->core_global_regs->gahbcfg, 1, 0);
3512 + dwc_write_reg32(&core_if->core_global_regs->gintmsk, 0);
3514 + if (core_if->wq_otg) {
3515 + destroy_workqueue(core_if->wq_otg);
3517 + if (core_if->dev_if) {
3518 + kfree(core_if->dev_if);
3520 + if (core_if->host_if) {
3521 + kfree(core_if->host_if);
3527 + * This function enables the controller's Global Interrupt in the AHB Config
3530 + * @param[in] core_if Programming view of DWC_otg controller.
3532 +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t *core_if)
3534 + gahbcfg_data_t ahbcfg = { .d32 = 0};
3535 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
3536 + dwc_modify_reg32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
3540 + * This function disables the controller's Global Interrupt in the AHB Config
3543 + * @param[in] core_if Programming view of DWC_otg controller.
3545 +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t *core_if)
3547 + gahbcfg_data_t ahbcfg = { .d32 = 0};
3548 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
3549 + dwc_modify_reg32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
3553 + * This function initializes the commmon interrupts, used in both
3554 + * device and host modes.
3556 + * @param[in] core_if Programming view of the DWC_otg controller
3559 +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t *core_if)
3561 + dwc_otg_core_global_regs_t *global_regs =
3562 + core_if->core_global_regs;
3563 + gintmsk_data_t intr_mask = { .d32 = 0};
3565 + /* Clear any pending OTG Interrupts */
3566 + dwc_write_reg32(&global_regs->gotgint, 0xFFFFFFFF);
3568 + /* Clear any pending interrupts */
3569 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
3572 + * Enable the interrupts in the GINTMSK.
3574 + intr_mask.b.modemismatch = 1;
3575 + intr_mask.b.otgintr = 1;
3577 + if (!core_if->dma_enable) {
3578 + intr_mask.b.rxstsqlvl = 1;
3581 + intr_mask.b.conidstschng = 1;
3582 + intr_mask.b.wkupintr = 1;
3583 + intr_mask.b.disconnect = 1;
3584 + intr_mask.b.usbsuspend = 1;
3585 + intr_mask.b.sessreqintr = 1;
3586 + dwc_write_reg32(&global_regs->gintmsk, intr_mask.d32);
3590 + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
3593 +static void init_fslspclksel(dwc_otg_core_if_t *core_if)
3598 + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
3599 + (core_if->hwcfg2.b.fs_phy_type == 1) &&
3600 + (core_if->core_params->ulpi_fs_ls)) ||
3601 + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
3602 + /* Full speed PHY */
3603 + val = DWC_HCFG_48_MHZ;
3606 + /* High speed PHY running at full speed or high speed */
3607 + val = DWC_HCFG_30_60_MHZ;
3610 + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
3611 + hcfg.d32 = dwc_read_reg32(&core_if->host_if->host_global_regs->hcfg);
3612 + hcfg.b.fslspclksel = val;
3613 + dwc_write_reg32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
3617 + * Initializes the DevSpd field of the DCFG register depending on the PHY type
3618 + * and the enumeration speed of the device.
3620 +static void init_devspd(dwc_otg_core_if_t *core_if)
3625 + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
3626 + (core_if->hwcfg2.b.fs_phy_type == 1) &&
3627 + (core_if->core_params->ulpi_fs_ls)) ||
3628 + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
3629 + /* Full speed PHY */
3632 + else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
3633 + /* High speed PHY running at full speed */
3637 + /* High speed PHY running at high speed */
3641 + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
3643 + dcfg.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dcfg);
3644 + dcfg.b.devspd = val;
3645 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
3649 + * This function calculates the number of IN EPS
3650 + * using GHWCFG1 and GHWCFG2 registers values
3652 + * @param core_if Programming view of the DWC_otg controller
3654 +static uint32_t calc_num_in_eps(dwc_otg_core_if_t *core_if)
3656 + uint32_t num_in_eps = 0;
3657 + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
3658 + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
3659 + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
3663 + for(i = 0; i < num_eps; ++i)
3665 + if(!(hwcfg1 & 0x1))
3671 + if(core_if->hwcfg4.b.ded_fifo_en) {
3672 + num_in_eps = (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
3675 + return num_in_eps;
3680 + * This function calculates the number of OUT EPS
3681 + * using GHWCFG1 and GHWCFG2 registers values
3683 + * @param core_if Programming view of the DWC_otg controller
3685 +static uint32_t calc_num_out_eps(dwc_otg_core_if_t *core_if)
3687 + uint32_t num_out_eps = 0;
3688 + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
3689 + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
3692 + for(i = 0; i < num_eps; ++i)
3694 + if(!(hwcfg1 & 0x2))
3699 + return num_out_eps;
3702 + * This function initializes the DWC_otg controller registers and
3703 + * prepares the core for device mode or host mode operation.
3705 + * @param core_if Programming view of the DWC_otg controller
3708 +void dwc_otg_core_init(dwc_otg_core_if_t *core_if)
3711 + dwc_otg_core_global_regs_t *global_regs =
3712 + core_if->core_global_regs;
3713 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
3714 + gahbcfg_data_t ahbcfg = { .d32 = 0 };
3715 + gusbcfg_data_t usbcfg = { .d32 = 0 };
3716 + gi2cctl_data_t i2cctl = { .d32 = 0 };
3718 + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p)\n", core_if);
3720 + /* Common Initialization */
3722 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3724 +// usbcfg.b.tx_end_delay = 1;
3725 + /* Program the ULPI External VBUS bit if needed */
3726 + usbcfg.b.ulpi_ext_vbus_drv =
3727 + (core_if->core_params->phy_ulpi_ext_vbus == DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
3729 + /* Set external TS Dline pulsing */
3730 + usbcfg.b.term_sel_dl_pulse = (core_if->core_params->ts_dline == 1) ? 1 : 0;
3731 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
3734 + /* Reset the Controller */
3735 + dwc_otg_core_reset(core_if);
3737 + /* Initialize parameters from Hardware configuration registers. */
3738 + dev_if->num_in_eps = calc_num_in_eps(core_if);
3739 + dev_if->num_out_eps = calc_num_out_eps(core_if);
3742 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n", core_if->hwcfg4.b.num_dev_perio_in_ep);
3744 + for (i=0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++)
3746 + dev_if->perio_tx_fifo_size[i] =
3747 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
3748 + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
3749 + i, dev_if->perio_tx_fifo_size[i]);
3752 + for (i=0; i < core_if->hwcfg4.b.num_in_eps; i++)
3754 + dev_if->tx_fifo_size[i] =
3755 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
3756 + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
3757 + i, dev_if->perio_tx_fifo_size[i]);
3760 + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
3761 + core_if->rx_fifo_size =
3762 + dwc_read_reg32(&global_regs->grxfsiz);
3763 + core_if->nperio_tx_fifo_size =
3764 + dwc_read_reg32(&global_regs->gnptxfsiz) >> 16;
3766 + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
3767 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
3768 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n", core_if->nperio_tx_fifo_size);
3770 + /* This programming sequence needs to happen in FS mode before any other
3771 + * programming occurs */
3772 + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
3773 + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
3774 + /* If FS mode with FS PHY */
3776 + /* core_init() is now called on every switch so only call the
3777 + * following for the first time through. */
3778 + if (!core_if->phy_init_done) {
3779 + core_if->phy_init_done = 1;
3780 + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
3781 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3782 + usbcfg.b.physel = 1;
3783 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
3785 + /* Reset after a PHY select */
3786 + dwc_otg_core_reset(core_if);
3789 + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
3790 + * do this on HNP Dev/Host mode switches (done in dev_init and
3792 + if (dwc_otg_is_host_mode(core_if)) {
3793 + init_fslspclksel(core_if);
3796 + init_devspd(core_if);
3799 + if (core_if->core_params->i2c_enable) {
3800 + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
3801 + /* Program GUSBCFG.OtgUtmifsSel to I2C */
3802 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3803 + usbcfg.b.otgutmifssel = 1;
3804 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
3806 + /* Program GI2CCTL.I2CEn */
3807 + i2cctl.d32 = dwc_read_reg32(&global_regs->gi2cctl);
3808 + i2cctl.b.i2cdevaddr = 1;
3809 + i2cctl.b.i2cen = 0;
3810 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
3811 + i2cctl.b.i2cen = 1;
3812 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
3815 + } /* endif speed == DWC_SPEED_PARAM_FULL */
3818 + /* High speed PHY. */
3819 + if (!core_if->phy_init_done) {
3820 + core_if->phy_init_done = 1;
3821 + /* HS PHY parameters. These parameters are preserved
3822 + * during soft reset so only program the first time. Do
3823 + * a soft reset immediately after setting phyif. */
3824 + usbcfg.b.ulpi_utmi_sel = core_if->core_params->phy_type;
3825 + if (usbcfg.b.ulpi_utmi_sel == 1) {
3826 + /* ULPI interface */
3827 + usbcfg.b.phyif = 0;
3828 + usbcfg.b.ddrsel = core_if->core_params->phy_ulpi_ddr;
3831 + /* UTMI+ interface */
3832 + if (core_if->core_params->phy_utmi_width == 16) {
3833 + usbcfg.b.phyif = 1;
3836 + usbcfg.b.phyif = 0;
3840 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3842 + /* Reset after setting the PHY parameters */
3843 + dwc_otg_core_reset(core_if);
3847 + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
3848 + (core_if->hwcfg2.b.fs_phy_type == 1) &&
3849 + (core_if->core_params->ulpi_fs_ls)) {
3850 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
3851 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3852 + usbcfg.b.ulpi_fsls = 1;
3853 + usbcfg.b.ulpi_clk_sus_m = 1;
3854 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3857 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3858 + usbcfg.b.ulpi_fsls = 0;
3859 + usbcfg.b.ulpi_clk_sus_m = 0;
3860 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3863 + /* Program the GAHBCFG Register.*/
3864 + switch (core_if->hwcfg2.b.architecture) {
3866 + case DWC_SLAVE_ONLY_ARCH:
3867 + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
3868 + ahbcfg.b.nptxfemplvl_txfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
3869 + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
3870 + core_if->dma_enable = 0;
3871 + core_if->dma_desc_enable = 0;
3874 + case DWC_EXT_DMA_ARCH:
3875 + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
3876 + ahbcfg.b.hburstlen = core_if->core_params->dma_burst_size;
3877 + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
3878 + core_if->dma_desc_enable = (core_if->core_params->dma_desc_enable != 0);
3881 + case DWC_INT_DMA_ARCH:
3882 + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
3883 + ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR;
3884 + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
3885 + core_if->dma_desc_enable = (core_if->core_params->dma_desc_enable != 0);
3889 + ahbcfg.b.dmaenable = core_if->dma_enable;
3890 + dwc_write_reg32(&global_regs->gahbcfg, ahbcfg.d32);
3892 + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
3894 + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
3895 + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
3896 + DWC_PRINT("Periodic Transfer Interrupt Enhancement - %s\n", ((core_if->pti_enh_enable) ? "enabled": "disabled"));
3897 + DWC_PRINT("Multiprocessor Interrupt Enhancement - %s\n", ((core_if->multiproc_int_enable) ? "enabled": "disabled"));
3900 + * Program the GUSBCFG register.
3902 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
3904 + switch (core_if->hwcfg2.b.op_mode) {
3905 + case DWC_MODE_HNP_SRP_CAPABLE:
3906 + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
3907 + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
3908 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3909 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3912 + case DWC_MODE_SRP_ONLY_CAPABLE:
3913 + usbcfg.b.hnpcap = 0;
3914 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3915 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3918 + case DWC_MODE_NO_HNP_SRP_CAPABLE:
3919 + usbcfg.b.hnpcap = 0;
3920 + usbcfg.b.srpcap = 0;
3923 + case DWC_MODE_SRP_CAPABLE_DEVICE:
3924 + usbcfg.b.hnpcap = 0;
3925 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3926 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3929 + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
3930 + usbcfg.b.hnpcap = 0;
3931 + usbcfg.b.srpcap = 0;
3934 + case DWC_MODE_SRP_CAPABLE_HOST:
3935 + usbcfg.b.hnpcap = 0;
3936 + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
3937 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
3940 + case DWC_MODE_NO_SRP_CAPABLE_HOST:
3941 + usbcfg.b.hnpcap = 0;
3942 + usbcfg.b.srpcap = 0;
3946 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
3948 + /* Enable common interrupts */
3949 + dwc_otg_enable_common_interrupts(core_if);
3951 + /* Do device or host intialization based on mode during PCD
3952 + * and HCD initialization */
3953 + if (dwc_otg_is_host_mode(core_if)) {
3954 + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
3955 + core_if->op_state = A_HOST;
3958 + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
3959 + core_if->op_state = B_PERIPHERAL;
3960 +#ifdef DWC_DEVICE_ONLY
3961 + dwc_otg_core_dev_init(core_if);
3968 + * This function enables the Device mode interrupts.
3970 + * @param core_if Programming view of DWC_otg controller
3972 +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *core_if)
3974 + gintmsk_data_t intr_mask = { .d32 = 0};
3975 + dwc_otg_core_global_regs_t *global_regs =
3976 + core_if->core_global_regs;
3978 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
3980 + /* Disable all interrupts. */
3981 + dwc_write_reg32(&global_regs->gintmsk, 0);
3983 + /* Clear any pending interrupts */
3984 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
3986 + /* Enable the common interrupts */
3987 + dwc_otg_enable_common_interrupts(core_if);
3989 + /* Enable interrupts */
3990 + intr_mask.b.usbreset = 1;
3991 + intr_mask.b.enumdone = 1;
3993 + if(!core_if->multiproc_int_enable) {
3994 + intr_mask.b.inepintr = 1;
3995 + intr_mask.b.outepintr = 1;
3998 + intr_mask.b.erlysuspend = 1;
4000 + if(core_if->en_multiple_tx_fifo == 0) {
4001 + intr_mask.b.epmismatch = 1;
4006 + if(core_if->dma_enable) {
4007 + if(core_if->dma_desc_enable == 0) {
4008 + if(core_if->pti_enh_enable) {
4009 + dctl_data_t dctl = { .d32 = 0 };
4010 + dctl.b.ifrmnum = 1;
4011 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
4013 + intr_mask.b.incomplisoin = 1;
4014 + intr_mask.b.incomplisoout = 1;
4018 + intr_mask.b.incomplisoin = 1;
4019 + intr_mask.b.incomplisoout = 1;
4021 +#endif // DWC_EN_ISOC
4023 +/** @todo NGS: Should this be a module parameter? */
4024 +#ifdef USE_PERIODIC_EP
4025 + intr_mask.b.isooutdrop = 1;
4026 + intr_mask.b.eopframe = 1;
4027 + intr_mask.b.incomplisoin = 1;
4028 + intr_mask.b.incomplisoout = 1;
4031 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
4033 + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
4034 + dwc_read_reg32(&global_regs->gintmsk));
4038 + * This function initializes the DWC_otg controller registers for
4041 + * @param core_if Programming view of DWC_otg controller
4044 +void dwc_otg_core_dev_init(dwc_otg_core_if_t *core_if)
4047 + u_int32_t *default_value_array;
4049 + dwc_otg_core_global_regs_t *global_regs =
4050 + core_if->core_global_regs;
4051 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
4052 + dwc_otg_core_params_t *params = core_if->core_params;
4053 + dcfg_data_t dcfg = { .d32 = 0};
4054 + grstctl_t resetctl = { .d32 = 0 };
4055 + uint32_t rx_fifo_size;
4056 + fifosize_data_t nptxfifosize;
4057 + fifosize_data_t txfifosize;
4058 + dthrctl_data_t dthrctl;
4060 + /* Restart the Phy Clock */
4061 + dwc_write_reg32(core_if->pcgcctl, 0);
4063 + /* Device configuration register */
4064 + init_devspd(core_if);
4065 + dcfg.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dcfg);
4066 + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
4067 + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
4069 + dwc_write_reg32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
4071 + /* Configure data FIFO sizes */
4072 + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
4073 + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n", core_if->total_fifo_size);
4074 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n", params->dev_rx_fifo_size);
4075 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n", params->dev_nperio_tx_fifo_size);
4078 + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
4079 + dwc_read_reg32(&global_regs->grxfsiz));
4081 + rx_fifo_size = params->dev_rx_fifo_size;
4082 + dwc_write_reg32(&global_regs->grxfsiz, rx_fifo_size);
4084 + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
4085 + dwc_read_reg32(&global_regs->grxfsiz));
4087 + /** Set Periodic Tx FIFO Mask all bits 0 */
4088 + core_if->p_tx_msk = 0;
4090 + /** Set Tx FIFO Mask all bits 0 */
4091 + core_if->tx_msk = 0;
4093 + /* Non-periodic Tx FIFO */
4094 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
4095 + dwc_read_reg32(&global_regs->gnptxfsiz));
4097 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
4098 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
4100 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
4102 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
4103 + dwc_read_reg32(&global_regs->gnptxfsiz));
4105 + txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
4106 + if(core_if->en_multiple_tx_fifo == 0) {
4107 + //core_if->hwcfg4.b.ded_fifo_en==0
4109 + /**@todo NGS: Fix Periodic FIFO Sizing! */
4111 + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
4112 + * Indexes of the FIFO size module parameters in the
4113 + * dev_perio_tx_fifo_size array and the FIFO size registers in
4114 + * the dptxfsiz array run from 0 to 14.
4116 + /** @todo Finish debug of this */
4117 + size=core_if->hwcfg4.b.num_dev_perio_in_ep;
4118 + default_value_array=params->dev_perio_tx_fifo_size;
4122 + //core_if->hwcfg4.b.ded_fifo_en==1
4124 + * Tx FIFOs These FIFOs are numbered from 1 to 15.
4125 + * Indexes of the FIFO size module parameters in the
4126 + * dev_tx_fifo_size array and the FIFO size registers in
4127 + * the dptxfsiz_dieptxf array run from 0 to 14.
4130 + size=core_if->hwcfg4.b.num_in_eps;
4131 + default_value_array=params->dev_tx_fifo_size;
4134 + for (i=0; i < size; i++)
4137 + txfifosize.b.depth = default_value_array[i];
4138 + DWC_DEBUGPL(DBG_CIL, "initial dptxfsiz_dieptxf[%d]=%08x\n", i,
4139 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
4140 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i],
4142 + DWC_DEBUGPL(DBG_CIL, "new dptxfsiz_dieptxf[%d]=%08x\n", i,
4143 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
4144 + txfifosize.b.startaddr += txfifosize.b.depth;
4147 + /* Flush the FIFOs */
4148 + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
4149 + dwc_otg_flush_rx_fifo(core_if);
4151 + /* Flush the Learning Queue. */
4152 + resetctl.b.intknqflsh = 1;
4153 + dwc_write_reg32(&core_if->core_global_regs->grstctl, resetctl.d32);
4155 + /* Clear all pending Device Interrupts */
4157 + if(core_if->multiproc_int_enable) {
4160 + /** @todo - if the condition needed to be checked
4161 + * or in any case all pending interrutps should be cleared?
4163 + if(core_if->multiproc_int_enable) {
4164 + for(i = 0; i < core_if->dev_if->num_in_eps; ++i) {
4165 + dwc_write_reg32(&dev_if->dev_global_regs->diepeachintmsk[i], 0);
4168 + for(i = 0; i < core_if->dev_if->num_out_eps; ++i) {
4169 + dwc_write_reg32(&dev_if->dev_global_regs->doepeachintmsk[i], 0);
4172 + dwc_write_reg32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
4173 + dwc_write_reg32(&dev_if->dev_global_regs->deachintmsk, 0);
4175 + dwc_write_reg32(&dev_if->dev_global_regs->diepmsk, 0);
4176 + dwc_write_reg32(&dev_if->dev_global_regs->doepmsk, 0);
4177 + dwc_write_reg32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
4178 + dwc_write_reg32(&dev_if->dev_global_regs->daintmsk, 0);
4181 + for (i=0; i <= dev_if->num_in_eps; i++)
4183 + depctl_data_t depctl;
4184 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
4185 + if (depctl.b.epena) {
4187 + depctl.b.epdis = 1;
4188 + depctl.b.snak = 1;
4194 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
4197 + dwc_write_reg32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
4198 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepdma, 0);
4199 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
4202 + for (i=0; i <= dev_if->num_out_eps; i++)
4204 + depctl_data_t depctl;
4205 + depctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doepctl);
4206 + if (depctl.b.epena) {
4208 + depctl.b.epdis = 1;
4209 + depctl.b.snak = 1;
4215 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
4217 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
4218 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepdma, 0);
4219 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
4222 + if(core_if->en_multiple_tx_fifo && core_if->dma_enable) {
4223 + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
4224 + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
4225 + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
4227 + dev_if->rx_thr_length = params->rx_thr_length;
4228 + dev_if->tx_thr_length = params->tx_thr_length;
4230 + dev_if->setup_desc_index = 0;
4233 + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
4234 + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
4235 + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
4236 + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
4237 + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
4239 + dwc_write_reg32(&dev_if->dev_global_regs->dtknqr3_dthrctl, dthrctl.d32);
4241 + 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",
4242 + 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);
4246 + dwc_otg_enable_device_interrupts(core_if);
4249 + diepmsk_data_t msk = { .d32 = 0 };
4250 + msk.b.txfifoundrn = 1;
4251 + if(core_if->multiproc_int_enable) {
4252 + dwc_modify_reg32(&dev_if->dev_global_regs->diepeachintmsk[0], msk.d32, msk.d32);
4254 + dwc_modify_reg32(&dev_if->dev_global_regs->diepmsk, msk.d32, msk.d32);
4259 + if(core_if->multiproc_int_enable) {
4260 + /* Set NAK on Babble */
4261 + dctl_data_t dctl = { .d32 = 0};
4262 + dctl.b.nakonbble = 1;
4263 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
4268 + * This function enables the Host mode interrupts.
4270 + * @param core_if Programming view of DWC_otg controller
4272 +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *core_if)
4274 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
4275 + gintmsk_data_t intr_mask = { .d32 = 0 };
4277 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
4279 + /* Disable all interrupts. */
4280 + dwc_write_reg32(&global_regs->gintmsk, 0);
4282 + /* Clear any pending interrupts. */
4283 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
4285 + /* Enable the common interrupts */
4286 + dwc_otg_enable_common_interrupts(core_if);
4289 + * Enable host mode interrupts without disturbing common
4292 + intr_mask.b.sofintr = 1;
4293 + intr_mask.b.portintr = 1;
4294 + intr_mask.b.hcintr = 1;
4296 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
4300 + * This function disables the Host Mode interrupts.
4302 + * @param core_if Programming view of DWC_otg controller
4304 +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *core_if)
4306 + dwc_otg_core_global_regs_t *global_regs =
4307 + core_if->core_global_regs;
4308 + gintmsk_data_t intr_mask = { .d32 = 0 };
4310 + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
4313 + * Disable host mode interrupts without disturbing common
4316 + intr_mask.b.sofintr = 1;
4317 + intr_mask.b.portintr = 1;
4318 + intr_mask.b.hcintr = 1;
4319 + intr_mask.b.ptxfempty = 1;
4320 + intr_mask.b.nptxfempty = 1;
4322 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
4326 + * This function initializes the DWC_otg controller registers for
4329 + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
4330 + * request queues. Host channels are reset to ensure that they are ready for
4331 + * performing transfers.
4333 + * @param core_if Programming view of DWC_otg controller
4336 +void dwc_otg_core_host_init(dwc_otg_core_if_t *core_if)
4338 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
4339 + dwc_otg_host_if_t *host_if = core_if->host_if;
4340 + dwc_otg_core_params_t *params = core_if->core_params;
4341 + hprt0_data_t hprt0 = { .d32 = 0 };
4342 + fifosize_data_t nptxfifosize;
4343 + fifosize_data_t ptxfifosize;
4345 + hcchar_data_t hcchar;
4347 + dwc_otg_hc_regs_t *hc_regs;
4349 + gotgctl_data_t gotgctl = { .d32 = 0 };
4351 + DWC_DEBUGPL(DBG_CILV,"%s(%p)\n", __func__, core_if);
4353 + /* Restart the Phy Clock */
4354 + dwc_write_reg32(core_if->pcgcctl, 0);
4356 + /* Initialize Host Configuration Register */
4357 + init_fslspclksel(core_if);
4358 + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL)
4360 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
4361 + hcfg.b.fslssupp = 1;
4362 + dwc_write_reg32(&host_if->host_global_regs->hcfg, hcfg.d32);
4365 + /* Configure data FIFO sizes */
4366 + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
4367 + DWC_DEBUGPL(DBG_CIL,"Total FIFO Size=%d\n", core_if->total_fifo_size);
4368 + DWC_DEBUGPL(DBG_CIL,"Rx FIFO Size=%d\n", params->host_rx_fifo_size);
4369 + DWC_DEBUGPL(DBG_CIL,"NP Tx FIFO Size=%d\n", params->host_nperio_tx_fifo_size);
4370 + DWC_DEBUGPL(DBG_CIL,"P Tx FIFO Size=%d\n", params->host_perio_tx_fifo_size);
4373 + DWC_DEBUGPL(DBG_CIL,"initial grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
4374 + dwc_write_reg32(&global_regs->grxfsiz, params->host_rx_fifo_size);
4375 + DWC_DEBUGPL(DBG_CIL,"new grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
4377 + /* Non-periodic Tx FIFO */
4378 + DWC_DEBUGPL(DBG_CIL,"initial gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
4379 + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
4380 + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
4381 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
4382 + DWC_DEBUGPL(DBG_CIL,"new gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
4384 + /* Periodic Tx FIFO */
4385 + DWC_DEBUGPL(DBG_CIL,"initial hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
4386 + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
4387 + ptxfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
4388 + dwc_write_reg32(&global_regs->hptxfsiz, ptxfifosize.d32);
4389 + DWC_DEBUGPL(DBG_CIL,"new hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
4392 + /* Clear Host Set HNP Enable in the OTG Control Register */
4393 + gotgctl.b.hstsethnpen = 1;
4394 + dwc_modify_reg32(&global_regs->gotgctl, gotgctl.d32, 0);
4396 + /* Make sure the FIFOs are flushed. */
4397 + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all Tx FIFOs */);
4398 + dwc_otg_flush_rx_fifo(core_if);
4400 + /* Flush out any leftover queued requests. */
4401 + num_channels = core_if->core_params->host_channels;
4402 + for (i = 0; i < num_channels; i++)
4404 + hc_regs = core_if->host_if->hc_regs[i];
4405 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4406 + hcchar.b.chen = 0;
4407 + hcchar.b.chdis = 1;
4408 + hcchar.b.epdir = 0;
4409 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
4412 + /* Halt all channels to put them into a known state. */
4413 + for (i = 0; i < num_channels; i++)
4416 + hc_regs = core_if->host_if->hc_regs[i];
4417 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4418 + hcchar.b.chen = 1;
4419 + hcchar.b.chdis = 1;
4420 + hcchar.b.epdir = 0;
4421 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
4422 + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d\n", __func__, i);
4424 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4425 + if (++count > 1000)
4427 + DWC_ERROR("%s: Unable to clear halt on channel %d\n",
4432 + while (hcchar.b.chen);
4435 + /* Turn on the vbus power. */
4436 + DWC_PRINT("Init: Port Power? op_state=%d\n", core_if->op_state);
4437 + if (core_if->op_state == A_HOST) {
4438 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
4439 + DWC_PRINT("Init: Power Port (%d)\n", hprt0.b.prtpwr);
4440 + if (hprt0.b.prtpwr == 0) {
4441 + hprt0.b.prtpwr = 1;
4442 + dwc_write_reg32(host_if->hprt0, hprt0.d32);
4446 + dwc_otg_enable_host_interrupts(core_if);
4450 + * Prepares a host channel for transferring packets to/from a specific
4451 + * endpoint. The HCCHARn register is set up with the characteristics specified
4452 + * in _hc. Host channel interrupts that may need to be serviced while this
4453 + * transfer is in progress are enabled.
4455 + * @param core_if Programming view of DWC_otg controller
4456 + * @param hc Information needed to initialize the host channel
4458 +void dwc_otg_hc_init(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4460 + uint32_t intr_enable;
4461 + hcintmsk_data_t hc_intr_mask;
4462 + gintmsk_data_t gintmsk = { .d32 = 0 };
4463 + hcchar_data_t hcchar;
4464 + hcsplt_data_t hcsplt;
4466 + uint8_t hc_num = hc->hc_num;
4467 + dwc_otg_host_if_t *host_if = core_if->host_if;
4468 + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
4470 + /* Clear old interrupt conditions for this host channel. */
4471 + hc_intr_mask.d32 = 0xFFFFFFFF;
4472 + hc_intr_mask.b.reserved = 0;
4473 + dwc_write_reg32(&hc_regs->hcint, hc_intr_mask.d32);
4475 + /* Enable channel interrupts required for this transfer. */
4476 + hc_intr_mask.d32 = 0;
4477 + hc_intr_mask.b.chhltd = 1;
4478 + if (core_if->dma_enable) {
4479 + hc_intr_mask.b.ahberr = 1;
4480 + if (hc->error_state && !hc->do_split &&
4481 + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
4482 + hc_intr_mask.b.ack = 1;
4483 + if (hc->ep_is_in) {
4484 + hc_intr_mask.b.datatglerr = 1;
4485 + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
4486 + hc_intr_mask.b.nak = 1;
4492 + switch (hc->ep_type) {
4493 + case DWC_OTG_EP_TYPE_CONTROL:
4494 + case DWC_OTG_EP_TYPE_BULK:
4495 + hc_intr_mask.b.xfercompl = 1;
4496 + hc_intr_mask.b.stall = 1;
4497 + hc_intr_mask.b.xacterr = 1;
4498 + hc_intr_mask.b.datatglerr = 1;
4499 + if (hc->ep_is_in) {
4500 + hc_intr_mask.b.bblerr = 1;
4503 + hc_intr_mask.b.nak = 1;
4504 + hc_intr_mask.b.nyet = 1;
4505 + if (hc->do_ping) {
4506 + hc_intr_mask.b.ack = 1;
4510 + if (hc->do_split) {
4511 + hc_intr_mask.b.nak = 1;
4512 + if (hc->complete_split) {
4513 + hc_intr_mask.b.nyet = 1;
4516 + hc_intr_mask.b.ack = 1;
4520 + if (hc->error_state) {
4521 + hc_intr_mask.b.ack = 1;
4524 + case DWC_OTG_EP_TYPE_INTR:
4525 + hc_intr_mask.b.xfercompl = 1;
4526 + hc_intr_mask.b.nak = 1;
4527 + hc_intr_mask.b.stall = 1;
4528 + hc_intr_mask.b.xacterr = 1;
4529 + hc_intr_mask.b.datatglerr = 1;
4530 + hc_intr_mask.b.frmovrun = 1;
4532 + if (hc->ep_is_in) {
4533 + hc_intr_mask.b.bblerr = 1;
4535 + if (hc->error_state) {
4536 + hc_intr_mask.b.ack = 1;
4538 + if (hc->do_split) {
4539 + if (hc->complete_split) {
4540 + hc_intr_mask.b.nyet = 1;
4543 + hc_intr_mask.b.ack = 1;
4547 + case DWC_OTG_EP_TYPE_ISOC:
4548 + hc_intr_mask.b.xfercompl = 1;
4549 + hc_intr_mask.b.frmovrun = 1;
4550 + hc_intr_mask.b.ack = 1;
4552 + if (hc->ep_is_in) {
4553 + hc_intr_mask.b.xacterr = 1;
4554 + hc_intr_mask.b.bblerr = 1;
4559 + dwc_write_reg32(&hc_regs->hcintmsk, hc_intr_mask.d32);
4561 +// if(hc->ep_type == DWC_OTG_EP_TYPE_BULK && !hc->ep_is_in)
4562 +// hc->max_packet = 512;
4563 + /* Enable the top level host channel interrupt. */
4564 + intr_enable = (1 << hc_num);
4565 + dwc_modify_reg32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
4567 + /* Make sure host channel interrupts are enabled. */
4568 + gintmsk.b.hcintr = 1;
4569 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
4572 + * Program the HCCHARn register with the endpoint characteristics for
4573 + * the current transfer.
4576 + hcchar.b.devaddr = hc->dev_addr;
4577 + hcchar.b.epnum = hc->ep_num;
4578 + hcchar.b.epdir = hc->ep_is_in;
4579 + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
4580 + hcchar.b.eptype = hc->ep_type;
4581 + hcchar.b.mps = hc->max_packet;
4583 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
4585 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
4586 + DWC_DEBUGPL(DBG_HCDV, " Dev Addr: %d\n", hcchar.b.devaddr);
4587 + DWC_DEBUGPL(DBG_HCDV, " Ep Num: %d\n", hcchar.b.epnum);
4588 + DWC_DEBUGPL(DBG_HCDV, " Is In: %d\n", hcchar.b.epdir);
4589 + DWC_DEBUGPL(DBG_HCDV, " Is Low Speed: %d\n", hcchar.b.lspddev);
4590 + DWC_DEBUGPL(DBG_HCDV, " Ep Type: %d\n", hcchar.b.eptype);
4591 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
4592 + DWC_DEBUGPL(DBG_HCDV, " Multi Cnt: %d\n", hcchar.b.multicnt);
4595 + * Program the HCSPLIT register for SPLITs
4598 + if (hc->do_split) {
4599 + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n", hc->hc_num,
4600 + hc->complete_split ? "CSPLIT" : "SSPLIT");
4601 + hcsplt.b.compsplt = hc->complete_split;
4602 + hcsplt.b.xactpos = hc->xact_pos;
4603 + hcsplt.b.hubaddr = hc->hub_addr;
4604 + hcsplt.b.prtaddr = hc->port_addr;
4605 + DWC_DEBUGPL(DBG_HCDV, " comp split %d\n", hc->complete_split);
4606 + DWC_DEBUGPL(DBG_HCDV, " xact pos %d\n", hc->xact_pos);
4607 + DWC_DEBUGPL(DBG_HCDV, " hub addr %d\n", hc->hub_addr);
4608 + DWC_DEBUGPL(DBG_HCDV, " port addr %d\n", hc->port_addr);
4609 + DWC_DEBUGPL(DBG_HCDV, " is_in %d\n", hc->ep_is_in);
4610 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
4611 + DWC_DEBUGPL(DBG_HCDV, " xferlen: %d\n", hc->xfer_len);
4613 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
4618 + * Attempts to halt a host channel. This function should only be called in
4619 + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
4620 + * normal circumstances in DMA mode, the controller halts the channel when the
4621 + * transfer is complete or a condition occurs that requires application
4624 + * In slave mode, checks for a free request queue entry, then sets the Channel
4625 + * Enable and Channel Disable bits of the Host Channel Characteristics
4626 + * register of the specified channel to intiate the halt. If there is no free
4627 + * request queue entry, sets only the Channel Disable bit of the HCCHARn
4628 + * register to flush requests for this channel. In the latter case, sets a
4629 + * flag to indicate that the host channel needs to be halted when a request
4630 + * queue slot is open.
4632 + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
4633 + * HCCHARn register. The controller ensures there is space in the request
4634 + * queue before submitting the halt request.
4636 + * Some time may elapse before the core flushes any posted requests for this
4637 + * host channel and halts. The Channel Halted interrupt handler completes the
4638 + * deactivation of the host channel.
4640 + * @param core_if Controller register interface.
4641 + * @param hc Host channel to halt.
4642 + * @param halt_status Reason for halting the channel.
4644 +void dwc_otg_hc_halt(dwc_otg_core_if_t *core_if,
4646 + dwc_otg_halt_status_e halt_status)
4648 + gnptxsts_data_t nptxsts;
4649 + hptxsts_data_t hptxsts;
4650 + hcchar_data_t hcchar;
4651 + dwc_otg_hc_regs_t *hc_regs;
4652 + dwc_otg_core_global_regs_t *global_regs;
4653 + dwc_otg_host_global_regs_t *host_global_regs;
4655 + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4656 + global_regs = core_if->core_global_regs;
4657 + host_global_regs = core_if->host_if->host_global_regs;
4659 + WARN_ON(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS);
4661 + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
4662 + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
4664 + * Disable all channel interrupts except Ch Halted. The QTD
4665 + * and QH state associated with this transfer has been cleared
4666 + * (in the case of URB_DEQUEUE), so the channel needs to be
4667 + * shut down carefully to prevent crashes.
4669 + hcintmsk_data_t hcintmsk;
4671 + hcintmsk.b.chhltd = 1;
4672 + dwc_write_reg32(&hc_regs->hcintmsk, hcintmsk.d32);
4675 + * Make sure no other interrupts besides halt are currently
4676 + * pending. Handling another interrupt could cause a crash due
4677 + * to the QTD and QH state.
4679 + dwc_write_reg32(&hc_regs->hcint, ~hcintmsk.d32);
4682 + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
4683 + * even if the channel was already halted for some other
4686 + hc->halt_status = halt_status;
4688 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4689 + if (hcchar.b.chen == 0) {
4691 + * The channel is either already halted or it hasn't
4692 + * started yet. In DMA mode, the transfer may halt if
4693 + * it finishes normally or a condition occurs that
4694 + * requires driver intervention. Don't want to halt
4695 + * the channel again. In either Slave or DMA mode,
4696 + * it's possible that the transfer has been assigned
4697 + * to a channel, but not started yet when an URB is
4698 + * dequeued. Don't want to halt a channel that hasn't
4705 + if (hc->halt_pending) {
4707 + * A halt has already been issued for this channel. This might
4708 + * happen when a transfer is aborted by a higher level in
4712 + DWC_PRINT("*** %s: Channel %d, _hc->halt_pending already set ***\n",
4713 + __func__, hc->hc_num);
4715 +/* dwc_otg_dump_global_registers(core_if); */
4716 +/* dwc_otg_dump_host_registers(core_if); */
4721 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4722 + hcchar.b.chen = 1;
4723 + hcchar.b.chdis = 1;
4725 + if (!core_if->dma_enable) {
4726 + /* Check for space in the request queue to issue the halt. */
4727 + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
4728 + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
4729 + nptxsts.d32 = dwc_read_reg32(&global_regs->gnptxsts);
4730 + if (nptxsts.b.nptxqspcavail == 0) {
4731 + hcchar.b.chen = 0;
4735 + hptxsts.d32 = dwc_read_reg32(&host_global_regs->hptxsts);
4736 + if ((hptxsts.b.ptxqspcavail == 0) || (core_if->queuing_high_bandwidth)) {
4737 + hcchar.b.chen = 0;
4742 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
4744 + hc->halt_status = halt_status;
4746 + if (hcchar.b.chen) {
4747 + hc->halt_pending = 1;
4748 + hc->halt_on_queue = 0;
4751 + hc->halt_on_queue = 1;
4754 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
4755 + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
4756 + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
4757 + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
4758 + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
4764 + * Clears the transfer state for a host channel. This function is normally
4765 + * called after a transfer is done and the host channel is being released.
4767 + * @param core_if Programming view of DWC_otg controller.
4768 + * @param hc Identifies the host channel to clean up.
4770 +void dwc_otg_hc_cleanup(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4772 + dwc_otg_hc_regs_t *hc_regs;
4774 + hc->xfer_started = 0;
4777 + * Clear channel interrupt enables and any unhandled channel interrupt
4780 + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4781 + dwc_write_reg32(&hc_regs->hcintmsk, 0);
4782 + dwc_write_reg32(&hc_regs->hcint, 0xFFFFFFFF);
4785 + del_timer(&core_if->hc_xfer_timer[hc->hc_num]);
4787 + hcchar_data_t hcchar;
4788 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
4789 + if (hcchar.b.chdis) {
4790 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
4791 + __func__, hc->hc_num, hcchar.d32);
4798 + * Sets the channel property that indicates in which frame a periodic transfer
4799 + * should occur. This is always set to the _next_ frame. This function has no
4800 + * effect on non-periodic transfers.
4802 + * @param core_if Programming view of DWC_otg controller.
4803 + * @param hc Identifies the host channel to set up and its properties.
4804 + * @param hcchar Current value of the HCCHAR register for the specified host
4807 +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t *core_if,
4809 + hcchar_data_t *hcchar)
4811 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
4812 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4813 + hfnum_data_t hfnum;
4814 + hfnum.d32 = dwc_read_reg32(&core_if->host_if->host_global_regs->hfnum);
4816 + /* 1 if _next_ frame is odd, 0 if it's even */
4817 + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
4819 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split && !hc->complete_split) {
4820 + switch (hfnum.b.frnum & 0x7) {
4822 + core_if->hfnum_7_samples++;
4823 + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
4826 + core_if->hfnum_0_samples++;
4827 + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
4830 + core_if->hfnum_other_samples++;
4831 + core_if->hfnum_other_frrem_accum += hfnum.b.frrem;
4840 +static void hc_xfer_timeout(unsigned long ptr)
4842 + hc_xfer_info_t *xfer_info = (hc_xfer_info_t *)ptr;
4843 + int hc_num = xfer_info->hc->hc_num;
4844 + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
4845 + DWC_WARN(" start_hcchar_val 0x%08x\n", xfer_info->core_if->start_hcchar_val[hc_num]);
4850 + * This function does the setup for a data transfer for a host channel and
4851 + * starts the transfer. May be called in either Slave mode or DMA mode. In
4852 + * Slave mode, the caller must ensure that there is sufficient space in the
4853 + * request queue and Tx Data FIFO.
4855 + * For an OUT transfer in Slave mode, it loads a data packet into the
4856 + * appropriate FIFO. If necessary, additional data packets will be loaded in
4859 + * For an IN transfer in Slave mode, a data packet is requested. The data
4860 + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
4861 + * additional data packets are requested in the Host ISR.
4863 + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
4864 + * register along with a packet count of 1 and the channel is enabled. This
4865 + * causes a single PING transaction to occur. Other fields in HCTSIZ are
4866 + * simply set to 0 since no data transfer occurs in this case.
4868 + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
4869 + * all the information required to perform the subsequent data transfer. In
4870 + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
4871 + * controller performs the entire PING protocol, then starts the data
4874 + * @param core_if Programming view of DWC_otg controller.
4875 + * @param hc Information needed to initialize the host channel. The xfer_len
4876 + * value may be reduced to accommodate the max widths of the XferSize and
4877 + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
4878 + * to reflect the final xfer_len value.
4880 +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
4882 + hcchar_data_t hcchar;
4883 + hctsiz_data_t hctsiz;
4884 + uint16_t num_packets;
4885 + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
4886 + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
4887 + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
4891 + if (hc->do_ping) {
4892 + if (!core_if->dma_enable) {
4893 + dwc_otg_hc_do_ping(core_if, hc);
4894 + hc->xfer_started = 1;
4898 + hctsiz.b.dopng = 1;
4902 + if (hc->do_split) {
4905 + if (hc->complete_split && !hc->ep_is_in) {
4906 + /* For CSPLIT OUT Transfer, set the size to 0 so the
4907 + * core doesn't expect any data written to the FIFO */
4910 + else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
4911 + hc->xfer_len = hc->max_packet;
4913 + else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
4914 + hc->xfer_len = 188;
4917 + hctsiz.b.xfersize = hc->xfer_len;
4921 + * Ensure that the transfer length and packet count will fit
4922 + * in the widths allocated for them in the HCTSIZn register.
4924 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
4925 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4927 + * Make sure the transfer size is no larger than one
4928 + * (micro)frame's worth of data. (A check was done
4929 + * when the periodic transfer was accepted to ensure
4930 + * that a (micro)frame's worth of data can be
4931 + * programmed into a channel.)
4933 + uint32_t max_periodic_len = hc->multi_count * hc->max_packet;
4934 + if (hc->xfer_len > max_periodic_len) {
4935 + hc->xfer_len = max_periodic_len;
4940 + else if (hc->xfer_len > max_hc_xfer_size) {
4941 + /* Make sure that xfer_len is a multiple of max packet size. */
4942 + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
4945 + if (hc->xfer_len > 0) {
4946 + num_packets = (hc->xfer_len + hc->max_packet - 1) / hc->max_packet;
4947 + if (num_packets > max_hc_pkt_count) {
4948 + num_packets = max_hc_pkt_count;
4949 + hc->xfer_len = num_packets * hc->max_packet;
4953 + /* Need 1 packet for transfer length of 0. */
4958 +//host testusb item 10, would do series of Control transfer
4959 +//with URB_SHORT_NOT_OK set in transfer_flags ,
4960 +//changing the xfer_len would cause the test fail
4961 + if (hc->ep_is_in) {
4962 + /* Always program an integral # of max packets for IN transfers. */
4963 + hc->xfer_len = num_packets * hc->max_packet;
4967 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
4968 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4970 + * Make sure that the multi_count field matches the
4971 + * actual transfer length.
4973 + hc->multi_count = num_packets;
4976 + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
4977 + /* Set up the initial PID for the transfer. */
4978 + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
4979 + if (hc->ep_is_in) {
4980 + if (hc->multi_count == 1) {
4981 + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
4983 + else if (hc->multi_count == 2) {
4984 + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
4987 + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
4991 + if (hc->multi_count == 1) {
4992 + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
4995 + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
5000 + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
5004 + hctsiz.b.xfersize = hc->xfer_len;
5007 + hc->start_pkt_count = num_packets;
5008 + hctsiz.b.pktcnt = num_packets;
5009 + hctsiz.b.pid = hc->data_pid_start;
5010 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
5012 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
5013 + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
5014 + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
5015 + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
5017 + if (core_if->dma_enable) {
5018 + dwc_write_reg32(&hc_regs->hcdma, (uint32_t)hc->xfer_buff);
5021 + /* Start the split */
5022 + if (hc->do_split) {
5023 + hcsplt_data_t hcsplt;
5024 + hcsplt.d32 = dwc_read_reg32 (&hc_regs->hcsplt);
5025 + hcsplt.b.spltena = 1;
5026 + dwc_write_reg32(&hc_regs->hcsplt, hcsplt.d32);
5029 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
5030 + hcchar.b.multicnt = hc->multi_count;
5031 + hc_set_even_odd_frame(core_if, hc, &hcchar);
5033 + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
5034 + if (hcchar.b.chdis) {
5035 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
5036 + __func__, hc->hc_num, hcchar.d32);
5040 + /* Set host channel enable after all other setup is complete. */
5041 + hcchar.b.chen = 1;
5042 + hcchar.b.chdis = 0;
5043 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
5045 + hc->xfer_started = 1;
5048 + if (!core_if->dma_enable &&
5049 + !hc->ep_is_in && hc->xfer_len > 0) {
5050 + /* Load OUT packet into the appropriate Tx FIFO. */
5051 + dwc_otg_hc_write_packet(core_if, hc);
5055 + /* Start a timer for this transfer. */
5056 + core_if->hc_xfer_timer[hc->hc_num].function = hc_xfer_timeout;
5057 + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
5058 + core_if->hc_xfer_info[hc->hc_num].hc = hc;
5059 + core_if->hc_xfer_timer[hc->hc_num].data = (unsigned long)(&core_if->hc_xfer_info[hc->hc_num]);
5060 + core_if->hc_xfer_timer[hc->hc_num].expires = jiffies + (HZ*10);
5061 + add_timer(&core_if->hc_xfer_timer[hc->hc_num]);
5066 + * This function continues a data transfer that was started by previous call
5067 + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
5068 + * sufficient space in the request queue and Tx Data FIFO. This function
5069 + * should only be called in Slave mode. In DMA mode, the controller acts
5070 + * autonomously to complete transfers programmed to a host channel.
5072 + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
5073 + * if there is any data remaining to be queued. For an IN transfer, another
5074 + * data packet is always requested. For the SETUP phase of a control transfer,
5075 + * this function does nothing.
5077 + * @return 1 if a new request is queued, 0 if no more requests are required
5078 + * for this transfer.
5080 +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
5082 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
5084 + if (hc->do_split) {
5085 + /* SPLITs always queue just once per channel */
5088 + else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
5089 + /* SETUPs are queued only once since they can't be NAKed. */
5092 + else if (hc->ep_is_in) {
5094 + * Always queue another request for other IN transfers. If
5095 + * back-to-back INs are issued and NAKs are received for both,
5096 + * the driver may still be processing the first NAK when the
5097 + * second NAK is received. When the interrupt handler clears
5098 + * the NAK interrupt for the first NAK, the second NAK will
5099 + * not be seen. So we can't depend on the NAK interrupt
5100 + * handler to requeue a NAKed request. Instead, IN requests
5101 + * are issued each time this function is called. When the
5102 + * transfer completes, the extra requests for the channel will
5105 + hcchar_data_t hcchar;
5106 + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
5108 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
5109 + hc_set_even_odd_frame(core_if, hc, &hcchar);
5110 + hcchar.b.chen = 1;
5111 + hcchar.b.chdis = 0;
5112 + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n", hcchar.d32);
5113 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
5118 + /* OUT transfers. */
5119 + if (hc->xfer_count < hc->xfer_len) {
5120 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
5121 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
5122 + hcchar_data_t hcchar;
5123 + dwc_otg_hc_regs_t *hc_regs;
5124 + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
5125 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
5126 + hc_set_even_odd_frame(core_if, hc, &hcchar);
5129 + /* Load OUT packet into the appropriate Tx FIFO. */
5130 + dwc_otg_hc_write_packet(core_if, hc);
5141 + * Starts a PING transfer. This function should only be called in Slave mode.
5142 + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
5144 +void dwc_otg_hc_do_ping(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
5146 + hcchar_data_t hcchar;
5147 + hctsiz_data_t hctsiz;
5148 + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
5150 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
5153 + hctsiz.b.dopng = 1;
5154 + hctsiz.b.pktcnt = 1;
5155 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
5157 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
5158 + hcchar.b.chen = 1;
5159 + hcchar.b.chdis = 0;
5160 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
5164 + * This function writes a packet into the Tx FIFO associated with the Host
5165 + * Channel. For a channel associated with a non-periodic EP, the non-periodic
5166 + * Tx FIFO is written. For a channel associated with a periodic EP, the
5167 + * periodic Tx FIFO is written. This function should only be called in Slave
5170 + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
5171 + * then number of bytes written to the Tx FIFO.
5173 +void dwc_otg_hc_write_packet(dwc_otg_core_if_t *core_if, dwc_hc_t *hc)
5176 + uint32_t remaining_count;
5177 + uint32_t byte_count;
5178 + uint32_t dword_count;
5180 + uint32_t *data_buff = (uint32_t *)(hc->xfer_buff);
5181 + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
5183 + remaining_count = hc->xfer_len - hc->xfer_count;
5184 + if (remaining_count > hc->max_packet) {
5185 + byte_count = hc->max_packet;
5188 + byte_count = remaining_count;
5191 + dword_count = (byte_count + 3) / 4;
5193 + if ((((unsigned long)data_buff) & 0x3) == 0) {
5194 + /* xfer_buff is DWORD aligned. */
5195 + for (i = 0; i < dword_count; i++, data_buff++)
5197 + dwc_write_reg32(data_fifo, *data_buff);
5201 + /* xfer_buff is not DWORD aligned. */
5202 + for (i = 0; i < dword_count; i++, data_buff++)
5204 + dwc_write_reg32(data_fifo, get_unaligned(data_buff));
5208 + hc->xfer_count += byte_count;
5209 + hc->xfer_buff += byte_count;
5213 + * Gets the current USB frame number. This is the frame number from the last
5216 +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *core_if)
5219 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
5221 + /* read current frame/microframe number from DSTS register */
5222 + return dsts.b.soffn;
5226 + * This function reads a setup packet from the Rx FIFO into the destination
5227 + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
5228 + * Interrupt routine when a SETUP packet has been received in Slave mode.
5230 + * @param core_if Programming view of DWC_otg controller.
5231 + * @param dest Destination buffer for packet data.
5233 +void dwc_otg_read_setup_packet(dwc_otg_core_if_t *core_if, uint32_t *dest)
5235 + /* Get the 8 bytes of a setup transaction data */
5237 + /* Pop 2 DWORDS off the receive data FIFO into memory */
5238 + dest[0] = dwc_read_reg32(core_if->data_fifo[0]);
5239 + dest[1] = dwc_read_reg32(core_if->data_fifo[0]);
5244 + * This function enables EP0 OUT to receive SETUP packets and configures EP0
5245 + * IN for transmitting packets. It is normally called when the
5246 + * "Enumeration Done" interrupt occurs.
5248 + * @param core_if Programming view of DWC_otg controller.
5249 + * @param ep The EP0 data.
5251 +void dwc_otg_ep0_activate(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5253 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
5255 + depctl_data_t diepctl;
5256 + depctl_data_t doepctl;
5257 + dctl_data_t dctl = { .d32 = 0 };
5259 + /* Read the Device Status and Endpoint 0 Control registers */
5260 + dsts.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dsts);
5261 + diepctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl);
5262 + doepctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl);
5264 + /* Set the MPS of the IN EP based on the enumeration speed */
5265 + switch (dsts.b.enumspd) {
5266 + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
5267 + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
5268 + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
5269 + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
5271 + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
5272 + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
5276 + dwc_write_reg32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
5278 + /* Enable OUT EP for receive */
5279 + doepctl.b.epena = 1;
5280 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
5283 + DWC_DEBUGPL(DBG_PCDV,"doepctl0=%0x\n",
5284 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
5285 + DWC_DEBUGPL(DBG_PCDV,"diepctl0=%0x\n",
5286 + dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl));
5288 + dctl.b.cgnpinnak = 1;
5290 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
5291 + DWC_DEBUGPL(DBG_PCDV,"dctl=%0x\n",
5292 + dwc_read_reg32(&dev_if->dev_global_regs->dctl));
5296 + * This function activates an EP. The Device EP control register for
5297 + * the EP is configured as defined in the ep structure. Note: This
5298 + * function is not used for EP0.
5300 + * @param core_if Programming view of DWC_otg controller.
5301 + * @param ep The EP to activate.
5303 +void dwc_otg_ep_activate(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5305 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
5306 + depctl_data_t depctl;
5307 + volatile uint32_t *addr;
5308 + daint_data_t daintmsk = { .d32 = 0 };
5310 + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
5311 + (ep->is_in?"IN":"OUT"));
5313 + /* Read DEPCTLn register */
5314 + if (ep->is_in == 1) {
5315 + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
5316 + daintmsk.ep.in = 1<<ep->num;
5319 + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
5320 + daintmsk.ep.out = 1<<ep->num;
5323 + /* If the EP is already active don't change the EP Control
5325 + depctl.d32 = dwc_read_reg32(addr);
5326 + if (!depctl.b.usbactep) {
5327 + depctl.b.mps = ep->maxpacket;
5328 + depctl.b.eptype = ep->type;
5329 + depctl.b.txfnum = ep->tx_fifo_num;
5331 + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
5332 + depctl.b.setd0pid = 1; // ???
5335 + depctl.b.setd0pid = 1;
5337 + depctl.b.usbactep = 1;
5339 + dwc_write_reg32(addr, depctl.d32);
5340 + DWC_DEBUGPL(DBG_PCDV,"DEPCTL(%.8x)=%08x\n",(u32)addr, dwc_read_reg32(addr));
5343 + /* Enable the Interrupt for this EP */
5344 + if(core_if->multiproc_int_enable) {
5345 + if (ep->is_in == 1) {
5346 + diepmsk_data_t diepmsk = { .d32 = 0};
5347 + diepmsk.b.xfercompl = 1;
5348 + diepmsk.b.timeout = 1;
5349 + diepmsk.b.epdisabled = 1;
5350 + diepmsk.b.ahberr = 1;
5351 + diepmsk.b.intknepmis = 1;
5352 + diepmsk.b.txfifoundrn = 1; //?????
5355 + if(core_if->dma_desc_enable) {
5356 + diepmsk.b.bna = 1;
5359 + if(core_if->dma_enable) {
5360 + doepmsk.b.nak = 1;
5363 + dwc_write_reg32(&dev_if->dev_global_regs->diepeachintmsk[ep->num], diepmsk.d32);
5366 + doepmsk_data_t doepmsk = { .d32 = 0};
5367 + doepmsk.b.xfercompl = 1;
5368 + doepmsk.b.ahberr = 1;
5369 + doepmsk.b.epdisabled = 1;
5372 + if(core_if->dma_desc_enable) {
5373 + doepmsk.b.bna = 1;
5376 + doepmsk.b.babble = 1;
5377 + doepmsk.b.nyet = 1;
5378 + doepmsk.b.nak = 1;
5380 + dwc_write_reg32(&dev_if->dev_global_regs->doepeachintmsk[ep->num], doepmsk.d32);
5382 + dwc_modify_reg32(&dev_if->dev_global_regs->deachintmsk,
5385 + dwc_modify_reg32(&dev_if->dev_global_regs->daintmsk,
5389 + DWC_DEBUGPL(DBG_PCDV,"DAINTMSK=%0x\n",
5390 + dwc_read_reg32(&dev_if->dev_global_regs->daintmsk));
5392 + ep->stall_clear_flag = 0;
5397 + * This function deactivates an EP. This is done by clearing the USB Active
5398 + * EP bit in the Device EP control register. Note: This function is not used
5399 + * for EP0. EP0 cannot be deactivated.
5401 + * @param core_if Programming view of DWC_otg controller.
5402 + * @param ep The EP to deactivate.
5404 +void dwc_otg_ep_deactivate(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5406 + depctl_data_t depctl = { .d32 = 0 };
5407 + volatile uint32_t *addr;
5408 + daint_data_t daintmsk = { .d32 = 0};
5410 + /* Read DEPCTLn register */
5411 + if (ep->is_in == 1) {
5412 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
5413 + daintmsk.ep.in = 1<<ep->num;
5416 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
5417 + daintmsk.ep.out = 1<<ep->num;
5420 + //disabled ep only when ep is enabled
5421 + //or got halt in the loop in test in cv9
5422 + depctl.d32=dwc_read_reg32(addr);
5423 + if(depctl.b.epena){
5424 + if (ep->is_in == 1) {
5425 + diepint_data_t diepint;
5426 + dwc_otg_dev_in_ep_regs_t *in_reg=core_if->dev_if->in_ep_regs[ep->num];
5429 + depctl.d32=dwc_read_reg32(&in_reg->diepctl);
5431 + dwc_write_reg32(&in_reg->diepctl,depctl.d32);
5433 + //wait for diepint.b.inepnakeff
5434 + diepint.d32=dwc_read_reg32(&in_reg->diepint);
5435 + while(!diepint.b.inepnakeff){
5437 + diepint.d32=dwc_read_reg32(&in_reg->diepint);
5440 + diepint.b.inepnakeff=1;
5441 + dwc_write_reg32(&in_reg->diepint,diepint.d32);
5443 + //set ep disable and snak
5444 + depctl.d32=dwc_read_reg32(&in_reg->diepctl);
5447 + dwc_write_reg32(&in_reg->diepctl,depctl.d32);
5449 + //wait for diepint.b.epdisabled
5450 + diepint.d32=dwc_read_reg32(&in_reg->diepint);
5451 + while(!diepint.b.epdisabled){
5453 + diepint.d32=dwc_read_reg32(&in_reg->diepint);
5456 + diepint.b.epdisabled=1;
5457 + dwc_write_reg32(&in_reg->diepint,diepint.d32);
5459 + //clear ep enable and disable bit
5460 + depctl.d32=dwc_read_reg32(&in_reg->diepctl);
5463 + dwc_write_reg32(&in_reg->diepctl,depctl.d32);
5467 +//following DWC OTG DataBook v2.72a, 6.4.2.1.3 Disabling an OUT Endpoint,
5468 +//but this doesn't work, the old code do.
5470 + doepint_data_t doepint;
5471 + dwc_otg_dev_out_ep_regs_t *out_reg=core_if->dev_if->out_ep_regs[ep->num];
5473 + gintsts_data_t gintsts;
5475 + //set dctl global out nak
5476 + dctl.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dctl);
5477 + dctl.b.sgoutnak=1;
5478 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->dctl,dctl.d32);
5480 + //wait for gintsts.goutnakeff
5481 + gintsts.d32=dwc_read_reg32(&core_if->core_global_regs->gintsts);
5482 + while(!gintsts.b.goutnakeff){
5484 + gintsts.d32=dwc_read_reg32(&core_if->core_global_regs->gintsts);
5487 + gintsts.b.goutnakeff=1;
5488 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
5490 + //set ep disable and snak
5491 + depctl.d32=dwc_read_reg32(&out_reg->doepctl);
5494 + dwc_write_reg32(&out_reg->doepctl,depctl.d32);
5496 + //wait for diepint.b.epdisabled
5497 + doepint.d32=dwc_read_reg32(&out_reg->doepint);
5498 + while(!doepint.b.epdisabled){
5500 + doepint.d32=dwc_read_reg32(&out_reg->doepint);
5503 + doepint.b.epdisabled=1;
5504 + dwc_write_reg32(&out_reg->doepint,doepint.d32);
5506 + //clear ep enable and disable bit
5507 + depctl.d32=dwc_read_reg32(&out_reg->doepctl);
5510 + dwc_write_reg32(&out_reg->doepctl,depctl.d32);
5515 + depctl.b.usbactep = 0;
5517 + if (ep->is_in == 0) {
5518 + if(core_if->dma_enable||core_if->dma_desc_enable)
5519 + depctl.b.epdis = 1;
5522 + dwc_write_reg32(addr, depctl.d32);
5525 + /* Disable the Interrupt for this EP */
5526 + if(core_if->multiproc_int_enable) {
5527 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->deachintmsk,
5530 + if (ep->is_in == 1) {
5531 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->diepeachintmsk[ep->num], 0);
5533 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[ep->num], 0);
5536 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->daintmsk,
5540 + if (ep->is_in == 1) {
5541 + DWC_DEBUGPL(DBG_PCD, "DIEPCTL(%.8x)=%08x DIEPTSIZ=%08x, DIEPINT=%.8x, DIEPDMA=%.8x, DTXFSTS=%.8x\n",
5542 + (u32)&core_if->dev_if->in_ep_regs[ep->num]->diepctl,
5543 + dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->diepctl),
5544 + dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz),
5545 + dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->diepint),
5546 + dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->diepdma),
5547 + dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts));
5548 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
5549 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk),
5550 + dwc_read_reg32(&core_if->core_global_regs->gintmsk));
5553 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL(%.8x)=%08x DOEPTSIZ=%08x, DOEPINT=%.8x, DOEPDMA=%.8x\n",
5554 + (u32)&core_if->dev_if->out_ep_regs[ep->num]->doepctl,
5555 + dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl),
5556 + dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz),
5557 + dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doepint),
5558 + dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doepdma));
5560 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
5561 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk),
5562 + dwc_read_reg32(&core_if->core_global_regs->gintmsk));
5568 + * This function does the setup for a data transfer for an EP and
5569 + * starts the transfer. For an IN transfer, the packets will be
5570 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
5571 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
5573 + * @param core_if Programming view of DWC_otg controller.
5574 + * @param ep The EP to start the transfer on.
5576 +static void init_dma_desc_chain(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5578 + dwc_otg_dma_desc_t* dma_desc;
5580 + uint32_t xfer_est;
5583 + ep->desc_cnt = ( ep->total_len / ep->maxxfer) +
5584 + ((ep->total_len % ep->maxxfer) ? 1 : 0);
5588 + dma_desc = ep->desc_addr;
5589 + xfer_est = ep->total_len;
5591 + for( i = 0; i < ep->desc_cnt; ++i) {
5592 + /** DMA Descriptor Setup */
5593 + if(xfer_est > ep->maxxfer) {
5594 + dma_desc->status.b.bs = BS_HOST_BUSY;
5595 + dma_desc->status.b.l = 0;
5596 + dma_desc->status.b.ioc = 0;
5597 + dma_desc->status.b.sp = 0;
5598 + dma_desc->status.b.bytes = ep->maxxfer;
5599 + dma_desc->buf = ep->dma_addr + offset;
5600 + dma_desc->status.b.bs = BS_HOST_READY;
5602 + xfer_est -= ep->maxxfer;
5603 + offset += ep->maxxfer;
5605 + dma_desc->status.b.bs = BS_HOST_BUSY;
5606 + dma_desc->status.b.l = 1;
5607 + dma_desc->status.b.ioc = 1;
5609 + dma_desc->status.b.sp = (xfer_est % ep->maxpacket) ?
5610 + 1 : ((ep->sent_zlp) ? 1 : 0);
5611 + dma_desc->status.b.bytes = xfer_est;
5613 + dma_desc->status.b.bytes = xfer_est + ((4 - (xfer_est & 0x3)) & 0x3) ;
5616 + dma_desc->buf = ep->dma_addr + offset;
5617 + dma_desc->status.b.bs = BS_HOST_READY;
5624 + * This function does the setup for a data transfer for an EP and
5625 + * starts the transfer. For an IN transfer, the packets will be
5626 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
5627 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
5629 + * @param core_if Programming view of DWC_otg controller.
5630 + * @param ep The EP to start the transfer on.
5633 +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5635 + depctl_data_t depctl;
5636 + deptsiz_data_t deptsiz;
5637 + gintmsk_data_t intr_mask = { .d32 = 0};
5639 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
5641 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
5642 + "xfer_buff=%p start_xfer_buff=%p\n",
5643 + ep->num, (ep->is_in?"IN":"OUT"), ep->xfer_len,
5644 + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
5647 + if (ep->is_in == 1) {
5648 + dwc_otg_dev_in_ep_regs_t *in_regs =
5649 + core_if->dev_if->in_ep_regs[ep->num];
5651 + gnptxsts_data_t gtxstatus;
5654 + dwc_read_reg32(&core_if->core_global_regs->gnptxsts);
5656 + if(core_if->en_multiple_tx_fifo == 0 && gtxstatus.b.nptxqspcavail == 0) {
5658 + DWC_PRINT("TX Queue Full (0x%0x)\n", gtxstatus.d32);
5663 + depctl.d32 = dwc_read_reg32(&(in_regs->diepctl));
5664 + deptsiz.d32 = dwc_read_reg32(&(in_regs->dieptsiz));
5666 + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
5667 + ep->maxxfer : (ep->total_len - ep->xfer_len);
5669 + /* Zero Length Packet? */
5670 + if ((ep->xfer_len - ep->xfer_count) == 0) {
5671 + deptsiz.b.xfersize = 0;
5672 + deptsiz.b.pktcnt = 1;
5675 + /* Program the transfer size and packet count
5676 + * as follows: xfersize = N * maxpacket +
5677 + * short_packet pktcnt = N + (short_packet
5680 + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
5681 + deptsiz.b.pktcnt =
5682 + (ep->xfer_len - ep->xfer_count - 1 + ep->maxpacket) /
5687 + /* Write the DMA register */
5688 + if (core_if->dma_enable) {
5689 + if (/*(core_if->dma_enable)&&*/(ep->dma_addr==DMA_ADDR_INVALID)) {
5690 + ep->dma_addr=dma_map_single(NULL,(void *)(ep->xfer_buff),(ep->xfer_len),DMA_TO_DEVICE);
5692 + DWC_DEBUGPL(DBG_PCDV, "ep%d dma_addr=%.8x\n", ep->num, ep->dma_addr);
5694 + if (core_if->dma_desc_enable == 0) {
5695 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5697 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
5698 + dwc_write_reg32 (&(in_regs->diepdma),
5699 + (uint32_t)ep->dma_addr);
5702 + init_dma_desc_chain(core_if, ep);
5703 + /** DIEPDMAn Register write */
5705 + VERIFY_PCD_DMA_ADDR(ep->dma_desc_addr);
5706 + dwc_write_reg32(&in_regs->diepdma, ep->dma_desc_addr);
5711 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5712 + if(ep->type != DWC_OTG_EP_TYPE_ISOC) {
5714 + * Enable the Non-Periodic Tx FIFO empty interrupt,
5715 + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
5716 + * the data will be written into the fifo by the ISR.
5718 + if(core_if->en_multiple_tx_fifo == 0) {
5719 + intr_mask.b.nptxfempty = 1;
5720 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
5721 + intr_mask.d32, intr_mask.d32);
5724 + /* Enable the Tx FIFO Empty Interrupt for this EP */
5725 + if(ep->xfer_len > 0) {
5726 + uint32_t fifoemptymsk = 0;
5727 + fifoemptymsk = 1 << ep->num;
5728 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
5736 + /* EP enable, IN data in FIFO */
5737 + depctl.b.cnak = 1;
5738 + depctl.b.epena = 1;
5739 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
5741 + depctl.d32 = dwc_read_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl);
5742 + depctl.b.nextep = ep->num;
5743 + dwc_write_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl, depctl.d32);
5745 + DWC_DEBUGPL(DBG_PCD, "DIEPCTL(%.8x)=%08x DIEPTSIZ=%08x, DIEPINT=%.8x, DIEPDMA=%.8x, DTXFSTS=%.8x\n",
5746 + (u32)&in_regs->diepctl,
5747 + dwc_read_reg32(&in_regs->diepctl),
5748 + dwc_read_reg32(&in_regs->dieptsiz),
5749 + dwc_read_reg32(&in_regs->diepint),
5750 + dwc_read_reg32(&in_regs->diepdma),
5751 + dwc_read_reg32(&in_regs->dtxfsts));
5752 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
5753 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk),
5754 + dwc_read_reg32(&core_if->core_global_regs->gintmsk));
5758 + /* OUT endpoint */
5759 + dwc_otg_dev_out_ep_regs_t *out_regs =
5760 + core_if->dev_if->out_ep_regs[ep->num];
5762 + depctl.d32 = dwc_read_reg32(&(out_regs->doepctl));
5763 + deptsiz.d32 = dwc_read_reg32(&(out_regs->doeptsiz));
5765 + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
5766 + ep->maxxfer : (ep->total_len - ep->xfer_len);
5768 + /* Program the transfer size and packet count as follows:
5771 + * xfersize = N * maxpacket
5773 + if ((ep->xfer_len - ep->xfer_count) == 0) {
5774 + /* Zero Length Packet */
5775 + deptsiz.b.xfersize = ep->maxpacket;
5776 + deptsiz.b.pktcnt = 1;
5779 + deptsiz.b.pktcnt =
5780 + (ep->xfer_len - ep->xfer_count + (ep->maxpacket - 1)) /
5782 + ep->xfer_len = deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
5783 + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
5786 + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
5788 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
5790 + if (core_if->dma_enable) {
5791 + if (/*(core_if->dma_enable)&&*/(ep->dma_addr==DMA_ADDR_INVALID)) {
5792 + ep->dma_addr=dma_map_single(NULL,(void *)(ep->xfer_buff),(ep->xfer_len),DMA_TO_DEVICE);
5794 + DWC_DEBUGPL(DBG_PCDV, "ep%d dma_addr=%.8x\n",
5797 + if (!core_if->dma_desc_enable) {
5798 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5800 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
5801 + dwc_write_reg32 (&(out_regs->doepdma),
5802 + (uint32_t)ep->dma_addr);
5805 + init_dma_desc_chain(core_if, ep);
5807 + /** DOEPDMAn Register write */
5809 + VERIFY_PCD_DMA_ADDR(ep->dma_desc_addr);
5810 + dwc_write_reg32(&out_regs->doepdma, ep->dma_desc_addr);
5814 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5818 + depctl.b.cnak = 1;
5819 + depctl.b.epena = 1;
5821 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
5823 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL(%.8x)=%08x DOEPTSIZ=%08x, DOEPINT=%.8x, DOEPDMA=%.8x\n",
5824 + (u32)&out_regs->doepctl,
5825 + dwc_read_reg32(&out_regs->doepctl),
5826 + dwc_read_reg32(&out_regs->doeptsiz),
5827 + dwc_read_reg32(&out_regs->doepint),
5828 + dwc_read_reg32(&out_regs->doepdma));
5830 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
5831 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk),
5832 + dwc_read_reg32(&core_if->core_global_regs->gintmsk));
5837 + * This function setup a zero length transfer in Buffer DMA and
5838 + * Slave modes for usb requests with zero field set
5840 + * @param core_if Programming view of DWC_otg controller.
5841 + * @param ep The EP to start the transfer on.
5844 +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5847 + depctl_data_t depctl;
5848 + deptsiz_data_t deptsiz;
5849 + gintmsk_data_t intr_mask = { .d32 = 0};
5851 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
5854 + if (ep->is_in == 1) {
5855 + dwc_otg_dev_in_ep_regs_t *in_regs =
5856 + core_if->dev_if->in_ep_regs[ep->num];
5858 + depctl.d32 = dwc_read_reg32(&(in_regs->diepctl));
5859 + deptsiz.d32 = dwc_read_reg32(&(in_regs->dieptsiz));
5861 + deptsiz.b.xfersize = 0;
5862 + deptsiz.b.pktcnt = 1;
5865 + /* Write the DMA register */
5866 + if (core_if->dma_enable) {
5867 + if (/*(core_if->dma_enable)&&*/(ep->dma_addr==DMA_ADDR_INVALID)) {
5868 + ep->dma_addr=dma_map_single(NULL,(void *)(ep->xfer_buff),(ep->xfer_len),DMA_TO_DEVICE);
5870 + if (core_if->dma_desc_enable == 0) {
5871 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5873 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
5874 + dwc_write_reg32 (&(in_regs->diepdma),
5875 + (uint32_t)ep->dma_addr);
5879 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
5881 + * Enable the Non-Periodic Tx FIFO empty interrupt,
5882 + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
5883 + * the data will be written into the fifo by the ISR.
5885 + if(core_if->en_multiple_tx_fifo == 0) {
5886 + intr_mask.b.nptxfempty = 1;
5887 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
5888 + intr_mask.d32, intr_mask.d32);
5891 + /* Enable the Tx FIFO Empty Interrupt for this EP */
5892 + if(ep->xfer_len > 0) {
5893 + uint32_t fifoemptymsk = 0;
5894 + fifoemptymsk = 1 << ep->num;
5895 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
5901 + /* EP enable, IN data in FIFO */
5902 + depctl.b.cnak = 1;
5903 + depctl.b.epena = 1;
5904 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
5906 + depctl.d32 = dwc_read_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl);
5907 + depctl.b.nextep = ep->num;
5908 + dwc_write_reg32 (&core_if->dev_if->in_ep_regs[0]->diepctl, depctl.d32);
5912 + /* OUT endpoint */
5913 + dwc_otg_dev_out_ep_regs_t *out_regs =
5914 + core_if->dev_if->out_ep_regs[ep->num];
5916 + depctl.d32 = dwc_read_reg32(&(out_regs->doepctl));
5917 + deptsiz.d32 = dwc_read_reg32(&(out_regs->doeptsiz));
5919 + /* Zero Length Packet */
5920 + deptsiz.b.xfersize = ep->maxpacket;
5921 + deptsiz.b.pktcnt = 1;
5923 + if (core_if->dma_enable) {
5924 + if (/*(core_if->dma_enable)&&*/(ep->dma_addr==DMA_ADDR_INVALID)) {
5925 + ep->dma_addr=dma_map_single(NULL,(void *)(ep->xfer_buff),(ep->xfer_len),DMA_TO_DEVICE);
5927 + if (!core_if->dma_desc_enable) {
5928 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5931 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
5932 + dwc_write_reg32 (&(out_regs->doepdma),
5933 + (uint32_t)ep->dma_addr);
5937 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
5941 + depctl.b.cnak = 1;
5942 + depctl.b.epena = 1;
5944 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
5950 + * This function does the setup for a data transfer for EP0 and starts
5951 + * the transfer. For an IN transfer, the packets will be loaded into
5952 + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
5953 + * unloaded from the Rx FIFO in the ISR.
5955 + * @param core_if Programming view of DWC_otg controller.
5956 + * @param ep The EP0 data.
5958 +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
5960 + depctl_data_t depctl;
5961 + deptsiz0_data_t deptsiz;
5962 + gintmsk_data_t intr_mask = { .d32 = 0};
5963 + dwc_otg_dma_desc_t* dma_desc;
5965 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
5966 + "xfer_buff=%p start_xfer_buff=%p, dma_addr=%.8x\n",
5967 + ep->num, (ep->is_in?"IN":"OUT"), ep->xfer_len,
5968 + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,ep->dma_addr);
5970 + ep->total_len = ep->xfer_len;
5973 + if (ep->is_in == 1) {
5974 + dwc_otg_dev_in_ep_regs_t *in_regs =
5975 + core_if->dev_if->in_ep_regs[0];
5977 + gnptxsts_data_t gtxstatus;
5980 + dwc_read_reg32(&core_if->core_global_regs->gnptxsts);
5982 + if(core_if->en_multiple_tx_fifo == 0 && gtxstatus.b.nptxqspcavail == 0) {
5984 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
5985 + DWC_DEBUGPL(DBG_PCD,"DIEPCTL0=%0x\n",
5986 + dwc_read_reg32(&in_regs->diepctl));
5987 + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
5989 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
5990 + DWC_PRINT("TX Queue or FIFO Full (0x%0x)\n",
5997 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
5998 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
6000 + /* Zero Length Packet? */
6001 + if (ep->xfer_len == 0) {
6002 + deptsiz.b.xfersize = 0;
6003 + deptsiz.b.pktcnt = 1;
6006 + /* Program the transfer size and packet count
6007 + * as follows: xfersize = N * maxpacket +
6008 + * short_packet pktcnt = N + (short_packet
6011 + if (ep->xfer_len > ep->maxpacket) {
6012 + ep->xfer_len = ep->maxpacket;
6013 + deptsiz.b.xfersize = ep->maxpacket;
6016 + deptsiz.b.xfersize = ep->xfer_len;
6018 + deptsiz.b.pktcnt = 1;
6021 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
6023 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
6024 + /* Write the DMA register */
6025 + if (core_if->dma_enable) {
6026 + if (/*(core_if->dma_enable)&&*/(ep->dma_addr==DMA_ADDR_INVALID)) {
6027 + ep->dma_addr=dma_map_single(NULL,(void *)(ep->xfer_buff),(ep->xfer_len),DMA_TO_DEVICE);
6029 + if(core_if->dma_desc_enable == 0) {
6030 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
6032 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
6033 + dwc_write_reg32 (&(in_regs->diepdma),
6034 + (uint32_t)ep->dma_addr);
6037 + dma_desc = core_if->dev_if->in_desc_addr;
6039 + /** DMA Descriptor Setup */
6040 + dma_desc->status.b.bs = BS_HOST_BUSY;
6041 + dma_desc->status.b.l = 1;
6042 + dma_desc->status.b.ioc = 1;
6043 + dma_desc->status.b.sp = (ep->xfer_len == ep->maxpacket) ? 0 : 1;
6044 + dma_desc->status.b.bytes = ep->xfer_len;
6045 + dma_desc->buf = ep->dma_addr;
6046 + dma_desc->status.b.bs = BS_HOST_READY;
6048 + /** DIEPDMA0 Register write */
6050 + VERIFY_PCD_DMA_ADDR(core_if->dev_if->dma_in_desc_addr);
6051 + dwc_write_reg32(&in_regs->diepdma, core_if->dev_if->dma_in_desc_addr);
6055 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
6058 + /* EP enable, IN data in FIFO */
6059 + depctl.b.cnak = 1;
6060 + depctl.b.epena = 1;
6061 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
6064 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
6065 + * data will be written into the fifo by the ISR.
6067 + if (!core_if->dma_enable) {
6068 + if(core_if->en_multiple_tx_fifo == 0) {
6069 + intr_mask.b.nptxfempty = 1;
6070 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
6071 + intr_mask.d32, intr_mask.d32);
6074 + /* Enable the Tx FIFO Empty Interrupt for this EP */
6075 + if(ep->xfer_len > 0) {
6076 + uint32_t fifoemptymsk = 0;
6077 + fifoemptymsk |= 1 << ep->num;
6078 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
6085 + /* OUT endpoint */
6086 + dwc_otg_dev_out_ep_regs_t *out_regs =
6087 + core_if->dev_if->out_ep_regs[0];
6089 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
6090 + deptsiz.d32 = dwc_read_reg32(&out_regs->doeptsiz);
6092 + /* Program the transfer size and packet count as follows:
6093 + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
6095 + /* Zero Length Packet */
6096 + deptsiz.b.xfersize = ep->maxpacket;
6097 + deptsiz.b.pktcnt = 1;
6099 + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
6101 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
6103 + if (core_if->dma_enable) {
6104 + if (/*(core_if->dma_enable)&&*/(ep->dma_addr==DMA_ADDR_INVALID)) {
6105 + ep->dma_addr=dma_map_single(NULL,(void *)(ep->xfer_buff),(ep->xfer_len),DMA_TO_DEVICE);
6107 + if(!core_if->dma_desc_enable) {
6108 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
6111 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
6112 + dwc_write_reg32 (&(out_regs->doepdma),
6113 + (uint32_t)ep->dma_addr);
6116 + dma_desc = core_if->dev_if->out_desc_addr;
6118 + /** DMA Descriptor Setup */
6119 + dma_desc->status.b.bs = BS_HOST_BUSY;
6120 + dma_desc->status.b.l = 1;
6121 + dma_desc->status.b.ioc = 1;
6122 + dma_desc->status.b.bytes = ep->maxpacket;
6123 + dma_desc->buf = ep->dma_addr;
6124 + dma_desc->status.b.bs = BS_HOST_READY;
6126 + /** DOEPDMA0 Register write */
6127 + VERIFY_PCD_DMA_ADDR(core_if->dev_if->dma_out_desc_addr);
6128 + dwc_write_reg32(&out_regs->doepdma, core_if->dev_if->dma_out_desc_addr);
6132 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
6136 + depctl.b.cnak = 1;
6137 + depctl.b.epena = 1;
6138 + dwc_write_reg32 (&(out_regs->doepctl), depctl.d32);
6143 + * This function continues control IN transfers started by
6144 + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
6145 + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
6146 + * bit for the packet count.
6148 + * @param core_if Programming view of DWC_otg controller.
6149 + * @param ep The EP0 data.
6151 +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
6153 + depctl_data_t depctl;
6154 + deptsiz0_data_t deptsiz;
6155 + gintmsk_data_t intr_mask = { .d32 = 0};
6156 + dwc_otg_dma_desc_t* dma_desc;
6158 + if (ep->is_in == 1) {
6159 + dwc_otg_dev_in_ep_regs_t *in_regs =
6160 + core_if->dev_if->in_ep_regs[0];
6161 + gnptxsts_data_t tx_status = { .d32 = 0 };
6163 + tx_status.d32 = dwc_read_reg32(&core_if->core_global_regs->gnptxsts);
6164 + /** @todo Should there be check for room in the Tx
6165 + * Status Queue. If not remove the code above this comment. */
6167 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
6168 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
6170 + /* Program the transfer size and packet count
6171 + * as follows: xfersize = N * maxpacket +
6172 + * short_packet pktcnt = N + (short_packet
6177 + if(core_if->dma_desc_enable == 0) {
6178 + deptsiz.b.xfersize = (ep->total_len - ep->xfer_count) > ep->maxpacket ? ep->maxpacket :
6179 + (ep->total_len - ep->xfer_count);
6180 + deptsiz.b.pktcnt = 1;
6181 + if(core_if->dma_enable == 0) {
6182 + ep->xfer_len += deptsiz.b.xfersize;
6184 + ep->xfer_len = deptsiz.b.xfersize;
6186 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
6189 + ep->xfer_len = (ep->total_len - ep->xfer_count) > ep->maxpacket ? ep->maxpacket :
6190 + (ep->total_len - ep->xfer_count);
6192 + dma_desc = core_if->dev_if->in_desc_addr;
6194 + /** DMA Descriptor Setup */
6195 + dma_desc->status.b.bs = BS_HOST_BUSY;
6196 + dma_desc->status.b.l = 1;
6197 + dma_desc->status.b.ioc = 1;
6198 + dma_desc->status.b.sp = (ep->xfer_len == ep->maxpacket) ? 0 : 1;
6199 + dma_desc->status.b.bytes = ep->xfer_len;
6200 + dma_desc->buf = ep->dma_addr;
6201 + dma_desc->status.b.bs = BS_HOST_READY;
6204 + /** DIEPDMA0 Register write */
6205 + VERIFY_PCD_DMA_ADDR(core_if->dev_if->dma_in_desc_addr);
6206 + dwc_write_reg32(&in_regs->diepdma, core_if->dev_if->dma_in_desc_addr);
6210 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
6212 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
6214 + /* Write the DMA register */
6215 + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
6216 + if(core_if->dma_desc_enable == 0){
6218 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
6219 + dwc_write_reg32 (&(in_regs->diepdma), (uint32_t)ep->dma_addr);
6223 + /* EP enable, IN data in FIFO */
6224 + depctl.b.cnak = 1;
6225 + depctl.b.epena = 1;
6226 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
6229 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
6230 + * data will be written into the fifo by the ISR.
6232 + if (!core_if->dma_enable) {
6233 + if(core_if->en_multiple_tx_fifo == 0) {
6234 + /* First clear it from GINTSTS */
6235 + intr_mask.b.nptxfempty = 1;
6236 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
6237 + intr_mask.d32, intr_mask.d32);
6241 + /* Enable the Tx FIFO Empty Interrupt for this EP */
6242 + if(ep->xfer_len > 0) {
6243 + uint32_t fifoemptymsk = 0;
6244 + fifoemptymsk |= 1 << ep->num;
6245 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
6252 + dwc_otg_dev_out_ep_regs_t *out_regs =
6253 + core_if->dev_if->out_ep_regs[0];
6256 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
6257 + deptsiz.d32 = dwc_read_reg32(&out_regs->doeptsiz);
6259 + /* Program the transfer size and packet count
6260 + * as follows: xfersize = N * maxpacket +
6261 + * short_packet pktcnt = N + (short_packet
6264 + deptsiz.b.xfersize = ep->maxpacket;
6265 + deptsiz.b.pktcnt = 1;
6268 + if(core_if->dma_desc_enable == 0) {
6269 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
6272 + dma_desc = core_if->dev_if->out_desc_addr;
6274 + /** DMA Descriptor Setup */
6275 + dma_desc->status.b.bs = BS_HOST_BUSY;
6276 + dma_desc->status.b.l = 1;
6277 + dma_desc->status.b.ioc = 1;
6278 + dma_desc->status.b.bytes = ep->maxpacket;
6279 + dma_desc->buf = ep->dma_addr;
6280 + dma_desc->status.b.bs = BS_HOST_READY;
6282 + /** DOEPDMA0 Register write */
6283 + VERIFY_PCD_DMA_ADDR(core_if->dev_if->dma_out_desc_addr);
6284 + dwc_write_reg32(&out_regs->doepdma, core_if->dev_if->dma_out_desc_addr);
6288 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
6290 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
6292 + /* Write the DMA register */
6293 + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
6294 + if(core_if->dma_desc_enable == 0){
6296 + VERIFY_PCD_DMA_ADDR(ep->dma_addr);
6297 + dwc_write_reg32 (&(out_regs->doepdma), (uint32_t)ep->dma_addr);
6301 + /* EP enable, IN data in FIFO */
6302 + depctl.b.cnak = 1;
6303 + depctl.b.epena = 1;
6304 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
6310 +void dump_msg(const u8 *buf, unsigned int length)
6312 + unsigned int start, num, i;
6313 + char line[52], *p;
6315 + if (length >= 512)
6318 + while (length > 0) {
6319 + num = min(length, 16u);
6321 + for (i = 0; i < num; ++i)
6325 + sprintf(p, " %02x", buf[i]);
6329 + DWC_PRINT("%6x: %s\n", start, line);
6336 +static inline void dump_msg(const u8 *buf, unsigned int length)
6342 + * This function writes a packet into the Tx FIFO associated with the
6343 + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
6344 + * periodic EPs the periodic Tx FIFO associated with the EP is written
6345 + * with all packets for the next micro-frame.
6347 + * @param core_if Programming view of DWC_otg controller.
6348 + * @param ep The EP to write packet for.
6349 + * @param dma Indicates if DMA is being used.
6351 +void dwc_otg_ep_write_packet(dwc_otg_core_if_t *core_if, dwc_ep_t *ep, int dma)
6354 + * The buffer is padded to DWORD on a per packet basis in
6355 + * slave/dma mode if the MPS is not DWORD aligned. The last
6356 + * packet, if short, is also padded to a multiple of DWORD.
6358 + * ep->xfer_buff always starts DWORD aligned in memory and is a
6359 + * multiple of DWORD in length
6361 + * ep->xfer_len can be any number of bytes
6363 + * ep->xfer_count is a multiple of ep->maxpacket until the last
6366 + * FIFO access is DWORD */
6369 + uint32_t byte_count;
6370 + uint32_t dword_count;
6372 + uint32_t *data_buff = (uint32_t *)ep->xfer_buff;
6374 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if, ep);
6375 + if (ep->xfer_count >= ep->xfer_len) {
6376 + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
6380 + /* Find the byte length of the packet either short packet or MPS */
6381 + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
6382 + byte_count = ep->xfer_len - ep->xfer_count;
6385 + byte_count = ep->maxpacket;
6388 + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
6389 + * is not a multiple of DWORD */
6390 + dword_count = (byte_count + 3) / 4;
6393 + dump_msg(ep->xfer_buff, byte_count);
6396 + /**@todo NGS Where are the Periodic Tx FIFO addresses
6397 + * intialized? What should this be? */
6399 + fifo = core_if->data_fifo[ep->num];
6402 + DWC_DEBUGPL((DBG_PCDV|DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n", fifo, data_buff, *data_buff, byte_count);
6405 + for (i=0; i<dword_count; i++, data_buff++) {
6406 + dwc_write_reg32(fifo, *data_buff);
6410 + ep->xfer_count += byte_count;
6411 + ep->xfer_buff += byte_count;
6412 + ep->dma_addr += byte_count;
6416 + * Set the EP STALL.
6418 + * @param core_if Programming view of DWC_otg controller.
6419 + * @param ep The EP to set the stall on.
6421 +void dwc_otg_ep_set_stall(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
6423 + depctl_data_t depctl;
6424 + volatile uint32_t *depctl_addr;
6426 + DWC_DEBUGPL(DBG_PCDV, "%s ep%d-%s1\n", __func__, ep->num,
6427 + (ep->is_in?"IN":"OUT"));
6429 + DWC_PRINT("%s ep%d-%s\n", __func__, ep->num,
6430 + (ep->is_in?"in":"out"));
6432 + if (ep->is_in == 1) {
6433 + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
6434 + depctl.d32 = dwc_read_reg32(depctl_addr);
6436 + /* set the disable and stall bits */
6438 +//epdis is set here but not cleared at latter dwc_otg_ep_clear_stall,
6439 +//which cause the testusb item 13 failed(Host:pc, device: otg device)
6440 + if (depctl.b.epena) {
6441 + depctl.b.epdis = 1;
6444 + depctl.b.stall = 1;
6445 + dwc_write_reg32(depctl_addr, depctl.d32);
6448 + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
6449 + depctl.d32 = dwc_read_reg32(depctl_addr);
6451 + /* set the stall bit */
6452 + depctl.b.stall = 1;
6453 + dwc_write_reg32(depctl_addr, depctl.d32);
6456 + DWC_DEBUGPL(DBG_PCDV,"%s: DEPCTL(%.8x)=%0x\n",__func__,(u32)depctl_addr,dwc_read_reg32(depctl_addr));
6462 + * Clear the EP STALL.
6464 + * @param core_if Programming view of DWC_otg controller.
6465 + * @param ep The EP to clear stall from.
6467 +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
6469 + depctl_data_t depctl;
6470 + volatile uint32_t *depctl_addr;
6472 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
6473 + (ep->is_in?"IN":"OUT"));
6475 + if (ep->is_in == 1) {
6476 + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
6479 + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
6482 + depctl.d32 = dwc_read_reg32(depctl_addr);
6484 + /* clear the stall bits */
6485 + depctl.b.stall = 0;
6488 + * USB Spec 9.4.5: For endpoints using data toggle, regardless
6489 + * of whether an endpoint has the Halt feature set, a
6490 + * ClearFeature(ENDPOINT_HALT) request always results in the
6491 + * data toggle being reinitialized to DATA0.
6493 + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
6494 + ep->type == DWC_OTG_EP_TYPE_BULK) {
6495 + depctl.b.setd0pid = 1; /* DATA0 */
6498 + dwc_write_reg32(depctl_addr, depctl.d32);
6499 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
6504 + * This function reads a packet from the Rx FIFO into the destination
6505 + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
6507 + * @param core_if Programming view of DWC_otg controller.
6508 + * @param dest Destination buffer for the packet.
6509 + * @param bytes Number of bytes to copy to the destination.
6511 +void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
6516 + int word_count = (bytes + 3) / 4;
6518 + volatile uint32_t *fifo = core_if->data_fifo[0];
6519 + uint32_t *data_buff = (uint32_t *)dest;
6522 + * @todo Account for the case where _dest is not dword aligned. This
6523 + * requires reading data from the FIFO into a uint32_t temp buffer,
6524 + * then moving it into the data buffer.
6527 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
6528 + core_if, dest, bytes);
6530 + for (i=0; i<word_count; i++, data_buff++)
6532 + *data_buff = dwc_read_reg32(fifo);
6541 + * This functions reads the device registers and prints them
6543 + * @param core_if Programming view of DWC_otg controller.
6545 +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *core_if)
6548 + volatile uint32_t *addr;
6550 + DWC_PRINT("Device Global Registers\n");
6551 + addr=&core_if->dev_if->dev_global_regs->dcfg;
6552 + DWC_PRINT("DCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6553 + addr=&core_if->dev_if->dev_global_regs->dctl;
6554 + DWC_PRINT("DCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6555 + addr=&core_if->dev_if->dev_global_regs->dsts;
6556 + DWC_PRINT("DSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6557 + addr=&core_if->dev_if->dev_global_regs->diepmsk;
6558 + DWC_PRINT("DIEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6559 + addr=&core_if->dev_if->dev_global_regs->doepmsk;
6560 + DWC_PRINT("DOEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6561 + addr=&core_if->dev_if->dev_global_regs->daint;
6562 + DWC_PRINT("DAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6563 + addr=&core_if->dev_if->dev_global_regs->daintmsk;
6564 + DWC_PRINT("DAINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6565 + addr=&core_if->dev_if->dev_global_regs->dtknqr1;
6566 + DWC_PRINT("DTKNQR1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6567 + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
6568 + addr=&core_if->dev_if->dev_global_regs->dtknqr2;
6569 + DWC_PRINT("DTKNQR2 @0x%08X : 0x%08X\n",
6570 + (uint32_t)addr,dwc_read_reg32(addr));
6573 + addr=&core_if->dev_if->dev_global_regs->dvbusdis;
6574 + DWC_PRINT("DVBUSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6576 + addr=&core_if->dev_if->dev_global_regs->dvbuspulse;
6577 + DWC_PRINT("DVBUSPULSE @0x%08X : 0x%08X\n",
6578 + (uint32_t)addr,dwc_read_reg32(addr));
6580 + if (core_if->hwcfg2.b.dev_token_q_depth > 14) {
6581 + addr=&core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
6582 + DWC_PRINT("DTKNQR3_DTHRCTL @0x%08X : 0x%08X\n",
6583 + (uint32_t)addr, dwc_read_reg32(addr));
6586 + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
6587 + addr=&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
6588 + DWC_PRINT("DTKNQR4 @0x%08X : 0x%08X\n",
6589 + (uint32_t)addr, dwc_read_reg32(addr));
6592 + addr=&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
6593 + DWC_PRINT("FIFOEMPMSK @0x%08X : 0x%08X\n", (uint32_t)addr, dwc_read_reg32(addr));
6595 + addr=&core_if->dev_if->dev_global_regs->deachint;
6596 + DWC_PRINT("DEACHINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6597 + addr=&core_if->dev_if->dev_global_regs->deachintmsk;
6598 + DWC_PRINT("DEACHINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6600 + for (i=0; i<= core_if->dev_if->num_in_eps; i++) {
6601 + addr=&core_if->dev_if->dev_global_regs->diepeachintmsk[i];
6602 + DWC_PRINT("DIEPEACHINTMSK[%d] @0x%08X : 0x%08X\n", i, (uint32_t)addr, dwc_read_reg32(addr));
6606 + for (i=0; i<= core_if->dev_if->num_out_eps; i++) {
6607 + addr=&core_if->dev_if->dev_global_regs->doepeachintmsk[i];
6608 + DWC_PRINT("DOEPEACHINTMSK[%d] @0x%08X : 0x%08X\n", i, (uint32_t)addr, dwc_read_reg32(addr));
6611 + for (i=0; i<= core_if->dev_if->num_in_eps; i++) {
6612 + DWC_PRINT("Device IN EP %d Registers\n", i);
6613 + addr=&core_if->dev_if->in_ep_regs[i]->diepctl;
6614 + DWC_PRINT("DIEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6615 + addr=&core_if->dev_if->in_ep_regs[i]->diepint;
6616 + DWC_PRINT("DIEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6617 + addr=&core_if->dev_if->in_ep_regs[i]->dieptsiz;
6618 + DWC_PRINT("DIETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6619 + addr=&core_if->dev_if->in_ep_regs[i]->diepdma;
6620 + DWC_PRINT("DIEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6621 + addr=&core_if->dev_if->in_ep_regs[i]->dtxfsts;
6622 + DWC_PRINT("DTXFSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6623 + //reading depdmab in non desc dma mode would halt the ahb bus...
6624 + if(core_if->dma_desc_enable){
6625 + addr=&core_if->dev_if->in_ep_regs[i]->diepdmab;
6626 + DWC_PRINT("DIEPDMAB @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6631 + for (i=0; i<= core_if->dev_if->num_out_eps; i++) {
6632 + DWC_PRINT("Device OUT EP %d Registers\n", i);
6633 + addr=&core_if->dev_if->out_ep_regs[i]->doepctl;
6634 + DWC_PRINT("DOEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6635 + addr=&core_if->dev_if->out_ep_regs[i]->doepfn;
6636 + DWC_PRINT("DOEPFN @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6637 + addr=&core_if->dev_if->out_ep_regs[i]->doepint;
6638 + DWC_PRINT("DOEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6639 + addr=&core_if->dev_if->out_ep_regs[i]->doeptsiz;
6640 + DWC_PRINT("DOETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6641 + addr=&core_if->dev_if->out_ep_regs[i]->doepdma;
6642 + DWC_PRINT("DOEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6644 + //reading depdmab in non desc dma mode would halt the ahb bus...
6645 + if(core_if->dma_desc_enable){
6646 + addr=&core_if->dev_if->out_ep_regs[i]->doepdmab;
6647 + DWC_PRINT("DOEPDMAB @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6658 + * This functions reads the SPRAM and prints its content
6660 + * @param core_if Programming view of DWC_otg controller.
6662 +void dwc_otg_dump_spram(dwc_otg_core_if_t *core_if)
6664 + volatile uint8_t *addr, *start_addr, *end_addr;
6666 + DWC_PRINT("SPRAM Data:\n");
6667 + start_addr = (void*)core_if->core_global_regs;
6668 + DWC_PRINT("Base Address: 0x%8X\n", (uint32_t)start_addr);
6669 + start_addr += 0x00028000;
6670 + end_addr=(void*)core_if->core_global_regs;
6671 + end_addr += 0x000280e0;
6673 + for(addr = start_addr; addr < end_addr; addr+=16)
6675 + 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,
6698 + * This function reads the host registers and prints them
6700 + * @param core_if Programming view of DWC_otg controller.
6702 +void dwc_otg_dump_host_registers(dwc_otg_core_if_t *core_if)
6705 + volatile uint32_t *addr;
6707 + DWC_PRINT("Host Global Registers\n");
6708 + addr=&core_if->host_if->host_global_regs->hcfg;
6709 + DWC_PRINT("HCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6710 + addr=&core_if->host_if->host_global_regs->hfir;
6711 + DWC_PRINT("HFIR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6712 + addr=&core_if->host_if->host_global_regs->hfnum;
6713 + DWC_PRINT("HFNUM @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6714 + addr=&core_if->host_if->host_global_regs->hptxsts;
6715 + DWC_PRINT("HPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6716 + addr=&core_if->host_if->host_global_regs->haint;
6717 + DWC_PRINT("HAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6718 + addr=&core_if->host_if->host_global_regs->haintmsk;
6719 + DWC_PRINT("HAINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6720 + addr=core_if->host_if->hprt0;
6721 + DWC_PRINT("HPRT0 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6723 + for (i=0; i<core_if->core_params->host_channels; i++)
6725 + DWC_PRINT("Host Channel %d Specific Registers\n", i);
6726 + addr=&core_if->host_if->hc_regs[i]->hcchar;
6727 + DWC_PRINT("HCCHAR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6728 + addr=&core_if->host_if->hc_regs[i]->hcsplt;
6729 + DWC_PRINT("HCSPLT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6730 + addr=&core_if->host_if->hc_regs[i]->hcint;
6731 + DWC_PRINT("HCINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6732 + addr=&core_if->host_if->hc_regs[i]->hcintmsk;
6733 + DWC_PRINT("HCINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6734 + addr=&core_if->host_if->hc_regs[i]->hctsiz;
6735 + DWC_PRINT("HCTSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6736 + addr=&core_if->host_if->hc_regs[i]->hcdma;
6737 + DWC_PRINT("HCDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6743 + * This function reads the core global registers and prints them
6745 + * @param core_if Programming view of DWC_otg controller.
6747 +void dwc_otg_dump_global_registers(dwc_otg_core_if_t *core_if)
6751 + volatile uint32_t *addr;
6753 + DWC_PRINT("Core Global Registers\n");
6754 + addr=&core_if->core_global_regs->gotgctl;
6755 + DWC_PRINT("GOTGCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6756 + addr=&core_if->core_global_regs->gotgint;
6757 + DWC_PRINT("GOTGINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6758 + addr=&core_if->core_global_regs->gahbcfg;
6759 + DWC_PRINT("GAHBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6760 + addr=&core_if->core_global_regs->gusbcfg;
6761 + DWC_PRINT("GUSBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6762 + addr=&core_if->core_global_regs->grstctl;
6763 + DWC_PRINT("GRSTCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6764 + addr=&core_if->core_global_regs->gintsts;
6765 + DWC_PRINT("GINTSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6766 + addr=&core_if->core_global_regs->gintmsk;
6767 + DWC_PRINT("GINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6768 + addr=&core_if->core_global_regs->grxstsr;
6769 + DWC_PRINT("GRXSTSR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6770 + //addr=&core_if->core_global_regs->grxstsp;
6771 + //DWC_PRINT("GRXSTSP @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6772 + addr=&core_if->core_global_regs->grxfsiz;
6773 + DWC_PRINT("GRXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6774 + addr=&core_if->core_global_regs->gnptxfsiz;
6775 + DWC_PRINT("GNPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6776 + addr=&core_if->core_global_regs->gnptxsts;
6777 + DWC_PRINT("GNPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6778 + addr=&core_if->core_global_regs->gi2cctl;
6779 + DWC_PRINT("GI2CCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6780 + addr=&core_if->core_global_regs->gpvndctl;
6781 + DWC_PRINT("GPVNDCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6782 + addr=&core_if->core_global_regs->ggpio;
6783 + DWC_PRINT("GGPIO @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6784 + addr=&core_if->core_global_regs->guid;
6785 + DWC_PRINT("GUID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6786 + addr=&core_if->core_global_regs->gsnpsid;
6787 + DWC_PRINT("GSNPSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6788 + addr=&core_if->core_global_regs->ghwcfg1;
6789 + DWC_PRINT("GHWCFG1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6790 + addr=&core_if->core_global_regs->ghwcfg2;
6791 + DWC_PRINT("GHWCFG2 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6792 + addr=&core_if->core_global_regs->ghwcfg3;
6793 + DWC_PRINT("GHWCFG3 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6794 + addr=&core_if->core_global_regs->ghwcfg4;
6795 + DWC_PRINT("GHWCFG4 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6796 + addr=&core_if->core_global_regs->hptxfsiz;
6797 + DWC_PRINT("HPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
6799 + size=(core_if->hwcfg4.b.ded_fifo_en)?
6800 + core_if->hwcfg4.b.num_in_eps:core_if->hwcfg4.b.num_dev_perio_in_ep;
6801 + str=(core_if->hwcfg4.b.ded_fifo_en)?"DIEPTXF":"DPTXFSIZ";
6802 + for (i=0; i<size; i++)
6804 + addr=&core_if->core_global_regs->dptxfsiz_dieptxf[i];
6805 + DWC_PRINT("%s[%d] @0x%08X : 0x%08X\n",str,i,(uint32_t)addr,dwc_read_reg32(addr));
6810 + * Flush a Tx FIFO.
6812 + * @param core_if Programming view of DWC_otg controller.
6813 + * @param num Tx FIFO to flush.
6815 +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t *core_if,
6818 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
6819 + volatile grstctl_t greset = { .d32 = 0};
6822 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "Flush Tx FIFO %d\n", num);
6824 + greset.b.txfflsh = 1;
6825 + greset.b.txfnum = num;
6826 + dwc_write_reg32(&global_regs->grstctl, greset.d32);
6829 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6830 + if (++count > 10000) {
6831 + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
6832 + __func__, greset.d32,
6833 + dwc_read_reg32(&global_regs->gnptxsts));
6837 + while (greset.b.txfflsh == 1);
6839 + /* Wait for 3 PHY Clocks*/
6846 + * @param core_if Programming view of DWC_otg controller.
6848 +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t *core_if)
6850 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
6851 + volatile grstctl_t greset = { .d32 = 0};
6854 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "%s\n", __func__);
6858 + greset.b.rxfflsh = 1;
6859 + dwc_write_reg32(&global_regs->grstctl, greset.d32);
6862 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6863 + if (++count > 10000) {
6864 + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
6869 + while (greset.b.rxfflsh == 1);
6871 + /* Wait for 3 PHY Clocks*/
6876 + * Do core a soft reset of the core. Be careful with this because it
6877 + * resets all the internal state machines of the core.
6879 +void dwc_otg_core_reset(dwc_otg_core_if_t *core_if)
6881 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
6882 + volatile grstctl_t greset = { .d32 = 0};
6885 + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
6886 + /* Wait for AHB master IDLE state. */
6889 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6890 + if (++count > 100000) {
6891 + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
6896 + while (greset.b.ahbidle == 0);
6898 + /* Core Soft Reset */
6900 + greset.b.csftrst = 1;
6901 + dwc_write_reg32(&global_regs->grstctl, greset.d32);
6903 + greset.d32 = dwc_read_reg32(&global_regs->grstctl);
6904 + if (++count > 10000) {
6905 + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n", __func__,
6910 + while (greset.b.csftrst == 1);
6912 + /* Wait for 3 PHY Clocks*/
6915 + DWC_DEBUGPL(DBG_CILV, "GINTSTS=%.8x\n", dwc_read_reg32(&global_regs->gintsts));
6916 + DWC_DEBUGPL(DBG_CILV, "GINTSTS=%.8x\n", dwc_read_reg32(&global_regs->gintsts));
6917 + DWC_DEBUGPL(DBG_CILV, "GINTSTS=%.8x\n", dwc_read_reg32(&global_regs->gintsts));
6924 + * Register HCD callbacks. The callbacks are used to start and stop
6925 + * the HCD for interrupt processing.
6927 + * @param core_if Programming view of DWC_otg controller.
6928 + * @param cb the HCD callback structure.
6929 + * @param p pointer to be passed to callback function (usb_hcd*).
6931 +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t *core_if,
6932 + dwc_otg_cil_callbacks_t *cb,
6935 + core_if->hcd_cb = cb;
6940 + * Register PCD callbacks. The callbacks are used to start and stop
6941 + * the PCD for interrupt processing.
6943 + * @param core_if Programming view of DWC_otg controller.
6944 + * @param cb the PCD callback structure.
6945 + * @param p pointer to be passed to callback function (pcd*).
6947 +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t *core_if,
6948 + dwc_otg_cil_callbacks_t *cb,
6951 + core_if->pcd_cb = cb;
6958 + * This function writes isoc data per 1 (micro)frame into tx fifo
6960 + * @param core_if Programming view of DWC_otg controller.
6961 + * @param ep The EP to start the transfer on.
6964 +void write_isoc_frame_data(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
6966 + dwc_otg_dev_in_ep_regs_t *ep_regs;
6967 + dtxfsts_data_t txstatus = {.d32 = 0};
6971 + ep->xfer_len = ep->data_per_frame;
6972 + ep->xfer_count = 0;
6974 + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
6976 + len = ep->xfer_len - ep->xfer_count;
6978 + if (len > ep->maxpacket) {
6979 + len = ep->maxpacket;
6982 + dwords = (len + 3)/4;
6984 + /* While there is space in the queue and space in the FIFO and
6985 + * More data to tranfer, Write packets to the Tx FIFO */
6986 + txstatus.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
6987 + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n",ep->num,txstatus.d32);
6989 + while (txstatus.b.txfspcavail > dwords &&
6990 + ep->xfer_count < ep->xfer_len &&
6991 + ep->xfer_len != 0) {
6992 + /* Write the FIFO */
6993 + dwc_otg_ep_write_packet(core_if, ep, 0);
6995 + len = ep->xfer_len - ep->xfer_count;
6996 + if (len > ep->maxpacket) {
6997 + len = ep->maxpacket;
7000 + dwords = (len + 3)/4;
7001 + txstatus.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
7002 + DWC_DEBUGPL(DBG_PCDV,"dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
7008 + * This function initializes a descriptor chain for Isochronous transfer
7010 + * @param core_if Programming view of DWC_otg controller.
7011 + * @param ep The EP to start the transfer on.
7014 +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
7016 + deptsiz_data_t deptsiz = { .d32 = 0 };
7017 + depctl_data_t depctl = { .d32 = 0 };
7018 + dsts_data_t dsts = { .d32 = 0 };
7019 + volatile uint32_t *addr;
7022 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
7024 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
7027 + ep->xfer_len = ep->data_per_frame;
7028 + ep->xfer_count = 0;
7029 + ep->xfer_buff = ep->cur_pkt_addr;
7030 + ep->dma_addr = ep->cur_pkt_dma_addr;
7033 + /* Program the transfer size and packet count
7034 + * as follows: xfersize = N * maxpacket +
7035 + * short_packet pktcnt = N + (short_packet
7038 + deptsiz.b.xfersize = ep->xfer_len;
7039 + deptsiz.b.pktcnt =
7040 + (ep->xfer_len - 1 + ep->maxpacket) /
7042 + deptsiz.b.mc = deptsiz.b.pktcnt;
7043 + dwc_write_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz, deptsiz.d32);
7045 + /* Write the DMA register */
7046 + if (core_if->dma_enable) {
7047 + dwc_write_reg32 (&(core_if->dev_if->in_ep_regs[ep->num]->diepdma), (uint32_t)ep->dma_addr);
7050 + deptsiz.b.pktcnt =
7051 + (ep->xfer_len + (ep->maxpacket - 1)) /
7053 + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
7055 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
7057 + if (core_if->dma_enable) {
7058 + dwc_write_reg32 (&(core_if->dev_if->out_ep_regs[ep->num]->doepdma),
7059 + (uint32_t)ep->dma_addr);
7064 + /** Enable endpoint, clear nak */
7067 + if(ep->bInterval == 1) {
7068 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
7069 + ep->next_frame = dsts.b.soffn + ep->bInterval;
7071 + if(ep->next_frame & 0x1) {
7072 + depctl.b.setd1pid = 1;
7074 + depctl.b.setd0pid = 1;
7077 + ep->next_frame += ep->bInterval;
7079 + if(ep->next_frame & 0x1) {
7080 + depctl.b.setd1pid = 1;
7082 + depctl.b.setd0pid = 1;
7085 + depctl.b.epena = 1;
7086 + depctl.b.cnak = 1;
7088 + dwc_modify_reg32(addr, 0, depctl.d32);
7089 + depctl.d32 = dwc_read_reg32(addr);
7091 + if(ep->is_in && core_if->dma_enable == 0) {
7092 + write_isoc_frame_data(core_if, ep);
7097 +#endif //DWC_EN_ISOC
7099 +++ b/drivers/usb/host/otg/dwc_otg_cil.h
7101 +/* ==========================================================================
7102 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
7103 + * $Revision: #91 $
7104 + * $Date: 2008/09/19 $
7105 + * $Change: 1099526 $
7107 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
7108 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
7109 + * otherwise expressly agreed to in writing between Synopsys and you.
7111 + * The Software IS NOT an item of Licensed Software or Licensed Product under
7112 + * any End User Software License Agreement or Agreement for Licensed Product
7113 + * with Synopsys or any supplement thereto. You are permitted to use and
7114 + * redistribute this Software in source and binary forms, with or without
7115 + * modification, provided that redistributions of source code must retain this
7116 + * notice. You may not view, use, disclose, copy or distribute this file or
7117 + * any information contained herein except pursuant to this license grant from
7118 + * Synopsys. If you do not agree with this notice, including the disclaimer
7119 + * below, then you are not authorized to use the Software.
7121 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
7122 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7123 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7124 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
7125 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7126 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7127 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7128 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7129 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7130 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
7132 + * ========================================================================== */
7134 +#if !defined(__DWC_CIL_H__)
7135 +#define __DWC_CIL_H__
7137 +#include <linux/workqueue.h>
7138 +#include <linux/version.h>
7139 +#include <asm/param.h>
7140 +//#include <asm/arch/regs-irq.h>
7142 +#include "dwc_otg_plat.h"
7143 +#include "dwc_otg_regs.h"
7145 +#include "linux/timer.h"
7150 + * This file contains the interface to the Core Interface Layer.
7154 +/** Macros defined for DWC OTG HW Release verison */
7155 +#define OTG_CORE_REV_2_00 0x4F542000
7156 +#define OTG_CORE_REV_2_60a 0x4F54260A
7157 +#define OTG_CORE_REV_2_71a 0x4F54271A
7158 +#define OTG_CORE_REV_2_72a 0x4F54272A
7162 +typedef struct iso_pkt_info
7169 + * The <code>dwc_ep</code> structure represents the state of a single
7170 + * endpoint when acting in device mode. It contains the data items
7171 + * needed for an endpoint to be activated and transfer packets.
7173 +typedef struct dwc_ep
7175 + /** EP number used for register address lookup */
7177 + /** EP direction 0 = OUT */
7178 + unsigned is_in : 1;
7180 + unsigned active : 1;
7182 + /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
7183 + If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
7184 + unsigned tx_fifo_num : 4;
7185 + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
7186 + unsigned type : 2;
7187 +#define DWC_OTG_EP_TYPE_CONTROL 0
7188 +#define DWC_OTG_EP_TYPE_ISOC 1
7189 +#define DWC_OTG_EP_TYPE_BULK 2
7190 +#define DWC_OTG_EP_TYPE_INTR 3
7192 + /** DATA start PID for INTR and BULK EP */
7193 + unsigned data_pid_start : 1;
7194 + /** Frame (even/odd) for ISOC EP */
7195 + unsigned even_odd_frame : 1;
7196 + /** Max Packet bytes */
7197 + unsigned maxpacket : 11;
7199 + /** Max Transfer size */
7200 + unsigned maxxfer : 16;
7202 + /** @name Transfer state */
7206 + * Pointer to the beginning of the transfer buffer -- do not modify
7207 + * during transfer.
7210 + uint32_t dma_addr;
7212 + uint32_t dma_desc_addr;
7213 + dwc_otg_dma_desc_t* desc_addr;
7216 + uint8_t *start_xfer_buff;
7217 + /** pointer to the transfer buffer */
7218 + uint8_t *xfer_buff;
7219 + /** Number of bytes to transfer */
7220 + unsigned xfer_len : 19;
7221 + /** Number of bytes transferred. */
7222 + unsigned xfer_count : 19;
7224 + unsigned sent_zlp : 1;
7225 + /** Total len for control transfer */
7226 + unsigned total_len : 19;
7228 + /** stall clear flag */
7229 + unsigned stall_clear_flag : 1;
7231 + /** Allocated DMA Desc count */
7232 + uint32_t desc_cnt;
7234 + uint32_t aligned_dma_addr;
7235 + uint32_t aligned_buf_size;
7236 + uint8_t *aligned_buf;
7241 + * Variables specific for ISOC EPs
7244 + /** DMA addresses of ISOC buffers */
7245 + uint32_t dma_addr0;
7246 + uint32_t dma_addr1;
7248 + uint32_t iso_dma_desc_addr;
7249 + dwc_otg_dma_desc_t* iso_desc_addr;
7251 + /** pointer to the transfer buffers */
7252 + uint8_t *xfer_buff0;
7253 + uint8_t *xfer_buff1;
7255 + /** number of ISOC Buffer is processing */
7256 + uint32_t proc_buf_num;
7257 + /** Interval of ISOC Buffer processing */
7258 + uint32_t buf_proc_intrvl;
7259 + /** Data size for regular frame */
7260 + uint32_t data_per_frame;
7262 + /* todo - pattern data support is to be implemented in the future */
7263 + /** Data size for pattern frame */
7264 + uint32_t data_pattern_frame;
7265 + /** Frame number of pattern data */
7266 + uint32_t sync_frame;
7269 + uint32_t bInterval;
7270 + /** ISO Packet number per frame */
7271 + uint32_t pkt_per_frm;
7272 + /** Next frame num for which will be setup DMA Desc */
7273 + uint32_t next_frame;
7274 + /** Number of packets per buffer processing */
7276 + /** Info for all isoc packets */
7277 + iso_pkt_info_t *pkt_info;
7278 + /** current pkt number */
7280 + /** current pkt number */
7281 + uint8_t *cur_pkt_addr;
7282 + /** current pkt number */
7283 + uint32_t cur_pkt_dma_addr;
7284 +#endif //DWC_EN_ISOC
7289 + * Reasons for halting a host channel.
7291 +typedef enum dwc_otg_halt_status
7293 + DWC_OTG_HC_XFER_NO_HALT_STATUS,
7294 + DWC_OTG_HC_XFER_COMPLETE,
7295 + DWC_OTG_HC_XFER_URB_COMPLETE,
7296 + DWC_OTG_HC_XFER_ACK,
7297 + DWC_OTG_HC_XFER_NAK,
7298 + DWC_OTG_HC_XFER_NYET,
7299 + DWC_OTG_HC_XFER_STALL,
7300 + DWC_OTG_HC_XFER_XACT_ERR,
7301 + DWC_OTG_HC_XFER_FRAME_OVERRUN,
7302 + DWC_OTG_HC_XFER_BABBLE_ERR,
7303 + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
7304 + DWC_OTG_HC_XFER_AHB_ERR,
7305 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
7306 + DWC_OTG_HC_XFER_URB_DEQUEUE
7307 +} dwc_otg_halt_status_e;
7310 + * Host channel descriptor. This structure represents the state of a single
7311 + * host channel when acting in host mode. It contains the data items needed to
7312 + * transfer packets to an endpoint via a host channel.
7314 +typedef struct dwc_hc
7316 + /** Host channel number used for register address lookup */
7319 + /** Device to access */
7320 + unsigned dev_addr : 7;
7322 + /** EP to access */
7323 + unsigned ep_num : 4;
7325 + /** EP direction. 0: OUT, 1: IN */
7326 + unsigned ep_is_in : 1;
7330 + * One of the following values:
7331 + * - DWC_OTG_EP_SPEED_LOW
7332 + * - DWC_OTG_EP_SPEED_FULL
7333 + * - DWC_OTG_EP_SPEED_HIGH
7335 + unsigned speed : 2;
7336 +#define DWC_OTG_EP_SPEED_LOW 0
7337 +#define DWC_OTG_EP_SPEED_FULL 1
7338 +#define DWC_OTG_EP_SPEED_HIGH 2
7342 + * One of the following values:
7343 + * - DWC_OTG_EP_TYPE_CONTROL: 0
7344 + * - DWC_OTG_EP_TYPE_ISOC: 1
7345 + * - DWC_OTG_EP_TYPE_BULK: 2
7346 + * - DWC_OTG_EP_TYPE_INTR: 3
7348 + unsigned ep_type : 2;
7350 + /** Max packet size in bytes */
7351 + unsigned max_packet : 11;
7354 + * PID for initial transaction.
7358 + * 3: MDATA (non-Control EP),
7359 + * SETUP (Control EP)
7361 + unsigned data_pid_start : 2;
7362 +#define DWC_OTG_HC_PID_DATA0 0
7363 +#define DWC_OTG_HC_PID_DATA2 1
7364 +#define DWC_OTG_HC_PID_DATA1 2
7365 +#define DWC_OTG_HC_PID_MDATA 3
7366 +#define DWC_OTG_HC_PID_SETUP 3
7368 + /** Number of periodic transactions per (micro)frame */
7369 + unsigned multi_count: 2;
7371 + /** @name Transfer State */
7374 + /** Pointer to the current transfer buffer position. */
7375 + uint8_t *xfer_buff;
7376 + /** Total number of bytes to transfer. */
7377 + uint32_t xfer_len;
7378 + /** Number of bytes transferred so far. */
7379 + uint32_t xfer_count;
7380 + /** Packet count at start of transfer.*/
7381 + uint16_t start_pkt_count;
7384 + * Flag to indicate whether the transfer has been started. Set to 1 if
7385 + * it has been started, 0 otherwise.
7387 + uint8_t xfer_started;
7390 + * Set to 1 to indicate that a PING request should be issued on this
7391 + * channel. If 0, process normally.
7396 + * Set to 1 to indicate that the error count for this transaction is
7397 + * non-zero. Set to 0 if the error count is 0.
7399 + uint8_t error_state;
7402 + * Set to 1 to indicate that this channel should be halted the next
7403 + * time a request is queued for the channel. This is necessary in
7404 + * slave mode if no request queue space is available when an attempt
7405 + * is made to halt the channel.
7407 + uint8_t halt_on_queue;
7410 + * Set to 1 if the host channel has been halted, but the core is not
7411 + * finished flushing queued requests. Otherwise 0.
7413 + uint8_t halt_pending;
7416 + * Reason for halting the host channel.
7418 + dwc_otg_halt_status_e halt_status;
7421 + * Split settings for the host channel
7423 + uint8_t do_split; /**< Enable split for the channel */
7424 + uint8_t complete_split; /**< Enable complete split */
7425 + uint8_t hub_addr; /**< Address of high speed hub */
7427 + uint8_t port_addr; /**< Port of the low/full speed device */
7428 + /** Split transaction position
7429 + * One of the following values:
7430 + * - DWC_HCSPLIT_XACTPOS_MID
7431 + * - DWC_HCSPLIT_XACTPOS_BEGIN
7432 + * - DWC_HCSPLIT_XACTPOS_END
7433 + * - DWC_HCSPLIT_XACTPOS_ALL */
7436 + /** Set when the host channel does a short read. */
7437 + uint8_t short_read;
7440 + * Number of requests issued for this channel since it was assigned to
7441 + * the current transfer (not counting PINGs).
7446 + * Queue Head for the transfer being processed by this channel.
7448 + struct dwc_otg_qh *qh;
7452 + /** Entry in list of host channels. */
7453 + struct list_head hc_list_entry;
7457 + * The following parameters may be specified when starting the module. These
7458 + * parameters define how the DWC_otg controller should be configured.
7459 + * Parameter values are passed to the CIL initialization function
7460 + * dwc_otg_cil_init.
7462 +typedef struct dwc_otg_core_params
7465 +#define dwc_param_opt_default 1
7468 + * Specifies the OTG capabilities. The driver will automatically
7469 + * detect the value for this parameter if none is specified.
7470 + * 0 - HNP and SRP capable (default)
7471 + * 1 - SRP Only capable
7472 + * 2 - No HNP/SRP capable
7475 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
7476 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
7477 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
7478 +//#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
7479 +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE
7482 + * Specifies whether to use slave or DMA mode for accessing the data
7483 + * FIFOs. The driver will automatically detect the value for this
7484 + * parameter if none is specified.
7486 + * 1 - DMA (default, if available)
7488 + int32_t dma_enable;
7489 +#define dwc_param_dma_enable_default 1
7492 + * When DMA mode is enabled specifies whether to use address DMA or DMA Descritor mode for accessing the data
7493 + * FIFOs in device mode. The driver will automatically detect the value for this
7494 + * parameter if none is specified.
7496 + * 1 - DMA Descriptor(default, if available)
7498 + int32_t dma_desc_enable;
7499 +#define dwc_param_dma_desc_enable_default 0
7500 + /** The DMA Burst size (applicable only for External DMA
7501 + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
7503 + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
7504 +//#define dwc_param_dma_burst_size_default 32
7505 +#define dwc_param_dma_burst_size_default 1
7508 + * Specifies the maximum speed of operation in host and device mode.
7509 + * The actual speed depends on the speed of the attached device and
7510 + * the value of phy_type. The actual speed depends on the speed of the
7511 + * attached device.
7512 + * 0 - High Speed (default)
7516 +#define dwc_param_speed_default 0
7517 +#define DWC_SPEED_PARAM_HIGH 0
7518 +#define DWC_SPEED_PARAM_FULL 1
7520 + /** Specifies whether low power mode is supported when attached
7521 + * to a Full Speed or Low Speed device in host mode.
7522 + * 0 - Don't support low power mode (default)
7523 + * 1 - Support low power mode
7525 + int32_t host_support_fs_ls_low_power;
7526 +#define dwc_param_host_support_fs_ls_low_power_default 0
7528 + /** Specifies the PHY clock rate in low power mode when connected to a
7529 + * Low Speed device in host mode. This parameter is applicable only if
7530 + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
7531 + * then defaults to 6 MHZ otherwise 48 MHZ.
7536 + int32_t host_ls_low_power_phy_clk;
7537 +#define dwc_param_host_ls_low_power_phy_clk_default 0
7538 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
7539 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
7542 + * 0 - Use cC FIFO size parameters
7543 + * 1 - Allow dynamic FIFO sizing (default)
7545 + int32_t enable_dynamic_fifo;
7546 +#define dwc_param_enable_dynamic_fifo_default 1
7548 + /** Total number of 4-byte words in the data FIFO memory. This
7549 + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
7551 + * 32 to 32768 (default 8192)
7552 + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
7554 + int32_t data_fifo_size;
7555 +#define dwc_param_data_fifo_size_default 8192
7557 + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
7558 + * FIFO sizing is enabled.
7559 + * 16 to 32768 (default 1064)
7561 + int32_t dev_rx_fifo_size;
7562 +//#define dwc_param_dev_rx_fifo_size_default 1064
7563 +#define dwc_param_dev_rx_fifo_size_default 0x100
7566 + * Specifies whether dedicated transmit FIFOs are
7567 + * enabled for non periodic IN endpoints in device mode
7571 + int32_t en_multiple_tx_fifo;
7572 +#define dwc_param_en_multiple_tx_fifo_default 1
7574 + /** Number of 4-byte words in each of the Tx FIFOs in device
7575 + * mode when dynamic FIFO sizing is enabled.
7576 + * 4 to 768 (default 256)
7578 + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
7579 +//#define dwc_param_dev_tx_fifo_size_default 256
7580 +#define dwc_param_dev_tx_fifo_size_default 0x80
7582 + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
7583 + * when dynamic FIFO sizing is enabled.
7584 + * 16 to 32768 (default 1024)
7586 + int32_t dev_nperio_tx_fifo_size;
7587 +//#define dwc_param_dev_nperio_tx_fifo_size_default 1024
7588 +#define dwc_param_dev_nperio_tx_fifo_size_default 0x80
7590 + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
7591 + * mode when dynamic FIFO sizing is enabled.
7592 + * 4 to 768 (default 256)
7594 + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
7595 +//#define dwc_param_dev_perio_tx_fifo_size_default 256
7596 +#define dwc_param_dev_perio_tx_fifo_size_default 0x80
7598 + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
7599 + * FIFO sizing is enabled.
7600 + * 16 to 32768 (default 1024)
7602 + int32_t host_rx_fifo_size;
7603 +//#define dwc_param_host_rx_fifo_size_default 1024
7604 +#define dwc_param_host_rx_fifo_size_default 0x292
7606 + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
7607 + * when Dynamic FIFO sizing is enabled in the core.
7608 + * 16 to 32768 (default 1024)
7610 + int32_t host_nperio_tx_fifo_size;
7611 +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
7612 +//#define dwc_param_host_nperio_tx_fifo_size_default 0x292
7613 +#define dwc_param_host_nperio_tx_fifo_size_default 0x80
7615 + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
7616 + * FIFO sizing is enabled.
7617 + * 16 to 32768 (default 1024)
7619 + int32_t host_perio_tx_fifo_size;
7620 +//#define dwc_param_host_perio_tx_fifo_size_default 1024
7621 +#define dwc_param_host_perio_tx_fifo_size_default 0x292
7623 + /** The maximum transfer size supported in bytes.
7624 + * 2047 to 65,535 (default 65,535)
7626 + int32_t max_transfer_size;
7627 +#define dwc_param_max_transfer_size_default 65535
7629 + /** The maximum number of packets in a transfer.
7630 + * 15 to 511 (default 511)
7632 + int32_t max_packet_count;
7633 +#define dwc_param_max_packet_count_default 511
7635 + /** The number of host channel registers to use.
7636 + * 1 to 16 (default 12)
7637 + * Note: The FPGA configuration supports a maximum of 12 host channels.
7639 + int32_t host_channels;
7640 +//#define dwc_param_host_channels_default 12
7641 +#define dwc_param_host_channels_default 16
7643 + /** The number of endpoints in addition to EP0 available for device
7644 + * mode operations.
7645 + * 1 to 15 (default 6 IN and OUT)
7646 + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
7647 + * endpoints in addition to EP0.
7649 + int32_t dev_endpoints;
7650 +//#define dwc_param_dev_endpoints_default 6
7651 +#define dwc_param_dev_endpoints_default 8
7654 + * Specifies the type of PHY interface to use. By default, the driver
7655 + * will automatically detect the phy_type.
7657 + * 0 - Full Speed PHY
7658 + * 1 - UTMI+ (default)
7662 +#define DWC_PHY_TYPE_PARAM_FS 0
7663 +#define DWC_PHY_TYPE_PARAM_UTMI 1
7664 +#define DWC_PHY_TYPE_PARAM_ULPI 2
7665 +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
7668 + * Specifies the UTMI+ Data Width. This parameter is
7669 + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
7670 + * PHY_TYPE, this parameter indicates the data width between
7671 + * the MAC and the ULPI Wrapper.) Also, this parameter is
7672 + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
7673 + * to "8 and 16 bits", meaning that the core has been
7674 + * configured to work at either data path width.
7676 + * 8 or 16 bits (default 16)
7678 + int32_t phy_utmi_width;
7679 +#define dwc_param_phy_utmi_width_default 16
7682 + * Specifies whether the ULPI operates at double or single
7683 + * data rate. This parameter is only applicable if PHY_TYPE is
7686 + * 0 - single data rate ULPI interface with 8 bit wide data
7688 + * 1 - double data rate ULPI interface with 4 bit wide data
7691 + int32_t phy_ulpi_ddr;
7692 +#define dwc_param_phy_ulpi_ddr_default 0
7695 + * Specifies whether to use the internal or external supply to
7696 + * drive the vbus with a ULPI phy.
7698 + int32_t phy_ulpi_ext_vbus;
7699 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
7700 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
7701 +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
7704 + * Specifies whether to use the I2Cinterface for full speed PHY. This
7705 + * parameter is only applicable if PHY_TYPE is FS.
7706 + * 0 - No (default)
7709 + int32_t i2c_enable;
7710 +#define dwc_param_i2c_enable_default 0
7712 + int32_t ulpi_fs_ls;
7713 +#define dwc_param_ulpi_fs_ls_default 0
7716 +#define dwc_param_ts_dline_default 0
7718 + /** Thresholding enable flag-
7719 + * bit 0 - enable non-ISO Tx thresholding
7720 + * bit 1 - enable ISO Tx thresholding
7721 + * bit 2 - enable Rx thresholding
7724 +#define dwc_param_thr_ctl_default 0
7726 + /** Thresholding length for Tx
7727 + * FIFOs in 32 bit DWORDs
7729 + uint32_t tx_thr_length;
7730 +#define dwc_param_tx_thr_length_default 64
7732 + /** Thresholding length for Rx
7733 + * FIFOs in 32 bit DWORDs
7735 + uint32_t rx_thr_length;
7736 +#define dwc_param_rx_thr_length_default 64
7738 + /** Per Transfer Interrupt
7739 + * mode enable flag
7743 + uint32_t pti_enable;
7744 +#define dwc_param_pti_enable_default 0
7746 + /** Molti Processor Interrupt
7747 + * mode enable flag
7751 + uint32_t mpi_enable;
7752 +#define dwc_param_mpi_enable_default 0
7754 +} dwc_otg_core_params_t;
7757 +struct dwc_otg_core_if;
7758 +typedef struct hc_xfer_info
7760 + struct dwc_otg_core_if *core_if;
7766 + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
7767 + * the DWC_otg controller acting in either host or device mode. It
7768 + * represents the programming view of the controller as a whole.
7770 +typedef struct dwc_otg_core_if
7772 + /** Parameters that define how the core should be configured.*/
7773 + dwc_otg_core_params_t *core_params;
7775 + /** Core Global registers starting at offset 000h. */
7776 + dwc_otg_core_global_regs_t *core_global_regs;
7778 + /** Device-specific information */
7779 + dwc_otg_dev_if_t *dev_if;
7780 + /** Host-specific information */
7781 + dwc_otg_host_if_t *host_if;
7783 + /** Value from SNPSID register */
7787 + * Set to 1 if the core PHY interface bits in USBCFG have been
7790 + uint8_t phy_init_done;
7793 + * SRP Success flag, set by srp success interrupt in FS I2C mode
7795 + uint8_t srp_success;
7796 + uint8_t srp_timer_started;
7798 + /* Common configuration information */
7799 + /** Power and Clock Gating Control Register */
7800 + volatile uint32_t *pcgcctl;
7801 +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
7803 + /** Push/pop addresses for endpoints or host channels.*/
7804 + uint32_t *data_fifo[MAX_EPS_CHANNELS];
7805 +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
7806 +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
7808 + /** Total RAM for FIFOs (Bytes) */
7809 + uint16_t total_fifo_size;
7810 + /** Size of Rx FIFO (Bytes) */
7811 + uint16_t rx_fifo_size;
7812 + /** Size of Non-periodic Tx FIFO (Bytes) */
7813 + uint16_t nperio_tx_fifo_size;
7816 + /** 1 if DMA is enabled, 0 otherwise. */
7817 + uint8_t dma_enable;
7819 + /** 1 if Descriptor DMA mode is enabled, 0 otherwise. */
7820 + uint8_t dma_desc_enable;
7822 + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
7823 + uint8_t pti_enh_enable;
7825 + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
7826 + uint8_t multiproc_int_enable;
7828 + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
7829 + uint8_t en_multiple_tx_fifo;
7831 + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
7832 + * process of being queued */
7833 + uint8_t queuing_high_bandwidth;
7835 + /** Hardware Configuration -- stored here for convenience.*/
7836 + hwcfg1_data_t hwcfg1;
7837 + hwcfg2_data_t hwcfg2;
7838 + hwcfg3_data_t hwcfg3;
7839 + hwcfg4_data_t hwcfg4;
7841 + /** Host and Device Configuration -- stored here for convenience.*/
7845 + /** The operational State, during transations
7846 + * (a_host>>a_peripherial and b_device=>b_host) this may not
7847 + * match the core but allows the software to determine
7853 + * Set to 1 if the HCD needs to be restarted on a session request
7854 + * interrupt. This is required if no connector ID status change has
7855 + * occurred since the HCD was last disconnected.
7857 + uint8_t restart_hcd_on_session_req;
7859 + /** HCD callbacks */
7860 + /** A-Device is a_host */
7862 + /** A-Device is a_suspend */
7863 +#define A_SUSPEND (2)
7864 + /** A-Device is a_peripherial */
7865 +#define A_PERIPHERAL (3)
7866 + /** B-Device is operating as a Peripheral. */
7867 +#define B_PERIPHERAL (4)
7868 + /** B-Device is operating as a Host. */
7871 + /** HCD callbacks */
7872 + struct dwc_otg_cil_callbacks *hcd_cb;
7873 + /** PCD callbacks */
7874 + struct dwc_otg_cil_callbacks *pcd_cb;
7876 + /** Device mode Periodic Tx FIFO Mask */
7877 + uint32_t p_tx_msk;
7878 + /** Device mode Periodic Tx FIFO Mask */
7881 + /** Workqueue object used for handling several interrupts */
7882 + struct workqueue_struct *wq_otg;
7884 + /** Work object used for handling "Connector ID Status Change" Interrupt */
7885 + struct work_struct w_conn_id;
7887 + /** Work object used for handling "Wakeup Detected" Interrupt */
7888 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7889 + struct work_struct w_wkp;
7891 + struct delayed_work w_wkp;
7895 + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
7897 + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
7898 + struct timer_list hc_xfer_timer[MAX_EPS_CHANNELS];
7900 + uint32_t hfnum_7_samples;
7901 + uint64_t hfnum_7_frrem_accum;
7902 + uint32_t hfnum_0_samples;
7903 + uint64_t hfnum_0_frrem_accum;
7904 + uint32_t hfnum_other_samples;
7905 + uint64_t hfnum_other_frrem_accum;
7909 +} dwc_otg_core_if_t;
7911 +/*We must clear S3C24XX_EINTPEND external interrupt register
7912 + * because after clearing in this register trigerred IRQ from
7913 + * H/W core in kernel interrupt can be occured again before OTG
7914 + * handlers clear all IRQ sources of Core registers because of
7915 + * timing latencies and Low Level IRQ Type.
7918 +#ifdef CONFIG_MACH_IPMATE
7919 +#define S3C2410X_CLEAR_EINTPEND() \
7921 + if (!dwc_otg_read_core_intr(core_if)) { \
7922 + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
7926 +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
7930 + * The following functions are functions for works
7931 + * using during handling some interrupts
7933 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7935 +extern void w_conn_id_status_change(void *p);
7936 +extern void w_wakeup_detected(void *p);
7940 +extern void w_conn_id_status_change(struct work_struct *p);
7941 +extern void w_wakeup_detected(struct work_struct *p);
7947 + * The following functions support initialization of the CIL driver component
7948 + * and the DWC_otg controller.
7950 +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
7951 + dwc_otg_core_params_t *_core_params);
7952 +extern void dwc_otg_cil_remove(dwc_otg_core_if_t *_core_if);
7953 +extern void dwc_otg_core_init(dwc_otg_core_if_t *_core_if);
7954 +extern void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if);
7955 +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if);
7956 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if );
7957 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if );
7959 +/** @name Device CIL Functions
7960 + * The following functions support managing the DWC_otg controller in device
7964 +extern void dwc_otg_wakeup(dwc_otg_core_if_t *_core_if);
7965 +extern void dwc_otg_read_setup_packet (dwc_otg_core_if_t *_core_if, uint32_t *_dest);
7966 +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if);
7967 +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7968 +extern void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7969 +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7970 +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7971 +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7972 +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7973 +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7974 +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma);
7975 +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7976 +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
7977 +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if);
7978 +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if);
7979 +extern void dwc_otg_dump_spram(dwc_otg_core_if_t *_core_if);
7981 +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep);
7982 +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep);
7983 +#endif //DWC_EN_ISOC
7986 +/** @name Host CIL Functions
7987 + * The following functions support managing the DWC_otg controller in host
7991 +extern void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7992 +extern void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
7994 + dwc_otg_halt_status_e _halt_status);
7995 +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7996 +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7997 +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7998 +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
7999 +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
8000 +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if);
8001 +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if);
8004 + * This function Reads HPRT0 in preparation to modify. It keeps the
8005 + * WC bits 0 so that if they are read as 1, they won't clear when you
8008 +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t *_core_if)
8010 + hprt0_data_t hprt0;
8011 + hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
8012 + hprt0.b.prtena = 0;
8013 + hprt0.b.prtconndet = 0;
8014 + hprt0.b.prtenchng = 0;
8015 + hprt0.b.prtovrcurrchng = 0;
8019 +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if);
8022 +/** @name Common CIL Functions
8023 + * The following functions support managing the DWC_otg controller in either
8024 + * device or host mode.
8028 +extern void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
8032 +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if);
8034 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
8036 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if );
8037 +extern void dwc_otg_core_reset( dwc_otg_core_if_t *_core_if );
8039 +extern dwc_otg_dma_desc_t* dwc_otg_ep_alloc_desc_chain(uint32_t * dma_desc_addr, uint32_t count);
8040 +extern void dwc_otg_ep_free_desc_chain(dwc_otg_dma_desc_t* desc_addr, uint32_t dma_desc_addr, uint32_t count);
8043 + * This function returns the Core Interrupt register.
8045 +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t *_core_if)
8047 + return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) &
8048 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
8052 + * This function returns the OTG Interrupt register.
8054 +static inline uint32_t dwc_otg_read_otg_intr (dwc_otg_core_if_t *_core_if)
8056 + return (dwc_read_reg32 (&_core_if->core_global_regs->gotgint));
8060 + * This function reads the Device All Endpoints Interrupt register and
8061 + * returns the IN endpoint interrupt bits.
8063 +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *core_if)
8067 + if(core_if->multiproc_int_enable) {
8068 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachint) &
8069 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachintmsk);
8071 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->daint) &
8072 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk);
8074 + return (v & 0xffff);
8079 + * This function reads the Device All Endpoints Interrupt register and
8080 + * returns the OUT endpoint interrupt bits.
8082 +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *core_if)
8086 + if(core_if->multiproc_int_enable) {
8087 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachint) &
8088 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->deachintmsk);
8090 + v = dwc_read_reg32(&core_if->dev_if->dev_global_regs->daint) &
8091 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->daintmsk);
8094 + return ((v & 0xffff0000) >> 16);
8098 + * This function returns the Device IN EP Interrupt register
8100 +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t *core_if,
8103 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
8104 + uint32_t v, msk, emp;
8106 + if(core_if->multiproc_int_enable) {
8107 + msk = dwc_read_reg32(&dev_if->dev_global_regs->diepeachintmsk[ep->num]);
8108 + emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
8109 + msk |= ((emp >> ep->num) & 0x1) << 7;
8110 + v = dwc_read_reg32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
8112 + msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
8113 + emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
8114 + msk |= ((emp >> ep->num) & 0x1) << 7;
8115 + v = dwc_read_reg32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
8122 + * This function returns the Device OUT EP Interrupt register
8124 +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *_core_if,
8127 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
8129 + doepmsk_data_t msk = { .d32 = 0 };
8131 + if(_core_if->multiproc_int_enable) {
8132 + msk.d32 = dwc_read_reg32(&dev_if->dev_global_regs->doepeachintmsk[_ep->num]);
8133 + if(_core_if->pti_enh_enable) {
8134 + msk.b.pktdrpsts = 1;
8136 + v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) & msk.d32;
8138 + msk.d32 = dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
8139 + if(_core_if->pti_enh_enable) {
8140 + msk.b.pktdrpsts = 1;
8142 + v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) & msk.d32;
8148 + * This function returns the Host All Channel Interrupt register
8150 +static inline uint32_t dwc_otg_read_host_all_channels_intr (dwc_otg_core_if_t *_core_if)
8152 + return (dwc_read_reg32 (&_core_if->host_if->host_global_regs->haint));
8155 +static inline uint32_t dwc_otg_read_host_channel_intr (dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
8157 + return (dwc_read_reg32 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
8162 + * This function returns the mode of the operation, host or device.
8164 + * @return 0 - Device Mode, 1 - Host Mode
8166 +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t *_core_if)
8168 + return (dwc_read_reg32( &_core_if->core_global_regs->gintsts ) & 0x1);
8171 +static inline uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t *_core_if)
8173 + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
8175 +static inline uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t *_core_if)
8177 + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
8180 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if );
8186 + * DWC_otg CIL callback structure. This structure allows the HCD and
8187 + * PCD to register functions used for starting and stopping the PCD
8188 + * and HCD for role change on for a DRD.
8190 +typedef struct dwc_otg_cil_callbacks
8192 + /** Start function for role change */
8193 + int (*start) (void *_p);
8194 + /** Stop Function for role change */
8195 + int (*stop) (void *_p);
8196 + /** Disconnect Function for role change */
8197 + int (*disconnect) (void *_p);
8198 + /** Resume/Remote wakeup Function */
8199 + int (*resume_wakeup) (void *_p);
8200 + /** Suspend function */
8201 + int (*suspend) (void *_p);
8202 + /** Session Start (SRP) */
8203 + int (*session_start) (void *_p);
8204 + /** Pointer passed to start() and stop() */
8206 +} dwc_otg_cil_callbacks_t;
8208 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
8209 + dwc_otg_cil_callbacks_t *_cb,
8211 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
8212 + dwc_otg_cil_callbacks_t *_cb,
8215 +#define warn printk
8221 +++ b/drivers/usb/host/otg/dwc_otg_cil_intr.c
8223 +/* ==========================================================================
8224 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
8225 + * $Revision: #10 $
8226 + * $Date: 2008/07/16 $
8227 + * $Change: 1065567 $
8229 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8230 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
8231 + * otherwise expressly agreed to in writing between Synopsys and you.
8233 + * The Software IS NOT an item of Licensed Software or Licensed Product under
8234 + * any End User Software License Agreement or Agreement for Licensed Product
8235 + * with Synopsys or any supplement thereto. You are permitted to use and
8236 + * redistribute this Software in source and binary forms, with or without
8237 + * modification, provided that redistributions of source code must retain this
8238 + * notice. You may not view, use, disclose, copy or distribute this file or
8239 + * any information contained herein except pursuant to this license grant from
8240 + * Synopsys. If you do not agree with this notice, including the disclaimer
8241 + * below, then you are not authorized to use the Software.
8243 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
8244 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8245 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8246 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
8247 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8248 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
8249 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
8250 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
8251 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
8252 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
8254 + * ========================================================================== */
8258 + * The Core Interface Layer provides basic services for accessing and
8259 + * managing the DWC_otg hardware. These services are used by both the
8260 + * Host Controller Driver and the Peripheral Controller Driver.
8262 + * This file contains the Common Interrupt handlers.
8264 +#include "dwc_otg_plat.h"
8265 +#include "dwc_otg_regs.h"
8266 +#include "dwc_otg_cil.h"
8267 +#include "dwc_otg_pcd.h"
8270 +inline const char *op_state_str(dwc_otg_core_if_t *core_if)
8272 + return (core_if->op_state==A_HOST?"a_host":
8273 + (core_if->op_state==A_SUSPEND?"a_suspend":
8274 + (core_if->op_state==A_PERIPHERAL?"a_peripheral":
8275 + (core_if->op_state==B_PERIPHERAL?"b_peripheral":
8276 + (core_if->op_state==B_HOST?"b_host":
8281 +/** This function will log a debug message
8283 + * @param core_if Programming view of DWC_otg controller.
8285 +int32_t dwc_otg_handle_mode_mismatch_intr (dwc_otg_core_if_t *core_if)
8287 + gintsts_data_t gintsts;
8288 + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
8289 + dwc_otg_mode(core_if) ? "Host" : "Device");
8291 + /* Clear interrupt */
8293 + gintsts.b.modemismatch = 1;
8294 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8298 +/** Start the HCD. Helper function for using the HCD callbacks.
8300 + * @param core_if Programming view of DWC_otg controller.
8302 +static inline void hcd_start(dwc_otg_core_if_t *core_if)
8304 + if (core_if->hcd_cb && core_if->hcd_cb->start) {
8305 + core_if->hcd_cb->start(core_if->hcd_cb->p);
8308 +/** Stop the HCD. Helper function for using the HCD callbacks.
8310 + * @param core_if Programming view of DWC_otg controller.
8312 +static inline void hcd_stop(dwc_otg_core_if_t *core_if)
8314 + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
8315 + core_if->hcd_cb->stop(core_if->hcd_cb->p);
8318 +/** Disconnect the HCD. Helper function for using the HCD callbacks.
8320 + * @param core_if Programming view of DWC_otg controller.
8322 +static inline void hcd_disconnect(dwc_otg_core_if_t *core_if)
8324 + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
8325 + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
8328 +/** Inform the HCD the a New Session has begun. Helper function for
8329 + * using the HCD callbacks.
8331 + * @param core_if Programming view of DWC_otg controller.
8333 +static inline void hcd_session_start(dwc_otg_core_if_t *core_if)
8335 + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
8336 + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
8340 +/** Start the PCD. Helper function for using the PCD callbacks.
8342 + * @param core_if Programming view of DWC_otg controller.
8344 +static inline void pcd_start(dwc_otg_core_if_t *core_if)
8346 + if (core_if->pcd_cb && core_if->pcd_cb->start) {
8347 + core_if->pcd_cb->start(core_if->pcd_cb->p);
8350 +/** Stop the PCD. Helper function for using the PCD callbacks.
8352 + * @param core_if Programming view of DWC_otg controller.
8354 +static inline void pcd_stop(dwc_otg_core_if_t *core_if)
8356 + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
8357 + core_if->pcd_cb->stop(core_if->pcd_cb->p);
8360 +/** Suspend the PCD. Helper function for using the PCD callbacks.
8362 + * @param core_if Programming view of DWC_otg controller.
8364 +static inline void pcd_suspend(dwc_otg_core_if_t *core_if)
8366 + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
8367 + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
8370 +/** Resume the PCD. Helper function for using the PCD callbacks.
8372 + * @param core_if Programming view of DWC_otg controller.
8374 +static inline void pcd_resume(dwc_otg_core_if_t *core_if)
8376 + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
8377 + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
8382 + * This function handles the OTG Interrupts. It reads the OTG
8383 + * Interrupt Register (GOTGINT) to determine what interrupt has
8386 + * @param core_if Programming view of DWC_otg controller.
8388 +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t *core_if)
8390 + dwc_otg_core_global_regs_t *global_regs =
8391 + core_if->core_global_regs;
8392 + gotgint_data_t gotgint;
8393 + gotgctl_data_t gotgctl;
8394 + gintmsk_data_t gintmsk;
8396 + gotgint.d32 = dwc_read_reg32(&global_regs->gotgint);
8397 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
8398 + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
8399 + op_state_str(core_if));
8400 + //DWC_DEBUGPL(DBG_CIL, "gotgctl=%08x\n", gotgctl.d32);
8402 + if (gotgint.b.sesenddet) {
8403 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
8404 + "Session End Detected++ (%s)\n",
8405 + op_state_str(core_if));
8406 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
8408 + if (core_if->op_state == B_HOST) {
8410 + dwc_otg_pcd_t *pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8411 + if(unlikely(!pcd)) {
8412 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8415 + SPIN_LOCK(&pcd->lock);
8417 + pcd_start(core_if);
8419 + SPIN_UNLOCK(&pcd->lock);
8420 + core_if->op_state = B_PERIPHERAL;
8422 + dwc_otg_pcd_t *pcd;
8424 + /* If not B_HOST and Device HNP still set. HNP
8425 + * Did not succeed!*/
8426 + if (gotgctl.b.devhnpen) {
8427 + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
8428 + DWC_ERROR("Device Not Connected/Responding!\n");
8431 + /* If Session End Detected the B-Cable has
8432 + * been disconnected. */
8433 + /* Reset PCD and Gadget driver to a
8436 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8437 + if(unlikely(!pcd)) {
8438 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8441 + SPIN_LOCK(&pcd->lock);
8443 + pcd_stop(core_if);
8445 + SPIN_UNLOCK(&pcd->lock);
8448 + gotgctl.b.devhnpen = 1;
8449 + dwc_modify_reg32(&global_regs->gotgctl,
8452 + if (gotgint.b.sesreqsucstschng) {
8453 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
8454 + "Session Reqeust Success Status Change++\n");
8455 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
8456 + if (gotgctl.b.sesreqscs) {
8457 + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
8458 + (core_if->core_params->i2c_enable)) {
8459 + core_if->srp_success = 1;
8462 + dwc_otg_pcd_t *pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8463 + if(unlikely(!pcd)) {
8464 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8467 + SPIN_LOCK(&pcd->lock);
8469 + pcd_resume(core_if);
8471 + SPIN_UNLOCK(&pcd->lock);
8472 + /* Clear Session Request */
8474 + gotgctl.b.sesreq = 1;
8475 + dwc_modify_reg32(&global_regs->gotgctl,
8480 + if (gotgint.b.hstnegsucstschng) {
8481 + /* Print statements during the HNP interrupt handling
8482 + * can cause it to fail.*/
8483 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
8484 + if (gotgctl.b.hstnegscs) {
8485 + if (dwc_otg_is_host_mode(core_if)) {
8486 + dwc_otg_pcd_t *pcd;
8488 + core_if->op_state = B_HOST;
8490 + * Need to disable SOF interrupt immediately.
8491 + * When switching from device to host, the PCD
8492 + * interrupt handler won't handle the
8493 + * interrupt if host mode is already set. The
8494 + * HCD interrupt handler won't get called if
8495 + * the HCD state is HALT. This means that the
8496 + * interrupt does not get handled and Linux
8497 + * complains loudly.
8500 + gintmsk.b.sofintr = 1;
8501 + dwc_modify_reg32(&global_regs->gintmsk,
8504 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8505 + if(unlikely(!pcd)) {
8506 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8509 + SPIN_LOCK(&pcd->lock);
8511 + pcd_stop(core_if);
8513 + SPIN_UNLOCK(&pcd->lock);
8515 + * Initialize the Core for Host mode.
8517 + hcd_start(core_if);
8518 + core_if->op_state = B_HOST;
8522 + gotgctl.b.hnpreq = 1;
8523 + gotgctl.b.devhnpen = 1;
8524 + dwc_modify_reg32(&global_regs->gotgctl,
8526 + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
8527 + DWC_ERROR("Device Not Connected/Responding\n");
8530 + if (gotgint.b.hstnegdet) {
8531 + /* The disconnect interrupt is set at the same time as
8532 + * Host Negotiation Detected. During the mode
8533 + * switch all interrupts are cleared so the disconnect
8534 + * interrupt handler will not get executed.
8536 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
8537 + "Host Negotiation Detected++ (%s)\n",
8538 + (dwc_otg_is_host_mode(core_if)?"Host":"Device"));
8539 + if (dwc_otg_is_device_mode(core_if)){
8540 + dwc_otg_pcd_t *pcd;
8542 + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n", core_if->op_state);
8543 + hcd_disconnect(core_if);
8545 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8546 + if(unlikely(!pcd)) {
8547 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8550 + SPIN_LOCK(&pcd->lock);
8552 + pcd_start(core_if);
8554 + SPIN_UNLOCK(&pcd->lock);
8555 + core_if->op_state = A_PERIPHERAL;
8557 + dwc_otg_pcd_t *pcd;
8560 + * Need to disable SOF interrupt immediately. When
8561 + * switching from device to host, the PCD interrupt
8562 + * handler won't handle the interrupt if host mode is
8563 + * already set. The HCD interrupt handler won't get
8564 + * called if the HCD state is HALT. This means that
8565 + * the interrupt does not get handled and Linux
8566 + * complains loudly.
8569 + gintmsk.b.sofintr = 1;
8570 + dwc_modify_reg32(&global_regs->gintmsk,
8573 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8574 + if(unlikely(!pcd)) {
8575 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8578 + SPIN_LOCK(&pcd->lock);
8580 + pcd_stop(core_if);
8582 + SPIN_UNLOCK(&pcd->lock);
8583 + hcd_start(core_if);
8584 + core_if->op_state = A_HOST;
8587 + if (gotgint.b.adevtoutchng) {
8588 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
8589 + "A-Device Timeout Change++\n");
8591 + if (gotgint.b.debdone) {
8592 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
8593 + "Debounce Done++\n");
8596 + /* Clear GOTGINT */
8597 + dwc_write_reg32 (&core_if->core_global_regs->gotgint, gotgint.d32);
8603 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
8605 +void w_conn_id_status_change(void *p)
8607 + dwc_otg_core_if_t *core_if = p;
8611 +void w_conn_id_status_change(struct work_struct *p)
8613 + dwc_otg_core_if_t *core_if = container_of(p, dwc_otg_core_if_t, w_conn_id);
8618 + uint32_t count = 0;
8619 + gotgctl_data_t gotgctl = { .d32 = 0 };
8621 + gotgctl.d32 = dwc_read_reg32(&core_if->core_global_regs->gotgctl);
8622 + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
8623 + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
8625 + /* B-Device connector (Device Mode) */
8626 + if (gotgctl.b.conidsts) {
8627 + dwc_otg_pcd_t *pcd;
8629 + /* Wait for switch to device mode. */
8630 + while (!dwc_otg_is_device_mode(core_if)){
8631 + DWC_PRINT("Waiting for Peripheral Mode, Mode=%s\n",
8632 + (dwc_otg_is_host_mode(core_if)?"Host":"Peripheral"));
8634 + if (++count > 10000) *(uint32_t*)NULL=0;
8636 + core_if->op_state = B_PERIPHERAL;
8637 + dwc_otg_core_init(core_if);
8638 + dwc_otg_enable_global_interrupts(core_if);
8640 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8641 + if(unlikely(!pcd)) {
8642 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8645 + SPIN_LOCK(&pcd->lock);
8647 + pcd_start(core_if);
8649 + SPIN_UNLOCK(&pcd->lock);
8651 + /* A-Device connector (Host Mode) */
8652 + while (!dwc_otg_is_host_mode(core_if)) {
8653 + DWC_PRINT("Waiting for Host Mode, Mode=%s\n",
8654 + (dwc_otg_is_host_mode(core_if)?"Host":"Peripheral"));
8656 + if (++count > 10000) *(uint32_t*)NULL=0;
8658 + core_if->op_state = A_HOST;
8660 + * Initialize the Core for Host mode.
8662 + dwc_otg_core_init(core_if);
8663 + dwc_otg_enable_global_interrupts(core_if);
8664 + hcd_start(core_if);
8670 + * This function handles the Connector ID Status Change Interrupt. It
8671 + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
8672 + * is a Device to Host Mode transition or a Host Mode to Device
8675 + * This only occurs when the cable is connected/removed from the PHY
8678 + * @param core_if Programming view of DWC_otg controller.
8680 +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t *core_if)
8684 + * Need to disable SOF interrupt immediately. If switching from device
8685 + * to host, the PCD interrupt handler won't handle the interrupt if
8686 + * host mode is already set. The HCD interrupt handler won't get
8687 + * called if the HCD state is HALT. This means that the interrupt does
8688 + * not get handled and Linux complains loudly.
8690 + gintmsk_data_t gintmsk = { .d32 = 0 };
8691 + gintsts_data_t gintsts = { .d32 = 0 };
8693 + gintmsk.b.sofintr = 1;
8694 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
8696 + DWC_DEBUGPL(DBG_CIL, " ++Connector ID Status Change Interrupt++ (%s)\n",
8697 + (dwc_otg_is_host_mode(core_if)?"Host":"Device"));
8700 + * Need to schedule a work, as there are possible DELAY function calls
8702 + queue_work(core_if->wq_otg, &core_if->w_conn_id);
8704 + /* Set flag and clear interrupt */
8705 + gintsts.b.conidstschng = 1;
8706 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8712 + * This interrupt indicates that a device is initiating the Session
8713 + * Request Protocol to request the host to turn on bus power so a new
8714 + * session can begin. The handler responds by turning on bus power. If
8715 + * the DWC_otg controller is in low power mode, the handler brings the
8716 + * controller out of low power mode before turning on bus power.
8718 + * @param core_if Programming view of DWC_otg controller.
8720 +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t *core_if)
8722 + hprt0_data_t hprt0;
8723 + gintsts_data_t gintsts;
8725 +#ifndef DWC_HOST_ONLY
8726 + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
8728 + if (dwc_otg_is_device_mode(core_if)) {
8729 + DWC_PRINT("SRP: Device mode\n");
8731 + DWC_PRINT("SRP: Host mode\n");
8733 + /* Turn on the port power bit. */
8734 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
8735 + hprt0.b.prtpwr = 1;
8736 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8738 + /* Start the Connection timer. So a message can be displayed
8739 + * if connect does not occur within 10 seconds. */
8740 + hcd_session_start(core_if);
8744 + /* Clear interrupt */
8746 + gintsts.b.sessreqintr = 1;
8747 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8753 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
8754 +void w_wakeup_detected(void *p)
8756 + dwc_otg_core_if_t* core_if = p;
8760 +void w_wakeup_detected(struct work_struct *p)
8762 + struct delayed_work *dw = container_of(p, struct delayed_work, work);
8763 + dwc_otg_core_if_t *core_if = container_of(dw, dwc_otg_core_if_t, w_wkp);
8767 + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
8768 + * so that OPT tests pass with all PHYs).
8770 + hprt0_data_t hprt0 = {.d32=0};
8772 + pcgcctl_data_t pcgcctl = {.d32=0};
8773 + /* Restart the Phy Clock */
8774 + pcgcctl.b.stoppclk = 1;
8775 + dwc_modify_reg32(core_if->pcgcctl, pcgcctl.d32, 0);
8778 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
8779 + DWC_DEBUGPL(DBG_ANY,"Resume: HPRT0=%0x\n", hprt0.d32);
8781 + hprt0.b.prtres = 0; /* Resume */
8782 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8783 + DWC_DEBUGPL(DBG_ANY,"Clear Resume: HPRT0=%0x\n", dwc_read_reg32(core_if->host_if->hprt0));
8786 + * This interrupt indicates that the DWC_otg controller has detected a
8787 + * resume or remote wakeup sequence. If the DWC_otg controller is in
8788 + * low power mode, the handler must brings the controller out of low
8789 + * power mode. The controller automatically begins resume
8790 + * signaling. The handler schedules a time to stop resume signaling.
8792 +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t *core_if)
8794 + gintsts_data_t gintsts;
8796 + DWC_DEBUGPL(DBG_ANY, "++Resume and Remote Wakeup Detected Interrupt++\n");
8798 + if (dwc_otg_is_device_mode(core_if)) {
8799 + dctl_data_t dctl = {.d32=0};
8800 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
8801 + dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts));
8802 +#ifdef PARTIAL_POWER_DOWN
8803 + if (core_if->hwcfg4.b.power_optimiz) {
8804 + pcgcctl_data_t power = {.d32=0};
8806 + power.d32 = dwc_read_reg32(core_if->pcgcctl);
8807 + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n", power.d32);
8809 + power.b.stoppclk = 0;
8810 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8812 + power.b.pwrclmp = 0;
8813 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8815 + power.b.rstpdwnmodule = 0;
8816 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8819 + /* Clear the Remote Wakeup Signalling */
8820 + dctl.b.rmtwkupsig = 1;
8821 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dctl,
8824 + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
8825 + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
8829 + pcgcctl_data_t pcgcctl = {.d32=0};
8831 + /* Restart the Phy Clock */
8832 + pcgcctl.b.stoppclk = 1;
8833 + dwc_modify_reg32(core_if->pcgcctl, pcgcctl.d32, 0);
8835 + queue_delayed_work(core_if->wq_otg, &core_if->w_wkp, ((70 * HZ / 1000) + 1));
8838 + /* Clear interrupt */
8840 + gintsts.b.wkupintr = 1;
8841 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8847 + * This interrupt indicates that a device has been disconnected from
8850 +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t *core_if)
8852 + gintsts_data_t gintsts;
8854 + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
8855 + (dwc_otg_is_host_mode(core_if)?"Host":"Device"),
8856 + op_state_str(core_if));
8858 +/** @todo Consolidate this if statement. */
8859 +#ifndef DWC_HOST_ONLY
8860 + if (core_if->op_state == B_HOST) {
8861 + dwc_otg_pcd_t *pcd;
8863 + /* If in device mode Disconnect and stop the HCD, then
8864 + * start the PCD. */
8865 + hcd_disconnect(core_if);
8867 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8868 + if(unlikely(!pcd)) {
8869 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8872 + SPIN_LOCK(&pcd->lock);
8874 + pcd_start(core_if);
8876 + SPIN_UNLOCK(&pcd->lock);
8877 + core_if->op_state = B_PERIPHERAL;
8878 + } else if (dwc_otg_is_device_mode(core_if)) {
8879 + gotgctl_data_t gotgctl = { .d32 = 0 };
8880 + gotgctl.d32 = dwc_read_reg32(&core_if->core_global_regs->gotgctl);
8881 + if (gotgctl.b.hstsethnpen==1) {
8882 + /* Do nothing, if HNP in process the OTG
8883 + * interrupt "Host Negotiation Detected"
8884 + * interrupt will do the mode switch.
8886 + } else if (gotgctl.b.devhnpen == 0) {
8887 + dwc_otg_pcd_t *pcd;
8889 + /* If in device mode Disconnect and stop the HCD, then
8890 + * start the PCD. */
8891 + hcd_disconnect(core_if);
8893 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8894 + if(unlikely(!pcd)) {
8895 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8898 + SPIN_LOCK(&pcd->lock);
8900 + pcd_start(core_if);
8902 + SPIN_UNLOCK(&pcd->lock);
8904 + core_if->op_state = B_PERIPHERAL;
8906 + DWC_DEBUGPL(DBG_ANY,"!a_peripheral && !devhnpen\n");
8909 + if (core_if->op_state == A_HOST) {
8910 + /* A-Cable still connected but device disconnected. */
8911 + hcd_disconnect(core_if);
8917 + gintsts.b.disconnect = 1;
8918 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
8922 + * This interrupt indicates that SUSPEND state has been detected on
8925 + * For HNP the USB Suspend interrupt signals the change from
8926 + * "a_peripheral" to "a_host".
8928 + * When power management is enabled the core will be put in low power
8931 +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t *core_if)
8934 + gintsts_data_t gintsts;
8936 + DWC_DEBUGPL(DBG_ANY,"USB SUSPEND\n");
8938 + if (dwc_otg_is_device_mode(core_if)) {
8939 + dwc_otg_pcd_t *pcd;
8941 + /* Check the Device status register to determine if the Suspend
8942 + * state is active. */
8943 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
8944 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
8945 + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
8946 + "HWCFG4.power Optimize=%d\n",
8947 + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
8950 +#ifdef PARTIAL_POWER_DOWN
8951 +/** @todo Add a module parameter for power management. */
8953 + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
8954 + pcgcctl_data_t power = {.d32=0};
8955 + DWC_DEBUGPL(DBG_CIL, "suspend\n");
8957 + power.b.pwrclmp = 1;
8958 + dwc_write_reg32(core_if->pcgcctl, power.d32);
8960 + power.b.rstpdwnmodule = 1;
8961 + dwc_modify_reg32(core_if->pcgcctl, 0, power.d32);
8963 + power.b.stoppclk = 1;
8964 + dwc_modify_reg32(core_if->pcgcctl, 0, power.d32);
8967 + DWC_DEBUGPL(DBG_ANY,"disconnect?\n");
8970 + /* PCD callback for suspend. */
8971 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8972 + if(unlikely(!pcd)) {
8973 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8976 + SPIN_LOCK(&pcd->lock);
8978 + pcd_suspend(core_if);
8980 + SPIN_UNLOCK(&pcd->lock);
8982 + if (core_if->op_state == A_PERIPHERAL) {
8983 + dwc_otg_pcd_t *pcd;
8985 + DWC_DEBUGPL(DBG_ANY,"a_peripheral->a_host\n");
8986 + /* Clear the a_peripheral flag, back to a_host. */
8988 + pcd=(dwc_otg_pcd_t *)core_if->pcd_cb->p;
8989 + if(unlikely(!pcd)) {
8990 + DWC_ERROR("%s: data structure not initialized properly, core_if->pcd_cb->p = NULL!!!",__func__);
8993 + SPIN_LOCK(&pcd->lock);
8995 + pcd_stop(core_if);
8997 + SPIN_UNLOCK(&pcd->lock);
8999 + hcd_start(core_if);
9000 + core_if->op_state = A_HOST;
9004 + /* Clear interrupt */
9006 + gintsts.b.usbsuspend = 1;
9007 + dwc_write_reg32(&core_if->core_global_regs->gintsts, gintsts.d32);
9014 + * This function returns the Core Interrupt register.
9016 +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t *core_if)
9018 + gintsts_data_t gintsts;
9019 + gintmsk_data_t gintmsk;
9020 + gintmsk_data_t gintmsk_common = {.d32=0};
9021 + gintmsk_common.b.wkupintr = 1;
9022 + gintmsk_common.b.sessreqintr = 1;
9023 + gintmsk_common.b.conidstschng = 1;
9024 + gintmsk_common.b.otgintr = 1;
9025 + gintmsk_common.b.modemismatch = 1;
9026 + gintmsk_common.b.disconnect = 1;
9027 + gintmsk_common.b.usbsuspend = 1;
9028 + /** @todo: The port interrupt occurs while in device
9029 + * mode. Added code to CIL to clear the interrupt for now!
9031 + gintmsk_common.b.portintr = 1;
9033 + gintsts.d32 = dwc_read_reg32(&core_if->core_global_regs->gintsts);
9034 + gintmsk.d32 = dwc_read_reg32(&core_if->core_global_regs->gintmsk);
9036 + /* if any common interrupts set */
9037 + if (gintsts.d32 & gintmsk_common.d32) {
9038 + DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
9039 + gintsts.d32, gintmsk.d32);
9043 + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
9048 + * Common interrupt handler.
9050 + * The common interrupts are those that occur in both Host and Device mode.
9051 + * This handler handles the following interrupts:
9052 + * - Mode Mismatch Interrupt
9053 + * - Disconnect Interrupt
9055 + * - Connector ID Status Change Interrupt
9056 + * - Session Request Interrupt.
9057 + * - Resume / Remote Wakeup Detected Interrupt.
9060 +int32_t dwc_otg_handle_common_intr(dwc_otg_core_if_t *core_if)
9063 + gintsts_data_t gintsts;
9065 + gintsts.d32 = dwc_otg_read_common_intr(core_if);
9067 + if (gintsts.b.modemismatch) {
9068 + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
9070 + if (gintsts.b.otgintr) {
9071 + retval |= dwc_otg_handle_otg_intr(core_if);
9073 + if (gintsts.b.conidstschng) {
9074 + retval |= dwc_otg_handle_conn_id_status_change_intr(core_if);
9076 + if (gintsts.b.disconnect) {
9077 + retval |= dwc_otg_handle_disconnect_intr(core_if);
9079 + if (gintsts.b.sessreqintr) {
9080 + retval |= dwc_otg_handle_session_req_intr(core_if);
9082 + if (gintsts.b.wkupintr) {
9083 + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
9085 + if (gintsts.b.usbsuspend) {
9086 + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
9088 + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
9089 + /* The port interrupt occurs while in device mode with HPRT0
9090 + * Port Enable/Disable.
9093 + gintsts.b.portintr = 1;
9094 + dwc_write_reg32(&core_if->core_global_regs->gintsts,
9100 + S3C2410X_CLEAR_EINTPEND();
9105 +++ b/drivers/usb/host/otg/dwc_otg_driver.c
9107 +/* ==========================================================================
9108 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
9109 + * $Revision: #63 $
9110 + * $Date: 2008/09/24 $
9111 + * $Change: 1101777 $
9113 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
9114 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9115 + * otherwise expressly agreed to in writing between Synopsys and you.
9117 + * The Software IS NOT an item of Licensed Software or Licensed Product under
9118 + * any End User Software License Agreement or Agreement for Licensed Product
9119 + * with Synopsys or any supplement thereto. You are permitted to use and
9120 + * redistribute this Software in source and binary forms, with or without
9121 + * modification, provided that redistributions of source code must retain this
9122 + * notice. You may not view, use, disclose, copy or distribute this file or
9123 + * any information contained herein except pursuant to this license grant from
9124 + * Synopsys. If you do not agree with this notice, including the disclaimer
9125 + * below, then you are not authorized to use the Software.
9127 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
9128 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9129 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9130 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
9131 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9132 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
9133 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
9134 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9135 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9136 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
9138 + * ========================================================================== */
9141 + * The dwc_otg_driver module provides the initialization and cleanup entry
9142 + * points for the DWC_otg driver. This module will be dynamically installed
9143 + * after Linux is booted using the insmod command. When the module is
9144 + * installed, the dwc_otg_driver_init function is called. When the module is
9145 + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
9147 + * This module also defines a data structure for the dwc_otg_driver, which is
9148 + * used in conjunction with the standard ARM lm_device structure. These
9149 + * structures allow the OTG driver to comply with the standard Linux driver
9150 + * model in which devices and drivers are registered with a bus driver. This
9151 + * has the benefit that Linux can expose attributes of the driver and device
9152 + * in its special sysfs file system. Users can then read or write files in
9153 + * this file system to perform diagnostics on the driver components or the
9157 +#include <linux/kernel.h>
9158 +#include <linux/module.h>
9159 +#include <linux/moduleparam.h>
9160 +#include <linux/init.h>
9161 +#include <linux/device.h>
9162 +#include <linux/errno.h>
9163 +#include <linux/types.h>
9164 +#include <linux/stat.h> /* permission constants */
9165 +#include <linux/version.h>
9167 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
9168 +# include <linux/irq.h>
9171 +#include <asm/io.h>
9173 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
9174 +# include <asm/irq.h>
9177 +//#include <asm/arch/lm.h>
9178 +#include <mach/lm.h>
9179 +#include <mach/board.h>
9180 +#include <asm/sizes.h>
9181 +#include <mach/pm.h>
9183 +#include "dwc_otg_plat.h"
9184 +#include "dwc_otg_attr.h"
9185 +#include "dwc_otg_driver.h"
9186 +#include "dwc_otg_cil.h"
9187 +#include "dwc_otg_pcd.h"
9188 +#include "dwc_otg_hcd.h"
9190 +#define DWC_DRIVER_VERSION "2.72a 24-JUN-2008"
9191 +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
9193 +static const char dwc_driver_name[] = "dwc_otg";
9195 +/*-------------------------------------------------------------------------*/
9196 +/* Encapsulate the module parameter settings */
9198 +static dwc_otg_core_params_t dwc_otg_module_params = {
9202 + .dma_desc_enable = -1,
9203 + .dma_burst_size = -1,
9205 + .host_support_fs_ls_low_power = -1,
9206 + .host_ls_low_power_phy_clk = -1,
9207 + .enable_dynamic_fifo = -1,
9208 + .data_fifo_size = -1,
9209 + .dev_rx_fifo_size = -1,
9210 + .dev_nperio_tx_fifo_size = -1,
9211 + .dev_perio_tx_fifo_size = {
9212 + /* dev_perio_tx_fifo_size_1 */
9230 + .host_rx_fifo_size = -1,
9231 + .host_nperio_tx_fifo_size = -1,
9232 + .host_perio_tx_fifo_size = -1,
9233 + .max_transfer_size = -1,
9234 + .max_packet_count = -1,
9235 + .host_channels = -1,
9236 + .dev_endpoints = -1,
9238 + .phy_utmi_width = -1,
9239 + .phy_ulpi_ddr = -1,
9240 + .phy_ulpi_ext_vbus = -1,
9244 + .en_multiple_tx_fifo = -1,
9245 + .dev_tx_fifo_size = {
9246 + /* dev_tx_fifo_size */
9265 + .tx_thr_length = -1,
9266 + .rx_thr_length = -1,
9272 + * This function shows the Driver Version.
9274 +static ssize_t version_show(struct device_driver *dev, char *buf)
9276 + return snprintf(buf, sizeof(DWC_DRIVER_VERSION)+2, "%s\n",
9277 + DWC_DRIVER_VERSION);
9279 +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
9282 + * Global Debug Level Mask.
9284 +uint32_t g_dbg_lvl = 0; /* OFF */
9287 + * This function shows the driver Debug Level.
9289 +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
9291 + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
9295 + * This function stores the driver Debug Level.
9297 +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
9300 + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
9303 +static DRIVER_ATTR(debuglevel, S_IRUGO|S_IWUSR, dbg_level_show, dbg_level_store);
9306 + * This function is called during module intialization to verify that
9307 + * the module parameters are in a valid state.
9309 +static int check_parameters(dwc_otg_core_if_t *core_if)
9314 +/* Checks if the parameter is outside of its valid range of values */
9315 +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
9316 + ((dwc_otg_module_params._param_ < (_low_)) || \
9317 + (dwc_otg_module_params._param_ > (_high_)))
9319 +/* If the parameter has been set by the user, check that the parameter value is
9320 + * within the value range of values. If not, report a module error. */
9321 +#define DWC_OTG_PARAM_ERR(_param_, _low_, _high_, _string_) \
9323 + if (dwc_otg_module_params._param_ != -1) { \
9324 + if (DWC_OTG_PARAM_TEST(_param_, (_low_), (_high_))) { \
9325 + DWC_ERROR("`%d' invalid for parameter `%s'\n", \
9326 + dwc_otg_module_params._param_, _string_); \
9327 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
9333 + DWC_OTG_PARAM_ERR(opt,0,1,"opt");
9334 + DWC_OTG_PARAM_ERR(otg_cap,0,2,"otg_cap");
9335 + DWC_OTG_PARAM_ERR(dma_enable,0,1,"dma_enable");
9336 + DWC_OTG_PARAM_ERR(dma_desc_enable,0,1,"dma_desc_enable");
9337 + DWC_OTG_PARAM_ERR(speed,0,1,"speed");
9338 + DWC_OTG_PARAM_ERR(host_support_fs_ls_low_power,0,1,"host_support_fs_ls_low_power");
9339 + DWC_OTG_PARAM_ERR(host_ls_low_power_phy_clk,0,1,"host_ls_low_power_phy_clk");
9340 + DWC_OTG_PARAM_ERR(enable_dynamic_fifo,0,1,"enable_dynamic_fifo");
9341 + DWC_OTG_PARAM_ERR(data_fifo_size,32,32768,"data_fifo_size");
9342 + DWC_OTG_PARAM_ERR(dev_rx_fifo_size,16,32768,"dev_rx_fifo_size");
9343 + DWC_OTG_PARAM_ERR(dev_nperio_tx_fifo_size,16,32768,"dev_nperio_tx_fifo_size");
9344 + DWC_OTG_PARAM_ERR(host_rx_fifo_size,16,32768,"host_rx_fifo_size");
9345 + DWC_OTG_PARAM_ERR(host_nperio_tx_fifo_size,16,32768,"host_nperio_tx_fifo_size");
9346 + DWC_OTG_PARAM_ERR(host_perio_tx_fifo_size,16,32768,"host_perio_tx_fifo_size");
9347 + DWC_OTG_PARAM_ERR(max_transfer_size,2047,524288,"max_transfer_size");
9348 + DWC_OTG_PARAM_ERR(max_packet_count,15,511,"max_packet_count");
9349 + DWC_OTG_PARAM_ERR(host_channels,1,16,"host_channels");
9350 + DWC_OTG_PARAM_ERR(dev_endpoints,1,15,"dev_endpoints");
9351 + DWC_OTG_PARAM_ERR(phy_type,0,2,"phy_type");
9352 + DWC_OTG_PARAM_ERR(phy_ulpi_ddr,0,1,"phy_ulpi_ddr");
9353 + DWC_OTG_PARAM_ERR(phy_ulpi_ext_vbus,0,1,"phy_ulpi_ext_vbus");
9354 + DWC_OTG_PARAM_ERR(i2c_enable,0,1,"i2c_enable");
9355 + DWC_OTG_PARAM_ERR(ulpi_fs_ls,0,1,"ulpi_fs_ls");
9356 + DWC_OTG_PARAM_ERR(ts_dline,0,1,"ts_dline");
9358 + if (dwc_otg_module_params.dma_burst_size != -1) {
9359 + if (DWC_OTG_PARAM_TEST(dma_burst_size,1,1) &&
9360 + DWC_OTG_PARAM_TEST(dma_burst_size,4,4) &&
9361 + DWC_OTG_PARAM_TEST(dma_burst_size,8,8) &&
9362 + DWC_OTG_PARAM_TEST(dma_burst_size,16,16) &&
9363 + DWC_OTG_PARAM_TEST(dma_burst_size,32,32) &&
9364 + DWC_OTG_PARAM_TEST(dma_burst_size,64,64) &&
9365 + DWC_OTG_PARAM_TEST(dma_burst_size,128,128) &&
9366 + DWC_OTG_PARAM_TEST(dma_burst_size,256,256)) {
9367 + DWC_ERROR("`%d' invalid for parameter `dma_burst_size'\n",
9368 + dwc_otg_module_params.dma_burst_size);
9369 + dwc_otg_module_params.dma_burst_size = 32;
9374 + uint8_t brst_sz = 0;
9375 + while(dwc_otg_module_params.dma_burst_size > 1) {
9377 + dwc_otg_module_params.dma_burst_size >>= 1;
9379 + dwc_otg_module_params.dma_burst_size = brst_sz;
9383 + if (dwc_otg_module_params.phy_utmi_width != -1) {
9384 + if (DWC_OTG_PARAM_TEST(phy_utmi_width, 8, 8) &&
9385 + DWC_OTG_PARAM_TEST(phy_utmi_width, 16, 16)) {
9386 + DWC_ERROR("`%d' invalid for parameter `phy_utmi_width'\n",
9387 + dwc_otg_module_params.phy_utmi_width);
9388 + dwc_otg_module_params.phy_utmi_width = 16;
9393 + for (i = 0; i < 15; i++) {
9394 + /** @todo should be like above */
9395 + //DWC_OTG_PARAM_ERR(dev_perio_tx_fifo_size[i], 4, 768, "dev_perio_tx_fifo_size");
9396 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
9397 + if (DWC_OTG_PARAM_TEST(dev_perio_tx_fifo_size[i], 4, 768)) {
9398 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
9399 + dwc_otg_module_params.dev_perio_tx_fifo_size[i], "dev_perio_tx_fifo_size", i);
9400 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
9406 + DWC_OTG_PARAM_ERR(en_multiple_tx_fifo, 0, 1, "en_multiple_tx_fifo");
9408 + for (i = 0; i < 15; i++) {
9409 + /** @todo should be like above */
9410 + //DWC_OTG_PARAM_ERR(dev_tx_fifo_size[i], 4, 768, "dev_tx_fifo_size");
9411 + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
9412 + if (DWC_OTG_PARAM_TEST(dev_tx_fifo_size[i], 4, 768)) {
9413 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
9414 + dwc_otg_module_params.dev_tx_fifo_size[i], "dev_tx_fifo_size", i);
9415 + dwc_otg_module_params.dev_tx_fifo_size[i] = dwc_param_dev_tx_fifo_size_default;
9421 + DWC_OTG_PARAM_ERR(thr_ctl, 0, 7, "thr_ctl");
9422 + DWC_OTG_PARAM_ERR(tx_thr_length, 8, 128, "tx_thr_length");
9423 + DWC_OTG_PARAM_ERR(rx_thr_length, 8, 128, "rx_thr_length");
9425 + DWC_OTG_PARAM_ERR(pti_enable,0,1,"pti_enable");
9426 + DWC_OTG_PARAM_ERR(mpi_enable,0,1,"mpi_enable");
9428 + /* At this point, all module parameters that have been set by the user
9429 + * are valid, and those that have not are left unset. Now set their
9430 + * default values and/or check the parameters against the hardware
9431 + * configurations of the OTG core. */
9433 +/* This sets the parameter to the default value if it has not been set by the
9435 +#define DWC_OTG_PARAM_SET_DEFAULT(_param_) \
9437 + int changed = 1; \
9438 + if (dwc_otg_module_params._param_ == -1) { \
9440 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
9445 +/* This checks the macro agains the hardware configuration to see if it is
9446 + * valid. It is possible that the default value could be invalid. In this
9447 + * case, it will report a module error if the user touched the parameter.
9448 + * Otherwise it will adjust the value without any error. */
9449 +#define DWC_OTG_PARAM_CHECK_VALID(_param_, _str_, _is_valid_, _set_valid_) \
9451 + int changed = DWC_OTG_PARAM_SET_DEFAULT(_param_); \
9453 + if (!(_is_valid_)) { \
9455 + DWC_ERROR("`%d' invalid for parameter `%s'. Check HW configuration.\n", dwc_otg_module_params._param_, _str_); \
9458 + dwc_otg_module_params._param_ = (_set_valid_); \
9464 + retval += DWC_OTG_PARAM_CHECK_VALID(otg_cap, "otg_cap",
9468 + switch (dwc_otg_module_params.otg_cap) {
9469 + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
9470 + if (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
9473 + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
9474 + if ((core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) &&
9475 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) &&
9476 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) &&
9477 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
9481 + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
9482 + /* always valid */
9487 + (((core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) ||
9488 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) ||
9489 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
9490 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
9491 + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
9492 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE));
9494 + retval += DWC_OTG_PARAM_CHECK_VALID(dma_enable, "dma_enable",
9495 + ((dwc_otg_module_params.dma_enable == 1) && (core_if->hwcfg2.b.architecture == 0)) ? 0 : 1,
9498 + retval += DWC_OTG_PARAM_CHECK_VALID(dma_desc_enable, "dma_desc_enable",
9499 + ((dwc_otg_module_params.dma_desc_enable == 1) &&
9500 + ((dwc_otg_module_params.dma_enable == 0) || (core_if->hwcfg4.b.desc_dma == 0))) ? 0 : 1,
9503 + retval += DWC_OTG_PARAM_CHECK_VALID(opt, "opt", 1, 0);
9505 + DWC_OTG_PARAM_SET_DEFAULT(dma_burst_size);
9507 + retval += DWC_OTG_PARAM_CHECK_VALID(host_support_fs_ls_low_power,
9508 + "host_support_fs_ls_low_power",
9511 + retval += DWC_OTG_PARAM_CHECK_VALID(enable_dynamic_fifo,
9512 + "enable_dynamic_fifo",
9513 + ((dwc_otg_module_params.enable_dynamic_fifo == 0) ||
9514 + (core_if->hwcfg2.b.dynamic_fifo == 1)), 0);
9516 + retval += DWC_OTG_PARAM_CHECK_VALID(data_fifo_size,
9518 + (dwc_otg_module_params.data_fifo_size <= core_if->hwcfg3.b.dfifo_depth),
9519 + core_if->hwcfg3.b.dfifo_depth);
9521 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_rx_fifo_size,
9522 + "dev_rx_fifo_size",
9523 + (dwc_otg_module_params.dev_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
9524 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
9526 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_nperio_tx_fifo_size,
9527 + "dev_nperio_tx_fifo_size",
9528 + (dwc_otg_module_params.dev_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
9529 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
9531 + retval += DWC_OTG_PARAM_CHECK_VALID(host_rx_fifo_size,
9532 + "host_rx_fifo_size",
9533 + (dwc_otg_module_params.host_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
9534 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
9536 + retval += DWC_OTG_PARAM_CHECK_VALID(host_nperio_tx_fifo_size,
9537 + "host_nperio_tx_fifo_size",
9538 + (dwc_otg_module_params.host_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
9539 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
9541 + retval += DWC_OTG_PARAM_CHECK_VALID(host_perio_tx_fifo_size,
9542 + "host_perio_tx_fifo_size",
9543 + (dwc_otg_module_params.host_perio_tx_fifo_size <= ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16))),
9544 + ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16)));
9546 + retval += DWC_OTG_PARAM_CHECK_VALID(max_transfer_size,
9547 + "max_transfer_size",
9548 + (dwc_otg_module_params.max_transfer_size < (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))),
9549 + ((1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1));
9551 + retval += DWC_OTG_PARAM_CHECK_VALID(max_packet_count,
9552 + "max_packet_count",
9553 + (dwc_otg_module_params.max_packet_count < (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))),
9554 + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1));
9556 + retval += DWC_OTG_PARAM_CHECK_VALID(host_channels,
9558 + (dwc_otg_module_params.host_channels <= (core_if->hwcfg2.b.num_host_chan + 1)),
9559 + (core_if->hwcfg2.b.num_host_chan + 1));
9561 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_endpoints,
9563 + (dwc_otg_module_params.dev_endpoints <= (core_if->hwcfg2.b.num_dev_ep)),
9564 + core_if->hwcfg2.b.num_dev_ep);
9567 + * Define the following to disable the FS PHY Hardware checking. This is for
9568 + * internal testing only.
9570 + * #define NO_FS_PHY_HW_CHECKS
9573 +#ifdef NO_FS_PHY_HW_CHECKS
9574 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
9575 + "phy_type", 1, 0);
9577 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
9581 + if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_UTMI) &&
9582 + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
9583 + (core_if->hwcfg2.b.hs_phy_type == 3))) {
9586 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_ULPI) &&
9587 + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
9588 + (core_if->hwcfg2.b.hs_phy_type == 3))) {
9591 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) &&
9592 + (core_if->hwcfg2.b.fs_phy_type == 1)) {
9598 + int set = DWC_PHY_TYPE_PARAM_FS;
9599 + if (core_if->hwcfg2.b.hs_phy_type) {
9600 + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
9601 + (core_if->hwcfg2.b.hs_phy_type == 1)) {
9602 + set = DWC_PHY_TYPE_PARAM_UTMI;
9605 + set = DWC_PHY_TYPE_PARAM_ULPI;
9612 + retval += DWC_OTG_PARAM_CHECK_VALID(speed, "speed",
9613 + (dwc_otg_module_params.speed == 0) && (dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1,
9614 + dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
9616 + retval += DWC_OTG_PARAM_CHECK_VALID(host_ls_low_power_phy_clk,
9617 + "host_ls_low_power_phy_clk",
9618 + ((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),
9619 + ((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));
9621 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ddr);
9622 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ext_vbus);
9623 + DWC_OTG_PARAM_SET_DEFAULT(phy_utmi_width);
9624 + DWC_OTG_PARAM_SET_DEFAULT(ulpi_fs_ls);
9625 + DWC_OTG_PARAM_SET_DEFAULT(ts_dline);
9627 +#ifdef NO_FS_PHY_HW_CHECKS
9628 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable, "i2c_enable", 1, 0);
9630 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
9632 + (dwc_otg_module_params.i2c_enable == 1) && (core_if->hwcfg3.b.i2c == 0) ? 0 : 1,
9636 + for (i = 0; i < 15; i++) {
9640 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] == -1) {
9642 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
9644 + if (!(dwc_otg_module_params.dev_perio_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
9646 + 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);
9649 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
9654 + retval += DWC_OTG_PARAM_CHECK_VALID(en_multiple_tx_fifo, "en_multiple_tx_fifo",
9655 + ((dwc_otg_module_params.en_multiple_tx_fifo == 1) && (core_if->hwcfg4.b.ded_fifo_en == 0)) ? 0 : 1,
9658 + for (i = 0; i < 15; i++) {
9662 + if (dwc_otg_module_params.dev_tx_fifo_size[i] == -1) {
9664 + dwc_otg_module_params.dev_tx_fifo_size[i] = dwc_param_dev_tx_fifo_size_default;
9666 + if (!(dwc_otg_module_params.dev_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
9668 + 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);
9671 + dwc_otg_module_params.dev_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
9676 + retval += DWC_OTG_PARAM_CHECK_VALID(thr_ctl, "thr_ctl",
9677 + ((dwc_otg_module_params.thr_ctl != 0) && ((dwc_otg_module_params.dma_enable == 0) || (core_if->hwcfg4.b.ded_fifo_en == 0))) ? 0 : 1,
9680 + DWC_OTG_PARAM_SET_DEFAULT(tx_thr_length);
9681 + DWC_OTG_PARAM_SET_DEFAULT(rx_thr_length);
9683 + retval += DWC_OTG_PARAM_CHECK_VALID(pti_enable, "pti_enable",
9684 + ((dwc_otg_module_params.pti_enable == 0) || ((dwc_otg_module_params.pti_enable == 1) && (core_if->snpsid >= 0x4F54272A))) ? 1 : 0,
9687 + retval += DWC_OTG_PARAM_CHECK_VALID(mpi_enable, "mpi_enable",
9688 + ((dwc_otg_module_params.mpi_enable == 0) || ((dwc_otg_module_params.mpi_enable == 1) && (core_if->hwcfg2.b.multi_proc_int == 1))) ? 1 : 0,
9694 + * This function is the top level interrupt handler for the Common
9695 + * (Device and host modes) interrupts.
9697 +static irqreturn_t dwc_otg_common_irq(int irq, void *dev
9698 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
9699 + , struct pt_regs *r
9703 + dwc_otg_device_t *otg_dev = dev;
9704 + int32_t retval = IRQ_NONE;
9706 + retval = dwc_otg_handle_common_intr(otg_dev->core_if);
9707 + return IRQ_RETVAL(retval);
9711 + * This function is called when a lm_device is unregistered with the
9712 + * dwc_otg_driver. This happens, for example, when the rmmod command is
9713 + * executed. The device may or may not be electrically present. If it is
9714 + * present, the driver stops device processing. Any resources used on behalf
9715 + * of this device are freed.
9717 + * @param[in] lmdev
9719 +static void dwc_otg_driver_remove(struct lm_device *lmdev)
9721 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lmdev);
9722 + DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, lmdev);
9725 + /* Memory allocation for the dwc_otg_device failed. */
9726 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
9733 + if (otg_dev->common_irq_installed) {
9734 + free_irq(lmdev->irq, otg_dev);
9737 +#ifndef DWC_DEVICE_ONLY
9738 + if (otg_dev->hcd) {
9739 + dwc_otg_hcd_remove(lmdev);
9741 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
9746 +#ifndef DWC_HOST_ONLY
9747 + if (otg_dev->pcd) {
9748 + dwc_otg_pcd_remove(lmdev);
9751 + if (otg_dev->core_if) {
9752 + dwc_otg_cil_remove(otg_dev->core_if);
9756 + * Remove the device attributes
9758 + dwc_otg_attr_remove(lmdev);
9761 + * Return the memory.
9763 + if (otg_dev->base) {
9764 + cns3xxx_iounmap(otg_dev->base);
9769 + * Clear the drvdata pointer.
9771 + lm_set_drvdata(lmdev, 0);
9775 + * This function is called when an lm_device is bound to a
9776 + * dwc_otg_driver. It creates the driver components required to
9777 + * control the device (CIL, HCD, and PCD) and it initializes the
9778 + * device. The driver components are stored in a dwc_otg_device
9779 + * structure. A reference to the dwc_otg_device is saved in the
9780 + * lm_device. This allows the driver to access the dwc_otg_device
9781 + * structure on subsequent calls to driver methods for this device.
9783 + * @param[in] lmdev lm_device definition
9785 +static int dwc_otg_driver_probe(struct lm_device *lmdev)
9789 + dwc_otg_device_t *dwc_otg_device;
9792 + dev_dbg(&lmdev->dev, "dwc_otg_driver_probe(%p)\n", lmdev);
9793 + dev_dbg(&lmdev->dev, "start=0x%08x\n", (unsigned)lmdev->resource.start);
9795 + dwc_otg_device = kmalloc(sizeof(dwc_otg_device_t), GFP_KERNEL);
9797 + if (!dwc_otg_device) {
9798 + dev_err(&lmdev->dev, "kmalloc of dwc_otg_device failed\n");
9803 + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
9804 + dwc_otg_device->reg_offset = 0xFFFFFFFF;
9807 + * Map the DWC_otg Core memory into virtual address space.
9809 +#ifdef CNS3XXX_USBOTG_BASE_VIRT
9810 + dwc_otg_device->base = (void __iomem *) CNS3XXX_USBOTG_BASE_VIRT;
9812 + dwc_otg_device->base = ioremap(lmdev->resource.start, SZ_256K);
9815 + if (!dwc_otg_device->base) {
9816 + dev_err(&lmdev->dev, "cns3xxx_ioremap() failed\n");
9820 + dev_dbg(&lmdev->dev, "base=0x%08x\n", (unsigned)dwc_otg_device->base);
9822 +#ifdef CONFIG_SILICON
9825 + cns3xxx_pwr_power_up(1<<PM_PLL_HM_PD_CTRL_REG_OFFSET_USB_PHY0);
9827 + //cns3xxx_pwr_power_up(1<<PM_PLL_HM_PD_CTRL_REG_OFFSET_USB_PHY1);
9829 + cns3xxx_pwr_power_up(1<<PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
9830 + cns3xxx_pwr_clk_en(1<<PM_CLK_GATE_REG_OFFSET_USB_OTG);
9831 + cns3xxx_pwr_soft_rst(1<<PM_SOFT_RST_REG_OFFST_USB_OTG);
9832 + //cns3xxx_pwr_clk_en(1<<PM_CLK_GATE_REG_OFFSET_USB_HOST);
9833 + //cns3xxx_pwr_soft_rst(1<<PM_SOFT_RST_REG_OFFST_USB_HOST);
9834 +#ifdef CONFIG_USB_CNS3XXX_OTG_ENABLE_OTG_DRVVBUS
9835 + *((volatile u32*) (CNS3XXX_MISC_BASE_VIRT/*0x7600_0000*/+0x14)) |= (1<<3);
9836 +#endif //#ifdef CONFIG_USB_CNS3XXX_OTG_ENABLE_OTG_DRVVBUS
9838 +#endif //CONFIG_SILICON
9841 + * Attempt to ensure this device is really a DWC_otg Controller.
9842 + * Read and verify the SNPSID register contents. The value should be
9843 + * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
9845 + snpsid = dwc_read_reg32((uint32_t *)((uint8_t *)dwc_otg_device->base + 0x40));
9847 + if ((snpsid & 0xFFFFF000) != OTG_CORE_REV_2_00) {
9848 + dev_err(&lmdev->dev, "Bad value for SNPSID: 0x%08x\n", snpsid);
9853 + DWC_PRINT("Core Release: %x.%x%x%x\n",
9854 + (snpsid >> 12 & 0xF),
9855 + (snpsid >> 8 & 0xF),
9856 + (snpsid >> 4 & 0xF),
9861 + // de-assert otgdisable
9862 + val=__raw_readl((void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0808));
9863 + __raw_writel(val&(~(1 << 10)), (void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0808));
9864 + val=__raw_readl((void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0808));
9865 + DWC_DEBUGPL(DBG_CIL, "de-assert otgdisable(bit10): MISC_USBPHY00_CFG_REG=%.8x\n",val);
9868 +#ifdef ENDIAN_MODE_BIG_ENDIAN
9869 + // bit[18]:otg endian, bit[19]:usbh endian
9870 + val=__raw_readl((void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0800));
9871 + __raw_writel(val|(1 << 18), (void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0800));
9873 + val=__raw_readl((void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0800));
9874 + DWC_DEBUGPL(DBG_CIL, "OTG endian(bit18): MISC_USB_CFG_REG=%.8x, OTG in %s endian mode\n",val,(val&(1<<18))?"big":"little");
9878 + HAL_PMU_POWER_ON_USB_PHY1();
9879 + HAL_PMU_POWER_ON_USB_PHY0();
9881 + HAL_PMU_POWER_ON_USB();
9883 + HAL_PMU_ENABLE_USB_OTG_CLOCK();
9884 + HAL_PMU_ENABLE_USB_HOST_CLOCK();
9886 + Hal_Pmu_Software_Reset(PMU_USB_OTG_SOFTWARE_RESET_BIT_INDEX);
9887 + Hal_Pmu_Software_Reset(PMU_USB_HOST_SOFTWARE_RESET_BIT_INDEX);
9891 + * Initialize driver data to point to the global DWC_otg
9892 + * Device structure.
9894 + lm_set_drvdata(lmdev, dwc_otg_device);
9895 + dev_dbg(&lmdev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
9897 + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->base,
9898 + &dwc_otg_module_params);
9900 + dwc_otg_device->core_if->snpsid = snpsid;
9902 + if (!dwc_otg_device->core_if) {
9903 + dev_err(&lmdev->dev, "CIL initialization failed!\n");
9909 + * Validate parameter values.
9911 + if (check_parameters(dwc_otg_device->core_if)) {
9917 + * Create Device Attributes in sysfs
9919 + dwc_otg_attr_create(lmdev);
9922 + * Disable the global interrupt until all the interrupt
9923 + * handlers are installed.
9925 + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
9928 + * Install the interrupt handler for the common interrupts before
9929 + * enabling common interrupts in core_init below.
9931 + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
9933 + retval = request_irq(lmdev->irq, dwc_otg_common_irq,
9934 + IRQF_SHARED, "dwc_otg", dwc_otg_device);
9936 + DWC_ERROR("request of irq%d failed\n", lmdev->irq);
9940 + dwc_otg_device->common_irq_installed = 1;
9944 + * Initialize the DWC_otg core.
9946 + dwc_otg_core_init(dwc_otg_device->core_if);
9948 +#ifndef DWC_HOST_ONLY
9950 + * Initialize the PCD
9952 + retval = dwc_otg_pcd_init(lmdev);
9953 + if (retval != 0) {
9954 + DWC_ERROR("dwc_otg_pcd_init failed\n");
9955 + dwc_otg_device->pcd = NULL;
9959 +#ifndef DWC_DEVICE_ONLY
9961 + * Initialize the HCD
9963 + retval = dwc_otg_hcd_init(lmdev);
9964 + if (retval != 0) {
9965 + DWC_ERROR("dwc_otg_hcd_init failed\n");
9966 + dwc_otg_device->hcd = NULL;
9972 + * Enable the global interrupt after all the interrupt
9973 + * handlers are installed.
9975 + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
9980 + dwc_otg_driver_remove(lmdev);
9985 + * This structure defines the methods to be called by a bus driver
9986 + * during the lifecycle of a device on that bus. Both drivers and
9987 + * devices are registered with a bus driver. The bus driver matches
9988 + * devices to drivers based on information in the device and driver
9991 + * The probe function is called when the bus driver matches a device
9992 + * to this driver. The remove function is called when a device is
9993 + * unregistered with the bus driver.
9995 +static struct lm_driver dwc_otg_driver = {
9997 + .name = (char *)dwc_driver_name,
9999 + .probe = dwc_otg_driver_probe,
10000 + .remove = dwc_otg_driver_remove,
10004 + * This function is called when the dwc_otg_driver is installed with the
10005 + * insmod command. It registers the dwc_otg_driver structure with the
10006 + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
10007 + * to be called. In addition, the bus driver will automatically expose
10008 + * attributes defined for the device and driver in the special sysfs file
10013 +static int __init dwc_otg_driver_init(void)
10017 + printk(KERN_INFO "%s: version %s\n", dwc_driver_name, DWC_DRIVER_VERSION);
10019 + retval = lm_driver_register(&dwc_otg_driver);
10020 + if (retval < 0) {
10021 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
10024 + error = driver_create_file(&dwc_otg_driver.drv, &driver_attr_version);
10025 + error = driver_create_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
10029 +module_init(dwc_otg_driver_init);
10032 + * This function is called when the driver is removed from the kernel
10033 + * with the rmmod command. The driver unregisters itself with its bus
10037 +static void __exit dwc_otg_driver_cleanup(void)
10039 + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
10041 + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
10042 + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
10044 + lm_driver_unregister(&dwc_otg_driver);
10046 + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
10048 +module_exit(dwc_otg_driver_cleanup);
10050 +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
10051 +MODULE_AUTHOR("Synopsys Inc.");
10052 +MODULE_LICENSE("GPL");
10054 +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
10055 +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
10056 +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
10057 +MODULE_PARM_DESC(opt, "OPT Mode");
10058 +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
10059 +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
10061 +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int, 0444);
10062 +MODULE_PARM_DESC(dma_desc_enable, "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
10064 +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int, 0444);
10065 +MODULE_PARM_DESC(dma_burst_size, "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
10066 +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
10067 +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
10068 +module_param_named(host_support_fs_ls_low_power, dwc_otg_module_params.host_support_fs_ls_low_power, int, 0444);
10069 +MODULE_PARM_DESC(host_support_fs_ls_low_power, "Support Low Power w/FS or LS 0=Support 1=Don't Support");
10070 +module_param_named(host_ls_low_power_phy_clk, dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
10071 +MODULE_PARM_DESC(host_ls_low_power_phy_clk, "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
10072 +module_param_named(enable_dynamic_fifo, dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
10073 +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
10074 +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int, 0444);
10075 +MODULE_PARM_DESC(data_fifo_size, "Total number of words in the data FIFO memory 32-32768");
10076 +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size, int, 0444);
10077 +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
10078 +module_param_named(dev_nperio_tx_fifo_size, dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
10079 +MODULE_PARM_DESC(dev_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
10080 +module_param_named(dev_perio_tx_fifo_size_1, dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
10081 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1, "Number of words in the periodic Tx FIFO 4-768");
10082 +module_param_named(dev_perio_tx_fifo_size_2, dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
10083 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2, "Number of words in the periodic Tx FIFO 4-768");
10084 +module_param_named(dev_perio_tx_fifo_size_3, dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
10085 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3, "Number of words in the periodic Tx FIFO 4-768");
10086 +module_param_named(dev_perio_tx_fifo_size_4, dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
10087 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4, "Number of words in the periodic Tx FIFO 4-768");
10088 +module_param_named(dev_perio_tx_fifo_size_5, dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
10089 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5, "Number of words in the periodic Tx FIFO 4-768");
10090 +module_param_named(dev_perio_tx_fifo_size_6, dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
10091 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6, "Number of words in the periodic Tx FIFO 4-768");
10092 +module_param_named(dev_perio_tx_fifo_size_7, dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
10093 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7, "Number of words in the periodic Tx FIFO 4-768");
10094 +module_param_named(dev_perio_tx_fifo_size_8, dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
10095 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8, "Number of words in the periodic Tx FIFO 4-768");
10096 +module_param_named(dev_perio_tx_fifo_size_9, dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
10097 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9, "Number of words in the periodic Tx FIFO 4-768");
10098 +module_param_named(dev_perio_tx_fifo_size_10, dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
10099 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10, "Number of words in the periodic Tx FIFO 4-768");
10100 +module_param_named(dev_perio_tx_fifo_size_11, dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
10101 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11, "Number of words in the periodic Tx FIFO 4-768");
10102 +module_param_named(dev_perio_tx_fifo_size_12, dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
10103 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12, "Number of words in the periodic Tx FIFO 4-768");
10104 +module_param_named(dev_perio_tx_fifo_size_13, dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
10105 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13, "Number of words in the periodic Tx FIFO 4-768");
10106 +module_param_named(dev_perio_tx_fifo_size_14, dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
10107 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14, "Number of words in the periodic Tx FIFO 4-768");
10108 +module_param_named(dev_perio_tx_fifo_size_15, dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
10109 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15, "Number of words in the periodic Tx FIFO 4-768");
10110 +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size, int, 0444);
10111 +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
10112 +module_param_named(host_nperio_tx_fifo_size, dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
10113 +MODULE_PARM_DESC(host_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
10114 +module_param_named(host_perio_tx_fifo_size, dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
10115 +MODULE_PARM_DESC(host_perio_tx_fifo_size, "Number of words in the host periodic Tx FIFO 16-32768");
10116 +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size, int, 0444);
10117 +/** @todo Set the max to 512K, modify checks */
10118 +MODULE_PARM_DESC(max_transfer_size, "The maximum transfer size supported in bytes 2047-65535");
10119 +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count, int, 0444);
10120 +MODULE_PARM_DESC(max_packet_count, "The maximum number of packets in a transfer 15-511");
10121 +module_param_named(host_channels, dwc_otg_module_params.host_channels, int, 0444);
10122 +MODULE_PARM_DESC(host_channels, "The number of host channel registers to use 1-16");
10123 +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int, 0444);
10124 +MODULE_PARM_DESC(dev_endpoints, "The number of endpoints in addition to EP0 available for device mode 1-15");
10125 +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
10126 +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
10127 +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int, 0444);
10128 +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
10129 +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
10130 +MODULE_PARM_DESC(phy_ulpi_ddr, "ULPI at double or single data rate 0=Single 1=Double");
10131 +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus, int, 0444);
10132 +MODULE_PARM_DESC(phy_ulpi_ext_vbus, "ULPI PHY using internal or external vbus 0=Internal");
10133 +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
10134 +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
10135 +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
10136 +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
10137 +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
10138 +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
10139 +module_param_named(debug, g_dbg_lvl, int, 0444);
10140 +MODULE_PARM_DESC(debug, "");
10142 +module_param_named(en_multiple_tx_fifo, dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
10143 +MODULE_PARM_DESC(en_multiple_tx_fifo, "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
10144 +module_param_named(dev_tx_fifo_size_1, dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
10145 +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
10146 +module_param_named(dev_tx_fifo_size_2, dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
10147 +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
10148 +module_param_named(dev_tx_fifo_size_3, dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
10149 +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
10150 +module_param_named(dev_tx_fifo_size_4, dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
10151 +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
10152 +module_param_named(dev_tx_fifo_size_5, dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
10153 +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
10154 +module_param_named(dev_tx_fifo_size_6, dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
10155 +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
10156 +module_param_named(dev_tx_fifo_size_7, dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
10157 +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
10158 +module_param_named(dev_tx_fifo_size_8, dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
10159 +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
10160 +module_param_named(dev_tx_fifo_size_9, dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
10161 +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
10162 +module_param_named(dev_tx_fifo_size_10, dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
10163 +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
10164 +module_param_named(dev_tx_fifo_size_11, dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
10165 +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
10166 +module_param_named(dev_tx_fifo_size_12, dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
10167 +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
10168 +module_param_named(dev_tx_fifo_size_13, dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
10169 +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
10170 +module_param_named(dev_tx_fifo_size_14, dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
10171 +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
10172 +module_param_named(dev_tx_fifo_size_15, dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
10173 +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
10175 +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
10176 +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");
10177 +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int, 0444);
10178 +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
10179 +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int, 0444);
10180 +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
10182 +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
10183 +MODULE_PARM_DESC(pti_enable, "Per Transfer Interrupt mode 0=disabled 1=enabled");
10185 +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
10186 +MODULE_PARM_DESC(mpi_enable, "Multiprocessor Interrupt mode 0=disabled 1=enabled");
10188 +/** @page "Module Parameters"
10190 + * The following parameters may be specified when starting the module.
10191 + * These parameters define how the DWC_otg controller should be
10192 + * configured. Parameter values are passed to the CIL initialization
10193 + * function dwc_otg_cil_init
10195 + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
10199 + <tr><td>Parameter Name</td><td>Meaning</td></tr>
10203 + <td>Specifies the OTG capabilities. The driver will automatically detect the
10204 + value for this parameter if none is specified.
10205 + - 0: HNP and SRP capable (default, if available)
10206 + - 1: SRP Only capable
10207 + - 2: No HNP/SRP capable
10211 + <td>dma_enable</td>
10212 + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
10213 + The driver will automatically detect the value for this parameter if none is
10216 + - 1: DMA (default, if available)
10220 + <td>dma_burst_size</td>
10221 + <td>The DMA Burst size (applicable only for External DMA Mode).
10222 + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
10227 + <td>Specifies the maximum speed of operation in host and device mode. The
10228 + actual speed depends on the speed of the attached device and the value of
10230 + - 0: High Speed (default)
10235 + <td>host_support_fs_ls_low_power</td>
10236 + <td>Specifies whether low power mode is supported when attached to a Full
10237 + Speed or Low Speed device in host mode.
10238 + - 0: Don't support low power mode (default)
10239 + - 1: Support low power mode
10243 + <td>host_ls_low_power_phy_clk</td>
10244 + <td>Specifies the PHY clock rate in low power mode when connected to a Low
10245 + Speed device in host mode. This parameter is applicable only if
10246 + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
10247 + - 0: 48 MHz (default)
10252 + <td>enable_dynamic_fifo</td>
10253 + <td> Specifies whether FIFOs may be resized by the driver software.
10254 + - 0: Use cC FIFO size parameters
10255 + - 1: Allow dynamic FIFO sizing (default)
10259 + <td>data_fifo_size</td>
10260 + <td>Total number of 4-byte words in the data FIFO memory. This memory
10261 + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
10262 + - Values: 32 to 32768 (default 8192)
10264 + Note: The total FIFO memory depth in the FPGA configuration is 8192.
10268 + <td>dev_rx_fifo_size</td>
10269 + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
10270 + FIFO sizing is enabled.
10271 + - Values: 16 to 32768 (default 1064)
10275 + <td>dev_nperio_tx_fifo_size</td>
10276 + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
10277 + dynamic FIFO sizing is enabled.
10278 + - Values: 16 to 32768 (default 1024)
10282 + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
10283 + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
10284 + when dynamic FIFO sizing is enabled.
10285 + - Values: 4 to 768 (default 256)
10289 + <td>host_rx_fifo_size</td>
10290 + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
10291 + sizing is enabled.
10292 + - Values: 16 to 32768 (default 1024)
10296 + <td>host_nperio_tx_fifo_size</td>
10297 + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
10298 + dynamic FIFO sizing is enabled in the core.
10299 + - Values: 16 to 32768 (default 1024)
10303 + <td>host_perio_tx_fifo_size</td>
10304 + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
10305 + sizing is enabled.
10306 + - Values: 16 to 32768 (default 1024)
10310 + <td>max_transfer_size</td>
10311 + <td>The maximum transfer size supported in bytes.
10312 + - Values: 2047 to 65,535 (default 65,535)
10316 + <td>max_packet_count</td>
10317 + <td>The maximum number of packets in a transfer.
10318 + - Values: 15 to 511 (default 511)
10322 + <td>host_channels</td>
10323 + <td>The number of host channel registers to use.
10324 + - Values: 1 to 16 (default 12)
10326 + Note: The FPGA configuration supports a maximum of 12 host channels.
10330 + <td>dev_endpoints</td>
10331 + <td>The number of endpoints in addition to EP0 available for device mode
10333 + - Values: 1 to 15 (default 6 IN and OUT)
10335 + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
10340 + <td>phy_type</td>
10341 + <td>Specifies the type of PHY interface to use. By default, the driver will
10342 + automatically detect the phy_type.
10344 + - 1: UTMI+ (default, if available)
10349 + <td>phy_utmi_width</td>
10350 + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
10351 + phy_type of UTMI+. Also, this parameter is applicable only if the
10352 + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
10353 + core has been configured to work at either data path width.
10354 + - Values: 8 or 16 bits (default 16)
10358 + <td>phy_ulpi_ddr</td>
10359 + <td>Specifies whether the ULPI operates at double or single data rate. This
10360 + parameter is only applicable if phy_type is ULPI.
10361 + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
10362 + - 1: double data rate ULPI interface with 4 bit wide data bus
10366 + <td>i2c_enable</td>
10367 + <td>Specifies whether to use the I2C interface for full speed PHY. This
10368 + parameter is only applicable if PHY_TYPE is FS.
10369 + - 0: Disabled (default)
10374 + <td>otg_en_multiple_tx_fifo</td>
10375 + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
10376 + The driver will automatically detect the value for this parameter if none is
10379 + - 1: Enabled (default, if available)
10383 + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
10384 + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
10385 + when dynamic FIFO sizing is enabled.
10386 + - Values: 4 to 768 (default 256)
10391 +++ b/drivers/usb/host/otg/dwc_otg_driver.h
10393 +/* ==========================================================================
10394 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
10395 + * $Revision: #12 $
10396 + * $Date: 2008/07/15 $
10397 + * $Change: 1064918 $
10399 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
10400 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
10401 + * otherwise expressly agreed to in writing between Synopsys and you.
10403 + * The Software IS NOT an item of Licensed Software or Licensed Product under
10404 + * any End User Software License Agreement or Agreement for Licensed Product
10405 + * with Synopsys or any supplement thereto. You are permitted to use and
10406 + * redistribute this Software in source and binary forms, with or without
10407 + * modification, provided that redistributions of source code must retain this
10408 + * notice. You may not view, use, disclose, copy or distribute this file or
10409 + * any information contained herein except pursuant to this license grant from
10410 + * Synopsys. If you do not agree with this notice, including the disclaimer
10411 + * below, then you are not authorized to use the Software.
10413 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
10414 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10415 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10416 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
10417 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10418 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
10419 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
10420 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10421 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10422 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
10424 + * ========================================================================== */
10426 +#ifndef __DWC_OTG_DRIVER_H__
10427 +#define __DWC_OTG_DRIVER_H__
10430 + * This file contains the interface to the Linux driver.
10432 +#include "dwc_otg_cil.h"
10434 +/* Type declarations */
10435 +struct dwc_otg_pcd;
10436 +struct dwc_otg_hcd;
10439 + * This structure is a wrapper that encapsulates the driver components used to
10440 + * manage a single DWC_otg controller.
10442 +typedef struct dwc_otg_device {
10443 + /** Base address returned from ioremap() */
10446 + struct lm_device *lmdev;
10448 + /** Pointer to the core interface structure. */
10449 + dwc_otg_core_if_t *core_if;
10451 + /** Register offset for Diagnostic API. */
10452 + uint32_t reg_offset;
10454 + /** Pointer to the PCD structure. */
10455 + struct dwc_otg_pcd *pcd;
10457 + /** Pointer to the HCD structure. */
10458 + struct dwc_otg_hcd *hcd;
10460 + /** Flag to indicate whether the common IRQ handler is installed. */
10461 + uint8_t common_irq_installed;
10463 +} dwc_otg_device_t;
10467 +++ b/drivers/usb/host/otg/dwc_otg_hcd.c
10469 +/* ==========================================================================
10470 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
10471 + * $Revision: #75 $
10472 + * $Date: 2008/07/15 $
10473 + * $Change: 1064940 $
10475 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
10476 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
10477 + * otherwise expressly agreed to in writing between Synopsys and you.
10479 + * The Software IS NOT an item of Licensed Software or Licensed Product under
10480 + * any End User Software License Agreement or Agreement for Licensed Product
10481 + * with Synopsys or any supplement thereto. You are permitted to use and
10482 + * redistribute this Software in source and binary forms, with or without
10483 + * modification, provided that redistributions of source code must retain this
10484 + * notice. You may not view, use, disclose, copy or distribute this file or
10485 + * any information contained herein except pursuant to this license grant from
10486 + * Synopsys. If you do not agree with this notice, including the disclaimer
10487 + * below, then you are not authorized to use the Software.
10489 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
10490 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10491 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10492 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
10493 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10494 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
10495 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
10496 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10497 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10498 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
10500 + * ========================================================================== */
10501 +#ifndef DWC_DEVICE_ONLY
10506 + * This file contains the implementation of the HCD. In Linux, the HCD
10507 + * implements the hc_driver API.
10509 +#include <linux/kernel.h>
10510 +#include <linux/module.h>
10511 +#include <linux/moduleparam.h>
10512 +#include <linux/init.h>
10513 +#include <linux/device.h>
10514 +#include <linux/errno.h>
10515 +#include <linux/list.h>
10516 +#include <linux/interrupt.h>
10517 +#include <linux/string.h>
10518 +#include <linux/dma-mapping.h>
10519 +#include <linux/version.h>
10521 +#include <mach/lm.h>
10522 +#include <mach/irqs.h>
10524 +#include "dwc_otg_driver.h"
10525 +#include "dwc_otg_hcd.h"
10526 +#include "dwc_otg_regs.h"
10528 +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
10530 +static const struct hc_driver dwc_otg_hc_driver = {
10532 + .description = dwc_otg_hcd_name,
10533 + .product_desc = "DWC OTG Controller",
10534 + .hcd_priv_size = sizeof(dwc_otg_hcd_t),
10536 + .irq = dwc_otg_hcd_irq,
10538 + .flags = HCD_MEMORY | HCD_USB2,
10541 + .start = dwc_otg_hcd_start,
10544 + .stop = dwc_otg_hcd_stop,
10546 + .urb_enqueue = dwc_otg_hcd_urb_enqueue,
10547 + .urb_dequeue = dwc_otg_hcd_urb_dequeue,
10548 + .endpoint_disable = dwc_otg_hcd_endpoint_disable,
10550 + .get_frame_number = dwc_otg_hcd_get_frame_number,
10552 + .hub_status_data = dwc_otg_hcd_hub_status_data,
10553 + .hub_control = dwc_otg_hcd_hub_control,
10559 + * Work queue function for starting the HCD when A-Cable is connected.
10560 + * The dwc_otg_hcd_start() must be called in a process context.
10562 +static void hcd_start_func(
10563 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10566 + struct work_struct *_work
10570 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10571 + struct usb_hcd *usb_hcd = (struct usb_hcd *)_vp;
10573 + struct delayed_work *dw = container_of(_work, struct delayed_work, work);
10574 + struct dwc_otg_hcd *otg_hcd = container_of(dw, struct dwc_otg_hcd, start_work);
10575 + struct usb_hcd *usb_hcd = container_of((void *)otg_hcd, struct usb_hcd, hcd_priv);
10577 + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, usb_hcd);
10579 + dwc_otg_hcd_start(usb_hcd);
10584 + * HCD Callback function for starting the HCD when A-Cable is
10587 + * @param p void pointer to the <code>struct usb_hcd</code>
10589 +static int32_t dwc_otg_hcd_start_cb(void *p)
10591 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(p);
10592 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
10593 + hprt0_data_t hprt0;
10595 + if (core_if->op_state == B_HOST) {
10597 + * Reset the port. During a HNP mode switch the reset
10598 + * needs to occur within 1ms and have a duration of at
10601 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
10602 + hprt0.b.prtrst = 1;
10603 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
10604 + ((struct usb_hcd *)p)->self.is_b_host = 1;
10606 + ((struct usb_hcd *)p)->self.is_b_host = 0;
10609 + /* Need to start the HCD in a non-interrupt context. */
10610 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10611 + INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func, p);
10612 +// INIT_DELAYED_WORK(&dwc_otg_hcd->start_work, hcd_start_func, p);
10614 +// INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
10615 + INIT_DELAYED_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
10617 +// schedule_work(&dwc_otg_hcd->start_work);
10618 + queue_delayed_work(core_if->wq_otg, &dwc_otg_hcd->start_work, 50 * HZ / 1000);
10624 + * HCD Callback function for stopping the HCD.
10626 + * @param p void pointer to the <code>struct usb_hcd</code>
10628 +static int32_t dwc_otg_hcd_stop_cb(void *p)
10630 + struct usb_hcd *usb_hcd = (struct usb_hcd *)p;
10631 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
10632 + dwc_otg_hcd_stop(usb_hcd);
10636 +static void del_xfer_timers(dwc_otg_hcd_t *hcd)
10640 + int num_channels = hcd->core_if->core_params->host_channels;
10641 + for (i = 0; i < num_channels; i++) {
10642 + del_timer(&hcd->core_if->hc_xfer_timer[i]);
10647 +static void del_timers(dwc_otg_hcd_t *hcd)
10649 + del_xfer_timers(hcd);
10650 + del_timer(&hcd->conn_timer);
10654 + * Processes all the URBs in a single list of QHs. Completes them with
10655 + * -ETIMEDOUT and frees the QTD.
10657 +static void kill_urbs_in_qh_list(dwc_otg_hcd_t *hcd, struct list_head *qh_list)
10659 + struct list_head *qh_item;
10660 + dwc_otg_qh_t *qh;
10661 + struct list_head *qtd_item;
10662 + dwc_otg_qtd_t *qtd;
10664 + list_for_each(qh_item, qh_list) {
10665 + qh = list_entry(qh_item, dwc_otg_qh_t, qh_list_entry);
10666 + for (qtd_item = qh->qtd_list.next;
10667 + qtd_item != &qh->qtd_list;
10668 + qtd_item = qh->qtd_list.next) {
10669 + qtd = list_entry(qtd_item, dwc_otg_qtd_t, qtd_list_entry);
10670 + if (qtd->urb != NULL) {
10671 + dwc_otg_hcd_complete_urb(hcd, qtd->urb,
10674 + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd);
10680 + * Responds with an error status of ETIMEDOUT to all URBs in the non-periodic
10681 + * and periodic schedules. The QTD associated with each URB is removed from
10682 + * the schedule and freed. This function may be called when a disconnect is
10683 + * detected or when the HCD is being stopped.
10685 +static void kill_all_urbs(dwc_otg_hcd_t *hcd)
10687 + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
10688 + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
10689 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
10690 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
10691 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
10692 + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
10696 + * HCD Callback function for disconnect of the HCD.
10698 + * @param p void pointer to the <code>struct usb_hcd</code>
10700 +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
10702 + gintsts_data_t intr;
10703 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(p);
10705 + //DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
10708 + * Set status flags for the hub driver.
10710 + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
10711 + dwc_otg_hcd->flags.b.port_connect_status = 0;
10714 + * Shutdown any transfers in process by clearing the Tx FIFO Empty
10715 + * interrupt mask and status bits and disabling subsequent host
10716 + * channel interrupts.
10719 + intr.b.nptxfempty = 1;
10720 + intr.b.ptxfempty = 1;
10721 + intr.b.hcintr = 1;
10722 + dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, intr.d32, 0);
10723 + dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintsts, intr.d32, 0);
10725 + del_timers(dwc_otg_hcd);
10728 + * Turn off the vbus power only if the core has transitioned to device
10729 + * mode. If still in host mode, need to keep power on to detect a
10732 + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
10733 + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
10734 + hprt0_data_t hprt0 = { .d32=0 };
10735 + DWC_PRINT("Disconnect: PortPower off\n");
10736 + hprt0.b.prtpwr = 0;
10737 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
10740 + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
10743 + /* Respond with an error status to all URBs in the schedule. */
10744 + kill_all_urbs(dwc_otg_hcd);
10746 + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
10747 + /* Clean up any host channels that were in use. */
10748 + int num_channels;
10750 + dwc_hc_t *channel;
10751 + dwc_otg_hc_regs_t *hc_regs;
10752 + hcchar_data_t hcchar;
10754 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
10756 + if (!dwc_otg_hcd->core_if->dma_enable) {
10757 + /* Flush out any channel requests in slave mode. */
10758 + for (i = 0; i < num_channels; i++) {
10759 + channel = dwc_otg_hcd->hc_ptr_array[i];
10760 + if (list_empty(&channel->hc_list_entry)) {
10761 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
10762 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10763 + if (hcchar.b.chen) {
10764 + hcchar.b.chen = 0;
10765 + hcchar.b.chdis = 1;
10766 + hcchar.b.epdir = 0;
10767 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
10773 + for (i = 0; i < num_channels; i++) {
10774 + channel = dwc_otg_hcd->hc_ptr_array[i];
10775 + if (list_empty(&channel->hc_list_entry)) {
10776 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
10777 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
10778 + if (hcchar.b.chen) {
10779 + /* Halt the channel. */
10780 + hcchar.b.chdis = 1;
10781 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
10784 + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if, channel);
10785 + list_add_tail(&channel->hc_list_entry,
10786 + &dwc_otg_hcd->free_hc_list);
10791 + /* A disconnect will end the session so the B-Device is no
10792 + * longer a B-host. */
10793 + ((struct usb_hcd *)p)->self.is_b_host = 0;
10798 + * Connection timeout function. An OTG host is required to display a
10799 + * message if the device does not connect within 10 seconds.
10801 +void dwc_otg_hcd_connect_timeout(unsigned long ptr)
10803 + DWC_DEBUGPL(DBG_HCDV, "%s(%x)\n", __func__, (int)ptr);
10804 + DWC_PRINT("Connect Timeout\n");
10805 + DWC_ERROR("Device Not Connected/Responding\n");
10809 + * Start the connection timer. An OTG host is required to display a
10810 + * message if the device does not connect within 10 seconds. The
10811 + * timer is deleted if a port connect interrupt occurs before the
10814 +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t *hcd)
10816 + init_timer(&hcd->conn_timer);
10817 + hcd->conn_timer.function = dwc_otg_hcd_connect_timeout;
10818 + hcd->conn_timer.data = 0;
10819 + hcd->conn_timer.expires = jiffies + (HZ * 10);
10820 + add_timer(&hcd->conn_timer);
10824 + * HCD Callback function for disconnect of the HCD.
10826 + * @param p void pointer to the <code>struct usb_hcd</code>
10828 +static int32_t dwc_otg_hcd_session_start_cb(void *p)
10830 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(p);
10831 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
10832 + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
10837 + * HCD Callback structure for handling mode switching.
10839 +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
10840 + .start = dwc_otg_hcd_start_cb,
10841 + .stop = dwc_otg_hcd_stop_cb,
10842 + .disconnect = dwc_otg_hcd_disconnect_cb,
10843 + .session_start = dwc_otg_hcd_session_start_cb,
10848 + * Reset tasklet function
10850 +static void reset_tasklet_func(unsigned long data)
10852 + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *)data;
10853 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
10854 + hprt0_data_t hprt0;
10856 + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
10858 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
10859 + hprt0.b.prtrst = 1;
10860 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
10863 + hprt0.b.prtrst = 0;
10864 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
10865 + dwc_otg_hcd->flags.b.port_reset_change = 1;
10868 +static struct tasklet_struct reset_tasklet = {
10871 + .count = ATOMIC_INIT(0),
10872 + .func = reset_tasklet_func,
10877 + * Initializes the HCD. This function allocates memory for and initializes the
10878 + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
10879 + * USB bus with the core and calls the hc_driver->start() function. It returns
10880 + * a negative error on failure.
10882 +int dwc_otg_hcd_init(struct lm_device *lmdev)
10884 + struct usb_hcd *hcd = NULL;
10885 + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
10886 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lmdev);
10888 + int num_channels;
10890 + dwc_hc_t *channel;
10894 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
10896 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
10897 + /* 2.6.20+ requires dev.dma_mask to be set prior to calling usb_create_hcd() */
10899 + /* Set device flags indicating whether the HCD supports DMA. */
10900 + if (otg_dev->core_if->dma_enable) {
10901 + DWC_PRINT("Using DMA mode\n");
10903 +//090707: setting dma_mask would cause kernel to fetch 0xffffffff, result in crash, at scsi_calculate_bounce_limit
10904 + lmdev->dev.dma_mask = (void *)~0;
10905 + lmdev->dev.coherent_dma_mask = ~0;
10908 + if (otg_dev->core_if->dma_desc_enable) {
10909 + DWC_PRINT("Device using Descriptor DMA mode\n");
10911 + DWC_PRINT("Device using Buffer DMA mode\n");
10914 + DWC_PRINT("Using Slave mode\n");
10915 + lmdev->dev.dma_mask = (void *)0;
10916 + lmdev->dev.coherent_dma_mask = 0;
10920 + * Allocate memory for the base HCD plus the DWC OTG HCD.
10921 + * Initialize the base HCD.
10924 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
10925 + hcd = usb_create_hcd(&dwc_otg_hc_driver, &lmdev->dev, lmdev->dev.bus_id);
10927 + hcd = usb_create_hcd(&dwc_otg_hc_driver, &lmdev->dev, "gadget");
10930 + retval = -ENOMEM;
10934 + hcd->regs = otg_dev->base;
10935 + hcd->self.otg_port = 1;
10937 + /* Initialize the DWC OTG HCD. */
10938 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
10939 + dwc_otg_hcd->core_if = otg_dev->core_if;
10940 + otg_dev->hcd = dwc_otg_hcd;
10943 + spin_lock_init(&dwc_otg_hcd->lock);
10945 + /* Register the HCD CIL Callbacks */
10946 + dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
10947 + &hcd_cil_callbacks, hcd);
10949 + /* Initialize the non-periodic schedule. */
10950 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
10951 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
10953 + /* Initialize the periodic schedule. */
10954 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
10955 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
10956 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
10957 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
10960 + * Create a host channel descriptor for each host channel implemented
10961 + * in the controller. Initialize the channel descriptor array.
10963 + INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
10964 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
10965 + memset(dwc_otg_hcd->hc_ptr_array, 0, sizeof(dwc_otg_hcd->hc_ptr_array));
10966 + for (i = 0; i < num_channels; i++) {
10967 + channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
10968 + if (channel == NULL) {
10969 + retval = -ENOMEM;
10970 + DWC_ERROR("%s: host channel allocation failed\n", __func__);
10973 + memset(channel, 0, sizeof(dwc_hc_t));
10974 + channel->hc_num = i;
10975 + dwc_otg_hcd->hc_ptr_array[i] = channel;
10977 + init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
10979 + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
10982 + /* Initialize the Connection timeout timer. */
10983 + init_timer(&dwc_otg_hcd->conn_timer);
10985 + /* Initialize reset tasklet. */
10986 + reset_tasklet.data = (unsigned long) dwc_otg_hcd;
10987 + dwc_otg_hcd->reset_tasklet = &reset_tasklet;
10989 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10990 + /* Set device flags indicating whether the HCD supports DMA. */
10991 + if (otg_dev->core_if->dma_enable) {
10992 + DWC_PRINT("Using DMA mode\n");
10993 + lmdev->dev.dma_mask = (void *)~0;
10994 + lmdev->dev.coherent_dma_mask = ~0;
10996 + if (otg_dev->core_if->dma_desc_enable){
10997 + DWC_PRINT("Device using Descriptor DMA mode\n");
10999 + DWC_PRINT("Device using Buffer DMA mode\n");
11002 + DWC_PRINT("Using Slave mode\n");
11003 + lmdev->dev.dma_mask = (void *)0;
11004 + lmdev->dev.coherent_dma_mask = 0;
11008 + * Finish generic HCD initialization and start the HCD. This function
11009 + * allocates the DMA buffer pool, registers the USB bus, requests the
11010 + * IRQ line, and calls dwc_otg_hcd_start method.
11012 + retval = usb_add_hcd(hcd, lmdev->irq, IRQF_SHARED);
11013 + if (retval < 0) {
11018 + * Allocate space for storing data on status transactions. Normally no
11019 + * data is sent, but this space acts as a bit bucket. This must be
11020 + * done after usb_add_hcd since that function allocates the DMA buffer
11023 + if (otg_dev->core_if->dma_enable) {
11024 + dwc_otg_hcd->status_buf =
11025 + dma_alloc_coherent(&lmdev->dev,
11026 + DWC_OTG_HCD_STATUS_BUF_SIZE,
11027 + &dwc_otg_hcd->status_buf_dma,
11028 + GFP_KERNEL | GFP_DMA);
11030 + dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
11033 + if (!dwc_otg_hcd->status_buf) {
11034 + retval = -ENOMEM;
11035 + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
11039 + dwc_otg_hcd->otg_dev = otg_dev;
11041 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
11042 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
11043 + lmdev->dev.bus_id, hcd->self.busnum);
11045 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, usbbus=%d\n",
11046 + hcd->self.busnum);
11050 + /* Error conditions */
11052 + usb_remove_hcd(hcd);
11054 + dwc_otg_hcd_free(hcd);
11055 + usb_put_hcd(hcd);
11061 + * Removes the HCD.
11062 + * Frees memory and resources associated with the HCD and deregisters the bus.
11064 +void dwc_otg_hcd_remove(struct lm_device *lmdev)
11066 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lmdev);
11067 + dwc_otg_hcd_t *dwc_otg_hcd;
11068 + struct usb_hcd *hcd;
11070 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE\n");
11073 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
11077 + dwc_otg_hcd = otg_dev->hcd;
11079 + if (!dwc_otg_hcd) {
11080 + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
11084 + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
11087 + DWC_DEBUGPL(DBG_ANY, "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n", __func__);
11091 + /* Turn off all interrupts */
11092 + dwc_write_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0);
11093 + dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gahbcfg, 1, 0);
11095 + usb_remove_hcd(hcd);
11096 + dwc_otg_hcd_free(hcd);
11097 + usb_put_hcd(hcd);
11100 +/* =========================================================================
11101 + * Linux HC Driver Functions
11102 + * ========================================================================= */
11105 + * Initializes dynamic portions of the DWC_otg HCD state.
11107 +static void hcd_reinit(dwc_otg_hcd_t *hcd)
11109 + struct list_head *item;
11110 + int num_channels;
11112 + dwc_hc_t *channel;
11114 + hcd->flags.d32 = 0;
11116 + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
11117 + hcd->non_periodic_channels = 0;
11118 + hcd->periodic_channels = 0;
11121 + * Put all channels in the free channel list and clean up channel
11124 + item = hcd->free_hc_list.next;
11125 + while (item != &hcd->free_hc_list) {
11127 + item = hcd->free_hc_list.next;
11129 + num_channels = hcd->core_if->core_params->host_channels;
11130 + for (i = 0; i < num_channels; i++) {
11131 + channel = hcd->hc_ptr_array[i];
11132 + list_add_tail(&channel->hc_list_entry, &hcd->free_hc_list);
11133 + dwc_otg_hc_cleanup(hcd->core_if, channel);
11136 + /* Initialize the DWC core for host mode operation. */
11137 + dwc_otg_core_host_init(hcd->core_if);
11140 +/** Initializes the DWC_otg controller and its root hub and prepares it for host
11141 + * mode operation. Activates the root port. Returns 0 on success and a negative
11142 + * error code on failure. */
11143 +int dwc_otg_hcd_start(struct usb_hcd *hcd)
11145 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11146 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
11147 + struct usb_bus *bus;
11149 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
11150 + struct usb_device *udev;
11154 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
11156 + bus = hcd_to_bus(hcd);
11158 + /* Initialize the bus state. If the core is in Device Mode
11159 + * HALT the USB bus and return. */
11160 + if (dwc_otg_is_device_mode(core_if)) {
11161 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
11162 + hcd->state = HC_STATE_HALT;
11164 + hcd->state = HC_STATE_RUNNING;
11168 + hcd->state = HC_STATE_RUNNING;
11170 + /* Initialize and connect root hub if one is not already attached */
11171 + if (bus->root_hub) {
11172 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
11173 + /* Inform the HUB driver to resume. */
11174 + usb_hcd_resume_root_hub(hcd);
11177 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Does Not Have Root Hub\n");
11179 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
11180 + udev = usb_alloc_dev(NULL, bus, 0);
11181 + udev->speed = USB_SPEED_HIGH;
11183 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
11186 + if ((retval = usb_hcd_register_root_hub(udev, hcd)) != 0) {
11187 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error registering %d\n", retval);
11193 + hcd_reinit(dwc_otg_hcd);
11198 +static void qh_list_free(dwc_otg_hcd_t *hcd, struct list_head *qh_list)
11200 + struct list_head *item;
11201 + dwc_otg_qh_t *qh;
11203 + if (!qh_list->next) {
11204 + /* The list hasn't been initialized yet. */
11208 + /* Ensure there are no QTDs or URBs left. */
11209 + kill_urbs_in_qh_list(hcd, qh_list);
11211 + for (item = qh_list->next; item != qh_list; item = qh_list->next) {
11212 + qh = list_entry(item, dwc_otg_qh_t, qh_list_entry);
11213 + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
11218 + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
11221 +void dwc_otg_hcd_stop(struct usb_hcd *hcd)
11223 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11224 + hprt0_data_t hprt0 = { .d32=0 };
11226 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
11228 + /* Turn off all host-specific interrupts. */
11229 + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
11232 + * The root hub should be disconnected before this function is called.
11233 + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
11234 + * and the QH lists (via ..._hcd_endpoint_disable).
11237 + /* Turn off the vbus power */
11238 + DWC_PRINT("PortPower off\n");
11239 + hprt0.b.prtpwr = 0;
11240 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
11243 +/** Returns the current frame number. */
11244 +int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd)
11246 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11247 + hfnum_data_t hfnum;
11249 + hfnum.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->
11250 + host_if->host_global_regs->hfnum);
11253 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n", hfnum.b.frnum);
11255 + return hfnum.b.frnum;
11259 + * Frees secondary storage associated with the dwc_otg_hcd structure contained
11260 + * in the struct usb_hcd field.
11262 +void dwc_otg_hcd_free(struct usb_hcd *hcd)
11264 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11267 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
11269 + del_timers(dwc_otg_hcd);
11271 + /* Free memory for QH/QTD lists */
11272 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
11273 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
11274 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
11275 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
11276 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
11277 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
11279 + /* Free memory for the host channels. */
11280 + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
11281 + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
11282 + if (hc != NULL) {
11283 + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n", i, hc);
11288 + if (dwc_otg_hcd->core_if->dma_enable) {
11289 + if (dwc_otg_hcd->status_buf_dma) {
11290 + dma_free_coherent(hcd->self.controller,
11291 + DWC_OTG_HCD_STATUS_BUF_SIZE,
11292 + dwc_otg_hcd->status_buf,
11293 + dwc_otg_hcd->status_buf_dma);
11295 + } else if (dwc_otg_hcd->status_buf != NULL) {
11296 + kfree(dwc_otg_hcd->status_buf);
11301 +static void dump_urb_info(struct urb *urb, char* fn_name)
11303 + DWC_PRINT("%s, urb %p\n", fn_name, urb);
11304 + DWC_PRINT(" Device address: %d\n", usb_pipedevice(urb->pipe));
11305 + DWC_PRINT(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
11306 + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
11307 + DWC_PRINT(" Endpoint type: %s\n",
11308 + ({char *pipetype;
11309 + switch (usb_pipetype(urb->pipe)) {
11310 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
11311 + case PIPE_BULK: pipetype = "BULK"; break;
11312 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
11313 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
11314 + default: pipetype = "UNKNOWN"; break;
11316 + DWC_PRINT(" Speed: %s\n",
11318 + switch (urb->dev->speed) {
11319 + case USB_SPEED_HIGH: speed = "HIGH"; break;
11320 + case USB_SPEED_FULL: speed = "FULL"; break;
11321 + case USB_SPEED_LOW: speed = "LOW"; break;
11322 + default: speed = "UNKNOWN"; break;
11324 + DWC_PRINT(" Max packet size: %d\n",
11325 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
11326 + DWC_PRINT(" Data buffer length: %d\n", urb->transfer_buffer_length);
11327 + DWC_PRINT(" Transfer buffer: %p, Transfer DMA: %p\n",
11328 + urb->transfer_buffer, (void *)urb->transfer_dma);
11329 + DWC_PRINT(" Setup buffer: %p, Setup DMA: %p\n",
11330 + urb->setup_packet, (void *)urb->setup_dma);
11331 + DWC_PRINT(" Interval: %d\n", urb->interval);
11332 + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
11334 + for (i = 0; i < urb->number_of_packets; i++) {
11335 + DWC_PRINT(" ISO Desc %d:\n", i);
11336 + DWC_PRINT(" offset: %d, length %d\n",
11337 + urb->iso_frame_desc[i].offset,
11338 + urb->iso_frame_desc[i].length);
11343 +static void dump_channel_info(dwc_otg_hcd_t *hcd,
11344 + dwc_otg_qh_t *qh)
11346 + if (qh->channel != NULL) {
11347 + dwc_hc_t *hc = qh->channel;
11348 + struct list_head *item;
11349 + dwc_otg_qh_t *qh_item;
11350 + int num_channels = hcd->core_if->core_params->host_channels;
11353 + dwc_otg_hc_regs_t *hc_regs;
11354 + hcchar_data_t hcchar;
11355 + hcsplt_data_t hcsplt;
11356 + hctsiz_data_t hctsiz;
11359 + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
11360 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11361 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
11362 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
11363 + hcdma = dwc_read_reg32(&hc_regs->hcdma);
11365 + DWC_PRINT(" Assigned to channel %p:\n", hc);
11366 + DWC_PRINT(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
11367 + DWC_PRINT(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
11368 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
11369 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
11370 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
11371 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
11372 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
11373 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
11374 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
11375 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
11376 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
11377 + DWC_PRINT(" qh: %p\n", hc->qh);
11378 + DWC_PRINT(" NP inactive sched:\n");
11379 + list_for_each(item, &hcd->non_periodic_sched_inactive) {
11380 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
11381 + DWC_PRINT(" %p\n", qh_item);
11383 + DWC_PRINT(" NP active sched:\n");
11384 + list_for_each(item, &hcd->non_periodic_sched_active) {
11385 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
11386 + DWC_PRINT(" %p\n", qh_item);
11388 + DWC_PRINT(" Channels: \n");
11389 + for (i = 0; i < num_channels; i++) {
11390 + dwc_hc_t *hc = hcd->hc_ptr_array[i];
11391 + DWC_PRINT(" %2d: %p\n", i, hc);
11398 +//OTG host require the DMA addr is DWORD-aligned,
11399 +//patch it if the buffer is not DWORD-aligned
11401 +void hcd_check_and_patch_dma_addr(struct urb *urb){
11403 + if((!urb->transfer_buffer)||!urb->transfer_dma||urb->transfer_dma==0xffffffff)
11406 + if(((u32)urb->transfer_buffer)& 0x3){
11410 + "transfer_buffer=%.8x, "
11411 + "transfer_dma=%.8x, "
11412 + "transfer_buffer_length=%d, "
11413 + "actual_length=%d(%x), "
11415 + ((urb->transfer_flags & URB_DIR_MASK)==URB_DIR_OUT)?"OUT":"IN",
11417 + urb->transfer_buffer,
11418 + urb->transfer_dma,
11419 + urb->transfer_buffer_length,
11420 + urb->actual_length,urb->actual_length
11423 + if(!urb->aligned_transfer_buffer||urb->aligned_transfer_buffer_length<urb->transfer_buffer_length){
11424 + urb->aligned_transfer_buffer_length=urb->transfer_buffer_length;
11425 + if(urb->aligned_transfer_buffer) {
11426 + kfree(urb->aligned_transfer_buffer);
11428 + urb->aligned_transfer_buffer=kmalloc(urb->aligned_transfer_buffer_length,GFP_KERNEL|GFP_DMA|GFP_ATOMIC);
11429 + urb->aligned_transfer_dma=dma_map_single(NULL,(void *)(urb->aligned_transfer_buffer),(urb->aligned_transfer_buffer_length),DMA_FROM_DEVICE);
11430 + if(!urb->aligned_transfer_buffer){
11431 + DWC_ERROR("Cannot alloc required buffer!!\n");
11434 + //printk(" new allocated aligned_buf=%.8x aligned_buf_len=%d\n", (u32)urb->aligned_transfer_buffer, urb->aligned_transfer_buffer_length);
11436 + urb->transfer_dma=urb->aligned_transfer_dma;
11437 + if((urb->transfer_flags & URB_DIR_MASK)==URB_DIR_OUT) {
11438 + memcpy(urb->aligned_transfer_buffer,urb->transfer_buffer,urb->transfer_buffer_length);
11439 + dma_sync_single_for_device(NULL,urb->transfer_dma,urb->transfer_buffer_length,DMA_TO_DEVICE);
11446 +/** Starts processing a USB transfer request specified by a USB Request Block
11447 + * (URB). mem_flags indicates the type of memory allocation to use while
11448 + * processing this URB. */
11449 +int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
11450 +// struct usb_host_endpoint *ep,
11452 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
11460 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11461 + dwc_otg_qtd_t *qtd;
11464 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
11465 + dump_urb_info(urb, "dwc_otg_hcd_urb_enqueue");
11468 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
11469 + /* No longer connected. */
11473 + hcd_check_and_patch_dma_addr(urb);
11474 + qtd = dwc_otg_hcd_qtd_create(urb);
11475 + if (qtd == NULL) {
11476 + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
11480 + retval = dwc_otg_hcd_qtd_add(qtd, dwc_otg_hcd);
11481 + if (retval < 0) {
11482 + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
11483 + "Error status %d\n", retval);
11484 + dwc_otg_hcd_qtd_free(qtd);
11490 +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
11492 +int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
11493 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
11494 + struct usb_host_endpoint *ep,
11496 + struct urb *urb, int status)
11498 + unsigned long flags;
11499 + dwc_otg_hcd_t *dwc_otg_hcd;
11500 + dwc_otg_qtd_t *urb_qtd;
11501 + dwc_otg_qh_t *qh;
11502 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
11503 + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
11506 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
11508 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11510 + SPIN_LOCK_IRQSAVE(&dwc_otg_hcd->lock, flags);
11512 + urb_qtd = (dwc_otg_qtd_t *)urb->hcpriv;
11513 + qh = (dwc_otg_qh_t *)ep->hcpriv;
11516 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
11517 + dump_urb_info(urb, "dwc_otg_hcd_urb_dequeue");
11518 + if (urb_qtd == qh->qtd_in_process) {
11519 + dump_channel_info(dwc_otg_hcd, qh);
11524 + if (urb_qtd == qh->qtd_in_process) {
11525 + /* The QTD is in process (it has been assigned to a channel). */
11527 + if (dwc_otg_hcd->flags.b.port_connect_status) {
11529 + * If still connected (i.e. in host mode), halt the
11530 + * channel so it can be used for other transfers. If
11531 + * no longer connected, the host registers can't be
11532 + * written to halt the channel since the core is in
11535 + dwc_otg_hc_halt(dwc_otg_hcd->core_if, qh->channel,
11536 + DWC_OTG_HC_XFER_URB_DEQUEUE);
11541 + * Free the QTD and clean up the associated QH. Leave the QH in the
11542 + * schedule if it has any remaining QTDs.
11544 + dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd, urb_qtd);
11545 + if (urb_qtd == qh->qtd_in_process) {
11546 + dwc_otg_hcd_qh_deactivate(dwc_otg_hcd, qh, 0);
11547 + qh->channel = NULL;
11548 + qh->qtd_in_process = NULL;
11549 + } else if (list_empty(&qh->qtd_list)) {
11550 + dwc_otg_hcd_qh_remove(dwc_otg_hcd, qh);
11553 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
11555 + urb->hcpriv = NULL;
11557 + /* Higher layer software sets URB status. */
11558 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
11559 + usb_hcd_giveback_urb(hcd, urb, status);
11561 + usb_hcd_giveback_urb(hcd, urb, NULL);
11563 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
11564 + DWC_PRINT("Called usb_hcd_giveback_urb()\n");
11565 + DWC_PRINT(" urb->status = %d\n", urb->status);
11571 +/** Frees resources in the DWC_otg controller related to a given endpoint. Also
11572 + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
11573 + * must already be dequeued. */
11574 +void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
11575 + struct usb_host_endpoint *ep)
11577 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11578 + dwc_otg_qh_t *qh;
11580 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
11581 + unsigned long flags;
11585 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
11586 + "endpoint=%d\n", ep->desc.bEndpointAddress,
11587 + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
11589 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
11591 + SPIN_LOCK_IRQSAVE(&dwc_otg_hcd->lock, flags);
11592 + qh = (dwc_otg_qh_t *)(ep->hcpriv);
11596 + /** Check that the QTD list is really empty */
11597 + if (!list_empty(&qh->qtd_list)) {
11598 + if (retry++ < 250) {
11599 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
11600 + schedule_timeout_uninterruptible(1);
11604 + DWC_WARN("DWC OTG HCD EP DISABLE:"
11605 + " QTD List for this endpoint is not empty\n");
11608 + dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
11609 + ep->hcpriv = NULL;
11611 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
11613 +#else // LINUX_VERSION_CODE
11615 + qh = (dwc_otg_qh_t *)(ep->hcpriv);
11616 + if (qh != NULL) {
11618 + /** Check that the QTD list is really empty */
11619 + if (!list_empty(&qh->qtd_list)) {
11620 + DWC_WARN("DWC OTG HCD EP DISABLE:"
11621 + " QTD List for this endpoint is not empty\n");
11624 + dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
11625 + ep->hcpriv = NULL;
11627 +#endif // LINUX_VERSION_CODE
11630 +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
11631 + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
11634 + * This function is called by the USB core when an interrupt occurs */
11635 +irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd
11636 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
11637 + , struct pt_regs *regs
11642 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11643 + retVal = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
11644 + if (dwc_otg_hcd->flags.b.port_connect_status_change == 1)
11645 + usb_hcd_poll_rh_status(hcd);
11646 + return IRQ_RETVAL(retVal);
11649 +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
11650 + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
11651 + * is the status change indicator for the single root port. Returns 1 if either
11652 + * change indicator is 1, otherwise returns 0. */
11653 +int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd, char *buf)
11655 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
11658 + buf[0] |= (dwc_otg_hcd->flags.b.port_connect_status_change ||
11659 + dwc_otg_hcd->flags.b.port_reset_change ||
11660 + dwc_otg_hcd->flags.b.port_enable_change ||
11661 + dwc_otg_hcd->flags.b.port_suspend_change ||
11662 + dwc_otg_hcd->flags.b.port_over_current_change) << 1;
11666 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
11667 + " Root port status changed\n");
11668 + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
11669 + dwc_otg_hcd->flags.b.port_connect_status_change);
11670 + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
11671 + dwc_otg_hcd->flags.b.port_reset_change);
11672 + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
11673 + dwc_otg_hcd->flags.b.port_enable_change);
11674 + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
11675 + dwc_otg_hcd->flags.b.port_suspend_change);
11676 + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
11677 + dwc_otg_hcd->flags.b.port_over_current_change);
11680 + return (buf[0] != 0);
11683 +#ifdef DWC_HS_ELECT_TST
11685 + * Quick and dirty hack to implement the HS Electrical Test
11686 + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
11688 + * This code was copied from our userspace app "hset". It sends a
11689 + * Get Device Descriptor control sequence in two parts, first the
11690 + * Setup packet by itself, followed some time later by the In and
11691 + * Ack packets. Rather than trying to figure out how to add this
11692 + * functionality to the normal driver code, we just hijack the
11693 + * hardware, using these two function to drive the hardware
11697 +dwc_otg_core_global_regs_t *global_regs;
11698 +dwc_otg_host_global_regs_t *hc_global_regs;
11699 +dwc_otg_hc_regs_t *hc_regs;
11700 +uint32_t *data_fifo;
11702 +static void do_setup(void)
11704 + gintsts_data_t gintsts;
11705 + hctsiz_data_t hctsiz;
11706 + hcchar_data_t hcchar;
11707 + haint_data_t haint;
11708 + hcint_data_t hcint;
11710 + /* Enable HAINTs */
11711 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
11713 + /* Enable HCINTs */
11714 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
11716 + /* Read GINTSTS */
11717 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11718 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11721 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11722 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11725 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11726 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11728 + /* Read HCCHAR */
11729 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11730 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11732 + /* Clear HCINT */
11733 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11735 + /* Clear HAINT */
11736 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11738 + /* Clear GINTSTS */
11739 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11741 + /* Read GINTSTS */
11742 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11743 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11746 + * Send Setup packet (Get Device Descriptor)
11749 + /* Make sure channel is disabled */
11750 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11751 + if (hcchar.b.chen) {
11752 + //fprintf(stderr, "Channel already enabled 1, HCCHAR = %08x\n", hcchar.d32);
11753 + hcchar.b.chdis = 1;
11754 +// hcchar.b.chen = 1;
11755 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11759 + /* Read GINTSTS */
11760 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11761 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11764 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11765 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11768 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11769 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11771 + /* Read HCCHAR */
11772 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11773 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11775 + /* Clear HCINT */
11776 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11778 + /* Clear HAINT */
11779 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11781 + /* Clear GINTSTS */
11782 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11784 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11785 + //if (hcchar.b.chen) {
11786 + // fprintf(stderr, "** Channel _still_ enabled 1, HCCHAR = %08x **\n", hcchar.d32);
11792 + hctsiz.b.xfersize = 8;
11793 + hctsiz.b.pktcnt = 1;
11794 + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
11795 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
11798 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11799 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
11800 + hcchar.b.epdir = 0;
11801 + hcchar.b.epnum = 0;
11802 + hcchar.b.mps = 8;
11803 + hcchar.b.chen = 1;
11804 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11806 + /* Fill FIFO with Setup data for Get Device Descriptor */
11807 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
11808 + dwc_write_reg32(data_fifo++, 0x01000680);
11809 + dwc_write_reg32(data_fifo++, 0x00080000);
11811 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11812 + //fprintf(stderr, "Waiting for HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
11814 + /* Wait for host channel interrupt */
11816 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11817 + } while (gintsts.b.hcintr == 0);
11819 + //fprintf(stderr, "Got HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
11821 + /* Disable HCINTs */
11822 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
11824 + /* Disable HAINTs */
11825 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
11828 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11829 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11832 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11833 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11835 + /* Read HCCHAR */
11836 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11837 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11839 + /* Clear HCINT */
11840 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11842 + /* Clear HAINT */
11843 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11845 + /* Clear GINTSTS */
11846 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11848 + /* Read GINTSTS */
11849 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11850 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11853 +static void do_in_ack(void)
11855 + gintsts_data_t gintsts;
11856 + hctsiz_data_t hctsiz;
11857 + hcchar_data_t hcchar;
11858 + haint_data_t haint;
11859 + hcint_data_t hcint;
11860 + host_grxsts_data_t grxsts;
11862 + /* Enable HAINTs */
11863 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
11865 + /* Enable HCINTs */
11866 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
11868 + /* Read GINTSTS */
11869 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11870 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11873 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11874 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11877 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11878 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11880 + /* Read HCCHAR */
11881 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11882 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11884 + /* Clear HCINT */
11885 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11887 + /* Clear HAINT */
11888 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11890 + /* Clear GINTSTS */
11891 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11893 + /* Read GINTSTS */
11894 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11895 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11898 + * Receive Control In packet
11901 + /* Make sure channel is disabled */
11902 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11903 + if (hcchar.b.chen) {
11904 + //fprintf(stderr, "Channel already enabled 2, HCCHAR = %08x\n", hcchar.d32);
11905 + hcchar.b.chdis = 1;
11906 + hcchar.b.chen = 1;
11907 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11911 + /* Read GINTSTS */
11912 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11913 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
11916 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
11917 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
11920 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
11921 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
11923 + /* Read HCCHAR */
11924 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11925 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
11927 + /* Clear HCINT */
11928 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
11930 + /* Clear HAINT */
11931 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
11933 + /* Clear GINTSTS */
11934 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11936 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11937 + //if (hcchar.b.chen) {
11938 + // fprintf(stderr, "** Channel _still_ enabled 2, HCCHAR = %08x **\n", hcchar.d32);
11944 + hctsiz.b.xfersize = 8;
11945 + hctsiz.b.pktcnt = 1;
11946 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
11947 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
11950 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
11951 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
11952 + hcchar.b.epdir = 1;
11953 + hcchar.b.epnum = 0;
11954 + hcchar.b.mps = 8;
11955 + hcchar.b.chen = 1;
11956 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
11958 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11959 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
11961 + /* Wait for receive status queue interrupt */
11963 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
11964 + } while (gintsts.b.rxstsqlvl == 0);
11966 + //fprintf(stderr, "Got RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
11969 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
11970 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
11972 + /* Clear RXSTSQLVL in GINTSTS */
11974 + gintsts.b.rxstsqlvl = 1;
11975 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
11977 + switch (grxsts.b.pktsts) {
11978 + case DWC_GRXSTS_PKTSTS_IN:
11979 + /* Read the data into the host buffer */
11980 + if (grxsts.b.bcnt > 0) {
11982 + int word_count = (grxsts.b.bcnt + 3) / 4;
11984 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
11986 + for (i = 0; i < word_count; i++) {
11987 + (void)dwc_read_reg32(data_fifo++);
11991 + //fprintf(stderr, "Received %u bytes\n", (unsigned)grxsts.b.bcnt);
11995 + //fprintf(stderr, "** Unexpected GRXSTS packet status 1 **\n");
11999 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12000 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
12002 + /* Wait for receive status queue interrupt */
12004 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12005 + } while (gintsts.b.rxstsqlvl == 0);
12007 + //fprintf(stderr, "Got RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
12010 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
12011 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
12013 + /* Clear RXSTSQLVL in GINTSTS */
12015 + gintsts.b.rxstsqlvl = 1;
12016 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
12018 + switch (grxsts.b.pktsts) {
12019 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
12023 + //fprintf(stderr, "** Unexpected GRXSTS packet status 2 **\n");
12027 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12028 + //fprintf(stderr, "Waiting for HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
12030 + /* Wait for host channel interrupt */
12032 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12033 + } while (gintsts.b.hcintr == 0);
12035 + //fprintf(stderr, "Got HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
12038 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
12039 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
12042 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
12043 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
12045 + /* Read HCCHAR */
12046 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
12047 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
12049 + /* Clear HCINT */
12050 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
12052 + /* Clear HAINT */
12053 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
12055 + /* Clear GINTSTS */
12056 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
12058 + /* Read GINTSTS */
12059 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12060 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
12062 +// usleep(100000);
12067 + * Send handshake packet
12071 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
12072 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
12075 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
12076 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
12078 + /* Read HCCHAR */
12079 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
12080 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
12082 + /* Clear HCINT */
12083 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
12085 + /* Clear HAINT */
12086 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
12088 + /* Clear GINTSTS */
12089 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
12091 + /* Read GINTSTS */
12092 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12093 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
12095 + /* Make sure channel is disabled */
12096 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
12097 + if (hcchar.b.chen) {
12098 + //fprintf(stderr, "Channel already enabled 3, HCCHAR = %08x\n", hcchar.d32);
12099 + hcchar.b.chdis = 1;
12100 + hcchar.b.chen = 1;
12101 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
12105 + /* Read GINTSTS */
12106 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12107 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
12110 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
12111 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
12114 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
12115 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
12117 + /* Read HCCHAR */
12118 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
12119 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
12121 + /* Clear HCINT */
12122 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
12124 + /* Clear HAINT */
12125 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
12127 + /* Clear GINTSTS */
12128 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
12130 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
12131 + //if (hcchar.b.chen) {
12132 + // fprintf(stderr, "** Channel _still_ enabled 3, HCCHAR = %08x **\n", hcchar.d32);
12138 + hctsiz.b.xfersize = 0;
12139 + hctsiz.b.pktcnt = 1;
12140 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
12141 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
12144 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
12145 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
12146 + hcchar.b.epdir = 0;
12147 + hcchar.b.epnum = 0;
12148 + hcchar.b.mps = 8;
12149 + hcchar.b.chen = 1;
12150 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
12152 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12153 + //fprintf(stderr, "Waiting for HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
12155 + /* Wait for host channel interrupt */
12157 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12158 + } while (gintsts.b.hcintr == 0);
12160 + //fprintf(stderr, "Got HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
12162 + /* Disable HCINTs */
12163 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
12165 + /* Disable HAINTs */
12166 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
12169 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
12170 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
12173 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
12174 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
12176 + /* Read HCCHAR */
12177 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
12178 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
12180 + /* Clear HCINT */
12181 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
12183 + /* Clear HAINT */
12184 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
12186 + /* Clear GINTSTS */
12187 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
12189 + /* Read GINTSTS */
12190 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
12191 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
12193 +#endif /* DWC_HS_ELECT_TST */
12195 +/** Handles hub class-specific requests. */
12196 +int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
12205 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
12206 + dwc_otg_core_if_t *core_if = hcd_to_dwc_otg_hcd(hcd)->core_if;
12207 + struct usb_hub_descriptor *desc;
12208 + hprt0_data_t hprt0 = {.d32 = 0};
12210 + uint32_t port_status;
12212 + switch (typeReq) {
12213 + case ClearHubFeature:
12214 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12215 + "ClearHubFeature 0x%x\n", wValue);
12216 + switch (wValue) {
12217 + case C_HUB_LOCAL_POWER:
12218 + case C_HUB_OVER_CURRENT:
12219 + /* Nothing required here */
12222 + retval = -EINVAL;
12223 + DWC_ERROR("DWC OTG HCD - "
12224 + "ClearHubFeature request %xh unknown\n", wValue);
12227 + case ClearPortFeature:
12228 + if (!wIndex || wIndex > 1)
12231 + switch (wValue) {
12232 + case USB_PORT_FEAT_ENABLE:
12233 + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
12234 + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
12235 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12236 + hprt0.b.prtena = 1;
12237 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12239 + case USB_PORT_FEAT_SUSPEND:
12240 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12241 + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
12242 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12243 + hprt0.b.prtres = 1;
12244 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12245 + /* Clear Resume bit */
12247 + hprt0.b.prtres = 0;
12248 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12250 + case USB_PORT_FEAT_POWER:
12251 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12252 + "ClearPortFeature USB_PORT_FEAT_POWER\n");
12253 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12254 + hprt0.b.prtpwr = 0;
12255 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12257 + case USB_PORT_FEAT_INDICATOR:
12258 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12259 + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
12260 + /* Port inidicator not supported */
12262 + case USB_PORT_FEAT_C_CONNECTION:
12263 + /* Clears drivers internal connect status change
12265 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12266 + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
12267 + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
12269 + case USB_PORT_FEAT_C_RESET:
12270 + /* Clears the driver's internal Port Reset Change
12272 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12273 + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
12274 + dwc_otg_hcd->flags.b.port_reset_change = 0;
12276 + case USB_PORT_FEAT_C_ENABLE:
12277 + /* Clears the driver's internal Port
12278 + * Enable/Disable Change flag */
12279 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12280 + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
12281 + dwc_otg_hcd->flags.b.port_enable_change = 0;
12283 + case USB_PORT_FEAT_C_SUSPEND:
12284 + /* Clears the driver's internal Port Suspend
12285 + * Change flag, which is set when resume signaling on
12286 + * the host port is complete */
12287 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12288 + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
12289 + dwc_otg_hcd->flags.b.port_suspend_change = 0;
12291 + case USB_PORT_FEAT_C_OVER_CURRENT:
12292 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12293 + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
12294 + dwc_otg_hcd->flags.b.port_over_current_change = 0;
12297 + retval = -EINVAL;
12298 + DWC_ERROR("DWC OTG HCD - "
12299 + "ClearPortFeature request %xh "
12300 + "unknown or unsupported\n", wValue);
12303 + case GetHubDescriptor:
12304 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12305 + "GetHubDescriptor\n");
12306 + desc = (struct usb_hub_descriptor *)buf;
12307 + desc->bDescLength = 9;
12308 + desc->bDescriptorType = 0x29;
12309 + desc->bNbrPorts = 1;
12310 + desc->wHubCharacteristics = 0x08;
12311 + desc->bPwrOn2PwrGood = 1;
12312 + desc->bHubContrCurrent = 0;
12313 + desc->bitmap[0] = 0;
12314 + desc->bitmap[1] = 0xff;
12316 + case GetHubStatus:
12317 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12318 + "GetHubStatus\n");
12319 + memset(buf, 0, 4);
12321 + case GetPortStatus:
12322 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12323 + "GetPortStatus\n");
12325 + if (!wIndex || wIndex > 1)
12330 + if (dwc_otg_hcd->flags.b.port_connect_status_change)
12331 + port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
12333 + if (dwc_otg_hcd->flags.b.port_enable_change)
12334 + port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
12336 + if (dwc_otg_hcd->flags.b.port_suspend_change)
12337 + port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
12339 + if (dwc_otg_hcd->flags.b.port_reset_change)
12340 + port_status |= (1 << USB_PORT_FEAT_C_RESET);
12342 + if (dwc_otg_hcd->flags.b.port_over_current_change) {
12343 + DWC_ERROR("Device Not Supported\n");
12344 + port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
12347 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
12349 + * The port is disconnected, which means the core is
12350 + * either in device mode or it soon will be. Just
12351 + * return 0's for the remainder of the port status
12352 + * since the port register can't be read if the core
12353 + * is in device mode.
12355 + *((__le32 *) buf) = cpu_to_le32(port_status);
12359 + hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
12360 + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
12362 + if (hprt0.b.prtconnsts)
12363 + port_status |= (1 << USB_PORT_FEAT_CONNECTION);
12365 + if (hprt0.b.prtena)
12366 + port_status |= (1 << USB_PORT_FEAT_ENABLE);
12368 + if (hprt0.b.prtsusp)
12369 + port_status |= (1 << USB_PORT_FEAT_SUSPEND);
12371 + if (hprt0.b.prtovrcurract)
12372 + port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
12374 + if (hprt0.b.prtrst)
12375 + port_status |= (1 << USB_PORT_FEAT_RESET);
12377 + if (hprt0.b.prtpwr)
12378 + port_status |= (1 << USB_PORT_FEAT_POWER);
12380 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
12381 + port_status |= (1 << USB_PORT_FEAT_HIGHSPEED);
12382 + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
12383 + port_status |= (1 << USB_PORT_FEAT_LOWSPEED);
12385 + if (hprt0.b.prttstctl)
12386 + port_status |= (1 << USB_PORT_FEAT_TEST);
12388 + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
12390 + *((__le32 *) buf) = cpu_to_le32(port_status);
12393 + case SetHubFeature:
12394 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12395 + "SetHubFeature\n");
12396 + /* No HUB features supported */
12398 + case SetPortFeature:
12399 + if (wValue != USB_PORT_FEAT_TEST && (!wIndex || wIndex > 1))
12402 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
12404 + * The port is disconnected, which means the core is
12405 + * either in device mode or it soon will be. Just
12406 + * return without doing anything since the port
12407 + * register can't be written if the core is in device
12413 + switch (wValue) {
12414 + case USB_PORT_FEAT_SUSPEND:
12415 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12416 + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
12417 + if (hcd->self.otg_port == wIndex &&
12418 + hcd->self.b_hnp_enable) {
12419 + gotgctl_data_t gotgctl = {.d32=0};
12420 + gotgctl.b.hstsethnpen = 1;
12421 + dwc_modify_reg32(&core_if->core_global_regs->gotgctl,
12423 + core_if->op_state = A_SUSPEND;
12425 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12426 + hprt0.b.prtsusp = 1;
12427 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12428 + //DWC_PRINT("SUSPEND: HPRT0=%0x\n", hprt0.d32);
12429 + /* Suspend the Phy Clock */
12431 + pcgcctl_data_t pcgcctl = {.d32=0};
12432 + pcgcctl.b.stoppclk = 1;
12433 + dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
12436 + /* For HNP the bus must be suspended for at least 200ms. */
12437 + if (hcd->self.b_hnp_enable) {
12439 + //DWC_PRINT("SUSPEND: wait complete! (%d)\n", _hcd->state);
12442 + case USB_PORT_FEAT_POWER:
12443 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12444 + "SetPortFeature - USB_PORT_FEAT_POWER\n");
12445 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12446 + hprt0.b.prtpwr = 1;
12447 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12449 + case USB_PORT_FEAT_RESET:
12450 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12451 + "SetPortFeature - USB_PORT_FEAT_RESET\n");
12452 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12453 + /* When B-Host the Port reset bit is set in
12454 + * the Start HCD Callback function, so that
12455 + * the reset is started within 1ms of the HNP
12456 + * success interrupt. */
12457 + if (!hcd->self.is_b_host) {
12458 + hprt0.b.prtrst = 1;
12459 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12461 + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
12463 + hprt0.b.prtrst = 0;
12464 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12467 +#ifdef DWC_HS_ELECT_TST
12468 + case USB_PORT_FEAT_TEST:
12471 + gintmsk_data_t gintmsk;
12473 + t = (wIndex >> 8); /* MSB wIndex USB */
12474 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12475 + "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
12476 + warn("USB_PORT_FEAT_TEST %d\n", t);
12478 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12479 + hprt0.b.prttstctl = t;
12480 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12482 + /* Setup global vars with reg addresses (quick and
12483 + * dirty hack, should be cleaned up)
12485 + global_regs = core_if->core_global_regs;
12486 + hc_global_regs = core_if->host_if->host_global_regs;
12487 + hc_regs = (dwc_otg_hc_regs_t *)((char *)global_regs + 0x500);
12488 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
12490 + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
12491 + /* Save current interrupt mask */
12492 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
12494 + /* Disable all interrupts while we muck with
12495 + * the hardware directly
12497 + dwc_write_reg32(&global_regs->gintmsk, 0);
12499 + /* 15 second delay per the test spec */
12502 + /* Drive suspend on the root port */
12503 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12504 + hprt0.b.prtsusp = 1;
12505 + hprt0.b.prtres = 0;
12506 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12508 + /* 15 second delay per the test spec */
12511 + /* Drive resume on the root port */
12512 + hprt0.d32 = dwc_otg_read_hprt0(core_if);
12513 + hprt0.b.prtsusp = 0;
12514 + hprt0.b.prtres = 1;
12515 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12518 + /* Clear the resume bit */
12519 + hprt0.b.prtres = 0;
12520 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
12522 + /* Restore interrupts */
12523 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
12524 + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
12525 + /* Save current interrupt mask */
12526 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
12528 + /* Disable all interrupts while we muck with
12529 + * the hardware directly
12531 + dwc_write_reg32(&global_regs->gintmsk, 0);
12533 + /* 15 second delay per the test spec */
12536 + /* Send the Setup packet */
12539 + /* 15 second delay so nothing else happens for awhile */
12542 + /* Restore interrupts */
12543 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
12544 + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
12545 + /* Save current interrupt mask */
12546 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
12548 + /* Disable all interrupts while we muck with
12549 + * the hardware directly
12551 + dwc_write_reg32(&global_regs->gintmsk, 0);
12553 + /* Send the Setup packet */
12556 + /* 15 second delay so nothing else happens for awhile */
12559 + /* Send the In and Ack packets */
12562 + /* 15 second delay so nothing else happens for awhile */
12565 + /* Restore interrupts */
12566 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
12571 +#endif /* DWC_HS_ELECT_TST */
12573 + case USB_PORT_FEAT_INDICATOR:
12574 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
12575 + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
12576 + /* Not supported */
12579 + retval = -EINVAL;
12580 + DWC_ERROR("DWC OTG HCD - "
12581 + "SetPortFeature request %xh "
12582 + "unknown or unsupported\n", wValue);
12588 + retval = -EINVAL;
12589 + DWC_WARN("DWC OTG HCD - "
12590 + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
12591 + typeReq, wIndex, wValue);
12599 + * Assigns transactions from a QTD to a free host channel and initializes the
12600 + * host channel to perform the transactions. The host channel is removed from
12603 + * @param hcd The HCD state structure.
12604 + * @param qh Transactions from the first QTD for this QH are selected and
12605 + * assigned to a free host channel.
12607 +static void assign_and_init_hc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
12610 + dwc_otg_qtd_t *qtd;
12613 + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p)\n", __func__, hcd, qh);
12615 + hc = list_entry(hcd->free_hc_list.next, dwc_hc_t, hc_list_entry);
12617 + /* Remove the host channel from the free list. */
12618 + list_del_init(&hc->hc_list_entry);
12620 + qtd = list_entry(qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
12622 + qh->channel = hc;
12623 + qh->qtd_in_process = qtd;
12626 + * Use usb_pipedevice to determine device address. This address is
12627 + * 0 before the SET_ADDRESS command and the correct address afterward.
12629 + hc->dev_addr = usb_pipedevice(urb->pipe);
12630 + hc->ep_num = usb_pipeendpoint(urb->pipe);
12632 + if (urb->dev->speed == USB_SPEED_LOW) {
12633 + hc->speed = DWC_OTG_EP_SPEED_LOW;
12634 + } else if (urb->dev->speed == USB_SPEED_FULL) {
12635 + hc->speed = DWC_OTG_EP_SPEED_FULL;
12637 + hc->speed = DWC_OTG_EP_SPEED_HIGH;
12640 + hc->max_packet = dwc_max_packet(qh->maxp);
12642 + hc->xfer_started = 0;
12643 + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
12644 + hc->error_state = (qtd->error_count > 0);
12645 + hc->halt_on_queue = 0;
12646 + hc->halt_pending = 0;
12647 + hc->requests = 0;
12650 + * The following values may be modified in the transfer type section
12651 + * below. The xfer_len value may be reduced when the transfer is
12652 + * started to accommodate the max widths of the XferSize and PktCnt
12653 + * fields in the HCTSIZn register.
12655 + hc->do_ping = qh->ping_state;
12656 + hc->ep_is_in = (usb_pipein(urb->pipe) != 0);
12657 + hc->data_pid_start = qh->data_toggle;
12658 + hc->multi_count = 1;
12660 + if (hcd->core_if->dma_enable) {
12661 + hc->xfer_buff = (uint8_t *)urb->transfer_dma + urb->actual_length;
12663 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer + urb->actual_length;
12665 + hc->xfer_len = urb->transfer_buffer_length - urb->actual_length;
12666 + hc->xfer_count = 0;
12669 + * Set the split attributes
12671 + hc->do_split = 0;
12672 + if (qh->do_split) {
12673 + hc->do_split = 1;
12674 + hc->xact_pos = qtd->isoc_split_pos;
12675 + hc->complete_split = qtd->complete_split;
12676 + hc->hub_addr = urb->dev->tt->hub->devnum;
12677 + hc->port_addr = urb->dev->ttport;
12680 + switch (usb_pipetype(urb->pipe)) {
12681 + case PIPE_CONTROL:
12682 + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
12683 + switch (qtd->control_phase) {
12684 + case DWC_OTG_CONTROL_SETUP:
12685 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
12687 + hc->ep_is_in = 0;
12688 + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
12689 + if (hcd->core_if->dma_enable) {
12690 + hc->xfer_buff = (uint8_t *)urb->setup_dma;
12692 + hc->xfer_buff = (uint8_t *)urb->setup_packet;
12694 + hc->xfer_len = 8;
12696 + case DWC_OTG_CONTROL_DATA:
12697 + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
12698 + hc->data_pid_start = qtd->data_toggle;
12700 + case DWC_OTG_CONTROL_STATUS:
12702 + * Direction is opposite of data direction or IN if no
12705 + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
12706 + if (urb->transfer_buffer_length == 0) {
12707 + hc->ep_is_in = 1;
12709 + hc->ep_is_in = (usb_pipein(urb->pipe) != USB_DIR_IN);
12711 + if (hc->ep_is_in) {
12714 + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
12715 + hc->xfer_len = 0;
12716 + if (hcd->core_if->dma_enable) {
12717 + hc->xfer_buff = (uint8_t *)hcd->status_buf_dma;
12719 + hc->xfer_buff = (uint8_t *)hcd->status_buf;
12725 + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
12727 + case PIPE_INTERRUPT:
12728 + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
12730 + case PIPE_ISOCHRONOUS:
12732 + struct usb_iso_packet_descriptor *frame_desc;
12733 + frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
12734 + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
12735 + if (hcd->core_if->dma_enable) {
12736 + hc->xfer_buff = (uint8_t *)urb->transfer_dma;
12738 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer;
12740 + hc->xfer_buff += frame_desc->offset + qtd->isoc_split_offset;
12741 + hc->xfer_len = frame_desc->length - qtd->isoc_split_offset;
12743 + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
12744 + if (hc->xfer_len <= 188) {
12745 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
12748 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_BEGIN;
12755 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
12756 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
12758 + * This value may be modified when the transfer is started to
12759 + * reflect the actual transfer length.
12761 + hc->multi_count = dwc_hb_mult(qh->maxp);
12764 + dwc_otg_hc_init(hcd->core_if, hc);
12769 + * This function selects transactions from the HCD transfer schedule and
12770 + * assigns them to available host channels. It is called from HCD interrupt
12771 + * handler functions.
12773 + * @param hcd The HCD state structure.
12775 + * @return The types of new transactions that were assigned to host channels.
12777 +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *hcd)
12779 + struct list_head *qh_ptr;
12780 + dwc_otg_qh_t *qh;
12781 + int num_channels;
12782 + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
12785 + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
12788 + /* Process entries in the periodic ready list. */
12789 + qh_ptr = hcd->periodic_sched_ready.next;
12790 + while (qh_ptr != &hcd->periodic_sched_ready &&
12791 + !list_empty(&hcd->free_hc_list)) {
12793 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
12794 + assign_and_init_hc(hcd, qh);
12797 + * Move the QH from the periodic ready schedule to the
12798 + * periodic assigned schedule.
12800 + qh_ptr = qh_ptr->next;
12801 + list_move(&qh->qh_list_entry, &hcd->periodic_sched_assigned);
12803 + ret_val = DWC_OTG_TRANSACTION_PERIODIC;
12807 + * Process entries in the inactive portion of the non-periodic
12808 + * schedule. Some free host channels may not be used if they are
12809 + * reserved for periodic transfers.
12811 + qh_ptr = hcd->non_periodic_sched_inactive.next;
12812 + num_channels = hcd->core_if->core_params->host_channels;
12813 + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
12814 + (hcd->non_periodic_channels <
12815 + num_channels - hcd->periodic_channels) &&
12816 + !list_empty(&hcd->free_hc_list)) {
12818 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
12819 + assign_and_init_hc(hcd, qh);
12822 + * Move the QH from the non-periodic inactive schedule to the
12823 + * non-periodic active schedule.
12825 + qh_ptr = qh_ptr->next;
12826 + list_move(&qh->qh_list_entry, &hcd->non_periodic_sched_active);
12828 + if (ret_val == DWC_OTG_TRANSACTION_NONE) {
12829 + ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
12831 + ret_val = DWC_OTG_TRANSACTION_ALL;
12834 + hcd->non_periodic_channels++;
12841 + * Attempts to queue a single transaction request for a host channel
12842 + * associated with either a periodic or non-periodic transfer. This function
12843 + * assumes that there is space available in the appropriate request queue. For
12844 + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
12845 + * is available in the appropriate Tx FIFO.
12847 + * @param hcd The HCD state structure.
12848 + * @param hc Host channel descriptor associated with either a periodic or
12849 + * non-periodic transfer.
12850 + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
12851 + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
12854 + * @return 1 if a request is queued and more requests may be needed to
12855 + * complete the transfer, 0 if no more requests are required for this
12856 + * transfer, -1 if there is insufficient space in the Tx FIFO.
12858 +static int queue_transaction(dwc_otg_hcd_t *hcd,
12860 + uint16_t fifo_dwords_avail)
12864 + if (hcd->core_if->dma_enable) {
12865 + if (!hc->xfer_started) {
12866 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12867 + hc->qh->ping_state = 0;
12870 + } else if (hc->halt_pending) {
12871 + /* Don't queue a request if the channel has been halted. */
12873 + } else if (hc->halt_on_queue) {
12874 + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
12876 + } else if (hc->do_ping) {
12877 + if (!hc->xfer_started) {
12878 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12881 + } else if (!hc->ep_is_in ||
12882 + hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
12883 + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
12884 + if (!hc->xfer_started) {
12885 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12888 + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
12894 + if (!hc->xfer_started) {
12895 + dwc_otg_hc_start_transfer(hcd->core_if, hc);
12898 + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
12906 + * Processes active non-periodic channels and queues transactions for these
12907 + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
12908 + * FIFO Empty interrupt is enabled if there are more transactions to queue as
12909 + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
12910 + * FIFO Empty interrupt is disabled.
12912 +static void process_non_periodic_channels(dwc_otg_hcd_t *hcd)
12914 + gnptxsts_data_t tx_status;
12915 + struct list_head *orig_qh_ptr;
12916 + dwc_otg_qh_t *qh;
12918 + int no_queue_space = 0;
12919 + int no_fifo_space = 0;
12920 + int more_to_do = 0;
12922 + dwc_otg_core_global_regs_t *global_regs = hcd->core_if->core_global_regs;
12924 + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
12926 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
12927 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (before queue): %d\n",
12928 + tx_status.b.nptxqspcavail);
12929 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
12930 + tx_status.b.nptxfspcavail);
12933 + * Keep track of the starting point. Skip over the start-of-list
12936 + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
12937 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
12939 + orig_qh_ptr = hcd->non_periodic_qh_ptr;
12942 + * Process once through the active list or until no more space is
12943 + * available in the request queue or the Tx FIFO.
12946 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
12947 + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
12948 + no_queue_space = 1;
12952 + qh = list_entry(hcd->non_periodic_qh_ptr, dwc_otg_qh_t, qh_list_entry);
12953 + status = queue_transaction(hcd, qh->channel, tx_status.b.nptxfspcavail);
12955 + if (status > 0) {
12957 + } else if (status < 0) {
12958 + no_fifo_space = 1;
12962 + /* Advance to next QH, skipping start-of-list entry. */
12963 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
12964 + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
12965 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
12968 + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
12970 + if (!hcd->core_if->dma_enable) {
12971 + gintmsk_data_t intr_mask = {.d32 = 0};
12972 + intr_mask.b.nptxfempty = 1;
12975 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
12976 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (after queue): %d\n",
12977 + tx_status.b.nptxqspcavail);
12978 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (after queue): %d\n",
12979 + tx_status.b.nptxfspcavail);
12981 + if (more_to_do || no_queue_space || no_fifo_space) {
12983 + * May need to queue more transactions as the request
12984 + * queue or Tx FIFO empties. Enable the non-periodic
12985 + * Tx FIFO empty interrupt. (Always use the half-empty
12986 + * level to ensure that new requests are loaded as
12987 + * soon as possible.)
12989 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
12992 + * Disable the Tx FIFO empty interrupt since there are
12993 + * no more transactions that need to be queued right
12994 + * now. This function is called from interrupt
12995 + * handlers to queue more transactions as transfer
12998 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
13004 + * Processes periodic channels for the next frame and queues transactions for
13005 + * these channels to the DWC_otg controller. After queueing transactions, the
13006 + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
13007 + * to queue as Periodic Tx FIFO or request queue space becomes available.
13008 + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
13010 +static void process_periodic_channels(dwc_otg_hcd_t *hcd)
13012 + hptxsts_data_t tx_status;
13013 + struct list_head *qh_ptr;
13014 + dwc_otg_qh_t *qh;
13016 + int no_queue_space = 0;
13017 + int no_fifo_space = 0;
13019 + dwc_otg_host_global_regs_t *host_regs;
13020 + host_regs = hcd->core_if->host_if->host_global_regs;
13022 + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
13024 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
13025 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (before queue): %d\n",
13026 + tx_status.b.ptxqspcavail);
13027 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
13028 + tx_status.b.ptxfspcavail);
13031 + qh_ptr = hcd->periodic_sched_assigned.next;
13032 + while (qh_ptr != &hcd->periodic_sched_assigned) {
13033 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
13034 + if (tx_status.b.ptxqspcavail == 0) {
13035 + no_queue_space = 1;
13039 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
13042 + * Set a flag if we're queuing high-bandwidth in slave mode.
13043 + * The flag prevents any halts to get into the request queue in
13044 + * the middle of multiple high-bandwidth packets getting queued.
13046 + if (!hcd->core_if->dma_enable &&
13047 + qh->channel->multi_count > 1)
13049 + hcd->core_if->queuing_high_bandwidth = 1;
13052 + status = queue_transaction(hcd, qh->channel, tx_status.b.ptxfspcavail);
13053 + if (status < 0) {
13054 + no_fifo_space = 1;
13059 + * In Slave mode, stay on the current transfer until there is
13060 + * nothing more to do or the high-bandwidth request count is
13061 + * reached. In DMA mode, only need to queue one request. The
13062 + * controller automatically handles multiple packets for
13063 + * high-bandwidth transfers.
13065 + if (hcd->core_if->dma_enable || status == 0 ||
13066 + qh->channel->requests == qh->channel->multi_count) {
13067 + qh_ptr = qh_ptr->next;
13069 + * Move the QH from the periodic assigned schedule to
13070 + * the periodic queued schedule.
13072 + list_move(&qh->qh_list_entry, &hcd->periodic_sched_queued);
13074 + /* done queuing high bandwidth */
13075 + hcd->core_if->queuing_high_bandwidth = 0;
13079 + if (!hcd->core_if->dma_enable) {
13080 + dwc_otg_core_global_regs_t *global_regs;
13081 + gintmsk_data_t intr_mask = {.d32 = 0};
13083 + global_regs = hcd->core_if->core_global_regs;
13084 + intr_mask.b.ptxfempty = 1;
13086 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
13087 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (after queue): %d\n",
13088 + tx_status.b.ptxqspcavail);
13089 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (after queue): %d\n",
13090 + tx_status.b.ptxfspcavail);
13092 + if (!list_empty(&hcd->periodic_sched_assigned) ||
13093 + no_queue_space || no_fifo_space) {
13095 + * May need to queue more transactions as the request
13096 + * queue or Tx FIFO empties. Enable the periodic Tx
13097 + * FIFO empty interrupt. (Always use the half-empty
13098 + * level to ensure that new requests are loaded as
13099 + * soon as possible.)
13101 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
13104 + * Disable the Tx FIFO empty interrupt since there are
13105 + * no more transactions that need to be queued right
13106 + * now. This function is called from interrupt
13107 + * handlers to queue more transactions as transfer
13110 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
13116 + * This function processes the currently active host channels and queues
13117 + * transactions for these channels to the DWC_otg controller. It is called
13118 + * from HCD interrupt handler functions.
13120 + * @param hcd The HCD state structure.
13121 + * @param tr_type The type(s) of transactions to queue (non-periodic,
13122 + * periodic, or both).
13124 +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *hcd,
13125 + dwc_otg_transaction_type_e tr_type)
13128 + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
13130 + /* Process host channels associated with periodic transfers. */
13131 + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
13132 + tr_type == DWC_OTG_TRANSACTION_ALL) &&
13133 + !list_empty(&hcd->periodic_sched_assigned)) {
13135 + process_periodic_channels(hcd);
13138 + /* Process host channels associated with non-periodic transfers. */
13139 + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
13140 + tr_type == DWC_OTG_TRANSACTION_ALL) {
13141 + if (!list_empty(&hcd->non_periodic_sched_active)) {
13142 + process_non_periodic_channels(hcd);
13145 + * Ensure NP Tx FIFO empty interrupt is disabled when
13146 + * there are no non-periodic transfers to process.
13148 + gintmsk_data_t gintmsk = {.d32 = 0};
13149 + gintmsk.b.nptxfempty = 1;
13150 + dwc_modify_reg32(&hcd->core_if->core_global_regs->gintmsk,
13157 + * Sets the final status of an URB and returns it to the device driver. Any
13158 + * required cleanup of the URB is performed.
13160 +void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *hcd, struct urb *urb, int status)
13163 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
13164 + DWC_PRINT("%s: urb %p, device %d, ep %d %s, status=%d\n",
13165 + __func__, urb, usb_pipedevice(urb->pipe),
13166 + usb_pipeendpoint(urb->pipe),
13167 + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
13168 + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
13170 + for (i = 0; i < urb->number_of_packets; i++) {
13171 + DWC_PRINT(" ISO Desc %d status: %d\n",
13172 + i, urb->iso_frame_desc[i].status);
13178 + //if we use the aligned buffer instead of the original unaligned buffer,
13179 + //for IN data, we have to move the data to the original buffer
13180 + if((urb->transfer_dma==urb->aligned_transfer_dma)&&((urb->transfer_flags & URB_DIR_MASK)==URB_DIR_IN)){
13181 + dma_sync_single_for_device(NULL,urb->transfer_dma,urb->actual_length,DMA_FROM_DEVICE);
13182 + memcpy(urb->transfer_buffer,urb->aligned_transfer_buffer,urb->actual_length);
13186 + urb->status = status;
13187 + urb->hcpriv = NULL;
13188 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
13189 + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, status);
13191 + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, NULL);
13196 + * Returns the Queue Head for an URB.
13198 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *urb)
13200 + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
13201 + return (dwc_otg_qh_t *)ep->hcpriv;
13205 +void dwc_print_setup_data(uint8_t *setup)
13208 + if (CHK_DEBUG_LEVEL(DBG_HCD)){
13209 + DWC_PRINT("Setup Data = MSB ");
13210 + for (i = 7; i >= 0; i--) DWC_PRINT("%02x ", setup[i]);
13212 + DWC_PRINT(" bmRequestType Tranfer = %s\n", (setup[0] & 0x80) ? "Device-to-Host" : "Host-to-Device");
13213 + DWC_PRINT(" bmRequestType Type = ");
13214 + switch ((setup[0] & 0x60) >> 5) {
13215 + case 0: DWC_PRINT("Standard\n"); break;
13216 + case 1: DWC_PRINT("Class\n"); break;
13217 + case 2: DWC_PRINT("Vendor\n"); break;
13218 + case 3: DWC_PRINT("Reserved\n"); break;
13220 + DWC_PRINT(" bmRequestType Recipient = ");
13221 + switch (setup[0] & 0x1f) {
13222 + case 0: DWC_PRINT("Device\n"); break;
13223 + case 1: DWC_PRINT("Interface\n"); break;
13224 + case 2: DWC_PRINT("Endpoint\n"); break;
13225 + case 3: DWC_PRINT("Other\n"); break;
13226 + default: DWC_PRINT("Reserved\n"); break;
13228 + DWC_PRINT(" bRequest = 0x%0x\n", setup[1]);
13229 + DWC_PRINT(" wValue = 0x%0x\n", *((uint16_t *)&setup[2]));
13230 + DWC_PRINT(" wIndex = 0x%0x\n", *((uint16_t *)&setup[4]));
13231 + DWC_PRINT(" wLength = 0x%0x\n\n", *((uint16_t *)&setup[6]));
13236 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *hcd) {
13237 +#if defined(DEBUG) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
13238 + DWC_PRINT("Frame remaining at SOF:\n");
13239 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13240 + hcd->frrem_samples, hcd->frrem_accum,
13241 + (hcd->frrem_samples > 0) ?
13242 + hcd->frrem_accum/hcd->frrem_samples : 0);
13245 + DWC_PRINT("Frame remaining at start_transfer (uframe 7):\n");
13246 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13247 + hcd->core_if->hfnum_7_samples, hcd->core_if->hfnum_7_frrem_accum,
13248 + (hcd->core_if->hfnum_7_samples > 0) ?
13249 + hcd->core_if->hfnum_7_frrem_accum/hcd->core_if->hfnum_7_samples : 0);
13250 + DWC_PRINT("Frame remaining at start_transfer (uframe 0):\n");
13251 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13252 + hcd->core_if->hfnum_0_samples, hcd->core_if->hfnum_0_frrem_accum,
13253 + (hcd->core_if->hfnum_0_samples > 0) ?
13254 + hcd->core_if->hfnum_0_frrem_accum/hcd->core_if->hfnum_0_samples : 0);
13255 + DWC_PRINT("Frame remaining at start_transfer (uframe 1-6):\n");
13256 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13257 + hcd->core_if->hfnum_other_samples, hcd->core_if->hfnum_other_frrem_accum,
13258 + (hcd->core_if->hfnum_other_samples > 0) ?
13259 + hcd->core_if->hfnum_other_frrem_accum/hcd->core_if->hfnum_other_samples : 0);
13262 + DWC_PRINT("Frame remaining at sample point A (uframe 7):\n");
13263 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13264 + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
13265 + (hcd->hfnum_7_samples_a > 0) ?
13266 + hcd->hfnum_7_frrem_accum_a/hcd->hfnum_7_samples_a : 0);
13267 + DWC_PRINT("Frame remaining at sample point A (uframe 0):\n");
13268 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13269 + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
13270 + (hcd->hfnum_0_samples_a > 0) ?
13271 + hcd->hfnum_0_frrem_accum_a/hcd->hfnum_0_samples_a : 0);
13272 + DWC_PRINT("Frame remaining at sample point A (uframe 1-6):\n");
13273 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13274 + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
13275 + (hcd->hfnum_other_samples_a > 0) ?
13276 + hcd->hfnum_other_frrem_accum_a/hcd->hfnum_other_samples_a : 0);
13279 + DWC_PRINT("Frame remaining at sample point B (uframe 7):\n");
13280 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13281 + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
13282 + (hcd->hfnum_7_samples_b > 0) ?
13283 + hcd->hfnum_7_frrem_accum_b/hcd->hfnum_7_samples_b : 0);
13284 + DWC_PRINT("Frame remaining at sample point B (uframe 0):\n");
13285 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13286 + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
13287 + (hcd->hfnum_0_samples_b > 0) ?
13288 + hcd->hfnum_0_frrem_accum_b/hcd->hfnum_0_samples_b : 0);
13289 + DWC_PRINT("Frame remaining at sample point B (uframe 1-6):\n");
13290 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
13291 + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
13292 + (hcd->hfnum_other_samples_b > 0) ?
13293 + hcd->hfnum_other_frrem_accum_b/hcd->hfnum_other_samples_b : 0);
13297 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *hcd)
13300 + int num_channels;
13302 + gnptxsts_data_t np_tx_status;
13303 + hptxsts_data_t p_tx_status;
13305 + num_channels = hcd->core_if->core_params->host_channels;
13307 + DWC_PRINT("************************************************************\n");
13308 + DWC_PRINT("HCD State:\n");
13309 + DWC_PRINT(" Num channels: %d\n", num_channels);
13310 + for (i = 0; i < num_channels; i++) {
13311 + dwc_hc_t *hc = hcd->hc_ptr_array[i];
13312 + DWC_PRINT(" Channel %d:\n", i);
13313 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
13314 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
13315 + DWC_PRINT(" speed: %d\n", hc->speed);
13316 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
13317 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
13318 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
13319 + DWC_PRINT(" multi_count: %d\n", hc->multi_count);
13320 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
13321 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
13322 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
13323 + DWC_PRINT(" xfer_count: %d\n", hc->xfer_count);
13324 + DWC_PRINT(" halt_on_queue: %d\n", hc->halt_on_queue);
13325 + DWC_PRINT(" halt_pending: %d\n", hc->halt_pending);
13326 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
13327 + DWC_PRINT(" do_split: %d\n", hc->do_split);
13328 + DWC_PRINT(" complete_split: %d\n", hc->complete_split);
13329 + DWC_PRINT(" hub_addr: %d\n", hc->hub_addr);
13330 + DWC_PRINT(" port_addr: %d\n", hc->port_addr);
13331 + DWC_PRINT(" xact_pos: %d\n", hc->xact_pos);
13332 + DWC_PRINT(" requests: %d\n", hc->requests);
13333 + DWC_PRINT(" qh: %p\n", hc->qh);
13334 + if (hc->xfer_started) {
13335 + hfnum_data_t hfnum;
13336 + hcchar_data_t hcchar;
13337 + hctsiz_data_t hctsiz;
13338 + hcint_data_t hcint;
13339 + hcintmsk_data_t hcintmsk;
13340 + hfnum.d32 = dwc_read_reg32(&hcd->core_if->host_if->host_global_regs->hfnum);
13341 + hcchar.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hcchar);
13342 + hctsiz.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hctsiz);
13343 + hcint.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hcint);
13344 + hcintmsk.d32 = dwc_read_reg32(&hcd->core_if->host_if->hc_regs[i]->hcintmsk);
13345 + DWC_PRINT(" hfnum: 0x%08x\n", hfnum.d32);
13346 + DWC_PRINT(" hcchar: 0x%08x\n", hcchar.d32);
13347 + DWC_PRINT(" hctsiz: 0x%08x\n", hctsiz.d32);
13348 + DWC_PRINT(" hcint: 0x%08x\n", hcint.d32);
13349 + DWC_PRINT(" hcintmsk: 0x%08x\n", hcintmsk.d32);
13351 + if (hc->xfer_started && hc->qh && hc->qh->qtd_in_process) {
13352 + dwc_otg_qtd_t *qtd;
13354 + qtd = hc->qh->qtd_in_process;
13356 + DWC_PRINT(" URB Info:\n");
13357 + DWC_PRINT(" qtd: %p, urb: %p\n", qtd, urb);
13359 + DWC_PRINT(" Dev: %d, EP: %d %s\n",
13360 + usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe),
13361 + usb_pipein(urb->pipe) ? "IN" : "OUT");
13362 + DWC_PRINT(" Max packet size: %d\n",
13363 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
13364 + DWC_PRINT(" transfer_buffer: %p\n", urb->transfer_buffer);
13365 + DWC_PRINT(" transfer_dma: %p\n", (void *)urb->transfer_dma);
13366 + DWC_PRINT(" transfer_buffer_length: %d\n", urb->transfer_buffer_length);
13367 + DWC_PRINT(" actual_length: %d\n", urb->actual_length);
13371 + DWC_PRINT(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
13372 + DWC_PRINT(" periodic_channels: %d\n", hcd->periodic_channels);
13373 + DWC_PRINT(" periodic_usecs: %d\n", hcd->periodic_usecs);
13374 + np_tx_status.d32 = dwc_read_reg32(&hcd->core_if->core_global_regs->gnptxsts);
13375 + DWC_PRINT(" NP Tx Req Queue Space Avail: %d\n", np_tx_status.b.nptxqspcavail);
13376 + DWC_PRINT(" NP Tx FIFO Space Avail: %d\n", np_tx_status.b.nptxfspcavail);
13377 + p_tx_status.d32 = dwc_read_reg32(&hcd->core_if->host_if->host_global_regs->hptxsts);
13378 + DWC_PRINT(" P Tx Req Queue Space Avail: %d\n", p_tx_status.b.ptxqspcavail);
13379 + DWC_PRINT(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
13380 + dwc_otg_hcd_dump_frrem(hcd);
13381 + dwc_otg_dump_global_registers(hcd->core_if);
13382 + dwc_otg_dump_host_registers(hcd->core_if);
13383 + DWC_PRINT("************************************************************\n");
13387 +#endif /* DWC_DEVICE_ONLY */
13389 +++ b/drivers/usb/host/otg/dwc_otg_hcd.h
13391 +/* ==========================================================================
13392 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
13393 + * $Revision: #45 $
13394 + * $Date: 2008/07/15 $
13395 + * $Change: 1064918 $
13397 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13398 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13399 + * otherwise expressly agreed to in writing between Synopsys and you.
13401 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13402 + * any End User Software License Agreement or Agreement for Licensed Product
13403 + * with Synopsys or any supplement thereto. You are permitted to use and
13404 + * redistribute this Software in source and binary forms, with or without
13405 + * modification, provided that redistributions of source code must retain this
13406 + * notice. You may not view, use, disclose, copy or distribute this file or
13407 + * any information contained herein except pursuant to this license grant from
13408 + * Synopsys. If you do not agree with this notice, including the disclaimer
13409 + * below, then you are not authorized to use the Software.
13411 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13412 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13413 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13414 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13415 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13416 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13417 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13418 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13419 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13420 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13422 + * ========================================================================== */
13423 +#ifndef DWC_DEVICE_ONLY
13424 +#ifndef __DWC_HCD_H__
13425 +#define __DWC_HCD_H__
13427 +#include <linux/list.h>
13428 +#include <linux/usb.h>
13429 +#include <../drivers/usb/core/hcd.h>
13432 +struct dwc_otg_device;
13434 +#include "dwc_otg_cil.h"
13439 + * This file contains the structures, constants, and interfaces for
13440 + * the Host Contoller Driver (HCD).
13442 + * The Host Controller Driver (HCD) is responsible for translating requests
13443 + * from the USB Driver into the appropriate actions on the DWC_otg controller.
13444 + * It isolates the USBD from the specifics of the controller by providing an
13445 + * API to the USBD.
13449 + * Phases for control transfers.
13451 +typedef enum dwc_otg_control_phase {
13452 + DWC_OTG_CONTROL_SETUP,
13453 + DWC_OTG_CONTROL_DATA,
13454 + DWC_OTG_CONTROL_STATUS
13455 +} dwc_otg_control_phase_e;
13457 +/** Transaction types. */
13458 +typedef enum dwc_otg_transaction_type {
13459 + DWC_OTG_TRANSACTION_NONE,
13460 + DWC_OTG_TRANSACTION_PERIODIC,
13461 + DWC_OTG_TRANSACTION_NON_PERIODIC,
13462 + DWC_OTG_TRANSACTION_ALL
13463 +} dwc_otg_transaction_type_e;
13466 + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
13467 + * interrupt, or isochronous transfer. A single QTD is created for each URB
13468 + * (of one of these types) submitted to the HCD. The transfer associated with
13469 + * a QTD may require one or multiple transactions.
13471 + * A QTD is linked to a Queue Head, which is entered in either the
13472 + * non-periodic or periodic schedule for execution. When a QTD is chosen for
13473 + * execution, some or all of its transactions may be executed. After
13474 + * execution, the state of the QTD is updated. The QTD may be retired if all
13475 + * its transactions are complete or if an error occurred. Otherwise, it
13476 + * remains in the schedule so more transactions can be executed later.
13478 +typedef struct dwc_otg_qtd {
13480 + * Determines the PID of the next data packet for the data phase of
13481 + * control transfers. Ignored for other transfer types.<br>
13482 + * One of the following values:
13483 + * - DWC_OTG_HC_PID_DATA0
13484 + * - DWC_OTG_HC_PID_DATA1
13486 + uint8_t data_toggle;
13488 + /** Current phase for control transfers (Setup, Data, or Status). */
13489 + dwc_otg_control_phase_e control_phase;
13491 + /** Keep track of the current split type
13492 + * for FS/LS endpoints on a HS Hub */
13493 + uint8_t complete_split;
13495 + /** How many bytes transferred during SSPLIT OUT */
13496 + uint32_t ssplit_out_xfer_count;
13499 + * Holds the number of bus errors that have occurred for a transaction
13500 + * within this transfer.
13502 + uint8_t error_count;
13505 + * Index of the next frame descriptor for an isochronous transfer. A
13506 + * frame descriptor describes the buffer position and length of the
13507 + * data to be transferred in the next scheduled (micro)frame of an
13508 + * isochronous transfer. It also holds status for that transaction.
13509 + * The frame index starts at 0.
13511 + int isoc_frame_index;
13513 + /** Position of the ISOC split on full/low speed */
13514 + uint8_t isoc_split_pos;
13516 + /** Position of the ISOC split in the buffer for the current frame */
13517 + uint16_t isoc_split_offset;
13519 + /** URB for this transfer */
13522 + /** This list of QTDs */
13523 + struct list_head qtd_list_entry;
13528 + * A Queue Head (QH) holds the static characteristics of an endpoint and
13529 + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
13530 + * be entered in either the non-periodic or periodic schedule.
13532 +typedef struct dwc_otg_qh {
13535 + * One of the following values:
13536 + * - USB_ENDPOINT_XFER_CONTROL
13537 + * - USB_ENDPOINT_XFER_ISOC
13538 + * - USB_ENDPOINT_XFER_BULK
13539 + * - USB_ENDPOINT_XFER_INT
13542 + uint8_t ep_is_in;
13544 + /** wMaxPacketSize Field of Endpoint Descriptor. */
13548 + * Determines the PID of the next data packet for non-control
13549 + * transfers. Ignored for control transfers.<br>
13550 + * One of the following values:
13551 + * - DWC_OTG_HC_PID_DATA0
13552 + * - DWC_OTG_HC_PID_DATA1
13554 + uint8_t data_toggle;
13556 + /** Ping state if 1. */
13557 + uint8_t ping_state;
13560 + * List of QTDs for this QH.
13562 + struct list_head qtd_list;
13564 + /** Host channel currently processing transfers for this QH. */
13565 + dwc_hc_t *channel;
13567 + /** QTD currently assigned to a host channel for this QH. */
13568 + dwc_otg_qtd_t *qtd_in_process;
13570 + /** Full/low speed endpoint on high-speed hub requires split. */
13571 + uint8_t do_split;
13573 + /** @name Periodic schedule information */
13576 + /** Bandwidth in microseconds per (micro)frame. */
13579 + /** Interval between transfers in (micro)frames. */
13580 + uint16_t interval;
13583 + * (micro)frame to initialize a periodic transfer. The transfer
13584 + * executes in the following (micro)frame.
13586 + uint16_t sched_frame;
13588 + /** (micro)frame at which last start split was initialized. */
13589 + uint16_t start_split_frame;
13593 + /** Entry for QH in either the periodic or non-periodic schedule. */
13594 + struct list_head qh_list_entry;
13598 + * This structure holds the state of the HCD, including the non-periodic and
13599 + * periodic schedules.
13601 +typedef struct dwc_otg_hcd {
13602 + /** The DWC otg device pointer */
13603 + struct dwc_otg_device *otg_dev;
13605 + /** DWC OTG Core Interface Layer */
13606 + dwc_otg_core_if_t *core_if;
13608 + /** Internal DWC HCD Flags */
13609 + volatile union dwc_otg_hcd_internal_flags {
13612 + unsigned port_connect_status_change : 1;
13613 + unsigned port_connect_status : 1;
13614 + unsigned port_reset_change : 1;
13615 + unsigned port_enable_change : 1;
13616 + unsigned port_suspend_change : 1;
13617 + unsigned port_over_current_change : 1;
13618 + unsigned reserved : 27;
13623 + * Inactive items in the non-periodic schedule. This is a list of
13624 + * Queue Heads. Transfers associated with these Queue Heads are not
13625 + * currently assigned to a host channel.
13627 + struct list_head non_periodic_sched_inactive;
13630 + * Active items in the non-periodic schedule. This is a list of
13631 + * Queue Heads. Transfers associated with these Queue Heads are
13632 + * currently assigned to a host channel.
13634 + struct list_head non_periodic_sched_active;
13637 + * Pointer to the next Queue Head to process in the active
13638 + * non-periodic schedule.
13640 + struct list_head *non_periodic_qh_ptr;
13643 + * Inactive items in the periodic schedule. This is a list of QHs for
13644 + * periodic transfers that are _not_ scheduled for the next frame.
13645 + * Each QH in the list has an interval counter that determines when it
13646 + * needs to be scheduled for execution. This scheduling mechanism
13647 + * allows only a simple calculation for periodic bandwidth used (i.e.
13648 + * must assume that all periodic transfers may need to execute in the
13649 + * same frame). However, it greatly simplifies scheduling and should
13650 + * be sufficient for the vast majority of OTG hosts, which need to
13651 + * connect to a small number of peripherals at one time.
13653 + * Items move from this list to periodic_sched_ready when the QH
13654 + * interval counter is 0 at SOF.
13656 + struct list_head periodic_sched_inactive;
13659 + * List of periodic QHs that are ready for execution in the next
13660 + * frame, but have not yet been assigned to host channels.
13662 + * Items move from this list to periodic_sched_assigned as host
13663 + * channels become available during the current frame.
13665 + struct list_head periodic_sched_ready;
13668 + * List of periodic QHs to be executed in the next frame that are
13669 + * assigned to host channels.
13671 + * Items move from this list to periodic_sched_queued as the
13672 + * transactions for the QH are queued to the DWC_otg controller.
13674 + struct list_head periodic_sched_assigned;
13677 + * List of periodic QHs that have been queued for execution.
13679 + * Items move from this list to either periodic_sched_inactive or
13680 + * periodic_sched_ready when the channel associated with the transfer
13681 + * is released. If the interval for the QH is 1, the item moves to
13682 + * periodic_sched_ready because it must be rescheduled for the next
13683 + * frame. Otherwise, the item moves to periodic_sched_inactive.
13685 + struct list_head periodic_sched_queued;
13688 + * Total bandwidth claimed so far for periodic transfers. This value
13689 + * is in microseconds per (micro)frame. The assumption is that all
13690 + * periodic transfers may occur in the same (micro)frame.
13692 + uint16_t periodic_usecs;
13695 + * Frame number read from the core at SOF. The value ranges from 0 to
13696 + * DWC_HFNUM_MAX_FRNUM.
13698 + uint16_t frame_number;
13701 + * Free host channels in the controller. This is a list of
13702 + * dwc_hc_t items.
13704 + struct list_head free_hc_list;
13707 + * Number of host channels assigned to periodic transfers. Currently
13708 + * assuming that there is a dedicated host channel for each periodic
13709 + * transaction and at least one host channel available for
13710 + * non-periodic transactions.
13712 + int periodic_channels;
13715 + * Number of host channels assigned to non-periodic transfers.
13717 + int non_periodic_channels;
13720 + * Array of pointers to the host channel descriptors. Allows accessing
13721 + * a host channel descriptor given the host channel number. This is
13722 + * useful in interrupt handlers.
13724 + dwc_hc_t *hc_ptr_array[MAX_EPS_CHANNELS];
13727 + * Buffer to use for any data received during the status phase of a
13728 + * control transfer. Normally no data is transferred during the status
13729 + * phase. This buffer is used as a bit bucket.
13731 + uint8_t *status_buf;
13734 + * DMA address for status_buf.
13736 + dma_addr_t status_buf_dma;
13737 +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
13740 + * Structure to allow starting the HCD in a non-interrupt context
13741 + * during an OTG role change.
13743 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
13744 + struct work_struct start_work;
13746 + struct delayed_work start_work;
13750 + * Connection timer. An OTG host must display a message if the device
13751 + * does not connect. Started when the VBus power is turned on via
13752 + * sysfs attribute "buspower".
13754 + struct timer_list conn_timer;
13756 + /* Tasket to do a reset */
13757 + struct tasklet_struct *reset_tasklet;
13763 + uint32_t frrem_samples;
13764 + uint64_t frrem_accum;
13766 + uint32_t hfnum_7_samples_a;
13767 + uint64_t hfnum_7_frrem_accum_a;
13768 + uint32_t hfnum_0_samples_a;
13769 + uint64_t hfnum_0_frrem_accum_a;
13770 + uint32_t hfnum_other_samples_a;
13771 + uint64_t hfnum_other_frrem_accum_a;
13773 + uint32_t hfnum_7_samples_b;
13774 + uint64_t hfnum_7_frrem_accum_b;
13775 + uint32_t hfnum_0_samples_b;
13776 + uint64_t hfnum_0_frrem_accum_b;
13777 + uint32_t hfnum_other_samples_b;
13778 + uint64_t hfnum_other_frrem_accum_b;
13782 +/** Gets the dwc_otg_hcd from a struct usb_hcd */
13783 +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
13785 + return (dwc_otg_hcd_t *)(hcd->hcd_priv);
13788 +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
13789 +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t *dwc_otg_hcd)
13791 + return container_of((void *)dwc_otg_hcd, struct usb_hcd, hcd_priv);
13794 +/** @name HCD Create/Destroy Functions */
13796 +extern int dwc_otg_hcd_init(struct lm_device *lmdev);
13797 +extern void dwc_otg_hcd_remove(struct lm_device *lmdev);
13800 +/** @name Linux HC Driver API Functions */
13803 +extern int dwc_otg_hcd_start(struct usb_hcd *hcd);
13804 +extern void dwc_otg_hcd_stop(struct usb_hcd *hcd);
13805 +extern int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd);
13806 +extern void dwc_otg_hcd_free(struct usb_hcd *hcd);
13807 +extern int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
13808 + // struct usb_host_endpoint *ep,
13810 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
13816 +extern int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
13817 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
13818 + struct usb_host_endpoint *ep,
13820 + struct urb *urb, int status);
13821 +extern void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
13822 + struct usb_host_endpoint *ep);
13823 +extern irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd
13824 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
13825 + , struct pt_regs *regs
13828 +extern int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd,
13830 +extern int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
13839 +/** @name Transaction Execution Functions */
13841 +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *hcd);
13842 +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *hcd,
13843 + dwc_otg_transaction_type_e tr_type);
13844 +extern void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *_hcd, struct urb *urb,
13848 +/** @name Interrupt Handler Functions */
13850 +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13851 +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13852 +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13853 +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13854 +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13855 +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13856 +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13857 +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13858 +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13859 +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13860 +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t *dwc_otg_hcd, uint32_t num);
13861 +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13862 +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *dwc_otg_hcd);
13866 +/** @name Schedule Queue Functions */
13869 +/* Implemented in dwc_otg_hcd_queue.c */
13870 +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t *hcd, struct urb *urb);
13871 +extern void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, struct urb *urb);
13872 +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
13873 +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
13874 +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
13875 +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, int sched_csplit);
13877 +/** Remove and free a QH */
13878 +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t *hcd,
13879 + dwc_otg_qh_t *qh)
13881 + dwc_otg_hcd_qh_remove(hcd, qh);
13882 + dwc_otg_hcd_qh_free(hcd, qh);
13885 +/** Allocates memory for a QH structure.
13886 + * @return Returns the memory allocate or NULL on error. */
13887 +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(void)
13889 + return (dwc_otg_qh_t *) kmalloc(sizeof(dwc_otg_qh_t), GFP_KERNEL);
13892 +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(struct urb *urb);
13893 +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t *qtd, struct urb *urb);
13894 +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t *qtd, dwc_otg_hcd_t *dwc_otg_hcd);
13896 +/** Allocates memory for a QTD structure.
13897 + * @return Returns the memory allocate or NULL on error. */
13898 +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(void)
13900 + return (dwc_otg_qtd_t *) kmalloc(sizeof(dwc_otg_qtd_t), GFP_KERNEL);
13903 +/** Frees the memory for a QTD structure. QTD should already be removed from
13905 + * @param[in] qtd QTD to free.*/
13906 +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t *qtd)
13911 +/** Removes a QTD from list.
13912 + * @param[in] hcd HCD instance.
13913 + * @param[in] qtd QTD to remove from list. */
13914 +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t *hcd, dwc_otg_qtd_t *qtd)
13916 + unsigned long flags;
13917 + SPIN_LOCK_IRQSAVE(&hcd->lock, flags);
13918 + list_del(&qtd->qtd_list_entry);
13919 + SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags);
13922 +/** Remove and free a QTD */
13923 +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t *hcd, dwc_otg_qtd_t *qtd)
13925 + dwc_otg_hcd_qtd_remove(hcd, qtd);
13926 + dwc_otg_hcd_qtd_free(qtd);
13932 +/** @name Internal Functions */
13934 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *urb);
13935 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *hcd);
13936 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *hcd);
13939 +/** Gets the usb_host_endpoint associated with an URB. */
13940 +static inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
13942 + struct usb_device *dev = urb->dev;
13943 + int ep_num = usb_pipeendpoint(urb->pipe);
13945 + if (usb_pipein(urb->pipe))
13946 + return dev->ep_in[ep_num];
13948 + return dev->ep_out[ep_num];
13952 + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
13953 + * qualified with its direction (possible 32 endpoints per device).
13955 +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
13956 + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
13958 +/** Gets the QH that contains the list_head */
13959 +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
13961 +/** Gets the QTD that contains the list_head */
13962 +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
13964 +/** Check if QH is non-periodic */
13965 +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == USB_ENDPOINT_XFER_BULK) || \
13966 + (_qh_ptr_->ep_type == USB_ENDPOINT_XFER_CONTROL))
13968 +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
13969 +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
13971 +/** Packet size for any kind of endpoint descriptor */
13972 +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
13975 + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
13976 + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
13977 + * frame number when the max frame number is reached.
13979 +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
13981 + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
13982 + (DWC_HFNUM_MAX_FRNUM >> 1);
13986 + * Returns true if _frame1 is greater than _frame2. The comparison is done
13987 + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
13988 + * number when the max frame number is reached.
13990 +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
13992 + return (frame1 != frame2) &&
13993 + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
13994 + (DWC_HFNUM_MAX_FRNUM >> 1));
13998 + * Increments _frame by the amount specified by _inc. The addition is done
13999 + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
14001 +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
14003 + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
14006 +static inline uint16_t dwc_full_frame_num(uint16_t frame)
14008 + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
14011 +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
14013 + return frame & 0x7;
14018 + * Macro to sample the remaining PHY clocks left in the current frame. This
14019 + * may be used during debugging to determine the average time it takes to
14020 + * execute sections of code. There are two possible sample points, "a" and
14021 + * "b", so the _letter argument must be one of these values.
14023 + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
14024 + * example, "cat /sys/devices/lm0/hcd_frrem".
14026 +#define dwc_sample_frrem(_hcd, _qh, _letter) \
14028 + hfnum_data_t hfnum; \
14029 + dwc_otg_qtd_t *qtd; \
14030 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
14031 + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
14032 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
14033 + switch (hfnum.b.frnum & 0x7) { \
14035 + _hcd->hfnum_7_samples_##_letter++; \
14036 + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
14039 + _hcd->hfnum_0_samples_##_letter++; \
14040 + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
14043 + _hcd->hfnum_other_samples_##_letter++; \
14044 + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
14050 +#define dwc_sample_frrem(_hcd, _qh, _letter)
14053 +#endif /* DWC_DEVICE_ONLY */
14055 +++ b/drivers/usb/host/otg/dwc_otg_hcd_intr.c
14057 +/* ==========================================================================
14058 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
14059 + * $Revision: #70 $
14060 + * $Date: 2008/10/16 $
14061 + * $Change: 1117667 $
14063 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
14064 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
14065 + * otherwise expressly agreed to in writing between Synopsys and you.
14067 + * The Software IS NOT an item of Licensed Software or Licensed Product under
14068 + * any End User Software License Agreement or Agreement for Licensed Product
14069 + * with Synopsys or any supplement thereto. You are permitted to use and
14070 + * redistribute this Software in source and binary forms, with or without
14071 + * modification, provided that redistributions of source code must retain this
14072 + * notice. You may not view, use, disclose, copy or distribute this file or
14073 + * any information contained herein except pursuant to this license grant from
14074 + * Synopsys. If you do not agree with this notice, including the disclaimer
14075 + * below, then you are not authorized to use the Software.
14077 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
14078 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14079 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
14080 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
14081 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
14082 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14083 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
14084 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14085 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
14086 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
14088 + * ========================================================================== */
14089 +#ifndef DWC_DEVICE_ONLY
14091 +#include <linux/version.h>
14093 +#include "dwc_otg_driver.h"
14094 +#include "dwc_otg_hcd.h"
14095 +#include "dwc_otg_regs.h"
14098 + * This file contains the implementation of the HCD Interrupt handlers.
14101 +/** This function handles interrupts for the HCD. */
14102 +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t *dwc_otg_hcd)
14106 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
14107 + gintsts_data_t gintsts;
14109 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
14112 + /* Check if HOST Mode */
14113 + if (dwc_otg_is_host_mode(core_if)) {
14114 + gintsts.d32 = dwc_otg_read_core_intr(core_if);
14115 + if (!gintsts.d32) {
14120 + /* Don't print debug message in the interrupt handler on SOF */
14121 +# ifndef DEBUG_SOF
14122 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
14124 + DWC_DEBUGPL(DBG_HCD, "\n");
14128 +# ifndef DEBUG_SOF
14129 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
14131 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n", gintsts.d32);
14133 + if (gintsts.b.usbreset) {
14134 + DWC_PRINT("Usb Reset In Host Mode\n");
14138 + if (gintsts.b.sofintr) {
14139 + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
14141 + if (gintsts.b.rxstsqlvl) {
14142 + retval |= dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd);
14144 + if (gintsts.b.nptxfempty) {
14145 + retval |= dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd);
14147 + if (gintsts.b.i2cintr) {
14148 + /** @todo Implement i2cintr handler. */
14150 + if (gintsts.b.portintr) {
14151 + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
14153 + if (gintsts.b.hcintr) {
14154 + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
14156 + if (gintsts.b.ptxfempty) {
14157 + retval |= dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd);
14160 +# ifndef DEBUG_SOF
14161 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
14164 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Finished Servicing Interrupts\n");
14165 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
14166 + dwc_read_reg32(&global_regs->gintsts));
14167 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
14168 + dwc_read_reg32(&global_regs->gintmsk));
14173 +# ifndef DEBUG_SOF
14174 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
14176 + DWC_DEBUGPL(DBG_HCD, "\n");
14181 + S3C2410X_CLEAR_EINTPEND();
14186 +#ifdef DWC_TRACK_MISSED_SOFS
14187 +#warning Compiling code to track missed SOFs
14188 +#define FRAME_NUM_ARRAY_SIZE 1000
14190 + * This function is for debug only.
14192 +static inline void track_missed_sofs(uint16_t curr_frame_number)
14194 + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
14195 + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
14196 + static int frame_num_idx = 0;
14197 + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
14198 + static int dumped_frame_num_array = 0;
14200 + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
14201 + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) != curr_frame_number) {
14202 + frame_num_array[frame_num_idx] = curr_frame_number;
14203 + last_frame_num_array[frame_num_idx++] = last_frame_num;
14205 + } else if (!dumped_frame_num_array) {
14207 + printk(KERN_EMERG USB_DWC "Frame Last Frame\n");
14208 + printk(KERN_EMERG USB_DWC "----- ----------\n");
14209 + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
14210 + printk(KERN_EMERG USB_DWC "0x%04x 0x%04x\n",
14211 + frame_num_array[i], last_frame_num_array[i]);
14213 + dumped_frame_num_array = 1;
14215 + last_frame_num = curr_frame_number;
14220 + * Handles the start-of-frame interrupt in host mode. Non-periodic
14221 + * transactions may be queued to the DWC_otg controller for the current
14222 + * (micro)frame. Periodic transactions may be queued to the controller for the
14223 + * next (micro)frame.
14225 +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t *hcd)
14227 + hfnum_data_t hfnum;
14228 + struct list_head *qh_entry;
14229 + dwc_otg_qh_t *qh;
14230 + dwc_otg_transaction_type_e tr_type;
14231 + gintsts_data_t gintsts = {.d32 = 0};
14233 + hfnum.d32 = dwc_read_reg32(&hcd->core_if->host_if->host_global_regs->hfnum);
14236 + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
14238 + hcd->frame_number = hfnum.b.frnum;
14241 + hcd->frrem_accum += hfnum.b.frrem;
14242 + hcd->frrem_samples++;
14245 +#ifdef DWC_TRACK_MISSED_SOFS
14246 + track_missed_sofs(hcd->frame_number);
14249 + /* Determine whether any periodic QHs should be executed. */
14250 + qh_entry = hcd->periodic_sched_inactive.next;
14251 + while (qh_entry != &hcd->periodic_sched_inactive) {
14252 + qh = list_entry(qh_entry, dwc_otg_qh_t, qh_list_entry);
14253 + qh_entry = qh_entry->next;
14254 + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
14256 + * Move QH to the ready list to be executed next
14259 + list_move(&qh->qh_list_entry, &hcd->periodic_sched_ready);
14263 + tr_type = dwc_otg_hcd_select_transactions(hcd);
14264 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
14265 + dwc_otg_hcd_queue_transactions(hcd, tr_type);
14268 + /* Clear interrupt */
14269 + gintsts.b.sofintr = 1;
14270 + dwc_write_reg32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
14275 +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
14276 + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
14277 + * memory if the DWC_otg controller is operating in Slave mode. */
14278 +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *dwc_otg_hcd)
14280 + host_grxsts_data_t grxsts;
14281 + dwc_hc_t *hc = NULL;
14283 + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
14285 + grxsts.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
14287 + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
14289 + /* Packet Status */
14290 + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
14291 + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
14292 + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid, hc->data_pid_start);
14293 + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
14295 + switch (grxsts.b.pktsts) {
14296 + case DWC_GRXSTS_PKTSTS_IN:
14297 + /* Read the data into the host buffer. */
14298 + if (grxsts.b.bcnt > 0) {
14299 + dwc_otg_read_packet(dwc_otg_hcd->core_if,
14303 + /* Update the HC fields for the next packet received. */
14304 + hc->xfer_count += grxsts.b.bcnt;
14305 + hc->xfer_buff += grxsts.b.bcnt;
14308 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
14309 + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
14310 + case DWC_GRXSTS_PKTSTS_CH_HALTED:
14311 + /* Handled in interrupt, just ignore data */
14314 + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n", grxsts.b.pktsts);
14321 +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
14322 + * data packets may be written to the FIFO for OUT transfers. More requests
14323 + * may be written to the non-periodic request queue for IN transfers. This
14324 + * interrupt is enabled only in Slave mode. */
14325 +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd)
14327 + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
14328 + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
14329 + DWC_OTG_TRANSACTION_NON_PERIODIC);
14333 +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
14334 + * packets may be written to the FIFO for OUT transfers. More requests may be
14335 + * written to the periodic request queue for IN transfers. This interrupt is
14336 + * enabled only in Slave mode. */
14337 +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd)
14339 + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
14340 + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
14341 + DWC_OTG_TRANSACTION_PERIODIC);
14345 +/** There are multiple conditions that can cause a port interrupt. This function
14346 + * determines which interrupt conditions have occurred and handles them
14347 + * appropriately. */
14348 +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t *dwc_otg_hcd)
14351 + hprt0_data_t hprt0;
14352 + hprt0_data_t hprt0_modify;
14354 + hprt0.d32 = dwc_read_reg32(dwc_otg_hcd->core_if->host_if->hprt0);
14355 + hprt0_modify.d32 = dwc_read_reg32(dwc_otg_hcd->core_if->host_if->hprt0);
14357 + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
14360 + hprt0_modify.b.prtena = 0;
14361 + hprt0_modify.b.prtconndet = 0;
14362 + hprt0_modify.b.prtenchng = 0;
14363 + hprt0_modify.b.prtovrcurrchng = 0;
14365 + /* Port Connect Detected
14366 + * Set flag and clear if detected */
14367 + if (hprt0.b.prtconndet) {
14368 + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
14369 + "Port Connect Detected--\n", hprt0.d32);
14370 + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
14371 + dwc_otg_hcd->flags.b.port_connect_status = 1;
14372 + hprt0_modify.b.prtconndet = 1;
14374 + /* B-Device has connected, Delete the connection timer. */
14375 + del_timer( &dwc_otg_hcd->conn_timer );
14377 + /* The Hub driver asserts a reset when it sees port connect
14378 + * status change flag */
14382 + /* Port Enable Changed
14383 + * Clear if detected - Set internal flag if disabled */
14384 + if (hprt0.b.prtenchng) {
14385 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
14386 + "Port Enable Changed--\n", hprt0.d32);
14387 + hprt0_modify.b.prtenchng = 1;
14388 + if (hprt0.b.prtena == 1) {
14389 + int do_reset = 0;
14390 + dwc_otg_core_params_t *params = dwc_otg_hcd->core_if->core_params;
14391 + dwc_otg_core_global_regs_t *global_regs = dwc_otg_hcd->core_if->core_global_regs;
14392 + dwc_otg_host_if_t *host_if = dwc_otg_hcd->core_if->host_if;
14394 + /* Check if we need to adjust the PHY clock speed for
14395 + * low power and adjust it */
14396 + if (params->host_support_fs_ls_low_power) {
14397 + gusbcfg_data_t usbcfg;
14399 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
14401 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED ||
14402 + hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
14406 + hcfg_data_t hcfg;
14407 + if (usbcfg.b.phylpwrclksel == 0) {
14408 + /* Set PHY low power clock select for FS/LS devices */
14409 + usbcfg.b.phylpwrclksel = 1;
14410 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
14414 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
14416 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED &&
14417 + params->host_ls_low_power_phy_clk ==
14418 + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ) {
14420 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
14421 + if (hcfg.b.fslspclksel != DWC_HCFG_6_MHZ) {
14422 + hcfg.b.fslspclksel = DWC_HCFG_6_MHZ;
14423 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
14429 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 48 MHz ()\n");
14430 + if (hcfg.b.fslspclksel != DWC_HCFG_48_MHZ) {
14431 + hcfg.b.fslspclksel = DWC_HCFG_48_MHZ;
14432 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
14441 + if (usbcfg.b.phylpwrclksel == 1) {
14442 + usbcfg.b.phylpwrclksel = 0;
14443 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
14449 + tasklet_schedule(dwc_otg_hcd->reset_tasklet);
14454 + /* Port has been enabled set the reset change flag */
14455 + dwc_otg_hcd->flags.b.port_reset_change = 1;
14458 + dwc_otg_hcd->flags.b.port_enable_change = 1;
14463 + /** Overcurrent Change Interrupt */
14464 + if (hprt0.b.prtovrcurrchng) {
14465 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
14466 + "Port Overcurrent Changed--\n", hprt0.d32);
14467 + dwc_otg_hcd->flags.b.port_over_current_change = 1;
14468 + hprt0_modify.b.prtovrcurrchng = 1;
14472 + /* Clear Port Interrupts */
14473 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
14478 +/** This interrupt indicates that one or more host channels has a pending
14479 + * interrupt. There are multiple conditions that can cause each host channel
14480 + * interrupt. This function determines which conditions have occurred for each
14481 + * host channel interrupt and handles them appropriately. */
14482 +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t *dwc_otg_hcd)
14486 + haint_data_t haint;
14488 + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
14491 + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
14493 + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
14494 + if (haint.b2.chint & (1 << i)) {
14495 + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
14502 +/* Macro used to clear one channel interrupt */
14503 +#define clear_hc_int(_hc_regs_, _intr_) \
14505 + hcint_data_t hcint_clear = {.d32 = 0}; \
14506 + hcint_clear.b._intr_ = 1; \
14507 + dwc_write_reg32(&(_hc_regs_)->hcint, hcint_clear.d32); \
14511 + * Macro used to disable one channel interrupt. Channel interrupts are
14512 + * disabled when the channel is halted or released by the interrupt handler.
14513 + * There is no need to handle further interrupts of that type until the
14514 + * channel is re-assigned. In fact, subsequent handling may cause crashes
14515 + * because the channel structures are cleaned up when the channel is released.
14517 +#define disable_hc_int(_hc_regs_, _intr_) \
14519 + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
14520 + hcintmsk.b._intr_ = 1; \
14521 + dwc_modify_reg32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
14525 + * Gets the actual length of a transfer after the transfer halts. _halt_status
14526 + * holds the reason for the halt.
14528 + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
14529 + * *short_read is set to 1 upon return if less than the requested
14530 + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
14531 + * return. short_read may also be NULL on entry, in which case it remains
14534 +static uint32_t get_actual_xfer_length(dwc_hc_t *hc,
14535 + dwc_otg_hc_regs_t *hc_regs,
14536 + dwc_otg_qtd_t *qtd,
14537 + dwc_otg_halt_status_e halt_status,
14540 + hctsiz_data_t hctsiz;
14543 + if (short_read != NULL) {
14546 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14548 + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
14549 + if (hc->ep_is_in) {
14550 + length = hc->xfer_len - hctsiz.b.xfersize;
14551 + if (short_read != NULL) {
14552 + *short_read = (hctsiz.b.xfersize != 0);
14554 + } else if (hc->qh->do_split) {
14555 + length = qtd->ssplit_out_xfer_count;
14557 + length = hc->xfer_len;
14561 + * Must use the hctsiz.pktcnt field to determine how much data
14562 + * has been transferred. This field reflects the number of
14563 + * packets that have been transferred via the USB. This is
14564 + * always an integral number of packets if the transfer was
14565 + * halted before its normal completion. (Can't use the
14566 + * hctsiz.xfersize field because that reflects the number of
14567 + * bytes transferred via the AHB, not the USB).
14569 + length = (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
14576 + * Updates the state of the URB after a Transfer Complete interrupt on the
14577 + * host channel. Updates the actual_length field of the URB based on the
14578 + * number of bytes transferred via the host channel. Sets the URB status
14579 + * if the data transfer is finished.
14581 + * @return 1 if the data transfer specified by the URB is completely finished,
14584 +static int update_urb_state_xfer_comp(dwc_hc_t *hc,
14585 + dwc_otg_hc_regs_t *hc_regs,
14587 + dwc_otg_qtd_t *qtd)
14589 + int xfer_done = 0;
14590 + int short_read = 0;
14592 + urb->actual_length += get_actual_xfer_length(hc, hc_regs, qtd,
14593 + DWC_OTG_HC_XFER_COMPLETE,
14596 + if (short_read || urb->actual_length == urb->transfer_buffer_length) {
14598 + if (short_read && (urb->transfer_flags & URB_SHORT_NOT_OK)) {
14599 + urb->status = -EREMOTEIO;
14607 + hctsiz_data_t hctsiz;
14608 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14609 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
14610 + __func__, (hc->ep_is_in ? "IN" : "OUT"), hc->hc_num);
14611 + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
14612 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n", hctsiz.b.xfersize);
14613 + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
14614 + urb->transfer_buffer_length);
14615 + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n", urb->actual_length);
14616 + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
14617 + short_read, xfer_done);
14621 + return xfer_done;
14625 + * Save the starting data toggle for the next transfer. The data toggle is
14626 + * saved in the QH for non-control transfers and it's saved in the QTD for
14627 + * control transfers.
14629 +static void save_data_toggle(dwc_hc_t *hc,
14630 + dwc_otg_hc_regs_t *hc_regs,
14631 + dwc_otg_qtd_t *qtd)
14633 + hctsiz_data_t hctsiz;
14634 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14636 + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
14637 + dwc_otg_qh_t *qh = hc->qh;
14638 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
14639 + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
14641 + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
14644 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
14645 + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
14647 + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
14653 + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
14654 + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
14655 + * still linked to the QH, the QH is added to the end of the inactive
14656 + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
14657 + * schedule if no more QTDs are linked to the QH.
14659 +static void deactivate_qh(dwc_otg_hcd_t *hcd,
14660 + dwc_otg_qh_t *qh,
14663 + int continue_split = 0;
14664 + dwc_otg_qtd_t *qtd;
14666 + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
14668 + qtd = list_entry(qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
14670 + if (qtd->complete_split) {
14671 + continue_split = 1;
14672 + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
14673 + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
14674 + continue_split = 1;
14678 + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd);
14679 + continue_split = 0;
14682 + qh->channel = NULL;
14683 + qh->qtd_in_process = NULL;
14684 + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
14688 + * Updates the state of an Isochronous URB when the transfer is stopped for
14689 + * any reason. The fields of the current entry in the frame descriptor array
14690 + * are set based on the transfer state and the input _halt_status. Completes
14691 + * the Isochronous URB if all the URB frames have been completed.
14693 + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
14694 + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
14696 +static dwc_otg_halt_status_e
14697 +update_isoc_urb_state(dwc_otg_hcd_t *hcd,
14699 + dwc_otg_hc_regs_t *hc_regs,
14700 + dwc_otg_qtd_t *qtd,
14701 + dwc_otg_halt_status_e halt_status)
14703 + struct urb *urb = qtd->urb;
14704 + dwc_otg_halt_status_e ret_val = halt_status;
14705 + struct usb_iso_packet_descriptor *frame_desc;
14707 + frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
14708 + switch (halt_status) {
14709 + case DWC_OTG_HC_XFER_COMPLETE:
14710 + frame_desc->status = 0;
14711 + frame_desc->actual_length =
14712 + get_actual_xfer_length(hc, hc_regs, qtd,
14713 + halt_status, NULL);
14715 + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
14716 + urb->error_count++;
14717 + if (hc->ep_is_in) {
14718 + frame_desc->status = -ENOSR;
14720 + frame_desc->status = -ECOMM;
14722 + frame_desc->actual_length = 0;
14724 + case DWC_OTG_HC_XFER_BABBLE_ERR:
14725 + urb->error_count++;
14726 + frame_desc->status = -EOVERFLOW;
14727 + /* Don't need to update actual_length in this case. */
14729 + case DWC_OTG_HC_XFER_XACT_ERR:
14730 + urb->error_count++;
14731 + frame_desc->status = -EPROTO;
14732 + frame_desc->actual_length =
14733 + get_actual_xfer_length(hc, hc_regs, qtd,
14734 + halt_status, NULL);
14736 + DWC_ERROR("%s: Unhandled _halt_status (%d)\n", __func__,
14742 + if (++qtd->isoc_frame_index == urb->number_of_packets) {
14744 + * urb->status is not used for isoc transfers.
14745 + * The individual frame_desc statuses are used instead.
14747 + dwc_otg_hcd_complete_urb(hcd, urb, 0);
14748 + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
14750 + ret_val = DWC_OTG_HC_XFER_COMPLETE;
14757 + * Releases a host channel for use by other transfers. Attempts to select and
14758 + * queue more transactions since at least one host channel is available.
14760 + * @param hcd The HCD state structure.
14761 + * @param hc The host channel to release.
14762 + * @param qtd The QTD associated with the host channel. This QTD may be freed
14763 + * if the transfer is complete or an error has occurred.
14764 + * @param halt_status Reason the channel is being released. This status
14765 + * determines the actions taken by this function.
14767 +static void release_channel(dwc_otg_hcd_t *hcd,
14769 + dwc_otg_qtd_t *qtd,
14770 + dwc_otg_halt_status_e halt_status)
14772 + dwc_otg_transaction_type_e tr_type;
14775 + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d\n",
14776 + __func__, hc->hc_num, halt_status);
14778 + switch (halt_status) {
14779 + case DWC_OTG_HC_XFER_URB_COMPLETE:
14782 + case DWC_OTG_HC_XFER_AHB_ERR:
14783 + case DWC_OTG_HC_XFER_STALL:
14784 + case DWC_OTG_HC_XFER_BABBLE_ERR:
14787 + case DWC_OTG_HC_XFER_XACT_ERR:
14788 + if (qtd->error_count >= 3) {
14789 + DWC_DEBUGPL(DBG_HCDV, " Complete URB with transaction error\n");
14791 + qtd->urb->status = -EPROTO;
14792 + dwc_otg_hcd_complete_urb(hcd, qtd->urb, -EPROTO);
14797 + case DWC_OTG_HC_XFER_URB_DEQUEUE:
14799 + * The QTD has already been removed and the QH has been
14800 + * deactivated. Don't want to do anything except release the
14801 + * host channel and try to queue more transfers.
14804 + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
14805 + DWC_ERROR("%s: No halt_status, channel %d\n", __func__, hc->hc_num);
14813 + deactivate_qh(hcd, hc->qh, free_qtd);
14817 + * Release the host channel for use by other transfers. The cleanup
14818 + * function clears the channel interrupt enables and conditions, so
14819 + * there's no need to clear the Channel Halted interrupt separately.
14821 + dwc_otg_hc_cleanup(hcd->core_if, hc);
14822 + list_add_tail(&hc->hc_list_entry, &hcd->free_hc_list);
14824 + switch (hc->ep_type) {
14825 + case DWC_OTG_EP_TYPE_CONTROL:
14826 + case DWC_OTG_EP_TYPE_BULK:
14827 + hcd->non_periodic_channels--;
14832 + * Don't release reservations for periodic channels here.
14833 + * That's done when a periodic transfer is descheduled (i.e.
14834 + * when the QH is removed from the periodic schedule).
14839 + /* Try to queue more transfers now that there's a free channel. */
14840 + tr_type = dwc_otg_hcd_select_transactions(hcd);
14841 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
14842 + dwc_otg_hcd_queue_transactions(hcd, tr_type);
14847 + * Halts a host channel. If the channel cannot be halted immediately because
14848 + * the request queue is full, this function ensures that the FIFO empty
14849 + * interrupt for the appropriate queue is enabled so that the halt request can
14850 + * be queued when there is space in the request queue.
14852 + * This function may also be called in DMA mode. In that case, the channel is
14853 + * simply released since the core always halts the channel automatically in
14856 +static void halt_channel(dwc_otg_hcd_t *hcd,
14858 + dwc_otg_qtd_t *qtd,
14859 + dwc_otg_halt_status_e halt_status)
14861 + if (hcd->core_if->dma_enable) {
14862 + release_channel(hcd, hc, qtd, halt_status);
14866 + /* Slave mode processing... */
14867 + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
14869 + if (hc->halt_on_queue) {
14870 + gintmsk_data_t gintmsk = {.d32 = 0};
14871 + dwc_otg_core_global_regs_t *global_regs;
14872 + global_regs = hcd->core_if->core_global_regs;
14874 + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
14875 + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
14877 + * Make sure the Non-periodic Tx FIFO empty interrupt
14878 + * is enabled so that the non-periodic schedule will
14881 + gintmsk.b.nptxfempty = 1;
14882 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
14885 + * Move the QH from the periodic queued schedule to
14886 + * the periodic assigned schedule. This allows the
14887 + * halt to be queued when the periodic schedule is
14890 + list_move(&hc->qh->qh_list_entry,
14891 + &hcd->periodic_sched_assigned);
14894 + * Make sure the Periodic Tx FIFO Empty interrupt is
14895 + * enabled so that the periodic schedule will be
14898 + gintmsk.b.ptxfempty = 1;
14899 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
14905 + * Performs common cleanup for non-periodic transfers after a Transfer
14906 + * Complete interrupt. This function should be called after any endpoint type
14907 + * specific handling is finished to release the host channel.
14909 +static void complete_non_periodic_xfer(dwc_otg_hcd_t *hcd,
14911 + dwc_otg_hc_regs_t *hc_regs,
14912 + dwc_otg_qtd_t *qtd,
14913 + dwc_otg_halt_status_e halt_status)
14915 + hcint_data_t hcint;
14917 + qtd->error_count = 0;
14919 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
14920 + if (hcint.b.nyet) {
14922 + * Got a NYET on the last transaction of the transfer. This
14923 + * means that the endpoint should be in the PING state at the
14924 + * beginning of the next transfer.
14926 + hc->qh->ping_state = 1;
14927 + clear_hc_int(hc_regs, nyet);
14931 + * Always halt and release the host channel to make it available for
14932 + * more transfers. There may still be more phases for a control
14933 + * transfer or more data packets for a bulk transfer at this point,
14934 + * but the host channel is still halted. A channel will be reassigned
14935 + * to the transfer when the non-periodic schedule is processed after
14936 + * the channel is released. This allows transactions to be queued
14937 + * properly via dwc_otg_hcd_queue_transactions, which also enables the
14938 + * Tx FIFO Empty interrupt if necessary.
14940 + if (hc->ep_is_in) {
14942 + * IN transfers in Slave mode require an explicit disable to
14943 + * halt the channel. (In DMA mode, this call simply releases
14946 + halt_channel(hcd, hc, qtd, halt_status);
14949 + * The channel is automatically disabled by the core for OUT
14950 + * transfers in Slave mode.
14952 + release_channel(hcd, hc, qtd, halt_status);
14957 + * Performs common cleanup for periodic transfers after a Transfer Complete
14958 + * interrupt. This function should be called after any endpoint type specific
14959 + * handling is finished to release the host channel.
14961 +static void complete_periodic_xfer(dwc_otg_hcd_t *hcd,
14963 + dwc_otg_hc_regs_t *hc_regs,
14964 + dwc_otg_qtd_t *qtd,
14965 + dwc_otg_halt_status_e halt_status)
14967 + hctsiz_data_t hctsiz;
14968 + qtd->error_count = 0;
14970 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
14971 + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
14972 + /* Core halts channel in these cases. */
14973 + release_channel(hcd, hc, qtd, halt_status);
14975 + /* Flush any outstanding requests from the Tx queue. */
14976 + halt_channel(hcd, hc, qtd, halt_status);
14981 + * Handles a host channel Transfer Complete interrupt. This handler may be
14982 + * called in either DMA mode or Slave mode.
14984 +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t *hcd,
14986 + dwc_otg_hc_regs_t *hc_regs,
14987 + dwc_otg_qtd_t *qtd)
14989 + int urb_xfer_done;
14990 + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
14991 + struct urb *urb = qtd->urb;
14992 + int pipe_type = usb_pipetype(urb->pipe);
14994 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
14995 + "Transfer Complete--\n", hc->hc_num);
14998 + * Handle xfer complete on CSPLIT.
15000 + if (hc->qh->do_split) {
15001 + qtd->complete_split = 0;
15004 + /* Update the QTD and URB states. */
15005 + switch (pipe_type) {
15006 + case PIPE_CONTROL:
15007 + switch (qtd->control_phase) {
15008 + case DWC_OTG_CONTROL_SETUP:
15009 + if (urb->transfer_buffer_length > 0) {
15010 + qtd->control_phase = DWC_OTG_CONTROL_DATA;
15012 + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
15014 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
15015 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
15017 + case DWC_OTG_CONTROL_DATA: {
15018 + urb_xfer_done = update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
15019 + if (urb_xfer_done) {
15020 + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
15021 + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
15023 + save_data_toggle(hc, hc_regs, qtd);
15025 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
15028 + case DWC_OTG_CONTROL_STATUS:
15029 + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
15030 + if (urb->status == -EINPROGRESS) {
15033 + dwc_otg_hcd_complete_urb(hcd, urb, urb->status);
15034 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
15038 + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
15041 + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
15042 + urb_xfer_done = update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
15043 + if (urb_xfer_done) {
15044 + dwc_otg_hcd_complete_urb(hcd, urb, urb->status);
15045 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
15047 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
15050 + save_data_toggle(hc, hc_regs, qtd);
15051 + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
15053 + case PIPE_INTERRUPT:
15054 + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
15055 + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
15058 + * Interrupt URB is done on the first transfer complete
15061 + dwc_otg_hcd_complete_urb(hcd, urb, urb->status);
15062 + save_data_toggle(hc, hc_regs, qtd);
15063 + complete_periodic_xfer(hcd, hc, hc_regs, qtd,
15064 + DWC_OTG_HC_XFER_URB_COMPLETE);
15066 + case PIPE_ISOCHRONOUS:
15067 + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
15068 + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
15069 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
15070 + DWC_OTG_HC_XFER_COMPLETE);
15072 + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
15076 + disable_hc_int(hc_regs, xfercompl);
15082 + * Handles a host channel STALL interrupt. This handler may be called in
15083 + * either DMA mode or Slave mode.
15085 +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t *hcd,
15087 + dwc_otg_hc_regs_t *hc_regs,
15088 + dwc_otg_qtd_t *qtd)
15090 + struct urb *urb = qtd->urb;
15091 + int pipe_type = usb_pipetype(urb->pipe);
15093 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15094 + "STALL Received--\n", hc->hc_num);
15096 + if (pipe_type == PIPE_CONTROL) {
15097 + dwc_otg_hcd_complete_urb(hcd, urb, -EPIPE);
15100 + if (pipe_type == PIPE_BULK || pipe_type == PIPE_INTERRUPT) {
15101 + dwc_otg_hcd_complete_urb(hcd, urb, -EPIPE);
15103 + * USB protocol requires resetting the data toggle for bulk
15104 + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
15105 + * setup command is issued to the endpoint. Anticipate the
15106 + * CLEAR_FEATURE command since a STALL has occurred and reset
15107 + * the data toggle now.
15109 + hc->qh->data_toggle = 0;
15112 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
15114 + disable_hc_int(hc_regs, stall);
15120 + * Updates the state of the URB when a transfer has been stopped due to an
15121 + * abnormal condition before the transfer completes. Modifies the
15122 + * actual_length field of the URB to reflect the number of bytes that have
15123 + * actually been transferred via the host channel.
15125 +static void update_urb_state_xfer_intr(dwc_hc_t *hc,
15126 + dwc_otg_hc_regs_t *hc_regs,
15128 + dwc_otg_qtd_t *qtd,
15129 + dwc_otg_halt_status_e halt_status)
15131 + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
15132 + halt_status, NULL);
15133 + urb->actual_length += bytes_transferred;
15137 + hctsiz_data_t hctsiz;
15138 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
15139 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
15140 + __func__, (hc->ep_is_in ? "IN" : "OUT"), hc->hc_num);
15141 + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n", hc->start_pkt_count);
15142 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
15143 + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
15144 + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n", bytes_transferred);
15145 + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n", urb->actual_length);
15146 + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
15147 + urb->transfer_buffer_length);
15153 + * Handles a host channel NAK interrupt. This handler may be called in either
15154 + * DMA mode or Slave mode.
15156 +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t *hcd,
15158 + dwc_otg_hc_regs_t *hc_regs,
15159 + dwc_otg_qtd_t *qtd)
15161 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15162 + "NAK Received--\n", hc->hc_num);
15165 + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
15166 + * interrupt. Re-start the SSPLIT transfer.
15168 + if (hc->do_split) {
15169 + if (hc->complete_split) {
15170 + qtd->error_count = 0;
15172 + qtd->complete_split = 0;
15173 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
15174 + goto handle_nak_done;
15177 + switch (usb_pipetype(qtd->urb->pipe)) {
15178 + case PIPE_CONTROL:
15180 + if (hcd->core_if->dma_enable && hc->ep_is_in) {
15182 + * NAK interrupts are enabled on bulk/control IN
15183 + * transfers in DMA mode for the sole purpose of
15184 + * resetting the error count after a transaction error
15185 + * occurs. The core will continue transferring data.
15187 + qtd->error_count = 0;
15188 + goto handle_nak_done;
15192 + * NAK interrupts normally occur during OUT transfers in DMA
15193 + * or Slave mode. For IN transfers, more requests will be
15194 + * queued as request queue space is available.
15196 + qtd->error_count = 0;
15198 + if (!hc->qh->ping_state) {
15199 + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb,
15200 + qtd, DWC_OTG_HC_XFER_NAK);
15201 + save_data_toggle(hc, hc_regs, qtd);
15202 + if (qtd->urb->dev->speed == USB_SPEED_HIGH) {
15203 + hc->qh->ping_state = 1;
15208 + * Halt the channel so the transfer can be re-started from
15209 + * the appropriate point or the PING protocol will
15210 + * start/continue.
15212 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
15214 + case PIPE_INTERRUPT:
15215 + qtd->error_count = 0;
15216 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
15218 + case PIPE_ISOCHRONOUS:
15219 + /* Should never get called for isochronous transfers. */
15225 + disable_hc_int(hc_regs, nak);
15231 + * Handles a host channel ACK interrupt. This interrupt is enabled when
15232 + * performing the PING protocol in Slave mode, when errors occur during
15233 + * either Slave mode or DMA mode, and during Start Split transactions.
15235 +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t *hcd,
15237 + dwc_otg_hc_regs_t *hc_regs,
15238 + dwc_otg_qtd_t *qtd)
15240 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15241 + "ACK Received--\n", hc->hc_num);
15243 + if (hc->do_split) {
15245 + * Handle ACK on SSPLIT.
15246 + * ACK should not occur in CSPLIT.
15248 + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
15249 + qtd->ssplit_out_xfer_count = hc->xfer_len;
15251 + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
15252 + /* Don't need complete for isochronous out transfers. */
15253 + qtd->complete_split = 1;
15257 + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
15258 + switch (hc->xact_pos) {
15259 + case DWC_HCSPLIT_XACTPOS_ALL:
15261 + case DWC_HCSPLIT_XACTPOS_END:
15262 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
15263 + qtd->isoc_split_offset = 0;
15265 + case DWC_HCSPLIT_XACTPOS_BEGIN:
15266 + case DWC_HCSPLIT_XACTPOS_MID:
15268 + * For BEGIN or MID, calculate the length for
15269 + * the next microframe to determine the correct
15270 + * SSPLIT token, either MID or END.
15273 + struct usb_iso_packet_descriptor *frame_desc;
15275 + frame_desc = &qtd->urb->iso_frame_desc[qtd->isoc_frame_index];
15276 + qtd->isoc_split_offset += 188;
15278 + if ((frame_desc->length - qtd->isoc_split_offset) <= 188) {
15279 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_END;
15281 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_MID;
15288 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
15291 + qtd->error_count = 0;
15293 + if (hc->qh->ping_state) {
15294 + hc->qh->ping_state = 0;
15296 + * Halt the channel so the transfer can be re-started
15297 + * from the appropriate point. This only happens in
15298 + * Slave mode. In DMA mode, the ping_state is cleared
15299 + * when the transfer is started because the core
15300 + * automatically executes the PING, then the transfer.
15302 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
15307 + * If the ACK occurred when _not_ in the PING state, let the channel
15308 + * continue transferring data after clearing the error count.
15311 + disable_hc_int(hc_regs, ack);
15317 + * Handles a host channel NYET interrupt. This interrupt should only occur on
15318 + * Bulk and Control OUT endpoints and for complete split transactions. If a
15319 + * NYET occurs at the same time as a Transfer Complete interrupt, it is
15320 + * handled in the xfercomp interrupt handler, not here. This handler may be
15321 + * called in either DMA mode or Slave mode.
15323 +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t *hcd,
15325 + dwc_otg_hc_regs_t *hc_regs,
15326 + dwc_otg_qtd_t *qtd)
15328 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15329 + "NYET Received--\n", hc->hc_num);
15333 + * re-do the CSPLIT immediately on non-periodic
15335 + if (hc->do_split && hc->complete_split) {
15336 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
15337 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
15338 + int frnum = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(hcd));
15340 + if (dwc_full_frame_num(frnum) !=
15341 + dwc_full_frame_num(hc->qh->sched_frame)) {
15343 + * No longer in the same full speed frame.
15344 + * Treat this as a transaction error.
15347 + /** @todo Fix system performance so this can
15348 + * be treated as an error. Right now complete
15349 + * splits cannot be scheduled precisely enough
15350 + * due to other system activity, so this error
15351 + * occurs regularly in Slave mode.
15353 + qtd->error_count++;
15355 + qtd->complete_split = 0;
15356 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
15357 + /** @todo add support for isoc release */
15358 + goto handle_nyet_done;
15362 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
15363 + goto handle_nyet_done;
15366 + hc->qh->ping_state = 1;
15367 + qtd->error_count = 0;
15369 + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
15370 + DWC_OTG_HC_XFER_NYET);
15371 + save_data_toggle(hc, hc_regs, qtd);
15374 + * Halt the channel and re-start the transfer so the PING
15375 + * protocol will start.
15377 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
15380 + disable_hc_int(hc_regs, nyet);
15385 + * Handles a host channel babble interrupt. This handler may be called in
15386 + * either DMA mode or Slave mode.
15388 +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t *hcd,
15390 + dwc_otg_hc_regs_t *hc_regs,
15391 + dwc_otg_qtd_t *qtd)
15393 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15394 + "Babble Error--\n", hc->hc_num);
15395 + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
15396 + dwc_otg_hcd_complete_urb(hcd, qtd->urb, -EOVERFLOW);
15397 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
15399 + dwc_otg_halt_status_e halt_status;
15400 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
15401 + DWC_OTG_HC_XFER_BABBLE_ERR);
15402 + halt_channel(hcd, hc, qtd, halt_status);
15404 + disable_hc_int(hc_regs, bblerr);
15409 + * Handles a host channel AHB error interrupt. This handler is only called in
15412 +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t *hcd,
15414 + dwc_otg_hc_regs_t *hc_regs,
15415 + dwc_otg_qtd_t *qtd)
15417 + hcchar_data_t hcchar;
15418 + hcsplt_data_t hcsplt;
15419 + hctsiz_data_t hctsiz;
15421 + struct urb *urb = qtd->urb;
15423 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15424 + "AHB Error--\n", hc->hc_num);
15426 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
15427 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
15428 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
15429 + hcdma = dwc_read_reg32(&hc_regs->hcdma);
15431 + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
15432 + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
15433 + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
15434 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
15435 + DWC_ERROR(" Device address: %d\n", usb_pipedevice(urb->pipe));
15436 + DWC_ERROR(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
15437 + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
15438 + DWC_ERROR(" Endpoint type: %s\n",
15439 + ({char *pipetype;
15440 + switch (usb_pipetype(urb->pipe)) {
15441 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
15442 + case PIPE_BULK: pipetype = "BULK"; break;
15443 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
15444 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
15445 + default: pipetype = "UNKNOWN"; break;
15447 + DWC_ERROR(" Speed: %s\n",
15449 + switch (urb->dev->speed) {
15450 + case USB_SPEED_HIGH: speed = "HIGH"; break;
15451 + case USB_SPEED_FULL: speed = "FULL"; break;
15452 + case USB_SPEED_LOW: speed = "LOW"; break;
15453 + default: speed = "UNKNOWN"; break;
15455 + DWC_ERROR(" Max packet size: %d\n",
15456 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
15457 + DWC_ERROR(" Data buffer length: %d\n", urb->transfer_buffer_length);
15458 + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
15459 + urb->transfer_buffer, (void *)urb->transfer_dma);
15460 + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
15461 + urb->setup_packet, (void *)urb->setup_dma);
15462 + DWC_ERROR(" Interval: %d\n", urb->interval);
15464 + dwc_otg_hcd_complete_urb(hcd, urb, -EIO);
15467 + * Force a channel halt. Don't call halt_channel because that won't
15468 + * write to the HCCHARn register in DMA mode to force the halt.
15470 + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
15472 + disable_hc_int(hc_regs, ahberr);
15477 + * Handles a host channel transaction error interrupt. This handler may be
15478 + * called in either DMA mode or Slave mode.
15480 +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t *hcd,
15482 + dwc_otg_hc_regs_t *hc_regs,
15483 + dwc_otg_qtd_t *qtd)
15485 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15486 + "Transaction Error--\n", hc->hc_num);
15488 + switch (usb_pipetype(qtd->urb->pipe)) {
15489 + case PIPE_CONTROL:
15491 + qtd->error_count++;
15492 + if (!hc->qh->ping_state) {
15493 + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb,
15494 + qtd, DWC_OTG_HC_XFER_XACT_ERR);
15495 + save_data_toggle(hc, hc_regs, qtd);
15496 + if (!hc->ep_is_in && qtd->urb->dev->speed == USB_SPEED_HIGH) {
15497 + hc->qh->ping_state = 1;
15502 + * Halt the channel so the transfer can be re-started from
15503 + * the appropriate point or the PING protocol will start.
15505 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
15507 + case PIPE_INTERRUPT:
15508 + qtd->error_count++;
15509 + if (hc->do_split && hc->complete_split) {
15510 + qtd->complete_split = 0;
15512 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
15514 + case PIPE_ISOCHRONOUS:
15516 + dwc_otg_halt_status_e halt_status;
15517 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
15518 + DWC_OTG_HC_XFER_XACT_ERR);
15520 + halt_channel(hcd, hc, qtd, halt_status);
15525 + disable_hc_int(hc_regs, xacterr);
15531 + * Handles a host channel frame overrun interrupt. This handler may be called
15532 + * in either DMA mode or Slave mode.
15534 +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t *hcd,
15536 + dwc_otg_hc_regs_t *hc_regs,
15537 + dwc_otg_qtd_t *qtd)
15539 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15540 + "Frame Overrun--\n", hc->hc_num);
15542 + switch (usb_pipetype(qtd->urb->pipe)) {
15543 + case PIPE_CONTROL:
15546 + case PIPE_INTERRUPT:
15547 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
15549 + case PIPE_ISOCHRONOUS:
15551 + dwc_otg_halt_status_e halt_status;
15552 + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
15553 + DWC_OTG_HC_XFER_FRAME_OVERRUN);
15555 + halt_channel(hcd, hc, qtd, halt_status);
15560 + disable_hc_int(hc_regs, frmovrun);
15566 + * Handles a host channel data toggle error interrupt. This handler may be
15567 + * called in either DMA mode or Slave mode.
15569 +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t *hcd,
15571 + dwc_otg_hc_regs_t *hc_regs,
15572 + dwc_otg_qtd_t *qtd)
15574 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15575 + "Data Toggle Error--\n", hc->hc_num);
15577 + if (hc->ep_is_in) {
15578 + qtd->error_count = 0;
15580 + DWC_ERROR("Data Toggle Error on OUT transfer,"
15581 + "channel %d\n", hc->hc_num);
15584 + disable_hc_int(hc_regs, datatglerr);
15591 + * This function is for debug only. It checks that a valid halt status is set
15592 + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
15593 + * taken and a warning is issued.
15594 + * @return 1 if halt status is ok, 0 otherwise.
15596 +static inline int halt_status_ok(dwc_otg_hcd_t *hcd,
15598 + dwc_otg_hc_regs_t *hc_regs,
15599 + dwc_otg_qtd_t *qtd)
15601 + hcchar_data_t hcchar;
15602 + hctsiz_data_t hctsiz;
15603 + hcint_data_t hcint;
15604 + hcintmsk_data_t hcintmsk;
15605 + hcsplt_data_t hcsplt;
15607 + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
15609 + * This code is here only as a check. This condition should
15610 + * never happen. Ignore the halt if it does occur.
15612 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
15613 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
15614 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
15615 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
15616 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
15617 + DWC_WARN("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
15618 + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
15619 + "hcint 0x%08x, hcintmsk 0x%08x, "
15620 + "hcsplt 0x%08x, qtd->complete_split %d\n",
15621 + __func__, hc->hc_num, hcchar.d32, hctsiz.d32,
15622 + hcint.d32, hcintmsk.d32,
15623 + hcsplt.d32, qtd->complete_split);
15625 + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
15626 + __func__, hc->hc_num);
15628 + clear_hc_int(hc_regs, chhltd);
15633 + * This code is here only as a check. hcchar.chdis should
15634 + * never be set when the halt interrupt occurs. Halt the
15635 + * channel again if it does occur.
15637 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
15638 + if (hcchar.b.chdis) {
15639 + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
15640 + "hcchar 0x%08x, trying to halt again\n",
15641 + __func__, hcchar.d32);
15642 + clear_hc_int(hc_regs, chhltd);
15643 + hc->halt_pending = 0;
15644 + halt_channel(hcd, hc, qtd, hc->halt_status);
15653 + * Handles a host Channel Halted interrupt in DMA mode. This handler
15654 + * determines the reason the channel halted and proceeds accordingly.
15656 +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t *hcd,
15658 + dwc_otg_hc_regs_t *hc_regs,
15659 + dwc_otg_qtd_t *qtd)
15661 + hcint_data_t hcint;
15662 + hcintmsk_data_t hcintmsk;
15663 + int out_nak_enh = 0;
15665 + /* For core with OUT NAK enhancement, the flow for high-
15666 + * speed CONTROL/BULK OUT is handled a little differently.
15668 + if (hcd->core_if->snpsid >= 0x4F54271A) {
15669 + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
15670 + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
15671 + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
15672 + DWC_DEBUGPL(DBG_HCD, "OUT NAK enhancement enabled\n");
15675 + DWC_DEBUGPL(DBG_HCD, "OUT NAK enhancement disabled, not HS Ctrl/Bulk OUT EP\n");
15678 + DWC_DEBUGPL(DBG_HCD, "OUT NAK enhancement disabled, no core support\n");
15681 + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
15682 + hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
15684 + * Just release the channel. A dequeue can happen on a
15685 + * transfer timeout. In the case of an AHB Error, the channel
15686 + * was forced to halt because there's no way to gracefully
15689 + release_channel(hcd, hc, qtd, hc->halt_status);
15693 + /* Read the HCINTn register to determine the cause for the halt. */
15694 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
15695 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
15697 + if (hcint.b.xfercomp) {
15698 + /** @todo This is here because of a possible hardware bug. Spec
15699 + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
15700 + * interrupt w/ACK bit set should occur, but I only see the
15701 + * XFERCOMP bit, even with it masked out. This is a workaround
15702 + * for that behavior. Should fix this when hardware is fixed.
15704 + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
15705 + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
15707 + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
15708 + } else if (hcint.b.stall) {
15709 + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
15710 + } else if (hcint.b.xacterr) {
15711 + if (out_nak_enh) {
15712 + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
15713 + printk(KERN_DEBUG "XactErr with NYET/NAK/ACK\n");
15714 + qtd->error_count = 0;
15716 + printk(KERN_DEBUG "XactErr without NYET/NAK/ACK\n");
15721 + * Must handle xacterr before nak or ack. Could get a xacterr
15722 + * at the same time as either of these on a BULK/CONTROL OUT
15723 + * that started with a PING. The xacterr takes precedence.
15725 + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
15726 + } else if (!out_nak_enh) {
15727 + if (hcint.b.nyet) {
15729 + * Must handle nyet before nak or ack. Could get a nyet at the
15730 + * same time as either of those on a BULK/CONTROL OUT that
15731 + * started with a PING. The nyet takes precedence.
15733 + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
15734 + } else if (hcint.b.bblerr) {
15735 + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
15736 + } else if (hcint.b.frmovrun) {
15737 + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
15738 + } else if (hcint.b.nak && !hcintmsk.b.nak) {
15740 + * If nak is not masked, it's because a non-split IN transfer
15741 + * is in an error state. In that case, the nak is handled by
15742 + * the nak interrupt handler, not here. Handle nak here for
15743 + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
15744 + * rewinding the buffer pointer.
15746 + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
15747 + } else if (hcint.b.ack && !hcintmsk.b.ack) {
15749 + * If ack is not masked, it's because a non-split IN transfer
15750 + * is in an error state. In that case, the ack is handled by
15751 + * the ack interrupt handler, not here. Handle ack here for
15752 + * split transfers. Start splits halt on ACK.
15754 + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
15756 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
15757 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
15759 + * A periodic transfer halted with no other channel
15760 + * interrupts set. Assume it was halted by the core
15761 + * because it could not be completed in its scheduled
15765 + DWC_PRINT("%s: Halt channel %d (assume incomplete periodic transfer)\n",
15766 + __func__, hc->hc_num);
15768 + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
15770 + DWC_ERROR("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
15771 + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
15772 + __func__, hc->hc_num, hcint.d32,
15773 + dwc_read_reg32(&hcd->core_if->core_global_regs->gintsts));
15777 + printk(KERN_DEBUG "NYET/NAK/ACK/other in non-error case, 0x%08x\n", hcint.d32);
15782 + * Handles a host channel Channel Halted interrupt.
15784 + * In slave mode, this handler is called only when the driver specifically
15785 + * requests a halt. This occurs during handling other host channel interrupts
15786 + * (e.g. nak, xacterr, stall, nyet, etc.).
15788 + * In DMA mode, this is the interrupt that occurs when the core has finished
15789 + * processing a transfer on a channel. Other host channel interrupts (except
15790 + * ahberr) are disabled in DMA mode.
15792 +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t *hcd,
15794 + dwc_otg_hc_regs_t *hc_regs,
15795 + dwc_otg_qtd_t *qtd)
15797 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
15798 + "Channel Halted--\n", hc->hc_num);
15800 + if (hcd->core_if->dma_enable) {
15801 + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
15804 + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
15808 + release_channel(hcd, hc, qtd, hc->halt_status);
15814 +/** Handles interrupt for a specific Host Channel */
15815 +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t *dwc_otg_hcd, uint32_t num)
15818 + hcint_data_t hcint;
15819 + hcintmsk_data_t hcintmsk;
15821 + dwc_otg_hc_regs_t *hc_regs;
15822 + dwc_otg_qtd_t *qtd;
15824 + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
15826 + hc = dwc_otg_hcd->hc_ptr_array[num];
15827 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
15828 + qtd = list_entry(hc->qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
15830 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
15831 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
15832 + DWC_DEBUGPL(DBG_HCDV, " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
15833 + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
15834 + hcint.d32 = hcint.d32 & hcintmsk.d32;
15836 + if (!dwc_otg_hcd->core_if->dma_enable) {
15837 + if (hcint.b.chhltd && hcint.d32 != 0x2) {
15838 + hcint.b.chhltd = 0;
15842 + if (hcint.b.xfercomp) {
15843 + retval |= handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15845 + * If NYET occurred at same time as Xfer Complete, the NYET is
15846 + * handled by the Xfer Complete interrupt handler. Don't want
15847 + * to call the NYET interrupt handler in this case.
15849 + hcint.b.nyet = 0;
15851 + if (hcint.b.chhltd) {
15852 + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15854 + if (hcint.b.ahberr) {
15855 + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15857 + if (hcint.b.stall) {
15858 + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15860 + if (hcint.b.nak) {
15861 + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15863 + if (hcint.b.ack) {
15864 + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15866 + if (hcint.b.nyet) {
15867 + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15869 + if (hcint.b.xacterr) {
15870 + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15872 + if (hcint.b.bblerr) {
15873 + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15875 + if (hcint.b.frmovrun) {
15876 + retval |= handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15878 + if (hcint.b.datatglerr) {
15879 + retval |= handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
15885 +#endif /* DWC_DEVICE_ONLY */
15887 +++ b/drivers/usb/host/otg/dwc_otg_hcd_queue.c
15889 +/* ==========================================================================
15890 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
15891 + * $Revision: #33 $
15892 + * $Date: 2008/07/15 $
15893 + * $Change: 1064918 $
15895 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
15896 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
15897 + * otherwise expressly agreed to in writing between Synopsys and you.
15899 + * The Software IS NOT an item of Licensed Software or Licensed Product under
15900 + * any End User Software License Agreement or Agreement for Licensed Product
15901 + * with Synopsys or any supplement thereto. You are permitted to use and
15902 + * redistribute this Software in source and binary forms, with or without
15903 + * modification, provided that redistributions of source code must retain this
15904 + * notice. You may not view, use, disclose, copy or distribute this file or
15905 + * any information contained herein except pursuant to this license grant from
15906 + * Synopsys. If you do not agree with this notice, including the disclaimer
15907 + * below, then you are not authorized to use the Software.
15909 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
15910 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15911 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15912 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
15913 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15914 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
15915 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
15916 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
15917 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15918 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
15920 + * ========================================================================== */
15921 +#ifndef DWC_DEVICE_ONLY
15926 + * This file contains the functions to manage Queue Heads and Queue
15927 + * Transfer Descriptors.
15929 +#include <linux/kernel.h>
15930 +#include <linux/module.h>
15931 +#include <linux/moduleparam.h>
15932 +#include <linux/init.h>
15933 +#include <linux/device.h>
15934 +#include <linux/errno.h>
15935 +#include <linux/list.h>
15936 +#include <linux/interrupt.h>
15937 +#include <linux/string.h>
15938 +#include <linux/version.h>
15940 +#include <mach/lm.h>
15941 +#include <mach/irqs.h>
15943 +#include "dwc_otg_driver.h"
15944 +#include "dwc_otg_hcd.h"
15945 +#include "dwc_otg_regs.h"
15948 + * This function allocates and initializes a QH.
15950 + * @param hcd The HCD state structure for the DWC OTG controller.
15951 + * @param[in] urb Holds the information about the device/endpoint that we need
15952 + * to initialize the QH.
15954 + * @return Returns pointer to the newly allocated QH, or NULL on error. */
15955 +dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *hcd, struct urb *urb)
15957 + dwc_otg_qh_t *qh;
15959 + /* Allocate memory */
15960 + /** @todo add memflags argument */
15961 + qh = dwc_otg_hcd_qh_alloc ();
15962 + if (qh == NULL) {
15966 + dwc_otg_hcd_qh_init (hcd, qh, urb);
15970 +/** Free each QTD in the QH's QTD-list then free the QH. QH should already be
15971 + * removed from a list. QTD list should already be empty if called from URB
15974 + * @param[in] hcd HCD instance.
15975 + * @param[in] qh The QH to free.
15977 +void dwc_otg_hcd_qh_free (dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
15979 + dwc_otg_qtd_t *qtd;
15980 + struct list_head *pos;
15981 + //unsigned long flags;
15983 + /* Free each QTD in the QTD list */
15986 + //the spinlock is locked before this function get called,
15987 + //but in case the lock is needed, the check function is preserved
15989 + //but in non-SMP mode, all spinlock is lockable.
15990 + //don't do the test in non-SMP mode
15992 + if(spin_trylock(&hcd->lock)) {
15993 + printk("%s: It is not supposed to be lockable!!\n",__func__);
15997 +// SPIN_LOCK_IRQSAVE(&hcd->lock, flags)
15998 + for (pos = qh->qtd_list.next;
15999 + pos != &qh->qtd_list;
16000 + pos = qh->qtd_list.next)
16003 + qtd = dwc_list_to_qtd (pos);
16004 + dwc_otg_hcd_qtd_free (qtd);
16006 +// SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags)
16012 +/** Initializes a QH structure.
16014 + * @param[in] hcd The HCD state structure for the DWC OTG controller.
16015 + * @param[in] qh The QH to init.
16016 + * @param[in] urb Holds the information about the device/endpoint that we need
16017 + * to initialize the QH. */
16018 +#define SCHEDULE_SLOP 10
16019 +void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, struct urb *urb)
16021 + char *speed, *type;
16022 + memset (qh, 0, sizeof (dwc_otg_qh_t));
16024 + /* Initialize QH */
16025 + switch (usb_pipetype(urb->pipe)) {
16026 + case PIPE_CONTROL:
16027 + qh->ep_type = USB_ENDPOINT_XFER_CONTROL;
16030 + qh->ep_type = USB_ENDPOINT_XFER_BULK;
16032 + case PIPE_ISOCHRONOUS:
16033 + qh->ep_type = USB_ENDPOINT_XFER_ISOC;
16035 + case PIPE_INTERRUPT:
16036 + qh->ep_type = USB_ENDPOINT_XFER_INT;
16040 + qh->ep_is_in = usb_pipein(urb->pipe) ? 1 : 0;
16042 + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
16043 + qh->maxp = usb_maxpacket(urb->dev, urb->pipe, !(usb_pipein(urb->pipe)));
16044 + INIT_LIST_HEAD(&qh->qtd_list);
16045 + INIT_LIST_HEAD(&qh->qh_list_entry);
16046 + qh->channel = NULL;
16048 + /* FS/LS Enpoint on HS Hub
16049 + * NOT virtual root hub */
16050 + qh->do_split = 0;
16051 + if (((urb->dev->speed == USB_SPEED_LOW) ||
16052 + (urb->dev->speed == USB_SPEED_FULL)) &&
16053 + (urb->dev->tt) && (urb->dev->tt->hub) && (urb->dev->tt->hub->devnum != 1))
16055 + DWC_DEBUGPL(DBG_HCD, "QH init: EP %d: TT found at hub addr %d, for port %d\n",
16056 + usb_pipeendpoint(urb->pipe), urb->dev->tt->hub->devnum,
16057 + urb->dev->ttport);
16058 + qh->do_split = 1;
16061 + if (qh->ep_type == USB_ENDPOINT_XFER_INT ||
16062 + qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
16063 + /* Compute scheduling parameters once and save them. */
16064 + hprt0_data_t hprt;
16066 + /** @todo Account for split transfers in the bus time. */
16067 + int bytecount = dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
16068 + qh->usecs = usb_calc_bus_time(urb->dev->speed,
16069 + usb_pipein(urb->pipe),
16070 + (qh->ep_type == USB_ENDPOINT_XFER_ISOC),
16073 + /* Start in a slightly future (micro)frame. */
16074 + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
16076 + qh->interval = urb->interval;
16078 + /* Increase interrupt polling rate for debugging. */
16079 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
16080 + qh->interval = 8;
16083 + hprt.d32 = dwc_read_reg32(hcd->core_if->host_if->hprt0);
16084 + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
16085 + ((urb->dev->speed == USB_SPEED_LOW) ||
16086 + (urb->dev->speed == USB_SPEED_FULL))) {
16087 + qh->interval *= 8;
16088 + qh->sched_frame |= 0x7;
16089 + qh->start_split_frame = qh->sched_frame;
16094 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
16095 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
16096 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
16097 + urb->dev->devnum);
16098 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
16099 + usb_pipeendpoint(urb->pipe),
16100 + usb_pipein(urb->pipe) == USB_DIR_IN ? "IN" : "OUT");
16102 + switch(urb->dev->speed) {
16103 + case USB_SPEED_LOW:
16106 + case USB_SPEED_FULL:
16109 + case USB_SPEED_HIGH:
16116 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
16118 + switch (qh->ep_type) {
16119 + case USB_ENDPOINT_XFER_ISOC:
16120 + type = "isochronous";
16122 + case USB_ENDPOINT_XFER_INT:
16123 + type = "interrupt";
16125 + case USB_ENDPOINT_XFER_CONTROL:
16126 + type = "control";
16128 + case USB_ENDPOINT_XFER_BULK:
16135 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n",type);
16138 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
16139 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
16141 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
16150 + * Checks that a channel is available for a periodic transfer.
16152 + * @return 0 if successful, negative error code otherise.
16154 +static int periodic_channel_available(dwc_otg_hcd_t *hcd)
16157 + * Currently assuming that there is a dedicated host channnel for each
16158 + * periodic transaction plus at least one host channel for
16159 + * non-periodic transactions.
16162 + int num_channels;
16164 + num_channels = hcd->core_if->core_params->host_channels;
16165 + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels) &&
16166 + (hcd->periodic_channels < num_channels - 1)) {
16170 + DWC_NOTICE("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
16171 + __func__, num_channels, hcd->periodic_channels,
16172 + hcd->non_periodic_channels);
16173 + status = -ENOSPC;
16180 + * Checks that there is sufficient bandwidth for the specified QH in the
16181 + * periodic schedule. For simplicity, this calculation assumes that all the
16182 + * transfers in the periodic schedule may occur in the same (micro)frame.
16184 + * @param hcd The HCD state structure for the DWC OTG controller.
16185 + * @param qh QH containing periodic bandwidth required.
16187 + * @return 0 if successful, negative error code otherwise.
16189 +static int check_periodic_bandwidth(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
16192 + uint16_t max_claimed_usecs;
16196 + if (hcd->core_if->core_params->speed == DWC_SPEED_PARAM_HIGH) {
16198 + * High speed mode.
16199 + * Max periodic usecs is 80% x 125 usec = 100 usec.
16201 + max_claimed_usecs = 100 - qh->usecs;
16204 + * Full speed mode.
16205 + * Max periodic usecs is 90% x 1000 usec = 900 usec.
16207 + max_claimed_usecs = 900 - qh->usecs;
16210 + if (hcd->periodic_usecs > max_claimed_usecs) {
16211 + DWC_NOTICE("%s: already claimed usecs %d, required usecs %d\n",
16212 + __func__, hcd->periodic_usecs, qh->usecs);
16213 + status = -ENOSPC;
16220 + * Checks that the max transfer size allowed in a host channel is large enough
16221 + * to handle the maximum data transfer in a single (micro)frame for a periodic
16224 + * @param hcd The HCD state structure for the DWC OTG controller.
16225 + * @param qh QH for a periodic endpoint.
16227 + * @return 0 if successful, negative error code otherwise.
16229 +static int check_max_xfer_size(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
16232 + uint32_t max_xfer_size;
16233 + uint32_t max_channel_xfer_size;
16237 + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
16238 + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
16240 + if (max_xfer_size > max_channel_xfer_size) {
16241 + DWC_NOTICE("%s: Periodic xfer length %d > "
16242 + "max xfer length for channel %d\n",
16243 + __func__, max_xfer_size, max_channel_xfer_size);
16244 + status = -ENOSPC;
16251 + * Schedules an interrupt or isochronous transfer in the periodic schedule.
16253 + * @param hcd The HCD state structure for the DWC OTG controller.
16254 + * @param qh QH for the periodic transfer. The QH should already contain the
16255 + * scheduling information.
16257 + * @return 0 if successful, negative error code otherwise.
16259 +static int schedule_periodic(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
16263 + status = periodic_channel_available(hcd);
16265 + DWC_NOTICE("%s: No host channel available for periodic "
16266 + "transfer.\n", __func__);
16270 + status = check_periodic_bandwidth(hcd, qh);
16272 + DWC_NOTICE("%s: Insufficient periodic bandwidth for "
16273 + "periodic transfer.\n", __func__);
16277 + status = check_max_xfer_size(hcd, qh);
16279 + DWC_NOTICE("%s: Channel max transfer size too small "
16280 + "for periodic transfer.\n", __func__);
16284 + /* Always start in the inactive schedule. */
16285 + list_add_tail(&qh->qh_list_entry, &hcd->periodic_sched_inactive);
16287 + /* Reserve the periodic channel. */
16288 + hcd->periodic_channels++;
16290 + /* Update claimed usecs per (micro)frame. */
16291 + hcd->periodic_usecs += qh->usecs;
16293 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
16294 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_allocated += qh->usecs / qh->interval;
16295 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
16296 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_int_reqs++;
16297 + DWC_DEBUGPL(DBG_HCD, "Scheduled intr: qh %p, usecs %d, period %d\n",
16298 + qh, qh->usecs, qh->interval);
16300 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_isoc_reqs++;
16301 + DWC_DEBUGPL(DBG_HCD, "Scheduled isoc: qh %p, usecs %d, period %d\n",
16302 + qh, qh->usecs, qh->interval);
16309 + * This function adds a QH to either the non periodic or periodic schedule if
16310 + * it is not already in the schedule. If the QH is already in the schedule, no
16311 + * action is taken.
16313 + * @return 0 if successful, negative error code otherwise.
16315 +int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
16317 + //unsigned long flags;
16321 + //the spinlock is locked before this function get called,
16322 + //but in case the lock is needed, the check function is preserved
16324 + //but in non-SMP mode, all spinlock is lockable.
16325 + //don't do the test in non-SMP mode
16327 + if(spin_trylock(&hcd->lock)) {
16328 + printk("%s: It is not supposed to be lockable!!\n",__func__);
16332 +// SPIN_LOCK_IRQSAVE(&hcd->lock, flags)
16334 + if (!list_empty(&qh->qh_list_entry)) {
16335 + /* QH already in a schedule. */
16339 + /* Add the new QH to the appropriate schedule */
16340 + if (dwc_qh_is_non_per(qh)) {
16341 + /* Always start in the inactive schedule. */
16342 + list_add_tail(&qh->qh_list_entry, &hcd->non_periodic_sched_inactive);
16344 + status = schedule_periodic(hcd, qh);
16348 +// SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags)
16354 + * Removes an interrupt or isochronous transfer from the periodic schedule.
16356 + * @param hcd The HCD state structure for the DWC OTG controller.
16357 + * @param qh QH for the periodic transfer.
16359 +static void deschedule_periodic(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
16361 + list_del_init(&qh->qh_list_entry);
16363 + /* Release the periodic channel reservation. */
16364 + hcd->periodic_channels--;
16366 + /* Update claimed usecs per (micro)frame. */
16367 + hcd->periodic_usecs -= qh->usecs;
16369 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
16370 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_allocated -= qh->usecs / qh->interval;
16372 + if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
16373 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_int_reqs--;
16374 + DWC_DEBUGPL(DBG_HCD, "Descheduled intr: qh %p, usecs %d, period %d\n",
16375 + qh, qh->usecs, qh->interval);
16377 + hcd_to_bus(dwc_otg_hcd_to_hcd(hcd))->bandwidth_isoc_reqs--;
16378 + DWC_DEBUGPL(DBG_HCD, "Descheduled isoc: qh %p, usecs %d, period %d\n",
16379 + qh, qh->usecs, qh->interval);
16384 + * Removes a QH from either the non-periodic or periodic schedule. Memory is
16387 + * @param[in] hcd The HCD state structure.
16388 + * @param[in] qh QH to remove from schedule. */
16389 +void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
16391 + //unsigned long flags;
16394 + //the spinlock is locked before this function get called,
16395 + //but in case the lock is needed, the check function is preserved
16397 + //but in non-SMP mode, all spinlock is lockable.
16398 + //don't do the test in non-SMP mode
16400 + if(spin_trylock(&hcd->lock)) {
16401 + printk("%s: It is not supposed to be lockable!!\n",__func__);
16405 +// SPIN_LOCK_IRQSAVE(&hcd->lock, flags);
16407 + if (list_empty(&qh->qh_list_entry)) {
16408 + /* QH is not in a schedule. */
16412 + if (dwc_qh_is_non_per(qh)) {
16413 + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
16414 + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
16416 + list_del_init(&qh->qh_list_entry);
16418 + deschedule_periodic(hcd, qh);
16422 +// SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags);
16427 + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
16428 + * non-periodic schedule. The QH is added to the inactive non-periodic
16429 + * schedule if any QTDs are still attached to the QH.
16431 + * For periodic QHs, the QH is removed from the periodic queued schedule. If
16432 + * there are any QTDs still attached to the QH, the QH is added to either the
16433 + * periodic inactive schedule or the periodic ready schedule and its next
16434 + * scheduled frame is calculated. The QH is placed in the ready schedule if
16435 + * the scheduled frame has been reached already. Otherwise it's placed in the
16436 + * inactive schedule. If there are no QTDs attached to the QH, the QH is
16437 + * completely removed from the periodic schedule.
16439 +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, int sched_next_periodic_split)
16441 + unsigned long flags;
16442 + SPIN_LOCK_IRQSAVE(&hcd->lock, flags);
16444 + if (dwc_qh_is_non_per(qh)) {
16445 + dwc_otg_hcd_qh_remove(hcd, qh);
16446 + if (!list_empty(&qh->qtd_list)) {
16447 + /* Add back to inactive non-periodic schedule. */
16448 + dwc_otg_hcd_qh_add(hcd, qh);
16451 + uint16_t frame_number = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(hcd));
16453 + if (qh->do_split) {
16454 + /* Schedule the next continuing periodic split transfer */
16455 + if (sched_next_periodic_split) {
16457 + qh->sched_frame = frame_number;
16458 + if (dwc_frame_num_le(frame_number,
16459 + dwc_frame_num_inc(qh->start_split_frame, 1))) {
16461 + * Allow one frame to elapse after start
16462 + * split microframe before scheduling
16463 + * complete split, but DONT if we are
16464 + * doing the next start split in the
16465 + * same frame for an ISOC out.
16467 + if ((qh->ep_type != USB_ENDPOINT_XFER_ISOC) || (qh->ep_is_in != 0)) {
16468 + qh->sched_frame = dwc_frame_num_inc(qh->sched_frame, 1);
16472 + qh->sched_frame = dwc_frame_num_inc(qh->start_split_frame,
16474 + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
16475 + qh->sched_frame = frame_number;
16477 + qh->sched_frame |= 0x7;
16478 + qh->start_split_frame = qh->sched_frame;
16481 + qh->sched_frame = dwc_frame_num_inc(qh->sched_frame, qh->interval);
16482 + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
16483 + qh->sched_frame = frame_number;
16487 + if (list_empty(&qh->qtd_list)) {
16488 + dwc_otg_hcd_qh_remove(hcd, qh);
16491 + * Remove from periodic_sched_queued and move to
16492 + * appropriate queue.
16494 + if (qh->sched_frame == frame_number) {
16495 + list_move(&qh->qh_list_entry,
16496 + &hcd->periodic_sched_ready);
16498 + list_move(&qh->qh_list_entry,
16499 + &hcd->periodic_sched_inactive);
16504 + SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags);
16508 + * This function allocates and initializes a QTD.
16510 + * @param[in] urb The URB to create a QTD from. Each URB-QTD pair will end up
16511 + * pointing to each other so each pair should have a unique correlation.
16513 + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
16514 +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *urb)
16516 + dwc_otg_qtd_t *qtd;
16518 + qtd = dwc_otg_hcd_qtd_alloc ();
16519 + if (qtd == NULL) {
16523 + dwc_otg_hcd_qtd_init (qtd, urb);
16528 + * Initializes a QTD structure.
16530 + * @param[in] qtd The QTD to initialize.
16531 + * @param[in] urb The URB to use for initialization. */
16532 +void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *qtd, struct urb *urb)
16534 + memset (qtd, 0, sizeof (dwc_otg_qtd_t));
16536 + if (usb_pipecontrol(urb->pipe)) {
16538 + * The only time the QTD data toggle is used is on the data
16539 + * phase of control transfers. This phase always starts with
16542 + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
16543 + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
16546 + /* start split */
16547 + qtd->complete_split = 0;
16548 + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
16549 + qtd->isoc_split_offset = 0;
16551 + /* Store the qtd ptr in the urb to reference what QTD. */
16552 + urb->hcpriv = qtd;
16557 + * This function adds a QTD to the QTD-list of a QH. It will find the correct
16558 + * QH to place the QTD into. If it does not find a QH, then it will create a
16559 + * new QH. If the QH to which the QTD is added is not currently scheduled, it
16560 + * is placed into the proper schedule based on its EP type.
16562 + * @param[in] qtd The QTD to add
16563 + * @param[in] dwc_otg_hcd The DWC HCD structure
16565 + * @return 0 if successful, negative error code otherwise.
16567 +int dwc_otg_hcd_qtd_add (dwc_otg_qtd_t *qtd,
16568 + dwc_otg_hcd_t *dwc_otg_hcd)
16570 + struct usb_host_endpoint *ep;
16571 + dwc_otg_qh_t *qh;
16572 + unsigned long flags;
16575 + struct urb *urb = qtd->urb;
16577 + SPIN_LOCK_IRQSAVE(&dwc_otg_hcd->lock, flags);
16580 + * Get the QH which holds the QTD-list to insert to. Create QH if it
16583 + ep = dwc_urb_to_endpoint(urb);
16584 + qh = (dwc_otg_qh_t *)ep->hcpriv;
16585 + if (qh == NULL) {
16586 + qh = dwc_otg_hcd_qh_create (dwc_otg_hcd, urb);
16587 + if (qh == NULL) {
16593 + retval = dwc_otg_hcd_qh_add(dwc_otg_hcd, qh);
16594 + if (retval == 0) {
16595 + list_add_tail(&qtd->qtd_list_entry, &qh->qtd_list);
16599 + SPIN_UNLOCK_IRQRESTORE(&dwc_otg_hcd->lock, flags);
16604 +#endif /* DWC_DEVICE_ONLY */
16606 +++ b/drivers/usb/host/otg/dwc_otg_pcd.c
16608 +/* ==========================================================================
16609 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
16610 + * $Revision: #70 $
16611 + * $Date: 2008/10/14 $
16612 + * $Change: 1115682 $
16614 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
16615 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
16616 + * otherwise expressly agreed to in writing between Synopsys and you.
16618 + * The Software IS NOT an item of Licensed Software or Licensed Product under
16619 + * any End User Software License Agreement or Agreement for Licensed Product
16620 + * with Synopsys or any supplement thereto. You are permitted to use and
16621 + * redistribute this Software in source and binary forms, with or without
16622 + * modification, provided that redistributions of source code must retain this
16623 + * notice. You may not view, use, disclose, copy or distribute this file or
16624 + * any information contained herein except pursuant to this license grant from
16625 + * Synopsys. If you do not agree with this notice, including the disclaimer
16626 + * below, then you are not authorized to use the Software.
16628 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
16629 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16630 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16631 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
16632 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16633 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16634 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
16635 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
16636 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
16637 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
16639 + * ========================================================================== */
16640 +#ifndef DWC_HOST_ONLY
16643 + * This file implements the Peripheral Controller Driver.
16645 + * The Peripheral Controller Driver (PCD) is responsible for
16646 + * translating requests from the Function Driver into the appropriate
16647 + * actions on the DWC_otg controller. It isolates the Function Driver
16648 + * from the specifics of the controller by providing an API to the
16649 + * Function Driver.
16651 + * The Peripheral Controller Driver for Linux will implement the
16652 + * Gadget API, so that the existing Gadget drivers can be used.
16653 + * (Gadget Driver is the Linux terminology for a Function Driver.)
16655 + * The Linux Gadget API is defined in the header file
16656 + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
16657 + * defined in the structure <code>usb_ep_ops</code> and the USB
16658 + * Controller API is defined in the structure
16659 + * <code>usb_gadget_ops</code>.
16661 + * An important function of the PCD is managing interrupts generated
16662 + * by the DWC_otg controller. The implementation of the DWC_otg device
16663 + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
16665 + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
16666 + * @todo Does it work when the request size is greater than DEPTSIZ
16672 +#include <linux/kernel.h>
16673 +#include <linux/module.h>
16674 +#include <linux/moduleparam.h>
16675 +#include <linux/init.h>
16676 +#include <linux/device.h>
16677 +#include <linux/errno.h>
16678 +#include <linux/list.h>
16679 +#include <linux/interrupt.h>
16680 +#include <linux/string.h>
16681 +#include <linux/dma-mapping.h>
16682 +#include <linux/version.h>
16684 +//#include <asm/arch/lm.h>
16685 +#include <mach/lm.h>
16686 +#include <mach/irqs.h>
16688 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
16689 +# include <linux/usb/ch9.h>
16691 +# include <linux/usb_ch9.h>
16694 +//#include <linux/usb_gadget.h>
16698 +#include "dwc_otg_driver.h"
16699 +#include "dwc_otg_pcd.h"
16704 + * Static PCD pointer for use in usb_gadget_register_driver and
16705 + * usb_gadget_unregister_driver. Initialized in dwc_otg_pcd_init.
16707 +static dwc_otg_pcd_t *s_pcd = 0;
16710 +/* Display the contents of the buffer */
16711 +extern void dump_msg(const u8 *buf, unsigned int length);
16715 + * This function completes a request. It call's the request call back.
16717 +void dwc_otg_request_done(dwc_otg_pcd_ep_t *ep, dwc_otg_pcd_request_t *req,
16720 + unsigned stopped = ep->stopped;
16722 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, ep);
16723 + list_del_init(&req->queue);
16725 + if (req->req.status == -EINPROGRESS) {
16726 + req->req.status = status;
16728 + status = req->req.status;
16731 + /* don't modify queue heads during completion callback */
16733 + SPIN_UNLOCK(&ep->pcd->lock);
16734 + req->req.complete(&ep->ep, &req->req);
16735 + SPIN_LOCK(&ep->pcd->lock);
16737 + if (ep->pcd->request_pending > 0) {
16738 + --ep->pcd->request_pending;
16741 + ep->stopped = stopped;
16745 + * This function terminates all the requsts in the EP request queue.
16747 +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t *ep)
16749 + dwc_otg_pcd_request_t *req;
16753 + /* called with irqs blocked?? */
16754 + while (!list_empty(&ep->queue)) {
16755 + req = list_entry(ep->queue.next, dwc_otg_pcd_request_t,
16757 + dwc_otg_request_done(ep, req, -ESHUTDOWN);
16761 +/* USB Endpoint Operations */
16763 + * The following sections briefly describe the behavior of the Gadget
16764 + * API endpoint operations implemented in the DWC_otg driver
16765 + * software. Detailed descriptions of the generic behavior of each of
16766 + * these functions can be found in the Linux header file
16767 + * include/linux/usb_gadget.h.
16769 + * The Gadget API provides wrapper functions for each of the function
16770 + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
16771 + * function, which then calls the underlying PCD function. The
16772 + * following sections are named according to the wrapper
16773 + * functions. Within each section, the corresponding DWC_otg PCD
16774 + * function name is specified.
16779 + * This function assigns periodic Tx FIFO to an periodic EP
16780 + * in shared Tx FIFO mode
16782 +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t *core_if)
16784 + uint32_t PerTxMsk = 1;
16786 + for(i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i)
16788 + if((PerTxMsk & core_if->p_tx_msk) == 0) {
16789 + core_if->p_tx_msk |= PerTxMsk;
16797 + * This function releases periodic Tx FIFO
16798 + * in shared Tx FIFO mode
16800 +static void release_perio_tx_fifo(dwc_otg_core_if_t *core_if, uint32_t fifo_num)
16802 + core_if->p_tx_msk = (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
16805 + * This function assigns periodic Tx FIFO to an periodic EP
16806 + * in shared Tx FIFO mode
16808 +static uint32_t assign_tx_fifo(dwc_otg_core_if_t *core_if)
16810 + uint32_t TxMsk = 1;
16813 + for(i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i)
16815 + if((TxMsk & core_if->tx_msk) == 0) {
16816 + core_if->tx_msk |= TxMsk;
16824 + * This function releases periodic Tx FIFO
16825 + * in shared Tx FIFO mode
16827 +static void release_tx_fifo(dwc_otg_core_if_t *core_if, uint32_t fifo_num)
16829 + core_if->tx_msk = (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
16833 + * This function is called by the Gadget Driver for each EP to be
16834 + * configured for the current configuration (SET_CONFIGURATION).
16836 + * This function initializes the dwc_otg_ep_t data structure, and then
16837 + * calls dwc_otg_ep_activate.
16839 +static int dwc_otg_pcd_ep_enable(struct usb_ep *usb_ep,
16840 + const struct usb_endpoint_descriptor *ep_desc)
16842 + dwc_otg_pcd_ep_t *ep = 0;
16843 + dwc_otg_pcd_t *pcd = 0;
16844 + unsigned long flags;
16846 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p)\n", __func__, usb_ep, ep_desc);
16848 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16849 + if (!usb_ep || !ep_desc || ep->desc ||
16850 + ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
16851 + DWC_WARN("%s, bad ep or descriptor\n", __func__);
16854 + if (ep == &ep->pcd->ep0) {
16855 + DWC_WARN("%s, bad ep(0)\n", __func__);
16859 + /* Check FIFO size? */
16860 + if (!ep_desc->wMaxPacketSize) {
16861 + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
16866 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
16867 + DWC_WARN("%s, bogus device state\n", __func__);
16868 + return -ESHUTDOWN;
16871 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
16873 + ep->desc = ep_desc;
16874 + ep->ep.maxpacket = le16_to_cpu (ep_desc->wMaxPacketSize);
16877 + * Activate the EP
16881 + ep->dwc_ep.is_in = (USB_DIR_IN & ep_desc->bEndpointAddress) != 0;
16882 + ep->dwc_ep.maxpacket = ep->ep.maxpacket;
16884 + ep->dwc_ep.type = ep_desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
16886 + if(ep->dwc_ep.is_in) {
16887 + if(!pcd->otg_dev->core_if->en_multiple_tx_fifo) {
16888 + ep->dwc_ep.tx_fifo_num = 0;
16890 + if (ep->dwc_ep.type == USB_ENDPOINT_XFER_ISOC) {
16892 + * if ISOC EP then assign a Periodic Tx FIFO.
16894 + ep->dwc_ep.tx_fifo_num = assign_perio_tx_fifo(pcd->otg_dev->core_if);
16898 + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
16900 + ep->dwc_ep.tx_fifo_num = assign_tx_fifo(pcd->otg_dev->core_if);
16904 + /* Set initial data PID. */
16905 + if (ep->dwc_ep.type == USB_ENDPOINT_XFER_BULK) {
16906 + ep->dwc_ep.data_pid_start = 0;
16909 + DWC_DEBUGPL(DBG_PCD, "Activate %s-%s: type=%d, mps=%d desc=%p\n",
16910 + ep->ep.name, (ep->dwc_ep.is_in ?"IN":"OUT"),
16911 + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
16913 + if(ep->dwc_ep.type != USB_ENDPOINT_XFER_ISOC) {
16914 + ep->dwc_ep.desc_addr = dwc_otg_ep_alloc_desc_chain(&ep->dwc_ep.dma_desc_addr, MAX_DMA_DESC_CNT);
16917 + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
16918 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
16924 + * This function is called when an EP is disabled due to disconnect or
16925 + * change in configuration. Any pending requests will terminate with a
16926 + * status of -ESHUTDOWN.
16928 + * This function modifies the dwc_otg_ep_t data structure for this EP,
16929 + * and then calls dwc_otg_ep_deactivate.
16931 +static int dwc_otg_pcd_ep_disable(struct usb_ep *usb_ep)
16933 + dwc_otg_pcd_ep_t *ep;
16934 + dwc_otg_pcd_t *pcd = 0;
16935 + unsigned long flags;
16937 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, usb_ep);
16938 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
16939 + if (!usb_ep || !ep->desc) {
16940 + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
16941 + usb_ep ? ep->ep.name : NULL);
16945 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
16947 + dwc_otg_request_nuke(ep);
16949 + dwc_otg_ep_deactivate(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
16953 + if(ep->dwc_ep.is_in) {
16954 + dwc_otg_flush_tx_fifo(GET_CORE_IF(ep->pcd), ep->dwc_ep.tx_fifo_num);
16955 + release_perio_tx_fifo(GET_CORE_IF(ep->pcd), ep->dwc_ep.tx_fifo_num);
16956 + release_tx_fifo(GET_CORE_IF(ep->pcd), ep->dwc_ep.tx_fifo_num);
16959 + /* Free DMA Descriptors */
16962 + SPIN_UNLOCK_IRQRESTORE(&ep->pcd->lock, flags);
16964 + if(ep->dwc_ep.type != USB_ENDPOINT_XFER_ISOC && ep->dwc_ep.desc_addr) {
16965 + dwc_otg_ep_free_desc_chain(ep->dwc_ep.desc_addr, ep->dwc_ep.dma_desc_addr, MAX_DMA_DESC_CNT);
16968 + DWC_DEBUGPL(DBG_PCD, "%s disabled\n", usb_ep->name);
16974 + * This function allocates a request object to use with the specified
16977 + * @param ep The endpoint to be used with with the request
16978 + * @param gfp_flags the GFP_* flags to use.
16980 +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
16981 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
16988 + dwc_otg_pcd_request_t *req;
16990 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%d)\n", __func__, ep, gfp_flags);
16992 + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
16995 + req = kmalloc(sizeof(dwc_otg_pcd_request_t), gfp_flags);
16997 + DWC_WARN("%s() %s\n", __func__,
16998 + "request allocation failed!\n");
17001 + memset(req, 0, sizeof(dwc_otg_pcd_request_t));
17002 + req->req.dma = DMA_ADDR_INVALID;
17003 + INIT_LIST_HEAD(&req->queue);
17004 + return &req->req;
17008 + * This function frees a request object.
17010 + * @param ep The endpoint associated with the request
17011 + * @param req The request being freed
17013 +static void dwc_otg_pcd_free_request(struct usb_ep *ep,
17014 + struct usb_request *req)
17016 + dwc_otg_pcd_request_t *request;
17017 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p)\n", __func__, ep, req);
17019 + if (0 == ep || 0 == req) {
17020 + DWC_WARN("%s() %s\n", __func__,
17021 + "Invalid ep or req argument!\n");
17025 + request = container_of(req, dwc_otg_pcd_request_t, req);
17031 + * This function allocates an I/O buffer to be used for a transfer
17032 + * to/from the specified endpoint.
17034 + * @param usb_ep The endpoint to be used with with the request
17035 + * @param bytes The desired number of bytes for the buffer
17036 + * @param dma Pointer to the buffer's DMA address; must be valid
17037 + * @param gfp_flags the GFP_* flags to use.
17038 + * @return address of a new buffer or null is buffer could not be allocated.
17040 +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
17042 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
17050 + dwc_otg_pcd_ep_t *ep;
17051 + dwc_otg_pcd_t *pcd = 0;
17053 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17056 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
17059 + /* Check dword alignment */
17060 + if ((bytes & 0x3UL) != 0) {
17061 + DWC_WARN("%s() Buffer size is not a multiple of"
17062 + "DWORD size (%d)",__func__, bytes);
17065 + if (GET_CORE_IF(pcd)->dma_enable) {
17066 + buf = dma_alloc_coherent (NULL, bytes, dma, gfp_flags);
17069 + buf = kmalloc(bytes, gfp_flags);
17072 + /* Check dword alignment */
17073 + if (((int)buf & 0x3UL) != 0) {
17074 + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
17082 + * This function frees an I/O buffer that was allocated by alloc_buffer.
17084 + * @param usb_ep the endpoint associated with the buffer
17085 + * @param buf address of the buffer
17086 + * @param dma The buffer's DMA address
17087 + * @param bytes The number of bytes of the buffer
17089 +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
17090 + dma_addr_t dma, unsigned bytes)
17092 + dwc_otg_pcd_ep_t *ep;
17093 + dwc_otg_pcd_t *pcd = 0;
17095 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17098 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p,%0x,%d)\n", __func__, ep, buf, dma, bytes);
17100 + if (GET_CORE_IF(pcd)->dma_enable) {
17101 + dma_free_coherent (NULL, bytes, buf, dma);
17110 + * This function is used to submit an I/O Request to an EP.
17112 + * - When the request completes the request's completion callback
17113 + * is called to return the request to the driver.
17114 + * - An EP, except control EPs, may have multiple requests
17116 + * - Once submitted the request cannot be examined or modified.
17117 + * - Each request is turned into one or more packets.
17118 + * - A BULK EP can queue any amount of data; the transfer is
17120 + * - Zero length Packets are specified with the request 'zero'
17123 +static int dwc_otg_pcd_ep_queue(struct usb_ep *usb_ep,
17124 + struct usb_request *usb_req,
17125 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
17132 + int prevented = 0;
17133 + dwc_otg_pcd_request_t *req;
17134 + dwc_otg_pcd_ep_t *ep;
17135 + dwc_otg_pcd_t *pcd;
17136 + unsigned long flags = 0;
17138 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p,%d)\n",
17139 + __func__, usb_ep, usb_req, gfp_flags);
17141 + req = container_of(usb_req, dwc_otg_pcd_request_t, req);
17142 + if (!usb_req || !usb_req->complete || !usb_req->buf ||
17143 + !list_empty(&req->queue)) {
17144 + DWC_WARN("%s, bad params\n", __func__);
17148 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17149 + if (!usb_ep || (!ep->desc && ep->dwc_ep.num != 0)/* || ep->stopped != 0*/) {
17150 + DWC_WARN("%s, bad ep\n", __func__);
17155 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
17156 + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n", pcd->gadget.speed);
17157 + DWC_WARN("%s, bogus device state\n", __func__);
17158 + return -ESHUTDOWN;
17162 + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
17163 + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
17165 + if (!GET_CORE_IF(pcd)->core_params->opt) {
17166 + if (ep->dwc_ep.num != 0) {
17167 + DWC_ERROR("%s queue req %p, len %d buf %p\n",
17168 + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
17172 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
17174 +#if defined(DEBUG) & defined(VERBOSE)
17175 + dump_msg(usb_req->buf, usb_req->length);
17178 + usb_req->status = -EINPROGRESS;
17179 + usb_req->actual = 0;
17182 + * For EP0 IN without premature status, zlp is required?
17184 + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
17185 + DWC_DEBUGPL(DBG_PCDV, "%s-OUT ZLP\n", usb_ep->name);
17186 + //_req->zero = 1;
17189 + /* Start the transfer */
17190 + if (list_empty(&ep->queue) && !ep->stopped) {
17191 + /* EP0 Transfer? */
17192 + if (ep->dwc_ep.num == 0) {
17193 + switch (pcd->ep0state) {
17194 + case EP0_IN_DATA_PHASE:
17195 + DWC_DEBUGPL(DBG_PCD,
17196 + "%s ep0: EP0_IN_DATA_PHASE\n",
17200 + case EP0_OUT_DATA_PHASE:
17201 + DWC_DEBUGPL(DBG_PCD,
17202 + "%s ep0: EP0_OUT_DATA_PHASE\n",
17204 + if (pcd->request_config) {
17205 + /* Complete STATUS PHASE */
17206 + ep->dwc_ep.is_in = 1;
17207 + pcd->ep0state = EP0_IN_STATUS_PHASE;
17211 + case EP0_IN_STATUS_PHASE:
17212 + DWC_DEBUGPL(DBG_PCD,
17213 + "%s ep0: EP0_IN_STATUS_PHASE\n",
17218 + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
17220 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
17223 + ep->dwc_ep.dma_addr = usb_req->dma;
17224 + ep->dwc_ep.start_xfer_buff = usb_req->buf;
17225 + ep->dwc_ep.xfer_buff = usb_req->buf;
17226 + ep->dwc_ep.xfer_len = usb_req->length;
17227 + ep->dwc_ep.xfer_count = 0;
17228 + ep->dwc_ep.sent_zlp = 0;
17229 + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
17231 + if(usb_req->zero) {
17232 + if((ep->dwc_ep.xfer_len % ep->dwc_ep.maxpacket == 0)
17233 + && (ep->dwc_ep.xfer_len != 0)) {
17234 + ep->dwc_ep.sent_zlp = 1;
17239 + ep_check_and_patch_dma_addr(ep);
17240 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep->dwc_ep);
17244 + uint32_t max_transfer = GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
17246 + /* Setup and start the Transfer */
17247 + ep->dwc_ep.dma_addr = usb_req->dma;
17248 + ep->dwc_ep.start_xfer_buff = usb_req->buf;
17249 + ep->dwc_ep.xfer_buff = usb_req->buf;
17250 + ep->dwc_ep.sent_zlp = 0;
17251 + ep->dwc_ep.total_len = usb_req->length;
17252 + ep->dwc_ep.xfer_len = 0;
17253 + ep->dwc_ep.xfer_count = 0;
17255 + if(max_transfer > MAX_TRANSFER_SIZE) {
17256 + ep->dwc_ep.maxxfer = max_transfer - (max_transfer % ep->dwc_ep.maxpacket);
17258 + ep->dwc_ep.maxxfer = max_transfer;
17261 + if(usb_req->zero) {
17262 + if((ep->dwc_ep.total_len % ep->dwc_ep.maxpacket == 0)
17263 + && (ep->dwc_ep.total_len != 0)) {
17264 + ep->dwc_ep.sent_zlp = 1;
17269 + ep_check_and_patch_dma_addr(ep);
17270 + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd), &ep->dwc_ep);
17274 + if ((req != 0) || prevented) {
17275 + ++pcd->request_pending;
17276 + list_add_tail(&req->queue, &ep->queue);
17277 + if (ep->dwc_ep.is_in && ep->stopped && !(GET_CORE_IF(pcd)->dma_enable)) {
17278 + /** @todo NGS Create a function for this. */
17279 + diepmsk_data_t diepmsk = { .d32 = 0};
17280 + diepmsk.b.intktxfemp = 1;
17281 + if(&GET_CORE_IF(pcd)->multiproc_int_enable) {
17282 + dwc_modify_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->diepeachintmsk[ep->dwc_ep.num],
17285 + dwc_modify_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
17290 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
17295 + * This function cancels an I/O request from an EP.
17297 +static int dwc_otg_pcd_ep_dequeue(struct usb_ep *usb_ep,
17298 + struct usb_request *usb_req)
17300 + dwc_otg_pcd_request_t *req;
17301 + dwc_otg_pcd_ep_t *ep;
17302 + dwc_otg_pcd_t *pcd;
17303 + unsigned long flags;
17305 + DWC_DEBUGPL(DBG_PCDV,"%s(%p,%p)\n", __func__, usb_ep, usb_req);
17307 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17308 + if (!usb_ep || !usb_req || (!ep->desc && ep->dwc_ep.num != 0)) {
17309 + DWC_WARN("%s, bad argument\n", __func__);
17313 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
17314 + DWC_WARN("%s, bogus device state\n", __func__);
17315 + return -ESHUTDOWN;
17318 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
17319 + DWC_DEBUGPL(DBG_PCDV, "%s %s %s %p\n", __func__, usb_ep->name,
17320 + ep->dwc_ep.is_in ? "IN" : "OUT",
17323 + /* make sure it's actually queued on this endpoint */
17324 + list_for_each_entry(req, &ep->queue, queue)
17326 + if (&req->req == usb_req) {
17331 + if (&req->req != usb_req) {
17332 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
17336 + if (!list_empty(&req->queue)) {
17337 + dwc_otg_request_done(ep, req, -ECONNRESET);
17343 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
17345 + return req ? 0 : -EOPNOTSUPP;
17349 + * usb_ep_set_halt stalls an endpoint.
17351 + * usb_ep_clear_halt clears an endpoint halt and resets its data
17354 + * Both of these functions are implemented with the same underlying
17355 + * function. The behavior depends on the value argument.
17357 + * @param[in] usb_ep the Endpoint to halt or clear halt.
17358 + * @param[in] value
17359 + * - 0 means clear_halt.
17360 + * - 1 means set_halt,
17361 + * - 2 means clear stall lock flag.
17362 + * - 3 means set stall lock flag.
17364 +static int dwc_otg_pcd_ep_set_halt(struct usb_ep *usb_ep, int value)
17367 + unsigned long flags;
17368 + dwc_otg_pcd_ep_t *ep = 0;
17371 + DWC_DEBUGPL(DBG_PCD,"HALT %s %d\n", usb_ep->name, value);
17373 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17375 + if (!usb_ep || (!ep->desc && ep != &ep->pcd->ep0) ||
17376 + ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
17377 + DWC_WARN("%s, bad ep\n", __func__);
17381 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
17382 + if (!list_empty(&ep->queue)) {
17383 + DWC_WARN("%s() %s XFer In process\n", __func__, usb_ep->name);
17384 + retval = -EAGAIN;
17386 + else if (value == 0) {
17387 + dwc_otg_ep_clear_stall(ep->pcd->otg_dev->core_if,
17390 + else if(value == 1) {
17391 + if (ep->dwc_ep.is_in == 1 && ep->pcd->otg_dev->core_if->dma_desc_enable) {
17392 + dtxfsts_data_t txstatus;
17393 + fifosize_data_t txfifosize;
17395 + txfifosize.d32 = dwc_read_reg32(&ep->pcd->otg_dev->core_if->core_global_regs->dptxfsiz_dieptxf[ep->dwc_ep.tx_fifo_num]);
17396 + txstatus.d32 = dwc_read_reg32(&ep->pcd->otg_dev->core_if->dev_if->in_ep_regs[ep->dwc_ep.num]->dtxfsts);
17398 + if(txstatus.b.txfspcavail < txfifosize.b.depth) {
17399 + DWC_WARN("%s() %s Data In Tx Fifo\n", __func__, usb_ep->name);
17400 + retval = -EAGAIN;
17403 + if (ep->dwc_ep.num == 0) {
17404 + ep->pcd->ep0state = EP0_STALL;
17408 + dwc_otg_ep_set_stall(ep->pcd->otg_dev->core_if,
17413 + if (ep->dwc_ep.num == 0) {
17414 + ep->pcd->ep0state = EP0_STALL;
17418 + dwc_otg_ep_set_stall(ep->pcd->otg_dev->core_if,
17422 + else if (value == 2) {
17423 + ep->dwc_ep.stall_clear_flag = 0;
17425 + else if (value == 3) {
17426 + ep->dwc_ep.stall_clear_flag = 1;
17429 + SPIN_UNLOCK_IRQRESTORE(&ep->pcd->lock, flags);
17434 + * This function allocates a DMA Descriptor chain for the Endpoint
17435 + * buffer to be used for a transfer to/from the specified endpoint.
17437 +dwc_otg_dma_desc_t* dwc_otg_ep_alloc_desc_chain(uint32_t * dma_desc_addr, uint32_t count)
17440 + return dma_alloc_coherent(NULL, count * sizeof(dwc_otg_dma_desc_t), dma_desc_addr, GFP_KERNEL);
17443 +LIST_HEAD(tofree_list);
17444 +spinlock_t tofree_list_lock=SPIN_LOCK_UNLOCKED;
17446 +struct free_param {
17447 + struct list_head list;
17450 + dma_addr_t dma_addr;
17453 +void free_list_agent_fn(void *data){
17454 + struct list_head free_list;
17455 + struct free_param *cur,*next;
17457 + spin_lock(&tofree_list_lock);
17458 + list_add(&free_list,&tofree_list);
17459 + list_del_init(&tofree_list);
17460 + spin_unlock(&tofree_list_lock);
17462 + list_for_each_entry_safe(cur,next,&free_list,list){
17463 + if(cur==&free_list) break;
17464 + dma_free_coherent(NULL,cur->size,cur->addr,cur->dma_addr);
17465 + list_del(&cur->list);
17469 +DECLARE_WORK(free_list_agent,free_list_agent_fn);
17471 + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
17473 +void dwc_otg_ep_free_desc_chain(dwc_otg_dma_desc_t* desc_addr, uint32_t dma_desc_addr, uint32_t count)
17475 + if(irqs_disabled()){
17476 + struct free_param* fp=kmalloc(sizeof(struct free_param),GFP_KERNEL);
17477 + fp->addr=desc_addr;
17478 + fp->dma_addr=dma_desc_addr;
17479 + fp->size=count*sizeof(dwc_otg_dma_desc_t);
17481 + spin_lock(&tofree_list_lock);
17482 + list_add(&fp->list,&tofree_list);
17483 + spin_unlock(&tofree_list_lock);
17485 + schedule_work(&free_list_agent);
17488 + dma_free_coherent(NULL, count * sizeof(dwc_otg_dma_desc_t), desc_addr, dma_desc_addr);
17491 +#ifdef DWC_EN_ISOC
17494 + * This function initializes a descriptor chain for Isochronous transfer
17496 + * @param core_if Programming view of DWC_otg controller.
17497 + * @param dwc_ep The EP to start the transfer on.
17500 +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
17503 + dsts_data_t dsts = { .d32 = 0};
17504 + depctl_data_t depctl = { .d32 = 0 };
17505 + volatile uint32_t *addr;
17508 + if(dwc_ep->is_in)
17509 + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
17511 + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm / dwc_ep->bInterval;
17514 + /** Allocate descriptors for double buffering */
17515 + dwc_ep->iso_desc_addr = dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,dwc_ep->desc_cnt*2);
17516 + if(dwc_ep->desc_addr) {
17517 + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
17521 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
17523 + /** ISO OUT EP */
17524 + if(dwc_ep->is_in == 0) {
17525 + desc_sts_data_t sts = { .d32 =0 };
17526 + dwc_otg_dma_desc_t* dma_desc = dwc_ep->iso_desc_addr;
17527 + dma_addr_t dma_ad;
17528 + uint32_t data_per_desc;
17529 + dwc_otg_dev_out_ep_regs_t *out_regs =
17530 + core_if->dev_if->out_ep_regs[dwc_ep->num];
17533 + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
17534 + dma_ad = (dma_addr_t)dwc_read_reg32(&(out_regs->doepdma));
17536 + /** Buffer 0 descriptors setup */
17537 + dma_ad = dwc_ep->dma_addr0;
17539 + sts.b_iso_out.bs = BS_HOST_READY;
17540 + sts.b_iso_out.rxsts = 0;
17541 + sts.b_iso_out.l = 0;
17542 + sts.b_iso_out.sp = 0;
17543 + sts.b_iso_out.ioc = 0;
17544 + sts.b_iso_out.pid = 0;
17545 + sts.b_iso_out.framenum = 0;
17548 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
17551 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
17553 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
17554 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
17556 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
17557 + sts.b_iso_out.rxbytes = data_per_desc;
17558 + writel((uint32_t)dma_ad, &dma_desc->buf);
17559 + writel(sts.d32, &dma_desc->status);
17561 + offset += data_per_desc;
17563 + //(uint32_t)dma_ad += data_per_desc;
17564 + dma_ad = (uint32_t)dma_ad + data_per_desc;
17568 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
17570 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
17571 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
17572 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
17573 + sts.b_iso_out.rxbytes = data_per_desc;
17574 + writel((uint32_t)dma_ad, &dma_desc->buf);
17575 + writel(sts.d32, &dma_desc->status);
17577 + offset += data_per_desc;
17579 + //(uint32_t)dma_ad += data_per_desc;
17580 + dma_ad = (uint32_t)dma_ad + data_per_desc;
17583 + sts.b_iso_out.ioc = 1;
17584 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
17585 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
17586 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
17587 + sts.b_iso_out.rxbytes = data_per_desc;
17589 + writel((uint32_t)dma_ad, &dma_desc->buf);
17590 + writel(sts.d32, &dma_desc->status);
17593 + /** Buffer 1 descriptors setup */
17594 + sts.b_iso_out.ioc = 0;
17595 + dma_ad = dwc_ep->dma_addr1;
17598 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
17600 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
17602 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
17603 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
17604 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
17605 + sts.b_iso_out.rxbytes = data_per_desc;
17606 + writel((uint32_t)dma_ad, &dma_desc->buf);
17607 + writel(sts.d32, &dma_desc->status);
17609 + offset += data_per_desc;
17611 + //(uint32_t)dma_ad += data_per_desc;
17612 + dma_ad = (uint32_t)dma_ad + data_per_desc;
17615 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
17617 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
17618 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
17619 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
17620 + sts.b_iso_out.rxbytes = data_per_desc;
17621 + writel((uint32_t)dma_ad, &dma_desc->buf);
17622 + writel(sts.d32, &dma_desc->status);
17624 + offset += data_per_desc;
17626 + //(uint32_t)dma_ad += data_per_desc;
17627 + dma_ad = (uint32_t)dma_ad + data_per_desc;
17630 + sts.b_iso_out.ioc = 1;
17631 + sts.b_iso_out.l = 1;
17632 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
17633 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
17634 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
17635 + sts.b_iso_out.rxbytes = data_per_desc;
17637 + writel((uint32_t)dma_ad, &dma_desc->buf);
17638 + writel(sts.d32, &dma_desc->status);
17640 + dwc_ep->next_frame = 0;
17642 + /** Write dma_ad into DOEPDMA register */
17643 + dwc_write_reg32(&(out_regs->doepdma),(uint32_t)dwc_ep->iso_dma_desc_addr);
17648 + desc_sts_data_t sts = { .d32 =0 };
17649 + dwc_otg_dma_desc_t* dma_desc = dwc_ep->iso_desc_addr;
17650 + dma_addr_t dma_ad;
17651 + dwc_otg_dev_in_ep_regs_t *in_regs =
17652 + core_if->dev_if->in_ep_regs[dwc_ep->num];
17653 + unsigned int frmnumber;
17654 + fifosize_data_t txfifosize,rxfifosize;
17656 + txfifosize.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->dtxfsts);
17657 + rxfifosize.d32 = dwc_read_reg32(&core_if->core_global_regs->grxfsiz);
17660 + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
17662 + dma_ad = dwc_ep->dma_addr0;
17664 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
17666 + sts.b_iso_in.bs = BS_HOST_READY;
17667 + sts.b_iso_in.txsts = 0;
17668 + sts.b_iso_in.sp = (dwc_ep->data_per_frame % dwc_ep->maxpacket)? 1 : 0;
17669 + sts.b_iso_in.ioc = 0;
17670 + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
17673 + frmnumber = dwc_ep->next_frame;
17675 + sts.b_iso_in.framenum = frmnumber;
17676 + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
17677 + sts.b_iso_in.l = 0;
17679 + /** Buffer 0 descriptors setup */
17680 + for(i = 0; i < dwc_ep->desc_cnt - 1; i++)
17682 + writel((uint32_t)dma_ad, &dma_desc->buf);
17683 + writel(sts.d32, &dma_desc->status);
17686 + //(uint32_t)dma_ad += dwc_ep->data_per_frame;
17687 + dma_ad = (uint32_t)dma_ad + dwc_ep->data_per_frame;
17688 + sts.b_iso_in.framenum += dwc_ep->bInterval;
17691 + sts.b_iso_in.ioc = 1;
17692 + writel((uint32_t)dma_ad, &dma_desc->buf);
17693 + writel(sts.d32, &dma_desc->status);
17696 + /** Buffer 1 descriptors setup */
17697 + sts.b_iso_in.ioc = 0;
17698 + dma_ad = dwc_ep->dma_addr1;
17700 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
17702 + writel((uint32_t)dma_ad, &dma_desc->buf);
17703 + writel(sts.d32, &dma_desc->status);
17706 + //(uint32_t)dma_ad += dwc_ep->data_per_frame;
17707 + dma_ad = (uint32_t)dma_ad + dwc_ep->data_per_frame;
17708 + sts.b_iso_in.framenum += dwc_ep->bInterval;
17710 + sts.b_iso_in.ioc = 0;
17712 + sts.b_iso_in.ioc = 1;
17713 + sts.b_iso_in.l = 1;
17715 + writel((uint32_t)dma_ad, &dma_desc->buf);
17716 + writel(sts.d32, &dma_desc->status);
17718 + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
17720 + /** Write dma_ad into diepdma register */
17721 + dwc_write_reg32(&(in_regs->diepdma),(uint32_t)dwc_ep->iso_dma_desc_addr);
17723 + /** Enable endpoint, clear nak */
17725 + depctl.b.epena = 1;
17726 + depctl.b.usbactep = 1;
17727 + depctl.b.cnak = 1;
17729 + dwc_modify_reg32(addr, depctl.d32,depctl.d32);
17730 + depctl.d32 = dwc_read_reg32(addr);
17734 + * This function initializes a descriptor chain for Isochronous transfer
17736 + * @param core_if Programming view of DWC_otg controller.
17737 + * @param ep The EP to start the transfer on.
17741 +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
17743 + depctl_data_t depctl = { .d32 = 0 };
17744 + volatile uint32_t *addr;
17748 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
17750 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
17754 + if(core_if->dma_enable == 0 || core_if->dma_desc_enable!= 0) {
17757 + deptsiz_data_t deptsiz = { .d32 = 0 };
17759 + ep->xfer_len = ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
17760 + ep->pkt_cnt = (ep->xfer_len - 1 + ep->maxpacket) /
17762 + ep->xfer_count = 0;
17763 + ep->xfer_buff = (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
17764 + ep->dma_addr = (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
17767 + /* Program the transfer size and packet count
17768 + * as follows: xfersize = N * maxpacket +
17769 + * short_packet pktcnt = N + (short_packet
17772 + deptsiz.b.mc = ep->pkt_per_frm;
17773 + deptsiz.b.xfersize = ep->xfer_len;
17774 + deptsiz.b.pktcnt =
17775 + (ep->xfer_len - 1 + ep->maxpacket) /
17777 + dwc_write_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz, deptsiz.d32);
17779 + /* Write the DMA register */
17780 + dwc_write_reg32 (&(core_if->dev_if->in_ep_regs[ep->num]->diepdma), (uint32_t)ep->dma_addr);
17783 + deptsiz.b.pktcnt =
17784 + (ep->xfer_len + (ep->maxpacket - 1)) /
17786 + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
17788 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
17790 + /* Write the DMA register */
17791 + dwc_write_reg32 (&(core_if->dev_if->out_ep_regs[ep->num]->doepdma), (uint32_t)ep->dma_addr);
17794 + /** Enable endpoint, clear nak */
17796 + dwc_modify_reg32(addr, depctl.d32,depctl.d32);
17798 + depctl.b.epena = 1;
17799 + depctl.b.cnak = 1;
17801 + dwc_modify_reg32(addr, depctl.d32,depctl.d32);
17807 + * This function does the setup for a data transfer for an EP and
17808 + * starts the transfer. For an IN transfer, the packets will be
17809 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
17810 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
17812 + * @param core_if Programming view of DWC_otg controller.
17813 + * @param ep The EP to start the transfer on.
17816 +void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
17818 + if(core_if->dma_enable) {
17819 + if(core_if->dma_desc_enable) {
17821 + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
17823 + ep->desc_cnt = ep->pkt_cnt;
17825 + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
17827 + if(core_if->pti_enh_enable) {
17828 + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
17830 + ep->cur_pkt_addr = (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
17831 + ep->cur_pkt_dma_addr = (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
17832 + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
17836 + ep->cur_pkt_addr = (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
17837 + ep->cur_pkt_dma_addr = (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
17838 + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
17843 + * This function does the setup for a data transfer for an EP and
17844 + * starts the transfer. For an IN transfer, the packets will be
17845 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
17846 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
17848 + * @param core_if Programming view of DWC_otg controller.
17849 + * @param ep The EP to start the transfer on.
17852 +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
17854 + depctl_data_t depctl = { .d32 = 0 };
17855 + volatile uint32_t *addr;
17857 + if(ep->is_in == 1) {
17858 + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
17861 + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
17864 + /* disable the ep */
17865 + depctl.d32 = dwc_read_reg32(addr);
17867 + depctl.b.epdis = 1;
17868 + depctl.b.snak = 1;
17870 + dwc_write_reg32(addr, depctl.d32);
17872 + if(core_if->dma_desc_enable &&
17873 + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
17874 + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,ep->iso_dma_desc_addr,ep->desc_cnt * 2);
17877 + /* reset varibales */
17878 + ep->dma_addr0 = 0;
17879 + ep->dma_addr1 = 0;
17880 + ep->xfer_buff0 = 0;
17881 + ep->xfer_buff1 = 0;
17882 + ep->data_per_frame = 0;
17883 + ep->data_pattern_frame = 0;
17884 + ep->sync_frame = 0;
17885 + ep->buf_proc_intrvl = 0;
17886 + ep->bInterval = 0;
17887 + ep->proc_buf_num = 0;
17888 + ep->pkt_per_frm = 0;
17889 + ep->pkt_per_frm = 0;
17890 + ep->desc_cnt = 0;
17891 + ep->iso_desc_addr = 0;
17892 + ep->iso_dma_desc_addr = 0;
17897 + * This function is used to submit an ISOC Transfer Request to an EP.
17899 + * - Every time a sync period completes the request's completion callback
17900 + * is called to provide data to the gadget driver.
17901 + * - Once submitted the request cannot be modified.
17902 + * - Each request is turned into periodic data packets untill ISO
17903 + * Transfer is stopped..
17905 +static int dwc_otg_pcd_iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
17906 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
17913 + dwc_otg_pcd_ep_t *ep;
17914 + dwc_otg_pcd_t *pcd;
17915 + dwc_ep_t *dwc_ep;
17916 + unsigned long flags = 0;
17917 + int32_t frm_data;
17918 + dwc_otg_core_if_t *core_if;
17919 + dcfg_data_t dcfg;
17920 + dsts_data_t dsts;
17923 + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
17924 + DWC_WARN("%s, bad params\n", __func__);
17928 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
17930 + if (!usb_ep || !ep->desc || ep->dwc_ep.num == 0) {
17931 + DWC_WARN("%s, bad ep\n", __func__);
17936 + core_if = GET_CORE_IF(pcd);
17938 + dcfg.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dcfg);
17940 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
17941 + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n", pcd->gadget.speed);
17942 + DWC_WARN("%s, bogus device state\n", __func__);
17943 + return -ESHUTDOWN;
17946 + SPIN_LOCK_IRQSAVE(&ep->pcd->lock, flags);
17948 + dwc_ep = &ep->dwc_ep;
17950 + if(ep->iso_req) {
17951 + DWC_WARN("%s, iso request in progress\n", __func__);
17953 + req->status = -EINPROGRESS;
17955 + dwc_ep->dma_addr0 = req->dma0;
17956 + dwc_ep->dma_addr1 = req->dma1;
17958 + dwc_ep->xfer_buff0 = req->buf0;
17959 + dwc_ep->xfer_buff1 = req->buf1;
17961 + ep->iso_req = req;
17963 + dwc_ep->data_per_frame = req->data_per_frame;
17965 + /** @todo - pattern data support is to be implemented in the future */
17966 + dwc_ep->data_pattern_frame = req->data_pattern_frame;
17967 + dwc_ep->sync_frame = req->sync_frame;
17969 + dwc_ep->buf_proc_intrvl = req->buf_proc_intrvl;
17971 + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
17973 + dwc_ep->proc_buf_num = 0;
17975 + dwc_ep->pkt_per_frm = 0;
17976 + frm_data = ep->dwc_ep.data_per_frame;
17977 + while(frm_data > 0) {
17978 + dwc_ep->pkt_per_frm++;
17979 + frm_data -= ep->dwc_ep.maxpacket;
17982 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
17984 + if(req->flags & USB_REQ_ISO_ASAP) {
17985 + dwc_ep->next_frame = dsts.b.soffn + 1;
17986 + if(dwc_ep->bInterval != 1){
17987 + dwc_ep->next_frame = dwc_ep->next_frame + (dwc_ep->bInterval - 1 - dwc_ep->next_frame % dwc_ep->bInterval);
17990 + dwc_ep->next_frame = req->start_frame;
17994 + if(!core_if->pti_enh_enable) {
17995 + dwc_ep->pkt_cnt = dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm / dwc_ep->bInterval;
17997 + dwc_ep->pkt_cnt =
17998 + (dwc_ep->data_per_frame * (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
17999 + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
18002 + if(core_if->dma_desc_enable) {
18003 + dwc_ep->desc_cnt =
18004 + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm / dwc_ep->bInterval;
18007 + dwc_ep->pkt_info = kmalloc(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt, GFP_KERNEL);
18008 + if(!dwc_ep->pkt_info) {
18011 + if(core_if->pti_enh_enable) {
18012 + memset(dwc_ep->pkt_info, 0, sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
18015 + dwc_ep->cur_pkt = 0;
18017 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
18019 + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
18025 + * This function stops ISO EP Periodic Data Transfer.
18027 +static int dwc_otg_pcd_iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
18029 + dwc_otg_pcd_ep_t *ep;
18030 + dwc_otg_pcd_t *pcd;
18031 + dwc_ep_t *dwc_ep;
18032 + unsigned long flags;
18034 + ep = container_of(usb_ep, dwc_otg_pcd_ep_t, ep);
18036 + if (!usb_ep || !ep->desc || ep->dwc_ep.num == 0) {
18037 + DWC_WARN("%s, bad ep\n", __func__);
18043 + if (!pcd->driver || pcd->gadget.speed == USB_SPEED_UNKNOWN) {
18044 + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n", pcd->gadget.speed);
18045 + DWC_WARN("%s, bogus device state\n", __func__);
18046 + return -ESHUTDOWN;
18049 + dwc_ep = &ep->dwc_ep;
18051 + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
18053 + kfree(dwc_ep->pkt_info);
18055 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
18057 + if(ep->iso_req != req) {
18061 + req->status = -ECONNRESET;
18063 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
18072 + * This function is used for perodical data exchnage between PCD and gadget drivers.
18073 + * for Isochronous EPs
18075 + * - Every time a sync period completes this function is called to
18076 + * perform data exchange between PCD and gadget
18078 +void dwc_otg_iso_buffer_done(dwc_otg_pcd_ep_t *ep, dwc_otg_pcd_iso_request_t *req)
18081 + struct usb_gadget_iso_packet_descriptor *iso_packet;
18082 + dwc_ep_t *dwc_ep;
18084 + dwc_ep = &ep->dwc_ep;
18086 + if(ep->iso_req->status == -ECONNRESET) {
18087 + DWC_PRINT("Device has already disconnected\n");
18088 + /*Device has been disconnected*/
18092 + if(dwc_ep->proc_buf_num != 0) {
18093 + iso_packet = ep->iso_req->iso_packet_desc0;
18097 + iso_packet = ep->iso_req->iso_packet_desc1;
18100 + /* Fill in ISOC packets descriptors & pass to gadget driver*/
18102 + for(i = 0; i < dwc_ep->pkt_cnt; ++i) {
18103 + iso_packet[i].status = dwc_ep->pkt_info[i].status;
18104 + iso_packet[i].offset = dwc_ep->pkt_info[i].offset;
18105 + iso_packet[i].actual_length = dwc_ep->pkt_info[i].length;
18106 + dwc_ep->pkt_info[i].status = 0;
18107 + dwc_ep->pkt_info[i].offset = 0;
18108 + dwc_ep->pkt_info[i].length = 0;
18111 + /* Call callback function to process data buffer */
18112 + ep->iso_req->status = 0;/* success */
18114 + SPIN_UNLOCK(&ep->pcd->lock);
18115 + ep->iso_req->process_buffer(&ep->ep, ep->iso_req);
18116 + SPIN_LOCK(&ep->pcd->lock);
18120 +static struct usb_iso_request *dwc_otg_pcd_alloc_iso_request(struct usb_ep *ep,int packets,
18121 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
18128 + struct usb_iso_request *pReq = NULL;
18129 + uint32_t req_size;
18132 + req_size = sizeof(struct usb_iso_request);
18133 + req_size += (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
18136 + pReq = kmalloc(req_size, gfp_flags);
18138 + DWC_WARN("%s, can't allocate Iso Request\n", __func__);
18141 + pReq->iso_packet_desc0 = (void*) (pReq + 1);
18143 + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
18148 +static void dwc_otg_pcd_free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
18153 +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops =
18157 + .enable = dwc_otg_pcd_ep_enable,
18158 + .disable = dwc_otg_pcd_ep_disable,
18160 + .alloc_request = dwc_otg_pcd_alloc_request,
18161 + .free_request = dwc_otg_pcd_free_request,
18163 + //.alloc_buffer = dwc_otg_pcd_alloc_buffer,
18164 + //.free_buffer = dwc_otg_pcd_free_buffer,
18166 + .queue = dwc_otg_pcd_ep_queue,
18167 + .dequeue = dwc_otg_pcd_ep_dequeue,
18169 + .set_halt = dwc_otg_pcd_ep_set_halt,
18170 + .fifo_status = 0,
18173 + .iso_ep_start = dwc_otg_pcd_iso_ep_start,
18174 + .iso_ep_stop = dwc_otg_pcd_iso_ep_stop,
18175 + .alloc_iso_request = dwc_otg_pcd_alloc_iso_request,
18176 + .free_iso_request = dwc_otg_pcd_free_iso_request,
18182 +static struct usb_ep_ops dwc_otg_pcd_ep_ops =
18184 + .enable = dwc_otg_pcd_ep_enable,
18185 + .disable = dwc_otg_pcd_ep_disable,
18187 + .alloc_request = dwc_otg_pcd_alloc_request,
18188 + .free_request = dwc_otg_pcd_free_request,
18190 +// .alloc_buffer = dwc_otg_pcd_alloc_buffer,
18191 +// .free_buffer = dwc_otg_pcd_free_buffer,
18193 + .queue = dwc_otg_pcd_ep_queue,
18194 + .dequeue = dwc_otg_pcd_ep_dequeue,
18196 + .set_halt = dwc_otg_pcd_ep_set_halt,
18197 + .fifo_status = 0,
18203 +#endif /* DWC_EN_ISOC */
18204 +/* Gadget Operations */
18206 + * The following gadget operations will be implemented in the DWC_otg
18207 + * PCD. Functions in the API that are not described below are not
18210 + * The Gadget API provides wrapper functions for each of the function
18211 + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
18212 + * wrapper function, which then calls the underlying PCD function. The
18213 + * following sections are named according to the wrapper functions
18214 + * (except for ioctl, which doesn't have a wrapper function). Within
18215 + * each section, the corresponding DWC_otg PCD function name is
18221 + *Gets the USB Frame number of the last SOF.
18223 +static int dwc_otg_pcd_get_frame(struct usb_gadget *gadget)
18225 + dwc_otg_pcd_t *pcd;
18227 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, gadget);
18229 + if (gadget == 0) {
18233 + pcd = container_of(gadget, dwc_otg_pcd_t, gadget);
18234 + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
18240 +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t *pcd)
18242 + uint32_t *addr = (uint32_t *)&(GET_CORE_IF(pcd)->core_global_regs->gotgctl);
18243 + gotgctl_data_t mem;
18244 + gotgctl_data_t val;
18246 + val.d32 = dwc_read_reg32(addr);
18247 + if (val.b.sesreq) {
18248 + DWC_ERROR("Session Request Already active!\n");
18252 + DWC_NOTICE("Session Request Initated\n");
18253 + mem.d32 = dwc_read_reg32(addr);
18254 + mem.b.sesreq = 1;
18255 + dwc_write_reg32(addr, mem.d32);
18257 + /* Start the SRP timer */
18258 + dwc_otg_pcd_start_srp_timer(pcd);
18262 +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t *pcd, int set)
18264 + dctl_data_t dctl = {.d32=0};
18265 + volatile uint32_t *addr = &(GET_CORE_IF(pcd)->dev_if->dev_global_regs->dctl);
18267 + if (dwc_otg_is_device_mode(GET_CORE_IF(pcd))) {
18268 + if (pcd->remote_wakeup_enable) {
18270 + dctl.b.rmtwkupsig = 1;
18271 + dwc_modify_reg32(addr, 0, dctl.d32);
18272 + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
18274 + dwc_modify_reg32(addr, dctl.d32, 0);
18275 + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
18281 + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
18288 + * Initiates Session Request Protocol (SRP) to wakeup the host if no
18289 + * session is in progress. If a session is already in progress, but
18290 + * the device is suspended, remote wakeup signaling is started.
18293 +static int dwc_otg_pcd_wakeup(struct usb_gadget *gadget)
18295 + unsigned long flags;
18296 + dwc_otg_pcd_t *pcd;
18297 + dsts_data_t dsts;
18298 + gotgctl_data_t gotgctl;
18300 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, gadget);
18302 + if (gadget == 0) {
18306 + pcd = container_of(gadget, dwc_otg_pcd_t, gadget);
18308 + SPIN_LOCK_IRQSAVE(&pcd->lock, flags);
18311 + * This function starts the Protocol if no session is in progress. If
18312 + * a session is already in progress, but the device is suspended,
18313 + * remote wakeup signaling is started.
18316 + /* Check if valid session */
18317 + gotgctl.d32 = dwc_read_reg32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
18318 + if (gotgctl.b.bsesvld) {
18319 + /* Check if suspend state */
18320 + dsts.d32 = dwc_read_reg32(&(GET_CORE_IF(pcd)->dev_if->dev_global_regs->dsts));
18321 + if (dsts.b.suspsts) {
18322 + dwc_otg_pcd_remote_wakeup(pcd, 1);
18326 + dwc_otg_pcd_initiate_srp(pcd);
18329 + SPIN_UNLOCK_IRQRESTORE(&pcd->lock, flags);
18333 +static const struct usb_gadget_ops dwc_otg_pcd_ops =
18335 + .get_frame = dwc_otg_pcd_get_frame,
18336 + .wakeup = dwc_otg_pcd_wakeup,
18337 + // current versions must always be self-powered
18341 + * This function updates the otg values in the gadget structure.
18343 +void dwc_otg_pcd_update_otg(dwc_otg_pcd_t *pcd, const unsigned reset)
18346 + if (!pcd->gadget.is_otg)
18350 + pcd->b_hnp_enable = 0;
18351 + pcd->a_hnp_support = 0;
18352 + pcd->a_alt_hnp_support = 0;
18355 + pcd->gadget.b_hnp_enable = pcd->b_hnp_enable;
18356 + pcd->gadget.a_hnp_support = pcd->a_hnp_support;
18357 + pcd->gadget.a_alt_hnp_support = pcd->a_alt_hnp_support;
18361 + * This function is the top level PCD interrupt handler.
18363 +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev
18364 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
18365 + , struct pt_regs *r
18369 + dwc_otg_pcd_t *pcd = dev;
18370 + int32_t retval = IRQ_NONE;
18372 + retval = dwc_otg_pcd_handle_intr(pcd);
18373 + return IRQ_RETVAL(retval);
18377 + * PCD Callback function for initializing the PCD when switching to
18380 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
18382 +static int32_t dwc_otg_pcd_start_cb(void *p)
18384 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
18387 + * Initialized the Core for Device mode.
18389 + if (dwc_otg_is_device_mode(GET_CORE_IF(pcd))) {
18390 + dwc_otg_core_dev_init(GET_CORE_IF(pcd));
18396 + * PCD Callback function for stopping the PCD when switching to Host
18399 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
18401 +static int32_t dwc_otg_pcd_stop_cb(void *p)
18403 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
18404 + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t *_pcd);
18406 + dwc_otg_pcd_stop(pcd);
18412 + * PCD Callback function for notifying the PCD when resuming from
18415 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
18417 +static int32_t dwc_otg_pcd_suspend_cb(void *p)
18419 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
18421 + if (pcd->driver && pcd->driver->resume) {
18422 + SPIN_UNLOCK(&pcd->lock);
18423 + pcd->driver->suspend(&pcd->gadget);
18424 + SPIN_LOCK(&pcd->lock);
18432 + * PCD Callback function for notifying the PCD when resuming from
18435 + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
18437 +static int32_t dwc_otg_pcd_resume_cb(void *p)
18439 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)p;
18441 + if (pcd->driver && pcd->driver->resume) {
18442 + SPIN_UNLOCK(&pcd->lock);
18443 + pcd->driver->resume(&pcd->gadget);
18444 + SPIN_LOCK(&pcd->lock);
18447 + /* Stop the SRP timeout timer. */
18448 + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS) ||
18449 + (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
18450 + if (GET_CORE_IF(pcd)->srp_timer_started) {
18451 + GET_CORE_IF(pcd)->srp_timer_started = 0;
18452 + del_timer(&pcd->srp_timer);
18460 + * PCD Callback structure for handling mode switching.
18462 +static dwc_otg_cil_callbacks_t pcd_callbacks =
18464 + .start = dwc_otg_pcd_start_cb,
18465 + .stop = dwc_otg_pcd_stop_cb,
18466 + .suspend = dwc_otg_pcd_suspend_cb,
18467 + .resume_wakeup = dwc_otg_pcd_resume_cb,
18468 + .p = 0, /* Set at registration */
18472 + * This function is called when the SRP timer expires. The SRP should
18473 + * complete within 6 seconds.
18475 +static void srp_timeout(unsigned long ptr)
18477 + gotgctl_data_t gotgctl;
18478 + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *)ptr;
18479 + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
18481 + gotgctl.d32 = dwc_read_reg32(addr);
18483 + core_if->srp_timer_started = 0;
18485 + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
18486 + (core_if->core_params->i2c_enable)) {
18487 + DWC_PRINT("SRP Timeout\n");
18489 + if ((core_if->srp_success) &&
18490 + (gotgctl.b.bsesvld)) {
18491 + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
18492 + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
18495 + /* Clear Session Request */
18497 + gotgctl.b.sesreq = 1;
18498 + dwc_modify_reg32(&core_if->core_global_regs->gotgctl,
18501 + core_if->srp_success = 0;
18504 + DWC_ERROR("Device not connected/responding\n");
18505 + gotgctl.b.sesreq = 0;
18506 + dwc_write_reg32(addr, gotgctl.d32);
18509 + else if (gotgctl.b.sesreq) {
18510 + DWC_PRINT("SRP Timeout\n");
18512 + DWC_ERROR("Device not connected/responding\n");
18513 + gotgctl.b.sesreq = 0;
18514 + dwc_write_reg32(addr, gotgctl.d32);
18517 + DWC_PRINT(" SRP GOTGCTL=%0x\n", gotgctl.d32);
18522 + * Start the SRP timer to detect when the SRP does not complete within
18525 + * @param pcd the pcd structure.
18527 +void dwc_otg_pcd_start_srp_timer(dwc_otg_pcd_t *pcd)
18529 + struct timer_list *srp_timer = &pcd->srp_timer;
18530 + GET_CORE_IF(pcd)->srp_timer_started = 1;
18531 + init_timer(srp_timer);
18532 + srp_timer->function = srp_timeout;
18533 + srp_timer->data = (unsigned long)GET_CORE_IF(pcd);
18534 + srp_timer->expires = jiffies + (HZ*6);
18535 + add_timer(srp_timer);
18542 +extern void start_next_request(dwc_otg_pcd_ep_t *ep);
18544 +static void start_xfer_tasklet_func (unsigned long data)
18546 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t*)data;
18547 + dwc_otg_core_if_t *core_if = pcd->otg_dev->core_if;
18550 + depctl_data_t diepctl;
18552 + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
18554 + diepctl.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[0]->diepctl);
18556 + if (pcd->ep0.queue_sof) {
18557 + pcd->ep0.queue_sof = 0;
18558 + start_next_request (&pcd->ep0);
18562 + for (i=0; i<core_if->dev_if->num_in_eps; i++)
18564 + depctl_data_t diepctl;
18565 + diepctl.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[i]->diepctl);
18567 + if (pcd->in_ep[i].queue_sof) {
18568 + pcd->in_ep[i].queue_sof = 0;
18569 + start_next_request (&pcd->in_ep[i]);
18583 +static struct tasklet_struct start_xfer_tasklet = {
18586 + .count = ATOMIC_INIT(0),
18587 + .func = start_xfer_tasklet_func,
18591 + * This function initialized the pcd Dp structures to there default
18594 + * @param pcd the pcd structure.
18596 +void dwc_otg_pcd_reinit(dwc_otg_pcd_t *pcd)
18598 + static const char * names[] =
18636 + int in_ep_cntr, out_ep_cntr;
18638 + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
18639 + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
18640 + dwc_otg_pcd_ep_t *ep;
18642 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
18644 + INIT_LIST_HEAD (&pcd->gadget.ep_list);
18645 + pcd->gadget.ep0 = &pcd->ep0.ep;
18646 + pcd->gadget.speed = USB_SPEED_UNKNOWN;
18648 + INIT_LIST_HEAD (&pcd->gadget.ep0->ep_list);
18651 + * Initialize the EP0 structure.
18655 + /* Init EP structure */
18660 + /* Init DWC ep structure */
18661 + ep->dwc_ep.num = 0;
18662 + ep->dwc_ep.active = 0;
18663 + ep->dwc_ep.tx_fifo_num = 0;
18664 + /* Control until ep is actvated */
18665 + ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
18666 + ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
18667 + ep->dwc_ep.dma_addr = 0;
18668 + ep->dwc_ep.start_xfer_buff = 0;
18669 + ep->dwc_ep.xfer_buff = 0;
18670 + ep->dwc_ep.xfer_len = 0;
18671 + ep->dwc_ep.xfer_count = 0;
18672 + ep->dwc_ep.sent_zlp = 0;
18673 + ep->dwc_ep.total_len = 0;
18674 + ep->queue_sof = 0;
18675 + ep->dwc_ep.desc_addr = 0;
18676 + ep->dwc_ep.dma_desc_addr = 0;
18678 + ep->dwc_ep.aligned_buf=NULL;
18679 + ep->dwc_ep.aligned_buf_size=0;
18680 + ep->dwc_ep.aligned_dma_addr=0;
18683 + /* Init the usb_ep structure. */
18684 + ep->ep.name = names[0];
18685 + ep->ep.ops = (struct usb_ep_ops*)&dwc_otg_pcd_ep_ops;
18688 + * @todo NGS: What should the max packet size be set to
18689 + * here? Before EP type is set?
18691 + ep->ep.maxpacket = MAX_PACKET_SIZE;
18693 + list_add_tail (&ep->ep.ep_list, &pcd->gadget.ep_list);
18695 + INIT_LIST_HEAD (&ep->queue);
18697 + * Initialize the EP structures.
18700 + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
18702 + for (i = 1; in_ep_cntr < num_in_eps; i++)
18704 + if((hwcfg1 & 0x1) == 0) {
18705 + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
18708 + /* Init EP structure */
18713 + /* Init DWC ep structure */
18714 + ep->dwc_ep.is_in = 1;
18715 + ep->dwc_ep.num = i;
18716 + ep->dwc_ep.active = 0;
18717 + ep->dwc_ep.tx_fifo_num = 0;
18719 + /* Control until ep is actvated */
18720 + ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
18721 + ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
18722 + ep->dwc_ep.dma_addr = 0;
18723 + ep->dwc_ep.start_xfer_buff = 0;
18724 + ep->dwc_ep.xfer_buff = 0;
18725 + ep->dwc_ep.xfer_len = 0;
18726 + ep->dwc_ep.xfer_count = 0;
18727 + ep->dwc_ep.sent_zlp = 0;
18728 + ep->dwc_ep.total_len = 0;
18729 + ep->queue_sof = 0;
18730 + ep->dwc_ep.desc_addr = 0;
18731 + ep->dwc_ep.dma_desc_addr = 0;
18733 + /* Init the usb_ep structure. */
18734 + ep->ep.name = names[i];
18735 + ep->ep.ops = (struct usb_ep_ops*)&dwc_otg_pcd_ep_ops;
18738 + * @todo NGS: What should the max packet size be set to
18739 + * here? Before EP type is set?
18741 + ep->ep.maxpacket = MAX_PACKET_SIZE;
18743 + //add only even number ep as in
18745 + list_add_tail (&ep->ep.ep_list, &pcd->gadget.ep_list);
18747 + INIT_LIST_HEAD (&ep->queue);
18753 + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
18755 + for (i = 1; out_ep_cntr < num_out_eps; i++)
18757 + if((hwcfg1 & 0x1) == 0) {
18758 + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
18761 + /* Init EP structure */
18766 + /* Init DWC ep structure */
18767 + ep->dwc_ep.is_in = 0;
18768 + ep->dwc_ep.num = i;
18769 + ep->dwc_ep.active = 0;
18770 + ep->dwc_ep.tx_fifo_num = 0;
18771 + /* Control until ep is actvated */
18772 + ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
18773 + ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
18774 + ep->dwc_ep.dma_addr = 0;
18775 + ep->dwc_ep.start_xfer_buff = 0;
18776 + ep->dwc_ep.xfer_buff = 0;
18777 + ep->dwc_ep.xfer_len = 0;
18778 + ep->dwc_ep.xfer_count = 0;
18779 + ep->dwc_ep.sent_zlp = 0;
18780 + ep->dwc_ep.total_len = 0;
18781 + ep->queue_sof = 0;
18783 + /* Init the usb_ep structure. */
18784 + ep->ep.name = names[15 + i];
18785 + ep->ep.ops = (struct usb_ep_ops*)&dwc_otg_pcd_ep_ops;
18787 + * @todo NGS: What should the max packet size be set to
18788 + * here? Before EP type is set?
18790 + ep->ep.maxpacket = MAX_PACKET_SIZE;
18792 + //add only odd number ep as out
18794 + list_add_tail (&ep->ep.ep_list, &pcd->gadget.ep_list);
18796 + INIT_LIST_HEAD (&ep->queue);
18801 + /* remove ep0 from the list. There is a ep0 pointer.*/
18802 + list_del_init (&pcd->ep0.ep.ep_list);
18804 + pcd->ep0state = EP0_DISCONNECT;
18805 + pcd->ep0.ep.maxpacket = MAX_EP0_SIZE;
18806 + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
18807 + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
18811 + * This function releases the Gadget device.
18812 + * required by device_unregister().
18814 + * @todo Should this do something? Should it free the PCD?
18816 +static void dwc_otg_pcd_gadget_release(struct device *dev)
18818 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, dev);
18824 + * This function initialized the PCD portion of the driver.
18827 +u8 dev_id[]="gadget";
18828 +int dwc_otg_pcd_init(struct lm_device *lmdev)
18830 + static char pcd_name[] = "dwc_otg_pcd";
18831 + dwc_otg_pcd_t *pcd;
18832 + dwc_otg_core_if_t* core_if;
18833 + dwc_otg_dev_if_t* dev_if;
18834 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lmdev);
18838 + DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n",__func__, lmdev);
18840 + * Allocate PCD structure
18842 + pcd = kmalloc(sizeof(dwc_otg_pcd_t), GFP_KERNEL);
18848 + memset(pcd, 0, sizeof(dwc_otg_pcd_t));
18849 + spin_lock_init(&pcd->lock);
18851 + otg_dev->pcd = pcd;
18853 + pcd->gadget.name = pcd_name;
18855 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
18856 + strcpy(pcd->gadget.dev.bus_id, "gadget");
18858 + pcd->gadget.dev.init_name = dev_id;
18860 + pcd->otg_dev = lm_get_drvdata(lmdev);
18862 + pcd->gadget.dev.parent = &lmdev->dev;
18863 + pcd->gadget.dev.release = dwc_otg_pcd_gadget_release;
18864 + pcd->gadget.ops = &dwc_otg_pcd_ops;
18866 + core_if = GET_CORE_IF(pcd);
18867 + dev_if = core_if->dev_if;
18869 + if(core_if->hwcfg4.b.ded_fifo_en) {
18870 + DWC_PRINT("Dedicated Tx FIFOs mode\n");
18873 + DWC_PRINT("Shared Tx FIFO mode\n");
18876 + /* If the module is set to FS or if the PHY_TYPE is FS then the gadget
18877 + * should not report as dual-speed capable. replace the following line
18878 + * with the block of code below it once the software is debugged for
18879 + * this. If is_dualspeed = 0 then the gadget driver should not report
18880 + * a device qualifier descriptor when queried. */
18881 + if ((GET_CORE_IF(pcd)->core_params->speed == DWC_SPEED_PARAM_FULL) ||
18882 + ((GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == 2) &&
18883 + (GET_CORE_IF(pcd)->hwcfg2.b.fs_phy_type == 1) &&
18884 + (GET_CORE_IF(pcd)->core_params->ulpi_fs_ls))) {
18885 + pcd->gadget.is_dualspeed = 0;
18888 + pcd->gadget.is_dualspeed = 1;
18891 + if ((otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE) ||
18892 + (otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST) ||
18893 + (otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
18894 + (otg_dev->core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
18895 + pcd->gadget.is_otg = 0;
18898 + pcd->gadget.is_otg = 1;
18903 + /* Register the gadget device */
18904 +printk("%s: 1\n",__func__);
18905 + retval = device_register(&pcd->gadget.dev);
18906 + if (retval != 0) {
18908 +printk("%s: 2\n",__func__);
18914 + * Initialized the Core for Device mode.
18916 + if (dwc_otg_is_device_mode(core_if)) {
18917 + dwc_otg_core_dev_init(core_if);
18921 + * Initialize EP structures
18923 + dwc_otg_pcd_reinit(pcd);
18926 + * Register the PCD Callbacks.
18928 + dwc_otg_cil_register_pcd_callbacks(otg_dev->core_if, &pcd_callbacks,
18931 + * Setup interupt handler
18933 + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n", lmdev->irq);
18934 + retval = request_irq(lmdev->irq, dwc_otg_pcd_irq,
18935 + IRQF_SHARED, pcd->gadget.name, pcd);
18936 + if (retval != 0) {
18937 + DWC_ERROR("request of irq%d failed\n", lmdev->irq);
18938 + device_unregister(&pcd->gadget.dev);
18944 + * Initialize the DMA buffer for SETUP packets
18946 + if (GET_CORE_IF(pcd)->dma_enable) {
18947 + pcd->setup_pkt = dma_alloc_coherent (NULL, sizeof (*pcd->setup_pkt) * 5, &pcd->setup_pkt_dma_handle, 0);
18948 + if (pcd->setup_pkt == 0) {
18949 + free_irq(lmdev->irq, pcd);
18950 + device_unregister(&pcd->gadget.dev);
18955 + pcd->status_buf = dma_alloc_coherent (NULL, sizeof (uint16_t), &pcd->status_buf_dma_handle, 0);
18956 + if (pcd->status_buf == 0) {
18957 + dma_free_coherent(NULL, sizeof(*pcd->setup_pkt), pcd->setup_pkt, pcd->setup_pkt_dma_handle);
18958 + free_irq(lmdev->irq, pcd);
18959 + device_unregister(&pcd->gadget.dev);
18964 + if (GET_CORE_IF(pcd)->dma_desc_enable) {
18965 + dev_if->setup_desc_addr[0] = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_setup_desc_addr[0], 1);
18966 + dev_if->setup_desc_addr[1] = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_setup_desc_addr[1], 1);
18967 + dev_if->in_desc_addr = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_in_desc_addr, 1);
18968 + dev_if->out_desc_addr = dwc_otg_ep_alloc_desc_chain(&dev_if->dma_out_desc_addr, 1);
18970 + if(dev_if->setup_desc_addr[0] == 0
18971 + || dev_if->setup_desc_addr[1] == 0
18972 + || dev_if->in_desc_addr == 0
18973 + || dev_if->out_desc_addr == 0 ) {
18975 + if(dev_if->out_desc_addr)
18976 + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr, dev_if->dma_out_desc_addr, 1);
18977 + if(dev_if->in_desc_addr)
18978 + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr, dev_if->dma_in_desc_addr, 1);
18979 + if(dev_if->setup_desc_addr[1])
18980 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1], dev_if->dma_setup_desc_addr[1], 1);
18981 + if(dev_if->setup_desc_addr[0])
18982 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0], dev_if->dma_setup_desc_addr[0], 1);
18985 + dma_free_coherent(NULL, sizeof(*pcd->status_buf), pcd->status_buf, pcd->setup_pkt_dma_handle);
18986 + dma_free_coherent(NULL, sizeof(*pcd->setup_pkt), pcd->setup_pkt, pcd->setup_pkt_dma_handle);
18988 + free_irq(lmdev->irq, pcd);
18989 + device_unregister(&pcd->gadget.dev);
18997 + pcd->setup_pkt = kmalloc (sizeof (*pcd->setup_pkt) * 5, GFP_KERNEL);
18998 + if (pcd->setup_pkt == 0) {
18999 + free_irq(lmdev->irq, pcd);
19000 + device_unregister(&pcd->gadget.dev);
19005 + pcd->status_buf = kmalloc (sizeof (uint16_t), GFP_KERNEL);
19006 + if (pcd->status_buf == 0) {
19007 + kfree(pcd->setup_pkt);
19008 + free_irq(lmdev->irq, pcd);
19009 + device_unregister(&pcd->gadget.dev);
19016 + /* Initialize tasklet */
19017 + start_xfer_tasklet.data = (unsigned long)pcd;
19018 + pcd->start_xfer_tasklet = &start_xfer_tasklet;
19024 + * Cleanup the PCD.
19026 +void dwc_otg_pcd_remove(struct lm_device *lmdev)
19028 + dwc_otg_device_t *otg_dev = lm_get_drvdata(lmdev);
19029 + dwc_otg_pcd_t *pcd = otg_dev->pcd;
19030 + dwc_otg_dev_if_t* dev_if = GET_CORE_IF(pcd)->dev_if;
19032 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, lmdev);
19037 + free_irq(lmdev->irq, pcd);
19039 + /* start with the driver above us */
19040 + if (pcd->driver) {
19041 + /* should have been done already by driver model core */
19042 + DWC_WARN("driver '%s' is still registered\n",
19043 + pcd->driver->driver.name);
19044 + usb_gadget_unregister_driver(pcd->driver);
19046 + device_unregister(&pcd->gadget.dev);
19048 + if (GET_CORE_IF(pcd)->dma_enable) {
19049 + dma_free_coherent (NULL, sizeof (*pcd->setup_pkt) * 5, pcd->setup_pkt, pcd->setup_pkt_dma_handle);
19050 + dma_free_coherent (NULL, sizeof (uint16_t), pcd->status_buf, pcd->status_buf_dma_handle);
19051 + if (GET_CORE_IF(pcd)->dma_desc_enable) {
19052 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0], dev_if->dma_setup_desc_addr[0], 1);
19053 + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1], dev_if->dma_setup_desc_addr[1], 1);
19054 + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr, dev_if->dma_in_desc_addr, 1);
19055 + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr, dev_if->dma_out_desc_addr, 1);
19059 + kfree (pcd->setup_pkt);
19060 + kfree (pcd->status_buf);
19064 + otg_dev->pcd = 0;
19068 + * This function registers a gadget driver with the PCD.
19070 + * When a driver is successfully registered, it will receive control
19071 + * requests including set_configuration(), which enables non-control
19072 + * requests. then usb traffic follows until a disconnect is reported.
19073 + * then a host may connect again, or the driver might get unbound.
19075 + * @param driver The driver being registered
19077 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
19081 + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n", driver->driver.name);
19083 + if (!driver || driver->speed == USB_SPEED_UNKNOWN ||
19085 + !driver->unbind ||
19086 + !driver->disconnect ||
19087 + !driver->setup) {
19088 + DWC_DEBUGPL(DBG_PCDV,"EINVAL\n");
19091 + if (s_pcd == 0) {
19092 + DWC_DEBUGPL(DBG_PCDV,"ENODEV\n");
19095 + if (s_pcd->driver != 0) {
19096 + DWC_DEBUGPL(DBG_PCDV,"EBUSY (%p)\n", s_pcd->driver);
19100 + /* hook up the driver */
19101 + s_pcd->driver = driver;
19102 + s_pcd->gadget.dev.driver = &driver->driver;
19104 + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
19105 + retval = driver->bind(&s_pcd->gadget);
19107 + DWC_ERROR("bind to driver %s --> error %d\n",
19108 + driver->driver.name, retval);
19109 + s_pcd->driver = 0;
19110 + s_pcd->gadget.dev.driver = 0;
19113 + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
19114 + driver->driver.name);
19118 +EXPORT_SYMBOL(usb_gadget_register_driver);
19121 + * This function unregisters a gadget driver
19123 + * @param driver The driver being unregistered
19125 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
19127 + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
19129 + if (s_pcd == 0) {
19130 + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
19134 + if (driver == 0 || driver != s_pcd->driver) {
19135 + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
19140 + driver->unbind(&s_pcd->gadget);
19141 + s_pcd->driver = 0;
19143 + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n",
19144 + driver->driver.name);
19147 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
19149 +#endif /* DWC_HOST_ONLY */
19151 +++ b/drivers/usb/host/otg/dwc_otg_pcd.h
19153 +/* ==========================================================================
19154 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
19155 + * $Revision: #36 $
19156 + * $Date: 2008/09/26 $
19157 + * $Change: 1103515 $
19159 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
19160 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
19161 + * otherwise expressly agreed to in writing between Synopsys and you.
19163 + * The Software IS NOT an item of Licensed Software or Licensed Product under
19164 + * any End User Software License Agreement or Agreement for Licensed Product
19165 + * with Synopsys or any supplement thereto. You are permitted to use and
19166 + * redistribute this Software in source and binary forms, with or without
19167 + * modification, provided that redistributions of source code must retain this
19168 + * notice. You may not view, use, disclose, copy or distribute this file or
19169 + * any information contained herein except pursuant to this license grant from
19170 + * Synopsys. If you do not agree with this notice, including the disclaimer
19171 + * below, then you are not authorized to use the Software.
19173 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
19174 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19175 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19176 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
19177 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19178 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19179 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19180 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19181 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
19182 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
19184 + * ========================================================================== */
19185 +#ifndef DWC_HOST_ONLY
19186 +#if !defined(__DWC_PCD_H__)
19187 +#define __DWC_PCD_H__
19189 +#include <linux/types.h>
19190 +#include <linux/list.h>
19191 +#include <linux/errno.h>
19192 +#include <linux/device.h>
19194 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
19195 +# include <linux/usb/ch9.h>
19196 +# include <linux/usb/gadget.h>
19198 +# include <linux/usb_ch9.h>
19199 +# include <linux/usb_gadget.h>
19202 +#include <linux/interrupt.h>
19203 +#include <linux/dma-mapping.h>
19206 +struct dwc_otg_device;
19208 +#include "dwc_otg_cil.h"
19213 + * This file contains the structures, constants, and interfaces for
19214 + * the Perpherial Contoller Driver (PCD).
19216 + * The Peripheral Controller Driver (PCD) for Linux will implement the
19217 + * Gadget API, so that the existing Gadget drivers can be used. For
19218 + * the Mass Storage Function driver the File-backed USB Storage Gadget
19219 + * (FBS) driver will be used. The FBS driver supports the
19220 + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
19225 +/** Invalid DMA Address */
19226 +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
19227 +/** Maxpacket size for EP0 */
19228 +#define MAX_EP0_SIZE 64
19229 +/** Maxpacket size for any EP */
19230 +#define MAX_PACKET_SIZE 1024
19232 +/** Max Transfer size for any EP */
19233 +#define MAX_TRANSFER_SIZE 65535
19235 +/** Max DMA Descriptor count for any EP */
19236 +#define MAX_DMA_DESC_CNT 64
19239 + * Get the pointer to the core_if from the pcd pointer.
19241 +#define GET_CORE_IF( _pcd ) (_pcd->otg_dev->core_if)
19246 +typedef enum ep0_state
19248 + EP0_DISCONNECT, /* no host */
19250 + EP0_IN_DATA_PHASE,
19251 + EP0_OUT_DATA_PHASE,
19252 + EP0_IN_STATUS_PHASE,
19253 + EP0_OUT_STATUS_PHASE,
19257 +/** Fordward declaration.*/
19258 +struct dwc_otg_pcd;
19260 +/** DWC_otg iso request structure.
19263 +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
19265 +/** PCD EP structure.
19266 + * This structure describes an EP, there is an array of EPs in the PCD
19269 +typedef struct dwc_otg_pcd_ep
19271 + /** USB EP data */
19272 + struct usb_ep ep;
19273 + /** USB EP Descriptor */
19274 + const struct usb_endpoint_descriptor *desc;
19276 + /** queue of dwc_otg_pcd_requests. */
19277 + struct list_head queue;
19278 + unsigned stopped : 1;
19279 + unsigned disabling : 1;
19280 + unsigned dma : 1;
19281 + unsigned queue_sof : 1;
19283 +#ifdef DWC_EN_ISOC
19284 + /** DWC_otg Isochronous Transfer */
19285 + struct usb_iso_request* iso_req;
19286 +#endif //DWC_EN_ISOC
19288 + /** DWC_otg ep data. */
19291 + /** Pointer to PCD */
19292 + struct dwc_otg_pcd *pcd;
19293 +}dwc_otg_pcd_ep_t;
19297 +/** DWC_otg PCD Structure.
19298 + * This structure encapsulates the data for the dwc_otg PCD.
19300 +typedef struct dwc_otg_pcd
19302 + /** USB gadget */
19303 + struct usb_gadget gadget;
19304 + /** USB gadget driver pointer*/
19305 + struct usb_gadget_driver *driver;
19306 + /** The DWC otg device pointer. */
19307 + struct dwc_otg_device *otg_dev;
19309 + /** State of EP0 */
19310 + ep0state_e ep0state;
19311 + /** EP0 Request is pending */
19312 + unsigned ep0_pending : 1;
19313 + /** Indicates when SET CONFIGURATION Request is in process */
19314 + unsigned request_config : 1;
19315 + /** The state of the Remote Wakeup Enable. */
19316 + unsigned remote_wakeup_enable : 1;
19317 + /** The state of the B-Device HNP Enable. */
19318 + unsigned b_hnp_enable : 1;
19319 + /** The state of A-Device HNP Support. */
19320 + unsigned a_hnp_support : 1;
19321 + /** The state of the A-Device Alt HNP support. */
19322 + unsigned a_alt_hnp_support : 1;
19323 + /** Count of pending Requests */
19324 + unsigned request_pending;
19326 + /** SETUP packet for EP0
19327 + * This structure is allocated as a DMA buffer on PCD initialization
19328 + * with enough space for up to 3 setup packets.
19332 + struct usb_ctrlrequest req;
19336 + dma_addr_t setup_pkt_dma_handle;
19338 + /** 2-byte dma buffer used to return status from GET_STATUS */
19339 + uint16_t *status_buf;
19340 + dma_addr_t status_buf_dma_handle;
19343 + dwc_otg_pcd_ep_t ep0;
19345 + /** Array of IN EPs. */
19346 + dwc_otg_pcd_ep_t in_ep[ MAX_EPS_CHANNELS - 1];
19347 + /** Array of OUT EPs. */
19348 + dwc_otg_pcd_ep_t out_ep[ MAX_EPS_CHANNELS - 1];
19349 + /** number of valid EPs in the above array. */
19350 +// unsigned num_eps : 4;
19352 + /** Timer for SRP. If it expires before SRP is successful
19353 + * clear the SRP. */
19354 + struct timer_list srp_timer;
19356 + /** Tasklet to defer starting of TEST mode transmissions until
19357 + * Status Phase has been completed.
19359 + struct tasklet_struct test_mode_tasklet;
19361 + /** Tasklet to delay starting of xfer in DMA mode */
19362 + struct tasklet_struct *start_xfer_tasklet;
19364 + /** The test mode to enter when the tasklet is executed. */
19365 + unsigned test_mode;
19370 +/** DWC_otg request structure.
19371 + * This structure is a list of requests.
19375 + struct usb_request req; /**< USB Request. */
19376 + struct list_head queue; /**< queue of these requests. */
19377 +} dwc_otg_pcd_request_t;
19380 +extern int dwc_otg_pcd_init(struct lm_device *lmdev);
19382 +//extern void dwc_otg_pcd_remove( struct dwc_otg_device *_otg_dev );
19383 +extern void dwc_otg_pcd_remove( struct lm_device *lmdev );
19384 +extern int32_t dwc_otg_pcd_handle_intr( dwc_otg_pcd_t *pcd );
19385 +extern void dwc_otg_pcd_start_srp_timer(dwc_otg_pcd_t *pcd );
19387 +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t *pcd);
19388 +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t *pcd, int set);
19390 +extern void dwc_otg_iso_buffer_done(dwc_otg_pcd_ep_t *ep, dwc_otg_pcd_iso_request_t *req);
19391 +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t *_ep, dwc_otg_pcd_request_t *req,
19393 +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t *_ep);
19394 +extern void dwc_otg_pcd_update_otg(dwc_otg_pcd_t *_pcd,
19395 + const unsigned reset);
19397 +#define VERIFY_PCD_DMA_ADDR(_addr_) BUG_ON(((_addr_)==DMA_ADDR_INVALID)||\
19401 +#define VERIFY_PCD_DMA_ADDR(_addr_) {\
19402 + if(((_addr_)==DMA_ADDR_INVALID)||\
19404 + ((_addr_)&0x3)) {\
19405 + printk("%s: Invalid DMA address "#_addr_"(%.8x)\n",__func__,_addr_);\
19412 +static inline void ep_check_and_patch_dma_addr(dwc_otg_pcd_ep_t *ep){
19413 +//void ep_check_and_patch_dma_addr(dwc_otg_pcd_ep_t *ep){
19414 + dwc_ep_t *dwc_ep=&ep->dwc_ep;
19416 +DWC_DEBUGPL(DBG_PCDV,"%s: dwc_ep xfer_buf=%.8x, total_len=%d, dma_addr=%.8x\n",__func__,(u32)dwc_ep->xfer_buff,(dwc_ep->total_len),dwc_ep->dma_addr);
19417 + if (/*(core_if->dma_enable)&&*/(dwc_ep->dma_addr==DMA_ADDR_INVALID)) {
19418 + if((((u32)dwc_ep->xfer_buff)&0x3)==0){
19419 + dwc_ep->dma_addr=dma_map_single(NULL,(void *)(dwc_ep->start_xfer_buff),(dwc_ep->total_len), DMA_TO_DEVICE);
19420 +DWC_DEBUGPL(DBG_PCDV," got dma_addr=%.8x\n",dwc_ep->dma_addr);
19422 +DWC_DEBUGPL(DBG_PCDV," buf not aligned, use aligned_buf instead. xfer_buf=%.8x, total_len=%d, aligned_buf_size=%d\n",(u32)dwc_ep->xfer_buff,(dwc_ep->total_len),dwc_ep->aligned_buf_size);
19423 + if(dwc_ep->aligned_buf_size<dwc_ep->total_len){
19424 + if(dwc_ep->aligned_buf){
19425 +//printk(" free buff dwc_ep aligned_buf_size=%d, aligned_buf(%.8x), aligned_dma_addr(%.8x));\n",dwc_ep->aligned_buf_size,dwc_ep->aligned_buf,dwc_ep->aligned_dma_addr);
19426 + //dma_free_coherent(NULL,dwc_ep->aligned_buf_size,dwc_ep->aligned_buf,dwc_ep->aligned_dma_addr);
19427 + kfree(dwc_ep->aligned_buf);
19429 + dwc_ep->aligned_buf_size=((1<<20)>(dwc_ep->total_len<<1))?(dwc_ep->total_len<<1):(1<<20);
19430 + //dwc_ep->aligned_buf = dma_alloc_coherent (NULL, dwc_ep->aligned_buf_size, &dwc_ep->aligned_dma_addr, GFP_KERNEL|GFP_DMA);
19431 + dwc_ep->aligned_buf=kmalloc(dwc_ep->aligned_buf_size,GFP_KERNEL|GFP_DMA|GFP_ATOMIC);
19432 + dwc_ep->aligned_dma_addr=dma_map_single(NULL,(void *)(dwc_ep->aligned_buf),(dwc_ep->aligned_buf_size),DMA_FROM_DEVICE);
19433 + if(!dwc_ep->aligned_buf){
19434 + DWC_ERROR("Cannot alloc required buffer!!\n");
19437 +DWC_DEBUGPL(DBG_PCDV," dwc_ep allocated aligned buf=%.8x, dma_addr=%.8x, size=%d(0x%x)\n", (u32)dwc_ep->aligned_buf, dwc_ep->aligned_dma_addr, dwc_ep->aligned_buf_size, dwc_ep->aligned_buf_size);
19439 + dwc_ep->dma_addr=dwc_ep->aligned_dma_addr;
19440 + if(dwc_ep->is_in) {
19441 + memcpy(dwc_ep->aligned_buf,dwc_ep->xfer_buff,dwc_ep->total_len);
19442 + dma_sync_single_for_device(NULL,dwc_ep->dma_addr,dwc_ep->total_len,DMA_TO_DEVICE);
19449 +#endif /* DWC_HOST_ONLY */
19451 +++ b/drivers/usb/host/otg/dwc_otg_pcd_intr.c
19453 +/* ==========================================================================
19454 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
19455 + * $Revision: #83 $
19456 + * $Date: 2008/10/14 $
19457 + * $Change: 1115682 $
19459 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
19460 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
19461 + * otherwise expressly agreed to in writing between Synopsys and you.
19463 + * The Software IS NOT an item of Licensed Software or Licensed Product under
19464 + * any End User Software License Agreement or Agreement for Licensed Product
19465 + * with Synopsys or any supplement thereto. You are permitted to use and
19466 + * redistribute this Software in source and binary forms, with or without
19467 + * modification, provided that redistributions of source code must retain this
19468 + * notice. You may not view, use, disclose, copy or distribute this file or
19469 + * any information contained herein except pursuant to this license grant from
19470 + * Synopsys. If you do not agree with this notice, including the disclaimer
19471 + * below, then you are not authorized to use the Software.
19473 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
19474 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19475 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19476 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
19477 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19478 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19479 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19480 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19481 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
19482 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
19484 + * ========================================================================== */
19485 +#ifndef DWC_HOST_ONLY
19486 +#include <linux/interrupt.h>
19487 +#include <linux/dma-mapping.h>
19488 +#include <linux/version.h>
19489 +#include <linux/pci.h>
19491 +#include "dwc_otg_driver.h"
19492 +#include "dwc_otg_pcd.h"
19498 +/* request functions defined in "dwc_otg_pcd.c" */
19501 + * This file contains the implementation of the PCD Interrupt handlers.
19503 + * The PCD handles the device interrupts. Many conditions can cause a
19504 + * device interrupt. When an interrupt occurs, the device interrupt
19505 + * service routine determines the cause of the interrupt and
19506 + * dispatches handling to the appropriate function. These interrupt
19507 + * handling functions are described below.
19508 + * All interrupt registers are processed from LSB to MSB.
19513 + * This function prints the ep0 state for debug purposes.
19515 +static inline void print_ep0_state(dwc_otg_pcd_t *pcd)
19520 + switch (pcd->ep0state) {
19521 + case EP0_DISCONNECT:
19522 + strcpy(str, "EP0_DISCONNECT");
19525 + strcpy(str, "EP0_IDLE");
19527 + case EP0_IN_DATA_PHASE:
19528 + strcpy(str, "EP0_IN_DATA_PHASE");
19530 + case EP0_OUT_DATA_PHASE:
19531 + strcpy(str, "EP0_OUT_DATA_PHASE");
19533 + case EP0_IN_STATUS_PHASE:
19534 + strcpy(str,"EP0_IN_STATUS_PHASE");
19536 + case EP0_OUT_STATUS_PHASE:
19537 + strcpy(str,"EP0_OUT_STATUS_PHASE");
19540 + strcpy(str,"EP0_STALL");
19543 + strcpy(str,"EP0_INVALID");
19546 + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
19551 + * This function returns pointer to in ep struct with number ep_num
19553 +static inline dwc_otg_pcd_ep_t* get_in_ep(dwc_otg_pcd_t *pcd, uint32_t ep_num)
19556 + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
19557 + if(ep_num == 0) {
19558 + return &pcd->ep0;
19561 + for(i = 0; i < num_in_eps; ++i)
19563 + if(pcd->in_ep[i].dwc_ep.num == ep_num)
19564 + return &pcd->in_ep[i];
19570 + * This function returns pointer to out ep struct with number ep_num
19572 +static inline dwc_otg_pcd_ep_t* get_out_ep(dwc_otg_pcd_t *pcd, uint32_t ep_num)
19575 + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
19576 + if(ep_num == 0) {
19577 + return &pcd->ep0;
19580 + for(i = 0; i < num_out_eps; ++i)
19582 + if(pcd->out_ep[i].dwc_ep.num == ep_num)
19583 + return &pcd->out_ep[i];
19589 + * This functions gets a pointer to an EP from the wIndex address
19590 + * value of the control request.
19592 +static dwc_otg_pcd_ep_t *get_ep_by_addr (dwc_otg_pcd_t *pcd, u16 wIndex)
19594 + dwc_otg_pcd_ep_t *ep;
19596 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
19597 + return &pcd->ep0;
19598 + list_for_each_entry(ep, &pcd->gadget.ep_list, ep.ep_list)
19600 + u8 bEndpointAddress;
19605 + bEndpointAddress = ep->desc->bEndpointAddress;
19606 + if((wIndex & (USB_DIR_IN | USB_ENDPOINT_NUMBER_MASK))
19607 + == (bEndpointAddress & (USB_DIR_IN | USB_ENDPOINT_NUMBER_MASK)))
19614 + * This function checks the EP request queue, if the queue is not
19615 + * empty the next request is started.
19617 +void start_next_request(dwc_otg_pcd_ep_t *ep)
19619 + dwc_otg_pcd_request_t *req = 0;
19620 + uint32_t max_transfer = GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
19621 + if (!list_empty(&ep->queue)) {
19622 + req = list_entry(ep->queue.next,
19623 + dwc_otg_pcd_request_t, queue);
19625 + /* Setup and start the Transfer */
19626 + ep->dwc_ep.dma_addr = req->req.dma;
19627 + ep->dwc_ep.start_xfer_buff = req->req.buf;
19628 + ep->dwc_ep.xfer_buff = req->req.buf;
19629 + ep->dwc_ep.sent_zlp = 0;
19630 + ep->dwc_ep.total_len = req->req.length;
19631 + ep->dwc_ep.xfer_len = 0;
19632 + ep->dwc_ep.xfer_count = 0;
19634 + if(max_transfer > MAX_TRANSFER_SIZE) {
19635 + ep->dwc_ep.maxxfer = max_transfer - (max_transfer % ep->dwc_ep.maxpacket);
19637 + ep->dwc_ep.maxxfer = max_transfer;
19640 + if(req->req.zero) {
19641 + if((ep->dwc_ep.total_len % ep->dwc_ep.maxpacket == 0)
19642 + && (ep->dwc_ep.total_len != 0)) {
19643 + ep->dwc_ep.sent_zlp = 1;
19647 + ep_check_and_patch_dma_addr(ep);
19648 + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
19653 + * This function handles the SOF Interrupts. At this time the SOF
19654 + * Interrupt is disabled.
19656 +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t *pcd)
19658 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19660 + gintsts_data_t gintsts;
19662 + DWC_DEBUGPL(DBG_PCD, "SOF\n");
19664 + /* Clear interrupt */
19666 + gintsts.b.sofintr = 1;
19667 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
19674 + * This function handles the Rx Status Queue Level Interrupt, which
19675 + * indicates that there is a least one packet in the Rx FIFO. The
19676 + * packets are moved from the FIFO to memory, where they will be
19677 + * processed when the Endpoint Interrupt Register indicates Transfer
19678 + * Complete or SETUP Phase Done.
19680 + * Repeat the following until the Rx Status Queue is empty:
19681 + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
19683 + * -# If Receive FIFO is empty then skip to step Clear the interrupt
19685 + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
19686 + * SETUP data to the buffer
19687 + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
19688 + * to the destination buffer
19690 +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t *pcd)
19692 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19693 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
19694 + gintmsk_data_t gintmask = {.d32=0};
19695 + device_grxsts_data_t status;
19696 + dwc_otg_pcd_ep_t *ep;
19697 + gintsts_data_t gintsts;
19699 + static char *dpid_str[] ={ "D0", "D2", "D1", "MDATA" };
19702 + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
19703 + /* Disable the Rx Status Queue Level interrupt */
19704 + gintmask.b.rxstsqlvl= 1;
19705 + dwc_modify_reg32(&global_regs->gintmsk, gintmask.d32, 0);
19707 + /* Get the Status from the top of the FIFO */
19708 + status.d32 = dwc_read_reg32(&global_regs->grxstsp);
19710 + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
19711 + "pktsts:%x Frame:%d(0x%0x)\n",
19712 + status.b.epnum, status.b.bcnt,
19713 + dpid_str[status.b.dpid],
19714 + status.b.pktsts, status.b.fn, status.b.fn);
19715 + /* Get pointer to EP structure */
19716 + ep = get_out_ep(pcd, status.b.epnum);
19718 + switch (status.b.pktsts) {
19719 + case DWC_DSTS_GOUT_NAK:
19720 + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
19722 + case DWC_STS_DATA_UPDT:
19723 + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
19724 + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
19725 + /** @todo NGS Check for buffer overflow? */
19726 + dwc_otg_read_packet(core_if,
19727 + ep->dwc_ep.xfer_buff,
19729 + ep->dwc_ep.xfer_count += status.b.bcnt;
19730 + ep->dwc_ep.xfer_buff += status.b.bcnt;
19733 + case DWC_STS_XFER_COMP:
19734 + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
19736 + case DWC_DSTS_SETUP_COMP:
19738 + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
19741 +case DWC_DSTS_SETUP_UPDT:
19742 + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
19744 + DWC_DEBUGPL(DBG_PCD,
19745 + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
19746 + pcd->setup_pkt->req.bRequestType,
19747 + pcd->setup_pkt->req.bRequest,
19748 + pcd->setup_pkt->req.wValue,
19749 + pcd->setup_pkt->req.wIndex,
19750 + pcd->setup_pkt->req.wLength);
19752 + ep->dwc_ep.xfer_count += status.b.bcnt;
19755 + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
19756 + status.b.pktsts);
19760 + /* Enable the Rx Status Queue Level interrupt */
19761 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmask.d32);
19762 + /* Clear interrupt */
19764 + gintsts.b.rxstsqlvl = 1;
19765 + dwc_write_reg32 (&global_regs->gintsts, gintsts.d32);
19767 + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
19771 + * This function examines the Device IN Token Learning Queue to
19772 + * determine the EP number of the last IN token received. This
19773 + * implementation is for the Mass Storage device where there are only
19774 + * 2 IN EPs (Control-IN and BULK-IN).
19776 + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
19777 + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
19779 + * @param core_if Programming view of DWC_otg controller.
19782 +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t *core_if)
19784 + dwc_otg_device_global_regs_t *dev_global_regs =
19785 + core_if->dev_if->dev_global_regs;
19786 + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
19787 + /* Number of Token Queue Registers */
19788 + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
19789 + dtknq1_data_t dtknqr1;
19790 + uint32_t in_tkn_epnums[4];
19793 + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
19796 + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
19799 + /* Read the DTKNQ Registers */
19800 + for (i = 0; i < DTKNQ_REG_CNT; i++)
19802 + in_tkn_epnums[ i ] = dwc_read_reg32(addr);
19803 + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i+1,
19804 + in_tkn_epnums[i]);
19805 + if (addr == &dev_global_regs->dvbusdis) {
19806 + addr = &dev_global_regs->dtknqr3_dthrctl;
19814 + /* Copy the DTKNQR1 data to the bit field. */
19815 + dtknqr1.d32 = in_tkn_epnums[0];
19816 + /* Get the EP numbers */
19817 + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
19818 + ndx = dtknqr1.b.intknwptr - 1;
19820 + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
19822 + /** @todo Find a simpler way to calculate the max
19823 + * queue position.*/
19824 + int cnt = TOKEN_Q_DEPTH;
19825 + if (TOKEN_Q_DEPTH <= 6) {
19826 + cnt = TOKEN_Q_DEPTH - 1;
19828 + else if (TOKEN_Q_DEPTH <= 14) {
19829 + cnt = TOKEN_Q_DEPTH - 7;
19831 + else if (TOKEN_Q_DEPTH <= 22) {
19832 + cnt = TOKEN_Q_DEPTH - 15;
19835 + cnt = TOKEN_Q_DEPTH - 23;
19837 + epnum = (in_tkn_epnums[ DTKNQ_REG_CNT - 1 ] >> (cnt * 4)) & 0xF;
19841 + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
19843 + else if (ndx <= 13) {
19845 + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
19847 + else if (ndx <= 21) {
19849 + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
19851 + else if (ndx <= 29) {
19853 + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
19856 + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
19861 + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
19862 + * The active request is checked for the next packet to be loaded into
19863 + * the non-periodic Tx FIFO.
19865 +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t *pcd)
19867 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19868 + dwc_otg_core_global_regs_t *global_regs =
19869 + core_if->core_global_regs;
19870 + dwc_otg_dev_in_ep_regs_t *ep_regs;
19871 + gnptxsts_data_t txstatus = {.d32 = 0};
19872 + gintsts_data_t gintsts;
19875 + dwc_otg_pcd_ep_t *ep = 0;
19876 + uint32_t len = 0;
19879 + /* Get the epnum from the IN Token Learning Queue. */
19880 + epnum = get_ep_of_last_in_token(core_if);
19881 + ep = get_in_ep(pcd, epnum);
19883 + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %s(%d) \n", ep->ep.name, epnum);
19884 + ep_regs = core_if->dev_if->in_ep_regs[epnum];
19886 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19887 + if (len > ep->dwc_ep.maxpacket) {
19888 + len = ep->dwc_ep.maxpacket;
19890 + dwords = (len + 3)/4;
19893 + /* While there is space in the queue and space in the FIFO and
19894 + * More data to tranfer, Write packets to the Tx FIFO */
19895 + txstatus.d32 = dwc_read_reg32(&global_regs->gnptxsts);
19896 + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n",txstatus.d32);
19898 + while (txstatus.b.nptxqspcavail > 0 &&
19899 + txstatus.b.nptxfspcavail > dwords &&
19900 + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
19901 + /* Write the FIFO */
19902 + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
19903 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19905 + if (len > ep->dwc_ep.maxpacket) {
19906 + len = ep->dwc_ep.maxpacket;
19909 + dwords = (len + 3)/4;
19910 + txstatus.d32 = dwc_read_reg32(&global_regs->gnptxsts);
19911 + DWC_DEBUGPL(DBG_PCDV,"GNPTXSTS=0x%08x\n",txstatus.d32);
19914 + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
19915 + dwc_read_reg32(&global_regs->gnptxsts));
19917 + /* Clear interrupt */
19919 + gintsts.b.nptxfempty = 1;
19920 + dwc_write_reg32 (&global_regs->gintsts, gintsts.d32);
19926 + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
19927 + * The active request is checked for the next packet to be loaded into
19928 + * apropriate Tx FIFO.
19930 +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t *pcd, uint32_t epnum)
19932 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
19933 + dwc_otg_dev_if_t* dev_if = core_if->dev_if;
19934 + dwc_otg_dev_in_ep_regs_t *ep_regs;
19935 + dtxfsts_data_t txstatus = {.d32 = 0};
19936 + dwc_otg_pcd_ep_t *ep = 0;
19937 + uint32_t len = 0;
19940 + ep = get_in_ep(pcd, epnum);
19942 + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %s(%d) \n", ep->ep.name, epnum);
19944 + ep_regs = core_if->dev_if->in_ep_regs[epnum];
19946 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19948 + if (len > ep->dwc_ep.maxpacket) {
19949 + len = ep->dwc_ep.maxpacket;
19952 + dwords = (len + 3)/4;
19954 + /* While there is space in the queue and space in the FIFO and
19955 + * More data to tranfer, Write packets to the Tx FIFO */
19956 + txstatus.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dtxfsts);
19957 + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n",epnum,txstatus.d32);
19959 + while (txstatus.b.txfspcavail > dwords &&
19960 + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
19961 + ep->dwc_ep.xfer_len != 0) {
19962 + /* Write the FIFO */
19963 + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
19965 + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
19966 + if (len > ep->dwc_ep.maxpacket) {
19967 + len = ep->dwc_ep.maxpacket;
19970 + dwords = (len + 3)/4;
19971 + txstatus.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dtxfsts);
19972 + DWC_DEBUGPL(DBG_PCDV,"dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
19975 + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n",epnum,dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dtxfsts));
19982 + * This function is called when the Device is disconnected. It stops
19983 + * any active requests and informs the Gadget driver of the
19986 +void dwc_otg_pcd_stop(dwc_otg_pcd_t *pcd)
19988 + int i, num_in_eps, num_out_eps;
19989 + dwc_otg_pcd_ep_t *ep;
19991 + gintmsk_data_t intr_mask = {.d32 = 0};
19993 + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
19994 + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
19996 + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
19997 + /* don't disconnect drivers more than once */
19998 + if (pcd->ep0state == EP0_DISCONNECT) {
19999 + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
20002 + pcd->ep0state = EP0_DISCONNECT;
20004 + /* Reset the OTG state. */
20005 + dwc_otg_pcd_update_otg(pcd, 1);
20007 + /* Disable the NP Tx Fifo Empty Interrupt. */
20008 + intr_mask.b.nptxfempty = 1;
20009 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
20010 + intr_mask.d32, 0);
20012 + /* Flush the FIFOs */
20013 + /**@todo NGS Flush Periodic FIFOs */
20014 + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
20015 + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
20017 + /* prevent new request submissions, kill any outstanding requests */
20019 + dwc_otg_request_nuke(ep);
20020 + /* prevent new request submissions, kill any outstanding requests */
20021 + for (i = 0; i < num_in_eps; i++)
20023 + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
20024 + dwc_otg_request_nuke(ep);
20026 + /* prevent new request submissions, kill any outstanding requests */
20027 + for (i = 0; i < num_out_eps; i++)
20029 + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
20030 + dwc_otg_request_nuke(ep);
20033 + /* report disconnect; the driver is already quiesced */
20034 + if (pcd->driver && pcd->driver->disconnect) {
20035 + SPIN_UNLOCK(&pcd->lock);
20036 + pcd->driver->disconnect(&pcd->gadget);
20037 + SPIN_LOCK(&pcd->lock);
20042 + * This interrupt indicates that ...
20044 +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t *pcd)
20046 + gintmsk_data_t intr_mask = { .d32 = 0};
20047 + gintsts_data_t gintsts;
20049 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "i2cintr");
20050 + intr_mask.b.i2cintr = 1;
20051 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
20052 + intr_mask.d32, 0);
20054 + /* Clear interrupt */
20056 + gintsts.b.i2cintr = 1;
20057 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
20064 + * This interrupt indicates that ...
20066 +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t *pcd)
20068 + gintsts_data_t gintsts;
20069 +#if defined(VERBOSE)
20070 + DWC_PRINT("Early Suspend Detected\n");
20072 + /* Clear interrupt */
20074 + gintsts.b.erlysuspend = 1;
20075 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
20081 + * This function configures EPO to receive SETUP packets.
20083 + * @todo NGS: Update the comments from the HW FS.
20085 + * -# Program the following fields in the endpoint specific registers
20086 + * for Control OUT EP 0, in order to receive a setup packet
20087 + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
20089 + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
20090 + * to back setup packets)
20091 + * - In DMA mode, DOEPDMA0 Register with a memory address to
20092 + * store any setup packets received
20094 + * @param core_if Programming view of DWC_otg controller.
20095 + * @param pcd Programming view of the PCD.
20097 +static inline void ep0_out_start(dwc_otg_core_if_t *core_if, dwc_otg_pcd_t *pcd)
20099 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
20100 + deptsiz0_data_t doeptsize0 = { .d32 = 0};
20101 + dwc_otg_dma_desc_t* dma_desc;
20102 + depctl_data_t doepctl = { .d32 = 0 };
20105 + DWC_DEBUGPL(DBG_PCDV,"%s() doepctl0=%0x\n", __func__,
20106 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
20109 + doeptsize0.b.supcnt = 3;
20110 + doeptsize0.b.pktcnt = 1;
20111 + doeptsize0.b.xfersize = 8*3;
20114 + if (core_if->dma_enable) {
20115 + if (!core_if->dma_desc_enable) {
20116 + /** put here as for Hermes mode deptisz register should not be written */
20117 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doeptsiz,
20120 + /** @todo dma needs to handle multiple setup packets (up to 3) */
20121 + VERIFY_PCD_DMA_ADDR(pcd->setup_pkt_dma_handle);
20123 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepdma,
20124 + pcd->setup_pkt_dma_handle);
20126 + dev_if->setup_desc_index = (dev_if->setup_desc_index + 1) & 1;
20127 + dma_desc = dev_if->setup_desc_addr[dev_if->setup_desc_index];
20129 + /** DMA Descriptor Setup */
20130 + dma_desc->status.b.bs = BS_HOST_BUSY;
20131 + dma_desc->status.b.l = 1;
20132 + dma_desc->status.b.ioc = 1;
20133 + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
20134 + dma_desc->buf = pcd->setup_pkt_dma_handle;
20135 + dma_desc->status.b.bs = BS_HOST_READY;
20137 + /** DOEPDMA0 Register write */
20138 + VERIFY_PCD_DMA_ADDR(dev_if->dma_setup_desc_addr[dev_if->setup_desc_index]);
20139 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepdma, dev_if->dma_setup_desc_addr[dev_if->setup_desc_index]);
20143 + /** put here as for Hermes mode deptisz register should not be written */
20144 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doeptsiz,
20148 + /** DOEPCTL0 Register write */
20149 + doepctl.b.epena = 1;
20150 + doepctl.b.cnak = 1;
20151 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
20154 + DWC_DEBUGPL(DBG_PCDV,"doepctl0=%0x\n",
20155 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
20156 + DWC_DEBUGPL(DBG_PCDV,"diepctl0=%0x\n",
20157 + dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl));
20163 + * This interrupt occurs when a USB Reset is detected. When the USB
20164 + * Reset Interrupt occurs the device state is set to DEFAULT and the
20165 + * EP0 state is set to IDLE.
20166 + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
20167 + * -# Unmask the following interrupt bits
20168 + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
20169 + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
20170 + * - DOEPMSK.SETUP = 1
20171 + * - DOEPMSK.XferCompl = 1
20172 + * - DIEPMSK.XferCompl = 1
20173 + * - DIEPMSK.TimeOut = 1
20174 + * -# Program the following fields in the endpoint specific registers
20175 + * for Control OUT EP 0, in order to receive a setup packet
20176 + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
20178 + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
20179 + * to back setup packets)
20180 + * - In DMA mode, DOEPDMA0 Register with a memory address to
20181 + * store any setup packets received
20182 + * At this point, all the required initialization, except for enabling
20183 + * the control 0 OUT endpoint is done, for receiving SETUP packets.
20185 +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
20187 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
20188 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
20189 + depctl_data_t doepctl = { .d32 = 0};
20191 + daint_data_t daintmsk = { .d32 = 0};
20192 + doepmsk_data_t doepmsk = { .d32 = 0};
20193 + diepmsk_data_t diepmsk = { .d32 = 0};
20195 + dcfg_data_t dcfg = { .d32=0 };
20196 + grstctl_t resetctl = { .d32=0 };
20197 + dctl_data_t dctl = {.d32=0};
20199 + gintsts_data_t gintsts;
20201 + DWC_PRINT("USB RESET\n");
20202 +#ifdef DWC_EN_ISOC
20203 + for(i = 1;i < 16; ++i)
20205 + dwc_otg_pcd_ep_t *ep;
20206 + dwc_ep_t *dwc_ep;
20207 + ep = get_in_ep(pcd,i);
20209 + dwc_ep = &ep->dwc_ep;
20210 + dwc_ep->next_frame = 0xffffffff;
20213 +#endif /* DWC_EN_ISOC */
20215 + /* reset the HNP settings */
20216 + dwc_otg_pcd_update_otg(pcd, 1);
20218 + /* Clear the Remote Wakeup Signalling */
20219 + dctl.b.rmtwkupsig = 1;
20220 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dctl,
20223 + /* Set NAK for all OUT EPs */
20224 + doepctl.b.snak = 1;
20225 + for (i=0; i <= dev_if->num_out_eps; i++)
20227 + dwc_write_reg32(&dev_if->out_ep_regs[i]->doepctl,
20231 + /* Flush the NP Tx FIFO */
20232 + dwc_otg_flush_tx_fifo(core_if, 0x10);
20233 + /* Flush the Learning Queue */
20234 + resetctl.b.intknqflsh = 1;
20235 + dwc_write_reg32(&core_if->core_global_regs->grstctl, resetctl.d32);
20237 + if(core_if->multiproc_int_enable) {
20238 + daintmsk.b.inep0 = 1;
20239 + daintmsk.b.outep0 = 1;
20240 + dwc_write_reg32(&dev_if->dev_global_regs->deachintmsk, daintmsk.d32);
20242 + doepmsk.b.setup = 1;
20243 + doepmsk.b.xfercompl = 1;
20244 + doepmsk.b.ahberr = 1;
20245 + doepmsk.b.epdisabled = 1;
20247 + if(core_if->dma_desc_enable) {
20248 + doepmsk.b.stsphsercvd = 1;
20249 + doepmsk.b.bna = 1;
20252 + doepmsk.b.babble = 1;
20253 + doepmsk.b.nyet = 1;
20255 + if(core_if->dma_enable) {
20256 + doepmsk.b.nak = 1;
20259 + dwc_write_reg32(&dev_if->dev_global_regs->doepeachintmsk[0], doepmsk.d32);
20261 + diepmsk.b.xfercompl = 1;
20262 + diepmsk.b.timeout = 1;
20263 + diepmsk.b.epdisabled = 1;
20264 + diepmsk.b.ahberr = 1;
20265 + diepmsk.b.intknepmis = 1;
20267 + if(core_if->dma_desc_enable) {
20268 + diepmsk.b.bna = 1;
20271 + if(core_if->dma_enable) {
20272 + diepmsk.b.nak = 1;
20275 + dwc_write_reg32(&dev_if->dev_global_regs->diepeachintmsk[0], diepmsk.d32);
20277 + daintmsk.b.inep0 = 1;
20278 + daintmsk.b.outep0 = 1;
20279 + dwc_write_reg32(&dev_if->dev_global_regs->daintmsk, daintmsk.d32);
20281 + doepmsk.b.setup = 1;
20282 + doepmsk.b.xfercompl = 1;
20283 + doepmsk.b.ahberr = 1;
20284 + doepmsk.b.epdisabled = 1;
20286 + if(core_if->dma_desc_enable) {
20287 + doepmsk.b.stsphsercvd = 1;
20288 + doepmsk.b.bna = 1;
20291 + doepmsk.b.babble = 1;
20292 + doepmsk.b.nyet = 1;
20293 + doepmsk.b.nak = 1;
20295 + dwc_write_reg32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
20297 + diepmsk.b.xfercompl = 1;
20298 + diepmsk.b.timeout = 1;
20299 + diepmsk.b.epdisabled = 1;
20300 + diepmsk.b.ahberr = 1;
20301 + diepmsk.b.intknepmis = 1;
20303 + if(core_if->dma_desc_enable) {
20304 + diepmsk.b.bna = 1;
20307 +// diepmsk.b.nak = 1;
20309 + dwc_write_reg32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
20312 + /* Reset Device Address */
20313 + dcfg.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dcfg);
20314 + dcfg.b.devaddr = 0;
20315 + dwc_write_reg32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
20317 + /* setup EP0 to receive SETUP packets */
20318 + ep0_out_start(core_if, pcd);
20320 + /* Clear interrupt */
20322 + gintsts.b.usbreset = 1;
20323 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
20329 + * Get the device speed from the device status register and convert it
20330 + * to USB speed constant.
20332 + * @param core_if Programming view of DWC_otg controller.
20334 +static int get_device_speed(dwc_otg_core_if_t *core_if)
20336 + dsts_data_t dsts;
20337 + enum usb_device_speed speed = USB_SPEED_UNKNOWN;
20338 + dsts.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dsts);
20340 + switch (dsts.b.enumspd) {
20341 + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
20342 + speed = USB_SPEED_HIGH;
20344 + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
20345 + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
20346 + speed = USB_SPEED_FULL;
20349 + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
20350 + speed = USB_SPEED_LOW;
20358 + * Read the device status register and set the device speed in the
20359 + * data structure.
20360 + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
20362 +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t *pcd)
20364 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
20365 + gintsts_data_t gintsts;
20366 + gusbcfg_data_t gusbcfg;
20367 + dwc_otg_core_global_regs_t *global_regs =
20368 + GET_CORE_IF(pcd)->core_global_regs;
20369 + uint8_t utmi16b, utmi8b;
20370 +// DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
20371 + DWC_PRINT("SPEED ENUM\n");
20373 + if (GET_CORE_IF(pcd)->snpsid >= 0x4F54260A) {
20380 + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
20383 + print_ep0_state(pcd);
20386 + if (pcd->ep0state == EP0_DISCONNECT) {
20387 + pcd->ep0state = EP0_IDLE;
20389 + else if (pcd->ep0state == EP0_STALL) {
20390 + pcd->ep0state = EP0_IDLE;
20393 + pcd->ep0state = EP0_IDLE;
20395 + ep0->stopped = 0;
20397 + pcd->gadget.speed = get_device_speed(GET_CORE_IF(pcd));
20399 + /* Set USB turnaround time based on device speed and PHY interface. */
20400 + gusbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
20401 + if (pcd->gadget.speed == USB_SPEED_HIGH) {
20402 + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
20403 + /* ULPI interface */
20404 + gusbcfg.b.usbtrdtim = 9;
20406 + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
20407 + /* UTMI+ interface */
20408 + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
20409 + gusbcfg.b.usbtrdtim = utmi8b;
20411 + else if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 1) {
20412 + gusbcfg.b.usbtrdtim = utmi16b;
20414 + else if (GET_CORE_IF(pcd)->core_params->phy_utmi_width == 8) {
20415 + gusbcfg.b.usbtrdtim = utmi8b;
20418 + gusbcfg.b.usbtrdtim = utmi16b;
20421 + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type == DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
20422 + /* UTMI+ OR ULPI interface */
20423 + if (gusbcfg.b.ulpi_utmi_sel == 1) {
20424 + /* ULPI interface */
20425 + gusbcfg.b.usbtrdtim = 9;
20428 + /* UTMI+ interface */
20429 + if (GET_CORE_IF(pcd)->core_params->phy_utmi_width == 16) {
20430 + gusbcfg.b.usbtrdtim = utmi16b;
20433 + gusbcfg.b.usbtrdtim = utmi8b;
20439 + /* Full or low speed */
20440 + gusbcfg.b.usbtrdtim = 9;
20442 + dwc_write_reg32(&global_regs->gusbcfg, gusbcfg.d32);
20444 + /* Clear interrupt */
20446 + gintsts.b.enumdone = 1;
20447 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
20453 + * This interrupt indicates that the ISO OUT Packet was dropped due to
20454 + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
20455 + * read all the data from the Rx FIFO.
20457 +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t *pcd)
20459 + gintmsk_data_t intr_mask = { .d32 = 0};
20460 + gintsts_data_t gintsts;
20462 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
20463 + "ISOC Out Dropped");
20465 + intr_mask.b.isooutdrop = 1;
20466 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
20467 + intr_mask.d32, 0);
20469 + /* Clear interrupt */
20472 + gintsts.b.isooutdrop = 1;
20473 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
20480 + * This interrupt indicates the end of the portion of the micro-frame
20481 + * for periodic transactions. If there is a periodic transaction for
20482 + * the next frame, load the packets into the EP periodic Tx FIFO.
20484 +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t *pcd)
20486 + gintmsk_data_t intr_mask = { .d32 = 0};
20487 + gintsts_data_t gintsts;
20488 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "EOP");
20490 + intr_mask.b.eopframe = 1;
20491 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
20492 + intr_mask.d32, 0);
20494 + /* Clear interrupt */
20496 + gintsts.b.eopframe = 1;
20497 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts, gintsts.d32);
20503 + * This interrupt indicates that EP of the packet on the top of the
20504 + * non-periodic Tx FIFO does not match EP of the IN Token received.
20506 + * The "Device IN Token Queue" Registers are read to determine the
20507 + * order the IN Tokens have been received. The non-periodic Tx FIFO
20508 + * is flushed, so it can be reloaded in the order seen in the IN Token
20511 +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_core_if_t *core_if)
20513 + gintsts_data_t gintsts;
20514 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
20516 + /* Clear interrupt */
20518 + gintsts.b.epmismatch = 1;
20519 + dwc_write_reg32 (&core_if->core_global_regs->gintsts, gintsts.d32);
20525 + * This funcion stalls EP0.
20527 +static inline void ep0_do_stall(dwc_otg_pcd_t *pcd, const int err_val)
20529 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
20530 + struct usb_ctrlrequest *ctrl = &pcd->setup_pkt->req;
20531 + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
20532 + ctrl->bRequestType, ctrl->bRequest, err_val);
20534 + ep0->dwc_ep.is_in = 1;
20535 + dwc_otg_ep_set_stall(pcd->otg_dev->core_if, &ep0->dwc_ep);
20536 + pcd->ep0.stopped = 1;
20537 + pcd->ep0state = EP0_IDLE;
20538 + ep0_out_start(GET_CORE_IF(pcd), pcd);
20542 + * This functions delegates the setup command to the gadget driver.
20544 +static inline void do_gadget_setup(dwc_otg_pcd_t *pcd,
20545 + struct usb_ctrlrequest * ctrl)
20548 + if (pcd->driver && pcd->driver->setup) {
20549 + SPIN_UNLOCK(&pcd->lock);
20550 + ret = pcd->driver->setup(&pcd->gadget, ctrl);
20551 + SPIN_LOCK(&pcd->lock);
20553 + ep0_do_stall(pcd, ret);
20556 + /** @todo This is a g_file_storage gadget driver specific
20557 + * workaround: a DELAYED_STATUS result from the fsg_setup
20558 + * routine will result in the gadget queueing a EP0 IN status
20559 + * phase for a two-stage control transfer. Exactly the same as
20560 + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
20561 + * specific request. Need a generic way to know when the gadget
20562 + * driver will queue the status phase. Can we assume when we
20563 + * call the gadget driver setup() function that it will always
20564 + * queue and require the following flag? Need to look into
20568 + if (ret == 256 + 999) {
20569 + pcd->request_config = 1;
20575 + * This function starts the Zero-Length Packet for the IN status phase
20576 + * of a 2 stage control transfer.
20578 +static inline void do_setup_in_status_phase(dwc_otg_pcd_t *pcd)
20580 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
20581 + if (pcd->ep0state == EP0_STALL) {
20585 + pcd->ep0state = EP0_IN_STATUS_PHASE;
20587 + /* Prepare for more SETUP Packets */
20588 + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
20589 + ep0->dwc_ep.xfer_len = 0;
20590 + ep0->dwc_ep.xfer_count = 0;
20591 + ep0->dwc_ep.is_in = 1;
20592 + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
20593 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
20595 + /* Prepare for more SETUP Packets */
20596 +// if(GET_CORE_IF(pcd)->dma_enable == 0) ep0_out_start(GET_CORE_IF(pcd), pcd);
20600 + * This function starts the Zero-Length Packet for the OUT status phase
20601 + * of a 2 stage control transfer.
20603 +static inline void do_setup_out_status_phase(dwc_otg_pcd_t *pcd)
20605 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
20606 + if (pcd->ep0state == EP0_STALL) {
20607 + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
20610 + pcd->ep0state = EP0_OUT_STATUS_PHASE;
20612 + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
20613 + ep0->dwc_ep.xfer_len = 0;
20614 + ep0->dwc_ep.xfer_count = 0;
20615 + ep0->dwc_ep.is_in = 0;
20616 + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
20617 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
20619 + /* Prepare for more SETUP Packets */
20620 + if(GET_CORE_IF(pcd)->dma_enable == 0) {
20621 + ep0_out_start(GET_CORE_IF(pcd), pcd);
20626 + * Clear the EP halt (STALL) and if pending requests start the
20629 +static inline void pcd_clear_halt(dwc_otg_pcd_t *pcd, dwc_otg_pcd_ep_t *ep)
20631 + if(ep->dwc_ep.stall_clear_flag == 0)
20632 + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
20634 + /* Reactive the EP */
20635 + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
20636 + if (ep->stopped) {
20638 + /* If there is a request in the EP queue start it */
20640 + /** @todo FIXME: this causes an EP mismatch in DMA mode.
20641 + * epmismatch not yet implemented. */
20644 + * Above fixme is solved by implmenting a tasklet to call the
20645 + * start_next_request(), outside of interrupt context at some
20646 + * time after the current time, after a clear-halt setup packet.
20647 + * Still need to implement ep mismatch in the future if a gadget
20648 + * ever uses more than one endpoint at once
20650 + ep->queue_sof = 1;
20651 + tasklet_schedule (pcd->start_xfer_tasklet);
20653 + /* Start Control Status Phase */
20654 + do_setup_in_status_phase(pcd);
20658 + * This function is called when the SET_FEATURE TEST_MODE Setup packet
20659 + * is sent from the host. The Device Control register is written with
20660 + * the Test Mode bits set to the specified Test Mode. This is done as
20661 + * a tasklet so that the "Status" phase of the control transfer
20662 + * completes before transmitting the TEST packets.
20664 + * @todo This has not been tested since the tasklet struct was put
20665 + * into the PCD struct!
20668 +static void do_test_mode(unsigned long data)
20670 + dctl_data_t dctl;
20671 + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *)data;
20672 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
20673 + int test_mode = pcd->test_mode;
20676 +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
20678 + dctl.d32 = dwc_read_reg32(&core_if->dev_if->dev_global_regs->dctl);
20679 + switch (test_mode) {
20680 + case 1: // TEST_J
20681 + dctl.b.tstctl = 1;
20684 + case 2: // TEST_K
20685 + dctl.b.tstctl = 2;
20688 + case 3: // TEST_SE0_NAK
20689 + dctl.b.tstctl = 3;
20692 + case 4: // TEST_PACKET
20693 + dctl.b.tstctl = 4;
20696 + case 5: // TEST_FORCE_ENABLE
20697 + dctl.b.tstctl = 5;
20700 + dwc_write_reg32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
20704 + * This function process the GET_STATUS Setup Commands.
20706 +static inline void do_get_status(dwc_otg_pcd_t *pcd)
20708 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
20709 + dwc_otg_pcd_ep_t *ep;
20710 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
20711 + uint16_t *status = pcd->status_buf;
20714 + DWC_DEBUGPL(DBG_PCD,
20715 + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
20716 + ctrl.bRequestType, ctrl.bRequest,
20717 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
20720 + switch (ctrl.bRequestType & USB_RECIP_MASK) {
20721 + case USB_RECIP_DEVICE:
20722 + *status = 0x1; /* Self powered */
20723 + *status |= pcd->remote_wakeup_enable << 1;
20726 + case USB_RECIP_INTERFACE:
20730 + case USB_RECIP_ENDPOINT:
20731 + ep = get_ep_by_addr(pcd, ctrl.wIndex);
20732 + if (ep == 0 || ctrl.wLength > 2) {
20733 + ep0_do_stall(pcd, -EOPNOTSUPP);
20736 + /** @todo check for EP stall */
20737 + *status = ep->stopped;
20740 + pcd->ep0_pending = 1;
20741 + ep0->dwc_ep.start_xfer_buff = (uint8_t *)status;
20742 + ep0->dwc_ep.xfer_buff = (uint8_t *)status;
20743 + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
20744 + ep0->dwc_ep.xfer_len = 2;
20745 + ep0->dwc_ep.xfer_count = 0;
20746 + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
20747 + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
20750 + * This function process the SET_FEATURE Setup Commands.
20752 +static inline void do_set_feature(dwc_otg_pcd_t *pcd)
20754 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
20755 + dwc_otg_core_global_regs_t *global_regs =
20756 + core_if->core_global_regs;
20757 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
20758 + dwc_otg_pcd_ep_t *ep = 0;
20759 + int32_t otg_cap_param = core_if->core_params->otg_cap;
20760 + gotgctl_data_t gotgctl = { .d32 = 0 };
20762 + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
20763 + ctrl.bRequestType, ctrl.bRequest,
20764 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
20765 + DWC_DEBUGPL(DBG_PCD,"otg_cap=%d\n", otg_cap_param);
20768 + switch (ctrl.bRequestType & USB_RECIP_MASK) {
20769 + case USB_RECIP_DEVICE:
20770 + switch (ctrl.wValue) {
20771 + case USB_DEVICE_REMOTE_WAKEUP:
20772 + pcd->remote_wakeup_enable = 1;
20775 + case USB_DEVICE_TEST_MODE:
20776 + /* Setup the Test Mode tasklet to do the Test
20777 + * Packet generation after the SETUP Status
20778 + * phase has completed. */
20780 + /** @todo This has not been tested since the
20781 + * tasklet struct was put into the PCD
20783 + pcd->test_mode_tasklet.next = 0;
20784 + pcd->test_mode_tasklet.state = 0;
20785 + atomic_set(&pcd->test_mode_tasklet.count, 0);
20786 + pcd->test_mode_tasklet.func = do_test_mode;
20787 + pcd->test_mode_tasklet.data = (unsigned long)pcd;
20788 + pcd->test_mode = ctrl.wIndex >> 8;
20789 + tasklet_schedule(&pcd->test_mode_tasklet);
20792 + case USB_DEVICE_B_HNP_ENABLE:
20793 + DWC_DEBUGPL(DBG_PCDV, "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
20795 + /* dev may initiate HNP */
20796 + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
20797 + pcd->b_hnp_enable = 1;
20798 + dwc_otg_pcd_update_otg(pcd, 0);
20799 + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
20800 + /**@todo Is the gotgctl.devhnpen cleared
20801 + * by a USB Reset? */
20802 + gotgctl.b.devhnpen = 1;
20803 + gotgctl.b.hnpreq = 1;
20804 + dwc_write_reg32(&global_regs->gotgctl, gotgctl.d32);
20807 + ep0_do_stall(pcd, -EOPNOTSUPP);
20811 + case USB_DEVICE_A_HNP_SUPPORT:
20812 + /* RH port supports HNP */
20813 + DWC_DEBUGPL(DBG_PCDV, "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
20814 + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
20815 + pcd->a_hnp_support = 1;
20816 + dwc_otg_pcd_update_otg(pcd, 0);
20819 + ep0_do_stall(pcd, -EOPNOTSUPP);
20823 + case USB_DEVICE_A_ALT_HNP_SUPPORT:
20824 + /* other RH port does */
20825 + DWC_DEBUGPL(DBG_PCDV, "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
20826 + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
20827 + pcd->a_alt_hnp_support = 1;
20828 + dwc_otg_pcd_update_otg(pcd, 0);
20831 + ep0_do_stall(pcd, -EOPNOTSUPP);
20835 + do_setup_in_status_phase(pcd);
20838 + case USB_RECIP_INTERFACE:
20839 + do_gadget_setup(pcd, &ctrl);
20842 + case USB_RECIP_ENDPOINT:
20843 + if (ctrl.wValue == USB_ENDPOINT_HALT) {
20844 + ep = get_ep_by_addr(pcd, ctrl.wIndex);
20846 + ep0_do_stall(pcd, -EOPNOTSUPP);
20850 + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
20852 + do_setup_in_status_phase(pcd);
20858 + * This function process the CLEAR_FEATURE Setup Commands.
20860 +static inline void do_clear_feature(dwc_otg_pcd_t *pcd)
20862 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
20863 + dwc_otg_pcd_ep_t *ep = 0;
20865 + DWC_DEBUGPL(DBG_PCD,
20866 + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
20867 + ctrl.bRequestType, ctrl.bRequest,
20868 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
20870 + switch (ctrl.bRequestType & USB_RECIP_MASK) {
20871 + case USB_RECIP_DEVICE:
20872 + switch (ctrl.wValue) {
20873 + case USB_DEVICE_REMOTE_WAKEUP:
20874 + pcd->remote_wakeup_enable = 0;
20877 + case USB_DEVICE_TEST_MODE:
20878 + /** @todo Add CLEAR_FEATURE for TEST modes. */
20881 + do_setup_in_status_phase(pcd);
20884 + case USB_RECIP_ENDPOINT:
20885 + ep = get_ep_by_addr(pcd, ctrl.wIndex);
20887 + ep0_do_stall(pcd, -EOPNOTSUPP);
20891 + pcd_clear_halt(pcd, ep);
20898 + * This function process the SET_ADDRESS Setup Commands.
20900 +static inline void do_set_address(dwc_otg_pcd_t *pcd)
20902 + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
20903 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
20905 + if (ctrl.bRequestType == USB_RECIP_DEVICE) {
20906 + dcfg_data_t dcfg = {.d32=0};
20909 +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
20911 + dcfg.b.devaddr = ctrl.wValue;
20912 + dwc_modify_reg32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
20913 + do_setup_in_status_phase(pcd);
20918 + * This function processes SETUP commands. In Linux, the USB Command
20919 + * processing is done in two places - the first being the PCD and the
20920 + * second in the Gadget Driver (for example, the File-Backed Storage
20921 + * Gadget Driver).
20924 + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
20926 + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
20927 + * defined in chapter 9 of the USB 2.0 Specification chapter 9
20930 + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
20931 + * requests are the ENDPOINT_HALT feature is procesed, all others the
20932 + * interface requests are ignored.</td></tr>
20934 + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
20935 + * requests are processed by the PCD. Interface requests are passed
20936 + * to the Gadget Driver.</td></tr>
20938 + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
20939 + * with device address received </td></tr>
20941 + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
20942 + * requested descriptor</td></tr>
20944 + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
20945 + * not implemented by any of the existing Gadget Drivers.</td></tr>
20947 + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
20948 + * all EPs and enable EPs for new configuration.</td></tr>
20950 + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
20951 + * the current configuration</td></tr>
20953 + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
20954 + * EPs and enable EPs for new configuration.</td></tr>
20956 + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
20957 + * current interface.</td></tr>
20959 + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
20960 + * message.</td></tr>
20963 + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
20964 + * processed by pcd_setup. Calling the Function Driver's setup function from
20965 + * pcd_setup processes the gadget SETUP commands.
20967 +static inline void pcd_setup(dwc_otg_pcd_t *pcd)
20969 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
20970 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
20971 + struct usb_ctrlrequest ctrl = pcd->setup_pkt->req;
20972 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
20974 + deptsiz0_data_t doeptsize0 = { .d32 = 0};
20977 + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
20978 + ctrl.bRequestType, ctrl.bRequest,
20979 + ctrl.wValue, ctrl.wIndex, ctrl.wLength);
20982 + doeptsize0.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doeptsiz);
20984 + /** @todo handle > 1 setup packet , assert error for now */
20986 + if (core_if->dma_enable && core_if->dma_desc_enable == 0 && (doeptsize0.b.supcnt < 2)) {
20987 + DWC_ERROR ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
20990 + /* Clean up the request queue */
20991 + dwc_otg_request_nuke(ep0);
20992 + ep0->stopped = 0;
20994 + if (ctrl.bRequestType & USB_DIR_IN) {
20995 + ep0->dwc_ep.is_in = 1;
20996 + pcd->ep0state = EP0_IN_DATA_PHASE;
20999 + ep0->dwc_ep.is_in = 0;
21000 + pcd->ep0state = EP0_OUT_DATA_PHASE;
21003 + if(ctrl.wLength == 0) {
21004 + ep0->dwc_ep.is_in = 1;
21005 + pcd->ep0state = EP0_IN_STATUS_PHASE;
21008 + if ((ctrl.bRequestType & USB_TYPE_MASK) != USB_TYPE_STANDARD) {
21009 + /* handle non-standard (class/vendor) requests in the gadget driver */
21010 + do_gadget_setup(pcd, &ctrl);
21014 + /** @todo NGS: Handle bad setup packet? */
21016 +///////////////////////////////////////////
21017 +//// --- Standard Request handling --- ////
21019 + switch (ctrl.bRequest) {
21020 + case USB_REQ_GET_STATUS:
21021 + do_get_status(pcd);
21024 + case USB_REQ_CLEAR_FEATURE:
21025 + do_clear_feature(pcd);
21028 + case USB_REQ_SET_FEATURE:
21029 + do_set_feature(pcd);
21032 + case USB_REQ_SET_ADDRESS:
21033 + do_set_address(pcd);
21036 + case USB_REQ_SET_INTERFACE:
21037 + case USB_REQ_SET_CONFIGURATION:
21038 +// _pcd->request_config = 1; /* Configuration changed */
21039 + do_gadget_setup(pcd, &ctrl);
21042 + case USB_REQ_SYNCH_FRAME:
21043 + do_gadget_setup(pcd, &ctrl);
21047 + /* Call the Gadget Driver's setup functions */
21048 + do_gadget_setup(pcd, &ctrl);
21054 + * This function completes the ep0 control transfer.
21056 +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t *ep)
21058 + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
21059 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
21060 + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
21061 + dev_if->in_ep_regs[ep->dwc_ep.num];
21063 + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
21064 + dev_if->out_ep_regs[ep->dwc_ep.num];
21066 + deptsiz0_data_t deptsiz;
21067 + desc_sts_data_t desc_sts;
21068 + dwc_otg_pcd_request_t *req;
21070 + dwc_otg_pcd_t *pcd = ep->pcd;
21072 + //DWC_DEBUGPL(DBG_PCDV, "%s() %s\n", __func__, _ep->ep.name);
21074 + if (pcd->ep0_pending && list_empty(&ep->queue)) {
21075 + if (ep->dwc_ep.is_in) {
21077 + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
21079 + do_setup_out_status_phase(pcd);
21083 + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
21085 + do_setup_in_status_phase(pcd);
21087 + pcd->ep0_pending = 0;
21091 + if (list_empty(&ep->queue)) {
21094 + req = list_entry(ep->queue.next, dwc_otg_pcd_request_t, queue);
21097 + if (pcd->ep0state == EP0_OUT_STATUS_PHASE || pcd->ep0state == EP0_IN_STATUS_PHASE) {
21100 + else if (ep->dwc_ep.is_in) {
21101 + deptsiz.d32 = dwc_read_reg32(&in_ep_regs->dieptsiz);
21102 + if(core_if->dma_desc_enable != 0)
21103 + desc_sts.d32 = readl(dev_if->in_desc_addr);
21105 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xfersize=%d pktcnt=%d\n",
21106 + ep->ep.name, ep->dwc_ep.xfer_len,
21107 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
21110 + if (((core_if->dma_desc_enable == 0) && (deptsiz.b.xfersize == 0)) ||
21111 + ((core_if->dma_desc_enable != 0) && (desc_sts.b.bytes == 0))) {
21112 + req->req.actual = ep->dwc_ep.xfer_count;
21113 + /* Is a Zero Len Packet needed? */
21114 + if (req->req.zero) {
21116 + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
21118 + req->req.zero = 0;
21120 + do_setup_out_status_phase(pcd);
21126 + deptsiz.d32 = dwc_read_reg32(&out_ep_regs->doeptsiz);
21127 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xsize=%d pktcnt=%d\n",
21128 + ep->ep.name, ep->dwc_ep.xfer_len,
21129 + deptsiz.b.xfersize,
21130 + deptsiz.b.pktcnt);
21132 + req->req.actual = ep->dwc_ep.xfer_count;
21133 + /* Is a Zero Len Packet needed? */
21134 + if (req->req.zero) {
21136 + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
21138 + req->req.zero = 0;
21140 + if(core_if->dma_desc_enable == 0)
21141 + do_setup_in_status_phase(pcd);
21144 + /* Complete the request */
21146 + dwc_otg_request_done(ep, req, 0);
21147 + ep->dwc_ep.start_xfer_buff = 0;
21148 + ep->dwc_ep.xfer_buff = 0;
21149 + ep->dwc_ep.xfer_len = 0;
21155 +inline void aligned_buf_patch_on_buf_dma_oep_completion(dwc_otg_pcd_ep_t *ep, uint32_t byte_count)
21157 + dwc_ep_t *dwc_ep = &ep->dwc_ep;
21158 + if(byte_count && dwc_ep->aligned_buf &&
21159 + dwc_ep->dma_addr>=dwc_ep->aligned_dma_addr &&
21160 + dwc_ep->dma_addr<=(dwc_ep->aligned_dma_addr+dwc_ep->aligned_buf_size))\
21162 + //aligned buf used, apply complete patch
21163 + u32 offset=(dwc_ep->dma_addr-dwc_ep->aligned_dma_addr);
21164 + memcpy(dwc_ep->start_xfer_buff+offset, dwc_ep->aligned_buf+offset, byte_count);
21170 + * This function completes the request for the EP. If there are
21171 + * additional requests for the EP in the queue they will be started.
21173 +static void complete_ep(dwc_otg_pcd_ep_t *ep)
21175 + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
21176 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
21177 + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
21178 + dev_if->in_ep_regs[ep->dwc_ep.num];
21179 + deptsiz_data_t deptsiz;
21180 + desc_sts_data_t desc_sts;
21181 + dwc_otg_pcd_request_t *req = 0;
21182 + dwc_otg_dma_desc_t* dma_desc;
21183 + uint32_t byte_count = 0;
21187 + DWC_DEBUGPL(DBG_PCDV,"%s() %s-%s\n", __func__, ep->ep.name,
21188 + (ep->dwc_ep.is_in?"IN":"OUT"));
21190 + /* Get any pending requests */
21191 + if (!list_empty(&ep->queue)) {
21192 + req = list_entry(ep->queue.next, dwc_otg_pcd_request_t,
21195 + printk("complete_ep 0x%p, req = NULL!\n", ep);
21200 + printk("complete_ep 0x%p, ep->queue empty!\n", ep);
21203 + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
21205 + if (ep->dwc_ep.is_in) {
21206 + deptsiz.d32 = dwc_read_reg32(&in_ep_regs->dieptsiz);
21208 + if (core_if->dma_enable) {
21209 + //dma_unmap_single(NULL,ep->dwc_ep.dma_addr,ep->dwc_ep.xfer_count,DMA_NONE);
21210 + if(core_if->dma_desc_enable == 0) {
21211 + //dma_unmap_single(NULL,ep->dwc_ep.dma_addr,ep->dwc_ep.xfer_count,DMA_NONE);
21212 + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
21213 + byte_count = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
21214 +DWC_DEBUGPL(DBG_PCDV,"byte_count(%.8x) = (ep->dwc_ep.xfer_len(%.8x) - ep->dwc_ep.xfer_count(%.8x)\n", byte_count ,ep->dwc_ep.xfer_len , ep->dwc_ep.xfer_count );
21216 + ep->dwc_ep.xfer_buff += byte_count;
21217 + ep->dwc_ep.dma_addr += byte_count;
21218 + ep->dwc_ep.xfer_count += byte_count;
21220 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xfersize=%d pktcnt=%d\n",
21221 + ep->ep.name, ep->dwc_ep.xfer_len,
21222 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
21225 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
21226 + //dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
21227 +printk("Warning: transfer ended, but specified len is not accomplished!! ep->total_len=%.x,ep->dwc_ep.sent_zlp=%d, byte_count(%.8x) = (ep->dwc_ep.xfer_len(%.8x) - ep->dwc_ep.xfer_count(%.8x) - deptsiz.b.xfersize(%.8x)\n", ep->dwc_ep.total_len, ep->dwc_ep.sent_zlp, byte_count ,ep->dwc_ep.xfer_len , ep->dwc_ep.xfer_count , deptsiz.b.xfersize);
21228 + } else if(ep->dwc_ep.sent_zlp) {
21230 + * This fragment of code should initiate 0
21231 + * length trasfer in case if it is queued
21232 + * a trasfer with size divisible to EPs max
21233 + * packet size and with usb_request zero field
21234 + * is set, which means that after data is transfered,
21235 + * it is also should be transfered
21236 + * a 0 length packet at the end. For Slave and
21237 + * Buffer DMA modes in this case SW has
21238 + * to initiate 2 transfers one with transfer size,
21239 + * and the second with 0 size. For Desriptor
21240 + * DMA mode SW is able to initiate a transfer,
21241 + * which will handle all the packets including
21242 + * the last 0 legth.
21244 + ep->dwc_ep.sent_zlp = 0;
21245 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
21250 + DWC_WARN("Incomplete transfer (%s-%s [siz=%d pkt=%d])\n",
21251 + ep->ep.name, (ep->dwc_ep.is_in?"IN":"OUT"),
21252 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
21256 + dma_desc = ep->dwc_ep.desc_addr;
21258 + ep->dwc_ep.sent_zlp = 0;
21260 + for(i = 0; i < ep->dwc_ep.desc_cnt; ++i) {
21261 + desc_sts.d32 = readl(dma_desc);
21262 + byte_count += desc_sts.b.bytes;
21266 + if(byte_count == 0) {
21267 + ep->dwc_ep.xfer_count = ep->dwc_ep.total_len;
21270 + DWC_WARN("Incomplete transfer\n");
21274 + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
21275 + /* Check if the whole transfer was completed,
21276 + * if no, setup transfer for next portion of data
21278 + DWC_DEBUGPL(DBG_PCDV, "%s len=%d xfersize=%d pktcnt=%d\n",
21279 + ep->ep.name, ep->dwc_ep.xfer_len,
21280 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
21281 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
21282 + //dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
21283 +printk("Warning: transfer ended, but specified len is not accomplished!! ep->total_len=%.x,ep->dwc_ep.sent_zlp=%d, ep->dwc_ep.xfer_len(%.8x) \n", ep->dwc_ep.total_len, ep->dwc_ep.sent_zlp, ep->dwc_ep.xfer_len );
21284 + } else if(ep->dwc_ep.sent_zlp) {
21286 + * This fragment of code should initiate 0
21287 + * length trasfer in case if it is queued
21288 + * a trasfer with size divisible to EPs max
21289 + * packet size and with usb_request zero field
21290 + * is set, which means that after data is transfered,
21291 + * it is also should be transfered
21292 + * a 0 length packet at the end. For Slave and
21293 + * Buffer DMA modes in this case SW has
21294 + * to initiate 2 transfers one with transfer size,
21295 + * and the second with 0 size. For Desriptor
21296 + * DMA mode SW is able to initiate a transfer,
21297 + * which will handle all the packets including
21298 + * the last 0 legth.
21300 + ep->dwc_ep.sent_zlp = 0;
21301 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
21307 + DWC_WARN("Incomplete transfer (%s-%s [siz=%d pkt=%d])\n",
21308 + ep->ep.name, (ep->dwc_ep.is_in?"IN":"OUT"),
21309 + deptsiz.b.xfersize, deptsiz.b.pktcnt);
21313 + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
21314 + dev_if->out_ep_regs[ep->dwc_ep.num];
21315 + desc_sts.d32 = 0;
21316 + if(core_if->dma_enable) {
21317 + //dma_unmap_single(NULL,ep->dwc_ep.dma_addr,ep->dwc_ep.xfer_count,DMA_FROM_DEVICE);
21318 + if(core_if->dma_desc_enable) {
21319 + DWC_WARN("\n\n%s: we need a cache invalidation here!!\n\n",__func__);
21320 + dma_desc = ep->dwc_ep.desc_addr;
21322 + ep->dwc_ep.sent_zlp = 0;
21323 + for(i = 0; i < ep->dwc_ep.desc_cnt; ++i) {
21324 + desc_sts.d32 = readl(dma_desc);
21325 + byte_count += desc_sts.b.bytes;
21329 + ep->dwc_ep.xfer_count = ep->dwc_ep.total_len
21330 + - byte_count + ((4 - (ep->dwc_ep.total_len & 0x3)) & 0x3);
21332 + //todo: invalidate cache & aligned buf patch on completion
21338 + deptsiz.d32 = dwc_read_reg32(&out_ep_regs->doeptsiz);
21340 + byte_count = (ep->dwc_ep.xfer_len -
21341 + ep->dwc_ep.xfer_count - deptsiz.b.xfersize);
21343 +// dma_sync_single_for_device(NULL,ep->dwc_ep.dma_addr,byte_count,DMA_FROM_DEVICE);
21345 +DWC_DEBUGPL(DBG_PCDV,"ep->total_len=%.x,ep->dwc_ep.sent_zlp=%d, byte_count(%.8x) = (ep->dwc_ep.xfer_len(%.8x) - ep->dwc_ep.xfer_count(%.8x) - deptsiz.b.xfersize(%.8x)\n", ep->dwc_ep.total_len, ep->dwc_ep.sent_zlp, byte_count ,ep->dwc_ep.xfer_len , ep->dwc_ep.xfer_count , deptsiz.b.xfersize);
21346 + //todo: invalidate cache & aligned buf patch on completion
21347 + dma_sync_single_for_device(NULL,ep->dwc_ep.dma_addr,byte_count,DMA_FROM_DEVICE);
21348 + aligned_buf_patch_on_buf_dma_oep_completion(ep,byte_count);
21350 + ep->dwc_ep.xfer_buff += byte_count;
21351 + ep->dwc_ep.dma_addr += byte_count;
21352 + ep->dwc_ep.xfer_count += byte_count;
21354 + /* Check if the whole transfer was completed,
21355 + * if no, setup transfer for next portion of data
21357 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
21358 + //dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
21359 +printk("Warning: transfer ended, but specified len is not accomplished!! ep->total_len=%.x,ep->dwc_ep.sent_zlp=%d, byte_count(%.8x) = (ep->dwc_ep.xfer_len(%.8x) - ep->dwc_ep.xfer_count(%.8x) - deptsiz.b.xfersize(%.8x)\n", ep->dwc_ep.total_len, ep->dwc_ep.sent_zlp, byte_count ,ep->dwc_ep.xfer_len , ep->dwc_ep.xfer_count , deptsiz.b.xfersize);
21361 + else if(ep->dwc_ep.sent_zlp) {
21363 + * This fragment of code should initiate 0
21364 + * length trasfer in case if it is queued
21365 + * a trasfer with size divisible to EPs max
21366 + * packet size and with usb_request zero field
21367 + * is set, which means that after data is transfered,
21368 + * it is also should be transfered
21369 + * a 0 length packet at the end. For Slave and
21370 + * Buffer DMA modes in this case SW has
21371 + * to initiate 2 transfers one with transfer size,
21372 + * and the second with 0 size. For Desriptor
21373 + * DMA mode SW is able to initiate a transfer,
21374 + * which will handle all the packets including
21375 + * the last 0 legth.
21377 + ep->dwc_ep.sent_zlp = 0;
21378 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
21384 + /* Check if the whole transfer was completed,
21385 + * if no, setup transfer for next portion of data
21387 + if(ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
21388 + //dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
21389 +printk("Warning: transfer ended, but specified len is not accomplished!! ep->total_len=%.x,ep->dwc_ep.sent_zlp=%d, ep->dwc_ep.xfer_len(%.8x) \n", ep->dwc_ep.total_len, ep->dwc_ep.sent_zlp, ep->dwc_ep.xfer_len );
21391 + else if(ep->dwc_ep.sent_zlp) {
21393 + * This fragment of code should initiate 0
21394 + * length trasfer in case if it is queued
21395 + * a trasfer with size divisible to EPs max
21396 + * packet size and with usb_request zero field
21397 + * is set, which means that after data is transfered,
21398 + * it is also should be transfered
21399 + * a 0 length packet at the end. For Slave and
21400 + * Buffer DMA modes in this case SW has
21401 + * to initiate 2 transfers one with transfer size,
21402 + * and the second with 0 size. For Desriptor
21403 + * DMA mode SW is able to initiate a transfer,
21404 + * which will handle all the packets including
21405 + * the last 0 legth.
21407 + ep->dwc_ep.sent_zlp = 0;
21408 + dwc_otg_ep_start_zl_transfer(core_if, &ep->dwc_ep);
21416 + DWC_DEBUGPL(DBG_PCDV, "addr %p, %s len=%d cnt=%d xsize=%d pktcnt=%d\n",
21417 + &out_ep_regs->doeptsiz, ep->ep.name, ep->dwc_ep.xfer_len,
21418 + ep->dwc_ep.xfer_count,
21419 + deptsiz.b.xfersize,
21420 + deptsiz.b.pktcnt);
21424 + /* Complete the request */
21426 + req->req.actual = ep->dwc_ep.xfer_count;
21428 + dwc_otg_request_done(ep, req, 0);
21430 + ep->dwc_ep.start_xfer_buff = 0;
21431 + ep->dwc_ep.xfer_buff = 0;
21432 + ep->dwc_ep.xfer_len = 0;
21434 + /* If there is a request in the queue start it.*/
21435 + start_next_request(ep);
21440 +#ifdef DWC_EN_ISOC
21443 + * This function BNA interrupt for Isochronous EPs
21446 +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t *ep)
21448 + dwc_ep_t *dwc_ep = &ep->dwc_ep;
21449 + volatile uint32_t *addr;
21450 + depctl_data_t depctl = {.d32 = 0};
21451 + dwc_otg_pcd_t *pcd = ep->pcd;
21452 + dwc_otg_dma_desc_t *dma_desc;
21455 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
21457 + if(dwc_ep->is_in) {
21458 + desc_sts_data_t sts = {.d32 = 0};
21459 + for(i = 0;i < dwc_ep->desc_cnt; ++i, ++dma_desc)
21461 + sts.d32 = readl(&dma_desc->status);
21462 + sts.b_iso_in.bs = BS_HOST_READY;
21463 + writel(sts.d32,&dma_desc->status);
21467 + desc_sts_data_t sts = {.d32 = 0};
21468 + for(i = 0;i < dwc_ep->desc_cnt; ++i, ++dma_desc)
21470 + sts.d32 = readl(&dma_desc->status);
21471 + sts.b_iso_out.bs = BS_HOST_READY;
21472 + writel(sts.d32,&dma_desc->status);
21476 + if(dwc_ep->is_in == 0){
21477 + addr = &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
21480 + addr = &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
21482 + depctl.b.epena = 1;
21483 + dwc_modify_reg32(addr,depctl.d32,depctl.d32);
21487 + * This function sets latest iso packet information(non-PTI mode)
21489 + * @param core_if Programming view of DWC_otg controller.
21490 + * @param ep The EP to start the transfer on.
21493 +void set_current_pkt_info(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
21495 + deptsiz_data_t deptsiz = { .d32 = 0 };
21496 + dma_addr_t dma_addr;
21499 + if(ep->proc_buf_num)
21500 + dma_addr = ep->dma_addr1;
21502 + dma_addr = ep->dma_addr0;
21506 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz);
21507 + offset = ep->data_per_frame;
21509 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz);
21510 + offset = ep->data_per_frame + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
21513 + if(!deptsiz.b.xfersize) {
21514 + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
21515 + ep->pkt_info[ep->cur_pkt].offset = ep->cur_pkt_dma_addr - dma_addr;
21516 + ep->pkt_info[ep->cur_pkt].status = 0;
21518 + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
21519 + ep->pkt_info[ep->cur_pkt].offset = ep->cur_pkt_dma_addr - dma_addr;
21520 + ep->pkt_info[ep->cur_pkt].status = -ENODATA;
21522 + ep->cur_pkt_addr += offset;
21523 + ep->cur_pkt_dma_addr += offset;
21528 + * This function sets latest iso packet information(DDMA mode)
21530 + * @param core_if Programming view of DWC_otg controller.
21531 + * @param dwc_ep The EP to start the transfer on.
21534 +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
21536 + dwc_otg_dma_desc_t* dma_desc;
21537 + desc_sts_data_t sts = {.d32 = 0};
21538 + iso_pkt_info_t *iso_packet;
21539 + uint32_t data_per_desc;
21543 + iso_packet = dwc_ep->pkt_info;
21545 + /** Reinit closed DMA Descriptors*/
21546 + /** ISO OUT EP */
21547 + if(dwc_ep->is_in == 0) {
21548 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
21551 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
21553 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
21555 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
21556 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
21557 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
21559 + sts.d32 = readl(&dma_desc->status);
21561 + /* Write status in iso_packet_decsriptor */
21562 + iso_packet->status = sts.b_iso_out.rxsts + (sts.b_iso_out.bs^BS_DMA_DONE);
21563 + if(iso_packet->status) {
21564 + iso_packet->status = -ENODATA;
21567 + /* Received data length */
21568 + if(!sts.b_iso_out.rxbytes){
21569 + iso_packet->length = data_per_desc - sts.b_iso_out.rxbytes;
21571 + iso_packet->length = data_per_desc - sts.b_iso_out.rxbytes +
21572 + (4 - dwc_ep->data_per_frame % 4);
21575 + iso_packet->offset = offset;
21577 + offset += data_per_desc;
21583 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
21585 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
21586 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
21587 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
21589 + sts.d32 = readl(&dma_desc->status);
21591 + /* Write status in iso_packet_decsriptor */
21592 + iso_packet->status = sts.b_iso_out.rxsts + (sts.b_iso_out.bs^BS_DMA_DONE);
21593 + if(iso_packet->status) {
21594 + iso_packet->status = -ENODATA;
21597 + /* Received data length */
21598 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
21600 + iso_packet->offset = offset;
21602 + offset += data_per_desc;
21607 + sts.d32 = readl(&dma_desc->status);
21609 + /* Write status in iso_packet_decsriptor */
21610 + iso_packet->status = sts.b_iso_out.rxsts + (sts.b_iso_out.bs^BS_DMA_DONE);
21611 + if(iso_packet->status) {
21612 + iso_packet->status = -ENODATA;
21614 + /* Received data length */
21615 + if(!sts.b_iso_out.rxbytes){
21616 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
21618 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
21619 + (4 - dwc_ep->data_per_frame % 4);
21622 + iso_packet->offset = offset;
21624 + else /** ISO IN EP */
21626 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
21628 + for(i = 0; i < dwc_ep->desc_cnt - 1; i++)
21630 + sts.d32 = readl(&dma_desc->status);
21632 + /* Write status in iso packet descriptor */
21633 + iso_packet->status = sts.b_iso_in.txsts + (sts.b_iso_in.bs^BS_DMA_DONE);
21634 + if(iso_packet->status != 0) {
21635 + iso_packet->status = -ENODATA;
21638 + /* Bytes has been transfered */
21639 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
21645 + sts.d32 = readl(&dma_desc->status);
21646 + while(sts.b_iso_in.bs == BS_DMA_BUSY) {
21647 + sts.d32 = readl(&dma_desc->status);
21650 + /* Write status in iso packet descriptor ??? do be done with ERROR codes*/
21651 + iso_packet->status = sts.b_iso_in.txsts + (sts.b_iso_in.bs^BS_DMA_DONE);
21652 + if(iso_packet->status != 0) {
21653 + iso_packet->status = -ENODATA;
21656 + /* Bytes has been transfered */
21657 + iso_packet->length = dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
21662 + * This function reinitialize DMA Descriptors for Isochronous transfer
21664 + * @param core_if Programming view of DWC_otg controller.
21665 + * @param dwc_ep The EP to start the transfer on.
21668 +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
21671 + dwc_otg_dma_desc_t* dma_desc;
21672 + dma_addr_t dma_ad;
21673 + volatile uint32_t *addr;
21674 + desc_sts_data_t sts = { .d32 =0 };
21675 + uint32_t data_per_desc;
21677 + if(dwc_ep->is_in == 0) {
21678 + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
21681 + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
21685 + if(dwc_ep->proc_buf_num == 0) {
21686 + /** Buffer 0 descriptors setup */
21687 + dma_ad = dwc_ep->dma_addr0;
21690 + /** Buffer 1 descriptors setup */
21691 + dma_ad = dwc_ep->dma_addr1;
21695 + /** Reinit closed DMA Descriptors*/
21696 + /** ISO OUT EP */
21697 + if(dwc_ep->is_in == 0) {
21698 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
21700 + sts.b_iso_out.bs = BS_HOST_READY;
21701 + sts.b_iso_out.rxsts = 0;
21702 + sts.b_iso_out.l = 0;
21703 + sts.b_iso_out.sp = 0;
21704 + sts.b_iso_out.ioc = 0;
21705 + sts.b_iso_out.pid = 0;
21706 + sts.b_iso_out.framenum = 0;
21708 + for(i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm; i+= dwc_ep->pkt_per_frm)
21710 + for(j = 0; j < dwc_ep->pkt_per_frm; ++j)
21712 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
21713 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
21714 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
21715 + sts.b_iso_out.rxbytes = data_per_desc;
21716 + writel((uint32_t)dma_ad, &dma_desc->buf);
21717 + writel(sts.d32, &dma_desc->status);
21719 + //(uint32_t)dma_ad += data_per_desc;
21720 + dma_ad = (uint32_t)dma_ad + data_per_desc;
21725 + for(j = 0; j < dwc_ep->pkt_per_frm - 1; ++j)
21728 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
21729 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
21730 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
21731 + sts.b_iso_out.rxbytes = data_per_desc;
21733 + writel((uint32_t)dma_ad, &dma_desc->buf);
21734 + writel(sts.d32, &dma_desc->status);
21737 + //(uint32_t)dma_ad += data_per_desc;
21738 + dma_ad = (uint32_t)dma_ad + data_per_desc;
21741 + sts.b_iso_out.ioc = 1;
21742 + sts.b_iso_out.l = dwc_ep->proc_buf_num;
21744 + data_per_desc = ((j + 1) * dwc_ep->maxpacket > dwc_ep->data_per_frame) ?
21745 + dwc_ep->data_per_frame - j * dwc_ep->maxpacket : dwc_ep->maxpacket;
21746 + data_per_desc += (data_per_desc % 4) ? (4 - data_per_desc % 4):0;
21747 + sts.b_iso_out.rxbytes = data_per_desc;
21749 + writel((uint32_t)dma_ad, &dma_desc->buf);
21750 + writel(sts.d32, &dma_desc->status);
21752 + else /** ISO IN EP */
21754 + dma_desc = dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
21756 + sts.b_iso_in.bs = BS_HOST_READY;
21757 + sts.b_iso_in.txsts = 0;
21758 + sts.b_iso_in.sp = 0;
21759 + sts.b_iso_in.ioc = 0;
21760 + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
21761 + sts.b_iso_in.framenum = dwc_ep->next_frame;
21762 + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
21763 + sts.b_iso_in.l = 0;
21765 + for(i = 0; i < dwc_ep->desc_cnt - 1; i++)
21767 + writel((uint32_t)dma_ad, &dma_desc->buf);
21768 + writel(sts.d32, &dma_desc->status);
21770 + sts.b_iso_in.framenum += dwc_ep->bInterval;
21771 + //(uint32_t)dma_ad += dwc_ep->data_per_frame;
21772 + dma_ad = (uint32_t)dma_ad + dwc_ep->data_per_frame;
21776 + sts.b_iso_in.ioc = 1;
21777 + sts.b_iso_in.l = dwc_ep->proc_buf_num;
21779 + writel((uint32_t)dma_ad, &dma_desc->buf);
21780 + writel(sts.d32, &dma_desc->status);
21782 + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
21784 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21789 + * This function is to handle Iso EP transfer complete interrupt
21790 + * in case Iso out packet was dropped
21792 + * @param core_if Programming view of DWC_otg controller.
21793 + * @param dwc_ep The EP for wihich transfer complete was asserted
21796 +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
21798 + uint32_t dma_addr;
21799 + uint32_t drp_pkt;
21800 + uint32_t drp_pkt_cnt;
21801 + deptsiz_data_t deptsiz = { .d32 = 0 };
21802 + depctl_data_t depctl = { .d32 = 0 };
21805 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
21807 + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
21808 + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
21810 + /* Setting dropped packets status */
21811 + for(i = 0; i < drp_pkt_cnt; ++i) {
21812 + dwc_ep->pkt_info[drp_pkt].status = -ENODATA;
21814 + deptsiz.b.pktcnt--;
21818 + if(deptsiz.b.pktcnt > 0) {
21819 + deptsiz.b.xfersize = dwc_ep->xfer_len - (dwc_ep->pkt_cnt - deptsiz.b.pktcnt) * dwc_ep->maxpacket;
21821 + deptsiz.b.xfersize = 0;
21822 + deptsiz.b.pktcnt = 0;
21825 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz, deptsiz.d32);
21827 + if(deptsiz.b.pktcnt > 0) {
21828 + if(dwc_ep->proc_buf_num) {
21829 + dma_addr = dwc_ep->dma_addr1 + dwc_ep->xfer_len - deptsiz.b.xfersize;
21831 + dma_addr = dwc_ep->dma_addr0 + dwc_ep->xfer_len - deptsiz.b.xfersize;;
21834 + VERIFY_PCD_DMA_ADDR(dma_addr);
21835 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
21837 + /** Re-enable endpoint, clear nak */
21839 + depctl.b.epena = 1;
21840 + depctl.b.cnak = 1;
21842 + dwc_modify_reg32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl,
21843 + depctl.d32,depctl.d32);
21851 + * This function sets iso packets information(PTI mode)
21853 + * @param core_if Programming view of DWC_otg controller.
21854 + * @param ep The EP to start the transfer on.
21857 +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
21860 + dma_addr_t dma_ad;
21861 + iso_pkt_info_t *packet_info = ep->pkt_info;
21863 + uint32_t frame_data;
21864 + deptsiz_data_t deptsiz;
21866 + if(ep->proc_buf_num == 0) {
21867 + /** Buffer 0 descriptors setup */
21868 + dma_ad = ep->dma_addr0;
21871 + /** Buffer 1 descriptors setup */
21872 + dma_ad = ep->dma_addr1;
21877 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz);
21879 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[ep->num]->doeptsiz);
21882 + if(!deptsiz.b.xfersize) {
21884 + for(i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm)
21886 + frame_data = ep->data_per_frame;
21887 + for(j = 0; j < ep->pkt_per_frm; ++j) {
21889 + /* Packet status - is not set as initially
21890 + * it is set to 0 and if packet was sent
21891 + successfully, status field will remain 0*/
21894 + /* Bytes has been transfered */
21895 + packet_info->length = (ep->maxpacket < frame_data) ?
21896 + ep->maxpacket : frame_data;
21898 + /* Received packet offset */
21899 + packet_info->offset = offset;
21900 + offset += packet_info->length;
21901 + frame_data -= packet_info->length;
21908 + /* This is a workaround for in case of Transfer Complete with
21909 + * PktDrpSts interrupts merging - in this case Transfer complete
21910 + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
21911 + * set and with DOEPTSIZ register non zero. Investigations showed,
21912 + * that this happens when Out packet is dropped, but because of
21913 + * interrupts merging during first interrupt handling PktDrpSts
21914 + * bit is cleared and for next merged interrupts it is not reset.
21915 + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
21920 + return handle_iso_out_pkt_dropped(core_if, ep);
21926 + * This function is to handle Iso EP transfer complete interrupt
21928 + * @param ep The EP for which transfer complete was asserted
21931 +static void complete_iso_ep(dwc_otg_pcd_ep_t *ep)
21933 + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
21934 + dwc_ep_t *dwc_ep = &ep->dwc_ep;
21935 + uint8_t is_last = 0;
21937 + if(core_if->dma_enable) {
21938 + if(core_if->dma_desc_enable) {
21939 + set_ddma_iso_pkts_info(core_if, dwc_ep);
21940 + reinit_ddma_iso_xfer(core_if, dwc_ep);
21943 + if(core_if->pti_enh_enable) {
21944 + if(set_iso_pkts_info(core_if, dwc_ep)) {
21945 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21946 + dwc_otg_iso_ep_start_buf_transfer(core_if, dwc_ep);
21950 + set_current_pkt_info(core_if, dwc_ep);
21951 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
21953 + dwc_ep->cur_pkt = 0;
21954 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21955 + if(dwc_ep->proc_buf_num) {
21956 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
21957 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
21959 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
21960 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
21964 + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
21968 + set_current_pkt_info(core_if, dwc_ep);
21969 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
21971 + dwc_ep->cur_pkt = 0;
21972 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
21973 + if(dwc_ep->proc_buf_num) {
21974 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
21975 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
21977 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
21978 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
21982 + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
21985 + dwc_otg_iso_buffer_done(ep, ep->iso_req);
21988 +#endif //DWC_EN_ISOC
21992 + * This function handles EP0 Control transfers.
21994 + * The state of the control tranfers are tracked in
21995 + * <code>ep0state</code>.
21997 +static void handle_ep0(dwc_otg_pcd_t *pcd)
21999 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
22000 + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
22001 + desc_sts_data_t desc_sts;
22002 + deptsiz0_data_t deptsiz;
22003 + uint32_t byte_count;
22006 + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
22007 + print_ep0_state(pcd);
22010 + switch (pcd->ep0state) {
22011 + case EP0_DISCONNECT:
22015 + pcd->request_config = 0;
22020 + case EP0_IN_DATA_PHASE:
22022 + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
22023 + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ?"IN":"OUT"),
22024 + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
22027 + if (core_if->dma_enable != 0) {
22029 + * For EP0 we can only program 1 packet at a time so we
22030 + * need to do the make calculations after each complete.
22031 + * Call write_packet to make the calculations, as in
22032 + * slave mode, and use those values to determine if we
22035 + if(core_if->dma_desc_enable == 0) {
22036 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->in_ep_regs[0]->dieptsiz);
22037 + byte_count = ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
22040 + desc_sts.d32 = readl(core_if->dev_if->in_desc_addr);
22041 + byte_count = ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
22044 + ep0->dwc_ep.xfer_count += byte_count;
22045 + ep0->dwc_ep.xfer_buff += byte_count;
22046 + ep0->dwc_ep.dma_addr += byte_count;
22048 + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
22049 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
22050 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
22052 + else if(ep0->dwc_ep.sent_zlp) {
22053 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
22054 + ep0->dwc_ep.sent_zlp = 0;
22055 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
22058 + ep0_complete_request(ep0);
22059 + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
22062 + case EP0_OUT_DATA_PHASE:
22064 + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
22065 + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ?"IN":"OUT"),
22066 + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
22068 + if (core_if->dma_enable != 0) {
22069 + if(core_if->dma_desc_enable == 0) {
22070 + deptsiz.d32 = dwc_read_reg32(&core_if->dev_if->out_ep_regs[0]->doeptsiz);
22071 + byte_count = ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
22073 + //todo: invalidate cache & aligned buf patch on completion
22074 + dma_sync_single_for_device(NULL,ep0->dwc_ep.dma_addr,byte_count,DMA_FROM_DEVICE);
22075 + aligned_buf_patch_on_buf_dma_oep_completion(ep0,byte_count);
22078 + desc_sts.d32 = readl(core_if->dev_if->out_desc_addr);
22079 + byte_count = ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
22081 + //todo: invalidate cache & aligned buf patch on completion
22085 + ep0->dwc_ep.xfer_count += byte_count;
22086 + ep0->dwc_ep.xfer_buff += byte_count;
22087 + ep0->dwc_ep.dma_addr += byte_count;
22089 + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
22090 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
22091 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
22093 + else if(ep0->dwc_ep.sent_zlp) {
22094 + dwc_otg_ep0_continue_transfer (GET_CORE_IF(pcd), &ep0->dwc_ep);
22095 + ep0->dwc_ep.sent_zlp = 0;
22096 + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
22099 + ep0_complete_request(ep0);
22100 + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
22105 + case EP0_IN_STATUS_PHASE:
22106 + case EP0_OUT_STATUS_PHASE:
22107 + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
22108 + ep0_complete_request(ep0);
22109 + pcd->ep0state = EP0_IDLE;
22110 + ep0->stopped = 1;
22111 + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
22113 + /* Prepare for more SETUP Packets */
22114 + if(core_if->dma_enable) {
22115 + ep0_out_start(core_if, pcd);
22120 + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
22124 + print_ep0_state(pcd);
22130 + * Restart transfer
22132 +static void restart_transfer(dwc_otg_pcd_t *pcd, const uint32_t epnum)
22134 + dwc_otg_core_if_t *core_if;
22135 + dwc_otg_dev_if_t *dev_if;
22136 + deptsiz_data_t dieptsiz = {.d32=0};
22137 + dwc_otg_pcd_ep_t *ep;
22139 + ep = get_in_ep(pcd, epnum);
22141 +#ifdef DWC_EN_ISOC
22142 + if(ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
22145 +#endif /* DWC_EN_ISOC */
22147 + core_if = GET_CORE_IF(pcd);
22148 + dev_if = core_if->dev_if;
22150 + dieptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dieptsiz);
22152 + DWC_DEBUGPL(DBG_PCD,"xfer_buff=%p xfer_count=%0x xfer_len=%0x"
22153 + " stopped=%d\n", ep->dwc_ep.xfer_buff,
22154 + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len ,
22157 + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
22159 + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
22160 + ep->dwc_ep.start_xfer_buff != 0) {
22161 + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
22162 + ep->dwc_ep.xfer_count = 0;
22163 + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
22164 + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
22167 + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
22168 + /* convert packet size to dwords. */
22169 + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
22170 + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
22173 + DWC_DEBUGPL(DBG_PCD,"xfer_buff=%p xfer_count=%0x "
22174 + "xfer_len=%0x stopped=%d\n",
22175 + ep->dwc_ep.xfer_buff,
22176 + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len ,
22179 + if (epnum == 0) {
22180 + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
22183 + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
22190 + * handle the IN EP disable interrupt.
22192 +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t *pcd,
22193 + const uint32_t epnum)
22195 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
22196 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
22197 + deptsiz_data_t dieptsiz = {.d32=0};
22198 + dctl_data_t dctl = {.d32=0};
22199 + dwc_otg_pcd_ep_t *ep;
22200 + dwc_ep_t *dwc_ep;
22202 + ep = get_in_ep(pcd, epnum);
22203 + dwc_ep = &ep->dwc_ep;
22205 + if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
22206 + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
22210 + DWC_DEBUGPL(DBG_PCD,"diepctl%d=%0x\n", epnum,
22211 + dwc_read_reg32(&dev_if->in_ep_regs[epnum]->diepctl));
22212 + dieptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->dieptsiz);
22214 + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
22215 + dieptsiz.b.pktcnt,
22216 + dieptsiz.b.xfersize);
22218 + if (ep->stopped) {
22219 + /* Flush the Tx FIFO */
22220 + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
22221 + /* Clear the Global IN NP NAK */
22223 + dctl.b.cgnpinnak = 1;
22224 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl,
22226 + /* Restart the transaction */
22227 + if (dieptsiz.b.pktcnt != 0 ||
22228 + dieptsiz.b.xfersize != 0) {
22229 + restart_transfer(pcd, epnum);
22233 + /* Restart the transaction */
22234 + if (dieptsiz.b.pktcnt != 0 ||
22235 + dieptsiz.b.xfersize != 0) {
22236 + restart_transfer(pcd, epnum);
22238 + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
22243 + * Handler for the IN EP timeout handshake interrupt.
22245 +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t *pcd,
22246 + const uint32_t epnum)
22248 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
22249 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
22252 + deptsiz_data_t dieptsiz = {.d32=0};
22253 + uint32_t num = 0;
22255 + dctl_data_t dctl = {.d32=0};
22256 + dwc_otg_pcd_ep_t *ep;
22258 + gintmsk_data_t intr_mask = {.d32 = 0};
22260 + ep = get_in_ep(pcd, epnum);
22262 + /* Disable the NP Tx Fifo Empty Interrrupt */
22263 + if (!core_if->dma_enable) {
22264 + intr_mask.b.nptxfempty = 1;
22265 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
22267 + /** @todo NGS Check EP type.
22268 + * Implement for Periodic EPs */
22270 + * Non-periodic EP
22272 + /* Enable the Global IN NAK Effective Interrupt */
22273 + intr_mask.b.ginnakeff = 1;
22274 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk,
22275 + 0, intr_mask.d32);
22277 + /* Set Global IN NAK */
22278 + dctl.b.sgnpinnak = 1;
22279 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl,
22280 + dctl.d32, dctl.d32);
22285 + dieptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[num]->dieptsiz);
22286 + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
22287 + dieptsiz.b.pktcnt,
22288 + dieptsiz.b.xfersize);
22291 +#ifdef DISABLE_PERIODIC_EP
22293 + * Set the NAK bit for this EP to
22294 + * start the disable process.
22297 + diepctl.b.snak = 1;
22298 + dwc_modify_reg32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32, diepctl.d32);
22299 + ep->disabling = 1;
22305 + * Handler for the IN EP NAK interrupt.
22307 +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t *pcd,
22308 + const uint32_t epnum)
22310 + /** @todo implement ISR */
22311 + dwc_otg_core_if_t* core_if;
22312 + diepmsk_data_t intr_mask = { .d32 = 0};
22314 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
22315 + core_if = GET_CORE_IF(pcd);
22316 + intr_mask.b.nak = 1;
22318 + if(core_if->multiproc_int_enable) {
22319 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->diepeachintmsk[epnum],
22320 + intr_mask.d32, 0);
22322 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->diepmsk,
22323 + intr_mask.d32, 0);
22330 + * Handler for the OUT EP Babble interrupt.
22332 +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t *pcd,
22333 + const uint32_t epnum)
22335 + /** @todo implement ISR */
22336 + dwc_otg_core_if_t* core_if;
22337 + doepmsk_data_t intr_mask = { .d32 = 0};
22339 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "OUT EP Babble");
22340 + core_if = GET_CORE_IF(pcd);
22341 + intr_mask.b.babble = 1;
22343 + if(core_if->multiproc_int_enable) {
22344 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[epnum],
22345 + intr_mask.d32, 0);
22347 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepmsk,
22348 + intr_mask.d32, 0);
22355 + * Handler for the OUT EP NAK interrupt.
22357 +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t *pcd,
22358 + const uint32_t epnum)
22360 + /** @todo implement ISR */
22361 + dwc_otg_core_if_t* core_if;
22362 + doepmsk_data_t intr_mask = { .d32 = 0};
22364 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
22365 + core_if = GET_CORE_IF(pcd);
22366 + intr_mask.b.nak = 1;
22368 + if(core_if->multiproc_int_enable) {
22369 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[epnum],
22370 + intr_mask.d32, 0);
22372 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepmsk,
22373 + intr_mask.d32, 0);
22380 + * Handler for the OUT EP NYET interrupt.
22382 +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t *pcd,
22383 + const uint32_t epnum)
22385 + /** @todo implement ISR */
22386 + dwc_otg_core_if_t* core_if;
22387 + doepmsk_data_t intr_mask = { .d32 = 0};
22389 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
22390 + core_if = GET_CORE_IF(pcd);
22391 + intr_mask.b.nyet = 1;
22393 + if(core_if->multiproc_int_enable) {
22394 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepeachintmsk[epnum],
22395 + intr_mask.d32, 0);
22397 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->doepmsk,
22398 + intr_mask.d32, 0);
22405 + * This interrupt indicates that an IN EP has a pending Interrupt.
22406 + * The sequence for handling the IN EP interrupt is shown below:
22407 + * -# Read the Device All Endpoint Interrupt register
22408 + * -# Repeat the following for each IN EP interrupt bit set (from
22410 + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
22411 + * -# If "Transfer Complete" call the request complete function
22412 + * -# If "Endpoint Disabled" complete the EP disable procedure.
22413 + * -# If "AHB Error Interrupt" log error
22414 + * -# If "Time-out Handshake" log error
22415 + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
22417 + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
22418 + * Mismatch Interrupt)
22420 +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t *pcd)
22422 +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
22424 + diepint_data_t diepint = {.d32=0}; \
22425 + diepint.b.__intr = 1; \
22426 + dwc_write_reg32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
22430 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
22431 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
22432 + diepint_data_t diepint = {.d32=0};
22433 + dctl_data_t dctl = {.d32=0};
22434 + depctl_data_t depctl = {.d32=0};
22435 + uint32_t ep_intr;
22436 + uint32_t epnum = 0;
22437 + dwc_otg_pcd_ep_t *ep;
22438 + dwc_ep_t *dwc_ep;
22439 + gintmsk_data_t intr_mask = {.d32 = 0};
22443 + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
22445 + /* Read in the device interrupt bits */
22446 + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
22448 + /* Service the Device IN interrupts for each endpoint */
22450 + if (ep_intr&0x1) {
22451 + uint32_t empty_msk;
22452 + /* Get EP pointer */
22453 + ep = get_in_ep(pcd, epnum);
22454 + dwc_ep = &ep->dwc_ep;
22456 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->diepctl);
22457 + empty_msk = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
22459 + DWC_DEBUGPL(DBG_PCDV,
22460 + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
22465 + DWC_DEBUGPL(DBG_PCD,
22466 + "EP%d-%s: type=%d, mps=%d\n",
22467 + dwc_ep->num, (dwc_ep->is_in ?"IN":"OUT"),
22468 + dwc_ep->type, dwc_ep->maxpacket);
22470 + diepint.d32 = dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
22472 + DWC_DEBUGPL(DBG_PCDV, "EP %d Interrupt Register - 0x%x\n", epnum, diepint.d32);
22473 + /* Transfer complete */
22474 + if (diepint.b.xfercompl) {
22475 + /* Disable the NP Tx FIFO Empty
22477 + if(core_if->en_multiple_tx_fifo == 0) {
22478 + intr_mask.b.nptxfempty = 1;
22479 + dwc_modify_reg32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
22482 + /* Disable the Tx FIFO Empty Interrupt for this EP */
22483 + uint32_t fifoemptymsk = 0x1 << dwc_ep->num;
22484 + dwc_modify_reg32(&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
22485 + fifoemptymsk, 0);
22487 + /* Clear the bit in DIEPINTn for this interrupt */
22488 + CLEAR_IN_EP_INTR(core_if,epnum,xfercompl);
22490 + /* Complete the transfer */
22491 + if (epnum == 0) {
22494 +#ifdef DWC_EN_ISOC
22495 + else if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
22497 + complete_iso_ep(ep);
22499 +#endif //DWC_EN_ISOC
22505 + /* Endpoint disable */
22506 + if (diepint.b.epdisabled) {
22507 + DWC_DEBUGPL(DBG_ANY,"EP%d IN disabled\n", epnum);
22508 + handle_in_ep_disable_intr(pcd, epnum);
22510 + /* Clear the bit in DIEPINTn for this interrupt */
22511 + CLEAR_IN_EP_INTR(core_if,epnum,epdisabled);
22514 + if (diepint.b.ahberr) {
22515 + DWC_DEBUGPL(DBG_ANY,"EP%d IN AHB Error\n", epnum);
22516 + /* Clear the bit in DIEPINTn for this interrupt */
22517 + CLEAR_IN_EP_INTR(core_if,epnum,ahberr);
22519 + /* TimeOUT Handshake (non-ISOC IN EPs) */
22520 + if (diepint.b.timeout) {
22521 + DWC_DEBUGPL(DBG_ANY,"EP%d IN Time-out\n", epnum);
22522 + handle_in_ep_timeout_intr(pcd, epnum);
22524 + CLEAR_IN_EP_INTR(core_if,epnum,timeout);
22526 + /** IN Token received with TxF Empty */
22527 + if (diepint.b.intktxfemp) {
22528 + DWC_DEBUGPL(DBG_ANY,"EP%d IN TKN TxFifo Empty\n",
22530 + if (!ep->stopped && epnum != 0) {
22532 + diepmsk_data_t diepmsk = { .d32 = 0};
22533 + diepmsk.b.intktxfemp = 1;
22535 + if(core_if->multiproc_int_enable) {
22536 + dwc_modify_reg32(&dev_if->dev_global_regs->diepeachintmsk[epnum],
22539 + dwc_modify_reg32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32, 0);
22541 + start_next_request(ep);
22543 + else if(core_if->dma_desc_enable && epnum == 0 &&
22544 + pcd->ep0state == EP0_OUT_STATUS_PHASE) {
22545 + // EP0 IN set STALL
22546 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[epnum]->diepctl);
22548 + /* set the disable and stall bits */
22549 + if (depctl.b.epena) {
22550 + depctl.b.epdis = 1;
22552 + depctl.b.stall = 1;
22553 + dwc_write_reg32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
22555 + CLEAR_IN_EP_INTR(core_if,epnum,intktxfemp);
22557 + /** IN Token Received with EP mismatch */
22558 + if (diepint.b.intknepmis) {
22559 + DWC_DEBUGPL(DBG_ANY,"EP%d IN TKN EP Mismatch\n", epnum);
22560 + CLEAR_IN_EP_INTR(core_if,epnum,intknepmis);
22562 + /** IN Endpoint NAK Effective */
22563 + if (diepint.b.inepnakeff) {
22564 + DWC_DEBUGPL(DBG_ANY,"EP%d IN EP NAK Effective\n", epnum);
22565 + /* Periodic EP */
22566 + if (ep->disabling) {
22568 + depctl.b.snak = 1;
22569 + depctl.b.epdis = 1;
22570 + dwc_modify_reg32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32, depctl.d32);
22572 + CLEAR_IN_EP_INTR(core_if,epnum,inepnakeff);
22576 + /** IN EP Tx FIFO Empty Intr */
22577 + if (diepint.b.emptyintr) {
22578 + DWC_DEBUGPL(DBG_ANY,"EP%d Tx FIFO Empty Intr \n", epnum);
22579 + write_empty_tx_fifo(pcd, epnum);
22581 + CLEAR_IN_EP_INTR(core_if,epnum,emptyintr);
22585 + /** IN EP BNA Intr */
22586 + if (diepint.b.bna) {
22587 + CLEAR_IN_EP_INTR(core_if,epnum,bna);
22588 + if(core_if->dma_desc_enable) {
22589 +#ifdef DWC_EN_ISOC
22590 + if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
22592 + * This checking is performed to prevent first "false" BNA
22593 + * handling occuring right after reconnect
22595 + if(dwc_ep->next_frame != 0xffffffff)
22596 + dwc_otg_pcd_handle_iso_bna(ep);
22599 +#endif //DWC_EN_ISOC
22601 + dctl.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dctl);
22603 + /* If Global Continue on BNA is disabled - disable EP */
22604 + if(!dctl.b.gcontbna) {
22606 + depctl.b.snak = 1;
22607 + depctl.b.epdis = 1;
22608 + dwc_modify_reg32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32, depctl.d32);
22610 + start_next_request(ep);
22615 + /* NAK Interrutp */
22616 + if (diepint.b.nak) {
22617 + DWC_DEBUGPL(DBG_ANY,"EP%d IN NAK Interrupt\n", epnum);
22618 + handle_in_ep_nak_intr(pcd, epnum);
22620 + CLEAR_IN_EP_INTR(core_if,epnum,nak);
22628 +#undef CLEAR_IN_EP_INTR
22632 + * This interrupt indicates that an OUT EP has a pending Interrupt.
22633 + * The sequence for handling the OUT EP interrupt is shown below:
22634 + * -# Read the Device All Endpoint Interrupt register
22635 + * -# Repeat the following for each OUT EP interrupt bit set (from
22637 + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
22638 + * -# If "Transfer Complete" call the request complete function
22639 + * -# If "Endpoint Disabled" complete the EP disable procedure.
22640 + * -# If "AHB Error Interrupt" log error
22641 + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
22642 + * Command Processing)
22644 +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t *pcd)
22646 +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
22648 + doepint_data_t doepint = {.d32=0}; \
22649 + doepint.b.__intr = 1; \
22650 + dwc_write_reg32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
22654 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
22655 + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
22656 + uint32_t ep_intr;
22657 + doepint_data_t doepint = {.d32=0};
22658 + dctl_data_t dctl = {.d32=0};
22659 + depctl_data_t doepctl = {.d32=0};
22660 + uint32_t epnum = 0;
22661 + dwc_otg_pcd_ep_t *ep;
22662 + dwc_ep_t *dwc_ep;
22664 + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
22666 + /* Read in the device interrupt bits */
22667 + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
22670 + if (ep_intr&0x1) {
22671 + /* Get EP pointer */
22672 + ep = get_out_ep(pcd, epnum);
22673 + dwc_ep = &ep->dwc_ep;
22676 + DWC_DEBUGPL(DBG_PCDV,
22677 + "EP%d-%s: type=%d, mps=%d\n",
22678 + dwc_ep->num, (dwc_ep->is_in ?"IN":"OUT"),
22679 + dwc_ep->type, dwc_ep->maxpacket);
22681 + doepint.d32 = dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
22683 + /* Transfer complete */
22684 + if (doepint.b.xfercompl) {
22686 + if (epnum == 0) {
22687 + /* Clear the bit in DOEPINTn for this interrupt */
22688 + CLEAR_OUT_EP_INTR(core_if,epnum,xfercompl);
22689 + if(core_if->dma_desc_enable == 0 || pcd->ep0state != EP0_IDLE)
22691 +#ifdef DWC_EN_ISOC
22692 + } else if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
22693 + if (doepint.b.pktdrpsts == 0) {
22694 + /* Clear the bit in DOEPINTn for this interrupt */
22695 + CLEAR_OUT_EP_INTR(core_if,epnum,xfercompl);
22696 + complete_iso_ep(ep);
22699 + doepint_data_t doepint = {.d32=0};
22700 + doepint.b.xfercompl = 1;
22701 + doepint.b.pktdrpsts = 1;
22702 + dwc_write_reg32(&core_if->dev_if->out_ep_regs[epnum]->doepint,
22704 + if(handle_iso_out_pkt_dropped(core_if,dwc_ep)) {
22705 + complete_iso_ep(ep);
22708 +#endif //DWC_EN_ISOC
22710 + /* Clear the bit in DOEPINTn for this interrupt */
22711 + CLEAR_OUT_EP_INTR(core_if,epnum,xfercompl);
22717 + /* Endpoint disable */
22718 + if (doepint.b.epdisabled) {
22720 + /* Clear the bit in DOEPINTn for this interrupt */
22721 + CLEAR_OUT_EP_INTR(core_if,epnum,epdisabled);
22724 + if (doepint.b.ahberr) {
22725 + DWC_DEBUGPL(DBG_PCD,"EP%d OUT AHB Error\n", epnum);
22726 + DWC_DEBUGPL(DBG_PCD,"EP DMA REG %d \n", core_if->dev_if->out_ep_regs[epnum]->doepdma);
22727 + CLEAR_OUT_EP_INTR(core_if,epnum,ahberr);
22729 + /* Setup Phase Done (contorl EPs) */
22730 + if (doepint.b.setup) {
22732 + DWC_DEBUGPL(DBG_PCD,"EP%d SETUP Done\n",
22735 + CLEAR_OUT_EP_INTR(core_if,epnum,setup);
22740 + /** OUT EP BNA Intr */
22741 + if (doepint.b.bna) {
22742 + CLEAR_OUT_EP_INTR(core_if,epnum,bna);
22743 + if(core_if->dma_desc_enable) {
22744 +#ifdef DWC_EN_ISOC
22745 + if(dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
22747 + * This checking is performed to prevent first "false" BNA
22748 + * handling occuring right after reconnect
22750 + if(dwc_ep->next_frame != 0xffffffff)
22751 + dwc_otg_pcd_handle_iso_bna(ep);
22754 +#endif //DWC_EN_ISOC
22756 + dctl.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dctl);
22758 + /* If Global Continue on BNA is disabled - disable EP*/
22759 + if(!dctl.b.gcontbna) {
22761 + doepctl.b.snak = 1;
22762 + doepctl.b.epdis = 1;
22763 + dwc_modify_reg32(&dev_if->out_ep_regs[epnum]->doepctl, doepctl.d32, doepctl.d32);
22765 + start_next_request(ep);
22770 + if (doepint.b.stsphsercvd) {
22771 + CLEAR_OUT_EP_INTR(core_if,epnum,stsphsercvd);
22772 + if(core_if->dma_desc_enable) {
22773 + do_setup_in_status_phase(pcd);
22776 + /* Babble Interrutp */
22777 + if (doepint.b.babble) {
22778 + DWC_DEBUGPL(DBG_ANY,"EP%d OUT Babble\n", epnum);
22779 + handle_out_ep_babble_intr(pcd, epnum);
22781 + CLEAR_OUT_EP_INTR(core_if,epnum,babble);
22783 + /* NAK Interrutp */
22784 + if (doepint.b.nak) {
22785 + DWC_DEBUGPL(DBG_ANY,"EP%d OUT NAK\n", epnum);
22786 + handle_out_ep_nak_intr(pcd, epnum);
22788 + CLEAR_OUT_EP_INTR(core_if,epnum,nak);
22790 + /* NYET Interrutp */
22791 + if (doepint.b.nyet) {
22792 + DWC_DEBUGPL(DBG_ANY,"EP%d OUT NYET\n", epnum);
22793 + handle_out_ep_nyet_intr(pcd, epnum);
22795 + CLEAR_OUT_EP_INTR(core_if,epnum,nyet);
22805 +#undef CLEAR_OUT_EP_INTR
22810 + * Incomplete ISO IN Transfer Interrupt.
22811 + * This interrupt indicates one of the following conditions occurred
22812 + * while transmitting an ISOC transaction.
22813 + * - Corrupted IN Token for ISOC EP.
22814 + * - Packet not complete in FIFO.
22815 + * The follow actions will be taken:
22816 + * -# Determine the EP
22817 + * -# Set incomplete flag in dwc_ep structure
22818 + * -# Disable EP; when "Endpoint Disabled" interrupt is received
22821 +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t *pcd)
22823 + gintsts_data_t gintsts;
22826 +#ifdef DWC_EN_ISOC
22827 + dwc_otg_dev_if_t *dev_if;
22828 + deptsiz_data_t deptsiz = { .d32 = 0};
22829 + depctl_data_t depctl = { .d32 = 0};
22830 + dsts_data_t dsts = { .d32 = 0};
22831 + dwc_ep_t *dwc_ep;
22834 + dev_if = GET_CORE_IF(pcd)->dev_if;
22836 + for(i = 1; i <= dev_if->num_in_eps; ++i) {
22837 + dwc_ep = &pcd->in_ep[i].dwc_ep;
22838 + if(dwc_ep->active &&
22839 + dwc_ep->type == USB_ENDPOINT_XFER_ISOC)
22841 + deptsiz.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->dieptsiz);
22842 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
22844 + if(depctl.b.epdis && deptsiz.d32) {
22845 + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
22846 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
22847 + dwc_ep->cur_pkt = 0;
22848 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
22850 + if(dwc_ep->proc_buf_num) {
22851 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
22852 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
22854 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
22855 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
22860 + dsts.d32 = dwc_read_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->dsts);
22861 + dwc_ep->next_frame = dsts.b.soffn;
22863 + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF(pcd), dwc_ep);
22869 + gintmsk_data_t intr_mask = { .d32 = 0};
22870 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
22871 + "IN ISOC Incomplete");
22873 + intr_mask.b.incomplisoin = 1;
22874 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
22875 + intr_mask.d32, 0);
22876 +#endif //DWC_EN_ISOC
22878 + /* Clear interrupt */
22880 + gintsts.b.incomplisoin = 1;
22881 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
22888 + * Incomplete ISO OUT Transfer Interrupt.
22890 + * This interrupt indicates that the core has dropped an ISO OUT
22891 + * packet. The following conditions can be the cause:
22892 + * - FIFO Full, the entire packet would not fit in the FIFO.
22894 + * - Corrupted Token
22895 + * The follow actions will be taken:
22896 + * -# Determine the EP
22897 + * -# Set incomplete flag in dwc_ep structure
22898 + * -# Read any data from the FIFO
22899 + * -# Disable EP. when "Endpoint Disabled" interrupt is received
22902 +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t *pcd)
22904 + /* @todo implement ISR */
22905 + gintsts_data_t gintsts;
22907 +#ifdef DWC_EN_ISOC
22908 + dwc_otg_dev_if_t *dev_if;
22909 + deptsiz_data_t deptsiz = { .d32 = 0};
22910 + depctl_data_t depctl = { .d32 = 0};
22911 + dsts_data_t dsts = { .d32 = 0};
22912 + dwc_ep_t *dwc_ep;
22915 + dev_if = GET_CORE_IF(pcd)->dev_if;
22917 + for(i = 1; i <= dev_if->num_out_eps; ++i) {
22918 + dwc_ep = &pcd->in_ep[i].dwc_ep;
22919 + if(pcd->out_ep[i].dwc_ep.active &&
22920 + pcd->out_ep[i].dwc_ep.type == USB_ENDPOINT_XFER_ISOC)
22922 + deptsiz.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doeptsiz);
22923 + depctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doepctl);
22925 + if(depctl.b.epdis && deptsiz.d32) {
22926 + set_current_pkt_info(GET_CORE_IF(pcd), &pcd->out_ep[i].dwc_ep);
22927 + if(dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
22928 + dwc_ep->cur_pkt = 0;
22929 + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
22931 + if(dwc_ep->proc_buf_num) {
22932 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
22933 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
22935 + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
22936 + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
22941 + dsts.d32 = dwc_read_reg32(&GET_CORE_IF(pcd)->dev_if->dev_global_regs->dsts);
22942 + dwc_ep->next_frame = dsts.b.soffn;
22944 + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF(pcd), dwc_ep);
22949 + /** @todo implement ISR */
22950 + gintmsk_data_t intr_mask = { .d32 = 0};
22952 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
22953 + "OUT ISOC Incomplete");
22955 + intr_mask.b.incomplisoout = 1;
22956 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
22957 + intr_mask.d32, 0);
22959 +#endif // DWC_EN_ISOC
22961 + /* Clear interrupt */
22963 + gintsts.b.incomplisoout = 1;
22964 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
22971 + * This function handles the Global IN NAK Effective interrupt.
22974 +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t *pcd)
22976 + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
22977 + depctl_data_t diepctl = { .d32 = 0};
22978 + depctl_data_t diepctl_rd = { .d32 = 0};
22979 + gintmsk_data_t intr_mask = { .d32 = 0};
22980 + gintsts_data_t gintsts;
22983 + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
22985 + /* Disable all active IN EPs */
22986 + diepctl.b.epdis = 1;
22987 + diepctl.b.snak = 1;
22989 + for (i=0; i <= dev_if->num_in_eps; i++)
22991 + diepctl_rd.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
22992 + if (diepctl_rd.b.epena) {
22993 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepctl,
22997 + /* Disable the Global IN NAK Effective Interrupt */
22998 + intr_mask.b.ginnakeff = 1;
22999 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
23000 + intr_mask.d32, 0);
23002 + /* Clear interrupt */
23004 + gintsts.b.ginnakeff = 1;
23005 + dwc_write_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
23012 + * OUT NAK Effective.
23015 +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t *pcd)
23017 + gintmsk_data_t intr_mask = { .d32 = 0};
23018 + gintsts_data_t gintsts;
23020 + DWC_PRINT("INTERRUPT Handler not implemented for %s\n",
23021 + "Global IN NAK Effective\n");
23022 + /* Disable the Global IN NAK Effective Interrupt */
23023 + intr_mask.b.goutnakeff = 1;
23024 + dwc_modify_reg32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
23025 + intr_mask.d32, 0);
23027 + /* Clear interrupt */
23029 + gintsts.b.goutnakeff = 1;
23030 + dwc_write_reg32 (&GET_CORE_IF(pcd)->core_global_regs->gintsts,
23038 + * PCD interrupt handler.
23040 + * The PCD handles the device interrupts. Many conditions can cause a
23041 + * device interrupt. When an interrupt occurs, the device interrupt
23042 + * service routine determines the cause of the interrupt and
23043 + * dispatches handling to the appropriate function. These interrupt
23044 + * handling functions are described below.
23046 + * All interrupt registers are processed from LSB to MSB.
23049 +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t *pcd)
23051 + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
23053 + dwc_otg_core_global_regs_t *global_regs =
23054 + core_if->core_global_regs;
23056 + gintsts_data_t gintr_status;
23057 + int32_t retval = 0;
23061 + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
23063 + dwc_read_reg32(&global_regs->gintsts),
23064 + dwc_read_reg32(&global_regs->gintmsk));
23067 + if (dwc_otg_is_device_mode(core_if)) {
23068 + SPIN_LOCK(&pcd->lock);
23070 + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
23072 + dwc_read_reg32(&global_regs->gintsts),
23073 + dwc_read_reg32(&global_regs->gintmsk));
23076 + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
23079 + if (!gintr_status.d32) {
23080 + SPIN_UNLOCK(&pcd->lock);
23084 + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
23085 + __func__, gintr_status.d32);
23087 + if (gintr_status.b.sofintr) {
23088 + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
23090 + if (gintr_status.b.rxstsqlvl) {
23091 + retval |= dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
23093 + if (gintr_status.b.nptxfempty) {
23094 + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
23096 + if (gintr_status.b.ginnakeff) {
23097 + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
23099 + if (gintr_status.b.goutnakeff) {
23100 + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
23102 + if (gintr_status.b.i2cintr) {
23103 + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
23105 + if (gintr_status.b.erlysuspend) {
23106 + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
23108 + if (gintr_status.b.usbreset) {
23109 + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
23111 + if (gintr_status.b.enumdone) {
23112 + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
23114 + if (gintr_status.b.isooutdrop) {
23115 + retval |= dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(pcd);
23117 + if (gintr_status.b.eopframe) {
23118 + retval |= dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
23120 + if (gintr_status.b.epmismatch) {
23121 + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(core_if);
23123 + if (gintr_status.b.inepint) {
23124 + if(!core_if->multiproc_int_enable) {
23125 + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
23128 + if (gintr_status.b.outepintr) {
23129 + if(!core_if->multiproc_int_enable) {
23130 + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
23133 + if (gintr_status.b.incomplisoin) {
23134 + retval |= dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
23136 + if (gintr_status.b.incomplisoout) {
23137 + retval |= dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
23140 + /* In MPI mode De vice Endpoints intterrupts are asserted
23141 + * without setting outepintr and inepint bits set, so these
23142 + * Interrupt handlers are called without checking these bit-fields
23144 + if(core_if->multiproc_int_enable) {
23145 + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
23146 + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
23149 + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
23150 + dwc_read_reg32(&global_regs->gintsts));
23152 + SPIN_UNLOCK(&pcd->lock);
23155 + S3C2410X_CLEAR_EINTPEND();
23160 +#endif /* DWC_HOST_ONLY */
23162 +++ b/drivers/usb/host/otg/dwc_otg_plat.h
23164 +/* ==========================================================================
23165 + * $File: //dwh/usb_iip/dev/software/otg/linux/platform/dwc_otg_plat.h $
23166 + * $Revision: #23 $
23167 + * $Date: 2008/07/15 $
23168 + * $Change: 1064915 $
23170 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
23171 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
23172 + * otherwise expressly agreed to in writing between Synopsys and you.
23174 + * The Software IS NOT an item of Licensed Software or Licensed Product under
23175 + * any End User Software License Agreement or Agreement for Licensed Product
23176 + * with Synopsys or any supplement thereto. You are permitted to use and
23177 + * redistribute this Software in source and binary forms, with or without
23178 + * modification, provided that redistributions of source code must retain this
23179 + * notice. You may not view, use, disclose, copy or distribute this file or
23180 + * any information contained herein except pursuant to this license grant from
23181 + * Synopsys. If you do not agree with this notice, including the disclaimer
23182 + * below, then you are not authorized to use the Software.
23184 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
23185 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23186 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23187 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
23188 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23189 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23190 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23191 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23192 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23193 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23195 + * ========================================================================== */
23197 +#if !defined(__DWC_OTG_PLAT_H__)
23198 +#define __DWC_OTG_PLAT_H__
23200 +#include <linux/types.h>
23201 +#include <linux/slab.h>
23202 +#include <linux/list.h>
23203 +#include <linux/delay.h>
23204 +#include <asm/io.h>
23206 +#define cns3xxx_ioremap(addr, size) ioremap(addr, size)
23207 +#define cns3xxx_iounmap(addr) iounmap(addr)
23208 +/* Changed all readl and writel to __raw_readl, __raw_writel */
23213 + * This file contains the Platform Specific constants, interfaces
23214 + * (functions and macros) for Linux.
23217 +//#if !defined(__LINUX_ARM_ARCH__)
23218 +//#error "The contents of this file is Linux specific!!!"
23222 + * Reads the content of a register.
23224 + * @param reg address of register to read.
23225 + * @return contents of the register.
23229 + * <code>uint32_t dev_ctl = dwc_read_reg32(&dev_regs->dctl);</code>
23231 +static __inline__ uint32_t dwc_read_reg32( volatile uint32_t *reg)
23233 + return __raw_readl(reg);
23234 + // return readl(reg);
23238 + * Writes a register with a 32 bit value.
23240 + * @param reg address of register to read.
23241 + * @param value to write to _reg.
23244 + * <code>dwc_write_reg32(&dev_regs->dctl, 0); </code>
23246 +static __inline__ void dwc_write_reg32( volatile uint32_t *reg, const uint32_t value)
23248 + // writel( value, reg );
23249 + __raw_writel(value, reg);
23254 + * This function modifies bit values in a register. Using the
23255 + * algorithm: (reg_contents & ~clear_mask) | set_mask.
23257 + * @param reg address of register to read.
23258 + * @param clear_mask bit mask to be cleared.
23259 + * @param set_mask bit mask to be set.
23262 + * <code> // Clear the SOF Interrupt Mask bit and <br>
23263 + * // set the OTG Interrupt mask bit, leaving all others as they were.
23264 + * dwc_modify_reg32(&dev_regs->gintmsk, DWC_SOF_INT, DWC_OTG_INT);</code>
23267 + void dwc_modify_reg32( volatile uint32_t *reg, const uint32_t clear_mask, const uint32_t set_mask)
23269 + // writel( (readl(reg) & ~clear_mask) | set_mask, reg );
23270 + __raw_writel( (__raw_readl(reg) & ~clear_mask) | set_mask, reg );
23275 + * Wrapper for the OS micro-second delay function.
23276 + * @param[in] usecs Microseconds of delay
23278 +static __inline__ void UDELAY( const uint32_t usecs )
23284 + * Wrapper for the OS milli-second delay function.
23285 + * @param[in] msecs milliseconds of delay
23287 +static __inline__ void MDELAY( const uint32_t msecs )
23293 + * Wrapper for the Linux spin_lock. On the ARM (Integrator)
23294 + * spin_lock() is a nop.
23296 + * @param lock Pointer to the spinlock.
23298 +static __inline__ void SPIN_LOCK( spinlock_t *lock )
23304 + * Wrapper for the Linux spin_unlock. On the ARM (Integrator)
23305 + * spin_lock() is a nop.
23307 + * @param lock Pointer to the spinlock.
23309 +static __inline__ void SPIN_UNLOCK( spinlock_t *lock )
23311 + spin_unlock(lock);
23315 + * Wrapper (macro) for the Linux spin_lock_irqsave. On the ARM
23316 + * (Integrator) spin_lock() is a nop.
23318 + * @param l Pointer to the spinlock.
23319 + * @param f unsigned long for irq flags storage.
23321 +#define SPIN_LOCK_IRQSAVE( l, f ) spin_lock_irqsave(l,f);
23324 + * Wrapper (macro) for the Linux spin_unlock_irqrestore. On the ARM
23325 + * (Integrator) spin_lock() is a nop.
23327 + * @param l Pointer to the spinlock.
23328 + * @param f unsigned long for irq flags storage.
23330 +#define SPIN_UNLOCK_IRQRESTORE( l,f ) spin_unlock_irqrestore(l,f);
23333 + * Debugging support vanishes in non-debug builds.
23338 + * The Debug Level bit-mask variable.
23340 +extern uint32_t g_dbg_lvl;
23342 + * Set the Debug Level variable.
23344 +static inline uint32_t SET_DEBUG_LEVEL( const uint32_t new )
23346 + uint32_t old = g_dbg_lvl;
23351 +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
23352 +#define DBG_CIL (0x2)
23353 +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
23355 +#define DBG_CILV (0x20)
23356 +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
23358 +#define DBG_PCD (0x4)
23359 +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
23361 +#define DBG_PCDV (0x40)
23362 +/** When debug level has the DBG_HCD bit set, display Host debug messages */
23363 +#define DBG_HCD (0x8)
23364 +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
23366 +#define DBG_HCDV (0x80)
23367 +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
23369 +#define DBG_HCD_URB (0x800)
23371 +/** When debug level has any bit set, display debug messages */
23372 +#define DBG_ANY (0xFF)
23374 +/** All debug messages off */
23377 +/** Prefix string for DWC_DEBUG print macros. */
23378 +#define USB_DWC "DWC_otg: "
23381 + * Print a debug message when the Global debug level variable contains
23382 + * the bit defined in <code>lvl</code>.
23384 + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
23385 + * @param[in] x - like printf
23389 + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
23392 + * results in:<br>
23394 + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
23399 +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)printk( KERN_DEBUG USB_DWC x ); }while(0)
23400 +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
23402 +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
23406 +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
23407 +# define DWC_DEBUGP(x...)
23409 +# define CHK_DEBUG_LEVEL(level) (0)
23414 + * Print an Error message.
23416 +#define DWC_ERROR(x...) printk( KERN_ERR USB_DWC x )
23418 + * Print a Warning message.
23420 +#define DWC_WARN(x...) printk( KERN_WARNING USB_DWC x )
23422 + * Print a notice (normal but significant message).
23424 +#define DWC_NOTICE(x...) printk( KERN_NOTICE USB_DWC x )
23426 + * Basic message printing.
23428 +#define DWC_PRINT(x...) printk( KERN_INFO USB_DWC x )
23433 +++ b/drivers/usb/host/otg/dwc_otg_regs.h
23435 +/* ==========================================================================
23436 + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
23437 + * $Revision: #72 $
23438 + * $Date: 2008/09/19 $
23439 + * $Change: 1099526 $
23441 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
23442 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
23443 + * otherwise expressly agreed to in writing between Synopsys and you.
23445 + * The Software IS NOT an item of Licensed Software or Licensed Product under
23446 + * any End User Software License Agreement or Agreement for Licensed Product
23447 + * with Synopsys or any supplement thereto. You are permitted to use and
23448 + * redistribute this Software in source and binary forms, with or without
23449 + * modification, provided that redistributions of source code must retain this
23450 + * notice. You may not view, use, disclose, copy or distribute this file or
23451 + * any information contained herein except pursuant to this license grant from
23452 + * Synopsys. If you do not agree with this notice, including the disclaimer
23453 + * below, then you are not authorized to use the Software.
23455 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
23456 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23457 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23458 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
23459 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23460 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23461 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23462 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23463 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23464 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23466 + * ========================================================================== */
23468 +#ifndef __DWC_OTG_REGS_H__
23469 +#define __DWC_OTG_REGS_H__
23474 + * This file contains the data structures for accessing the DWC_otg core registers.
23476 + * The application interfaces with the HS OTG core by reading from and
23477 + * writing to the Control and Status Register (CSR) space through the
23478 + * AHB Slave interface. These registers are 32 bits wide, and the
23479 + * addresses are 32-bit-block aligned.
23480 + * CSRs are classified as follows:
23481 + * - Core Global Registers
23482 + * - Device Mode Registers
23483 + * - Device Global Registers
23484 + * - Device Endpoint Specific Registers
23485 + * - Host Mode Registers
23486 + * - Host Global Registers
23487 + * - Host Port CSRs
23488 + * - Host Channel Specific Registers
23490 + * Only the Core Global registers can be accessed in both Device and
23491 + * Host modes. When the HS OTG core is operating in one mode, either
23492 + * Device or Host, the application must not access registers from the
23493 + * other mode. When the core switches from one mode to another, the
23494 + * registers in the new mode of operation must be reprogrammed as they
23495 + * would be after a power-on reset.
23498 +/** Maximum number of Periodic FIFOs */
23499 +#define MAX_PERIO_FIFOS 15
23500 +/** Maximum number of Transmit FIFOs */
23501 +#define MAX_TX_FIFOS 15
23503 +/** Maximum number of Endpoints/HostChannels */
23504 +#define MAX_EPS_CHANNELS 16
23506 +/****************************************************************************/
23507 +/** DWC_otg Core registers .
23508 + * The dwc_otg_core_global_regs structure defines the size
23509 + * and relative field offsets for the Core Global registers.
23511 +typedef struct dwc_otg_core_global_regs
23513 + /** OTG Control and Status Register. <i>Offset: 000h</i> */
23514 + volatile uint32_t gotgctl;
23515 + /** OTG Interrupt Register. <i>Offset: 004h</i> */
23516 + volatile uint32_t gotgint;
23517 + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
23518 + volatile uint32_t gahbcfg;
23520 +#define DWC_GLBINTRMASK 0x0001
23521 +#define DWC_DMAENABLE 0x0020
23522 +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
23523 +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
23524 +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
23525 +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
23527 + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
23528 + volatile uint32_t gusbcfg;
23529 + /**Core Reset Register. <i>Offset: 010h</i> */
23530 + volatile uint32_t grstctl;
23531 + /**Core Interrupt Register. <i>Offset: 014h</i> */
23532 + volatile uint32_t gintsts;
23533 + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
23534 + volatile uint32_t gintmsk;
23535 + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
23536 + volatile uint32_t grxstsr;
23537 + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
23538 + volatile uint32_t grxstsp;
23539 + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
23540 + volatile uint32_t grxfsiz;
23541 + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
23542 + volatile uint32_t gnptxfsiz;
23543 + /**Non Periodic Transmit FIFO/Queue Status Register (Read
23544 + * Only). <i>Offset: 02Ch</i> */
23545 + volatile uint32_t gnptxsts;
23546 + /**I2C Access Register. <i>Offset: 030h</i> */
23547 + volatile uint32_t gi2cctl;
23548 + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
23549 + volatile uint32_t gpvndctl;
23550 + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
23551 + volatile uint32_t ggpio;
23552 + /**User ID Register. <i>Offset: 03Ch</i> */
23553 + volatile uint32_t guid;
23554 + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
23555 + volatile uint32_t gsnpsid;
23556 + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
23557 + volatile uint32_t ghwcfg1;
23558 + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
23559 + volatile uint32_t ghwcfg2;
23560 +#define DWC_SLAVE_ONLY_ARCH 0
23561 +#define DWC_EXT_DMA_ARCH 1
23562 +#define DWC_INT_DMA_ARCH 2
23564 +#define DWC_MODE_HNP_SRP_CAPABLE 0
23565 +#define DWC_MODE_SRP_ONLY_CAPABLE 1
23566 +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
23567 +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
23568 +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
23569 +#define DWC_MODE_SRP_CAPABLE_HOST 5
23570 +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
23572 + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
23573 + volatile uint32_t ghwcfg3;
23574 + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
23575 + volatile uint32_t ghwcfg4;
23576 + /** Reserved <i>Offset: 054h-0FFh</i> */
23577 + volatile uint32_t reserved[43];
23578 + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
23579 + volatile uint32_t hptxfsiz;
23580 + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
23581 + otherwise Device Transmit FIFO#n Register.
23582 + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
23583 + volatile uint32_t dptxfsiz_dieptxf[15];
23584 +} dwc_otg_core_global_regs_t;
23587 + * This union represents the bit fields of the Core OTG Control
23588 + * and Status Register (GOTGCTL). Set the bits using the bit
23589 + * fields then write the <i>d32</i> value to the register.
23591 +typedef union gotgctl_data
23593 + /** raw register data */
23595 + /** register bits */
23598 + unsigned sesreqscs : 1;
23599 + unsigned sesreq : 1;
23600 + unsigned reserved2_7 : 6;
23601 + unsigned hstnegscs : 1;
23602 + unsigned hnpreq : 1;
23603 + unsigned hstsethnpen : 1;
23604 + unsigned devhnpen : 1;
23605 + unsigned reserved12_15 : 4;
23606 + unsigned conidsts : 1;
23607 + unsigned reserved17 : 1;
23608 + unsigned asesvld : 1;
23609 + unsigned bsesvld : 1;
23610 + unsigned currmod : 1;
23611 + unsigned reserved21_31 : 11;
23616 + * This union represents the bit fields of the Core OTG Interrupt Register
23617 + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
23618 + * value to the register.
23620 +typedef union gotgint_data
23622 + /** raw register data */
23624 + /** register bits */
23627 + /** Current Mode */
23628 + unsigned reserved0_1 : 2;
23630 + /** Session End Detected */
23631 + unsigned sesenddet : 1;
23633 + unsigned reserved3_7 : 5;
23635 + /** Session Request Success Status Change */
23636 + unsigned sesreqsucstschng : 1;
23637 + /** Host Negotiation Success Status Change */
23638 + unsigned hstnegsucstschng : 1;
23640 + unsigned reserver10_16 : 7;
23642 + /** Host Negotiation Detected */
23643 + unsigned hstnegdet : 1;
23644 + /** A-Device Timeout Change */
23645 + unsigned adevtoutchng : 1;
23646 + /** Debounce Done */
23647 + unsigned debdone : 1;
23649 + unsigned reserved31_20 : 12;
23656 + * This union represents the bit fields of the Core AHB Configuration
23657 + * Register (GAHBCFG). Set/clear the bits using the bit fields then
23658 + * write the <i>d32</i> value to the register.
23660 +typedef union gahbcfg_data
23662 + /** raw register data */
23664 + /** register bits */
23667 + unsigned glblintrmsk : 1;
23668 +#define DWC_GAHBCFG_GLBINT_ENABLE 1
23670 + unsigned hburstlen : 4;
23671 +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
23672 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
23673 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
23674 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
23675 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
23677 + unsigned dmaenable : 1;
23678 +#define DWC_GAHBCFG_DMAENABLE 1
23679 + unsigned reserved : 1;
23680 + unsigned nptxfemplvl_txfemplvl : 1;
23681 + unsigned ptxfemplvl : 1;
23682 +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
23683 +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
23684 + unsigned reserved9_31 : 23;
23689 + * This union represents the bit fields of the Core USB Configuration
23690 + * Register (GUSBCFG). Set the bits using the bit fields then write
23691 + * the <i>d32</i> value to the register.
23693 +typedef union gusbcfg_data
23695 + /** raw register data */
23697 + /** register bits */
23700 + unsigned toutcal : 3;
23701 + unsigned phyif : 1;
23702 + unsigned ulpi_utmi_sel : 1;
23703 + unsigned fsintf : 1;
23704 + unsigned physel : 1;
23705 + unsigned ddrsel : 1;
23706 + unsigned srpcap : 1;
23707 + unsigned hnpcap : 1;
23708 + unsigned usbtrdtim : 4;
23709 + unsigned nptxfrwnden : 1;
23710 + unsigned phylpwrclksel : 1;
23711 + unsigned otgutmifssel : 1;
23712 + unsigned ulpi_fsls : 1;
23713 + unsigned ulpi_auto_res : 1;
23714 + unsigned ulpi_clk_sus_m : 1;
23715 + unsigned ulpi_ext_vbus_drv : 1;
23716 + unsigned ulpi_int_vbus_indicator : 1;
23717 + unsigned term_sel_dl_pulse : 1;
23718 + unsigned reserved23_27 : 5;
23719 + unsigned tx_end_delay : 1;
23720 + unsigned reserved29_31 : 3;
23725 + * This union represents the bit fields of the Core Reset Register
23726 + * (GRSTCTL). Set/clear the bits using the bit fields then write the
23727 + * <i>d32</i> value to the register.
23729 +typedef union grstctl_data
23731 + /** raw register data */
23733 + /** register bits */
23736 + /** Core Soft Reset (CSftRst) (Device and Host)
23738 + * The application can flush the control logic in the
23739 + * entire core using this bit. This bit resets the
23740 + * pipelines in the AHB Clock domain as well as the
23741 + * PHY Clock domain.
23743 + * The state machines are reset to an IDLE state, the
23744 + * control bits in the CSRs are cleared, all the
23745 + * transmit FIFOs and the receive FIFO are flushed.
23747 + * The status mask bits that control the generation of
23748 + * the interrupt, are cleared, to clear the
23749 + * interrupt. The interrupt status bits are not
23750 + * cleared, so the application can get the status of
23751 + * any events that occurred in the core after it has
23754 + * Any transactions on the AHB are terminated as soon
23755 + * as possible following the protocol. Any
23756 + * transactions on the USB are terminated immediately.
23758 + * The configuration settings in the CSRs are
23759 + * unchanged, so the software doesn't have to
23760 + * reprogram these registers (Device
23761 + * Configuration/Host Configuration/Core System
23762 + * Configuration/Core PHY Configuration).
23764 + * The application can write to this bit, any time it
23765 + * wants to reset the core. This is a self clearing
23766 + * bit and the core clears this bit after all the
23767 + * necessary logic is reset in the core, which may
23768 + * take several clocks, depending on the current state
23771 + unsigned csftrst : 1;
23772 + /** Hclk Soft Reset
23774 + * The application uses this bit to reset the control logic in
23775 + * the AHB clock domain. Only AHB clock domain pipelines are
23778 + unsigned hsftrst : 1;
23779 + /** Host Frame Counter Reset (Host Only)<br>
23781 + * The application can reset the (micro)frame number
23782 + * counter inside the core, using this bit. When the
23783 + * (micro)frame counter is reset, the subsequent SOF
23784 + * sent out by the core, will have a (micro)frame
23787 + unsigned hstfrm : 1;
23788 + /** In Token Sequence Learning Queue Flush
23789 + * (INTknQFlsh) (Device Only)
23791 + unsigned intknqflsh : 1;
23792 + /** RxFIFO Flush (RxFFlsh) (Device and Host)
23794 + * The application can flush the entire Receive FIFO
23795 + * using this bit. <p>The application must first
23796 + * ensure that the core is not in the middle of a
23797 + * transaction. <p>The application should write into
23798 + * this bit, only after making sure that neither the
23799 + * DMA engine is reading from the RxFIFO nor the MAC
23800 + * is writing the data in to the FIFO. <p>The
23801 + * application should wait until the bit is cleared
23802 + * before performing any other operations. This bit
23803 + * will takes 8 clocks (slowest of PHY or AHB clock)
23806 + unsigned rxfflsh : 1;
23807 + /** TxFIFO Flush (TxFFlsh) (Device and Host).
23809 + * This bit is used to selectively flush a single or
23810 + * all transmit FIFOs. The application must first
23811 + * ensure that the core is not in the middle of a
23812 + * transaction. <p>The application should write into
23813 + * this bit, only after making sure that neither the
23814 + * DMA engine is writing into the TxFIFO nor the MAC
23815 + * is reading the data out of the FIFO. <p>The
23816 + * application should wait until the core clears this
23817 + * bit, before performing any operations. This bit
23818 + * will takes 8 clocks (slowest of PHY or AHB clock)
23821 + unsigned txfflsh : 1;
23823 + /** TxFIFO Number (TxFNum) (Device and Host).
23825 + * This is the FIFO number which needs to be flushed,
23826 + * using the TxFIFO Flush bit. This field should not
23827 + * be changed until the TxFIFO Flush bit is cleared by
23829 + * - 0x0 : Non Periodic TxFIFO Flush
23830 + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
23831 + * or Periodic TxFIFO in host mode
23832 + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
23834 + * - 0xF : Periodic TxFIFO #15 Flush in device mode
23835 + * - 0x10: Flush all the Transmit NonPeriodic and
23836 + * Transmit Periodic FIFOs in the core
23838 + unsigned txfnum : 5;
23840 + unsigned reserved11_29 : 19;
23841 + /** DMA Request Signal. Indicated DMA request is in
23842 + * probress. Used for debug purpose. */
23843 + unsigned dmareq : 1;
23844 + /** AHB Master Idle. Indicates the AHB Master State
23845 + * Machine is in IDLE condition. */
23846 + unsigned ahbidle : 1;
23852 + * This union represents the bit fields of the Core Interrupt Mask
23853 + * Register (GINTMSK). Set/clear the bits using the bit fields then
23854 + * write the <i>d32</i> value to the register.
23856 +typedef union gintmsk_data
23858 + /** raw register data */
23860 + /** register bits */
23863 + unsigned reserved0 : 1;
23864 + unsigned modemismatch : 1;
23865 + unsigned otgintr : 1;
23866 + unsigned sofintr : 1;
23867 + unsigned rxstsqlvl : 1;
23868 + unsigned nptxfempty : 1;
23869 + unsigned ginnakeff : 1;
23870 + unsigned goutnakeff : 1;
23871 + unsigned reserved8 : 1;
23872 + unsigned i2cintr : 1;
23873 + unsigned erlysuspend : 1;
23874 + unsigned usbsuspend : 1;
23875 + unsigned usbreset : 1;
23876 + unsigned enumdone : 1;
23877 + unsigned isooutdrop : 1;
23878 + unsigned eopframe : 1;
23879 + unsigned reserved16 : 1;
23880 + unsigned epmismatch : 1;
23881 + unsigned inepintr : 1;
23882 + unsigned outepintr : 1;
23883 + unsigned incomplisoin : 1;
23884 + unsigned incomplisoout : 1;
23885 + unsigned reserved22_23 : 2;
23886 + unsigned portintr : 1;
23887 + unsigned hcintr : 1;
23888 + unsigned ptxfempty : 1;
23889 + unsigned reserved27 : 1;
23890 + unsigned conidstschng : 1;
23891 + unsigned disconnect : 1;
23892 + unsigned sessreqintr : 1;
23893 + unsigned wkupintr : 1;
23897 + * This union represents the bit fields of the Core Interrupt Register
23898 + * (GINTSTS). Set/clear the bits using the bit fields then write the
23899 + * <i>d32</i> value to the register.
23901 +typedef union gintsts_data
23903 + /** raw register data */
23905 +#define DWC_SOF_INTR_MASK 0x0008
23906 + /** register bits */
23909 +#define DWC_HOST_MODE 1
23910 + unsigned curmode : 1;
23911 + unsigned modemismatch : 1;
23912 + unsigned otgintr : 1;
23913 + unsigned sofintr : 1;
23914 + unsigned rxstsqlvl : 1;
23915 + unsigned nptxfempty : 1;
23916 + unsigned ginnakeff : 1;
23917 + unsigned goutnakeff : 1;
23918 + unsigned reserved8 : 1;
23919 + unsigned i2cintr : 1;
23920 + unsigned erlysuspend : 1;
23921 + unsigned usbsuspend : 1;
23922 + unsigned usbreset : 1;
23923 + unsigned enumdone : 1;
23924 + unsigned isooutdrop : 1;
23925 + unsigned eopframe : 1;
23926 + unsigned intokenrx : 1;
23927 + unsigned epmismatch : 1;
23928 + unsigned inepint: 1;
23929 + unsigned outepintr : 1;
23930 + unsigned incomplisoin : 1;
23931 + unsigned incomplisoout : 1;
23932 + unsigned reserved22_23 : 2;
23933 + unsigned portintr : 1;
23934 + unsigned hcintr : 1;
23935 + unsigned ptxfempty : 1;
23936 + unsigned reserved27 : 1;
23937 + unsigned conidstschng : 1;
23938 + unsigned disconnect : 1;
23939 + unsigned sessreqintr : 1;
23940 + unsigned wkupintr : 1;
23946 + * This union represents the bit fields in the Device Receive Status Read and
23947 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
23948 + * element then read out the bits using the <i>b</i>it elements.
23950 +typedef union device_grxsts_data
23952 + /** raw register data */
23954 + /** register bits */
23957 + unsigned epnum : 4;
23958 + unsigned bcnt : 11;
23959 + unsigned dpid : 2;
23961 +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
23962 +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
23964 +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
23965 +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
23966 +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
23967 + unsigned pktsts : 4;
23969 + unsigned reserved : 7;
23971 +} device_grxsts_data_t;
23974 + * This union represents the bit fields in the Host Receive Status Read and
23975 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
23976 + * element then read out the bits using the <i>b</i>it elements.
23978 +typedef union host_grxsts_data
23980 + /** raw register data */
23982 + /** register bits */
23985 + unsigned chnum : 4;
23986 + unsigned bcnt : 11;
23987 + unsigned dpid : 2;
23989 + unsigned pktsts : 4;
23990 +#define DWC_GRXSTS_PKTSTS_IN 0x2
23991 +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
23992 +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
23993 +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
23995 + unsigned reserved : 11;
23997 +} host_grxsts_data_t;
24000 + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
24001 + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element then
24002 + * read out the bits using the <i>b</i>it elements.
24004 +typedef union fifosize_data
24006 + /** raw register data */
24008 + /** register bits */
24011 + unsigned startaddr : 16;
24012 + unsigned depth : 16;
24014 +} fifosize_data_t;
24017 + * This union represents the bit fields in the Non-Periodic Transmit
24018 + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
24019 + * <i>d32</i> element then read out the bits using the <i>b</i>it
24022 +typedef union gnptxsts_data
24024 + /** raw register data */
24026 + /** register bits */
24029 + unsigned nptxfspcavail : 16;
24030 + unsigned nptxqspcavail : 8;
24031 + /** Top of the Non-Periodic Transmit Request Queue
24032 + * - bit 24 - Terminate (Last entry for the selected
24034 + * - bits 26:25 - Token Type
24035 + * - 2'b00 - IN/OUT
24036 + * - 2'b01 - Zero Length OUT
24037 + * - 2'b10 - PING/Complete Split
24038 + * - 2'b11 - Channel Halt
24039 + * - bits 30:27 - Channel/EP Number
24041 + unsigned nptxqtop_terminate : 1;
24042 + unsigned nptxqtop_token : 2;
24043 + unsigned nptxqtop_chnep : 4;
24044 + unsigned reserved : 1;
24046 +} gnptxsts_data_t;
24049 + * This union represents the bit fields in the Transmit
24050 + * FIFO Status Register (DTXFSTS). Read the register into the
24051 + * <i>d32</i> element then read out the bits using the <i>b</i>it
24054 +typedef union dtxfsts_data
24056 + /** raw register data */
24058 + /** register bits */
24061 + unsigned txfspcavail : 16;
24062 + unsigned reserved : 16;
24067 + * This union represents the bit fields in the I2C Control Register
24068 + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
24069 + * bits using the <i>b</i>it elements.
24071 +typedef union gi2cctl_data
24073 + /** raw register data */
24075 + /** register bits */
24078 + unsigned rwdata : 8;
24079 + unsigned regaddr : 8;
24080 + unsigned addr : 7;
24081 + unsigned i2cen : 1;
24082 + unsigned ack : 1;
24083 + unsigned i2csuspctl : 1;
24084 + unsigned i2cdevaddr : 2;
24085 + unsigned reserved : 2;
24087 + unsigned bsydne : 1;
24092 + * This union represents the bit fields in the User HW Config1
24093 + * Register. Read the register into the <i>d32</i> element then read
24094 + * out the bits using the <i>b</i>it elements.
24096 +typedef union hwcfg1_data
24098 + /** raw register data */
24100 + /** register bits */
24103 + unsigned ep_dir0 : 2;
24104 + unsigned ep_dir1 : 2;
24105 + unsigned ep_dir2 : 2;
24106 + unsigned ep_dir3 : 2;
24107 + unsigned ep_dir4 : 2;
24108 + unsigned ep_dir5 : 2;
24109 + unsigned ep_dir6 : 2;
24110 + unsigned ep_dir7 : 2;
24111 + unsigned ep_dir8 : 2;
24112 + unsigned ep_dir9 : 2;
24113 + unsigned ep_dir10 : 2;
24114 + unsigned ep_dir11 : 2;
24115 + unsigned ep_dir12 : 2;
24116 + unsigned ep_dir13 : 2;
24117 + unsigned ep_dir14 : 2;
24118 + unsigned ep_dir15 : 2;
24123 + * This union represents the bit fields in the User HW Config2
24124 + * Register. Read the register into the <i>d32</i> element then read
24125 + * out the bits using the <i>b</i>it elements.
24127 +typedef union hwcfg2_data
24129 + /** raw register data */
24131 + /** register bits */
24135 + unsigned op_mode : 3;
24136 +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
24137 +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
24138 +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
24139 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
24140 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
24141 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
24142 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
24144 + unsigned architecture : 2;
24145 + unsigned point2point : 1;
24146 + unsigned hs_phy_type : 2;
24147 +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
24148 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
24149 +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
24150 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
24152 + unsigned fs_phy_type : 2;
24153 + unsigned num_dev_ep : 4;
24154 + unsigned num_host_chan : 4;
24155 + unsigned perio_ep_supported : 1;
24156 + unsigned dynamic_fifo : 1;
24157 + unsigned multi_proc_int : 1;
24158 + unsigned reserved21 : 1;
24159 + unsigned nonperio_tx_q_depth : 2;
24160 + unsigned host_perio_tx_q_depth : 2;
24161 + unsigned dev_token_q_depth : 5;
24162 + unsigned reserved31 : 1;
24167 + * This union represents the bit fields in the User HW Config3
24168 + * Register. Read the register into the <i>d32</i> element then read
24169 + * out the bits using the <i>b</i>it elements.
24171 +typedef union hwcfg3_data
24173 + /** raw register data */
24175 + /** register bits */
24179 + unsigned xfer_size_cntr_width : 4;
24180 + unsigned packet_size_cntr_width : 3;
24181 + unsigned otg_func : 1;
24182 + unsigned i2c : 1;
24183 + unsigned vendor_ctrl_if : 1;
24184 + unsigned optional_features : 1;
24185 + unsigned synch_reset_type : 1;
24186 + unsigned ahb_phy_clock_synch : 1;
24187 + unsigned reserved15_13 : 3;
24188 + unsigned dfifo_depth : 16;
24193 + * This union represents the bit fields in the User HW Config4
24194 + * Register. Read the register into the <i>d32</i> element then read
24195 + * out the bits using the <i>b</i>it elements.
24197 +typedef union hwcfg4_data
24199 + /** raw register data */
24201 + /** register bits */
24204 + unsigned num_dev_perio_in_ep : 4;
24205 + unsigned power_optimiz : 1;
24206 + unsigned min_ahb_freq : 9;
24207 + unsigned utmi_phy_data_width : 2;
24208 + unsigned num_dev_mode_ctrl_ep : 4;
24209 + unsigned iddig_filt_en : 1;
24210 + unsigned vbus_valid_filt_en : 1;
24211 + unsigned a_valid_filt_en : 1;
24212 + unsigned b_valid_filt_en : 1;
24213 + unsigned session_end_filt_en : 1;
24214 + unsigned ded_fifo_en : 1;
24215 + unsigned num_in_eps : 4;
24216 + unsigned desc_dma : 1;
24217 + unsigned desc_dma_dyn : 1;
24221 +////////////////////////////////////////////
24222 +// Device Registers
24224 + * Device Global Registers. <i>Offsets 800h-BFFh</i>
24226 + * The following structures define the size and relative field offsets
24227 + * for the Device Mode Registers.
24229 + * <i>These registers are visible only in Device mode and must not be
24230 + * accessed in Host mode, as the results are unknown.</i>
24232 +typedef struct dwc_otg_dev_global_regs
24234 + /** Device Configuration Register. <i>Offset 800h</i> */
24235 + volatile uint32_t dcfg;
24236 + /** Device Control Register. <i>Offset: 804h</i> */
24237 + volatile uint32_t dctl;
24238 + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
24239 + volatile uint32_t dsts;
24240 + /** Reserved. <i>Offset: 80Ch</i> */
24242 + /** Device IN Endpoint Common Interrupt Mask
24243 + * Register. <i>Offset: 810h</i> */
24244 + volatile uint32_t diepmsk;
24245 + /** Device OUT Endpoint Common Interrupt Mask
24246 + * Register. <i>Offset: 814h</i> */
24247 + volatile uint32_t doepmsk;
24248 + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
24249 + volatile uint32_t daint;
24250 + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
24252 + volatile uint32_t daintmsk;
24253 + /** Device IN Token Queue Read Register-1 (Read Only).
24254 + * <i>Offset: 820h</i> */
24255 + volatile uint32_t dtknqr1;
24256 + /** Device IN Token Queue Read Register-2 (Read Only).
24257 + * <i>Offset: 824h</i> */
24258 + volatile uint32_t dtknqr2;
24259 + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
24260 + volatile uint32_t dvbusdis;
24261 + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
24262 + volatile uint32_t dvbuspulse;
24263 + /** Device IN Token Queue Read Register-3 (Read Only). /
24264 + * Device Thresholding control register (Read/Write)
24265 + * <i>Offset: 830h</i> */
24266 + volatile uint32_t dtknqr3_dthrctl;
24267 + /** Device IN Token Queue Read Register-4 (Read Only). /
24268 + * Device IN EPs empty Inr. Mask Register (Read/Write)
24269 + * <i>Offset: 834h</i> */
24270 + volatile uint32_t dtknqr4_fifoemptymsk;
24271 + /** Device Each Endpoint Interrupt Register (Read Only). /
24272 + * <i>Offset: 838h</i> */
24273 + volatile uint32_t deachint;
24274 + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
24275 + * <i>Offset: 83Ch</i> */
24276 + volatile uint32_t deachintmsk;
24277 + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
24278 + * <i>Offset: 840h</i> */
24279 + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
24280 + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
24281 + * <i>Offset: 880h</i> */
24282 + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
24283 +} dwc_otg_device_global_regs_t;
24286 + * This union represents the bit fields in the Device Configuration
24287 + * Register. Read the register into the <i>d32</i> member then
24288 + * set/clear the bits using the <i>b</i>it elements. Write the
24289 + * <i>d32</i> member to the dcfg register.
24291 +typedef union dcfg_data
24293 + /** raw register data */
24295 + /** register bits */
24298 + /** Device Speed */
24299 + unsigned devspd : 2;
24300 + /** Non Zero Length Status OUT Handshake */
24301 + unsigned nzstsouthshk : 1;
24302 +#define DWC_DCFG_SEND_STALL 1
24304 + unsigned reserved3 : 1;
24305 + /** Device Addresses */
24306 + unsigned devaddr : 7;
24307 + /** Periodic Frame Interval */
24308 + unsigned perfrint : 2;
24309 +#define DWC_DCFG_FRAME_INTERVAL_80 0
24310 +#define DWC_DCFG_FRAME_INTERVAL_85 1
24311 +#define DWC_DCFG_FRAME_INTERVAL_90 2
24312 +#define DWC_DCFG_FRAME_INTERVAL_95 3
24314 + unsigned reserved13_17 : 5;
24315 + /** In Endpoint Mis-match count */
24316 + unsigned epmscnt : 5;
24317 + /** Enable Descriptor DMA in Device mode */
24318 + unsigned descdma : 1;
24323 + * This union represents the bit fields in the Device Control
24324 + * Register. Read the register into the <i>d32</i> member then
24325 + * set/clear the bits using the <i>b</i>it elements.
24327 +typedef union dctl_data
24329 + /** raw register data */
24331 + /** register bits */
24334 + /** Remote Wakeup */
24335 + unsigned rmtwkupsig : 1;
24336 + /** Soft Disconnect */
24337 + unsigned sftdiscon : 1;
24338 + /** Global Non-Periodic IN NAK Status */
24339 + unsigned gnpinnaksts : 1;
24340 + /** Global OUT NAK Status */
24341 + unsigned goutnaksts : 1;
24342 + /** Test Control */
24343 + unsigned tstctl : 3;
24344 + /** Set Global Non-Periodic IN NAK */
24345 + unsigned sgnpinnak : 1;
24346 + /** Clear Global Non-Periodic IN NAK */
24347 + unsigned cgnpinnak : 1;
24348 + /** Set Global OUT NAK */
24349 + unsigned sgoutnak : 1;
24350 + /** Clear Global OUT NAK */
24351 + unsigned cgoutnak : 1;
24353 + /** Power-On Programming Done */
24354 + unsigned pwronprgdone : 1;
24355 + /** Global Continue on BNA */
24356 + unsigned gcontbna : 1;
24357 + /** Global Multi Count */
24358 + unsigned gmc : 2;
24359 + /** Ignore Frame Number for ISOC EPs */
24360 + unsigned ifrmnum : 1;
24361 + /** NAK on Babble */
24362 + unsigned nakonbble : 1;
24364 + unsigned reserved16_31 : 16;
24369 + * This union represents the bit fields in the Device Status
24370 + * Register. Read the register into the <i>d32</i> member then
24371 + * set/clear the bits using the <i>b</i>it elements.
24373 +typedef union dsts_data
24375 + /** raw register data */
24377 + /** register bits */
24380 + /** Suspend Status */
24381 + unsigned suspsts : 1;
24382 + /** Enumerated Speed */
24383 + unsigned enumspd : 2;
24384 +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
24385 +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
24386 +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
24387 +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
24388 + /** Erratic Error */
24389 + unsigned errticerr : 1;
24390 + unsigned reserved4_7: 4;
24391 + /** Frame or Microframe Number of the received SOF */
24392 + unsigned soffn : 14;
24393 + unsigned reserved22_31 : 10;
24399 + * This union represents the bit fields in the Device IN EP Interrupt
24400 + * Register and the Device IN EP Common Mask Register.
24402 + * - Read the register into the <i>d32</i> member then set/clear the
24403 + * bits using the <i>b</i>it elements.
24405 +typedef union diepint_data
24407 + /** raw register data */
24409 + /** register bits */
24412 + /** Transfer complete mask */
24413 + unsigned xfercompl : 1;
24414 + /** Endpoint disable mask */
24415 + unsigned epdisabled : 1;
24416 + /** AHB Error mask */
24417 + unsigned ahberr : 1;
24418 + /** TimeOUT Handshake mask (non-ISOC EPs) */
24419 + unsigned timeout : 1;
24420 + /** IN Token received with TxF Empty mask */
24421 + unsigned intktxfemp : 1;
24422 + /** IN Token Received with EP mismatch mask */
24423 + unsigned intknepmis : 1;
24424 + /** IN Endpoint HAK Effective mask */
24425 + unsigned inepnakeff : 1;
24426 + /** IN Endpoint HAK Effective mask */
24427 + unsigned emptyintr : 1;
24429 + unsigned txfifoundrn : 1;
24431 + /** BNA Interrupt mask */
24432 + unsigned bna : 1;
24434 + unsigned reserved10_12 : 3;
24435 + /** BNA Interrupt mask */
24436 + unsigned nak : 1;
24438 + unsigned reserved14_31 : 18;
24443 + * This union represents the bit fields in the Device IN EP
24444 + * Common/Dedicated Interrupt Mask Register.
24446 +typedef union diepint_data diepmsk_data_t;
24449 + * This union represents the bit fields in the Device OUT EP Interrupt
24450 + * Registerand Device OUT EP Common Interrupt Mask Register.
24452 + * - Read the register into the <i>d32</i> member then set/clear the
24453 + * bits using the <i>b</i>it elements.
24455 +typedef union doepint_data
24457 + /** raw register data */
24459 + /** register bits */
24462 + /** Transfer complete */
24463 + unsigned xfercompl : 1;
24464 + /** Endpoint disable */
24465 + unsigned epdisabled : 1;
24467 + unsigned ahberr : 1;
24468 + /** Setup Phase Done (contorl EPs) */
24469 + unsigned setup : 1;
24470 + /** OUT Token Received when Endpoint Disabled */
24471 + unsigned outtknepdis : 1;
24473 + unsigned stsphsercvd : 1;
24474 + /** Back-to-Back SETUP Packets Received */
24475 + unsigned back2backsetup : 1;
24477 + unsigned reserved7 : 1;
24478 + /** OUT packet Error */
24479 + unsigned outpkterr : 1;
24480 + /** BNA Interrupt */
24481 + unsigned bna : 1;
24483 + unsigned reserved10 : 1;
24484 + /** Packet Drop Status */
24485 + unsigned pktdrpsts : 1;
24486 + /** Babble Interrupt */
24487 + unsigned babble : 1;
24488 + /** NAK Interrupt */
24489 + unsigned nak : 1;
24490 + /** NYET Interrupt */
24491 + unsigned nyet : 1;
24493 + unsigned reserved15_31 : 17;
24498 + * This union represents the bit fields in the Device OUT EP
24499 + * Common/Dedicated Interrupt Mask Register.
24501 +typedef union doepint_data doepmsk_data_t;
24504 + * This union represents the bit fields in the Device All EP Interrupt
24505 + * and Mask Registers.
24506 + * - Read the register into the <i>d32</i> member then set/clear the
24507 + * bits using the <i>b</i>it elements.
24509 +typedef union daint_data
24511 + /** raw register data */
24513 + /** register bits */
24516 + /** IN Endpoint bits */
24517 + unsigned in : 16;
24518 + /** OUT Endpoint bits */
24519 + unsigned out : 16;
24523 + /** IN Endpoint bits */
24524 + unsigned inep0 : 1;
24525 + unsigned inep1 : 1;
24526 + unsigned inep2 : 1;
24527 + unsigned inep3 : 1;
24528 + unsigned inep4 : 1;
24529 + unsigned inep5 : 1;
24530 + unsigned inep6 : 1;
24531 + unsigned inep7 : 1;
24532 + unsigned inep8 : 1;
24533 + unsigned inep9 : 1;
24534 + unsigned inep10 : 1;
24535 + unsigned inep11 : 1;
24536 + unsigned inep12 : 1;
24537 + unsigned inep13 : 1;
24538 + unsigned inep14 : 1;
24539 + unsigned inep15 : 1;
24540 + /** OUT Endpoint bits */
24541 + unsigned outep0 : 1;
24542 + unsigned outep1 : 1;
24543 + unsigned outep2 : 1;
24544 + unsigned outep3 : 1;
24545 + unsigned outep4 : 1;
24546 + unsigned outep5 : 1;
24547 + unsigned outep6 : 1;
24548 + unsigned outep7 : 1;
24549 + unsigned outep8 : 1;
24550 + unsigned outep9 : 1;
24551 + unsigned outep10 : 1;
24552 + unsigned outep11 : 1;
24553 + unsigned outep12 : 1;
24554 + unsigned outep13 : 1;
24555 + unsigned outep14 : 1;
24556 + unsigned outep15 : 1;
24561 + * This union represents the bit fields in the Device IN Token Queue
24562 + * Read Registers.
24563 + * - Read the register into the <i>d32</i> member.
24564 + * - READ-ONLY Register
24566 +typedef union dtknq1_data
24568 + /** raw register data */
24570 + /** register bits */
24573 + /** In Token Queue Write Pointer */
24574 + unsigned intknwptr : 5;
24576 + unsigned reserved05_06 : 2;
24577 + /** write pointer has wrapped. */
24578 + unsigned wrap_bit : 1;
24579 + /** EP Numbers of IN Tokens 0 ... 4 */
24580 + unsigned epnums0_5 : 24;
24585 + * This union represents Threshold control Register
24586 + * - Read and write the register into the <i>d32</i> member.
24587 + * - READ-WRITABLE Register
24589 +typedef union dthrctl_data
24591 + /** raw register data */
24593 + /** register bits */
24596 + /** non ISO Tx Thr. Enable */
24597 + unsigned non_iso_thr_en : 1;
24598 + /** ISO Tx Thr. Enable */
24599 + unsigned iso_thr_en : 1;
24600 + /** Tx Thr. Length */
24601 + unsigned tx_thr_len : 9;
24603 + unsigned reserved11_15 : 5;
24604 + /** Rx Thr. Enable */
24605 + unsigned rx_thr_en : 1;
24606 + /** Rx Thr. Length */
24607 + unsigned rx_thr_len : 9;
24609 + unsigned reserved26_31 : 6;
24615 + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
24618 + * There will be one set of endpoint registers per logical endpoint
24621 + * <i>These registers are visible only in Device mode and must not be
24622 + * accessed in Host mode, as the results are unknown.</i>
24624 +typedef struct dwc_otg_dev_in_ep_regs
24626 + /** Device IN Endpoint Control Register. <i>Offset:900h +
24627 + * (ep_num * 20h) + 00h</i> */
24628 + volatile uint32_t diepctl;
24629 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
24630 + uint32_t reserved04;
24631 + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
24632 + * (ep_num * 20h) + 08h</i> */
24633 + volatile uint32_t diepint;
24634 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
24635 + uint32_t reserved0C;
24636 + /** Device IN Endpoint Transfer Size
24637 + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
24638 + volatile uint32_t dieptsiz;
24639 + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
24640 + * (ep_num * 20h) + 14h</i> */
24641 + volatile uint32_t diepdma;
24642 + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
24643 + * (ep_num * 20h) + 18h</i> */
24644 + volatile uint32_t dtxfsts;
24645 + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
24646 + * (ep_num * 20h) + 1Ch</i> */
24647 + volatile uint32_t diepdmab;
24648 +} dwc_otg_dev_in_ep_regs_t;
24651 + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
24654 + * There will be one set of endpoint registers per logical endpoint
24657 + * <i>These registers are visible only in Device mode and must not be
24658 + * accessed in Host mode, as the results are unknown.</i>
24660 +typedef struct dwc_otg_dev_out_ep_regs
24662 + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
24663 + * (ep_num * 20h) + 00h</i> */
24664 + volatile uint32_t doepctl;
24665 + /** Device OUT Endpoint Frame number Register. <i>Offset:
24666 + * B00h + (ep_num * 20h) + 04h</i> */
24667 + volatile uint32_t doepfn;
24668 + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
24669 + * (ep_num * 20h) + 08h</i> */
24670 + volatile uint32_t doepint;
24671 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
24672 + uint32_t reserved0C;
24673 + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
24674 + * B00h + (ep_num * 20h) + 10h</i> */
24675 + volatile uint32_t doeptsiz;
24676 + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
24677 + * + (ep_num * 20h) + 14h</i> */
24678 + volatile uint32_t doepdma;
24679 + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 1Ch</i> */
24681 + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
24682 + * + (ep_num * 20h) + 1Ch</i> */
24683 + uint32_t doepdmab;
24684 +} dwc_otg_dev_out_ep_regs_t;
24687 + * This union represents the bit fields in the Device EP Control
24688 + * Register. Read the register into the <i>d32</i> member then
24689 + * set/clear the bits using the <i>b</i>it elements.
24691 +typedef union depctl_data
24693 + /** raw register data */
24695 + /** register bits */
24698 + /** Maximum Packet Size
24700 + * IN/OUT EP0 - 2 bits
24701 + * 2'b00: 64 Bytes
24705 + unsigned mps : 11;
24706 +#define DWC_DEP0CTL_MPS_64 0
24707 +#define DWC_DEP0CTL_MPS_32 1
24708 +#define DWC_DEP0CTL_MPS_16 2
24709 +#define DWC_DEP0CTL_MPS_8 3
24711 + /** Next Endpoint
24713 + * OUT EPn/OUT EP0 - reserved */
24714 + unsigned nextep : 4;
24716 + /** USB Active Endpoint */
24717 + unsigned usbactep : 1;
24719 + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
24720 + * This field contains the PID of the packet going to
24721 + * be received or transmitted on this endpoint. The
24722 + * application should program the PID of the first
24723 + * packet going to be received or transmitted on this
24724 + * endpoint , after the endpoint is
24725 + * activated. Application use the SetD1PID and
24726 + * SetD0PID fields of this register to program either
24729 + * The encoding for this field is
24733 + unsigned dpid : 1;
24735 + /** NAK Status */
24736 + unsigned naksts : 1;
24738 + /** Endpoint Type
24740 + * 2'b01: Isochronous
24742 + * 2'b11: Interrupt */
24743 + unsigned eptype : 2;
24746 + * OUT EPn/OUT EP0
24747 + * IN EPn/IN EP0 - reserved */
24748 + unsigned snp : 1;
24750 + /** Stall Handshake */
24751 + unsigned stall : 1;
24753 + /** Tx Fifo Number
24755 + * OUT EPn/OUT EP0 - reserved */
24756 + unsigned txfnum : 4;
24759 + unsigned cnak : 1;
24761 + unsigned snak : 1;
24762 + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
24763 + * Writing to this field sets the Endpoint DPID (DPID)
24764 + * field in this register to DATA0. Set Even
24765 + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
24766 + * Writing to this field sets the Even/Odd
24767 + * (micro)frame (EO_FrNum) field to even (micro)
24770 + unsigned setd0pid : 1;
24771 + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
24772 + * Writing to this field sets the Endpoint DPID (DPID)
24773 + * field in this register to DATA1 Set Odd
24774 + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
24775 + * Writing to this field sets the Even/Odd
24776 + * (micro)frame (EO_FrNum) field to odd (micro) frame.
24778 + unsigned setd1pid : 1;
24780 + /** Endpoint Disable */
24781 + unsigned epdis : 1;
24782 + /** Endpoint Enable */
24783 + unsigned epena : 1;
24788 + * This union represents the bit fields in the Device EP Transfer
24789 + * Size Register. Read the register into the <i>d32</i> member then
24790 + * set/clear the bits using the <i>b</i>it elements.
24792 +typedef union deptsiz_data
24794 + /** raw register data */
24796 + /** register bits */
24798 + /** Transfer size */
24799 + unsigned xfersize : 19;
24800 + /** Packet Count */
24801 + unsigned pktcnt : 10;
24802 + /** Multi Count - Periodic IN endpoints */
24804 + unsigned reserved : 1;
24809 + * This union represents the bit fields in the Device EP 0 Transfer
24810 + * Size Register. Read the register into the <i>d32</i> member then
24811 + * set/clear the bits using the <i>b</i>it elements.
24813 +typedef union deptsiz0_data
24815 + /** raw register data */
24817 + /** register bits */
24819 + /** Transfer size */
24820 + unsigned xfersize : 7;
24822 + unsigned reserved7_18 : 12;
24823 + /** Packet Count */
24824 + unsigned pktcnt : 1;
24826 + unsigned reserved20_28 : 9;
24827 + /**Setup Packet Count (DOEPTSIZ0 Only) */
24828 + unsigned supcnt : 2;
24829 + unsigned reserved31;
24831 +} deptsiz0_data_t;
24834 +/////////////////////////////////////////////////
24835 +// DMA Descriptor Specific Structures
24838 +/** Buffer status definitions */
24840 +#define BS_HOST_READY 0x0
24841 +#define BS_DMA_BUSY 0x1
24842 +#define BS_DMA_DONE 0x2
24843 +#define BS_HOST_BUSY 0x3
24845 +/** Receive/Transmit status definitions */
24847 +#define RTS_SUCCESS 0x0
24848 +#define RTS_BUFFLUSH 0x1
24849 +#define RTS_RESERVED 0x2
24850 +#define RTS_BUFERR 0x3
24854 + * This union represents the bit fields in the DMA Descriptor
24855 + * status quadlet. Read the quadlet into the <i>d32</i> member then
24856 + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
24857 + * <i>b_iso_in</i> elements.
24859 +typedef union desc_sts_data
24861 + /** raw register data */
24863 + /** quadlet bits */
24865 + /** Received number of bytes */
24866 + unsigned bytes : 16;
24868 + unsigned reserved16_22 : 7;
24869 + /** Multiple Transfer - only for OUT EPs */
24870 + unsigned mtrf : 1;
24871 + /** Setup Packet received - only for OUT EPs */
24873 + /** Interrupt On Complete */
24874 + unsigned ioc : 1;
24875 + /** Short Packet */
24879 + /** Receive Status */
24880 + unsigned sts : 2;
24881 + /** Buffer Status */
24885 +#ifdef DWC_EN_ISOC
24886 + /** iso out quadlet bits */
24888 + /** Received number of bytes */
24889 + unsigned rxbytes : 11;
24891 + unsigned reserved11 : 1;
24892 + /** Frame Number */
24893 + unsigned framenum : 11;
24894 + /** Received ISO Data PID */
24895 + unsigned pid : 2;
24896 + /** Interrupt On Complete */
24897 + unsigned ioc : 1;
24898 + /** Short Packet */
24902 + /** Receive Status */
24903 + unsigned rxsts : 2;
24904 + /** Buffer Status */
24908 + /** iso in quadlet bits */
24910 + /** Transmited number of bytes */
24911 + unsigned txbytes : 12;
24912 + /** Frame Number */
24913 + unsigned framenum : 11;
24914 + /** Transmited ISO Data PID */
24915 + unsigned pid : 2;
24916 + /** Interrupt On Complete */
24917 + unsigned ioc : 1;
24918 + /** Short Packet */
24922 + /** Transmit Status */
24923 + unsigned txsts : 2;
24924 + /** Buffer Status */
24927 +#endif //DWC_EN_ISOC
24928 +} desc_sts_data_t;
24931 + * DMA Descriptor structure
24933 + * DMA Descriptor structure contains two quadlets:
24934 + * Status quadlet and Data buffer pointer.
24936 +typedef struct dwc_otg_dma_desc
24938 + /** DMA Descriptor status quadlet */
24939 + desc_sts_data_t status;
24940 + /** DMA Descriptor data buffer pointer */
24942 +} dwc_otg_dma_desc_t;
24945 + * The dwc_otg_dev_if structure contains information needed to manage
24946 + * the DWC_otg controller acting in device mode. It represents the
24947 + * programming view of the device-specific aspects of the controller.
24949 +typedef struct dwc_otg_dev_if
24951 + /** Pointer to device Global registers.
24952 + * Device Global Registers starting at offset 800h
24954 + dwc_otg_device_global_regs_t *dev_global_regs;
24955 +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
24958 + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
24960 + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
24961 +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
24962 +#define DWC_EP_REG_OFFSET 0x20
24964 + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
24965 + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
24966 +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
24968 + /* Device configuration information*/
24969 + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
24970 + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
24971 + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
24973 + /** Size of periodic FIFOs (Bytes) */
24974 + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
24976 + /** Size of Tx FIFOs (Bytes) */
24977 + uint16_t tx_fifo_size[MAX_TX_FIFOS];
24979 + /** Thresholding enable flags and length varaiables **/
24980 + uint16_t rx_thr_en;
24981 + uint16_t iso_tx_thr_en;
24982 + uint16_t non_iso_tx_thr_en;
24984 + uint16_t rx_thr_length;
24985 + uint16_t tx_thr_length;
24988 + * Pointers to the DMA Descriptors for EP0 Control
24989 + * transfers (virtual and physical)
24992 + /** 2 descriptors for SETUP packets */
24993 + uint32_t dma_setup_desc_addr[2];
24994 + dwc_otg_dma_desc_t* setup_desc_addr[2];
24996 + /** Pointer to Descriptor with latest SETUP packet */
24997 + dwc_otg_dma_desc_t* psetup;
24999 + /** Index of current SETUP handler descriptor */
25000 + uint32_t setup_desc_index;
25002 + /** Descriptor for Data In or Status In phases */
25003 + uint32_t dma_in_desc_addr;
25004 + dwc_otg_dma_desc_t* in_desc_addr;;
25006 + /** Descriptor for Data Out or Status Out phases */
25007 + uint32_t dma_out_desc_addr;
25008 + dwc_otg_dma_desc_t* out_desc_addr;
25010 +} dwc_otg_dev_if_t;
25015 +/////////////////////////////////////////////////
25016 +// Host Mode Register Structures
25019 + * The Host Global Registers structure defines the size and relative
25020 + * field offsets for the Host Mode Global Registers. Host Global
25021 + * Registers offsets 400h-7FFh.
25023 +typedef struct dwc_otg_host_global_regs
25025 + /** Host Configuration Register. <i>Offset: 400h</i> */
25026 + volatile uint32_t hcfg;
25027 + /** Host Frame Interval Register. <i>Offset: 404h</i> */
25028 + volatile uint32_t hfir;
25029 + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
25030 + volatile uint32_t hfnum;
25031 + /** Reserved. <i>Offset: 40Ch</i> */
25032 + uint32_t reserved40C;
25033 + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
25034 + volatile uint32_t hptxsts;
25035 + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
25036 + volatile uint32_t haint;
25037 + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
25038 + volatile uint32_t haintmsk;
25039 +} dwc_otg_host_global_regs_t;
25042 + * This union represents the bit fields in the Host Configuration Register.
25043 + * Read the register into the <i>d32</i> member then set/clear the bits using
25044 + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
25046 +typedef union hcfg_data
25048 + /** raw register data */
25051 + /** register bits */
25054 + /** FS/LS Phy Clock Select */
25055 + unsigned fslspclksel : 2;
25056 +#define DWC_HCFG_30_60_MHZ 0
25057 +#define DWC_HCFG_48_MHZ 1
25058 +#define DWC_HCFG_6_MHZ 2
25060 + /** FS/LS Only Support */
25061 + unsigned fslssupp : 1;
25066 + * This union represents the bit fields in the Host Frame Remaing/Number
25069 +typedef union hfir_data
25071 + /** raw register data */
25074 + /** register bits */
25077 + unsigned frint : 16;
25078 + unsigned reserved : 16;
25083 + * This union represents the bit fields in the Host Frame Remaing/Number
25086 +typedef union hfnum_data
25088 + /** raw register data */
25091 + /** register bits */
25094 + unsigned frnum : 16;
25095 +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
25096 + unsigned frrem : 16;
25100 +typedef union hptxsts_data
25102 + /** raw register data */
25105 + /** register bits */
25108 + unsigned ptxfspcavail : 16;
25109 + unsigned ptxqspcavail : 8;
25110 + /** Top of the Periodic Transmit Request Queue
25111 + * - bit 24 - Terminate (last entry for the selected channel)
25112 + * - bits 26:25 - Token Type
25113 + * - 2'b00 - Zero length
25115 + * - 2'b10 - Disable
25116 + * - bits 30:27 - Channel Number
25117 + * - bit 31 - Odd/even microframe
25119 + unsigned ptxqtop_terminate : 1;
25120 + unsigned ptxqtop_token : 2;
25121 + unsigned ptxqtop_chnum : 4;
25122 + unsigned ptxqtop_odd : 1;
25127 + * This union represents the bit fields in the Host Port Control and Status
25128 + * Register. Read the register into the <i>d32</i> member then set/clear the
25129 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
25130 + * hprt0 register.
25132 +typedef union hprt0_data
25134 + /** raw register data */
25136 + /** register bits */
25139 + unsigned prtconnsts : 1;
25140 + unsigned prtconndet : 1;
25141 + unsigned prtena : 1;
25142 + unsigned prtenchng : 1;
25143 + unsigned prtovrcurract : 1;
25144 + unsigned prtovrcurrchng : 1;
25145 + unsigned prtres : 1;
25146 + unsigned prtsusp : 1;
25147 + unsigned prtrst : 1;
25148 + unsigned reserved9 : 1;
25149 + unsigned prtlnsts : 2;
25150 + unsigned prtpwr : 1;
25151 + unsigned prttstctl : 4;
25152 + unsigned prtspd : 2;
25153 +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
25154 +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
25155 +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
25156 + unsigned reserved19_31 : 13;
25161 + * This union represents the bit fields in the Host All Interrupt
25164 +typedef union haint_data
25166 + /** raw register data */
25168 + /** register bits */
25171 + unsigned ch0 : 1;
25172 + unsigned ch1 : 1;
25173 + unsigned ch2 : 1;
25174 + unsigned ch3 : 1;
25175 + unsigned ch4 : 1;
25176 + unsigned ch5 : 1;
25177 + unsigned ch6 : 1;
25178 + unsigned ch7 : 1;
25179 + unsigned ch8 : 1;
25180 + unsigned ch9 : 1;
25181 + unsigned ch10 : 1;
25182 + unsigned ch11 : 1;
25183 + unsigned ch12 : 1;
25184 + unsigned ch13 : 1;
25185 + unsigned ch14 : 1;
25186 + unsigned ch15 : 1;
25187 + unsigned reserved : 16;
25192 + unsigned chint : 16;
25193 + unsigned reserved : 16;
25198 + * This union represents the bit fields in the Host All Interrupt
25201 +typedef union haintmsk_data
25203 + /** raw register data */
25205 + /** register bits */
25208 + unsigned ch0 : 1;
25209 + unsigned ch1 : 1;
25210 + unsigned ch2 : 1;
25211 + unsigned ch3 : 1;
25212 + unsigned ch4 : 1;
25213 + unsigned ch5 : 1;
25214 + unsigned ch6 : 1;
25215 + unsigned ch7 : 1;
25216 + unsigned ch8 : 1;
25217 + unsigned ch9 : 1;
25218 + unsigned ch10 : 1;
25219 + unsigned ch11 : 1;
25220 + unsigned ch12 : 1;
25221 + unsigned ch13 : 1;
25222 + unsigned ch14 : 1;
25223 + unsigned ch15 : 1;
25224 + unsigned reserved : 16;
25229 + unsigned chint : 16;
25230 + unsigned reserved : 16;
25232 +} haintmsk_data_t;
25235 + * Host Channel Specific Registers. <i>500h-5FCh</i>
25237 +typedef struct dwc_otg_hc_regs
25239 + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
25240 + volatile uint32_t hcchar;
25241 + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
25242 + volatile uint32_t hcsplt;
25243 + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
25244 + volatile uint32_t hcint;
25245 + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
25246 + volatile uint32_t hcintmsk;
25247 + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
25248 + volatile uint32_t hctsiz;
25249 + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
25250 + volatile uint32_t hcdma;
25251 + /** Reserved. <i>Offset: 500h + (chan_num * 20h) + 18h - 500h + (chan_num * 20h) + 1Ch</i> */
25252 + uint32_t reserved[2];
25253 +} dwc_otg_hc_regs_t;
25256 + * This union represents the bit fields in the Host Channel Characteristics
25257 + * Register. Read the register into the <i>d32</i> member then set/clear the
25258 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
25259 + * hcchar register.
25261 +typedef union hcchar_data
25263 + /** raw register data */
25266 + /** register bits */
25269 + /** Maximum packet size in bytes */
25270 + unsigned mps : 11;
25272 + /** Endpoint number */
25273 + unsigned epnum : 4;
25275 + /** 0: OUT, 1: IN */
25276 + unsigned epdir : 1;
25278 + unsigned reserved : 1;
25280 + /** 0: Full/high speed device, 1: Low speed device */
25281 + unsigned lspddev : 1;
25283 + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
25284 + unsigned eptype : 2;
25286 + /** Packets per frame for periodic transfers. 0 is reserved. */
25287 + unsigned multicnt : 2;
25289 + /** Device address */
25290 + unsigned devaddr : 7;
25293 + * Frame to transmit periodic transaction.
25294 + * 0: even, 1: odd
25296 + unsigned oddfrm : 1;
25298 + /** Channel disable */
25299 + unsigned chdis : 1;
25301 + /** Channel enable */
25302 + unsigned chen : 1;
25306 +typedef union hcsplt_data
25308 + /** raw register data */
25311 + /** register bits */
25314 + /** Port Address */
25315 + unsigned prtaddr : 7;
25317 + /** Hub Address */
25318 + unsigned hubaddr : 7;
25320 + /** Transaction Position */
25321 + unsigned xactpos : 2;
25322 +#define DWC_HCSPLIT_XACTPOS_MID 0
25323 +#define DWC_HCSPLIT_XACTPOS_END 1
25324 +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
25325 +#define DWC_HCSPLIT_XACTPOS_ALL 3
25327 + /** Do Complete Split */
25328 + unsigned compsplt : 1;
25331 + unsigned reserved : 14;
25333 + /** Split Enble */
25334 + unsigned spltena : 1;
25340 + * This union represents the bit fields in the Host All Interrupt
25343 +typedef union hcint_data
25345 + /** raw register data */
25347 + /** register bits */
25350 + /** Transfer Complete */
25351 + unsigned xfercomp : 1;
25352 + /** Channel Halted */
25353 + unsigned chhltd : 1;
25355 + unsigned ahberr : 1;
25356 + /** STALL Response Received */
25357 + unsigned stall : 1;
25358 + /** NAK Response Received */
25359 + unsigned nak : 1;
25360 + /** ACK Response Received */
25361 + unsigned ack : 1;
25362 + /** NYET Response Received */
25363 + unsigned nyet : 1;
25364 + /** Transaction Err */
25365 + unsigned xacterr : 1;
25366 + /** Babble Error */
25367 + unsigned bblerr : 1;
25368 + /** Frame Overrun */
25369 + unsigned frmovrun : 1;
25370 + /** Data Toggle Error */
25371 + unsigned datatglerr : 1;
25373 + unsigned reserved : 21;
25378 + * This union represents the bit fields in the Host Channel Transfer Size
25379 + * Register. Read the register into the <i>d32</i> member then set/clear the
25380 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
25381 + * hcchar register.
25383 +typedef union hctsiz_data
25385 + /** raw register data */
25388 + /** register bits */
25391 + /** Total transfer size in bytes */
25392 + unsigned xfersize : 19;
25394 + /** Data packets to transfer */
25395 + unsigned pktcnt : 10;
25398 + * Packet ID for next data packet
25402 + * 3: MDATA (non-Control), SETUP (Control)
25404 + unsigned pid : 2;
25405 +#define DWC_HCTSIZ_DATA0 0
25406 +#define DWC_HCTSIZ_DATA1 2
25407 +#define DWC_HCTSIZ_DATA2 1
25408 +#define DWC_HCTSIZ_MDATA 3
25409 +#define DWC_HCTSIZ_SETUP 3
25411 + /** Do PING protocol when 1 */
25412 + unsigned dopng : 1;
25417 + * This union represents the bit fields in the Host Channel Interrupt Mask
25418 + * Register. Read the register into the <i>d32</i> member then set/clear the
25419 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
25420 + * hcintmsk register.
25422 +typedef union hcintmsk_data
25424 + /** raw register data */
25427 + /** register bits */
25430 + unsigned xfercompl : 1;
25431 + unsigned chhltd : 1;
25432 + unsigned ahberr : 1;
25433 + unsigned stall : 1;
25434 + unsigned nak : 1;
25435 + unsigned ack : 1;
25436 + unsigned nyet : 1;
25437 + unsigned xacterr : 1;
25438 + unsigned bblerr : 1;
25439 + unsigned frmovrun : 1;
25440 + unsigned datatglerr : 1;
25441 + unsigned reserved : 21;
25443 +} hcintmsk_data_t;
25445 +/** OTG Host Interface Structure.
25447 + * The OTG Host Interface Structure structure contains information
25448 + * needed to manage the DWC_otg controller acting in host mode. It
25449 + * represents the programming view of the host-specific aspects of the
25452 +typedef struct dwc_otg_host_if
25454 + /** Host Global Registers starting at offset 400h.*/
25455 + dwc_otg_host_global_regs_t *host_global_regs;
25456 +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
25458 + /** Host Port 0 Control and Status Register */
25459 + volatile uint32_t *hprt0;
25460 +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
25463 + /** Host Channel Specific Registers at offsets 500h-5FCh. */
25464 + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
25465 +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
25466 +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
25469 + /* Host configuration information */
25470 + /** Number of Host Channels (range: 1-16) */
25471 + uint8_t num_host_channels;
25472 + /** Periodic EPs supported (0: no, 1: yes) */
25473 + uint8_t perio_eps_supported;
25474 + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
25475 + uint16_t perio_tx_fifo_size;
25477 +} dwc_otg_host_if_t;
25481 + * This union represents the bit fields in the Power and Clock Gating Control
25482 + * Register. Read the register into the <i>d32</i> member then set/clear the
25483 + * bits using the <i>b</i>it elements.
25485 +typedef union pcgcctl_data
25487 + /** raw register data */
25490 + /** register bits */
25494 + unsigned stoppclk : 1;
25496 + unsigned gatehclk : 1;
25497 + /** Power Clamp */
25498 + unsigned pwrclmp : 1;
25499 + /** Reset Power Down Modules */
25500 + unsigned rstpdwnmodule : 1;
25501 + /** PHY Suspended */
25502 + unsigned physuspended : 1;
25504 + unsigned reserved : 27;
25511 +++ b/drivers/usb/host/otg/Makefile
25514 +# Makefile for DWC_otg Highspeed USB controller driver
25517 +ifneq ($(KERNELRELEASE),)
25518 +EXTRA_CFLAGS += -DDEBUG
25520 +# Use one of the following flags to compile the software in host-only or
25521 +# device-only mode.
25522 +#CPPFLAGS += -DDWC_HOST_ONLY
25523 +#CPPFLAGS += -DDWC_DEVICE_ONLY
25525 +EXTRA_CFLAGS += -Dlinux -DDWC_HS_ELECT_TST
25526 +#EXTRA_CFLAGS += -DDWC_EN_ISOC
25528 +ifneq ($(CONFIG_USB_CNS3XXX_OTG_HCD_ONLY),)
25529 +EXTRA_CFLAGS += -DDWC_HOST_ONLY
25532 +ifneq ($(CONFIG_USB_CNS3XXX_OTG_PCD_ONLY),)
25533 +EXTRA_CFLAGS += -DDWC_DEVICE_ONLY
25536 +obj-$(CONFIG_USB_CNS3XXX_OTG) := dwc_otg.o
25537 +#obj-$(CONFIG_USB_GADGET_CNS3XXX_OTG) := dwc_otg.o
25539 +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
25540 +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
25541 +dwc_otg-objs += dwc_otg_pcd.o dwc_otg_pcd_intr.o
25542 +dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o
25546 +PWD := $(shell pwd)
25550 +DOXYGEN := $(DOXYGEN)
25553 + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
25555 +docs: $(wildcard *.[hc]) doc/doxygen.cfg
25556 + $(DOXYGEN) doc/doxygen.cfg
25558 +tags: $(wildcard *.[hc])
25559 + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
25564 + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions
25565 --- a/drivers/usb/Kconfig
25566 +++ b/drivers/usb/Kconfig
25567 @@ -39,6 +39,7 @@ config USB_ARCH_HAS_OHCI
25568 default y if ARCH_AT91
25569 default y if ARCH_PNX4008 && I2C
25570 default y if MFD_TC6393XB
25571 + default y if ARCH_CNS3XXX
25573 default y if STB03xxx
25574 default y if PPC_MPC52xx
25575 @@ -58,6 +59,7 @@ config USB_ARCH_HAS_EHCI
25576 default y if PPC_83xx
25577 default y if SOC_AU1200
25578 default y if ARCH_IXP4XX
25579 + default y if ARCH_CNS3XXX
25582 # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
25583 --- a/drivers/usb/Makefile
25584 +++ b/drivers/usb/Makefile
25585 @@ -20,6 +20,8 @@ obj-$(CONFIG_USB_U132_HCD) += host/
25586 obj-$(CONFIG_USB_R8A66597_HCD) += host/
25587 obj-$(CONFIG_USB_HWA_HCD) += host/
25588 obj-$(CONFIG_USB_ISP1760_HCD) += host/
25589 +obj-$(CONFIG_USB_CNS3XXX_OTG) += host/
25590 +obj-$(CONFIG_USB_GADGET_CNS3XXX_OTG) += host/
25592 obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
25594 --- a/drivers/usb/storage/protocol.c
25595 +++ b/drivers/usb/storage/protocol.c
25596 @@ -182,9 +182,10 @@ unsigned int usb_stor_access_xfer_buf(un
25598 unsigned char *ptr = kmap(page);
25600 - if (dir == TO_XFER_BUF)
25601 + if (dir == TO_XFER_BUF) {
25602 memcpy(ptr + poff, buffer + cnt, plen);
25604 + flush_dcache_page(page);
25606 memcpy(buffer + cnt, ptr + poff, plen);
25609 --- a/include/linux/usb.h
25610 +++ b/include/linux/usb.h
25611 @@ -1201,8 +1201,14 @@ struct urb {
25612 unsigned int pipe; /* (in) pipe information */
25613 int status; /* (return) non-ISO status */
25614 unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/
25616 void *transfer_buffer; /* (in) associated data buffer */
25617 dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */
25619 + void * aligned_transfer_buffer; /* (in) associated data buffer */
25620 + dma_addr_t aligned_transfer_dma; /* (in) dma addr for transfer_buffer */
25621 + u32 aligned_transfer_buffer_length; /* (in) data buffer length */
25623 struct usb_sg_request *sg; /* (in) scatter gather buffer list */
25624 int num_sgs; /* (in) number of entries in the sg list */
25625 u32 transfer_buffer_length; /* (in) data buffer length */