1 --- a/drivers/usb/Kconfig
2 +++ b/drivers/usb/Kconfig
5 source "drivers/usb/host/Kconfig"
7 +source "drivers/usb/dwc_otg/Kconfig"
9 source "drivers/usb/musb/Kconfig"
11 source "drivers/usb/class/Kconfig"
12 --- a/drivers/usb/Makefile
13 +++ b/drivers/usb/Makefile
16 obj-$(CONFIG_USB_WUSB) += wusbcore/
18 +obj-$(CONFIG_DWC_OTG) += dwc_otg/
20 obj-$(CONFIG_USB_ACM) += class/
21 obj-$(CONFIG_USB_PRINTER) += class/
22 obj-$(CONFIG_USB_WDM) += class/
24 +++ b/drivers/usb/dwc_otg/Kconfig
27 + tristate "Synopsis DWC_OTG support"
30 + This driver supports Synopsis DWC_OTG IP core
31 + embebbed on many SOCs (ralink, infineon, etc)
34 + prompt "USB Operation Mode"
36 + default DWC_OTG_HOST_ONLY
38 +config DWC_OTG_HOST_ONLY
39 + bool "HOST ONLY MODE"
42 +#config DWC_OTG_DEVICE_ONLY
43 +# bool "DEVICE ONLY MODE"
50 + default DWC_OTG_LANTIQ
52 +config DWC_OTG_LANTIQ
56 + Danube USB Host Controller
61 + bool "Enable debug mode"
64 +++ b/drivers/usb/dwc_otg/Makefile
67 +# Makefile for DWC_otg Highspeed USB controller driver
70 +ifeq ($(CONFIG_DWC_OTG_DEBUG),y)
71 +EXTRA_CFLAGS += -DDEBUG
74 +# Use one of the following flags to compile the software in host-only or
75 +# device-only mode based on the configuration selected by the user
76 +ifeq ($(CONFIG_DWC_OTG_HOST_ONLY),y)
77 + EXTRA_CFLAGS += -DDWC_OTG_HOST_ONLY -DDWC_HOST_ONLY
78 + EXTRA_CFLAGS += -DDWC_OTG_EN_ISOC -DDWC_EN_ISOC
79 +else ifeq ($(CONFIG_DWC_OTG_DEVICE_ONLY),y)
80 + EXTRA_CFLAGS += -DDWC_OTG_DEVICE_ONLY
82 + EXTRA_CFLAGS += -DDWC_OTG_MODE
85 +# EXTRA_CFLAGS += -DDWC_HS_ELECT_TST
86 +# EXTRA_CFLAGS += -DDWC_OTG_EXT_CHG_PUMP
88 +ifeq ($(CONFIG_DWC_OTG_LANTIQ),y)
89 + EXTRA_CFLAGS += -Dlinux -D__LINUX__ -DDWC_OTG_IFX -DDWC_OTG_HOST_ONLY -DDWC_HOST_ONLY -D__KERNEL__
91 +ifeq ($(CONFIG_DWC_OTG_LANTIQ),m)
92 + EXTRA_CFLAGS += -Dlinux -D__LINUX__ -DDWC_OTG_IFX -DDWC_HOST_ONLY -DMODULE -D__KERNEL__ -DDEBUG
95 +obj-$(CONFIG_DWC_OTG) := dwc_otg.o
96 +dwc_otg-objs := dwc_otg_hcd.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o
97 +#dwc_otg-objs += dwc_otg_pcd.o dwc_otg_pcd_intr.o
98 +dwc_otg-objs += dwc_otg_attr.o
99 +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
100 +dwc_otg-objs += dwc_otg_ifx.o
101 +dwc_otg-objs += dwc_otg_driver.o
103 +#obj-$(CONFIG_DWC_OTG_IFX) := dwc_otg_ifx.o
104 +#dwc_otg_ifx-objs := dwc_otg_ifx.o
106 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.c
108 +/* ==========================================================================
109 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_attr.c $
110 + * $Revision: 1.1.1.1 $
111 + * $Date: 2009-04-17 06:15:34 $
112 + * $Change: 537387 $
114 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
115 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
116 + * otherwise expressly agreed to in writing between Synopsys and you.
118 + * The Software IS NOT an item of Licensed Software or Licensed Product under
119 + * any End User Software License Agreement or Agreement for Licensed Product
120 + * with Synopsys or any supplement thereto. You are permitted to use and
121 + * redistribute this Software in source and binary forms, with or without
122 + * modification, provided that redistributions of source code must retain this
123 + * notice. You may not view, use, disclose, copy or distribute this file or
124 + * any information contained herein except pursuant to this license grant from
125 + * Synopsys. If you do not agree with this notice, including the disclaimer
126 + * below, then you are not authorized to use the Software.
128 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
129 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
130 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
131 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
132 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
133 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
134 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
135 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
136 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
137 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
139 + * ========================================================================== */
143 + * The diagnostic interface will provide access to the controller for
144 + * bringing up the hardware and testing. The Linux driver attributes
145 + * feature will be used to provide the Linux Diagnostic
146 + * Interface. These attributes are accessed through sysfs.
149 +/** @page "Linux Module Attributes"
151 + * The Linux module attributes feature is used to provide the Linux
152 + * Diagnostic Interface. These attributes are accessed through sysfs.
153 + * The diagnostic interface will provide access to the controller for
154 + * bringing up the hardware and testing.
157 + The following table shows the attributes.
160 + <td><b> Name</b></td>
161 + <td><b> Description</b></td>
162 + <td><b> Access</b></td>
167 + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
172 + <td> hnpcapable </td>
173 + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
174 + Read returns the current value.</td>
175 + <td> Read/Write</td>
179 + <td> srpcapable </td>
180 + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
181 + Read returns the current value.</td>
182 + <td> Read/Write</td>
187 + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
188 + <td> Read/Write</td>
193 + <td> Initiates the Session Request Protocol. Read returns the status.</td>
194 + <td> Read/Write</td>
198 + <td> buspower </td>
199 + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
200 + <td> Read/Write</td>
204 + <td> bussuspend </td>
205 + <td> Suspends the USB bus.</td>
206 + <td> Read/Write</td>
210 + <td> busconnected </td>
211 + <td> Gets the connection status of the bus</td>
217 + <td> Gets or sets the Core Control Status Register.</td>
218 + <td> Read/Write</td>
223 + <td> Gets or sets the Core USB Configuration Register</td>
224 + <td> Read/Write</td>
229 + <td> Gets or sets the Receive FIFO Size Register</td>
230 + <td> Read/Write</td>
234 + <td> gnptxfsiz </td>
235 + <td> Gets or sets the non-periodic Transmit Size Register</td>
236 + <td> Read/Write</td>
240 + <td> gpvndctl </td>
241 + <td> Gets or sets the PHY Vendor Control Register</td>
242 + <td> Read/Write</td>
247 + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
248 + or sets the upper 16 bits.</td>
249 + <td> Read/Write</td>
254 + <td> Gets or sets the value of the User ID Register</td>
255 + <td> Read/Write</td>
260 + <td> Gets the value of the Synopsys ID Regester</td>
265 + <td> devspeed </td>
266 + <td> Gets or sets the device speed setting in the DCFG register</td>
267 + <td> Read/Write</td>
271 + <td> enumspeed </td>
272 + <td> Gets the device enumeration Speed.</td>
277 + <td> hptxfsiz </td>
278 + <td> Gets the value of the Host Periodic Transmit FIFO</td>
284 + <td> Gets or sets the value in the Host Port Control and Status Register</td>
285 + <td> Read/Write</td>
289 + <td> regoffset </td>
290 + <td> Sets the register offset for the next Register Access</td>
291 + <td> Read/Write</td>
295 + <td> regvalue </td>
296 + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
297 + <td> Read/Write</td>
301 + <td> remote_wakeup </td>
302 + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
303 + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
304 + Wakeup signalling bit in the Device Control Register is set for 1
306 + <td> Read/Write</td>
311 + <td> Dumps the contents of core registers.</td>
317 + <td> Dumps the current HCD state.</td>
322 + <td> hcd_frrem </td>
323 + <td> Shows the average value of the Frame Remaining
324 + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
325 + occurs. This can be used to determine the average interrupt latency. Also
326 + shows the average Frame Remaining value for start_transfer and the "a" and
327 + "b" sample points. The "a" and "b" sample points may be used during debugging
328 + bto determine how long it takes to execute a section of the HCD code.</td>
333 + <td> rd_reg_test </td>
334 + <td> Displays the time required to read the GNPTXFSIZ register many times
335 + (the output shows the number of times the register is read).
340 + <td> wr_reg_test </td>
341 + <td> Displays the time required to write the GNPTXFSIZ register many times
342 + (the output shows the number of times the register is written).
349 + To get the current mode:
350 + cat /sys/devices/lm0/mode
352 + To power down the USB:
353 + echo 0 > /sys/devices/lm0/buspower
355 +#include <linux/kernel.h>
356 +#include <linux/module.h>
357 +#include <linux/moduleparam.h>
358 +#include <linux/init.h>
359 +#include <linux/device.h>
360 +#include <linux/errno.h>
361 +#include <linux/types.h>
362 +#include <linux/stat.h> /* permission constants */
366 +#include "dwc_otg_plat.h"
367 +#include "dwc_otg_attr.h"
368 +#include "dwc_otg_driver.h"
369 +// #include "dwc_otg_pcd.h"
370 +#include "dwc_otg_hcd.h"
372 +// 20070316, winder added.
374 +#define SZ_256K 0x00040000
378 + * MACROs for defining sysfs attribute
380 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
381 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
383 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
385 + val = dwc_read_reg32 (_addr_); \
386 + val = (val & (_mask_)) >> _shift_; \
387 + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
389 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
390 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, const char *buf, size_t count) \
392 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
393 + uint32_t set = simple_strtoul(buf, NULL, 16); \
394 + uint32_t clear = set; \
395 + clear = ((~clear) << _shift_) & _mask_; \
396 + set = (set << _shift_) & _mask_; \
397 + dev_dbg(_dev, "Storing Address=0x%08x Set=0x%08x Clear=0x%08x\n", (uint32_t)_addr_, set, clear); \
398 + dwc_modify_reg32(_addr_, clear, set); \
402 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
403 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
404 +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
405 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
407 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
408 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
409 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
412 + * MACROs for defining sysfs attribute for 32-bit registers
414 +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
415 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
417 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
419 + val = dwc_read_reg32 (_addr_); \
420 + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
422 +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
423 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, const char *buf, size_t count) \
425 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
426 + uint32_t val = simple_strtoul(buf, NULL, 16); \
427 + dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \
428 + dwc_write_reg32(_addr_, val); \
432 +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
433 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
434 +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
435 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
437 +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
438 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
439 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
442 +/** @name Functions for Show/Store of Attributes */
446 + * Show the register offset of the Register Access.
448 +static ssize_t regoffset_show( struct device *_dev, struct device_attribute *attr, char *buf)
450 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
451 + return snprintf(buf, sizeof("0xFFFFFFFF\n")+1,"0x%08x\n", otg_dev->reg_offset);
455 + * Set the register offset for the next Register Access Read/Write
457 +static ssize_t regoffset_store( struct device *_dev, struct device_attribute *attr, const char *buf,
460 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
461 + uint32_t offset = simple_strtoul(buf, NULL, 16);
462 + //dev_dbg(_dev, "Offset=0x%08x\n", offset);
463 + if (offset < SZ_256K ) {
464 + otg_dev->reg_offset = offset;
467 + dev_err( _dev, "invalid offset\n" );
472 +DEVICE_ATTR(regoffset, S_IRUGO|S_IWUSR, regoffset_show, regoffset_store);
475 + * Show the value of the register at the offset in the reg_offset
478 +static ssize_t regvalue_show( struct device *_dev, struct device_attribute *attr, char *buf)
480 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
482 + volatile uint32_t *addr;
484 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
485 + /* Calculate the address */
486 + addr = (uint32_t*)(otg_dev->reg_offset +
487 + (uint8_t*)otg_dev->base);
488 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
489 + val = dwc_read_reg32( addr );
490 + return snprintf(buf, sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n")+1,
491 + "Reg@0x%06x = 0x%08x\n",
492 + otg_dev->reg_offset, val);
495 + dev_err(_dev, "Invalid offset (0x%0x)\n",
496 + otg_dev->reg_offset);
497 + return sprintf(buf, "invalid offset\n" );
502 + * Store the value in the register at the offset in the reg_offset
506 +static ssize_t regvalue_store( struct device *_dev, struct device_attribute *attr, const char *buf,
509 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
510 + volatile uint32_t * addr;
511 + uint32_t val = simple_strtoul(buf, NULL, 16);
512 + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
513 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
514 + /* Calculate the address */
515 + addr = (uint32_t*)(otg_dev->reg_offset +
516 + (uint8_t*)otg_dev->base);
517 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
518 + dwc_write_reg32( addr, val );
521 + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
522 + otg_dev->reg_offset);
526 +DEVICE_ATTR(regvalue, S_IRUGO|S_IWUSR, regvalue_show, regvalue_store);
531 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<20),20,"Mode");
532 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<9),9,"Mode");
533 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<8),8,"Mode");
535 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
536 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
537 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected,otg_dev->core_if->host_if->hprt0,0x01,0,"Bus Connected");
539 +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl,&(otg_dev->core_if->core_global_regs->gotgctl),"GOTGCTL");
540 +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,&(otg_dev->core_if->core_global_regs->gusbcfg),"GUSBCFG");
541 +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,&(otg_dev->core_if->core_global_regs->grxfsiz),"GRXFSIZ");
542 +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,&(otg_dev->core_if->core_global_regs->gnptxfsiz),"GNPTXFSIZ");
543 +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,&(otg_dev->core_if->core_global_regs->gpvndctl),"GPVNDCTL");
544 +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,&(otg_dev->core_if->core_global_regs->ggpio),"GGPIO");
545 +DWC_OTG_DEVICE_ATTR_REG32_RW(guid,&(otg_dev->core_if->core_global_regs->guid),"GUID");
546 +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,&(otg_dev->core_if->core_global_regs->gsnpsid),"GSNPSID");
547 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dcfg),0x3,0,"Device Speed");
548 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dsts),0x6,1,"Device Enumeration Speed");
550 +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,&(otg_dev->core_if->core_global_regs->hptxfsiz),"HPTXFSIZ");
551 +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0,otg_dev->core_if->host_if->hprt0,"HPRT0");
555 + * @todo Add code to initiate the HNP.
558 + * Show the HNP status bit
560 +static ssize_t hnp_show( struct device *_dev, struct device_attribute *attr, char *buf)
562 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
563 + gotgctl_data_t val;
564 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
565 + return sprintf (buf, "HstNegScs = 0x%x\n", val.b.hstnegscs);
569 + * Set the HNP Request bit
571 +static ssize_t hnp_store( struct device *_dev, struct device_attribute *attr, const char *buf,
574 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
575 + uint32_t in = simple_strtoul(buf, NULL, 16);
576 + uint32_t *addr = (uint32_t *)&(otg_dev->core_if->core_global_regs->gotgctl);
577 + gotgctl_data_t mem;
578 + mem.d32 = dwc_read_reg32(addr);
580 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
581 + dwc_write_reg32(addr, mem.d32);
584 +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
587 + * @todo Add code to initiate the SRP.
590 + * Show the SRP status bit
592 +static ssize_t srp_show( struct device *_dev, struct device_attribute *attr, char *buf)
594 +#ifndef DWC_HOST_ONLY
595 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
596 + gotgctl_data_t val;
597 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
598 + return sprintf (buf, "SesReqScs = 0x%x\n", val.b.sesreqscs);
600 + return sprintf(buf, "Host Only Mode!\n");
605 + * Set the SRP Request bit
607 +static ssize_t srp_store( struct device *_dev, struct device_attribute *attr, const char *buf,
610 +#ifndef DWC_HOST_ONLY
611 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
612 + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
616 +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
619 + * @todo Need to do more for power on/off?
622 + * Show the Bus Power status
624 +static ssize_t buspower_show( struct device *_dev, struct device_attribute *attr, char *buf)
626 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
628 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
629 + return sprintf (buf, "Bus Power = 0x%x\n", val.b.prtpwr);
634 + * Set the Bus Power status
636 +static ssize_t buspower_store( struct device *_dev, struct device_attribute *attr, const char *buf,
639 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
640 + uint32_t on = simple_strtoul(buf, NULL, 16);
641 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
644 + mem.d32 = dwc_read_reg32(addr);
647 + //dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
648 + dwc_write_reg32(addr, mem.d32);
652 +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
655 + * @todo Need to do more for suspend?
658 + * Show the Bus Suspend status
660 +static ssize_t bussuspend_show( struct device *_dev, struct device_attribute *attr, char *buf)
662 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
664 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
665 + return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
669 + * Set the Bus Suspend status
671 +static ssize_t bussuspend_store( struct device *_dev, struct device_attribute *attr, const char *buf,
674 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
675 + uint32_t in = simple_strtoul(buf, NULL, 16);
676 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
678 + mem.d32 = dwc_read_reg32(addr);
679 + mem.b.prtsusp = in;
680 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
681 + dwc_write_reg32(addr, mem.d32);
684 +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
687 + * Show the status of Remote Wakeup.
689 +static ssize_t remote_wakeup_show( struct device *_dev, struct device_attribute *attr, char *buf)
691 +#ifndef DWC_HOST_ONLY
692 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
694 + val.d32 = dwc_read_reg32( &otg_dev->core_if->dev_if->dev_global_regs->dctl);
695 + return sprintf( buf, "Remote Wakeup = %d Enabled = %d\n",
696 + val.b.rmtwkupsig, otg_dev->pcd->remote_wakeup_enable);
698 + return sprintf(buf, "Host Only Mode!\n");
703 + * Initiate a remote wakeup of the host. The Device control register
704 + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
708 +static ssize_t remote_wakeup_store( struct device *_dev, struct device_attribute *attr, const char *buf,
711 +#ifndef DWC_HOST_ONLY
712 + uint32_t val = simple_strtoul(buf, NULL, 16);
713 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
715 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
718 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
723 +DEVICE_ATTR(remote_wakeup, S_IRUGO|S_IWUSR, remote_wakeup_show,
724 + remote_wakeup_store);
727 + * Dump global registers and either host or device registers (depending on the
728 + * current mode of the core).
730 +static ssize_t regdump_show( struct device *_dev, struct device_attribute *attr, char *buf)
733 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
734 + printk("%s otg_dev=0x%p\n", __FUNCTION__, otg_dev);
736 + dwc_otg_dump_global_registers( otg_dev->core_if);
737 + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
738 + dwc_otg_dump_host_registers( otg_dev->core_if);
740 + dwc_otg_dump_dev_registers( otg_dev->core_if);
744 + return sprintf( buf, "Register Dump\n" );
747 +DEVICE_ATTR(regdump, S_IRUGO|S_IWUSR, regdump_show, 0);
750 + * Dump the current hcd state.
752 +static ssize_t hcddump_show( struct device *_dev, struct device_attribute *attr, char *buf)
754 +#ifndef DWC_DEVICE_ONLY
755 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
756 + dwc_otg_hcd_dump_state(otg_dev->hcd);
758 + return sprintf( buf, "HCD Dump\n" );
761 +DEVICE_ATTR(hcddump, S_IRUGO|S_IWUSR, hcddump_show, 0);
764 + * Dump the average frame remaining at SOF. This can be used to
765 + * determine average interrupt latency. Frame remaining is also shown for
766 + * start transfer and two additional sample points.
768 +static ssize_t hcd_frrem_show( struct device *_dev, struct device_attribute *attr, char *buf)
770 +#ifndef DWC_DEVICE_ONLY
771 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
772 + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
774 + return sprintf( buf, "HCD Dump Frame Remaining\n" );
777 +DEVICE_ATTR(hcd_frrem, S_IRUGO|S_IWUSR, hcd_frrem_show, 0);
780 + * Displays the time required to read the GNPTXFSIZ register many times (the
781 + * output shows the number of times the register is read).
783 +#define RW_REG_COUNT 10000000
784 +#define MSEC_PER_JIFFIE 1000/HZ
785 +static ssize_t rd_reg_test_show( struct device *_dev, struct device_attribute *attr, char *buf)
790 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
792 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
793 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
794 + start_jiffies = jiffies;
795 + for (i = 0; i < RW_REG_COUNT; i++) {
796 + dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
798 + time = jiffies - start_jiffies;
799 + return sprintf( buf, "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
800 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time );
803 +DEVICE_ATTR(rd_reg_test, S_IRUGO|S_IWUSR, rd_reg_test_show, 0);
806 + * Displays the time required to write the GNPTXFSIZ register many times (the
807 + * output shows the number of times the register is written).
809 +static ssize_t wr_reg_test_show( struct device *_dev, struct device_attribute *attr, char *buf)
814 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
817 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
818 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
819 + reg_val = dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
820 + start_jiffies = jiffies;
821 + for (i = 0; i < RW_REG_COUNT; i++) {
822 + dwc_write_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz, reg_val);
824 + time = jiffies - start_jiffies;
825 + return sprintf( buf, "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
826 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
829 +DEVICE_ATTR(wr_reg_test, S_IRUGO|S_IWUSR, wr_reg_test_show, 0);
833 + * Create the device files
835 +void dwc_otg_attr_create (struct device *_dev)
839 + retval = device_create_file(_dev, &dev_attr_regoffset);
840 + retval += device_create_file(_dev, &dev_attr_regvalue);
841 + retval += device_create_file(_dev, &dev_attr_mode);
842 + retval += device_create_file(_dev, &dev_attr_hnpcapable);
843 + retval += device_create_file(_dev, &dev_attr_srpcapable);
844 + retval += device_create_file(_dev, &dev_attr_hnp);
845 + retval += device_create_file(_dev, &dev_attr_srp);
846 + retval += device_create_file(_dev, &dev_attr_buspower);
847 + retval += device_create_file(_dev, &dev_attr_bussuspend);
848 + retval += device_create_file(_dev, &dev_attr_busconnected);
849 + retval += device_create_file(_dev, &dev_attr_gotgctl);
850 + retval += device_create_file(_dev, &dev_attr_gusbcfg);
851 + retval += device_create_file(_dev, &dev_attr_grxfsiz);
852 + retval += device_create_file(_dev, &dev_attr_gnptxfsiz);
853 + retval += device_create_file(_dev, &dev_attr_gpvndctl);
854 + retval += device_create_file(_dev, &dev_attr_ggpio);
855 + retval += device_create_file(_dev, &dev_attr_guid);
856 + retval += device_create_file(_dev, &dev_attr_gsnpsid);
857 + retval += device_create_file(_dev, &dev_attr_devspeed);
858 + retval += device_create_file(_dev, &dev_attr_enumspeed);
859 + retval += device_create_file(_dev, &dev_attr_hptxfsiz);
860 + retval += device_create_file(_dev, &dev_attr_hprt0);
861 + retval += device_create_file(_dev, &dev_attr_remote_wakeup);
862 + retval += device_create_file(_dev, &dev_attr_regdump);
863 + retval += device_create_file(_dev, &dev_attr_hcddump);
864 + retval += device_create_file(_dev, &dev_attr_hcd_frrem);
865 + retval += device_create_file(_dev, &dev_attr_rd_reg_test);
866 + retval += device_create_file(_dev, &dev_attr_wr_reg_test);
870 + DWC_PRINT("cannot create sysfs device files.\n");
871 + // DWC_PRINT("killing own sysfs device files!\n");
872 + dwc_otg_attr_remove(_dev);
877 + * Remove the device files
879 +void dwc_otg_attr_remove (struct device *_dev)
881 + device_remove_file(_dev, &dev_attr_regoffset);
882 + device_remove_file(_dev, &dev_attr_regvalue);
883 + device_remove_file(_dev, &dev_attr_mode);
884 + device_remove_file(_dev, &dev_attr_hnpcapable);
885 + device_remove_file(_dev, &dev_attr_srpcapable);
886 + device_remove_file(_dev, &dev_attr_hnp);
887 + device_remove_file(_dev, &dev_attr_srp);
888 + device_remove_file(_dev, &dev_attr_buspower);
889 + device_remove_file(_dev, &dev_attr_bussuspend);
890 + device_remove_file(_dev, &dev_attr_busconnected);
891 + device_remove_file(_dev, &dev_attr_gotgctl);
892 + device_remove_file(_dev, &dev_attr_gusbcfg);
893 + device_remove_file(_dev, &dev_attr_grxfsiz);
894 + device_remove_file(_dev, &dev_attr_gnptxfsiz);
895 + device_remove_file(_dev, &dev_attr_gpvndctl);
896 + device_remove_file(_dev, &dev_attr_ggpio);
897 + device_remove_file(_dev, &dev_attr_guid);
898 + device_remove_file(_dev, &dev_attr_gsnpsid);
899 + device_remove_file(_dev, &dev_attr_devspeed);
900 + device_remove_file(_dev, &dev_attr_enumspeed);
901 + device_remove_file(_dev, &dev_attr_hptxfsiz);
902 + device_remove_file(_dev, &dev_attr_hprt0);
903 + device_remove_file(_dev, &dev_attr_remote_wakeup);
904 + device_remove_file(_dev, &dev_attr_regdump);
905 + device_remove_file(_dev, &dev_attr_hcddump);
906 + device_remove_file(_dev, &dev_attr_hcd_frrem);
907 + device_remove_file(_dev, &dev_attr_rd_reg_test);
908 + device_remove_file(_dev, &dev_attr_wr_reg_test);
911 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.h
913 +/* ==========================================================================
914 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_attr.h $
915 + * $Revision: 1.1.1.1 $
916 + * $Date: 2009-04-17 06:15:34 $
917 + * $Change: 510275 $
919 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
920 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
921 + * otherwise expressly agreed to in writing between Synopsys and you.
923 + * The Software IS NOT an item of Licensed Software or Licensed Product under
924 + * any End User Software License Agreement or Agreement for Licensed Product
925 + * with Synopsys or any supplement thereto. You are permitted to use and
926 + * redistribute this Software in source and binary forms, with or without
927 + * modification, provided that redistributions of source code must retain this
928 + * notice. You may not view, use, disclose, copy or distribute this file or
929 + * any information contained herein except pursuant to this license grant from
930 + * Synopsys. If you do not agree with this notice, including the disclaimer
931 + * below, then you are not authorized to use the Software.
933 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
934 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
935 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
936 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
937 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
938 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
939 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
940 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
941 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
942 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
944 + * ========================================================================== */
946 +#if !defined(__DWC_OTG_ATTR_H__)
947 +#define __DWC_OTG_ATTR_H__
950 + * This file contains the interface to the Linux device attributes.
952 +extern struct device_attribute dev_attr_regoffset;
953 +extern struct device_attribute dev_attr_regvalue;
955 +extern struct device_attribute dev_attr_mode;
956 +extern struct device_attribute dev_attr_hnpcapable;
957 +extern struct device_attribute dev_attr_srpcapable;
958 +extern struct device_attribute dev_attr_hnp;
959 +extern struct device_attribute dev_attr_srp;
960 +extern struct device_attribute dev_attr_buspower;
961 +extern struct device_attribute dev_attr_bussuspend;
962 +extern struct device_attribute dev_attr_busconnected;
963 +extern struct device_attribute dev_attr_gotgctl;
964 +extern struct device_attribute dev_attr_gusbcfg;
965 +extern struct device_attribute dev_attr_grxfsiz;
966 +extern struct device_attribute dev_attr_gnptxfsiz;
967 +extern struct device_attribute dev_attr_gpvndctl;
968 +extern struct device_attribute dev_attr_ggpio;
969 +extern struct device_attribute dev_attr_guid;
970 +extern struct device_attribute dev_attr_gsnpsid;
971 +extern struct device_attribute dev_attr_devspeed;
972 +extern struct device_attribute dev_attr_enumspeed;
973 +extern struct device_attribute dev_attr_hptxfsiz;
974 +extern struct device_attribute dev_attr_hprt0;
976 +void dwc_otg_attr_create (struct device *_dev);
977 +void dwc_otg_attr_remove (struct device *_dev);
981 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.c
983 +/* ==========================================================================
984 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil.c $
985 + * $Revision: 1.1.1.1 $
986 + * $Date: 2009-04-17 06:15:34 $
987 + * $Change: 631780 $
989 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
990 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
991 + * otherwise expressly agreed to in writing between Synopsys and you.
993 + * The Software IS NOT an item of Licensed Software or Licensed Product under
994 + * any End User Software License Agreement or Agreement for Licensed Product
995 + * with Synopsys or any supplement thereto. You are permitted to use and
996 + * redistribute this Software in source and binary forms, with or without
997 + * modification, provided that redistributions of source code must retain this
998 + * notice. You may not view, use, disclose, copy or distribute this file or
999 + * any information contained herein except pursuant to this license grant from
1000 + * Synopsys. If you do not agree with this notice, including the disclaimer
1001 + * below, then you are not authorized to use the Software.
1003 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
1004 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1005 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1006 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
1007 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1008 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1009 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1010 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1011 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1012 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1014 + * ========================================================================== */
1018 + * The Core Interface Layer provides basic services for accessing and
1019 + * managing the DWC_otg hardware. These services are used by both the
1020 + * Host Controller Driver and the Peripheral Controller Driver.
1022 + * The CIL manages the memory map for the core so that the HCD and PCD
1023 + * don't have to do this separately. It also handles basic tasks like
1024 + * reading/writing the registers and data FIFOs in the controller.
1025 + * Some of the data access functions provide encapsulation of several
1026 + * operations required to perform a task, such as writing multiple
1027 + * registers to start a transfer. Finally, the CIL performs basic
1028 + * services that are not specific to either the host or device modes
1029 + * of operation. These services include management of the OTG Host
1030 + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
1031 + * Diagnostic API is also provided to allow testing of the controller
1034 + * The Core Interface Layer has the following requirements:
1035 + * - Provides basic controller operations.
1036 + * - Minimal use of OS services.
1037 + * - The OS services used will be abstracted by using inline functions
1041 +#include <asm/unaligned.h>
1044 +#include <linux/jiffies.h>
1047 +#include "dwc_otg_plat.h"
1049 +#include "dwc_otg_regs.h"
1050 +#include "dwc_otg_cil.h"
1053 + * This function is called to initialize the DWC_otg CSR data
1054 + * structures. The register addresses in the device and host
1055 + * structures are initialized from the base address supplied by the
1056 + * caller. The calling function must make the OS calls to get the
1057 + * base address of the DWC_otg controller registers. The core_params
1058 + * argument holds the parameters that specify how the core should be
1061 + * @param[in] _reg_base_addr Base address of DWC_otg core registers
1062 + * @param[in] _core_params Pointer to the core configuration parameters
1065 +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
1066 + dwc_otg_core_params_t *_core_params)
1068 + dwc_otg_core_if_t *core_if = 0;
1069 + dwc_otg_dev_if_t *dev_if = 0;
1070 + dwc_otg_host_if_t *host_if = 0;
1071 + uint8_t *reg_base = (uint8_t *)_reg_base_addr;
1074 + DWC_DEBUGPL(DBG_CILV, "%s(%p,%p)\n", __func__, _reg_base_addr, _core_params);
1076 + core_if = kmalloc( sizeof(dwc_otg_core_if_t), GFP_KERNEL);
1077 + if (core_if == 0) {
1078 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_core_if_t failed\n");
1081 + memset(core_if, 0, sizeof(dwc_otg_core_if_t));
1083 + core_if->core_params = _core_params;
1084 + core_if->core_global_regs = (dwc_otg_core_global_regs_t *)reg_base;
1086 + * Allocate the Device Mode structures.
1088 + dev_if = kmalloc( sizeof(dwc_otg_dev_if_t), GFP_KERNEL);
1089 + if (dev_if == 0) {
1090 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
1095 + dev_if->dev_global_regs =
1096 + (dwc_otg_device_global_regs_t *)(reg_base + DWC_DEV_GLOBAL_REG_OFFSET);
1098 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1099 + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
1100 + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
1101 + (i * DWC_EP_REG_OFFSET));
1103 + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
1104 + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
1105 + (i * DWC_EP_REG_OFFSET));
1106 + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
1107 + i, &dev_if->in_ep_regs[i]->diepctl);
1108 + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
1109 + i, &dev_if->out_ep_regs[i]->doepctl);
1111 + dev_if->speed = 0; // unknown
1112 + //dev_if->num_eps = MAX_EPS_CHANNELS;
1113 + //dev_if->num_perio_eps = 0;
1115 + core_if->dev_if = dev_if;
1117 + * Allocate the Host Mode structures.
1119 + host_if = kmalloc( sizeof(dwc_otg_host_if_t), GFP_KERNEL);
1120 + if (host_if == 0) {
1121 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_host_if_t failed\n");
1127 + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
1128 + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
1129 + host_if->hprt0 = (uint32_t*)(reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
1130 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1131 + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
1132 + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
1133 + (i * DWC_OTG_CHAN_REGS_OFFSET));
1134 + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
1135 + i, &host_if->hc_regs[i]->hcchar);
1137 + host_if->num_host_channels = MAX_EPS_CHANNELS;
1138 + core_if->host_if = host_if;
1140 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1141 + core_if->data_fifo[i] =
1142 + (uint32_t *)(reg_base + DWC_OTG_DATA_FIFO_OFFSET +
1143 + (i * DWC_OTG_DATA_FIFO_SIZE));
1144 + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08x\n",
1145 + i, (unsigned)core_if->data_fifo[i]);
1148 + core_if->pcgcctl = (uint32_t*)(reg_base + DWC_OTG_PCGCCTL_OFFSET);
1151 + * Store the contents of the hardware configuration registers here for
1152 + * easy access later.
1154 + core_if->hwcfg1.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg1);
1155 + core_if->hwcfg2.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg2);
1156 + core_if->hwcfg3.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg3);
1157 + core_if->hwcfg4.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg4);
1159 + DWC_DEBUGPL(DBG_CILV,"hwcfg1=%08x\n",core_if->hwcfg1.d32);
1160 + DWC_DEBUGPL(DBG_CILV,"hwcfg2=%08x\n",core_if->hwcfg2.d32);
1161 + DWC_DEBUGPL(DBG_CILV,"hwcfg3=%08x\n",core_if->hwcfg3.d32);
1162 + DWC_DEBUGPL(DBG_CILV,"hwcfg4=%08x\n",core_if->hwcfg4.d32);
1165 + DWC_DEBUGPL(DBG_CILV,"op_mode=%0x\n",core_if->hwcfg2.b.op_mode);
1166 + DWC_DEBUGPL(DBG_CILV,"arch=%0x\n",core_if->hwcfg2.b.architecture);
1167 + DWC_DEBUGPL(DBG_CILV,"num_dev_ep=%d\n",core_if->hwcfg2.b.num_dev_ep);
1168 + DWC_DEBUGPL(DBG_CILV,"num_host_chan=%d\n",core_if->hwcfg2.b.num_host_chan);
1169 + DWC_DEBUGPL(DBG_CILV,"nonperio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.nonperio_tx_q_depth);
1170 + DWC_DEBUGPL(DBG_CILV,"host_perio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.host_perio_tx_q_depth);
1171 + DWC_DEBUGPL(DBG_CILV,"dev_token_q_depth=0x%0x\n",core_if->hwcfg2.b.dev_token_q_depth);
1173 + DWC_DEBUGPL(DBG_CILV,"Total FIFO SZ=%d\n", core_if->hwcfg3.b.dfifo_depth);
1174 + DWC_DEBUGPL(DBG_CILV,"xfer_size_cntr_width=%0x\n", core_if->hwcfg3.b.xfer_size_cntr_width);
1177 + * Set the SRP sucess bit for FS-I2c
1179 + core_if->srp_success = 0;
1180 + core_if->srp_timer_started = 0;
1185 + * This function frees the structures allocated by dwc_otg_cil_init().
1187 + * @param[in] _core_if The core interface pointer returned from
1188 + * dwc_otg_cil_init().
1191 +void dwc_otg_cil_remove( dwc_otg_core_if_t *_core_if )
1193 + /* Disable all interrupts */
1194 + dwc_modify_reg32( &_core_if->core_global_regs->gahbcfg, 1, 0);
1195 + dwc_write_reg32( &_core_if->core_global_regs->gintmsk, 0);
1197 + if ( _core_if->dev_if ) {
1198 + kfree( _core_if->dev_if );
1200 + if ( _core_if->host_if ) {
1201 + kfree( _core_if->host_if );
1203 + kfree( _core_if );
1207 + * This function enables the controller's Global Interrupt in the AHB Config
1210 + * @param[in] _core_if Programming view of DWC_otg controller.
1212 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if )
1214 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1215 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
1216 + dwc_modify_reg32(&_core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
1219 + * This function disables the controller's Global Interrupt in the AHB Config
1222 + * @param[in] _core_if Programming view of DWC_otg controller.
1224 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if )
1226 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1227 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
1228 + dwc_modify_reg32(&_core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
1232 + * This function initializes the commmon interrupts, used in both
1233 + * device and host modes.
1235 + * @param[in] _core_if Programming view of the DWC_otg controller
1238 +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t *_core_if)
1240 + dwc_otg_core_global_regs_t *global_regs =
1241 + _core_if->core_global_regs;
1242 + gintmsk_data_t intr_mask = { .d32 = 0};
1243 + /* Clear any pending OTG Interrupts */
1244 + dwc_write_reg32( &global_regs->gotgint, 0xFFFFFFFF);
1245 + /* Clear any pending interrupts */
1246 + dwc_write_reg32( &global_regs->gintsts, 0xFFFFFFFF);
1248 + * Enable the interrupts in the GINTMSK.
1250 + intr_mask.b.modemismatch = 1;
1251 + intr_mask.b.otgintr = 1;
1252 + if (!_core_if->dma_enable) {
1253 + intr_mask.b.rxstsqlvl = 1;
1255 + intr_mask.b.conidstschng = 1;
1256 + intr_mask.b.wkupintr = 1;
1257 + intr_mask.b.disconnect = 1;
1258 + intr_mask.b.usbsuspend = 1;
1259 + intr_mask.b.sessreqintr = 1;
1260 + dwc_write_reg32( &global_regs->gintmsk, intr_mask.d32);
1264 + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
1267 +static void init_fslspclksel(dwc_otg_core_if_t *_core_if)
1272 + if (((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1273 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1274 + (_core_if->core_params->ulpi_fs_ls)) ||
1275 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS))
1277 + /* Full speed PHY */
1278 + val = DWC_HCFG_48_MHZ;
1280 + /* High speed PHY running at full speed or high speed */
1281 + val = DWC_HCFG_30_60_MHZ;
1284 + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
1285 + hcfg.d32 = dwc_read_reg32(&_core_if->host_if->host_global_regs->hcfg);
1286 + hcfg.b.fslspclksel = val;
1287 + dwc_write_reg32(&_core_if->host_if->host_global_regs->hcfg, hcfg.d32);
1291 + * Initializes the DevSpd field of the DCFG register depending on the PHY type
1292 + * and the enumeration speed of the device.
1294 +static void init_devspd(dwc_otg_core_if_t *_core_if)
1299 + if (((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1300 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1301 + (_core_if->core_params->ulpi_fs_ls)) ||
1302 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS))
1304 + /* Full speed PHY */
1306 + } else if (_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
1307 + /* High speed PHY running at full speed */
1310 + /* High speed PHY running at high speed */
1314 + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
1315 + dcfg.d32 = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->dcfg);
1316 + dcfg.b.devspd = val;
1317 + dwc_write_reg32(&_core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
1321 + * This function calculates the number of IN EPS
1322 + * using GHWCFG1 and GHWCFG2 registers values
1324 + * @param _pcd the pcd structure.
1326 +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * _core_if)
1328 + uint32_t num_in_eps = 0;
1329 + uint32_t num_eps = _core_if->hwcfg2.b.num_dev_ep;
1330 + uint32_t hwcfg1 = _core_if->hwcfg1.d32 >> 2;
1331 + uint32_t num_tx_fifos = _core_if->hwcfg4.b.num_in_eps;
1333 + for (i = 0; i < num_eps; ++i) {
1334 + if (!(hwcfg1 & 0x1))
1338 + if (_core_if->hwcfg4.b.ded_fifo_en) {
1339 + num_in_eps = (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
1341 + return num_in_eps;
1346 + * This function calculates the number of OUT EPS
1347 + * using GHWCFG1 and GHWCFG2 registers values
1349 + * @param _pcd the pcd structure.
1351 +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * _core_if)
1353 + uint32_t num_out_eps = 0;
1354 + uint32_t num_eps = _core_if->hwcfg2.b.num_dev_ep;
1355 + uint32_t hwcfg1 = _core_if->hwcfg1.d32 >> 2;
1357 + for (i = 0; i < num_eps; ++i) {
1358 + if (!(hwcfg1 & 0x2))
1362 + return num_out_eps;
1365 + * This function initializes the DWC_otg controller registers and
1366 + * prepares the core for device mode or host mode operation.
1368 + * @param _core_if Programming view of the DWC_otg controller
1371 +void dwc_otg_core_init(dwc_otg_core_if_t *_core_if)
1373 + dwc_otg_core_global_regs_t * global_regs = _core_if->core_global_regs;
1374 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1376 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1377 + gusbcfg_data_t usbcfg = { .d32 = 0 };
1378 + gi2cctl_data_t i2cctl = {.d32 = 0};
1380 + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p)\n",_core_if);
1382 + /* Common Initialization */
1384 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1385 + DWC_DEBUGPL(DBG_CIL, "USB config register: 0x%08x\n", usbcfg.d32);
1387 + /* Program the ULPI External VBUS bit if needed */
1388 + //usbcfg.b.ulpi_ext_vbus_drv = 1;
1389 + //usbcfg.b.ulpi_ext_vbus_drv = 0;
1390 + usbcfg.b.ulpi_ext_vbus_drv =
1391 + (_core_if->core_params->phy_ulpi_ext_vbus == DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
1393 + /* Set external TS Dline pulsing */
1394 + usbcfg.b.term_sel_dl_pulse = (_core_if->core_params->ts_dline == 1) ? 1 : 0;
1395 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1397 + /* Reset the Controller */
1398 + dwc_otg_core_reset( _core_if );
1400 + /* Initialize parameters from Hardware configuration registers. */
1402 + dev_if->num_eps = _core_if->hwcfg2.b.num_dev_ep;
1403 + dev_if->num_perio_eps = _core_if->hwcfg4.b.num_dev_perio_in_ep;
1405 + dev_if->num_in_eps = calc_num_in_eps(_core_if);
1406 + dev_if->num_out_eps = calc_num_out_eps(_core_if);
1408 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
1409 + _core_if->hwcfg4.b.num_dev_perio_in_ep);
1410 + DWC_DEBUGPL(DBG_CIL, "Is power optimization enabled? %s\n",
1411 + _core_if->hwcfg4.b.power_optimiz ? "Yes" : "No");
1412 + DWC_DEBUGPL(DBG_CIL, "vbus_valid filter enabled? %s\n",
1413 + _core_if->hwcfg4.b.vbus_valid_filt_en ? "Yes" : "No");
1414 + DWC_DEBUGPL(DBG_CIL, "iddig filter enabled? %s\n",
1415 + _core_if->hwcfg4.b.iddig_filt_en ? "Yes" : "No");
1417 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",_core_if->hwcfg4.b.num_dev_perio_in_ep);
1418 + for (i=0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
1419 + dev_if->perio_tx_fifo_size[i] =
1420 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
1421 + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n", i,
1422 + dev_if->perio_tx_fifo_size[i]);
1424 + for (i = 0; i < _core_if->hwcfg4.b.num_in_eps; i++) {
1425 + dev_if->tx_fifo_size[i] =
1426 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
1427 + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n", i,
1428 + dev_if->perio_tx_fifo_size[i]);
1431 + _core_if->total_fifo_size = _core_if->hwcfg3.b.dfifo_depth;
1432 + _core_if->rx_fifo_size = dwc_read_reg32(&global_regs->grxfsiz);
1433 + _core_if->nperio_tx_fifo_size = dwc_read_reg32(&global_regs->gnptxfsiz) >> 16;
1435 + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", _core_if->total_fifo_size);
1436 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", _core_if->rx_fifo_size);
1437 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n", _core_if->nperio_tx_fifo_size);
1439 + /* This programming sequence needs to happen in FS mode before any other
1440 + * programming occurs */
1441 + if ((_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
1442 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
1443 + /* If FS mode with FS PHY */
1445 + /* core_init() is now called on every switch so only call the
1446 + * following for the first time through. */
1447 + if (!_core_if->phy_init_done) {
1448 + _core_if->phy_init_done = 1;
1449 + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
1450 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1451 + usbcfg.b.physel = 1;
1452 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1454 + /* Reset after a PHY select */
1455 + dwc_otg_core_reset( _core_if );
1458 + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
1459 + * do this on HNP Dev/Host mode switches (done in dev_init and
1461 + if (dwc_otg_is_host_mode(_core_if)) {
1462 + DWC_DEBUGPL(DBG_CIL, "host mode\n");
1463 + init_fslspclksel(_core_if);
1465 + DWC_DEBUGPL(DBG_CIL, "device mode\n");
1466 + init_devspd(_core_if);
1469 + if (_core_if->core_params->i2c_enable) {
1470 + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
1471 + /* Program GUSBCFG.OtgUtmifsSel to I2C */
1472 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1473 + usbcfg.b.otgutmifssel = 1;
1474 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1476 + /* Program GI2CCTL.I2CEn */
1477 + i2cctl.d32 = dwc_read_reg32(&global_regs->gi2cctl);
1478 + i2cctl.b.i2cdevaddr = 1;
1479 + i2cctl.b.i2cen = 0;
1480 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
1481 + i2cctl.b.i2cen = 1;
1482 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
1485 + } /* endif speed == DWC_SPEED_PARAM_FULL */
1487 + /* High speed PHY. */
1488 + if (!_core_if->phy_init_done) {
1489 + _core_if->phy_init_done = 1;
1490 + DWC_DEBUGPL(DBG_CIL, "High spped PHY\n");
1491 + /* HS PHY parameters. These parameters are preserved
1492 + * during soft reset so only program the first time. Do
1493 + * a soft reset immediately after setting phyif. */
1494 + usbcfg.b.ulpi_utmi_sel = _core_if->core_params->phy_type;
1495 + if (usbcfg.b.ulpi_utmi_sel == 2) { // winder
1496 + DWC_DEBUGPL(DBG_CIL, "ULPI\n");
1497 + /* ULPI interface */
1498 + usbcfg.b.phyif = 0;
1499 + usbcfg.b.ddrsel = _core_if->core_params->phy_ulpi_ddr;
1501 + /* UTMI+ interface */
1502 + if (_core_if->core_params->phy_utmi_width == 16) {
1503 + usbcfg.b.phyif = 1;
1504 + DWC_DEBUGPL(DBG_CIL, "UTMI+ 16\n");
1506 + DWC_DEBUGPL(DBG_CIL, "UTMI+ 8\n");
1507 + usbcfg.b.phyif = 0;
1510 + dwc_write_reg32( &global_regs->gusbcfg, usbcfg.d32);
1512 + /* Reset after setting the PHY parameters */
1513 + dwc_otg_core_reset( _core_if );
1517 + if ((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1518 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1519 + (_core_if->core_params->ulpi_fs_ls))
1521 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
1522 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1523 + usbcfg.b.ulpi_fsls = 1;
1524 + usbcfg.b.ulpi_clk_sus_m = 1;
1525 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
1527 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS=0\n");
1528 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1529 + usbcfg.b.ulpi_fsls = 0;
1530 + usbcfg.b.ulpi_clk_sus_m = 0;
1531 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
1534 + /* Program the GAHBCFG Register.*/
1535 + switch (_core_if->hwcfg2.b.architecture){
1537 + case DWC_SLAVE_ONLY_ARCH:
1538 + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
1539 + ahbcfg.b.nptxfemplvl_txfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
1540 + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
1541 + _core_if->dma_enable = 0;
1544 + case DWC_EXT_DMA_ARCH:
1545 + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
1546 + ahbcfg.b.hburstlen = _core_if->core_params->dma_burst_size;
1547 + _core_if->dma_enable = (_core_if->core_params->dma_enable != 0);
1550 + case DWC_INT_DMA_ARCH:
1551 + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
1552 + //ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR;
1553 + ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR4;
1554 + _core_if->dma_enable = (_core_if->core_params->dma_enable != 0);
1557 + ahbcfg.b.dmaenable = _core_if->dma_enable;
1558 + dwc_write_reg32(&global_regs->gahbcfg, ahbcfg.d32);
1559 + _core_if->en_multiple_tx_fifo = _core_if->hwcfg4.b.ded_fifo_en;
1562 + * Program the GUSBCFG register.
1564 + usbcfg.d32 = dwc_read_reg32( &global_regs->gusbcfg );
1566 + switch (_core_if->hwcfg2.b.op_mode) {
1567 + case DWC_MODE_HNP_SRP_CAPABLE:
1568 + usbcfg.b.hnpcap = (_core_if->core_params->otg_cap ==
1569 + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
1570 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1571 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1574 + case DWC_MODE_SRP_ONLY_CAPABLE:
1575 + usbcfg.b.hnpcap = 0;
1576 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1577 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1580 + case DWC_MODE_NO_HNP_SRP_CAPABLE:
1581 + usbcfg.b.hnpcap = 0;
1582 + usbcfg.b.srpcap = 0;
1585 + case DWC_MODE_SRP_CAPABLE_DEVICE:
1586 + usbcfg.b.hnpcap = 0;
1587 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1588 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1591 + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
1592 + usbcfg.b.hnpcap = 0;
1593 + usbcfg.b.srpcap = 0;
1596 + case DWC_MODE_SRP_CAPABLE_HOST:
1597 + usbcfg.b.hnpcap = 0;
1598 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1599 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1602 + case DWC_MODE_NO_SRP_CAPABLE_HOST:
1603 + usbcfg.b.hnpcap = 0;
1604 + usbcfg.b.srpcap = 0;
1608 + dwc_write_reg32( &global_regs->gusbcfg, usbcfg.d32);
1610 + /* Enable common interrupts */
1611 + dwc_otg_enable_common_interrupts( _core_if );
1613 + /* Do device or host intialization based on mode during PCD
1614 + * and HCD initialization */
1615 + if (dwc_otg_is_host_mode( _core_if )) {
1616 + DWC_DEBUGPL(DBG_ANY, "Host Mode\n" );
1617 + _core_if->op_state = A_HOST;
1619 + DWC_DEBUGPL(DBG_ANY, "Device Mode\n" );
1620 + _core_if->op_state = B_PERIPHERAL;
1621 +#ifdef DWC_DEVICE_ONLY
1622 + dwc_otg_core_dev_init( _core_if );
1629 + * This function enables the Device mode interrupts.
1631 + * @param _core_if Programming view of DWC_otg controller
1633 +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if)
1635 + gintmsk_data_t intr_mask = { .d32 = 0};
1636 + dwc_otg_core_global_regs_t * global_regs = _core_if->core_global_regs;
1638 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
1640 + /* Disable all interrupts. */
1641 + dwc_write_reg32( &global_regs->gintmsk, 0);
1643 + /* Clear any pending interrupts */
1644 + dwc_write_reg32( &global_regs->gintsts, 0xFFFFFFFF);
1646 + /* Enable the common interrupts */
1647 + dwc_otg_enable_common_interrupts( _core_if );
1649 + /* Enable interrupts */
1650 + intr_mask.b.usbreset = 1;
1651 + intr_mask.b.enumdone = 1;
1652 + //intr_mask.b.epmismatch = 1;
1653 + intr_mask.b.inepintr = 1;
1654 + intr_mask.b.outepintr = 1;
1655 + intr_mask.b.erlysuspend = 1;
1656 + if (_core_if->en_multiple_tx_fifo == 0) {
1657 + intr_mask.b.epmismatch = 1;
1660 + /** @todo NGS: Should this be a module parameter? */
1661 + intr_mask.b.isooutdrop = 1;
1662 + intr_mask.b.eopframe = 1;
1663 + intr_mask.b.incomplisoin = 1;
1664 + intr_mask.b.incomplisoout = 1;
1666 + dwc_modify_reg32( &global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1668 + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
1669 + dwc_read_reg32( &global_regs->gintmsk));
1673 + * This function initializes the DWC_otg controller registers for
1676 + * @param _core_if Programming view of DWC_otg controller
1679 +void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if)
1681 + dwc_otg_core_global_regs_t *global_regs =
1682 + _core_if->core_global_regs;
1683 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1684 + dwc_otg_core_params_t *params = _core_if->core_params;
1685 + dcfg_data_t dcfg = {.d32 = 0};
1686 + grstctl_t resetctl = { .d32=0 };
1688 + uint32_t rx_fifo_size;
1689 + fifosize_data_t nptxfifosize;
1690 + fifosize_data_t txfifosize;
1691 + dthrctl_data_t dthrctl;
1693 + fifosize_data_t ptxfifosize;
1695 + /* Restart the Phy Clock */
1696 + dwc_write_reg32(_core_if->pcgcctl, 0);
1698 + /* Device configuration register */
1699 + init_devspd(_core_if);
1700 + dcfg.d32 = dwc_read_reg32( &dev_if->dev_global_regs->dcfg);
1701 + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
1702 + dwc_write_reg32( &dev_if->dev_global_regs->dcfg, dcfg.d32 );
1704 + /* Configure data FIFO sizes */
1705 + if ( _core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo ) {
1707 + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n", _core_if->total_fifo_size);
1708 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n", params->dev_rx_fifo_size);
1709 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n", params->dev_nperio_tx_fifo_size);
1712 + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
1713 + dwc_read_reg32(&global_regs->grxfsiz));
1714 + rx_fifo_size = params->dev_rx_fifo_size;
1715 + dwc_write_reg32( &global_regs->grxfsiz, rx_fifo_size );
1716 + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
1717 + dwc_read_reg32(&global_regs->grxfsiz));
1719 + /** Set Periodic Tx FIFO Mask all bits 0 */
1720 + _core_if->p_tx_msk = 0;
1722 + /** Set Tx FIFO Mask all bits 0 */
1723 + _core_if->tx_msk = 0;
1724 + if (_core_if->en_multiple_tx_fifo == 0) {
1725 + /* Non-periodic Tx FIFO */
1726 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
1727 + dwc_read_reg32(&global_regs->gnptxfsiz));
1728 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
1729 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
1730 + dwc_write_reg32( &global_regs->gnptxfsiz, nptxfifosize.d32 );
1731 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
1732 + dwc_read_reg32(&global_regs->gnptxfsiz));
1735 + /**@todo NGS: Fix Periodic FIFO Sizing! */
1737 + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
1738 + * Indexes of the FIFO size module parameters in the
1739 + * dev_perio_tx_fifo_size array and the FIFO size registers in
1740 + * the dptxfsiz array run from 0 to 14.
1742 + /** @todo Finish debug of this */
1743 + ptxfifosize.b.startaddr =
1744 + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
1745 + for (i = 0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep;i++) {
1746 + ptxfifosize.b.depth = params->dev_perio_tx_fifo_size[i];
1747 + DWC_DEBUGPL(DBG_CIL,"initial dptxfsiz_dieptxf[%d]=%08x\n",
1748 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1749 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i],ptxfifosize.d32);
1750 + DWC_DEBUGPL(DBG_CIL,"new dptxfsiz_dieptxf[%d]=%08x\n",
1751 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1752 + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
1757 + * Tx FIFOs These FIFOs are numbered from 1 to 15.
1758 + * Indexes of the FIFO size module parameters in the
1759 + * dev_tx_fifo_size array and the FIFO size registers in
1760 + * the dptxfsiz_dieptxf array run from 0 to 14.
1763 + /* Non-periodic Tx FIFO */
1764 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
1765 + dwc_read_reg32(&global_regs->gnptxfsiz));
1766 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
1767 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
1768 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
1769 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
1770 + dwc_read_reg32(&global_regs->gnptxfsiz));
1771 + txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
1772 + for (i = 1;i < _core_if->hwcfg4.b.num_dev_perio_in_ep;i++) {
1773 + txfifosize.b.depth = params->dev_tx_fifo_size[i];
1774 + DWC_DEBUGPL(DBG_CIL,"initial dptxfsiz_dieptxf[%d]=%08x\n",
1775 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1776 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i - 1],txfifosize.d32);
1777 + DWC_DEBUGPL(DBG_CIL,"new dptxfsiz_dieptxf[%d]=%08x\n",
1778 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i-1]));
1779 + txfifosize.b.startaddr += txfifosize.b.depth;
1783 + /* Flush the FIFOs */
1784 + dwc_otg_flush_tx_fifo(_core_if, 0x10); /* all Tx FIFOs */
1785 + dwc_otg_flush_rx_fifo(_core_if);
1787 + /* Flush the Learning Queue. */
1788 + resetctl.b.intknqflsh = 1;
1789 + dwc_write_reg32( &_core_if->core_global_regs->grstctl, resetctl.d32);
1791 + /* Clear all pending Device Interrupts */
1792 + dwc_write_reg32( &dev_if->dev_global_regs->diepmsk, 0 );
1793 + dwc_write_reg32( &dev_if->dev_global_regs->doepmsk, 0 );
1794 + dwc_write_reg32( &dev_if->dev_global_regs->daint, 0xFFFFFFFF );
1795 + dwc_write_reg32( &dev_if->dev_global_regs->daintmsk, 0 );
1797 + for (i = 0; i <= dev_if->num_in_eps; i++) {
1798 + depctl_data_t depctl;
1799 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
1800 + if (depctl.b.epena) {
1802 + depctl.b.epdis = 1;
1803 + depctl.b.snak = 1;
1807 + dwc_write_reg32( &dev_if->in_ep_regs[i]->diepctl, depctl.d32);
1809 + dwc_write_reg32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
1810 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepdma, 0);
1811 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
1813 + for (i = 0; i <= dev_if->num_out_eps; i++) {
1814 + depctl_data_t depctl;
1815 + depctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doepctl);
1816 + if (depctl.b.epena) {
1818 + depctl.b.epdis = 1;
1819 + depctl.b.snak = 1;
1823 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepctl, depctl.d32);
1825 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->dieptsiz, 0);
1826 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doeptsiz, 0);
1827 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->diepdma, 0);
1828 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepdma, 0);
1829 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->diepint, 0xFF);
1830 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepint, 0xFF);
1833 + if (_core_if->en_multiple_tx_fifo && _core_if->dma_enable) {
1834 + dev_if->non_iso_tx_thr_en = _core_if->core_params->thr_ctl & 0x1;
1835 + dev_if->iso_tx_thr_en = (_core_if->core_params->thr_ctl >> 1) & 0x1;
1836 + dev_if->rx_thr_en = (_core_if->core_params->thr_ctl >> 2) & 0x1;
1837 + dev_if->rx_thr_length = _core_if->core_params->rx_thr_length;
1838 + dev_if->tx_thr_length = _core_if->core_params->tx_thr_length;
1840 + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
1841 + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
1842 + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
1843 + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
1844 + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
1845 + dwc_write_reg32(&dev_if->dev_global_regs->dtknqr3_dthrctl,dthrctl.d32);
1846 + DWC_DEBUGPL(DBG_CIL, "Non ISO Tx Thr - %d\nISO Tx Thr - %d\n"
1847 + "Rx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
1848 + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
1849 + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
1850 + dthrctl.b.rx_thr_len);
1852 + dwc_otg_enable_device_interrupts( _core_if );
1854 + diepmsk_data_t msk = {.d32 = 0};
1855 + msk.b.txfifoundrn = 1;
1856 + dwc_modify_reg32(&dev_if->dev_global_regs->diepmsk, msk.d32,msk.d32);
1861 + * This function enables the Host mode interrupts.
1863 + * @param _core_if Programming view of DWC_otg controller
1865 +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if)
1867 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
1868 + gintmsk_data_t intr_mask = {.d32 = 0};
1870 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
1872 + /* Disable all interrupts. */
1873 + dwc_write_reg32(&global_regs->gintmsk, 0);
1875 + /* Clear any pending interrupts. */
1876 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
1878 + /* Enable the common interrupts */
1879 + dwc_otg_enable_common_interrupts(_core_if);
1882 + * Enable host mode interrupts without disturbing common
1885 + intr_mask.b.sofintr = 1;
1886 + intr_mask.b.portintr = 1;
1887 + intr_mask.b.hcintr = 1;
1889 + //dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1890 + //dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
1891 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1895 + * This function disables the Host Mode interrupts.
1897 + * @param _core_if Programming view of DWC_otg controller
1899 +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if)
1901 + dwc_otg_core_global_regs_t *global_regs =
1902 + _core_if->core_global_regs;
1903 + gintmsk_data_t intr_mask = {.d32 = 0};
1905 + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
1908 + * Disable host mode interrupts without disturbing common
1911 + intr_mask.b.sofintr = 1;
1912 + intr_mask.b.portintr = 1;
1913 + intr_mask.b.hcintr = 1;
1914 + intr_mask.b.ptxfempty = 1;
1915 + intr_mask.b.nptxfempty = 1;
1917 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
1921 +/* currently not used, keep it here as if needed later */
1922 +static int phy_read(dwc_otg_core_if_t * _core_if, int addr)
1927 + dwc_write_reg32(&_core_if->core_global_regs->gpvndctl,
1928 + 0x02000000 | (addr << 16));
1929 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1930 + while (((val & 0x08000000) == 0) && (timeout--)) {
1932 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1934 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1935 + printk("%s: addr=%02x regval=%02x\n", __func__, addr, val & 0x000000ff);
1942 + * This function initializes the DWC_otg controller registers for
1945 + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
1946 + * request queues. Host channels are reset to ensure that they are ready for
1947 + * performing transfers.
1949 + * @param _core_if Programming view of DWC_otg controller
1952 +void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if)
1954 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
1955 + dwc_otg_host_if_t *host_if = _core_if->host_if;
1956 + dwc_otg_core_params_t *params = _core_if->core_params;
1957 + hprt0_data_t hprt0 = {.d32 = 0};
1958 + fifosize_data_t nptxfifosize;
1959 + fifosize_data_t ptxfifosize;
1961 + hcchar_data_t hcchar;
1963 + dwc_otg_hc_regs_t *hc_regs;
1965 + gotgctl_data_t gotgctl = {.d32 = 0};
1967 + DWC_DEBUGPL(DBG_CILV,"%s(%p)\n", __func__, _core_if);
1969 + /* Restart the Phy Clock */
1970 + dwc_write_reg32(_core_if->pcgcctl, 0);
1972 + /* Initialize Host Configuration Register */
1973 + init_fslspclksel(_core_if);
1974 + if (_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
1975 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
1976 + hcfg.b.fslssupp = 1;
1977 + dwc_write_reg32(&host_if->host_global_regs->hcfg, hcfg.d32);
1980 + /* Configure data FIFO sizes */
1981 + if (_core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
1982 + DWC_DEBUGPL(DBG_CIL,"Total FIFO Size=%d\n", _core_if->total_fifo_size);
1983 + DWC_DEBUGPL(DBG_CIL,"Rx FIFO Size=%d\n", params->host_rx_fifo_size);
1984 + DWC_DEBUGPL(DBG_CIL,"NP Tx FIFO Size=%d\n", params->host_nperio_tx_fifo_size);
1985 + DWC_DEBUGPL(DBG_CIL,"P Tx FIFO Size=%d\n", params->host_perio_tx_fifo_size);
1988 + DWC_DEBUGPL(DBG_CIL,"initial grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
1989 + dwc_write_reg32(&global_regs->grxfsiz, params->host_rx_fifo_size);
1990 + DWC_DEBUGPL(DBG_CIL,"new grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
1992 + /* Non-periodic Tx FIFO */
1993 + DWC_DEBUGPL(DBG_CIL,"initial gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
1994 + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
1995 + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
1996 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
1997 + DWC_DEBUGPL(DBG_CIL,"new gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
1999 + /* Periodic Tx FIFO */
2000 + DWC_DEBUGPL(DBG_CIL,"initial hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
2001 + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
2002 + ptxfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
2003 + dwc_write_reg32(&global_regs->hptxfsiz, ptxfifosize.d32);
2004 + DWC_DEBUGPL(DBG_CIL,"new hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
2007 + /* Clear Host Set HNP Enable in the OTG Control Register */
2008 + gotgctl.b.hstsethnpen = 1;
2009 + dwc_modify_reg32( &global_regs->gotgctl, gotgctl.d32, 0);
2011 + /* Make sure the FIFOs are flushed. */
2012 + dwc_otg_flush_tx_fifo(_core_if, 0x10 /* all Tx FIFOs */);
2013 + dwc_otg_flush_rx_fifo(_core_if);
2015 + /* Flush out any leftover queued requests. */
2016 + num_channels = _core_if->core_params->host_channels;
2017 + for (i = 0; i < num_channels; i++) {
2018 + hc_regs = _core_if->host_if->hc_regs[i];
2019 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2020 + hcchar.b.chen = 0;
2021 + hcchar.b.chdis = 1;
2022 + hcchar.b.epdir = 0;
2023 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2026 + /* Halt all channels to put them into a known state. */
2027 + for (i = 0; i < num_channels; i++) {
2029 + hc_regs = _core_if->host_if->hc_regs[i];
2030 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2031 + hcchar.b.chen = 1;
2032 + hcchar.b.chdis = 1;
2033 + hcchar.b.epdir = 0;
2034 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2035 + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d\n", __func__, i);
2037 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2038 + if (++count > 200) {
2039 + DWC_ERROR("%s: Unable to clear halt on channel %d\n",
2044 + } while (hcchar.b.chen);
2047 + /* Turn on the vbus power. */
2048 + DWC_PRINT("Init: Port Power? op_state=%d\n", _core_if->op_state);
2049 + if (_core_if->op_state == A_HOST){
2050 + hprt0.d32 = dwc_otg_read_hprt0(_core_if);
2051 + DWC_PRINT("Init: Power Port (%d)\n", hprt0.b.prtpwr);
2052 + if (hprt0.b.prtpwr == 0 ) {
2053 + hprt0.b.prtpwr = 1;
2054 + dwc_write_reg32(host_if->hprt0, hprt0.d32);
2058 + dwc_otg_enable_host_interrupts( _core_if );
2062 + * Prepares a host channel for transferring packets to/from a specific
2063 + * endpoint. The HCCHARn register is set up with the characteristics specified
2064 + * in _hc. Host channel interrupts that may need to be serviced while this
2065 + * transfer is in progress are enabled.
2067 + * @param _core_if Programming view of DWC_otg controller
2068 + * @param _hc Information needed to initialize the host channel
2070 +void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2072 + uint32_t intr_enable;
2073 + hcintmsk_data_t hc_intr_mask;
2074 + gintmsk_data_t gintmsk = {.d32 = 0};
2075 + hcchar_data_t hcchar;
2076 + hcsplt_data_t hcsplt;
2078 + uint8_t hc_num = _hc->hc_num;
2079 + dwc_otg_host_if_t *host_if = _core_if->host_if;
2080 + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
2082 + /* Clear old interrupt conditions for this host channel. */
2083 + hc_intr_mask.d32 = 0xFFFFFFFF;
2084 + hc_intr_mask.b.reserved = 0;
2085 + dwc_write_reg32(&hc_regs->hcint, hc_intr_mask.d32);
2087 + /* Enable channel interrupts required for this transfer. */
2088 + hc_intr_mask.d32 = 0;
2089 + hc_intr_mask.b.chhltd = 1;
2090 + if (_core_if->dma_enable) {
2091 + hc_intr_mask.b.ahberr = 1;
2092 + if (_hc->error_state && !_hc->do_split &&
2093 + _hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
2094 + hc_intr_mask.b.ack = 1;
2095 + if (_hc->ep_is_in) {
2096 + hc_intr_mask.b.datatglerr = 1;
2097 + if (_hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
2098 + hc_intr_mask.b.nak = 1;
2103 + switch (_hc->ep_type) {
2104 + case DWC_OTG_EP_TYPE_CONTROL:
2105 + case DWC_OTG_EP_TYPE_BULK:
2106 + hc_intr_mask.b.xfercompl = 1;
2107 + hc_intr_mask.b.stall = 1;
2108 + hc_intr_mask.b.xacterr = 1;
2109 + hc_intr_mask.b.datatglerr = 1;
2110 + if (_hc->ep_is_in) {
2111 + hc_intr_mask.b.bblerr = 1;
2113 + hc_intr_mask.b.nak = 1;
2114 + hc_intr_mask.b.nyet = 1;
2115 + if (_hc->do_ping) {
2116 + hc_intr_mask.b.ack = 1;
2120 + if (_hc->do_split) {
2121 + hc_intr_mask.b.nak = 1;
2122 + if (_hc->complete_split) {
2123 + hc_intr_mask.b.nyet = 1;
2126 + hc_intr_mask.b.ack = 1;
2130 + if (_hc->error_state) {
2131 + hc_intr_mask.b.ack = 1;
2134 + case DWC_OTG_EP_TYPE_INTR:
2135 + hc_intr_mask.b.xfercompl = 1;
2136 + hc_intr_mask.b.nak = 1;
2137 + hc_intr_mask.b.stall = 1;
2138 + hc_intr_mask.b.xacterr = 1;
2139 + hc_intr_mask.b.datatglerr = 1;
2140 + hc_intr_mask.b.frmovrun = 1;
2142 + if (_hc->ep_is_in) {
2143 + hc_intr_mask.b.bblerr = 1;
2145 + if (_hc->error_state) {
2146 + hc_intr_mask.b.ack = 1;
2148 + if (_hc->do_split) {
2149 + if (_hc->complete_split) {
2150 + hc_intr_mask.b.nyet = 1;
2153 + hc_intr_mask.b.ack = 1;
2157 + case DWC_OTG_EP_TYPE_ISOC:
2158 + hc_intr_mask.b.xfercompl = 1;
2159 + hc_intr_mask.b.frmovrun = 1;
2160 + hc_intr_mask.b.ack = 1;
2162 + if (_hc->ep_is_in) {
2163 + hc_intr_mask.b.xacterr = 1;
2164 + hc_intr_mask.b.bblerr = 1;
2169 + dwc_write_reg32(&hc_regs->hcintmsk, hc_intr_mask.d32);
2171 + /* Enable the top level host channel interrupt. */
2172 + intr_enable = (1 << hc_num);
2173 + dwc_modify_reg32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
2175 + /* Make sure host channel interrupts are enabled. */
2176 + gintmsk.b.hcintr = 1;
2177 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
2180 + * Program the HCCHARn register with the endpoint characteristics for
2181 + * the current transfer.
2184 + hcchar.b.devaddr = _hc->dev_addr;
2185 + hcchar.b.epnum = _hc->ep_num;
2186 + hcchar.b.epdir = _hc->ep_is_in;
2187 + hcchar.b.lspddev = (_hc->speed == DWC_OTG_EP_SPEED_LOW);
2188 + hcchar.b.eptype = _hc->ep_type;
2189 + hcchar.b.mps = _hc->max_packet;
2191 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
2193 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2194 + DWC_DEBUGPL(DBG_HCDV, " Dev Addr: %d\n", hcchar.b.devaddr);
2195 + DWC_DEBUGPL(DBG_HCDV, " Ep Num: %d\n", hcchar.b.epnum);
2196 + DWC_DEBUGPL(DBG_HCDV, " Is In: %d\n", hcchar.b.epdir);
2197 + DWC_DEBUGPL(DBG_HCDV, " Is Low Speed: %d\n", hcchar.b.lspddev);
2198 + DWC_DEBUGPL(DBG_HCDV, " Ep Type: %d\n", hcchar.b.eptype);
2199 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
2200 + DWC_DEBUGPL(DBG_HCDV, " Multi Cnt: %d\n", hcchar.b.multicnt);
2203 + * Program the HCSPLIT register for SPLITs
2206 + if (_hc->do_split) {
2207 + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n", _hc->hc_num,
2208 + _hc->complete_split ? "CSPLIT" : "SSPLIT");
2209 + hcsplt.b.compsplt = _hc->complete_split;
2210 + hcsplt.b.xactpos = _hc->xact_pos;
2211 + hcsplt.b.hubaddr = _hc->hub_addr;
2212 + hcsplt.b.prtaddr = _hc->port_addr;
2213 + DWC_DEBUGPL(DBG_HCDV, " comp split %d\n", _hc->complete_split);
2214 + DWC_DEBUGPL(DBG_HCDV, " xact pos %d\n", _hc->xact_pos);
2215 + DWC_DEBUGPL(DBG_HCDV, " hub addr %d\n", _hc->hub_addr);
2216 + DWC_DEBUGPL(DBG_HCDV, " port addr %d\n", _hc->port_addr);
2217 + DWC_DEBUGPL(DBG_HCDV, " is_in %d\n", _hc->ep_is_in);
2218 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
2219 + DWC_DEBUGPL(DBG_HCDV, " xferlen: %d\n", _hc->xfer_len);
2221 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
2226 + * Attempts to halt a host channel. This function should only be called in
2227 + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
2228 + * normal circumstances in DMA mode, the controller halts the channel when the
2229 + * transfer is complete or a condition occurs that requires application
2232 + * In slave mode, checks for a free request queue entry, then sets the Channel
2233 + * Enable and Channel Disable bits of the Host Channel Characteristics
2234 + * register of the specified channel to intiate the halt. If there is no free
2235 + * request queue entry, sets only the Channel Disable bit of the HCCHARn
2236 + * register to flush requests for this channel. In the latter case, sets a
2237 + * flag to indicate that the host channel needs to be halted when a request
2238 + * queue slot is open.
2240 + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
2241 + * HCCHARn register. The controller ensures there is space in the request
2242 + * queue before submitting the halt request.
2244 + * Some time may elapse before the core flushes any posted requests for this
2245 + * host channel and halts. The Channel Halted interrupt handler completes the
2246 + * deactivation of the host channel.
2248 + * @param _core_if Controller register interface.
2249 + * @param _hc Host channel to halt.
2250 + * @param _halt_status Reason for halting the channel.
2252 +void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
2254 + dwc_otg_halt_status_e _halt_status)
2256 + gnptxsts_data_t nptxsts;
2257 + hptxsts_data_t hptxsts;
2258 + hcchar_data_t hcchar;
2259 + dwc_otg_hc_regs_t *hc_regs;
2260 + dwc_otg_core_global_regs_t *global_regs;
2261 + dwc_otg_host_global_regs_t *host_global_regs;
2263 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2264 + global_regs = _core_if->core_global_regs;
2265 + host_global_regs = _core_if->host_if->host_global_regs;
2267 + WARN_ON(_halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS);
2269 + if (_halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
2270 + _halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
2272 + * Disable all channel interrupts except Ch Halted. The QTD
2273 + * and QH state associated with this transfer has been cleared
2274 + * (in the case of URB_DEQUEUE), so the channel needs to be
2275 + * shut down carefully to prevent crashes.
2277 + hcintmsk_data_t hcintmsk;
2279 + hcintmsk.b.chhltd = 1;
2280 + dwc_write_reg32(&hc_regs->hcintmsk, hcintmsk.d32);
2283 + * Make sure no other interrupts besides halt are currently
2284 + * pending. Handling another interrupt could cause a crash due
2285 + * to the QTD and QH state.
2287 + dwc_write_reg32(&hc_regs->hcint, ~hcintmsk.d32);
2290 + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
2291 + * even if the channel was already halted for some other
2294 + _hc->halt_status = _halt_status;
2296 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2297 + if (hcchar.b.chen == 0) {
2299 + * The channel is either already halted or it hasn't
2300 + * started yet. In DMA mode, the transfer may halt if
2301 + * it finishes normally or a condition occurs that
2302 + * requires driver intervention. Don't want to halt
2303 + * the channel again. In either Slave or DMA mode,
2304 + * it's possible that the transfer has been assigned
2305 + * to a channel, but not started yet when an URB is
2306 + * dequeued. Don't want to halt a channel that hasn't
2313 + if (_hc->halt_pending) {
2315 + * A halt has already been issued for this channel. This might
2316 + * happen when a transfer is aborted by a higher level in
2320 + DWC_PRINT("*** %s: Channel %d, _hc->halt_pending already set ***\n",
2321 + __func__, _hc->hc_num);
2323 +/* dwc_otg_dump_global_registers(_core_if); */
2324 +/* dwc_otg_dump_host_registers(_core_if); */
2329 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2330 + hcchar.b.chen = 1;
2331 + hcchar.b.chdis = 1;
2333 + if (!_core_if->dma_enable) {
2334 + /* Check for space in the request queue to issue the halt. */
2335 + if (_hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
2336 + _hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
2337 + nptxsts.d32 = dwc_read_reg32(&global_regs->gnptxsts);
2338 + if (nptxsts.b.nptxqspcavail == 0) {
2339 + hcchar.b.chen = 0;
2342 + hptxsts.d32 = dwc_read_reg32(&host_global_regs->hptxsts);
2343 + if ((hptxsts.b.ptxqspcavail == 0) || (_core_if->queuing_high_bandwidth)) {
2344 + hcchar.b.chen = 0;
2349 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2351 + _hc->halt_status = _halt_status;
2353 + if (hcchar.b.chen) {
2354 + _hc->halt_pending = 1;
2355 + _hc->halt_on_queue = 0;
2357 + _hc->halt_on_queue = 1;
2360 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2361 + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
2362 + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", _hc->halt_pending);
2363 + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", _hc->halt_on_queue);
2364 + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", _hc->halt_status);
2370 + * Clears the transfer state for a host channel. This function is normally
2371 + * called after a transfer is done and the host channel is being released.
2373 + * @param _core_if Programming view of DWC_otg controller.
2374 + * @param _hc Identifies the host channel to clean up.
2376 +void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2378 + dwc_otg_hc_regs_t *hc_regs;
2380 + _hc->xfer_started = 0;
2383 + * Clear channel interrupt enables and any unhandled channel interrupt
2386 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2387 + dwc_write_reg32(&hc_regs->hcintmsk, 0);
2388 + dwc_write_reg32(&hc_regs->hcint, 0xFFFFFFFF);
2391 + del_timer(&_core_if->hc_xfer_timer[_hc->hc_num]);
2393 + hcchar_data_t hcchar;
2394 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2395 + if (hcchar.b.chdis) {
2396 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
2397 + __func__, _hc->hc_num, hcchar.d32);
2404 + * Sets the channel property that indicates in which frame a periodic transfer
2405 + * should occur. This is always set to the _next_ frame. This function has no
2406 + * effect on non-periodic transfers.
2408 + * @param _core_if Programming view of DWC_otg controller.
2409 + * @param _hc Identifies the host channel to set up and its properties.
2410 + * @param _hcchar Current value of the HCCHAR register for the specified host
2413 +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t *_core_if,
2415 + hcchar_data_t *_hcchar)
2417 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2418 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2419 + hfnum_data_t hfnum;
2420 + hfnum.d32 = dwc_read_reg32(&_core_if->host_if->host_global_regs->hfnum);
2421 + /* 1 if _next_ frame is odd, 0 if it's even */
2422 + _hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
2424 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR && _hc->do_split && !_hc->complete_split) {
2425 + switch (hfnum.b.frnum & 0x7) {
2427 + _core_if->hfnum_7_samples++;
2428 + _core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
2431 + _core_if->hfnum_0_samples++;
2432 + _core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
2435 + _core_if->hfnum_other_samples++;
2436 + _core_if->hfnum_other_frrem_accum += hfnum.b.frrem;
2445 +static void hc_xfer_timeout(unsigned long _ptr)
2447 + hc_xfer_info_t *xfer_info = (hc_xfer_info_t *)_ptr;
2448 + int hc_num = xfer_info->hc->hc_num;
2449 + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
2450 + DWC_WARN(" start_hcchar_val 0x%08x\n", xfer_info->core_if->start_hcchar_val[hc_num]);
2455 + * This function does the setup for a data transfer for a host channel and
2456 + * starts the transfer. May be called in either Slave mode or DMA mode. In
2457 + * Slave mode, the caller must ensure that there is sufficient space in the
2458 + * request queue and Tx Data FIFO.
2460 + * For an OUT transfer in Slave mode, it loads a data packet into the
2461 + * appropriate FIFO. If necessary, additional data packets will be loaded in
2464 + * For an IN transfer in Slave mode, a data packet is requested. The data
2465 + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
2466 + * additional data packets are requested in the Host ISR.
2468 + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
2469 + * register along with a packet count of 1 and the channel is enabled. This
2470 + * causes a single PING transaction to occur. Other fields in HCTSIZ are
2471 + * simply set to 0 since no data transfer occurs in this case.
2473 + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
2474 + * all the information required to perform the subsequent data transfer. In
2475 + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
2476 + * controller performs the entire PING protocol, then starts the data
2479 + * @param _core_if Programming view of DWC_otg controller.
2480 + * @param _hc Information needed to initialize the host channel. The xfer_len
2481 + * value may be reduced to accommodate the max widths of the XferSize and
2482 + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
2483 + * to reflect the final xfer_len value.
2485 +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2487 + hcchar_data_t hcchar;
2488 + hctsiz_data_t hctsiz;
2489 + uint16_t num_packets;
2490 + uint32_t max_hc_xfer_size = _core_if->core_params->max_transfer_size;
2491 + uint16_t max_hc_pkt_count = _core_if->core_params->max_packet_count;
2492 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2496 + if (_hc->do_ping) {
2497 + if (!_core_if->dma_enable) {
2498 + dwc_otg_hc_do_ping(_core_if, _hc);
2499 + _hc->xfer_started = 1;
2502 + hctsiz.b.dopng = 1;
2506 + if (_hc->do_split) {
2509 + if (_hc->complete_split && !_hc->ep_is_in) {
2510 + /* For CSPLIT OUT Transfer, set the size to 0 so the
2511 + * core doesn't expect any data written to the FIFO */
2512 + _hc->xfer_len = 0;
2513 + } else if (_hc->ep_is_in || (_hc->xfer_len > _hc->max_packet)) {
2514 + _hc->xfer_len = _hc->max_packet;
2515 + } else if (!_hc->ep_is_in && (_hc->xfer_len > 188)) {
2516 + _hc->xfer_len = 188;
2519 + hctsiz.b.xfersize = _hc->xfer_len;
2522 + * Ensure that the transfer length and packet count will fit
2523 + * in the widths allocated for them in the HCTSIZn register.
2525 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2526 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2528 + * Make sure the transfer size is no larger than one
2529 + * (micro)frame's worth of data. (A check was done
2530 + * when the periodic transfer was accepted to ensure
2531 + * that a (micro)frame's worth of data can be
2532 + * programmed into a channel.)
2534 + uint32_t max_periodic_len = _hc->multi_count * _hc->max_packet;
2535 + if (_hc->xfer_len > max_periodic_len) {
2536 + _hc->xfer_len = max_periodic_len;
2539 + } else if (_hc->xfer_len > max_hc_xfer_size) {
2540 + /* Make sure that xfer_len is a multiple of max packet size. */
2541 + _hc->xfer_len = max_hc_xfer_size - _hc->max_packet + 1;
2544 + if (_hc->xfer_len > 0) {
2545 + num_packets = (_hc->xfer_len + _hc->max_packet - 1) / _hc->max_packet;
2546 + if (num_packets > max_hc_pkt_count) {
2547 + num_packets = max_hc_pkt_count;
2548 + _hc->xfer_len = num_packets * _hc->max_packet;
2551 + /* Need 1 packet for transfer length of 0. */
2555 + if (_hc->ep_is_in) {
2556 + /* Always program an integral # of max packets for IN transfers. */
2557 + _hc->xfer_len = num_packets * _hc->max_packet;
2560 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2561 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2563 + * Make sure that the multi_count field matches the
2564 + * actual transfer length.
2566 + _hc->multi_count = num_packets;
2570 + if (_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2571 + /* Set up the initial PID for the transfer. */
2572 + if (_hc->speed == DWC_OTG_EP_SPEED_HIGH) {
2573 + if (_hc->ep_is_in) {
2574 + if (_hc->multi_count == 1) {
2575 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2576 + } else if (_hc->multi_count == 2) {
2577 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
2579 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
2582 + if (_hc->multi_count == 1) {
2583 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2585 + _hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
2589 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2593 + hctsiz.b.xfersize = _hc->xfer_len;
2596 + _hc->start_pkt_count = num_packets;
2597 + hctsiz.b.pktcnt = num_packets;
2598 + hctsiz.b.pid = _hc->data_pid_start;
2599 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2601 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2602 + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
2603 + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
2604 + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
2606 + if (_core_if->dma_enable) {
2608 +if(((uint32_t)_hc->xfer_buff)%4)
2609 +printk("dwc_otg_hc_start_transfer _hc->xfer_buff not 4 byte alignment\n");
2611 + dwc_write_reg32(&hc_regs->hcdma, (uint32_t)_hc->xfer_buff);
2614 + /* Start the split */
2615 + if (_hc->do_split) {
2616 + hcsplt_data_t hcsplt;
2617 + hcsplt.d32 = dwc_read_reg32 (&hc_regs->hcsplt);
2618 + hcsplt.b.spltena = 1;
2619 + dwc_write_reg32(&hc_regs->hcsplt, hcsplt.d32);
2622 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2623 + hcchar.b.multicnt = _hc->multi_count;
2624 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2626 + _core_if->start_hcchar_val[_hc->hc_num] = hcchar.d32;
2627 + if (hcchar.b.chdis) {
2628 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
2629 + __func__, _hc->hc_num, hcchar.d32);
2633 + /* Set host channel enable after all other setup is complete. */
2634 + hcchar.b.chen = 1;
2635 + hcchar.b.chdis = 0;
2636 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2638 + _hc->xfer_started = 1;
2641 + if (!_core_if->dma_enable && !_hc->ep_is_in && _hc->xfer_len > 0) {
2642 + /* Load OUT packet into the appropriate Tx FIFO. */
2643 + dwc_otg_hc_write_packet(_core_if, _hc);
2647 + /* Start a timer for this transfer. */
2648 + _core_if->hc_xfer_timer[_hc->hc_num].function = hc_xfer_timeout;
2649 + _core_if->hc_xfer_info[_hc->hc_num].core_if = _core_if;
2650 + _core_if->hc_xfer_info[_hc->hc_num].hc = _hc;
2651 + _core_if->hc_xfer_timer[_hc->hc_num].data = (unsigned long)(&_core_if->hc_xfer_info[_hc->hc_num]);
2652 + _core_if->hc_xfer_timer[_hc->hc_num].expires = jiffies + (HZ*10);
2653 + add_timer(&_core_if->hc_xfer_timer[_hc->hc_num]);
2658 + * This function continues a data transfer that was started by previous call
2659 + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
2660 + * sufficient space in the request queue and Tx Data FIFO. This function
2661 + * should only be called in Slave mode. In DMA mode, the controller acts
2662 + * autonomously to complete transfers programmed to a host channel.
2664 + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
2665 + * if there is any data remaining to be queued. For an IN transfer, another
2666 + * data packet is always requested. For the SETUP phase of a control transfer,
2667 + * this function does nothing.
2669 + * @return 1 if a new request is queued, 0 if no more requests are required
2670 + * for this transfer.
2672 +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2674 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2676 + if (_hc->do_split) {
2677 + /* SPLITs always queue just once per channel */
2679 + } else if (_hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
2680 + /* SETUPs are queued only once since they can't be NAKed. */
2682 + } else if (_hc->ep_is_in) {
2684 + * Always queue another request for other IN transfers. If
2685 + * back-to-back INs are issued and NAKs are received for both,
2686 + * the driver may still be processing the first NAK when the
2687 + * second NAK is received. When the interrupt handler clears
2688 + * the NAK interrupt for the first NAK, the second NAK will
2689 + * not be seen. So we can't depend on the NAK interrupt
2690 + * handler to requeue a NAKed request. Instead, IN requests
2691 + * are issued each time this function is called. When the
2692 + * transfer completes, the extra requests for the channel will
2695 + hcchar_data_t hcchar;
2696 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2698 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2699 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2700 + hcchar.b.chen = 1;
2701 + hcchar.b.chdis = 0;
2702 + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n", hcchar.d32);
2703 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2707 + /* OUT transfers. */
2708 + if (_hc->xfer_count < _hc->xfer_len) {
2709 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2710 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2711 + hcchar_data_t hcchar;
2712 + dwc_otg_hc_regs_t *hc_regs;
2713 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2714 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2715 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2718 + /* Load OUT packet into the appropriate Tx FIFO. */
2719 + dwc_otg_hc_write_packet(_core_if, _hc);
2729 + * Starts a PING transfer. This function should only be called in Slave mode.
2730 + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
2732 +void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2734 + hcchar_data_t hcchar;
2735 + hctsiz_data_t hctsiz;
2736 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2738 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2741 + hctsiz.b.dopng = 1;
2742 + hctsiz.b.pktcnt = 1;
2743 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2745 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2746 + hcchar.b.chen = 1;
2747 + hcchar.b.chdis = 0;
2748 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2752 + * This function writes a packet into the Tx FIFO associated with the Host
2753 + * Channel. For a channel associated with a non-periodic EP, the non-periodic
2754 + * Tx FIFO is written. For a channel associated with a periodic EP, the
2755 + * periodic Tx FIFO is written. This function should only be called in Slave
2758 + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
2759 + * then number of bytes written to the Tx FIFO.
2761 +void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2764 + uint32_t remaining_count;
2765 + uint32_t byte_count;
2766 + uint32_t dword_count;
2768 + uint32_t *data_buff = (uint32_t *)(_hc->xfer_buff);
2769 + uint32_t *data_fifo = _core_if->data_fifo[_hc->hc_num];
2771 + remaining_count = _hc->xfer_len - _hc->xfer_count;
2772 + if (remaining_count > _hc->max_packet) {
2773 + byte_count = _hc->max_packet;
2775 + byte_count = remaining_count;
2778 + dword_count = (byte_count + 3) / 4;
2780 + if ((((unsigned long)data_buff) & 0x3) == 0) {
2781 + /* xfer_buff is DWORD aligned. */
2782 + for (i = 0; i < dword_count; i++, data_buff++) {
2783 + dwc_write_reg32(data_fifo, *data_buff);
2786 + /* xfer_buff is not DWORD aligned. */
2787 + for (i = 0; i < dword_count; i++, data_buff++) {
2788 + dwc_write_reg32(data_fifo, get_unaligned(data_buff));
2792 + _hc->xfer_count += byte_count;
2793 + _hc->xfer_buff += byte_count;
2797 + * Gets the current USB frame number. This is the frame number from the last
2800 +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if)
2803 + dsts.d32 = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->dsts);
2805 + /* read current frame/microfreme number from DSTS register */
2806 + return dsts.b.soffn;
2810 + * This function reads a setup packet from the Rx FIFO into the destination
2811 + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
2812 + * Interrupt routine when a SETUP packet has been received in Slave mode.
2814 + * @param _core_if Programming view of DWC_otg controller.
2815 + * @param _dest Destination buffer for packet data.
2817 +void dwc_otg_read_setup_packet(dwc_otg_core_if_t *_core_if, uint32_t *_dest)
2819 + /* Get the 8 bytes of a setup transaction data */
2821 + /* Pop 2 DWORDS off the receive data FIFO into memory */
2822 + _dest[0] = dwc_read_reg32(_core_if->data_fifo[0]);
2823 + _dest[1] = dwc_read_reg32(_core_if->data_fifo[0]);
2824 + //_dest[0] = dwc_read_datafifo32(_core_if->data_fifo[0]);
2825 + //_dest[1] = dwc_read_datafifo32(_core_if->data_fifo[0]);
2830 + * This function enables EP0 OUT to receive SETUP packets and configures EP0
2831 + * IN for transmitting packets. It is normally called when the
2832 + * "Enumeration Done" interrupt occurs.
2834 + * @param _core_if Programming view of DWC_otg controller.
2835 + * @param _ep The EP0 data.
2837 +void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2839 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
2841 + depctl_data_t diepctl;
2842 + depctl_data_t doepctl;
2843 + dctl_data_t dctl ={.d32=0};
2845 + /* Read the Device Status and Endpoint 0 Control registers */
2846 + dsts.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dsts);
2847 + diepctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl);
2848 + doepctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl);
2850 + /* Set the MPS of the IN EP based on the enumeration speed */
2851 + switch (dsts.b.enumspd) {
2852 + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
2853 + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
2854 + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
2855 + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
2857 + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
2858 + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
2862 + dwc_write_reg32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
2864 + /* Enable OUT EP for receive */
2865 + doepctl.b.epena = 1;
2866 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
2869 + DWC_DEBUGPL(DBG_PCDV,"doepctl0=%0x\n",
2870 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
2871 + DWC_DEBUGPL(DBG_PCDV,"diepctl0=%0x\n",
2872 + dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl));
2874 + dctl.b.cgnpinnak = 1;
2875 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
2876 + DWC_DEBUGPL(DBG_PCDV,"dctl=%0x\n",
2877 + dwc_read_reg32(&dev_if->dev_global_regs->dctl));
2881 + * This function activates an EP. The Device EP control register for
2882 + * the EP is configured as defined in the ep structure. Note: This
2883 + * function is not used for EP0.
2885 + * @param _core_if Programming view of DWC_otg controller.
2886 + * @param _ep The EP to activate.
2888 +void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2890 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
2891 + depctl_data_t depctl;
2892 + volatile uint32_t *addr;
2893 + daint_data_t daintmsk = {.d32=0};
2895 + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, _ep->num,
2896 + (_ep->is_in?"IN":"OUT"));
2898 + /* Read DEPCTLn register */
2899 + if (_ep->is_in == 1) {
2900 + addr = &dev_if->in_ep_regs[_ep->num]->diepctl;
2901 + daintmsk.ep.in = 1<<_ep->num;
2903 + addr = &dev_if->out_ep_regs[_ep->num]->doepctl;
2904 + daintmsk.ep.out = 1<<_ep->num;
2907 + /* If the EP is already active don't change the EP Control
2909 + depctl.d32 = dwc_read_reg32(addr);
2910 + if (!depctl.b.usbactep) {
2911 + depctl.b.mps = _ep->maxpacket;
2912 + depctl.b.eptype = _ep->type;
2913 + depctl.b.txfnum = _ep->tx_fifo_num;
2915 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
2916 + depctl.b.setd0pid = 1; // ???
2918 + depctl.b.setd0pid = 1;
2920 + depctl.b.usbactep = 1;
2922 + dwc_write_reg32(addr, depctl.d32);
2923 + DWC_DEBUGPL(DBG_PCDV,"DEPCTL=%08x\n", dwc_read_reg32(addr));
2927 + /* Enable the Interrupt for this EP */
2928 + dwc_modify_reg32(&dev_if->dev_global_regs->daintmsk,
2930 + DWC_DEBUGPL(DBG_PCDV,"DAINTMSK=%0x\n",
2931 + dwc_read_reg32(&dev_if->dev_global_regs->daintmsk));
2932 + _ep->stall_clear_flag = 0;
2937 + * This function deactivates an EP. This is done by clearing the USB Active
2938 + * EP bit in the Device EP control register. Note: This function is not used
2939 + * for EP0. EP0 cannot be deactivated.
2941 + * @param _core_if Programming view of DWC_otg controller.
2942 + * @param _ep The EP to deactivate.
2944 +void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2946 + depctl_data_t depctl ={.d32 = 0};
2947 + volatile uint32_t *addr;
2948 + daint_data_t daintmsk = {.d32=0};
2950 + /* Read DEPCTLn register */
2951 + if (_ep->is_in == 1) {
2952 + addr = &_core_if->dev_if->in_ep_regs[_ep->num]->diepctl;
2953 + daintmsk.ep.in = 1<<_ep->num;
2955 + addr = &_core_if->dev_if->out_ep_regs[_ep->num]->doepctl;
2956 + daintmsk.ep.out = 1<<_ep->num;
2959 + depctl.b.usbactep = 0;
2960 + dwc_write_reg32(addr, depctl.d32);
2962 + /* Disable the Interrupt for this EP */
2963 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->daintmsk,
2970 + * This function does the setup for a data transfer for an EP and
2971 + * starts the transfer. For an IN transfer, the packets will be
2972 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
2973 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
2975 + * @param _core_if Programming view of DWC_otg controller.
2976 + * @param _ep The EP to start the transfer on.
2978 +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2980 + /** @todo Refactor this funciton to check the transfer size
2981 + * count value does not execed the number bits in the Transfer
2982 + * count register. */
2983 + depctl_data_t depctl;
2984 + deptsiz_data_t deptsiz;
2985 + gintmsk_data_t intr_mask = { .d32 = 0};
2987 +#ifdef CHECK_PACKET_COUNTER_WIDTH
2988 + const uint32_t MAX_XFER_SIZE =
2989 + _core_if->core_params->max_transfer_size;
2990 + const uint32_t MAX_PKT_COUNT =
2991 + _core_if->core_params->max_packet_count;
2992 + uint32_t num_packets;
2993 + uint32_t transfer_len;
2994 + dwc_otg_dev_out_ep_regs_t *out_regs =
2995 + _core_if->dev_if->out_ep_regs[_ep->num];
2996 + dwc_otg_dev_in_ep_regs_t *in_regs =
2997 + _core_if->dev_if->in_ep_regs[_ep->num];
2998 + gnptxsts_data_t txstatus;
3000 + int lvl = SET_DEBUG_LEVEL(DBG_PCD);
3003 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3004 + "xfer_buff=%p start_xfer_buff=%p\n",
3005 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3006 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff);
3008 + transfer_len = _ep->xfer_len - _ep->xfer_count;
3009 + if (transfer_len > MAX_XFER_SIZE) {
3010 + transfer_len = MAX_XFER_SIZE;
3012 + if (transfer_len == 0) {
3014 + /* OUT EP to recieve Zero-length packet set transfer
3015 + * size to maxpacket size. */
3016 + if (!_ep->is_in) {
3017 + transfer_len = _ep->maxpacket;
3021 + (transfer_len + _ep->maxpacket - 1) / _ep->maxpacket;
3022 + if (num_packets > MAX_PKT_COUNT) {
3023 + num_packets = MAX_PKT_COUNT;
3026 + DWC_DEBUGPL(DBG_PCD, "transfer_len=%d #pckt=%d\n", transfer_len,
3029 + deptsiz.b.xfersize = transfer_len;
3030 + deptsiz.b.pktcnt = num_packets;
3033 + if (_ep->is_in == 1) {
3034 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3035 + } else {/* OUT endpoint */
3036 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
3039 + /* EP enable, IN data in FIFO */
3040 + depctl.b.cnak = 1;
3041 + depctl.b.epena = 1;
3043 + if (_ep->is_in == 1) {
3045 + dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3046 + if (txstatus.b.nptxqspcavail == 0) {
3047 + DWC_DEBUGPL(DBG_ANY, "TX Queue Full (0x%0x)\n",
3051 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3052 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3054 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3055 + * data will be written into the fifo by the ISR.
3057 + if (_core_if->dma_enable) {
3058 + dwc_write_reg32(&in_regs->diepdma, (uint32_t) _ep->xfer_buff);
3060 + if (_core_if->en_multiple_tx_fifo == 0) {
3061 + intr_mask.b.nptxfempty = 1;
3062 + dwc_modify_reg32( &_core_if->core_global_regs->gintsts,
3063 + intr_mask.d32, 0);
3064 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3065 + intr_mask.d32, intr_mask.d32);
3067 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3068 + if (_ep->xfer_len > 0 &&
3069 + _ep->type != DWC_OTG_EP_TYPE_ISOC) {
3070 + uint32_t fifoemptymsk = 0;
3071 + fifoemptymsk = (0x1 << _ep->num);
3072 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->
3073 + dtknqr4_fifoemptymsk,0, fifoemptymsk);
3077 + } else { /* OUT endpoint */
3078 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3079 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
3080 + if (_core_if->dma_enable) {
3081 + dwc_write_reg32(&out_regs->doepdma,(uint32_t) _ep->xfer_buff);
3084 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
3085 + dwc_read_reg32(&out_regs->doepctl),
3086 + dwc_read_reg32(&out_regs->doeptsiz));
3087 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
3088 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk),
3089 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
3091 + SET_DEBUG_LEVEL(lvl);
3093 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
3095 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3096 + "xfer_buff=%p start_xfer_buff=%p\n",
3097 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3098 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff);
3101 + if (_ep->is_in == 1) {
3102 + dwc_otg_dev_in_ep_regs_t * in_regs = _core_if->dev_if->in_ep_regs[_ep->num];
3103 + gnptxsts_data_t gtxstatus;
3104 + gtxstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3105 + if (_core_if->en_multiple_tx_fifo == 0 &&
3106 + gtxstatus.b.nptxqspcavail == 0) {
3108 + DWC_PRINT("TX Queue Full (0x%0x)\n", gtxstatus.d32);
3111 + MDELAY(100); //james
3114 + depctl.d32 = dwc_read_reg32(&(in_regs->diepctl));
3115 + deptsiz.d32 = dwc_read_reg32(&(in_regs->dieptsiz));
3117 + /* Zero Length Packet? */
3118 + if (_ep->xfer_len == 0) {
3119 + deptsiz.b.xfersize = 0;
3120 + deptsiz.b.pktcnt = 1;
3123 + /* Program the transfer size and packet count
3124 + * as follows: xfersize = N * maxpacket +
3125 + * short_packet pktcnt = N + (short_packet
3128 + deptsiz.b.xfersize = _ep->xfer_len;
3129 + deptsiz.b.pktcnt = (_ep->xfer_len - 1 + _ep->maxpacket) / _ep->maxpacket;
3132 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3134 + /* Write the DMA register */
3135 + if (_core_if->dma_enable) {
3137 + dma_cache_wback_inv((unsigned long) _ep->xfer_buff, _ep->xfer_len); // winder
3138 + dwc_write_reg32 (&(in_regs->diepdma),
3139 + CPHYSADDR((uint32_t)_ep->xfer_buff)); // winder
3141 + dwc_write_reg32 (&(in_regs->diepdma),
3142 + (uint32_t)_ep->dma_addr);
3145 + if (_ep->type != DWC_OTG_EP_TYPE_ISOC) {
3147 + * Enable the Non-Periodic Tx FIFO empty interrupt,
3148 + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
3149 + * the data will be written into the fifo by the ISR.
3151 + if (_core_if->en_multiple_tx_fifo == 0) {
3152 + intr_mask.b.nptxfempty = 1;
3153 + dwc_modify_reg32( &_core_if->core_global_regs->gintsts,
3154 + intr_mask.d32, 0);
3155 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3156 + intr_mask.d32, intr_mask.d32);
3158 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3159 + if (_ep->xfer_len > 0) {
3160 + uint32_t fifoemptymsk = 0;
3161 + fifoemptymsk = 1 << _ep->num;
3162 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->
3163 + dtknqr4_fifoemptymsk,0,fifoemptymsk);
3169 + /* EP enable, IN data in FIFO */
3170 + depctl.b.cnak = 1;
3171 + depctl.b.epena = 1;
3172 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3174 + if (_core_if->dma_enable) {
3175 + depctl.d32 = dwc_read_reg32 (&_core_if->dev_if->in_ep_regs[0]->diepctl);
3176 + depctl.b.nextep = _ep->num;
3177 + dwc_write_reg32 (&_core_if->dev_if->in_ep_regs[0]->diepctl, depctl.d32);
3181 + /* OUT endpoint */
3182 + dwc_otg_dev_out_ep_regs_t * out_regs = _core_if->dev_if->out_ep_regs[_ep->num];
3184 + depctl.d32 = dwc_read_reg32(&(out_regs->doepctl));
3185 + deptsiz.d32 = dwc_read_reg32(&(out_regs->doeptsiz));
3187 + /* Program the transfer size and packet count as follows:
3190 + * xfersize = N * maxpacket
3192 + if (_ep->xfer_len == 0) {
3193 + /* Zero Length Packet */
3194 + deptsiz.b.xfersize = _ep->maxpacket;
3195 + deptsiz.b.pktcnt = 1;
3197 + deptsiz.b.pktcnt = (_ep->xfer_len + (_ep->maxpacket - 1)) / _ep->maxpacket;
3198 + deptsiz.b.xfersize = deptsiz.b.pktcnt * _ep->maxpacket;
3200 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3202 + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
3203 + _ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
3205 + if (_core_if->dma_enable) {
3207 + dwc_write_reg32 (&(out_regs->doepdma),
3208 + CPHYSADDR((uint32_t)_ep->xfer_buff)); // winder
3210 + dwc_write_reg32 (&(out_regs->doepdma),
3211 + (uint32_t)_ep->dma_addr);
3215 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
3216 + /** @todo NGS: dpid is read-only. Use setd0pid
3218 + if (_ep->even_odd_frame) {
3219 + depctl.b.setd1pid = 1;
3221 + depctl.b.setd0pid = 1;
3226 + depctl.b.cnak = 1;
3227 + depctl.b.epena = 1;
3229 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
3231 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
3232 + dwc_read_reg32(&out_regs->doepctl),
3233 + dwc_read_reg32(&out_regs->doeptsiz));
3234 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
3235 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk),
3236 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
3242 + * This function does the setup for a data transfer for EP0 and starts
3243 + * the transfer. For an IN transfer, the packets will be loaded into
3244 + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
3245 + * unloaded from the Rx FIFO in the ISR.
3247 + * @param _core_if Programming view of DWC_otg controller.
3248 + * @param _ep The EP0 data.
3250 +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3252 + volatile depctl_data_t depctl;
3253 + volatile deptsiz0_data_t deptsiz;
3254 + gintmsk_data_t intr_mask = { .d32 = 0};
3256 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3257 + "xfer_buff=%p start_xfer_buff=%p total_len=%d\n",
3258 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3259 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff,
3261 + _ep->total_len = _ep->xfer_len;
3264 + if (_ep->is_in == 1) {
3265 + dwc_otg_dev_in_ep_regs_t * in_regs = _core_if->dev_if->in_ep_regs[0];
3266 + gnptxsts_data_t gtxstatus;
3267 + gtxstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3268 + if (_core_if->en_multiple_tx_fifo == 0 &&
3269 + gtxstatus.b.nptxqspcavail == 0) {
3271 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3272 + DWC_DEBUGPL(DBG_PCD,"DIEPCTL0=%0x\n",
3273 + dwc_read_reg32(&in_regs->diepctl));
3274 + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
3275 + deptsiz.d32, deptsiz.b.xfersize,deptsiz.b.pktcnt);
3276 + DWC_PRINT("TX Queue or FIFO Full (0x%0x)\n", gtxstatus.d32);
3278 + printk("TX Queue or FIFO Full!!!!\n"); // test-only
3280 + MDELAY(100); //james
3283 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3284 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3286 + /* Zero Length Packet? */
3287 + if (_ep->xfer_len == 0) {
3288 + deptsiz.b.xfersize = 0;
3289 + deptsiz.b.pktcnt = 1;
3291 + /* Program the transfer size and packet count
3292 + * as follows: xfersize = N * maxpacket +
3293 + * short_packet pktcnt = N + (short_packet
3296 + if (_ep->xfer_len > _ep->maxpacket) {
3297 + _ep->xfer_len = _ep->maxpacket;
3298 + deptsiz.b.xfersize = _ep->maxpacket;
3301 + deptsiz.b.xfersize = _ep->xfer_len;
3303 + deptsiz.b.pktcnt = 1;
3306 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3307 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
3308 + _ep->xfer_len, deptsiz.b.xfersize,deptsiz.b.pktcnt, deptsiz.d32);
3310 + /* Write the DMA register */
3311 + if (_core_if->dma_enable) {
3312 + dwc_write_reg32(&(in_regs->diepdma), (uint32_t) _ep->dma_addr);
3315 + /* EP enable, IN data in FIFO */
3316 + depctl.b.cnak = 1;
3317 + depctl.b.epena = 1;
3318 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3321 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3322 + * data will be written into the fifo by the ISR.
3324 + if (!_core_if->dma_enable) {
3325 + if (_core_if->en_multiple_tx_fifo == 0) {
3326 + intr_mask.b.nptxfempty = 1;
3327 + dwc_modify_reg32(&_core_if->core_global_regs->gintsts, intr_mask.d32, 0);
3328 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, intr_mask.d32,
3331 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3332 + if (_ep->xfer_len > 0) {
3333 + uint32_t fifoemptymsk = 0;
3334 + fifoemptymsk |= 1 << _ep->num;
3335 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
3342 + /* OUT endpoint */
3343 + dwc_otg_dev_out_ep_regs_t * out_regs = _core_if->dev_if->out_ep_regs[_ep->num];
3345 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
3346 + deptsiz.d32 = dwc_read_reg32(&out_regs->doeptsiz);
3348 + /* Program the transfer size and packet count as follows:
3349 + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
3351 + if (_ep->xfer_len == 0) {
3352 + /* Zero Length Packet */
3353 + deptsiz.b.xfersize = _ep->maxpacket;
3354 + deptsiz.b.pktcnt = 1;
3356 + deptsiz.b.pktcnt = (_ep->xfer_len + (_ep->maxpacket - 1)) / _ep->maxpacket;
3357 + deptsiz.b.xfersize = deptsiz.b.pktcnt * _ep->maxpacket;
3360 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3361 + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
3362 + _ep->xfer_len, deptsiz.b.xfersize,deptsiz.b.pktcnt);
3364 + if (_core_if->dma_enable) {
3365 + dwc_write_reg32(&(out_regs->doepdma), (uint32_t) _ep->dma_addr);
3369 + depctl.b.cnak = 1;
3370 + depctl.b.epena = 1;
3371 + dwc_write_reg32 (&(out_regs->doepctl), depctl.d32);
3376 + * This function continues control IN transfers started by
3377 + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
3378 + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
3379 + * bit for the packet count.
3381 + * @param _core_if Programming view of DWC_otg controller.
3382 + * @param _ep The EP0 data.
3384 +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3386 + depctl_data_t depctl;
3387 + deptsiz0_data_t deptsiz;
3388 + gintmsk_data_t intr_mask = { .d32 = 0};
3390 + if (_ep->is_in == 1) {
3391 + dwc_otg_dev_in_ep_regs_t *in_regs =
3392 + _core_if->dev_if->in_ep_regs[0];
3393 + gnptxsts_data_t tx_status = {.d32 = 0};
3395 + tx_status.d32 = dwc_read_reg32( &_core_if->core_global_regs->gnptxsts );
3396 + /** @todo Should there be check for room in the Tx
3397 + * Status Queue. If not remove the code above this comment. */
3399 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3400 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3402 + /* Program the transfer size and packet count
3403 + * as follows: xfersize = N * maxpacket +
3404 + * short_packet pktcnt = N + (short_packet
3407 + deptsiz.b.xfersize = (_ep->total_len - _ep->xfer_count) > _ep->maxpacket ? _ep->maxpacket :
3408 + (_ep->total_len - _ep->xfer_count);
3409 + deptsiz.b.pktcnt = 1;
3410 + _ep->xfer_len += deptsiz.b.xfersize;
3412 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3413 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
3415 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
3417 + /* Write the DMA register */
3418 + if (_core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
3419 + dwc_write_reg32 (&(in_regs->diepdma),
3420 + CPHYSADDR((uint32_t)_ep->dma_addr)); // winder
3423 + /* EP enable, IN data in FIFO */
3424 + depctl.b.cnak = 1;
3425 + depctl.b.epena = 1;
3426 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3429 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3430 + * data will be written into the fifo by the ISR.
3432 + if (!_core_if->dma_enable) {
3433 + /* First clear it from GINTSTS */
3434 + intr_mask.b.nptxfempty = 1;
3435 + dwc_write_reg32( &_core_if->core_global_regs->gintsts,
3438 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3439 + intr_mask.d32, intr_mask.d32);
3447 +void dump_msg(const u8 *buf, unsigned int length)
3449 + unsigned int start, num, i;
3450 + char line[52], *p;
3452 + if (length >= 512)
3455 + while (length > 0) {
3456 + num = min(length, 16u);
3458 + for (i = 0; i < num; ++i) {
3461 + sprintf(p, " %02x", buf[i]);
3465 + DWC_PRINT( "%6x: %s\n", start, line);
3472 +static inline void dump_msg(const u8 *buf, unsigned int length)
3478 + * This function writes a packet into the Tx FIFO associated with the
3479 + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
3480 + * periodic EPs the periodic Tx FIFO associated with the EP is written
3481 + * with all packets for the next micro-frame.
3483 + * @param _core_if Programming view of DWC_otg controller.
3484 + * @param _ep The EP to write packet for.
3485 + * @param _dma Indicates if DMA is being used.
3487 +void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma)
3490 + * The buffer is padded to DWORD on a per packet basis in
3491 + * slave/dma mode if the MPS is not DWORD aligned. The last
3492 + * packet, if short, is also padded to a multiple of DWORD.
3494 + * ep->xfer_buff always starts DWORD aligned in memory and is a
3495 + * multiple of DWORD in length
3497 + * ep->xfer_len can be any number of bytes
3499 + * ep->xfer_count is a multiple of ep->maxpacket until the last
3502 + * FIFO access is DWORD */
3505 + uint32_t byte_count;
3506 + uint32_t dword_count;
3508 + uint32_t *data_buff = (uint32_t *)_ep->xfer_buff;
3510 + //DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, _core_if, _ep);
3511 + if (_ep->xfer_count >= _ep->xfer_len) {
3512 + DWC_WARN("%s() No data for EP%d!!!\n", __func__, _ep->num);
3516 + /* Find the byte length of the packet either short packet or MPS */
3517 + if ((_ep->xfer_len - _ep->xfer_count) < _ep->maxpacket) {
3518 + byte_count = _ep->xfer_len - _ep->xfer_count;
3521 + byte_count = _ep->maxpacket;
3524 + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
3525 + * is not a multiple of DWORD */
3526 + dword_count = (byte_count + 3) / 4;
3529 + dump_msg(_ep->xfer_buff, byte_count);
3531 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
3532 + /**@todo NGS Where are the Periodic Tx FIFO addresses
3533 + * intialized? What should this be? */
3534 + fifo = _core_if->data_fifo[_ep->tx_fifo_num];
3536 + fifo = _core_if->data_fifo[_ep->num];
3539 + DWC_DEBUGPL((DBG_PCDV|DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
3540 + fifo, data_buff, *data_buff, byte_count);
3544 + for (i=0; i<dword_count; i++, data_buff++) {
3545 + dwc_write_reg32( fifo, *data_buff );
3549 + _ep->xfer_count += byte_count;
3550 + _ep->xfer_buff += byte_count;
3551 +#if 1 // winder, why do we need this??
3552 + _ep->dma_addr += byte_count;
3557 + * Set the EP STALL.
3559 + * @param _core_if Programming view of DWC_otg controller.
3560 + * @param _ep The EP to set the stall on.
3562 +void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3564 + depctl_data_t depctl;
3565 + volatile uint32_t *depctl_addr;
3567 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _ep->num,
3568 + (_ep->is_in?"IN":"OUT"));
3570 + if (_ep->is_in == 1) {
3571 + depctl_addr = &(_core_if->dev_if->in_ep_regs[_ep->num]->diepctl);
3572 + depctl.d32 = dwc_read_reg32(depctl_addr);
3574 + /* set the disable and stall bits */
3575 + if (depctl.b.epena) {
3576 + depctl.b.epdis = 1;
3578 + depctl.b.stall = 1;
3579 + dwc_write_reg32(depctl_addr, depctl.d32);
3582 + depctl_addr = &(_core_if->dev_if->out_ep_regs[_ep->num]->doepctl);
3583 + depctl.d32 = dwc_read_reg32(depctl_addr);
3585 + /* set the stall bit */
3586 + depctl.b.stall = 1;
3587 + dwc_write_reg32(depctl_addr, depctl.d32);
3589 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
3594 + * Clear the EP STALL.
3596 + * @param _core_if Programming view of DWC_otg controller.
3597 + * @param _ep The EP to clear stall from.
3599 +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3601 + depctl_data_t depctl;
3602 + volatile uint32_t *depctl_addr;
3604 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _ep->num,
3605 + (_ep->is_in?"IN":"OUT"));
3607 + if (_ep->is_in == 1) {
3608 + depctl_addr = &(_core_if->dev_if->in_ep_regs[_ep->num]->diepctl);
3610 + depctl_addr = &(_core_if->dev_if->out_ep_regs[_ep->num]->doepctl);
3613 + depctl.d32 = dwc_read_reg32(depctl_addr);
3615 + /* clear the stall bits */
3616 + depctl.b.stall = 0;
3619 + * USB Spec 9.4.5: For endpoints using data toggle, regardless
3620 + * of whether an endpoint has the Halt feature set, a
3621 + * ClearFeature(ENDPOINT_HALT) request always results in the
3622 + * data toggle being reinitialized to DATA0.
3624 + if (_ep->type == DWC_OTG_EP_TYPE_INTR ||
3625 + _ep->type == DWC_OTG_EP_TYPE_BULK) {
3626 + depctl.b.setd0pid = 1; /* DATA0 */
3629 + dwc_write_reg32(depctl_addr, depctl.d32);
3630 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
3635 + * This function reads a packet from the Rx FIFO into the destination
3636 + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
3638 + * @param _core_if Programming view of DWC_otg controller.
3639 + * @param _dest Destination buffer for the packet.
3640 + * @param _bytes Number of bytes to copy to the destination.
3642 +void dwc_otg_read_packet(dwc_otg_core_if_t *_core_if,
3647 + int word_count = (_bytes + 3) / 4;
3649 + volatile uint32_t *fifo = _core_if->data_fifo[0];
3650 + uint32_t *data_buff = (uint32_t *)_dest;
3653 + * @todo Account for the case where _dest is not dword aligned. This
3654 + * requires reading data from the FIFO into a uint32_t temp buffer,
3655 + * then moving it into the data buffer.
3658 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
3659 + _core_if, _dest, _bytes);
3661 + for (i=0; i<word_count; i++, data_buff++) {
3662 + *data_buff = dwc_read_reg32(fifo);
3671 + * This functions reads the device registers and prints them
3673 + * @param _core_if Programming view of DWC_otg controller.
3675 +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if)
3678 + volatile uint32_t *addr;
3680 + DWC_PRINT("Device Global Registers\n");
3681 + addr=&_core_if->dev_if->dev_global_regs->dcfg;
3682 + DWC_PRINT("DCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3683 + addr=&_core_if->dev_if->dev_global_regs->dctl;
3684 + DWC_PRINT("DCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3685 + addr=&_core_if->dev_if->dev_global_regs->dsts;
3686 + DWC_PRINT("DSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3687 + addr=&_core_if->dev_if->dev_global_regs->diepmsk;
3688 + DWC_PRINT("DIEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3689 + addr=&_core_if->dev_if->dev_global_regs->doepmsk;
3690 + DWC_PRINT("DOEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3691 + addr=&_core_if->dev_if->dev_global_regs->daint;
3692 + DWC_PRINT("DAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3693 + addr=&_core_if->dev_if->dev_global_regs->dtknqr1;
3694 + DWC_PRINT("DTKNQR1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3695 + if (_core_if->hwcfg2.b.dev_token_q_depth > 6) {
3696 + addr=&_core_if->dev_if->dev_global_regs->dtknqr2;
3697 + DWC_PRINT("DTKNQR2 @0x%08X : 0x%08X\n",
3698 + (uint32_t)addr,dwc_read_reg32(addr));
3701 + addr=&_core_if->dev_if->dev_global_regs->dvbusdis;
3702 + DWC_PRINT("DVBUSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3704 + addr=&_core_if->dev_if->dev_global_regs->dvbuspulse;
3705 + DWC_PRINT("DVBUSPULSE @0x%08X : 0x%08X\n",
3706 + (uint32_t)addr,dwc_read_reg32(addr));
3708 + if (_core_if->hwcfg2.b.dev_token_q_depth > 14) {
3709 + addr = &_core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
3710 + DWC_PRINT("DTKNQR3 @0x%08X : 0x%08X\n",
3711 + (uint32_t)addr, dwc_read_reg32(addr));
3714 + if (_core_if->hwcfg2.b.dev_token_q_depth > 22) {
3715 + addr = &_core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
3716 + DWC_PRINT("DTKNQR4 @0x%08X : 0x%08X\n", (uint32_t) addr,
3717 + dwc_read_reg32(addr));
3719 + for (i = 0; i <= _core_if->dev_if->num_in_eps; i++) {
3720 + DWC_PRINT("Device IN EP %d Registers\n", i);
3721 + addr=&_core_if->dev_if->in_ep_regs[i]->diepctl;
3722 + DWC_PRINT("DIEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3723 + addr=&_core_if->dev_if->in_ep_regs[i]->diepint;
3724 + DWC_PRINT("DIEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3725 + addr=&_core_if->dev_if->in_ep_regs[i]->dieptsiz;
3726 + DWC_PRINT("DIETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3727 + addr=&_core_if->dev_if->in_ep_regs[i]->diepdma;
3728 + DWC_PRINT("DIEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3730 +addr = &_core_if->dev_if->in_ep_regs[i]->dtxfsts;
3731 + DWC_PRINT("DTXFSTS @0x%08X : 0x%08X\n", (uint32_t) addr,
3732 + dwc_read_reg32(addr));
3734 + for (i = 0; i <= _core_if->dev_if->num_out_eps; i++) {
3735 + DWC_PRINT("Device OUT EP %d Registers\n", i);
3736 + addr=&_core_if->dev_if->out_ep_regs[i]->doepctl;
3737 + DWC_PRINT("DOEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3738 + addr=&_core_if->dev_if->out_ep_regs[i]->doepfn;
3739 + DWC_PRINT("DOEPFN @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3740 + addr=&_core_if->dev_if->out_ep_regs[i]->doepint;
3741 + DWC_PRINT("DOEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3742 + addr=&_core_if->dev_if->out_ep_regs[i]->doeptsiz;
3743 + DWC_PRINT("DOETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3744 + addr=&_core_if->dev_if->out_ep_regs[i]->doepdma;
3745 + DWC_PRINT("DOEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3751 + * This function reads the host registers and prints them
3753 + * @param _core_if Programming view of DWC_otg controller.
3755 +void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if)
3758 + volatile uint32_t *addr;
3760 + DWC_PRINT("Host Global Registers\n");
3761 + addr=&_core_if->host_if->host_global_regs->hcfg;
3762 + DWC_PRINT("HCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3763 + addr=&_core_if->host_if->host_global_regs->hfir;
3764 + DWC_PRINT("HFIR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3765 + addr=&_core_if->host_if->host_global_regs->hfnum;
3766 + DWC_PRINT("HFNUM @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3767 + addr=&_core_if->host_if->host_global_regs->hptxsts;
3768 + DWC_PRINT("HPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3769 + addr=&_core_if->host_if->host_global_regs->haint;
3770 + DWC_PRINT("HAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3771 + addr=&_core_if->host_if->host_global_regs->haintmsk;
3772 + DWC_PRINT("HAINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3773 + addr=_core_if->host_if->hprt0;
3774 + DWC_PRINT("HPRT0 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3776 + for (i=0; i<_core_if->core_params->host_channels; i++) {
3777 + DWC_PRINT("Host Channel %d Specific Registers\n", i);
3778 + addr=&_core_if->host_if->hc_regs[i]->hcchar;
3779 + DWC_PRINT("HCCHAR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3780 + addr=&_core_if->host_if->hc_regs[i]->hcsplt;
3781 + DWC_PRINT("HCSPLT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3782 + addr=&_core_if->host_if->hc_regs[i]->hcint;
3783 + DWC_PRINT("HCINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3784 + addr=&_core_if->host_if->hc_regs[i]->hcintmsk;
3785 + DWC_PRINT("HCINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3786 + addr=&_core_if->host_if->hc_regs[i]->hctsiz;
3787 + DWC_PRINT("HCTSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3788 + addr=&_core_if->host_if->hc_regs[i]->hcdma;
3789 + DWC_PRINT("HCDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3796 + * This function reads the core global registers and prints them
3798 + * @param _core_if Programming view of DWC_otg controller.
3800 +void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if)
3803 + volatile uint32_t *addr;
3805 + DWC_PRINT("Core Global Registers\n");
3806 + addr=&_core_if->core_global_regs->gotgctl;
3807 + DWC_PRINT("GOTGCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3808 + addr=&_core_if->core_global_regs->gotgint;
3809 + DWC_PRINT("GOTGINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3810 + addr=&_core_if->core_global_regs->gahbcfg;
3811 + DWC_PRINT("GAHBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3812 + addr=&_core_if->core_global_regs->gusbcfg;
3813 + DWC_PRINT("GUSBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3814 + addr=&_core_if->core_global_regs->grstctl;
3815 + DWC_PRINT("GRSTCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3816 + addr=&_core_if->core_global_regs->gintsts;
3817 + DWC_PRINT("GINTSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3818 + addr=&_core_if->core_global_regs->gintmsk;
3819 + DWC_PRINT("GINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3820 + addr=&_core_if->core_global_regs->grxstsr;
3821 + DWC_PRINT("GRXSTSR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3822 + //addr=&_core_if->core_global_regs->grxstsp;
3823 + //DWC_PRINT("GRXSTSP @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3824 + addr=&_core_if->core_global_regs->grxfsiz;
3825 + DWC_PRINT("GRXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3826 + addr=&_core_if->core_global_regs->gnptxfsiz;
3827 + DWC_PRINT("GNPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3828 + addr=&_core_if->core_global_regs->gnptxsts;
3829 + DWC_PRINT("GNPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3830 + addr=&_core_if->core_global_regs->gi2cctl;
3831 + DWC_PRINT("GI2CCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3832 + addr=&_core_if->core_global_regs->gpvndctl;
3833 + DWC_PRINT("GPVNDCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3834 + addr=&_core_if->core_global_regs->ggpio;
3835 + DWC_PRINT("GGPIO @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3836 + addr=&_core_if->core_global_regs->guid;
3837 + DWC_PRINT("GUID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3838 + addr=&_core_if->core_global_regs->gsnpsid;
3839 + DWC_PRINT("GSNPSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3840 + addr=&_core_if->core_global_regs->ghwcfg1;
3841 + DWC_PRINT("GHWCFG1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3842 + addr=&_core_if->core_global_regs->ghwcfg2;
3843 + DWC_PRINT("GHWCFG2 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3844 + addr=&_core_if->core_global_regs->ghwcfg3;
3845 + DWC_PRINT("GHWCFG3 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3846 + addr=&_core_if->core_global_regs->ghwcfg4;
3847 + DWC_PRINT("GHWCFG4 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3848 + addr=&_core_if->core_global_regs->hptxfsiz;
3849 + DWC_PRINT("HPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3851 + for (i=0; i<_core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
3852 + addr=&_core_if->core_global_regs->dptxfsiz_dieptxf[i];
3853 + DWC_PRINT("DPTXFSIZ[%d] @0x%08X : 0x%08X\n",i,(uint32_t)addr,dwc_read_reg32(addr));
3860 + * Flush a Tx FIFO.
3862 + * @param _core_if Programming view of DWC_otg controller.
3863 + * @param _num Tx FIFO to flush.
3865 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
3868 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3869 + volatile grstctl_t greset = { .d32 = 0};
3872 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "Flush Tx FIFO %d\n", _num);
3874 + greset.b.txfflsh = 1;
3875 + greset.b.txfnum = _num;
3876 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3879 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3880 + if (++count > 10000){
3881 + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
3882 + __func__, greset.d32,
3883 + dwc_read_reg32( &global_regs->gnptxsts));
3888 + } while (greset.b.txfflsh == 1);
3889 + /* Wait for 3 PHY Clocks*/
3896 + * @param _core_if Programming view of DWC_otg controller.
3898 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if )
3900 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3901 + volatile grstctl_t greset = { .d32 = 0};
3904 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "%s\n", __func__);
3908 + greset.b.rxfflsh = 1;
3909 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3912 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3913 + if (++count > 10000){
3914 + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
3918 + } while (greset.b.rxfflsh == 1);
3919 + /* Wait for 3 PHY Clocks*/
3924 + * Do core a soft reset of the core. Be careful with this because it
3925 + * resets all the internal state machines of the core.
3928 +void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if)
3930 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3931 + volatile grstctl_t greset = { .d32 = 0};
3934 + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
3935 + /* Wait for AHB master IDLE state. */
3938 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3939 + if (++count > 100000){
3940 + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x %x\n", __func__,
3941 + greset.d32, greset.b.ahbidle);
3944 + } while (greset.b.ahbidle == 0);
3948 + /* Note: Actually, I don't exactly why we need to put delay here. */
3951 + /* Core Soft Reset */
3953 + greset.b.csftrst = 1;
3954 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3957 + /* Note: Actually, I don't exactly why we need to put delay here. */
3961 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3962 + if (++count > 10000){
3963 + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n", __func__,
3968 + } while (greset.b.csftrst == 1);
3969 + /* Wait for 3 PHY Clocks*/
3970 + //DWC_PRINT("100ms\n");
3977 + * Register HCD callbacks. The callbacks are used to start and stop
3978 + * the HCD for interrupt processing.
3980 + * @param _core_if Programming view of DWC_otg controller.
3981 + * @param _cb the HCD callback structure.
3982 + * @param _p pointer to be passed to callback function (usb_hcd*).
3984 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
3985 + dwc_otg_cil_callbacks_t *_cb,
3988 + _core_if->hcd_cb = _cb;
3993 + * Register PCD callbacks. The callbacks are used to start and stop
3994 + * the PCD for interrupt processing.
3996 + * @param _core_if Programming view of DWC_otg controller.
3997 + * @param _cb the PCD callback structure.
3998 + * @param _p pointer to be passed to callback function (pcd*).
4000 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
4001 + dwc_otg_cil_callbacks_t *_cb,
4004 + _core_if->pcd_cb = _cb;
4009 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.h
4011 +/* ==========================================================================
4012 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil.h $
4013 + * $Revision: 1.1.1.1 $
4014 + * $Date: 2009-04-17 06:15:34 $
4015 + * $Change: 631780 $
4017 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
4018 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
4019 + * otherwise expressly agreed to in writing between Synopsys and you.
4021 + * The Software IS NOT an item of Licensed Software or Licensed Product under
4022 + * any End User Software License Agreement or Agreement for Licensed Product
4023 + * with Synopsys or any supplement thereto. You are permitted to use and
4024 + * redistribute this Software in source and binary forms, with or without
4025 + * modification, provided that redistributions of source code must retain this
4026 + * notice. You may not view, use, disclose, copy or distribute this file or
4027 + * any information contained herein except pursuant to this license grant from
4028 + * Synopsys. If you do not agree with this notice, including the disclaimer
4029 + * below, then you are not authorized to use the Software.
4031 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
4032 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4033 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4034 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
4035 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
4036 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
4037 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
4038 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4039 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4040 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
4042 + * ========================================================================== */
4044 +#if !defined(__DWC_CIL_H__)
4045 +#define __DWC_CIL_H__
4047 +#include "dwc_otg_plat.h"
4049 +#include "dwc_otg_regs.h"
4051 +#include "linux/timer.h"
4054 +/* the OTG capabilities. */
4055 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
4056 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
4057 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
4058 +/* the maximum speed of operation in host and device mode. */
4059 +#define DWC_SPEED_PARAM_HIGH 0
4060 +#define DWC_SPEED_PARAM_FULL 1
4061 +/* the PHY clock rate in low power mode when connected to a
4062 + * Low Speed device in host mode. */
4063 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
4064 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
4065 +/* the type of PHY interface to use. */
4066 +#define DWC_PHY_TYPE_PARAM_FS 0
4067 +#define DWC_PHY_TYPE_PARAM_UTMI 1
4068 +#define DWC_PHY_TYPE_PARAM_ULPI 2
4069 +/* whether to use the internal or external supply to
4070 + * drive the vbus with a ULPI phy. */
4071 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
4072 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
4077 + * This file contains the interface to the Core Interface Layer.
4081 + * The <code>dwc_ep</code> structure represents the state of a single
4082 + * endpoint when acting in device mode. It contains the data items
4083 + * needed for an endpoint to be activated and transfer packets.
4085 +typedef struct dwc_ep {
4086 + /** EP number used for register address lookup */
4088 + /** EP direction 0 = OUT */
4089 + unsigned is_in : 1;
4091 + unsigned active : 1;
4093 + /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
4094 + If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
4095 + unsigned tx_fifo_num : 4;
4096 + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
4097 + unsigned type : 2;
4098 +#define DWC_OTG_EP_TYPE_CONTROL 0
4099 +#define DWC_OTG_EP_TYPE_ISOC 1
4100 +#define DWC_OTG_EP_TYPE_BULK 2
4101 +#define DWC_OTG_EP_TYPE_INTR 3
4103 + /** DATA start PID for INTR and BULK EP */
4104 + unsigned data_pid_start : 1;
4105 + /** Frame (even/odd) for ISOC EP */
4106 + unsigned even_odd_frame : 1;
4107 + /** Max Packet bytes */
4108 + unsigned maxpacket : 11;
4110 + /** @name Transfer state */
4114 + * Pointer to the beginning of the transfer buffer -- do not modify
4115 + * during transfer.
4118 + uint32_t dma_addr;
4120 + uint8_t *start_xfer_buff;
4121 + /** pointer to the transfer buffer */
4122 + uint8_t *xfer_buff;
4123 + /** Number of bytes to transfer */
4124 + unsigned xfer_len : 19;
4125 + /** Number of bytes transferred. */
4126 + unsigned xfer_count : 19;
4128 + unsigned sent_zlp : 1;
4129 + /** Total len for control transfer */
4130 + unsigned total_len : 19;
4132 + /** stall clear flag */
4133 + unsigned stall_clear_flag : 1;
4139 + * Reasons for halting a host channel.
4141 +typedef enum dwc_otg_halt_status {
4142 + DWC_OTG_HC_XFER_NO_HALT_STATUS,
4143 + DWC_OTG_HC_XFER_COMPLETE,
4144 + DWC_OTG_HC_XFER_URB_COMPLETE,
4145 + DWC_OTG_HC_XFER_ACK,
4146 + DWC_OTG_HC_XFER_NAK,
4147 + DWC_OTG_HC_XFER_NYET,
4148 + DWC_OTG_HC_XFER_STALL,
4149 + DWC_OTG_HC_XFER_XACT_ERR,
4150 + DWC_OTG_HC_XFER_FRAME_OVERRUN,
4151 + DWC_OTG_HC_XFER_BABBLE_ERR,
4152 + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
4153 + DWC_OTG_HC_XFER_AHB_ERR,
4154 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
4155 + DWC_OTG_HC_XFER_URB_DEQUEUE
4156 +} dwc_otg_halt_status_e;
4159 + * Host channel descriptor. This structure represents the state of a single
4160 + * host channel when acting in host mode. It contains the data items needed to
4161 + * transfer packets to an endpoint via a host channel.
4163 +typedef struct dwc_hc {
4164 + /** Host channel number used for register address lookup */
4167 + /** Device to access */
4168 + unsigned dev_addr : 7;
4170 + /** EP to access */
4171 + unsigned ep_num : 4;
4173 + /** EP direction. 0: OUT, 1: IN */
4174 + unsigned ep_is_in : 1;
4178 + * One of the following values:
4179 + * - DWC_OTG_EP_SPEED_LOW
4180 + * - DWC_OTG_EP_SPEED_FULL
4181 + * - DWC_OTG_EP_SPEED_HIGH
4183 + unsigned speed : 2;
4184 +#define DWC_OTG_EP_SPEED_LOW 0
4185 +#define DWC_OTG_EP_SPEED_FULL 1
4186 +#define DWC_OTG_EP_SPEED_HIGH 2
4190 + * One of the following values:
4191 + * - DWC_OTG_EP_TYPE_CONTROL: 0
4192 + * - DWC_OTG_EP_TYPE_ISOC: 1
4193 + * - DWC_OTG_EP_TYPE_BULK: 2
4194 + * - DWC_OTG_EP_TYPE_INTR: 3
4196 + unsigned ep_type : 2;
4198 + /** Max packet size in bytes */
4199 + unsigned max_packet : 11;
4202 + * PID for initial transaction.
4206 + * 3: MDATA (non-Control EP),
4207 + * SETUP (Control EP)
4209 + unsigned data_pid_start : 2;
4210 +#define DWC_OTG_HC_PID_DATA0 0
4211 +#define DWC_OTG_HC_PID_DATA2 1
4212 +#define DWC_OTG_HC_PID_DATA1 2
4213 +#define DWC_OTG_HC_PID_MDATA 3
4214 +#define DWC_OTG_HC_PID_SETUP 3
4216 + /** Number of periodic transactions per (micro)frame */
4217 + unsigned multi_count: 2;
4219 + /** @name Transfer State */
4222 + /** Pointer to the current transfer buffer position. */
4223 + uint8_t *xfer_buff;
4224 + /** Total number of bytes to transfer. */
4225 + uint32_t xfer_len;
4226 + /** Number of bytes transferred so far. */
4227 + uint32_t xfer_count;
4228 + /** Packet count at start of transfer.*/
4229 + uint16_t start_pkt_count;
4232 + * Flag to indicate whether the transfer has been started. Set to 1 if
4233 + * it has been started, 0 otherwise.
4235 + uint8_t xfer_started;
4238 + * Set to 1 to indicate that a PING request should be issued on this
4239 + * channel. If 0, process normally.
4244 + * Set to 1 to indicate that the error count for this transaction is
4245 + * non-zero. Set to 0 if the error count is 0.
4247 + uint8_t error_state;
4250 + * Set to 1 to indicate that this channel should be halted the next
4251 + * time a request is queued for the channel. This is necessary in
4252 + * slave mode if no request queue space is available when an attempt
4253 + * is made to halt the channel.
4255 + uint8_t halt_on_queue;
4258 + * Set to 1 if the host channel has been halted, but the core is not
4259 + * finished flushing queued requests. Otherwise 0.
4261 + uint8_t halt_pending;
4264 + * Reason for halting the host channel.
4266 + dwc_otg_halt_status_e halt_status;
4269 + * Split settings for the host channel
4271 + uint8_t do_split; /**< Enable split for the channel */
4272 + uint8_t complete_split; /**< Enable complete split */
4273 + uint8_t hub_addr; /**< Address of high speed hub */
4275 + uint8_t port_addr; /**< Port of the low/full speed device */
4276 + /** Split transaction position
4277 + * One of the following values:
4278 + * - DWC_HCSPLIT_XACTPOS_MID
4279 + * - DWC_HCSPLIT_XACTPOS_BEGIN
4280 + * - DWC_HCSPLIT_XACTPOS_END
4281 + * - DWC_HCSPLIT_XACTPOS_ALL */
4284 + /** Set when the host channel does a short read. */
4285 + uint8_t short_read;
4288 + * Number of requests issued for this channel since it was assigned to
4289 + * the current transfer (not counting PINGs).
4294 + * Queue Head for the transfer being processed by this channel.
4296 + struct dwc_otg_qh *qh;
4300 + /** Entry in list of host channels. */
4301 + struct list_head hc_list_entry;
4305 + * The following parameters may be specified when starting the module. These
4306 + * parameters define how the DWC_otg controller should be configured.
4307 + * Parameter values are passed to the CIL initialization function
4308 + * dwc_otg_cil_init.
4311 +typedef struct dwc_otg_core_params
4314 +//#define dwc_param_opt_default 1
4316 + * Specifies the OTG capabilities. The driver will automatically
4317 + * detect the value for this parameter if none is specified.
4318 + * 0 - HNP and SRP capable (default)
4319 + * 1 - SRP Only capable
4320 + * 2 - No HNP/SRP capable
4323 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
4324 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
4325 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
4326 +//#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
4328 + * Specifies whether to use slave or DMA mode for accessing the data
4329 + * FIFOs. The driver will automatically detect the value for this
4330 + * parameter if none is specified.
4332 + * 1 - DMA (default, if available)
4334 + int32_t dma_enable;
4335 +//#define dwc_param_dma_enable_default 1
4336 + /** The DMA Burst size (applicable only for External DMA
4337 + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
4339 + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
4340 +//#define dwc_param_dma_burst_size_default 32
4342 + * Specifies the maximum speed of operation in host and device mode.
4343 + * The actual speed depends on the speed of the attached device and
4344 + * the value of phy_type. The actual speed depends on the speed of the
4345 + * attached device.
4346 + * 0 - High Speed (default)
4350 +//#define dwc_param_speed_default 0
4351 +#define DWC_SPEED_PARAM_HIGH 0
4352 +#define DWC_SPEED_PARAM_FULL 1
4354 + /** Specifies whether low power mode is supported when attached
4355 + * to a Full Speed or Low Speed device in host mode.
4356 + * 0 - Don't support low power mode (default)
4357 + * 1 - Support low power mode
4359 + int32_t host_support_fs_ls_low_power;
4360 +//#define dwc_param_host_support_fs_ls_low_power_default 0
4361 + /** Specifies the PHY clock rate in low power mode when connected to a
4362 + * Low Speed device in host mode. This parameter is applicable only if
4363 + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
4364 + * then defaults to 6 MHZ otherwise 48 MHZ.
4369 + int32_t host_ls_low_power_phy_clk;
4370 +//#define dwc_param_host_ls_low_power_phy_clk_default 0
4371 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
4372 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
4374 + * 0 - Use cC FIFO size parameters
4375 + * 1 - Allow dynamic FIFO sizing (default)
4377 + int32_t enable_dynamic_fifo;
4378 +//#define dwc_param_enable_dynamic_fifo_default 1
4379 + /** Total number of 4-byte words in the data FIFO memory. This
4380 + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
4382 + * 32 to 32768 (default 8192)
4383 + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
4385 + int32_t data_fifo_size;
4386 +//#define dwc_param_data_fifo_size_default 8192
4387 + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
4388 + * FIFO sizing is enabled.
4389 + * 16 to 32768 (default 1064)
4391 + int32_t dev_rx_fifo_size;
4392 +//#define dwc_param_dev_rx_fifo_size_default 1064
4393 + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
4394 + * when dynamic FIFO sizing is enabled.
4395 + * 16 to 32768 (default 1024)
4397 + int32_t dev_nperio_tx_fifo_size;
4398 +//#define dwc_param_dev_nperio_tx_fifo_size_default 1024
4399 + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
4400 + * mode when dynamic FIFO sizing is enabled.
4401 + * 4 to 768 (default 256)
4403 + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
4404 +//#define dwc_param_dev_perio_tx_fifo_size_default 256
4405 + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
4406 + * FIFO sizing is enabled.
4407 + * 16 to 32768 (default 1024)
4409 + int32_t host_rx_fifo_size;
4410 +//#define dwc_param_host_rx_fifo_size_default 1024
4411 + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
4412 + * when Dynamic FIFO sizing is enabled in the core.
4413 + * 16 to 32768 (default 1024)
4415 + int32_t host_nperio_tx_fifo_size;
4416 +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
4417 + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
4418 + * FIFO sizing is enabled.
4419 + * 16 to 32768 (default 1024)
4421 + int32_t host_perio_tx_fifo_size;
4422 +//#define dwc_param_host_perio_tx_fifo_size_default 1024
4423 + /** The maximum transfer size supported in bytes.
4424 + * 2047 to 65,535 (default 65,535)
4426 + int32_t max_transfer_size;
4427 +//#define dwc_param_max_transfer_size_default 65535
4428 + /** The maximum number of packets in a transfer.
4429 + * 15 to 511 (default 511)
4431 + int32_t max_packet_count;
4432 +//#define dwc_param_max_packet_count_default 511
4433 + /** The number of host channel registers to use.
4434 + * 1 to 16 (default 12)
4435 + * Note: The FPGA configuration supports a maximum of 12 host channels.
4437 + int32_t host_channels;
4438 +//#define dwc_param_host_channels_default 12
4439 + /** The number of endpoints in addition to EP0 available for device
4440 + * mode operations.
4441 + * 1 to 15 (default 6 IN and OUT)
4442 + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
4443 + * endpoints in addition to EP0.
4445 + int32_t dev_endpoints;
4446 +//#define dwc_param_dev_endpoints_default 6
4448 + * Specifies the type of PHY interface to use. By default, the driver
4449 + * will automatically detect the phy_type.
4451 + * 0 - Full Speed PHY
4452 + * 1 - UTMI+ (default)
4456 +#define DWC_PHY_TYPE_PARAM_FS 0
4457 +#define DWC_PHY_TYPE_PARAM_UTMI 1
4458 +#define DWC_PHY_TYPE_PARAM_ULPI 2
4459 +//#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
4461 + * Specifies the UTMI+ Data Width. This parameter is
4462 + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
4463 + * PHY_TYPE, this parameter indicates the data width between
4464 + * the MAC and the ULPI Wrapper.) Also, this parameter is
4465 + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
4466 + * to "8 and 16 bits", meaning that the core has been
4467 + * configured to work at either data path width.
4469 + * 8 or 16 bits (default 16)
4471 + int32_t phy_utmi_width;
4472 +//#define dwc_param_phy_utmi_width_default 16
4474 + * Specifies whether the ULPI operates at double or single
4475 + * data rate. This parameter is only applicable if PHY_TYPE is
4478 + * 0 - single data rate ULPI interface with 8 bit wide data
4480 + * 1 - double data rate ULPI interface with 4 bit wide data
4483 + int32_t phy_ulpi_ddr;
4484 +//#define dwc_param_phy_ulpi_ddr_default 0
4486 + * Specifies whether to use the internal or external supply to
4487 + * drive the vbus with a ULPI phy.
4489 + int32_t phy_ulpi_ext_vbus;
4490 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
4491 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
4492 +//#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
4494 + * Specifies whether to use the I2Cinterface for full speed PHY. This
4495 + * parameter is only applicable if PHY_TYPE is FS.
4496 + * 0 - No (default)
4499 + int32_t i2c_enable;
4500 +//#define dwc_param_i2c_enable_default 0
4502 + int32_t ulpi_fs_ls;
4503 +//#define dwc_param_ulpi_fs_ls_default 0
4506 +//#define dwc_param_ts_dline_default 0
4509 + * Specifies whether dedicated transmit FIFOs are
4510 + * enabled for non periodic IN endpoints in device mode
4514 + int32_t en_multiple_tx_fifo;
4515 +#define dwc_param_en_multiple_tx_fifo_default 1
4517 + /** Number of 4-byte words in each of the Tx FIFOs in device
4518 + * mode when dynamic FIFO sizing is enabled.
4519 + * 4 to 768 (default 256)
4521 + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
4522 +#define dwc_param_dev_tx_fifo_size_default 256
4524 + /** Thresholding enable flag-
4525 + * bit 0 - enable non-ISO Tx thresholding
4526 + * bit 1 - enable ISO Tx thresholding
4527 + * bit 2 - enable Rx thresholding
4530 +#define dwc_param_thr_ctl_default 0
4532 + /** Thresholding length for Tx
4533 + * FIFOs in 32 bit DWORDs
4535 + uint32_t tx_thr_length;
4536 +#define dwc_param_tx_thr_length_default 64
4538 + /** Thresholding length for Rx
4539 + * FIFOs in 32 bit DWORDs
4541 + uint32_t rx_thr_length;
4542 +#define dwc_param_rx_thr_length_default 64
4543 +} dwc_otg_core_params_t;
4546 +struct dwc_otg_core_if;
4547 +typedef struct hc_xfer_info
4549 + struct dwc_otg_core_if *core_if;
4555 + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
4556 + * the DWC_otg controller acting in either host or device mode. It
4557 + * represents the programming view of the controller as a whole.
4559 +typedef struct dwc_otg_core_if
4561 + /** Parameters that define how the core should be configured.*/
4562 + dwc_otg_core_params_t *core_params;
4564 + /** Core Global registers starting at offset 000h. */
4565 + dwc_otg_core_global_regs_t *core_global_regs;
4567 + /** Device-specific information */
4568 + dwc_otg_dev_if_t *dev_if;
4569 + /** Host-specific information */
4570 + dwc_otg_host_if_t *host_if;
4573 + * Set to 1 if the core PHY interface bits in USBCFG have been
4576 + uint8_t phy_init_done;
4579 + * SRP Success flag, set by srp success interrupt in FS I2C mode
4581 + uint8_t srp_success;
4582 + uint8_t srp_timer_started;
4584 + /* Common configuration information */
4585 + /** Power and Clock Gating Control Register */
4586 + volatile uint32_t *pcgcctl;
4587 +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
4589 + /** Push/pop addresses for endpoints or host channels.*/
4590 + uint32_t *data_fifo[MAX_EPS_CHANNELS];
4591 +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
4592 +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
4594 + /** Total RAM for FIFOs (Bytes) */
4595 + uint16_t total_fifo_size;
4596 + /** Size of Rx FIFO (Bytes) */
4597 + uint16_t rx_fifo_size;
4598 + /** Size of Non-periodic Tx FIFO (Bytes) */
4599 + uint16_t nperio_tx_fifo_size;
4601 + /** 1 if DMA is enabled, 0 otherwise. */
4602 + uint8_t dma_enable;
4604 + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
4605 + uint8_t en_multiple_tx_fifo;
4607 + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
4608 + * process of being queued */
4609 + uint8_t queuing_high_bandwidth;
4611 + /** Hardware Configuration -- stored here for convenience.*/
4612 + hwcfg1_data_t hwcfg1;
4613 + hwcfg2_data_t hwcfg2;
4614 + hwcfg3_data_t hwcfg3;
4615 + hwcfg4_data_t hwcfg4;
4617 + /** The operational State, during transations
4618 + * (a_host>>a_peripherial and b_device=>b_host) this may not
4619 + * match the core but allows the software to determine
4625 + * Set to 1 if the HCD needs to be restarted on a session request
4626 + * interrupt. This is required if no connector ID status change has
4627 + * occurred since the HCD was last disconnected.
4629 + uint8_t restart_hcd_on_session_req;
4631 + /** HCD callbacks */
4632 + /** A-Device is a_host */
4634 + /** A-Device is a_suspend */
4635 +#define A_SUSPEND (2)
4636 + /** A-Device is a_peripherial */
4637 +#define A_PERIPHERAL (3)
4638 + /** B-Device is operating as a Peripheral. */
4639 +#define B_PERIPHERAL (4)
4640 + /** B-Device is operating as a Host. */
4643 + /** HCD callbacks */
4644 + struct dwc_otg_cil_callbacks *hcd_cb;
4645 + /** PCD callbacks */
4646 + struct dwc_otg_cil_callbacks *pcd_cb;
4648 + /** Device mode Periodic Tx FIFO Mask */
4649 + uint32_t p_tx_msk;
4650 + /** Device mode Periodic Tx FIFO Mask */
4654 + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
4656 + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
4657 + struct timer_list hc_xfer_timer[MAX_EPS_CHANNELS];
4660 + uint32_t hfnum_7_samples;
4661 + uint32_t hfnum_7_frrem_accum;
4662 + uint32_t hfnum_0_samples;
4663 + uint32_t hfnum_0_frrem_accum;
4664 + uint32_t hfnum_other_samples;
4665 + uint32_t hfnum_other_frrem_accum;
4667 + uint32_t hfnum_7_samples;
4668 + uint64_t hfnum_7_frrem_accum;
4669 + uint32_t hfnum_0_samples;
4670 + uint64_t hfnum_0_frrem_accum;
4671 + uint32_t hfnum_other_samples;
4672 + uint64_t hfnum_other_frrem_accum;
4674 + resource_size_t phys_addr; /* Added to support PLB DMA : phys-virt mapping */
4677 +} dwc_otg_core_if_t;
4680 + * The following functions support initialization of the CIL driver component
4681 + * and the DWC_otg controller.
4683 +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
4684 + dwc_otg_core_params_t *_core_params);
4685 +extern void dwc_otg_cil_remove(dwc_otg_core_if_t *_core_if);
4686 +extern void dwc_otg_core_init(dwc_otg_core_if_t *_core_if);
4687 +extern void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if);
4688 +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if);
4689 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if );
4690 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if );
4692 +/** @name Device CIL Functions
4693 + * The following functions support managing the DWC_otg controller in device
4697 +extern void dwc_otg_wakeup(dwc_otg_core_if_t *_core_if);
4698 +extern void dwc_otg_read_setup_packet (dwc_otg_core_if_t *_core_if, uint32_t *_dest);
4699 +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if);
4700 +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4701 +extern void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4702 +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4703 +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4704 +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4705 +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4706 +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma);
4707 +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4708 +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4709 +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if);
4710 +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if);
4713 +/** @name Host CIL Functions
4714 + * The following functions support managing the DWC_otg controller in host
4718 +extern void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4719 +extern void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
4721 + dwc_otg_halt_status_e _halt_status);
4722 +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4723 +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4724 +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4725 +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4726 +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4727 +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if);
4728 +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if);
4731 + * This function Reads HPRT0 in preparation to modify. It keeps the
4732 + * WC bits 0 so that if they are read as 1, they won't clear when you
4735 +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t *_core_if)
4737 + hprt0_data_t hprt0;
4738 + hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
4739 + hprt0.b.prtena = 0;
4740 + hprt0.b.prtconndet = 0;
4741 + hprt0.b.prtenchng = 0;
4742 + hprt0.b.prtovrcurrchng = 0;
4746 +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if);
4749 +/** @name Common CIL Functions
4750 + * The following functions support managing the DWC_otg controller in either
4751 + * device or host mode.
4755 +extern void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
4759 +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if);
4761 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
4763 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if );
4764 +extern void dwc_otg_core_reset( dwc_otg_core_if_t *_core_if );
4766 +#define NP_TXFIFO_EMPTY -1
4767 +#define MAX_NP_TXREQUEST_Q_SLOTS 8
4769 + * This function returns the endpoint number of the request at
4770 + * the top of non-periodic TX FIFO, or -1 if the request FIFO is
4773 +static inline int dwc_otg_top_nptxfifo_epnum(dwc_otg_core_if_t *_core_if) {
4774 + gnptxsts_data_t txstatus = {.d32 = 0};
4776 + txstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
4777 + return (txstatus.b.nptxqspcavail == MAX_NP_TXREQUEST_Q_SLOTS ?
4778 + -1 : txstatus.b.nptxqtop_chnep);
4781 + * This function returns the Core Interrupt register.
4783 +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t *_core_if) {
4784 + return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) &
4785 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
4789 + * This function returns the OTG Interrupt register.
4791 +static inline uint32_t dwc_otg_read_otg_intr (dwc_otg_core_if_t *_core_if) {
4792 + return (dwc_read_reg32 (&_core_if->core_global_regs->gotgint));
4796 + * This function reads the Device All Endpoints Interrupt register and
4797 + * returns the IN endpoint interrupt bits.
4799 +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *_core_if) {
4801 + v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
4802 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
4803 + return (v & 0xffff);
4808 + * This function reads the Device All Endpoints Interrupt register and
4809 + * returns the OUT endpoint interrupt bits.
4811 +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *_core_if) {
4813 + v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
4814 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
4815 + return ((v & 0xffff0000) >> 16);
4819 + * This function returns the Device IN EP Interrupt register
4821 +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t *_core_if,
4824 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4825 + uint32_t v, msk, emp;
4826 + msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
4827 + emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
4828 + msk |= ((emp >> _ep->num) & 0x1) << 7;
4829 + v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) & msk;
4831 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4833 + v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) &
4834 + dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
4839 + * This function returns the Device OUT EP Interrupt register
4841 +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *_core_if,
4844 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4846 + v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) &
4847 + dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
4852 + * This function returns the Host All Channel Interrupt register
4854 +static inline uint32_t dwc_otg_read_host_all_channels_intr (dwc_otg_core_if_t *_core_if)
4856 + return (dwc_read_reg32 (&_core_if->host_if->host_global_regs->haint));
4859 +static inline uint32_t dwc_otg_read_host_channel_intr (dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
4861 + return (dwc_read_reg32 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
4866 + * This function returns the mode of the operation, host or device.
4868 + * @return 0 - Device Mode, 1 - Host Mode
4870 +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t *_core_if) {
4871 + return (dwc_read_reg32( &_core_if->core_global_regs->gintsts ) & 0x1);
4874 +static inline uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t *_core_if)
4876 + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
4878 +static inline uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t *_core_if)
4880 + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
4883 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if );
4889 + * DWC_otg CIL callback structure. This structure allows the HCD and
4890 + * PCD to register functions used for starting and stopping the PCD
4891 + * and HCD for role change on for a DRD.
4893 +typedef struct dwc_otg_cil_callbacks
4895 + /** Start function for role change */
4896 + int (*start) (void *_p);
4897 + /** Stop Function for role change */
4898 + int (*stop) (void *_p);
4899 + /** Disconnect Function for role change */
4900 + int (*disconnect) (void *_p);
4901 + /** Resume/Remote wakeup Function */
4902 + int (*resume_wakeup) (void *_p);
4903 + /** Suspend function */
4904 + int (*suspend) (void *_p);
4905 + /** Session Start (SRP) */
4906 + int (*session_start) (void *_p);
4907 + /** Pointer passed to start() and stop() */
4909 +} dwc_otg_cil_callbacks_t;
4913 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
4914 + dwc_otg_cil_callbacks_t *_cb,
4916 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
4917 + dwc_otg_cil_callbacks_t *_cb,
4923 +++ b/drivers/usb/dwc_otg/dwc_otg_cil_ifx.h
4925 +/******************************************************************************
4927 +** FILE NAME : dwc_otg_cil_ifx.h
4928 +** PROJECT : Twinpass/Danube
4929 +** MODULES : DWC OTG USB
4931 +** DATE : 07 Sep. 2007
4932 +** AUTHOR : Sung Winder
4933 +** DESCRIPTION : Default param value.
4934 +** COPYRIGHT : Copyright (c) 2007
4935 +** Infineon Technologies AG
4936 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
4937 +** Hsin-chu City, 300 Taiwan.
4939 +** This program is free software; you can redistribute it and/or modify
4940 +** it under the terms of the GNU General Public License as published by
4941 +** the Free Software Foundation; either version 2 of the License, or
4942 +** (at your option) any later version.
4945 +** $Date $Author $Comment
4946 +** 12 April 2007 Sung Winder Initiate Version
4947 +*******************************************************************************/
4948 +#if !defined(__DWC_OTG_CIL_IFX_H__)
4949 +#define __DWC_OTG_CIL_IFX_H__
4951 +/* ================ Default param value ================== */
4952 +#define dwc_param_opt_default 1
4953 +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE
4954 +#define dwc_param_dma_enable_default 1
4955 +#define dwc_param_dma_burst_size_default 32
4956 +#define dwc_param_speed_default DWC_SPEED_PARAM_HIGH
4957 +#define dwc_param_host_support_fs_ls_low_power_default 0
4958 +#define dwc_param_host_ls_low_power_phy_clk_default DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ
4959 +#define dwc_param_enable_dynamic_fifo_default 1
4960 +#define dwc_param_data_fifo_size_default 2048
4961 +#define dwc_param_dev_rx_fifo_size_default 1024
4962 +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
4963 +#define dwc_param_dev_perio_tx_fifo_size_default 768
4964 +#define dwc_param_host_rx_fifo_size_default 640
4965 +#define dwc_param_host_nperio_tx_fifo_size_default 640
4966 +#define dwc_param_host_perio_tx_fifo_size_default 768
4967 +#define dwc_param_max_transfer_size_default 65535
4968 +#define dwc_param_max_packet_count_default 511
4969 +#define dwc_param_host_channels_default 16
4970 +#define dwc_param_dev_endpoints_default 6
4971 +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
4972 +#define dwc_param_phy_utmi_width_default 16
4973 +#define dwc_param_phy_ulpi_ddr_default 0
4974 +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
4975 +#define dwc_param_i2c_enable_default 0
4976 +#define dwc_param_ulpi_fs_ls_default 0
4977 +#define dwc_param_ts_dline_default 0
4979 +/* ======================================================= */
4981 +#endif // __DWC_OTG_CIL_IFX_H__
4984 +++ b/drivers/usb/dwc_otg/dwc_otg_cil_intr.c
4986 +/* ==========================================================================
4987 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil_intr.c $
4988 + * $Revision: 1.1.1.1 $
4989 + * $Date: 2009-04-17 06:15:34 $
4990 + * $Change: 553126 $
4992 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
4993 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
4994 + * otherwise expressly agreed to in writing between Synopsys and you.
4996 + * The Software IS NOT an item of Licensed Software or Licensed Product under
4997 + * any End User Software License Agreement or Agreement for Licensed Product
4998 + * with Synopsys or any supplement thereto. You are permitted to use and
4999 + * redistribute this Software in source and binary forms, with or without
5000 + * modification, provided that redistributions of source code must retain this
5001 + * notice. You may not view, use, disclose, copy or distribute this file or
5002 + * any information contained herein except pursuant to this license grant from
5003 + * Synopsys. If you do not agree with this notice, including the disclaimer
5004 + * below, then you are not authorized to use the Software.
5006 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
5007 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5008 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5009 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
5010 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5011 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5012 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5013 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5014 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5015 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
5017 + * ========================================================================== */
5021 + * The Core Interface Layer provides basic services for accessing and
5022 + * managing the DWC_otg hardware. These services are used by both the
5023 + * Host Controller Driver and the Peripheral Controller Driver.
5025 + * This file contains the Common Interrupt handlers.
5027 +#include "dwc_otg_plat.h"
5028 +#include "dwc_otg_regs.h"
5029 +#include "dwc_otg_cil.h"
5032 +inline const char *op_state_str( dwc_otg_core_if_t *_core_if )
5034 + return (_core_if->op_state==A_HOST?"a_host":
5035 + (_core_if->op_state==A_SUSPEND?"a_suspend":
5036 + (_core_if->op_state==A_PERIPHERAL?"a_peripheral":
5037 + (_core_if->op_state==B_PERIPHERAL?"b_peripheral":
5038 + (_core_if->op_state==B_HOST?"b_host":
5043 +/** This function will log a debug message
5045 + * @param _core_if Programming view of DWC_otg controller.
5047 +int32_t dwc_otg_handle_mode_mismatch_intr (dwc_otg_core_if_t *_core_if)
5049 + gintsts_data_t gintsts;
5050 + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
5051 + dwc_otg_mode(_core_if) ? "Host" : "Device");
5053 + /* Clear interrupt */
5055 + gintsts.b.modemismatch = 1;
5056 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5060 +/** Start the HCD. Helper function for using the HCD callbacks.
5062 + * @param _core_if Programming view of DWC_otg controller.
5064 +static inline void hcd_start( dwc_otg_core_if_t *_core_if )
5066 + if (_core_if->hcd_cb && _core_if->hcd_cb->start) {
5067 + _core_if->hcd_cb->start( _core_if->hcd_cb->p );
5070 +/** Stop the HCD. Helper function for using the HCD callbacks.
5072 + * @param _core_if Programming view of DWC_otg controller.
5074 +static inline void hcd_stop( dwc_otg_core_if_t *_core_if )
5076 + if (_core_if->hcd_cb && _core_if->hcd_cb->stop) {
5077 + _core_if->hcd_cb->stop( _core_if->hcd_cb->p );
5080 +/** Disconnect the HCD. Helper function for using the HCD callbacks.
5082 + * @param _core_if Programming view of DWC_otg controller.
5084 +static inline void hcd_disconnect( dwc_otg_core_if_t *_core_if )
5086 + if (_core_if->hcd_cb && _core_if->hcd_cb->disconnect) {
5087 + _core_if->hcd_cb->disconnect( _core_if->hcd_cb->p );
5090 +/** Inform the HCD the a New Session has begun. Helper function for
5091 + * using the HCD callbacks.
5093 + * @param _core_if Programming view of DWC_otg controller.
5095 +static inline void hcd_session_start( dwc_otg_core_if_t *_core_if )
5097 + if (_core_if->hcd_cb && _core_if->hcd_cb->session_start) {
5098 + _core_if->hcd_cb->session_start( _core_if->hcd_cb->p );
5102 +/** Start the PCD. Helper function for using the PCD callbacks.
5104 + * @param _core_if Programming view of DWC_otg controller.
5106 +static inline void pcd_start( dwc_otg_core_if_t *_core_if )
5108 + if (_core_if->pcd_cb && _core_if->pcd_cb->start ) {
5109 + _core_if->pcd_cb->start( _core_if->pcd_cb->p );
5112 +/** Stop the PCD. Helper function for using the PCD callbacks.
5114 + * @param _core_if Programming view of DWC_otg controller.
5116 +static inline void pcd_stop( dwc_otg_core_if_t *_core_if )
5118 + if (_core_if->pcd_cb && _core_if->pcd_cb->stop ) {
5119 + _core_if->pcd_cb->stop( _core_if->pcd_cb->p );
5122 +/** Suspend the PCD. Helper function for using the PCD callbacks.
5124 + * @param _core_if Programming view of DWC_otg controller.
5126 +static inline void pcd_suspend( dwc_otg_core_if_t *_core_if )
5128 + if (_core_if->pcd_cb && _core_if->pcd_cb->suspend ) {
5129 + _core_if->pcd_cb->suspend( _core_if->pcd_cb->p );
5132 +/** Resume the PCD. Helper function for using the PCD callbacks.
5134 + * @param _core_if Programming view of DWC_otg controller.
5136 +static inline void pcd_resume( dwc_otg_core_if_t *_core_if )
5138 + if (_core_if->pcd_cb && _core_if->pcd_cb->resume_wakeup ) {
5139 + _core_if->pcd_cb->resume_wakeup( _core_if->pcd_cb->p );
5144 + * This function handles the OTG Interrupts. It reads the OTG
5145 + * Interrupt Register (GOTGINT) to determine what interrupt has
5148 + * @param _core_if Programming view of DWC_otg controller.
5150 +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t *_core_if)
5152 + dwc_otg_core_global_regs_t *global_regs =
5153 + _core_if->core_global_regs;
5154 + gotgint_data_t gotgint;
5155 + gotgctl_data_t gotgctl;
5156 + gintmsk_data_t gintmsk;
5158 + gotgint.d32 = dwc_read_reg32( &global_regs->gotgint);
5159 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5160 + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
5161 + op_state_str(_core_if));
5162 + //DWC_DEBUGPL(DBG_CIL, "gotgctl=%08x\n", gotgctl.d32 );
5164 + if (gotgint.b.sesenddet) {
5165 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5166 + "Session End Detected++ (%s)\n",
5167 + op_state_str(_core_if));
5168 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5170 + if (_core_if->op_state == B_HOST) {
5171 + pcd_start( _core_if );
5172 + _core_if->op_state = B_PERIPHERAL;
5174 + /* If not B_HOST and Device HNP still set. HNP
5175 + * Did not succeed!*/
5176 + if (gotgctl.b.devhnpen) {
5177 + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
5178 + DWC_ERROR( "Device Not Connected/Responding!\n" );
5181 + /* If Session End Detected the B-Cable has
5182 + * been disconnected. */
5183 + /* Reset PCD and Gadget driver to a
5185 + pcd_stop(_core_if);
5188 + gotgctl.b.devhnpen = 1;
5189 + dwc_modify_reg32( &global_regs->gotgctl,
5192 + if (gotgint.b.sesreqsucstschng) {
5193 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5194 + "Session Reqeust Success Status Change++\n");
5195 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5196 + if (gotgctl.b.sesreqscs) {
5197 + if ((_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
5198 + (_core_if->core_params->i2c_enable)) {
5199 + _core_if->srp_success = 1;
5202 + pcd_resume( _core_if );
5203 + /* Clear Session Request */
5205 + gotgctl.b.sesreq = 1;
5206 + dwc_modify_reg32( &global_regs->gotgctl,
5211 + if (gotgint.b.hstnegsucstschng) {
5212 + /* Print statements during the HNP interrupt handling
5213 + * can cause it to fail.*/
5214 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
5215 + if (gotgctl.b.hstnegscs) {
5216 + if (dwc_otg_is_host_mode(_core_if) ) {
5217 + _core_if->op_state = B_HOST;
5219 + * Need to disable SOF interrupt immediately.
5220 + * When switching from device to host, the PCD
5221 + * interrupt handler won't handle the
5222 + * interrupt if host mode is already set. The
5223 + * HCD interrupt handler won't get called if
5224 + * the HCD state is HALT. This means that the
5225 + * interrupt does not get handled and Linux
5226 + * complains loudly.
5229 + gintmsk.b.sofintr = 1;
5230 + dwc_modify_reg32(&global_regs->gintmsk,
5232 + pcd_stop(_core_if);
5234 + * Initialize the Core for Host mode.
5236 + hcd_start( _core_if );
5237 + _core_if->op_state = B_HOST;
5241 + gotgctl.b.hnpreq = 1;
5242 + gotgctl.b.devhnpen = 1;
5243 + dwc_modify_reg32( &global_regs->gotgctl,
5245 + DWC_DEBUGPL( DBG_ANY, "HNP Failed\n");
5246 + DWC_ERROR( "Device Not Connected/Responding\n" );
5249 + if (gotgint.b.hstnegdet) {
5250 + /* The disconnect interrupt is set at the same time as
5251 + * Host Negotiation Detected. During the mode
5252 + * switch all interrupts are cleared so the disconnect
5253 + * interrupt handler will not get executed.
5255 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5256 + "Host Negotiation Detected++ (%s)\n",
5257 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"));
5258 + if (dwc_otg_is_device_mode(_core_if)){
5259 + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",_core_if->op_state);
5260 + hcd_disconnect( _core_if );
5261 + pcd_start( _core_if );
5262 + _core_if->op_state = A_PERIPHERAL;
5265 + * Need to disable SOF interrupt immediately. When
5266 + * switching from device to host, the PCD interrupt
5267 + * handler won't handle the interrupt if host mode is
5268 + * already set. The HCD interrupt handler won't get
5269 + * called if the HCD state is HALT. This means that
5270 + * the interrupt does not get handled and Linux
5271 + * complains loudly.
5274 + gintmsk.b.sofintr = 1;
5275 + dwc_modify_reg32(&global_regs->gintmsk,
5277 + pcd_stop( _core_if );
5278 + hcd_start( _core_if );
5279 + _core_if->op_state = A_HOST;
5282 + if (gotgint.b.adevtoutchng) {
5283 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5284 + "A-Device Timeout Change++\n");
5286 + if (gotgint.b.debdone) {
5287 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5288 + "Debounce Done++\n");
5291 + /* Clear GOTGINT */
5292 + dwc_write_reg32 (&_core_if->core_global_regs->gotgint, gotgint.d32);
5298 + * This function handles the Connector ID Status Change Interrupt. It
5299 + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
5300 + * is a Device to Host Mode transition or a Host Mode to Device
5303 + * This only occurs when the cable is connected/removed from the PHY
5306 + * @param _core_if Programming view of DWC_otg controller.
5308 +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t *_core_if)
5310 + uint32_t count = 0;
5312 + gintsts_data_t gintsts = { .d32 = 0 };
5313 + gintmsk_data_t gintmsk = { .d32 = 0 };
5314 + gotgctl_data_t gotgctl = { .d32 = 0 };
5317 + * Need to disable SOF interrupt immediately. If switching from device
5318 + * to host, the PCD interrupt handler won't handle the interrupt if
5319 + * host mode is already set. The HCD interrupt handler won't get
5320 + * called if the HCD state is HALT. This means that the interrupt does
5321 + * not get handled and Linux complains loudly.
5323 + gintmsk.b.sofintr = 1;
5324 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
5326 + DWC_DEBUGPL(DBG_CIL, " ++Connector ID Status Change Interrupt++ (%s)\n",
5327 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"));
5328 + gotgctl.d32 = dwc_read_reg32(&_core_if->core_global_regs->gotgctl);
5329 + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
5330 + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
5332 + /* B-Device connector (Device Mode) */
5333 + if (gotgctl.b.conidsts) {
5334 + /* Wait for switch to device mode. */
5335 + while (!dwc_otg_is_device_mode(_core_if) ){
5336 + DWC_PRINT("Waiting for Peripheral Mode, Mode=%s\n",
5337 + (dwc_otg_is_host_mode(_core_if)?"Host":"Peripheral"));
5339 + if (++count > 10000) *(uint32_t*)NULL=0;
5341 + _core_if->op_state = B_PERIPHERAL;
5342 + dwc_otg_core_init(_core_if);
5343 + dwc_otg_enable_global_interrupts(_core_if);
5344 + pcd_start( _core_if );
5346 + /* A-Device connector (Host Mode) */
5347 + while (!dwc_otg_is_host_mode(_core_if) ) {
5348 + DWC_PRINT("Waiting for Host Mode, Mode=%s\n",
5349 + (dwc_otg_is_host_mode(_core_if)?"Host":"Peripheral"));
5351 + if (++count > 10000) *(uint32_t*)NULL=0;
5353 + _core_if->op_state = A_HOST;
5355 + * Initialize the Core for Host mode.
5357 + dwc_otg_core_init(_core_if);
5358 + dwc_otg_enable_global_interrupts(_core_if);
5359 + hcd_start( _core_if );
5362 + /* Set flag and clear interrupt */
5363 + gintsts.b.conidstschng = 1;
5364 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5370 + * This interrupt indicates that a device is initiating the Session
5371 + * Request Protocol to request the host to turn on bus power so a new
5372 + * session can begin. The handler responds by turning on bus power. If
5373 + * the DWC_otg controller is in low power mode, the handler brings the
5374 + * controller out of low power mode before turning on bus power.
5376 + * @param _core_if Programming view of DWC_otg controller.
5378 +int32_t dwc_otg_handle_session_req_intr( dwc_otg_core_if_t *_core_if )
5380 +#ifndef DWC_HOST_ONLY // winder
5381 + hprt0_data_t hprt0;
5383 + gintsts_data_t gintsts;
5385 +#ifndef DWC_HOST_ONLY
5386 + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
5388 + if (dwc_otg_is_device_mode(_core_if) ) {
5389 + DWC_PRINT("SRP: Device mode\n");
5391 + DWC_PRINT("SRP: Host mode\n");
5393 + /* Turn on the port power bit. */
5394 + hprt0.d32 = dwc_otg_read_hprt0( _core_if );
5395 + hprt0.b.prtpwr = 1;
5396 + dwc_write_reg32(_core_if->host_if->hprt0, hprt0.d32);
5398 + /* Start the Connection timer. So a message can be displayed
5399 + * if connect does not occur within 10 seconds. */
5400 + hcd_session_start( _core_if );
5404 + /* Clear interrupt */
5406 + gintsts.b.sessreqintr = 1;
5407 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5413 + * This interrupt indicates that the DWC_otg controller has detected a
5414 + * resume or remote wakeup sequence. If the DWC_otg controller is in
5415 + * low power mode, the handler must brings the controller out of low
5416 + * power mode. The controller automatically begins resume
5417 + * signaling. The handler schedules a time to stop resume signaling.
5419 +int32_t dwc_otg_handle_wakeup_detected_intr( dwc_otg_core_if_t *_core_if )
5421 + gintsts_data_t gintsts;
5423 + DWC_DEBUGPL(DBG_ANY, "++Resume and Remote Wakeup Detected Interrupt++\n");
5425 + if (dwc_otg_is_device_mode(_core_if) ) {
5426 + dctl_data_t dctl = {.d32=0};
5427 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
5428 + dwc_read_reg32( &_core_if->dev_if->dev_global_regs->dsts));
5429 +#ifdef PARTIAL_POWER_DOWN
5430 + if (_core_if->hwcfg4.b.power_optimiz) {
5431 + pcgcctl_data_t power = {.d32=0};
5433 + power.d32 = dwc_read_reg32( _core_if->pcgcctl );
5434 + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n", power.d32);
5436 + power.b.stoppclk = 0;
5437 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5439 + power.b.pwrclmp = 0;
5440 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5442 + power.b.rstpdwnmodule = 0;
5443 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5446 + /* Clear the Remote Wakeup Signalling */
5447 + dctl.b.rmtwkupsig = 1;
5448 + dwc_modify_reg32( &_core_if->dev_if->dev_global_regs->dctl,
5451 + if (_core_if->pcd_cb && _core_if->pcd_cb->resume_wakeup) {
5452 + _core_if->pcd_cb->resume_wakeup( _core_if->pcd_cb->p );
5457 + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
5458 + * so that OPT tests pass with all PHYs).
5460 + hprt0_data_t hprt0 = {.d32=0};
5461 + pcgcctl_data_t pcgcctl = {.d32=0};
5462 + /* Restart the Phy Clock */
5463 + pcgcctl.b.stoppclk = 1;
5464 + dwc_modify_reg32(_core_if->pcgcctl, pcgcctl.d32, 0);
5467 + /* Now wait for 70 ms. */
5468 + hprt0.d32 = dwc_otg_read_hprt0( _core_if );
5469 + DWC_DEBUGPL(DBG_ANY,"Resume: HPRT0=%0x\n", hprt0.d32);
5471 + hprt0.b.prtres = 0; /* Resume */
5472 + dwc_write_reg32(_core_if->host_if->hprt0, hprt0.d32);
5473 + DWC_DEBUGPL(DBG_ANY,"Clear Resume: HPRT0=%0x\n", dwc_read_reg32(_core_if->host_if->hprt0));
5476 + /* Clear interrupt */
5478 + gintsts.b.wkupintr = 1;
5479 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5485 + * This interrupt indicates that a device has been disconnected from
5488 +int32_t dwc_otg_handle_disconnect_intr( dwc_otg_core_if_t *_core_if)
5490 + gintsts_data_t gintsts;
5492 + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
5493 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"),
5494 + op_state_str(_core_if));
5496 +/** @todo Consolidate this if statement. */
5497 +#ifndef DWC_HOST_ONLY
5498 + if (_core_if->op_state == B_HOST) {
5499 + /* If in device mode Disconnect and stop the HCD, then
5500 + * start the PCD. */
5501 + hcd_disconnect( _core_if );
5502 + pcd_start( _core_if );
5503 + _core_if->op_state = B_PERIPHERAL;
5504 + } else if (dwc_otg_is_device_mode(_core_if)) {
5505 + gotgctl_data_t gotgctl = { .d32 = 0 };
5506 + gotgctl.d32 = dwc_read_reg32(&_core_if->core_global_regs->gotgctl);
5507 + if (gotgctl.b.hstsethnpen==1) {
5508 + /* Do nothing, if HNP in process the OTG
5509 + * interrupt "Host Negotiation Detected"
5510 + * interrupt will do the mode switch.
5512 + } else if (gotgctl.b.devhnpen == 0) {
5513 + /* If in device mode Disconnect and stop the HCD, then
5514 + * start the PCD. */
5515 + hcd_disconnect( _core_if );
5516 + pcd_start( _core_if );
5517 + _core_if->op_state = B_PERIPHERAL;
5519 + DWC_DEBUGPL(DBG_ANY,"!a_peripheral && !devhnpen\n");
5522 + if (_core_if->op_state == A_HOST) {
5523 + /* A-Cable still connected but device disconnected. */
5524 + hcd_disconnect( _core_if );
5528 +/* Without OTG, we should use the disconnect function!? winder added.*/
5529 +#if 1 // NO OTG, so host only!!
5530 + hcd_disconnect( _core_if );
5534 + gintsts.b.disconnect = 1;
5535 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5539 + * This interrupt indicates that SUSPEND state has been detected on
5542 + * For HNP the USB Suspend interrupt signals the change from
5543 + * "a_peripheral" to "a_host".
5545 + * When power management is enabled the core will be put in low power
5548 +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t *_core_if )
5551 + gintsts_data_t gintsts;
5553 + //805141:<IFTW-fchang>.removed DWC_DEBUGPL(DBG_ANY,"USB SUSPEND\n");
5555 + if (dwc_otg_is_device_mode( _core_if ) ) {
5556 + /* Check the Device status register to determine if the Suspend
5557 + * state is active. */
5558 + dsts.d32 = dwc_read_reg32( &_core_if->dev_if->dev_global_regs->dsts);
5559 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
5560 + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
5561 + "HWCFG4.power Optimize=%d\n",
5562 + dsts.b.suspsts, _core_if->hwcfg4.b.power_optimiz);
5565 +#ifdef PARTIAL_POWER_DOWN
5566 +/** @todo Add a module parameter for power management. */
5568 + if (dsts.b.suspsts && _core_if->hwcfg4.b.power_optimiz) {
5569 + pcgcctl_data_t power = {.d32=0};
5570 + DWC_DEBUGPL(DBG_CIL, "suspend\n");
5572 + power.b.pwrclmp = 1;
5573 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5575 + power.b.rstpdwnmodule = 1;
5576 + dwc_modify_reg32( _core_if->pcgcctl, 0, power.d32);
5578 + power.b.stoppclk = 1;
5579 + dwc_modify_reg32( _core_if->pcgcctl, 0, power.d32);
5582 + DWC_DEBUGPL(DBG_ANY,"disconnect?\n");
5585 + /* PCD callback for suspend. */
5586 + pcd_suspend(_core_if);
5588 + if (_core_if->op_state == A_PERIPHERAL) {
5589 + DWC_DEBUGPL(DBG_ANY,"a_peripheral->a_host\n");
5590 + /* Clear the a_peripheral flag, back to a_host. */
5591 + pcd_stop( _core_if );
5592 + hcd_start( _core_if );
5593 + _core_if->op_state = A_HOST;
5597 + /* Clear interrupt */
5599 + gintsts.b.usbsuspend = 1;
5600 + dwc_write_reg32( &_core_if->core_global_regs->gintsts, gintsts.d32);
5607 + * This function returns the Core Interrupt register.
5609 +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t *_core_if)
5611 + gintsts_data_t gintsts;
5612 + gintmsk_data_t gintmsk;
5613 + gintmsk_data_t gintmsk_common = {.d32=0};
5614 + gintmsk_common.b.wkupintr = 1;
5615 + gintmsk_common.b.sessreqintr = 1;
5616 + gintmsk_common.b.conidstschng = 1;
5617 + gintmsk_common.b.otgintr = 1;
5618 + gintmsk_common.b.modemismatch = 1;
5619 + gintmsk_common.b.disconnect = 1;
5620 + gintmsk_common.b.usbsuspend = 1;
5621 + /** @todo: The port interrupt occurs while in device
5622 + * mode. Added code to CIL to clear the interrupt for now!
5624 + gintmsk_common.b.portintr = 1;
5626 + gintsts.d32 = dwc_read_reg32(&_core_if->core_global_regs->gintsts);
5627 + gintmsk.d32 = dwc_read_reg32(&_core_if->core_global_regs->gintmsk);
5629 + /* if any common interrupts set */
5630 + if (gintsts.d32 & gintmsk_common.d32) {
5631 + DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
5632 + gintsts.d32, gintmsk.d32);
5636 + return ((gintsts.d32 & gintmsk.d32 ) & gintmsk_common.d32);
5641 + * Common interrupt handler.
5643 + * The common interrupts are those that occur in both Host and Device mode.
5644 + * This handler handles the following interrupts:
5645 + * - Mode Mismatch Interrupt
5646 + * - Disconnect Interrupt
5648 + * - Connector ID Status Change Interrupt
5649 + * - Session Request Interrupt.
5650 + * - Resume / Remote Wakeup Detected Interrupt.
5653 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if )
5656 + gintsts_data_t gintsts;
5658 + gintsts.d32 = dwc_otg_read_common_intr(_core_if);
5660 + if (gintsts.b.modemismatch) {
5661 + retval |= dwc_otg_handle_mode_mismatch_intr( _core_if );
5663 + if (gintsts.b.otgintr) {
5664 + retval |= dwc_otg_handle_otg_intr( _core_if );
5666 + if (gintsts.b.conidstschng) {
5667 + retval |= dwc_otg_handle_conn_id_status_change_intr( _core_if );
5669 + if (gintsts.b.disconnect) {
5670 + retval |= dwc_otg_handle_disconnect_intr( _core_if );
5672 + if (gintsts.b.sessreqintr) {
5673 + retval |= dwc_otg_handle_session_req_intr( _core_if );
5675 + if (gintsts.b.wkupintr) {
5676 + retval |= dwc_otg_handle_wakeup_detected_intr( _core_if );
5678 + if (gintsts.b.usbsuspend) {
5679 + retval |= dwc_otg_handle_usb_suspend_intr( _core_if );
5681 + if (gintsts.b.portintr && dwc_otg_is_device_mode(_core_if)) {
5682 + /* The port interrupt occurs while in device mode with HPRT0
5683 + * Port Enable/Disable.
5686 + gintsts.b.portintr = 1;
5687 + dwc_write_reg32(&_core_if->core_global_regs->gintsts,
5695 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.c
5697 +/* ==========================================================================
5698 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.c $
5699 + * $Revision: 1.1.1.1 $
5700 + * $Date: 2009-04-17 06:15:34 $
5701 + * $Change: 631780 $
5703 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
5704 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
5705 + * otherwise expressly agreed to in writing between Synopsys and you.
5707 + * The Software IS NOT an item of Licensed Software or Licensed Product under
5708 + * any End User Software License Agreement or Agreement for Licensed Product
5709 + * with Synopsys or any supplement thereto. You are permitted to use and
5710 + * redistribute this Software in source and binary forms, with or without
5711 + * modification, provided that redistributions of source code must retain this
5712 + * notice. You may not view, use, disclose, copy or distribute this file or
5713 + * any information contained herein except pursuant to this license grant from
5714 + * Synopsys. If you do not agree with this notice, including the disclaimer
5715 + * below, then you are not authorized to use the Software.
5717 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
5718 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5719 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5720 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
5721 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5722 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5723 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5724 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5725 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5726 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
5728 + * ========================================================================== */
5731 + * The dwc_otg_driver module provides the initialization and cleanup entry
5732 + * points for the DWC_otg driver. This module will be dynamically installed
5733 + * after Linux is booted using the insmod command. When the module is
5734 + * installed, the dwc_otg_init function is called. When the module is
5735 + * removed (using rmmod), the dwc_otg_cleanup function is called.
5737 + * This module also defines a data structure for the dwc_otg_driver, which is
5738 + * used in conjunction with the standard ARM lm_device structure. These
5739 + * structures allow the OTG driver to comply with the standard Linux driver
5740 + * model in which devices and drivers are registered with a bus driver. This
5741 + * has the benefit that Linux can expose attributes of the driver and device
5742 + * in its special sysfs file system. Users can then read or write files in
5743 + * this file system to perform diagnostics on the driver components or the
5747 +#include <linux/kernel.h>
5748 +#include <linux/module.h>
5749 +#include <linux/moduleparam.h>
5750 +#include <linux/init.h>
5751 +#include <linux/gpio.h>
5753 +#include <linux/device.h>
5754 +#include <linux/platform_device.h>
5756 +#include <linux/errno.h>
5757 +#include <linux/types.h>
5758 +#include <linux/stat.h> /* permission constants */
5759 +#include <linux/irq.h>
5760 +#include <asm/io.h>
5762 +#include "dwc_otg_plat.h"
5763 +#include "dwc_otg_attr.h"
5764 +#include "dwc_otg_driver.h"
5765 +#include "dwc_otg_cil.h"
5766 +#include "dwc_otg_cil_ifx.h"
5768 +// #include "dwc_otg_pcd.h" // device
5769 +#include "dwc_otg_hcd.h" // host
5771 +#include "dwc_otg_ifx.h" // for Infineon platform specific.
5773 +#define DWC_DRIVER_VERSION "2.60a 22-NOV-2006"
5774 +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
5776 +const char dwc_driver_name[] = "dwc_otg";
5778 +static unsigned long dwc_iomem_base = IFX_USB_IOMEM_BASE;
5779 +int dwc_irq = LTQ_USB_INT;
5780 +//int dwc_irq = 54;
5781 +//int dwc_irq = IFXMIPS_USB_OC_INT;
5783 +extern int ifx_usb_hc_init(unsigned long base_addr, int irq);
5784 +extern void ifx_usb_hc_remove(void);
5786 +/*-------------------------------------------------------------------------*/
5787 +/* Encapsulate the module parameter settings */
5789 +static dwc_otg_core_params_t dwc_otg_module_params = {
5793 + .dma_burst_size = -1,
5795 + .host_support_fs_ls_low_power = -1,
5796 + .host_ls_low_power_phy_clk = -1,
5797 + .enable_dynamic_fifo = -1,
5798 + .data_fifo_size = -1,
5799 + .dev_rx_fifo_size = -1,
5800 + .dev_nperio_tx_fifo_size = -1,
5801 + .dev_perio_tx_fifo_size = /* dev_perio_tx_fifo_size_1 */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* 15 */
5802 + .host_rx_fifo_size = -1,
5803 + .host_nperio_tx_fifo_size = -1,
5804 + .host_perio_tx_fifo_size = -1,
5805 + .max_transfer_size = -1,
5806 + .max_packet_count = -1,
5807 + .host_channels = -1,
5808 + .dev_endpoints = -1,
5810 + .phy_utmi_width = -1,
5811 + .phy_ulpi_ddr = -1,
5812 + .phy_ulpi_ext_vbus = -1,
5816 + .en_multiple_tx_fifo = -1,
5817 + .dev_tx_fifo_size = { /* dev_tx_fifo_size */
5818 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
5821 + .tx_thr_length = -1,
5822 + .rx_thr_length = -1,
5826 + * This function shows the Driver Version.
5828 +static ssize_t version_show(struct device_driver *dev, char *buf)
5830 + return snprintf(buf, sizeof(DWC_DRIVER_VERSION)+2,"%s\n",
5831 + DWC_DRIVER_VERSION);
5833 +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
5836 + * Global Debug Level Mask.
5838 +uint32_t g_dbg_lvl = 0xff; /* OFF */
5841 + * This function shows the driver Debug Level.
5843 +static ssize_t dbg_level_show(struct device_driver *_drv, char *_buf)
5845 + return sprintf(_buf, "0x%0x\n", g_dbg_lvl);
5848 + * This function stores the driver Debug Level.
5850 +static ssize_t dbg_level_store(struct device_driver *_drv, const char *_buf,
5853 + g_dbg_lvl = simple_strtoul(_buf, NULL, 16);
5856 +static DRIVER_ATTR(debuglevel, S_IRUGO|S_IWUSR, dbg_level_show, dbg_level_store);
5859 + * This function is called during module intialization to verify that
5860 + * the module parameters are in a valid state.
5862 +static int check_parameters(dwc_otg_core_if_t *core_if)
5867 +/* Checks if the parameter is outside of its valid range of values */
5868 +#define DWC_OTG_PARAM_TEST(_param_,_low_,_high_) \
5869 + ((dwc_otg_module_params._param_ < (_low_)) || \
5870 + (dwc_otg_module_params._param_ > (_high_)))
5872 +/* If the parameter has been set by the user, check that the parameter value is
5873 + * within the value range of values. If not, report a module error. */
5874 +#define DWC_OTG_PARAM_ERR(_param_,_low_,_high_,_string_) \
5876 + if (dwc_otg_module_params._param_ != -1) { \
5877 + if (DWC_OTG_PARAM_TEST(_param_,(_low_),(_high_))) { \
5878 + DWC_ERROR("`%d' invalid for parameter `%s'\n", \
5879 + dwc_otg_module_params._param_, _string_); \
5880 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
5886 + DWC_OTG_PARAM_ERR(opt,0,1,"opt");
5887 + DWC_OTG_PARAM_ERR(otg_cap,0,2,"otg_cap");
5888 + DWC_OTG_PARAM_ERR(dma_enable,0,1,"dma_enable");
5889 + DWC_OTG_PARAM_ERR(speed,0,1,"speed");
5890 + DWC_OTG_PARAM_ERR(host_support_fs_ls_low_power,0,1,"host_support_fs_ls_low_power");
5891 + DWC_OTG_PARAM_ERR(host_ls_low_power_phy_clk,0,1,"host_ls_low_power_phy_clk");
5892 + DWC_OTG_PARAM_ERR(enable_dynamic_fifo,0,1,"enable_dynamic_fifo");
5893 + DWC_OTG_PARAM_ERR(data_fifo_size,32,32768,"data_fifo_size");
5894 + DWC_OTG_PARAM_ERR(dev_rx_fifo_size,16,32768,"dev_rx_fifo_size");
5895 + DWC_OTG_PARAM_ERR(dev_nperio_tx_fifo_size,16,32768,"dev_nperio_tx_fifo_size");
5896 + DWC_OTG_PARAM_ERR(host_rx_fifo_size,16,32768,"host_rx_fifo_size");
5897 + DWC_OTG_PARAM_ERR(host_nperio_tx_fifo_size,16,32768,"host_nperio_tx_fifo_size");
5898 + DWC_OTG_PARAM_ERR(host_perio_tx_fifo_size,16,32768,"host_perio_tx_fifo_size");
5899 + DWC_OTG_PARAM_ERR(max_transfer_size,2047,524288,"max_transfer_size");
5900 + DWC_OTG_PARAM_ERR(max_packet_count,15,511,"max_packet_count");
5901 + DWC_OTG_PARAM_ERR(host_channels,1,16,"host_channels");
5902 + DWC_OTG_PARAM_ERR(dev_endpoints,1,15,"dev_endpoints");
5903 + DWC_OTG_PARAM_ERR(phy_type,0,2,"phy_type");
5904 + DWC_OTG_PARAM_ERR(phy_ulpi_ddr,0,1,"phy_ulpi_ddr");
5905 + DWC_OTG_PARAM_ERR(phy_ulpi_ext_vbus,0,1,"phy_ulpi_ext_vbus");
5906 + DWC_OTG_PARAM_ERR(i2c_enable,0,1,"i2c_enable");
5907 + DWC_OTG_PARAM_ERR(ulpi_fs_ls,0,1,"ulpi_fs_ls");
5908 + DWC_OTG_PARAM_ERR(ts_dline,0,1,"ts_dline");
5910 + if (dwc_otg_module_params.dma_burst_size != -1) {
5911 + if (DWC_OTG_PARAM_TEST(dma_burst_size,1,1) &&
5912 + DWC_OTG_PARAM_TEST(dma_burst_size,4,4) &&
5913 + DWC_OTG_PARAM_TEST(dma_burst_size,8,8) &&
5914 + DWC_OTG_PARAM_TEST(dma_burst_size,16,16) &&
5915 + DWC_OTG_PARAM_TEST(dma_burst_size,32,32) &&
5916 + DWC_OTG_PARAM_TEST(dma_burst_size,64,64) &&
5917 + DWC_OTG_PARAM_TEST(dma_burst_size,128,128) &&
5918 + DWC_OTG_PARAM_TEST(dma_burst_size,256,256))
5920 + DWC_ERROR("`%d' invalid for parameter `dma_burst_size'\n",
5921 + dwc_otg_module_params.dma_burst_size);
5922 + dwc_otg_module_params.dma_burst_size = 32;
5927 + if (dwc_otg_module_params.phy_utmi_width != -1) {
5928 + if (DWC_OTG_PARAM_TEST(phy_utmi_width,8,8) &&
5929 + DWC_OTG_PARAM_TEST(phy_utmi_width,16,16))
5931 + DWC_ERROR("`%d' invalid for parameter `phy_utmi_width'\n",
5932 + dwc_otg_module_params.phy_utmi_width);
5933 + //dwc_otg_module_params.phy_utmi_width = 16;
5934 + dwc_otg_module_params.phy_utmi_width = 8;
5939 + for (i=0; i<15; i++) {
5940 + /** @todo should be like above */
5941 + //DWC_OTG_PARAM_ERR(dev_perio_tx_fifo_size[i],4,768,"dev_perio_tx_fifo_size");
5942 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
5943 + if (DWC_OTG_PARAM_TEST(dev_perio_tx_fifo_size[i],4,768)) {
5944 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
5945 + dwc_otg_module_params.dev_perio_tx_fifo_size[i], "dev_perio_tx_fifo_size", i);
5946 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
5952 + DWC_OTG_PARAM_ERR(en_multiple_tx_fifo, 0, 1, "en_multiple_tx_fifo");
5953 + for (i = 0; i < 15; i++) {
5954 + /** @todo should be like above */
5955 + //DWC_OTG_PARAM_ERR(dev_tx_fifo_size[i],4,768,"dev_tx_fifo_size");
5956 + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
5957 + if (DWC_OTG_PARAM_TEST(dev_tx_fifo_size[i], 4, 768)) {
5958 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
5959 + dwc_otg_module_params.dev_tx_fifo_size[i],
5960 + "dev_tx_fifo_size", i);
5961 + dwc_otg_module_params.dev_tx_fifo_size[i] =
5962 + dwc_param_dev_tx_fifo_size_default;
5967 + DWC_OTG_PARAM_ERR(thr_ctl, 0, 7, "thr_ctl");
5968 + DWC_OTG_PARAM_ERR(tx_thr_length, 8, 128, "tx_thr_length");
5969 + DWC_OTG_PARAM_ERR(rx_thr_length, 8, 128, "rx_thr_length");
5971 + /* At this point, all module parameters that have been set by the user
5972 + * are valid, and those that have not are left unset. Now set their
5973 + * default values and/or check the parameters against the hardware
5974 + * configurations of the OTG core. */
5978 +/* This sets the parameter to the default value if it has not been set by the
5980 +#define DWC_OTG_PARAM_SET_DEFAULT(_param_) \
5982 + int changed = 1; \
5983 + if (dwc_otg_module_params._param_ == -1) { \
5985 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
5990 +/* This checks the macro agains the hardware configuration to see if it is
5991 + * valid. It is possible that the default value could be invalid. In this
5992 + * case, it will report a module error if the user touched the parameter.
5993 + * Otherwise it will adjust the value without any error. */
5994 +#define DWC_OTG_PARAM_CHECK_VALID(_param_,_str_,_is_valid_,_set_valid_) \
5996 + int changed = DWC_OTG_PARAM_SET_DEFAULT(_param_); \
5998 + if (!(_is_valid_)) { \
6000 + DWC_ERROR("`%d' invalid for parameter `%s'. Check HW configuration.\n", dwc_otg_module_params._param_,_str_); \
6003 + dwc_otg_module_params._param_ = (_set_valid_); \
6009 + retval += DWC_OTG_PARAM_CHECK_VALID(otg_cap,"otg_cap",
6013 + switch (dwc_otg_module_params.otg_cap) {
6014 + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
6015 + if (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) valid = 0;
6017 + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
6018 + if ((core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) &&
6019 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) &&
6020 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) &&
6021 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST))
6026 + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
6027 + /* always valid */
6032 + (((core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) ||
6033 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) ||
6034 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
6035 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
6036 + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
6037 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE));
6039 + retval += DWC_OTG_PARAM_CHECK_VALID(dma_enable,"dma_enable",
6040 + ((dwc_otg_module_params.dma_enable == 1) && (core_if->hwcfg2.b.architecture == 0)) ? 0 : 1,
6043 + retval += DWC_OTG_PARAM_CHECK_VALID(opt,"opt",
6047 + DWC_OTG_PARAM_SET_DEFAULT(dma_burst_size);
6049 + retval += DWC_OTG_PARAM_CHECK_VALID(host_support_fs_ls_low_power,
6050 + "host_support_fs_ls_low_power",
6053 + retval += DWC_OTG_PARAM_CHECK_VALID(enable_dynamic_fifo,
6054 + "enable_dynamic_fifo",
6055 + ((dwc_otg_module_params.enable_dynamic_fifo == 0) ||
6056 + (core_if->hwcfg2.b.dynamic_fifo == 1)), 0);
6059 + retval += DWC_OTG_PARAM_CHECK_VALID(data_fifo_size,
6061 + (dwc_otg_module_params.data_fifo_size <= core_if->hwcfg3.b.dfifo_depth),
6062 + core_if->hwcfg3.b.dfifo_depth);
6064 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_rx_fifo_size,
6065 + "dev_rx_fifo_size",
6066 + (dwc_otg_module_params.dev_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
6067 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
6069 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_nperio_tx_fifo_size,
6070 + "dev_nperio_tx_fifo_size",
6071 + (dwc_otg_module_params.dev_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
6072 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
6074 + retval += DWC_OTG_PARAM_CHECK_VALID(host_rx_fifo_size,
6075 + "host_rx_fifo_size",
6076 + (dwc_otg_module_params.host_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
6077 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
6080 + retval += DWC_OTG_PARAM_CHECK_VALID(host_nperio_tx_fifo_size,
6081 + "host_nperio_tx_fifo_size",
6082 + (dwc_otg_module_params.host_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
6083 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
6085 + retval += DWC_OTG_PARAM_CHECK_VALID(host_perio_tx_fifo_size,
6086 + "host_perio_tx_fifo_size",
6087 + (dwc_otg_module_params.host_perio_tx_fifo_size <= ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16))),
6088 + ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16)));
6090 + retval += DWC_OTG_PARAM_CHECK_VALID(max_transfer_size,
6091 + "max_transfer_size",
6092 + (dwc_otg_module_params.max_transfer_size < (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))),
6093 + ((1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1));
6095 + retval += DWC_OTG_PARAM_CHECK_VALID(max_packet_count,
6096 + "max_packet_count",
6097 + (dwc_otg_module_params.max_packet_count < (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))),
6098 + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1));
6100 + retval += DWC_OTG_PARAM_CHECK_VALID(host_channels,
6102 + (dwc_otg_module_params.host_channels <= (core_if->hwcfg2.b.num_host_chan + 1)),
6103 + (core_if->hwcfg2.b.num_host_chan + 1));
6105 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_endpoints,
6107 + (dwc_otg_module_params.dev_endpoints <= (core_if->hwcfg2.b.num_dev_ep)),
6108 + core_if->hwcfg2.b.num_dev_ep);
6111 + * Define the following to disable the FS PHY Hardware checking. This is for
6112 + * internal testing only.
6114 + * #define NO_FS_PHY_HW_CHECKS
6117 +#ifdef NO_FS_PHY_HW_CHECKS
6118 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
6119 + "phy_type", 1, 0);
6121 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
6125 + if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_UTMI) &&
6126 + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
6127 + (core_if->hwcfg2.b.hs_phy_type == 3)))
6131 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_ULPI) &&
6132 + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
6133 + (core_if->hwcfg2.b.hs_phy_type == 3)))
6137 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) &&
6138 + (core_if->hwcfg2.b.fs_phy_type == 1))
6145 + int set = DWC_PHY_TYPE_PARAM_FS;
6146 + if (core_if->hwcfg2.b.hs_phy_type) {
6147 + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
6148 + (core_if->hwcfg2.b.hs_phy_type == 1)) {
6149 + set = DWC_PHY_TYPE_PARAM_UTMI;
6152 + set = DWC_PHY_TYPE_PARAM_ULPI;
6159 + retval += DWC_OTG_PARAM_CHECK_VALID(speed,"speed",
6160 + (dwc_otg_module_params.speed == 0) && (dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1,
6161 + dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
6163 + retval += DWC_OTG_PARAM_CHECK_VALID(host_ls_low_power_phy_clk,
6164 + "host_ls_low_power_phy_clk",
6165 + ((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),
6166 + ((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));
6168 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ddr);
6169 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ext_vbus);
6170 + DWC_OTG_PARAM_SET_DEFAULT(phy_utmi_width);
6171 + DWC_OTG_PARAM_SET_DEFAULT(ulpi_fs_ls);
6172 + DWC_OTG_PARAM_SET_DEFAULT(ts_dline);
6174 +#ifdef NO_FS_PHY_HW_CHECKS
6175 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
6176 + "i2c_enable", 1, 0);
6178 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
6180 + (dwc_otg_module_params.i2c_enable == 1) && (core_if->hwcfg3.b.i2c == 0) ? 0 : 1,
6184 + for (i=0; i<16; i++) {
6189 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] == -1) {
6191 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
6193 + if (!(dwc_otg_module_params.dev_perio_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
6195 + 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);
6198 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
6203 + retval += DWC_OTG_PARAM_CHECK_VALID(en_multiple_tx_fifo,
6204 + "en_multiple_tx_fifo",
6205 + ((dwc_otg_module_params.en_multiple_tx_fifo == 1) &&
6206 + (core_if->hwcfg4.b.ded_fifo_en == 0)) ? 0 : 1, 0);
6208 + for (i = 0; i < 16; i++) {
6211 + if (dwc_otg_module_params.dev_tx_fifo_size[i] == -1) {
6213 + dwc_otg_module_params.dev_tx_fifo_size[i] =
6214 + dwc_param_dev_tx_fifo_size_default;
6216 + if (!(dwc_otg_module_params.dev_tx_fifo_size[i] <=
6217 + (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
6219 + DWC_ERROR("%d' invalid for parameter `dev_perio_fifo_size_%d'."
6220 + "Check HW configuration.\n",dwc_otg_module_params.dev_tx_fifo_size[i],i);
6223 + dwc_otg_module_params.dev_tx_fifo_size[i] =
6224 + dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
6228 + DWC_OTG_PARAM_SET_DEFAULT(thr_ctl);
6229 + DWC_OTG_PARAM_SET_DEFAULT(tx_thr_length);
6230 + DWC_OTG_PARAM_SET_DEFAULT(rx_thr_length);
6232 +} // check_parameters
6236 + * This function is the top level interrupt handler for the Common
6237 + * (Device and host modes) interrupts.
6239 +static irqreturn_t dwc_otg_common_irq(int _irq, void *_dev)
6241 + dwc_otg_device_t *otg_dev = _dev;
6242 + int32_t retval = IRQ_NONE;
6244 + retval = dwc_otg_handle_common_intr( otg_dev->core_if );
6246 + mask_and_ack_ifx_irq (_irq);
6248 + return IRQ_RETVAL(retval);
6253 + * This function is called when a DWC_OTG device is unregistered with the
6254 + * dwc_otg_driver. This happens, for example, when the rmmod command is
6255 + * executed. The device may or may not be electrically present. If it is
6256 + * present, the driver stops device processing. Any resources used on behalf
6257 + * of this device are freed.
6262 +dwc_otg_driver_remove(struct platform_device *_dev)
6264 + //dwc_otg_device_t *otg_dev = dev_get_drvdata(&_dev->dev);
6265 + dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
6267 + DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, _dev);
6269 + if (otg_dev == NULL) {
6270 + /* Memory allocation for the dwc_otg_device failed. */
6277 + if (otg_dev->common_irq_installed) {
6278 + free_irq( otg_dev->irq, otg_dev );
6281 +#ifndef DWC_DEVICE_ONLY
6282 + if (otg_dev->hcd != NULL) {
6283 + dwc_otg_hcd_remove(&_dev->dev);
6286 + printk("after removehcd\n");
6288 +// Note: Integrate HOST and DEVICE(Gadget) is not planned yet.
6289 +#ifndef DWC_HOST_ONLY
6290 + if (otg_dev->pcd != NULL) {
6291 + dwc_otg_pcd_remove(otg_dev);
6294 + if (otg_dev->core_if != NULL) {
6295 + dwc_otg_cil_remove( otg_dev->core_if );
6297 + printk("after removecil\n");
6300 + * Remove the device attributes
6302 + dwc_otg_attr_remove(&_dev->dev);
6303 + printk("after removeattr\n");
6306 + * Return the memory.
6308 + if (otg_dev->base != NULL) {
6309 + iounmap(otg_dev->base);
6311 + if (otg_dev->phys_addr != 0) {
6312 + release_mem_region(otg_dev->phys_addr, otg_dev->base_len);
6317 + * Clear the drvdata pointer.
6319 + //dev_set_drvdata(&_dev->dev, 0);
6320 + platform_set_drvdata(_dev, 0);
6325 + * This function is called when an DWC_OTG device is bound to a
6326 + * dwc_otg_driver. It creates the driver components required to
6327 + * control the device (CIL, HCD, and PCD) and it initializes the
6328 + * device. The driver components are stored in a dwc_otg_device
6329 + * structure. A reference to the dwc_otg_device is saved in the
6330 + * lm_device. This allows the driver to access the dwc_otg_device
6331 + * structure on subsequent calls to driver methods for this device.
6335 +static int __devinit
6336 +dwc_otg_driver_probe(struct platform_device *_dev)
6339 + dwc_otg_device_t *dwc_otg_device;
6340 + int pin = (int)_dev->dev.platform_data;
6342 + struct resource *res;
6343 + gusbcfg_data_t usbcfg = {.d32 = 0};
6348 + gpio_request(pin, "usb_power");
6349 + gpio_direction_output(pin, 1);
6350 + gpio_set_value(pin, 1);
6351 + gpio_export(pin, 0);
6353 + dev_dbg(&_dev->dev, "dwc_otg_driver_probe (%p)\n", _dev);
6355 + dwc_otg_device = kmalloc(sizeof(dwc_otg_device_t), GFP_KERNEL);
6356 + if (dwc_otg_device == 0) {
6357 + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
6361 + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
6362 + dwc_otg_device->reg_offset = 0xFFFFFFFF;
6365 + * Retrieve the memory and IRQ resources.
6367 + dwc_otg_device->irq = platform_get_irq(_dev, 0);
6368 + if (dwc_otg_device->irq == 0) {
6369 + dev_err(&_dev->dev, "no device irq\n");
6373 + dev_dbg(&_dev->dev, "OTG - device irq: %d\n", dwc_otg_device->irq);
6374 + res = platform_get_resource(_dev, IORESOURCE_MEM, 0);
6375 + if (res == NULL) {
6376 + dev_err(&_dev->dev, "no CSR address\n");
6380 + dev_dbg(&_dev->dev, "OTG - ioresource_mem start0x%08x: end:0x%08x\n",
6381 + (unsigned)res->start, (unsigned)res->end);
6382 + dwc_otg_device->phys_addr = res->start;
6383 + dwc_otg_device->base_len = res->end - res->start + 1;
6384 + if (request_mem_region(dwc_otg_device->phys_addr, dwc_otg_device->base_len,
6385 + dwc_driver_name) == NULL) {
6386 + dev_err(&_dev->dev, "request_mem_region failed\n");
6392 + * Map the DWC_otg Core memory into virtual address space.
6394 + dwc_otg_device->base = ioremap_nocache(dwc_otg_device->phys_addr, dwc_otg_device->base_len);
6395 + if (dwc_otg_device->base == NULL) {
6396 + dev_err(&_dev->dev, "ioremap() failed\n");
6400 + dev_dbg(&_dev->dev, "mapped base=0x%08x\n", (unsigned)dwc_otg_device->base);
6403 + * Attempt to ensure this device is really a DWC_otg Controller.
6404 + * Read and verify the SNPSID register contents. The value should be
6405 + * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
6407 + snpsid = dwc_read_reg32((uint32_t *)((uint8_t *)dwc_otg_device->base + 0x40));
6408 + if ((snpsid & 0xFFFFF000) != 0x4F542000) {
6409 + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n", snpsid);
6415 + * Initialize driver data to point to the global DWC_otg
6416 + * Device structure.
6418 + platform_set_drvdata(_dev, dwc_otg_device);
6419 + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
6420 + dwc_otg_device->core_if = dwc_otg_cil_init( dwc_otg_device->base, &dwc_otg_module_params);
6421 + if (dwc_otg_device->core_if == 0) {
6422 + dev_err(&_dev->dev, "CIL initialization failed!\n");
6428 + * Validate parameter values.
6430 + if (check_parameters(dwc_otg_device->core_if) != 0) {
6435 + /* Added for PLB DMA phys virt mapping */
6436 + //dwc_otg_device->core_if->phys_addr = dwc_otg_device->phys_addr;
6438 + * Create Device Attributes in sysfs
6440 + dwc_otg_attr_create (&_dev->dev);
6443 + * Disable the global interrupt until all the interrupt
6444 + * handlers are installed.
6446 + dwc_otg_disable_global_interrupts( dwc_otg_device->core_if );
6448 + * Install the interrupt handler for the common interrupts before
6449 + * enabling common interrupts in core_init below.
6451 + DWC_DEBUGPL( DBG_CIL, "registering (common) handler for irq%d\n", dwc_otg_device->irq);
6453 + retval = request_irq((unsigned int)dwc_otg_device->irq, dwc_otg_common_irq,
6454 + //SA_INTERRUPT|SA_SHIRQ, "dwc_otg", (void *)dwc_otg_device );
6455 + IRQF_SHARED, "dwc_otg", (void *)dwc_otg_device );
6456 + //IRQF_DISABLED, "dwc_otg", (void *)dwc_otg_device );
6457 + if (retval != 0) {
6458 + DWC_ERROR("request of irq%d failed retval: %d\n", dwc_otg_device->irq, retval);
6462 + dwc_otg_device->common_irq_installed = 1;
6466 + * Initialize the DWC_otg core.
6468 + dwc_otg_core_init( dwc_otg_device->core_if );
6471 +#ifndef DWC_HOST_ONLY // otg device mode. (gadget.)
6473 + * Initialize the PCD
6475 + retval = dwc_otg_pcd_init(dwc_otg_device);
6476 + if (retval != 0) {
6477 + DWC_ERROR("dwc_otg_pcd_init failed\n");
6478 + dwc_otg_device->pcd = NULL;
6481 +#endif // DWC_HOST_ONLY
6483 +#ifndef DWC_DEVICE_ONLY // otg host mode. (HCD)
6485 + * Initialize the HCD
6488 + /* force_host_mode */
6489 + usbcfg.d32 = dwc_read_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg);
6490 + usbcfg.b.force_host_mode = 1;
6491 + dwc_write_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg, usbcfg.d32);
6493 + retval = dwc_otg_hcd_init(&_dev->dev, dwc_otg_device);
6494 + if (retval != 0) {
6495 + DWC_ERROR("dwc_otg_hcd_init failed\n");
6496 + dwc_otg_device->hcd = NULL;
6499 +#endif // DWC_DEVICE_ONLY
6502 + * Enable the global interrupt after all the interrupt
6503 + * handlers are installed.
6505 + dwc_otg_enable_global_interrupts( dwc_otg_device->core_if );
6507 + usbcfg.d32 = dwc_read_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg);
6508 + usbcfg.b.force_host_mode = 0;
6509 + dwc_write_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg, usbcfg.d32);
6516 + dwc_otg_driver_remove(_dev);
6521 + * This structure defines the methods to be called by a bus driver
6522 + * during the lifecycle of a device on that bus. Both drivers and
6523 + * devices are registered with a bus driver. The bus driver matches
6524 + * devices to drivers based on information in the device and driver
6527 + * The probe function is called when the bus driver matches a device
6528 + * to this driver. The remove function is called when a device is
6529 + * unregistered with the bus driver.
6531 +struct platform_driver dwc_otg_driver = {
6532 + .probe = dwc_otg_driver_probe,
6533 + .remove = dwc_otg_driver_remove,
6534 +// .suspend = dwc_otg_driver_suspend,
6535 +// .resume = dwc_otg_driver_resume,
6537 + .name = dwc_driver_name,
6538 + .owner = THIS_MODULE,
6541 +EXPORT_SYMBOL(dwc_otg_driver);
6544 + * This function is called when the dwc_otg_driver is installed with the
6545 + * insmod command. It registers the dwc_otg_driver structure with the
6546 + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
6547 + * to be called. In addition, the bus driver will automatically expose
6548 + * attributes defined for the device and driver in the special sysfs file
6553 +static int __init dwc_otg_init(void)
6557 + printk(KERN_INFO "%s: version %s\n", dwc_driver_name, DWC_DRIVER_VERSION);
6560 + retval = ifx_usb_hc_init(dwc_iomem_base, dwc_irq);
6563 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6566 + dwc_otg_power_on(); // ifx only!!
6569 + retval = platform_driver_register(&dwc_otg_driver);
6572 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6576 + retval = driver_create_file(&dwc_otg_driver.driver, &driver_attr_version);
6579 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6582 + retval = driver_create_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
6585 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6592 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
6594 + driver_unregister(&dwc_otg_driver.driver);
6596 + ifx_usb_hc_remove();
6599 +module_init(dwc_otg_init);
6602 + * This function is called when the driver is removed from the kernel
6603 + * with the rmmod command. The driver unregisters itself with its bus
6607 +static void __exit dwc_otg_cleanup(void)
6609 + printk(KERN_DEBUG "dwc_otg_cleanup()\n");
6611 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
6612 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
6614 + platform_driver_unregister(&dwc_otg_driver);
6615 + ifx_usb_hc_remove();
6617 + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
6619 +module_exit(dwc_otg_cleanup);
6621 +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
6622 +MODULE_AUTHOR("Synopsys Inc.");
6623 +MODULE_LICENSE("GPL");
6625 +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
6626 +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
6627 +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
6628 +MODULE_PARM_DESC(opt, "OPT Mode");
6629 +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
6630 +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
6631 +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int, 0444);
6632 +MODULE_PARM_DESC(dma_burst_size, "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
6633 +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
6634 +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
6635 +module_param_named(host_support_fs_ls_low_power, dwc_otg_module_params.host_support_fs_ls_low_power, int, 0444);
6636 +MODULE_PARM_DESC(host_support_fs_ls_low_power, "Support Low Power w/FS or LS 0=Support 1=Don't Support");
6637 +module_param_named(host_ls_low_power_phy_clk, dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
6638 +MODULE_PARM_DESC(host_ls_low_power_phy_clk, "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
6639 +module_param_named(enable_dynamic_fifo, dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
6640 +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
6641 +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int, 0444);
6642 +MODULE_PARM_DESC(data_fifo_size, "Total number of words in the data FIFO memory 32-32768");
6643 +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size, int, 0444);
6644 +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
6645 +module_param_named(dev_nperio_tx_fifo_size, dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
6646 +MODULE_PARM_DESC(dev_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
6647 +module_param_named(dev_perio_tx_fifo_size_1, dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
6648 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1, "Number of words in the periodic Tx FIFO 4-768");
6649 +module_param_named(dev_perio_tx_fifo_size_2, dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
6650 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2, "Number of words in the periodic Tx FIFO 4-768");
6651 +module_param_named(dev_perio_tx_fifo_size_3, dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
6652 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3, "Number of words in the periodic Tx FIFO 4-768");
6653 +module_param_named(dev_perio_tx_fifo_size_4, dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
6654 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4, "Number of words in the periodic Tx FIFO 4-768");
6655 +module_param_named(dev_perio_tx_fifo_size_5, dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
6656 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5, "Number of words in the periodic Tx FIFO 4-768");
6657 +module_param_named(dev_perio_tx_fifo_size_6, dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
6658 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6, "Number of words in the periodic Tx FIFO 4-768");
6659 +module_param_named(dev_perio_tx_fifo_size_7, dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
6660 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7, "Number of words in the periodic Tx FIFO 4-768");
6661 +module_param_named(dev_perio_tx_fifo_size_8, dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
6662 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8, "Number of words in the periodic Tx FIFO 4-768");
6663 +module_param_named(dev_perio_tx_fifo_size_9, dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
6664 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9, "Number of words in the periodic Tx FIFO 4-768");
6665 +module_param_named(dev_perio_tx_fifo_size_10, dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
6666 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10, "Number of words in the periodic Tx FIFO 4-768");
6667 +module_param_named(dev_perio_tx_fifo_size_11, dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
6668 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11, "Number of words in the periodic Tx FIFO 4-768");
6669 +module_param_named(dev_perio_tx_fifo_size_12, dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
6670 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12, "Number of words in the periodic Tx FIFO 4-768");
6671 +module_param_named(dev_perio_tx_fifo_size_13, dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
6672 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13, "Number of words in the periodic Tx FIFO 4-768");
6673 +module_param_named(dev_perio_tx_fifo_size_14, dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
6674 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14, "Number of words in the periodic Tx FIFO 4-768");
6675 +module_param_named(dev_perio_tx_fifo_size_15, dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
6676 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15, "Number of words in the periodic Tx FIFO 4-768");
6677 +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size, int, 0444);
6678 +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
6679 +module_param_named(host_nperio_tx_fifo_size, dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
6680 +MODULE_PARM_DESC(host_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
6681 +module_param_named(host_perio_tx_fifo_size, dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
6682 +MODULE_PARM_DESC(host_perio_tx_fifo_size, "Number of words in the host periodic Tx FIFO 16-32768");
6683 +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size, int, 0444);
6684 +/** @todo Set the max to 512K, modify checks */
6685 +MODULE_PARM_DESC(max_transfer_size, "The maximum transfer size supported in bytes 2047-65535");
6686 +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count, int, 0444);
6687 +MODULE_PARM_DESC(max_packet_count, "The maximum number of packets in a transfer 15-511");
6688 +module_param_named(host_channels, dwc_otg_module_params.host_channels, int, 0444);
6689 +MODULE_PARM_DESC(host_channels, "The number of host channel registers to use 1-16");
6690 +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int, 0444);
6691 +MODULE_PARM_DESC(dev_endpoints, "The number of endpoints in addition to EP0 available for device mode 1-15");
6692 +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
6693 +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
6694 +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int, 0444);
6695 +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
6696 +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
6697 +MODULE_PARM_DESC(phy_ulpi_ddr, "ULPI at double or single data rate 0=Single 1=Double");
6698 +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus, int, 0444);
6699 +MODULE_PARM_DESC(phy_ulpi_ext_vbus, "ULPI PHY using internal or external vbus 0=Internal");
6700 +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
6701 +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
6702 +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
6703 +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
6704 +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
6705 +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
6706 +module_param_named(debug, g_dbg_lvl, int, 0444);
6707 +MODULE_PARM_DESC(debug, "0");
6708 +module_param_named(en_multiple_tx_fifo,
6709 + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
6710 +MODULE_PARM_DESC(en_multiple_tx_fifo,
6711 + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
6712 +module_param_named(dev_tx_fifo_size_1,
6713 + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
6714 +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
6715 +module_param_named(dev_tx_fifo_size_2,
6716 + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
6717 +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
6718 +module_param_named(dev_tx_fifo_size_3,
6719 + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
6720 +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
6721 +module_param_named(dev_tx_fifo_size_4,
6722 + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
6723 +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
6724 +module_param_named(dev_tx_fifo_size_5,
6725 + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
6726 +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
6727 +module_param_named(dev_tx_fifo_size_6,
6728 + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
6729 +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
6730 +module_param_named(dev_tx_fifo_size_7,
6731 + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
6732 +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
6733 +module_param_named(dev_tx_fifo_size_8,
6734 + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
6735 +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
6736 +module_param_named(dev_tx_fifo_size_9,
6737 + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
6738 +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
6739 +module_param_named(dev_tx_fifo_size_10,
6740 + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
6741 +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
6742 +module_param_named(dev_tx_fifo_size_11,
6743 + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
6744 +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
6745 +module_param_named(dev_tx_fifo_size_12,
6746 + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
6747 +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
6748 +module_param_named(dev_tx_fifo_size_13,
6749 + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
6750 +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
6751 +module_param_named(dev_tx_fifo_size_14,
6752 + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
6753 +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
6754 +module_param_named(dev_tx_fifo_size_15,
6755 + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
6756 +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
6757 +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
6758 +MODULE_PARM_DESC(thr_ctl, "Thresholding enable flag bit"
6759 + "0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
6760 +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int, 0444);
6761 +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
6762 +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int, 0444);
6763 +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
6764 +module_param_named (iomem_base, dwc_iomem_base, ulong, 0444);
6765 +MODULE_PARM_DESC (dwc_iomem_base, "The base address of the DWC_OTG register.");
6766 +module_param_named (irq, dwc_irq, int, 0444);
6767 +MODULE_PARM_DESC (dwc_irq, "The interrupt number");
6769 +/** @page "Module Parameters"
6771 + * The following parameters may be specified when starting the module.
6772 + * These parameters define how the DWC_otg controller should be
6773 + * configured. Parameter values are passed to the CIL initialization
6774 + * function dwc_otg_cil_init
6776 + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
6780 + <tr><td>Parameter Name</td><td>Meaning</td></tr>
6784 + <td>Specifies the OTG capabilities. The driver will automatically detect the
6785 + value for this parameter if none is specified.
6786 + - 0: HNP and SRP capable (default, if available)
6787 + - 1: SRP Only capable
6788 + - 2: No HNP/SRP capable
6792 + <td>dma_enable</td>
6793 + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
6794 + The driver will automatically detect the value for this parameter if none is
6797 + - 1: DMA (default, if available)
6801 + <td>dma_burst_size</td>
6802 + <td>The DMA Burst size (applicable only for External DMA Mode).
6803 + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
6808 + <td>Specifies the maximum speed of operation in host and device mode. The
6809 + actual speed depends on the speed of the attached device and the value of
6811 + - 0: High Speed (default)
6816 + <td>host_support_fs_ls_low_power</td>
6817 + <td>Specifies whether low power mode is supported when attached to a Full
6818 + Speed or Low Speed device in host mode.
6819 + - 0: Don't support low power mode (default)
6820 + - 1: Support low power mode
6824 + <td>host_ls_low_power_phy_clk</td>
6825 + <td>Specifies the PHY clock rate in low power mode when connected to a Low
6826 + Speed device in host mode. This parameter is applicable only if
6827 + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
6828 + - 0: 48 MHz (default)
6833 + <td>enable_dynamic_fifo</td>
6834 + <td> Specifies whether FIFOs may be resized by the driver software.
6835 + - 0: Use cC FIFO size parameters
6836 + - 1: Allow dynamic FIFO sizing (default)
6840 + <td>data_fifo_size</td>
6841 + <td>Total number of 4-byte words in the data FIFO memory. This memory
6842 + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
6843 + - Values: 32 to 32768 (default 8192)
6845 + Note: The total FIFO memory depth in the FPGA configuration is 8192.
6849 + <td>dev_rx_fifo_size</td>
6850 + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
6851 + FIFO sizing is enabled.
6852 + - Values: 16 to 32768 (default 1064)
6856 + <td>dev_nperio_tx_fifo_size</td>
6857 + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
6858 + dynamic FIFO sizing is enabled.
6859 + - Values: 16 to 32768 (default 1024)
6863 + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
6864 + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
6865 + when dynamic FIFO sizing is enabled.
6866 + - Values: 4 to 768 (default 256)
6870 + <td>host_rx_fifo_size</td>
6871 + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
6872 + sizing is enabled.
6873 + - Values: 16 to 32768 (default 1024)
6877 + <td>host_nperio_tx_fifo_size</td>
6878 + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
6879 + dynamic FIFO sizing is enabled in the core.
6880 + - Values: 16 to 32768 (default 1024)
6884 + <td>host_perio_tx_fifo_size</td>
6885 + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
6886 + sizing is enabled.
6887 + - Values: 16 to 32768 (default 1024)
6891 + <td>max_transfer_size</td>
6892 + <td>The maximum transfer size supported in bytes.
6893 + - Values: 2047 to 65,535 (default 65,535)
6897 + <td>max_packet_count</td>
6898 + <td>The maximum number of packets in a transfer.
6899 + - Values: 15 to 511 (default 511)
6903 + <td>host_channels</td>
6904 + <td>The number of host channel registers to use.
6905 + - Values: 1 to 16 (default 12)
6907 + Note: The FPGA configuration supports a maximum of 12 host channels.
6911 + <td>dev_endpoints</td>
6912 + <td>The number of endpoints in addition to EP0 available for device mode
6914 + - Values: 1 to 15 (default 6 IN and OUT)
6916 + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
6922 + <td>Specifies the type of PHY interface to use. By default, the driver will
6923 + automatically detect the phy_type.
6925 + - 1: UTMI+ (default, if available)
6930 + <td>phy_utmi_width</td>
6931 + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
6932 + phy_type of UTMI+. Also, this parameter is applicable only if the
6933 + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
6934 + core has been configured to work at either data path width.
6935 + - Values: 8 or 16 bits (default 16)
6939 + <td>phy_ulpi_ddr</td>
6940 + <td>Specifies whether the ULPI operates at double or single data rate. This
6941 + parameter is only applicable if phy_type is ULPI.
6942 + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
6943 + - 1: double data rate ULPI interface with 4 bit wide data bus
6947 + <td>i2c_enable</td>
6948 + <td>Specifies whether to use the I2C interface for full speed PHY. This
6949 + parameter is only applicable if PHY_TYPE is FS.
6950 + - 0: Disabled (default)
6955 + <td>otg_en_multiple_tx_fifo</td>
6956 + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
6957 + The driver will automatically detect the value for this parameter if none is
6960 + - 1: Enabled (default, if available)
6964 + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
6965 + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
6966 + when dynamic FIFO sizing is enabled.
6967 + - Values: 4 to 768 (default 256)
6972 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.h
6974 +/* ==========================================================================
6975 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.h $
6976 + * $Revision: 1.1.1.1 $
6977 + * $Date: 2009-04-17 06:15:34 $
6978 + * $Change: 510275 $
6980 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
6981 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
6982 + * otherwise expressly agreed to in writing between Synopsys and you.
6984 + * The Software IS NOT an item of Licensed Software or Licensed Product under
6985 + * any End User Software License Agreement or Agreement for Licensed Product
6986 + * with Synopsys or any supplement thereto. You are permitted to use and
6987 + * redistribute this Software in source and binary forms, with or without
6988 + * modification, provided that redistributions of source code must retain this
6989 + * notice. You may not view, use, disclose, copy or distribute this file or
6990 + * any information contained herein except pursuant to this license grant from
6991 + * Synopsys. If you do not agree with this notice, including the disclaimer
6992 + * below, then you are not authorized to use the Software.
6994 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
6995 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6996 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6997 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
6998 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
6999 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7000 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7001 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7002 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7003 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
7005 + * ========================================================================== */
7007 +#if !defined(__DWC_OTG_DRIVER_H__)
7008 +#define __DWC_OTG_DRIVER_H__
7011 + * This file contains the interface to the Linux driver.
7013 +#include "dwc_otg_cil.h"
7015 +/* Type declarations */
7016 +struct dwc_otg_pcd;
7017 +struct dwc_otg_hcd;
7020 + * This structure is a wrapper that encapsulates the driver components used to
7021 + * manage a single DWC_otg controller.
7023 +typedef struct dwc_otg_device
7025 + /** Base address returned from ioremap() */
7028 + /** Pointer to the core interface structure. */
7029 + dwc_otg_core_if_t *core_if;
7031 + /** Register offset for Diagnostic API.*/
7032 + uint32_t reg_offset;
7034 + /** Pointer to the PCD structure. */
7035 + struct dwc_otg_pcd *pcd;
7037 + /** Pointer to the HCD structure. */
7038 + struct dwc_otg_hcd *hcd;
7040 + /** Flag to indicate whether the common IRQ handler is installed. */
7041 + uint8_t common_irq_installed;
7043 + /** Interrupt request number. */
7046 + /** Physical address of Control and Status registers, used by
7047 + * release_mem_region().
7049 + resource_size_t phys_addr;
7051 + /** Length of memory region, used by release_mem_region(). */
7052 + unsigned long base_len;
7053 +} dwc_otg_device_t;
7055 +//#define dev_dbg(fake, format, arg...) printk(KERN_CRIT __FILE__ ":%d: " format "\n" , __LINE__, ## arg)
7059 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.c
7061 +/* ==========================================================================
7062 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd.c $
7063 + * $Revision: 1.1.1.1 $
7064 + * $Date: 2009-04-17 06:15:34 $
7065 + * $Change: 631780 $
7067 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
7068 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
7069 + * otherwise expressly agreed to in writing between Synopsys and you.
7071 + * The Software IS NOT an item of Licensed Software or Licensed Product under
7072 + * any End User Software License Agreement or Agreement for Licensed Product
7073 + * with Synopsys or any supplement thereto. You are permitted to use and
7074 + * redistribute this Software in source and binary forms, with or without
7075 + * modification, provided that redistributions of source code must retain this
7076 + * notice. You may not view, use, disclose, copy or distribute this file or
7077 + * any information contained herein except pursuant to this license grant from
7078 + * Synopsys. If you do not agree with this notice, including the disclaimer
7079 + * below, then you are not authorized to use the Software.
7081 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
7082 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7083 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7084 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
7085 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7086 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7087 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7088 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7089 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7090 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
7092 + * ========================================================================== */
7093 +#ifndef DWC_DEVICE_ONLY
7098 + * This file contains the implementation of the HCD. In Linux, the HCD
7099 + * implements the hc_driver API.
7101 +#include <linux/kernel.h>
7102 +#include <linux/module.h>
7103 +#include <linux/moduleparam.h>
7104 +#include <linux/init.h>
7106 +#include <linux/device.h>
7108 +#include <linux/errno.h>
7109 +#include <linux/list.h>
7110 +#include <linux/interrupt.h>
7111 +#include <linux/string.h>
7113 +#include <linux/dma-mapping.h>
7115 +#include "dwc_otg_driver.h"
7116 +#include "dwc_otg_hcd.h"
7117 +#include "dwc_otg_regs.h"
7119 +#include <asm/irq.h>
7120 +#include "dwc_otg_ifx.h" // for Infineon platform specific.
7121 +extern atomic_t release_later;
7123 +static u64 dma_mask = DMA_BIT_MASK(32);
7125 +static const char dwc_otg_hcd_name [] = "dwc_otg_hcd";
7126 +static const struct hc_driver dwc_otg_hc_driver =
7128 + .description = dwc_otg_hcd_name,
7129 + .product_desc = "DWC OTG Controller",
7130 + .hcd_priv_size = sizeof(dwc_otg_hcd_t),
7131 + .irq = dwc_otg_hcd_irq,
7132 + .flags = HCD_MEMORY | HCD_USB2,
7134 + .start = dwc_otg_hcd_start,
7137 + .stop = dwc_otg_hcd_stop,
7138 + .urb_enqueue = dwc_otg_hcd_urb_enqueue,
7139 + .urb_dequeue = dwc_otg_hcd_urb_dequeue,
7140 + .endpoint_disable = dwc_otg_hcd_endpoint_disable,
7141 + .get_frame_number = dwc_otg_hcd_get_frame_number,
7142 + .hub_status_data = dwc_otg_hcd_hub_status_data,
7143 + .hub_control = dwc_otg_hcd_hub_control,
7150 + * Work queue function for starting the HCD when A-Cable is connected.
7151 + * The dwc_otg_hcd_start() must be called in a process context.
7153 +static void hcd_start_func(struct work_struct *work)
7155 + struct dwc_otg_hcd *priv =
7156 + container_of(work, struct dwc_otg_hcd, start_work);
7157 + struct usb_hcd *usb_hcd = (struct usb_hcd *)priv->_p;
7158 + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, usb_hcd);
7160 + dwc_otg_hcd_start(usb_hcd);
7166 + * HCD Callback function for starting the HCD when A-Cable is
7169 + * @param _p void pointer to the <code>struct usb_hcd</code>
7171 +static int32_t dwc_otg_hcd_start_cb(void *_p)
7173 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_p);
7174 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
7175 + hprt0_data_t hprt0;
7176 + if (core_if->op_state == B_HOST) {
7178 + * Reset the port. During a HNP mode switch the reset
7179 + * needs to occur within 1ms and have a duration of at
7182 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
7183 + hprt0.b.prtrst = 1;
7184 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7185 + ((struct usb_hcd *)_p)->self.is_b_host = 1;
7187 + ((struct usb_hcd *)_p)->self.is_b_host = 0;
7189 + /* Need to start the HCD in a non-interrupt context. */
7190 + INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
7191 + dwc_otg_hcd->_p = _p;
7192 + schedule_work(&dwc_otg_hcd->start_work);
7198 + * HCD Callback function for stopping the HCD.
7200 + * @param _p void pointer to the <code>struct usb_hcd</code>
7202 +static int32_t dwc_otg_hcd_stop_cb( void *_p )
7204 + struct usb_hcd *usb_hcd = (struct usb_hcd *)_p;
7205 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7206 + dwc_otg_hcd_stop( usb_hcd );
7209 +static void del_xfer_timers(dwc_otg_hcd_t *_hcd)
7213 + int num_channels = _hcd->core_if->core_params->host_channels;
7214 + for (i = 0; i < num_channels; i++) {
7215 + del_timer(&_hcd->core_if->hc_xfer_timer[i]);
7220 +static void del_timers(dwc_otg_hcd_t *_hcd)
7222 + del_xfer_timers(_hcd);
7223 + del_timer(&_hcd->conn_timer);
7227 + * Processes all the URBs in a single list of QHs. Completes them with
7228 + * -ETIMEDOUT and frees the QTD.
7230 +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * _hcd,
7231 + struct list_head *_qh_list)
7233 + struct list_head *qh_item;
7235 + struct list_head *qtd_item;
7236 + dwc_otg_qtd_t *qtd;
7238 + list_for_each(qh_item, _qh_list) {
7239 + qh = list_entry(qh_item, dwc_otg_qh_t, qh_list_entry);
7240 + for (qtd_item = qh->qtd_list.next; qtd_item != &qh->qtd_list;
7241 + qtd_item = qh->qtd_list.next) {
7242 + qtd = list_entry(qtd_item, dwc_otg_qtd_t, qtd_list_entry);
7243 + if (qtd->urb != NULL) {
7244 + dwc_otg_hcd_complete_urb(_hcd, qtd->urb,-ETIMEDOUT);
7246 + dwc_otg_hcd_qtd_remove_and_free(qtd);
7252 + * Responds with an error status of ETIMEDOUT to all URBs in the non-periodic
7253 + * and periodic schedules. The QTD associated with each URB is removed from
7254 + * the schedule and freed. This function may be called when a disconnect is
7255 + * detected or when the HCD is being stopped.
7257 +static void kill_all_urbs(dwc_otg_hcd_t *_hcd)
7259 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_deferred);
7260 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_inactive);
7261 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_active);
7262 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_inactive);
7263 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_ready);
7264 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_assigned);
7265 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_queued);
7269 + * HCD Callback function for disconnect of the HCD.
7271 + * @param _p void pointer to the <code>struct usb_hcd</code>
7273 +static int32_t dwc_otg_hcd_disconnect_cb( void *_p )
7275 + gintsts_data_t intr;
7276 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
7278 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7281 + * Set status flags for the hub driver.
7283 + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
7284 + dwc_otg_hcd->flags.b.port_connect_status = 0;
7287 + * Shutdown any transfers in process by clearing the Tx FIFO Empty
7288 + * interrupt mask and status bits and disabling subsequent host
7289 + * channel interrupts.
7292 + intr.b.nptxfempty = 1;
7293 + intr.b.ptxfempty = 1;
7294 + intr.b.hcintr = 1;
7295 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, intr.d32, 0);
7296 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintsts, intr.d32, 0);
7298 + del_timers(dwc_otg_hcd);
7301 + * Turn off the vbus power only if the core has transitioned to device
7302 + * mode. If still in host mode, need to keep power on to detect a
7305 + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
7306 + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
7307 + hprt0_data_t hprt0 = { .d32=0 };
7308 + DWC_PRINT("Disconnect: PortPower off\n");
7309 + hprt0.b.prtpwr = 0;
7310 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
7313 + dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
7316 + /* Respond with an error status to all URBs in the schedule. */
7317 + kill_all_urbs(dwc_otg_hcd);
7319 + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
7320 + /* Clean up any host channels that were in use. */
7323 + dwc_hc_t *channel;
7324 + dwc_otg_hc_regs_t *hc_regs;
7325 + hcchar_data_t hcchar;
7327 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
7329 + if (!dwc_otg_hcd->core_if->dma_enable) {
7330 + /* Flush out any channel requests in slave mode. */
7331 + for (i = 0; i < num_channels; i++) {
7332 + channel = dwc_otg_hcd->hc_ptr_array[i];
7333 + if (list_empty(&channel->hc_list_entry)) {
7334 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
7335 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7336 + if (hcchar.b.chen) {
7337 + hcchar.b.chen = 0;
7338 + hcchar.b.chdis = 1;
7339 + hcchar.b.epdir = 0;
7340 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
7346 + for (i = 0; i < num_channels; i++) {
7347 + channel = dwc_otg_hcd->hc_ptr_array[i];
7348 + if (list_empty(&channel->hc_list_entry)) {
7349 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
7350 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7351 + if (hcchar.b.chen) {
7352 + /* Halt the channel. */
7353 + hcchar.b.chdis = 1;
7354 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
7357 + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if, channel);
7358 + list_add_tail(&channel->hc_list_entry,
7359 + &dwc_otg_hcd->free_hc_list);
7364 + /* A disconnect will end the session so the B-Device is no
7365 + * longer a B-host. */
7366 + ((struct usb_hcd *)_p)->self.is_b_host = 0;
7372 + * Connection timeout function. An OTG host is required to display a
7373 + * message if the device does not connect within 10 seconds.
7375 +void dwc_otg_hcd_connect_timeout( unsigned long _ptr )
7377 + DWC_DEBUGPL(DBG_HCDV, "%s(%x)\n", __func__, (int)_ptr);
7378 + DWC_PRINT( "Connect Timeout\n");
7379 + DWC_ERROR( "Device Not Connected/Responding\n" );
7383 + * Start the connection timer. An OTG host is required to display a
7384 + * message if the device does not connect within 10 seconds. The
7385 + * timer is deleted if a port connect interrupt occurs before the
7388 +static void dwc_otg_hcd_start_connect_timer( dwc_otg_hcd_t *_hcd)
7390 + init_timer( &_hcd->conn_timer );
7391 + _hcd->conn_timer.function = dwc_otg_hcd_connect_timeout;
7392 + _hcd->conn_timer.data = (unsigned long)0;
7393 + _hcd->conn_timer.expires = jiffies + (HZ*10);
7394 + add_timer( &_hcd->conn_timer );
7398 + * HCD Callback function for disconnect of the HCD.
7400 + * @param _p void pointer to the <code>struct usb_hcd</code>
7402 +static int32_t dwc_otg_hcd_session_start_cb( void *_p )
7404 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
7405 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7406 + dwc_otg_hcd_start_connect_timer( dwc_otg_hcd );
7411 + * HCD Callback structure for handling mode switching.
7413 +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
7414 + .start = dwc_otg_hcd_start_cb,
7415 + .stop = dwc_otg_hcd_stop_cb,
7416 + .disconnect = dwc_otg_hcd_disconnect_cb,
7417 + .session_start = dwc_otg_hcd_session_start_cb,
7423 + * Reset tasklet function
7425 +static void reset_tasklet_func (unsigned long data)
7427 + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t*)data;
7428 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
7429 + hprt0_data_t hprt0;
7431 + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
7433 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
7434 + hprt0.b.prtrst = 1;
7435 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7438 + hprt0.b.prtrst = 0;
7439 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7440 + dwc_otg_hcd->flags.b.port_reset_change = 1;
7445 +static struct tasklet_struct reset_tasklet = {
7448 + .count = ATOMIC_INIT(0),
7449 + .func = reset_tasklet_func,
7454 + * Initializes the HCD. This function allocates memory for and initializes the
7455 + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
7456 + * USB bus with the core and calls the hc_driver->start() function. It returns
7457 + * a negative error on failure.
7459 +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
7461 +int __devinit dwc_otg_hcd_init(struct device *_dev, dwc_otg_device_t * dwc_otg_device)
7463 + struct usb_hcd *hcd = NULL;
7464 + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
7465 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
7469 + dwc_hc_t *channel;
7473 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
7476 + * Allocate memory for the base HCD plus the DWC OTG HCD.
7477 + * Initialize the base HCD.
7479 + hcd = usb_create_hcd(&dwc_otg_hc_driver, _dev, dev_name(_dev));
7480 + if (hcd == NULL) {
7484 + dev_set_drvdata(_dev, dwc_otg_device); /* fscz restore */
7485 + hcd->regs = otg_dev->base;
7486 + hcd->rsrc_start = (int)otg_dev->base;
7488 + hcd->self.otg_port = 1;
7490 + /* Initialize the DWC OTG HCD. */
7491 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
7492 + dwc_otg_hcd->core_if = otg_dev->core_if;
7493 + otg_dev->hcd = dwc_otg_hcd;
7495 + /* Register the HCD CIL Callbacks */
7496 + dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
7497 + &hcd_cil_callbacks, hcd);
7499 + /* Initialize the non-periodic schedule. */
7500 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
7501 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
7502 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_deferred);
7504 + /* Initialize the periodic schedule. */
7505 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
7506 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
7507 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
7508 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
7511 + * Create a host channel descriptor for each host channel implemented
7512 + * in the controller. Initialize the channel descriptor array.
7514 + INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
7515 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
7516 + for (i = 0; i < num_channels; i++) {
7517 + channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
7518 + if (channel == NULL) {
7520 + DWC_ERROR("%s: host channel allocation failed\n", __func__);
7523 + memset(channel, 0, sizeof(dwc_hc_t));
7524 + channel->hc_num = i;
7525 + dwc_otg_hcd->hc_ptr_array[i] = channel;
7527 + init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
7530 + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
7533 + /* Initialize the Connection timeout timer. */
7534 + init_timer( &dwc_otg_hcd->conn_timer );
7536 + /* Initialize reset tasklet. */
7537 + reset_tasklet.data = (unsigned long) dwc_otg_hcd;
7538 + dwc_otg_hcd->reset_tasklet = &reset_tasklet;
7540 + /* Set device flags indicating whether the HCD supports DMA. */
7541 + if (otg_dev->core_if->dma_enable) {
7542 + DWC_PRINT("Using DMA mode\n");
7543 + //_dev->dma_mask = (void *)~0;
7544 + //_dev->coherent_dma_mask = ~0;
7545 + _dev->dma_mask = &dma_mask;
7546 + _dev->coherent_dma_mask = DMA_BIT_MASK(32);
7548 + DWC_PRINT("Using Slave mode\n");
7549 + _dev->dma_mask = (void *)0;
7550 + _dev->coherent_dma_mask = 0;
7553 + init_hcd_usecs(dwc_otg_hcd);
7555 + * Finish generic HCD initialization and start the HCD. This function
7556 + * allocates the DMA buffer pool, registers the USB bus, requests the
7557 + * IRQ line, and calls dwc_otg_hcd_start method.
7559 + retval = usb_add_hcd(hcd, otg_dev->irq, IRQF_SHARED);
7565 + * Allocate space for storing data on status transactions. Normally no
7566 + * data is sent, but this space acts as a bit bucket. This must be
7567 + * done after usb_add_hcd since that function allocates the DMA buffer
7570 + if (otg_dev->core_if->dma_enable) {
7571 + dwc_otg_hcd->status_buf =
7572 + dma_alloc_coherent(_dev,
7573 + DWC_OTG_HCD_STATUS_BUF_SIZE,
7574 + &dwc_otg_hcd->status_buf_dma,
7575 + GFP_KERNEL | GFP_DMA);
7577 + dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
7580 + if (dwc_otg_hcd->status_buf == NULL) {
7582 + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
7586 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
7587 + dev_name(_dev), hcd->self.busnum);
7591 + /* Error conditions */
7593 + usb_remove_hcd(hcd);
7595 + dwc_otg_hcd_free(hcd);
7602 + * Removes the HCD.
7603 + * Frees memory and resources associated with the HCD and deregisters the bus.
7605 +void dwc_otg_hcd_remove(struct device *_dev)
7607 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
7608 + dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
7609 + struct usb_hcd *hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
7611 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE\n");
7613 + /* Turn off all interrupts */
7614 + dwc_write_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0);
7615 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gahbcfg, 1, 0);
7617 + usb_remove_hcd(hcd);
7619 + dwc_otg_hcd_free(hcd);
7627 +/* =========================================================================
7628 + * Linux HC Driver Functions
7629 + * ========================================================================= */
7632 + * Initializes dynamic portions of the DWC_otg HCD state.
7634 +static void hcd_reinit(dwc_otg_hcd_t *_hcd)
7636 + struct list_head *item;
7639 + dwc_hc_t *channel;
7641 + _hcd->flags.d32 = 0;
7643 + _hcd->non_periodic_qh_ptr = &_hcd->non_periodic_sched_active;
7644 + _hcd->available_host_channels = _hcd->core_if->core_params->host_channels;
7647 + * Put all channels in the free channel list and clean up channel
7650 + item = _hcd->free_hc_list.next;
7651 + while (item != &_hcd->free_hc_list) {
7653 + item = _hcd->free_hc_list.next;
7655 + num_channels = _hcd->core_if->core_params->host_channels;
7656 + for (i = 0; i < num_channels; i++) {
7657 + channel = _hcd->hc_ptr_array[i];
7658 + list_add_tail(&channel->hc_list_entry, &_hcd->free_hc_list);
7659 + dwc_otg_hc_cleanup(_hcd->core_if, channel);
7662 + /* Initialize the DWC core for host mode operation. */
7663 + dwc_otg_core_host_init(_hcd->core_if);
7666 +/** Initializes the DWC_otg controller and its root hub and prepares it for host
7667 + * mode operation. Activates the root port. Returns 0 on success and a negative
7668 + * error code on failure. */
7669 +int dwc_otg_hcd_start(struct usb_hcd *_hcd)
7671 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7672 + dwc_otg_core_if_t * core_if = dwc_otg_hcd->core_if;
7673 + struct usb_bus *bus;
7677 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
7679 + bus = hcd_to_bus(_hcd);
7681 + /* Initialize the bus state. If the core is in Device Mode
7682 + * HALT the USB bus and return. */
7683 + if (dwc_otg_is_device_mode (core_if)) {
7684 + _hcd->state = HC_STATE_HALT;
7687 + _hcd->state = HC_STATE_RUNNING;
7689 + /* Initialize and connect root hub if one is not already attached */
7690 + if (bus->root_hub) {
7691 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
7692 + /* Inform the HUB driver to resume. */
7693 + usb_hcd_resume_root_hub(_hcd);
7697 + struct usb_device *udev;
7698 + udev = usb_alloc_dev(NULL, bus, 0);
7700 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
7703 + udev->speed = USB_SPEED_HIGH;
7704 + /* Not needed - VJ
7705 + if ((retval = usb_hcd_register_root_hub(udev, _hcd)) != 0) {
7706 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error registering %d\n", retval);
7711 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
7715 + hcd_reinit(dwc_otg_hcd);
7720 +static void qh_list_free(dwc_otg_hcd_t *_hcd, struct list_head *_qh_list)
7722 + struct list_head *item;
7725 + if (_qh_list->next == NULL) {
7726 + /* The list hasn't been initialized yet. */
7730 + /* Ensure there are no QTDs or URBs left. */
7731 + kill_urbs_in_qh_list(_hcd, _qh_list);
7733 + for (item = _qh_list->next; item != _qh_list; item = _qh_list->next) {
7734 + qh = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7735 + dwc_otg_hcd_qh_remove_and_free(_hcd, qh);
7740 + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
7743 +void dwc_otg_hcd_stop(struct usb_hcd *_hcd)
7745 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7746 + hprt0_data_t hprt0 = { .d32=0 };
7748 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
7750 + /* Turn off all host-specific interrupts. */
7751 + dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
7754 + * The root hub should be disconnected before this function is called.
7755 + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
7756 + * and the QH lists (via ..._hcd_endpoint_disable).
7759 + /* Turn off the vbus power */
7760 + DWC_PRINT("PortPower off\n");
7761 + hprt0.b.prtpwr = 0;
7762 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
7768 +/** Returns the current frame number. */
7769 +int dwc_otg_hcd_get_frame_number(struct usb_hcd *_hcd)
7771 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7772 + hfnum_data_t hfnum;
7774 + hfnum.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->
7775 + host_if->host_global_regs->hfnum);
7778 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n", hfnum.b.frnum);
7780 + return hfnum.b.frnum;
7784 + * Frees secondary storage associated with the dwc_otg_hcd structure contained
7785 + * in the struct usb_hcd field.
7787 +void dwc_otg_hcd_free(struct usb_hcd *_hcd)
7789 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7792 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
7794 + del_timers(dwc_otg_hcd);
7796 + /* Free memory for QH/QTD lists */
7797 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
7798 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_deferred);
7799 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
7800 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
7801 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
7802 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
7803 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
7805 + /* Free memory for the host channels. */
7806 + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
7807 + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
7809 + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n", i, hc);
7814 + if (dwc_otg_hcd->core_if->dma_enable) {
7815 + if (dwc_otg_hcd->status_buf_dma) {
7816 + dma_free_coherent(_hcd->self.controller,
7817 + DWC_OTG_HCD_STATUS_BUF_SIZE,
7818 + dwc_otg_hcd->status_buf,
7819 + dwc_otg_hcd->status_buf_dma);
7821 + } else if (dwc_otg_hcd->status_buf != NULL) {
7822 + kfree(dwc_otg_hcd->status_buf);
7830 +static void dump_urb_info(struct urb *_urb, char* _fn_name)
7832 + DWC_PRINT("%s, urb %p\n", _fn_name, _urb);
7833 + DWC_PRINT(" Device address: %d\n", usb_pipedevice(_urb->pipe));
7834 + DWC_PRINT(" Endpoint: %d, %s\n", usb_pipeendpoint(_urb->pipe),
7835 + (usb_pipein(_urb->pipe) ? "IN" : "OUT"));
7836 + DWC_PRINT(" Endpoint type: %s\n",
7838 + switch (usb_pipetype(_urb->pipe)) {
7839 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
7840 + case PIPE_BULK: pipetype = "BULK"; break;
7841 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
7842 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
7843 + default: pipetype = "UNKNOWN"; break;
7845 + DWC_PRINT(" Speed: %s\n",
7847 + switch (_urb->dev->speed) {
7848 + case USB_SPEED_HIGH: speed = "HIGH"; break;
7849 + case USB_SPEED_FULL: speed = "FULL"; break;
7850 + case USB_SPEED_LOW: speed = "LOW"; break;
7851 + default: speed = "UNKNOWN"; break;
7853 + DWC_PRINT(" Max packet size: %d\n",
7854 + usb_maxpacket(_urb->dev, _urb->pipe, usb_pipeout(_urb->pipe)));
7855 + DWC_PRINT(" Data buffer length: %d\n", _urb->transfer_buffer_length);
7856 + DWC_PRINT(" Transfer buffer: %p, Transfer DMA: %p\n",
7857 + _urb->transfer_buffer, (void *)_urb->transfer_dma);
7858 + DWC_PRINT(" Setup buffer: %p, Setup DMA: %p\n",
7859 + _urb->setup_packet, (void *)_urb->setup_dma);
7860 + DWC_PRINT(" Interval: %d\n", _urb->interval);
7861 + if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
7863 + for (i = 0; i < _urb->number_of_packets; i++) {
7864 + DWC_PRINT(" ISO Desc %d:\n", i);
7865 + DWC_PRINT(" offset: %d, length %d\n",
7866 + _urb->iso_frame_desc[i].offset,
7867 + _urb->iso_frame_desc[i].length);
7872 +static void dump_channel_info(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *qh)
7874 + if (qh->channel != NULL) {
7875 + dwc_hc_t *hc = qh->channel;
7876 + struct list_head *item;
7877 + dwc_otg_qh_t *qh_item;
7878 + int num_channels = _hcd->core_if->core_params->host_channels;
7881 + dwc_otg_hc_regs_t *hc_regs;
7882 + hcchar_data_t hcchar;
7883 + hcsplt_data_t hcsplt;
7884 + hctsiz_data_t hctsiz;
7887 + hc_regs = _hcd->core_if->host_if->hc_regs[hc->hc_num];
7888 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7889 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
7890 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
7891 + hcdma = dwc_read_reg32(&hc_regs->hcdma);
7893 + DWC_PRINT(" Assigned to channel %p:\n", hc);
7894 + DWC_PRINT(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
7895 + DWC_PRINT(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
7896 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
7897 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
7898 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
7899 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
7900 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
7901 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
7902 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
7903 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
7904 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
7905 + DWC_PRINT(" qh: %p\n", hc->qh);
7906 + DWC_PRINT(" NP inactive sched:\n");
7907 + list_for_each(item, &_hcd->non_periodic_sched_inactive) {
7908 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7909 + DWC_PRINT(" %p\n", qh_item);
7910 + } DWC_PRINT(" NP active sched:\n");
7911 + list_for_each(item, &_hcd->non_periodic_sched_deferred) {
7912 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7913 + DWC_PRINT(" %p\n", qh_item);
7914 + } DWC_PRINT(" NP deferred sched:\n");
7915 + list_for_each(item, &_hcd->non_periodic_sched_active) {
7916 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7917 + DWC_PRINT(" %p\n", qh_item);
7918 + } DWC_PRINT(" Channels: \n");
7919 + for (i = 0; i < num_channels; i++) {
7920 + dwc_hc_t *hc = _hcd->hc_ptr_array[i];
7921 + DWC_PRINT(" %2d: %p\n", i, hc);
7927 +/** Starts processing a USB transfer request specified by a USB Request Block
7928 + * (URB). mem_flags indicates the type of memory allocation to use while
7929 + * processing this URB. */
7930 +int dwc_otg_hcd_urb_enqueue(struct usb_hcd *_hcd,
7934 + unsigned long flags;
7936 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7937 + dwc_otg_qtd_t *qtd;
7939 + local_irq_save(flags);
7940 + retval = usb_hcd_link_urb_to_ep(_hcd, _urb);
7942 + local_irq_restore(flags);
7946 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
7947 + dump_urb_info(_urb, "dwc_otg_hcd_urb_enqueue");
7950 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
7951 + /* No longer connected. */
7952 + local_irq_restore(flags);
7956 + qtd = dwc_otg_hcd_qtd_create (_urb);
7957 + if (qtd == NULL) {
7958 + local_irq_restore(flags);
7959 + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
7963 + retval = dwc_otg_hcd_qtd_add (qtd, dwc_otg_hcd);
7965 + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
7966 + "Error status %d\n", retval);
7967 + dwc_otg_hcd_qtd_free(qtd);
7970 + local_irq_restore (flags);
7974 +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
7976 +int dwc_otg_hcd_urb_dequeue(struct usb_hcd *_hcd, struct urb *_urb, int _status)
7978 + unsigned long flags;
7979 + dwc_otg_hcd_t *dwc_otg_hcd;
7980 + dwc_otg_qtd_t *urb_qtd;
7983 + //struct usb_host_endpoint *_ep = NULL;
7985 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
7987 + local_irq_save(flags);
7989 + retval = usb_hcd_check_unlink_urb(_hcd, _urb, _status);
7991 + local_irq_restore(flags);
7995 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7996 + urb_qtd = (dwc_otg_qtd_t *)_urb->hcpriv;
7997 + if (urb_qtd == NULL) {
7998 + printk("urb_qtd is NULL for _urb %08x\n",(unsigned)_urb);
8001 + qh = (dwc_otg_qh_t *) urb_qtd->qtd_qh_ptr;
8007 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
8008 + dump_urb_info(_urb, "dwc_otg_hcd_urb_dequeue");
8009 + if (urb_qtd == qh->qtd_in_process) {
8010 + dump_channel_info(dwc_otg_hcd, qh);
8015 + if (urb_qtd == qh->qtd_in_process) {
8016 + /* The QTD is in process (it has been assigned to a channel). */
8018 + if (dwc_otg_hcd->flags.b.port_connect_status) {
8020 + * If still connected (i.e. in host mode), halt the
8021 + * channel so it can be used for other transfers. If
8022 + * no longer connected, the host registers can't be
8023 + * written to halt the channel since the core is in
8026 + dwc_otg_hc_halt(dwc_otg_hcd->core_if, qh->channel,
8027 + DWC_OTG_HC_XFER_URB_DEQUEUE);
8032 + * Free the QTD and clean up the associated QH. Leave the QH in the
8033 + * schedule if it has any remaining QTDs.
8035 + dwc_otg_hcd_qtd_remove_and_free(urb_qtd);
8036 + if (urb_qtd == qh->qtd_in_process) {
8037 + dwc_otg_hcd_qh_deactivate(dwc_otg_hcd, qh, 0);
8038 + qh->channel = NULL;
8039 + qh->qtd_in_process = NULL;
8040 + } else if (list_empty(&qh->qtd_list)) {
8041 + dwc_otg_hcd_qh_remove(dwc_otg_hcd, qh);
8045 + local_irq_restore(flags);
8046 + _urb->hcpriv = NULL;
8048 + /* Higher layer software sets URB status. */
8049 + usb_hcd_unlink_urb_from_ep(_hcd, _urb);
8050 + usb_hcd_giveback_urb(_hcd, _urb, _status);
8051 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
8052 + DWC_PRINT("Called usb_hcd_giveback_urb()\n");
8053 + DWC_PRINT(" urb->status = %d\n", _urb->status);
8060 +/** Frees resources in the DWC_otg controller related to a given endpoint. Also
8061 + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
8062 + * must already be dequeued. */
8063 +void dwc_otg_hcd_endpoint_disable(struct usb_hcd *_hcd,
8064 + struct usb_host_endpoint *_ep)
8068 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
8070 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
8071 + "endpoint=%d\n", _ep->desc.bEndpointAddress,
8072 + dwc_ep_addr_to_endpoint(_ep->desc.bEndpointAddress));
8074 + qh = (dwc_otg_qh_t *)(_ep->hcpriv);
8077 + /** Check that the QTD list is really empty */
8078 + if (!list_empty(&qh->qtd_list)) {
8079 + DWC_WARN("DWC OTG HCD EP DISABLE:"
8080 + " QTD List for this endpoint is not empty\n");
8084 + dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
8085 + _ep->hcpriv = NULL;
8090 +extern int dwc_irq;
8091 +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
8092 + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
8095 + * This function is called by the USB core when an interrupt occurs */
8096 +irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *_hcd)
8098 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8100 + mask_and_ack_ifx_irq (dwc_irq);
8101 + return IRQ_RETVAL(dwc_otg_hcd_handle_intr(dwc_otg_hcd));
8104 +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
8105 + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
8106 + * is the status change indicator for the single root port. Returns 1 if either
8107 + * change indicator is 1, otherwise returns 0. */
8108 +int dwc_otg_hcd_hub_status_data(struct usb_hcd *_hcd, char *_buf)
8110 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8113 + _buf[0] |= (dwc_otg_hcd->flags.b.port_connect_status_change ||
8114 + dwc_otg_hcd->flags.b.port_reset_change ||
8115 + dwc_otg_hcd->flags.b.port_enable_change ||
8116 + dwc_otg_hcd->flags.b.port_suspend_change ||
8117 + dwc_otg_hcd->flags.b.port_over_current_change) << 1;
8121 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
8122 + " Root port status changed\n");
8123 + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
8124 + dwc_otg_hcd->flags.b.port_connect_status_change);
8125 + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
8126 + dwc_otg_hcd->flags.b.port_reset_change);
8127 + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
8128 + dwc_otg_hcd->flags.b.port_enable_change);
8129 + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
8130 + dwc_otg_hcd->flags.b.port_suspend_change);
8131 + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
8132 + dwc_otg_hcd->flags.b.port_over_current_change);
8135 + return (_buf[0] != 0);
8138 +#ifdef DWC_HS_ELECT_TST
8140 + * Quick and dirty hack to implement the HS Electrical Test
8141 + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
8143 + * This code was copied from our userspace app "hset". It sends a
8144 + * Get Device Descriptor control sequence in two parts, first the
8145 + * Setup packet by itself, followed some time later by the In and
8146 + * Ack packets. Rather than trying to figure out how to add this
8147 + * functionality to the normal driver code, we just hijack the
8148 + * hardware, using these two function to drive the hardware
8152 +dwc_otg_core_global_regs_t *global_regs;
8153 +dwc_otg_host_global_regs_t *hc_global_regs;
8154 +dwc_otg_hc_regs_t *hc_regs;
8155 +uint32_t *data_fifo;
8157 +static void do_setup(void)
8159 + gintsts_data_t gintsts;
8160 + hctsiz_data_t hctsiz;
8161 + hcchar_data_t hcchar;
8162 + haint_data_t haint;
8163 + hcint_data_t hcint;
8165 + /* Enable HAINTs */
8166 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
8168 + /* Enable HCINTs */
8169 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
8171 + /* Read GINTSTS */
8172 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8173 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8176 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8177 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8180 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8181 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8184 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8185 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8188 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8191 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8193 + /* Clear GINTSTS */
8194 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8196 + /* Read GINTSTS */
8197 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8198 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8201 + * Send Setup packet (Get Device Descriptor)
8204 + /* Make sure channel is disabled */
8205 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8206 + if (hcchar.b.chen) {
8207 + //fprintf(stderr, "Channel already enabled 1, HCCHAR = %08x\n", hcchar.d32);
8208 + hcchar.b.chdis = 1;
8209 + // hcchar.b.chen = 1;
8210 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8214 + /* Read GINTSTS */
8215 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8216 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8219 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8220 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8223 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8224 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8227 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8228 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8231 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8234 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8236 + /* Clear GINTSTS */
8237 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8239 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8240 + //if (hcchar.b.chen) {
8241 + // fprintf(stderr, "** Channel _still_ enabled 1, HCCHAR = %08x **\n", hcchar.d32);
8247 + hctsiz.b.xfersize = 8;
8248 + hctsiz.b.pktcnt = 1;
8249 + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
8250 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8253 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8254 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8255 + hcchar.b.epdir = 0;
8256 + hcchar.b.epnum = 0;
8258 + hcchar.b.chen = 1;
8259 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8261 + /* Fill FIFO with Setup data for Get Device Descriptor */
8262 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8263 + dwc_write_reg32(data_fifo++, 0x01000680);
8264 + dwc_write_reg32(data_fifo++, 0x00080000);
8266 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8267 + //fprintf(stderr, "Waiting for HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
8269 + /* Wait for host channel interrupt */
8271 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8272 + } while (gintsts.b.hcintr == 0);
8274 + //fprintf(stderr, "Got HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
8276 + /* Disable HCINTs */
8277 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
8279 + /* Disable HAINTs */
8280 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
8283 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8284 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8287 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8288 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8291 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8292 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8295 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8298 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8300 + /* Clear GINTSTS */
8301 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8303 + /* Read GINTSTS */
8304 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8305 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8308 +static void do_in_ack(void)
8310 + gintsts_data_t gintsts;
8311 + hctsiz_data_t hctsiz;
8312 + hcchar_data_t hcchar;
8313 + haint_data_t haint;
8314 + hcint_data_t hcint;
8315 + host_grxsts_data_t grxsts;
8317 + /* Enable HAINTs */
8318 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
8320 + /* Enable HCINTs */
8321 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
8323 + /* Read GINTSTS */
8324 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8325 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8328 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8329 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8332 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8333 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8336 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8337 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8340 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8343 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8345 + /* Clear GINTSTS */
8346 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8348 + /* Read GINTSTS */
8349 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8350 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8353 + * Receive Control In packet
8356 + /* Make sure channel is disabled */
8357 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8358 + if (hcchar.b.chen) {
8359 + //fprintf(stderr, "Channel already enabled 2, HCCHAR = %08x\n", hcchar.d32);
8360 + hcchar.b.chdis = 1;
8361 + hcchar.b.chen = 1;
8362 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8366 + /* Read GINTSTS */
8367 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8368 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8371 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8372 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8375 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8376 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8379 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8380 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8383 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8386 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8388 + /* Clear GINTSTS */
8389 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8391 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8392 + //if (hcchar.b.chen) {
8393 + // fprintf(stderr, "** Channel _still_ enabled 2, HCCHAR = %08x **\n", hcchar.d32);
8399 + hctsiz.b.xfersize = 8;
8400 + hctsiz.b.pktcnt = 1;
8401 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
8402 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8405 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8406 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8407 + hcchar.b.epdir = 1;
8408 + hcchar.b.epnum = 0;
8410 + hcchar.b.chen = 1;
8411 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8413 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8414 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
8416 + /* Wait for receive status queue interrupt */
8418 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8419 + } while (gintsts.b.rxstsqlvl == 0);
8421 + //fprintf(stderr, "Got RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
8424 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
8425 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
8427 + /* Clear RXSTSQLVL in GINTSTS */
8429 + gintsts.b.rxstsqlvl = 1;
8430 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8432 + switch (grxsts.b.pktsts) {
8433 + case DWC_GRXSTS_PKTSTS_IN:
8434 + /* Read the data into the host buffer */
8435 + if (grxsts.b.bcnt > 0) {
8437 + int word_count = (grxsts.b.bcnt + 3) / 4;
8439 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8441 + for (i = 0; i < word_count; i++) {
8442 + (void)dwc_read_reg32(data_fifo++);
8446 + //fprintf(stderr, "Received %u bytes\n", (unsigned)grxsts.b.bcnt);
8450 + //fprintf(stderr, "** Unexpected GRXSTS packet status 1 **\n");
8454 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8455 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
8457 + /* Wait for receive status queue interrupt */
8459 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8460 + } while (gintsts.b.rxstsqlvl == 0);
8462 + //fprintf(stderr, "Got RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
8465 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
8466 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
8468 + /* Clear RXSTSQLVL in GINTSTS */
8470 + gintsts.b.rxstsqlvl = 1;
8471 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8473 + switch (grxsts.b.pktsts) {
8474 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
8478 + //fprintf(stderr, "** Unexpected GRXSTS packet status 2 **\n");
8482 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8483 + //fprintf(stderr, "Waiting for HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
8485 + /* Wait for host channel interrupt */
8487 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8488 + } while (gintsts.b.hcintr == 0);
8490 + //fprintf(stderr, "Got HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
8493 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8494 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8497 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8498 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8501 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8502 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8505 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8508 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8510 + /* Clear GINTSTS */
8511 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8513 + /* Read GINTSTS */
8514 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8515 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8517 + // usleep(100000);
8522 + * Send handshake packet
8526 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8527 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8530 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8531 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8534 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8535 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8538 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8541 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8543 + /* Clear GINTSTS */
8544 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8546 + /* Read GINTSTS */
8547 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8548 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8550 + /* Make sure channel is disabled */
8551 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8552 + if (hcchar.b.chen) {
8553 + //fprintf(stderr, "Channel already enabled 3, HCCHAR = %08x\n", hcchar.d32);
8554 + hcchar.b.chdis = 1;
8555 + hcchar.b.chen = 1;
8556 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8560 + /* Read GINTSTS */
8561 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8562 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8565 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8566 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8569 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8570 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8573 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8574 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8577 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8580 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8582 + /* Clear GINTSTS */
8583 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8585 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8586 + //if (hcchar.b.chen) {
8587 + // fprintf(stderr, "** Channel _still_ enabled 3, HCCHAR = %08x **\n", hcchar.d32);
8593 + hctsiz.b.xfersize = 0;
8594 + hctsiz.b.pktcnt = 1;
8595 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
8596 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8599 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8600 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8601 + hcchar.b.epdir = 0;
8602 + hcchar.b.epnum = 0;
8604 + hcchar.b.chen = 1;
8605 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8607 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8608 + //fprintf(stderr, "Waiting for HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
8610 + /* Wait for host channel interrupt */
8612 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8613 + } while (gintsts.b.hcintr == 0);
8615 + //fprintf(stderr, "Got HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
8617 + /* Disable HCINTs */
8618 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
8620 + /* Disable HAINTs */
8621 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
8624 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8625 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8628 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8629 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8632 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8633 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8636 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8639 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8641 + /* Clear GINTSTS */
8642 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8644 + /* Read GINTSTS */
8645 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8646 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8648 +#endif /* DWC_HS_ELECT_TST */
8650 +/** Handles hub class-specific requests.*/
8651 +int dwc_otg_hcd_hub_control(struct usb_hcd *_hcd,
8660 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8661 + dwc_otg_core_if_t *core_if = hcd_to_dwc_otg_hcd (_hcd)->core_if;
8662 + struct usb_hub_descriptor *desc;
8663 + hprt0_data_t hprt0 = {.d32 = 0};
8665 + uint32_t port_status;
8667 + switch (_typeReq) {
8668 + case ClearHubFeature:
8669 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8670 + "ClearHubFeature 0x%x\n", _wValue);
8671 + switch (_wValue) {
8672 + case C_HUB_LOCAL_POWER:
8673 + case C_HUB_OVER_CURRENT:
8674 + /* Nothing required here */
8678 + DWC_ERROR ("DWC OTG HCD - "
8679 + "ClearHubFeature request %xh unknown\n", _wValue);
8682 + case ClearPortFeature:
8683 + if (!_wIndex || _wIndex > 1)
8686 + switch (_wValue) {
8687 + case USB_PORT_FEAT_ENABLE:
8688 + DWC_DEBUGPL (DBG_ANY, "DWC OTG HCD HUB CONTROL - "
8689 + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
8690 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8691 + hprt0.b.prtena = 1;
8692 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8694 + case USB_PORT_FEAT_SUSPEND:
8695 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8696 + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
8697 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8698 + hprt0.b.prtres = 1;
8699 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8700 + /* Clear Resume bit */
8702 + hprt0.b.prtres = 0;
8703 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8705 + case USB_PORT_FEAT_POWER:
8706 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8707 + "ClearPortFeature USB_PORT_FEAT_POWER\n");
8708 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8709 + hprt0.b.prtpwr = 0;
8710 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8712 + case USB_PORT_FEAT_INDICATOR:
8713 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8714 + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
8715 + /* Port inidicator not supported */
8717 + case USB_PORT_FEAT_C_CONNECTION:
8718 + /* Clears drivers internal connect status change
8720 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8721 + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
8722 + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
8724 + case USB_PORT_FEAT_C_RESET:
8725 + /* Clears the driver's internal Port Reset Change
8727 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8728 + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
8729 + dwc_otg_hcd->flags.b.port_reset_change = 0;
8731 + case USB_PORT_FEAT_C_ENABLE:
8732 + /* Clears the driver's internal Port
8733 + * Enable/Disable Change flag */
8734 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8735 + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
8736 + dwc_otg_hcd->flags.b.port_enable_change = 0;
8738 + case USB_PORT_FEAT_C_SUSPEND:
8739 + /* Clears the driver's internal Port Suspend
8740 + * Change flag, which is set when resume signaling on
8741 + * the host port is complete */
8742 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8743 + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
8744 + dwc_otg_hcd->flags.b.port_suspend_change = 0;
8746 + case USB_PORT_FEAT_C_OVER_CURRENT:
8747 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8748 + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
8749 + dwc_otg_hcd->flags.b.port_over_current_change = 0;
8753 + DWC_ERROR ("DWC OTG HCD - "
8754 + "ClearPortFeature request %xh "
8755 + "unknown or unsupported\n", _wValue);
8758 + case GetHubDescriptor:
8759 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8760 + "GetHubDescriptor\n");
8761 + desc = (struct usb_hub_descriptor *)_buf;
8762 + desc->bDescLength = 9;
8763 + desc->bDescriptorType = 0x29;
8764 + desc->bNbrPorts = 1;
8765 + desc->wHubCharacteristics = 0x08;
8766 + desc->bPwrOn2PwrGood = 1;
8767 + desc->bHubContrCurrent = 0;
8768 + desc->bitmap[0] = 0;
8769 + desc->bitmap[1] = 0xff;
8771 + case GetHubStatus:
8772 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8773 + "GetHubStatus\n");
8774 + memset (_buf, 0, 4);
8776 + case GetPortStatus:
8777 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8778 + "GetPortStatus\n");
8780 + if (!_wIndex || _wIndex > 1)
8785 + if (dwc_otg_hcd->flags.b.port_connect_status_change)
8786 + port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
8788 + if (dwc_otg_hcd->flags.b.port_enable_change)
8789 + port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
8791 + if (dwc_otg_hcd->flags.b.port_suspend_change)
8792 + port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
8794 + if (dwc_otg_hcd->flags.b.port_reset_change)
8795 + port_status |= (1 << USB_PORT_FEAT_C_RESET);
8797 + if (dwc_otg_hcd->flags.b.port_over_current_change) {
8798 + DWC_ERROR("Device Not Supported\n");
8799 + port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
8802 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
8803 + printk("DISCONNECTED PORT\n");
8805 + * The port is disconnected, which means the core is
8806 + * either in device mode or it soon will be. Just
8807 + * return 0's for the remainder of the port status
8808 + * since the port register can't be read if the core
8809 + * is in device mode.
8812 + *((u32 *) _buf) = cpu_to_le32(port_status);
8814 + *((__le32 *) _buf) = cpu_to_le32(port_status);
8819 + hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
8820 + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
8822 + if (hprt0.b.prtconnsts)
8823 + port_status |= (1 << USB_PORT_FEAT_CONNECTION);
8825 + if (hprt0.b.prtena)
8826 + port_status |= (1 << USB_PORT_FEAT_ENABLE);
8828 + if (hprt0.b.prtsusp)
8829 + port_status |= (1 << USB_PORT_FEAT_SUSPEND);
8831 + if (hprt0.b.prtovrcurract)
8832 + port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
8834 + if (hprt0.b.prtrst)
8835 + port_status |= (1 << USB_PORT_FEAT_RESET);
8837 + if (hprt0.b.prtpwr)
8838 + port_status |= (1 << USB_PORT_FEAT_POWER);
8840 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
8841 + port_status |= USB_PORT_STAT_HIGH_SPEED;
8843 + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
8844 + port_status |= (1 << USB_PORT_FEAT_LOWSPEED);
8846 + if (hprt0.b.prttstctl)
8847 + port_status |= (1 << USB_PORT_FEAT_TEST);
8849 + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
8851 + *((u32 *) _buf) = cpu_to_le32(port_status);
8853 + *((__le32 *) _buf) = cpu_to_le32(port_status);
8857 + case SetHubFeature:
8858 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8859 + "SetHubFeature\n");
8860 + /* No HUB features supported */
8862 + case SetPortFeature:
8863 + if (_wValue != USB_PORT_FEAT_TEST && (!_wIndex || _wIndex > 1))
8866 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
8868 + * The port is disconnected, which means the core is
8869 + * either in device mode or it soon will be. Just
8870 + * return without doing anything since the port
8871 + * register can't be written if the core is in device
8877 + switch (_wValue) {
8878 + case USB_PORT_FEAT_SUSPEND:
8879 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8880 + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
8881 + if (_hcd->self.otg_port == _wIndex
8882 + && _hcd->self.b_hnp_enable) {
8883 + gotgctl_data_t gotgctl = {.d32=0};
8884 + gotgctl.b.hstsethnpen = 1;
8885 + dwc_modify_reg32(&core_if->core_global_regs->
8886 + gotgctl, 0, gotgctl.d32);
8887 + core_if->op_state = A_SUSPEND;
8889 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8890 + hprt0.b.prtsusp = 1;
8891 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8892 + //DWC_PRINT( "SUSPEND: HPRT0=%0x\n", hprt0.d32);
8893 + /* Suspend the Phy Clock */
8895 + pcgcctl_data_t pcgcctl = {.d32=0};
8896 + pcgcctl.b.stoppclk = 1;
8897 + dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
8900 + /* For HNP the bus must be suspended for at least 200ms.*/
8901 + if (_hcd->self.b_hnp_enable) {
8903 + //DWC_PRINT( "SUSPEND: wait complete! (%d)\n", _hcd->state);
8906 + case USB_PORT_FEAT_POWER:
8907 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8908 + "SetPortFeature - USB_PORT_FEAT_POWER\n");
8909 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8910 + hprt0.b.prtpwr = 1;
8911 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8913 + case USB_PORT_FEAT_RESET:
8914 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8915 + "SetPortFeature - USB_PORT_FEAT_RESET\n");
8916 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8917 + /* TODO: Is this for OTG protocol??
8918 + * We shoudl remove OTG totally for Danube system.
8919 + * But, in the future, maybe we need this.
8922 + hprt0.b.prtrst = 1;
8923 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8925 + /* When B-Host the Port reset bit is set in
8926 + * the Start HCD Callback function, so that
8927 + * the reset is started within 1ms of the HNP
8928 + * success interrupt. */
8929 + if (!_hcd->self.is_b_host) {
8930 + hprt0.b.prtrst = 1;
8931 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8934 + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
8936 + hprt0.b.prtrst = 0;
8937 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8940 +#ifdef DWC_HS_ELECT_TST
8941 + case USB_PORT_FEAT_TEST:
8944 + gintmsk_data_t gintmsk;
8946 + t = (_wIndex >> 8); /* MSB wIndex USB */
8947 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8948 + "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
8949 + printk("USB_PORT_FEAT_TEST %d\n", t);
8951 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8952 + hprt0.b.prttstctl = t;
8953 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8955 + /* Setup global vars with reg addresses (quick and
8956 + * dirty hack, should be cleaned up)
8958 + global_regs = core_if->core_global_regs;
8959 + hc_global_regs = core_if->host_if->host_global_regs;
8960 + hc_regs = (dwc_otg_hc_regs_t *)((char *)global_regs + 0x500);
8961 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8963 + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
8964 + /* Save current interrupt mask */
8965 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
8967 + /* Disable all interrupts while we muck with
8968 + * the hardware directly
8970 + dwc_write_reg32(&global_regs->gintmsk, 0);
8972 + /* 15 second delay per the test spec */
8975 + /* Drive suspend on the root port */
8976 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8977 + hprt0.b.prtsusp = 1;
8978 + hprt0.b.prtres = 0;
8979 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8981 + /* 15 second delay per the test spec */
8984 + /* Drive resume on the root port */
8985 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8986 + hprt0.b.prtsusp = 0;
8987 + hprt0.b.prtres = 1;
8988 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8991 + /* Clear the resume bit */
8992 + hprt0.b.prtres = 0;
8993 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8995 + /* Restore interrupts */
8996 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
8997 + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
8998 + /* Save current interrupt mask */
8999 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
9001 + /* Disable all interrupts while we muck with
9002 + * the hardware directly
9004 + dwc_write_reg32(&global_regs->gintmsk, 0);
9006 + /* 15 second delay per the test spec */
9009 + /* Send the Setup packet */
9012 + /* 15 second delay so nothing else happens for awhile */
9015 + /* Restore interrupts */
9016 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
9017 + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
9018 + /* Save current interrupt mask */
9019 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
9021 + /* Disable all interrupts while we muck with
9022 + * the hardware directly
9024 + dwc_write_reg32(&global_regs->gintmsk, 0);
9026 + /* Send the Setup packet */
9029 + /* 15 second delay so nothing else happens for awhile */
9032 + /* Send the In and Ack packets */
9035 + /* 15 second delay so nothing else happens for awhile */
9038 + /* Restore interrupts */
9039 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
9044 +#endif /* DWC_HS_ELECT_TST */
9046 + case USB_PORT_FEAT_INDICATOR:
9047 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
9048 + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
9049 + /* Not supported */
9053 + DWC_ERROR ("DWC OTG HCD - "
9054 + "SetPortFeature request %xh "
9055 + "unknown or unsupported\n", _wValue);
9062 + DWC_WARN ("DWC OTG HCD - "
9063 + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
9064 + _typeReq, _wIndex, _wValue);
9073 + * Assigns transactions from a QTD to a free host channel and initializes the
9074 + * host channel to perform the transactions. The host channel is removed from
9077 + * @param _hcd The HCD state structure.
9078 + * @param _qh Transactions from the first QTD for this QH are selected and
9079 + * assigned to a free host channel.
9081 +static void assign_and_init_hc(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
9084 + dwc_otg_qtd_t *qtd;
9087 + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p)\n", __func__, _hcd, _qh);
9089 + hc = list_entry(_hcd->free_hc_list.next, dwc_hc_t, hc_list_entry);
9091 + /* Remove the host channel from the free list. */
9092 + list_del_init(&hc->hc_list_entry);
9094 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
9096 + _qh->channel = hc;
9097 + _qh->qtd_in_process = qtd;
9100 + * Use usb_pipedevice to determine device address. This address is
9101 + * 0 before the SET_ADDRESS command and the correct address afterward.
9103 + hc->dev_addr = usb_pipedevice(urb->pipe);
9104 + hc->ep_num = usb_pipeendpoint(urb->pipe);
9106 + if (urb->dev->speed == USB_SPEED_LOW) {
9107 + hc->speed = DWC_OTG_EP_SPEED_LOW;
9108 + } else if (urb->dev->speed == USB_SPEED_FULL) {
9109 + hc->speed = DWC_OTG_EP_SPEED_FULL;
9111 + hc->speed = DWC_OTG_EP_SPEED_HIGH;
9113 + hc->max_packet = dwc_max_packet(_qh->maxp);
9115 + hc->xfer_started = 0;
9116 + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
9117 + hc->error_state = (qtd->error_count > 0);
9118 + hc->halt_on_queue = 0;
9119 + hc->halt_pending = 0;
9123 + * The following values may be modified in the transfer type section
9124 + * below. The xfer_len value may be reduced when the transfer is
9125 + * started to accommodate the max widths of the XferSize and PktCnt
9126 + * fields in the HCTSIZn register.
9128 + hc->do_ping = _qh->ping_state;
9129 + hc->ep_is_in = (usb_pipein(urb->pipe) != 0);
9130 + hc->data_pid_start = _qh->data_toggle;
9131 + hc->multi_count = 1;
9133 + if (_hcd->core_if->dma_enable) {
9134 + hc->xfer_buff = (uint8_t *)(u32)urb->transfer_dma + urb->actual_length;
9136 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer + urb->actual_length;
9138 + hc->xfer_len = urb->transfer_buffer_length - urb->actual_length;
9139 + hc->xfer_count = 0;
9142 + * Set the split attributes
9145 + if (_qh->do_split) {
9147 + hc->xact_pos = qtd->isoc_split_pos;
9148 + hc->complete_split = qtd->complete_split;
9149 + hc->hub_addr = urb->dev->tt->hub->devnum;
9150 + hc->port_addr = urb->dev->ttport;
9153 + switch (usb_pipetype(urb->pipe)) {
9154 + case PIPE_CONTROL:
9155 + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
9156 + switch (qtd->control_phase) {
9157 + case DWC_OTG_CONTROL_SETUP:
9158 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
9161 + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
9162 + if (_hcd->core_if->dma_enable) {
9163 + hc->xfer_buff = (uint8_t *)(u32)urb->setup_dma;
9165 + hc->xfer_buff = (uint8_t *)urb->setup_packet;
9169 + case DWC_OTG_CONTROL_DATA:
9170 + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
9171 + hc->data_pid_start = qtd->data_toggle;
9173 + case DWC_OTG_CONTROL_STATUS:
9175 + * Direction is opposite of data direction or IN if no
9178 + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
9179 + if (urb->transfer_buffer_length == 0) {
9182 + hc->ep_is_in = (usb_pipein(urb->pipe) != USB_DIR_IN);
9184 + if (hc->ep_is_in) {
9187 + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
9189 + if (_hcd->core_if->dma_enable) {
9190 + hc->xfer_buff = (uint8_t *)_hcd->status_buf_dma;
9192 + hc->xfer_buff = (uint8_t *)_hcd->status_buf;
9198 + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
9200 + case PIPE_INTERRUPT:
9201 + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
9203 + case PIPE_ISOCHRONOUS:
9205 + struct usb_iso_packet_descriptor *frame_desc;
9206 + frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
9207 + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
9208 + if (_hcd->core_if->dma_enable) {
9209 + hc->xfer_buff = (uint8_t *)(u32)urb->transfer_dma;
9211 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer;
9213 + hc->xfer_buff += frame_desc->offset + qtd->isoc_split_offset;
9214 + hc->xfer_len = frame_desc->length - qtd->isoc_split_offset;
9216 + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
9217 + if (hc->xfer_len <= 188) {
9218 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
9221 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_BEGIN;
9228 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
9229 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
9231 + * This value may be modified when the transfer is started to
9232 + * reflect the actual transfer length.
9234 + hc->multi_count = dwc_hb_mult(_qh->maxp);
9237 + dwc_otg_hc_init(_hcd->core_if, hc);
9240 +#define DEBUG_HOST_CHANNELS
9241 +#ifdef DEBUG_HOST_CHANNELS
9242 +static int last_sel_trans_num_per_scheduled = 0;
9243 +module_param(last_sel_trans_num_per_scheduled, int, 0444);
9245 +static int last_sel_trans_num_nonper_scheduled = 0;
9246 +module_param(last_sel_trans_num_nonper_scheduled, int, 0444);
9248 +static int last_sel_trans_num_avail_hc_at_start = 0;
9249 +module_param(last_sel_trans_num_avail_hc_at_start, int, 0444);
9251 +static int last_sel_trans_num_avail_hc_at_end = 0;
9252 +module_param(last_sel_trans_num_avail_hc_at_end, int, 0444);
9253 +#endif /* DEBUG_HOST_CHANNELS */
9256 + * This function selects transactions from the HCD transfer schedule and
9257 + * assigns them to available host channels. It is called from HCD interrupt
9258 + * handler functions.
9260 + * @param _hcd The HCD state structure.
9262 + * @return The types of new transactions that were assigned to host channels.
9264 +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd)
9266 + struct list_head *qh_ptr;
9269 + unsigned long flags;
9270 + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
9273 + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
9276 +#ifdef DEBUG_HOST_CHANNELS
9277 + last_sel_trans_num_per_scheduled = 0;
9278 + last_sel_trans_num_nonper_scheduled = 0;
9279 + last_sel_trans_num_avail_hc_at_start = _hcd->available_host_channels;
9280 +#endif /* DEBUG_HOST_CHANNELS */
9282 + /* Process entries in the periodic ready list. */
9283 + num_channels = _hcd->core_if->core_params->host_channels;
9284 + qh_ptr = _hcd->periodic_sched_ready.next;
9285 + while (qh_ptr != &_hcd->periodic_sched_ready
9286 + && !list_empty(&_hcd->free_hc_list)) {
9288 + // Make sure we leave one channel for non periodic transactions.
9289 + local_irq_save(flags);
9290 + if (_hcd->available_host_channels <= 1) {
9291 + local_irq_restore(flags);
9294 + _hcd->available_host_channels--;
9295 + local_irq_restore(flags);
9296 +#ifdef DEBUG_HOST_CHANNELS
9297 + last_sel_trans_num_per_scheduled++;
9298 +#endif /* DEBUG_HOST_CHANNELS */
9300 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9301 + assign_and_init_hc(_hcd, qh);
9304 + * Move the QH from the periodic ready schedule to the
9305 + * periodic assigned schedule.
9307 + qh_ptr = qh_ptr->next;
9308 + local_irq_save(flags);
9309 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_assigned);
9310 + local_irq_restore(flags);
9311 + ret_val = DWC_OTG_TRANSACTION_PERIODIC;
9315 + * Process entries in the deferred portion of the non-periodic list.
9316 + * A NAK put them here and, at the right time, they need to be
9317 + * placed on the sched_inactive list.
9319 + qh_ptr = _hcd->non_periodic_sched_deferred.next;
9320 + while (qh_ptr != &_hcd->non_periodic_sched_deferred) {
9321 + uint16_t frame_number =
9322 + dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
9323 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9324 + qh_ptr = qh_ptr->next;
9326 + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
9329 + * Move the QH from the non periodic deferred schedule to
9330 + * the non periodic inactive schedule.
9332 + local_irq_save(flags);
9333 + list_move(&qh->qh_list_entry,
9334 + &_hcd->non_periodic_sched_inactive);
9335 + local_irq_restore(flags);
9340 + * Process entries in the inactive portion of the non-periodic
9341 + * schedule. Some free host channels may not be used if they are
9342 + * reserved for periodic transfers.
9344 + qh_ptr = _hcd->non_periodic_sched_inactive.next;
9345 + num_channels = _hcd->core_if->core_params->host_channels;
9346 + while (qh_ptr != &_hcd->non_periodic_sched_inactive
9347 + && !list_empty(&_hcd->free_hc_list)) {
9349 + local_irq_save(flags);
9350 + if (_hcd->available_host_channels < 1) {
9351 + local_irq_restore(flags);
9354 + _hcd->available_host_channels--;
9355 + local_irq_restore(flags);
9356 +#ifdef DEBUG_HOST_CHANNELS
9357 + last_sel_trans_num_nonper_scheduled++;
9358 +#endif /* DEBUG_HOST_CHANNELS */
9360 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9361 + assign_and_init_hc(_hcd, qh);
9364 + * Move the QH from the non-periodic inactive schedule to the
9365 + * non-periodic active schedule.
9367 + qh_ptr = qh_ptr->next;
9368 + local_irq_save(flags);
9369 + list_move(&qh->qh_list_entry, &_hcd->non_periodic_sched_active);
9370 + local_irq_restore(flags);
9372 + if (ret_val == DWC_OTG_TRANSACTION_NONE) {
9373 + ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
9375 + ret_val = DWC_OTG_TRANSACTION_ALL;
9379 +#ifdef DEBUG_HOST_CHANNELS
9380 + last_sel_trans_num_avail_hc_at_end = _hcd->available_host_channels;
9381 +#endif /* DEBUG_HOST_CHANNELS */
9387 + * Attempts to queue a single transaction request for a host channel
9388 + * associated with either a periodic or non-periodic transfer. This function
9389 + * assumes that there is space available in the appropriate request queue. For
9390 + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
9391 + * is available in the appropriate Tx FIFO.
9393 + * @param _hcd The HCD state structure.
9394 + * @param _hc Host channel descriptor associated with either a periodic or
9395 + * non-periodic transfer.
9396 + * @param _fifo_dwords_avail Number of DWORDs available in the periodic Tx
9397 + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
9400 + * @return 1 if a request is queued and more requests may be needed to
9401 + * complete the transfer, 0 if no more requests are required for this
9402 + * transfer, -1 if there is insufficient space in the Tx FIFO.
9404 +static int queue_transaction(dwc_otg_hcd_t *_hcd,
9406 + uint16_t _fifo_dwords_avail)
9410 + if (_hcd->core_if->dma_enable) {
9411 + if (!_hc->xfer_started) {
9412 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9413 + _hc->qh->ping_state = 0;
9416 + } else if (_hc->halt_pending) {
9417 + /* Don't queue a request if the channel has been halted. */
9419 + } else if (_hc->halt_on_queue) {
9420 + dwc_otg_hc_halt(_hcd->core_if, _hc, _hc->halt_status);
9422 + } else if (_hc->do_ping) {
9423 + if (!_hc->xfer_started) {
9424 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9427 + } else if (!_hc->ep_is_in ||
9428 + _hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
9429 + if ((_fifo_dwords_avail * 4) >= _hc->max_packet) {
9430 + if (!_hc->xfer_started) {
9431 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9434 + retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
9440 + if (!_hc->xfer_started) {
9441 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9444 + retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
9452 + * Processes active non-periodic channels and queues transactions for these
9453 + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
9454 + * FIFO Empty interrupt is enabled if there are more transactions to queue as
9455 + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
9456 + * FIFO Empty interrupt is disabled.
9458 +static void process_non_periodic_channels(dwc_otg_hcd_t *_hcd)
9460 + gnptxsts_data_t tx_status;
9461 + struct list_head *orig_qh_ptr;
9464 + int no_queue_space = 0;
9465 + int no_fifo_space = 0;
9466 + int more_to_do = 0;
9468 + dwc_otg_core_global_regs_t *global_regs = _hcd->core_if->core_global_regs;
9470 + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
9472 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9473 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (before queue): %d\n",
9474 + tx_status.b.nptxqspcavail);
9475 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
9476 + tx_status.b.nptxfspcavail);
9479 + * Keep track of the starting point. Skip over the start-of-list
9482 + if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
9483 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9485 + orig_qh_ptr = _hcd->non_periodic_qh_ptr;
9488 + * Process once through the active list or until no more space is
9489 + * available in the request queue or the Tx FIFO.
9492 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9493 + if (!_hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
9494 + no_queue_space = 1;
9498 + qh = list_entry(_hcd->non_periodic_qh_ptr, dwc_otg_qh_t, qh_list_entry);
9499 + status = queue_transaction(_hcd, qh->channel, tx_status.b.nptxfspcavail);
9503 + } else if (status < 0) {
9504 + no_fifo_space = 1;
9508 + /* Advance to next QH, skipping start-of-list entry. */
9509 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9510 + if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
9511 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9514 + } while (_hcd->non_periodic_qh_ptr != orig_qh_ptr);
9516 + if (!_hcd->core_if->dma_enable) {
9517 + gintmsk_data_t intr_mask = {.d32 = 0};
9518 + intr_mask.b.nptxfempty = 1;
9521 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9522 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (after queue): %d\n",
9523 + tx_status.b.nptxqspcavail);
9524 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (after queue): %d\n",
9525 + tx_status.b.nptxfspcavail);
9527 + if (more_to_do || no_queue_space || no_fifo_space) {
9529 + * May need to queue more transactions as the request
9530 + * queue or Tx FIFO empties. Enable the non-periodic
9531 + * Tx FIFO empty interrupt. (Always use the half-empty
9532 + * level to ensure that new requests are loaded as
9533 + * soon as possible.)
9535 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
9538 + * Disable the Tx FIFO empty interrupt since there are
9539 + * no more transactions that need to be queued right
9540 + * now. This function is called from interrupt
9541 + * handlers to queue more transactions as transfer
9544 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
9550 + * Processes periodic channels for the next frame and queues transactions for
9551 + * these channels to the DWC_otg controller. After queueing transactions, the
9552 + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
9553 + * to queue as Periodic Tx FIFO or request queue space becomes available.
9554 + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
9556 +static void process_periodic_channels(dwc_otg_hcd_t *_hcd)
9558 + hptxsts_data_t tx_status;
9559 + struct list_head *qh_ptr;
9562 + int no_queue_space = 0;
9563 + int no_fifo_space = 0;
9565 + dwc_otg_host_global_regs_t *host_regs;
9566 + host_regs = _hcd->core_if->host_if->host_global_regs;
9568 + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
9570 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9571 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (before queue): %d\n",
9572 + tx_status.b.ptxqspcavail);
9573 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
9574 + tx_status.b.ptxfspcavail);
9577 + qh_ptr = _hcd->periodic_sched_assigned.next;
9578 + while (qh_ptr != &_hcd->periodic_sched_assigned) {
9579 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9580 + if (tx_status.b.ptxqspcavail == 0) {
9581 + no_queue_space = 1;
9585 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9588 + * Set a flag if we're queuing high-bandwidth in slave mode.
9589 + * The flag prevents any halts to get into the request queue in
9590 + * the middle of multiple high-bandwidth packets getting queued.
9592 + if ((!_hcd->core_if->dma_enable) &&
9593 + (qh->channel->multi_count > 1))
9595 + _hcd->core_if->queuing_high_bandwidth = 1;
9598 + status = queue_transaction(_hcd, qh->channel, tx_status.b.ptxfspcavail);
9600 + no_fifo_space = 1;
9605 + * In Slave mode, stay on the current transfer until there is
9606 + * nothing more to do or the high-bandwidth request count is
9607 + * reached. In DMA mode, only need to queue one request. The
9608 + * controller automatically handles multiple packets for
9609 + * high-bandwidth transfers.
9611 + if (_hcd->core_if->dma_enable ||
9613 + qh->channel->requests == qh->channel->multi_count)) {
9614 + qh_ptr = qh_ptr->next;
9616 + * Move the QH from the periodic assigned schedule to
9617 + * the periodic queued schedule.
9619 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_queued);
9621 + /* done queuing high bandwidth */
9622 + _hcd->core_if->queuing_high_bandwidth = 0;
9626 + if (!_hcd->core_if->dma_enable) {
9627 + dwc_otg_core_global_regs_t *global_regs;
9628 + gintmsk_data_t intr_mask = {.d32 = 0};
9630 + global_regs = _hcd->core_if->core_global_regs;
9631 + intr_mask.b.ptxfempty = 1;
9633 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9634 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (after queue): %d\n",
9635 + tx_status.b.ptxqspcavail);
9636 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (after queue): %d\n",
9637 + tx_status.b.ptxfspcavail);
9639 + if (!(list_empty(&_hcd->periodic_sched_assigned)) ||
9640 + no_queue_space || no_fifo_space) {
9642 + * May need to queue more transactions as the request
9643 + * queue or Tx FIFO empties. Enable the periodic Tx
9644 + * FIFO empty interrupt. (Always use the half-empty
9645 + * level to ensure that new requests are loaded as
9646 + * soon as possible.)
9648 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
9651 + * Disable the Tx FIFO empty interrupt since there are
9652 + * no more transactions that need to be queued right
9653 + * now. This function is called from interrupt
9654 + * handlers to queue more transactions as transfer
9657 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
9663 + * This function processes the currently active host channels and queues
9664 + * transactions for these channels to the DWC_otg controller. It is called
9665 + * from HCD interrupt handler functions.
9667 + * @param _hcd The HCD state structure.
9668 + * @param _tr_type The type(s) of transactions to queue (non-periodic,
9669 + * periodic, or both).
9671 +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
9672 + dwc_otg_transaction_type_e _tr_type)
9675 + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
9677 + /* Process host channels associated with periodic transfers. */
9678 + if ((_tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
9679 + _tr_type == DWC_OTG_TRANSACTION_ALL) &&
9680 + !list_empty(&_hcd->periodic_sched_assigned)) {
9682 + process_periodic_channels(_hcd);
9685 + /* Process host channels associated with non-periodic transfers. */
9686 + if ((_tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
9687 + _tr_type == DWC_OTG_TRANSACTION_ALL)) {
9688 + if (!list_empty(&_hcd->non_periodic_sched_active)) {
9689 + process_non_periodic_channels(_hcd);
9692 + * Ensure NP Tx FIFO empty interrupt is disabled when
9693 + * there are no non-periodic transfers to process.
9695 + gintmsk_data_t gintmsk = {.d32 = 0};
9696 + gintmsk.b.nptxfempty = 1;
9697 + dwc_modify_reg32(&_hcd->core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
9703 + * Sets the final status of an URB and returns it to the device driver. Any
9704 + * required cleanup of the URB is performed.
9706 +void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t * _hcd, struct urb *_urb,
9708 + __releases(_hcd->lock)
9709 +__acquires(_hcd->lock)
9712 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
9713 + DWC_PRINT("%s: urb %p, device %d, ep %d %s, status=%d\n",
9714 + __func__, _urb, usb_pipedevice(_urb->pipe),
9715 + usb_pipeendpoint(_urb->pipe),
9716 + usb_pipein(_urb->pipe) ? "IN" : "OUT", _status);
9717 + if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
9719 + for (i = 0; i < _urb->number_of_packets; i++) {
9720 + DWC_PRINT(" ISO Desc %d status: %d\n",
9721 + i, _urb->iso_frame_desc[i].status);
9727 + _urb->status = _status;
9728 + _urb->hcpriv = NULL;
9729 + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(_hcd), _urb);
9730 + spin_unlock(&_hcd->lock);
9731 + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(_hcd), _urb, _status);
9732 + spin_lock(&_hcd->lock);
9736 + * Returns the Queue Head for an URB.
9738 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *_urb)
9740 + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(_urb);
9741 + return (dwc_otg_qh_t *)ep->hcpriv;
9745 +void dwc_print_setup_data (uint8_t *setup)
9748 + if (CHK_DEBUG_LEVEL(DBG_HCD)){
9749 + DWC_PRINT("Setup Data = MSB ");
9750 + for (i=7; i>=0; i--) DWC_PRINT ("%02x ", setup[i]);
9752 + DWC_PRINT(" bmRequestType Tranfer = %s\n", (setup[0]&0x80) ? "Device-to-Host" : "Host-to-Device");
9753 + DWC_PRINT(" bmRequestType Type = ");
9754 + switch ((setup[0]&0x60) >> 5) {
9755 + case 0: DWC_PRINT("Standard\n"); break;
9756 + case 1: DWC_PRINT("Class\n"); break;
9757 + case 2: DWC_PRINT("Vendor\n"); break;
9758 + case 3: DWC_PRINT("Reserved\n"); break;
9760 + DWC_PRINT(" bmRequestType Recipient = ");
9761 + switch (setup[0]&0x1f) {
9762 + case 0: DWC_PRINT("Device\n"); break;
9763 + case 1: DWC_PRINT("Interface\n"); break;
9764 + case 2: DWC_PRINT("Endpoint\n"); break;
9765 + case 3: DWC_PRINT("Other\n"); break;
9766 + default: DWC_PRINT("Reserved\n"); break;
9768 + DWC_PRINT(" bRequest = 0x%0x\n", setup[1]);
9769 + DWC_PRINT(" wValue = 0x%0x\n", *((uint16_t *)&setup[2]));
9770 + DWC_PRINT(" wIndex = 0x%0x\n", *((uint16_t *)&setup[4]));
9771 + DWC_PRINT(" wLength = 0x%0x\n\n", *((uint16_t *)&setup[6]));
9776 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd) {
9779 + DWC_PRINT("Frame remaining at SOF:\n");
9780 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9781 + _hcd->frrem_samples, _hcd->frrem_accum,
9782 + (_hcd->frrem_samples > 0) ?
9783 + _hcd->frrem_accum/_hcd->frrem_samples : 0);
9786 + DWC_PRINT("Frame remaining at start_transfer (uframe 7):\n");
9787 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9788 + _hcd->core_if->hfnum_7_samples, _hcd->core_if->hfnum_7_frrem_accum,
9789 + (_hcd->core_if->hfnum_7_samples > 0) ?
9790 + _hcd->core_if->hfnum_7_frrem_accum/_hcd->core_if->hfnum_7_samples : 0);
9791 + DWC_PRINT("Frame remaining at start_transfer (uframe 0):\n");
9792 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9793 + _hcd->core_if->hfnum_0_samples, _hcd->core_if->hfnum_0_frrem_accum,
9794 + (_hcd->core_if->hfnum_0_samples > 0) ?
9795 + _hcd->core_if->hfnum_0_frrem_accum/_hcd->core_if->hfnum_0_samples : 0);
9796 + DWC_PRINT("Frame remaining at start_transfer (uframe 1-6):\n");
9797 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9798 + _hcd->core_if->hfnum_other_samples, _hcd->core_if->hfnum_other_frrem_accum,
9799 + (_hcd->core_if->hfnum_other_samples > 0) ?
9800 + _hcd->core_if->hfnum_other_frrem_accum/_hcd->core_if->hfnum_other_samples : 0);
9803 + DWC_PRINT("Frame remaining at sample point A (uframe 7):\n");
9804 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9805 + _hcd->hfnum_7_samples_a, _hcd->hfnum_7_frrem_accum_a,
9806 + (_hcd->hfnum_7_samples_a > 0) ?
9807 + _hcd->hfnum_7_frrem_accum_a/_hcd->hfnum_7_samples_a : 0);
9808 + DWC_PRINT("Frame remaining at sample point A (uframe 0):\n");
9809 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9810 + _hcd->hfnum_0_samples_a, _hcd->hfnum_0_frrem_accum_a,
9811 + (_hcd->hfnum_0_samples_a > 0) ?
9812 + _hcd->hfnum_0_frrem_accum_a/_hcd->hfnum_0_samples_a : 0);
9813 + DWC_PRINT("Frame remaining at sample point A (uframe 1-6):\n");
9814 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9815 + _hcd->hfnum_other_samples_a, _hcd->hfnum_other_frrem_accum_a,
9816 + (_hcd->hfnum_other_samples_a > 0) ?
9817 + _hcd->hfnum_other_frrem_accum_a/_hcd->hfnum_other_samples_a : 0);
9820 + DWC_PRINT("Frame remaining at sample point B (uframe 7):\n");
9821 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9822 + _hcd->hfnum_7_samples_b, _hcd->hfnum_7_frrem_accum_b,
9823 + (_hcd->hfnum_7_samples_b > 0) ?
9824 + _hcd->hfnum_7_frrem_accum_b/_hcd->hfnum_7_samples_b : 0);
9825 + DWC_PRINT("Frame remaining at sample point B (uframe 0):\n");
9826 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9827 + _hcd->hfnum_0_samples_b, _hcd->hfnum_0_frrem_accum_b,
9828 + (_hcd->hfnum_0_samples_b > 0) ?
9829 + _hcd->hfnum_0_frrem_accum_b/_hcd->hfnum_0_samples_b : 0);
9830 + DWC_PRINT("Frame remaining at sample point B (uframe 1-6):\n");
9831 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9832 + _hcd->hfnum_other_samples_b, _hcd->hfnum_other_frrem_accum_b,
9833 + (_hcd->hfnum_other_samples_b > 0) ?
9834 + _hcd->hfnum_other_frrem_accum_b/_hcd->hfnum_other_samples_b : 0);
9839 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd)
9844 + gnptxsts_data_t np_tx_status;
9845 + hptxsts_data_t p_tx_status;
9847 + num_channels = _hcd->core_if->core_params->host_channels;
9849 + DWC_PRINT("************************************************************\n");
9850 + DWC_PRINT("HCD State:\n");
9851 + DWC_PRINT(" Num channels: %d\n", num_channels);
9852 + for (i = 0; i < num_channels; i++) {
9853 + dwc_hc_t *hc = _hcd->hc_ptr_array[i];
9854 + DWC_PRINT(" Channel %d:\n", i);
9855 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
9856 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
9857 + DWC_PRINT(" speed: %d\n", hc->speed);
9858 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
9859 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
9860 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
9861 + DWC_PRINT(" multi_count: %d\n", hc->multi_count);
9862 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
9863 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
9864 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
9865 + DWC_PRINT(" xfer_count: %d\n", hc->xfer_count);
9866 + DWC_PRINT(" halt_on_queue: %d\n", hc->halt_on_queue);
9867 + DWC_PRINT(" halt_pending: %d\n", hc->halt_pending);
9868 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
9869 + DWC_PRINT(" do_split: %d\n", hc->do_split);
9870 + DWC_PRINT(" complete_split: %d\n", hc->complete_split);
9871 + DWC_PRINT(" hub_addr: %d\n", hc->hub_addr);
9872 + DWC_PRINT(" port_addr: %d\n", hc->port_addr);
9873 + DWC_PRINT(" xact_pos: %d\n", hc->xact_pos);
9874 + DWC_PRINT(" requests: %d\n", hc->requests);
9875 + DWC_PRINT(" qh: %p\n", hc->qh);
9876 + if (hc->xfer_started) {
9877 + hfnum_data_t hfnum;
9878 + hcchar_data_t hcchar;
9879 + hctsiz_data_t hctsiz;
9880 + hcint_data_t hcint;
9881 + hcintmsk_data_t hcintmsk;
9882 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
9883 + hcchar.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcchar);
9884 + hctsiz.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hctsiz);
9885 + hcint.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcint);
9886 + hcintmsk.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcintmsk);
9887 + DWC_PRINT(" hfnum: 0x%08x\n", hfnum.d32);
9888 + DWC_PRINT(" hcchar: 0x%08x\n", hcchar.d32);
9889 + DWC_PRINT(" hctsiz: 0x%08x\n", hctsiz.d32);
9890 + DWC_PRINT(" hcint: 0x%08x\n", hcint.d32);
9891 + DWC_PRINT(" hcintmsk: 0x%08x\n", hcintmsk.d32);
9893 + if (hc->xfer_started && (hc->qh != NULL) && (hc->qh->qtd_in_process != NULL)) {
9894 + dwc_otg_qtd_t *qtd;
9896 + qtd = hc->qh->qtd_in_process;
9898 + DWC_PRINT(" URB Info:\n");
9899 + DWC_PRINT(" qtd: %p, urb: %p\n", qtd, urb);
9900 + if (urb != NULL) {
9901 + DWC_PRINT(" Dev: %d, EP: %d %s\n",
9902 + usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe),
9903 + usb_pipein(urb->pipe) ? "IN" : "OUT");
9904 + DWC_PRINT(" Max packet size: %d\n",
9905 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
9906 + DWC_PRINT(" transfer_buffer: %p\n", urb->transfer_buffer);
9907 + DWC_PRINT(" transfer_dma: %p\n", (void *)urb->transfer_dma);
9908 + DWC_PRINT(" transfer_buffer_length: %d\n", urb->transfer_buffer_length);
9909 + DWC_PRINT(" actual_length: %d\n", urb->actual_length);
9913 + //DWC_PRINT(" non_periodic_channels: %d\n", _hcd->non_periodic_channels);
9914 + //DWC_PRINT(" periodic_channels: %d\n", _hcd->periodic_channels);
9915 + DWC_PRINT(" available_channels: %d\n", _hcd->available_host_channels);
9916 + DWC_PRINT(" periodic_usecs: %d\n", _hcd->periodic_usecs);
9917 + np_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->core_global_regs->gnptxsts);
9918 + DWC_PRINT(" NP Tx Req Queue Space Avail: %d\n", np_tx_status.b.nptxqspcavail);
9919 + DWC_PRINT(" NP Tx FIFO Space Avail: %d\n", np_tx_status.b.nptxfspcavail);
9920 + p_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hptxsts);
9921 + DWC_PRINT(" P Tx Req Queue Space Avail: %d\n", p_tx_status.b.ptxqspcavail);
9922 + DWC_PRINT(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
9923 + dwc_otg_hcd_dump_frrem(_hcd);
9924 + dwc_otg_dump_global_registers(_hcd->core_if);
9925 + dwc_otg_dump_host_registers(_hcd->core_if);
9926 + DWC_PRINT("************************************************************\n");
9930 +#endif /* DWC_DEVICE_ONLY */
9932 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.h
9934 +/* ==========================================================================
9935 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd.h $
9936 + * $Revision: 1.1.1.1 $
9937 + * $Date: 2009-04-17 06:15:34 $
9938 + * $Change: 537387 $
9940 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
9941 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9942 + * otherwise expressly agreed to in writing between Synopsys and you.
9944 + * The Software IS NOT an item of Licensed Software or Licensed Product under
9945 + * any End User Software License Agreement or Agreement for Licensed Product
9946 + * with Synopsys or any supplement thereto. You are permitted to use and
9947 + * redistribute this Software in source and binary forms, with or without
9948 + * modification, provided that redistributions of source code must retain this
9949 + * notice. You may not view, use, disclose, copy or distribute this file or
9950 + * any information contained herein except pursuant to this license grant from
9951 + * Synopsys. If you do not agree with this notice, including the disclaimer
9952 + * below, then you are not authorized to use the Software.
9954 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
9955 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9956 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9957 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
9958 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9959 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
9960 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
9961 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9962 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9963 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
9965 + * ========================================================================== */
9966 +#ifndef DWC_DEVICE_ONLY
9967 +#if !defined(__DWC_HCD_H__)
9968 +#define __DWC_HCD_H__
9970 +#include <linux/list.h>
9971 +#include <linux/usb.h>
9972 +//#include <linux/usb/hcd.h>
9973 +#include "../core/hcd.h"
9976 +struct dwc_otg_device;
9978 +#include "dwc_otg_cil.h"
9979 +//#include "dwc_otg_ifx.h" // winder
9985 + * This file contains the structures, constants, and interfaces for
9986 + * the Host Contoller Driver (HCD).
9988 + * The Host Controller Driver (HCD) is responsible for translating requests
9989 + * from the USB Driver into the appropriate actions on the DWC_otg controller.
9990 + * It isolates the USBD from the specifics of the controller by providing an
9991 + * API to the USBD.
9995 + * Phases for control transfers.
9997 +typedef enum dwc_otg_control_phase {
9998 + DWC_OTG_CONTROL_SETUP,
9999 + DWC_OTG_CONTROL_DATA,
10000 + DWC_OTG_CONTROL_STATUS
10001 +} dwc_otg_control_phase_e;
10003 +/** Transaction types. */
10004 +typedef enum dwc_otg_transaction_type {
10005 + DWC_OTG_TRANSACTION_NONE,
10006 + DWC_OTG_TRANSACTION_PERIODIC,
10007 + DWC_OTG_TRANSACTION_NON_PERIODIC,
10008 + DWC_OTG_TRANSACTION_ALL
10009 +} dwc_otg_transaction_type_e;
10012 + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
10013 + * interrupt, or isochronous transfer. A single QTD is created for each URB
10014 + * (of one of these types) submitted to the HCD. The transfer associated with
10015 + * a QTD may require one or multiple transactions.
10017 + * A QTD is linked to a Queue Head, which is entered in either the
10018 + * non-periodic or periodic schedule for execution. When a QTD is chosen for
10019 + * execution, some or all of its transactions may be executed. After
10020 + * execution, the state of the QTD is updated. The QTD may be retired if all
10021 + * its transactions are complete or if an error occurred. Otherwise, it
10022 + * remains in the schedule so more transactions can be executed later.
10024 +struct dwc_otg_qh;
10025 +typedef struct dwc_otg_qtd {
10027 + * Determines the PID of the next data packet for the data phase of
10028 + * control transfers. Ignored for other transfer types.<br>
10029 + * One of the following values:
10030 + * - DWC_OTG_HC_PID_DATA0
10031 + * - DWC_OTG_HC_PID_DATA1
10033 + uint8_t data_toggle;
10035 + /** Current phase for control transfers (Setup, Data, or Status). */
10036 + dwc_otg_control_phase_e control_phase;
10038 + /** Keep track of the current split type
10039 + * for FS/LS endpoints on a HS Hub */
10040 + uint8_t complete_split;
10042 + /** How many bytes transferred during SSPLIT OUT */
10043 + uint32_t ssplit_out_xfer_count;
10046 + * Holds the number of bus errors that have occurred for a transaction
10047 + * within this transfer.
10049 + uint8_t error_count;
10052 + * Index of the next frame descriptor for an isochronous transfer. A
10053 + * frame descriptor describes the buffer position and length of the
10054 + * data to be transferred in the next scheduled (micro)frame of an
10055 + * isochronous transfer. It also holds status for that transaction.
10056 + * The frame index starts at 0.
10058 + int isoc_frame_index;
10060 + /** Position of the ISOC split on full/low speed */
10061 + uint8_t isoc_split_pos;
10063 + /** Position of the ISOC split in the buffer for the current frame */
10064 + uint16_t isoc_split_offset;
10066 + /** URB for this transfer */
10069 + /** This list of QTDs */
10070 + struct list_head qtd_list_entry;
10072 + /* Field to track the qh pointer */
10073 + struct dwc_otg_qh *qtd_qh_ptr;
10077 + * A Queue Head (QH) holds the static characteristics of an endpoint and
10078 + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
10079 + * be entered in either the non-periodic or periodic schedule.
10081 +typedef struct dwc_otg_qh {
10084 + * One of the following values:
10085 + * - USB_ENDPOINT_XFER_CONTROL
10086 + * - USB_ENDPOINT_XFER_ISOC
10087 + * - USB_ENDPOINT_XFER_BULK
10088 + * - USB_ENDPOINT_XFER_INT
10091 + uint8_t ep_is_in;
10093 + /** wMaxPacketSize Field of Endpoint Descriptor. */
10097 + * Determines the PID of the next data packet for non-control
10098 + * transfers. Ignored for control transfers.<br>
10099 + * One of the following values:
10100 + * - DWC_OTG_HC_PID_DATA0
10101 + * - DWC_OTG_HC_PID_DATA1
10103 + uint8_t data_toggle;
10105 + /** Ping state if 1. */
10106 + uint8_t ping_state;
10109 + * List of QTDs for this QH.
10111 + struct list_head qtd_list;
10113 + /** Host channel currently processing transfers for this QH. */
10114 + dwc_hc_t *channel;
10116 + /** QTD currently assigned to a host channel for this QH. */
10117 + dwc_otg_qtd_t *qtd_in_process;
10119 + /** Full/low speed endpoint on high-speed hub requires split. */
10120 + uint8_t do_split;
10122 + /** @name Periodic schedule information */
10125 + /** Bandwidth in microseconds per (micro)frame. */
10128 + /** Interval between transfers in (micro)frames. */
10129 + uint16_t interval;
10132 + * (micro)frame to initialize a periodic transfer. The transfer
10133 + * executes in the following (micro)frame.
10135 + uint16_t sched_frame;
10137 + /** (micro)frame at which last start split was initialized. */
10138 + uint16_t start_split_frame;
10143 + uint16_t frame_usecs[8];
10144 + /** Entry for QH in either the periodic or non-periodic schedule. */
10145 + struct list_head qh_list_entry;
10149 + * This structure holds the state of the HCD, including the non-periodic and
10150 + * periodic schedules.
10152 +typedef struct dwc_otg_hcd {
10155 + /** DWC OTG Core Interface Layer */
10156 + dwc_otg_core_if_t *core_if;
10158 + /** Internal DWC HCD Flags */
10159 + volatile union dwc_otg_hcd_internal_flags {
10162 + unsigned port_connect_status_change : 1;
10163 + unsigned port_connect_status : 1;
10164 + unsigned port_reset_change : 1;
10165 + unsigned port_enable_change : 1;
10166 + unsigned port_suspend_change : 1;
10167 + unsigned port_over_current_change : 1;
10168 + unsigned reserved : 27;
10173 + * Inactive items in the non-periodic schedule. This is a list of
10174 + * Queue Heads. Transfers associated with these Queue Heads are not
10175 + * currently assigned to a host channel.
10177 + struct list_head non_periodic_sched_inactive;
10180 + * Deferred items in the non-periodic schedule. This is a list of
10181 + * Queue Heads. Transfers associated with these Queue Heads are not
10182 + * currently assigned to a host channel.
10183 + * When we get an NAK, the QH goes here.
10185 + struct list_head non_periodic_sched_deferred;
10188 + * Active items in the non-periodic schedule. This is a list of
10189 + * Queue Heads. Transfers associated with these Queue Heads are
10190 + * currently assigned to a host channel.
10192 + struct list_head non_periodic_sched_active;
10195 + * Pointer to the next Queue Head to process in the active
10196 + * non-periodic schedule.
10198 + struct list_head *non_periodic_qh_ptr;
10201 + * Inactive items in the periodic schedule. This is a list of QHs for
10202 + * periodic transfers that are _not_ scheduled for the next frame.
10203 + * Each QH in the list has an interval counter that determines when it
10204 + * needs to be scheduled for execution. This scheduling mechanism
10205 + * allows only a simple calculation for periodic bandwidth used (i.e.
10206 + * must assume that all periodic transfers may need to execute in the
10207 + * same frame). However, it greatly simplifies scheduling and should
10208 + * be sufficient for the vast majority of OTG hosts, which need to
10209 + * connect to a small number of peripherals at one time.
10211 + * Items move from this list to periodic_sched_ready when the QH
10212 + * interval counter is 0 at SOF.
10214 + struct list_head periodic_sched_inactive;
10217 + * List of periodic QHs that are ready for execution in the next
10218 + * frame, but have not yet been assigned to host channels.
10220 + * Items move from this list to periodic_sched_assigned as host
10221 + * channels become available during the current frame.
10223 + struct list_head periodic_sched_ready;
10226 + * List of periodic QHs to be executed in the next frame that are
10227 + * assigned to host channels.
10229 + * Items move from this list to periodic_sched_queued as the
10230 + * transactions for the QH are queued to the DWC_otg controller.
10232 + struct list_head periodic_sched_assigned;
10235 + * List of periodic QHs that have been queued for execution.
10237 + * Items move from this list to either periodic_sched_inactive or
10238 + * periodic_sched_ready when the channel associated with the transfer
10239 + * is released. If the interval for the QH is 1, the item moves to
10240 + * periodic_sched_ready because it must be rescheduled for the next
10241 + * frame. Otherwise, the item moves to periodic_sched_inactive.
10243 + struct list_head periodic_sched_queued;
10246 + * Total bandwidth claimed so far for periodic transfers. This value
10247 + * is in microseconds per (micro)frame. The assumption is that all
10248 + * periodic transfers may occur in the same (micro)frame.
10250 + uint16_t periodic_usecs;
10253 + * Total bandwidth claimed so far for all periodic transfers
10255 + * This will include a mixture of HS and FS transfers.
10256 + * Units are microseconds per (micro)frame.
10257 + * We have a budget per frame and have to schedule
10258 + * transactions accordingly.
10259 + * Watch out for the fact that things are actually scheduled for the
10262 + uint16_t frame_usecs[8];
10265 + * Frame number read from the core at SOF. The value ranges from 0 to
10266 + * DWC_HFNUM_MAX_FRNUM.
10268 + uint16_t frame_number;
10271 + * Free host channels in the controller. This is a list of
10272 + * dwc_hc_t items.
10274 + struct list_head free_hc_list;
10277 + * Number of available host channels.
10279 + int available_host_channels;
10282 + * Array of pointers to the host channel descriptors. Allows accessing
10283 + * a host channel descriptor given the host channel number. This is
10284 + * useful in interrupt handlers.
10286 + dwc_hc_t *hc_ptr_array[MAX_EPS_CHANNELS];
10289 + * Buffer to use for any data received during the status phase of a
10290 + * control transfer. Normally no data is transferred during the status
10291 + * phase. This buffer is used as a bit bucket.
10293 + uint8_t *status_buf;
10296 + * DMA address for status_buf.
10298 + dma_addr_t status_buf_dma;
10299 +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
10302 + * Structure to allow starting the HCD in a non-interrupt context
10303 + * during an OTG role change.
10305 + struct work_struct start_work;
10306 + struct usb_hcd *_p;
10309 + * Connection timer. An OTG host must display a message if the device
10310 + * does not connect. Started when the VBus power is turned on via
10311 + * sysfs attribute "buspower".
10313 + struct timer_list conn_timer;
10315 + /* Tasket to do a reset */
10316 + struct tasklet_struct *reset_tasklet;
10319 + uint32_t frrem_samples;
10320 + uint64_t frrem_accum;
10322 + uint32_t hfnum_7_samples_a;
10323 + uint64_t hfnum_7_frrem_accum_a;
10324 + uint32_t hfnum_0_samples_a;
10325 + uint64_t hfnum_0_frrem_accum_a;
10326 + uint32_t hfnum_other_samples_a;
10327 + uint64_t hfnum_other_frrem_accum_a;
10329 + uint32_t hfnum_7_samples_b;
10330 + uint64_t hfnum_7_frrem_accum_b;
10331 + uint32_t hfnum_0_samples_b;
10332 + uint64_t hfnum_0_frrem_accum_b;
10333 + uint32_t hfnum_other_samples_b;
10334 + uint64_t hfnum_other_frrem_accum_b;
10339 +/** Gets the dwc_otg_hcd from a struct usb_hcd */
10340 +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
10342 + return (dwc_otg_hcd_t *)(hcd->hcd_priv);
10345 +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
10346 +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t *dwc_otg_hcd)
10348 + return container_of((void *)dwc_otg_hcd, struct usb_hcd, hcd_priv);
10351 +/** @name HCD Create/Destroy Functions */
10353 +extern int __devinit dwc_otg_hcd_init(struct device *_dev, dwc_otg_device_t * dwc_otg_device);
10354 +extern void dwc_otg_hcd_remove(struct device *_dev);
10357 +/** @name Linux HC Driver API Functions */
10360 +extern int dwc_otg_hcd_start(struct usb_hcd *hcd);
10361 +extern void dwc_otg_hcd_stop(struct usb_hcd *hcd);
10362 +extern int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd);
10363 +extern void dwc_otg_hcd_free(struct usb_hcd *hcd);
10365 +extern int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
10367 + gfp_t mem_flags);
10368 +extern int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
10371 +extern irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
10373 +extern void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
10374 + struct usb_host_endpoint *ep);
10376 +extern int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd,
10378 +extern int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
10387 +/** @name Transaction Execution Functions */
10389 +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd);
10390 +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
10391 + dwc_otg_transaction_type_e _tr_type);
10392 +extern void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *_hcd, struct urb *_urb,
10396 +/** @name Interrupt Handler Functions */
10398 +extern int32_t dwc_otg_hcd_handle_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10399 +extern int32_t dwc_otg_hcd_handle_sof_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10400 +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10401 +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10402 +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10403 +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *_dwc_otg_hcd);
10404 +extern int32_t dwc_otg_hcd_handle_port_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10405 +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10406 +extern int32_t dwc_otg_hcd_handle_disconnect_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10407 +extern int32_t dwc_otg_hcd_handle_hc_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10408 +extern int32_t dwc_otg_hcd_handle_hc_n_intr (dwc_otg_hcd_t *_dwc_otg_hcd, uint32_t _num);
10409 +extern int32_t dwc_otg_hcd_handle_session_req_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10410 +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10414 +/** @name Schedule Queue Functions */
10417 +/* Implemented in dwc_otg_hcd_queue.c */
10418 +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *_hcd, struct urb *_urb);
10419 +extern void dwc_otg_hcd_qh_init (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, struct urb *_urb);
10420 +extern void dwc_otg_hcd_qh_free (dwc_otg_qh_t *_qh);
10421 +extern int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh);
10422 +extern void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh);
10423 +extern void dwc_otg_hcd_qh_deactivate (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int sched_csplit);
10424 +extern int dwc_otg_hcd_qh_deferr (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int delay);
10426 +/** Remove and free a QH */
10427 +static inline void dwc_otg_hcd_qh_remove_and_free (dwc_otg_hcd_t *_hcd,
10428 + dwc_otg_qh_t *_qh)
10430 + dwc_otg_hcd_qh_remove (_hcd, _qh);
10431 + dwc_otg_hcd_qh_free (_qh);
10434 +/** Allocates memory for a QH structure.
10435 + * @return Returns the memory allocate or NULL on error. */
10436 +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc (void)
10439 + return (dwc_otg_qh_t *) kmalloc (sizeof(dwc_otg_qh_t), GFP_ATOMIC);
10441 + return (dwc_otg_qh_t *) kmalloc (sizeof(dwc_otg_qh_t), GFP_KERNEL);
10445 +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *urb);
10446 +extern void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *qtd, struct urb *urb);
10447 +extern int dwc_otg_hcd_qtd_add (dwc_otg_qtd_t *qtd, dwc_otg_hcd_t *dwc_otg_hcd);
10449 +/** Allocates memory for a QTD structure.
10450 + * @return Returns the memory allocate or NULL on error. */
10451 +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc (void)
10454 + return (dwc_otg_qtd_t *) kmalloc (sizeof(dwc_otg_qtd_t), GFP_ATOMIC);
10456 + return (dwc_otg_qtd_t *) kmalloc (sizeof(dwc_otg_qtd_t), GFP_KERNEL);
10460 +/** Frees the memory for a QTD structure. QTD should already be removed from
10462 + * @param[in] _qtd QTD to free.*/
10463 +static inline void dwc_otg_hcd_qtd_free (dwc_otg_qtd_t *_qtd)
10468 +/** Removes a QTD from list.
10469 + * @param[in] _qtd QTD to remove from list. */
10470 +static inline void dwc_otg_hcd_qtd_remove (dwc_otg_qtd_t *_qtd)
10472 + unsigned long flags;
10473 + local_irq_save (flags);
10474 + list_del (&_qtd->qtd_list_entry);
10475 + local_irq_restore (flags);
10478 +/** Remove and free a QTD */
10479 +static inline void dwc_otg_hcd_qtd_remove_and_free (dwc_otg_qtd_t *_qtd)
10481 + dwc_otg_hcd_qtd_remove (_qtd);
10482 + dwc_otg_hcd_qtd_free (_qtd);
10488 +/** @name Internal Functions */
10490 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *_urb);
10491 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd);
10492 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd);
10496 +/** Gets the usb_host_endpoint associated with an URB. */
10497 +static inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *_urb)
10499 + struct usb_device *dev = _urb->dev;
10500 + int ep_num = usb_pipeendpoint(_urb->pipe);
10501 + if (usb_pipein(_urb->pipe))
10502 + return dev->ep_in[ep_num];
10504 + return dev->ep_out[ep_num];
10508 + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
10509 + * qualified with its direction (possible 32 endpoints per device).
10511 +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) \
10512 + ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
10513 + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
10515 +/** Gets the QH that contains the list_head */
10516 +#define dwc_list_to_qh(_list_head_ptr_) (container_of(_list_head_ptr_,dwc_otg_qh_t,qh_list_entry))
10518 +/** Gets the QTD that contains the list_head */
10519 +#define dwc_list_to_qtd(_list_head_ptr_) (container_of(_list_head_ptr_,dwc_otg_qtd_t,qtd_list_entry))
10521 +/** Check if QH is non-periodic */
10522 +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == USB_ENDPOINT_XFER_BULK) || \
10523 + (_qh_ptr_->ep_type == USB_ENDPOINT_XFER_CONTROL))
10525 +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
10526 +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
10528 +/** Packet size for any kind of endpoint descriptor */
10529 +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
10532 + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
10533 + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
10534 + * frame number when the max frame number is reached.
10536 +static inline int dwc_frame_num_le(uint16_t _frame1, uint16_t _frame2)
10538 + return ((_frame2 - _frame1) & DWC_HFNUM_MAX_FRNUM) <=
10539 + (DWC_HFNUM_MAX_FRNUM >> 1);
10543 + * Returns true if _frame1 is greater than _frame2. The comparison is done
10544 + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
10545 + * number when the max frame number is reached.
10547 +static inline int dwc_frame_num_gt(uint16_t _frame1, uint16_t _frame2)
10549 + return (_frame1 != _frame2) &&
10550 + (((_frame1 - _frame2) & DWC_HFNUM_MAX_FRNUM) <
10551 + (DWC_HFNUM_MAX_FRNUM >> 1));
10555 + * Increments _frame by the amount specified by _inc. The addition is done
10556 + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
10558 +static inline uint16_t dwc_frame_num_inc(uint16_t _frame, uint16_t _inc)
10560 + return (_frame + _inc) & DWC_HFNUM_MAX_FRNUM;
10563 +static inline uint16_t dwc_full_frame_num (uint16_t _frame)
10565 + return ((_frame) & DWC_HFNUM_MAX_FRNUM) >> 3;
10568 +static inline uint16_t dwc_micro_frame_num (uint16_t _frame)
10570 + return (_frame) & 0x7;
10575 + * Macro to sample the remaining PHY clocks left in the current frame. This
10576 + * may be used during debugging to determine the average time it takes to
10577 + * execute sections of code. There are two possible sample points, "a" and
10578 + * "b", so the _letter argument must be one of these values.
10580 + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
10581 + * example, "cat /sys/devices/lm0/hcd_frrem".
10583 +#define dwc_sample_frrem(_hcd, _qh, _letter) \
10585 + hfnum_data_t hfnum; \
10586 + dwc_otg_qtd_t *qtd; \
10587 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
10588 + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
10589 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
10590 + switch (hfnum.b.frnum & 0x7) { \
10592 + _hcd->hfnum_7_samples_##_letter++; \
10593 + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
10596 + _hcd->hfnum_0_samples_##_letter++; \
10597 + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
10600 + _hcd->hfnum_other_samples_##_letter++; \
10601 + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
10607 +#define dwc_sample_frrem(_hcd, _qh, _letter)
10609 +#endif // __DWC_HCD_H__
10610 +#endif /* DWC_DEVICE_ONLY */
10612 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
10614 +/* ==========================================================================
10615 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd_intr.c $
10616 + * $Revision: 1.1.1.1 $
10617 + * $Date: 2009-04-17 06:15:34 $
10618 + * $Change: 553126 $
10620 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
10621 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
10622 + * otherwise expressly agreed to in writing between Synopsys and you.
10624 + * The Software IS NOT an item of Licensed Software or Licensed Product under
10625 + * any End User Software License Agreement or Agreement for Licensed Product
10626 + * with Synopsys or any supplement thereto. You are permitted to use and
10627 + * redistribute this Software in source and binary forms, with or without
10628 + * modification, provided that redistributions of source code must retain this
10629 + * notice. You may not view, use, disclose, copy or distribute this file or
10630 + * any information contained herein except pursuant to this license grant from
10631 + * Synopsys. If you do not agree with this notice, including the disclaimer
10632 + * below, then you are not authorized to use the Software.
10634 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
10635 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10636 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10637 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
10638 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10639 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
10640 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
10641 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10642 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10643 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
10645 + * ========================================================================== */
10646 +#ifndef DWC_DEVICE_ONLY
10648 +#include "dwc_otg_driver.h"
10649 +#include "dwc_otg_hcd.h"
10650 +#include "dwc_otg_regs.h"
10652 +const int erratum_usb09_patched = 0;
10653 +const int deferral_on = 1;
10654 +const int nak_deferral_delay = 8;
10655 +const int nyet_deferral_delay = 1;
10657 + * This file contains the implementation of the HCD Interrupt handlers.
10660 +/** This function handles interrupts for the HCD. */
10661 +int32_t dwc_otg_hcd_handle_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10665 + dwc_otg_core_if_t *core_if = _dwc_otg_hcd->core_if;
10666 + gintsts_data_t gintsts;
10668 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
10671 + /* Check if HOST Mode */
10672 + if (dwc_otg_is_host_mode(core_if)) {
10673 + gintsts.d32 = dwc_otg_read_core_intr(core_if);
10674 + if (!gintsts.d32) {
10679 + /* Don't print debug message in the interrupt handler on SOF */
10680 +# ifndef DEBUG_SOF
10681 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10683 + DWC_DEBUGPL (DBG_HCD, "\n");
10687 +# ifndef DEBUG_SOF
10688 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10690 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n", gintsts.d32);
10693 + if (gintsts.b.sofintr) {
10694 + retval |= dwc_otg_hcd_handle_sof_intr (_dwc_otg_hcd);
10696 + if (gintsts.b.rxstsqlvl) {
10697 + retval |= dwc_otg_hcd_handle_rx_status_q_level_intr (_dwc_otg_hcd);
10699 + if (gintsts.b.nptxfempty) {
10700 + retval |= dwc_otg_hcd_handle_np_tx_fifo_empty_intr (_dwc_otg_hcd);
10702 + if (gintsts.b.i2cintr) {
10703 + /** @todo Implement i2cintr handler. */
10705 + if (gintsts.b.portintr) {
10706 + retval |= dwc_otg_hcd_handle_port_intr (_dwc_otg_hcd);
10708 + if (gintsts.b.hcintr) {
10709 + retval |= dwc_otg_hcd_handle_hc_intr (_dwc_otg_hcd);
10711 + if (gintsts.b.ptxfempty) {
10712 + retval |= dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (_dwc_otg_hcd);
10715 +# ifndef DEBUG_SOF
10716 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10719 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Finished Servicing Interrupts\n");
10720 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
10721 + dwc_read_reg32(&global_regs->gintsts));
10722 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
10723 + dwc_read_reg32(&global_regs->gintmsk));
10728 +# ifndef DEBUG_SOF
10729 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10731 + DWC_DEBUGPL (DBG_HCD, "\n");
10739 +#ifdef DWC_TRACK_MISSED_SOFS
10740 +#warning Compiling code to track missed SOFs
10741 +#define FRAME_NUM_ARRAY_SIZE 1000
10743 + * This function is for debug only.
10745 +static inline void track_missed_sofs(uint16_t _curr_frame_number) {
10746 + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
10747 + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
10748 + static int frame_num_idx = 0;
10749 + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
10750 + static int dumped_frame_num_array = 0;
10752 + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
10753 + if ((((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) != _curr_frame_number)) {
10754 + frame_num_array[frame_num_idx] = _curr_frame_number;
10755 + last_frame_num_array[frame_num_idx++] = last_frame_num;
10757 + } else if (!dumped_frame_num_array) {
10759 + printk(KERN_EMERG USB_DWC "Frame Last Frame\n");
10760 + printk(KERN_EMERG USB_DWC "----- ----------\n");
10761 + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
10762 + printk(KERN_EMERG USB_DWC "0x%04x 0x%04x\n",
10763 + frame_num_array[i], last_frame_num_array[i]);
10765 + dumped_frame_num_array = 1;
10767 + last_frame_num = _curr_frame_number;
10772 + * Handles the start-of-frame interrupt in host mode. Non-periodic
10773 + * transactions may be queued to the DWC_otg controller for the current
10774 + * (micro)frame. Periodic transactions may be queued to the controller for the
10775 + * next (micro)frame.
10777 +int32_t dwc_otg_hcd_handle_sof_intr (dwc_otg_hcd_t *_hcd)
10779 + hfnum_data_t hfnum;
10780 + struct list_head *qh_entry;
10781 + dwc_otg_qh_t *qh;
10782 + dwc_otg_transaction_type_e tr_type;
10783 + gintsts_data_t gintsts = {.d32 = 0};
10785 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
10788 + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
10791 + _hcd->frame_number = hfnum.b.frnum;
10794 + _hcd->frrem_accum += hfnum.b.frrem;
10795 + _hcd->frrem_samples++;
10798 +#ifdef DWC_TRACK_MISSED_SOFS
10799 + track_missed_sofs(_hcd->frame_number);
10802 + /* Determine whether any periodic QHs should be executed. */
10803 + qh_entry = _hcd->periodic_sched_inactive.next;
10804 + while (qh_entry != &_hcd->periodic_sched_inactive) {
10805 + qh = list_entry(qh_entry, dwc_otg_qh_t, qh_list_entry);
10806 + qh_entry = qh_entry->next;
10807 + if (dwc_frame_num_le(qh->sched_frame, _hcd->frame_number)) {
10809 + * Move QH to the ready list to be executed next
10812 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_ready);
10816 + tr_type = dwc_otg_hcd_select_transactions(_hcd);
10817 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
10818 + dwc_otg_hcd_queue_transactions(_hcd, tr_type);
10821 + /* Clear interrupt */
10822 + gintsts.b.sofintr = 1;
10823 + dwc_write_reg32(&_hcd->core_if->core_global_regs->gintsts, gintsts.d32);
10828 +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
10829 + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
10830 + * memory if the DWC_otg controller is operating in Slave mode. */
10831 +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10833 + host_grxsts_data_t grxsts;
10834 + dwc_hc_t *hc = NULL;
10836 + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
10838 + grxsts.d32 = dwc_read_reg32(&_dwc_otg_hcd->core_if->core_global_regs->grxstsp);
10840 + hc = _dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
10842 + /* Packet Status */
10843 + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
10844 + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
10845 + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid, hc->data_pid_start);
10846 + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
10848 + switch (grxsts.b.pktsts) {
10849 + case DWC_GRXSTS_PKTSTS_IN:
10850 + /* Read the data into the host buffer. */
10851 + if (grxsts.b.bcnt > 0) {
10852 + dwc_otg_read_packet(_dwc_otg_hcd->core_if,
10856 + /* Update the HC fields for the next packet received. */
10857 + hc->xfer_count += grxsts.b.bcnt;
10858 + hc->xfer_buff += grxsts.b.bcnt;
10861 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
10862 + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
10863 + case DWC_GRXSTS_PKTSTS_CH_HALTED:
10864 + /* Handled in interrupt, just ignore data */
10867 + DWC_ERROR ("RX_STS_Q Interrupt: Unknown status %d\n", grxsts.b.pktsts);
10874 +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
10875 + * data packets may be written to the FIFO for OUT transfers. More requests
10876 + * may be written to the non-periodic request queue for IN transfers. This
10877 + * interrupt is enabled only in Slave mode. */
10878 +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10880 + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
10881 + dwc_otg_hcd_queue_transactions(_dwc_otg_hcd,
10882 + DWC_OTG_TRANSACTION_NON_PERIODIC);
10886 +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
10887 + * packets may be written to the FIFO for OUT transfers. More requests may be
10888 + * written to the periodic request queue for IN transfers. This interrupt is
10889 + * enabled only in Slave mode. */
10890 +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10892 + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
10893 + dwc_otg_hcd_queue_transactions(_dwc_otg_hcd,
10894 + DWC_OTG_TRANSACTION_PERIODIC);
10898 +/** There are multiple conditions that can cause a port interrupt. This function
10899 + * determines which interrupt conditions have occurred and handles them
10900 + * appropriately. */
10901 +int32_t dwc_otg_hcd_handle_port_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10904 + hprt0_data_t hprt0;
10905 + hprt0_data_t hprt0_modify;
10907 + hprt0.d32 = dwc_read_reg32(_dwc_otg_hcd->core_if->host_if->hprt0);
10908 + hprt0_modify.d32 = dwc_read_reg32(_dwc_otg_hcd->core_if->host_if->hprt0);
10910 + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
10913 + hprt0_modify.b.prtena = 0;
10914 + hprt0_modify.b.prtconndet = 0;
10915 + hprt0_modify.b.prtenchng = 0;
10916 + hprt0_modify.b.prtovrcurrchng = 0;
10918 + /* Port Connect Detected
10919 + * Set flag and clear if detected */
10920 + if (hprt0.b.prtconndet) {
10921 + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
10922 + "Port Connect Detected--\n", hprt0.d32);
10923 + _dwc_otg_hcd->flags.b.port_connect_status_change = 1;
10924 + _dwc_otg_hcd->flags.b.port_connect_status = 1;
10925 + hprt0_modify.b.prtconndet = 1;
10927 + /* B-Device has connected, Delete the connection timer. */
10928 + del_timer( &_dwc_otg_hcd->conn_timer );
10930 + /* The Hub driver asserts a reset when it sees port connect
10931 + * status change flag */
10935 + /* Port Enable Changed
10936 + * Clear if detected - Set internal flag if disabled */
10937 + if (hprt0.b.prtenchng) {
10938 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
10939 + "Port Enable Changed--\n", hprt0.d32);
10940 + hprt0_modify.b.prtenchng = 1;
10941 + if (hprt0.b.prtena == 1) {
10942 + int do_reset = 0;
10943 + dwc_otg_core_params_t *params = _dwc_otg_hcd->core_if->core_params;
10944 + dwc_otg_core_global_regs_t *global_regs = _dwc_otg_hcd->core_if->core_global_regs;
10945 + dwc_otg_host_if_t *host_if = _dwc_otg_hcd->core_if->host_if;
10947 + /* Check if we need to adjust the PHY clock speed for
10948 + * low power and adjust it */
10949 + if (params->host_support_fs_ls_low_power)
10951 + gusbcfg_data_t usbcfg;
10953 + usbcfg.d32 = dwc_read_reg32 (&global_regs->gusbcfg);
10955 + if ((hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED) ||
10956 + (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED))
10961 + hcfg_data_t hcfg;
10962 + if (usbcfg.b.phylpwrclksel == 0) {
10963 + /* Set PHY low power clock select for FS/LS devices */
10964 + usbcfg.b.phylpwrclksel = 1;
10965 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
10969 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
10971 + if ((hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED) &&
10972 + (params->host_ls_low_power_phy_clk ==
10973 + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ))
10976 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
10977 + if (hcfg.b.fslspclksel != DWC_HCFG_6_MHZ) {
10978 + hcfg.b.fslspclksel = DWC_HCFG_6_MHZ;
10979 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
10986 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 48 MHz ()\n");
10987 + if (hcfg.b.fslspclksel != DWC_HCFG_48_MHZ) {
10988 + hcfg.b.fslspclksel = DWC_HCFG_48_MHZ;
10989 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
10999 + if (usbcfg.b.phylpwrclksel == 1) {
11000 + usbcfg.b.phylpwrclksel = 0;
11001 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
11007 + tasklet_schedule(_dwc_otg_hcd->reset_tasklet);
11012 + /* Port has been enabled set the reset change flag */
11013 + _dwc_otg_hcd->flags.b.port_reset_change = 1;
11017 + _dwc_otg_hcd->flags.b.port_enable_change = 1;
11022 + /** Overcurrent Change Interrupt */
11023 + if (hprt0.b.prtovrcurrchng) {
11024 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
11025 + "Port Overcurrent Changed--\n", hprt0.d32);
11026 + _dwc_otg_hcd->flags.b.port_over_current_change = 1;
11027 + hprt0_modify.b.prtovrcurrchng = 1;
11031 + /* Clear Port Interrupts */
11032 + dwc_write_reg32(_dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
11038 +/** This interrupt indicates that one or more host channels has a pending
11039 + * interrupt. There are multiple conditions that can cause each host channel
11040 + * interrupt. This function determines which conditions have occurred for each
11041 + * host channel interrupt and handles them appropriately. */
11042 +int32_t dwc_otg_hcd_handle_hc_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
11046 + haint_data_t haint;
11048 + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
11051 + haint.d32 = dwc_otg_read_host_all_channels_intr(_dwc_otg_hcd->core_if);
11053 + for (i=0; i<_dwc_otg_hcd->core_if->core_params->host_channels; i++) {
11054 + if (haint.b2.chint & (1 << i)) {
11055 + retval |= dwc_otg_hcd_handle_hc_n_intr (_dwc_otg_hcd, i);
11062 +/* Macro used to clear one channel interrupt */
11063 +#define clear_hc_int(_hc_regs_,_intr_) \
11065 + hcint_data_t hcint_clear = {.d32 = 0}; \
11066 + hcint_clear.b._intr_ = 1; \
11067 + dwc_write_reg32(&((_hc_regs_)->hcint), hcint_clear.d32); \
11071 + * Macro used to disable one channel interrupt. Channel interrupts are
11072 + * disabled when the channel is halted or released by the interrupt handler.
11073 + * There is no need to handle further interrupts of that type until the
11074 + * channel is re-assigned. In fact, subsequent handling may cause crashes
11075 + * because the channel structures are cleaned up when the channel is released.
11077 +#define disable_hc_int(_hc_regs_,_intr_) \
11079 + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
11080 + hcintmsk.b._intr_ = 1; \
11081 + dwc_modify_reg32(&((_hc_regs_)->hcintmsk), hcintmsk.d32, 0); \
11085 + * Gets the actual length of a transfer after the transfer halts. _halt_status
11086 + * holds the reason for the halt.
11088 + * For IN transfers where _halt_status is DWC_OTG_HC_XFER_COMPLETE,
11089 + * *_short_read is set to 1 upon return if less than the requested
11090 + * number of bytes were transferred. Otherwise, *_short_read is set to 0 upon
11091 + * return. _short_read may also be NULL on entry, in which case it remains
11094 +static uint32_t get_actual_xfer_length(dwc_hc_t *_hc,
11095 + dwc_otg_hc_regs_t *_hc_regs,
11096 + dwc_otg_qtd_t *_qtd,
11097 + dwc_otg_halt_status_e _halt_status,
11098 + int *_short_read)
11100 + hctsiz_data_t hctsiz;
11103 + if (_short_read != NULL) {
11104 + *_short_read = 0;
11106 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11108 + if (_halt_status == DWC_OTG_HC_XFER_COMPLETE) {
11109 + if (_hc->ep_is_in) {
11110 + length = _hc->xfer_len - hctsiz.b.xfersize;
11111 + if (_short_read != NULL) {
11112 + *_short_read = (hctsiz.b.xfersize != 0);
11114 + } else if (_hc->qh->do_split) {
11115 + length = _qtd->ssplit_out_xfer_count;
11117 + length = _hc->xfer_len;
11121 + * Must use the hctsiz.pktcnt field to determine how much data
11122 + * has been transferred. This field reflects the number of
11123 + * packets that have been transferred via the USB. This is
11124 + * always an integral number of packets if the transfer was
11125 + * halted before its normal completion. (Can't use the
11126 + * hctsiz.xfersize field because that reflects the number of
11127 + * bytes transferred via the AHB, not the USB).
11129 + length = (_hc->start_pkt_count - hctsiz.b.pktcnt) * _hc->max_packet;
11136 + * Updates the state of the URB after a Transfer Complete interrupt on the
11137 + * host channel. Updates the actual_length field of the URB based on the
11138 + * number of bytes transferred via the host channel. Sets the URB status
11139 + * if the data transfer is finished.
11141 + * @return 1 if the data transfer specified by the URB is completely finished,
11144 +static int update_urb_state_xfer_comp(dwc_hc_t *_hc,
11145 + dwc_otg_hc_regs_t * _hc_regs, struct urb *_urb,
11146 + dwc_otg_qtd_t * _qtd, int *status)
11148 + int xfer_done = 0;
11149 + int short_read = 0;
11151 + _urb->actual_length += get_actual_xfer_length(_hc, _hc_regs, _qtd,
11152 + DWC_OTG_HC_XFER_COMPLETE,
11155 + if (short_read || (_urb->actual_length == _urb->transfer_buffer_length)) {
11157 + if (short_read && (_urb->transfer_flags & URB_SHORT_NOT_OK)) {
11158 + *status = -EREMOTEIO;
11166 + hctsiz_data_t hctsiz;
11167 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11168 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
11169 + __func__, (_hc->ep_is_in ? "IN" : "OUT"), _hc->hc_num);
11170 + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", _hc->xfer_len);
11171 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n", hctsiz.b.xfersize);
11172 + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
11173 + _urb->transfer_buffer_length);
11174 + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n", _urb->actual_length);
11175 + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
11176 + short_read, xfer_done);
11180 + return xfer_done;
11184 + * Save the starting data toggle for the next transfer. The data toggle is
11185 + * saved in the QH for non-control transfers and it's saved in the QTD for
11186 + * control transfers.
11188 +static void save_data_toggle(dwc_hc_t *_hc,
11189 + dwc_otg_hc_regs_t *_hc_regs,
11190 + dwc_otg_qtd_t *_qtd)
11192 + hctsiz_data_t hctsiz;
11193 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11195 + if (_hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
11196 + dwc_otg_qh_t *qh = _hc->qh;
11197 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
11198 + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
11200 + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
11203 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
11204 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
11206 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
11212 + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
11213 + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
11214 + * still linked to the QH, the QH is added to the end of the inactive
11215 + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
11216 + * schedule if no more QTDs are linked to the QH.
11218 +static void deactivate_qh(dwc_otg_hcd_t *_hcd,
11219 + dwc_otg_qh_t *_qh,
11222 + int continue_split = 0;
11223 + dwc_otg_qtd_t *qtd;
11225 + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, _hcd, _qh, free_qtd);
11227 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
11229 + if (qtd->complete_split) {
11230 + continue_split = 1;
11232 + else if ((qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID) ||
11233 + (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))
11235 + continue_split = 1;
11240 + * Note that this was previously a call to
11241 + * dwc_otg_hcd_qtd_remove_and_free(qtd), which frees the qtd.
11242 + * However, that call frees the qtd memory, and we continue in the
11243 + * interrupt logic to access it many more times, including writing
11244 + * to it. With slub debugging on, it is clear that we were writing
11245 + * to memory we had freed.
11246 + * Call this instead, and now I have moved the freeing of the memory to
11247 + * the end of processing this interrupt.
11249 + //dwc_otg_hcd_qtd_remove_and_free(qtd);
11250 + dwc_otg_hcd_qtd_remove(qtd);
11252 + continue_split = 0;
11255 + _qh->channel = NULL;
11256 + _qh->qtd_in_process = NULL;
11257 + dwc_otg_hcd_qh_deactivate(_hcd, _qh, continue_split);
11261 + * Updates the state of an Isochronous URB when the transfer is stopped for
11262 + * any reason. The fields of the current entry in the frame descriptor array
11263 + * are set based on the transfer state and the input _halt_status. Completes
11264 + * the Isochronous URB if all the URB frames have been completed.
11266 + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
11267 + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
11269 +static dwc_otg_halt_status_e
11270 +update_isoc_urb_state(dwc_otg_hcd_t *_hcd,
11272 + dwc_otg_hc_regs_t *_hc_regs,
11273 + dwc_otg_qtd_t *_qtd,
11274 + dwc_otg_halt_status_e _halt_status)
11276 + struct urb *urb = _qtd->urb;
11277 + dwc_otg_halt_status_e ret_val = _halt_status;
11278 + struct usb_iso_packet_descriptor *frame_desc;
11280 + frame_desc = &urb->iso_frame_desc[_qtd->isoc_frame_index];
11281 + switch (_halt_status) {
11282 + case DWC_OTG_HC_XFER_COMPLETE:
11283 + frame_desc->status = 0;
11284 + frame_desc->actual_length =
11285 + get_actual_xfer_length(_hc, _hc_regs, _qtd,
11286 + _halt_status, NULL);
11288 + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
11289 + urb->error_count++;
11290 + if (_hc->ep_is_in) {
11291 + frame_desc->status = -ENOSR;
11293 + frame_desc->status = -ECOMM;
11295 + frame_desc->actual_length = 0;
11297 + case DWC_OTG_HC_XFER_BABBLE_ERR:
11298 + urb->error_count++;
11299 + frame_desc->status = -EOVERFLOW;
11300 + /* Don't need to update actual_length in this case. */
11302 + case DWC_OTG_HC_XFER_XACT_ERR:
11303 + urb->error_count++;
11304 + frame_desc->status = -EPROTO;
11305 + frame_desc->actual_length =
11306 + get_actual_xfer_length(_hc, _hc_regs, _qtd,
11307 + _halt_status, NULL);
11309 + DWC_ERROR("%s: Unhandled _halt_status (%d)\n", __func__,
11315 + if (++_qtd->isoc_frame_index == urb->number_of_packets) {
11317 + * urb->status is not used for isoc transfers.
11318 + * The individual frame_desc statuses are used instead.
11320 + dwc_otg_hcd_complete_urb(_hcd, urb, 0);
11321 + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
11323 + ret_val = DWC_OTG_HC_XFER_COMPLETE;
11330 + * Releases a host channel for use by other transfers. Attempts to select and
11331 + * queue more transactions since at least one host channel is available.
11333 + * @param _hcd The HCD state structure.
11334 + * @param _hc The host channel to release.
11335 + * @param _qtd The QTD associated with the host channel. This QTD may be freed
11336 + * if the transfer is complete or an error has occurred.
11337 + * @param _halt_status Reason the channel is being released. This status
11338 + * determines the actions taken by this function.
11340 +static void release_channel(dwc_otg_hcd_t *_hcd,
11342 + dwc_otg_qtd_t *_qtd,
11343 + dwc_otg_halt_status_e _halt_status,
11346 + dwc_otg_transaction_type_e tr_type;
11348 + dwc_otg_qh_t * _qh;
11350 + int retry_delay = 1;
11351 + unsigned long flags;
11353 + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d\n", __func__,
11354 + _hc->hc_num, _halt_status);
11356 + switch (_halt_status) {
11357 + case DWC_OTG_HC_XFER_NYET:
11358 + case DWC_OTG_HC_XFER_NAK:
11359 + if (_halt_status == DWC_OTG_HC_XFER_NYET) {
11360 + retry_delay = nyet_deferral_delay;
11362 + retry_delay = nak_deferral_delay;
11365 + if (deferral_on && _hc->do_split) {
11368 + deact = dwc_otg_hcd_qh_deferr(_hcd, _qh , retry_delay);
11372 + case DWC_OTG_HC_XFER_URB_COMPLETE:
11375 + case DWC_OTG_HC_XFER_AHB_ERR:
11376 + case DWC_OTG_HC_XFER_STALL:
11377 + case DWC_OTG_HC_XFER_BABBLE_ERR:
11380 + case DWC_OTG_HC_XFER_XACT_ERR:
11381 + if (_qtd->error_count >= 3) {
11382 + DWC_DEBUGPL(DBG_HCDV, " Complete URB with transaction error\n");
11384 + //_qtd->urb->status = -EPROTO;
11385 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPROTO);
11390 + case DWC_OTG_HC_XFER_URB_DEQUEUE:
11392 + * The QTD has already been removed and the QH has been
11393 + * deactivated. Don't want to do anything except release the
11394 + * host channel and try to queue more transfers.
11397 + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
11398 + DWC_ERROR("%s: No halt_status, channel %d\n", __func__, _hc->hc_num);
11406 + /* Only change must_free to true (do not set to zero here -- it is
11407 + * pre-initialized to zero).
11412 + deactivate_qh(_hcd, _hc->qh, free_qtd);
11416 + * Release the host channel for use by other transfers. The cleanup
11417 + * function clears the channel interrupt enables and conditions, so
11418 + * there's no need to clear the Channel Halted interrupt separately.
11420 + dwc_otg_hc_cleanup(_hcd->core_if, _hc);
11421 + list_add_tail(&_hc->hc_list_entry, &_hcd->free_hc_list);
11423 + local_irq_save(flags);
11424 + _hcd->available_host_channels++;
11425 + local_irq_restore(flags);
11426 + /* Try to queue more transfers now that there's a free channel, */
11427 + /* unless erratum_usb09_patched is set */
11428 + if (!erratum_usb09_patched) {
11429 + tr_type = dwc_otg_hcd_select_transactions(_hcd);
11430 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
11431 + dwc_otg_hcd_queue_transactions(_hcd, tr_type);
11437 + * Halts a host channel. If the channel cannot be halted immediately because
11438 + * the request queue is full, this function ensures that the FIFO empty
11439 + * interrupt for the appropriate queue is enabled so that the halt request can
11440 + * be queued when there is space in the request queue.
11442 + * This function may also be called in DMA mode. In that case, the channel is
11443 + * simply released since the core always halts the channel automatically in
11446 +static void halt_channel(dwc_otg_hcd_t *_hcd,
11448 + dwc_otg_qtd_t *_qtd,
11449 + dwc_otg_halt_status_e _halt_status, int *must_free)
11451 + if (_hcd->core_if->dma_enable) {
11452 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11456 + /* Slave mode processing... */
11457 + dwc_otg_hc_halt(_hcd->core_if, _hc, _halt_status);
11459 + if (_hc->halt_on_queue) {
11460 + gintmsk_data_t gintmsk = {.d32 = 0};
11461 + dwc_otg_core_global_regs_t *global_regs;
11462 + global_regs = _hcd->core_if->core_global_regs;
11464 + if (_hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
11465 + _hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
11467 + * Make sure the Non-periodic Tx FIFO empty interrupt
11468 + * is enabled so that the non-periodic schedule will
11471 + gintmsk.b.nptxfempty = 1;
11472 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
11475 + * Move the QH from the periodic queued schedule to
11476 + * the periodic assigned schedule. This allows the
11477 + * halt to be queued when the periodic schedule is
11480 + list_move(&_hc->qh->qh_list_entry,
11481 + &_hcd->periodic_sched_assigned);
11484 + * Make sure the Periodic Tx FIFO Empty interrupt is
11485 + * enabled so that the periodic schedule will be
11488 + gintmsk.b.ptxfempty = 1;
11489 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
11495 + * Performs common cleanup for non-periodic transfers after a Transfer
11496 + * Complete interrupt. This function should be called after any endpoint type
11497 + * specific handling is finished to release the host channel.
11499 +static void complete_non_periodic_xfer(dwc_otg_hcd_t *_hcd,
11501 + dwc_otg_hc_regs_t *_hc_regs,
11502 + dwc_otg_qtd_t *_qtd,
11503 + dwc_otg_halt_status_e _halt_status, int *must_free)
11505 + hcint_data_t hcint;
11507 + _qtd->error_count = 0;
11509 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
11510 + if (hcint.b.nyet) {
11512 + * Got a NYET on the last transaction of the transfer. This
11513 + * means that the endpoint should be in the PING state at the
11514 + * beginning of the next transfer.
11516 + _hc->qh->ping_state = 1;
11517 + clear_hc_int(_hc_regs,nyet);
11521 + * Always halt and release the host channel to make it available for
11522 + * more transfers. There may still be more phases for a control
11523 + * transfer or more data packets for a bulk transfer at this point,
11524 + * but the host channel is still halted. A channel will be reassigned
11525 + * to the transfer when the non-periodic schedule is processed after
11526 + * the channel is released. This allows transactions to be queued
11527 + * properly via dwc_otg_hcd_queue_transactions, which also enables the
11528 + * Tx FIFO Empty interrupt if necessary.
11530 + if (_hc->ep_is_in) {
11532 + * IN transfers in Slave mode require an explicit disable to
11533 + * halt the channel. (In DMA mode, this call simply releases
11536 + halt_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11539 + * The channel is automatically disabled by the core for OUT
11540 + * transfers in Slave mode.
11542 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11547 + * Performs common cleanup for periodic transfers after a Transfer Complete
11548 + * interrupt. This function should be called after any endpoint type specific
11549 + * handling is finished to release the host channel.
11551 +static void complete_periodic_xfer(dwc_otg_hcd_t *_hcd,
11553 + dwc_otg_hc_regs_t *_hc_regs,
11554 + dwc_otg_qtd_t *_qtd,
11555 + dwc_otg_halt_status_e _halt_status, int *must_free)
11557 + hctsiz_data_t hctsiz;
11558 + _qtd->error_count = 0;
11560 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11561 + if (!_hc->ep_is_in || hctsiz.b.pktcnt == 0) {
11562 + /* Core halts channel in these cases. */
11563 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11565 + /* Flush any outstanding requests from the Tx queue. */
11566 + halt_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11571 + * Handles a host channel Transfer Complete interrupt. This handler may be
11572 + * called in either DMA mode or Slave mode.
11574 +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t *_hcd,
11576 + dwc_otg_hc_regs_t *_hc_regs,
11577 + dwc_otg_qtd_t *_qtd, int *must_free)
11579 + int urb_xfer_done;
11580 + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
11581 + struct urb *urb = _qtd->urb;
11582 + int pipe_type = usb_pipetype(urb->pipe);
11583 + int status = -EINPROGRESS;
11585 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11586 + "Transfer Complete--\n", _hc->hc_num);
11589 + * Handle xfer complete on CSPLIT.
11591 + if (_hc->qh->do_split) {
11592 + _qtd->complete_split = 0;
11595 + /* Update the QTD and URB states. */
11596 + switch (pipe_type) {
11597 + case PIPE_CONTROL:
11598 + switch (_qtd->control_phase) {
11599 + case DWC_OTG_CONTROL_SETUP:
11600 + if (urb->transfer_buffer_length > 0) {
11601 + _qtd->control_phase = DWC_OTG_CONTROL_DATA;
11603 + _qtd->control_phase = DWC_OTG_CONTROL_STATUS;
11605 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
11606 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11608 + case DWC_OTG_CONTROL_DATA: {
11609 + urb_xfer_done = update_urb_state_xfer_comp(_hc, _hc_regs,urb, _qtd, &status);
11610 + if (urb_xfer_done) {
11611 + _qtd->control_phase = DWC_OTG_CONTROL_STATUS;
11612 + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
11614 + save_data_toggle(_hc, _hc_regs, _qtd);
11616 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11619 + case DWC_OTG_CONTROL_STATUS:
11620 + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
11621 + if (status == -EINPROGRESS) {
11624 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11625 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
11629 + complete_non_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,
11630 + halt_status, must_free);
11633 + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
11634 + urb_xfer_done = update_urb_state_xfer_comp(_hc, _hc_regs, urb, _qtd, &status);
11635 + if (urb_xfer_done) {
11636 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11637 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
11639 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11642 + save_data_toggle(_hc, _hc_regs, _qtd);
11643 + complete_non_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,halt_status, must_free);
11645 + case PIPE_INTERRUPT:
11646 + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
11647 + update_urb_state_xfer_comp(_hc, _hc_regs, urb, _qtd, &status);
11650 + * Interrupt URB is done on the first transfer complete
11653 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11654 + save_data_toggle(_hc, _hc_regs, _qtd);
11655 + complete_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,
11656 + DWC_OTG_HC_XFER_URB_COMPLETE, must_free);
11658 + case PIPE_ISOCHRONOUS:
11659 + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
11660 + if (_qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL)
11662 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
11663 + DWC_OTG_HC_XFER_COMPLETE);
11665 + complete_periodic_xfer(_hcd, _hc, _hc_regs, _qtd, halt_status, must_free);
11669 + disable_hc_int(_hc_regs,xfercompl);
11675 + * Handles a host channel STALL interrupt. This handler may be called in
11676 + * either DMA mode or Slave mode.
11678 +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t *_hcd,
11680 + dwc_otg_hc_regs_t *_hc_regs,
11681 + dwc_otg_qtd_t *_qtd, int *must_free)
11683 + struct urb *urb = _qtd->urb;
11684 + int pipe_type = usb_pipetype(urb->pipe);
11686 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11687 + "STALL Received--\n", _hc->hc_num);
11689 + if (pipe_type == PIPE_CONTROL) {
11690 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPIPE);
11693 + if (pipe_type == PIPE_BULK || pipe_type == PIPE_INTERRUPT) {
11694 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPIPE);
11696 + * USB protocol requires resetting the data toggle for bulk
11697 + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
11698 + * setup command is issued to the endpoint. Anticipate the
11699 + * CLEAR_FEATURE command since a STALL has occurred and reset
11700 + * the data toggle now.
11702 + _hc->qh->data_toggle = 0;
11705 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_STALL, must_free);
11706 + disable_hc_int(_hc_regs,stall);
11712 + * Updates the state of the URB when a transfer has been stopped due to an
11713 + * abnormal condition before the transfer completes. Modifies the
11714 + * actual_length field of the URB to reflect the number of bytes that have
11715 + * actually been transferred via the host channel.
11717 +static void update_urb_state_xfer_intr(dwc_hc_t *_hc,
11718 + dwc_otg_hc_regs_t *_hc_regs,
11719 + struct urb *_urb,
11720 + dwc_otg_qtd_t *_qtd,
11721 + dwc_otg_halt_status_e _halt_status)
11723 + uint32_t bytes_transferred = get_actual_xfer_length(_hc, _hc_regs, _qtd,
11724 + _halt_status, NULL);
11725 + _urb->actual_length += bytes_transferred;
11729 + hctsiz_data_t hctsiz;
11730 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11731 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
11732 + __func__, (_hc->ep_is_in ? "IN" : "OUT"), _hc->hc_num);
11733 + DWC_DEBUGPL(DBG_HCDV, " _hc->start_pkt_count %d\n", _hc->start_pkt_count);
11734 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
11735 + DWC_DEBUGPL(DBG_HCDV, " _hc->max_packet %d\n", _hc->max_packet);
11736 + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n", bytes_transferred);
11737 + DWC_DEBUGPL(DBG_HCDV, " _urb->actual_length %d\n", _urb->actual_length);
11738 + DWC_DEBUGPL(DBG_HCDV, " _urb->transfer_buffer_length %d\n",
11739 + _urb->transfer_buffer_length);
11745 + * Handles a host channel NAK interrupt. This handler may be called in either
11746 + * DMA mode or Slave mode.
11748 +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t *_hcd,
11750 + dwc_otg_hc_regs_t *_hc_regs,
11751 + dwc_otg_qtd_t *_qtd, int *must_free)
11753 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11754 + "NAK Received--\n", _hc->hc_num);
11757 + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
11758 + * interrupt. Re-start the SSPLIT transfer.
11760 + if (_hc->do_split) {
11761 + if (_hc->complete_split) {
11762 + _qtd->error_count = 0;
11764 + _qtd->complete_split = 0;
11765 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11766 + goto handle_nak_done;
11769 + switch (usb_pipetype(_qtd->urb->pipe)) {
11770 + case PIPE_CONTROL:
11772 + if (_hcd->core_if->dma_enable && _hc->ep_is_in) {
11774 + * NAK interrupts are enabled on bulk/control IN
11775 + * transfers in DMA mode for the sole purpose of
11776 + * resetting the error count after a transaction error
11777 + * occurs. The core will continue transferring data.
11779 + _qtd->error_count = 0;
11780 + goto handle_nak_done;
11784 + * NAK interrupts normally occur during OUT transfers in DMA
11785 + * or Slave mode. For IN transfers, more requests will be
11786 + * queued as request queue space is available.
11788 + _qtd->error_count = 0;
11790 + if (!_hc->qh->ping_state) {
11791 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb,
11792 + _qtd, DWC_OTG_HC_XFER_NAK);
11793 + save_data_toggle(_hc, _hc_regs, _qtd);
11794 + if (_qtd->urb->dev->speed == USB_SPEED_HIGH) {
11795 + _hc->qh->ping_state = 1;
11800 + * Halt the channel so the transfer can be re-started from
11801 + * the appropriate point or the PING protocol will
11802 + * start/continue.
11804 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11806 + case PIPE_INTERRUPT:
11807 + _qtd->error_count = 0;
11808 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11810 + case PIPE_ISOCHRONOUS:
11811 + /* Should never get called for isochronous transfers. */
11817 + disable_hc_int(_hc_regs,nak);
11823 + * Handles a host channel ACK interrupt. This interrupt is enabled when
11824 + * performing the PING protocol in Slave mode, when errors occur during
11825 + * either Slave mode or DMA mode, and during Start Split transactions.
11827 +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t *_hcd,
11828 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
11830 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11831 + "ACK Received--\n", _hc->hc_num);
11833 + if (_hc->do_split) {
11835 + * Handle ACK on SSPLIT.
11836 + * ACK should not occur in CSPLIT.
11838 + if ((!_hc->ep_is_in) && (_hc->data_pid_start != DWC_OTG_HC_PID_SETUP)) {
11839 + _qtd->ssplit_out_xfer_count = _hc->xfer_len;
11841 + if (!(_hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !_hc->ep_is_in)) {
11842 + /* Don't need complete for isochronous out transfers. */
11843 + _qtd->complete_split = 1;
11847 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && !_hc->ep_is_in) {
11848 + switch (_hc->xact_pos) {
11849 + case DWC_HCSPLIT_XACTPOS_ALL:
11851 + case DWC_HCSPLIT_XACTPOS_END:
11852 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
11853 + _qtd->isoc_split_offset = 0;
11855 + case DWC_HCSPLIT_XACTPOS_BEGIN:
11856 + case DWC_HCSPLIT_XACTPOS_MID:
11858 + * For BEGIN or MID, calculate the length for
11859 + * the next microframe to determine the correct
11860 + * SSPLIT token, either MID or END.
11863 + struct usb_iso_packet_descriptor *frame_desc;
11865 + frame_desc = &_qtd->urb->iso_frame_desc[_qtd->isoc_frame_index];
11866 + _qtd->isoc_split_offset += 188;
11868 + if ((frame_desc->length - _qtd->isoc_split_offset) <= 188) {
11869 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_END;
11872 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_MID;
11879 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_ACK, must_free);
11882 + _qtd->error_count = 0;
11884 + if (_hc->qh->ping_state) {
11885 + _hc->qh->ping_state = 0;
11887 + * Halt the channel so the transfer can be re-started
11888 + * from the appropriate point. This only happens in
11889 + * Slave mode. In DMA mode, the ping_state is cleared
11890 + * when the transfer is started because the core
11891 + * automatically executes the PING, then the transfer.
11893 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_ACK, must_free);
11895 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
11900 + * If the ACK occurred when _not_ in the PING state, let the channel
11901 + * continue transferring data after clearing the error count.
11904 + disable_hc_int(_hc_regs,ack);
11910 + * Handles a host channel NYET interrupt. This interrupt should only occur on
11911 + * Bulk and Control OUT endpoints and for complete split transactions. If a
11912 + * NYET occurs at the same time as a Transfer Complete interrupt, it is
11913 + * handled in the xfercomp interrupt handler, not here. This handler may be
11914 + * called in either DMA mode or Slave mode.
11916 +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t *_hcd,
11918 + dwc_otg_hc_regs_t *_hc_regs,
11919 + dwc_otg_qtd_t *_qtd, int *must_free)
11921 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11922 + "NYET Received--\n", _hc->hc_num);
11926 + * re-do the CSPLIT immediately on non-periodic
11928 + if ((_hc->do_split) && (_hc->complete_split)) {
11929 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_INTR) ||
11930 + (_hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
11931 + int frnum = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
11933 + if (dwc_full_frame_num(frnum) !=
11934 + dwc_full_frame_num(_hc->qh->sched_frame)) {
11936 + * No longer in the same full speed frame.
11937 + * Treat this as a transaction error.
11940 + /** @todo Fix system performance so this can
11941 + * be treated as an error. Right now complete
11942 + * splits cannot be scheduled precisely enough
11943 + * due to other system activity, so this error
11944 + * occurs regularly in Slave mode.
11946 + _qtd->error_count++;
11948 + _qtd->complete_split = 0;
11949 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
11950 + /** @todo add support for isoc release */
11951 + goto handle_nyet_done;
11955 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NYET, must_free);
11956 + goto handle_nyet_done;
11959 + _hc->qh->ping_state = 1;
11960 + _qtd->error_count = 0;
11962 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb, _qtd,
11963 + DWC_OTG_HC_XFER_NYET);
11964 + save_data_toggle(_hc, _hc_regs, _qtd);
11967 + * Halt the channel and re-start the transfer so the PING
11968 + * protocol will start.
11970 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NYET, must_free);
11973 + disable_hc_int(_hc_regs,nyet);
11974 + clear_hc_int(_hc_regs, nyet);
11979 + * Handles a host channel babble interrupt. This handler may be called in
11980 + * either DMA mode or Slave mode.
11982 +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t *_hcd,
11983 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
11985 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11986 + "Babble Error--\n", _hc->hc_num);
11987 + if (_hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
11988 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EOVERFLOW);
11989 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_BABBLE_ERR, must_free);
11991 + dwc_otg_halt_status_e halt_status;
11992 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
11993 + DWC_OTG_HC_XFER_BABBLE_ERR);
11994 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
11996 + disable_hc_int(_hc_regs,bblerr);
12001 + * Handles a host channel AHB error interrupt. This handler is only called in
12004 +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t *_hcd,
12006 + dwc_otg_hc_regs_t *_hc_regs,
12007 + dwc_otg_qtd_t *_qtd)
12009 + hcchar_data_t hcchar;
12010 + hcsplt_data_t hcsplt;
12011 + hctsiz_data_t hctsiz;
12013 + struct urb *urb = _qtd->urb;
12015 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12016 + "AHB Error--\n", _hc->hc_num);
12018 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12019 + hcsplt.d32 = dwc_read_reg32(&_hc_regs->hcsplt);
12020 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
12021 + hcdma = dwc_read_reg32(&_hc_regs->hcdma);
12023 + DWC_ERROR("AHB ERROR, Channel %d\n", _hc->hc_num);
12024 + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
12025 + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
12026 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
12027 + DWC_ERROR(" Device address: %d\n", usb_pipedevice(urb->pipe));
12028 + DWC_ERROR(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
12029 + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
12030 + DWC_ERROR(" Endpoint type: %s\n",
12031 + ({char *pipetype;
12032 + switch (usb_pipetype(urb->pipe)) {
12033 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
12034 + case PIPE_BULK: pipetype = "BULK"; break;
12035 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
12036 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
12037 + default: pipetype = "UNKNOWN"; break;
12039 + DWC_ERROR(" Speed: %s\n",
12041 + switch (urb->dev->speed) {
12042 + case USB_SPEED_HIGH: speed = "HIGH"; break;
12043 + case USB_SPEED_FULL: speed = "FULL"; break;
12044 + case USB_SPEED_LOW: speed = "LOW"; break;
12045 + default: speed = "UNKNOWN"; break;
12047 + DWC_ERROR(" Max packet size: %d\n",
12048 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
12049 + DWC_ERROR(" Data buffer length: %d\n", urb->transfer_buffer_length);
12050 + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
12051 + urb->transfer_buffer, (void *)(u32)urb->transfer_dma);
12052 + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
12053 + urb->setup_packet, (void *)(u32)urb->setup_dma);
12054 + DWC_ERROR(" Interval: %d\n", urb->interval);
12056 + dwc_otg_hcd_complete_urb(_hcd, urb, -EIO);
12059 + * Force a channel halt. Don't call halt_channel because that won't
12060 + * write to the HCCHARn register in DMA mode to force the halt.
12062 + dwc_otg_hc_halt(_hcd->core_if, _hc, DWC_OTG_HC_XFER_AHB_ERR);
12064 + disable_hc_int(_hc_regs,ahberr);
12069 + * Handles a host channel transaction error interrupt. This handler may be
12070 + * called in either DMA mode or Slave mode.
12072 +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t *_hcd,
12073 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12075 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12076 + "Transaction Error--\n", _hc->hc_num);
12078 + switch (usb_pipetype(_qtd->urb->pipe)) {
12079 + case PIPE_CONTROL:
12081 + _qtd->error_count++;
12082 + if (!_hc->qh->ping_state) {
12083 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb,
12084 + _qtd, DWC_OTG_HC_XFER_XACT_ERR);
12085 + save_data_toggle(_hc, _hc_regs, _qtd);
12086 + if (!_hc->ep_is_in && _qtd->urb->dev->speed == USB_SPEED_HIGH) {
12087 + _hc->qh->ping_state = 1;
12092 + * Halt the channel so the transfer can be re-started from
12093 + * the appropriate point or the PING protocol will start.
12095 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
12097 + case PIPE_INTERRUPT:
12098 + _qtd->error_count++;
12099 + if ((_hc->do_split) && (_hc->complete_split)) {
12100 + _qtd->complete_split = 0;
12102 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
12104 + case PIPE_ISOCHRONOUS:
12106 + dwc_otg_halt_status_e halt_status;
12107 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
12108 + DWC_OTG_HC_XFER_XACT_ERR);
12110 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
12116 + disable_hc_int(_hc_regs,xacterr);
12122 + * Handles a host channel frame overrun interrupt. This handler may be called
12123 + * in either DMA mode or Slave mode.
12125 +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t *_hcd,
12126 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12128 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12129 + "Frame Overrun--\n", _hc->hc_num);
12131 + switch (usb_pipetype(_qtd->urb->pipe)) {
12132 + case PIPE_CONTROL:
12135 + case PIPE_INTERRUPT:
12136 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN, must_free);
12138 + case PIPE_ISOCHRONOUS:
12140 + dwc_otg_halt_status_e halt_status;
12141 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
12142 + DWC_OTG_HC_XFER_FRAME_OVERRUN);
12144 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
12149 + disable_hc_int(_hc_regs,frmovrun);
12155 + * Handles a host channel data toggle error interrupt. This handler may be
12156 + * called in either DMA mode or Slave mode.
12158 +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t *_hcd,
12159 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12161 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12162 + "Data Toggle Error--\n", _hc->hc_num);
12164 + if (_hc->ep_is_in) {
12165 + _qtd->error_count = 0;
12167 + DWC_ERROR("Data Toggle Error on OUT transfer,"
12168 + "channel %d\n", _hc->hc_num);
12171 + disable_hc_int(_hc_regs,datatglerr);
12178 + * This function is for debug only. It checks that a valid halt status is set
12179 + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
12180 + * taken and a warning is issued.
12181 + * @return 1 if halt status is ok, 0 otherwise.
12183 +static inline int halt_status_ok(dwc_otg_hcd_t *_hcd,
12184 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12186 + hcchar_data_t hcchar;
12187 + hctsiz_data_t hctsiz;
12188 + hcint_data_t hcint;
12189 + hcintmsk_data_t hcintmsk;
12190 + hcsplt_data_t hcsplt;
12192 + if (_hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
12194 + * This code is here only as a check. This condition should
12195 + * never happen. Ignore the halt if it does occur.
12197 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12198 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
12199 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
12200 + hcintmsk.d32 = dwc_read_reg32(&_hc_regs->hcintmsk);
12201 + hcsplt.d32 = dwc_read_reg32(&_hc_regs->hcsplt);
12202 + DWC_WARN("%s: _hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
12203 + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
12204 + "hcint 0x%08x, hcintmsk 0x%08x, "
12205 + "hcsplt 0x%08x, qtd->complete_split %d\n",
12206 + __func__, _hc->hc_num, hcchar.d32, hctsiz.d32,
12207 + hcint.d32, hcintmsk.d32,
12208 + hcsplt.d32, _qtd->complete_split);
12210 + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
12211 + __func__, _hc->hc_num);
12213 + clear_hc_int(_hc_regs,chhltd);
12218 + * This code is here only as a check. hcchar.chdis should
12219 + * never be set when the halt interrupt occurs. Halt the
12220 + * channel again if it does occur.
12222 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12223 + if (hcchar.b.chdis) {
12224 + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
12225 + "hcchar 0x%08x, trying to halt again\n",
12226 + __func__, hcchar.d32);
12227 + clear_hc_int(_hc_regs,chhltd);
12228 + _hc->halt_pending = 0;
12229 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12238 + * Handles a host Channel Halted interrupt in DMA mode. This handler
12239 + * determines the reason the channel halted and proceeds accordingly.
12241 +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t *_hcd,
12242 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12244 + hcint_data_t hcint;
12245 + hcintmsk_data_t hcintmsk;
12247 + if (_hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
12248 + _hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
12250 + * Just release the channel. A dequeue can happen on a
12251 + * transfer timeout. In the case of an AHB Error, the channel
12252 + * was forced to halt because there's no way to gracefully
12255 + release_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12259 + /* Read the HCINTn register to determine the cause for the halt. */
12260 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
12261 + hcintmsk.d32 = dwc_read_reg32(&_hc_regs->hcintmsk);
12263 + if (hcint.b.xfercomp) {
12264 + /** @todo This is here because of a possible hardware bug. Spec
12265 + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
12266 + * interrupt w/ACK bit set should occur, but I only see the
12267 + * XFERCOMP bit, even with it masked out. This is a workaround
12268 + * for that behavior. Should fix this when hardware is fixed.
12270 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!_hc->ep_is_in)) {
12271 + handle_hc_ack_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12273 + handle_hc_xfercomp_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12274 + } else if (hcint.b.stall) {
12275 + handle_hc_stall_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12276 + } else if (hcint.b.xacterr) {
12278 + * Must handle xacterr before nak or ack. Could get a xacterr
12279 + * at the same time as either of these on a BULK/CONTROL OUT
12280 + * that started with a PING. The xacterr takes precedence.
12282 + handle_hc_xacterr_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12283 + } else if (hcint.b.nyet) {
12285 + * Must handle nyet before nak or ack. Could get a nyet at the
12286 + * same time as either of those on a BULK/CONTROL OUT that
12287 + * started with a PING. The nyet takes precedence.
12289 + handle_hc_nyet_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12290 + } else if (hcint.b.bblerr) {
12291 + handle_hc_babble_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12292 + } else if (hcint.b.frmovrun) {
12293 + handle_hc_frmovrun_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12294 + } else if (hcint.b.datatglerr) {
12295 + handle_hc_datatglerr_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12296 + _hc->qh->data_toggle = 0;
12297 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12298 + } else if (hcint.b.nak && !hcintmsk.b.nak) {
12300 + * If nak is not masked, it's because a non-split IN transfer
12301 + * is in an error state. In that case, the nak is handled by
12302 + * the nak interrupt handler, not here. Handle nak here for
12303 + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
12304 + * rewinding the buffer pointer.
12306 + handle_hc_nak_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12307 + } else if (hcint.b.ack && !hcintmsk.b.ack) {
12309 + * If ack is not masked, it's because a non-split IN transfer
12310 + * is in an error state. In that case, the ack is handled by
12311 + * the ack interrupt handler, not here. Handle ack here for
12312 + * split transfers. Start splits halt on ACK.
12314 + handle_hc_ack_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12316 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
12317 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
12319 + * A periodic transfer halted with no other channel
12320 + * interrupts set. Assume it was halted by the core
12321 + * because it could not be completed in its scheduled
12325 + DWC_PRINT("%s: Halt channel %d (assume incomplete periodic transfer)\n",
12326 + __func__, _hc->hc_num);
12328 + halt_channel(_hcd, _hc, _qtd,
12329 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE, must_free);
12332 + DWC_ERROR("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
12333 + "for halting is unknown, nyet %d, hcint 0x%08x, intsts 0x%08x\n",
12334 + __func__, _hc->hc_num, hcint.b.nyet, hcint.d32,
12335 + dwc_read_reg32(&_hcd->core_if->core_global_regs->gintsts));
12337 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12343 + * Handles a host channel Channel Halted interrupt.
12345 + * In slave mode, this handler is called only when the driver specifically
12346 + * requests a halt. This occurs during handling other host channel interrupts
12347 + * (e.g. nak, xacterr, stall, nyet, etc.).
12349 + * In DMA mode, this is the interrupt that occurs when the core has finished
12350 + * processing a transfer on a channel. Other host channel interrupts (except
12351 + * ahberr) are disabled in DMA mode.
12353 +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t *_hcd,
12354 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12356 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12357 + "Channel Halted--\n", _hc->hc_num);
12359 + if (_hcd->core_if->dma_enable) {
12360 + handle_hc_chhltd_intr_dma(_hcd, _hc, _hc_regs, _qtd, must_free);
12363 + if (!halt_status_ok(_hcd, _hc, _hc_regs, _qtd, must_free)) {
12367 + release_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12373 +/** Handles interrupt for a specific Host Channel */
12374 +int32_t dwc_otg_hcd_handle_hc_n_intr (dwc_otg_hcd_t *_dwc_otg_hcd, uint32_t _num)
12376 + int must_free = 0;
12378 + hcint_data_t hcint;
12379 + hcintmsk_data_t hcintmsk;
12381 + dwc_otg_hc_regs_t *hc_regs;
12382 + dwc_otg_qtd_t *qtd;
12384 + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", _num);
12386 + hc = _dwc_otg_hcd->hc_ptr_array[_num];
12387 + hc_regs = _dwc_otg_hcd->core_if->host_if->hc_regs[_num];
12388 + qtd = list_entry(hc->qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
12390 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
12391 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
12392 + DWC_DEBUGPL(DBG_HCDV, " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
12393 + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
12394 + hcint.d32 = hcint.d32 & hcintmsk.d32;
12396 + if (!_dwc_otg_hcd->core_if->dma_enable) {
12397 + if ((hcint.b.chhltd) && (hcint.d32 != 0x2)) {
12398 + hcint.b.chhltd = 0;
12402 + if (hcint.b.xfercomp) {
12403 + retval |= handle_hc_xfercomp_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12405 + * If NYET occurred at same time as Xfer Complete, the NYET is
12406 + * handled by the Xfer Complete interrupt handler. Don't want
12407 + * to call the NYET interrupt handler in this case.
12409 + hcint.b.nyet = 0;
12411 + if (hcint.b.chhltd) {
12412 + retval |= handle_hc_chhltd_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12414 + if (hcint.b.ahberr) {
12415 + retval |= handle_hc_ahberr_intr(_dwc_otg_hcd, hc, hc_regs, qtd);
12417 + if (hcint.b.stall) {
12418 + retval |= handle_hc_stall_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12420 + if (hcint.b.nak) {
12421 + retval |= handle_hc_nak_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12423 + if (hcint.b.ack) {
12424 + retval |= handle_hc_ack_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12426 + if (hcint.b.nyet) {
12427 + retval |= handle_hc_nyet_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12429 + if (hcint.b.xacterr) {
12430 + retval |= handle_hc_xacterr_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12432 + if (hcint.b.bblerr) {
12433 + retval |= handle_hc_babble_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12435 + if (hcint.b.frmovrun) {
12436 + retval |= handle_hc_frmovrun_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12438 + if (hcint.b.datatglerr) {
12439 + retval |= handle_hc_datatglerr_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12443 + * Logic to free the qtd here, at the end of the hc intr
12444 + * processing, if the handling of this interrupt determined
12445 + * that it needs to be freed.
12448 + /* Free the qtd here now that we are done using it. */
12449 + dwc_otg_hcd_qtd_free(qtd);
12454 +#endif /* DWC_DEVICE_ONLY */
12456 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
12458 +/* ==========================================================================
12459 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd_queue.c $
12460 + * $Revision: 1.1.1.1 $
12461 + * $Date: 2009-04-17 06:15:34 $
12462 + * $Change: 537387 $
12464 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
12465 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
12466 + * otherwise expressly agreed to in writing between Synopsys and you.
12468 + * The Software IS NOT an item of Licensed Software or Licensed Product under
12469 + * any End User Software License Agreement or Agreement for Licensed Product
12470 + * with Synopsys or any supplement thereto. You are permitted to use and
12471 + * redistribute this Software in source and binary forms, with or without
12472 + * modification, provided that redistributions of source code must retain this
12473 + * notice. You may not view, use, disclose, copy or distribute this file or
12474 + * any information contained herein except pursuant to this license grant from
12475 + * Synopsys. If you do not agree with this notice, including the disclaimer
12476 + * below, then you are not authorized to use the Software.
12478 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
12479 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12480 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
12481 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
12482 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
12483 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12484 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
12485 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
12486 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
12487 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
12489 + * ========================================================================== */
12490 +#ifndef DWC_DEVICE_ONLY
12495 + * This file contains the functions to manage Queue Heads and Queue
12496 + * Transfer Descriptors.
12498 +#include <linux/kernel.h>
12499 +#include <linux/module.h>
12500 +#include <linux/moduleparam.h>
12501 +#include <linux/init.h>
12502 +#include <linux/device.h>
12503 +#include <linux/errno.h>
12504 +#include <linux/list.h>
12505 +#include <linux/interrupt.h>
12506 +#include <linux/string.h>
12508 +#include "dwc_otg_driver.h"
12509 +#include "dwc_otg_hcd.h"
12510 +#include "dwc_otg_regs.h"
12513 + * This function allocates and initializes a QH.
12515 + * @param _hcd The HCD state structure for the DWC OTG controller.
12516 + * @param[in] _urb Holds the information about the device/endpoint that we need
12517 + * to initialize the QH.
12519 + * @return Returns pointer to the newly allocated QH, or NULL on error. */
12520 +dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *_hcd, struct urb *_urb)
12522 + dwc_otg_qh_t *qh;
12524 + /* Allocate memory */
12525 + /** @todo add memflags argument */
12526 + qh = dwc_otg_hcd_qh_alloc ();
12527 + if (qh == NULL) {
12531 + dwc_otg_hcd_qh_init (_hcd, qh, _urb);
12535 +/** Free each QTD in the QH's QTD-list then free the QH. QH should already be
12536 + * removed from a list. QTD list should already be empty if called from URB
12539 + * @param[in] _qh The QH to free.
12541 +void dwc_otg_hcd_qh_free (dwc_otg_qh_t *_qh)
12543 + dwc_otg_qtd_t *qtd;
12544 + struct list_head *pos;
12545 + unsigned long flags;
12547 + /* Free each QTD in the QTD list */
12548 + local_irq_save (flags);
12549 + for (pos = _qh->qtd_list.next;
12550 + pos != &_qh->qtd_list;
12551 + pos = _qh->qtd_list.next)
12554 + qtd = dwc_list_to_qtd (pos);
12555 + dwc_otg_hcd_qtd_free (qtd);
12557 + local_irq_restore (flags);
12563 +/** Initializes a QH structure.
12565 + * @param[in] _hcd The HCD state structure for the DWC OTG controller.
12566 + * @param[in] _qh The QH to init.
12567 + * @param[in] _urb Holds the information about the device/endpoint that we need
12568 + * to initialize the QH. */
12569 +#define SCHEDULE_SLOP 10
12570 +void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, struct urb *_urb)
12572 + memset (_qh, 0, sizeof (dwc_otg_qh_t));
12574 + /* Initialize QH */
12575 + switch (usb_pipetype(_urb->pipe)) {
12576 + case PIPE_CONTROL:
12577 + _qh->ep_type = USB_ENDPOINT_XFER_CONTROL;
12580 + _qh->ep_type = USB_ENDPOINT_XFER_BULK;
12582 + case PIPE_ISOCHRONOUS:
12583 + _qh->ep_type = USB_ENDPOINT_XFER_ISOC;
12585 + case PIPE_INTERRUPT:
12586 + _qh->ep_type = USB_ENDPOINT_XFER_INT;
12590 + _qh->ep_is_in = usb_pipein(_urb->pipe) ? 1 : 0;
12592 + _qh->data_toggle = DWC_OTG_HC_PID_DATA0;
12593 + _qh->maxp = usb_maxpacket(_urb->dev, _urb->pipe, !(usb_pipein(_urb->pipe)));
12594 + INIT_LIST_HEAD(&_qh->qtd_list);
12595 + INIT_LIST_HEAD(&_qh->qh_list_entry);
12596 + _qh->channel = NULL;
12598 + /* FS/LS Enpoint on HS Hub
12599 + * NOT virtual root hub */
12600 + _qh->do_split = 0;
12601 + _qh->speed = _urb->dev->speed;
12602 + if (((_urb->dev->speed == USB_SPEED_LOW) ||
12603 + (_urb->dev->speed == USB_SPEED_FULL)) &&
12604 + (_urb->dev->tt) && (_urb->dev->tt->hub) && (_urb->dev->tt->hub->devnum != 1)) {
12605 + DWC_DEBUGPL(DBG_HCD, "QH init: EP %d: TT found at hub addr %d, for port %d\n",
12606 + usb_pipeendpoint(_urb->pipe), _urb->dev->tt->hub->devnum,
12607 + _urb->dev->ttport);
12608 + _qh->do_split = 1;
12611 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT ||
12612 + _qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
12613 + /* Compute scheduling parameters once and save them. */
12614 + hprt0_data_t hprt;
12616 + /** @todo Account for split transfers in the bus time. */
12617 + int bytecount = dwc_hb_mult(_qh->maxp) * dwc_max_packet(_qh->maxp);
12618 + _qh->usecs = NS_TO_US(usb_calc_bus_time(_urb->dev->speed,
12619 + usb_pipein(_urb->pipe),
12620 + (_qh->ep_type == USB_ENDPOINT_XFER_ISOC),bytecount));
12622 + /* Start in a slightly future (micro)frame. */
12623 + _qh->sched_frame = dwc_frame_num_inc(_hcd->frame_number, SCHEDULE_SLOP);
12624 + _qh->interval = _urb->interval;
12626 + /* Increase interrupt polling rate for debugging. */
12627 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12628 + _qh->interval = 8;
12631 + hprt.d32 = dwc_read_reg32(_hcd->core_if->host_if->hprt0);
12632 + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
12633 + ((_urb->dev->speed == USB_SPEED_LOW) ||
12634 + (_urb->dev->speed == USB_SPEED_FULL)))
12636 + _qh->interval *= 8;
12637 + _qh->sched_frame |= 0x7;
12638 + _qh->start_split_frame = _qh->sched_frame;
12642 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
12643 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", _qh);
12644 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
12645 + _urb->dev->devnum);
12646 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
12647 + usb_pipeendpoint(_urb->pipe),
12648 + usb_pipein(_urb->pipe) == USB_DIR_IN ? "IN" : "OUT");
12649 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n",
12650 + ({ char *speed; switch (_urb->dev->speed) {
12651 + case USB_SPEED_LOW: speed = "low"; break;
12652 + case USB_SPEED_FULL: speed = "full"; break;
12653 + case USB_SPEED_HIGH: speed = "high"; break;
12654 + default: speed = "?"; break;
12656 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n",
12657 + ({ char *type; switch (_qh->ep_type) {
12658 + case USB_ENDPOINT_XFER_ISOC: type = "isochronous"; break;
12659 + case USB_ENDPOINT_XFER_INT: type = "interrupt"; break;
12660 + case USB_ENDPOINT_XFER_CONTROL: type = "control"; break;
12661 + case USB_ENDPOINT_XFER_BULK: type = "bulk"; break;
12662 + default: type = "?"; break;
12665 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12666 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
12668 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
12677 + * Microframe scheduler
12678 + * track the total use in hcd->frame_usecs
12679 + * keep each qh use in qh->frame_usecs
12680 + * when surrendering the qh then donate the time back
12682 +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
12685 + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
12687 +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
12690 + for (i=0; i<8; i++) {
12691 + _hcd->frame_usecs[i] = max_uframe_usecs[i];
12696 +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12699 + unsigned short utime;
12705 + utime = _qh->usecs;
12709 + while (done == 0) {
12710 + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
12711 + if (utime <= _hcd->frame_usecs[i]) {
12712 + _hcd->frame_usecs[i] -= utime;
12713 + _qh->frame_usecs[i] += utime;
12730 + * use this for FS apps that can span multiple uframes
12732 +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12736 + unsigned short utime;
12740 + unsigned short xtime;
12743 + utime = _qh->usecs;
12748 + while (done == 0) {
12749 + if(_hcd->frame_usecs[i] <= 0) {
12759 + * we need n consequtive slots
12760 + * so use j as a start slot j plus j+1 must be enough time (for now)
12762 + xtime= _hcd->frame_usecs[i];
12763 + for (j = i+1 ; j < 8 ; j++ ) {
12765 + * if we add this frame remaining time to xtime we may
12766 + * be OK, if not we need to test j for a complete frame
12768 + if ((xtime+_hcd->frame_usecs[j]) < utime) {
12769 + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
12775 + if (xtime >= utime) {
12777 + j = 8; /* stop loop with a good value ret */
12780 + /* add the frame time to x time */
12781 + xtime += _hcd->frame_usecs[j];
12782 + /* we must have a fully available next frame or break */
12783 + if ((xtime < utime)
12784 + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
12786 + j = 8; /* stop loop with a bad value ret */
12792 + for (j = i; (t_left>0) && (j < 8); j++ ) {
12793 + t_left -= _hcd->frame_usecs[j];
12794 + if ( t_left <= 0 ) {
12795 + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
12796 + _hcd->frame_usecs[j]= -t_left;
12800 + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
12801 + _hcd->frame_usecs[j] = 0;
12815 +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12820 + if (_qh->speed == USB_SPEED_HIGH) {
12821 + /* if this is a hs transaction we need a full frame */
12822 + ret = find_single_uframe(_hcd, _qh);
12824 + /* if this is a fs transaction we may need a sequence of frames */
12825 + ret = find_multi_uframe(_hcd, _qh);
12831 + * Checks that the max transfer size allowed in a host channel is large enough
12832 + * to handle the maximum data transfer in a single (micro)frame for a periodic
12835 + * @param _hcd The HCD state structure for the DWC OTG controller.
12836 + * @param _qh QH for a periodic endpoint.
12838 + * @return 0 if successful, negative error code otherwise.
12840 +static int check_max_xfer_size(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12843 + uint32_t max_xfer_size;
12844 + uint32_t max_channel_xfer_size;
12848 + max_xfer_size = dwc_max_packet(_qh->maxp) * dwc_hb_mult(_qh->maxp);
12849 + max_channel_xfer_size = _hcd->core_if->core_params->max_transfer_size;
12851 + if (max_xfer_size > max_channel_xfer_size) {
12852 + DWC_NOTICE("%s: Periodic xfer length %d > "
12853 + "max xfer length for channel %d\n",
12854 + __func__, max_xfer_size, max_channel_xfer_size);
12855 + status = -ENOSPC;
12862 + * Schedules an interrupt or isochronous transfer in the periodic schedule.
12864 + * @param _hcd The HCD state structure for the DWC OTG controller.
12865 + * @param _qh QH for the periodic transfer. The QH should already contain the
12866 + * scheduling information.
12868 + * @return 0 if successful, negative error code otherwise.
12870 +static int schedule_periodic(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12875 + status = find_uframe(_hcd, _qh);
12877 + if (status == 0) {
12881 + frame = status-1;
12884 + /* Set the new frame up */
12885 + if (frame > -1) {
12886 + _qh->sched_frame &= ~0x7;
12887 + _qh->sched_frame |= (frame & 7);
12890 + if (status != -1 )
12893 + DWC_NOTICE("%s: Insufficient periodic bandwidth for "
12894 + "periodic transfer.\n", __func__);
12898 + status = check_max_xfer_size(_hcd, _qh);
12900 + DWC_NOTICE("%s: Channel max transfer size too small "
12901 + "for periodic transfer.\n", __func__);
12905 + /* Always start in the inactive schedule. */
12906 + list_add_tail(&_qh->qh_list_entry, &_hcd->periodic_sched_inactive);
12909 + /* Update claimed usecs per (micro)frame. */
12910 + _hcd->periodic_usecs += _qh->usecs;
12912 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
12913 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_allocated += _qh->usecs / _qh->interval;
12914 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12915 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_int_reqs++;
12916 + DWC_DEBUGPL(DBG_HCD, "Scheduled intr: qh %p, usecs %d, period %d\n",
12917 + _qh, _qh->usecs, _qh->interval);
12919 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_isoc_reqs++;
12920 + DWC_DEBUGPL(DBG_HCD, "Scheduled isoc: qh %p, usecs %d, period %d\n",
12921 + _qh, _qh->usecs, _qh->interval);
12928 + * This function adds a QH to either the non periodic or periodic schedule if
12929 + * it is not already in the schedule. If the QH is already in the schedule, no
12930 + * action is taken.
12932 + * @return 0 if successful, negative error code otherwise.
12934 +int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12936 + unsigned long flags;
12939 + local_irq_save(flags);
12941 + if (!list_empty(&_qh->qh_list_entry)) {
12942 + /* QH already in a schedule. */
12946 + /* Add the new QH to the appropriate schedule */
12947 + if (dwc_qh_is_non_per(_qh)) {
12948 + /* Always start in the inactive schedule. */
12949 + list_add_tail(&_qh->qh_list_entry, &_hcd->non_periodic_sched_inactive);
12951 + status = schedule_periodic(_hcd, _qh);
12955 + local_irq_restore(flags);
12961 + * This function adds a QH to the non periodic deferred schedule.
12963 + * @return 0 if successful, negative error code otherwise.
12965 +int dwc_otg_hcd_qh_add_deferred(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12967 + unsigned long flags;
12968 + local_irq_save(flags);
12969 + if (!list_empty(&_qh->qh_list_entry)) {
12970 + /* QH already in a schedule. */
12974 + /* Add the new QH to the non periodic deferred schedule */
12975 + if (dwc_qh_is_non_per(_qh)) {
12976 + list_add_tail(&_qh->qh_list_entry,
12977 + &_hcd->non_periodic_sched_deferred);
12980 + local_irq_restore(flags);
12985 + * Removes an interrupt or isochronous transfer from the periodic schedule.
12987 + * @param _hcd The HCD state structure for the DWC OTG controller.
12988 + * @param _qh QH for the periodic transfer.
12990 +static void deschedule_periodic(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12993 + list_del_init(&_qh->qh_list_entry);
12996 + /* Update claimed usecs per (micro)frame. */
12997 + _hcd->periodic_usecs -= _qh->usecs;
12999 + for (i = 0; i < 8; i++) {
13000 + _hcd->frame_usecs[i] += _qh->frame_usecs[i];
13001 + _qh->frame_usecs[i] = 0;
13003 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
13004 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_allocated -= _qh->usecs / _qh->interval;
13006 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
13007 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_int_reqs--;
13008 + DWC_DEBUGPL(DBG_HCD, "Descheduled intr: qh %p, usecs %d, period %d\n",
13009 + _qh, _qh->usecs, _qh->interval);
13011 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_isoc_reqs--;
13012 + DWC_DEBUGPL(DBG_HCD, "Descheduled isoc: qh %p, usecs %d, period %d\n",
13013 + _qh, _qh->usecs, _qh->interval);
13018 + * Removes a QH from either the non-periodic or periodic schedule. Memory is
13021 + * @param[in] _hcd The HCD state structure.
13022 + * @param[in] _qh QH to remove from schedule. */
13023 +void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
13025 + unsigned long flags;
13027 + local_irq_save(flags);
13029 + if (list_empty(&_qh->qh_list_entry)) {
13030 + /* QH is not in a schedule. */
13034 + if (dwc_qh_is_non_per(_qh)) {
13035 + if (_hcd->non_periodic_qh_ptr == &_qh->qh_list_entry) {
13036 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
13038 + list_del_init(&_qh->qh_list_entry);
13040 + deschedule_periodic(_hcd, _qh);
13044 + local_irq_restore(flags);
13048 + * Defers a QH. For non-periodic QHs, removes the QH from the active
13049 + * non-periodic schedule. The QH is added to the deferred non-periodic
13050 + * schedule if any QTDs are still attached to the QH.
13052 +int dwc_otg_hcd_qh_deferr(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh, int delay)
13055 + unsigned long flags;
13056 + local_irq_save(flags);
13057 + if (dwc_qh_is_non_per(_qh)) {
13058 + _qh->sched_frame =
13059 + dwc_frame_num_inc(_hcd->frame_number,
13061 + _qh->channel = NULL;
13062 + _qh->qtd_in_process = NULL;
13064 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13065 + if (!list_empty(&_qh->qtd_list)) {
13066 + /* Add back to deferred non-periodic schedule. */
13067 + dwc_otg_hcd_qh_add_deferred(_hcd, _qh);
13070 + local_irq_restore(flags);
13075 + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
13076 + * non-periodic schedule. The QH is added to the inactive non-periodic
13077 + * schedule if any QTDs are still attached to the QH.
13079 + * For periodic QHs, the QH is removed from the periodic queued schedule. If
13080 + * there are any QTDs still attached to the QH, the QH is added to either the
13081 + * periodic inactive schedule or the periodic ready schedule and its next
13082 + * scheduled frame is calculated. The QH is placed in the ready schedule if
13083 + * the scheduled frame has been reached already. Otherwise it's placed in the
13084 + * inactive schedule. If there are no QTDs attached to the QH, the QH is
13085 + * completely removed from the periodic schedule.
13087 +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int sched_next_periodic_split)
13089 + unsigned long flags;
13090 + local_irq_save(flags);
13092 + if (dwc_qh_is_non_per(_qh)) {
13093 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13094 + if (!list_empty(&_qh->qtd_list)) {
13095 + /* Add back to inactive non-periodic schedule. */
13096 + dwc_otg_hcd_qh_add(_hcd, _qh);
13099 + uint16_t frame_number = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
13101 + if (_qh->do_split) {
13102 + /* Schedule the next continuing periodic split transfer */
13103 + if (sched_next_periodic_split) {
13105 + _qh->sched_frame = frame_number;
13106 + if (dwc_frame_num_le(frame_number,
13107 + dwc_frame_num_inc(_qh->start_split_frame, 1))) {
13109 + * Allow one frame to elapse after start
13110 + * split microframe before scheduling
13111 + * complete split, but DONT if we are
13112 + * doing the next start split in the
13113 + * same frame for an ISOC out.
13115 + if ((_qh->ep_type != USB_ENDPOINT_XFER_ISOC) || (_qh->ep_is_in != 0)) {
13116 + _qh->sched_frame = dwc_frame_num_inc(_qh->sched_frame, 1);
13120 + _qh->sched_frame = dwc_frame_num_inc(_qh->start_split_frame,
13122 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13123 + _qh->sched_frame = frame_number;
13125 + _qh->sched_frame |= 0x7;
13126 + _qh->start_split_frame = _qh->sched_frame;
13129 + _qh->sched_frame = dwc_frame_num_inc(_qh->sched_frame, _qh->interval);
13130 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13131 + _qh->sched_frame = frame_number;
13135 + if (list_empty(&_qh->qtd_list)) {
13136 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13139 + * Remove from periodic_sched_queued and move to
13140 + * appropriate queue.
13142 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13143 + list_move(&_qh->qh_list_entry,
13144 + &_hcd->periodic_sched_ready);
13146 + list_move(&_qh->qh_list_entry,
13147 + &_hcd->periodic_sched_inactive);
13152 + local_irq_restore(flags);
13156 + * This function allocates and initializes a QTD.
13158 + * @param[in] _urb The URB to create a QTD from. Each URB-QTD pair will end up
13159 + * pointing to each other so each pair should have a unique correlation.
13161 + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
13162 +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *_urb)
13164 + dwc_otg_qtd_t *qtd;
13166 + qtd = dwc_otg_hcd_qtd_alloc ();
13167 + if (qtd == NULL) {
13171 + dwc_otg_hcd_qtd_init (qtd, _urb);
13176 + * Initializes a QTD structure.
13178 + * @param[in] _qtd The QTD to initialize.
13179 + * @param[in] _urb The URB to use for initialization. */
13180 +void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *_qtd, struct urb *_urb)
13182 + memset (_qtd, 0, sizeof (dwc_otg_qtd_t));
13183 + _qtd->urb = _urb;
13184 + if (usb_pipecontrol(_urb->pipe)) {
13186 + * The only time the QTD data toggle is used is on the data
13187 + * phase of control transfers. This phase always starts with
13190 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
13191 + _qtd->control_phase = DWC_OTG_CONTROL_SETUP;
13194 + /* start split */
13195 + _qtd->complete_split = 0;
13196 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
13197 + _qtd->isoc_split_offset = 0;
13199 + /* Store the qtd ptr in the urb to reference what QTD. */
13200 + _urb->hcpriv = _qtd;
13205 + * This function adds a QTD to the QTD-list of a QH. It will find the correct
13206 + * QH to place the QTD into. If it does not find a QH, then it will create a
13207 + * new QH. If the QH to which the QTD is added is not currently scheduled, it
13208 + * is placed into the proper schedule based on its EP type.
13210 + * @param[in] _qtd The QTD to add
13211 + * @param[in] _dwc_otg_hcd The DWC HCD structure
13213 + * @return 0 if successful, negative error code otherwise.
13215 +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * _qtd, dwc_otg_hcd_t * _dwc_otg_hcd)
13217 + struct usb_host_endpoint *ep;
13218 + dwc_otg_qh_t *qh;
13219 + unsigned long flags;
13221 + struct urb *urb = _qtd->urb;
13223 + local_irq_save(flags);
13226 + * Get the QH which holds the QTD-list to insert to. Create QH if it
13229 + ep = dwc_urb_to_endpoint(urb);
13230 + qh = (dwc_otg_qh_t *)ep->hcpriv;
13231 + if (qh == NULL) {
13232 + qh = dwc_otg_hcd_qh_create (_dwc_otg_hcd, urb);
13233 + if (qh == NULL) {
13240 + _qtd->qtd_qh_ptr = qh;
13241 + retval = dwc_otg_hcd_qh_add(_dwc_otg_hcd, qh);
13242 + if (retval == 0) {
13243 + list_add_tail(&_qtd->qtd_list_entry, &qh->qtd_list);
13247 + local_irq_restore(flags);
13251 +#endif /* DWC_DEVICE_ONLY */
13253 +++ b/drivers/usb/dwc_otg/dwc_otg_ifx.c
13255 +/******************************************************************************
13257 +** FILE NAME : dwc_otg_ifx.c
13258 +** PROJECT : Twinpass/Danube
13259 +** MODULES : DWC OTG USB
13261 +** DATE : 12 Auguest 2007
13262 +** AUTHOR : Sung Winder
13263 +** DESCRIPTION : Platform specific initialization.
13264 +** COPYRIGHT : Copyright (c) 2007
13265 +** Infineon Technologies AG
13266 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
13267 +** Hsin-chu City, 300 Taiwan.
13269 +** This program is free software; you can redistribute it and/or modify
13270 +** it under the terms of the GNU General Public License as published by
13271 +** the Free Software Foundation; either version 2 of the License, or
13272 +** (at your option) any later version.
13275 +** $Date $Author $Comment
13276 +** 12 Auguest 2007 Sung Winder Initiate Version
13277 +*******************************************************************************/
13278 +#include "dwc_otg_ifx.h"
13280 +#include <linux/platform_device.h>
13281 +#include <linux/kernel.h>
13282 +#include <linux/ioport.h>
13283 +#include <linux/gpio.h>
13285 +#include <asm/io.h>
13286 +//#include <asm/mach-ifxmips/ifxmips.h>
13287 +#include <lantiq_soc.h>
13289 +#define IFXMIPS_GPIO_BASE_ADDR (0xBE100B00)
13291 +#define IFXMIPS_GPIO_P0_OUT ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0010))
13292 +#define IFXMIPS_GPIO_P1_OUT ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0040))
13293 +#define IFXMIPS_GPIO_P0_IN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0014))
13294 +#define IFXMIPS_GPIO_P1_IN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0044))
13295 +#define IFXMIPS_GPIO_P0_DIR ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0018))
13296 +#define IFXMIPS_GPIO_P1_DIR ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0048))
13297 +#define IFXMIPS_GPIO_P0_ALTSEL0 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x001C))
13298 +#define IFXMIPS_GPIO_P1_ALTSEL0 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x004C))
13299 +#define IFXMIPS_GPIO_P0_ALTSEL1 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0020))
13300 +#define IFXMIPS_GPIO_P1_ALTSEL1 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0050))
13301 +#define IFXMIPS_GPIO_P0_OD ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0024))
13302 +#define IFXMIPS_GPIO_P1_OD ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0054))
13303 +#define IFXMIPS_GPIO_P0_STOFF ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0028))
13304 +#define IFXMIPS_GPIO_P1_STOFF ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0058))
13305 +#define IFXMIPS_GPIO_P0_PUDSEL ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x002C))
13306 +#define IFXMIPS_GPIO_P1_PUDSEL ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x005C))
13307 +#define IFXMIPS_GPIO_P0_PUDEN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0030))
13308 +#define IFXMIPS_GPIO_P1_PUDEN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0060))
13311 +extern void ltq_enable_irq(unsigned int irq_nr);
13312 +#define writel ltq_w32
13313 +#define readl ltq_r32
13314 +void dwc_otg_power_on (void)
13317 + writel(readl(DANUBE_PMU_PWDCR) | 0x41, DANUBE_PMU_PWDCR);
13318 + // set clock gating
13319 + writel(readl(DANUBE_CGU_IFCCR) | 0x30, DANUBE_CGU_IFCCR);
13321 + writel(readl(DANUBE_PMU_PWDCR) & ~0x1, DANUBE_PMU_PWDCR);
13322 + writel(readl(DANUBE_PMU_PWDCR) & ~0x40, DANUBE_PMU_PWDCR);
13323 + writel(readl(DANUBE_PMU_PWDCR) & ~0x8000, DANUBE_PMU_PWDCR);
13325 +#if 1//defined (DWC_HOST_ONLY)
13326 + // make the hardware be a host controller (default)
13327 + //clear_bit (DANUBE_USBCFG_HDSEL_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13328 + writel(readl(DANUBE_RCU_UBSCFG) & ~(1<<DANUBE_USBCFG_HDSEL_BIT), DANUBE_RCU_UBSCFG);
13330 + //#elif defined (DWC_DEVICE_ONLY)
13331 + /* set the controller to the device mode */
13332 + // set_bit (DANUBE_USBCFG_HDSEL_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13334 +#error "For Danube/Twinpass, it should be HOST or Device Only."
13337 + // set the HC's byte-order to big-endian
13338 + //set_bit (DANUBE_USBCFG_HOST_END_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13339 + writel(readl(DANUBE_RCU_UBSCFG) | (1<<DANUBE_USBCFG_HOST_END_BIT), DANUBE_RCU_UBSCFG);
13340 + //clear_bit (DANUBE_USBCFG_SLV_END_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13341 + writel(readl(DANUBE_RCU_UBSCFG) & ~(1<<DANUBE_USBCFG_SLV_END_BIT), DANUBE_RCU_UBSCFG);
13342 + //writel(0x400, DANUBE_RCU_UBSCFG);
13344 + // PHY configurations.
13345 + writel (0x14014, (volatile unsigned long *)0xbe10103c);
13348 +int ifx_usb_hc_init(unsigned long base_addr, int irq)
13353 +void ifx_usb_hc_remove(void)
13357 +++ b/drivers/usb/dwc_otg/dwc_otg_ifx.h
13359 +/******************************************************************************
13361 +** FILE NAME : dwc_otg_ifx.h
13362 +** PROJECT : Twinpass/Danube
13363 +** MODULES : DWC OTG USB
13365 +** DATE : 12 April 2007
13366 +** AUTHOR : Sung Winder
13367 +** DESCRIPTION : Platform specific initialization.
13368 +** COPYRIGHT : Copyright (c) 2007
13369 +** Infineon Technologies AG
13370 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
13371 +** Hsin-chu City, 300 Taiwan.
13373 +** This program is free software; you can redistribute it and/or modify
13374 +** it under the terms of the GNU General Public License as published by
13375 +** the Free Software Foundation; either version 2 of the License, or
13376 +** (at your option) any later version.
13379 +** $Date $Author $Comment
13380 +** 12 April 2007 Sung Winder Initiate Version
13381 +*******************************************************************************/
13382 +#if !defined(__DWC_OTG_IFX_H__)
13383 +#define __DWC_OTG_IFX_H__
13387 +// 20070316, winder added.
13389 +#define SZ_256K 0x00040000
13392 +extern void dwc_otg_power_on (void);
13394 +/* FIXME: The current Linux-2.6 do not have these header files, but anyway, we need these. */
13395 +// #include <asm/danube/danube.h>
13396 +// #include <asm/ifx/irq.h>
13398 +/* winder, I used the Danube parameter as default. *
13399 + * We could change this through module param. */
13400 +#define IFX_USB_IOMEM_BASE 0x1e101000
13401 +#define IFX_USB_IOMEM_SIZE SZ_256K
13402 +#define IFX_USB_IRQ LTQ_USB_INT
13405 + * This function is called to set correct clock gating and power.
13406 + * For Twinpass/Danube board.
13408 +#ifndef DANUBE_RCU_BASE_ADDR
13409 +#define DANUBE_RCU_BASE_ADDR (0xBF203000)
13412 +#ifndef DANUBE_CGU
13413 +#define DANUBE_CGU (0xBF103000)
13415 +#ifndef DANUBE_CGU_IFCCR
13416 +/***CGU Interface Clock Control Register***/
13417 +#define DANUBE_CGU_IFCCR ((volatile u32*)(DANUBE_CGU+ 0x0018))
13420 +#ifndef DANUBE_PMU
13421 +#define DANUBE_PMU (KSEG1+0x1F102000)
13423 +#ifndef DANUBE_PMU_PWDCR
13424 +/* PMU Power down Control Register */
13425 +#define DANUBE_PMU_PWDCR ((volatile u32*)(DANUBE_PMU+0x001C))
13429 +#define DANUBE_RCU_UBSCFG ((volatile u32*)(DANUBE_RCU_BASE_ADDR + 0x18))
13430 +#define DANUBE_USBCFG_HDSEL_BIT 11 // 0:host, 1:device
13431 +#define DANUBE_USBCFG_HOST_END_BIT 10 // 0:little_end, 1:big_end
13432 +#define DANUBE_USBCFG_SLV_END_BIT 9 // 0:little_end, 1:big_end
13434 +extern void ltq_mask_and_ack_irq (unsigned int irq_nr);
13435 +#define mask_and_ack_ifx_irq ltq_mask_and_ack_irq
13437 +#endif //__DWC_OTG_IFX_H__
13439 +++ b/drivers/usb/dwc_otg/dwc_otg_plat.h
13441 +/* ==========================================================================
13442 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/platform/dwc_otg_plat.h $
13443 + * $Revision: 1.1.1.1 $
13444 + * $Date: 2009-04-17 06:15:34 $
13445 + * $Change: 510301 $
13447 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13448 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13449 + * otherwise expressly agreed to in writing between Synopsys and you.
13451 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13452 + * any End User Software License Agreement or Agreement for Licensed Product
13453 + * with Synopsys or any supplement thereto. You are permitted to use and
13454 + * redistribute this Software in source and binary forms, with or without
13455 + * modification, provided that redistributions of source code must retain this
13456 + * notice. You may not view, use, disclose, copy or distribute this file or
13457 + * any information contained herein except pursuant to this license grant from
13458 + * Synopsys. If you do not agree with this notice, including the disclaimer
13459 + * below, then you are not authorized to use the Software.
13461 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13462 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13463 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13464 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13465 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13466 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13467 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13468 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13469 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13470 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13472 + * ========================================================================== */
13474 +#if !defined(__DWC_OTG_PLAT_H__)
13475 +#define __DWC_OTG_PLAT_H__
13477 +#include <linux/types.h>
13478 +#include <linux/slab.h>
13479 +#include <linux/list.h>
13480 +#include <linux/delay.h>
13481 +#include <asm/io.h>
13486 + * This file contains the Platform Specific constants, interfaces
13487 + * (functions and macros) for Linux.
13490 +/*#if !defined(__LINUX__)
13491 +#error "The contents of this file is Linux specific!!!"
13494 +#include <lantiq_soc.h>
13495 +#define writel ltq_w32
13496 +#define readl ltq_r32
13499 + * Reads the content of a register.
13501 + * @param _reg address of register to read.
13502 + * @return contents of the register.
13506 + * <code>uint32_t dev_ctl = dwc_read_reg32(&dev_regs->dctl);</code>
13508 +static __inline__ uint32_t dwc_read_reg32( volatile uint32_t *_reg)
13510 + return readl(_reg);
13514 + * Writes a register with a 32 bit value.
13516 + * @param _reg address of register to read.
13517 + * @param _value to write to _reg.
13520 + * <code>dwc_write_reg32(&dev_regs->dctl, 0); </code>
13522 +static __inline__ void dwc_write_reg32( volatile uint32_t *_reg, const uint32_t _value)
13524 + writel( _value, _reg );
13528 + * This function modifies bit values in a register. Using the
13529 + * algorithm: (reg_contents & ~clear_mask) | set_mask.
13531 + * @param _reg address of register to read.
13532 + * @param _clear_mask bit mask to be cleared.
13533 + * @param _set_mask bit mask to be set.
13536 + * <code> // Clear the SOF Interrupt Mask bit and <br>
13537 + * // set the OTG Interrupt mask bit, leaving all others as they were.
13538 + * dwc_modify_reg32(&dev_regs->gintmsk, DWC_SOF_INT, DWC_OTG_INT);</code>
13541 + void dwc_modify_reg32( volatile uint32_t *_reg, const uint32_t _clear_mask, const uint32_t _set_mask)
13543 + writel( (readl(_reg) & ~_clear_mask) | _set_mask, _reg );
13548 + * Wrapper for the OS micro-second delay function.
13549 + * @param[in] _usecs Microseconds of delay
13551 +static __inline__ void UDELAY( const uint32_t _usecs )
13553 + udelay( _usecs );
13557 + * Wrapper for the OS milli-second delay function.
13558 + * @param[in] _msecs milliseconds of delay
13560 +static __inline__ void MDELAY( const uint32_t _msecs )
13562 + mdelay( _msecs );
13566 + * Wrapper for the Linux spin_lock. On the ARM (Integrator)
13567 + * spin_lock() is a nop.
13569 + * @param _lock Pointer to the spinlock.
13571 +static __inline__ void SPIN_LOCK( spinlock_t *_lock )
13573 + spin_lock(_lock);
13577 + * Wrapper for the Linux spin_unlock. On the ARM (Integrator)
13578 + * spin_lock() is a nop.
13580 + * @param _lock Pointer to the spinlock.
13582 +static __inline__ void SPIN_UNLOCK( spinlock_t *_lock )
13584 + spin_unlock(_lock);
13588 + * Wrapper (macro) for the Linux spin_lock_irqsave. On the ARM
13589 + * (Integrator) spin_lock() is a nop.
13591 + * @param _l Pointer to the spinlock.
13592 + * @param _f unsigned long for irq flags storage.
13594 +#define SPIN_LOCK_IRQSAVE( _l, _f ) { \
13595 + spin_lock_irqsave(_l,_f); \
13599 + * Wrapper (macro) for the Linux spin_unlock_irqrestore. On the ARM
13600 + * (Integrator) spin_lock() is a nop.
13602 + * @param _l Pointer to the spinlock.
13603 + * @param _f unsigned long for irq flags storage.
13605 +#define SPIN_UNLOCK_IRQRESTORE( _l,_f ) {\
13606 + spin_unlock_irqrestore(_l,_f); \
13611 + * Debugging support vanishes in non-debug builds.
13616 + * The Debug Level bit-mask variable.
13618 +extern uint32_t g_dbg_lvl;
13620 + * Set the Debug Level variable.
13622 +static inline uint32_t SET_DEBUG_LEVEL( const uint32_t _new )
13624 + uint32_t old = g_dbg_lvl;
13625 + g_dbg_lvl = _new;
13629 +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
13630 +#define DBG_CIL (0x2)
13631 +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
13633 +#define DBG_CILV (0x20)
13634 +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
13636 +#define DBG_PCD (0x4)
13637 +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
13639 +#define DBG_PCDV (0x40)
13640 +/** When debug level has the DBG_HCD bit set, display Host debug messages */
13641 +#define DBG_HCD (0x8)
13642 +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
13644 +#define DBG_HCDV (0x80)
13645 +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
13647 +#define DBG_HCD_URB (0x800)
13649 +/** When debug level has any bit set, display debug messages */
13650 +#define DBG_ANY (0xFF)
13652 +/** All debug messages off */
13655 +/** Prefix string for DWC_DEBUG print macros. */
13656 +#define USB_DWC "DWC_otg: "
13659 + * Print a debug message when the Global debug level variable contains
13660 + * the bit defined in <code>lvl</code>.
13662 + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
13663 + * @param[in] x - like printf
13667 + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
13670 + * results in:<br>
13672 + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
13677 +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)printk( KERN_DEBUG USB_DWC x ); }while(0)
13678 +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
13680 +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
13684 +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
13685 +# define DWC_DEBUGP(x...)
13687 +# define CHK_DEBUG_LEVEL(level) (0)
13692 + * Print an Error message.
13694 +#define DWC_ERROR(x...) printk( KERN_ERR USB_DWC x )
13696 + * Print a Warning message.
13698 +#define DWC_WARN(x...) printk( KERN_WARNING USB_DWC x )
13700 + * Print a notice (normal but significant message).
13702 +#define DWC_NOTICE(x...) printk( KERN_NOTICE USB_DWC x )
13704 + * Basic message printing.
13706 +#define DWC_PRINT(x...) printk( KERN_INFO USB_DWC x )
13711 +++ b/drivers/usb/dwc_otg/dwc_otg_regs.h
13713 +/* ==========================================================================
13714 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_regs.h $
13715 + * $Revision: 1.1.1.1 $
13716 + * $Date: 2009-04-17 06:15:34 $
13717 + * $Change: 631780 $
13719 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13720 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13721 + * otherwise expressly agreed to in writing between Synopsys and you.
13723 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13724 + * any End User Software License Agreement or Agreement for Licensed Product
13725 + * with Synopsys or any supplement thereto. You are permitted to use and
13726 + * redistribute this Software in source and binary forms, with or without
13727 + * modification, provided that redistributions of source code must retain this
13728 + * notice. You may not view, use, disclose, copy or distribute this file or
13729 + * any information contained herein except pursuant to this license grant from
13730 + * Synopsys. If you do not agree with this notice, including the disclaimer
13731 + * below, then you are not authorized to use the Software.
13733 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13734 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13735 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13736 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13737 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13738 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13739 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13740 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13741 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13742 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13744 + * ========================================================================== */
13746 +#ifndef __DWC_OTG_REGS_H__
13747 +#define __DWC_OTG_REGS_H__
13752 + * This file contains the data structures for accessing the DWC_otg core registers.
13754 + * The application interfaces with the HS OTG core by reading from and
13755 + * writing to the Control and Status Register (CSR) space through the
13756 + * AHB Slave interface. These registers are 32 bits wide, and the
13757 + * addresses are 32-bit-block aligned.
13758 + * CSRs are classified as follows:
13759 + * - Core Global Registers
13760 + * - Device Mode Registers
13761 + * - Device Global Registers
13762 + * - Device Endpoint Specific Registers
13763 + * - Host Mode Registers
13764 + * - Host Global Registers
13765 + * - Host Port CSRs
13766 + * - Host Channel Specific Registers
13768 + * Only the Core Global registers can be accessed in both Device and
13769 + * Host modes. When the HS OTG core is operating in one mode, either
13770 + * Device or Host, the application must not access registers from the
13771 + * other mode. When the core switches from one mode to another, the
13772 + * registers in the new mode of operation must be reprogrammed as they
13773 + * would be after a power-on reset.
13776 +/****************************************************************************/
13777 +/** DWC_otg Core registers .
13778 + * The dwc_otg_core_global_regs structure defines the size
13779 + * and relative field offsets for the Core Global registers.
13781 +typedef struct dwc_otg_core_global_regs
13783 + /** OTG Control and Status Register. <i>Offset: 000h</i> */
13784 + volatile uint32_t gotgctl;
13785 + /** OTG Interrupt Register. <i>Offset: 004h</i> */
13786 + volatile uint32_t gotgint;
13787 + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
13788 + volatile uint32_t gahbcfg;
13789 +#define DWC_GLBINTRMASK 0x0001
13790 +#define DWC_DMAENABLE 0x0020
13791 +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
13792 +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
13793 +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
13794 +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
13797 + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
13798 + volatile uint32_t gusbcfg;
13799 + /**Core Reset Register. <i>Offset: 010h</i> */
13800 + volatile uint32_t grstctl;
13801 + /**Core Interrupt Register. <i>Offset: 014h</i> */
13802 + volatile uint32_t gintsts;
13803 + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
13804 + volatile uint32_t gintmsk;
13805 + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
13806 + volatile uint32_t grxstsr;
13807 + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
13808 + volatile uint32_t grxstsp;
13809 + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
13810 + volatile uint32_t grxfsiz;
13811 + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
13812 + volatile uint32_t gnptxfsiz;
13813 + /**Non Periodic Transmit FIFO/Queue Status Register (Read
13814 + * Only). <i>Offset: 02Ch</i> */
13815 + volatile uint32_t gnptxsts;
13816 + /**I2C Access Register. <i>Offset: 030h</i> */
13817 + volatile uint32_t gi2cctl;
13818 + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
13819 + volatile uint32_t gpvndctl;
13820 + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
13821 + volatile uint32_t ggpio;
13822 + /**User ID Register. <i>Offset: 03Ch</i> */
13823 + volatile uint32_t guid;
13824 + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
13825 + volatile uint32_t gsnpsid;
13826 + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
13827 + volatile uint32_t ghwcfg1;
13828 + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
13829 + volatile uint32_t ghwcfg2;
13830 +#define DWC_SLAVE_ONLY_ARCH 0
13831 +#define DWC_EXT_DMA_ARCH 1
13832 +#define DWC_INT_DMA_ARCH 2
13834 +#define DWC_MODE_HNP_SRP_CAPABLE 0
13835 +#define DWC_MODE_SRP_ONLY_CAPABLE 1
13836 +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
13837 +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
13838 +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
13839 +#define DWC_MODE_SRP_CAPABLE_HOST 5
13840 +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
13842 + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
13843 + volatile uint32_t ghwcfg3;
13844 + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
13845 + volatile uint32_t ghwcfg4;
13846 + /** Reserved <i>Offset: 054h-0FFh</i> */
13847 + uint32_t reserved[43];
13848 + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
13849 + volatile uint32_t hptxfsiz;
13850 + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
13851 + otherwise Device Transmit FIFO#n Register.
13852 + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
13853 + //volatile uint32_t dptxfsiz[15];
13854 + volatile uint32_t dptxfsiz_dieptxf[15];
13855 +} dwc_otg_core_global_regs_t;
13858 + * This union represents the bit fields of the Core OTG Control
13859 + * and Status Register (GOTGCTL). Set the bits using the bit
13860 + * fields then write the <i>d32</i> value to the register.
13862 +typedef union gotgctl_data
13864 + /** raw register data */
13866 + /** register bits */
13869 + unsigned reserved31_21 : 11;
13870 + unsigned currmod : 1;
13871 + unsigned bsesvld : 1;
13872 + unsigned asesvld : 1;
13873 + unsigned reserved17 : 1;
13874 + unsigned conidsts : 1;
13875 + unsigned reserved15_12 : 4;
13876 + unsigned devhnpen : 1;
13877 + unsigned hstsethnpen : 1;
13878 + unsigned hnpreq : 1;
13879 + unsigned hstnegscs : 1;
13880 + unsigned reserved7_2 : 6;
13881 + unsigned sesreq : 1;
13882 + unsigned sesreqscs : 1;
13887 + * This union represents the bit fields of the Core OTG Interrupt Register
13888 + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
13889 + * value to the register.
13891 +typedef union gotgint_data
13893 + /** raw register data */
13895 + /** register bits */
13898 + /** Current Mode */
13899 + unsigned reserved31_20 : 12;
13900 + /** Debounce Done */
13901 + unsigned debdone : 1;
13902 + /** A-Device Timeout Change */
13903 + unsigned adevtoutchng : 1;
13904 + /** Host Negotiation Detected */
13905 + unsigned hstnegdet : 1;
13906 + unsigned reserver16_10 : 7;
13907 + /** Host Negotiation Success Status Change */
13908 + unsigned hstnegsucstschng : 1;
13909 + /** Session Request Success Status Change */
13910 + unsigned sesreqsucstschng : 1;
13911 + unsigned reserved3_7 : 5;
13912 + /** Session End Detected */
13913 + unsigned sesenddet : 1;
13914 + /** Current Mode */
13915 + unsigned reserved1_0 : 2;
13921 + * This union represents the bit fields of the Core AHB Configuration
13922 + * Register (GAHBCFG). Set/clear the bits using the bit fields then
13923 + * write the <i>d32</i> value to the register.
13925 +typedef union gahbcfg_data
13927 + /** raw register data */
13929 + /** register bits */
13932 +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
13933 +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
13934 + unsigned reserved9_31 : 23;
13935 + unsigned ptxfemplvl : 1;
13936 + unsigned nptxfemplvl_txfemplvl : 1;
13937 +#define DWC_GAHBCFG_DMAENABLE 1
13938 + unsigned reserved : 1;
13939 + unsigned dmaenable : 1;
13940 +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
13941 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
13942 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
13943 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
13944 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
13945 + unsigned hburstlen : 4;
13946 + unsigned glblintrmsk : 1;
13947 +#define DWC_GAHBCFG_GLBINT_ENABLE 1
13953 + * This union represents the bit fields of the Core USB Configuration
13954 + * Register (GUSBCFG). Set the bits using the bit fields then write
13955 + * the <i>d32</i> value to the register.
13957 +typedef union gusbcfg_data
13959 + /** raw register data */
13961 + /** register bits */
13964 + unsigned corrupt_tx_packet: 1; /*fscz*/
13965 + unsigned force_device_mode: 1;
13966 + unsigned force_host_mode: 1;
13967 + unsigned reserved23_28 : 6;
13968 + unsigned term_sel_dl_pulse : 1;
13969 + unsigned ulpi_int_vbus_indicator : 1;
13970 + unsigned ulpi_ext_vbus_drv : 1;
13971 + unsigned ulpi_clk_sus_m : 1;
13972 + unsigned ulpi_auto_res : 1;
13973 + unsigned ulpi_fsls : 1;
13974 + unsigned otgutmifssel : 1;
13975 + unsigned phylpwrclksel : 1;
13976 + unsigned nptxfrwnden : 1;
13977 + unsigned usbtrdtim : 4;
13978 + unsigned hnpcap : 1;
13979 + unsigned srpcap : 1;
13980 + unsigned ddrsel : 1;
13981 + unsigned physel : 1;
13982 + unsigned fsintf : 1;
13983 + unsigned ulpi_utmi_sel : 1;
13984 + unsigned phyif : 1;
13985 + unsigned toutcal : 3;
13990 + * This union represents the bit fields of the Core Reset Register
13991 + * (GRSTCTL). Set/clear the bits using the bit fields then write the
13992 + * <i>d32</i> value to the register.
13994 +typedef union grstctl_data
13996 + /** raw register data */
13998 + /** register bits */
14001 + /** AHB Master Idle. Indicates the AHB Master State
14002 + * Machine is in IDLE condition. */
14003 + unsigned ahbidle : 1;
14004 + /** DMA Request Signal. Indicated DMA request is in
14005 + * probress. Used for debug purpose. */
14006 + unsigned dmareq : 1;
14008 + unsigned reserved29_11 : 19;
14009 + /** TxFIFO Number (TxFNum) (Device and Host).
14011 + * This is the FIFO number which needs to be flushed,
14012 + * using the TxFIFO Flush bit. This field should not
14013 + * be changed until the TxFIFO Flush bit is cleared by
14015 + * - 0x0 : Non Periodic TxFIFO Flush
14016 + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
14017 + * or Periodic TxFIFO in host mode
14018 + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
14020 + * - 0xF : Periodic TxFIFO #15 Flush in device mode
14021 + * - 0x10: Flush all the Transmit NonPeriodic and
14022 + * Transmit Periodic FIFOs in the core
14024 + unsigned txfnum : 5;
14025 + /** TxFIFO Flush (TxFFlsh) (Device and Host).
14027 + * This bit is used to selectively flush a single or
14028 + * all transmit FIFOs. The application must first
14029 + * ensure that the core is not in the middle of a
14030 + * transaction. <p>The application should write into
14031 + * this bit, only after making sure that neither the
14032 + * DMA engine is writing into the TxFIFO nor the MAC
14033 + * is reading the data out of the FIFO. <p>The
14034 + * application should wait until the core clears this
14035 + * bit, before performing any operations. This bit
14036 + * will takes 8 clocks (slowest of PHY or AHB clock)
14039 + unsigned txfflsh : 1;
14040 + /** RxFIFO Flush (RxFFlsh) (Device and Host)
14042 + * The application can flush the entire Receive FIFO
14043 + * using this bit. <p>The application must first
14044 + * ensure that the core is not in the middle of a
14045 + * transaction. <p>The application should write into
14046 + * this bit, only after making sure that neither the
14047 + * DMA engine is reading from the RxFIFO nor the MAC
14048 + * is writing the data in to the FIFO. <p>The
14049 + * application should wait until the bit is cleared
14050 + * before performing any other operations. This bit
14051 + * will takes 8 clocks (slowest of PHY or AHB clock)
14054 + unsigned rxfflsh : 1;
14055 + /** In Token Sequence Learning Queue Flush
14056 + * (INTknQFlsh) (Device Only)
14058 + unsigned intknqflsh : 1;
14059 + /** Host Frame Counter Reset (Host Only)<br>
14061 + * The application can reset the (micro)frame number
14062 + * counter inside the core, using this bit. When the
14063 + * (micro)frame counter is reset, the subsequent SOF
14064 + * sent out by the core, will have a (micro)frame
14067 + unsigned hstfrm : 1;
14068 + /** Hclk Soft Reset
14070 + * The application uses this bit to reset the control logic in
14071 + * the AHB clock domain. Only AHB clock domain pipelines are
14074 + unsigned hsftrst : 1;
14075 + /** Core Soft Reset (CSftRst) (Device and Host)
14077 + * The application can flush the control logic in the
14078 + * entire core using this bit. This bit resets the
14079 + * pipelines in the AHB Clock domain as well as the
14080 + * PHY Clock domain.
14082 + * The state machines are reset to an IDLE state, the
14083 + * control bits in the CSRs are cleared, all the
14084 + * transmit FIFOs and the receive FIFO are flushed.
14086 + * The status mask bits that control the generation of
14087 + * the interrupt, are cleared, to clear the
14088 + * interrupt. The interrupt status bits are not
14089 + * cleared, so the application can get the status of
14090 + * any events that occurred in the core after it has
14093 + * Any transactions on the AHB are terminated as soon
14094 + * as possible following the protocol. Any
14095 + * transactions on the USB are terminated immediately.
14097 + * The configuration settings in the CSRs are
14098 + * unchanged, so the software doesn't have to
14099 + * reprogram these registers (Device
14100 + * Configuration/Host Configuration/Core System
14101 + * Configuration/Core PHY Configuration).
14103 + * The application can write to this bit, any time it
14104 + * wants to reset the core. This is a self clearing
14105 + * bit and the core clears this bit after all the
14106 + * necessary logic is reset in the core, which may
14107 + * take several clocks, depending on the current state
14110 + unsigned csftrst : 1;
14116 + * This union represents the bit fields of the Core Interrupt Mask
14117 + * Register (GINTMSK). Set/clear the bits using the bit fields then
14118 + * write the <i>d32</i> value to the register.
14120 +typedef union gintmsk_data
14122 + /** raw register data */
14124 + /** register bits */
14127 + unsigned wkupintr : 1;
14128 + unsigned sessreqintr : 1;
14129 + unsigned disconnect : 1;
14130 + unsigned conidstschng : 1;
14131 + unsigned reserved27 : 1;
14132 + unsigned ptxfempty : 1;
14133 + unsigned hcintr : 1;
14134 + unsigned portintr : 1;
14135 + unsigned reserved22_23 : 2;
14136 + unsigned incomplisoout : 1;
14137 + unsigned incomplisoin : 1;
14138 + unsigned outepintr : 1;
14139 + unsigned inepintr : 1;
14140 + unsigned epmismatch : 1;
14141 + unsigned reserved16 : 1;
14142 + unsigned eopframe : 1;
14143 + unsigned isooutdrop : 1;
14144 + unsigned enumdone : 1;
14145 + unsigned usbreset : 1;
14146 + unsigned usbsuspend : 1;
14147 + unsigned erlysuspend : 1;
14148 + unsigned i2cintr : 1;
14149 + unsigned reserved8 : 1;
14150 + unsigned goutnakeff : 1;
14151 + unsigned ginnakeff : 1;
14152 + unsigned nptxfempty : 1;
14153 + unsigned rxstsqlvl : 1;
14154 + unsigned sofintr : 1;
14155 + unsigned otgintr : 1;
14156 + unsigned modemismatch : 1;
14157 + unsigned reserved0 : 1;
14161 + * This union represents the bit fields of the Core Interrupt Register
14162 + * (GINTSTS). Set/clear the bits using the bit fields then write the
14163 + * <i>d32</i> value to the register.
14165 +typedef union gintsts_data
14167 + /** raw register data */
14169 +#define DWC_SOF_INTR_MASK 0x0008
14170 + /** register bits */
14173 +#define DWC_HOST_MODE 1
14174 + unsigned wkupintr : 1;
14175 + unsigned sessreqintr : 1;
14176 + unsigned disconnect : 1;
14177 + unsigned conidstschng : 1;
14178 + unsigned reserved27 : 1;
14179 + unsigned ptxfempty : 1;
14180 + unsigned hcintr : 1;
14181 + unsigned portintr : 1;
14182 + unsigned reserved22_23 : 2;
14183 + unsigned incomplisoout : 1;
14184 + unsigned incomplisoin : 1;
14185 + unsigned outepintr : 1;
14186 + unsigned inepint: 1;
14187 + unsigned epmismatch : 1;
14188 + unsigned intokenrx : 1;
14189 + unsigned eopframe : 1;
14190 + unsigned isooutdrop : 1;
14191 + unsigned enumdone : 1;
14192 + unsigned usbreset : 1;
14193 + unsigned usbsuspend : 1;
14194 + unsigned erlysuspend : 1;
14195 + unsigned i2cintr : 1;
14196 + unsigned reserved8 : 1;
14197 + unsigned goutnakeff : 1;
14198 + unsigned ginnakeff : 1;
14199 + unsigned nptxfempty : 1;
14200 + unsigned rxstsqlvl : 1;
14201 + unsigned sofintr : 1;
14202 + unsigned otgintr : 1;
14203 + unsigned modemismatch : 1;
14204 + unsigned curmode : 1;
14210 + * This union represents the bit fields in the Device Receive Status Read and
14211 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
14212 + * element then read out the bits using the <i>b</i>it elements.
14214 +typedef union device_grxsts_data {
14215 + /** raw register data */
14217 + /** register bits */
14219 + unsigned reserved : 7;
14221 +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
14222 +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
14224 +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
14225 +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
14226 +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
14227 + unsigned pktsts : 4;
14228 + unsigned dpid : 2;
14229 + unsigned bcnt : 11;
14230 + unsigned epnum : 4;
14232 +} device_grxsts_data_t;
14235 + * This union represents the bit fields in the Host Receive Status Read and
14236 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
14237 + * element then read out the bits using the <i>b</i>it elements.
14239 +typedef union host_grxsts_data {
14240 + /** raw register data */
14242 + /** register bits */
14244 + unsigned reserved31_21 : 11;
14245 +#define DWC_GRXSTS_PKTSTS_IN 0x2
14246 +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
14247 +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
14248 +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
14249 + unsigned pktsts : 4;
14250 + unsigned dpid : 2;
14251 + unsigned bcnt : 11;
14252 + unsigned chnum : 4;
14254 +} host_grxsts_data_t;
14257 + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
14258 + * GNPTXFSIZ, DPTXFSIZn). Read the register into the <i>d32</i> element then
14259 + * read out the bits using the <i>b</i>it elements.
14261 +typedef union fifosize_data {
14262 + /** raw register data */
14264 + /** register bits */
14266 + unsigned depth : 16;
14267 + unsigned startaddr : 16;
14269 +} fifosize_data_t;
14272 + * This union represents the bit fields in the Non-Periodic Transmit
14273 + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
14274 + * <i>d32</i> element then read out the bits using the <i>b</i>it
14277 +typedef union gnptxsts_data {
14278 + /** raw register data */
14280 + /** register bits */
14282 + unsigned reserved : 1;
14283 + /** Top of the Non-Periodic Transmit Request Queue
14284 + * - bits 30:27 - Channel/EP Number
14285 + * - bits 26:25 - Token Type
14286 + * - bit 24 - Terminate (Last entry for the selected
14288 + * - 2'b00 - IN/OUT
14289 + * - 2'b01 - Zero Length OUT
14290 + * - 2'b10 - PING/Complete Split
14291 + * - 2'b11 - Channel Halt
14294 + unsigned nptxqtop_chnep : 4;
14295 + unsigned nptxqtop_token : 2;
14296 + unsigned nptxqtop_terminate : 1;
14297 + unsigned nptxqspcavail : 8;
14298 + unsigned nptxfspcavail : 16;
14300 +} gnptxsts_data_t;
14303 + * This union represents the bit fields in the Transmit
14304 + * FIFO Status Register (DTXFSTS). Read the register into the
14305 + * <i>d32</i> element then read out the bits using the <i>b</i>it
14308 +typedef union dtxfsts_data /* fscz */ //*
14310 + /** raw register data */
14312 + /** register bits */
14314 + unsigned reserved : 16;
14315 + unsigned txfspcavail : 16;
14320 + * This union represents the bit fields in the I2C Control Register
14321 + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
14322 + * bits using the <i>b</i>it elements.
14324 +typedef union gi2cctl_data {
14325 + /** raw register data */
14327 + /** register bits */
14329 + unsigned bsydne : 1;
14331 + unsigned reserved : 2;
14332 + unsigned i2cdevaddr : 2;
14333 + unsigned i2csuspctl : 1;
14334 + unsigned ack : 1;
14335 + unsigned i2cen : 1;
14336 + unsigned addr : 7;
14337 + unsigned regaddr : 8;
14338 + unsigned rwdata : 8;
14343 + * This union represents the bit fields in the User HW Config1
14344 + * Register. Read the register into the <i>d32</i> element then read
14345 + * out the bits using the <i>b</i>it elements.
14347 +typedef union hwcfg1_data {
14348 + /** raw register data */
14350 + /** register bits */
14352 + unsigned ep_dir15 : 2;
14353 + unsigned ep_dir14 : 2;
14354 + unsigned ep_dir13 : 2;
14355 + unsigned ep_dir12 : 2;
14356 + unsigned ep_dir11 : 2;
14357 + unsigned ep_dir10 : 2;
14358 + unsigned ep_dir9 : 2;
14359 + unsigned ep_dir8 : 2;
14360 + unsigned ep_dir7 : 2;
14361 + unsigned ep_dir6 : 2;
14362 + unsigned ep_dir5 : 2;
14363 + unsigned ep_dir4 : 2;
14364 + unsigned ep_dir3 : 2;
14365 + unsigned ep_dir2 : 2;
14366 + unsigned ep_dir1 : 2;
14367 + unsigned ep_dir0 : 2;
14372 + * This union represents the bit fields in the User HW Config2
14373 + * Register. Read the register into the <i>d32</i> element then read
14374 + * out the bits using the <i>b</i>it elements.
14376 +typedef union hwcfg2_data
14378 + /** raw register data */
14380 + /** register bits */
14383 + unsigned reserved31 : 1;
14384 + unsigned dev_token_q_depth : 5;
14385 + unsigned host_perio_tx_q_depth : 2;
14386 + unsigned nonperio_tx_q_depth : 2;
14387 + unsigned rx_status_q_depth : 2;
14388 + unsigned dynamic_fifo : 1;
14389 + unsigned perio_ep_supported : 1;
14390 + unsigned num_host_chan : 4;
14391 + unsigned num_dev_ep : 4;
14392 + unsigned fs_phy_type : 2;
14393 +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
14394 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
14395 +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
14396 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
14397 + unsigned hs_phy_type : 2;
14398 + unsigned point2point : 1;
14399 + unsigned architecture : 2;
14400 +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
14401 +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
14402 +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
14403 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
14404 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
14405 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
14406 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
14407 + unsigned op_mode : 3;
14412 + * This union represents the bit fields in the User HW Config3
14413 + * Register. Read the register into the <i>d32</i> element then read
14414 + * out the bits using the <i>b</i>it elements.
14416 +typedef union hwcfg3_data
14418 + /** raw register data */
14420 + /** register bits */
14423 + unsigned dfifo_depth : 16;
14424 + unsigned reserved15_13 : 3;
14425 + unsigned ahb_phy_clock_synch : 1;
14426 + unsigned synch_reset_type : 1;
14427 + unsigned optional_features : 1;
14428 + unsigned vendor_ctrl_if : 1;
14429 + unsigned i2c : 1;
14430 + unsigned otg_func : 1;
14431 + unsigned packet_size_cntr_width : 3;
14432 + unsigned xfer_size_cntr_width : 4;
14437 + * This union represents the bit fields in the User HW Config4
14438 + * Register. Read the register into the <i>d32</i> element then read
14439 + * out the bits using the <i>b</i>it elements.
14441 +typedef union hwcfg4_data
14443 + /** raw register data */
14445 + /** register bits */
14447 +unsigned reserved31_30 : 2; /* fscz */
14448 + unsigned num_in_eps : 4;
14449 + unsigned ded_fifo_en : 1;
14451 + unsigned session_end_filt_en : 1;
14452 + unsigned b_valid_filt_en : 1;
14453 + unsigned a_valid_filt_en : 1;
14454 + unsigned vbus_valid_filt_en : 1;
14455 + unsigned iddig_filt_en : 1;
14456 + unsigned num_dev_mode_ctrl_ep : 4;
14457 + unsigned utmi_phy_data_width : 2;
14458 + unsigned min_ahb_freq : 9;
14459 + unsigned power_optimiz : 1;
14460 + unsigned num_dev_perio_in_ep : 4;
14464 +////////////////////////////////////////////
14465 +// Device Registers
14467 + * Device Global Registers. <i>Offsets 800h-BFFh</i>
14469 + * The following structures define the size and relative field offsets
14470 + * for the Device Mode Registers.
14472 + * <i>These registers are visible only in Device mode and must not be
14473 + * accessed in Host mode, as the results are unknown.</i>
14475 +typedef struct dwc_otg_dev_global_regs
14477 + /** Device Configuration Register. <i>Offset 800h</i> */
14478 + volatile uint32_t dcfg;
14479 + /** Device Control Register. <i>Offset: 804h</i> */
14480 + volatile uint32_t dctl;
14481 + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
14482 + volatile uint32_t dsts;
14483 + /** Reserved. <i>Offset: 80Ch</i> */
14485 + /** Device IN Endpoint Common Interrupt Mask
14486 + * Register. <i>Offset: 810h</i> */
14487 + volatile uint32_t diepmsk;
14488 + /** Device OUT Endpoint Common Interrupt Mask
14489 + * Register. <i>Offset: 814h</i> */
14490 + volatile uint32_t doepmsk;
14491 + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
14492 + volatile uint32_t daint;
14493 + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
14495 + volatile uint32_t daintmsk;
14496 + /** Device IN Token Queue Read Register-1 (Read Only).
14497 + * <i>Offset: 820h</i> */
14498 + volatile uint32_t dtknqr1;
14499 + /** Device IN Token Queue Read Register-2 (Read Only).
14500 + * <i>Offset: 824h</i> */
14501 + volatile uint32_t dtknqr2;
14502 + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
14503 + volatile uint32_t dvbusdis;
14504 + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
14505 + volatile uint32_t dvbuspulse;
14506 + /** Device IN Token Queue Read Register-3 (Read Only).
14507 + * Device Thresholding control register (Read/Write)
14508 + * <i>Offset: 830h</i> */
14509 + volatile uint32_t dtknqr3_dthrctl;
14510 + /** Device IN Token Queue Read Register-4 (Read Only). /
14511 + * Device IN EPs empty Inr. Mask Register (Read/Write)
14512 + * <i>Offset: 834h</i> */
14513 + volatile uint32_t dtknqr4_fifoemptymsk;
14514 +} dwc_otg_device_global_regs_t;
14517 + * This union represents the bit fields in the Device Configuration
14518 + * Register. Read the register into the <i>d32</i> member then
14519 + * set/clear the bits using the <i>b</i>it elements. Write the
14520 + * <i>d32</i> member to the dcfg register.
14522 +typedef union dcfg_data
14524 + /** raw register data */
14526 + /** register bits */
14528 + unsigned reserved31_23 : 9;
14529 + /** In Endpoint Mis-match count */
14530 + unsigned epmscnt : 5;
14531 + unsigned reserved13_17 : 5;
14532 + /** Periodic Frame Interval */
14533 +#define DWC_DCFG_FRAME_INTERVAL_80 0
14534 +#define DWC_DCFG_FRAME_INTERVAL_85 1
14535 +#define DWC_DCFG_FRAME_INTERVAL_90 2
14536 +#define DWC_DCFG_FRAME_INTERVAL_95 3
14537 + unsigned perfrint : 2;
14538 + /** Device Addresses */
14539 + unsigned devaddr : 7;
14540 + unsigned reserved3 : 1;
14541 + /** Non Zero Length Status OUT Handshake */
14542 +#define DWC_DCFG_SEND_STALL 1
14543 + unsigned nzstsouthshk : 1;
14544 + /** Device Speed */
14545 + unsigned devspd : 2;
14550 + * This union represents the bit fields in the Device Control
14551 + * Register. Read the register into the <i>d32</i> member then
14552 + * set/clear the bits using the <i>b</i>it elements.
14554 +typedef union dctl_data
14556 + /** raw register data */
14558 + /** register bits */
14560 + unsigned reserved : 20;
14561 + /** Power-On Programming Done */
14562 + unsigned pwronprgdone : 1;
14563 + /** Clear Global OUT NAK */
14564 + unsigned cgoutnak : 1;
14565 + /** Set Global OUT NAK */
14566 + unsigned sgoutnak : 1;
14567 + /** Clear Global Non-Periodic IN NAK */
14568 + unsigned cgnpinnak : 1;
14569 + /** Set Global Non-Periodic IN NAK */
14570 + unsigned sgnpinnak : 1;
14571 + /** Test Control */
14572 + unsigned tstctl : 3;
14573 + /** Global OUT NAK Status */
14574 + unsigned goutnaksts : 1;
14575 + /** Global Non-Periodic IN NAK Status */
14576 + unsigned gnpinnaksts : 1;
14577 + /** Soft Disconnect */
14578 + unsigned sftdiscon : 1;
14579 + /** Remote Wakeup */
14580 + unsigned rmtwkupsig : 1;
14585 + * This union represents the bit fields in the Device Status
14586 + * Register. Read the register into the <i>d32</i> member then
14587 + * set/clear the bits using the <i>b</i>it elements.
14589 +typedef union dsts_data
14591 + /** raw register data */
14593 + /** register bits */
14595 + unsigned reserved22_31 : 10;
14596 + /** Frame or Microframe Number of the received SOF */
14597 + unsigned soffn : 14;
14598 + unsigned reserved4_7: 4;
14599 + /** Erratic Error */
14600 + unsigned errticerr : 1;
14601 + /** Enumerated Speed */
14602 +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
14603 +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
14604 +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
14605 +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
14606 + unsigned enumspd : 2;
14607 + /** Suspend Status */
14608 + unsigned suspsts : 1;
14614 + * This union represents the bit fields in the Device IN EP Interrupt
14615 + * Register and the Device IN EP Common Mask Register.
14617 + * - Read the register into the <i>d32</i> member then set/clear the
14618 + * bits using the <i>b</i>it elements.
14620 +typedef union diepint_data
14622 + /** raw register data */
14624 + /** register bits */
14626 + unsigned reserved07_31 : 23;
14627 + unsigned txfifoundrn : 1;
14628 + /** IN Endpoint HAK Effective mask */
14629 + unsigned emptyintr : 1;
14630 + /** IN Endpoint NAK Effective mask */
14631 + unsigned inepnakeff : 1;
14632 + /** IN Token Received with EP mismatch mask */
14633 + unsigned intknepmis : 1;
14634 + /** IN Token received with TxF Empty mask */
14635 + unsigned intktxfemp : 1;
14636 + /** TimeOUT Handshake mask (non-ISOC EPs) */
14637 + unsigned timeout : 1;
14638 + /** AHB Error mask */
14639 + unsigned ahberr : 1;
14640 + /** Endpoint disable mask */
14641 + unsigned epdisabled : 1;
14642 + /** Transfer complete mask */
14643 + unsigned xfercompl : 1;
14647 + * This union represents the bit fields in the Device IN EP Common
14648 + * Interrupt Mask Register.
14650 +typedef union diepint_data diepmsk_data_t;
14653 + * This union represents the bit fields in the Device OUT EP Interrupt
14654 + * Registerand Device OUT EP Common Interrupt Mask Register.
14656 + * - Read the register into the <i>d32</i> member then set/clear the
14657 + * bits using the <i>b</i>it elements.
14659 +typedef union doepint_data
14661 + /** raw register data */
14663 + /** register bits */
14665 + unsigned reserved04_31 : 27;
14666 + /** OUT Token Received when Endpoint Disabled */
14667 + unsigned outtknepdis : 1;
14668 + /** Setup Phase Done (contorl EPs) */
14669 + unsigned setup : 1;
14671 + unsigned ahberr : 1;
14672 + /** Endpoint disable */
14673 + unsigned epdisabled : 1;
14674 + /** Transfer complete */
14675 + unsigned xfercompl : 1;
14679 + * This union represents the bit fields in the Device OUT EP Common
14680 + * Interrupt Mask Register.
14682 +typedef union doepint_data doepmsk_data_t;
14686 + * This union represents the bit fields in the Device All EP Interrupt
14687 + * and Mask Registers.
14688 + * - Read the register into the <i>d32</i> member then set/clear the
14689 + * bits using the <i>b</i>it elements.
14691 +typedef union daint_data
14693 + /** raw register data */
14695 + /** register bits */
14697 + /** OUT Endpoint bits */
14698 + unsigned out : 16;
14699 + /** IN Endpoint bits */
14700 + unsigned in : 16;
14703 + /** OUT Endpoint bits */
14704 + unsigned outep15 : 1;
14705 + unsigned outep14 : 1;
14706 + unsigned outep13 : 1;
14707 + unsigned outep12 : 1;
14708 + unsigned outep11 : 1;
14709 + unsigned outep10 : 1;
14710 + unsigned outep9 : 1;
14711 + unsigned outep8 : 1;
14712 + unsigned outep7 : 1;
14713 + unsigned outep6 : 1;
14714 + unsigned outep5 : 1;
14715 + unsigned outep4 : 1;
14716 + unsigned outep3 : 1;
14717 + unsigned outep2 : 1;
14718 + unsigned outep1 : 1;
14719 + unsigned outep0 : 1;
14720 + /** IN Endpoint bits */
14721 + unsigned inep15 : 1;
14722 + unsigned inep14 : 1;
14723 + unsigned inep13 : 1;
14724 + unsigned inep12 : 1;
14725 + unsigned inep11 : 1;
14726 + unsigned inep10 : 1;
14727 + unsigned inep9 : 1;
14728 + unsigned inep8 : 1;
14729 + unsigned inep7 : 1;
14730 + unsigned inep6 : 1;
14731 + unsigned inep5 : 1;
14732 + unsigned inep4 : 1;
14733 + unsigned inep3 : 1;
14734 + unsigned inep2 : 1;
14735 + unsigned inep1 : 1;
14736 + unsigned inep0 : 1;
14741 + * This union represents the bit fields in the Device IN Token Queue
14742 + * Read Registers.
14743 + * - Read the register into the <i>d32</i> member.
14744 + * - READ-ONLY Register
14746 +typedef union dtknq1_data
14748 + /** raw register data */
14750 + /** register bits */
14752 + /** EP Numbers of IN Tokens 0 ... 4 */
14753 + unsigned epnums0_5 : 24;
14754 + /** write pointer has wrapped. */
14755 + unsigned wrap_bit : 1;
14757 + unsigned reserved05_06 : 2;
14758 + /** In Token Queue Write Pointer */
14759 + unsigned intknwptr : 5;
14764 + * This union represents Threshold control Register
14765 + * - Read and write the register into the <i>d32</i> member.
14766 + * - READ-WRITABLE Register
14768 +typedef union dthrctl_data //* /*fscz */
14770 + /** raw register data */
14772 + /** register bits */
14775 + unsigned reserved26_31 : 6;
14776 + /** Rx Thr. Length */
14777 + unsigned rx_thr_len : 9;
14778 + /** Rx Thr. Enable */
14779 + unsigned rx_thr_en : 1;
14781 + unsigned reserved11_15 : 5;
14782 + /** Tx Thr. Length */
14783 + unsigned tx_thr_len : 9;
14784 + /** ISO Tx Thr. Enable */
14785 + unsigned iso_thr_en : 1;
14786 + /** non ISO Tx Thr. Enable */
14787 + unsigned non_iso_thr_en : 1;
14793 + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
14796 + * There will be one set of endpoint registers per logical endpoint
14799 + * <i>These registers are visible only in Device mode and must not be
14800 + * accessed in Host mode, as the results are unknown.</i>
14802 +typedef struct dwc_otg_dev_in_ep_regs
14804 + /** Device IN Endpoint Control Register. <i>Offset:900h +
14805 + * (ep_num * 20h) + 00h</i> */
14806 + volatile uint32_t diepctl;
14807 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
14808 + uint32_t reserved04;
14809 + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
14810 + * (ep_num * 20h) + 08h</i> */
14811 + volatile uint32_t diepint;
14812 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
14813 + uint32_t reserved0C;
14814 + /** Device IN Endpoint Transfer Size
14815 + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
14816 + volatile uint32_t dieptsiz;
14817 + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
14818 + * (ep_num * 20h) + 14h</i> */
14819 + volatile uint32_t diepdma;
14820 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 18h - 900h +
14821 + * (ep_num * 20h) + 1Ch</i>*/
14822 + volatile uint32_t dtxfsts;
14823 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 1Ch - 900h +
14824 + * (ep_num * 20h) + 1Ch</i>*/
14825 + uint32_t reserved18;
14826 +} dwc_otg_dev_in_ep_regs_t;
14829 + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
14832 + * There will be one set of endpoint registers per logical endpoint
14835 + * <i>These registers are visible only in Device mode and must not be
14836 + * accessed in Host mode, as the results are unknown.</i>
14838 +typedef struct dwc_otg_dev_out_ep_regs
14840 + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
14841 + * (ep_num * 20h) + 00h</i> */
14842 + volatile uint32_t doepctl;
14843 + /** Device OUT Endpoint Frame number Register. <i>Offset:
14844 + * B00h + (ep_num * 20h) + 04h</i> */
14845 + volatile uint32_t doepfn;
14846 + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
14847 + * (ep_num * 20h) + 08h</i> */
14848 + volatile uint32_t doepint;
14849 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
14850 + uint32_t reserved0C;
14851 + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
14852 + * B00h + (ep_num * 20h) + 10h</i> */
14853 + volatile uint32_t doeptsiz;
14854 + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
14855 + * + (ep_num * 20h) + 14h</i> */
14856 + volatile uint32_t doepdma;
14857 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 18h - B00h +
14858 + * (ep_num * 20h) + 1Ch</i> */
14859 + uint32_t unused[2];
14860 +} dwc_otg_dev_out_ep_regs_t;
14863 + * This union represents the bit fields in the Device EP Control
14864 + * Register. Read the register into the <i>d32</i> member then
14865 + * set/clear the bits using the <i>b</i>it elements.
14867 +typedef union depctl_data
14869 + /** raw register data */
14871 + /** register bits */
14873 + /** Endpoint Enable */
14874 + unsigned epena : 1;
14875 + /** Endpoint Disable */
14876 + unsigned epdis : 1;
14877 + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
14878 + * Writing to this field sets the Endpoint DPID (DPID)
14879 + * field in this register to DATA1 Set Odd
14880 + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
14881 + * Writing to this field sets the Even/Odd
14882 + * (micro)frame (EO_FrNum) field to odd (micro) frame.
14884 + unsigned setd1pid : 1;
14885 + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
14886 + * Writing to this field sets the Endpoint DPID (DPID)
14887 + * field in this register to DATA0. Set Even
14888 + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
14889 + * Writing to this field sets the Even/Odd
14890 + * (micro)frame (EO_FrNum) field to even (micro)
14893 + unsigned setd0pid : 1;
14895 + unsigned snak : 1;
14897 + unsigned cnak : 1;
14898 + /** Tx Fifo Number
14900 + * OUT EPn/OUT EP0 - reserved */
14901 + unsigned txfnum : 4;
14902 + /** Stall Handshake */
14903 + unsigned stall : 1;
14905 + * OUT EPn/OUT EP0
14906 + * IN EPn/IN EP0 - reserved */
14907 + unsigned snp : 1;
14908 + /** Endpoint Type
14910 + * 2'b01: Isochronous
14912 + * 2'b11: Interrupt */
14913 + unsigned eptype : 2;
14914 + /** NAK Status */
14915 + unsigned naksts : 1;
14916 + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
14917 + * This field contains the PID of the packet going to
14918 + * be received or transmitted on this endpoint. The
14919 + * application should program the PID of the first
14920 + * packet going to be received or transmitted on this
14921 + * endpoint , after the endpoint is
14922 + * activated. Application use the SetD1PID and
14923 + * SetD0PID fields of this register to program either
14926 + * The encoding for this field is
14930 + unsigned dpid : 1;
14931 + /** USB Active Endpoint */
14932 + unsigned usbactep : 1;
14933 + /** Next Endpoint
14935 + * OUT EPn/OUT EP0 - reserved */
14936 + unsigned nextep : 4;
14937 + /** Maximum Packet Size
14939 + * IN/OUT EP0 - 2 bits
14940 + * 2'b00: 64 Bytes
14944 +#define DWC_DEP0CTL_MPS_64 0
14945 +#define DWC_DEP0CTL_MPS_32 1
14946 +#define DWC_DEP0CTL_MPS_16 2
14947 +#define DWC_DEP0CTL_MPS_8 3
14948 + unsigned mps : 11;
14953 + * This union represents the bit fields in the Device EP Transfer
14954 + * Size Register. Read the register into the <i>d32</i> member then
14955 + * set/clear the bits using the <i>b</i>it elements.
14957 +typedef union deptsiz_data
14959 + /** raw register data */
14961 + /** register bits */
14963 + unsigned reserved : 1;
14964 + /** Multi Count - Periodic IN endpoints */
14966 + /** Packet Count */
14967 + unsigned pktcnt : 10;
14968 + /** Transfer size */
14969 + unsigned xfersize : 19;
14974 + * This union represents the bit fields in the Device EP 0 Transfer
14975 + * Size Register. Read the register into the <i>d32</i> member then
14976 + * set/clear the bits using the <i>b</i>it elements.
14978 +typedef union deptsiz0_data
14980 + /** raw register data */
14982 + /** register bits */
14984 + unsigned reserved31 : 1;
14985 + /**Setup Packet Count (DOEPTSIZ0 Only) */
14986 + unsigned supcnt : 2;
14988 + unsigned reserved28_20 : 9;
14989 + /** Packet Count */
14990 + unsigned pktcnt : 1;
14992 + unsigned reserved18_7 : 12;
14993 + /** Transfer size */
14994 + unsigned xfersize : 7;
14996 +} deptsiz0_data_t;
14999 +/** Maximum number of Periodic FIFOs */
15000 +#define MAX_PERIO_FIFOS 15
15001 +/** Maximum number of TX FIFOs */
15002 +#define MAX_TX_FIFOS 15
15003 +/** Maximum number of Endpoints/HostChannels */
15004 +#define MAX_EPS_CHANNELS 16
15005 +//#define MAX_EPS_CHANNELS 4
15008 + * The dwc_otg_dev_if structure contains information needed to manage
15009 + * the DWC_otg controller acting in device mode. It represents the
15010 + * programming view of the device-specific aspects of the controller.
15012 +typedef struct dwc_otg_dev_if {
15013 + /** Pointer to device Global registers.
15014 + * Device Global Registers starting at offset 800h
15016 + dwc_otg_device_global_regs_t *dev_global_regs;
15017 +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
15020 + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
15022 + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
15023 +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
15024 +#define DWC_EP_REG_OFFSET 0x20
15026 + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
15027 + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
15028 +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
15030 + /* Device configuration information*/
15031 + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
15032 + //uint8_t num_eps; /**< Number of EPs range: 0-16 (includes EP0) */
15033 + //uint8_t num_perio_eps; /**< # of Periodic EP range: 0-15 */
15035 + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
15036 + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
15038 + /** Size of periodic FIFOs (Bytes) */
15039 + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
15041 + /** Size of Tx FIFOs (Bytes) */
15042 + uint16_t tx_fifo_size[MAX_TX_FIFOS];
15044 + /** Thresholding enable flags and length varaiables **/
15045 + uint16_t rx_thr_en;
15046 + uint16_t iso_tx_thr_en;
15047 + uint16_t non_iso_tx_thr_en;
15049 + uint16_t rx_thr_length;
15050 + uint16_t tx_thr_length;
15051 +} dwc_otg_dev_if_t;
15054 + * This union represents the bit fields in the Power and Clock Gating Control
15055 + * Register. Read the register into the <i>d32</i> member then set/clear the
15056 + * bits using the <i>b</i>it elements.
15058 +typedef union pcgcctl_data
15060 + /** raw register data */
15063 + /** register bits */
15065 + unsigned reserved31_05 : 27;
15066 + /** PHY Suspended */
15067 + unsigned physuspended : 1;
15068 + /** Reset Power Down Modules */
15069 + unsigned rstpdwnmodule : 1;
15070 + /** Power Clamp */
15071 + unsigned pwrclmp : 1;
15073 + unsigned gatehclk : 1;
15075 + unsigned stoppclk : 1;
15079 +/////////////////////////////////////////////////
15080 +// Host Mode Register Structures
15083 + * The Host Global Registers structure defines the size and relative
15084 + * field offsets for the Host Mode Global Registers. Host Global
15085 + * Registers offsets 400h-7FFh.
15087 +typedef struct dwc_otg_host_global_regs
15089 + /** Host Configuration Register. <i>Offset: 400h</i> */
15090 + volatile uint32_t hcfg;
15091 + /** Host Frame Interval Register. <i>Offset: 404h</i> */
15092 + volatile uint32_t hfir;
15093 + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
15094 + volatile uint32_t hfnum;
15095 + /** Reserved. <i>Offset: 40Ch</i> */
15096 + uint32_t reserved40C;
15097 + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
15098 + volatile uint32_t hptxsts;
15099 + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
15100 + volatile uint32_t haint;
15101 + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
15102 + volatile uint32_t haintmsk;
15103 +} dwc_otg_host_global_regs_t;
15106 + * This union represents the bit fields in the Host Configuration Register.
15107 + * Read the register into the <i>d32</i> member then set/clear the bits using
15108 + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
15110 +typedef union hcfg_data
15112 + /** raw register data */
15115 + /** register bits */
15118 + //unsigned reserved31_03 : 29;
15119 + /** FS/LS Only Support */
15120 + unsigned fslssupp : 1;
15121 + /** FS/LS Phy Clock Select */
15122 +#define DWC_HCFG_30_60_MHZ 0
15123 +#define DWC_HCFG_48_MHZ 1
15124 +#define DWC_HCFG_6_MHZ 2
15125 + unsigned fslspclksel : 2;
15130 + * This union represents the bit fields in the Host Frame Remaing/Number
15133 +typedef union hfir_data
15135 + /** raw register data */
15138 + /** register bits */
15140 + unsigned reserved : 16;
15141 + unsigned frint : 16;
15146 + * This union represents the bit fields in the Host Frame Remaing/Number
15149 +typedef union hfnum_data
15151 + /** raw register data */
15154 + /** register bits */
15156 + unsigned frrem : 16;
15157 +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
15158 + unsigned frnum : 16;
15162 +typedef union hptxsts_data
15164 + /** raw register data */
15167 + /** register bits */
15169 + /** Top of the Periodic Transmit Request Queue
15170 + * - bit 24 - Terminate (last entry for the selected channel)
15171 + * - bits 26:25 - Token Type
15172 + * - 2'b00 - Zero length
15174 + * - 2'b10 - Disable
15175 + * - bits 30:27 - Channel Number
15176 + * - bit 31 - Odd/even microframe
15178 + unsigned ptxqtop_odd : 1;
15179 + unsigned ptxqtop_chnum : 4;
15180 + unsigned ptxqtop_token : 2;
15181 + unsigned ptxqtop_terminate : 1;
15182 + unsigned ptxqspcavail : 8;
15183 + unsigned ptxfspcavail : 16;
15188 + * This union represents the bit fields in the Host Port Control and Status
15189 + * Register. Read the register into the <i>d32</i> member then set/clear the
15190 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15191 + * hprt0 register.
15193 +typedef union hprt0_data
15195 + /** raw register data */
15197 + /** register bits */
15199 + unsigned reserved19_31 : 13;
15200 +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
15201 +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
15202 +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
15203 + unsigned prtspd : 2;
15204 + unsigned prttstctl : 4;
15205 + unsigned prtpwr : 1;
15206 + unsigned prtlnsts : 2;
15207 + unsigned reserved9 : 1;
15208 + unsigned prtrst : 1;
15209 + unsigned prtsusp : 1;
15210 + unsigned prtres : 1;
15211 + unsigned prtovrcurrchng : 1;
15212 + unsigned prtovrcurract : 1;
15213 + unsigned prtenchng : 1;
15214 + unsigned prtena : 1;
15215 + unsigned prtconndet : 1;
15216 + unsigned prtconnsts : 1;
15221 + * This union represents the bit fields in the Host All Interrupt
15224 +typedef union haint_data
15226 + /** raw register data */
15228 + /** register bits */
15230 + unsigned reserved : 16;
15231 + unsigned ch15 : 1;
15232 + unsigned ch14 : 1;
15233 + unsigned ch13 : 1;
15234 + unsigned ch12 : 1;
15235 + unsigned ch11 : 1;
15236 + unsigned ch10 : 1;
15237 + unsigned ch9 : 1;
15238 + unsigned ch8 : 1;
15239 + unsigned ch7 : 1;
15240 + unsigned ch6 : 1;
15241 + unsigned ch5 : 1;
15242 + unsigned ch4 : 1;
15243 + unsigned ch3 : 1;
15244 + unsigned ch2 : 1;
15245 + unsigned ch1 : 1;
15246 + unsigned ch0 : 1;
15249 + unsigned reserved : 16;
15250 + unsigned chint : 16;
15255 + * This union represents the bit fields in the Host All Interrupt
15258 +typedef union haintmsk_data
15260 + /** raw register data */
15262 + /** register bits */
15264 + unsigned reserved : 16;
15265 + unsigned ch15 : 1;
15266 + unsigned ch14 : 1;
15267 + unsigned ch13 : 1;
15268 + unsigned ch12 : 1;
15269 + unsigned ch11 : 1;
15270 + unsigned ch10 : 1;
15271 + unsigned ch9 : 1;
15272 + unsigned ch8 : 1;
15273 + unsigned ch7 : 1;
15274 + unsigned ch6 : 1;
15275 + unsigned ch5 : 1;
15276 + unsigned ch4 : 1;
15277 + unsigned ch3 : 1;
15278 + unsigned ch2 : 1;
15279 + unsigned ch1 : 1;
15280 + unsigned ch0 : 1;
15283 + unsigned reserved : 16;
15284 + unsigned chint : 16;
15286 +} haintmsk_data_t;
15289 + * Host Channel Specific Registers. <i>500h-5FCh</i>
15291 +typedef struct dwc_otg_hc_regs
15293 + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
15294 + volatile uint32_t hcchar;
15295 + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
15296 + volatile uint32_t hcsplt;
15297 + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
15298 + volatile uint32_t hcint;
15299 + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
15300 + volatile uint32_t hcintmsk;
15301 + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
15302 + volatile uint32_t hctsiz;
15303 + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
15304 + volatile uint32_t hcdma;
15305 + /** Reserved. <i>Offset: 500h + (chan_num * 20h) + 18h - 500h + (chan_num * 20h) + 1Ch</i> */
15306 + uint32_t reserved[2];
15307 +} dwc_otg_hc_regs_t;
15310 + * This union represents the bit fields in the Host Channel Characteristics
15311 + * Register. Read the register into the <i>d32</i> member then set/clear the
15312 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15313 + * hcchar register.
15315 +typedef union hcchar_data
15317 + /** raw register data */
15320 + /** register bits */
15322 + /** Channel enable */
15323 + unsigned chen : 1;
15324 + /** Channel disable */
15325 + unsigned chdis : 1;
15327 + * Frame to transmit periodic transaction.
15328 + * 0: even, 1: odd
15330 + unsigned oddfrm : 1;
15331 + /** Device address */
15332 + unsigned devaddr : 7;
15333 + /** Packets per frame for periodic transfers. 0 is reserved. */
15334 + unsigned multicnt : 2;
15335 + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
15336 + unsigned eptype : 2;
15337 + /** 0: Full/high speed device, 1: Low speed device */
15338 + unsigned lspddev : 1;
15339 + unsigned reserved : 1;
15340 + /** 0: OUT, 1: IN */
15341 + unsigned epdir : 1;
15342 + /** Endpoint number */
15343 + unsigned epnum : 4;
15344 + /** Maximum packet size in bytes */
15345 + unsigned mps : 11;
15349 +typedef union hcsplt_data
15351 + /** raw register data */
15354 + /** register bits */
15356 + /** Split Enble */
15357 + unsigned spltena : 1;
15359 + unsigned reserved : 14;
15360 + /** Do Complete Split */
15361 + unsigned compsplt : 1;
15362 + /** Transaction Position */
15363 +#define DWC_HCSPLIT_XACTPOS_MID 0
15364 +#define DWC_HCSPLIT_XACTPOS_END 1
15365 +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
15366 +#define DWC_HCSPLIT_XACTPOS_ALL 3
15367 + unsigned xactpos : 2;
15368 + /** Hub Address */
15369 + unsigned hubaddr : 7;
15370 + /** Port Address */
15371 + unsigned prtaddr : 7;
15377 + * This union represents the bit fields in the Host All Interrupt
15380 +typedef union hcint_data
15382 + /** raw register data */
15384 + /** register bits */
15387 + unsigned reserved : 21;
15388 + /** Data Toggle Error */
15389 + unsigned datatglerr : 1;
15390 + /** Frame Overrun */
15391 + unsigned frmovrun : 1;
15392 + /** Babble Error */
15393 + unsigned bblerr : 1;
15394 + /** Transaction Err */
15395 + unsigned xacterr : 1;
15396 + /** NYET Response Received */
15397 + unsigned nyet : 1;
15398 + /** ACK Response Received */
15399 + unsigned ack : 1;
15400 + /** NAK Response Received */
15401 + unsigned nak : 1;
15402 + /** STALL Response Received */
15403 + unsigned stall : 1;
15405 + unsigned ahberr : 1;
15406 + /** Channel Halted */
15407 + unsigned chhltd : 1;
15408 + /** Transfer Complete */
15409 + unsigned xfercomp : 1;
15414 + * This union represents the bit fields in the Host Channel Transfer Size
15415 + * Register. Read the register into the <i>d32</i> member then set/clear the
15416 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15417 + * hcchar register.
15419 +typedef union hctsiz_data
15421 + /** raw register data */
15424 + /** register bits */
15426 + /** Do PING protocol when 1 */
15427 + unsigned dopng : 1;
15429 + * Packet ID for next data packet
15433 + * 3: MDATA (non-Control), SETUP (Control)
15435 +#define DWC_HCTSIZ_DATA0 0
15436 +#define DWC_HCTSIZ_DATA1 2
15437 +#define DWC_HCTSIZ_DATA2 1
15438 +#define DWC_HCTSIZ_MDATA 3
15439 +#define DWC_HCTSIZ_SETUP 3
15440 + unsigned pid : 2;
15441 + /** Data packets to transfer */
15442 + unsigned pktcnt : 10;
15443 + /** Total transfer size in bytes */
15444 + unsigned xfersize : 19;
15449 + * This union represents the bit fields in the Host Channel Interrupt Mask
15450 + * Register. Read the register into the <i>d32</i> member then set/clear the
15451 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15452 + * hcintmsk register.
15454 +typedef union hcintmsk_data
15456 + /** raw register data */
15459 + /** register bits */
15461 + unsigned reserved : 21;
15462 + unsigned datatglerr : 1;
15463 + unsigned frmovrun : 1;
15464 + unsigned bblerr : 1;
15465 + unsigned xacterr : 1;
15466 + unsigned nyet : 1;
15467 + unsigned ack : 1;
15468 + unsigned nak : 1;
15469 + unsigned stall : 1;
15470 + unsigned ahberr : 1;
15471 + unsigned chhltd : 1;
15472 + unsigned xfercompl : 1;
15474 +} hcintmsk_data_t;
15476 +/** OTG Host Interface Structure.
15478 + * The OTG Host Interface Structure structure contains information
15479 + * needed to manage the DWC_otg controller acting in host mode. It
15480 + * represents the programming view of the host-specific aspects of the
15483 +typedef struct dwc_otg_host_if {
15484 + /** Host Global Registers starting at offset 400h.*/
15485 + dwc_otg_host_global_regs_t *host_global_regs;
15486 +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
15488 + /** Host Port 0 Control and Status Register */
15489 + volatile uint32_t *hprt0;
15490 +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
15493 + /** Host Channel Specific Registers at offsets 500h-5FCh. */
15494 + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
15495 +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
15496 +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
15499 + /* Host configuration information */
15500 + /** Number of Host Channels (range: 1-16) */
15501 + uint8_t num_host_channels;
15502 + /** Periodic EPs supported (0: no, 1: yes) */
15503 + uint8_t perio_eps_supported;
15504 + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
15505 + uint16_t perio_tx_fifo_size;
15507 +} dwc_otg_host_if_t;
15510 --- a/arch/mips/lantiq/xway/Makefile
15511 +++ b/arch/mips/lantiq/xway/Makefile
15513 obj-$(CONFIG_LANTIQ_MACH_EASY50712) += mach-easy50712.o
15514 obj-$(CONFIG_LANTIQ_MACH_EASY50601) += mach-easy50601.o
15515 obj-$(CONFIG_LANTIQ_MACH_ARV45XX) += mach-arv45xx.o
15516 +obj-y += dev-dwc_otg.o
15518 +++ b/arch/mips/lantiq/xway/dev-dwc_otg.c
15521 + * This program is free software; you can redistribute it and/or modify
15522 + * it under the terms of the GNU General Public License as published by
15523 + * the Free Software Foundation; either version 2 of the License, or
15524 + * (at your option) any later version.
15526 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
15529 +#include <linux/init.h>
15530 +#include <linux/module.h>
15531 +#include <linux/types.h>
15532 +#include <linux/string.h>
15533 +#include <linux/mtd/physmap.h>
15534 +#include <linux/kernel.h>
15535 +#include <linux/reboot.h>
15536 +#include <linux/platform_device.h>
15537 +#include <linux/leds.h>
15538 +#include <linux/etherdevice.h>
15539 +#include <linux/reboot.h>
15540 +#include <linux/time.h>
15541 +#include <linux/io.h>
15542 +#include <linux/gpio.h>
15543 +#include <linux/leds.h>
15545 +#include <asm/bootinfo.h>
15546 +#include <asm/irq.h>
15548 +#include <lantiq_soc.h>
15549 +#include <lantiq_irq.h>
15550 +#include <lantiq_platform.h>
15552 +#define LTQ_USB_IOMEM_BASE 0x1e101000
15553 +#define LTQ_USB_IOMEM_SIZE 0x00001000
15555 +static struct resource resources[] =
15558 + .name = "dwc_otg_membase",
15559 + .start = LTQ_USB_IOMEM_BASE,
15560 + .end = LTQ_USB_IOMEM_BASE + LTQ_USB_IOMEM_SIZE - 1,
15561 + .flags = IORESOURCE_MEM,
15564 + .name = "dwc_otg_irq",
15565 + .start = LTQ_USB_INT,
15566 + .flags = IORESOURCE_IRQ,
15570 +static u64 dwc_dmamask = (u32)0x1fffffff;
15572 +static struct platform_device platform_dev = {
15573 + .name = "dwc_otg",
15575 + .dma_mask = &dwc_dmamask,
15577 + .resource = resources,
15578 + .num_resources = ARRAY_SIZE(resources),
15582 +xway_register_dwc(int pin)
15584 + ltq_enable_irq(resources[1].start);
15585 + platform_dev.dev.platform_data = (void*) pin;
15586 + return platform_device_register(&platform_dev);
15589 +++ b/arch/mips/lantiq/xway/dev-dwc_otg.h
15592 + * This program is free software; you can redistribute it and/or modify
15593 + * it under the terms of the GNU General Public License as published by
15594 + * the Free Software Foundation; either version 2 of the License, or
15595 + * (at your option) any later version.
15597 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
15600 +#ifndef _LTQ_DEV_DWC_H__
15601 +#define _LTQ_DEV_DWC_H__
15603 +#include <lantiq_platform.h>
15605 +extern void __init xway_register_dwc(int pin);
15608 --- a/drivers/usb/core/hub.c
15609 +++ b/drivers/usb/core/hub.c
15610 @@ -2704,11 +2704,11 @@
15611 udev->ttport = hdev->ttport;
15612 } else if (udev->speed != USB_SPEED_HIGH
15613 && hdev->speed == USB_SPEED_HIGH) {
15614 - if (!hub->tt.hub) {
15615 +/* if (!hub->tt.hub) {
15616 dev_err(&udev->dev, "parent hub has no TT\n");
15621 udev->tt = &hub->tt;
15622 udev->ttport = port1;