1 From ffd7924fcc69ff146d62f131d72ef18575bf0227 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Fri, 30 Sep 2011 14:37:36 +0200
4 Subject: [PATCH 18/24] MIPS: lantiq: adds dwc_otg
7 drivers/usb/Kconfig | 2 +
8 drivers/usb/Makefile | 2 +
9 drivers/usb/core/hub.c | 4 +-
10 drivers/usb/dwc_otg/Kconfig | 37 +
11 drivers/usb/dwc_otg/Makefile | 39 +
12 drivers/usb/dwc_otg/dwc_otg_attr.c | 802 ++++++++
13 drivers/usb/dwc_otg/dwc_otg_attr.h | 67 +
14 drivers/usb/dwc_otg/dwc_otg_cil.c | 3025 +++++++++++++++++++++++++++++++
15 drivers/usb/dwc_otg/dwc_otg_cil.h | 911 ++++++++++
16 drivers/usb/dwc_otg/dwc_otg_cil_ifx.h | 58 +
17 drivers/usb/dwc_otg/dwc_otg_cil_intr.c | 708 ++++++++
18 drivers/usb/dwc_otg/dwc_otg_driver.c | 1274 +++++++++++++
19 drivers/usb/dwc_otg/dwc_otg_driver.h | 84 +
20 drivers/usb/dwc_otg/dwc_otg_hcd.c | 2870 +++++++++++++++++++++++++++++
21 drivers/usb/dwc_otg/dwc_otg_hcd.h | 676 +++++++
22 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c | 1841 +++++++++++++++++++
23 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c | 794 ++++++++
24 drivers/usb/dwc_otg/dwc_otg_ifx.c | 100 +
25 drivers/usb/dwc_otg/dwc_otg_ifx.h | 85 +
26 drivers/usb/dwc_otg/dwc_otg_plat.h | 269 +++
27 drivers/usb/dwc_otg/dwc_otg_regs.h | 1797 ++++++++++++++++++
28 21 files changed, 15443 insertions(+), 2 deletions(-)
29 create mode 100644 drivers/usb/dwc_otg/Kconfig
30 create mode 100644 drivers/usb/dwc_otg/Makefile
31 create mode 100644 drivers/usb/dwc_otg/dwc_otg_attr.c
32 create mode 100644 drivers/usb/dwc_otg/dwc_otg_attr.h
33 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.c
34 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.h
35 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil_ifx.h
36 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil_intr.c
37 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.c
38 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.h
39 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.c
40 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.h
41 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
42 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
43 create mode 100644 drivers/usb/dwc_otg/dwc_otg_ifx.c
44 create mode 100644 drivers/usb/dwc_otg/dwc_otg_ifx.h
45 create mode 100644 drivers/usb/dwc_otg/dwc_otg_plat.h
46 create mode 100644 drivers/usb/dwc_otg/dwc_otg_regs.h
48 --- a/drivers/usb/Kconfig
49 +++ b/drivers/usb/Kconfig
50 @@ -116,6 +116,8 @@ source "drivers/usb/wusbcore/Kconfig"
52 source "drivers/usb/host/Kconfig"
54 +source "drivers/usb/dwc_otg/Kconfig"
56 source "drivers/usb/musb/Kconfig"
58 source "drivers/usb/renesas_usbhs/Kconfig"
59 --- a/drivers/usb/Makefile
60 +++ b/drivers/usb/Makefile
61 @@ -28,6 +28,8 @@ obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
63 obj-$(CONFIG_USB_WUSB) += wusbcore/
65 +obj-$(CONFIG_DWC_OTG) += dwc_otg/
67 obj-$(CONFIG_USB_ACM) += class/
68 obj-$(CONFIG_USB_PRINTER) += class/
69 obj-$(CONFIG_USB_WDM) += class/
70 --- a/drivers/usb/core/hub.c
71 +++ b/drivers/usb/core/hub.c
72 @@ -2885,11 +2885,11 @@ hub_port_init (struct usb_hub *hub, stru
73 udev->ttport = hdev->ttport;
74 } else if (udev->speed != USB_SPEED_HIGH
75 && hdev->speed == USB_SPEED_HIGH) {
77 +/* if (!hub->tt.hub) {
78 dev_err(&udev->dev, "parent hub has no TT\n");
87 +++ b/drivers/usb/dwc_otg/Kconfig
90 + tristate "Synopsis DWC_OTG support"
93 + This driver supports Synopsis DWC_OTG IP core
94 + embebbed on many SOCs (ralink, infineon, etc)
97 + prompt "USB Operation Mode"
99 + default DWC_OTG_HOST_ONLY
101 +config DWC_OTG_HOST_ONLY
102 + bool "HOST ONLY MODE"
105 +#config DWC_OTG_DEVICE_ONLY
106 +# bool "DEVICE ONLY MODE"
107 +# depends on DWC_OTG
113 + default DWC_OTG_LANTIQ
115 +config DWC_OTG_LANTIQ
119 + Danube USB Host Controller
123 +config DWC_OTG_DEBUG
124 + bool "Enable debug mode"
127 +++ b/drivers/usb/dwc_otg/Makefile
130 +# Makefile for DWC_otg Highspeed USB controller driver
133 +ifeq ($(CONFIG_DWC_OTG_DEBUG),y)
134 +EXTRA_CFLAGS += -DDEBUG
137 +# Use one of the following flags to compile the software in host-only or
138 +# device-only mode based on the configuration selected by the user
139 +ifeq ($(CONFIG_DWC_OTG_HOST_ONLY),y)
140 + EXTRA_CFLAGS += -DDWC_OTG_HOST_ONLY -DDWC_HOST_ONLY
141 + EXTRA_CFLAGS += -DDWC_OTG_EN_ISOC -DDWC_EN_ISOC
142 +else ifeq ($(CONFIG_DWC_OTG_DEVICE_ONLY),y)
143 + EXTRA_CFLAGS += -DDWC_OTG_DEVICE_ONLY
145 + EXTRA_CFLAGS += -DDWC_OTG_MODE
148 +# EXTRA_CFLAGS += -DDWC_HS_ELECT_TST
149 +# EXTRA_CFLAGS += -DDWC_OTG_EXT_CHG_PUMP
151 +ifeq ($(CONFIG_DWC_OTG_LANTIQ),y)
152 + EXTRA_CFLAGS += -Dlinux -D__LINUX__ -DDWC_OTG_IFX -DDWC_OTG_HOST_ONLY -DDWC_HOST_ONLY -D__KERNEL__
154 +ifeq ($(CONFIG_DWC_OTG_LANTIQ),m)
155 + EXTRA_CFLAGS += -Dlinux -D__LINUX__ -DDWC_OTG_IFX -DDWC_HOST_ONLY -DMODULE -D__KERNEL__ -DDEBUG
158 +obj-$(CONFIG_DWC_OTG) := dwc_otg.o
159 +dwc_otg-objs := dwc_otg_hcd.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o
160 +#dwc_otg-objs += dwc_otg_pcd.o dwc_otg_pcd_intr.o
161 +dwc_otg-objs += dwc_otg_attr.o
162 +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
163 +dwc_otg-objs += dwc_otg_ifx.o
164 +dwc_otg-objs += dwc_otg_driver.o
166 +#obj-$(CONFIG_DWC_OTG_IFX) := dwc_otg_ifx.o
167 +#dwc_otg_ifx-objs := dwc_otg_ifx.o
169 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.c
171 +/* ==========================================================================
172 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_attr.c $
173 + * $Revision: 1.1.1.1 $
174 + * $Date: 2009-04-17 06:15:34 $
175 + * $Change: 537387 $
177 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
178 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
179 + * otherwise expressly agreed to in writing between Synopsys and you.
181 + * The Software IS NOT an item of Licensed Software or Licensed Product under
182 + * any End User Software License Agreement or Agreement for Licensed Product
183 + * with Synopsys or any supplement thereto. You are permitted to use and
184 + * redistribute this Software in source and binary forms, with or without
185 + * modification, provided that redistributions of source code must retain this
186 + * notice. You may not view, use, disclose, copy or distribute this file or
187 + * any information contained herein except pursuant to this license grant from
188 + * Synopsys. If you do not agree with this notice, including the disclaimer
189 + * below, then you are not authorized to use the Software.
191 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
192 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
193 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
195 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
196 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
197 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
198 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
200 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
202 + * ========================================================================== */
206 + * The diagnostic interface will provide access to the controller for
207 + * bringing up the hardware and testing. The Linux driver attributes
208 + * feature will be used to provide the Linux Diagnostic
209 + * Interface. These attributes are accessed through sysfs.
212 +/** @page "Linux Module Attributes"
214 + * The Linux module attributes feature is used to provide the Linux
215 + * Diagnostic Interface. These attributes are accessed through sysfs.
216 + * The diagnostic interface will provide access to the controller for
217 + * bringing up the hardware and testing.
220 + The following table shows the attributes.
223 + <td><b> Name</b></td>
224 + <td><b> Description</b></td>
225 + <td><b> Access</b></td>
230 + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
235 + <td> hnpcapable </td>
236 + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
237 + Read returns the current value.</td>
238 + <td> Read/Write</td>
242 + <td> srpcapable </td>
243 + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
244 + Read returns the current value.</td>
245 + <td> Read/Write</td>
250 + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
251 + <td> Read/Write</td>
256 + <td> Initiates the Session Request Protocol. Read returns the status.</td>
257 + <td> Read/Write</td>
261 + <td> buspower </td>
262 + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
263 + <td> Read/Write</td>
267 + <td> bussuspend </td>
268 + <td> Suspends the USB bus.</td>
269 + <td> Read/Write</td>
273 + <td> busconnected </td>
274 + <td> Gets the connection status of the bus</td>
280 + <td> Gets or sets the Core Control Status Register.</td>
281 + <td> Read/Write</td>
286 + <td> Gets or sets the Core USB Configuration Register</td>
287 + <td> Read/Write</td>
292 + <td> Gets or sets the Receive FIFO Size Register</td>
293 + <td> Read/Write</td>
297 + <td> gnptxfsiz </td>
298 + <td> Gets or sets the non-periodic Transmit Size Register</td>
299 + <td> Read/Write</td>
303 + <td> gpvndctl </td>
304 + <td> Gets or sets the PHY Vendor Control Register</td>
305 + <td> Read/Write</td>
310 + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
311 + or sets the upper 16 bits.</td>
312 + <td> Read/Write</td>
317 + <td> Gets or sets the value of the User ID Register</td>
318 + <td> Read/Write</td>
323 + <td> Gets the value of the Synopsys ID Regester</td>
328 + <td> devspeed </td>
329 + <td> Gets or sets the device speed setting in the DCFG register</td>
330 + <td> Read/Write</td>
334 + <td> enumspeed </td>
335 + <td> Gets the device enumeration Speed.</td>
340 + <td> hptxfsiz </td>
341 + <td> Gets the value of the Host Periodic Transmit FIFO</td>
347 + <td> Gets or sets the value in the Host Port Control and Status Register</td>
348 + <td> Read/Write</td>
352 + <td> regoffset </td>
353 + <td> Sets the register offset for the next Register Access</td>
354 + <td> Read/Write</td>
358 + <td> regvalue </td>
359 + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
360 + <td> Read/Write</td>
364 + <td> remote_wakeup </td>
365 + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
366 + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
367 + Wakeup signalling bit in the Device Control Register is set for 1
369 + <td> Read/Write</td>
374 + <td> Dumps the contents of core registers.</td>
380 + <td> Dumps the current HCD state.</td>
385 + <td> hcd_frrem </td>
386 + <td> Shows the average value of the Frame Remaining
387 + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
388 + occurs. This can be used to determine the average interrupt latency. Also
389 + shows the average Frame Remaining value for start_transfer and the "a" and
390 + "b" sample points. The "a" and "b" sample points may be used during debugging
391 + bto determine how long it takes to execute a section of the HCD code.</td>
396 + <td> rd_reg_test </td>
397 + <td> Displays the time required to read the GNPTXFSIZ register many times
398 + (the output shows the number of times the register is read).
403 + <td> wr_reg_test </td>
404 + <td> Displays the time required to write the GNPTXFSIZ register many times
405 + (the output shows the number of times the register is written).
412 + To get the current mode:
413 + cat /sys/devices/lm0/mode
415 + To power down the USB:
416 + echo 0 > /sys/devices/lm0/buspower
418 +#include <linux/kernel.h>
419 +#include <linux/module.h>
420 +#include <linux/moduleparam.h>
421 +#include <linux/init.h>
422 +#include <linux/device.h>
423 +#include <linux/errno.h>
424 +#include <linux/types.h>
425 +#include <linux/stat.h> /* permission constants */
429 +#include "dwc_otg_plat.h"
430 +#include "dwc_otg_attr.h"
431 +#include "dwc_otg_driver.h"
432 +// #include "dwc_otg_pcd.h"
433 +#include "dwc_otg_hcd.h"
435 +// 20070316, winder added.
437 +#define SZ_256K 0x00040000
441 + * MACROs for defining sysfs attribute
443 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
444 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
446 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
448 + val = dwc_read_reg32 (_addr_); \
449 + val = (val & (_mask_)) >> _shift_; \
450 + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
452 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
453 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, const char *buf, size_t count) \
455 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
456 + uint32_t set = simple_strtoul(buf, NULL, 16); \
457 + uint32_t clear = set; \
458 + clear = ((~clear) << _shift_) & _mask_; \
459 + set = (set << _shift_) & _mask_; \
460 + dev_dbg(_dev, "Storing Address=0x%08x Set=0x%08x Clear=0x%08x\n", (uint32_t)_addr_, set, clear); \
461 + dwc_modify_reg32(_addr_, clear, set); \
465 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
466 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
467 +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
468 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
470 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
471 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
472 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
475 + * MACROs for defining sysfs attribute for 32-bit registers
477 +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
478 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
480 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
482 + val = dwc_read_reg32 (_addr_); \
483 + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
485 +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
486 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, const char *buf, size_t count) \
488 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
489 + uint32_t val = simple_strtoul(buf, NULL, 16); \
490 + dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \
491 + dwc_write_reg32(_addr_, val); \
495 +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
496 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
497 +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
498 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
500 +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
501 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
502 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
505 +/** @name Functions for Show/Store of Attributes */
509 + * Show the register offset of the Register Access.
511 +static ssize_t regoffset_show( struct device *_dev, struct device_attribute *attr, char *buf)
513 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
514 + return snprintf(buf, sizeof("0xFFFFFFFF\n")+1,"0x%08x\n", otg_dev->reg_offset);
518 + * Set the register offset for the next Register Access Read/Write
520 +static ssize_t regoffset_store( struct device *_dev, struct device_attribute *attr, const char *buf,
523 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
524 + uint32_t offset = simple_strtoul(buf, NULL, 16);
525 + //dev_dbg(_dev, "Offset=0x%08x\n", offset);
526 + if (offset < SZ_256K ) {
527 + otg_dev->reg_offset = offset;
530 + dev_err( _dev, "invalid offset\n" );
535 +DEVICE_ATTR(regoffset, S_IRUGO|S_IWUSR, regoffset_show, regoffset_store);
538 + * Show the value of the register at the offset in the reg_offset
541 +static ssize_t regvalue_show( struct device *_dev, struct device_attribute *attr, char *buf)
543 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
545 + volatile uint32_t *addr;
547 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
548 + /* Calculate the address */
549 + addr = (uint32_t*)(otg_dev->reg_offset +
550 + (uint8_t*)otg_dev->base);
551 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
552 + val = dwc_read_reg32( addr );
553 + return snprintf(buf, sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n")+1,
554 + "Reg@0x%06x = 0x%08x\n",
555 + otg_dev->reg_offset, val);
558 + dev_err(_dev, "Invalid offset (0x%0x)\n",
559 + otg_dev->reg_offset);
560 + return sprintf(buf, "invalid offset\n" );
565 + * Store the value in the register at the offset in the reg_offset
569 +static ssize_t regvalue_store( struct device *_dev, struct device_attribute *attr, const char *buf,
572 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
573 + volatile uint32_t * addr;
574 + uint32_t val = simple_strtoul(buf, NULL, 16);
575 + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
576 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
577 + /* Calculate the address */
578 + addr = (uint32_t*)(otg_dev->reg_offset +
579 + (uint8_t*)otg_dev->base);
580 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
581 + dwc_write_reg32( addr, val );
584 + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
585 + otg_dev->reg_offset);
589 +DEVICE_ATTR(regvalue, S_IRUGO|S_IWUSR, regvalue_show, regvalue_store);
594 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<20),20,"Mode");
595 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<9),9,"Mode");
596 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<8),8,"Mode");
598 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
599 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
600 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected,otg_dev->core_if->host_if->hprt0,0x01,0,"Bus Connected");
602 +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl,&(otg_dev->core_if->core_global_regs->gotgctl),"GOTGCTL");
603 +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,&(otg_dev->core_if->core_global_regs->gusbcfg),"GUSBCFG");
604 +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,&(otg_dev->core_if->core_global_regs->grxfsiz),"GRXFSIZ");
605 +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,&(otg_dev->core_if->core_global_regs->gnptxfsiz),"GNPTXFSIZ");
606 +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,&(otg_dev->core_if->core_global_regs->gpvndctl),"GPVNDCTL");
607 +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,&(otg_dev->core_if->core_global_regs->ggpio),"GGPIO");
608 +DWC_OTG_DEVICE_ATTR_REG32_RW(guid,&(otg_dev->core_if->core_global_regs->guid),"GUID");
609 +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,&(otg_dev->core_if->core_global_regs->gsnpsid),"GSNPSID");
610 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dcfg),0x3,0,"Device Speed");
611 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dsts),0x6,1,"Device Enumeration Speed");
613 +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,&(otg_dev->core_if->core_global_regs->hptxfsiz),"HPTXFSIZ");
614 +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0,otg_dev->core_if->host_if->hprt0,"HPRT0");
618 + * @todo Add code to initiate the HNP.
621 + * Show the HNP status bit
623 +static ssize_t hnp_show( struct device *_dev, struct device_attribute *attr, char *buf)
625 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
626 + gotgctl_data_t val;
627 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
628 + return sprintf (buf, "HstNegScs = 0x%x\n", val.b.hstnegscs);
632 + * Set the HNP Request bit
634 +static ssize_t hnp_store( struct device *_dev, struct device_attribute *attr, const char *buf,
637 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
638 + uint32_t in = simple_strtoul(buf, NULL, 16);
639 + uint32_t *addr = (uint32_t *)&(otg_dev->core_if->core_global_regs->gotgctl);
640 + gotgctl_data_t mem;
641 + mem.d32 = dwc_read_reg32(addr);
643 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
644 + dwc_write_reg32(addr, mem.d32);
647 +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
650 + * @todo Add code to initiate the SRP.
653 + * Show the SRP status bit
655 +static ssize_t srp_show( struct device *_dev, struct device_attribute *attr, char *buf)
657 +#ifndef DWC_HOST_ONLY
658 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
659 + gotgctl_data_t val;
660 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
661 + return sprintf (buf, "SesReqScs = 0x%x\n", val.b.sesreqscs);
663 + return sprintf(buf, "Host Only Mode!\n");
668 + * Set the SRP Request bit
670 +static ssize_t srp_store( struct device *_dev, struct device_attribute *attr, const char *buf,
673 +#ifndef DWC_HOST_ONLY
674 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
675 + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
679 +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
682 + * @todo Need to do more for power on/off?
685 + * Show the Bus Power status
687 +static ssize_t buspower_show( struct device *_dev, struct device_attribute *attr, char *buf)
689 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
691 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
692 + return sprintf (buf, "Bus Power = 0x%x\n", val.b.prtpwr);
697 + * Set the Bus Power status
699 +static ssize_t buspower_store( struct device *_dev, struct device_attribute *attr, const char *buf,
702 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
703 + uint32_t on = simple_strtoul(buf, NULL, 16);
704 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
707 + mem.d32 = dwc_read_reg32(addr);
710 + //dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
711 + dwc_write_reg32(addr, mem.d32);
715 +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
718 + * @todo Need to do more for suspend?
721 + * Show the Bus Suspend status
723 +static ssize_t bussuspend_show( struct device *_dev, struct device_attribute *attr, char *buf)
725 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
727 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
728 + return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
732 + * Set the Bus Suspend status
734 +static ssize_t bussuspend_store( struct device *_dev, struct device_attribute *attr, const char *buf,
737 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
738 + uint32_t in = simple_strtoul(buf, NULL, 16);
739 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
741 + mem.d32 = dwc_read_reg32(addr);
742 + mem.b.prtsusp = in;
743 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
744 + dwc_write_reg32(addr, mem.d32);
747 +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
750 + * Show the status of Remote Wakeup.
752 +static ssize_t remote_wakeup_show( struct device *_dev, struct device_attribute *attr, char *buf)
754 +#ifndef DWC_HOST_ONLY
755 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
757 + val.d32 = dwc_read_reg32( &otg_dev->core_if->dev_if->dev_global_regs->dctl);
758 + return sprintf( buf, "Remote Wakeup = %d Enabled = %d\n",
759 + val.b.rmtwkupsig, otg_dev->pcd->remote_wakeup_enable);
761 + return sprintf(buf, "Host Only Mode!\n");
766 + * Initiate a remote wakeup of the host. The Device control register
767 + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
771 +static ssize_t remote_wakeup_store( struct device *_dev, struct device_attribute *attr, const char *buf,
774 +#ifndef DWC_HOST_ONLY
775 + uint32_t val = simple_strtoul(buf, NULL, 16);
776 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
778 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
781 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
786 +DEVICE_ATTR(remote_wakeup, S_IRUGO|S_IWUSR, remote_wakeup_show,
787 + remote_wakeup_store);
790 + * Dump global registers and either host or device registers (depending on the
791 + * current mode of the core).
793 +static ssize_t regdump_show( struct device *_dev, struct device_attribute *attr, char *buf)
796 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
797 + printk("%s otg_dev=0x%p\n", __FUNCTION__, otg_dev);
799 + dwc_otg_dump_global_registers( otg_dev->core_if);
800 + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
801 + dwc_otg_dump_host_registers( otg_dev->core_if);
803 + dwc_otg_dump_dev_registers( otg_dev->core_if);
807 + return sprintf( buf, "Register Dump\n" );
810 +DEVICE_ATTR(regdump, S_IRUGO|S_IWUSR, regdump_show, 0);
813 + * Dump the current hcd state.
815 +static ssize_t hcddump_show( struct device *_dev, struct device_attribute *attr, char *buf)
817 +#ifndef DWC_DEVICE_ONLY
818 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
819 + dwc_otg_hcd_dump_state(otg_dev->hcd);
821 + return sprintf( buf, "HCD Dump\n" );
824 +DEVICE_ATTR(hcddump, S_IRUGO|S_IWUSR, hcddump_show, 0);
827 + * Dump the average frame remaining at SOF. This can be used to
828 + * determine average interrupt latency. Frame remaining is also shown for
829 + * start transfer and two additional sample points.
831 +static ssize_t hcd_frrem_show( struct device *_dev, struct device_attribute *attr, char *buf)
833 +#ifndef DWC_DEVICE_ONLY
834 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
835 + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
837 + return sprintf( buf, "HCD Dump Frame Remaining\n" );
840 +DEVICE_ATTR(hcd_frrem, S_IRUGO|S_IWUSR, hcd_frrem_show, 0);
843 + * Displays the time required to read the GNPTXFSIZ register many times (the
844 + * output shows the number of times the register is read).
846 +#define RW_REG_COUNT 10000000
847 +#define MSEC_PER_JIFFIE 1000/HZ
848 +static ssize_t rd_reg_test_show( struct device *_dev, struct device_attribute *attr, char *buf)
853 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
855 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
856 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
857 + start_jiffies = jiffies;
858 + for (i = 0; i < RW_REG_COUNT; i++) {
859 + dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
861 + time = jiffies - start_jiffies;
862 + return sprintf( buf, "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
863 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time );
866 +DEVICE_ATTR(rd_reg_test, S_IRUGO|S_IWUSR, rd_reg_test_show, 0);
869 + * Displays the time required to write the GNPTXFSIZ register many times (the
870 + * output shows the number of times the register is written).
872 +static ssize_t wr_reg_test_show( struct device *_dev, struct device_attribute *attr, char *buf)
877 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
880 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
881 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
882 + reg_val = dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
883 + start_jiffies = jiffies;
884 + for (i = 0; i < RW_REG_COUNT; i++) {
885 + dwc_write_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz, reg_val);
887 + time = jiffies - start_jiffies;
888 + return sprintf( buf, "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
889 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
892 +DEVICE_ATTR(wr_reg_test, S_IRUGO|S_IWUSR, wr_reg_test_show, 0);
896 + * Create the device files
898 +void dwc_otg_attr_create (struct device *_dev)
902 + retval = device_create_file(_dev, &dev_attr_regoffset);
903 + retval += device_create_file(_dev, &dev_attr_regvalue);
904 + retval += device_create_file(_dev, &dev_attr_mode);
905 + retval += device_create_file(_dev, &dev_attr_hnpcapable);
906 + retval += device_create_file(_dev, &dev_attr_srpcapable);
907 + retval += device_create_file(_dev, &dev_attr_hnp);
908 + retval += device_create_file(_dev, &dev_attr_srp);
909 + retval += device_create_file(_dev, &dev_attr_buspower);
910 + retval += device_create_file(_dev, &dev_attr_bussuspend);
911 + retval += device_create_file(_dev, &dev_attr_busconnected);
912 + retval += device_create_file(_dev, &dev_attr_gotgctl);
913 + retval += device_create_file(_dev, &dev_attr_gusbcfg);
914 + retval += device_create_file(_dev, &dev_attr_grxfsiz);
915 + retval += device_create_file(_dev, &dev_attr_gnptxfsiz);
916 + retval += device_create_file(_dev, &dev_attr_gpvndctl);
917 + retval += device_create_file(_dev, &dev_attr_ggpio);
918 + retval += device_create_file(_dev, &dev_attr_guid);
919 + retval += device_create_file(_dev, &dev_attr_gsnpsid);
920 + retval += device_create_file(_dev, &dev_attr_devspeed);
921 + retval += device_create_file(_dev, &dev_attr_enumspeed);
922 + retval += device_create_file(_dev, &dev_attr_hptxfsiz);
923 + retval += device_create_file(_dev, &dev_attr_hprt0);
924 + retval += device_create_file(_dev, &dev_attr_remote_wakeup);
925 + retval += device_create_file(_dev, &dev_attr_regdump);
926 + retval += device_create_file(_dev, &dev_attr_hcddump);
927 + retval += device_create_file(_dev, &dev_attr_hcd_frrem);
928 + retval += device_create_file(_dev, &dev_attr_rd_reg_test);
929 + retval += device_create_file(_dev, &dev_attr_wr_reg_test);
933 + DWC_PRINT("cannot create sysfs device files.\n");
934 + // DWC_PRINT("killing own sysfs device files!\n");
935 + dwc_otg_attr_remove(_dev);
940 + * Remove the device files
942 +void dwc_otg_attr_remove (struct device *_dev)
944 + device_remove_file(_dev, &dev_attr_regoffset);
945 + device_remove_file(_dev, &dev_attr_regvalue);
946 + device_remove_file(_dev, &dev_attr_mode);
947 + device_remove_file(_dev, &dev_attr_hnpcapable);
948 + device_remove_file(_dev, &dev_attr_srpcapable);
949 + device_remove_file(_dev, &dev_attr_hnp);
950 + device_remove_file(_dev, &dev_attr_srp);
951 + device_remove_file(_dev, &dev_attr_buspower);
952 + device_remove_file(_dev, &dev_attr_bussuspend);
953 + device_remove_file(_dev, &dev_attr_busconnected);
954 + device_remove_file(_dev, &dev_attr_gotgctl);
955 + device_remove_file(_dev, &dev_attr_gusbcfg);
956 + device_remove_file(_dev, &dev_attr_grxfsiz);
957 + device_remove_file(_dev, &dev_attr_gnptxfsiz);
958 + device_remove_file(_dev, &dev_attr_gpvndctl);
959 + device_remove_file(_dev, &dev_attr_ggpio);
960 + device_remove_file(_dev, &dev_attr_guid);
961 + device_remove_file(_dev, &dev_attr_gsnpsid);
962 + device_remove_file(_dev, &dev_attr_devspeed);
963 + device_remove_file(_dev, &dev_attr_enumspeed);
964 + device_remove_file(_dev, &dev_attr_hptxfsiz);
965 + device_remove_file(_dev, &dev_attr_hprt0);
966 + device_remove_file(_dev, &dev_attr_remote_wakeup);
967 + device_remove_file(_dev, &dev_attr_regdump);
968 + device_remove_file(_dev, &dev_attr_hcddump);
969 + device_remove_file(_dev, &dev_attr_hcd_frrem);
970 + device_remove_file(_dev, &dev_attr_rd_reg_test);
971 + device_remove_file(_dev, &dev_attr_wr_reg_test);
974 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.h
976 +/* ==========================================================================
977 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_attr.h $
978 + * $Revision: 1.1.1.1 $
979 + * $Date: 2009-04-17 06:15:34 $
980 + * $Change: 510275 $
982 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
983 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
984 + * otherwise expressly agreed to in writing between Synopsys and you.
986 + * The Software IS NOT an item of Licensed Software or Licensed Product under
987 + * any End User Software License Agreement or Agreement for Licensed Product
988 + * with Synopsys or any supplement thereto. You are permitted to use and
989 + * redistribute this Software in source and binary forms, with or without
990 + * modification, provided that redistributions of source code must retain this
991 + * notice. You may not view, use, disclose, copy or distribute this file or
992 + * any information contained herein except pursuant to this license grant from
993 + * Synopsys. If you do not agree with this notice, including the disclaimer
994 + * below, then you are not authorized to use the Software.
996 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
997 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
998 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
999 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
1000 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1001 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1002 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1003 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1004 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1005 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1007 + * ========================================================================== */
1009 +#if !defined(__DWC_OTG_ATTR_H__)
1010 +#define __DWC_OTG_ATTR_H__
1013 + * This file contains the interface to the Linux device attributes.
1015 +extern struct device_attribute dev_attr_regoffset;
1016 +extern struct device_attribute dev_attr_regvalue;
1018 +extern struct device_attribute dev_attr_mode;
1019 +extern struct device_attribute dev_attr_hnpcapable;
1020 +extern struct device_attribute dev_attr_srpcapable;
1021 +extern struct device_attribute dev_attr_hnp;
1022 +extern struct device_attribute dev_attr_srp;
1023 +extern struct device_attribute dev_attr_buspower;
1024 +extern struct device_attribute dev_attr_bussuspend;
1025 +extern struct device_attribute dev_attr_busconnected;
1026 +extern struct device_attribute dev_attr_gotgctl;
1027 +extern struct device_attribute dev_attr_gusbcfg;
1028 +extern struct device_attribute dev_attr_grxfsiz;
1029 +extern struct device_attribute dev_attr_gnptxfsiz;
1030 +extern struct device_attribute dev_attr_gpvndctl;
1031 +extern struct device_attribute dev_attr_ggpio;
1032 +extern struct device_attribute dev_attr_guid;
1033 +extern struct device_attribute dev_attr_gsnpsid;
1034 +extern struct device_attribute dev_attr_devspeed;
1035 +extern struct device_attribute dev_attr_enumspeed;
1036 +extern struct device_attribute dev_attr_hptxfsiz;
1037 +extern struct device_attribute dev_attr_hprt0;
1039 +void dwc_otg_attr_create (struct device *_dev);
1040 +void dwc_otg_attr_remove (struct device *_dev);
1044 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.c
1046 +/* ==========================================================================
1047 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil.c $
1048 + * $Revision: 1.1.1.1 $
1049 + * $Date: 2009-04-17 06:15:34 $
1050 + * $Change: 631780 $
1052 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
1053 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
1054 + * otherwise expressly agreed to in writing between Synopsys and you.
1056 + * The Software IS NOT an item of Licensed Software or Licensed Product under
1057 + * any End User Software License Agreement or Agreement for Licensed Product
1058 + * with Synopsys or any supplement thereto. You are permitted to use and
1059 + * redistribute this Software in source and binary forms, with or without
1060 + * modification, provided that redistributions of source code must retain this
1061 + * notice. You may not view, use, disclose, copy or distribute this file or
1062 + * any information contained herein except pursuant to this license grant from
1063 + * Synopsys. If you do not agree with this notice, including the disclaimer
1064 + * below, then you are not authorized to use the Software.
1066 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
1067 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1068 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1069 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
1070 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1071 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1072 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1073 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1074 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1075 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1077 + * ========================================================================== */
1081 + * The Core Interface Layer provides basic services for accessing and
1082 + * managing the DWC_otg hardware. These services are used by both the
1083 + * Host Controller Driver and the Peripheral Controller Driver.
1085 + * The CIL manages the memory map for the core so that the HCD and PCD
1086 + * don't have to do this separately. It also handles basic tasks like
1087 + * reading/writing the registers and data FIFOs in the controller.
1088 + * Some of the data access functions provide encapsulation of several
1089 + * operations required to perform a task, such as writing multiple
1090 + * registers to start a transfer. Finally, the CIL performs basic
1091 + * services that are not specific to either the host or device modes
1092 + * of operation. These services include management of the OTG Host
1093 + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
1094 + * Diagnostic API is also provided to allow testing of the controller
1097 + * The Core Interface Layer has the following requirements:
1098 + * - Provides basic controller operations.
1099 + * - Minimal use of OS services.
1100 + * - The OS services used will be abstracted by using inline functions
1104 +#include <asm/unaligned.h>
1107 +#include <linux/jiffies.h>
1110 +#include "dwc_otg_plat.h"
1112 +#include "dwc_otg_regs.h"
1113 +#include "dwc_otg_cil.h"
1116 + * This function is called to initialize the DWC_otg CSR data
1117 + * structures. The register addresses in the device and host
1118 + * structures are initialized from the base address supplied by the
1119 + * caller. The calling function must make the OS calls to get the
1120 + * base address of the DWC_otg controller registers. The core_params
1121 + * argument holds the parameters that specify how the core should be
1124 + * @param[in] _reg_base_addr Base address of DWC_otg core registers
1125 + * @param[in] _core_params Pointer to the core configuration parameters
1128 +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
1129 + dwc_otg_core_params_t *_core_params)
1131 + dwc_otg_core_if_t *core_if = 0;
1132 + dwc_otg_dev_if_t *dev_if = 0;
1133 + dwc_otg_host_if_t *host_if = 0;
1134 + uint8_t *reg_base = (uint8_t *)_reg_base_addr;
1137 + DWC_DEBUGPL(DBG_CILV, "%s(%p,%p)\n", __func__, _reg_base_addr, _core_params);
1139 + core_if = kmalloc( sizeof(dwc_otg_core_if_t), GFP_KERNEL);
1140 + if (core_if == 0) {
1141 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_core_if_t failed\n");
1144 + memset(core_if, 0, sizeof(dwc_otg_core_if_t));
1146 + core_if->core_params = _core_params;
1147 + core_if->core_global_regs = (dwc_otg_core_global_regs_t *)reg_base;
1149 + * Allocate the Device Mode structures.
1151 + dev_if = kmalloc( sizeof(dwc_otg_dev_if_t), GFP_KERNEL);
1152 + if (dev_if == 0) {
1153 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
1158 + dev_if->dev_global_regs =
1159 + (dwc_otg_device_global_regs_t *)(reg_base + DWC_DEV_GLOBAL_REG_OFFSET);
1161 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1162 + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
1163 + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
1164 + (i * DWC_EP_REG_OFFSET));
1166 + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
1167 + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
1168 + (i * DWC_EP_REG_OFFSET));
1169 + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
1170 + i, &dev_if->in_ep_regs[i]->diepctl);
1171 + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
1172 + i, &dev_if->out_ep_regs[i]->doepctl);
1174 + dev_if->speed = 0; // unknown
1175 + //dev_if->num_eps = MAX_EPS_CHANNELS;
1176 + //dev_if->num_perio_eps = 0;
1178 + core_if->dev_if = dev_if;
1180 + * Allocate the Host Mode structures.
1182 + host_if = kmalloc( sizeof(dwc_otg_host_if_t), GFP_KERNEL);
1183 + if (host_if == 0) {
1184 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_host_if_t failed\n");
1190 + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
1191 + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
1192 + host_if->hprt0 = (uint32_t*)(reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
1193 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1194 + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
1195 + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
1196 + (i * DWC_OTG_CHAN_REGS_OFFSET));
1197 + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
1198 + i, &host_if->hc_regs[i]->hcchar);
1200 + host_if->num_host_channels = MAX_EPS_CHANNELS;
1201 + core_if->host_if = host_if;
1203 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1204 + core_if->data_fifo[i] =
1205 + (uint32_t *)(reg_base + DWC_OTG_DATA_FIFO_OFFSET +
1206 + (i * DWC_OTG_DATA_FIFO_SIZE));
1207 + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08x\n",
1208 + i, (unsigned)core_if->data_fifo[i]);
1211 + core_if->pcgcctl = (uint32_t*)(reg_base + DWC_OTG_PCGCCTL_OFFSET);
1214 + * Store the contents of the hardware configuration registers here for
1215 + * easy access later.
1217 + core_if->hwcfg1.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg1);
1218 + core_if->hwcfg2.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg2);
1219 + core_if->hwcfg3.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg3);
1220 + core_if->hwcfg4.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg4);
1222 + DWC_DEBUGPL(DBG_CILV,"hwcfg1=%08x\n",core_if->hwcfg1.d32);
1223 + DWC_DEBUGPL(DBG_CILV,"hwcfg2=%08x\n",core_if->hwcfg2.d32);
1224 + DWC_DEBUGPL(DBG_CILV,"hwcfg3=%08x\n",core_if->hwcfg3.d32);
1225 + DWC_DEBUGPL(DBG_CILV,"hwcfg4=%08x\n",core_if->hwcfg4.d32);
1228 + DWC_DEBUGPL(DBG_CILV,"op_mode=%0x\n",core_if->hwcfg2.b.op_mode);
1229 + DWC_DEBUGPL(DBG_CILV,"arch=%0x\n",core_if->hwcfg2.b.architecture);
1230 + DWC_DEBUGPL(DBG_CILV,"num_dev_ep=%d\n",core_if->hwcfg2.b.num_dev_ep);
1231 + DWC_DEBUGPL(DBG_CILV,"num_host_chan=%d\n",core_if->hwcfg2.b.num_host_chan);
1232 + DWC_DEBUGPL(DBG_CILV,"nonperio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.nonperio_tx_q_depth);
1233 + DWC_DEBUGPL(DBG_CILV,"host_perio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.host_perio_tx_q_depth);
1234 + DWC_DEBUGPL(DBG_CILV,"dev_token_q_depth=0x%0x\n",core_if->hwcfg2.b.dev_token_q_depth);
1236 + DWC_DEBUGPL(DBG_CILV,"Total FIFO SZ=%d\n", core_if->hwcfg3.b.dfifo_depth);
1237 + DWC_DEBUGPL(DBG_CILV,"xfer_size_cntr_width=%0x\n", core_if->hwcfg3.b.xfer_size_cntr_width);
1240 + * Set the SRP sucess bit for FS-I2c
1242 + core_if->srp_success = 0;
1243 + core_if->srp_timer_started = 0;
1248 + * This function frees the structures allocated by dwc_otg_cil_init().
1250 + * @param[in] _core_if The core interface pointer returned from
1251 + * dwc_otg_cil_init().
1254 +void dwc_otg_cil_remove( dwc_otg_core_if_t *_core_if )
1256 + /* Disable all interrupts */
1257 + dwc_modify_reg32( &_core_if->core_global_regs->gahbcfg, 1, 0);
1258 + dwc_write_reg32( &_core_if->core_global_regs->gintmsk, 0);
1260 + if ( _core_if->dev_if ) {
1261 + kfree( _core_if->dev_if );
1263 + if ( _core_if->host_if ) {
1264 + kfree( _core_if->host_if );
1266 + kfree( _core_if );
1270 + * This function enables the controller's Global Interrupt in the AHB Config
1273 + * @param[in] _core_if Programming view of DWC_otg controller.
1275 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if )
1277 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1278 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
1279 + dwc_modify_reg32(&_core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
1282 + * This function disables the controller's Global Interrupt in the AHB Config
1285 + * @param[in] _core_if Programming view of DWC_otg controller.
1287 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if )
1289 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1290 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
1291 + dwc_modify_reg32(&_core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
1295 + * This function initializes the commmon interrupts, used in both
1296 + * device and host modes.
1298 + * @param[in] _core_if Programming view of the DWC_otg controller
1301 +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t *_core_if)
1303 + dwc_otg_core_global_regs_t *global_regs =
1304 + _core_if->core_global_regs;
1305 + gintmsk_data_t intr_mask = { .d32 = 0};
1306 + /* Clear any pending OTG Interrupts */
1307 + dwc_write_reg32( &global_regs->gotgint, 0xFFFFFFFF);
1308 + /* Clear any pending interrupts */
1309 + dwc_write_reg32( &global_regs->gintsts, 0xFFFFFFFF);
1311 + * Enable the interrupts in the GINTMSK.
1313 + intr_mask.b.modemismatch = 1;
1314 + intr_mask.b.otgintr = 1;
1315 + if (!_core_if->dma_enable) {
1316 + intr_mask.b.rxstsqlvl = 1;
1318 + intr_mask.b.conidstschng = 1;
1319 + intr_mask.b.wkupintr = 1;
1320 + intr_mask.b.disconnect = 1;
1321 + intr_mask.b.usbsuspend = 1;
1322 + intr_mask.b.sessreqintr = 1;
1323 + dwc_write_reg32( &global_regs->gintmsk, intr_mask.d32);
1327 + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
1330 +static void init_fslspclksel(dwc_otg_core_if_t *_core_if)
1335 + if (((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1336 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1337 + (_core_if->core_params->ulpi_fs_ls)) ||
1338 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS))
1340 + /* Full speed PHY */
1341 + val = DWC_HCFG_48_MHZ;
1343 + /* High speed PHY running at full speed or high speed */
1344 + val = DWC_HCFG_30_60_MHZ;
1347 + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
1348 + hcfg.d32 = dwc_read_reg32(&_core_if->host_if->host_global_regs->hcfg);
1349 + hcfg.b.fslspclksel = val;
1350 + dwc_write_reg32(&_core_if->host_if->host_global_regs->hcfg, hcfg.d32);
1354 + * Initializes the DevSpd field of the DCFG register depending on the PHY type
1355 + * and the enumeration speed of the device.
1357 +static void init_devspd(dwc_otg_core_if_t *_core_if)
1362 + if (((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1363 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1364 + (_core_if->core_params->ulpi_fs_ls)) ||
1365 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS))
1367 + /* Full speed PHY */
1369 + } else if (_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
1370 + /* High speed PHY running at full speed */
1373 + /* High speed PHY running at high speed */
1377 + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
1378 + dcfg.d32 = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->dcfg);
1379 + dcfg.b.devspd = val;
1380 + dwc_write_reg32(&_core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
1384 + * This function calculates the number of IN EPS
1385 + * using GHWCFG1 and GHWCFG2 registers values
1387 + * @param _pcd the pcd structure.
1389 +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * _core_if)
1391 + uint32_t num_in_eps = 0;
1392 + uint32_t num_eps = _core_if->hwcfg2.b.num_dev_ep;
1393 + uint32_t hwcfg1 = _core_if->hwcfg1.d32 >> 2;
1394 + uint32_t num_tx_fifos = _core_if->hwcfg4.b.num_in_eps;
1396 + for (i = 0; i < num_eps; ++i) {
1397 + if (!(hwcfg1 & 0x1))
1401 + if (_core_if->hwcfg4.b.ded_fifo_en) {
1402 + num_in_eps = (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
1404 + return num_in_eps;
1409 + * This function calculates the number of OUT EPS
1410 + * using GHWCFG1 and GHWCFG2 registers values
1412 + * @param _pcd the pcd structure.
1414 +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * _core_if)
1416 + uint32_t num_out_eps = 0;
1417 + uint32_t num_eps = _core_if->hwcfg2.b.num_dev_ep;
1418 + uint32_t hwcfg1 = _core_if->hwcfg1.d32 >> 2;
1420 + for (i = 0; i < num_eps; ++i) {
1421 + if (!(hwcfg1 & 0x2))
1425 + return num_out_eps;
1428 + * This function initializes the DWC_otg controller registers and
1429 + * prepares the core for device mode or host mode operation.
1431 + * @param _core_if Programming view of the DWC_otg controller
1434 +void dwc_otg_core_init(dwc_otg_core_if_t *_core_if)
1436 + dwc_otg_core_global_regs_t * global_regs = _core_if->core_global_regs;
1437 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1439 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1440 + gusbcfg_data_t usbcfg = { .d32 = 0 };
1441 + gi2cctl_data_t i2cctl = {.d32 = 0};
1443 + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p)\n",_core_if);
1445 + /* Common Initialization */
1447 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1448 + DWC_DEBUGPL(DBG_CIL, "USB config register: 0x%08x\n", usbcfg.d32);
1450 + /* Program the ULPI External VBUS bit if needed */
1451 + //usbcfg.b.ulpi_ext_vbus_drv = 1;
1452 + //usbcfg.b.ulpi_ext_vbus_drv = 0;
1453 + usbcfg.b.ulpi_ext_vbus_drv =
1454 + (_core_if->core_params->phy_ulpi_ext_vbus == DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
1456 + /* Set external TS Dline pulsing */
1457 + usbcfg.b.term_sel_dl_pulse = (_core_if->core_params->ts_dline == 1) ? 1 : 0;
1458 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1460 + /* Reset the Controller */
1461 + dwc_otg_core_reset( _core_if );
1463 + /* Initialize parameters from Hardware configuration registers. */
1465 + dev_if->num_eps = _core_if->hwcfg2.b.num_dev_ep;
1466 + dev_if->num_perio_eps = _core_if->hwcfg4.b.num_dev_perio_in_ep;
1468 + dev_if->num_in_eps = calc_num_in_eps(_core_if);
1469 + dev_if->num_out_eps = calc_num_out_eps(_core_if);
1471 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
1472 + _core_if->hwcfg4.b.num_dev_perio_in_ep);
1473 + DWC_DEBUGPL(DBG_CIL, "Is power optimization enabled? %s\n",
1474 + _core_if->hwcfg4.b.power_optimiz ? "Yes" : "No");
1475 + DWC_DEBUGPL(DBG_CIL, "vbus_valid filter enabled? %s\n",
1476 + _core_if->hwcfg4.b.vbus_valid_filt_en ? "Yes" : "No");
1477 + DWC_DEBUGPL(DBG_CIL, "iddig filter enabled? %s\n",
1478 + _core_if->hwcfg4.b.iddig_filt_en ? "Yes" : "No");
1480 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",_core_if->hwcfg4.b.num_dev_perio_in_ep);
1481 + for (i=0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
1482 + dev_if->perio_tx_fifo_size[i] =
1483 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
1484 + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n", i,
1485 + dev_if->perio_tx_fifo_size[i]);
1487 + for (i = 0; i < _core_if->hwcfg4.b.num_in_eps; i++) {
1488 + dev_if->tx_fifo_size[i] =
1489 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
1490 + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n", i,
1491 + dev_if->perio_tx_fifo_size[i]);
1494 + _core_if->total_fifo_size = _core_if->hwcfg3.b.dfifo_depth;
1495 + _core_if->rx_fifo_size = dwc_read_reg32(&global_regs->grxfsiz);
1496 + _core_if->nperio_tx_fifo_size = dwc_read_reg32(&global_regs->gnptxfsiz) >> 16;
1498 + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", _core_if->total_fifo_size);
1499 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", _core_if->rx_fifo_size);
1500 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n", _core_if->nperio_tx_fifo_size);
1502 + /* This programming sequence needs to happen in FS mode before any other
1503 + * programming occurs */
1504 + if ((_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
1505 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
1506 + /* If FS mode with FS PHY */
1508 + /* core_init() is now called on every switch so only call the
1509 + * following for the first time through. */
1510 + if (!_core_if->phy_init_done) {
1511 + _core_if->phy_init_done = 1;
1512 + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
1513 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1514 + usbcfg.b.physel = 1;
1515 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1517 + /* Reset after a PHY select */
1518 + dwc_otg_core_reset( _core_if );
1521 + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
1522 + * do this on HNP Dev/Host mode switches (done in dev_init and
1524 + if (dwc_otg_is_host_mode(_core_if)) {
1525 + DWC_DEBUGPL(DBG_CIL, "host mode\n");
1526 + init_fslspclksel(_core_if);
1528 + DWC_DEBUGPL(DBG_CIL, "device mode\n");
1529 + init_devspd(_core_if);
1532 + if (_core_if->core_params->i2c_enable) {
1533 + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
1534 + /* Program GUSBCFG.OtgUtmifsSel to I2C */
1535 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1536 + usbcfg.b.otgutmifssel = 1;
1537 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1539 + /* Program GI2CCTL.I2CEn */
1540 + i2cctl.d32 = dwc_read_reg32(&global_regs->gi2cctl);
1541 + i2cctl.b.i2cdevaddr = 1;
1542 + i2cctl.b.i2cen = 0;
1543 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
1544 + i2cctl.b.i2cen = 1;
1545 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
1548 + } /* endif speed == DWC_SPEED_PARAM_FULL */
1550 + /* High speed PHY. */
1551 + if (!_core_if->phy_init_done) {
1552 + _core_if->phy_init_done = 1;
1553 + DWC_DEBUGPL(DBG_CIL, "High spped PHY\n");
1554 + /* HS PHY parameters. These parameters are preserved
1555 + * during soft reset so only program the first time. Do
1556 + * a soft reset immediately after setting phyif. */
1557 + usbcfg.b.ulpi_utmi_sel = _core_if->core_params->phy_type;
1558 + if (usbcfg.b.ulpi_utmi_sel == 2) { // winder
1559 + DWC_DEBUGPL(DBG_CIL, "ULPI\n");
1560 + /* ULPI interface */
1561 + usbcfg.b.phyif = 0;
1562 + usbcfg.b.ddrsel = _core_if->core_params->phy_ulpi_ddr;
1564 + /* UTMI+ interface */
1565 + if (_core_if->core_params->phy_utmi_width == 16) {
1566 + usbcfg.b.phyif = 1;
1567 + DWC_DEBUGPL(DBG_CIL, "UTMI+ 16\n");
1569 + DWC_DEBUGPL(DBG_CIL, "UTMI+ 8\n");
1570 + usbcfg.b.phyif = 0;
1573 + dwc_write_reg32( &global_regs->gusbcfg, usbcfg.d32);
1575 + /* Reset after setting the PHY parameters */
1576 + dwc_otg_core_reset( _core_if );
1580 + if ((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1581 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1582 + (_core_if->core_params->ulpi_fs_ls))
1584 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
1585 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1586 + usbcfg.b.ulpi_fsls = 1;
1587 + usbcfg.b.ulpi_clk_sus_m = 1;
1588 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
1590 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS=0\n");
1591 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1592 + usbcfg.b.ulpi_fsls = 0;
1593 + usbcfg.b.ulpi_clk_sus_m = 0;
1594 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
1597 + /* Program the GAHBCFG Register.*/
1598 + switch (_core_if->hwcfg2.b.architecture){
1600 + case DWC_SLAVE_ONLY_ARCH:
1601 + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
1602 + ahbcfg.b.nptxfemplvl_txfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
1603 + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
1604 + _core_if->dma_enable = 0;
1607 + case DWC_EXT_DMA_ARCH:
1608 + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
1609 + ahbcfg.b.hburstlen = _core_if->core_params->dma_burst_size;
1610 + _core_if->dma_enable = (_core_if->core_params->dma_enable != 0);
1613 + case DWC_INT_DMA_ARCH:
1614 + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
1615 + //ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR;
1616 + ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR4;
1617 + _core_if->dma_enable = (_core_if->core_params->dma_enable != 0);
1620 + ahbcfg.b.dmaenable = _core_if->dma_enable;
1621 + dwc_write_reg32(&global_regs->gahbcfg, ahbcfg.d32);
1622 + _core_if->en_multiple_tx_fifo = _core_if->hwcfg4.b.ded_fifo_en;
1625 + * Program the GUSBCFG register.
1627 + usbcfg.d32 = dwc_read_reg32( &global_regs->gusbcfg );
1629 + switch (_core_if->hwcfg2.b.op_mode) {
1630 + case DWC_MODE_HNP_SRP_CAPABLE:
1631 + usbcfg.b.hnpcap = (_core_if->core_params->otg_cap ==
1632 + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
1633 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1634 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1637 + case DWC_MODE_SRP_ONLY_CAPABLE:
1638 + usbcfg.b.hnpcap = 0;
1639 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1640 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1643 + case DWC_MODE_NO_HNP_SRP_CAPABLE:
1644 + usbcfg.b.hnpcap = 0;
1645 + usbcfg.b.srpcap = 0;
1648 + case DWC_MODE_SRP_CAPABLE_DEVICE:
1649 + usbcfg.b.hnpcap = 0;
1650 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1651 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1654 + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
1655 + usbcfg.b.hnpcap = 0;
1656 + usbcfg.b.srpcap = 0;
1659 + case DWC_MODE_SRP_CAPABLE_HOST:
1660 + usbcfg.b.hnpcap = 0;
1661 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1662 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1665 + case DWC_MODE_NO_SRP_CAPABLE_HOST:
1666 + usbcfg.b.hnpcap = 0;
1667 + usbcfg.b.srpcap = 0;
1671 + dwc_write_reg32( &global_regs->gusbcfg, usbcfg.d32);
1673 + /* Enable common interrupts */
1674 + dwc_otg_enable_common_interrupts( _core_if );
1676 + /* Do device or host intialization based on mode during PCD
1677 + * and HCD initialization */
1678 + if (dwc_otg_is_host_mode( _core_if )) {
1679 + DWC_DEBUGPL(DBG_ANY, "Host Mode\n" );
1680 + _core_if->op_state = A_HOST;
1682 + DWC_DEBUGPL(DBG_ANY, "Device Mode\n" );
1683 + _core_if->op_state = B_PERIPHERAL;
1684 +#ifdef DWC_DEVICE_ONLY
1685 + dwc_otg_core_dev_init( _core_if );
1692 + * This function enables the Device mode interrupts.
1694 + * @param _core_if Programming view of DWC_otg controller
1696 +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if)
1698 + gintmsk_data_t intr_mask = { .d32 = 0};
1699 + dwc_otg_core_global_regs_t * global_regs = _core_if->core_global_regs;
1701 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
1703 + /* Disable all interrupts. */
1704 + dwc_write_reg32( &global_regs->gintmsk, 0);
1706 + /* Clear any pending interrupts */
1707 + dwc_write_reg32( &global_regs->gintsts, 0xFFFFFFFF);
1709 + /* Enable the common interrupts */
1710 + dwc_otg_enable_common_interrupts( _core_if );
1712 + /* Enable interrupts */
1713 + intr_mask.b.usbreset = 1;
1714 + intr_mask.b.enumdone = 1;
1715 + //intr_mask.b.epmismatch = 1;
1716 + intr_mask.b.inepintr = 1;
1717 + intr_mask.b.outepintr = 1;
1718 + intr_mask.b.erlysuspend = 1;
1719 + if (_core_if->en_multiple_tx_fifo == 0) {
1720 + intr_mask.b.epmismatch = 1;
1723 + /** @todo NGS: Should this be a module parameter? */
1724 + intr_mask.b.isooutdrop = 1;
1725 + intr_mask.b.eopframe = 1;
1726 + intr_mask.b.incomplisoin = 1;
1727 + intr_mask.b.incomplisoout = 1;
1729 + dwc_modify_reg32( &global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1731 + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
1732 + dwc_read_reg32( &global_regs->gintmsk));
1736 + * This function initializes the DWC_otg controller registers for
1739 + * @param _core_if Programming view of DWC_otg controller
1742 +void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if)
1744 + dwc_otg_core_global_regs_t *global_regs =
1745 + _core_if->core_global_regs;
1746 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1747 + dwc_otg_core_params_t *params = _core_if->core_params;
1748 + dcfg_data_t dcfg = {.d32 = 0};
1749 + grstctl_t resetctl = { .d32=0 };
1751 + uint32_t rx_fifo_size;
1752 + fifosize_data_t nptxfifosize;
1753 + fifosize_data_t txfifosize;
1754 + dthrctl_data_t dthrctl;
1756 + fifosize_data_t ptxfifosize;
1758 + /* Restart the Phy Clock */
1759 + dwc_write_reg32(_core_if->pcgcctl, 0);
1761 + /* Device configuration register */
1762 + init_devspd(_core_if);
1763 + dcfg.d32 = dwc_read_reg32( &dev_if->dev_global_regs->dcfg);
1764 + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
1765 + dwc_write_reg32( &dev_if->dev_global_regs->dcfg, dcfg.d32 );
1767 + /* Configure data FIFO sizes */
1768 + if ( _core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo ) {
1770 + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n", _core_if->total_fifo_size);
1771 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n", params->dev_rx_fifo_size);
1772 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n", params->dev_nperio_tx_fifo_size);
1775 + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
1776 + dwc_read_reg32(&global_regs->grxfsiz));
1777 + rx_fifo_size = params->dev_rx_fifo_size;
1778 + dwc_write_reg32( &global_regs->grxfsiz, rx_fifo_size );
1779 + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
1780 + dwc_read_reg32(&global_regs->grxfsiz));
1782 + /** Set Periodic Tx FIFO Mask all bits 0 */
1783 + _core_if->p_tx_msk = 0;
1785 + /** Set Tx FIFO Mask all bits 0 */
1786 + _core_if->tx_msk = 0;
1787 + if (_core_if->en_multiple_tx_fifo == 0) {
1788 + /* Non-periodic Tx FIFO */
1789 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
1790 + dwc_read_reg32(&global_regs->gnptxfsiz));
1791 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
1792 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
1793 + dwc_write_reg32( &global_regs->gnptxfsiz, nptxfifosize.d32 );
1794 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
1795 + dwc_read_reg32(&global_regs->gnptxfsiz));
1798 + /**@todo NGS: Fix Periodic FIFO Sizing! */
1800 + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
1801 + * Indexes of the FIFO size module parameters in the
1802 + * dev_perio_tx_fifo_size array and the FIFO size registers in
1803 + * the dptxfsiz array run from 0 to 14.
1805 + /** @todo Finish debug of this */
1806 + ptxfifosize.b.startaddr =
1807 + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
1808 + for (i = 0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep;i++) {
1809 + ptxfifosize.b.depth = params->dev_perio_tx_fifo_size[i];
1810 + DWC_DEBUGPL(DBG_CIL,"initial dptxfsiz_dieptxf[%d]=%08x\n",
1811 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1812 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i],ptxfifosize.d32);
1813 + DWC_DEBUGPL(DBG_CIL,"new dptxfsiz_dieptxf[%d]=%08x\n",
1814 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1815 + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
1820 + * Tx FIFOs These FIFOs are numbered from 1 to 15.
1821 + * Indexes of the FIFO size module parameters in the
1822 + * dev_tx_fifo_size array and the FIFO size registers in
1823 + * the dptxfsiz_dieptxf array run from 0 to 14.
1826 + /* Non-periodic Tx FIFO */
1827 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
1828 + dwc_read_reg32(&global_regs->gnptxfsiz));
1829 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
1830 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
1831 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
1832 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
1833 + dwc_read_reg32(&global_regs->gnptxfsiz));
1834 + txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
1835 + for (i = 1;i < _core_if->hwcfg4.b.num_dev_perio_in_ep;i++) {
1836 + txfifosize.b.depth = params->dev_tx_fifo_size[i];
1837 + DWC_DEBUGPL(DBG_CIL,"initial dptxfsiz_dieptxf[%d]=%08x\n",
1838 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1839 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i - 1],txfifosize.d32);
1840 + DWC_DEBUGPL(DBG_CIL,"new dptxfsiz_dieptxf[%d]=%08x\n",
1841 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i-1]));
1842 + txfifosize.b.startaddr += txfifosize.b.depth;
1846 + /* Flush the FIFOs */
1847 + dwc_otg_flush_tx_fifo(_core_if, 0x10); /* all Tx FIFOs */
1848 + dwc_otg_flush_rx_fifo(_core_if);
1850 + /* Flush the Learning Queue. */
1851 + resetctl.b.intknqflsh = 1;
1852 + dwc_write_reg32( &_core_if->core_global_regs->grstctl, resetctl.d32);
1854 + /* Clear all pending Device Interrupts */
1855 + dwc_write_reg32( &dev_if->dev_global_regs->diepmsk, 0 );
1856 + dwc_write_reg32( &dev_if->dev_global_regs->doepmsk, 0 );
1857 + dwc_write_reg32( &dev_if->dev_global_regs->daint, 0xFFFFFFFF );
1858 + dwc_write_reg32( &dev_if->dev_global_regs->daintmsk, 0 );
1860 + for (i = 0; i <= dev_if->num_in_eps; i++) {
1861 + depctl_data_t depctl;
1862 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
1863 + if (depctl.b.epena) {
1865 + depctl.b.epdis = 1;
1866 + depctl.b.snak = 1;
1870 + dwc_write_reg32( &dev_if->in_ep_regs[i]->diepctl, depctl.d32);
1872 + dwc_write_reg32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
1873 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepdma, 0);
1874 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
1876 + for (i = 0; i <= dev_if->num_out_eps; i++) {
1877 + depctl_data_t depctl;
1878 + depctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doepctl);
1879 + if (depctl.b.epena) {
1881 + depctl.b.epdis = 1;
1882 + depctl.b.snak = 1;
1886 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepctl, depctl.d32);
1888 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->dieptsiz, 0);
1889 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doeptsiz, 0);
1890 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->diepdma, 0);
1891 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepdma, 0);
1892 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->diepint, 0xFF);
1893 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepint, 0xFF);
1896 + if (_core_if->en_multiple_tx_fifo && _core_if->dma_enable) {
1897 + dev_if->non_iso_tx_thr_en = _core_if->core_params->thr_ctl & 0x1;
1898 + dev_if->iso_tx_thr_en = (_core_if->core_params->thr_ctl >> 1) & 0x1;
1899 + dev_if->rx_thr_en = (_core_if->core_params->thr_ctl >> 2) & 0x1;
1900 + dev_if->rx_thr_length = _core_if->core_params->rx_thr_length;
1901 + dev_if->tx_thr_length = _core_if->core_params->tx_thr_length;
1903 + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
1904 + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
1905 + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
1906 + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
1907 + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
1908 + dwc_write_reg32(&dev_if->dev_global_regs->dtknqr3_dthrctl,dthrctl.d32);
1909 + DWC_DEBUGPL(DBG_CIL, "Non ISO Tx Thr - %d\nISO Tx Thr - %d\n"
1910 + "Rx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
1911 + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
1912 + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
1913 + dthrctl.b.rx_thr_len);
1915 + dwc_otg_enable_device_interrupts( _core_if );
1917 + diepmsk_data_t msk = {.d32 = 0};
1918 + msk.b.txfifoundrn = 1;
1919 + dwc_modify_reg32(&dev_if->dev_global_regs->diepmsk, msk.d32,msk.d32);
1924 + * This function enables the Host mode interrupts.
1926 + * @param _core_if Programming view of DWC_otg controller
1928 +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if)
1930 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
1931 + gintmsk_data_t intr_mask = {.d32 = 0};
1933 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
1935 + /* Disable all interrupts. */
1936 + dwc_write_reg32(&global_regs->gintmsk, 0);
1938 + /* Clear any pending interrupts. */
1939 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
1941 + /* Enable the common interrupts */
1942 + dwc_otg_enable_common_interrupts(_core_if);
1945 + * Enable host mode interrupts without disturbing common
1948 + intr_mask.b.sofintr = 1;
1949 + intr_mask.b.portintr = 1;
1950 + intr_mask.b.hcintr = 1;
1952 + //dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1953 + //dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
1954 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1958 + * This function disables the Host Mode interrupts.
1960 + * @param _core_if Programming view of DWC_otg controller
1962 +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if)
1964 + dwc_otg_core_global_regs_t *global_regs =
1965 + _core_if->core_global_regs;
1966 + gintmsk_data_t intr_mask = {.d32 = 0};
1968 + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
1971 + * Disable host mode interrupts without disturbing common
1974 + intr_mask.b.sofintr = 1;
1975 + intr_mask.b.portintr = 1;
1976 + intr_mask.b.hcintr = 1;
1977 + intr_mask.b.ptxfempty = 1;
1978 + intr_mask.b.nptxfempty = 1;
1980 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
1984 +/* currently not used, keep it here as if needed later */
1985 +static int phy_read(dwc_otg_core_if_t * _core_if, int addr)
1990 + dwc_write_reg32(&_core_if->core_global_regs->gpvndctl,
1991 + 0x02000000 | (addr << 16));
1992 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1993 + while (((val & 0x08000000) == 0) && (timeout--)) {
1995 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1997 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1998 + printk("%s: addr=%02x regval=%02x\n", __func__, addr, val & 0x000000ff);
2005 + * This function initializes the DWC_otg controller registers for
2008 + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
2009 + * request queues. Host channels are reset to ensure that they are ready for
2010 + * performing transfers.
2012 + * @param _core_if Programming view of DWC_otg controller
2015 +void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if)
2017 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
2018 + dwc_otg_host_if_t *host_if = _core_if->host_if;
2019 + dwc_otg_core_params_t *params = _core_if->core_params;
2020 + hprt0_data_t hprt0 = {.d32 = 0};
2021 + fifosize_data_t nptxfifosize;
2022 + fifosize_data_t ptxfifosize;
2024 + hcchar_data_t hcchar;
2026 + dwc_otg_hc_regs_t *hc_regs;
2028 + gotgctl_data_t gotgctl = {.d32 = 0};
2030 + DWC_DEBUGPL(DBG_CILV,"%s(%p)\n", __func__, _core_if);
2032 + /* Restart the Phy Clock */
2033 + dwc_write_reg32(_core_if->pcgcctl, 0);
2035 + /* Initialize Host Configuration Register */
2036 + init_fslspclksel(_core_if);
2037 + if (_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
2038 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
2039 + hcfg.b.fslssupp = 1;
2040 + dwc_write_reg32(&host_if->host_global_regs->hcfg, hcfg.d32);
2043 + /* Configure data FIFO sizes */
2044 + if (_core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
2045 + DWC_DEBUGPL(DBG_CIL,"Total FIFO Size=%d\n", _core_if->total_fifo_size);
2046 + DWC_DEBUGPL(DBG_CIL,"Rx FIFO Size=%d\n", params->host_rx_fifo_size);
2047 + DWC_DEBUGPL(DBG_CIL,"NP Tx FIFO Size=%d\n", params->host_nperio_tx_fifo_size);
2048 + DWC_DEBUGPL(DBG_CIL,"P Tx FIFO Size=%d\n", params->host_perio_tx_fifo_size);
2051 + DWC_DEBUGPL(DBG_CIL,"initial grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
2052 + dwc_write_reg32(&global_regs->grxfsiz, params->host_rx_fifo_size);
2053 + DWC_DEBUGPL(DBG_CIL,"new grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
2055 + /* Non-periodic Tx FIFO */
2056 + DWC_DEBUGPL(DBG_CIL,"initial gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
2057 + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
2058 + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
2059 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
2060 + DWC_DEBUGPL(DBG_CIL,"new gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
2062 + /* Periodic Tx FIFO */
2063 + DWC_DEBUGPL(DBG_CIL,"initial hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
2064 + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
2065 + ptxfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
2066 + dwc_write_reg32(&global_regs->hptxfsiz, ptxfifosize.d32);
2067 + DWC_DEBUGPL(DBG_CIL,"new hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
2070 + /* Clear Host Set HNP Enable in the OTG Control Register */
2071 + gotgctl.b.hstsethnpen = 1;
2072 + dwc_modify_reg32( &global_regs->gotgctl, gotgctl.d32, 0);
2074 + /* Make sure the FIFOs are flushed. */
2075 + dwc_otg_flush_tx_fifo(_core_if, 0x10 /* all Tx FIFOs */);
2076 + dwc_otg_flush_rx_fifo(_core_if);
2078 + /* Flush out any leftover queued requests. */
2079 + num_channels = _core_if->core_params->host_channels;
2080 + for (i = 0; i < num_channels; i++) {
2081 + hc_regs = _core_if->host_if->hc_regs[i];
2082 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2083 + hcchar.b.chen = 0;
2084 + hcchar.b.chdis = 1;
2085 + hcchar.b.epdir = 0;
2086 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2089 + /* Halt all channels to put them into a known state. */
2090 + for (i = 0; i < num_channels; i++) {
2092 + hc_regs = _core_if->host_if->hc_regs[i];
2093 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2094 + hcchar.b.chen = 1;
2095 + hcchar.b.chdis = 1;
2096 + hcchar.b.epdir = 0;
2097 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2098 + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d\n", __func__, i);
2100 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2101 + if (++count > 200) {
2102 + DWC_ERROR("%s: Unable to clear halt on channel %d\n",
2107 + } while (hcchar.b.chen);
2110 + /* Turn on the vbus power. */
2111 + DWC_PRINT("Init: Port Power? op_state=%d\n", _core_if->op_state);
2112 + if (_core_if->op_state == A_HOST){
2113 + hprt0.d32 = dwc_otg_read_hprt0(_core_if);
2114 + DWC_PRINT("Init: Power Port (%d)\n", hprt0.b.prtpwr);
2115 + if (hprt0.b.prtpwr == 0 ) {
2116 + hprt0.b.prtpwr = 1;
2117 + dwc_write_reg32(host_if->hprt0, hprt0.d32);
2121 + dwc_otg_enable_host_interrupts( _core_if );
2125 + * Prepares a host channel for transferring packets to/from a specific
2126 + * endpoint. The HCCHARn register is set up with the characteristics specified
2127 + * in _hc. Host channel interrupts that may need to be serviced while this
2128 + * transfer is in progress are enabled.
2130 + * @param _core_if Programming view of DWC_otg controller
2131 + * @param _hc Information needed to initialize the host channel
2133 +void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2135 + uint32_t intr_enable;
2136 + hcintmsk_data_t hc_intr_mask;
2137 + gintmsk_data_t gintmsk = {.d32 = 0};
2138 + hcchar_data_t hcchar;
2139 + hcsplt_data_t hcsplt;
2141 + uint8_t hc_num = _hc->hc_num;
2142 + dwc_otg_host_if_t *host_if = _core_if->host_if;
2143 + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
2145 + /* Clear old interrupt conditions for this host channel. */
2146 + hc_intr_mask.d32 = 0xFFFFFFFF;
2147 + hc_intr_mask.b.reserved = 0;
2148 + dwc_write_reg32(&hc_regs->hcint, hc_intr_mask.d32);
2150 + /* Enable channel interrupts required for this transfer. */
2151 + hc_intr_mask.d32 = 0;
2152 + hc_intr_mask.b.chhltd = 1;
2153 + if (_core_if->dma_enable) {
2154 + hc_intr_mask.b.ahberr = 1;
2155 + if (_hc->error_state && !_hc->do_split &&
2156 + _hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
2157 + hc_intr_mask.b.ack = 1;
2158 + if (_hc->ep_is_in) {
2159 + hc_intr_mask.b.datatglerr = 1;
2160 + if (_hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
2161 + hc_intr_mask.b.nak = 1;
2166 + switch (_hc->ep_type) {
2167 + case DWC_OTG_EP_TYPE_CONTROL:
2168 + case DWC_OTG_EP_TYPE_BULK:
2169 + hc_intr_mask.b.xfercompl = 1;
2170 + hc_intr_mask.b.stall = 1;
2171 + hc_intr_mask.b.xacterr = 1;
2172 + hc_intr_mask.b.datatglerr = 1;
2173 + if (_hc->ep_is_in) {
2174 + hc_intr_mask.b.bblerr = 1;
2176 + hc_intr_mask.b.nak = 1;
2177 + hc_intr_mask.b.nyet = 1;
2178 + if (_hc->do_ping) {
2179 + hc_intr_mask.b.ack = 1;
2183 + if (_hc->do_split) {
2184 + hc_intr_mask.b.nak = 1;
2185 + if (_hc->complete_split) {
2186 + hc_intr_mask.b.nyet = 1;
2189 + hc_intr_mask.b.ack = 1;
2193 + if (_hc->error_state) {
2194 + hc_intr_mask.b.ack = 1;
2197 + case DWC_OTG_EP_TYPE_INTR:
2198 + hc_intr_mask.b.xfercompl = 1;
2199 + hc_intr_mask.b.nak = 1;
2200 + hc_intr_mask.b.stall = 1;
2201 + hc_intr_mask.b.xacterr = 1;
2202 + hc_intr_mask.b.datatglerr = 1;
2203 + hc_intr_mask.b.frmovrun = 1;
2205 + if (_hc->ep_is_in) {
2206 + hc_intr_mask.b.bblerr = 1;
2208 + if (_hc->error_state) {
2209 + hc_intr_mask.b.ack = 1;
2211 + if (_hc->do_split) {
2212 + if (_hc->complete_split) {
2213 + hc_intr_mask.b.nyet = 1;
2216 + hc_intr_mask.b.ack = 1;
2220 + case DWC_OTG_EP_TYPE_ISOC:
2221 + hc_intr_mask.b.xfercompl = 1;
2222 + hc_intr_mask.b.frmovrun = 1;
2223 + hc_intr_mask.b.ack = 1;
2225 + if (_hc->ep_is_in) {
2226 + hc_intr_mask.b.xacterr = 1;
2227 + hc_intr_mask.b.bblerr = 1;
2232 + dwc_write_reg32(&hc_regs->hcintmsk, hc_intr_mask.d32);
2234 + /* Enable the top level host channel interrupt. */
2235 + intr_enable = (1 << hc_num);
2236 + dwc_modify_reg32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
2238 + /* Make sure host channel interrupts are enabled. */
2239 + gintmsk.b.hcintr = 1;
2240 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
2243 + * Program the HCCHARn register with the endpoint characteristics for
2244 + * the current transfer.
2247 + hcchar.b.devaddr = _hc->dev_addr;
2248 + hcchar.b.epnum = _hc->ep_num;
2249 + hcchar.b.epdir = _hc->ep_is_in;
2250 + hcchar.b.lspddev = (_hc->speed == DWC_OTG_EP_SPEED_LOW);
2251 + hcchar.b.eptype = _hc->ep_type;
2252 + hcchar.b.mps = _hc->max_packet;
2254 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
2256 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2257 + DWC_DEBUGPL(DBG_HCDV, " Dev Addr: %d\n", hcchar.b.devaddr);
2258 + DWC_DEBUGPL(DBG_HCDV, " Ep Num: %d\n", hcchar.b.epnum);
2259 + DWC_DEBUGPL(DBG_HCDV, " Is In: %d\n", hcchar.b.epdir);
2260 + DWC_DEBUGPL(DBG_HCDV, " Is Low Speed: %d\n", hcchar.b.lspddev);
2261 + DWC_DEBUGPL(DBG_HCDV, " Ep Type: %d\n", hcchar.b.eptype);
2262 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
2263 + DWC_DEBUGPL(DBG_HCDV, " Multi Cnt: %d\n", hcchar.b.multicnt);
2266 + * Program the HCSPLIT register for SPLITs
2269 + if (_hc->do_split) {
2270 + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n", _hc->hc_num,
2271 + _hc->complete_split ? "CSPLIT" : "SSPLIT");
2272 + hcsplt.b.compsplt = _hc->complete_split;
2273 + hcsplt.b.xactpos = _hc->xact_pos;
2274 + hcsplt.b.hubaddr = _hc->hub_addr;
2275 + hcsplt.b.prtaddr = _hc->port_addr;
2276 + DWC_DEBUGPL(DBG_HCDV, " comp split %d\n", _hc->complete_split);
2277 + DWC_DEBUGPL(DBG_HCDV, " xact pos %d\n", _hc->xact_pos);
2278 + DWC_DEBUGPL(DBG_HCDV, " hub addr %d\n", _hc->hub_addr);
2279 + DWC_DEBUGPL(DBG_HCDV, " port addr %d\n", _hc->port_addr);
2280 + DWC_DEBUGPL(DBG_HCDV, " is_in %d\n", _hc->ep_is_in);
2281 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
2282 + DWC_DEBUGPL(DBG_HCDV, " xferlen: %d\n", _hc->xfer_len);
2284 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
2289 + * Attempts to halt a host channel. This function should only be called in
2290 + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
2291 + * normal circumstances in DMA mode, the controller halts the channel when the
2292 + * transfer is complete or a condition occurs that requires application
2295 + * In slave mode, checks for a free request queue entry, then sets the Channel
2296 + * Enable and Channel Disable bits of the Host Channel Characteristics
2297 + * register of the specified channel to intiate the halt. If there is no free
2298 + * request queue entry, sets only the Channel Disable bit of the HCCHARn
2299 + * register to flush requests for this channel. In the latter case, sets a
2300 + * flag to indicate that the host channel needs to be halted when a request
2301 + * queue slot is open.
2303 + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
2304 + * HCCHARn register. The controller ensures there is space in the request
2305 + * queue before submitting the halt request.
2307 + * Some time may elapse before the core flushes any posted requests for this
2308 + * host channel and halts. The Channel Halted interrupt handler completes the
2309 + * deactivation of the host channel.
2311 + * @param _core_if Controller register interface.
2312 + * @param _hc Host channel to halt.
2313 + * @param _halt_status Reason for halting the channel.
2315 +void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
2317 + dwc_otg_halt_status_e _halt_status)
2319 + gnptxsts_data_t nptxsts;
2320 + hptxsts_data_t hptxsts;
2321 + hcchar_data_t hcchar;
2322 + dwc_otg_hc_regs_t *hc_regs;
2323 + dwc_otg_core_global_regs_t *global_regs;
2324 + dwc_otg_host_global_regs_t *host_global_regs;
2326 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2327 + global_regs = _core_if->core_global_regs;
2328 + host_global_regs = _core_if->host_if->host_global_regs;
2330 + WARN_ON(_halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS);
2332 + if (_halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
2333 + _halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
2335 + * Disable all channel interrupts except Ch Halted. The QTD
2336 + * and QH state associated with this transfer has been cleared
2337 + * (in the case of URB_DEQUEUE), so the channel needs to be
2338 + * shut down carefully to prevent crashes.
2340 + hcintmsk_data_t hcintmsk;
2342 + hcintmsk.b.chhltd = 1;
2343 + dwc_write_reg32(&hc_regs->hcintmsk, hcintmsk.d32);
2346 + * Make sure no other interrupts besides halt are currently
2347 + * pending. Handling another interrupt could cause a crash due
2348 + * to the QTD and QH state.
2350 + dwc_write_reg32(&hc_regs->hcint, ~hcintmsk.d32);
2353 + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
2354 + * even if the channel was already halted for some other
2357 + _hc->halt_status = _halt_status;
2359 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2360 + if (hcchar.b.chen == 0) {
2362 + * The channel is either already halted or it hasn't
2363 + * started yet. In DMA mode, the transfer may halt if
2364 + * it finishes normally or a condition occurs that
2365 + * requires driver intervention. Don't want to halt
2366 + * the channel again. In either Slave or DMA mode,
2367 + * it's possible that the transfer has been assigned
2368 + * to a channel, but not started yet when an URB is
2369 + * dequeued. Don't want to halt a channel that hasn't
2376 + if (_hc->halt_pending) {
2378 + * A halt has already been issued for this channel. This might
2379 + * happen when a transfer is aborted by a higher level in
2383 + DWC_PRINT("*** %s: Channel %d, _hc->halt_pending already set ***\n",
2384 + __func__, _hc->hc_num);
2386 +/* dwc_otg_dump_global_registers(_core_if); */
2387 +/* dwc_otg_dump_host_registers(_core_if); */
2392 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2393 + hcchar.b.chen = 1;
2394 + hcchar.b.chdis = 1;
2396 + if (!_core_if->dma_enable) {
2397 + /* Check for space in the request queue to issue the halt. */
2398 + if (_hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
2399 + _hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
2400 + nptxsts.d32 = dwc_read_reg32(&global_regs->gnptxsts);
2401 + if (nptxsts.b.nptxqspcavail == 0) {
2402 + hcchar.b.chen = 0;
2405 + hptxsts.d32 = dwc_read_reg32(&host_global_regs->hptxsts);
2406 + if ((hptxsts.b.ptxqspcavail == 0) || (_core_if->queuing_high_bandwidth)) {
2407 + hcchar.b.chen = 0;
2412 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2414 + _hc->halt_status = _halt_status;
2416 + if (hcchar.b.chen) {
2417 + _hc->halt_pending = 1;
2418 + _hc->halt_on_queue = 0;
2420 + _hc->halt_on_queue = 1;
2423 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2424 + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
2425 + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", _hc->halt_pending);
2426 + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", _hc->halt_on_queue);
2427 + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", _hc->halt_status);
2433 + * Clears the transfer state for a host channel. This function is normally
2434 + * called after a transfer is done and the host channel is being released.
2436 + * @param _core_if Programming view of DWC_otg controller.
2437 + * @param _hc Identifies the host channel to clean up.
2439 +void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2441 + dwc_otg_hc_regs_t *hc_regs;
2443 + _hc->xfer_started = 0;
2446 + * Clear channel interrupt enables and any unhandled channel interrupt
2449 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2450 + dwc_write_reg32(&hc_regs->hcintmsk, 0);
2451 + dwc_write_reg32(&hc_regs->hcint, 0xFFFFFFFF);
2454 + del_timer(&_core_if->hc_xfer_timer[_hc->hc_num]);
2456 + hcchar_data_t hcchar;
2457 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2458 + if (hcchar.b.chdis) {
2459 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
2460 + __func__, _hc->hc_num, hcchar.d32);
2467 + * Sets the channel property that indicates in which frame a periodic transfer
2468 + * should occur. This is always set to the _next_ frame. This function has no
2469 + * effect on non-periodic transfers.
2471 + * @param _core_if Programming view of DWC_otg controller.
2472 + * @param _hc Identifies the host channel to set up and its properties.
2473 + * @param _hcchar Current value of the HCCHAR register for the specified host
2476 +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t *_core_if,
2478 + hcchar_data_t *_hcchar)
2480 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2481 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2482 + hfnum_data_t hfnum;
2483 + hfnum.d32 = dwc_read_reg32(&_core_if->host_if->host_global_regs->hfnum);
2484 + /* 1 if _next_ frame is odd, 0 if it's even */
2485 + _hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
2487 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR && _hc->do_split && !_hc->complete_split) {
2488 + switch (hfnum.b.frnum & 0x7) {
2490 + _core_if->hfnum_7_samples++;
2491 + _core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
2494 + _core_if->hfnum_0_samples++;
2495 + _core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
2498 + _core_if->hfnum_other_samples++;
2499 + _core_if->hfnum_other_frrem_accum += hfnum.b.frrem;
2508 +static void hc_xfer_timeout(unsigned long _ptr)
2510 + hc_xfer_info_t *xfer_info = (hc_xfer_info_t *)_ptr;
2511 + int hc_num = xfer_info->hc->hc_num;
2512 + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
2513 + DWC_WARN(" start_hcchar_val 0x%08x\n", xfer_info->core_if->start_hcchar_val[hc_num]);
2518 + * This function does the setup for a data transfer for a host channel and
2519 + * starts the transfer. May be called in either Slave mode or DMA mode. In
2520 + * Slave mode, the caller must ensure that there is sufficient space in the
2521 + * request queue and Tx Data FIFO.
2523 + * For an OUT transfer in Slave mode, it loads a data packet into the
2524 + * appropriate FIFO. If necessary, additional data packets will be loaded in
2527 + * For an IN transfer in Slave mode, a data packet is requested. The data
2528 + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
2529 + * additional data packets are requested in the Host ISR.
2531 + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
2532 + * register along with a packet count of 1 and the channel is enabled. This
2533 + * causes a single PING transaction to occur. Other fields in HCTSIZ are
2534 + * simply set to 0 since no data transfer occurs in this case.
2536 + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
2537 + * all the information required to perform the subsequent data transfer. In
2538 + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
2539 + * controller performs the entire PING protocol, then starts the data
2542 + * @param _core_if Programming view of DWC_otg controller.
2543 + * @param _hc Information needed to initialize the host channel. The xfer_len
2544 + * value may be reduced to accommodate the max widths of the XferSize and
2545 + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
2546 + * to reflect the final xfer_len value.
2548 +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2550 + hcchar_data_t hcchar;
2551 + hctsiz_data_t hctsiz;
2552 + uint16_t num_packets;
2553 + uint32_t max_hc_xfer_size = _core_if->core_params->max_transfer_size;
2554 + uint16_t max_hc_pkt_count = _core_if->core_params->max_packet_count;
2555 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2559 + if (_hc->do_ping) {
2560 + if (!_core_if->dma_enable) {
2561 + dwc_otg_hc_do_ping(_core_if, _hc);
2562 + _hc->xfer_started = 1;
2565 + hctsiz.b.dopng = 1;
2569 + if (_hc->do_split) {
2572 + if (_hc->complete_split && !_hc->ep_is_in) {
2573 + /* For CSPLIT OUT Transfer, set the size to 0 so the
2574 + * core doesn't expect any data written to the FIFO */
2575 + _hc->xfer_len = 0;
2576 + } else if (_hc->ep_is_in || (_hc->xfer_len > _hc->max_packet)) {
2577 + _hc->xfer_len = _hc->max_packet;
2578 + } else if (!_hc->ep_is_in && (_hc->xfer_len > 188)) {
2579 + _hc->xfer_len = 188;
2582 + hctsiz.b.xfersize = _hc->xfer_len;
2585 + * Ensure that the transfer length and packet count will fit
2586 + * in the widths allocated for them in the HCTSIZn register.
2588 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2589 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2591 + * Make sure the transfer size is no larger than one
2592 + * (micro)frame's worth of data. (A check was done
2593 + * when the periodic transfer was accepted to ensure
2594 + * that a (micro)frame's worth of data can be
2595 + * programmed into a channel.)
2597 + uint32_t max_periodic_len = _hc->multi_count * _hc->max_packet;
2598 + if (_hc->xfer_len > max_periodic_len) {
2599 + _hc->xfer_len = max_periodic_len;
2602 + } else if (_hc->xfer_len > max_hc_xfer_size) {
2603 + /* Make sure that xfer_len is a multiple of max packet size. */
2604 + _hc->xfer_len = max_hc_xfer_size - _hc->max_packet + 1;
2607 + if (_hc->xfer_len > 0) {
2608 + num_packets = (_hc->xfer_len + _hc->max_packet - 1) / _hc->max_packet;
2609 + if (num_packets > max_hc_pkt_count) {
2610 + num_packets = max_hc_pkt_count;
2611 + _hc->xfer_len = num_packets * _hc->max_packet;
2614 + /* Need 1 packet for transfer length of 0. */
2618 + if (_hc->ep_is_in) {
2619 + /* Always program an integral # of max packets for IN transfers. */
2620 + _hc->xfer_len = num_packets * _hc->max_packet;
2623 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2624 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2626 + * Make sure that the multi_count field matches the
2627 + * actual transfer length.
2629 + _hc->multi_count = num_packets;
2633 + if (_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2634 + /* Set up the initial PID for the transfer. */
2635 + if (_hc->speed == DWC_OTG_EP_SPEED_HIGH) {
2636 + if (_hc->ep_is_in) {
2637 + if (_hc->multi_count == 1) {
2638 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2639 + } else if (_hc->multi_count == 2) {
2640 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
2642 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
2645 + if (_hc->multi_count == 1) {
2646 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2648 + _hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
2652 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2656 + hctsiz.b.xfersize = _hc->xfer_len;
2659 + _hc->start_pkt_count = num_packets;
2660 + hctsiz.b.pktcnt = num_packets;
2661 + hctsiz.b.pid = _hc->data_pid_start;
2662 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2664 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2665 + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
2666 + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
2667 + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
2669 + if (_core_if->dma_enable) {
2671 +if(((uint32_t)_hc->xfer_buff)%4)
2672 +printk("dwc_otg_hc_start_transfer _hc->xfer_buff not 4 byte alignment\n");
2674 + dwc_write_reg32(&hc_regs->hcdma, (uint32_t)_hc->xfer_buff);
2677 + /* Start the split */
2678 + if (_hc->do_split) {
2679 + hcsplt_data_t hcsplt;
2680 + hcsplt.d32 = dwc_read_reg32 (&hc_regs->hcsplt);
2681 + hcsplt.b.spltena = 1;
2682 + dwc_write_reg32(&hc_regs->hcsplt, hcsplt.d32);
2685 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2686 + hcchar.b.multicnt = _hc->multi_count;
2687 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2689 + _core_if->start_hcchar_val[_hc->hc_num] = hcchar.d32;
2690 + if (hcchar.b.chdis) {
2691 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
2692 + __func__, _hc->hc_num, hcchar.d32);
2696 + /* Set host channel enable after all other setup is complete. */
2697 + hcchar.b.chen = 1;
2698 + hcchar.b.chdis = 0;
2699 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2701 + _hc->xfer_started = 1;
2704 + if (!_core_if->dma_enable && !_hc->ep_is_in && _hc->xfer_len > 0) {
2705 + /* Load OUT packet into the appropriate Tx FIFO. */
2706 + dwc_otg_hc_write_packet(_core_if, _hc);
2710 + /* Start a timer for this transfer. */
2711 + _core_if->hc_xfer_timer[_hc->hc_num].function = hc_xfer_timeout;
2712 + _core_if->hc_xfer_info[_hc->hc_num].core_if = _core_if;
2713 + _core_if->hc_xfer_info[_hc->hc_num].hc = _hc;
2714 + _core_if->hc_xfer_timer[_hc->hc_num].data = (unsigned long)(&_core_if->hc_xfer_info[_hc->hc_num]);
2715 + _core_if->hc_xfer_timer[_hc->hc_num].expires = jiffies + (HZ*10);
2716 + add_timer(&_core_if->hc_xfer_timer[_hc->hc_num]);
2721 + * This function continues a data transfer that was started by previous call
2722 + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
2723 + * sufficient space in the request queue and Tx Data FIFO. This function
2724 + * should only be called in Slave mode. In DMA mode, the controller acts
2725 + * autonomously to complete transfers programmed to a host channel.
2727 + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
2728 + * if there is any data remaining to be queued. For an IN transfer, another
2729 + * data packet is always requested. For the SETUP phase of a control transfer,
2730 + * this function does nothing.
2732 + * @return 1 if a new request is queued, 0 if no more requests are required
2733 + * for this transfer.
2735 +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2737 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2739 + if (_hc->do_split) {
2740 + /* SPLITs always queue just once per channel */
2742 + } else if (_hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
2743 + /* SETUPs are queued only once since they can't be NAKed. */
2745 + } else if (_hc->ep_is_in) {
2747 + * Always queue another request for other IN transfers. If
2748 + * back-to-back INs are issued and NAKs are received for both,
2749 + * the driver may still be processing the first NAK when the
2750 + * second NAK is received. When the interrupt handler clears
2751 + * the NAK interrupt for the first NAK, the second NAK will
2752 + * not be seen. So we can't depend on the NAK interrupt
2753 + * handler to requeue a NAKed request. Instead, IN requests
2754 + * are issued each time this function is called. When the
2755 + * transfer completes, the extra requests for the channel will
2758 + hcchar_data_t hcchar;
2759 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2761 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2762 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2763 + hcchar.b.chen = 1;
2764 + hcchar.b.chdis = 0;
2765 + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n", hcchar.d32);
2766 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2770 + /* OUT transfers. */
2771 + if (_hc->xfer_count < _hc->xfer_len) {
2772 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2773 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2774 + hcchar_data_t hcchar;
2775 + dwc_otg_hc_regs_t *hc_regs;
2776 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2777 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2778 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2781 + /* Load OUT packet into the appropriate Tx FIFO. */
2782 + dwc_otg_hc_write_packet(_core_if, _hc);
2792 + * Starts a PING transfer. This function should only be called in Slave mode.
2793 + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
2795 +void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2797 + hcchar_data_t hcchar;
2798 + hctsiz_data_t hctsiz;
2799 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2801 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2804 + hctsiz.b.dopng = 1;
2805 + hctsiz.b.pktcnt = 1;
2806 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2808 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2809 + hcchar.b.chen = 1;
2810 + hcchar.b.chdis = 0;
2811 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2815 + * This function writes a packet into the Tx FIFO associated with the Host
2816 + * Channel. For a channel associated with a non-periodic EP, the non-periodic
2817 + * Tx FIFO is written. For a channel associated with a periodic EP, the
2818 + * periodic Tx FIFO is written. This function should only be called in Slave
2821 + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
2822 + * then number of bytes written to the Tx FIFO.
2824 +void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2827 + uint32_t remaining_count;
2828 + uint32_t byte_count;
2829 + uint32_t dword_count;
2831 + uint32_t *data_buff = (uint32_t *)(_hc->xfer_buff);
2832 + uint32_t *data_fifo = _core_if->data_fifo[_hc->hc_num];
2834 + remaining_count = _hc->xfer_len - _hc->xfer_count;
2835 + if (remaining_count > _hc->max_packet) {
2836 + byte_count = _hc->max_packet;
2838 + byte_count = remaining_count;
2841 + dword_count = (byte_count + 3) / 4;
2843 + if ((((unsigned long)data_buff) & 0x3) == 0) {
2844 + /* xfer_buff is DWORD aligned. */
2845 + for (i = 0; i < dword_count; i++, data_buff++) {
2846 + dwc_write_reg32(data_fifo, *data_buff);
2849 + /* xfer_buff is not DWORD aligned. */
2850 + for (i = 0; i < dword_count; i++, data_buff++) {
2851 + dwc_write_reg32(data_fifo, get_unaligned(data_buff));
2855 + _hc->xfer_count += byte_count;
2856 + _hc->xfer_buff += byte_count;
2860 + * Gets the current USB frame number. This is the frame number from the last
2863 +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if)
2866 + dsts.d32 = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->dsts);
2868 + /* read current frame/microfreme number from DSTS register */
2869 + return dsts.b.soffn;
2873 + * This function reads a setup packet from the Rx FIFO into the destination
2874 + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
2875 + * Interrupt routine when a SETUP packet has been received in Slave mode.
2877 + * @param _core_if Programming view of DWC_otg controller.
2878 + * @param _dest Destination buffer for packet data.
2880 +void dwc_otg_read_setup_packet(dwc_otg_core_if_t *_core_if, uint32_t *_dest)
2882 + /* Get the 8 bytes of a setup transaction data */
2884 + /* Pop 2 DWORDS off the receive data FIFO into memory */
2885 + _dest[0] = dwc_read_reg32(_core_if->data_fifo[0]);
2886 + _dest[1] = dwc_read_reg32(_core_if->data_fifo[0]);
2887 + //_dest[0] = dwc_read_datafifo32(_core_if->data_fifo[0]);
2888 + //_dest[1] = dwc_read_datafifo32(_core_if->data_fifo[0]);
2893 + * This function enables EP0 OUT to receive SETUP packets and configures EP0
2894 + * IN for transmitting packets. It is normally called when the
2895 + * "Enumeration Done" interrupt occurs.
2897 + * @param _core_if Programming view of DWC_otg controller.
2898 + * @param _ep The EP0 data.
2900 +void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2902 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
2904 + depctl_data_t diepctl;
2905 + depctl_data_t doepctl;
2906 + dctl_data_t dctl ={.d32=0};
2908 + /* Read the Device Status and Endpoint 0 Control registers */
2909 + dsts.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dsts);
2910 + diepctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl);
2911 + doepctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl);
2913 + /* Set the MPS of the IN EP based on the enumeration speed */
2914 + switch (dsts.b.enumspd) {
2915 + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
2916 + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
2917 + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
2918 + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
2920 + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
2921 + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
2925 + dwc_write_reg32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
2927 + /* Enable OUT EP for receive */
2928 + doepctl.b.epena = 1;
2929 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
2932 + DWC_DEBUGPL(DBG_PCDV,"doepctl0=%0x\n",
2933 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
2934 + DWC_DEBUGPL(DBG_PCDV,"diepctl0=%0x\n",
2935 + dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl));
2937 + dctl.b.cgnpinnak = 1;
2938 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
2939 + DWC_DEBUGPL(DBG_PCDV,"dctl=%0x\n",
2940 + dwc_read_reg32(&dev_if->dev_global_regs->dctl));
2944 + * This function activates an EP. The Device EP control register for
2945 + * the EP is configured as defined in the ep structure. Note: This
2946 + * function is not used for EP0.
2948 + * @param _core_if Programming view of DWC_otg controller.
2949 + * @param _ep The EP to activate.
2951 +void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2953 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
2954 + depctl_data_t depctl;
2955 + volatile uint32_t *addr;
2956 + daint_data_t daintmsk = {.d32=0};
2958 + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, _ep->num,
2959 + (_ep->is_in?"IN":"OUT"));
2961 + /* Read DEPCTLn register */
2962 + if (_ep->is_in == 1) {
2963 + addr = &dev_if->in_ep_regs[_ep->num]->diepctl;
2964 + daintmsk.ep.in = 1<<_ep->num;
2966 + addr = &dev_if->out_ep_regs[_ep->num]->doepctl;
2967 + daintmsk.ep.out = 1<<_ep->num;
2970 + /* If the EP is already active don't change the EP Control
2972 + depctl.d32 = dwc_read_reg32(addr);
2973 + if (!depctl.b.usbactep) {
2974 + depctl.b.mps = _ep->maxpacket;
2975 + depctl.b.eptype = _ep->type;
2976 + depctl.b.txfnum = _ep->tx_fifo_num;
2978 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
2979 + depctl.b.setd0pid = 1; // ???
2981 + depctl.b.setd0pid = 1;
2983 + depctl.b.usbactep = 1;
2985 + dwc_write_reg32(addr, depctl.d32);
2986 + DWC_DEBUGPL(DBG_PCDV,"DEPCTL=%08x\n", dwc_read_reg32(addr));
2990 + /* Enable the Interrupt for this EP */
2991 + dwc_modify_reg32(&dev_if->dev_global_regs->daintmsk,
2993 + DWC_DEBUGPL(DBG_PCDV,"DAINTMSK=%0x\n",
2994 + dwc_read_reg32(&dev_if->dev_global_regs->daintmsk));
2995 + _ep->stall_clear_flag = 0;
3000 + * This function deactivates an EP. This is done by clearing the USB Active
3001 + * EP bit in the Device EP control register. Note: This function is not used
3002 + * for EP0. EP0 cannot be deactivated.
3004 + * @param _core_if Programming view of DWC_otg controller.
3005 + * @param _ep The EP to deactivate.
3007 +void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3009 + depctl_data_t depctl ={.d32 = 0};
3010 + volatile uint32_t *addr;
3011 + daint_data_t daintmsk = {.d32=0};
3013 + /* Read DEPCTLn register */
3014 + if (_ep->is_in == 1) {
3015 + addr = &_core_if->dev_if->in_ep_regs[_ep->num]->diepctl;
3016 + daintmsk.ep.in = 1<<_ep->num;
3018 + addr = &_core_if->dev_if->out_ep_regs[_ep->num]->doepctl;
3019 + daintmsk.ep.out = 1<<_ep->num;
3022 + depctl.b.usbactep = 0;
3023 + dwc_write_reg32(addr, depctl.d32);
3025 + /* Disable the Interrupt for this EP */
3026 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->daintmsk,
3033 + * This function does the setup for a data transfer for an EP and
3034 + * starts the transfer. For an IN transfer, the packets will be
3035 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
3036 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
3038 + * @param _core_if Programming view of DWC_otg controller.
3039 + * @param _ep The EP to start the transfer on.
3041 +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3043 + /** @todo Refactor this funciton to check the transfer size
3044 + * count value does not execed the number bits in the Transfer
3045 + * count register. */
3046 + depctl_data_t depctl;
3047 + deptsiz_data_t deptsiz;
3048 + gintmsk_data_t intr_mask = { .d32 = 0};
3050 +#ifdef CHECK_PACKET_COUNTER_WIDTH
3051 + const uint32_t MAX_XFER_SIZE =
3052 + _core_if->core_params->max_transfer_size;
3053 + const uint32_t MAX_PKT_COUNT =
3054 + _core_if->core_params->max_packet_count;
3055 + uint32_t num_packets;
3056 + uint32_t transfer_len;
3057 + dwc_otg_dev_out_ep_regs_t *out_regs =
3058 + _core_if->dev_if->out_ep_regs[_ep->num];
3059 + dwc_otg_dev_in_ep_regs_t *in_regs =
3060 + _core_if->dev_if->in_ep_regs[_ep->num];
3061 + gnptxsts_data_t txstatus;
3063 + int lvl = SET_DEBUG_LEVEL(DBG_PCD);
3066 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3067 + "xfer_buff=%p start_xfer_buff=%p\n",
3068 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3069 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff);
3071 + transfer_len = _ep->xfer_len - _ep->xfer_count;
3072 + if (transfer_len > MAX_XFER_SIZE) {
3073 + transfer_len = MAX_XFER_SIZE;
3075 + if (transfer_len == 0) {
3077 + /* OUT EP to recieve Zero-length packet set transfer
3078 + * size to maxpacket size. */
3079 + if (!_ep->is_in) {
3080 + transfer_len = _ep->maxpacket;
3084 + (transfer_len + _ep->maxpacket - 1) / _ep->maxpacket;
3085 + if (num_packets > MAX_PKT_COUNT) {
3086 + num_packets = MAX_PKT_COUNT;
3089 + DWC_DEBUGPL(DBG_PCD, "transfer_len=%d #pckt=%d\n", transfer_len,
3092 + deptsiz.b.xfersize = transfer_len;
3093 + deptsiz.b.pktcnt = num_packets;
3096 + if (_ep->is_in == 1) {
3097 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3098 + } else {/* OUT endpoint */
3099 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
3102 + /* EP enable, IN data in FIFO */
3103 + depctl.b.cnak = 1;
3104 + depctl.b.epena = 1;
3106 + if (_ep->is_in == 1) {
3108 + dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3109 + if (txstatus.b.nptxqspcavail == 0) {
3110 + DWC_DEBUGPL(DBG_ANY, "TX Queue Full (0x%0x)\n",
3114 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3115 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3117 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3118 + * data will be written into the fifo by the ISR.
3120 + if (_core_if->dma_enable) {
3121 + dwc_write_reg32(&in_regs->diepdma, (uint32_t) _ep->xfer_buff);
3123 + if (_core_if->en_multiple_tx_fifo == 0) {
3124 + intr_mask.b.nptxfempty = 1;
3125 + dwc_modify_reg32( &_core_if->core_global_regs->gintsts,
3126 + intr_mask.d32, 0);
3127 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3128 + intr_mask.d32, intr_mask.d32);
3130 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3131 + if (_ep->xfer_len > 0 &&
3132 + _ep->type != DWC_OTG_EP_TYPE_ISOC) {
3133 + uint32_t fifoemptymsk = 0;
3134 + fifoemptymsk = (0x1 << _ep->num);
3135 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->
3136 + dtknqr4_fifoemptymsk,0, fifoemptymsk);
3140 + } else { /* OUT endpoint */
3141 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3142 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
3143 + if (_core_if->dma_enable) {
3144 + dwc_write_reg32(&out_regs->doepdma,(uint32_t) _ep->xfer_buff);
3147 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
3148 + dwc_read_reg32(&out_regs->doepctl),
3149 + dwc_read_reg32(&out_regs->doeptsiz));
3150 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
3151 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk),
3152 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
3154 + SET_DEBUG_LEVEL(lvl);
3156 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
3158 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3159 + "xfer_buff=%p start_xfer_buff=%p\n",
3160 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3161 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff);
3164 + if (_ep->is_in == 1) {
3165 + dwc_otg_dev_in_ep_regs_t * in_regs = _core_if->dev_if->in_ep_regs[_ep->num];
3166 + gnptxsts_data_t gtxstatus;
3167 + gtxstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3168 + if (_core_if->en_multiple_tx_fifo == 0 &&
3169 + gtxstatus.b.nptxqspcavail == 0) {
3171 + DWC_PRINT("TX Queue Full (0x%0x)\n", gtxstatus.d32);
3174 + MDELAY(100); //james
3177 + depctl.d32 = dwc_read_reg32(&(in_regs->diepctl));
3178 + deptsiz.d32 = dwc_read_reg32(&(in_regs->dieptsiz));
3180 + /* Zero Length Packet? */
3181 + if (_ep->xfer_len == 0) {
3182 + deptsiz.b.xfersize = 0;
3183 + deptsiz.b.pktcnt = 1;
3186 + /* Program the transfer size and packet count
3187 + * as follows: xfersize = N * maxpacket +
3188 + * short_packet pktcnt = N + (short_packet
3191 + deptsiz.b.xfersize = _ep->xfer_len;
3192 + deptsiz.b.pktcnt = (_ep->xfer_len - 1 + _ep->maxpacket) / _ep->maxpacket;
3195 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3197 + /* Write the DMA register */
3198 + if (_core_if->dma_enable) {
3200 + dma_cache_wback_inv((unsigned long) _ep->xfer_buff, _ep->xfer_len); // winder
3201 + dwc_write_reg32 (&(in_regs->diepdma),
3202 + CPHYSADDR((uint32_t)_ep->xfer_buff)); // winder
3204 + dwc_write_reg32 (&(in_regs->diepdma),
3205 + (uint32_t)_ep->dma_addr);
3208 + if (_ep->type != DWC_OTG_EP_TYPE_ISOC) {
3210 + * Enable the Non-Periodic Tx FIFO empty interrupt,
3211 + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
3212 + * the data will be written into the fifo by the ISR.
3214 + if (_core_if->en_multiple_tx_fifo == 0) {
3215 + intr_mask.b.nptxfempty = 1;
3216 + dwc_modify_reg32( &_core_if->core_global_regs->gintsts,
3217 + intr_mask.d32, 0);
3218 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3219 + intr_mask.d32, intr_mask.d32);
3221 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3222 + if (_ep->xfer_len > 0) {
3223 + uint32_t fifoemptymsk = 0;
3224 + fifoemptymsk = 1 << _ep->num;
3225 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->
3226 + dtknqr4_fifoemptymsk,0,fifoemptymsk);
3232 + /* EP enable, IN data in FIFO */
3233 + depctl.b.cnak = 1;
3234 + depctl.b.epena = 1;
3235 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3237 + if (_core_if->dma_enable) {
3238 + depctl.d32 = dwc_read_reg32 (&_core_if->dev_if->in_ep_regs[0]->diepctl);
3239 + depctl.b.nextep = _ep->num;
3240 + dwc_write_reg32 (&_core_if->dev_if->in_ep_regs[0]->diepctl, depctl.d32);
3244 + /* OUT endpoint */
3245 + dwc_otg_dev_out_ep_regs_t * out_regs = _core_if->dev_if->out_ep_regs[_ep->num];
3247 + depctl.d32 = dwc_read_reg32(&(out_regs->doepctl));
3248 + deptsiz.d32 = dwc_read_reg32(&(out_regs->doeptsiz));
3250 + /* Program the transfer size and packet count as follows:
3253 + * xfersize = N * maxpacket
3255 + if (_ep->xfer_len == 0) {
3256 + /* Zero Length Packet */
3257 + deptsiz.b.xfersize = _ep->maxpacket;
3258 + deptsiz.b.pktcnt = 1;
3260 + deptsiz.b.pktcnt = (_ep->xfer_len + (_ep->maxpacket - 1)) / _ep->maxpacket;
3261 + deptsiz.b.xfersize = deptsiz.b.pktcnt * _ep->maxpacket;
3263 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3265 + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
3266 + _ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
3268 + if (_core_if->dma_enable) {
3270 + dwc_write_reg32 (&(out_regs->doepdma),
3271 + CPHYSADDR((uint32_t)_ep->xfer_buff)); // winder
3273 + dwc_write_reg32 (&(out_regs->doepdma),
3274 + (uint32_t)_ep->dma_addr);
3278 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
3279 + /** @todo NGS: dpid is read-only. Use setd0pid
3281 + if (_ep->even_odd_frame) {
3282 + depctl.b.setd1pid = 1;
3284 + depctl.b.setd0pid = 1;
3289 + depctl.b.cnak = 1;
3290 + depctl.b.epena = 1;
3292 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
3294 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
3295 + dwc_read_reg32(&out_regs->doepctl),
3296 + dwc_read_reg32(&out_regs->doeptsiz));
3297 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
3298 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk),
3299 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
3305 + * This function does the setup for a data transfer for EP0 and starts
3306 + * the transfer. For an IN transfer, the packets will be loaded into
3307 + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
3308 + * unloaded from the Rx FIFO in the ISR.
3310 + * @param _core_if Programming view of DWC_otg controller.
3311 + * @param _ep The EP0 data.
3313 +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3315 + volatile depctl_data_t depctl;
3316 + volatile deptsiz0_data_t deptsiz;
3317 + gintmsk_data_t intr_mask = { .d32 = 0};
3319 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3320 + "xfer_buff=%p start_xfer_buff=%p total_len=%d\n",
3321 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3322 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff,
3324 + _ep->total_len = _ep->xfer_len;
3327 + if (_ep->is_in == 1) {
3328 + dwc_otg_dev_in_ep_regs_t * in_regs = _core_if->dev_if->in_ep_regs[0];
3329 + gnptxsts_data_t gtxstatus;
3330 + gtxstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3331 + if (_core_if->en_multiple_tx_fifo == 0 &&
3332 + gtxstatus.b.nptxqspcavail == 0) {
3334 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3335 + DWC_DEBUGPL(DBG_PCD,"DIEPCTL0=%0x\n",
3336 + dwc_read_reg32(&in_regs->diepctl));
3337 + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
3338 + deptsiz.d32, deptsiz.b.xfersize,deptsiz.b.pktcnt);
3339 + DWC_PRINT("TX Queue or FIFO Full (0x%0x)\n", gtxstatus.d32);
3341 + printk("TX Queue or FIFO Full!!!!\n"); // test-only
3343 + MDELAY(100); //james
3346 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3347 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3349 + /* Zero Length Packet? */
3350 + if (_ep->xfer_len == 0) {
3351 + deptsiz.b.xfersize = 0;
3352 + deptsiz.b.pktcnt = 1;
3354 + /* Program the transfer size and packet count
3355 + * as follows: xfersize = N * maxpacket +
3356 + * short_packet pktcnt = N + (short_packet
3359 + if (_ep->xfer_len > _ep->maxpacket) {
3360 + _ep->xfer_len = _ep->maxpacket;
3361 + deptsiz.b.xfersize = _ep->maxpacket;
3364 + deptsiz.b.xfersize = _ep->xfer_len;
3366 + deptsiz.b.pktcnt = 1;
3369 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3370 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
3371 + _ep->xfer_len, deptsiz.b.xfersize,deptsiz.b.pktcnt, deptsiz.d32);
3373 + /* Write the DMA register */
3374 + if (_core_if->dma_enable) {
3375 + dwc_write_reg32(&(in_regs->diepdma), (uint32_t) _ep->dma_addr);
3378 + /* EP enable, IN data in FIFO */
3379 + depctl.b.cnak = 1;
3380 + depctl.b.epena = 1;
3381 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3384 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3385 + * data will be written into the fifo by the ISR.
3387 + if (!_core_if->dma_enable) {
3388 + if (_core_if->en_multiple_tx_fifo == 0) {
3389 + intr_mask.b.nptxfempty = 1;
3390 + dwc_modify_reg32(&_core_if->core_global_regs->gintsts, intr_mask.d32, 0);
3391 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, intr_mask.d32,
3394 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3395 + if (_ep->xfer_len > 0) {
3396 + uint32_t fifoemptymsk = 0;
3397 + fifoemptymsk |= 1 << _ep->num;
3398 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
3405 + /* OUT endpoint */
3406 + dwc_otg_dev_out_ep_regs_t * out_regs = _core_if->dev_if->out_ep_regs[_ep->num];
3408 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
3409 + deptsiz.d32 = dwc_read_reg32(&out_regs->doeptsiz);
3411 + /* Program the transfer size and packet count as follows:
3412 + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
3414 + if (_ep->xfer_len == 0) {
3415 + /* Zero Length Packet */
3416 + deptsiz.b.xfersize = _ep->maxpacket;
3417 + deptsiz.b.pktcnt = 1;
3419 + deptsiz.b.pktcnt = (_ep->xfer_len + (_ep->maxpacket - 1)) / _ep->maxpacket;
3420 + deptsiz.b.xfersize = deptsiz.b.pktcnt * _ep->maxpacket;
3423 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3424 + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
3425 + _ep->xfer_len, deptsiz.b.xfersize,deptsiz.b.pktcnt);
3427 + if (_core_if->dma_enable) {
3428 + dwc_write_reg32(&(out_regs->doepdma), (uint32_t) _ep->dma_addr);
3432 + depctl.b.cnak = 1;
3433 + depctl.b.epena = 1;
3434 + dwc_write_reg32 (&(out_regs->doepctl), depctl.d32);
3439 + * This function continues control IN transfers started by
3440 + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
3441 + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
3442 + * bit for the packet count.
3444 + * @param _core_if Programming view of DWC_otg controller.
3445 + * @param _ep The EP0 data.
3447 +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3449 + depctl_data_t depctl;
3450 + deptsiz0_data_t deptsiz;
3451 + gintmsk_data_t intr_mask = { .d32 = 0};
3453 + if (_ep->is_in == 1) {
3454 + dwc_otg_dev_in_ep_regs_t *in_regs =
3455 + _core_if->dev_if->in_ep_regs[0];
3456 + gnptxsts_data_t tx_status = {.d32 = 0};
3458 + tx_status.d32 = dwc_read_reg32( &_core_if->core_global_regs->gnptxsts );
3459 + /** @todo Should there be check for room in the Tx
3460 + * Status Queue. If not remove the code above this comment. */
3462 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3463 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3465 + /* Program the transfer size and packet count
3466 + * as follows: xfersize = N * maxpacket +
3467 + * short_packet pktcnt = N + (short_packet
3470 + deptsiz.b.xfersize = (_ep->total_len - _ep->xfer_count) > _ep->maxpacket ? _ep->maxpacket :
3471 + (_ep->total_len - _ep->xfer_count);
3472 + deptsiz.b.pktcnt = 1;
3473 + _ep->xfer_len += deptsiz.b.xfersize;
3475 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3476 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
3478 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
3480 + /* Write the DMA register */
3481 + if (_core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
3482 + dwc_write_reg32 (&(in_regs->diepdma),
3483 + CPHYSADDR((uint32_t)_ep->dma_addr)); // winder
3486 + /* EP enable, IN data in FIFO */
3487 + depctl.b.cnak = 1;
3488 + depctl.b.epena = 1;
3489 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3492 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3493 + * data will be written into the fifo by the ISR.
3495 + if (!_core_if->dma_enable) {
3496 + /* First clear it from GINTSTS */
3497 + intr_mask.b.nptxfempty = 1;
3498 + dwc_write_reg32( &_core_if->core_global_regs->gintsts,
3501 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3502 + intr_mask.d32, intr_mask.d32);
3510 +void dump_msg(const u8 *buf, unsigned int length)
3512 + unsigned int start, num, i;
3513 + char line[52], *p;
3515 + if (length >= 512)
3518 + while (length > 0) {
3519 + num = min(length, 16u);
3521 + for (i = 0; i < num; ++i) {
3524 + sprintf(p, " %02x", buf[i]);
3528 + DWC_PRINT( "%6x: %s\n", start, line);
3535 +static inline void dump_msg(const u8 *buf, unsigned int length)
3541 + * This function writes a packet into the Tx FIFO associated with the
3542 + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
3543 + * periodic EPs the periodic Tx FIFO associated with the EP is written
3544 + * with all packets for the next micro-frame.
3546 + * @param _core_if Programming view of DWC_otg controller.
3547 + * @param _ep The EP to write packet for.
3548 + * @param _dma Indicates if DMA is being used.
3550 +void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma)
3553 + * The buffer is padded to DWORD on a per packet basis in
3554 + * slave/dma mode if the MPS is not DWORD aligned. The last
3555 + * packet, if short, is also padded to a multiple of DWORD.
3557 + * ep->xfer_buff always starts DWORD aligned in memory and is a
3558 + * multiple of DWORD in length
3560 + * ep->xfer_len can be any number of bytes
3562 + * ep->xfer_count is a multiple of ep->maxpacket until the last
3565 + * FIFO access is DWORD */
3568 + uint32_t byte_count;
3569 + uint32_t dword_count;
3571 + uint32_t *data_buff = (uint32_t *)_ep->xfer_buff;
3573 + //DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, _core_if, _ep);
3574 + if (_ep->xfer_count >= _ep->xfer_len) {
3575 + DWC_WARN("%s() No data for EP%d!!!\n", __func__, _ep->num);
3579 + /* Find the byte length of the packet either short packet or MPS */
3580 + if ((_ep->xfer_len - _ep->xfer_count) < _ep->maxpacket) {
3581 + byte_count = _ep->xfer_len - _ep->xfer_count;
3584 + byte_count = _ep->maxpacket;
3587 + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
3588 + * is not a multiple of DWORD */
3589 + dword_count = (byte_count + 3) / 4;
3592 + dump_msg(_ep->xfer_buff, byte_count);
3594 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
3595 + /**@todo NGS Where are the Periodic Tx FIFO addresses
3596 + * intialized? What should this be? */
3597 + fifo = _core_if->data_fifo[_ep->tx_fifo_num];
3599 + fifo = _core_if->data_fifo[_ep->num];
3602 + DWC_DEBUGPL((DBG_PCDV|DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
3603 + fifo, data_buff, *data_buff, byte_count);
3607 + for (i=0; i<dword_count; i++, data_buff++) {
3608 + dwc_write_reg32( fifo, *data_buff );
3612 + _ep->xfer_count += byte_count;
3613 + _ep->xfer_buff += byte_count;
3614 +#if 1 // winder, why do we need this??
3615 + _ep->dma_addr += byte_count;
3620 + * Set the EP STALL.
3622 + * @param _core_if Programming view of DWC_otg controller.
3623 + * @param _ep The EP to set the stall on.
3625 +void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3627 + depctl_data_t depctl;
3628 + volatile uint32_t *depctl_addr;
3630 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _ep->num,
3631 + (_ep->is_in?"IN":"OUT"));
3633 + if (_ep->is_in == 1) {
3634 + depctl_addr = &(_core_if->dev_if->in_ep_regs[_ep->num]->diepctl);
3635 + depctl.d32 = dwc_read_reg32(depctl_addr);
3637 + /* set the disable and stall bits */
3638 + if (depctl.b.epena) {
3639 + depctl.b.epdis = 1;
3641 + depctl.b.stall = 1;
3642 + dwc_write_reg32(depctl_addr, depctl.d32);
3645 + depctl_addr = &(_core_if->dev_if->out_ep_regs[_ep->num]->doepctl);
3646 + depctl.d32 = dwc_read_reg32(depctl_addr);
3648 + /* set the stall bit */
3649 + depctl.b.stall = 1;
3650 + dwc_write_reg32(depctl_addr, depctl.d32);
3652 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
3657 + * Clear the EP STALL.
3659 + * @param _core_if Programming view of DWC_otg controller.
3660 + * @param _ep The EP to clear stall from.
3662 +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3664 + depctl_data_t depctl;
3665 + volatile uint32_t *depctl_addr;
3667 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _ep->num,
3668 + (_ep->is_in?"IN":"OUT"));
3670 + if (_ep->is_in == 1) {
3671 + depctl_addr = &(_core_if->dev_if->in_ep_regs[_ep->num]->diepctl);
3673 + depctl_addr = &(_core_if->dev_if->out_ep_regs[_ep->num]->doepctl);
3676 + depctl.d32 = dwc_read_reg32(depctl_addr);
3678 + /* clear the stall bits */
3679 + depctl.b.stall = 0;
3682 + * USB Spec 9.4.5: For endpoints using data toggle, regardless
3683 + * of whether an endpoint has the Halt feature set, a
3684 + * ClearFeature(ENDPOINT_HALT) request always results in the
3685 + * data toggle being reinitialized to DATA0.
3687 + if (_ep->type == DWC_OTG_EP_TYPE_INTR ||
3688 + _ep->type == DWC_OTG_EP_TYPE_BULK) {
3689 + depctl.b.setd0pid = 1; /* DATA0 */
3692 + dwc_write_reg32(depctl_addr, depctl.d32);
3693 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
3698 + * This function reads a packet from the Rx FIFO into the destination
3699 + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
3701 + * @param _core_if Programming view of DWC_otg controller.
3702 + * @param _dest Destination buffer for the packet.
3703 + * @param _bytes Number of bytes to copy to the destination.
3705 +void dwc_otg_read_packet(dwc_otg_core_if_t *_core_if,
3710 + int word_count = (_bytes + 3) / 4;
3712 + volatile uint32_t *fifo = _core_if->data_fifo[0];
3713 + uint32_t *data_buff = (uint32_t *)_dest;
3716 + * @todo Account for the case where _dest is not dword aligned. This
3717 + * requires reading data from the FIFO into a uint32_t temp buffer,
3718 + * then moving it into the data buffer.
3721 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
3722 + _core_if, _dest, _bytes);
3724 + for (i=0; i<word_count; i++, data_buff++) {
3725 + *data_buff = dwc_read_reg32(fifo);
3734 + * This functions reads the device registers and prints them
3736 + * @param _core_if Programming view of DWC_otg controller.
3738 +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if)
3741 + volatile uint32_t *addr;
3743 + DWC_PRINT("Device Global Registers\n");
3744 + addr=&_core_if->dev_if->dev_global_regs->dcfg;
3745 + DWC_PRINT("DCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3746 + addr=&_core_if->dev_if->dev_global_regs->dctl;
3747 + DWC_PRINT("DCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3748 + addr=&_core_if->dev_if->dev_global_regs->dsts;
3749 + DWC_PRINT("DSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3750 + addr=&_core_if->dev_if->dev_global_regs->diepmsk;
3751 + DWC_PRINT("DIEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3752 + addr=&_core_if->dev_if->dev_global_regs->doepmsk;
3753 + DWC_PRINT("DOEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3754 + addr=&_core_if->dev_if->dev_global_regs->daint;
3755 + DWC_PRINT("DAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3756 + addr=&_core_if->dev_if->dev_global_regs->dtknqr1;
3757 + DWC_PRINT("DTKNQR1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3758 + if (_core_if->hwcfg2.b.dev_token_q_depth > 6) {
3759 + addr=&_core_if->dev_if->dev_global_regs->dtknqr2;
3760 + DWC_PRINT("DTKNQR2 @0x%08X : 0x%08X\n",
3761 + (uint32_t)addr,dwc_read_reg32(addr));
3764 + addr=&_core_if->dev_if->dev_global_regs->dvbusdis;
3765 + DWC_PRINT("DVBUSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3767 + addr=&_core_if->dev_if->dev_global_regs->dvbuspulse;
3768 + DWC_PRINT("DVBUSPULSE @0x%08X : 0x%08X\n",
3769 + (uint32_t)addr,dwc_read_reg32(addr));
3771 + if (_core_if->hwcfg2.b.dev_token_q_depth > 14) {
3772 + addr = &_core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
3773 + DWC_PRINT("DTKNQR3 @0x%08X : 0x%08X\n",
3774 + (uint32_t)addr, dwc_read_reg32(addr));
3777 + if (_core_if->hwcfg2.b.dev_token_q_depth > 22) {
3778 + addr = &_core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
3779 + DWC_PRINT("DTKNQR4 @0x%08X : 0x%08X\n", (uint32_t) addr,
3780 + dwc_read_reg32(addr));
3782 + for (i = 0; i <= _core_if->dev_if->num_in_eps; i++) {
3783 + DWC_PRINT("Device IN EP %d Registers\n", i);
3784 + addr=&_core_if->dev_if->in_ep_regs[i]->diepctl;
3785 + DWC_PRINT("DIEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3786 + addr=&_core_if->dev_if->in_ep_regs[i]->diepint;
3787 + DWC_PRINT("DIEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3788 + addr=&_core_if->dev_if->in_ep_regs[i]->dieptsiz;
3789 + DWC_PRINT("DIETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3790 + addr=&_core_if->dev_if->in_ep_regs[i]->diepdma;
3791 + DWC_PRINT("DIEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3793 +addr = &_core_if->dev_if->in_ep_regs[i]->dtxfsts;
3794 + DWC_PRINT("DTXFSTS @0x%08X : 0x%08X\n", (uint32_t) addr,
3795 + dwc_read_reg32(addr));
3797 + for (i = 0; i <= _core_if->dev_if->num_out_eps; i++) {
3798 + DWC_PRINT("Device OUT EP %d Registers\n", i);
3799 + addr=&_core_if->dev_if->out_ep_regs[i]->doepctl;
3800 + DWC_PRINT("DOEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3801 + addr=&_core_if->dev_if->out_ep_regs[i]->doepfn;
3802 + DWC_PRINT("DOEPFN @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3803 + addr=&_core_if->dev_if->out_ep_regs[i]->doepint;
3804 + DWC_PRINT("DOEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3805 + addr=&_core_if->dev_if->out_ep_regs[i]->doeptsiz;
3806 + DWC_PRINT("DOETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3807 + addr=&_core_if->dev_if->out_ep_regs[i]->doepdma;
3808 + DWC_PRINT("DOEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3814 + * This function reads the host registers and prints them
3816 + * @param _core_if Programming view of DWC_otg controller.
3818 +void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if)
3821 + volatile uint32_t *addr;
3823 + DWC_PRINT("Host Global Registers\n");
3824 + addr=&_core_if->host_if->host_global_regs->hcfg;
3825 + DWC_PRINT("HCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3826 + addr=&_core_if->host_if->host_global_regs->hfir;
3827 + DWC_PRINT("HFIR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3828 + addr=&_core_if->host_if->host_global_regs->hfnum;
3829 + DWC_PRINT("HFNUM @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3830 + addr=&_core_if->host_if->host_global_regs->hptxsts;
3831 + DWC_PRINT("HPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3832 + addr=&_core_if->host_if->host_global_regs->haint;
3833 + DWC_PRINT("HAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3834 + addr=&_core_if->host_if->host_global_regs->haintmsk;
3835 + DWC_PRINT("HAINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3836 + addr=_core_if->host_if->hprt0;
3837 + DWC_PRINT("HPRT0 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3839 + for (i=0; i<_core_if->core_params->host_channels; i++) {
3840 + DWC_PRINT("Host Channel %d Specific Registers\n", i);
3841 + addr=&_core_if->host_if->hc_regs[i]->hcchar;
3842 + DWC_PRINT("HCCHAR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3843 + addr=&_core_if->host_if->hc_regs[i]->hcsplt;
3844 + DWC_PRINT("HCSPLT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3845 + addr=&_core_if->host_if->hc_regs[i]->hcint;
3846 + DWC_PRINT("HCINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3847 + addr=&_core_if->host_if->hc_regs[i]->hcintmsk;
3848 + DWC_PRINT("HCINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3849 + addr=&_core_if->host_if->hc_regs[i]->hctsiz;
3850 + DWC_PRINT("HCTSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3851 + addr=&_core_if->host_if->hc_regs[i]->hcdma;
3852 + DWC_PRINT("HCDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3859 + * This function reads the core global registers and prints them
3861 + * @param _core_if Programming view of DWC_otg controller.
3863 +void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if)
3866 + volatile uint32_t *addr;
3868 + DWC_PRINT("Core Global Registers\n");
3869 + addr=&_core_if->core_global_regs->gotgctl;
3870 + DWC_PRINT("GOTGCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3871 + addr=&_core_if->core_global_regs->gotgint;
3872 + DWC_PRINT("GOTGINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3873 + addr=&_core_if->core_global_regs->gahbcfg;
3874 + DWC_PRINT("GAHBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3875 + addr=&_core_if->core_global_regs->gusbcfg;
3876 + DWC_PRINT("GUSBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3877 + addr=&_core_if->core_global_regs->grstctl;
3878 + DWC_PRINT("GRSTCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3879 + addr=&_core_if->core_global_regs->gintsts;
3880 + DWC_PRINT("GINTSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3881 + addr=&_core_if->core_global_regs->gintmsk;
3882 + DWC_PRINT("GINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3883 + addr=&_core_if->core_global_regs->grxstsr;
3884 + DWC_PRINT("GRXSTSR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3885 + //addr=&_core_if->core_global_regs->grxstsp;
3886 + //DWC_PRINT("GRXSTSP @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3887 + addr=&_core_if->core_global_regs->grxfsiz;
3888 + DWC_PRINT("GRXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3889 + addr=&_core_if->core_global_regs->gnptxfsiz;
3890 + DWC_PRINT("GNPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3891 + addr=&_core_if->core_global_regs->gnptxsts;
3892 + DWC_PRINT("GNPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3893 + addr=&_core_if->core_global_regs->gi2cctl;
3894 + DWC_PRINT("GI2CCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3895 + addr=&_core_if->core_global_regs->gpvndctl;
3896 + DWC_PRINT("GPVNDCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3897 + addr=&_core_if->core_global_regs->ggpio;
3898 + DWC_PRINT("GGPIO @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3899 + addr=&_core_if->core_global_regs->guid;
3900 + DWC_PRINT("GUID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3901 + addr=&_core_if->core_global_regs->gsnpsid;
3902 + DWC_PRINT("GSNPSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3903 + addr=&_core_if->core_global_regs->ghwcfg1;
3904 + DWC_PRINT("GHWCFG1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3905 + addr=&_core_if->core_global_regs->ghwcfg2;
3906 + DWC_PRINT("GHWCFG2 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3907 + addr=&_core_if->core_global_regs->ghwcfg3;
3908 + DWC_PRINT("GHWCFG3 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3909 + addr=&_core_if->core_global_regs->ghwcfg4;
3910 + DWC_PRINT("GHWCFG4 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3911 + addr=&_core_if->core_global_regs->hptxfsiz;
3912 + DWC_PRINT("HPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3914 + for (i=0; i<_core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
3915 + addr=&_core_if->core_global_regs->dptxfsiz_dieptxf[i];
3916 + DWC_PRINT("DPTXFSIZ[%d] @0x%08X : 0x%08X\n",i,(uint32_t)addr,dwc_read_reg32(addr));
3923 + * Flush a Tx FIFO.
3925 + * @param _core_if Programming view of DWC_otg controller.
3926 + * @param _num Tx FIFO to flush.
3928 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
3931 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3932 + volatile grstctl_t greset = { .d32 = 0};
3935 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "Flush Tx FIFO %d\n", _num);
3937 + greset.b.txfflsh = 1;
3938 + greset.b.txfnum = _num;
3939 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3942 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3943 + if (++count > 10000){
3944 + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
3945 + __func__, greset.d32,
3946 + dwc_read_reg32( &global_regs->gnptxsts));
3951 + } while (greset.b.txfflsh == 1);
3952 + /* Wait for 3 PHY Clocks*/
3959 + * @param _core_if Programming view of DWC_otg controller.
3961 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if )
3963 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3964 + volatile grstctl_t greset = { .d32 = 0};
3967 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "%s\n", __func__);
3971 + greset.b.rxfflsh = 1;
3972 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3975 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3976 + if (++count > 10000){
3977 + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
3981 + } while (greset.b.rxfflsh == 1);
3982 + /* Wait for 3 PHY Clocks*/
3987 + * Do core a soft reset of the core. Be careful with this because it
3988 + * resets all the internal state machines of the core.
3991 +void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if)
3993 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3994 + volatile grstctl_t greset = { .d32 = 0};
3997 + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
3998 + /* Wait for AHB master IDLE state. */
4001 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
4002 + if (++count > 100000){
4003 + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x %x\n", __func__,
4004 + greset.d32, greset.b.ahbidle);
4007 + } while (greset.b.ahbidle == 0);
4011 + /* Note: Actually, I don't exactly why we need to put delay here. */
4014 + /* Core Soft Reset */
4016 + greset.b.csftrst = 1;
4017 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
4020 + /* Note: Actually, I don't exactly why we need to put delay here. */
4024 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
4025 + if (++count > 10000){
4026 + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n", __func__,
4031 + } while (greset.b.csftrst == 1);
4032 + /* Wait for 3 PHY Clocks*/
4033 + //DWC_PRINT("100ms\n");
4040 + * Register HCD callbacks. The callbacks are used to start and stop
4041 + * the HCD for interrupt processing.
4043 + * @param _core_if Programming view of DWC_otg controller.
4044 + * @param _cb the HCD callback structure.
4045 + * @param _p pointer to be passed to callback function (usb_hcd*).
4047 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
4048 + dwc_otg_cil_callbacks_t *_cb,
4051 + _core_if->hcd_cb = _cb;
4056 + * Register PCD callbacks. The callbacks are used to start and stop
4057 + * the PCD for interrupt processing.
4059 + * @param _core_if Programming view of DWC_otg controller.
4060 + * @param _cb the PCD callback structure.
4061 + * @param _p pointer to be passed to callback function (pcd*).
4063 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
4064 + dwc_otg_cil_callbacks_t *_cb,
4067 + _core_if->pcd_cb = _cb;
4072 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.h
4074 +/* ==========================================================================
4075 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil.h $
4076 + * $Revision: 1.1.1.1 $
4077 + * $Date: 2009-04-17 06:15:34 $
4078 + * $Change: 631780 $
4080 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
4081 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
4082 + * otherwise expressly agreed to in writing between Synopsys and you.
4084 + * The Software IS NOT an item of Licensed Software or Licensed Product under
4085 + * any End User Software License Agreement or Agreement for Licensed Product
4086 + * with Synopsys or any supplement thereto. You are permitted to use and
4087 + * redistribute this Software in source and binary forms, with or without
4088 + * modification, provided that redistributions of source code must retain this
4089 + * notice. You may not view, use, disclose, copy or distribute this file or
4090 + * any information contained herein except pursuant to this license grant from
4091 + * Synopsys. If you do not agree with this notice, including the disclaimer
4092 + * below, then you are not authorized to use the Software.
4094 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
4095 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4096 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4097 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
4098 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
4099 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
4100 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
4101 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4102 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4103 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
4105 + * ========================================================================== */
4107 +#if !defined(__DWC_CIL_H__)
4108 +#define __DWC_CIL_H__
4110 +#include "dwc_otg_plat.h"
4112 +#include "dwc_otg_regs.h"
4114 +#include "linux/timer.h"
4117 +/* the OTG capabilities. */
4118 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
4119 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
4120 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
4121 +/* the maximum speed of operation in host and device mode. */
4122 +#define DWC_SPEED_PARAM_HIGH 0
4123 +#define DWC_SPEED_PARAM_FULL 1
4124 +/* the PHY clock rate in low power mode when connected to a
4125 + * Low Speed device in host mode. */
4126 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
4127 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
4128 +/* the type of PHY interface to use. */
4129 +#define DWC_PHY_TYPE_PARAM_FS 0
4130 +#define DWC_PHY_TYPE_PARAM_UTMI 1
4131 +#define DWC_PHY_TYPE_PARAM_ULPI 2
4132 +/* whether to use the internal or external supply to
4133 + * drive the vbus with a ULPI phy. */
4134 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
4135 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
4140 + * This file contains the interface to the Core Interface Layer.
4144 + * The <code>dwc_ep</code> structure represents the state of a single
4145 + * endpoint when acting in device mode. It contains the data items
4146 + * needed for an endpoint to be activated and transfer packets.
4148 +typedef struct dwc_ep {
4149 + /** EP number used for register address lookup */
4151 + /** EP direction 0 = OUT */
4152 + unsigned is_in : 1;
4154 + unsigned active : 1;
4156 + /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
4157 + If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
4158 + unsigned tx_fifo_num : 4;
4159 + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
4160 + unsigned type : 2;
4161 +#define DWC_OTG_EP_TYPE_CONTROL 0
4162 +#define DWC_OTG_EP_TYPE_ISOC 1
4163 +#define DWC_OTG_EP_TYPE_BULK 2
4164 +#define DWC_OTG_EP_TYPE_INTR 3
4166 + /** DATA start PID for INTR and BULK EP */
4167 + unsigned data_pid_start : 1;
4168 + /** Frame (even/odd) for ISOC EP */
4169 + unsigned even_odd_frame : 1;
4170 + /** Max Packet bytes */
4171 + unsigned maxpacket : 11;
4173 + /** @name Transfer state */
4177 + * Pointer to the beginning of the transfer buffer -- do not modify
4178 + * during transfer.
4181 + uint32_t dma_addr;
4183 + uint8_t *start_xfer_buff;
4184 + /** pointer to the transfer buffer */
4185 + uint8_t *xfer_buff;
4186 + /** Number of bytes to transfer */
4187 + unsigned xfer_len : 19;
4188 + /** Number of bytes transferred. */
4189 + unsigned xfer_count : 19;
4191 + unsigned sent_zlp : 1;
4192 + /** Total len for control transfer */
4193 + unsigned total_len : 19;
4195 + /** stall clear flag */
4196 + unsigned stall_clear_flag : 1;
4202 + * Reasons for halting a host channel.
4204 +typedef enum dwc_otg_halt_status {
4205 + DWC_OTG_HC_XFER_NO_HALT_STATUS,
4206 + DWC_OTG_HC_XFER_COMPLETE,
4207 + DWC_OTG_HC_XFER_URB_COMPLETE,
4208 + DWC_OTG_HC_XFER_ACK,
4209 + DWC_OTG_HC_XFER_NAK,
4210 + DWC_OTG_HC_XFER_NYET,
4211 + DWC_OTG_HC_XFER_STALL,
4212 + DWC_OTG_HC_XFER_XACT_ERR,
4213 + DWC_OTG_HC_XFER_FRAME_OVERRUN,
4214 + DWC_OTG_HC_XFER_BABBLE_ERR,
4215 + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
4216 + DWC_OTG_HC_XFER_AHB_ERR,
4217 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
4218 + DWC_OTG_HC_XFER_URB_DEQUEUE
4219 +} dwc_otg_halt_status_e;
4222 + * Host channel descriptor. This structure represents the state of a single
4223 + * host channel when acting in host mode. It contains the data items needed to
4224 + * transfer packets to an endpoint via a host channel.
4226 +typedef struct dwc_hc {
4227 + /** Host channel number used for register address lookup */
4230 + /** Device to access */
4231 + unsigned dev_addr : 7;
4233 + /** EP to access */
4234 + unsigned ep_num : 4;
4236 + /** EP direction. 0: OUT, 1: IN */
4237 + unsigned ep_is_in : 1;
4241 + * One of the following values:
4242 + * - DWC_OTG_EP_SPEED_LOW
4243 + * - DWC_OTG_EP_SPEED_FULL
4244 + * - DWC_OTG_EP_SPEED_HIGH
4246 + unsigned speed : 2;
4247 +#define DWC_OTG_EP_SPEED_LOW 0
4248 +#define DWC_OTG_EP_SPEED_FULL 1
4249 +#define DWC_OTG_EP_SPEED_HIGH 2
4253 + * One of the following values:
4254 + * - DWC_OTG_EP_TYPE_CONTROL: 0
4255 + * - DWC_OTG_EP_TYPE_ISOC: 1
4256 + * - DWC_OTG_EP_TYPE_BULK: 2
4257 + * - DWC_OTG_EP_TYPE_INTR: 3
4259 + unsigned ep_type : 2;
4261 + /** Max packet size in bytes */
4262 + unsigned max_packet : 11;
4265 + * PID for initial transaction.
4269 + * 3: MDATA (non-Control EP),
4270 + * SETUP (Control EP)
4272 + unsigned data_pid_start : 2;
4273 +#define DWC_OTG_HC_PID_DATA0 0
4274 +#define DWC_OTG_HC_PID_DATA2 1
4275 +#define DWC_OTG_HC_PID_DATA1 2
4276 +#define DWC_OTG_HC_PID_MDATA 3
4277 +#define DWC_OTG_HC_PID_SETUP 3
4279 + /** Number of periodic transactions per (micro)frame */
4280 + unsigned multi_count: 2;
4282 + /** @name Transfer State */
4285 + /** Pointer to the current transfer buffer position. */
4286 + uint8_t *xfer_buff;
4287 + /** Total number of bytes to transfer. */
4288 + uint32_t xfer_len;
4289 + /** Number of bytes transferred so far. */
4290 + uint32_t xfer_count;
4291 + /** Packet count at start of transfer.*/
4292 + uint16_t start_pkt_count;
4295 + * Flag to indicate whether the transfer has been started. Set to 1 if
4296 + * it has been started, 0 otherwise.
4298 + uint8_t xfer_started;
4301 + * Set to 1 to indicate that a PING request should be issued on this
4302 + * channel. If 0, process normally.
4307 + * Set to 1 to indicate that the error count for this transaction is
4308 + * non-zero. Set to 0 if the error count is 0.
4310 + uint8_t error_state;
4313 + * Set to 1 to indicate that this channel should be halted the next
4314 + * time a request is queued for the channel. This is necessary in
4315 + * slave mode if no request queue space is available when an attempt
4316 + * is made to halt the channel.
4318 + uint8_t halt_on_queue;
4321 + * Set to 1 if the host channel has been halted, but the core is not
4322 + * finished flushing queued requests. Otherwise 0.
4324 + uint8_t halt_pending;
4327 + * Reason for halting the host channel.
4329 + dwc_otg_halt_status_e halt_status;
4332 + * Split settings for the host channel
4334 + uint8_t do_split; /**< Enable split for the channel */
4335 + uint8_t complete_split; /**< Enable complete split */
4336 + uint8_t hub_addr; /**< Address of high speed hub */
4338 + uint8_t port_addr; /**< Port of the low/full speed device */
4339 + /** Split transaction position
4340 + * One of the following values:
4341 + * - DWC_HCSPLIT_XACTPOS_MID
4342 + * - DWC_HCSPLIT_XACTPOS_BEGIN
4343 + * - DWC_HCSPLIT_XACTPOS_END
4344 + * - DWC_HCSPLIT_XACTPOS_ALL */
4347 + /** Set when the host channel does a short read. */
4348 + uint8_t short_read;
4351 + * Number of requests issued for this channel since it was assigned to
4352 + * the current transfer (not counting PINGs).
4357 + * Queue Head for the transfer being processed by this channel.
4359 + struct dwc_otg_qh *qh;
4363 + /** Entry in list of host channels. */
4364 + struct list_head hc_list_entry;
4368 + * The following parameters may be specified when starting the module. These
4369 + * parameters define how the DWC_otg controller should be configured.
4370 + * Parameter values are passed to the CIL initialization function
4371 + * dwc_otg_cil_init.
4374 +typedef struct dwc_otg_core_params
4377 +//#define dwc_param_opt_default 1
4379 + * Specifies the OTG capabilities. The driver will automatically
4380 + * detect the value for this parameter if none is specified.
4381 + * 0 - HNP and SRP capable (default)
4382 + * 1 - SRP Only capable
4383 + * 2 - No HNP/SRP capable
4386 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
4387 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
4388 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
4389 +//#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
4391 + * Specifies whether to use slave or DMA mode for accessing the data
4392 + * FIFOs. The driver will automatically detect the value for this
4393 + * parameter if none is specified.
4395 + * 1 - DMA (default, if available)
4397 + int32_t dma_enable;
4398 +//#define dwc_param_dma_enable_default 1
4399 + /** The DMA Burst size (applicable only for External DMA
4400 + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
4402 + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
4403 +//#define dwc_param_dma_burst_size_default 32
4405 + * Specifies the maximum speed of operation in host and device mode.
4406 + * The actual speed depends on the speed of the attached device and
4407 + * the value of phy_type. The actual speed depends on the speed of the
4408 + * attached device.
4409 + * 0 - High Speed (default)
4413 +//#define dwc_param_speed_default 0
4414 +#define DWC_SPEED_PARAM_HIGH 0
4415 +#define DWC_SPEED_PARAM_FULL 1
4417 + /** Specifies whether low power mode is supported when attached
4418 + * to a Full Speed or Low Speed device in host mode.
4419 + * 0 - Don't support low power mode (default)
4420 + * 1 - Support low power mode
4422 + int32_t host_support_fs_ls_low_power;
4423 +//#define dwc_param_host_support_fs_ls_low_power_default 0
4424 + /** Specifies the PHY clock rate in low power mode when connected to a
4425 + * Low Speed device in host mode. This parameter is applicable only if
4426 + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
4427 + * then defaults to 6 MHZ otherwise 48 MHZ.
4432 + int32_t host_ls_low_power_phy_clk;
4433 +//#define dwc_param_host_ls_low_power_phy_clk_default 0
4434 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
4435 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
4437 + * 0 - Use cC FIFO size parameters
4438 + * 1 - Allow dynamic FIFO sizing (default)
4440 + int32_t enable_dynamic_fifo;
4441 +//#define dwc_param_enable_dynamic_fifo_default 1
4442 + /** Total number of 4-byte words in the data FIFO memory. This
4443 + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
4445 + * 32 to 32768 (default 8192)
4446 + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
4448 + int32_t data_fifo_size;
4449 +//#define dwc_param_data_fifo_size_default 8192
4450 + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
4451 + * FIFO sizing is enabled.
4452 + * 16 to 32768 (default 1064)
4454 + int32_t dev_rx_fifo_size;
4455 +//#define dwc_param_dev_rx_fifo_size_default 1064
4456 + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
4457 + * when dynamic FIFO sizing is enabled.
4458 + * 16 to 32768 (default 1024)
4460 + int32_t dev_nperio_tx_fifo_size;
4461 +//#define dwc_param_dev_nperio_tx_fifo_size_default 1024
4462 + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
4463 + * mode when dynamic FIFO sizing is enabled.
4464 + * 4 to 768 (default 256)
4466 + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
4467 +//#define dwc_param_dev_perio_tx_fifo_size_default 256
4468 + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
4469 + * FIFO sizing is enabled.
4470 + * 16 to 32768 (default 1024)
4472 + int32_t host_rx_fifo_size;
4473 +//#define dwc_param_host_rx_fifo_size_default 1024
4474 + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
4475 + * when Dynamic FIFO sizing is enabled in the core.
4476 + * 16 to 32768 (default 1024)
4478 + int32_t host_nperio_tx_fifo_size;
4479 +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
4480 + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
4481 + * FIFO sizing is enabled.
4482 + * 16 to 32768 (default 1024)
4484 + int32_t host_perio_tx_fifo_size;
4485 +//#define dwc_param_host_perio_tx_fifo_size_default 1024
4486 + /** The maximum transfer size supported in bytes.
4487 + * 2047 to 65,535 (default 65,535)
4489 + int32_t max_transfer_size;
4490 +//#define dwc_param_max_transfer_size_default 65535
4491 + /** The maximum number of packets in a transfer.
4492 + * 15 to 511 (default 511)
4494 + int32_t max_packet_count;
4495 +//#define dwc_param_max_packet_count_default 511
4496 + /** The number of host channel registers to use.
4497 + * 1 to 16 (default 12)
4498 + * Note: The FPGA configuration supports a maximum of 12 host channels.
4500 + int32_t host_channels;
4501 +//#define dwc_param_host_channels_default 12
4502 + /** The number of endpoints in addition to EP0 available for device
4503 + * mode operations.
4504 + * 1 to 15 (default 6 IN and OUT)
4505 + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
4506 + * endpoints in addition to EP0.
4508 + int32_t dev_endpoints;
4509 +//#define dwc_param_dev_endpoints_default 6
4511 + * Specifies the type of PHY interface to use. By default, the driver
4512 + * will automatically detect the phy_type.
4514 + * 0 - Full Speed PHY
4515 + * 1 - UTMI+ (default)
4519 +#define DWC_PHY_TYPE_PARAM_FS 0
4520 +#define DWC_PHY_TYPE_PARAM_UTMI 1
4521 +#define DWC_PHY_TYPE_PARAM_ULPI 2
4522 +//#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
4524 + * Specifies the UTMI+ Data Width. This parameter is
4525 + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
4526 + * PHY_TYPE, this parameter indicates the data width between
4527 + * the MAC and the ULPI Wrapper.) Also, this parameter is
4528 + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
4529 + * to "8 and 16 bits", meaning that the core has been
4530 + * configured to work at either data path width.
4532 + * 8 or 16 bits (default 16)
4534 + int32_t phy_utmi_width;
4535 +//#define dwc_param_phy_utmi_width_default 16
4537 + * Specifies whether the ULPI operates at double or single
4538 + * data rate. This parameter is only applicable if PHY_TYPE is
4541 + * 0 - single data rate ULPI interface with 8 bit wide data
4543 + * 1 - double data rate ULPI interface with 4 bit wide data
4546 + int32_t phy_ulpi_ddr;
4547 +//#define dwc_param_phy_ulpi_ddr_default 0
4549 + * Specifies whether to use the internal or external supply to
4550 + * drive the vbus with a ULPI phy.
4552 + int32_t phy_ulpi_ext_vbus;
4553 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
4554 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
4555 +//#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
4557 + * Specifies whether to use the I2Cinterface for full speed PHY. This
4558 + * parameter is only applicable if PHY_TYPE is FS.
4559 + * 0 - No (default)
4562 + int32_t i2c_enable;
4563 +//#define dwc_param_i2c_enable_default 0
4565 + int32_t ulpi_fs_ls;
4566 +//#define dwc_param_ulpi_fs_ls_default 0
4569 +//#define dwc_param_ts_dline_default 0
4572 + * Specifies whether dedicated transmit FIFOs are
4573 + * enabled for non periodic IN endpoints in device mode
4577 + int32_t en_multiple_tx_fifo;
4578 +#define dwc_param_en_multiple_tx_fifo_default 1
4580 + /** Number of 4-byte words in each of the Tx FIFOs in device
4581 + * mode when dynamic FIFO sizing is enabled.
4582 + * 4 to 768 (default 256)
4584 + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
4585 +#define dwc_param_dev_tx_fifo_size_default 256
4587 + /** Thresholding enable flag-
4588 + * bit 0 - enable non-ISO Tx thresholding
4589 + * bit 1 - enable ISO Tx thresholding
4590 + * bit 2 - enable Rx thresholding
4593 +#define dwc_param_thr_ctl_default 0
4595 + /** Thresholding length for Tx
4596 + * FIFOs in 32 bit DWORDs
4598 + uint32_t tx_thr_length;
4599 +#define dwc_param_tx_thr_length_default 64
4601 + /** Thresholding length for Rx
4602 + * FIFOs in 32 bit DWORDs
4604 + uint32_t rx_thr_length;
4605 +#define dwc_param_rx_thr_length_default 64
4606 +} dwc_otg_core_params_t;
4609 +struct dwc_otg_core_if;
4610 +typedef struct hc_xfer_info
4612 + struct dwc_otg_core_if *core_if;
4618 + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
4619 + * the DWC_otg controller acting in either host or device mode. It
4620 + * represents the programming view of the controller as a whole.
4622 +typedef struct dwc_otg_core_if
4624 + /** Parameters that define how the core should be configured.*/
4625 + dwc_otg_core_params_t *core_params;
4627 + /** Core Global registers starting at offset 000h. */
4628 + dwc_otg_core_global_regs_t *core_global_regs;
4630 + /** Device-specific information */
4631 + dwc_otg_dev_if_t *dev_if;
4632 + /** Host-specific information */
4633 + dwc_otg_host_if_t *host_if;
4636 + * Set to 1 if the core PHY interface bits in USBCFG have been
4639 + uint8_t phy_init_done;
4642 + * SRP Success flag, set by srp success interrupt in FS I2C mode
4644 + uint8_t srp_success;
4645 + uint8_t srp_timer_started;
4647 + /* Common configuration information */
4648 + /** Power and Clock Gating Control Register */
4649 + volatile uint32_t *pcgcctl;
4650 +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
4652 + /** Push/pop addresses for endpoints or host channels.*/
4653 + uint32_t *data_fifo[MAX_EPS_CHANNELS];
4654 +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
4655 +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
4657 + /** Total RAM for FIFOs (Bytes) */
4658 + uint16_t total_fifo_size;
4659 + /** Size of Rx FIFO (Bytes) */
4660 + uint16_t rx_fifo_size;
4661 + /** Size of Non-periodic Tx FIFO (Bytes) */
4662 + uint16_t nperio_tx_fifo_size;
4664 + /** 1 if DMA is enabled, 0 otherwise. */
4665 + uint8_t dma_enable;
4667 + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
4668 + uint8_t en_multiple_tx_fifo;
4670 + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
4671 + * process of being queued */
4672 + uint8_t queuing_high_bandwidth;
4674 + /** Hardware Configuration -- stored here for convenience.*/
4675 + hwcfg1_data_t hwcfg1;
4676 + hwcfg2_data_t hwcfg2;
4677 + hwcfg3_data_t hwcfg3;
4678 + hwcfg4_data_t hwcfg4;
4680 + /** The operational State, during transations
4681 + * (a_host>>a_peripherial and b_device=>b_host) this may not
4682 + * match the core but allows the software to determine
4688 + * Set to 1 if the HCD needs to be restarted on a session request
4689 + * interrupt. This is required if no connector ID status change has
4690 + * occurred since the HCD was last disconnected.
4692 + uint8_t restart_hcd_on_session_req;
4694 + /** HCD callbacks */
4695 + /** A-Device is a_host */
4697 + /** A-Device is a_suspend */
4698 +#define A_SUSPEND (2)
4699 + /** A-Device is a_peripherial */
4700 +#define A_PERIPHERAL (3)
4701 + /** B-Device is operating as a Peripheral. */
4702 +#define B_PERIPHERAL (4)
4703 + /** B-Device is operating as a Host. */
4706 + /** HCD callbacks */
4707 + struct dwc_otg_cil_callbacks *hcd_cb;
4708 + /** PCD callbacks */
4709 + struct dwc_otg_cil_callbacks *pcd_cb;
4711 + /** Device mode Periodic Tx FIFO Mask */
4712 + uint32_t p_tx_msk;
4713 + /** Device mode Periodic Tx FIFO Mask */
4717 + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
4719 + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
4720 + struct timer_list hc_xfer_timer[MAX_EPS_CHANNELS];
4723 + uint32_t hfnum_7_samples;
4724 + uint32_t hfnum_7_frrem_accum;
4725 + uint32_t hfnum_0_samples;
4726 + uint32_t hfnum_0_frrem_accum;
4727 + uint32_t hfnum_other_samples;
4728 + uint32_t hfnum_other_frrem_accum;
4730 + uint32_t hfnum_7_samples;
4731 + uint64_t hfnum_7_frrem_accum;
4732 + uint32_t hfnum_0_samples;
4733 + uint64_t hfnum_0_frrem_accum;
4734 + uint32_t hfnum_other_samples;
4735 + uint64_t hfnum_other_frrem_accum;
4737 + resource_size_t phys_addr; /* Added to support PLB DMA : phys-virt mapping */
4740 +} dwc_otg_core_if_t;
4743 + * The following functions support initialization of the CIL driver component
4744 + * and the DWC_otg controller.
4746 +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
4747 + dwc_otg_core_params_t *_core_params);
4748 +extern void dwc_otg_cil_remove(dwc_otg_core_if_t *_core_if);
4749 +extern void dwc_otg_core_init(dwc_otg_core_if_t *_core_if);
4750 +extern void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if);
4751 +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if);
4752 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if );
4753 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if );
4755 +/** @name Device CIL Functions
4756 + * The following functions support managing the DWC_otg controller in device
4760 +extern void dwc_otg_wakeup(dwc_otg_core_if_t *_core_if);
4761 +extern void dwc_otg_read_setup_packet (dwc_otg_core_if_t *_core_if, uint32_t *_dest);
4762 +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if);
4763 +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4764 +extern void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4765 +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4766 +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4767 +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4768 +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4769 +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma);
4770 +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4771 +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4772 +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if);
4773 +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if);
4776 +/** @name Host CIL Functions
4777 + * The following functions support managing the DWC_otg controller in host
4781 +extern void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4782 +extern void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
4784 + dwc_otg_halt_status_e _halt_status);
4785 +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4786 +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4787 +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4788 +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4789 +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4790 +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if);
4791 +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if);
4794 + * This function Reads HPRT0 in preparation to modify. It keeps the
4795 + * WC bits 0 so that if they are read as 1, they won't clear when you
4798 +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t *_core_if)
4800 + hprt0_data_t hprt0;
4801 + hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
4802 + hprt0.b.prtena = 0;
4803 + hprt0.b.prtconndet = 0;
4804 + hprt0.b.prtenchng = 0;
4805 + hprt0.b.prtovrcurrchng = 0;
4809 +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if);
4812 +/** @name Common CIL Functions
4813 + * The following functions support managing the DWC_otg controller in either
4814 + * device or host mode.
4818 +extern void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
4822 +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if);
4824 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
4826 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if );
4827 +extern void dwc_otg_core_reset( dwc_otg_core_if_t *_core_if );
4829 +#define NP_TXFIFO_EMPTY -1
4830 +#define MAX_NP_TXREQUEST_Q_SLOTS 8
4832 + * This function returns the endpoint number of the request at
4833 + * the top of non-periodic TX FIFO, or -1 if the request FIFO is
4836 +static inline int dwc_otg_top_nptxfifo_epnum(dwc_otg_core_if_t *_core_if) {
4837 + gnptxsts_data_t txstatus = {.d32 = 0};
4839 + txstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
4840 + return (txstatus.b.nptxqspcavail == MAX_NP_TXREQUEST_Q_SLOTS ?
4841 + -1 : txstatus.b.nptxqtop_chnep);
4844 + * This function returns the Core Interrupt register.
4846 +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t *_core_if) {
4847 + return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) &
4848 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
4852 + * This function returns the OTG Interrupt register.
4854 +static inline uint32_t dwc_otg_read_otg_intr (dwc_otg_core_if_t *_core_if) {
4855 + return (dwc_read_reg32 (&_core_if->core_global_regs->gotgint));
4859 + * This function reads the Device All Endpoints Interrupt register and
4860 + * returns the IN endpoint interrupt bits.
4862 +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *_core_if) {
4864 + v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
4865 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
4866 + return (v & 0xffff);
4871 + * This function reads the Device All Endpoints Interrupt register and
4872 + * returns the OUT endpoint interrupt bits.
4874 +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *_core_if) {
4876 + v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
4877 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
4878 + return ((v & 0xffff0000) >> 16);
4882 + * This function returns the Device IN EP Interrupt register
4884 +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t *_core_if,
4887 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4888 + uint32_t v, msk, emp;
4889 + msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
4890 + emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
4891 + msk |= ((emp >> _ep->num) & 0x1) << 7;
4892 + v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) & msk;
4894 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4896 + v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) &
4897 + dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
4902 + * This function returns the Device OUT EP Interrupt register
4904 +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *_core_if,
4907 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4909 + v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) &
4910 + dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
4915 + * This function returns the Host All Channel Interrupt register
4917 +static inline uint32_t dwc_otg_read_host_all_channels_intr (dwc_otg_core_if_t *_core_if)
4919 + return (dwc_read_reg32 (&_core_if->host_if->host_global_regs->haint));
4922 +static inline uint32_t dwc_otg_read_host_channel_intr (dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
4924 + return (dwc_read_reg32 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
4929 + * This function returns the mode of the operation, host or device.
4931 + * @return 0 - Device Mode, 1 - Host Mode
4933 +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t *_core_if) {
4934 + return (dwc_read_reg32( &_core_if->core_global_regs->gintsts ) & 0x1);
4937 +static inline uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t *_core_if)
4939 + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
4941 +static inline uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t *_core_if)
4943 + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
4946 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if );
4952 + * DWC_otg CIL callback structure. This structure allows the HCD and
4953 + * PCD to register functions used for starting and stopping the PCD
4954 + * and HCD for role change on for a DRD.
4956 +typedef struct dwc_otg_cil_callbacks
4958 + /** Start function for role change */
4959 + int (*start) (void *_p);
4960 + /** Stop Function for role change */
4961 + int (*stop) (void *_p);
4962 + /** Disconnect Function for role change */
4963 + int (*disconnect) (void *_p);
4964 + /** Resume/Remote wakeup Function */
4965 + int (*resume_wakeup) (void *_p);
4966 + /** Suspend function */
4967 + int (*suspend) (void *_p);
4968 + /** Session Start (SRP) */
4969 + int (*session_start) (void *_p);
4970 + /** Pointer passed to start() and stop() */
4972 +} dwc_otg_cil_callbacks_t;
4976 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
4977 + dwc_otg_cil_callbacks_t *_cb,
4979 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
4980 + dwc_otg_cil_callbacks_t *_cb,
4986 +++ b/drivers/usb/dwc_otg/dwc_otg_cil_ifx.h
4988 +/******************************************************************************
4990 +** FILE NAME : dwc_otg_cil_ifx.h
4991 +** PROJECT : Twinpass/Danube
4992 +** MODULES : DWC OTG USB
4994 +** DATE : 07 Sep. 2007
4995 +** AUTHOR : Sung Winder
4996 +** DESCRIPTION : Default param value.
4997 +** COPYRIGHT : Copyright (c) 2007
4998 +** Infineon Technologies AG
4999 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
5000 +** Hsin-chu City, 300 Taiwan.
5002 +** This program is free software; you can redistribute it and/or modify
5003 +** it under the terms of the GNU General Public License as published by
5004 +** the Free Software Foundation; either version 2 of the License, or
5005 +** (at your option) any later version.
5008 +** $Date $Author $Comment
5009 +** 12 April 2007 Sung Winder Initiate Version
5010 +*******************************************************************************/
5011 +#if !defined(__DWC_OTG_CIL_IFX_H__)
5012 +#define __DWC_OTG_CIL_IFX_H__
5014 +/* ================ Default param value ================== */
5015 +#define dwc_param_opt_default 1
5016 +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE
5017 +#define dwc_param_dma_enable_default 1
5018 +#define dwc_param_dma_burst_size_default 32
5019 +#define dwc_param_speed_default DWC_SPEED_PARAM_HIGH
5020 +#define dwc_param_host_support_fs_ls_low_power_default 0
5021 +#define dwc_param_host_ls_low_power_phy_clk_default DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ
5022 +#define dwc_param_enable_dynamic_fifo_default 1
5023 +#define dwc_param_data_fifo_size_default 2048
5024 +#define dwc_param_dev_rx_fifo_size_default 1024
5025 +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
5026 +#define dwc_param_dev_perio_tx_fifo_size_default 768
5027 +#define dwc_param_host_rx_fifo_size_default 640
5028 +#define dwc_param_host_nperio_tx_fifo_size_default 640
5029 +#define dwc_param_host_perio_tx_fifo_size_default 768
5030 +#define dwc_param_max_transfer_size_default 65535
5031 +#define dwc_param_max_packet_count_default 511
5032 +#define dwc_param_host_channels_default 16
5033 +#define dwc_param_dev_endpoints_default 6
5034 +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
5035 +#define dwc_param_phy_utmi_width_default 16
5036 +#define dwc_param_phy_ulpi_ddr_default 0
5037 +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
5038 +#define dwc_param_i2c_enable_default 0
5039 +#define dwc_param_ulpi_fs_ls_default 0
5040 +#define dwc_param_ts_dline_default 0
5042 +/* ======================================================= */
5044 +#endif // __DWC_OTG_CIL_IFX_H__
5047 +++ b/drivers/usb/dwc_otg/dwc_otg_cil_intr.c
5049 +/* ==========================================================================
5050 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil_intr.c $
5051 + * $Revision: 1.1.1.1 $
5052 + * $Date: 2009-04-17 06:15:34 $
5053 + * $Change: 553126 $
5055 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
5056 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
5057 + * otherwise expressly agreed to in writing between Synopsys and you.
5059 + * The Software IS NOT an item of Licensed Software or Licensed Product under
5060 + * any End User Software License Agreement or Agreement for Licensed Product
5061 + * with Synopsys or any supplement thereto. You are permitted to use and
5062 + * redistribute this Software in source and binary forms, with or without
5063 + * modification, provided that redistributions of source code must retain this
5064 + * notice. You may not view, use, disclose, copy or distribute this file or
5065 + * any information contained herein except pursuant to this license grant from
5066 + * Synopsys. If you do not agree with this notice, including the disclaimer
5067 + * below, then you are not authorized to use the Software.
5069 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
5070 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5071 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5072 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
5073 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5074 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5075 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5076 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5077 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5078 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
5080 + * ========================================================================== */
5084 + * The Core Interface Layer provides basic services for accessing and
5085 + * managing the DWC_otg hardware. These services are used by both the
5086 + * Host Controller Driver and the Peripheral Controller Driver.
5088 + * This file contains the Common Interrupt handlers.
5090 +#include "dwc_otg_plat.h"
5091 +#include "dwc_otg_regs.h"
5092 +#include "dwc_otg_cil.h"
5095 +inline const char *op_state_str( dwc_otg_core_if_t *_core_if )
5097 + return (_core_if->op_state==A_HOST?"a_host":
5098 + (_core_if->op_state==A_SUSPEND?"a_suspend":
5099 + (_core_if->op_state==A_PERIPHERAL?"a_peripheral":
5100 + (_core_if->op_state==B_PERIPHERAL?"b_peripheral":
5101 + (_core_if->op_state==B_HOST?"b_host":
5106 +/** This function will log a debug message
5108 + * @param _core_if Programming view of DWC_otg controller.
5110 +int32_t dwc_otg_handle_mode_mismatch_intr (dwc_otg_core_if_t *_core_if)
5112 + gintsts_data_t gintsts;
5113 + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
5114 + dwc_otg_mode(_core_if) ? "Host" : "Device");
5116 + /* Clear interrupt */
5118 + gintsts.b.modemismatch = 1;
5119 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5123 +/** Start the HCD. Helper function for using the HCD callbacks.
5125 + * @param _core_if Programming view of DWC_otg controller.
5127 +static inline void hcd_start( dwc_otg_core_if_t *_core_if )
5129 + if (_core_if->hcd_cb && _core_if->hcd_cb->start) {
5130 + _core_if->hcd_cb->start( _core_if->hcd_cb->p );
5133 +/** Stop the HCD. Helper function for using the HCD callbacks.
5135 + * @param _core_if Programming view of DWC_otg controller.
5137 +static inline void hcd_stop( dwc_otg_core_if_t *_core_if )
5139 + if (_core_if->hcd_cb && _core_if->hcd_cb->stop) {
5140 + _core_if->hcd_cb->stop( _core_if->hcd_cb->p );
5143 +/** Disconnect the HCD. Helper function for using the HCD callbacks.
5145 + * @param _core_if Programming view of DWC_otg controller.
5147 +static inline void hcd_disconnect( dwc_otg_core_if_t *_core_if )
5149 + if (_core_if->hcd_cb && _core_if->hcd_cb->disconnect) {
5150 + _core_if->hcd_cb->disconnect( _core_if->hcd_cb->p );
5153 +/** Inform the HCD the a New Session has begun. Helper function for
5154 + * using the HCD callbacks.
5156 + * @param _core_if Programming view of DWC_otg controller.
5158 +static inline void hcd_session_start( dwc_otg_core_if_t *_core_if )
5160 + if (_core_if->hcd_cb && _core_if->hcd_cb->session_start) {
5161 + _core_if->hcd_cb->session_start( _core_if->hcd_cb->p );
5165 +/** Start the PCD. Helper function for using the PCD callbacks.
5167 + * @param _core_if Programming view of DWC_otg controller.
5169 +static inline void pcd_start( dwc_otg_core_if_t *_core_if )
5171 + if (_core_if->pcd_cb && _core_if->pcd_cb->start ) {
5172 + _core_if->pcd_cb->start( _core_if->pcd_cb->p );
5175 +/** Stop the PCD. Helper function for using the PCD callbacks.
5177 + * @param _core_if Programming view of DWC_otg controller.
5179 +static inline void pcd_stop( dwc_otg_core_if_t *_core_if )
5181 + if (_core_if->pcd_cb && _core_if->pcd_cb->stop ) {
5182 + _core_if->pcd_cb->stop( _core_if->pcd_cb->p );
5185 +/** Suspend the PCD. Helper function for using the PCD callbacks.
5187 + * @param _core_if Programming view of DWC_otg controller.
5189 +static inline void pcd_suspend( dwc_otg_core_if_t *_core_if )
5191 + if (_core_if->pcd_cb && _core_if->pcd_cb->suspend ) {
5192 + _core_if->pcd_cb->suspend( _core_if->pcd_cb->p );
5195 +/** Resume the PCD. Helper function for using the PCD callbacks.
5197 + * @param _core_if Programming view of DWC_otg controller.
5199 +static inline void pcd_resume( dwc_otg_core_if_t *_core_if )
5201 + if (_core_if->pcd_cb && _core_if->pcd_cb->resume_wakeup ) {
5202 + _core_if->pcd_cb->resume_wakeup( _core_if->pcd_cb->p );
5207 + * This function handles the OTG Interrupts. It reads the OTG
5208 + * Interrupt Register (GOTGINT) to determine what interrupt has
5211 + * @param _core_if Programming view of DWC_otg controller.
5213 +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t *_core_if)
5215 + dwc_otg_core_global_regs_t *global_regs =
5216 + _core_if->core_global_regs;
5217 + gotgint_data_t gotgint;
5218 + gotgctl_data_t gotgctl;
5219 + gintmsk_data_t gintmsk;
5221 + gotgint.d32 = dwc_read_reg32( &global_regs->gotgint);
5222 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5223 + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
5224 + op_state_str(_core_if));
5225 + //DWC_DEBUGPL(DBG_CIL, "gotgctl=%08x\n", gotgctl.d32 );
5227 + if (gotgint.b.sesenddet) {
5228 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5229 + "Session End Detected++ (%s)\n",
5230 + op_state_str(_core_if));
5231 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5233 + if (_core_if->op_state == B_HOST) {
5234 + pcd_start( _core_if );
5235 + _core_if->op_state = B_PERIPHERAL;
5237 + /* If not B_HOST and Device HNP still set. HNP
5238 + * Did not succeed!*/
5239 + if (gotgctl.b.devhnpen) {
5240 + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
5241 + DWC_ERROR( "Device Not Connected/Responding!\n" );
5244 + /* If Session End Detected the B-Cable has
5245 + * been disconnected. */
5246 + /* Reset PCD and Gadget driver to a
5248 + pcd_stop(_core_if);
5251 + gotgctl.b.devhnpen = 1;
5252 + dwc_modify_reg32( &global_regs->gotgctl,
5255 + if (gotgint.b.sesreqsucstschng) {
5256 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5257 + "Session Reqeust Success Status Change++\n");
5258 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5259 + if (gotgctl.b.sesreqscs) {
5260 + if ((_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
5261 + (_core_if->core_params->i2c_enable)) {
5262 + _core_if->srp_success = 1;
5265 + pcd_resume( _core_if );
5266 + /* Clear Session Request */
5268 + gotgctl.b.sesreq = 1;
5269 + dwc_modify_reg32( &global_regs->gotgctl,
5274 + if (gotgint.b.hstnegsucstschng) {
5275 + /* Print statements during the HNP interrupt handling
5276 + * can cause it to fail.*/
5277 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
5278 + if (gotgctl.b.hstnegscs) {
5279 + if (dwc_otg_is_host_mode(_core_if) ) {
5280 + _core_if->op_state = B_HOST;
5282 + * Need to disable SOF interrupt immediately.
5283 + * When switching from device to host, the PCD
5284 + * interrupt handler won't handle the
5285 + * interrupt if host mode is already set. The
5286 + * HCD interrupt handler won't get called if
5287 + * the HCD state is HALT. This means that the
5288 + * interrupt does not get handled and Linux
5289 + * complains loudly.
5292 + gintmsk.b.sofintr = 1;
5293 + dwc_modify_reg32(&global_regs->gintmsk,
5295 + pcd_stop(_core_if);
5297 + * Initialize the Core for Host mode.
5299 + hcd_start( _core_if );
5300 + _core_if->op_state = B_HOST;
5304 + gotgctl.b.hnpreq = 1;
5305 + gotgctl.b.devhnpen = 1;
5306 + dwc_modify_reg32( &global_regs->gotgctl,
5308 + DWC_DEBUGPL( DBG_ANY, "HNP Failed\n");
5309 + DWC_ERROR( "Device Not Connected/Responding\n" );
5312 + if (gotgint.b.hstnegdet) {
5313 + /* The disconnect interrupt is set at the same time as
5314 + * Host Negotiation Detected. During the mode
5315 + * switch all interrupts are cleared so the disconnect
5316 + * interrupt handler will not get executed.
5318 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5319 + "Host Negotiation Detected++ (%s)\n",
5320 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"));
5321 + if (dwc_otg_is_device_mode(_core_if)){
5322 + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",_core_if->op_state);
5323 + hcd_disconnect( _core_if );
5324 + pcd_start( _core_if );
5325 + _core_if->op_state = A_PERIPHERAL;
5328 + * Need to disable SOF interrupt immediately. When
5329 + * switching from device to host, the PCD interrupt
5330 + * handler won't handle the interrupt if host mode is
5331 + * already set. The HCD interrupt handler won't get
5332 + * called if the HCD state is HALT. This means that
5333 + * the interrupt does not get handled and Linux
5334 + * complains loudly.
5337 + gintmsk.b.sofintr = 1;
5338 + dwc_modify_reg32(&global_regs->gintmsk,
5340 + pcd_stop( _core_if );
5341 + hcd_start( _core_if );
5342 + _core_if->op_state = A_HOST;
5345 + if (gotgint.b.adevtoutchng) {
5346 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5347 + "A-Device Timeout Change++\n");
5349 + if (gotgint.b.debdone) {
5350 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5351 + "Debounce Done++\n");
5354 + /* Clear GOTGINT */
5355 + dwc_write_reg32 (&_core_if->core_global_regs->gotgint, gotgint.d32);
5361 + * This function handles the Connector ID Status Change Interrupt. It
5362 + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
5363 + * is a Device to Host Mode transition or a Host Mode to Device
5366 + * This only occurs when the cable is connected/removed from the PHY
5369 + * @param _core_if Programming view of DWC_otg controller.
5371 +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t *_core_if)
5373 + uint32_t count = 0;
5375 + gintsts_data_t gintsts = { .d32 = 0 };
5376 + gintmsk_data_t gintmsk = { .d32 = 0 };
5377 + gotgctl_data_t gotgctl = { .d32 = 0 };
5380 + * Need to disable SOF interrupt immediately. If switching from device
5381 + * to host, the PCD interrupt handler won't handle the interrupt if
5382 + * host mode is already set. The HCD interrupt handler won't get
5383 + * called if the HCD state is HALT. This means that the interrupt does
5384 + * not get handled and Linux complains loudly.
5386 + gintmsk.b.sofintr = 1;
5387 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
5389 + DWC_DEBUGPL(DBG_CIL, " ++Connector ID Status Change Interrupt++ (%s)\n",
5390 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"));
5391 + gotgctl.d32 = dwc_read_reg32(&_core_if->core_global_regs->gotgctl);
5392 + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
5393 + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
5395 + /* B-Device connector (Device Mode) */
5396 + if (gotgctl.b.conidsts) {
5397 + /* Wait for switch to device mode. */
5398 + while (!dwc_otg_is_device_mode(_core_if) ){
5399 + DWC_PRINT("Waiting for Peripheral Mode, Mode=%s\n",
5400 + (dwc_otg_is_host_mode(_core_if)?"Host":"Peripheral"));
5402 + if (++count > 10000) *(uint32_t*)NULL=0;
5404 + _core_if->op_state = B_PERIPHERAL;
5405 + dwc_otg_core_init(_core_if);
5406 + dwc_otg_enable_global_interrupts(_core_if);
5407 + pcd_start( _core_if );
5409 + /* A-Device connector (Host Mode) */
5410 + while (!dwc_otg_is_host_mode(_core_if) ) {
5411 + DWC_PRINT("Waiting for Host Mode, Mode=%s\n",
5412 + (dwc_otg_is_host_mode(_core_if)?"Host":"Peripheral"));
5414 + if (++count > 10000) *(uint32_t*)NULL=0;
5416 + _core_if->op_state = A_HOST;
5418 + * Initialize the Core for Host mode.
5420 + dwc_otg_core_init(_core_if);
5421 + dwc_otg_enable_global_interrupts(_core_if);
5422 + hcd_start( _core_if );
5425 + /* Set flag and clear interrupt */
5426 + gintsts.b.conidstschng = 1;
5427 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5433 + * This interrupt indicates that a device is initiating the Session
5434 + * Request Protocol to request the host to turn on bus power so a new
5435 + * session can begin. The handler responds by turning on bus power. If
5436 + * the DWC_otg controller is in low power mode, the handler brings the
5437 + * controller out of low power mode before turning on bus power.
5439 + * @param _core_if Programming view of DWC_otg controller.
5441 +int32_t dwc_otg_handle_session_req_intr( dwc_otg_core_if_t *_core_if )
5443 +#ifndef DWC_HOST_ONLY // winder
5444 + hprt0_data_t hprt0;
5446 + gintsts_data_t gintsts;
5448 +#ifndef DWC_HOST_ONLY
5449 + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
5451 + if (dwc_otg_is_device_mode(_core_if) ) {
5452 + DWC_PRINT("SRP: Device mode\n");
5454 + DWC_PRINT("SRP: Host mode\n");
5456 + /* Turn on the port power bit. */
5457 + hprt0.d32 = dwc_otg_read_hprt0( _core_if );
5458 + hprt0.b.prtpwr = 1;
5459 + dwc_write_reg32(_core_if->host_if->hprt0, hprt0.d32);
5461 + /* Start the Connection timer. So a message can be displayed
5462 + * if connect does not occur within 10 seconds. */
5463 + hcd_session_start( _core_if );
5467 + /* Clear interrupt */
5469 + gintsts.b.sessreqintr = 1;
5470 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5476 + * This interrupt indicates that the DWC_otg controller has detected a
5477 + * resume or remote wakeup sequence. If the DWC_otg controller is in
5478 + * low power mode, the handler must brings the controller out of low
5479 + * power mode. The controller automatically begins resume
5480 + * signaling. The handler schedules a time to stop resume signaling.
5482 +int32_t dwc_otg_handle_wakeup_detected_intr( dwc_otg_core_if_t *_core_if )
5484 + gintsts_data_t gintsts;
5486 + DWC_DEBUGPL(DBG_ANY, "++Resume and Remote Wakeup Detected Interrupt++\n");
5488 + if (dwc_otg_is_device_mode(_core_if) ) {
5489 + dctl_data_t dctl = {.d32=0};
5490 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
5491 + dwc_read_reg32( &_core_if->dev_if->dev_global_regs->dsts));
5492 +#ifdef PARTIAL_POWER_DOWN
5493 + if (_core_if->hwcfg4.b.power_optimiz) {
5494 + pcgcctl_data_t power = {.d32=0};
5496 + power.d32 = dwc_read_reg32( _core_if->pcgcctl );
5497 + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n", power.d32);
5499 + power.b.stoppclk = 0;
5500 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5502 + power.b.pwrclmp = 0;
5503 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5505 + power.b.rstpdwnmodule = 0;
5506 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5509 + /* Clear the Remote Wakeup Signalling */
5510 + dctl.b.rmtwkupsig = 1;
5511 + dwc_modify_reg32( &_core_if->dev_if->dev_global_regs->dctl,
5514 + if (_core_if->pcd_cb && _core_if->pcd_cb->resume_wakeup) {
5515 + _core_if->pcd_cb->resume_wakeup( _core_if->pcd_cb->p );
5520 + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
5521 + * so that OPT tests pass with all PHYs).
5523 + hprt0_data_t hprt0 = {.d32=0};
5524 + pcgcctl_data_t pcgcctl = {.d32=0};
5525 + /* Restart the Phy Clock */
5526 + pcgcctl.b.stoppclk = 1;
5527 + dwc_modify_reg32(_core_if->pcgcctl, pcgcctl.d32, 0);
5530 + /* Now wait for 70 ms. */
5531 + hprt0.d32 = dwc_otg_read_hprt0( _core_if );
5532 + DWC_DEBUGPL(DBG_ANY,"Resume: HPRT0=%0x\n", hprt0.d32);
5534 + hprt0.b.prtres = 0; /* Resume */
5535 + dwc_write_reg32(_core_if->host_if->hprt0, hprt0.d32);
5536 + DWC_DEBUGPL(DBG_ANY,"Clear Resume: HPRT0=%0x\n", dwc_read_reg32(_core_if->host_if->hprt0));
5539 + /* Clear interrupt */
5541 + gintsts.b.wkupintr = 1;
5542 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5548 + * This interrupt indicates that a device has been disconnected from
5551 +int32_t dwc_otg_handle_disconnect_intr( dwc_otg_core_if_t *_core_if)
5553 + gintsts_data_t gintsts;
5555 + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
5556 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"),
5557 + op_state_str(_core_if));
5559 +/** @todo Consolidate this if statement. */
5560 +#ifndef DWC_HOST_ONLY
5561 + if (_core_if->op_state == B_HOST) {
5562 + /* If in device mode Disconnect and stop the HCD, then
5563 + * start the PCD. */
5564 + hcd_disconnect( _core_if );
5565 + pcd_start( _core_if );
5566 + _core_if->op_state = B_PERIPHERAL;
5567 + } else if (dwc_otg_is_device_mode(_core_if)) {
5568 + gotgctl_data_t gotgctl = { .d32 = 0 };
5569 + gotgctl.d32 = dwc_read_reg32(&_core_if->core_global_regs->gotgctl);
5570 + if (gotgctl.b.hstsethnpen==1) {
5571 + /* Do nothing, if HNP in process the OTG
5572 + * interrupt "Host Negotiation Detected"
5573 + * interrupt will do the mode switch.
5575 + } else if (gotgctl.b.devhnpen == 0) {
5576 + /* If in device mode Disconnect and stop the HCD, then
5577 + * start the PCD. */
5578 + hcd_disconnect( _core_if );
5579 + pcd_start( _core_if );
5580 + _core_if->op_state = B_PERIPHERAL;
5582 + DWC_DEBUGPL(DBG_ANY,"!a_peripheral && !devhnpen\n");
5585 + if (_core_if->op_state == A_HOST) {
5586 + /* A-Cable still connected but device disconnected. */
5587 + hcd_disconnect( _core_if );
5591 +/* Without OTG, we should use the disconnect function!? winder added.*/
5592 +#if 1 // NO OTG, so host only!!
5593 + hcd_disconnect( _core_if );
5597 + gintsts.b.disconnect = 1;
5598 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5602 + * This interrupt indicates that SUSPEND state has been detected on
5605 + * For HNP the USB Suspend interrupt signals the change from
5606 + * "a_peripheral" to "a_host".
5608 + * When power management is enabled the core will be put in low power
5611 +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t *_core_if )
5614 + gintsts_data_t gintsts;
5616 + //805141:<IFTW-fchang>.removed DWC_DEBUGPL(DBG_ANY,"USB SUSPEND\n");
5618 + if (dwc_otg_is_device_mode( _core_if ) ) {
5619 + /* Check the Device status register to determine if the Suspend
5620 + * state is active. */
5621 + dsts.d32 = dwc_read_reg32( &_core_if->dev_if->dev_global_regs->dsts);
5622 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
5623 + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
5624 + "HWCFG4.power Optimize=%d\n",
5625 + dsts.b.suspsts, _core_if->hwcfg4.b.power_optimiz);
5628 +#ifdef PARTIAL_POWER_DOWN
5629 +/** @todo Add a module parameter for power management. */
5631 + if (dsts.b.suspsts && _core_if->hwcfg4.b.power_optimiz) {
5632 + pcgcctl_data_t power = {.d32=0};
5633 + DWC_DEBUGPL(DBG_CIL, "suspend\n");
5635 + power.b.pwrclmp = 1;
5636 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5638 + power.b.rstpdwnmodule = 1;
5639 + dwc_modify_reg32( _core_if->pcgcctl, 0, power.d32);
5641 + power.b.stoppclk = 1;
5642 + dwc_modify_reg32( _core_if->pcgcctl, 0, power.d32);
5645 + DWC_DEBUGPL(DBG_ANY,"disconnect?\n");
5648 + /* PCD callback for suspend. */
5649 + pcd_suspend(_core_if);
5651 + if (_core_if->op_state == A_PERIPHERAL) {
5652 + DWC_DEBUGPL(DBG_ANY,"a_peripheral->a_host\n");
5653 + /* Clear the a_peripheral flag, back to a_host. */
5654 + pcd_stop( _core_if );
5655 + hcd_start( _core_if );
5656 + _core_if->op_state = A_HOST;
5660 + /* Clear interrupt */
5662 + gintsts.b.usbsuspend = 1;
5663 + dwc_write_reg32( &_core_if->core_global_regs->gintsts, gintsts.d32);
5670 + * This function returns the Core Interrupt register.
5672 +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t *_core_if)
5674 + gintsts_data_t gintsts;
5675 + gintmsk_data_t gintmsk;
5676 + gintmsk_data_t gintmsk_common = {.d32=0};
5677 + gintmsk_common.b.wkupintr = 1;
5678 + gintmsk_common.b.sessreqintr = 1;
5679 + gintmsk_common.b.conidstschng = 1;
5680 + gintmsk_common.b.otgintr = 1;
5681 + gintmsk_common.b.modemismatch = 1;
5682 + gintmsk_common.b.disconnect = 1;
5683 + gintmsk_common.b.usbsuspend = 1;
5684 + /** @todo: The port interrupt occurs while in device
5685 + * mode. Added code to CIL to clear the interrupt for now!
5687 + gintmsk_common.b.portintr = 1;
5689 + gintsts.d32 = dwc_read_reg32(&_core_if->core_global_regs->gintsts);
5690 + gintmsk.d32 = dwc_read_reg32(&_core_if->core_global_regs->gintmsk);
5692 + /* if any common interrupts set */
5693 + if (gintsts.d32 & gintmsk_common.d32) {
5694 + DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
5695 + gintsts.d32, gintmsk.d32);
5699 + return ((gintsts.d32 & gintmsk.d32 ) & gintmsk_common.d32);
5704 + * Common interrupt handler.
5706 + * The common interrupts are those that occur in both Host and Device mode.
5707 + * This handler handles the following interrupts:
5708 + * - Mode Mismatch Interrupt
5709 + * - Disconnect Interrupt
5711 + * - Connector ID Status Change Interrupt
5712 + * - Session Request Interrupt.
5713 + * - Resume / Remote Wakeup Detected Interrupt.
5716 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if )
5719 + gintsts_data_t gintsts;
5721 + gintsts.d32 = dwc_otg_read_common_intr(_core_if);
5723 + if (gintsts.b.modemismatch) {
5724 + retval |= dwc_otg_handle_mode_mismatch_intr( _core_if );
5726 + if (gintsts.b.otgintr) {
5727 + retval |= dwc_otg_handle_otg_intr( _core_if );
5729 + if (gintsts.b.conidstschng) {
5730 + retval |= dwc_otg_handle_conn_id_status_change_intr( _core_if );
5732 + if (gintsts.b.disconnect) {
5733 + retval |= dwc_otg_handle_disconnect_intr( _core_if );
5735 + if (gintsts.b.sessreqintr) {
5736 + retval |= dwc_otg_handle_session_req_intr( _core_if );
5738 + if (gintsts.b.wkupintr) {
5739 + retval |= dwc_otg_handle_wakeup_detected_intr( _core_if );
5741 + if (gintsts.b.usbsuspend) {
5742 + retval |= dwc_otg_handle_usb_suspend_intr( _core_if );
5744 + if (gintsts.b.portintr && dwc_otg_is_device_mode(_core_if)) {
5745 + /* The port interrupt occurs while in device mode with HPRT0
5746 + * Port Enable/Disable.
5749 + gintsts.b.portintr = 1;
5750 + dwc_write_reg32(&_core_if->core_global_regs->gintsts,
5758 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.c
5760 +/* ==========================================================================
5761 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.c $
5762 + * $Revision: 1.1.1.1 $
5763 + * $Date: 2009-04-17 06:15:34 $
5764 + * $Change: 631780 $
5766 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
5767 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
5768 + * otherwise expressly agreed to in writing between Synopsys and you.
5770 + * The Software IS NOT an item of Licensed Software or Licensed Product under
5771 + * any End User Software License Agreement or Agreement for Licensed Product
5772 + * with Synopsys or any supplement thereto. You are permitted to use and
5773 + * redistribute this Software in source and binary forms, with or without
5774 + * modification, provided that redistributions of source code must retain this
5775 + * notice. You may not view, use, disclose, copy or distribute this file or
5776 + * any information contained herein except pursuant to this license grant from
5777 + * Synopsys. If you do not agree with this notice, including the disclaimer
5778 + * below, then you are not authorized to use the Software.
5780 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
5781 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5782 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5783 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
5784 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5785 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5786 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5787 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5788 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5789 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
5791 + * ========================================================================== */
5794 + * The dwc_otg_driver module provides the initialization and cleanup entry
5795 + * points for the DWC_otg driver. This module will be dynamically installed
5796 + * after Linux is booted using the insmod command. When the module is
5797 + * installed, the dwc_otg_init function is called. When the module is
5798 + * removed (using rmmod), the dwc_otg_cleanup function is called.
5800 + * This module also defines a data structure for the dwc_otg_driver, which is
5801 + * used in conjunction with the standard ARM lm_device structure. These
5802 + * structures allow the OTG driver to comply with the standard Linux driver
5803 + * model in which devices and drivers are registered with a bus driver. This
5804 + * has the benefit that Linux can expose attributes of the driver and device
5805 + * in its special sysfs file system. Users can then read or write files in
5806 + * this file system to perform diagnostics on the driver components or the
5810 +#include <linux/kernel.h>
5811 +#include <linux/module.h>
5812 +#include <linux/moduleparam.h>
5813 +#include <linux/init.h>
5814 +#include <linux/gpio.h>
5816 +#include <linux/device.h>
5817 +#include <linux/platform_device.h>
5819 +#include <linux/errno.h>
5820 +#include <linux/types.h>
5821 +#include <linux/stat.h> /* permission constants */
5822 +#include <linux/irq.h>
5823 +#include <asm/io.h>
5825 +#include "dwc_otg_plat.h"
5826 +#include "dwc_otg_attr.h"
5827 +#include "dwc_otg_driver.h"
5828 +#include "dwc_otg_cil.h"
5829 +#include "dwc_otg_cil_ifx.h"
5831 +// #include "dwc_otg_pcd.h" // device
5832 +#include "dwc_otg_hcd.h" // host
5834 +#include "dwc_otg_ifx.h" // for Infineon platform specific.
5836 +#define DWC_DRIVER_VERSION "2.60a 22-NOV-2006"
5837 +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
5839 +const char dwc_driver_name[] = "dwc_otg";
5841 +static unsigned long dwc_iomem_base = IFX_USB_IOMEM_BASE;
5842 +int dwc_irq = LTQ_USB_INT;
5843 +//int dwc_irq = 54;
5844 +//int dwc_irq = IFXMIPS_USB_OC_INT;
5846 +extern int ifx_usb_hc_init(unsigned long base_addr, int irq);
5847 +extern void ifx_usb_hc_remove(void);
5849 +/*-------------------------------------------------------------------------*/
5850 +/* Encapsulate the module parameter settings */
5852 +static dwc_otg_core_params_t dwc_otg_module_params = {
5856 + .dma_burst_size = -1,
5858 + .host_support_fs_ls_low_power = -1,
5859 + .host_ls_low_power_phy_clk = -1,
5860 + .enable_dynamic_fifo = -1,
5861 + .data_fifo_size = -1,
5862 + .dev_rx_fifo_size = -1,
5863 + .dev_nperio_tx_fifo_size = -1,
5864 + .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 */
5865 + .host_rx_fifo_size = -1,
5866 + .host_nperio_tx_fifo_size = -1,
5867 + .host_perio_tx_fifo_size = -1,
5868 + .max_transfer_size = -1,
5869 + .max_packet_count = -1,
5870 + .host_channels = -1,
5871 + .dev_endpoints = -1,
5873 + .phy_utmi_width = -1,
5874 + .phy_ulpi_ddr = -1,
5875 + .phy_ulpi_ext_vbus = -1,
5879 + .en_multiple_tx_fifo = -1,
5880 + .dev_tx_fifo_size = { /* dev_tx_fifo_size */
5881 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
5884 + .tx_thr_length = -1,
5885 + .rx_thr_length = -1,
5889 + * This function shows the Driver Version.
5891 +static ssize_t version_show(struct device_driver *dev, char *buf)
5893 + return snprintf(buf, sizeof(DWC_DRIVER_VERSION)+2,"%s\n",
5894 + DWC_DRIVER_VERSION);
5896 +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
5899 + * Global Debug Level Mask.
5901 +uint32_t g_dbg_lvl = 0xff; /* OFF */
5904 + * This function shows the driver Debug Level.
5906 +static ssize_t dbg_level_show(struct device_driver *_drv, char *_buf)
5908 + return sprintf(_buf, "0x%0x\n", g_dbg_lvl);
5911 + * This function stores the driver Debug Level.
5913 +static ssize_t dbg_level_store(struct device_driver *_drv, const char *_buf,
5916 + g_dbg_lvl = simple_strtoul(_buf, NULL, 16);
5919 +static DRIVER_ATTR(debuglevel, S_IRUGO|S_IWUSR, dbg_level_show, dbg_level_store);
5922 + * This function is called during module intialization to verify that
5923 + * the module parameters are in a valid state.
5925 +static int check_parameters(dwc_otg_core_if_t *core_if)
5930 +/* Checks if the parameter is outside of its valid range of values */
5931 +#define DWC_OTG_PARAM_TEST(_param_,_low_,_high_) \
5932 + ((dwc_otg_module_params._param_ < (_low_)) || \
5933 + (dwc_otg_module_params._param_ > (_high_)))
5935 +/* If the parameter has been set by the user, check that the parameter value is
5936 + * within the value range of values. If not, report a module error. */
5937 +#define DWC_OTG_PARAM_ERR(_param_,_low_,_high_,_string_) \
5939 + if (dwc_otg_module_params._param_ != -1) { \
5940 + if (DWC_OTG_PARAM_TEST(_param_,(_low_),(_high_))) { \
5941 + DWC_ERROR("`%d' invalid for parameter `%s'\n", \
5942 + dwc_otg_module_params._param_, _string_); \
5943 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
5949 + DWC_OTG_PARAM_ERR(opt,0,1,"opt");
5950 + DWC_OTG_PARAM_ERR(otg_cap,0,2,"otg_cap");
5951 + DWC_OTG_PARAM_ERR(dma_enable,0,1,"dma_enable");
5952 + DWC_OTG_PARAM_ERR(speed,0,1,"speed");
5953 + DWC_OTG_PARAM_ERR(host_support_fs_ls_low_power,0,1,"host_support_fs_ls_low_power");
5954 + DWC_OTG_PARAM_ERR(host_ls_low_power_phy_clk,0,1,"host_ls_low_power_phy_clk");
5955 + DWC_OTG_PARAM_ERR(enable_dynamic_fifo,0,1,"enable_dynamic_fifo");
5956 + DWC_OTG_PARAM_ERR(data_fifo_size,32,32768,"data_fifo_size");
5957 + DWC_OTG_PARAM_ERR(dev_rx_fifo_size,16,32768,"dev_rx_fifo_size");
5958 + DWC_OTG_PARAM_ERR(dev_nperio_tx_fifo_size,16,32768,"dev_nperio_tx_fifo_size");
5959 + DWC_OTG_PARAM_ERR(host_rx_fifo_size,16,32768,"host_rx_fifo_size");
5960 + DWC_OTG_PARAM_ERR(host_nperio_tx_fifo_size,16,32768,"host_nperio_tx_fifo_size");
5961 + DWC_OTG_PARAM_ERR(host_perio_tx_fifo_size,16,32768,"host_perio_tx_fifo_size");
5962 + DWC_OTG_PARAM_ERR(max_transfer_size,2047,524288,"max_transfer_size");
5963 + DWC_OTG_PARAM_ERR(max_packet_count,15,511,"max_packet_count");
5964 + DWC_OTG_PARAM_ERR(host_channels,1,16,"host_channels");
5965 + DWC_OTG_PARAM_ERR(dev_endpoints,1,15,"dev_endpoints");
5966 + DWC_OTG_PARAM_ERR(phy_type,0,2,"phy_type");
5967 + DWC_OTG_PARAM_ERR(phy_ulpi_ddr,0,1,"phy_ulpi_ddr");
5968 + DWC_OTG_PARAM_ERR(phy_ulpi_ext_vbus,0,1,"phy_ulpi_ext_vbus");
5969 + DWC_OTG_PARAM_ERR(i2c_enable,0,1,"i2c_enable");
5970 + DWC_OTG_PARAM_ERR(ulpi_fs_ls,0,1,"ulpi_fs_ls");
5971 + DWC_OTG_PARAM_ERR(ts_dline,0,1,"ts_dline");
5973 + if (dwc_otg_module_params.dma_burst_size != -1) {
5974 + if (DWC_OTG_PARAM_TEST(dma_burst_size,1,1) &&
5975 + DWC_OTG_PARAM_TEST(dma_burst_size,4,4) &&
5976 + DWC_OTG_PARAM_TEST(dma_burst_size,8,8) &&
5977 + DWC_OTG_PARAM_TEST(dma_burst_size,16,16) &&
5978 + DWC_OTG_PARAM_TEST(dma_burst_size,32,32) &&
5979 + DWC_OTG_PARAM_TEST(dma_burst_size,64,64) &&
5980 + DWC_OTG_PARAM_TEST(dma_burst_size,128,128) &&
5981 + DWC_OTG_PARAM_TEST(dma_burst_size,256,256))
5983 + DWC_ERROR("`%d' invalid for parameter `dma_burst_size'\n",
5984 + dwc_otg_module_params.dma_burst_size);
5985 + dwc_otg_module_params.dma_burst_size = 32;
5990 + if (dwc_otg_module_params.phy_utmi_width != -1) {
5991 + if (DWC_OTG_PARAM_TEST(phy_utmi_width,8,8) &&
5992 + DWC_OTG_PARAM_TEST(phy_utmi_width,16,16))
5994 + DWC_ERROR("`%d' invalid for parameter `phy_utmi_width'\n",
5995 + dwc_otg_module_params.phy_utmi_width);
5996 + //dwc_otg_module_params.phy_utmi_width = 16;
5997 + dwc_otg_module_params.phy_utmi_width = 8;
6002 + for (i=0; i<15; i++) {
6003 + /** @todo should be like above */
6004 + //DWC_OTG_PARAM_ERR(dev_perio_tx_fifo_size[i],4,768,"dev_perio_tx_fifo_size");
6005 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
6006 + if (DWC_OTG_PARAM_TEST(dev_perio_tx_fifo_size[i],4,768)) {
6007 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
6008 + dwc_otg_module_params.dev_perio_tx_fifo_size[i], "dev_perio_tx_fifo_size", i);
6009 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
6015 + DWC_OTG_PARAM_ERR(en_multiple_tx_fifo, 0, 1, "en_multiple_tx_fifo");
6016 + for (i = 0; i < 15; i++) {
6017 + /** @todo should be like above */
6018 + //DWC_OTG_PARAM_ERR(dev_tx_fifo_size[i],4,768,"dev_tx_fifo_size");
6019 + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
6020 + if (DWC_OTG_PARAM_TEST(dev_tx_fifo_size[i], 4, 768)) {
6021 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
6022 + dwc_otg_module_params.dev_tx_fifo_size[i],
6023 + "dev_tx_fifo_size", i);
6024 + dwc_otg_module_params.dev_tx_fifo_size[i] =
6025 + dwc_param_dev_tx_fifo_size_default;
6030 + DWC_OTG_PARAM_ERR(thr_ctl, 0, 7, "thr_ctl");
6031 + DWC_OTG_PARAM_ERR(tx_thr_length, 8, 128, "tx_thr_length");
6032 + DWC_OTG_PARAM_ERR(rx_thr_length, 8, 128, "rx_thr_length");
6034 + /* At this point, all module parameters that have been set by the user
6035 + * are valid, and those that have not are left unset. Now set their
6036 + * default values and/or check the parameters against the hardware
6037 + * configurations of the OTG core. */
6041 +/* This sets the parameter to the default value if it has not been set by the
6043 +#define DWC_OTG_PARAM_SET_DEFAULT(_param_) \
6045 + int changed = 1; \
6046 + if (dwc_otg_module_params._param_ == -1) { \
6048 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
6053 +/* This checks the macro agains the hardware configuration to see if it is
6054 + * valid. It is possible that the default value could be invalid. In this
6055 + * case, it will report a module error if the user touched the parameter.
6056 + * Otherwise it will adjust the value without any error. */
6057 +#define DWC_OTG_PARAM_CHECK_VALID(_param_,_str_,_is_valid_,_set_valid_) \
6059 + int changed = DWC_OTG_PARAM_SET_DEFAULT(_param_); \
6061 + if (!(_is_valid_)) { \
6063 + DWC_ERROR("`%d' invalid for parameter `%s'. Check HW configuration.\n", dwc_otg_module_params._param_,_str_); \
6066 + dwc_otg_module_params._param_ = (_set_valid_); \
6072 + retval += DWC_OTG_PARAM_CHECK_VALID(otg_cap,"otg_cap",
6076 + switch (dwc_otg_module_params.otg_cap) {
6077 + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
6078 + if (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) valid = 0;
6080 + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
6081 + if ((core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) &&
6082 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) &&
6083 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) &&
6084 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST))
6089 + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
6090 + /* always valid */
6095 + (((core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) ||
6096 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) ||
6097 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
6098 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
6099 + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
6100 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE));
6102 + retval += DWC_OTG_PARAM_CHECK_VALID(dma_enable,"dma_enable",
6103 + ((dwc_otg_module_params.dma_enable == 1) && (core_if->hwcfg2.b.architecture == 0)) ? 0 : 1,
6106 + retval += DWC_OTG_PARAM_CHECK_VALID(opt,"opt",
6110 + DWC_OTG_PARAM_SET_DEFAULT(dma_burst_size);
6112 + retval += DWC_OTG_PARAM_CHECK_VALID(host_support_fs_ls_low_power,
6113 + "host_support_fs_ls_low_power",
6116 + retval += DWC_OTG_PARAM_CHECK_VALID(enable_dynamic_fifo,
6117 + "enable_dynamic_fifo",
6118 + ((dwc_otg_module_params.enable_dynamic_fifo == 0) ||
6119 + (core_if->hwcfg2.b.dynamic_fifo == 1)), 0);
6122 + retval += DWC_OTG_PARAM_CHECK_VALID(data_fifo_size,
6124 + (dwc_otg_module_params.data_fifo_size <= core_if->hwcfg3.b.dfifo_depth),
6125 + core_if->hwcfg3.b.dfifo_depth);
6127 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_rx_fifo_size,
6128 + "dev_rx_fifo_size",
6129 + (dwc_otg_module_params.dev_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
6130 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
6132 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_nperio_tx_fifo_size,
6133 + "dev_nperio_tx_fifo_size",
6134 + (dwc_otg_module_params.dev_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
6135 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
6137 + retval += DWC_OTG_PARAM_CHECK_VALID(host_rx_fifo_size,
6138 + "host_rx_fifo_size",
6139 + (dwc_otg_module_params.host_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
6140 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
6143 + retval += DWC_OTG_PARAM_CHECK_VALID(host_nperio_tx_fifo_size,
6144 + "host_nperio_tx_fifo_size",
6145 + (dwc_otg_module_params.host_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
6146 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
6148 + retval += DWC_OTG_PARAM_CHECK_VALID(host_perio_tx_fifo_size,
6149 + "host_perio_tx_fifo_size",
6150 + (dwc_otg_module_params.host_perio_tx_fifo_size <= ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16))),
6151 + ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16)));
6153 + retval += DWC_OTG_PARAM_CHECK_VALID(max_transfer_size,
6154 + "max_transfer_size",
6155 + (dwc_otg_module_params.max_transfer_size < (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))),
6156 + ((1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1));
6158 + retval += DWC_OTG_PARAM_CHECK_VALID(max_packet_count,
6159 + "max_packet_count",
6160 + (dwc_otg_module_params.max_packet_count < (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))),
6161 + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1));
6163 + retval += DWC_OTG_PARAM_CHECK_VALID(host_channels,
6165 + (dwc_otg_module_params.host_channels <= (core_if->hwcfg2.b.num_host_chan + 1)),
6166 + (core_if->hwcfg2.b.num_host_chan + 1));
6168 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_endpoints,
6170 + (dwc_otg_module_params.dev_endpoints <= (core_if->hwcfg2.b.num_dev_ep)),
6171 + core_if->hwcfg2.b.num_dev_ep);
6174 + * Define the following to disable the FS PHY Hardware checking. This is for
6175 + * internal testing only.
6177 + * #define NO_FS_PHY_HW_CHECKS
6180 +#ifdef NO_FS_PHY_HW_CHECKS
6181 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
6182 + "phy_type", 1, 0);
6184 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
6188 + if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_UTMI) &&
6189 + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
6190 + (core_if->hwcfg2.b.hs_phy_type == 3)))
6194 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_ULPI) &&
6195 + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
6196 + (core_if->hwcfg2.b.hs_phy_type == 3)))
6200 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) &&
6201 + (core_if->hwcfg2.b.fs_phy_type == 1))
6208 + int set = DWC_PHY_TYPE_PARAM_FS;
6209 + if (core_if->hwcfg2.b.hs_phy_type) {
6210 + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
6211 + (core_if->hwcfg2.b.hs_phy_type == 1)) {
6212 + set = DWC_PHY_TYPE_PARAM_UTMI;
6215 + set = DWC_PHY_TYPE_PARAM_ULPI;
6222 + retval += DWC_OTG_PARAM_CHECK_VALID(speed,"speed",
6223 + (dwc_otg_module_params.speed == 0) && (dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1,
6224 + dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
6226 + retval += DWC_OTG_PARAM_CHECK_VALID(host_ls_low_power_phy_clk,
6227 + "host_ls_low_power_phy_clk",
6228 + ((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),
6229 + ((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));
6231 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ddr);
6232 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ext_vbus);
6233 + DWC_OTG_PARAM_SET_DEFAULT(phy_utmi_width);
6234 + DWC_OTG_PARAM_SET_DEFAULT(ulpi_fs_ls);
6235 + DWC_OTG_PARAM_SET_DEFAULT(ts_dline);
6237 +#ifdef NO_FS_PHY_HW_CHECKS
6238 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
6239 + "i2c_enable", 1, 0);
6241 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
6243 + (dwc_otg_module_params.i2c_enable == 1) && (core_if->hwcfg3.b.i2c == 0) ? 0 : 1,
6247 + for (i=0; i<16; i++) {
6252 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] == -1) {
6254 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
6256 + if (!(dwc_otg_module_params.dev_perio_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
6258 + 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);
6261 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
6266 + retval += DWC_OTG_PARAM_CHECK_VALID(en_multiple_tx_fifo,
6267 + "en_multiple_tx_fifo",
6268 + ((dwc_otg_module_params.en_multiple_tx_fifo == 1) &&
6269 + (core_if->hwcfg4.b.ded_fifo_en == 0)) ? 0 : 1, 0);
6271 + for (i = 0; i < 16; i++) {
6274 + if (dwc_otg_module_params.dev_tx_fifo_size[i] == -1) {
6276 + dwc_otg_module_params.dev_tx_fifo_size[i] =
6277 + dwc_param_dev_tx_fifo_size_default;
6279 + if (!(dwc_otg_module_params.dev_tx_fifo_size[i] <=
6280 + (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
6282 + DWC_ERROR("%d' invalid for parameter `dev_perio_fifo_size_%d'."
6283 + "Check HW configuration.\n",dwc_otg_module_params.dev_tx_fifo_size[i],i);
6286 + dwc_otg_module_params.dev_tx_fifo_size[i] =
6287 + dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
6291 + DWC_OTG_PARAM_SET_DEFAULT(thr_ctl);
6292 + DWC_OTG_PARAM_SET_DEFAULT(tx_thr_length);
6293 + DWC_OTG_PARAM_SET_DEFAULT(rx_thr_length);
6295 +} // check_parameters
6299 + * This function is the top level interrupt handler for the Common
6300 + * (Device and host modes) interrupts.
6302 +static irqreturn_t dwc_otg_common_irq(int _irq, void *_dev)
6304 + dwc_otg_device_t *otg_dev = _dev;
6305 + int32_t retval = IRQ_NONE;
6307 + retval = dwc_otg_handle_common_intr( otg_dev->core_if );
6309 + mask_and_ack_ifx_irq (_irq);
6311 + return IRQ_RETVAL(retval);
6316 + * This function is called when a DWC_OTG device is unregistered with the
6317 + * dwc_otg_driver. This happens, for example, when the rmmod command is
6318 + * executed. The device may or may not be electrically present. If it is
6319 + * present, the driver stops device processing. Any resources used on behalf
6320 + * of this device are freed.
6325 +dwc_otg_driver_remove(struct platform_device *_dev)
6327 + //dwc_otg_device_t *otg_dev = dev_get_drvdata(&_dev->dev);
6328 + dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
6330 + DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, _dev);
6332 + if (otg_dev == NULL) {
6333 + /* Memory allocation for the dwc_otg_device failed. */
6340 + if (otg_dev->common_irq_installed) {
6341 + free_irq( otg_dev->irq, otg_dev );
6344 +#ifndef DWC_DEVICE_ONLY
6345 + if (otg_dev->hcd != NULL) {
6346 + dwc_otg_hcd_remove(&_dev->dev);
6349 + printk("after removehcd\n");
6351 +// Note: Integrate HOST and DEVICE(Gadget) is not planned yet.
6352 +#ifndef DWC_HOST_ONLY
6353 + if (otg_dev->pcd != NULL) {
6354 + dwc_otg_pcd_remove(otg_dev);
6357 + if (otg_dev->core_if != NULL) {
6358 + dwc_otg_cil_remove( otg_dev->core_if );
6360 + printk("after removecil\n");
6363 + * Remove the device attributes
6365 + dwc_otg_attr_remove(&_dev->dev);
6366 + printk("after removeattr\n");
6369 + * Return the memory.
6371 + if (otg_dev->base != NULL) {
6372 + iounmap(otg_dev->base);
6374 + if (otg_dev->phys_addr != 0) {
6375 + release_mem_region(otg_dev->phys_addr, otg_dev->base_len);
6380 + * Clear the drvdata pointer.
6382 + //dev_set_drvdata(&_dev->dev, 0);
6383 + platform_set_drvdata(_dev, 0);
6388 + * This function is called when an DWC_OTG device is bound to a
6389 + * dwc_otg_driver. It creates the driver components required to
6390 + * control the device (CIL, HCD, and PCD) and it initializes the
6391 + * device. The driver components are stored in a dwc_otg_device
6392 + * structure. A reference to the dwc_otg_device is saved in the
6393 + * lm_device. This allows the driver to access the dwc_otg_device
6394 + * structure on subsequent calls to driver methods for this device.
6398 +static int __devinit
6399 +dwc_otg_driver_probe(struct platform_device *_dev)
6402 + dwc_otg_device_t *dwc_otg_device;
6403 + int pin = (int)_dev->dev.platform_data;
6405 + struct resource *res;
6406 + gusbcfg_data_t usbcfg = {.d32 = 0};
6411 + gpio_request(pin, "usb_power");
6412 + gpio_direction_output(pin, 1);
6413 + gpio_set_value(pin, 1);
6414 + gpio_export(pin, 0);
6416 + dev_dbg(&_dev->dev, "dwc_otg_driver_probe (%p)\n", _dev);
6418 + dwc_otg_device = kmalloc(sizeof(dwc_otg_device_t), GFP_KERNEL);
6419 + if (dwc_otg_device == 0) {
6420 + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
6424 + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
6425 + dwc_otg_device->reg_offset = 0xFFFFFFFF;
6428 + * Retrieve the memory and IRQ resources.
6430 + dwc_otg_device->irq = platform_get_irq(_dev, 0);
6431 + if (dwc_otg_device->irq == 0) {
6432 + dev_err(&_dev->dev, "no device irq\n");
6436 + dev_dbg(&_dev->dev, "OTG - device irq: %d\n", dwc_otg_device->irq);
6437 + res = platform_get_resource(_dev, IORESOURCE_MEM, 0);
6438 + if (res == NULL) {
6439 + dev_err(&_dev->dev, "no CSR address\n");
6443 + dev_dbg(&_dev->dev, "OTG - ioresource_mem start0x%08x: end:0x%08x\n",
6444 + (unsigned)res->start, (unsigned)res->end);
6445 + dwc_otg_device->phys_addr = res->start;
6446 + dwc_otg_device->base_len = res->end - res->start + 1;
6447 + if (request_mem_region(dwc_otg_device->phys_addr, dwc_otg_device->base_len,
6448 + dwc_driver_name) == NULL) {
6449 + dev_err(&_dev->dev, "request_mem_region failed\n");
6455 + * Map the DWC_otg Core memory into virtual address space.
6457 + dwc_otg_device->base = ioremap_nocache(dwc_otg_device->phys_addr, dwc_otg_device->base_len);
6458 + if (dwc_otg_device->base == NULL) {
6459 + dev_err(&_dev->dev, "ioremap() failed\n");
6463 + dev_dbg(&_dev->dev, "mapped base=0x%08x\n", (unsigned)dwc_otg_device->base);
6466 + * Attempt to ensure this device is really a DWC_otg Controller.
6467 + * Read and verify the SNPSID register contents. The value should be
6468 + * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
6470 + snpsid = dwc_read_reg32((uint32_t *)((uint8_t *)dwc_otg_device->base + 0x40));
6471 + if ((snpsid & 0xFFFFF000) != 0x4F542000) {
6472 + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n", snpsid);
6478 + * Initialize driver data to point to the global DWC_otg
6479 + * Device structure.
6481 + platform_set_drvdata(_dev, dwc_otg_device);
6482 + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
6483 + dwc_otg_device->core_if = dwc_otg_cil_init( dwc_otg_device->base, &dwc_otg_module_params);
6484 + if (dwc_otg_device->core_if == 0) {
6485 + dev_err(&_dev->dev, "CIL initialization failed!\n");
6491 + * Validate parameter values.
6493 + if (check_parameters(dwc_otg_device->core_if) != 0) {
6498 + /* Added for PLB DMA phys virt mapping */
6499 + //dwc_otg_device->core_if->phys_addr = dwc_otg_device->phys_addr;
6501 + * Create Device Attributes in sysfs
6503 + dwc_otg_attr_create (&_dev->dev);
6506 + * Disable the global interrupt until all the interrupt
6507 + * handlers are installed.
6509 + dwc_otg_disable_global_interrupts( dwc_otg_device->core_if );
6511 + * Install the interrupt handler for the common interrupts before
6512 + * enabling common interrupts in core_init below.
6514 + DWC_DEBUGPL( DBG_CIL, "registering (common) handler for irq%d\n", dwc_otg_device->irq);
6516 + retval = request_irq((unsigned int)dwc_otg_device->irq, dwc_otg_common_irq,
6517 + //SA_INTERRUPT|SA_SHIRQ, "dwc_otg", (void *)dwc_otg_device );
6518 + IRQF_SHARED, "dwc_otg", (void *)dwc_otg_device );
6519 + //IRQF_DISABLED, "dwc_otg", (void *)dwc_otg_device );
6520 + if (retval != 0) {
6521 + DWC_ERROR("request of irq%d failed retval: %d\n", dwc_otg_device->irq, retval);
6525 + dwc_otg_device->common_irq_installed = 1;
6529 + * Initialize the DWC_otg core.
6531 + dwc_otg_core_init( dwc_otg_device->core_if );
6534 +#ifndef DWC_HOST_ONLY // otg device mode. (gadget.)
6536 + * Initialize the PCD
6538 + retval = dwc_otg_pcd_init(dwc_otg_device);
6539 + if (retval != 0) {
6540 + DWC_ERROR("dwc_otg_pcd_init failed\n");
6541 + dwc_otg_device->pcd = NULL;
6544 +#endif // DWC_HOST_ONLY
6546 +#ifndef DWC_DEVICE_ONLY // otg host mode. (HCD)
6548 + * Initialize the HCD
6551 + /* force_host_mode */
6552 + usbcfg.d32 = dwc_read_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg);
6553 + usbcfg.b.force_host_mode = 1;
6554 + dwc_write_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg, usbcfg.d32);
6556 + retval = dwc_otg_hcd_init(&_dev->dev, dwc_otg_device);
6557 + if (retval != 0) {
6558 + DWC_ERROR("dwc_otg_hcd_init failed\n");
6559 + dwc_otg_device->hcd = NULL;
6562 +#endif // DWC_DEVICE_ONLY
6565 + * Enable the global interrupt after all the interrupt
6566 + * handlers are installed.
6568 + dwc_otg_enable_global_interrupts( dwc_otg_device->core_if );
6570 + usbcfg.d32 = dwc_read_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg);
6571 + usbcfg.b.force_host_mode = 0;
6572 + dwc_write_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg, usbcfg.d32);
6579 + dwc_otg_driver_remove(_dev);
6584 + * This structure defines the methods to be called by a bus driver
6585 + * during the lifecycle of a device on that bus. Both drivers and
6586 + * devices are registered with a bus driver. The bus driver matches
6587 + * devices to drivers based on information in the device and driver
6590 + * The probe function is called when the bus driver matches a device
6591 + * to this driver. The remove function is called when a device is
6592 + * unregistered with the bus driver.
6594 +struct platform_driver dwc_otg_driver = {
6595 + .probe = dwc_otg_driver_probe,
6596 + .remove = dwc_otg_driver_remove,
6597 +// .suspend = dwc_otg_driver_suspend,
6598 +// .resume = dwc_otg_driver_resume,
6600 + .name = dwc_driver_name,
6601 + .owner = THIS_MODULE,
6604 +EXPORT_SYMBOL(dwc_otg_driver);
6607 + * This function is called when the dwc_otg_driver is installed with the
6608 + * insmod command. It registers the dwc_otg_driver structure with the
6609 + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
6610 + * to be called. In addition, the bus driver will automatically expose
6611 + * attributes defined for the device and driver in the special sysfs file
6616 +static int __init dwc_otg_init(void)
6620 + printk(KERN_INFO "%s: version %s\n", dwc_driver_name, DWC_DRIVER_VERSION);
6623 + retval = ifx_usb_hc_init(dwc_iomem_base, dwc_irq);
6626 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6629 + dwc_otg_power_on(); // ifx only!!
6632 + retval = platform_driver_register(&dwc_otg_driver);
6635 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6639 + retval = driver_create_file(&dwc_otg_driver.driver, &driver_attr_version);
6642 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6645 + retval = driver_create_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
6648 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6655 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
6657 + driver_unregister(&dwc_otg_driver.driver);
6659 + ifx_usb_hc_remove();
6662 +module_init(dwc_otg_init);
6665 + * This function is called when the driver is removed from the kernel
6666 + * with the rmmod command. The driver unregisters itself with its bus
6670 +static void __exit dwc_otg_cleanup(void)
6672 + printk(KERN_DEBUG "dwc_otg_cleanup()\n");
6674 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
6675 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
6677 + platform_driver_unregister(&dwc_otg_driver);
6678 + ifx_usb_hc_remove();
6680 + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
6682 +module_exit(dwc_otg_cleanup);
6684 +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
6685 +MODULE_AUTHOR("Synopsys Inc.");
6686 +MODULE_LICENSE("GPL");
6688 +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
6689 +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
6690 +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
6691 +MODULE_PARM_DESC(opt, "OPT Mode");
6692 +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
6693 +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
6694 +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int, 0444);
6695 +MODULE_PARM_DESC(dma_burst_size, "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
6696 +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
6697 +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
6698 +module_param_named(host_support_fs_ls_low_power, dwc_otg_module_params.host_support_fs_ls_low_power, int, 0444);
6699 +MODULE_PARM_DESC(host_support_fs_ls_low_power, "Support Low Power w/FS or LS 0=Support 1=Don't Support");
6700 +module_param_named(host_ls_low_power_phy_clk, dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
6701 +MODULE_PARM_DESC(host_ls_low_power_phy_clk, "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
6702 +module_param_named(enable_dynamic_fifo, dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
6703 +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
6704 +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int, 0444);
6705 +MODULE_PARM_DESC(data_fifo_size, "Total number of words in the data FIFO memory 32-32768");
6706 +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size, int, 0444);
6707 +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
6708 +module_param_named(dev_nperio_tx_fifo_size, dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
6709 +MODULE_PARM_DESC(dev_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
6710 +module_param_named(dev_perio_tx_fifo_size_1, dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
6711 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1, "Number of words in the periodic Tx FIFO 4-768");
6712 +module_param_named(dev_perio_tx_fifo_size_2, dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
6713 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2, "Number of words in the periodic Tx FIFO 4-768");
6714 +module_param_named(dev_perio_tx_fifo_size_3, dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
6715 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3, "Number of words in the periodic Tx FIFO 4-768");
6716 +module_param_named(dev_perio_tx_fifo_size_4, dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
6717 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4, "Number of words in the periodic Tx FIFO 4-768");
6718 +module_param_named(dev_perio_tx_fifo_size_5, dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
6719 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5, "Number of words in the periodic Tx FIFO 4-768");
6720 +module_param_named(dev_perio_tx_fifo_size_6, dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
6721 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6, "Number of words in the periodic Tx FIFO 4-768");
6722 +module_param_named(dev_perio_tx_fifo_size_7, dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
6723 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7, "Number of words in the periodic Tx FIFO 4-768");
6724 +module_param_named(dev_perio_tx_fifo_size_8, dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
6725 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8, "Number of words in the periodic Tx FIFO 4-768");
6726 +module_param_named(dev_perio_tx_fifo_size_9, dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
6727 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9, "Number of words in the periodic Tx FIFO 4-768");
6728 +module_param_named(dev_perio_tx_fifo_size_10, dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
6729 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10, "Number of words in the periodic Tx FIFO 4-768");
6730 +module_param_named(dev_perio_tx_fifo_size_11, dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
6731 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11, "Number of words in the periodic Tx FIFO 4-768");
6732 +module_param_named(dev_perio_tx_fifo_size_12, dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
6733 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12, "Number of words in the periodic Tx FIFO 4-768");
6734 +module_param_named(dev_perio_tx_fifo_size_13, dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
6735 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13, "Number of words in the periodic Tx FIFO 4-768");
6736 +module_param_named(dev_perio_tx_fifo_size_14, dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
6737 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14, "Number of words in the periodic Tx FIFO 4-768");
6738 +module_param_named(dev_perio_tx_fifo_size_15, dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
6739 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15, "Number of words in the periodic Tx FIFO 4-768");
6740 +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size, int, 0444);
6741 +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
6742 +module_param_named(host_nperio_tx_fifo_size, dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
6743 +MODULE_PARM_DESC(host_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
6744 +module_param_named(host_perio_tx_fifo_size, dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
6745 +MODULE_PARM_DESC(host_perio_tx_fifo_size, "Number of words in the host periodic Tx FIFO 16-32768");
6746 +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size, int, 0444);
6747 +/** @todo Set the max to 512K, modify checks */
6748 +MODULE_PARM_DESC(max_transfer_size, "The maximum transfer size supported in bytes 2047-65535");
6749 +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count, int, 0444);
6750 +MODULE_PARM_DESC(max_packet_count, "The maximum number of packets in a transfer 15-511");
6751 +module_param_named(host_channels, dwc_otg_module_params.host_channels, int, 0444);
6752 +MODULE_PARM_DESC(host_channels, "The number of host channel registers to use 1-16");
6753 +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int, 0444);
6754 +MODULE_PARM_DESC(dev_endpoints, "The number of endpoints in addition to EP0 available for device mode 1-15");
6755 +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
6756 +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
6757 +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int, 0444);
6758 +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
6759 +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
6760 +MODULE_PARM_DESC(phy_ulpi_ddr, "ULPI at double or single data rate 0=Single 1=Double");
6761 +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus, int, 0444);
6762 +MODULE_PARM_DESC(phy_ulpi_ext_vbus, "ULPI PHY using internal or external vbus 0=Internal");
6763 +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
6764 +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
6765 +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
6766 +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
6767 +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
6768 +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
6769 +module_param_named(debug, g_dbg_lvl, int, 0444);
6770 +MODULE_PARM_DESC(debug, "0");
6771 +module_param_named(en_multiple_tx_fifo,
6772 + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
6773 +MODULE_PARM_DESC(en_multiple_tx_fifo,
6774 + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
6775 +module_param_named(dev_tx_fifo_size_1,
6776 + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
6777 +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
6778 +module_param_named(dev_tx_fifo_size_2,
6779 + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
6780 +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
6781 +module_param_named(dev_tx_fifo_size_3,
6782 + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
6783 +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
6784 +module_param_named(dev_tx_fifo_size_4,
6785 + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
6786 +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
6787 +module_param_named(dev_tx_fifo_size_5,
6788 + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
6789 +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
6790 +module_param_named(dev_tx_fifo_size_6,
6791 + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
6792 +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
6793 +module_param_named(dev_tx_fifo_size_7,
6794 + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
6795 +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
6796 +module_param_named(dev_tx_fifo_size_8,
6797 + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
6798 +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
6799 +module_param_named(dev_tx_fifo_size_9,
6800 + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
6801 +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
6802 +module_param_named(dev_tx_fifo_size_10,
6803 + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
6804 +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
6805 +module_param_named(dev_tx_fifo_size_11,
6806 + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
6807 +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
6808 +module_param_named(dev_tx_fifo_size_12,
6809 + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
6810 +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
6811 +module_param_named(dev_tx_fifo_size_13,
6812 + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
6813 +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
6814 +module_param_named(dev_tx_fifo_size_14,
6815 + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
6816 +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
6817 +module_param_named(dev_tx_fifo_size_15,
6818 + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
6819 +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
6820 +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
6821 +MODULE_PARM_DESC(thr_ctl, "Thresholding enable flag bit"
6822 + "0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
6823 +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int, 0444);
6824 +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
6825 +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int, 0444);
6826 +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
6827 +module_param_named (iomem_base, dwc_iomem_base, ulong, 0444);
6828 +MODULE_PARM_DESC (dwc_iomem_base, "The base address of the DWC_OTG register.");
6829 +module_param_named (irq, dwc_irq, int, 0444);
6830 +MODULE_PARM_DESC (dwc_irq, "The interrupt number");
6832 +/** @page "Module Parameters"
6834 + * The following parameters may be specified when starting the module.
6835 + * These parameters define how the DWC_otg controller should be
6836 + * configured. Parameter values are passed to the CIL initialization
6837 + * function dwc_otg_cil_init
6839 + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
6843 + <tr><td>Parameter Name</td><td>Meaning</td></tr>
6847 + <td>Specifies the OTG capabilities. The driver will automatically detect the
6848 + value for this parameter if none is specified.
6849 + - 0: HNP and SRP capable (default, if available)
6850 + - 1: SRP Only capable
6851 + - 2: No HNP/SRP capable
6855 + <td>dma_enable</td>
6856 + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
6857 + The driver will automatically detect the value for this parameter if none is
6860 + - 1: DMA (default, if available)
6864 + <td>dma_burst_size</td>
6865 + <td>The DMA Burst size (applicable only for External DMA Mode).
6866 + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
6871 + <td>Specifies the maximum speed of operation in host and device mode. The
6872 + actual speed depends on the speed of the attached device and the value of
6874 + - 0: High Speed (default)
6879 + <td>host_support_fs_ls_low_power</td>
6880 + <td>Specifies whether low power mode is supported when attached to a Full
6881 + Speed or Low Speed device in host mode.
6882 + - 0: Don't support low power mode (default)
6883 + - 1: Support low power mode
6887 + <td>host_ls_low_power_phy_clk</td>
6888 + <td>Specifies the PHY clock rate in low power mode when connected to a Low
6889 + Speed device in host mode. This parameter is applicable only if
6890 + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
6891 + - 0: 48 MHz (default)
6896 + <td>enable_dynamic_fifo</td>
6897 + <td> Specifies whether FIFOs may be resized by the driver software.
6898 + - 0: Use cC FIFO size parameters
6899 + - 1: Allow dynamic FIFO sizing (default)
6903 + <td>data_fifo_size</td>
6904 + <td>Total number of 4-byte words in the data FIFO memory. This memory
6905 + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
6906 + - Values: 32 to 32768 (default 8192)
6908 + Note: The total FIFO memory depth in the FPGA configuration is 8192.
6912 + <td>dev_rx_fifo_size</td>
6913 + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
6914 + FIFO sizing is enabled.
6915 + - Values: 16 to 32768 (default 1064)
6919 + <td>dev_nperio_tx_fifo_size</td>
6920 + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
6921 + dynamic FIFO sizing is enabled.
6922 + - Values: 16 to 32768 (default 1024)
6926 + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
6927 + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
6928 + when dynamic FIFO sizing is enabled.
6929 + - Values: 4 to 768 (default 256)
6933 + <td>host_rx_fifo_size</td>
6934 + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
6935 + sizing is enabled.
6936 + - Values: 16 to 32768 (default 1024)
6940 + <td>host_nperio_tx_fifo_size</td>
6941 + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
6942 + dynamic FIFO sizing is enabled in the core.
6943 + - Values: 16 to 32768 (default 1024)
6947 + <td>host_perio_tx_fifo_size</td>
6948 + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
6949 + sizing is enabled.
6950 + - Values: 16 to 32768 (default 1024)
6954 + <td>max_transfer_size</td>
6955 + <td>The maximum transfer size supported in bytes.
6956 + - Values: 2047 to 65,535 (default 65,535)
6960 + <td>max_packet_count</td>
6961 + <td>The maximum number of packets in a transfer.
6962 + - Values: 15 to 511 (default 511)
6966 + <td>host_channels</td>
6967 + <td>The number of host channel registers to use.
6968 + - Values: 1 to 16 (default 12)
6970 + Note: The FPGA configuration supports a maximum of 12 host channels.
6974 + <td>dev_endpoints</td>
6975 + <td>The number of endpoints in addition to EP0 available for device mode
6977 + - Values: 1 to 15 (default 6 IN and OUT)
6979 + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
6985 + <td>Specifies the type of PHY interface to use. By default, the driver will
6986 + automatically detect the phy_type.
6988 + - 1: UTMI+ (default, if available)
6993 + <td>phy_utmi_width</td>
6994 + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
6995 + phy_type of UTMI+. Also, this parameter is applicable only if the
6996 + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
6997 + core has been configured to work at either data path width.
6998 + - Values: 8 or 16 bits (default 16)
7002 + <td>phy_ulpi_ddr</td>
7003 + <td>Specifies whether the ULPI operates at double or single data rate. This
7004 + parameter is only applicable if phy_type is ULPI.
7005 + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
7006 + - 1: double data rate ULPI interface with 4 bit wide data bus
7010 + <td>i2c_enable</td>
7011 + <td>Specifies whether to use the I2C interface for full speed PHY. This
7012 + parameter is only applicable if PHY_TYPE is FS.
7013 + - 0: Disabled (default)
7018 + <td>otg_en_multiple_tx_fifo</td>
7019 + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
7020 + The driver will automatically detect the value for this parameter if none is
7023 + - 1: Enabled (default, if available)
7027 + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
7028 + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
7029 + when dynamic FIFO sizing is enabled.
7030 + - Values: 4 to 768 (default 256)
7035 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.h
7037 +/* ==========================================================================
7038 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.h $
7039 + * $Revision: 1.1.1.1 $
7040 + * $Date: 2009-04-17 06:15:34 $
7041 + * $Change: 510275 $
7043 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
7044 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
7045 + * otherwise expressly agreed to in writing between Synopsys and you.
7047 + * The Software IS NOT an item of Licensed Software or Licensed Product under
7048 + * any End User Software License Agreement or Agreement for Licensed Product
7049 + * with Synopsys or any supplement thereto. You are permitted to use and
7050 + * redistribute this Software in source and binary forms, with or without
7051 + * modification, provided that redistributions of source code must retain this
7052 + * notice. You may not view, use, disclose, copy or distribute this file or
7053 + * any information contained herein except pursuant to this license grant from
7054 + * Synopsys. If you do not agree with this notice, including the disclaimer
7055 + * below, then you are not authorized to use the Software.
7057 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
7058 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7059 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7060 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
7061 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7062 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7063 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7064 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7065 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7066 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
7068 + * ========================================================================== */
7070 +#if !defined(__DWC_OTG_DRIVER_H__)
7071 +#define __DWC_OTG_DRIVER_H__
7074 + * This file contains the interface to the Linux driver.
7076 +#include "dwc_otg_cil.h"
7078 +/* Type declarations */
7079 +struct dwc_otg_pcd;
7080 +struct dwc_otg_hcd;
7083 + * This structure is a wrapper that encapsulates the driver components used to
7084 + * manage a single DWC_otg controller.
7086 +typedef struct dwc_otg_device
7088 + /** Base address returned from ioremap() */
7091 + /** Pointer to the core interface structure. */
7092 + dwc_otg_core_if_t *core_if;
7094 + /** Register offset for Diagnostic API.*/
7095 + uint32_t reg_offset;
7097 + /** Pointer to the PCD structure. */
7098 + struct dwc_otg_pcd *pcd;
7100 + /** Pointer to the HCD structure. */
7101 + struct dwc_otg_hcd *hcd;
7103 + /** Flag to indicate whether the common IRQ handler is installed. */
7104 + uint8_t common_irq_installed;
7106 + /** Interrupt request number. */
7109 + /** Physical address of Control and Status registers, used by
7110 + * release_mem_region().
7112 + resource_size_t phys_addr;
7114 + /** Length of memory region, used by release_mem_region(). */
7115 + unsigned long base_len;
7116 +} dwc_otg_device_t;
7118 +//#define dev_dbg(fake, format, arg...) printk(KERN_CRIT __FILE__ ":%d: " format "\n" , __LINE__, ## arg)
7122 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.c
7124 +/* ==========================================================================
7125 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd.c $
7126 + * $Revision: 1.1.1.1 $
7127 + * $Date: 2009-04-17 06:15:34 $
7128 + * $Change: 631780 $
7130 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
7131 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
7132 + * otherwise expressly agreed to in writing between Synopsys and you.
7134 + * The Software IS NOT an item of Licensed Software or Licensed Product under
7135 + * any End User Software License Agreement or Agreement for Licensed Product
7136 + * with Synopsys or any supplement thereto. You are permitted to use and
7137 + * redistribute this Software in source and binary forms, with or without
7138 + * modification, provided that redistributions of source code must retain this
7139 + * notice. You may not view, use, disclose, copy or distribute this file or
7140 + * any information contained herein except pursuant to this license grant from
7141 + * Synopsys. If you do not agree with this notice, including the disclaimer
7142 + * below, then you are not authorized to use the Software.
7144 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
7145 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7146 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7147 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
7148 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7149 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7150 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7151 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7152 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7153 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
7155 + * ========================================================================== */
7156 +#ifndef DWC_DEVICE_ONLY
7161 + * This file contains the implementation of the HCD. In Linux, the HCD
7162 + * implements the hc_driver API.
7164 +#include <linux/kernel.h>
7165 +#include <linux/module.h>
7166 +#include <linux/moduleparam.h>
7167 +#include <linux/init.h>
7169 +#include <linux/device.h>
7171 +#include <linux/errno.h>
7172 +#include <linux/list.h>
7173 +#include <linux/interrupt.h>
7174 +#include <linux/string.h>
7176 +#include <linux/dma-mapping.h>
7178 +#include "dwc_otg_driver.h"
7179 +#include "dwc_otg_hcd.h"
7180 +#include "dwc_otg_regs.h"
7182 +#include <asm/irq.h>
7183 +#include "dwc_otg_ifx.h" // for Infineon platform specific.
7184 +extern atomic_t release_later;
7186 +static u64 dma_mask = DMA_BIT_MASK(32);
7188 +static const char dwc_otg_hcd_name [] = "dwc_otg_hcd";
7189 +static const struct hc_driver dwc_otg_hc_driver =
7191 + .description = dwc_otg_hcd_name,
7192 + .product_desc = "DWC OTG Controller",
7193 + .hcd_priv_size = sizeof(dwc_otg_hcd_t),
7194 + .irq = dwc_otg_hcd_irq,
7195 + .flags = HCD_MEMORY | HCD_USB2,
7197 + .start = dwc_otg_hcd_start,
7200 + .stop = dwc_otg_hcd_stop,
7201 + .urb_enqueue = dwc_otg_hcd_urb_enqueue,
7202 + .urb_dequeue = dwc_otg_hcd_urb_dequeue,
7203 + .endpoint_disable = dwc_otg_hcd_endpoint_disable,
7204 + .get_frame_number = dwc_otg_hcd_get_frame_number,
7205 + .hub_status_data = dwc_otg_hcd_hub_status_data,
7206 + .hub_control = dwc_otg_hcd_hub_control,
7213 + * Work queue function for starting the HCD when A-Cable is connected.
7214 + * The dwc_otg_hcd_start() must be called in a process context.
7216 +static void hcd_start_func(struct work_struct *work)
7218 + struct dwc_otg_hcd *priv =
7219 + container_of(work, struct dwc_otg_hcd, start_work);
7220 + struct usb_hcd *usb_hcd = (struct usb_hcd *)priv->_p;
7221 + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, usb_hcd);
7223 + dwc_otg_hcd_start(usb_hcd);
7229 + * HCD Callback function for starting the HCD when A-Cable is
7232 + * @param _p void pointer to the <code>struct usb_hcd</code>
7234 +static int32_t dwc_otg_hcd_start_cb(void *_p)
7236 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_p);
7237 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
7238 + hprt0_data_t hprt0;
7239 + if (core_if->op_state == B_HOST) {
7241 + * Reset the port. During a HNP mode switch the reset
7242 + * needs to occur within 1ms and have a duration of at
7245 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
7246 + hprt0.b.prtrst = 1;
7247 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7248 + ((struct usb_hcd *)_p)->self.is_b_host = 1;
7250 + ((struct usb_hcd *)_p)->self.is_b_host = 0;
7252 + /* Need to start the HCD in a non-interrupt context. */
7253 + INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
7254 + dwc_otg_hcd->_p = _p;
7255 + schedule_work(&dwc_otg_hcd->start_work);
7261 + * HCD Callback function for stopping the HCD.
7263 + * @param _p void pointer to the <code>struct usb_hcd</code>
7265 +static int32_t dwc_otg_hcd_stop_cb( void *_p )
7267 + struct usb_hcd *usb_hcd = (struct usb_hcd *)_p;
7268 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7269 + dwc_otg_hcd_stop( usb_hcd );
7272 +static void del_xfer_timers(dwc_otg_hcd_t *_hcd)
7276 + int num_channels = _hcd->core_if->core_params->host_channels;
7277 + for (i = 0; i < num_channels; i++) {
7278 + del_timer(&_hcd->core_if->hc_xfer_timer[i]);
7283 +static void del_timers(dwc_otg_hcd_t *_hcd)
7285 + del_xfer_timers(_hcd);
7286 + del_timer(&_hcd->conn_timer);
7290 + * Processes all the URBs in a single list of QHs. Completes them with
7291 + * -ETIMEDOUT and frees the QTD.
7293 +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * _hcd,
7294 + struct list_head *_qh_list)
7296 + struct list_head *qh_item;
7298 + struct list_head *qtd_item;
7299 + dwc_otg_qtd_t *qtd;
7301 + list_for_each(qh_item, _qh_list) {
7302 + qh = list_entry(qh_item, dwc_otg_qh_t, qh_list_entry);
7303 + for (qtd_item = qh->qtd_list.next; qtd_item != &qh->qtd_list;
7304 + qtd_item = qh->qtd_list.next) {
7305 + qtd = list_entry(qtd_item, dwc_otg_qtd_t, qtd_list_entry);
7306 + if (qtd->urb != NULL) {
7307 + dwc_otg_hcd_complete_urb(_hcd, qtd->urb,-ETIMEDOUT);
7309 + dwc_otg_hcd_qtd_remove_and_free(qtd);
7315 + * Responds with an error status of ETIMEDOUT to all URBs in the non-periodic
7316 + * and periodic schedules. The QTD associated with each URB is removed from
7317 + * the schedule and freed. This function may be called when a disconnect is
7318 + * detected or when the HCD is being stopped.
7320 +static void kill_all_urbs(dwc_otg_hcd_t *_hcd)
7322 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_deferred);
7323 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_inactive);
7324 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_active);
7325 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_inactive);
7326 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_ready);
7327 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_assigned);
7328 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_queued);
7332 + * HCD Callback function for disconnect of the HCD.
7334 + * @param _p void pointer to the <code>struct usb_hcd</code>
7336 +static int32_t dwc_otg_hcd_disconnect_cb( void *_p )
7338 + gintsts_data_t intr;
7339 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
7341 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7344 + * Set status flags for the hub driver.
7346 + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
7347 + dwc_otg_hcd->flags.b.port_connect_status = 0;
7350 + * Shutdown any transfers in process by clearing the Tx FIFO Empty
7351 + * interrupt mask and status bits and disabling subsequent host
7352 + * channel interrupts.
7355 + intr.b.nptxfempty = 1;
7356 + intr.b.ptxfempty = 1;
7357 + intr.b.hcintr = 1;
7358 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, intr.d32, 0);
7359 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintsts, intr.d32, 0);
7361 + del_timers(dwc_otg_hcd);
7364 + * Turn off the vbus power only if the core has transitioned to device
7365 + * mode. If still in host mode, need to keep power on to detect a
7368 + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
7369 + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
7370 + hprt0_data_t hprt0 = { .d32=0 };
7371 + DWC_PRINT("Disconnect: PortPower off\n");
7372 + hprt0.b.prtpwr = 0;
7373 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
7376 + dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
7379 + /* Respond with an error status to all URBs in the schedule. */
7380 + kill_all_urbs(dwc_otg_hcd);
7382 + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
7383 + /* Clean up any host channels that were in use. */
7386 + dwc_hc_t *channel;
7387 + dwc_otg_hc_regs_t *hc_regs;
7388 + hcchar_data_t hcchar;
7390 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
7392 + if (!dwc_otg_hcd->core_if->dma_enable) {
7393 + /* Flush out any channel requests in slave mode. */
7394 + for (i = 0; i < num_channels; i++) {
7395 + channel = dwc_otg_hcd->hc_ptr_array[i];
7396 + if (list_empty(&channel->hc_list_entry)) {
7397 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
7398 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7399 + if (hcchar.b.chen) {
7400 + hcchar.b.chen = 0;
7401 + hcchar.b.chdis = 1;
7402 + hcchar.b.epdir = 0;
7403 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
7409 + for (i = 0; i < num_channels; i++) {
7410 + channel = dwc_otg_hcd->hc_ptr_array[i];
7411 + if (list_empty(&channel->hc_list_entry)) {
7412 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
7413 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7414 + if (hcchar.b.chen) {
7415 + /* Halt the channel. */
7416 + hcchar.b.chdis = 1;
7417 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
7420 + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if, channel);
7421 + list_add_tail(&channel->hc_list_entry,
7422 + &dwc_otg_hcd->free_hc_list);
7427 + /* A disconnect will end the session so the B-Device is no
7428 + * longer a B-host. */
7429 + ((struct usb_hcd *)_p)->self.is_b_host = 0;
7435 + * Connection timeout function. An OTG host is required to display a
7436 + * message if the device does not connect within 10 seconds.
7438 +void dwc_otg_hcd_connect_timeout( unsigned long _ptr )
7440 + DWC_DEBUGPL(DBG_HCDV, "%s(%x)\n", __func__, (int)_ptr);
7441 + DWC_PRINT( "Connect Timeout\n");
7442 + DWC_ERROR( "Device Not Connected/Responding\n" );
7446 + * Start the connection timer. An OTG host is required to display a
7447 + * message if the device does not connect within 10 seconds. The
7448 + * timer is deleted if a port connect interrupt occurs before the
7451 +static void dwc_otg_hcd_start_connect_timer( dwc_otg_hcd_t *_hcd)
7453 + init_timer( &_hcd->conn_timer );
7454 + _hcd->conn_timer.function = dwc_otg_hcd_connect_timeout;
7455 + _hcd->conn_timer.data = (unsigned long)0;
7456 + _hcd->conn_timer.expires = jiffies + (HZ*10);
7457 + add_timer( &_hcd->conn_timer );
7461 + * HCD Callback function for disconnect of the HCD.
7463 + * @param _p void pointer to the <code>struct usb_hcd</code>
7465 +static int32_t dwc_otg_hcd_session_start_cb( void *_p )
7467 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
7468 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7469 + dwc_otg_hcd_start_connect_timer( dwc_otg_hcd );
7474 + * HCD Callback structure for handling mode switching.
7476 +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
7477 + .start = dwc_otg_hcd_start_cb,
7478 + .stop = dwc_otg_hcd_stop_cb,
7479 + .disconnect = dwc_otg_hcd_disconnect_cb,
7480 + .session_start = dwc_otg_hcd_session_start_cb,
7486 + * Reset tasklet function
7488 +static void reset_tasklet_func (unsigned long data)
7490 + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t*)data;
7491 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
7492 + hprt0_data_t hprt0;
7494 + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
7496 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
7497 + hprt0.b.prtrst = 1;
7498 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7501 + hprt0.b.prtrst = 0;
7502 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7503 + dwc_otg_hcd->flags.b.port_reset_change = 1;
7508 +static struct tasklet_struct reset_tasklet = {
7511 + .count = ATOMIC_INIT(0),
7512 + .func = reset_tasklet_func,
7517 + * Initializes the HCD. This function allocates memory for and initializes the
7518 + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
7519 + * USB bus with the core and calls the hc_driver->start() function. It returns
7520 + * a negative error on failure.
7522 +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
7524 +int __devinit dwc_otg_hcd_init(struct device *_dev, dwc_otg_device_t * dwc_otg_device)
7526 + struct usb_hcd *hcd = NULL;
7527 + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
7528 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
7532 + dwc_hc_t *channel;
7536 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
7539 + * Allocate memory for the base HCD plus the DWC OTG HCD.
7540 + * Initialize the base HCD.
7542 + hcd = usb_create_hcd(&dwc_otg_hc_driver, _dev, dev_name(_dev));
7543 + if (hcd == NULL) {
7547 + dev_set_drvdata(_dev, dwc_otg_device); /* fscz restore */
7548 + hcd->regs = otg_dev->base;
7549 + hcd->rsrc_start = (int)otg_dev->base;
7551 + hcd->self.otg_port = 1;
7553 + /* Initialize the DWC OTG HCD. */
7554 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
7555 + dwc_otg_hcd->core_if = otg_dev->core_if;
7556 + otg_dev->hcd = dwc_otg_hcd;
7558 + /* Register the HCD CIL Callbacks */
7559 + dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
7560 + &hcd_cil_callbacks, hcd);
7562 + /* Initialize the non-periodic schedule. */
7563 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
7564 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
7565 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_deferred);
7567 + /* Initialize the periodic schedule. */
7568 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
7569 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
7570 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
7571 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
7574 + * Create a host channel descriptor for each host channel implemented
7575 + * in the controller. Initialize the channel descriptor array.
7577 + INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
7578 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
7579 + for (i = 0; i < num_channels; i++) {
7580 + channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
7581 + if (channel == NULL) {
7583 + DWC_ERROR("%s: host channel allocation failed\n", __func__);
7586 + memset(channel, 0, sizeof(dwc_hc_t));
7587 + channel->hc_num = i;
7588 + dwc_otg_hcd->hc_ptr_array[i] = channel;
7590 + init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
7593 + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
7596 + /* Initialize the Connection timeout timer. */
7597 + init_timer( &dwc_otg_hcd->conn_timer );
7599 + /* Initialize reset tasklet. */
7600 + reset_tasklet.data = (unsigned long) dwc_otg_hcd;
7601 + dwc_otg_hcd->reset_tasklet = &reset_tasklet;
7603 + /* Set device flags indicating whether the HCD supports DMA. */
7604 + if (otg_dev->core_if->dma_enable) {
7605 + DWC_PRINT("Using DMA mode\n");
7606 + //_dev->dma_mask = (void *)~0;
7607 + //_dev->coherent_dma_mask = ~0;
7608 + _dev->dma_mask = &dma_mask;
7609 + _dev->coherent_dma_mask = DMA_BIT_MASK(32);
7611 + DWC_PRINT("Using Slave mode\n");
7612 + _dev->dma_mask = (void *)0;
7613 + _dev->coherent_dma_mask = 0;
7616 + init_hcd_usecs(dwc_otg_hcd);
7618 + * Finish generic HCD initialization and start the HCD. This function
7619 + * allocates the DMA buffer pool, registers the USB bus, requests the
7620 + * IRQ line, and calls dwc_otg_hcd_start method.
7622 + retval = usb_add_hcd(hcd, otg_dev->irq, IRQF_SHARED);
7628 + * Allocate space for storing data on status transactions. Normally no
7629 + * data is sent, but this space acts as a bit bucket. This must be
7630 + * done after usb_add_hcd since that function allocates the DMA buffer
7633 + if (otg_dev->core_if->dma_enable) {
7634 + dwc_otg_hcd->status_buf =
7635 + dma_alloc_coherent(_dev,
7636 + DWC_OTG_HCD_STATUS_BUF_SIZE,
7637 + &dwc_otg_hcd->status_buf_dma,
7638 + GFP_KERNEL | GFP_DMA);
7640 + dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
7643 + if (dwc_otg_hcd->status_buf == NULL) {
7645 + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
7649 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
7650 + dev_name(_dev), hcd->self.busnum);
7654 + /* Error conditions */
7656 + usb_remove_hcd(hcd);
7658 + dwc_otg_hcd_free(hcd);
7665 + * Removes the HCD.
7666 + * Frees memory and resources associated with the HCD and deregisters the bus.
7668 +void dwc_otg_hcd_remove(struct device *_dev)
7670 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
7671 + dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
7672 + struct usb_hcd *hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
7674 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE\n");
7676 + /* Turn off all interrupts */
7677 + dwc_write_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0);
7678 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gahbcfg, 1, 0);
7680 + usb_remove_hcd(hcd);
7682 + dwc_otg_hcd_free(hcd);
7690 +/* =========================================================================
7691 + * Linux HC Driver Functions
7692 + * ========================================================================= */
7695 + * Initializes dynamic portions of the DWC_otg HCD state.
7697 +static void hcd_reinit(dwc_otg_hcd_t *_hcd)
7699 + struct list_head *item;
7702 + dwc_hc_t *channel;
7704 + _hcd->flags.d32 = 0;
7706 + _hcd->non_periodic_qh_ptr = &_hcd->non_periodic_sched_active;
7707 + _hcd->available_host_channels = _hcd->core_if->core_params->host_channels;
7710 + * Put all channels in the free channel list and clean up channel
7713 + item = _hcd->free_hc_list.next;
7714 + while (item != &_hcd->free_hc_list) {
7716 + item = _hcd->free_hc_list.next;
7718 + num_channels = _hcd->core_if->core_params->host_channels;
7719 + for (i = 0; i < num_channels; i++) {
7720 + channel = _hcd->hc_ptr_array[i];
7721 + list_add_tail(&channel->hc_list_entry, &_hcd->free_hc_list);
7722 + dwc_otg_hc_cleanup(_hcd->core_if, channel);
7725 + /* Initialize the DWC core for host mode operation. */
7726 + dwc_otg_core_host_init(_hcd->core_if);
7729 +/** Initializes the DWC_otg controller and its root hub and prepares it for host
7730 + * mode operation. Activates the root port. Returns 0 on success and a negative
7731 + * error code on failure. */
7732 +int dwc_otg_hcd_start(struct usb_hcd *_hcd)
7734 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7735 + dwc_otg_core_if_t * core_if = dwc_otg_hcd->core_if;
7736 + struct usb_bus *bus;
7740 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
7742 + bus = hcd_to_bus(_hcd);
7744 + /* Initialize the bus state. If the core is in Device Mode
7745 + * HALT the USB bus and return. */
7746 + if (dwc_otg_is_device_mode (core_if)) {
7747 + _hcd->state = HC_STATE_HALT;
7750 + _hcd->state = HC_STATE_RUNNING;
7752 + /* Initialize and connect root hub if one is not already attached */
7753 + if (bus->root_hub) {
7754 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
7755 + /* Inform the HUB driver to resume. */
7756 + usb_hcd_resume_root_hub(_hcd);
7760 + struct usb_device *udev;
7761 + udev = usb_alloc_dev(NULL, bus, 0);
7763 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
7766 + udev->speed = USB_SPEED_HIGH;
7767 + /* Not needed - VJ
7768 + if ((retval = usb_hcd_register_root_hub(udev, _hcd)) != 0) {
7769 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error registering %d\n", retval);
7774 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
7778 + hcd_reinit(dwc_otg_hcd);
7783 +static void qh_list_free(dwc_otg_hcd_t *_hcd, struct list_head *_qh_list)
7785 + struct list_head *item;
7788 + if (_qh_list->next == NULL) {
7789 + /* The list hasn't been initialized yet. */
7793 + /* Ensure there are no QTDs or URBs left. */
7794 + kill_urbs_in_qh_list(_hcd, _qh_list);
7796 + for (item = _qh_list->next; item != _qh_list; item = _qh_list->next) {
7797 + qh = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7798 + dwc_otg_hcd_qh_remove_and_free(_hcd, qh);
7803 + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
7806 +void dwc_otg_hcd_stop(struct usb_hcd *_hcd)
7808 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7809 + hprt0_data_t hprt0 = { .d32=0 };
7811 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
7813 + /* Turn off all host-specific interrupts. */
7814 + dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
7817 + * The root hub should be disconnected before this function is called.
7818 + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
7819 + * and the QH lists (via ..._hcd_endpoint_disable).
7822 + /* Turn off the vbus power */
7823 + DWC_PRINT("PortPower off\n");
7824 + hprt0.b.prtpwr = 0;
7825 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
7831 +/** Returns the current frame number. */
7832 +int dwc_otg_hcd_get_frame_number(struct usb_hcd *_hcd)
7834 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7835 + hfnum_data_t hfnum;
7837 + hfnum.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->
7838 + host_if->host_global_regs->hfnum);
7841 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n", hfnum.b.frnum);
7843 + return hfnum.b.frnum;
7847 + * Frees secondary storage associated with the dwc_otg_hcd structure contained
7848 + * in the struct usb_hcd field.
7850 +void dwc_otg_hcd_free(struct usb_hcd *_hcd)
7852 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7855 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
7857 + del_timers(dwc_otg_hcd);
7859 + /* Free memory for QH/QTD lists */
7860 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
7861 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_deferred);
7862 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
7863 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
7864 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
7865 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
7866 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
7868 + /* Free memory for the host channels. */
7869 + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
7870 + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
7872 + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n", i, hc);
7877 + if (dwc_otg_hcd->core_if->dma_enable) {
7878 + if (dwc_otg_hcd->status_buf_dma) {
7879 + dma_free_coherent(_hcd->self.controller,
7880 + DWC_OTG_HCD_STATUS_BUF_SIZE,
7881 + dwc_otg_hcd->status_buf,
7882 + dwc_otg_hcd->status_buf_dma);
7884 + } else if (dwc_otg_hcd->status_buf != NULL) {
7885 + kfree(dwc_otg_hcd->status_buf);
7893 +static void dump_urb_info(struct urb *_urb, char* _fn_name)
7895 + DWC_PRINT("%s, urb %p\n", _fn_name, _urb);
7896 + DWC_PRINT(" Device address: %d\n", usb_pipedevice(_urb->pipe));
7897 + DWC_PRINT(" Endpoint: %d, %s\n", usb_pipeendpoint(_urb->pipe),
7898 + (usb_pipein(_urb->pipe) ? "IN" : "OUT"));
7899 + DWC_PRINT(" Endpoint type: %s\n",
7901 + switch (usb_pipetype(_urb->pipe)) {
7902 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
7903 + case PIPE_BULK: pipetype = "BULK"; break;
7904 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
7905 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
7906 + default: pipetype = "UNKNOWN"; break;
7908 + DWC_PRINT(" Speed: %s\n",
7910 + switch (_urb->dev->speed) {
7911 + case USB_SPEED_HIGH: speed = "HIGH"; break;
7912 + case USB_SPEED_FULL: speed = "FULL"; break;
7913 + case USB_SPEED_LOW: speed = "LOW"; break;
7914 + default: speed = "UNKNOWN"; break;
7916 + DWC_PRINT(" Max packet size: %d\n",
7917 + usb_maxpacket(_urb->dev, _urb->pipe, usb_pipeout(_urb->pipe)));
7918 + DWC_PRINT(" Data buffer length: %d\n", _urb->transfer_buffer_length);
7919 + DWC_PRINT(" Transfer buffer: %p, Transfer DMA: %p\n",
7920 + _urb->transfer_buffer, (void *)_urb->transfer_dma);
7921 + DWC_PRINT(" Setup buffer: %p, Setup DMA: %p\n",
7922 + _urb->setup_packet, (void *)_urb->setup_dma);
7923 + DWC_PRINT(" Interval: %d\n", _urb->interval);
7924 + if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
7926 + for (i = 0; i < _urb->number_of_packets; i++) {
7927 + DWC_PRINT(" ISO Desc %d:\n", i);
7928 + DWC_PRINT(" offset: %d, length %d\n",
7929 + _urb->iso_frame_desc[i].offset,
7930 + _urb->iso_frame_desc[i].length);
7935 +static void dump_channel_info(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *qh)
7937 + if (qh->channel != NULL) {
7938 + dwc_hc_t *hc = qh->channel;
7939 + struct list_head *item;
7940 + dwc_otg_qh_t *qh_item;
7941 + int num_channels = _hcd->core_if->core_params->host_channels;
7944 + dwc_otg_hc_regs_t *hc_regs;
7945 + hcchar_data_t hcchar;
7946 + hcsplt_data_t hcsplt;
7947 + hctsiz_data_t hctsiz;
7950 + hc_regs = _hcd->core_if->host_if->hc_regs[hc->hc_num];
7951 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7952 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
7953 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
7954 + hcdma = dwc_read_reg32(&hc_regs->hcdma);
7956 + DWC_PRINT(" Assigned to channel %p:\n", hc);
7957 + DWC_PRINT(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
7958 + DWC_PRINT(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
7959 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
7960 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
7961 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
7962 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
7963 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
7964 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
7965 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
7966 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
7967 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
7968 + DWC_PRINT(" qh: %p\n", hc->qh);
7969 + DWC_PRINT(" NP inactive sched:\n");
7970 + list_for_each(item, &_hcd->non_periodic_sched_inactive) {
7971 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7972 + DWC_PRINT(" %p\n", qh_item);
7973 + } DWC_PRINT(" NP active sched:\n");
7974 + list_for_each(item, &_hcd->non_periodic_sched_deferred) {
7975 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7976 + DWC_PRINT(" %p\n", qh_item);
7977 + } DWC_PRINT(" NP deferred sched:\n");
7978 + list_for_each(item, &_hcd->non_periodic_sched_active) {
7979 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7980 + DWC_PRINT(" %p\n", qh_item);
7981 + } DWC_PRINT(" Channels: \n");
7982 + for (i = 0; i < num_channels; i++) {
7983 + dwc_hc_t *hc = _hcd->hc_ptr_array[i];
7984 + DWC_PRINT(" %2d: %p\n", i, hc);
7990 +/** Starts processing a USB transfer request specified by a USB Request Block
7991 + * (URB). mem_flags indicates the type of memory allocation to use while
7992 + * processing this URB. */
7993 +int dwc_otg_hcd_urb_enqueue(struct usb_hcd *_hcd,
7997 + unsigned long flags;
7999 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8000 + dwc_otg_qtd_t *qtd;
8002 + local_irq_save(flags);
8003 + retval = usb_hcd_link_urb_to_ep(_hcd, _urb);
8005 + local_irq_restore(flags);
8009 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
8010 + dump_urb_info(_urb, "dwc_otg_hcd_urb_enqueue");
8013 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
8014 + /* No longer connected. */
8015 + local_irq_restore(flags);
8019 + qtd = dwc_otg_hcd_qtd_create (_urb);
8020 + if (qtd == NULL) {
8021 + local_irq_restore(flags);
8022 + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
8026 + retval = dwc_otg_hcd_qtd_add (qtd, dwc_otg_hcd);
8028 + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
8029 + "Error status %d\n", retval);
8030 + dwc_otg_hcd_qtd_free(qtd);
8033 + local_irq_restore (flags);
8037 +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
8039 +int dwc_otg_hcd_urb_dequeue(struct usb_hcd *_hcd, struct urb *_urb, int _status)
8041 + unsigned long flags;
8042 + dwc_otg_hcd_t *dwc_otg_hcd;
8043 + dwc_otg_qtd_t *urb_qtd;
8046 + //struct usb_host_endpoint *_ep = NULL;
8048 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
8050 + local_irq_save(flags);
8052 + retval = usb_hcd_check_unlink_urb(_hcd, _urb, _status);
8054 + local_irq_restore(flags);
8058 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
8059 + urb_qtd = (dwc_otg_qtd_t *)_urb->hcpriv;
8060 + if (urb_qtd == NULL) {
8061 + printk("urb_qtd is NULL for _urb %08x\n",(unsigned)_urb);
8064 + qh = (dwc_otg_qh_t *) urb_qtd->qtd_qh_ptr;
8070 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
8071 + dump_urb_info(_urb, "dwc_otg_hcd_urb_dequeue");
8072 + if (urb_qtd == qh->qtd_in_process) {
8073 + dump_channel_info(dwc_otg_hcd, qh);
8078 + if (urb_qtd == qh->qtd_in_process) {
8079 + /* The QTD is in process (it has been assigned to a channel). */
8081 + if (dwc_otg_hcd->flags.b.port_connect_status) {
8083 + * If still connected (i.e. in host mode), halt the
8084 + * channel so it can be used for other transfers. If
8085 + * no longer connected, the host registers can't be
8086 + * written to halt the channel since the core is in
8089 + dwc_otg_hc_halt(dwc_otg_hcd->core_if, qh->channel,
8090 + DWC_OTG_HC_XFER_URB_DEQUEUE);
8095 + * Free the QTD and clean up the associated QH. Leave the QH in the
8096 + * schedule if it has any remaining QTDs.
8098 + dwc_otg_hcd_qtd_remove_and_free(urb_qtd);
8099 + if (urb_qtd == qh->qtd_in_process) {
8100 + dwc_otg_hcd_qh_deactivate(dwc_otg_hcd, qh, 0);
8101 + qh->channel = NULL;
8102 + qh->qtd_in_process = NULL;
8103 + } else if (list_empty(&qh->qtd_list)) {
8104 + dwc_otg_hcd_qh_remove(dwc_otg_hcd, qh);
8108 + local_irq_restore(flags);
8109 + _urb->hcpriv = NULL;
8111 + /* Higher layer software sets URB status. */
8112 + usb_hcd_unlink_urb_from_ep(_hcd, _urb);
8113 + usb_hcd_giveback_urb(_hcd, _urb, _status);
8114 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
8115 + DWC_PRINT("Called usb_hcd_giveback_urb()\n");
8116 + DWC_PRINT(" urb->status = %d\n", _urb->status);
8123 +/** Frees resources in the DWC_otg controller related to a given endpoint. Also
8124 + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
8125 + * must already be dequeued. */
8126 +void dwc_otg_hcd_endpoint_disable(struct usb_hcd *_hcd,
8127 + struct usb_host_endpoint *_ep)
8131 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
8133 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
8134 + "endpoint=%d\n", _ep->desc.bEndpointAddress,
8135 + dwc_ep_addr_to_endpoint(_ep->desc.bEndpointAddress));
8137 + qh = (dwc_otg_qh_t *)(_ep->hcpriv);
8140 + /** Check that the QTD list is really empty */
8141 + if (!list_empty(&qh->qtd_list)) {
8142 + DWC_WARN("DWC OTG HCD EP DISABLE:"
8143 + " QTD List for this endpoint is not empty\n");
8147 + dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
8148 + _ep->hcpriv = NULL;
8153 +extern int dwc_irq;
8154 +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
8155 + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
8158 + * This function is called by the USB core when an interrupt occurs */
8159 +irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *_hcd)
8161 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8163 + mask_and_ack_ifx_irq (dwc_irq);
8164 + return IRQ_RETVAL(dwc_otg_hcd_handle_intr(dwc_otg_hcd));
8167 +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
8168 + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
8169 + * is the status change indicator for the single root port. Returns 1 if either
8170 + * change indicator is 1, otherwise returns 0. */
8171 +int dwc_otg_hcd_hub_status_data(struct usb_hcd *_hcd, char *_buf)
8173 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8176 + _buf[0] |= (dwc_otg_hcd->flags.b.port_connect_status_change ||
8177 + dwc_otg_hcd->flags.b.port_reset_change ||
8178 + dwc_otg_hcd->flags.b.port_enable_change ||
8179 + dwc_otg_hcd->flags.b.port_suspend_change ||
8180 + dwc_otg_hcd->flags.b.port_over_current_change) << 1;
8184 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
8185 + " Root port status changed\n");
8186 + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
8187 + dwc_otg_hcd->flags.b.port_connect_status_change);
8188 + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
8189 + dwc_otg_hcd->flags.b.port_reset_change);
8190 + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
8191 + dwc_otg_hcd->flags.b.port_enable_change);
8192 + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
8193 + dwc_otg_hcd->flags.b.port_suspend_change);
8194 + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
8195 + dwc_otg_hcd->flags.b.port_over_current_change);
8198 + return (_buf[0] != 0);
8201 +#ifdef DWC_HS_ELECT_TST
8203 + * Quick and dirty hack to implement the HS Electrical Test
8204 + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
8206 + * This code was copied from our userspace app "hset". It sends a
8207 + * Get Device Descriptor control sequence in two parts, first the
8208 + * Setup packet by itself, followed some time later by the In and
8209 + * Ack packets. Rather than trying to figure out how to add this
8210 + * functionality to the normal driver code, we just hijack the
8211 + * hardware, using these two function to drive the hardware
8215 +dwc_otg_core_global_regs_t *global_regs;
8216 +dwc_otg_host_global_regs_t *hc_global_regs;
8217 +dwc_otg_hc_regs_t *hc_regs;
8218 +uint32_t *data_fifo;
8220 +static void do_setup(void)
8222 + gintsts_data_t gintsts;
8223 + hctsiz_data_t hctsiz;
8224 + hcchar_data_t hcchar;
8225 + haint_data_t haint;
8226 + hcint_data_t hcint;
8228 + /* Enable HAINTs */
8229 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
8231 + /* Enable HCINTs */
8232 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
8234 + /* Read GINTSTS */
8235 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8236 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8239 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8240 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8243 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8244 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8247 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8248 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8251 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8254 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8256 + /* Clear GINTSTS */
8257 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8259 + /* Read GINTSTS */
8260 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8261 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8264 + * Send Setup packet (Get Device Descriptor)
8267 + /* Make sure channel is disabled */
8268 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8269 + if (hcchar.b.chen) {
8270 + //fprintf(stderr, "Channel already enabled 1, HCCHAR = %08x\n", hcchar.d32);
8271 + hcchar.b.chdis = 1;
8272 + // hcchar.b.chen = 1;
8273 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8277 + /* Read GINTSTS */
8278 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8279 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8282 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8283 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8286 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8287 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8290 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8291 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8294 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8297 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8299 + /* Clear GINTSTS */
8300 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8302 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8303 + //if (hcchar.b.chen) {
8304 + // fprintf(stderr, "** Channel _still_ enabled 1, HCCHAR = %08x **\n", hcchar.d32);
8310 + hctsiz.b.xfersize = 8;
8311 + hctsiz.b.pktcnt = 1;
8312 + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
8313 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8316 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8317 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8318 + hcchar.b.epdir = 0;
8319 + hcchar.b.epnum = 0;
8321 + hcchar.b.chen = 1;
8322 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8324 + /* Fill FIFO with Setup data for Get Device Descriptor */
8325 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8326 + dwc_write_reg32(data_fifo++, 0x01000680);
8327 + dwc_write_reg32(data_fifo++, 0x00080000);
8329 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8330 + //fprintf(stderr, "Waiting for HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
8332 + /* Wait for host channel interrupt */
8334 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8335 + } while (gintsts.b.hcintr == 0);
8337 + //fprintf(stderr, "Got HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
8339 + /* Disable HCINTs */
8340 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
8342 + /* Disable HAINTs */
8343 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
8346 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8347 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8350 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8351 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8354 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8355 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8358 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8361 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8363 + /* Clear GINTSTS */
8364 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8366 + /* Read GINTSTS */
8367 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8368 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8371 +static void do_in_ack(void)
8373 + gintsts_data_t gintsts;
8374 + hctsiz_data_t hctsiz;
8375 + hcchar_data_t hcchar;
8376 + haint_data_t haint;
8377 + hcint_data_t hcint;
8378 + host_grxsts_data_t grxsts;
8380 + /* Enable HAINTs */
8381 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
8383 + /* Enable HCINTs */
8384 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
8386 + /* Read GINTSTS */
8387 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8388 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8391 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8392 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8395 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8396 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8399 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8400 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8403 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8406 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8408 + /* Clear GINTSTS */
8409 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8411 + /* Read GINTSTS */
8412 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8413 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8416 + * Receive Control In packet
8419 + /* Make sure channel is disabled */
8420 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8421 + if (hcchar.b.chen) {
8422 + //fprintf(stderr, "Channel already enabled 2, HCCHAR = %08x\n", hcchar.d32);
8423 + hcchar.b.chdis = 1;
8424 + hcchar.b.chen = 1;
8425 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8429 + /* Read GINTSTS */
8430 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8431 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8434 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8435 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8438 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8439 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8442 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8443 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8446 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8449 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8451 + /* Clear GINTSTS */
8452 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8454 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8455 + //if (hcchar.b.chen) {
8456 + // fprintf(stderr, "** Channel _still_ enabled 2, HCCHAR = %08x **\n", hcchar.d32);
8462 + hctsiz.b.xfersize = 8;
8463 + hctsiz.b.pktcnt = 1;
8464 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
8465 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8468 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8469 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8470 + hcchar.b.epdir = 1;
8471 + hcchar.b.epnum = 0;
8473 + hcchar.b.chen = 1;
8474 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8476 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8477 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
8479 + /* Wait for receive status queue interrupt */
8481 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8482 + } while (gintsts.b.rxstsqlvl == 0);
8484 + //fprintf(stderr, "Got RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
8487 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
8488 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
8490 + /* Clear RXSTSQLVL in GINTSTS */
8492 + gintsts.b.rxstsqlvl = 1;
8493 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8495 + switch (grxsts.b.pktsts) {
8496 + case DWC_GRXSTS_PKTSTS_IN:
8497 + /* Read the data into the host buffer */
8498 + if (grxsts.b.bcnt > 0) {
8500 + int word_count = (grxsts.b.bcnt + 3) / 4;
8502 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8504 + for (i = 0; i < word_count; i++) {
8505 + (void)dwc_read_reg32(data_fifo++);
8509 + //fprintf(stderr, "Received %u bytes\n", (unsigned)grxsts.b.bcnt);
8513 + //fprintf(stderr, "** Unexpected GRXSTS packet status 1 **\n");
8517 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8518 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
8520 + /* Wait for receive status queue interrupt */
8522 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8523 + } while (gintsts.b.rxstsqlvl == 0);
8525 + //fprintf(stderr, "Got RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
8528 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
8529 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
8531 + /* Clear RXSTSQLVL in GINTSTS */
8533 + gintsts.b.rxstsqlvl = 1;
8534 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8536 + switch (grxsts.b.pktsts) {
8537 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
8541 + //fprintf(stderr, "** Unexpected GRXSTS packet status 2 **\n");
8545 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8546 + //fprintf(stderr, "Waiting for HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
8548 + /* Wait for host channel interrupt */
8550 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8551 + } while (gintsts.b.hcintr == 0);
8553 + //fprintf(stderr, "Got HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
8556 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8557 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8560 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8561 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8564 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8565 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8568 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8571 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8573 + /* Clear GINTSTS */
8574 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8576 + /* Read GINTSTS */
8577 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8578 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8580 + // usleep(100000);
8585 + * Send handshake packet
8589 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8590 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8593 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8594 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8597 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8598 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8601 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8604 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8606 + /* Clear GINTSTS */
8607 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8609 + /* Read GINTSTS */
8610 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8611 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8613 + /* Make sure channel is disabled */
8614 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8615 + if (hcchar.b.chen) {
8616 + //fprintf(stderr, "Channel already enabled 3, HCCHAR = %08x\n", hcchar.d32);
8617 + hcchar.b.chdis = 1;
8618 + hcchar.b.chen = 1;
8619 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8623 + /* Read GINTSTS */
8624 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8625 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8628 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8629 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8632 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8633 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8636 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8637 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8640 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8643 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8645 + /* Clear GINTSTS */
8646 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8648 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8649 + //if (hcchar.b.chen) {
8650 + // fprintf(stderr, "** Channel _still_ enabled 3, HCCHAR = %08x **\n", hcchar.d32);
8656 + hctsiz.b.xfersize = 0;
8657 + hctsiz.b.pktcnt = 1;
8658 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
8659 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8662 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8663 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8664 + hcchar.b.epdir = 0;
8665 + hcchar.b.epnum = 0;
8667 + hcchar.b.chen = 1;
8668 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8670 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8671 + //fprintf(stderr, "Waiting for HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
8673 + /* Wait for host channel interrupt */
8675 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8676 + } while (gintsts.b.hcintr == 0);
8678 + //fprintf(stderr, "Got HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
8680 + /* Disable HCINTs */
8681 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
8683 + /* Disable HAINTs */
8684 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
8687 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8688 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8691 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8692 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8695 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8696 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8699 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8702 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8704 + /* Clear GINTSTS */
8705 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8707 + /* Read GINTSTS */
8708 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8709 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8711 +#endif /* DWC_HS_ELECT_TST */
8713 +/** Handles hub class-specific requests.*/
8714 +int dwc_otg_hcd_hub_control(struct usb_hcd *_hcd,
8723 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8724 + dwc_otg_core_if_t *core_if = hcd_to_dwc_otg_hcd (_hcd)->core_if;
8725 + struct usb_hub_descriptor *desc;
8726 + hprt0_data_t hprt0 = {.d32 = 0};
8728 + uint32_t port_status;
8730 + switch (_typeReq) {
8731 + case ClearHubFeature:
8732 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8733 + "ClearHubFeature 0x%x\n", _wValue);
8734 + switch (_wValue) {
8735 + case C_HUB_LOCAL_POWER:
8736 + case C_HUB_OVER_CURRENT:
8737 + /* Nothing required here */
8741 + DWC_ERROR ("DWC OTG HCD - "
8742 + "ClearHubFeature request %xh unknown\n", _wValue);
8745 + case ClearPortFeature:
8746 + if (!_wIndex || _wIndex > 1)
8749 + switch (_wValue) {
8750 + case USB_PORT_FEAT_ENABLE:
8751 + DWC_DEBUGPL (DBG_ANY, "DWC OTG HCD HUB CONTROL - "
8752 + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
8753 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8754 + hprt0.b.prtena = 1;
8755 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8757 + case USB_PORT_FEAT_SUSPEND:
8758 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8759 + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
8760 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8761 + hprt0.b.prtres = 1;
8762 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8763 + /* Clear Resume bit */
8765 + hprt0.b.prtres = 0;
8766 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8768 + case USB_PORT_FEAT_POWER:
8769 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8770 + "ClearPortFeature USB_PORT_FEAT_POWER\n");
8771 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8772 + hprt0.b.prtpwr = 0;
8773 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8775 + case USB_PORT_FEAT_INDICATOR:
8776 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8777 + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
8778 + /* Port inidicator not supported */
8780 + case USB_PORT_FEAT_C_CONNECTION:
8781 + /* Clears drivers internal connect status change
8783 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8784 + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
8785 + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
8787 + case USB_PORT_FEAT_C_RESET:
8788 + /* Clears the driver's internal Port Reset Change
8790 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8791 + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
8792 + dwc_otg_hcd->flags.b.port_reset_change = 0;
8794 + case USB_PORT_FEAT_C_ENABLE:
8795 + /* Clears the driver's internal Port
8796 + * Enable/Disable Change flag */
8797 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8798 + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
8799 + dwc_otg_hcd->flags.b.port_enable_change = 0;
8801 + case USB_PORT_FEAT_C_SUSPEND:
8802 + /* Clears the driver's internal Port Suspend
8803 + * Change flag, which is set when resume signaling on
8804 + * the host port is complete */
8805 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8806 + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
8807 + dwc_otg_hcd->flags.b.port_suspend_change = 0;
8809 + case USB_PORT_FEAT_C_OVER_CURRENT:
8810 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8811 + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
8812 + dwc_otg_hcd->flags.b.port_over_current_change = 0;
8816 + DWC_ERROR ("DWC OTG HCD - "
8817 + "ClearPortFeature request %xh "
8818 + "unknown or unsupported\n", _wValue);
8821 + case GetHubDescriptor:
8822 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8823 + "GetHubDescriptor\n");
8824 + desc = (struct usb_hub_descriptor *)_buf;
8825 + desc->bDescLength = 9;
8826 + desc->bDescriptorType = 0x29;
8827 + desc->bNbrPorts = 1;
8828 + desc->wHubCharacteristics = 0x08;
8829 + desc->bPwrOn2PwrGood = 1;
8830 + desc->bHubContrCurrent = 0;
8831 + desc->u.hs.DeviceRemovable[0] = 0;
8832 + desc->u.hs.DeviceRemovable[1] = 0xff;
8834 + case GetHubStatus:
8835 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8836 + "GetHubStatus\n");
8837 + memset (_buf, 0, 4);
8839 + case GetPortStatus:
8840 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8841 + "GetPortStatus\n");
8843 + if (!_wIndex || _wIndex > 1)
8848 + if (dwc_otg_hcd->flags.b.port_connect_status_change)
8849 + port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
8851 + if (dwc_otg_hcd->flags.b.port_enable_change)
8852 + port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
8854 + if (dwc_otg_hcd->flags.b.port_suspend_change)
8855 + port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
8857 + if (dwc_otg_hcd->flags.b.port_reset_change)
8858 + port_status |= (1 << USB_PORT_FEAT_C_RESET);
8860 + if (dwc_otg_hcd->flags.b.port_over_current_change) {
8861 + DWC_ERROR("Device Not Supported\n");
8862 + port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
8865 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
8866 + printk("DISCONNECTED PORT\n");
8868 + * The port is disconnected, which means the core is
8869 + * either in device mode or it soon will be. Just
8870 + * return 0's for the remainder of the port status
8871 + * since the port register can't be read if the core
8872 + * is in device mode.
8875 + *((u32 *) _buf) = cpu_to_le32(port_status);
8877 + *((__le32 *) _buf) = cpu_to_le32(port_status);
8882 + hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
8883 + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
8885 + if (hprt0.b.prtconnsts)
8886 + port_status |= (1 << USB_PORT_FEAT_CONNECTION);
8888 + if (hprt0.b.prtena)
8889 + port_status |= (1 << USB_PORT_FEAT_ENABLE);
8891 + if (hprt0.b.prtsusp)
8892 + port_status |= (1 << USB_PORT_FEAT_SUSPEND);
8894 + if (hprt0.b.prtovrcurract)
8895 + port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
8897 + if (hprt0.b.prtrst)
8898 + port_status |= (1 << USB_PORT_FEAT_RESET);
8900 + if (hprt0.b.prtpwr)
8901 + port_status |= (1 << USB_PORT_FEAT_POWER);
8903 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
8904 + port_status |= USB_PORT_STAT_HIGH_SPEED;
8906 + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
8907 + port_status |= (1 << USB_PORT_FEAT_LOWSPEED);
8909 + if (hprt0.b.prttstctl)
8910 + port_status |= (1 << USB_PORT_FEAT_TEST);
8912 + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
8914 + *((u32 *) _buf) = cpu_to_le32(port_status);
8916 + *((__le32 *) _buf) = cpu_to_le32(port_status);
8920 + case SetHubFeature:
8921 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8922 + "SetHubFeature\n");
8923 + /* No HUB features supported */
8925 + case SetPortFeature:
8926 + if (_wValue != USB_PORT_FEAT_TEST && (!_wIndex || _wIndex > 1))
8929 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
8931 + * The port is disconnected, which means the core is
8932 + * either in device mode or it soon will be. Just
8933 + * return without doing anything since the port
8934 + * register can't be written if the core is in device
8940 + switch (_wValue) {
8941 + case USB_PORT_FEAT_SUSPEND:
8942 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8943 + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
8944 + if (_hcd->self.otg_port == _wIndex
8945 + && _hcd->self.b_hnp_enable) {
8946 + gotgctl_data_t gotgctl = {.d32=0};
8947 + gotgctl.b.hstsethnpen = 1;
8948 + dwc_modify_reg32(&core_if->core_global_regs->
8949 + gotgctl, 0, gotgctl.d32);
8950 + core_if->op_state = A_SUSPEND;
8952 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8953 + hprt0.b.prtsusp = 1;
8954 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8955 + //DWC_PRINT( "SUSPEND: HPRT0=%0x\n", hprt0.d32);
8956 + /* Suspend the Phy Clock */
8958 + pcgcctl_data_t pcgcctl = {.d32=0};
8959 + pcgcctl.b.stoppclk = 1;
8960 + dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
8963 + /* For HNP the bus must be suspended for at least 200ms.*/
8964 + if (_hcd->self.b_hnp_enable) {
8966 + //DWC_PRINT( "SUSPEND: wait complete! (%d)\n", _hcd->state);
8969 + case USB_PORT_FEAT_POWER:
8970 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8971 + "SetPortFeature - USB_PORT_FEAT_POWER\n");
8972 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8973 + hprt0.b.prtpwr = 1;
8974 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8976 + case USB_PORT_FEAT_RESET:
8977 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8978 + "SetPortFeature - USB_PORT_FEAT_RESET\n");
8979 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8980 + /* TODO: Is this for OTG protocol??
8981 + * We shoudl remove OTG totally for Danube system.
8982 + * But, in the future, maybe we need this.
8985 + hprt0.b.prtrst = 1;
8986 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8988 + /* When B-Host the Port reset bit is set in
8989 + * the Start HCD Callback function, so that
8990 + * the reset is started within 1ms of the HNP
8991 + * success interrupt. */
8992 + if (!_hcd->self.is_b_host) {
8993 + hprt0.b.prtrst = 1;
8994 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8997 + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
8999 + hprt0.b.prtrst = 0;
9000 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
9003 +#ifdef DWC_HS_ELECT_TST
9004 + case USB_PORT_FEAT_TEST:
9007 + gintmsk_data_t gintmsk;
9009 + t = (_wIndex >> 8); /* MSB wIndex USB */
9010 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
9011 + "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
9012 + printk("USB_PORT_FEAT_TEST %d\n", t);
9014 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
9015 + hprt0.b.prttstctl = t;
9016 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
9018 + /* Setup global vars with reg addresses (quick and
9019 + * dirty hack, should be cleaned up)
9021 + global_regs = core_if->core_global_regs;
9022 + hc_global_regs = core_if->host_if->host_global_regs;
9023 + hc_regs = (dwc_otg_hc_regs_t *)((char *)global_regs + 0x500);
9024 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
9026 + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
9027 + /* Save current interrupt mask */
9028 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
9030 + /* Disable all interrupts while we muck with
9031 + * the hardware directly
9033 + dwc_write_reg32(&global_regs->gintmsk, 0);
9035 + /* 15 second delay per the test spec */
9038 + /* Drive suspend on the root port */
9039 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
9040 + hprt0.b.prtsusp = 1;
9041 + hprt0.b.prtres = 0;
9042 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
9044 + /* 15 second delay per the test spec */
9047 + /* Drive resume on the root port */
9048 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
9049 + hprt0.b.prtsusp = 0;
9050 + hprt0.b.prtres = 1;
9051 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
9054 + /* Clear the resume bit */
9055 + hprt0.b.prtres = 0;
9056 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
9058 + /* Restore interrupts */
9059 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
9060 + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
9061 + /* Save current interrupt mask */
9062 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
9064 + /* Disable all interrupts while we muck with
9065 + * the hardware directly
9067 + dwc_write_reg32(&global_regs->gintmsk, 0);
9069 + /* 15 second delay per the test spec */
9072 + /* Send the Setup packet */
9075 + /* 15 second delay so nothing else happens for awhile */
9078 + /* Restore interrupts */
9079 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
9080 + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
9081 + /* Save current interrupt mask */
9082 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
9084 + /* Disable all interrupts while we muck with
9085 + * the hardware directly
9087 + dwc_write_reg32(&global_regs->gintmsk, 0);
9089 + /* Send the Setup packet */
9092 + /* 15 second delay so nothing else happens for awhile */
9095 + /* Send the In and Ack packets */
9098 + /* 15 second delay so nothing else happens for awhile */
9101 + /* Restore interrupts */
9102 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
9107 +#endif /* DWC_HS_ELECT_TST */
9109 + case USB_PORT_FEAT_INDICATOR:
9110 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
9111 + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
9112 + /* Not supported */
9116 + DWC_ERROR ("DWC OTG HCD - "
9117 + "SetPortFeature request %xh "
9118 + "unknown or unsupported\n", _wValue);
9125 + DWC_WARN ("DWC OTG HCD - "
9126 + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
9127 + _typeReq, _wIndex, _wValue);
9136 + * Assigns transactions from a QTD to a free host channel and initializes the
9137 + * host channel to perform the transactions. The host channel is removed from
9140 + * @param _hcd The HCD state structure.
9141 + * @param _qh Transactions from the first QTD for this QH are selected and
9142 + * assigned to a free host channel.
9144 +static void assign_and_init_hc(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
9147 + dwc_otg_qtd_t *qtd;
9150 + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p)\n", __func__, _hcd, _qh);
9152 + hc = list_entry(_hcd->free_hc_list.next, dwc_hc_t, hc_list_entry);
9154 + /* Remove the host channel from the free list. */
9155 + list_del_init(&hc->hc_list_entry);
9157 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
9159 + _qh->channel = hc;
9160 + _qh->qtd_in_process = qtd;
9163 + * Use usb_pipedevice to determine device address. This address is
9164 + * 0 before the SET_ADDRESS command and the correct address afterward.
9166 + hc->dev_addr = usb_pipedevice(urb->pipe);
9167 + hc->ep_num = usb_pipeendpoint(urb->pipe);
9169 + if (urb->dev->speed == USB_SPEED_LOW) {
9170 + hc->speed = DWC_OTG_EP_SPEED_LOW;
9171 + } else if (urb->dev->speed == USB_SPEED_FULL) {
9172 + hc->speed = DWC_OTG_EP_SPEED_FULL;
9174 + hc->speed = DWC_OTG_EP_SPEED_HIGH;
9176 + hc->max_packet = dwc_max_packet(_qh->maxp);
9178 + hc->xfer_started = 0;
9179 + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
9180 + hc->error_state = (qtd->error_count > 0);
9181 + hc->halt_on_queue = 0;
9182 + hc->halt_pending = 0;
9186 + * The following values may be modified in the transfer type section
9187 + * below. The xfer_len value may be reduced when the transfer is
9188 + * started to accommodate the max widths of the XferSize and PktCnt
9189 + * fields in the HCTSIZn register.
9191 + hc->do_ping = _qh->ping_state;
9192 + hc->ep_is_in = (usb_pipein(urb->pipe) != 0);
9193 + hc->data_pid_start = _qh->data_toggle;
9194 + hc->multi_count = 1;
9196 + if (_hcd->core_if->dma_enable) {
9197 + hc->xfer_buff = (uint8_t *)(u32)urb->transfer_dma + urb->actual_length;
9199 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer + urb->actual_length;
9201 + hc->xfer_len = urb->transfer_buffer_length - urb->actual_length;
9202 + hc->xfer_count = 0;
9205 + * Set the split attributes
9208 + if (_qh->do_split) {
9210 + hc->xact_pos = qtd->isoc_split_pos;
9211 + hc->complete_split = qtd->complete_split;
9212 + hc->hub_addr = urb->dev->tt->hub->devnum;
9213 + hc->port_addr = urb->dev->ttport;
9216 + switch (usb_pipetype(urb->pipe)) {
9217 + case PIPE_CONTROL:
9218 + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
9219 + switch (qtd->control_phase) {
9220 + case DWC_OTG_CONTROL_SETUP:
9221 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
9224 + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
9225 + if (_hcd->core_if->dma_enable) {
9226 + hc->xfer_buff = (uint8_t *)(u32)urb->setup_dma;
9228 + hc->xfer_buff = (uint8_t *)urb->setup_packet;
9232 + case DWC_OTG_CONTROL_DATA:
9233 + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
9234 + hc->data_pid_start = qtd->data_toggle;
9236 + case DWC_OTG_CONTROL_STATUS:
9238 + * Direction is opposite of data direction or IN if no
9241 + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
9242 + if (urb->transfer_buffer_length == 0) {
9245 + hc->ep_is_in = (usb_pipein(urb->pipe) != USB_DIR_IN);
9247 + if (hc->ep_is_in) {
9250 + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
9252 + if (_hcd->core_if->dma_enable) {
9253 + hc->xfer_buff = (uint8_t *)_hcd->status_buf_dma;
9255 + hc->xfer_buff = (uint8_t *)_hcd->status_buf;
9261 + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
9263 + case PIPE_INTERRUPT:
9264 + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
9266 + case PIPE_ISOCHRONOUS:
9268 + struct usb_iso_packet_descriptor *frame_desc;
9269 + frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
9270 + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
9271 + if (_hcd->core_if->dma_enable) {
9272 + hc->xfer_buff = (uint8_t *)(u32)urb->transfer_dma;
9274 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer;
9276 + hc->xfer_buff += frame_desc->offset + qtd->isoc_split_offset;
9277 + hc->xfer_len = frame_desc->length - qtd->isoc_split_offset;
9279 + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
9280 + if (hc->xfer_len <= 188) {
9281 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
9284 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_BEGIN;
9291 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
9292 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
9294 + * This value may be modified when the transfer is started to
9295 + * reflect the actual transfer length.
9297 + hc->multi_count = dwc_hb_mult(_qh->maxp);
9300 + dwc_otg_hc_init(_hcd->core_if, hc);
9303 +#define DEBUG_HOST_CHANNELS
9304 +#ifdef DEBUG_HOST_CHANNELS
9305 +static int last_sel_trans_num_per_scheduled = 0;
9306 +module_param(last_sel_trans_num_per_scheduled, int, 0444);
9308 +static int last_sel_trans_num_nonper_scheduled = 0;
9309 +module_param(last_sel_trans_num_nonper_scheduled, int, 0444);
9311 +static int last_sel_trans_num_avail_hc_at_start = 0;
9312 +module_param(last_sel_trans_num_avail_hc_at_start, int, 0444);
9314 +static int last_sel_trans_num_avail_hc_at_end = 0;
9315 +module_param(last_sel_trans_num_avail_hc_at_end, int, 0444);
9316 +#endif /* DEBUG_HOST_CHANNELS */
9319 + * This function selects transactions from the HCD transfer schedule and
9320 + * assigns them to available host channels. It is called from HCD interrupt
9321 + * handler functions.
9323 + * @param _hcd The HCD state structure.
9325 + * @return The types of new transactions that were assigned to host channels.
9327 +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd)
9329 + struct list_head *qh_ptr;
9332 + unsigned long flags;
9333 + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
9336 + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
9339 +#ifdef DEBUG_HOST_CHANNELS
9340 + last_sel_trans_num_per_scheduled = 0;
9341 + last_sel_trans_num_nonper_scheduled = 0;
9342 + last_sel_trans_num_avail_hc_at_start = _hcd->available_host_channels;
9343 +#endif /* DEBUG_HOST_CHANNELS */
9345 + /* Process entries in the periodic ready list. */
9346 + num_channels = _hcd->core_if->core_params->host_channels;
9347 + qh_ptr = _hcd->periodic_sched_ready.next;
9348 + while (qh_ptr != &_hcd->periodic_sched_ready
9349 + && !list_empty(&_hcd->free_hc_list)) {
9351 + // Make sure we leave one channel for non periodic transactions.
9352 + local_irq_save(flags);
9353 + if (_hcd->available_host_channels <= 1) {
9354 + local_irq_restore(flags);
9357 + _hcd->available_host_channels--;
9358 + local_irq_restore(flags);
9359 +#ifdef DEBUG_HOST_CHANNELS
9360 + last_sel_trans_num_per_scheduled++;
9361 +#endif /* DEBUG_HOST_CHANNELS */
9363 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9364 + assign_and_init_hc(_hcd, qh);
9367 + * Move the QH from the periodic ready schedule to the
9368 + * periodic assigned schedule.
9370 + qh_ptr = qh_ptr->next;
9371 + local_irq_save(flags);
9372 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_assigned);
9373 + local_irq_restore(flags);
9374 + ret_val = DWC_OTG_TRANSACTION_PERIODIC;
9378 + * Process entries in the deferred portion of the non-periodic list.
9379 + * A NAK put them here and, at the right time, they need to be
9380 + * placed on the sched_inactive list.
9382 + qh_ptr = _hcd->non_periodic_sched_deferred.next;
9383 + while (qh_ptr != &_hcd->non_periodic_sched_deferred) {
9384 + uint16_t frame_number =
9385 + dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
9386 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9387 + qh_ptr = qh_ptr->next;
9389 + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
9392 + * Move the QH from the non periodic deferred schedule to
9393 + * the non periodic inactive schedule.
9395 + local_irq_save(flags);
9396 + list_move(&qh->qh_list_entry,
9397 + &_hcd->non_periodic_sched_inactive);
9398 + local_irq_restore(flags);
9403 + * Process entries in the inactive portion of the non-periodic
9404 + * schedule. Some free host channels may not be used if they are
9405 + * reserved for periodic transfers.
9407 + qh_ptr = _hcd->non_periodic_sched_inactive.next;
9408 + num_channels = _hcd->core_if->core_params->host_channels;
9409 + while (qh_ptr != &_hcd->non_periodic_sched_inactive
9410 + && !list_empty(&_hcd->free_hc_list)) {
9412 + local_irq_save(flags);
9413 + if (_hcd->available_host_channels < 1) {
9414 + local_irq_restore(flags);
9417 + _hcd->available_host_channels--;
9418 + local_irq_restore(flags);
9419 +#ifdef DEBUG_HOST_CHANNELS
9420 + last_sel_trans_num_nonper_scheduled++;
9421 +#endif /* DEBUG_HOST_CHANNELS */
9423 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9424 + assign_and_init_hc(_hcd, qh);
9427 + * Move the QH from the non-periodic inactive schedule to the
9428 + * non-periodic active schedule.
9430 + qh_ptr = qh_ptr->next;
9431 + local_irq_save(flags);
9432 + list_move(&qh->qh_list_entry, &_hcd->non_periodic_sched_active);
9433 + local_irq_restore(flags);
9435 + if (ret_val == DWC_OTG_TRANSACTION_NONE) {
9436 + ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
9438 + ret_val = DWC_OTG_TRANSACTION_ALL;
9442 +#ifdef DEBUG_HOST_CHANNELS
9443 + last_sel_trans_num_avail_hc_at_end = _hcd->available_host_channels;
9444 +#endif /* DEBUG_HOST_CHANNELS */
9450 + * Attempts to queue a single transaction request for a host channel
9451 + * associated with either a periodic or non-periodic transfer. This function
9452 + * assumes that there is space available in the appropriate request queue. For
9453 + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
9454 + * is available in the appropriate Tx FIFO.
9456 + * @param _hcd The HCD state structure.
9457 + * @param _hc Host channel descriptor associated with either a periodic or
9458 + * non-periodic transfer.
9459 + * @param _fifo_dwords_avail Number of DWORDs available in the periodic Tx
9460 + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
9463 + * @return 1 if a request is queued and more requests may be needed to
9464 + * complete the transfer, 0 if no more requests are required for this
9465 + * transfer, -1 if there is insufficient space in the Tx FIFO.
9467 +static int queue_transaction(dwc_otg_hcd_t *_hcd,
9469 + uint16_t _fifo_dwords_avail)
9473 + if (_hcd->core_if->dma_enable) {
9474 + if (!_hc->xfer_started) {
9475 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9476 + _hc->qh->ping_state = 0;
9479 + } else if (_hc->halt_pending) {
9480 + /* Don't queue a request if the channel has been halted. */
9482 + } else if (_hc->halt_on_queue) {
9483 + dwc_otg_hc_halt(_hcd->core_if, _hc, _hc->halt_status);
9485 + } else if (_hc->do_ping) {
9486 + if (!_hc->xfer_started) {
9487 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9490 + } else if (!_hc->ep_is_in ||
9491 + _hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
9492 + if ((_fifo_dwords_avail * 4) >= _hc->max_packet) {
9493 + if (!_hc->xfer_started) {
9494 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9497 + retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
9503 + if (!_hc->xfer_started) {
9504 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9507 + retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
9515 + * Processes active non-periodic channels and queues transactions for these
9516 + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
9517 + * FIFO Empty interrupt is enabled if there are more transactions to queue as
9518 + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
9519 + * FIFO Empty interrupt is disabled.
9521 +static void process_non_periodic_channels(dwc_otg_hcd_t *_hcd)
9523 + gnptxsts_data_t tx_status;
9524 + struct list_head *orig_qh_ptr;
9527 + int no_queue_space = 0;
9528 + int no_fifo_space = 0;
9529 + int more_to_do = 0;
9531 + dwc_otg_core_global_regs_t *global_regs = _hcd->core_if->core_global_regs;
9533 + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
9535 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9536 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (before queue): %d\n",
9537 + tx_status.b.nptxqspcavail);
9538 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
9539 + tx_status.b.nptxfspcavail);
9542 + * Keep track of the starting point. Skip over the start-of-list
9545 + if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
9546 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9548 + orig_qh_ptr = _hcd->non_periodic_qh_ptr;
9551 + * Process once through the active list or until no more space is
9552 + * available in the request queue or the Tx FIFO.
9555 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9556 + if (!_hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
9557 + no_queue_space = 1;
9561 + qh = list_entry(_hcd->non_periodic_qh_ptr, dwc_otg_qh_t, qh_list_entry);
9562 + status = queue_transaction(_hcd, qh->channel, tx_status.b.nptxfspcavail);
9566 + } else if (status < 0) {
9567 + no_fifo_space = 1;
9571 + /* Advance to next QH, skipping start-of-list entry. */
9572 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9573 + if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
9574 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9577 + } while (_hcd->non_periodic_qh_ptr != orig_qh_ptr);
9579 + if (!_hcd->core_if->dma_enable) {
9580 + gintmsk_data_t intr_mask = {.d32 = 0};
9581 + intr_mask.b.nptxfempty = 1;
9584 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9585 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (after queue): %d\n",
9586 + tx_status.b.nptxqspcavail);
9587 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (after queue): %d\n",
9588 + tx_status.b.nptxfspcavail);
9590 + if (more_to_do || no_queue_space || no_fifo_space) {
9592 + * May need to queue more transactions as the request
9593 + * queue or Tx FIFO empties. Enable the non-periodic
9594 + * Tx FIFO empty interrupt. (Always use the half-empty
9595 + * level to ensure that new requests are loaded as
9596 + * soon as possible.)
9598 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
9601 + * Disable the Tx FIFO empty interrupt since there are
9602 + * no more transactions that need to be queued right
9603 + * now. This function is called from interrupt
9604 + * handlers to queue more transactions as transfer
9607 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
9613 + * Processes periodic channels for the next frame and queues transactions for
9614 + * these channels to the DWC_otg controller. After queueing transactions, the
9615 + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
9616 + * to queue as Periodic Tx FIFO or request queue space becomes available.
9617 + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
9619 +static void process_periodic_channels(dwc_otg_hcd_t *_hcd)
9621 + hptxsts_data_t tx_status;
9622 + struct list_head *qh_ptr;
9625 + int no_queue_space = 0;
9626 + int no_fifo_space = 0;
9628 + dwc_otg_host_global_regs_t *host_regs;
9629 + host_regs = _hcd->core_if->host_if->host_global_regs;
9631 + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
9633 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9634 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (before queue): %d\n",
9635 + tx_status.b.ptxqspcavail);
9636 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
9637 + tx_status.b.ptxfspcavail);
9640 + qh_ptr = _hcd->periodic_sched_assigned.next;
9641 + while (qh_ptr != &_hcd->periodic_sched_assigned) {
9642 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9643 + if (tx_status.b.ptxqspcavail == 0) {
9644 + no_queue_space = 1;
9648 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9651 + * Set a flag if we're queuing high-bandwidth in slave mode.
9652 + * The flag prevents any halts to get into the request queue in
9653 + * the middle of multiple high-bandwidth packets getting queued.
9655 + if ((!_hcd->core_if->dma_enable) &&
9656 + (qh->channel->multi_count > 1))
9658 + _hcd->core_if->queuing_high_bandwidth = 1;
9661 + status = queue_transaction(_hcd, qh->channel, tx_status.b.ptxfspcavail);
9663 + no_fifo_space = 1;
9668 + * In Slave mode, stay on the current transfer until there is
9669 + * nothing more to do or the high-bandwidth request count is
9670 + * reached. In DMA mode, only need to queue one request. The
9671 + * controller automatically handles multiple packets for
9672 + * high-bandwidth transfers.
9674 + if (_hcd->core_if->dma_enable ||
9676 + qh->channel->requests == qh->channel->multi_count)) {
9677 + qh_ptr = qh_ptr->next;
9679 + * Move the QH from the periodic assigned schedule to
9680 + * the periodic queued schedule.
9682 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_queued);
9684 + /* done queuing high bandwidth */
9685 + _hcd->core_if->queuing_high_bandwidth = 0;
9689 + if (!_hcd->core_if->dma_enable) {
9690 + dwc_otg_core_global_regs_t *global_regs;
9691 + gintmsk_data_t intr_mask = {.d32 = 0};
9693 + global_regs = _hcd->core_if->core_global_regs;
9694 + intr_mask.b.ptxfempty = 1;
9696 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9697 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (after queue): %d\n",
9698 + tx_status.b.ptxqspcavail);
9699 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (after queue): %d\n",
9700 + tx_status.b.ptxfspcavail);
9702 + if (!(list_empty(&_hcd->periodic_sched_assigned)) ||
9703 + no_queue_space || no_fifo_space) {
9705 + * May need to queue more transactions as the request
9706 + * queue or Tx FIFO empties. Enable the periodic Tx
9707 + * FIFO empty interrupt. (Always use the half-empty
9708 + * level to ensure that new requests are loaded as
9709 + * soon as possible.)
9711 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
9714 + * Disable the Tx FIFO empty interrupt since there are
9715 + * no more transactions that need to be queued right
9716 + * now. This function is called from interrupt
9717 + * handlers to queue more transactions as transfer
9720 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
9726 + * This function processes the currently active host channels and queues
9727 + * transactions for these channels to the DWC_otg controller. It is called
9728 + * from HCD interrupt handler functions.
9730 + * @param _hcd The HCD state structure.
9731 + * @param _tr_type The type(s) of transactions to queue (non-periodic,
9732 + * periodic, or both).
9734 +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
9735 + dwc_otg_transaction_type_e _tr_type)
9738 + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
9740 + /* Process host channels associated with periodic transfers. */
9741 + if ((_tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
9742 + _tr_type == DWC_OTG_TRANSACTION_ALL) &&
9743 + !list_empty(&_hcd->periodic_sched_assigned)) {
9745 + process_periodic_channels(_hcd);
9748 + /* Process host channels associated with non-periodic transfers. */
9749 + if ((_tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
9750 + _tr_type == DWC_OTG_TRANSACTION_ALL)) {
9751 + if (!list_empty(&_hcd->non_periodic_sched_active)) {
9752 + process_non_periodic_channels(_hcd);
9755 + * Ensure NP Tx FIFO empty interrupt is disabled when
9756 + * there are no non-periodic transfers to process.
9758 + gintmsk_data_t gintmsk = {.d32 = 0};
9759 + gintmsk.b.nptxfempty = 1;
9760 + dwc_modify_reg32(&_hcd->core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
9766 + * Sets the final status of an URB and returns it to the device driver. Any
9767 + * required cleanup of the URB is performed.
9769 +void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t * _hcd, struct urb *_urb,
9771 + __releases(_hcd->lock)
9772 +__acquires(_hcd->lock)
9775 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
9776 + DWC_PRINT("%s: urb %p, device %d, ep %d %s, status=%d\n",
9777 + __func__, _urb, usb_pipedevice(_urb->pipe),
9778 + usb_pipeendpoint(_urb->pipe),
9779 + usb_pipein(_urb->pipe) ? "IN" : "OUT", _status);
9780 + if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
9782 + for (i = 0; i < _urb->number_of_packets; i++) {
9783 + DWC_PRINT(" ISO Desc %d status: %d\n",
9784 + i, _urb->iso_frame_desc[i].status);
9790 + _urb->status = _status;
9791 + _urb->hcpriv = NULL;
9792 + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(_hcd), _urb);
9793 + spin_unlock(&_hcd->lock);
9794 + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(_hcd), _urb, _status);
9795 + spin_lock(&_hcd->lock);
9799 + * Returns the Queue Head for an URB.
9801 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *_urb)
9803 + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(_urb);
9804 + return (dwc_otg_qh_t *)ep->hcpriv;
9808 +void dwc_print_setup_data (uint8_t *setup)
9811 + if (CHK_DEBUG_LEVEL(DBG_HCD)){
9812 + DWC_PRINT("Setup Data = MSB ");
9813 + for (i=7; i>=0; i--) DWC_PRINT ("%02x ", setup[i]);
9815 + DWC_PRINT(" bmRequestType Tranfer = %s\n", (setup[0]&0x80) ? "Device-to-Host" : "Host-to-Device");
9816 + DWC_PRINT(" bmRequestType Type = ");
9817 + switch ((setup[0]&0x60) >> 5) {
9818 + case 0: DWC_PRINT("Standard\n"); break;
9819 + case 1: DWC_PRINT("Class\n"); break;
9820 + case 2: DWC_PRINT("Vendor\n"); break;
9821 + case 3: DWC_PRINT("Reserved\n"); break;
9823 + DWC_PRINT(" bmRequestType Recipient = ");
9824 + switch (setup[0]&0x1f) {
9825 + case 0: DWC_PRINT("Device\n"); break;
9826 + case 1: DWC_PRINT("Interface\n"); break;
9827 + case 2: DWC_PRINT("Endpoint\n"); break;
9828 + case 3: DWC_PRINT("Other\n"); break;
9829 + default: DWC_PRINT("Reserved\n"); break;
9831 + DWC_PRINT(" bRequest = 0x%0x\n", setup[1]);
9832 + DWC_PRINT(" wValue = 0x%0x\n", *((uint16_t *)&setup[2]));
9833 + DWC_PRINT(" wIndex = 0x%0x\n", *((uint16_t *)&setup[4]));
9834 + DWC_PRINT(" wLength = 0x%0x\n\n", *((uint16_t *)&setup[6]));
9839 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd) {
9842 + DWC_PRINT("Frame remaining at SOF:\n");
9843 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9844 + _hcd->frrem_samples, _hcd->frrem_accum,
9845 + (_hcd->frrem_samples > 0) ?
9846 + _hcd->frrem_accum/_hcd->frrem_samples : 0);
9849 + DWC_PRINT("Frame remaining at start_transfer (uframe 7):\n");
9850 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9851 + _hcd->core_if->hfnum_7_samples, _hcd->core_if->hfnum_7_frrem_accum,
9852 + (_hcd->core_if->hfnum_7_samples > 0) ?
9853 + _hcd->core_if->hfnum_7_frrem_accum/_hcd->core_if->hfnum_7_samples : 0);
9854 + DWC_PRINT("Frame remaining at start_transfer (uframe 0):\n");
9855 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9856 + _hcd->core_if->hfnum_0_samples, _hcd->core_if->hfnum_0_frrem_accum,
9857 + (_hcd->core_if->hfnum_0_samples > 0) ?
9858 + _hcd->core_if->hfnum_0_frrem_accum/_hcd->core_if->hfnum_0_samples : 0);
9859 + DWC_PRINT("Frame remaining at start_transfer (uframe 1-6):\n");
9860 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9861 + _hcd->core_if->hfnum_other_samples, _hcd->core_if->hfnum_other_frrem_accum,
9862 + (_hcd->core_if->hfnum_other_samples > 0) ?
9863 + _hcd->core_if->hfnum_other_frrem_accum/_hcd->core_if->hfnum_other_samples : 0);
9866 + DWC_PRINT("Frame remaining at sample point A (uframe 7):\n");
9867 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9868 + _hcd->hfnum_7_samples_a, _hcd->hfnum_7_frrem_accum_a,
9869 + (_hcd->hfnum_7_samples_a > 0) ?
9870 + _hcd->hfnum_7_frrem_accum_a/_hcd->hfnum_7_samples_a : 0);
9871 + DWC_PRINT("Frame remaining at sample point A (uframe 0):\n");
9872 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9873 + _hcd->hfnum_0_samples_a, _hcd->hfnum_0_frrem_accum_a,
9874 + (_hcd->hfnum_0_samples_a > 0) ?
9875 + _hcd->hfnum_0_frrem_accum_a/_hcd->hfnum_0_samples_a : 0);
9876 + DWC_PRINT("Frame remaining at sample point A (uframe 1-6):\n");
9877 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9878 + _hcd->hfnum_other_samples_a, _hcd->hfnum_other_frrem_accum_a,
9879 + (_hcd->hfnum_other_samples_a > 0) ?
9880 + _hcd->hfnum_other_frrem_accum_a/_hcd->hfnum_other_samples_a : 0);
9883 + DWC_PRINT("Frame remaining at sample point B (uframe 7):\n");
9884 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9885 + _hcd->hfnum_7_samples_b, _hcd->hfnum_7_frrem_accum_b,
9886 + (_hcd->hfnum_7_samples_b > 0) ?
9887 + _hcd->hfnum_7_frrem_accum_b/_hcd->hfnum_7_samples_b : 0);
9888 + DWC_PRINT("Frame remaining at sample point B (uframe 0):\n");
9889 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9890 + _hcd->hfnum_0_samples_b, _hcd->hfnum_0_frrem_accum_b,
9891 + (_hcd->hfnum_0_samples_b > 0) ?
9892 + _hcd->hfnum_0_frrem_accum_b/_hcd->hfnum_0_samples_b : 0);
9893 + DWC_PRINT("Frame remaining at sample point B (uframe 1-6):\n");
9894 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9895 + _hcd->hfnum_other_samples_b, _hcd->hfnum_other_frrem_accum_b,
9896 + (_hcd->hfnum_other_samples_b > 0) ?
9897 + _hcd->hfnum_other_frrem_accum_b/_hcd->hfnum_other_samples_b : 0);
9902 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd)
9907 + gnptxsts_data_t np_tx_status;
9908 + hptxsts_data_t p_tx_status;
9910 + num_channels = _hcd->core_if->core_params->host_channels;
9912 + DWC_PRINT("************************************************************\n");
9913 + DWC_PRINT("HCD State:\n");
9914 + DWC_PRINT(" Num channels: %d\n", num_channels);
9915 + for (i = 0; i < num_channels; i++) {
9916 + dwc_hc_t *hc = _hcd->hc_ptr_array[i];
9917 + DWC_PRINT(" Channel %d:\n", i);
9918 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
9919 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
9920 + DWC_PRINT(" speed: %d\n", hc->speed);
9921 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
9922 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
9923 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
9924 + DWC_PRINT(" multi_count: %d\n", hc->multi_count);
9925 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
9926 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
9927 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
9928 + DWC_PRINT(" xfer_count: %d\n", hc->xfer_count);
9929 + DWC_PRINT(" halt_on_queue: %d\n", hc->halt_on_queue);
9930 + DWC_PRINT(" halt_pending: %d\n", hc->halt_pending);
9931 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
9932 + DWC_PRINT(" do_split: %d\n", hc->do_split);
9933 + DWC_PRINT(" complete_split: %d\n", hc->complete_split);
9934 + DWC_PRINT(" hub_addr: %d\n", hc->hub_addr);
9935 + DWC_PRINT(" port_addr: %d\n", hc->port_addr);
9936 + DWC_PRINT(" xact_pos: %d\n", hc->xact_pos);
9937 + DWC_PRINT(" requests: %d\n", hc->requests);
9938 + DWC_PRINT(" qh: %p\n", hc->qh);
9939 + if (hc->xfer_started) {
9940 + hfnum_data_t hfnum;
9941 + hcchar_data_t hcchar;
9942 + hctsiz_data_t hctsiz;
9943 + hcint_data_t hcint;
9944 + hcintmsk_data_t hcintmsk;
9945 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
9946 + hcchar.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcchar);
9947 + hctsiz.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hctsiz);
9948 + hcint.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcint);
9949 + hcintmsk.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcintmsk);
9950 + DWC_PRINT(" hfnum: 0x%08x\n", hfnum.d32);
9951 + DWC_PRINT(" hcchar: 0x%08x\n", hcchar.d32);
9952 + DWC_PRINT(" hctsiz: 0x%08x\n", hctsiz.d32);
9953 + DWC_PRINT(" hcint: 0x%08x\n", hcint.d32);
9954 + DWC_PRINT(" hcintmsk: 0x%08x\n", hcintmsk.d32);
9956 + if (hc->xfer_started && (hc->qh != NULL) && (hc->qh->qtd_in_process != NULL)) {
9957 + dwc_otg_qtd_t *qtd;
9959 + qtd = hc->qh->qtd_in_process;
9961 + DWC_PRINT(" URB Info:\n");
9962 + DWC_PRINT(" qtd: %p, urb: %p\n", qtd, urb);
9963 + if (urb != NULL) {
9964 + DWC_PRINT(" Dev: %d, EP: %d %s\n",
9965 + usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe),
9966 + usb_pipein(urb->pipe) ? "IN" : "OUT");
9967 + DWC_PRINT(" Max packet size: %d\n",
9968 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
9969 + DWC_PRINT(" transfer_buffer: %p\n", urb->transfer_buffer);
9970 + DWC_PRINT(" transfer_dma: %p\n", (void *)urb->transfer_dma);
9971 + DWC_PRINT(" transfer_buffer_length: %d\n", urb->transfer_buffer_length);
9972 + DWC_PRINT(" actual_length: %d\n", urb->actual_length);
9976 + //DWC_PRINT(" non_periodic_channels: %d\n", _hcd->non_periodic_channels);
9977 + //DWC_PRINT(" periodic_channels: %d\n", _hcd->periodic_channels);
9978 + DWC_PRINT(" available_channels: %d\n", _hcd->available_host_channels);
9979 + DWC_PRINT(" periodic_usecs: %d\n", _hcd->periodic_usecs);
9980 + np_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->core_global_regs->gnptxsts);
9981 + DWC_PRINT(" NP Tx Req Queue Space Avail: %d\n", np_tx_status.b.nptxqspcavail);
9982 + DWC_PRINT(" NP Tx FIFO Space Avail: %d\n", np_tx_status.b.nptxfspcavail);
9983 + p_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hptxsts);
9984 + DWC_PRINT(" P Tx Req Queue Space Avail: %d\n", p_tx_status.b.ptxqspcavail);
9985 + DWC_PRINT(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
9986 + dwc_otg_hcd_dump_frrem(_hcd);
9987 + dwc_otg_dump_global_registers(_hcd->core_if);
9988 + dwc_otg_dump_host_registers(_hcd->core_if);
9989 + DWC_PRINT("************************************************************\n");
9993 +#endif /* DWC_DEVICE_ONLY */
9995 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.h
9997 +/* ==========================================================================
9998 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd.h $
9999 + * $Revision: 1.1.1.1 $
10000 + * $Date: 2009-04-17 06:15:34 $
10001 + * $Change: 537387 $
10003 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
10004 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
10005 + * otherwise expressly agreed to in writing between Synopsys and you.
10007 + * The Software IS NOT an item of Licensed Software or Licensed Product under
10008 + * any End User Software License Agreement or Agreement for Licensed Product
10009 + * with Synopsys or any supplement thereto. You are permitted to use and
10010 + * redistribute this Software in source and binary forms, with or without
10011 + * modification, provided that redistributions of source code must retain this
10012 + * notice. You may not view, use, disclose, copy or distribute this file or
10013 + * any information contained herein except pursuant to this license grant from
10014 + * Synopsys. If you do not agree with this notice, including the disclaimer
10015 + * below, then you are not authorized to use the Software.
10017 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
10018 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10019 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10020 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
10021 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10022 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
10023 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
10024 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10025 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10026 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
10028 + * ========================================================================== */
10029 +#ifndef DWC_DEVICE_ONLY
10030 +#if !defined(__DWC_HCD_H__)
10031 +#define __DWC_HCD_H__
10033 +#include <linux/list.h>
10034 +#include <linux/usb.h>
10035 +#include <linux/usb/hcd.h>
10038 +struct dwc_otg_device;
10040 +#include "dwc_otg_cil.h"
10041 +//#include "dwc_otg_ifx.h" // winder
10047 + * This file contains the structures, constants, and interfaces for
10048 + * the Host Contoller Driver (HCD).
10050 + * The Host Controller Driver (HCD) is responsible for translating requests
10051 + * from the USB Driver into the appropriate actions on the DWC_otg controller.
10052 + * It isolates the USBD from the specifics of the controller by providing an
10053 + * API to the USBD.
10057 + * Phases for control transfers.
10059 +typedef enum dwc_otg_control_phase {
10060 + DWC_OTG_CONTROL_SETUP,
10061 + DWC_OTG_CONTROL_DATA,
10062 + DWC_OTG_CONTROL_STATUS
10063 +} dwc_otg_control_phase_e;
10065 +/** Transaction types. */
10066 +typedef enum dwc_otg_transaction_type {
10067 + DWC_OTG_TRANSACTION_NONE,
10068 + DWC_OTG_TRANSACTION_PERIODIC,
10069 + DWC_OTG_TRANSACTION_NON_PERIODIC,
10070 + DWC_OTG_TRANSACTION_ALL
10071 +} dwc_otg_transaction_type_e;
10074 + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
10075 + * interrupt, or isochronous transfer. A single QTD is created for each URB
10076 + * (of one of these types) submitted to the HCD. The transfer associated with
10077 + * a QTD may require one or multiple transactions.
10079 + * A QTD is linked to a Queue Head, which is entered in either the
10080 + * non-periodic or periodic schedule for execution. When a QTD is chosen for
10081 + * execution, some or all of its transactions may be executed. After
10082 + * execution, the state of the QTD is updated. The QTD may be retired if all
10083 + * its transactions are complete or if an error occurred. Otherwise, it
10084 + * remains in the schedule so more transactions can be executed later.
10086 +struct dwc_otg_qh;
10087 +typedef struct dwc_otg_qtd {
10089 + * Determines the PID of the next data packet for the data phase of
10090 + * control transfers. Ignored for other transfer types.<br>
10091 + * One of the following values:
10092 + * - DWC_OTG_HC_PID_DATA0
10093 + * - DWC_OTG_HC_PID_DATA1
10095 + uint8_t data_toggle;
10097 + /** Current phase for control transfers (Setup, Data, or Status). */
10098 + dwc_otg_control_phase_e control_phase;
10100 + /** Keep track of the current split type
10101 + * for FS/LS endpoints on a HS Hub */
10102 + uint8_t complete_split;
10104 + /** How many bytes transferred during SSPLIT OUT */
10105 + uint32_t ssplit_out_xfer_count;
10108 + * Holds the number of bus errors that have occurred for a transaction
10109 + * within this transfer.
10111 + uint8_t error_count;
10114 + * Index of the next frame descriptor for an isochronous transfer. A
10115 + * frame descriptor describes the buffer position and length of the
10116 + * data to be transferred in the next scheduled (micro)frame of an
10117 + * isochronous transfer. It also holds status for that transaction.
10118 + * The frame index starts at 0.
10120 + int isoc_frame_index;
10122 + /** Position of the ISOC split on full/low speed */
10123 + uint8_t isoc_split_pos;
10125 + /** Position of the ISOC split in the buffer for the current frame */
10126 + uint16_t isoc_split_offset;
10128 + /** URB for this transfer */
10131 + /** This list of QTDs */
10132 + struct list_head qtd_list_entry;
10134 + /* Field to track the qh pointer */
10135 + struct dwc_otg_qh *qtd_qh_ptr;
10139 + * A Queue Head (QH) holds the static characteristics of an endpoint and
10140 + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
10141 + * be entered in either the non-periodic or periodic schedule.
10143 +typedef struct dwc_otg_qh {
10146 + * One of the following values:
10147 + * - USB_ENDPOINT_XFER_CONTROL
10148 + * - USB_ENDPOINT_XFER_ISOC
10149 + * - USB_ENDPOINT_XFER_BULK
10150 + * - USB_ENDPOINT_XFER_INT
10153 + uint8_t ep_is_in;
10155 + /** wMaxPacketSize Field of Endpoint Descriptor. */
10159 + * Determines the PID of the next data packet for non-control
10160 + * transfers. Ignored for control transfers.<br>
10161 + * One of the following values:
10162 + * - DWC_OTG_HC_PID_DATA0
10163 + * - DWC_OTG_HC_PID_DATA1
10165 + uint8_t data_toggle;
10167 + /** Ping state if 1. */
10168 + uint8_t ping_state;
10171 + * List of QTDs for this QH.
10173 + struct list_head qtd_list;
10175 + /** Host channel currently processing transfers for this QH. */
10176 + dwc_hc_t *channel;
10178 + /** QTD currently assigned to a host channel for this QH. */
10179 + dwc_otg_qtd_t *qtd_in_process;
10181 + /** Full/low speed endpoint on high-speed hub requires split. */
10182 + uint8_t do_split;
10184 + /** @name Periodic schedule information */
10187 + /** Bandwidth in microseconds per (micro)frame. */
10190 + /** Interval between transfers in (micro)frames. */
10191 + uint16_t interval;
10194 + * (micro)frame to initialize a periodic transfer. The transfer
10195 + * executes in the following (micro)frame.
10197 + uint16_t sched_frame;
10199 + /** (micro)frame at which last start split was initialized. */
10200 + uint16_t start_split_frame;
10205 + uint16_t frame_usecs[8];
10206 + /** Entry for QH in either the periodic or non-periodic schedule. */
10207 + struct list_head qh_list_entry;
10211 + * This structure holds the state of the HCD, including the non-periodic and
10212 + * periodic schedules.
10214 +typedef struct dwc_otg_hcd {
10217 + /** DWC OTG Core Interface Layer */
10218 + dwc_otg_core_if_t *core_if;
10220 + /** Internal DWC HCD Flags */
10221 + volatile union dwc_otg_hcd_internal_flags {
10224 + unsigned port_connect_status_change : 1;
10225 + unsigned port_connect_status : 1;
10226 + unsigned port_reset_change : 1;
10227 + unsigned port_enable_change : 1;
10228 + unsigned port_suspend_change : 1;
10229 + unsigned port_over_current_change : 1;
10230 + unsigned reserved : 27;
10235 + * Inactive items in the non-periodic schedule. This is a list of
10236 + * Queue Heads. Transfers associated with these Queue Heads are not
10237 + * currently assigned to a host channel.
10239 + struct list_head non_periodic_sched_inactive;
10242 + * Deferred items in the non-periodic schedule. This is a list of
10243 + * Queue Heads. Transfers associated with these Queue Heads are not
10244 + * currently assigned to a host channel.
10245 + * When we get an NAK, the QH goes here.
10247 + struct list_head non_periodic_sched_deferred;
10250 + * Active items in the non-periodic schedule. This is a list of
10251 + * Queue Heads. Transfers associated with these Queue Heads are
10252 + * currently assigned to a host channel.
10254 + struct list_head non_periodic_sched_active;
10257 + * Pointer to the next Queue Head to process in the active
10258 + * non-periodic schedule.
10260 + struct list_head *non_periodic_qh_ptr;
10263 + * Inactive items in the periodic schedule. This is a list of QHs for
10264 + * periodic transfers that are _not_ scheduled for the next frame.
10265 + * Each QH in the list has an interval counter that determines when it
10266 + * needs to be scheduled for execution. This scheduling mechanism
10267 + * allows only a simple calculation for periodic bandwidth used (i.e.
10268 + * must assume that all periodic transfers may need to execute in the
10269 + * same frame). However, it greatly simplifies scheduling and should
10270 + * be sufficient for the vast majority of OTG hosts, which need to
10271 + * connect to a small number of peripherals at one time.
10273 + * Items move from this list to periodic_sched_ready when the QH
10274 + * interval counter is 0 at SOF.
10276 + struct list_head periodic_sched_inactive;
10279 + * List of periodic QHs that are ready for execution in the next
10280 + * frame, but have not yet been assigned to host channels.
10282 + * Items move from this list to periodic_sched_assigned as host
10283 + * channels become available during the current frame.
10285 + struct list_head periodic_sched_ready;
10288 + * List of periodic QHs to be executed in the next frame that are
10289 + * assigned to host channels.
10291 + * Items move from this list to periodic_sched_queued as the
10292 + * transactions for the QH are queued to the DWC_otg controller.
10294 + struct list_head periodic_sched_assigned;
10297 + * List of periodic QHs that have been queued for execution.
10299 + * Items move from this list to either periodic_sched_inactive or
10300 + * periodic_sched_ready when the channel associated with the transfer
10301 + * is released. If the interval for the QH is 1, the item moves to
10302 + * periodic_sched_ready because it must be rescheduled for the next
10303 + * frame. Otherwise, the item moves to periodic_sched_inactive.
10305 + struct list_head periodic_sched_queued;
10308 + * Total bandwidth claimed so far for periodic transfers. This value
10309 + * is in microseconds per (micro)frame. The assumption is that all
10310 + * periodic transfers may occur in the same (micro)frame.
10312 + uint16_t periodic_usecs;
10315 + * Total bandwidth claimed so far for all periodic transfers
10317 + * This will include a mixture of HS and FS transfers.
10318 + * Units are microseconds per (micro)frame.
10319 + * We have a budget per frame and have to schedule
10320 + * transactions accordingly.
10321 + * Watch out for the fact that things are actually scheduled for the
10324 + uint16_t frame_usecs[8];
10327 + * Frame number read from the core at SOF. The value ranges from 0 to
10328 + * DWC_HFNUM_MAX_FRNUM.
10330 + uint16_t frame_number;
10333 + * Free host channels in the controller. This is a list of
10334 + * dwc_hc_t items.
10336 + struct list_head free_hc_list;
10339 + * Number of available host channels.
10341 + int available_host_channels;
10344 + * Array of pointers to the host channel descriptors. Allows accessing
10345 + * a host channel descriptor given the host channel number. This is
10346 + * useful in interrupt handlers.
10348 + dwc_hc_t *hc_ptr_array[MAX_EPS_CHANNELS];
10351 + * Buffer to use for any data received during the status phase of a
10352 + * control transfer. Normally no data is transferred during the status
10353 + * phase. This buffer is used as a bit bucket.
10355 + uint8_t *status_buf;
10358 + * DMA address for status_buf.
10360 + dma_addr_t status_buf_dma;
10361 +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
10364 + * Structure to allow starting the HCD in a non-interrupt context
10365 + * during an OTG role change.
10367 + struct work_struct start_work;
10368 + struct usb_hcd *_p;
10371 + * Connection timer. An OTG host must display a message if the device
10372 + * does not connect. Started when the VBus power is turned on via
10373 + * sysfs attribute "buspower".
10375 + struct timer_list conn_timer;
10377 + /* Tasket to do a reset */
10378 + struct tasklet_struct *reset_tasklet;
10381 + uint32_t frrem_samples;
10382 + uint64_t frrem_accum;
10384 + uint32_t hfnum_7_samples_a;
10385 + uint64_t hfnum_7_frrem_accum_a;
10386 + uint32_t hfnum_0_samples_a;
10387 + uint64_t hfnum_0_frrem_accum_a;
10388 + uint32_t hfnum_other_samples_a;
10389 + uint64_t hfnum_other_frrem_accum_a;
10391 + uint32_t hfnum_7_samples_b;
10392 + uint64_t hfnum_7_frrem_accum_b;
10393 + uint32_t hfnum_0_samples_b;
10394 + uint64_t hfnum_0_frrem_accum_b;
10395 + uint32_t hfnum_other_samples_b;
10396 + uint64_t hfnum_other_frrem_accum_b;
10401 +/** Gets the dwc_otg_hcd from a struct usb_hcd */
10402 +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
10404 + return (dwc_otg_hcd_t *)(hcd->hcd_priv);
10407 +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
10408 +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t *dwc_otg_hcd)
10410 + return container_of((void *)dwc_otg_hcd, struct usb_hcd, hcd_priv);
10413 +/** @name HCD Create/Destroy Functions */
10415 +extern int __devinit dwc_otg_hcd_init(struct device *_dev, dwc_otg_device_t * dwc_otg_device);
10416 +extern void dwc_otg_hcd_remove(struct device *_dev);
10419 +/** @name Linux HC Driver API Functions */
10422 +extern int dwc_otg_hcd_start(struct usb_hcd *hcd);
10423 +extern void dwc_otg_hcd_stop(struct usb_hcd *hcd);
10424 +extern int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd);
10425 +extern void dwc_otg_hcd_free(struct usb_hcd *hcd);
10427 +extern int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
10429 + gfp_t mem_flags);
10430 +extern int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
10433 +extern irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
10435 +extern void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
10436 + struct usb_host_endpoint *ep);
10438 +extern int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd,
10440 +extern int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
10449 +/** @name Transaction Execution Functions */
10451 +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd);
10452 +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
10453 + dwc_otg_transaction_type_e _tr_type);
10454 +extern void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *_hcd, struct urb *_urb,
10458 +/** @name Interrupt Handler Functions */
10460 +extern int32_t dwc_otg_hcd_handle_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10461 +extern int32_t dwc_otg_hcd_handle_sof_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10462 +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10463 +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10464 +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10465 +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *_dwc_otg_hcd);
10466 +extern int32_t dwc_otg_hcd_handle_port_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10467 +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10468 +extern int32_t dwc_otg_hcd_handle_disconnect_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10469 +extern int32_t dwc_otg_hcd_handle_hc_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10470 +extern int32_t dwc_otg_hcd_handle_hc_n_intr (dwc_otg_hcd_t *_dwc_otg_hcd, uint32_t _num);
10471 +extern int32_t dwc_otg_hcd_handle_session_req_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10472 +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10476 +/** @name Schedule Queue Functions */
10479 +/* Implemented in dwc_otg_hcd_queue.c */
10480 +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *_hcd, struct urb *_urb);
10481 +extern void dwc_otg_hcd_qh_init (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, struct urb *_urb);
10482 +extern void dwc_otg_hcd_qh_free (dwc_otg_qh_t *_qh);
10483 +extern int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh);
10484 +extern void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh);
10485 +extern void dwc_otg_hcd_qh_deactivate (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int sched_csplit);
10486 +extern int dwc_otg_hcd_qh_deferr (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int delay);
10488 +/** Remove and free a QH */
10489 +static inline void dwc_otg_hcd_qh_remove_and_free (dwc_otg_hcd_t *_hcd,
10490 + dwc_otg_qh_t *_qh)
10492 + dwc_otg_hcd_qh_remove (_hcd, _qh);
10493 + dwc_otg_hcd_qh_free (_qh);
10496 +/** Allocates memory for a QH structure.
10497 + * @return Returns the memory allocate or NULL on error. */
10498 +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc (void)
10501 + return (dwc_otg_qh_t *) kmalloc (sizeof(dwc_otg_qh_t), GFP_ATOMIC);
10503 + return (dwc_otg_qh_t *) kmalloc (sizeof(dwc_otg_qh_t), GFP_KERNEL);
10507 +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *urb);
10508 +extern void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *qtd, struct urb *urb);
10509 +extern int dwc_otg_hcd_qtd_add (dwc_otg_qtd_t *qtd, dwc_otg_hcd_t *dwc_otg_hcd);
10511 +/** Allocates memory for a QTD structure.
10512 + * @return Returns the memory allocate or NULL on error. */
10513 +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc (void)
10516 + return (dwc_otg_qtd_t *) kmalloc (sizeof(dwc_otg_qtd_t), GFP_ATOMIC);
10518 + return (dwc_otg_qtd_t *) kmalloc (sizeof(dwc_otg_qtd_t), GFP_KERNEL);
10522 +/** Frees the memory for a QTD structure. QTD should already be removed from
10524 + * @param[in] _qtd QTD to free.*/
10525 +static inline void dwc_otg_hcd_qtd_free (dwc_otg_qtd_t *_qtd)
10530 +/** Removes a QTD from list.
10531 + * @param[in] _qtd QTD to remove from list. */
10532 +static inline void dwc_otg_hcd_qtd_remove (dwc_otg_qtd_t *_qtd)
10534 + unsigned long flags;
10535 + local_irq_save (flags);
10536 + list_del (&_qtd->qtd_list_entry);
10537 + local_irq_restore (flags);
10540 +/** Remove and free a QTD */
10541 +static inline void dwc_otg_hcd_qtd_remove_and_free (dwc_otg_qtd_t *_qtd)
10543 + dwc_otg_hcd_qtd_remove (_qtd);
10544 + dwc_otg_hcd_qtd_free (_qtd);
10550 +/** @name Internal Functions */
10552 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *_urb);
10553 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd);
10554 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd);
10558 +/** Gets the usb_host_endpoint associated with an URB. */
10559 +static inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *_urb)
10561 + struct usb_device *dev = _urb->dev;
10562 + int ep_num = usb_pipeendpoint(_urb->pipe);
10563 + if (usb_pipein(_urb->pipe))
10564 + return dev->ep_in[ep_num];
10566 + return dev->ep_out[ep_num];
10570 + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
10571 + * qualified with its direction (possible 32 endpoints per device).
10573 +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) \
10574 + ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
10575 + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
10577 +/** Gets the QH that contains the list_head */
10578 +#define dwc_list_to_qh(_list_head_ptr_) (container_of(_list_head_ptr_,dwc_otg_qh_t,qh_list_entry))
10580 +/** Gets the QTD that contains the list_head */
10581 +#define dwc_list_to_qtd(_list_head_ptr_) (container_of(_list_head_ptr_,dwc_otg_qtd_t,qtd_list_entry))
10583 +/** Check if QH is non-periodic */
10584 +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == USB_ENDPOINT_XFER_BULK) || \
10585 + (_qh_ptr_->ep_type == USB_ENDPOINT_XFER_CONTROL))
10587 +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
10588 +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
10590 +/** Packet size for any kind of endpoint descriptor */
10591 +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
10594 + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
10595 + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
10596 + * frame number when the max frame number is reached.
10598 +static inline int dwc_frame_num_le(uint16_t _frame1, uint16_t _frame2)
10600 + return ((_frame2 - _frame1) & DWC_HFNUM_MAX_FRNUM) <=
10601 + (DWC_HFNUM_MAX_FRNUM >> 1);
10605 + * Returns true if _frame1 is greater than _frame2. The comparison is done
10606 + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
10607 + * number when the max frame number is reached.
10609 +static inline int dwc_frame_num_gt(uint16_t _frame1, uint16_t _frame2)
10611 + return (_frame1 != _frame2) &&
10612 + (((_frame1 - _frame2) & DWC_HFNUM_MAX_FRNUM) <
10613 + (DWC_HFNUM_MAX_FRNUM >> 1));
10617 + * Increments _frame by the amount specified by _inc. The addition is done
10618 + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
10620 +static inline uint16_t dwc_frame_num_inc(uint16_t _frame, uint16_t _inc)
10622 + return (_frame + _inc) & DWC_HFNUM_MAX_FRNUM;
10625 +static inline uint16_t dwc_full_frame_num (uint16_t _frame)
10627 + return ((_frame) & DWC_HFNUM_MAX_FRNUM) >> 3;
10630 +static inline uint16_t dwc_micro_frame_num (uint16_t _frame)
10632 + return (_frame) & 0x7;
10637 + * Macro to sample the remaining PHY clocks left in the current frame. This
10638 + * may be used during debugging to determine the average time it takes to
10639 + * execute sections of code. There are two possible sample points, "a" and
10640 + * "b", so the _letter argument must be one of these values.
10642 + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
10643 + * example, "cat /sys/devices/lm0/hcd_frrem".
10645 +#define dwc_sample_frrem(_hcd, _qh, _letter) \
10647 + hfnum_data_t hfnum; \
10648 + dwc_otg_qtd_t *qtd; \
10649 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
10650 + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
10651 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
10652 + switch (hfnum.b.frnum & 0x7) { \
10654 + _hcd->hfnum_7_samples_##_letter++; \
10655 + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
10658 + _hcd->hfnum_0_samples_##_letter++; \
10659 + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
10662 + _hcd->hfnum_other_samples_##_letter++; \
10663 + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
10669 +#define dwc_sample_frrem(_hcd, _qh, _letter)
10671 +#endif // __DWC_HCD_H__
10672 +#endif /* DWC_DEVICE_ONLY */
10674 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
10676 +/* ==========================================================================
10677 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd_intr.c $
10678 + * $Revision: 1.1.1.1 $
10679 + * $Date: 2009-04-17 06:15:34 $
10680 + * $Change: 553126 $
10682 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
10683 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
10684 + * otherwise expressly agreed to in writing between Synopsys and you.
10686 + * The Software IS NOT an item of Licensed Software or Licensed Product under
10687 + * any End User Software License Agreement or Agreement for Licensed Product
10688 + * with Synopsys or any supplement thereto. You are permitted to use and
10689 + * redistribute this Software in source and binary forms, with or without
10690 + * modification, provided that redistributions of source code must retain this
10691 + * notice. You may not view, use, disclose, copy or distribute this file or
10692 + * any information contained herein except pursuant to this license grant from
10693 + * Synopsys. If you do not agree with this notice, including the disclaimer
10694 + * below, then you are not authorized to use the Software.
10696 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
10697 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10698 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10699 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
10700 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10701 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
10702 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
10703 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10704 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10705 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
10707 + * ========================================================================== */
10708 +#ifndef DWC_DEVICE_ONLY
10710 +#include "dwc_otg_driver.h"
10711 +#include "dwc_otg_hcd.h"
10712 +#include "dwc_otg_regs.h"
10714 +const int erratum_usb09_patched = 0;
10715 +const int deferral_on = 1;
10716 +const int nak_deferral_delay = 8;
10717 +const int nyet_deferral_delay = 1;
10719 + * This file contains the implementation of the HCD Interrupt handlers.
10722 +/** This function handles interrupts for the HCD. */
10723 +int32_t dwc_otg_hcd_handle_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10727 + dwc_otg_core_if_t *core_if = _dwc_otg_hcd->core_if;
10728 + gintsts_data_t gintsts;
10730 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
10733 + /* Check if HOST Mode */
10734 + if (dwc_otg_is_host_mode(core_if)) {
10735 + gintsts.d32 = dwc_otg_read_core_intr(core_if);
10736 + if (!gintsts.d32) {
10741 + /* Don't print debug message in the interrupt handler on SOF */
10742 +# ifndef DEBUG_SOF
10743 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10745 + DWC_DEBUGPL (DBG_HCD, "\n");
10749 +# ifndef DEBUG_SOF
10750 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10752 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n", gintsts.d32);
10755 + if (gintsts.b.sofintr) {
10756 + retval |= dwc_otg_hcd_handle_sof_intr (_dwc_otg_hcd);
10758 + if (gintsts.b.rxstsqlvl) {
10759 + retval |= dwc_otg_hcd_handle_rx_status_q_level_intr (_dwc_otg_hcd);
10761 + if (gintsts.b.nptxfempty) {
10762 + retval |= dwc_otg_hcd_handle_np_tx_fifo_empty_intr (_dwc_otg_hcd);
10764 + if (gintsts.b.i2cintr) {
10765 + /** @todo Implement i2cintr handler. */
10767 + if (gintsts.b.portintr) {
10768 + retval |= dwc_otg_hcd_handle_port_intr (_dwc_otg_hcd);
10770 + if (gintsts.b.hcintr) {
10771 + retval |= dwc_otg_hcd_handle_hc_intr (_dwc_otg_hcd);
10773 + if (gintsts.b.ptxfempty) {
10774 + retval |= dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (_dwc_otg_hcd);
10777 +# ifndef DEBUG_SOF
10778 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10781 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Finished Servicing Interrupts\n");
10782 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
10783 + dwc_read_reg32(&global_regs->gintsts));
10784 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
10785 + dwc_read_reg32(&global_regs->gintmsk));
10790 +# ifndef DEBUG_SOF
10791 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10793 + DWC_DEBUGPL (DBG_HCD, "\n");
10801 +#ifdef DWC_TRACK_MISSED_SOFS
10802 +#warning Compiling code to track missed SOFs
10803 +#define FRAME_NUM_ARRAY_SIZE 1000
10805 + * This function is for debug only.
10807 +static inline void track_missed_sofs(uint16_t _curr_frame_number) {
10808 + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
10809 + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
10810 + static int frame_num_idx = 0;
10811 + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
10812 + static int dumped_frame_num_array = 0;
10814 + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
10815 + if ((((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) != _curr_frame_number)) {
10816 + frame_num_array[frame_num_idx] = _curr_frame_number;
10817 + last_frame_num_array[frame_num_idx++] = last_frame_num;
10819 + } else if (!dumped_frame_num_array) {
10821 + printk(KERN_EMERG USB_DWC "Frame Last Frame\n");
10822 + printk(KERN_EMERG USB_DWC "----- ----------\n");
10823 + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
10824 + printk(KERN_EMERG USB_DWC "0x%04x 0x%04x\n",
10825 + frame_num_array[i], last_frame_num_array[i]);
10827 + dumped_frame_num_array = 1;
10829 + last_frame_num = _curr_frame_number;
10834 + * Handles the start-of-frame interrupt in host mode. Non-periodic
10835 + * transactions may be queued to the DWC_otg controller for the current
10836 + * (micro)frame. Periodic transactions may be queued to the controller for the
10837 + * next (micro)frame.
10839 +int32_t dwc_otg_hcd_handle_sof_intr (dwc_otg_hcd_t *_hcd)
10841 + hfnum_data_t hfnum;
10842 + struct list_head *qh_entry;
10843 + dwc_otg_qh_t *qh;
10844 + dwc_otg_transaction_type_e tr_type;
10845 + gintsts_data_t gintsts = {.d32 = 0};
10847 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
10850 + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
10853 + _hcd->frame_number = hfnum.b.frnum;
10856 + _hcd->frrem_accum += hfnum.b.frrem;
10857 + _hcd->frrem_samples++;
10860 +#ifdef DWC_TRACK_MISSED_SOFS
10861 + track_missed_sofs(_hcd->frame_number);
10864 + /* Determine whether any periodic QHs should be executed. */
10865 + qh_entry = _hcd->periodic_sched_inactive.next;
10866 + while (qh_entry != &_hcd->periodic_sched_inactive) {
10867 + qh = list_entry(qh_entry, dwc_otg_qh_t, qh_list_entry);
10868 + qh_entry = qh_entry->next;
10869 + if (dwc_frame_num_le(qh->sched_frame, _hcd->frame_number)) {
10871 + * Move QH to the ready list to be executed next
10874 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_ready);
10878 + tr_type = dwc_otg_hcd_select_transactions(_hcd);
10879 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
10880 + dwc_otg_hcd_queue_transactions(_hcd, tr_type);
10883 + /* Clear interrupt */
10884 + gintsts.b.sofintr = 1;
10885 + dwc_write_reg32(&_hcd->core_if->core_global_regs->gintsts, gintsts.d32);
10890 +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
10891 + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
10892 + * memory if the DWC_otg controller is operating in Slave mode. */
10893 +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10895 + host_grxsts_data_t grxsts;
10896 + dwc_hc_t *hc = NULL;
10898 + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
10900 + grxsts.d32 = dwc_read_reg32(&_dwc_otg_hcd->core_if->core_global_regs->grxstsp);
10902 + hc = _dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
10904 + /* Packet Status */
10905 + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
10906 + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
10907 + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid, hc->data_pid_start);
10908 + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
10910 + switch (grxsts.b.pktsts) {
10911 + case DWC_GRXSTS_PKTSTS_IN:
10912 + /* Read the data into the host buffer. */
10913 + if (grxsts.b.bcnt > 0) {
10914 + dwc_otg_read_packet(_dwc_otg_hcd->core_if,
10918 + /* Update the HC fields for the next packet received. */
10919 + hc->xfer_count += grxsts.b.bcnt;
10920 + hc->xfer_buff += grxsts.b.bcnt;
10923 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
10924 + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
10925 + case DWC_GRXSTS_PKTSTS_CH_HALTED:
10926 + /* Handled in interrupt, just ignore data */
10929 + DWC_ERROR ("RX_STS_Q Interrupt: Unknown status %d\n", grxsts.b.pktsts);
10936 +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
10937 + * data packets may be written to the FIFO for OUT transfers. More requests
10938 + * may be written to the non-periodic request queue for IN transfers. This
10939 + * interrupt is enabled only in Slave mode. */
10940 +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10942 + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
10943 + dwc_otg_hcd_queue_transactions(_dwc_otg_hcd,
10944 + DWC_OTG_TRANSACTION_NON_PERIODIC);
10948 +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
10949 + * packets may be written to the FIFO for OUT transfers. More requests may be
10950 + * written to the periodic request queue for IN transfers. This interrupt is
10951 + * enabled only in Slave mode. */
10952 +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10954 + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
10955 + dwc_otg_hcd_queue_transactions(_dwc_otg_hcd,
10956 + DWC_OTG_TRANSACTION_PERIODIC);
10960 +/** There are multiple conditions that can cause a port interrupt. This function
10961 + * determines which interrupt conditions have occurred and handles them
10962 + * appropriately. */
10963 +int32_t dwc_otg_hcd_handle_port_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10966 + hprt0_data_t hprt0;
10967 + hprt0_data_t hprt0_modify;
10969 + hprt0.d32 = dwc_read_reg32(_dwc_otg_hcd->core_if->host_if->hprt0);
10970 + hprt0_modify.d32 = dwc_read_reg32(_dwc_otg_hcd->core_if->host_if->hprt0);
10972 + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
10975 + hprt0_modify.b.prtena = 0;
10976 + hprt0_modify.b.prtconndet = 0;
10977 + hprt0_modify.b.prtenchng = 0;
10978 + hprt0_modify.b.prtovrcurrchng = 0;
10980 + /* Port Connect Detected
10981 + * Set flag and clear if detected */
10982 + if (hprt0.b.prtconndet) {
10983 + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
10984 + "Port Connect Detected--\n", hprt0.d32);
10985 + _dwc_otg_hcd->flags.b.port_connect_status_change = 1;
10986 + _dwc_otg_hcd->flags.b.port_connect_status = 1;
10987 + hprt0_modify.b.prtconndet = 1;
10989 + /* B-Device has connected, Delete the connection timer. */
10990 + del_timer( &_dwc_otg_hcd->conn_timer );
10992 + /* The Hub driver asserts a reset when it sees port connect
10993 + * status change flag */
10997 + /* Port Enable Changed
10998 + * Clear if detected - Set internal flag if disabled */
10999 + if (hprt0.b.prtenchng) {
11000 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
11001 + "Port Enable Changed--\n", hprt0.d32);
11002 + hprt0_modify.b.prtenchng = 1;
11003 + if (hprt0.b.prtena == 1) {
11004 + int do_reset = 0;
11005 + dwc_otg_core_params_t *params = _dwc_otg_hcd->core_if->core_params;
11006 + dwc_otg_core_global_regs_t *global_regs = _dwc_otg_hcd->core_if->core_global_regs;
11007 + dwc_otg_host_if_t *host_if = _dwc_otg_hcd->core_if->host_if;
11009 + /* Check if we need to adjust the PHY clock speed for
11010 + * low power and adjust it */
11011 + if (params->host_support_fs_ls_low_power)
11013 + gusbcfg_data_t usbcfg;
11015 + usbcfg.d32 = dwc_read_reg32 (&global_regs->gusbcfg);
11017 + if ((hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED) ||
11018 + (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED))
11023 + hcfg_data_t hcfg;
11024 + if (usbcfg.b.phylpwrclksel == 0) {
11025 + /* Set PHY low power clock select for FS/LS devices */
11026 + usbcfg.b.phylpwrclksel = 1;
11027 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
11031 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
11033 + if ((hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED) &&
11034 + (params->host_ls_low_power_phy_clk ==
11035 + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ))
11038 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
11039 + if (hcfg.b.fslspclksel != DWC_HCFG_6_MHZ) {
11040 + hcfg.b.fslspclksel = DWC_HCFG_6_MHZ;
11041 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
11048 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 48 MHz ()\n");
11049 + if (hcfg.b.fslspclksel != DWC_HCFG_48_MHZ) {
11050 + hcfg.b.fslspclksel = DWC_HCFG_48_MHZ;
11051 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
11061 + if (usbcfg.b.phylpwrclksel == 1) {
11062 + usbcfg.b.phylpwrclksel = 0;
11063 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
11069 + tasklet_schedule(_dwc_otg_hcd->reset_tasklet);
11074 + /* Port has been enabled set the reset change flag */
11075 + _dwc_otg_hcd->flags.b.port_reset_change = 1;
11079 + _dwc_otg_hcd->flags.b.port_enable_change = 1;
11084 + /** Overcurrent Change Interrupt */
11085 + if (hprt0.b.prtovrcurrchng) {
11086 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
11087 + "Port Overcurrent Changed--\n", hprt0.d32);
11088 + _dwc_otg_hcd->flags.b.port_over_current_change = 1;
11089 + hprt0_modify.b.prtovrcurrchng = 1;
11093 + /* Clear Port Interrupts */
11094 + dwc_write_reg32(_dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
11100 +/** This interrupt indicates that one or more host channels has a pending
11101 + * interrupt. There are multiple conditions that can cause each host channel
11102 + * interrupt. This function determines which conditions have occurred for each
11103 + * host channel interrupt and handles them appropriately. */
11104 +int32_t dwc_otg_hcd_handle_hc_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
11108 + haint_data_t haint;
11110 + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
11113 + haint.d32 = dwc_otg_read_host_all_channels_intr(_dwc_otg_hcd->core_if);
11115 + for (i=0; i<_dwc_otg_hcd->core_if->core_params->host_channels; i++) {
11116 + if (haint.b2.chint & (1 << i)) {
11117 + retval |= dwc_otg_hcd_handle_hc_n_intr (_dwc_otg_hcd, i);
11124 +/* Macro used to clear one channel interrupt */
11125 +#define clear_hc_int(_hc_regs_,_intr_) \
11127 + hcint_data_t hcint_clear = {.d32 = 0}; \
11128 + hcint_clear.b._intr_ = 1; \
11129 + dwc_write_reg32(&((_hc_regs_)->hcint), hcint_clear.d32); \
11133 + * Macro used to disable one channel interrupt. Channel interrupts are
11134 + * disabled when the channel is halted or released by the interrupt handler.
11135 + * There is no need to handle further interrupts of that type until the
11136 + * channel is re-assigned. In fact, subsequent handling may cause crashes
11137 + * because the channel structures are cleaned up when the channel is released.
11139 +#define disable_hc_int(_hc_regs_,_intr_) \
11141 + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
11142 + hcintmsk.b._intr_ = 1; \
11143 + dwc_modify_reg32(&((_hc_regs_)->hcintmsk), hcintmsk.d32, 0); \
11147 + * Gets the actual length of a transfer after the transfer halts. _halt_status
11148 + * holds the reason for the halt.
11150 + * For IN transfers where _halt_status is DWC_OTG_HC_XFER_COMPLETE,
11151 + * *_short_read is set to 1 upon return if less than the requested
11152 + * number of bytes were transferred. Otherwise, *_short_read is set to 0 upon
11153 + * return. _short_read may also be NULL on entry, in which case it remains
11156 +static uint32_t get_actual_xfer_length(dwc_hc_t *_hc,
11157 + dwc_otg_hc_regs_t *_hc_regs,
11158 + dwc_otg_qtd_t *_qtd,
11159 + dwc_otg_halt_status_e _halt_status,
11160 + int *_short_read)
11162 + hctsiz_data_t hctsiz;
11165 + if (_short_read != NULL) {
11166 + *_short_read = 0;
11168 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11170 + if (_halt_status == DWC_OTG_HC_XFER_COMPLETE) {
11171 + if (_hc->ep_is_in) {
11172 + length = _hc->xfer_len - hctsiz.b.xfersize;
11173 + if (_short_read != NULL) {
11174 + *_short_read = (hctsiz.b.xfersize != 0);
11176 + } else if (_hc->qh->do_split) {
11177 + length = _qtd->ssplit_out_xfer_count;
11179 + length = _hc->xfer_len;
11183 + * Must use the hctsiz.pktcnt field to determine how much data
11184 + * has been transferred. This field reflects the number of
11185 + * packets that have been transferred via the USB. This is
11186 + * always an integral number of packets if the transfer was
11187 + * halted before its normal completion. (Can't use the
11188 + * hctsiz.xfersize field because that reflects the number of
11189 + * bytes transferred via the AHB, not the USB).
11191 + length = (_hc->start_pkt_count - hctsiz.b.pktcnt) * _hc->max_packet;
11198 + * Updates the state of the URB after a Transfer Complete interrupt on the
11199 + * host channel. Updates the actual_length field of the URB based on the
11200 + * number of bytes transferred via the host channel. Sets the URB status
11201 + * if the data transfer is finished.
11203 + * @return 1 if the data transfer specified by the URB is completely finished,
11206 +static int update_urb_state_xfer_comp(dwc_hc_t *_hc,
11207 + dwc_otg_hc_regs_t * _hc_regs, struct urb *_urb,
11208 + dwc_otg_qtd_t * _qtd, int *status)
11210 + int xfer_done = 0;
11211 + int short_read = 0;
11213 + _urb->actual_length += get_actual_xfer_length(_hc, _hc_regs, _qtd,
11214 + DWC_OTG_HC_XFER_COMPLETE,
11217 + if (short_read || (_urb->actual_length == _urb->transfer_buffer_length)) {
11219 + if (short_read && (_urb->transfer_flags & URB_SHORT_NOT_OK)) {
11220 + *status = -EREMOTEIO;
11228 + hctsiz_data_t hctsiz;
11229 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11230 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
11231 + __func__, (_hc->ep_is_in ? "IN" : "OUT"), _hc->hc_num);
11232 + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", _hc->xfer_len);
11233 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n", hctsiz.b.xfersize);
11234 + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
11235 + _urb->transfer_buffer_length);
11236 + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n", _urb->actual_length);
11237 + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
11238 + short_read, xfer_done);
11242 + return xfer_done;
11246 + * Save the starting data toggle for the next transfer. The data toggle is
11247 + * saved in the QH for non-control transfers and it's saved in the QTD for
11248 + * control transfers.
11250 +static void save_data_toggle(dwc_hc_t *_hc,
11251 + dwc_otg_hc_regs_t *_hc_regs,
11252 + dwc_otg_qtd_t *_qtd)
11254 + hctsiz_data_t hctsiz;
11255 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11257 + if (_hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
11258 + dwc_otg_qh_t *qh = _hc->qh;
11259 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
11260 + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
11262 + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
11265 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
11266 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
11268 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
11274 + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
11275 + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
11276 + * still linked to the QH, the QH is added to the end of the inactive
11277 + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
11278 + * schedule if no more QTDs are linked to the QH.
11280 +static void deactivate_qh(dwc_otg_hcd_t *_hcd,
11281 + dwc_otg_qh_t *_qh,
11284 + int continue_split = 0;
11285 + dwc_otg_qtd_t *qtd;
11287 + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, _hcd, _qh, free_qtd);
11289 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
11291 + if (qtd->complete_split) {
11292 + continue_split = 1;
11294 + else if ((qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID) ||
11295 + (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))
11297 + continue_split = 1;
11302 + * Note that this was previously a call to
11303 + * dwc_otg_hcd_qtd_remove_and_free(qtd), which frees the qtd.
11304 + * However, that call frees the qtd memory, and we continue in the
11305 + * interrupt logic to access it many more times, including writing
11306 + * to it. With slub debugging on, it is clear that we were writing
11307 + * to memory we had freed.
11308 + * Call this instead, and now I have moved the freeing of the memory to
11309 + * the end of processing this interrupt.
11311 + //dwc_otg_hcd_qtd_remove_and_free(qtd);
11312 + dwc_otg_hcd_qtd_remove(qtd);
11314 + continue_split = 0;
11317 + _qh->channel = NULL;
11318 + _qh->qtd_in_process = NULL;
11319 + dwc_otg_hcd_qh_deactivate(_hcd, _qh, continue_split);
11323 + * Updates the state of an Isochronous URB when the transfer is stopped for
11324 + * any reason. The fields of the current entry in the frame descriptor array
11325 + * are set based on the transfer state and the input _halt_status. Completes
11326 + * the Isochronous URB if all the URB frames have been completed.
11328 + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
11329 + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
11331 +static dwc_otg_halt_status_e
11332 +update_isoc_urb_state(dwc_otg_hcd_t *_hcd,
11334 + dwc_otg_hc_regs_t *_hc_regs,
11335 + dwc_otg_qtd_t *_qtd,
11336 + dwc_otg_halt_status_e _halt_status)
11338 + struct urb *urb = _qtd->urb;
11339 + dwc_otg_halt_status_e ret_val = _halt_status;
11340 + struct usb_iso_packet_descriptor *frame_desc;
11342 + frame_desc = &urb->iso_frame_desc[_qtd->isoc_frame_index];
11343 + switch (_halt_status) {
11344 + case DWC_OTG_HC_XFER_COMPLETE:
11345 + frame_desc->status = 0;
11346 + frame_desc->actual_length =
11347 + get_actual_xfer_length(_hc, _hc_regs, _qtd,
11348 + _halt_status, NULL);
11350 + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
11351 + urb->error_count++;
11352 + if (_hc->ep_is_in) {
11353 + frame_desc->status = -ENOSR;
11355 + frame_desc->status = -ECOMM;
11357 + frame_desc->actual_length = 0;
11359 + case DWC_OTG_HC_XFER_BABBLE_ERR:
11360 + urb->error_count++;
11361 + frame_desc->status = -EOVERFLOW;
11362 + /* Don't need to update actual_length in this case. */
11364 + case DWC_OTG_HC_XFER_XACT_ERR:
11365 + urb->error_count++;
11366 + frame_desc->status = -EPROTO;
11367 + frame_desc->actual_length =
11368 + get_actual_xfer_length(_hc, _hc_regs, _qtd,
11369 + _halt_status, NULL);
11371 + DWC_ERROR("%s: Unhandled _halt_status (%d)\n", __func__,
11377 + if (++_qtd->isoc_frame_index == urb->number_of_packets) {
11379 + * urb->status is not used for isoc transfers.
11380 + * The individual frame_desc statuses are used instead.
11382 + dwc_otg_hcd_complete_urb(_hcd, urb, 0);
11383 + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
11385 + ret_val = DWC_OTG_HC_XFER_COMPLETE;
11392 + * Releases a host channel for use by other transfers. Attempts to select and
11393 + * queue more transactions since at least one host channel is available.
11395 + * @param _hcd The HCD state structure.
11396 + * @param _hc The host channel to release.
11397 + * @param _qtd The QTD associated with the host channel. This QTD may be freed
11398 + * if the transfer is complete or an error has occurred.
11399 + * @param _halt_status Reason the channel is being released. This status
11400 + * determines the actions taken by this function.
11402 +static void release_channel(dwc_otg_hcd_t *_hcd,
11404 + dwc_otg_qtd_t *_qtd,
11405 + dwc_otg_halt_status_e _halt_status,
11408 + dwc_otg_transaction_type_e tr_type;
11410 + dwc_otg_qh_t * _qh;
11412 + int retry_delay = 1;
11413 + unsigned long flags;
11415 + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d\n", __func__,
11416 + _hc->hc_num, _halt_status);
11418 + switch (_halt_status) {
11419 + case DWC_OTG_HC_XFER_NYET:
11420 + case DWC_OTG_HC_XFER_NAK:
11421 + if (_halt_status == DWC_OTG_HC_XFER_NYET) {
11422 + retry_delay = nyet_deferral_delay;
11424 + retry_delay = nak_deferral_delay;
11427 + if (deferral_on && _hc->do_split) {
11430 + deact = dwc_otg_hcd_qh_deferr(_hcd, _qh , retry_delay);
11434 + case DWC_OTG_HC_XFER_URB_COMPLETE:
11437 + case DWC_OTG_HC_XFER_AHB_ERR:
11438 + case DWC_OTG_HC_XFER_STALL:
11439 + case DWC_OTG_HC_XFER_BABBLE_ERR:
11442 + case DWC_OTG_HC_XFER_XACT_ERR:
11443 + if (_qtd->error_count >= 3) {
11444 + DWC_DEBUGPL(DBG_HCDV, " Complete URB with transaction error\n");
11446 + //_qtd->urb->status = -EPROTO;
11447 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPROTO);
11452 + case DWC_OTG_HC_XFER_URB_DEQUEUE:
11454 + * The QTD has already been removed and the QH has been
11455 + * deactivated. Don't want to do anything except release the
11456 + * host channel and try to queue more transfers.
11459 + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
11460 + DWC_ERROR("%s: No halt_status, channel %d\n", __func__, _hc->hc_num);
11468 + /* Only change must_free to true (do not set to zero here -- it is
11469 + * pre-initialized to zero).
11474 + deactivate_qh(_hcd, _hc->qh, free_qtd);
11478 + * Release the host channel for use by other transfers. The cleanup
11479 + * function clears the channel interrupt enables and conditions, so
11480 + * there's no need to clear the Channel Halted interrupt separately.
11482 + dwc_otg_hc_cleanup(_hcd->core_if, _hc);
11483 + list_add_tail(&_hc->hc_list_entry, &_hcd->free_hc_list);
11485 + local_irq_save(flags);
11486 + _hcd->available_host_channels++;
11487 + local_irq_restore(flags);
11488 + /* Try to queue more transfers now that there's a free channel, */
11489 + /* unless erratum_usb09_patched is set */
11490 + if (!erratum_usb09_patched) {
11491 + tr_type = dwc_otg_hcd_select_transactions(_hcd);
11492 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
11493 + dwc_otg_hcd_queue_transactions(_hcd, tr_type);
11499 + * Halts a host channel. If the channel cannot be halted immediately because
11500 + * the request queue is full, this function ensures that the FIFO empty
11501 + * interrupt for the appropriate queue is enabled so that the halt request can
11502 + * be queued when there is space in the request queue.
11504 + * This function may also be called in DMA mode. In that case, the channel is
11505 + * simply released since the core always halts the channel automatically in
11508 +static void halt_channel(dwc_otg_hcd_t *_hcd,
11510 + dwc_otg_qtd_t *_qtd,
11511 + dwc_otg_halt_status_e _halt_status, int *must_free)
11513 + if (_hcd->core_if->dma_enable) {
11514 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11518 + /* Slave mode processing... */
11519 + dwc_otg_hc_halt(_hcd->core_if, _hc, _halt_status);
11521 + if (_hc->halt_on_queue) {
11522 + gintmsk_data_t gintmsk = {.d32 = 0};
11523 + dwc_otg_core_global_regs_t *global_regs;
11524 + global_regs = _hcd->core_if->core_global_regs;
11526 + if (_hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
11527 + _hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
11529 + * Make sure the Non-periodic Tx FIFO empty interrupt
11530 + * is enabled so that the non-periodic schedule will
11533 + gintmsk.b.nptxfempty = 1;
11534 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
11537 + * Move the QH from the periodic queued schedule to
11538 + * the periodic assigned schedule. This allows the
11539 + * halt to be queued when the periodic schedule is
11542 + list_move(&_hc->qh->qh_list_entry,
11543 + &_hcd->periodic_sched_assigned);
11546 + * Make sure the Periodic Tx FIFO Empty interrupt is
11547 + * enabled so that the periodic schedule will be
11550 + gintmsk.b.ptxfempty = 1;
11551 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
11557 + * Performs common cleanup for non-periodic transfers after a Transfer
11558 + * Complete interrupt. This function should be called after any endpoint type
11559 + * specific handling is finished to release the host channel.
11561 +static void complete_non_periodic_xfer(dwc_otg_hcd_t *_hcd,
11563 + dwc_otg_hc_regs_t *_hc_regs,
11564 + dwc_otg_qtd_t *_qtd,
11565 + dwc_otg_halt_status_e _halt_status, int *must_free)
11567 + hcint_data_t hcint;
11569 + _qtd->error_count = 0;
11571 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
11572 + if (hcint.b.nyet) {
11574 + * Got a NYET on the last transaction of the transfer. This
11575 + * means that the endpoint should be in the PING state at the
11576 + * beginning of the next transfer.
11578 + _hc->qh->ping_state = 1;
11579 + clear_hc_int(_hc_regs,nyet);
11583 + * Always halt and release the host channel to make it available for
11584 + * more transfers. There may still be more phases for a control
11585 + * transfer or more data packets for a bulk transfer at this point,
11586 + * but the host channel is still halted. A channel will be reassigned
11587 + * to the transfer when the non-periodic schedule is processed after
11588 + * the channel is released. This allows transactions to be queued
11589 + * properly via dwc_otg_hcd_queue_transactions, which also enables the
11590 + * Tx FIFO Empty interrupt if necessary.
11592 + if (_hc->ep_is_in) {
11594 + * IN transfers in Slave mode require an explicit disable to
11595 + * halt the channel. (In DMA mode, this call simply releases
11598 + halt_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11601 + * The channel is automatically disabled by the core for OUT
11602 + * transfers in Slave mode.
11604 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11609 + * Performs common cleanup for periodic transfers after a Transfer Complete
11610 + * interrupt. This function should be called after any endpoint type specific
11611 + * handling is finished to release the host channel.
11613 +static void complete_periodic_xfer(dwc_otg_hcd_t *_hcd,
11615 + dwc_otg_hc_regs_t *_hc_regs,
11616 + dwc_otg_qtd_t *_qtd,
11617 + dwc_otg_halt_status_e _halt_status, int *must_free)
11619 + hctsiz_data_t hctsiz;
11620 + _qtd->error_count = 0;
11622 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11623 + if (!_hc->ep_is_in || hctsiz.b.pktcnt == 0) {
11624 + /* Core halts channel in these cases. */
11625 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11627 + /* Flush any outstanding requests from the Tx queue. */
11628 + halt_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11633 + * Handles a host channel Transfer Complete interrupt. This handler may be
11634 + * called in either DMA mode or Slave mode.
11636 +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t *_hcd,
11638 + dwc_otg_hc_regs_t *_hc_regs,
11639 + dwc_otg_qtd_t *_qtd, int *must_free)
11641 + int urb_xfer_done;
11642 + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
11643 + struct urb *urb = _qtd->urb;
11644 + int pipe_type = usb_pipetype(urb->pipe);
11645 + int status = -EINPROGRESS;
11647 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11648 + "Transfer Complete--\n", _hc->hc_num);
11651 + * Handle xfer complete on CSPLIT.
11653 + if (_hc->qh->do_split) {
11654 + _qtd->complete_split = 0;
11657 + /* Update the QTD and URB states. */
11658 + switch (pipe_type) {
11659 + case PIPE_CONTROL:
11660 + switch (_qtd->control_phase) {
11661 + case DWC_OTG_CONTROL_SETUP:
11662 + if (urb->transfer_buffer_length > 0) {
11663 + _qtd->control_phase = DWC_OTG_CONTROL_DATA;
11665 + _qtd->control_phase = DWC_OTG_CONTROL_STATUS;
11667 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
11668 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11670 + case DWC_OTG_CONTROL_DATA: {
11671 + urb_xfer_done = update_urb_state_xfer_comp(_hc, _hc_regs,urb, _qtd, &status);
11672 + if (urb_xfer_done) {
11673 + _qtd->control_phase = DWC_OTG_CONTROL_STATUS;
11674 + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
11676 + save_data_toggle(_hc, _hc_regs, _qtd);
11678 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11681 + case DWC_OTG_CONTROL_STATUS:
11682 + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
11683 + if (status == -EINPROGRESS) {
11686 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11687 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
11691 + complete_non_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,
11692 + halt_status, must_free);
11695 + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
11696 + urb_xfer_done = update_urb_state_xfer_comp(_hc, _hc_regs, urb, _qtd, &status);
11697 + if (urb_xfer_done) {
11698 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11699 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
11701 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11704 + save_data_toggle(_hc, _hc_regs, _qtd);
11705 + complete_non_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,halt_status, must_free);
11707 + case PIPE_INTERRUPT:
11708 + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
11709 + update_urb_state_xfer_comp(_hc, _hc_regs, urb, _qtd, &status);
11712 + * Interrupt URB is done on the first transfer complete
11715 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11716 + save_data_toggle(_hc, _hc_regs, _qtd);
11717 + complete_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,
11718 + DWC_OTG_HC_XFER_URB_COMPLETE, must_free);
11720 + case PIPE_ISOCHRONOUS:
11721 + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
11722 + if (_qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL)
11724 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
11725 + DWC_OTG_HC_XFER_COMPLETE);
11727 + complete_periodic_xfer(_hcd, _hc, _hc_regs, _qtd, halt_status, must_free);
11731 + disable_hc_int(_hc_regs,xfercompl);
11737 + * Handles a host channel STALL interrupt. This handler may be called in
11738 + * either DMA mode or Slave mode.
11740 +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t *_hcd,
11742 + dwc_otg_hc_regs_t *_hc_regs,
11743 + dwc_otg_qtd_t *_qtd, int *must_free)
11745 + struct urb *urb = _qtd->urb;
11746 + int pipe_type = usb_pipetype(urb->pipe);
11748 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11749 + "STALL Received--\n", _hc->hc_num);
11751 + if (pipe_type == PIPE_CONTROL) {
11752 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPIPE);
11755 + if (pipe_type == PIPE_BULK || pipe_type == PIPE_INTERRUPT) {
11756 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPIPE);
11758 + * USB protocol requires resetting the data toggle for bulk
11759 + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
11760 + * setup command is issued to the endpoint. Anticipate the
11761 + * CLEAR_FEATURE command since a STALL has occurred and reset
11762 + * the data toggle now.
11764 + _hc->qh->data_toggle = 0;
11767 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_STALL, must_free);
11768 + disable_hc_int(_hc_regs,stall);
11774 + * Updates the state of the URB when a transfer has been stopped due to an
11775 + * abnormal condition before the transfer completes. Modifies the
11776 + * actual_length field of the URB to reflect the number of bytes that have
11777 + * actually been transferred via the host channel.
11779 +static void update_urb_state_xfer_intr(dwc_hc_t *_hc,
11780 + dwc_otg_hc_regs_t *_hc_regs,
11781 + struct urb *_urb,
11782 + dwc_otg_qtd_t *_qtd,
11783 + dwc_otg_halt_status_e _halt_status)
11785 + uint32_t bytes_transferred = get_actual_xfer_length(_hc, _hc_regs, _qtd,
11786 + _halt_status, NULL);
11787 + _urb->actual_length += bytes_transferred;
11791 + hctsiz_data_t hctsiz;
11792 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11793 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
11794 + __func__, (_hc->ep_is_in ? "IN" : "OUT"), _hc->hc_num);
11795 + DWC_DEBUGPL(DBG_HCDV, " _hc->start_pkt_count %d\n", _hc->start_pkt_count);
11796 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
11797 + DWC_DEBUGPL(DBG_HCDV, " _hc->max_packet %d\n", _hc->max_packet);
11798 + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n", bytes_transferred);
11799 + DWC_DEBUGPL(DBG_HCDV, " _urb->actual_length %d\n", _urb->actual_length);
11800 + DWC_DEBUGPL(DBG_HCDV, " _urb->transfer_buffer_length %d\n",
11801 + _urb->transfer_buffer_length);
11807 + * Handles a host channel NAK interrupt. This handler may be called in either
11808 + * DMA mode or Slave mode.
11810 +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t *_hcd,
11812 + dwc_otg_hc_regs_t *_hc_regs,
11813 + dwc_otg_qtd_t *_qtd, int *must_free)
11815 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11816 + "NAK Received--\n", _hc->hc_num);
11819 + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
11820 + * interrupt. Re-start the SSPLIT transfer.
11822 + if (_hc->do_split) {
11823 + if (_hc->complete_split) {
11824 + _qtd->error_count = 0;
11826 + _qtd->complete_split = 0;
11827 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11828 + goto handle_nak_done;
11831 + switch (usb_pipetype(_qtd->urb->pipe)) {
11832 + case PIPE_CONTROL:
11834 + if (_hcd->core_if->dma_enable && _hc->ep_is_in) {
11836 + * NAK interrupts are enabled on bulk/control IN
11837 + * transfers in DMA mode for the sole purpose of
11838 + * resetting the error count after a transaction error
11839 + * occurs. The core will continue transferring data.
11841 + _qtd->error_count = 0;
11842 + goto handle_nak_done;
11846 + * NAK interrupts normally occur during OUT transfers in DMA
11847 + * or Slave mode. For IN transfers, more requests will be
11848 + * queued as request queue space is available.
11850 + _qtd->error_count = 0;
11852 + if (!_hc->qh->ping_state) {
11853 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb,
11854 + _qtd, DWC_OTG_HC_XFER_NAK);
11855 + save_data_toggle(_hc, _hc_regs, _qtd);
11856 + if (_qtd->urb->dev->speed == USB_SPEED_HIGH) {
11857 + _hc->qh->ping_state = 1;
11862 + * Halt the channel so the transfer can be re-started from
11863 + * the appropriate point or the PING protocol will
11864 + * start/continue.
11866 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11868 + case PIPE_INTERRUPT:
11869 + _qtd->error_count = 0;
11870 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11872 + case PIPE_ISOCHRONOUS:
11873 + /* Should never get called for isochronous transfers. */
11879 + disable_hc_int(_hc_regs,nak);
11885 + * Handles a host channel ACK interrupt. This interrupt is enabled when
11886 + * performing the PING protocol in Slave mode, when errors occur during
11887 + * either Slave mode or DMA mode, and during Start Split transactions.
11889 +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t *_hcd,
11890 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
11892 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11893 + "ACK Received--\n", _hc->hc_num);
11895 + if (_hc->do_split) {
11897 + * Handle ACK on SSPLIT.
11898 + * ACK should not occur in CSPLIT.
11900 + if ((!_hc->ep_is_in) && (_hc->data_pid_start != DWC_OTG_HC_PID_SETUP)) {
11901 + _qtd->ssplit_out_xfer_count = _hc->xfer_len;
11903 + if (!(_hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !_hc->ep_is_in)) {
11904 + /* Don't need complete for isochronous out transfers. */
11905 + _qtd->complete_split = 1;
11909 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && !_hc->ep_is_in) {
11910 + switch (_hc->xact_pos) {
11911 + case DWC_HCSPLIT_XACTPOS_ALL:
11913 + case DWC_HCSPLIT_XACTPOS_END:
11914 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
11915 + _qtd->isoc_split_offset = 0;
11917 + case DWC_HCSPLIT_XACTPOS_BEGIN:
11918 + case DWC_HCSPLIT_XACTPOS_MID:
11920 + * For BEGIN or MID, calculate the length for
11921 + * the next microframe to determine the correct
11922 + * SSPLIT token, either MID or END.
11925 + struct usb_iso_packet_descriptor *frame_desc;
11927 + frame_desc = &_qtd->urb->iso_frame_desc[_qtd->isoc_frame_index];
11928 + _qtd->isoc_split_offset += 188;
11930 + if ((frame_desc->length - _qtd->isoc_split_offset) <= 188) {
11931 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_END;
11934 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_MID;
11941 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_ACK, must_free);
11944 + _qtd->error_count = 0;
11946 + if (_hc->qh->ping_state) {
11947 + _hc->qh->ping_state = 0;
11949 + * Halt the channel so the transfer can be re-started
11950 + * from the appropriate point. This only happens in
11951 + * Slave mode. In DMA mode, the ping_state is cleared
11952 + * when the transfer is started because the core
11953 + * automatically executes the PING, then the transfer.
11955 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_ACK, must_free);
11957 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
11962 + * If the ACK occurred when _not_ in the PING state, let the channel
11963 + * continue transferring data after clearing the error count.
11966 + disable_hc_int(_hc_regs,ack);
11972 + * Handles a host channel NYET interrupt. This interrupt should only occur on
11973 + * Bulk and Control OUT endpoints and for complete split transactions. If a
11974 + * NYET occurs at the same time as a Transfer Complete interrupt, it is
11975 + * handled in the xfercomp interrupt handler, not here. This handler may be
11976 + * called in either DMA mode or Slave mode.
11978 +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t *_hcd,
11980 + dwc_otg_hc_regs_t *_hc_regs,
11981 + dwc_otg_qtd_t *_qtd, int *must_free)
11983 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11984 + "NYET Received--\n", _hc->hc_num);
11988 + * re-do the CSPLIT immediately on non-periodic
11990 + if ((_hc->do_split) && (_hc->complete_split)) {
11991 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_INTR) ||
11992 + (_hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
11993 + int frnum = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
11995 + if (dwc_full_frame_num(frnum) !=
11996 + dwc_full_frame_num(_hc->qh->sched_frame)) {
11998 + * No longer in the same full speed frame.
11999 + * Treat this as a transaction error.
12002 + /** @todo Fix system performance so this can
12003 + * be treated as an error. Right now complete
12004 + * splits cannot be scheduled precisely enough
12005 + * due to other system activity, so this error
12006 + * occurs regularly in Slave mode.
12008 + _qtd->error_count++;
12010 + _qtd->complete_split = 0;
12011 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
12012 + /** @todo add support for isoc release */
12013 + goto handle_nyet_done;
12017 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NYET, must_free);
12018 + goto handle_nyet_done;
12021 + _hc->qh->ping_state = 1;
12022 + _qtd->error_count = 0;
12024 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb, _qtd,
12025 + DWC_OTG_HC_XFER_NYET);
12026 + save_data_toggle(_hc, _hc_regs, _qtd);
12029 + * Halt the channel and re-start the transfer so the PING
12030 + * protocol will start.
12032 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NYET, must_free);
12035 + disable_hc_int(_hc_regs,nyet);
12036 + clear_hc_int(_hc_regs, nyet);
12041 + * Handles a host channel babble interrupt. This handler may be called in
12042 + * either DMA mode or Slave mode.
12044 +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t *_hcd,
12045 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12047 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12048 + "Babble Error--\n", _hc->hc_num);
12049 + if (_hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
12050 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EOVERFLOW);
12051 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_BABBLE_ERR, must_free);
12053 + dwc_otg_halt_status_e halt_status;
12054 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
12055 + DWC_OTG_HC_XFER_BABBLE_ERR);
12056 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
12058 + disable_hc_int(_hc_regs,bblerr);
12063 + * Handles a host channel AHB error interrupt. This handler is only called in
12066 +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t *_hcd,
12068 + dwc_otg_hc_regs_t *_hc_regs,
12069 + dwc_otg_qtd_t *_qtd)
12071 + hcchar_data_t hcchar;
12072 + hcsplt_data_t hcsplt;
12073 + hctsiz_data_t hctsiz;
12075 + struct urb *urb = _qtd->urb;
12077 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12078 + "AHB Error--\n", _hc->hc_num);
12080 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12081 + hcsplt.d32 = dwc_read_reg32(&_hc_regs->hcsplt);
12082 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
12083 + hcdma = dwc_read_reg32(&_hc_regs->hcdma);
12085 + DWC_ERROR("AHB ERROR, Channel %d\n", _hc->hc_num);
12086 + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
12087 + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
12088 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
12089 + DWC_ERROR(" Device address: %d\n", usb_pipedevice(urb->pipe));
12090 + DWC_ERROR(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
12091 + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
12092 + DWC_ERROR(" Endpoint type: %s\n",
12093 + ({char *pipetype;
12094 + switch (usb_pipetype(urb->pipe)) {
12095 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
12096 + case PIPE_BULK: pipetype = "BULK"; break;
12097 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
12098 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
12099 + default: pipetype = "UNKNOWN"; break;
12101 + DWC_ERROR(" Speed: %s\n",
12103 + switch (urb->dev->speed) {
12104 + case USB_SPEED_HIGH: speed = "HIGH"; break;
12105 + case USB_SPEED_FULL: speed = "FULL"; break;
12106 + case USB_SPEED_LOW: speed = "LOW"; break;
12107 + default: speed = "UNKNOWN"; break;
12109 + DWC_ERROR(" Max packet size: %d\n",
12110 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
12111 + DWC_ERROR(" Data buffer length: %d\n", urb->transfer_buffer_length);
12112 + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
12113 + urb->transfer_buffer, (void *)(u32)urb->transfer_dma);
12114 + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
12115 + urb->setup_packet, (void *)(u32)urb->setup_dma);
12116 + DWC_ERROR(" Interval: %d\n", urb->interval);
12118 + dwc_otg_hcd_complete_urb(_hcd, urb, -EIO);
12121 + * Force a channel halt. Don't call halt_channel because that won't
12122 + * write to the HCCHARn register in DMA mode to force the halt.
12124 + dwc_otg_hc_halt(_hcd->core_if, _hc, DWC_OTG_HC_XFER_AHB_ERR);
12126 + disable_hc_int(_hc_regs,ahberr);
12131 + * Handles a host channel transaction error interrupt. This handler may be
12132 + * called in either DMA mode or Slave mode.
12134 +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t *_hcd,
12135 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12137 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12138 + "Transaction Error--\n", _hc->hc_num);
12140 + switch (usb_pipetype(_qtd->urb->pipe)) {
12141 + case PIPE_CONTROL:
12143 + _qtd->error_count++;
12144 + if (!_hc->qh->ping_state) {
12145 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb,
12146 + _qtd, DWC_OTG_HC_XFER_XACT_ERR);
12147 + save_data_toggle(_hc, _hc_regs, _qtd);
12148 + if (!_hc->ep_is_in && _qtd->urb->dev->speed == USB_SPEED_HIGH) {
12149 + _hc->qh->ping_state = 1;
12154 + * Halt the channel so the transfer can be re-started from
12155 + * the appropriate point or the PING protocol will start.
12157 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
12159 + case PIPE_INTERRUPT:
12160 + _qtd->error_count++;
12161 + if ((_hc->do_split) && (_hc->complete_split)) {
12162 + _qtd->complete_split = 0;
12164 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
12166 + case PIPE_ISOCHRONOUS:
12168 + dwc_otg_halt_status_e halt_status;
12169 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
12170 + DWC_OTG_HC_XFER_XACT_ERR);
12172 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
12178 + disable_hc_int(_hc_regs,xacterr);
12184 + * Handles a host channel frame overrun interrupt. This handler may be called
12185 + * in either DMA mode or Slave mode.
12187 +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t *_hcd,
12188 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12190 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12191 + "Frame Overrun--\n", _hc->hc_num);
12193 + switch (usb_pipetype(_qtd->urb->pipe)) {
12194 + case PIPE_CONTROL:
12197 + case PIPE_INTERRUPT:
12198 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN, must_free);
12200 + case PIPE_ISOCHRONOUS:
12202 + dwc_otg_halt_status_e halt_status;
12203 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
12204 + DWC_OTG_HC_XFER_FRAME_OVERRUN);
12206 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
12211 + disable_hc_int(_hc_regs,frmovrun);
12217 + * Handles a host channel data toggle error interrupt. This handler may be
12218 + * called in either DMA mode or Slave mode.
12220 +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t *_hcd,
12221 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12223 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12224 + "Data Toggle Error--\n", _hc->hc_num);
12226 + if (_hc->ep_is_in) {
12227 + _qtd->error_count = 0;
12229 + DWC_ERROR("Data Toggle Error on OUT transfer,"
12230 + "channel %d\n", _hc->hc_num);
12233 + disable_hc_int(_hc_regs,datatglerr);
12240 + * This function is for debug only. It checks that a valid halt status is set
12241 + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
12242 + * taken and a warning is issued.
12243 + * @return 1 if halt status is ok, 0 otherwise.
12245 +static inline int halt_status_ok(dwc_otg_hcd_t *_hcd,
12246 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12248 + hcchar_data_t hcchar;
12249 + hctsiz_data_t hctsiz;
12250 + hcint_data_t hcint;
12251 + hcintmsk_data_t hcintmsk;
12252 + hcsplt_data_t hcsplt;
12254 + if (_hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
12256 + * This code is here only as a check. This condition should
12257 + * never happen. Ignore the halt if it does occur.
12259 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12260 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
12261 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
12262 + hcintmsk.d32 = dwc_read_reg32(&_hc_regs->hcintmsk);
12263 + hcsplt.d32 = dwc_read_reg32(&_hc_regs->hcsplt);
12264 + DWC_WARN("%s: _hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
12265 + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
12266 + "hcint 0x%08x, hcintmsk 0x%08x, "
12267 + "hcsplt 0x%08x, qtd->complete_split %d\n",
12268 + __func__, _hc->hc_num, hcchar.d32, hctsiz.d32,
12269 + hcint.d32, hcintmsk.d32,
12270 + hcsplt.d32, _qtd->complete_split);
12272 + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
12273 + __func__, _hc->hc_num);
12275 + clear_hc_int(_hc_regs,chhltd);
12280 + * This code is here only as a check. hcchar.chdis should
12281 + * never be set when the halt interrupt occurs. Halt the
12282 + * channel again if it does occur.
12284 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12285 + if (hcchar.b.chdis) {
12286 + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
12287 + "hcchar 0x%08x, trying to halt again\n",
12288 + __func__, hcchar.d32);
12289 + clear_hc_int(_hc_regs,chhltd);
12290 + _hc->halt_pending = 0;
12291 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12300 + * Handles a host Channel Halted interrupt in DMA mode. This handler
12301 + * determines the reason the channel halted and proceeds accordingly.
12303 +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t *_hcd,
12304 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12306 + hcint_data_t hcint;
12307 + hcintmsk_data_t hcintmsk;
12309 + if (_hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
12310 + _hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
12312 + * Just release the channel. A dequeue can happen on a
12313 + * transfer timeout. In the case of an AHB Error, the channel
12314 + * was forced to halt because there's no way to gracefully
12317 + release_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12321 + /* Read the HCINTn register to determine the cause for the halt. */
12322 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
12323 + hcintmsk.d32 = dwc_read_reg32(&_hc_regs->hcintmsk);
12325 + if (hcint.b.xfercomp) {
12326 + /** @todo This is here because of a possible hardware bug. Spec
12327 + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
12328 + * interrupt w/ACK bit set should occur, but I only see the
12329 + * XFERCOMP bit, even with it masked out. This is a workaround
12330 + * for that behavior. Should fix this when hardware is fixed.
12332 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!_hc->ep_is_in)) {
12333 + handle_hc_ack_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12335 + handle_hc_xfercomp_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12336 + } else if (hcint.b.stall) {
12337 + handle_hc_stall_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12338 + } else if (hcint.b.xacterr) {
12340 + * Must handle xacterr before nak or ack. Could get a xacterr
12341 + * at the same time as either of these on a BULK/CONTROL OUT
12342 + * that started with a PING. The xacterr takes precedence.
12344 + handle_hc_xacterr_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12345 + } else if (hcint.b.nyet) {
12347 + * Must handle nyet before nak or ack. Could get a nyet at the
12348 + * same time as either of those on a BULK/CONTROL OUT that
12349 + * started with a PING. The nyet takes precedence.
12351 + handle_hc_nyet_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12352 + } else if (hcint.b.bblerr) {
12353 + handle_hc_babble_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12354 + } else if (hcint.b.frmovrun) {
12355 + handle_hc_frmovrun_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12356 + } else if (hcint.b.datatglerr) {
12357 + handle_hc_datatglerr_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12358 + _hc->qh->data_toggle = 0;
12359 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12360 + } else if (hcint.b.nak && !hcintmsk.b.nak) {
12362 + * If nak is not masked, it's because a non-split IN transfer
12363 + * is in an error state. In that case, the nak is handled by
12364 + * the nak interrupt handler, not here. Handle nak here for
12365 + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
12366 + * rewinding the buffer pointer.
12368 + handle_hc_nak_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12369 + } else if (hcint.b.ack && !hcintmsk.b.ack) {
12371 + * If ack is not masked, it's because a non-split IN transfer
12372 + * is in an error state. In that case, the ack is handled by
12373 + * the ack interrupt handler, not here. Handle ack here for
12374 + * split transfers. Start splits halt on ACK.
12376 + handle_hc_ack_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12378 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
12379 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
12381 + * A periodic transfer halted with no other channel
12382 + * interrupts set. Assume it was halted by the core
12383 + * because it could not be completed in its scheduled
12387 + DWC_PRINT("%s: Halt channel %d (assume incomplete periodic transfer)\n",
12388 + __func__, _hc->hc_num);
12390 + halt_channel(_hcd, _hc, _qtd,
12391 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE, must_free);
12394 + DWC_ERROR("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
12395 + "for halting is unknown, nyet %d, hcint 0x%08x, intsts 0x%08x\n",
12396 + __func__, _hc->hc_num, hcint.b.nyet, hcint.d32,
12397 + dwc_read_reg32(&_hcd->core_if->core_global_regs->gintsts));
12399 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12405 + * Handles a host channel Channel Halted interrupt.
12407 + * In slave mode, this handler is called only when the driver specifically
12408 + * requests a halt. This occurs during handling other host channel interrupts
12409 + * (e.g. nak, xacterr, stall, nyet, etc.).
12411 + * In DMA mode, this is the interrupt that occurs when the core has finished
12412 + * processing a transfer on a channel. Other host channel interrupts (except
12413 + * ahberr) are disabled in DMA mode.
12415 +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t *_hcd,
12416 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12418 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12419 + "Channel Halted--\n", _hc->hc_num);
12421 + if (_hcd->core_if->dma_enable) {
12422 + handle_hc_chhltd_intr_dma(_hcd, _hc, _hc_regs, _qtd, must_free);
12425 + if (!halt_status_ok(_hcd, _hc, _hc_regs, _qtd, must_free)) {
12429 + release_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12435 +/** Handles interrupt for a specific Host Channel */
12436 +int32_t dwc_otg_hcd_handle_hc_n_intr (dwc_otg_hcd_t *_dwc_otg_hcd, uint32_t _num)
12438 + int must_free = 0;
12440 + hcint_data_t hcint;
12441 + hcintmsk_data_t hcintmsk;
12443 + dwc_otg_hc_regs_t *hc_regs;
12444 + dwc_otg_qtd_t *qtd;
12446 + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", _num);
12448 + hc = _dwc_otg_hcd->hc_ptr_array[_num];
12449 + hc_regs = _dwc_otg_hcd->core_if->host_if->hc_regs[_num];
12450 + qtd = list_entry(hc->qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
12452 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
12453 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
12454 + DWC_DEBUGPL(DBG_HCDV, " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
12455 + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
12456 + hcint.d32 = hcint.d32 & hcintmsk.d32;
12458 + if (!_dwc_otg_hcd->core_if->dma_enable) {
12459 + if ((hcint.b.chhltd) && (hcint.d32 != 0x2)) {
12460 + hcint.b.chhltd = 0;
12464 + if (hcint.b.xfercomp) {
12465 + retval |= handle_hc_xfercomp_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12467 + * If NYET occurred at same time as Xfer Complete, the NYET is
12468 + * handled by the Xfer Complete interrupt handler. Don't want
12469 + * to call the NYET interrupt handler in this case.
12471 + hcint.b.nyet = 0;
12473 + if (hcint.b.chhltd) {
12474 + retval |= handle_hc_chhltd_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12476 + if (hcint.b.ahberr) {
12477 + retval |= handle_hc_ahberr_intr(_dwc_otg_hcd, hc, hc_regs, qtd);
12479 + if (hcint.b.stall) {
12480 + retval |= handle_hc_stall_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12482 + if (hcint.b.nak) {
12483 + retval |= handle_hc_nak_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12485 + if (hcint.b.ack) {
12486 + retval |= handle_hc_ack_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12488 + if (hcint.b.nyet) {
12489 + retval |= handle_hc_nyet_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12491 + if (hcint.b.xacterr) {
12492 + retval |= handle_hc_xacterr_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12494 + if (hcint.b.bblerr) {
12495 + retval |= handle_hc_babble_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12497 + if (hcint.b.frmovrun) {
12498 + retval |= handle_hc_frmovrun_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12500 + if (hcint.b.datatglerr) {
12501 + retval |= handle_hc_datatglerr_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12505 + * Logic to free the qtd here, at the end of the hc intr
12506 + * processing, if the handling of this interrupt determined
12507 + * that it needs to be freed.
12510 + /* Free the qtd here now that we are done using it. */
12511 + dwc_otg_hcd_qtd_free(qtd);
12516 +#endif /* DWC_DEVICE_ONLY */
12518 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
12520 +/* ==========================================================================
12521 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd_queue.c $
12522 + * $Revision: 1.1.1.1 $
12523 + * $Date: 2009-04-17 06:15:34 $
12524 + * $Change: 537387 $
12526 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
12527 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
12528 + * otherwise expressly agreed to in writing between Synopsys and you.
12530 + * The Software IS NOT an item of Licensed Software or Licensed Product under
12531 + * any End User Software License Agreement or Agreement for Licensed Product
12532 + * with Synopsys or any supplement thereto. You are permitted to use and
12533 + * redistribute this Software in source and binary forms, with or without
12534 + * modification, provided that redistributions of source code must retain this
12535 + * notice. You may not view, use, disclose, copy or distribute this file or
12536 + * any information contained herein except pursuant to this license grant from
12537 + * Synopsys. If you do not agree with this notice, including the disclaimer
12538 + * below, then you are not authorized to use the Software.
12540 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
12541 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12542 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
12543 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
12544 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
12545 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12546 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
12547 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
12548 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
12549 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
12551 + * ========================================================================== */
12552 +#ifndef DWC_DEVICE_ONLY
12557 + * This file contains the functions to manage Queue Heads and Queue
12558 + * Transfer Descriptors.
12560 +#include <linux/kernel.h>
12561 +#include <linux/module.h>
12562 +#include <linux/moduleparam.h>
12563 +#include <linux/init.h>
12564 +#include <linux/device.h>
12565 +#include <linux/errno.h>
12566 +#include <linux/list.h>
12567 +#include <linux/interrupt.h>
12568 +#include <linux/string.h>
12570 +#include "dwc_otg_driver.h"
12571 +#include "dwc_otg_hcd.h"
12572 +#include "dwc_otg_regs.h"
12575 + * This function allocates and initializes a QH.
12577 + * @param _hcd The HCD state structure for the DWC OTG controller.
12578 + * @param[in] _urb Holds the information about the device/endpoint that we need
12579 + * to initialize the QH.
12581 + * @return Returns pointer to the newly allocated QH, or NULL on error. */
12582 +dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *_hcd, struct urb *_urb)
12584 + dwc_otg_qh_t *qh;
12586 + /* Allocate memory */
12587 + /** @todo add memflags argument */
12588 + qh = dwc_otg_hcd_qh_alloc ();
12589 + if (qh == NULL) {
12593 + dwc_otg_hcd_qh_init (_hcd, qh, _urb);
12597 +/** Free each QTD in the QH's QTD-list then free the QH. QH should already be
12598 + * removed from a list. QTD list should already be empty if called from URB
12601 + * @param[in] _qh The QH to free.
12603 +void dwc_otg_hcd_qh_free (dwc_otg_qh_t *_qh)
12605 + dwc_otg_qtd_t *qtd;
12606 + struct list_head *pos;
12607 + unsigned long flags;
12609 + /* Free each QTD in the QTD list */
12610 + local_irq_save (flags);
12611 + for (pos = _qh->qtd_list.next;
12612 + pos != &_qh->qtd_list;
12613 + pos = _qh->qtd_list.next)
12616 + qtd = dwc_list_to_qtd (pos);
12617 + dwc_otg_hcd_qtd_free (qtd);
12619 + local_irq_restore (flags);
12625 +/** Initializes a QH structure.
12627 + * @param[in] _hcd The HCD state structure for the DWC OTG controller.
12628 + * @param[in] _qh The QH to init.
12629 + * @param[in] _urb Holds the information about the device/endpoint that we need
12630 + * to initialize the QH. */
12631 +#define SCHEDULE_SLOP 10
12632 +void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, struct urb *_urb)
12634 + memset (_qh, 0, sizeof (dwc_otg_qh_t));
12636 + /* Initialize QH */
12637 + switch (usb_pipetype(_urb->pipe)) {
12638 + case PIPE_CONTROL:
12639 + _qh->ep_type = USB_ENDPOINT_XFER_CONTROL;
12642 + _qh->ep_type = USB_ENDPOINT_XFER_BULK;
12644 + case PIPE_ISOCHRONOUS:
12645 + _qh->ep_type = USB_ENDPOINT_XFER_ISOC;
12647 + case PIPE_INTERRUPT:
12648 + _qh->ep_type = USB_ENDPOINT_XFER_INT;
12652 + _qh->ep_is_in = usb_pipein(_urb->pipe) ? 1 : 0;
12654 + _qh->data_toggle = DWC_OTG_HC_PID_DATA0;
12655 + _qh->maxp = usb_maxpacket(_urb->dev, _urb->pipe, !(usb_pipein(_urb->pipe)));
12656 + INIT_LIST_HEAD(&_qh->qtd_list);
12657 + INIT_LIST_HEAD(&_qh->qh_list_entry);
12658 + _qh->channel = NULL;
12660 + /* FS/LS Enpoint on HS Hub
12661 + * NOT virtual root hub */
12662 + _qh->do_split = 0;
12663 + _qh->speed = _urb->dev->speed;
12664 + if (((_urb->dev->speed == USB_SPEED_LOW) ||
12665 + (_urb->dev->speed == USB_SPEED_FULL)) &&
12666 + (_urb->dev->tt) && (_urb->dev->tt->hub) && (_urb->dev->tt->hub->devnum != 1)) {
12667 + DWC_DEBUGPL(DBG_HCD, "QH init: EP %d: TT found at hub addr %d, for port %d\n",
12668 + usb_pipeendpoint(_urb->pipe), _urb->dev->tt->hub->devnum,
12669 + _urb->dev->ttport);
12670 + _qh->do_split = 1;
12673 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT ||
12674 + _qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
12675 + /* Compute scheduling parameters once and save them. */
12676 + hprt0_data_t hprt;
12678 + /** @todo Account for split transfers in the bus time. */
12679 + int bytecount = dwc_hb_mult(_qh->maxp) * dwc_max_packet(_qh->maxp);
12680 + _qh->usecs = NS_TO_US(usb_calc_bus_time(_urb->dev->speed,
12681 + usb_pipein(_urb->pipe),
12682 + (_qh->ep_type == USB_ENDPOINT_XFER_ISOC),bytecount));
12684 + /* Start in a slightly future (micro)frame. */
12685 + _qh->sched_frame = dwc_frame_num_inc(_hcd->frame_number, SCHEDULE_SLOP);
12686 + _qh->interval = _urb->interval;
12688 + /* Increase interrupt polling rate for debugging. */
12689 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12690 + _qh->interval = 8;
12693 + hprt.d32 = dwc_read_reg32(_hcd->core_if->host_if->hprt0);
12694 + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
12695 + ((_urb->dev->speed == USB_SPEED_LOW) ||
12696 + (_urb->dev->speed == USB_SPEED_FULL)))
12698 + _qh->interval *= 8;
12699 + _qh->sched_frame |= 0x7;
12700 + _qh->start_split_frame = _qh->sched_frame;
12704 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
12705 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", _qh);
12706 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
12707 + _urb->dev->devnum);
12708 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
12709 + usb_pipeendpoint(_urb->pipe),
12710 + usb_pipein(_urb->pipe) == USB_DIR_IN ? "IN" : "OUT");
12711 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n",
12712 + ({ char *speed; switch (_urb->dev->speed) {
12713 + case USB_SPEED_LOW: speed = "low"; break;
12714 + case USB_SPEED_FULL: speed = "full"; break;
12715 + case USB_SPEED_HIGH: speed = "high"; break;
12716 + default: speed = "?"; break;
12718 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n",
12719 + ({ char *type; switch (_qh->ep_type) {
12720 + case USB_ENDPOINT_XFER_ISOC: type = "isochronous"; break;
12721 + case USB_ENDPOINT_XFER_INT: type = "interrupt"; break;
12722 + case USB_ENDPOINT_XFER_CONTROL: type = "control"; break;
12723 + case USB_ENDPOINT_XFER_BULK: type = "bulk"; break;
12724 + default: type = "?"; break;
12727 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12728 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
12730 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
12739 + * Microframe scheduler
12740 + * track the total use in hcd->frame_usecs
12741 + * keep each qh use in qh->frame_usecs
12742 + * when surrendering the qh then donate the time back
12744 +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
12747 + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
12749 +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
12752 + for (i=0; i<8; i++) {
12753 + _hcd->frame_usecs[i] = max_uframe_usecs[i];
12758 +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12761 + unsigned short utime;
12767 + utime = _qh->usecs;
12771 + while (done == 0) {
12772 + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
12773 + if (utime <= _hcd->frame_usecs[i]) {
12774 + _hcd->frame_usecs[i] -= utime;
12775 + _qh->frame_usecs[i] += utime;
12792 + * use this for FS apps that can span multiple uframes
12794 +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12798 + unsigned short utime;
12802 + unsigned short xtime;
12805 + utime = _qh->usecs;
12810 + while (done == 0) {
12811 + if(_hcd->frame_usecs[i] <= 0) {
12821 + * we need n consequtive slots
12822 + * so use j as a start slot j plus j+1 must be enough time (for now)
12824 + xtime= _hcd->frame_usecs[i];
12825 + for (j = i+1 ; j < 8 ; j++ ) {
12827 + * if we add this frame remaining time to xtime we may
12828 + * be OK, if not we need to test j for a complete frame
12830 + if ((xtime+_hcd->frame_usecs[j]) < utime) {
12831 + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
12837 + if (xtime >= utime) {
12839 + j = 8; /* stop loop with a good value ret */
12842 + /* add the frame time to x time */
12843 + xtime += _hcd->frame_usecs[j];
12844 + /* we must have a fully available next frame or break */
12845 + if ((xtime < utime)
12846 + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
12848 + j = 8; /* stop loop with a bad value ret */
12854 + for (j = i; (t_left>0) && (j < 8); j++ ) {
12855 + t_left -= _hcd->frame_usecs[j];
12856 + if ( t_left <= 0 ) {
12857 + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
12858 + _hcd->frame_usecs[j]= -t_left;
12862 + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
12863 + _hcd->frame_usecs[j] = 0;
12877 +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12882 + if (_qh->speed == USB_SPEED_HIGH) {
12883 + /* if this is a hs transaction we need a full frame */
12884 + ret = find_single_uframe(_hcd, _qh);
12886 + /* if this is a fs transaction we may need a sequence of frames */
12887 + ret = find_multi_uframe(_hcd, _qh);
12893 + * Checks that the max transfer size allowed in a host channel is large enough
12894 + * to handle the maximum data transfer in a single (micro)frame for a periodic
12897 + * @param _hcd The HCD state structure for the DWC OTG controller.
12898 + * @param _qh QH for a periodic endpoint.
12900 + * @return 0 if successful, negative error code otherwise.
12902 +static int check_max_xfer_size(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12905 + uint32_t max_xfer_size;
12906 + uint32_t max_channel_xfer_size;
12910 + max_xfer_size = dwc_max_packet(_qh->maxp) * dwc_hb_mult(_qh->maxp);
12911 + max_channel_xfer_size = _hcd->core_if->core_params->max_transfer_size;
12913 + if (max_xfer_size > max_channel_xfer_size) {
12914 + DWC_NOTICE("%s: Periodic xfer length %d > "
12915 + "max xfer length for channel %d\n",
12916 + __func__, max_xfer_size, max_channel_xfer_size);
12917 + status = -ENOSPC;
12924 + * Schedules an interrupt or isochronous transfer in the periodic schedule.
12926 + * @param _hcd The HCD state structure for the DWC OTG controller.
12927 + * @param _qh QH for the periodic transfer. The QH should already contain the
12928 + * scheduling information.
12930 + * @return 0 if successful, negative error code otherwise.
12932 +static int schedule_periodic(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12937 + status = find_uframe(_hcd, _qh);
12939 + if (status == 0) {
12943 + frame = status-1;
12946 + /* Set the new frame up */
12947 + if (frame > -1) {
12948 + _qh->sched_frame &= ~0x7;
12949 + _qh->sched_frame |= (frame & 7);
12952 + if (status != -1 )
12955 + DWC_NOTICE("%s: Insufficient periodic bandwidth for "
12956 + "periodic transfer.\n", __func__);
12960 + status = check_max_xfer_size(_hcd, _qh);
12962 + DWC_NOTICE("%s: Channel max transfer size too small "
12963 + "for periodic transfer.\n", __func__);
12967 + /* Always start in the inactive schedule. */
12968 + list_add_tail(&_qh->qh_list_entry, &_hcd->periodic_sched_inactive);
12971 + /* Update claimed usecs per (micro)frame. */
12972 + _hcd->periodic_usecs += _qh->usecs;
12974 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
12975 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_allocated += _qh->usecs / _qh->interval;
12976 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12977 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_int_reqs++;
12978 + DWC_DEBUGPL(DBG_HCD, "Scheduled intr: qh %p, usecs %d, period %d\n",
12979 + _qh, _qh->usecs, _qh->interval);
12981 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_isoc_reqs++;
12982 + DWC_DEBUGPL(DBG_HCD, "Scheduled isoc: qh %p, usecs %d, period %d\n",
12983 + _qh, _qh->usecs, _qh->interval);
12990 + * This function adds a QH to either the non periodic or periodic schedule if
12991 + * it is not already in the schedule. If the QH is already in the schedule, no
12992 + * action is taken.
12994 + * @return 0 if successful, negative error code otherwise.
12996 +int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12998 + unsigned long flags;
13001 + local_irq_save(flags);
13003 + if (!list_empty(&_qh->qh_list_entry)) {
13004 + /* QH already in a schedule. */
13008 + /* Add the new QH to the appropriate schedule */
13009 + if (dwc_qh_is_non_per(_qh)) {
13010 + /* Always start in the inactive schedule. */
13011 + list_add_tail(&_qh->qh_list_entry, &_hcd->non_periodic_sched_inactive);
13013 + status = schedule_periodic(_hcd, _qh);
13017 + local_irq_restore(flags);
13023 + * This function adds a QH to the non periodic deferred schedule.
13025 + * @return 0 if successful, negative error code otherwise.
13027 +int dwc_otg_hcd_qh_add_deferred(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
13029 + unsigned long flags;
13030 + local_irq_save(flags);
13031 + if (!list_empty(&_qh->qh_list_entry)) {
13032 + /* QH already in a schedule. */
13036 + /* Add the new QH to the non periodic deferred schedule */
13037 + if (dwc_qh_is_non_per(_qh)) {
13038 + list_add_tail(&_qh->qh_list_entry,
13039 + &_hcd->non_periodic_sched_deferred);
13042 + local_irq_restore(flags);
13047 + * Removes an interrupt or isochronous transfer from the periodic schedule.
13049 + * @param _hcd The HCD state structure for the DWC OTG controller.
13050 + * @param _qh QH for the periodic transfer.
13052 +static void deschedule_periodic(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
13055 + list_del_init(&_qh->qh_list_entry);
13058 + /* Update claimed usecs per (micro)frame. */
13059 + _hcd->periodic_usecs -= _qh->usecs;
13061 + for (i = 0; i < 8; i++) {
13062 + _hcd->frame_usecs[i] += _qh->frame_usecs[i];
13063 + _qh->frame_usecs[i] = 0;
13065 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
13066 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_allocated -= _qh->usecs / _qh->interval;
13068 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
13069 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_int_reqs--;
13070 + DWC_DEBUGPL(DBG_HCD, "Descheduled intr: qh %p, usecs %d, period %d\n",
13071 + _qh, _qh->usecs, _qh->interval);
13073 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_isoc_reqs--;
13074 + DWC_DEBUGPL(DBG_HCD, "Descheduled isoc: qh %p, usecs %d, period %d\n",
13075 + _qh, _qh->usecs, _qh->interval);
13080 + * Removes a QH from either the non-periodic or periodic schedule. Memory is
13083 + * @param[in] _hcd The HCD state structure.
13084 + * @param[in] _qh QH to remove from schedule. */
13085 +void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
13087 + unsigned long flags;
13089 + local_irq_save(flags);
13091 + if (list_empty(&_qh->qh_list_entry)) {
13092 + /* QH is not in a schedule. */
13096 + if (dwc_qh_is_non_per(_qh)) {
13097 + if (_hcd->non_periodic_qh_ptr == &_qh->qh_list_entry) {
13098 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
13100 + list_del_init(&_qh->qh_list_entry);
13102 + deschedule_periodic(_hcd, _qh);
13106 + local_irq_restore(flags);
13110 + * Defers a QH. For non-periodic QHs, removes the QH from the active
13111 + * non-periodic schedule. The QH is added to the deferred non-periodic
13112 + * schedule if any QTDs are still attached to the QH.
13114 +int dwc_otg_hcd_qh_deferr(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh, int delay)
13117 + unsigned long flags;
13118 + local_irq_save(flags);
13119 + if (dwc_qh_is_non_per(_qh)) {
13120 + _qh->sched_frame =
13121 + dwc_frame_num_inc(_hcd->frame_number,
13123 + _qh->channel = NULL;
13124 + _qh->qtd_in_process = NULL;
13126 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13127 + if (!list_empty(&_qh->qtd_list)) {
13128 + /* Add back to deferred non-periodic schedule. */
13129 + dwc_otg_hcd_qh_add_deferred(_hcd, _qh);
13132 + local_irq_restore(flags);
13137 + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
13138 + * non-periodic schedule. The QH is added to the inactive non-periodic
13139 + * schedule if any QTDs are still attached to the QH.
13141 + * For periodic QHs, the QH is removed from the periodic queued schedule. If
13142 + * there are any QTDs still attached to the QH, the QH is added to either the
13143 + * periodic inactive schedule or the periodic ready schedule and its next
13144 + * scheduled frame is calculated. The QH is placed in the ready schedule if
13145 + * the scheduled frame has been reached already. Otherwise it's placed in the
13146 + * inactive schedule. If there are no QTDs attached to the QH, the QH is
13147 + * completely removed from the periodic schedule.
13149 +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int sched_next_periodic_split)
13151 + unsigned long flags;
13152 + local_irq_save(flags);
13154 + if (dwc_qh_is_non_per(_qh)) {
13155 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13156 + if (!list_empty(&_qh->qtd_list)) {
13157 + /* Add back to inactive non-periodic schedule. */
13158 + dwc_otg_hcd_qh_add(_hcd, _qh);
13161 + uint16_t frame_number = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
13163 + if (_qh->do_split) {
13164 + /* Schedule the next continuing periodic split transfer */
13165 + if (sched_next_periodic_split) {
13167 + _qh->sched_frame = frame_number;
13168 + if (dwc_frame_num_le(frame_number,
13169 + dwc_frame_num_inc(_qh->start_split_frame, 1))) {
13171 + * Allow one frame to elapse after start
13172 + * split microframe before scheduling
13173 + * complete split, but DONT if we are
13174 + * doing the next start split in the
13175 + * same frame for an ISOC out.
13177 + if ((_qh->ep_type != USB_ENDPOINT_XFER_ISOC) || (_qh->ep_is_in != 0)) {
13178 + _qh->sched_frame = dwc_frame_num_inc(_qh->sched_frame, 1);
13182 + _qh->sched_frame = dwc_frame_num_inc(_qh->start_split_frame,
13184 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13185 + _qh->sched_frame = frame_number;
13187 + _qh->sched_frame |= 0x7;
13188 + _qh->start_split_frame = _qh->sched_frame;
13191 + _qh->sched_frame = dwc_frame_num_inc(_qh->sched_frame, _qh->interval);
13192 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13193 + _qh->sched_frame = frame_number;
13197 + if (list_empty(&_qh->qtd_list)) {
13198 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13201 + * Remove from periodic_sched_queued and move to
13202 + * appropriate queue.
13204 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13205 + list_move(&_qh->qh_list_entry,
13206 + &_hcd->periodic_sched_ready);
13208 + list_move(&_qh->qh_list_entry,
13209 + &_hcd->periodic_sched_inactive);
13214 + local_irq_restore(flags);
13218 + * This function allocates and initializes a QTD.
13220 + * @param[in] _urb The URB to create a QTD from. Each URB-QTD pair will end up
13221 + * pointing to each other so each pair should have a unique correlation.
13223 + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
13224 +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *_urb)
13226 + dwc_otg_qtd_t *qtd;
13228 + qtd = dwc_otg_hcd_qtd_alloc ();
13229 + if (qtd == NULL) {
13233 + dwc_otg_hcd_qtd_init (qtd, _urb);
13238 + * Initializes a QTD structure.
13240 + * @param[in] _qtd The QTD to initialize.
13241 + * @param[in] _urb The URB to use for initialization. */
13242 +void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *_qtd, struct urb *_urb)
13244 + memset (_qtd, 0, sizeof (dwc_otg_qtd_t));
13245 + _qtd->urb = _urb;
13246 + if (usb_pipecontrol(_urb->pipe)) {
13248 + * The only time the QTD data toggle is used is on the data
13249 + * phase of control transfers. This phase always starts with
13252 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
13253 + _qtd->control_phase = DWC_OTG_CONTROL_SETUP;
13256 + /* start split */
13257 + _qtd->complete_split = 0;
13258 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
13259 + _qtd->isoc_split_offset = 0;
13261 + /* Store the qtd ptr in the urb to reference what QTD. */
13262 + _urb->hcpriv = _qtd;
13267 + * This function adds a QTD to the QTD-list of a QH. It will find the correct
13268 + * QH to place the QTD into. If it does not find a QH, then it will create a
13269 + * new QH. If the QH to which the QTD is added is not currently scheduled, it
13270 + * is placed into the proper schedule based on its EP type.
13272 + * @param[in] _qtd The QTD to add
13273 + * @param[in] _dwc_otg_hcd The DWC HCD structure
13275 + * @return 0 if successful, negative error code otherwise.
13277 +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * _qtd, dwc_otg_hcd_t * _dwc_otg_hcd)
13279 + struct usb_host_endpoint *ep;
13280 + dwc_otg_qh_t *qh;
13281 + unsigned long flags;
13283 + struct urb *urb = _qtd->urb;
13285 + local_irq_save(flags);
13288 + * Get the QH which holds the QTD-list to insert to. Create QH if it
13291 + ep = dwc_urb_to_endpoint(urb);
13292 + qh = (dwc_otg_qh_t *)ep->hcpriv;
13293 + if (qh == NULL) {
13294 + qh = dwc_otg_hcd_qh_create (_dwc_otg_hcd, urb);
13295 + if (qh == NULL) {
13302 + _qtd->qtd_qh_ptr = qh;
13303 + retval = dwc_otg_hcd_qh_add(_dwc_otg_hcd, qh);
13304 + if (retval == 0) {
13305 + list_add_tail(&_qtd->qtd_list_entry, &qh->qtd_list);
13309 + local_irq_restore(flags);
13313 +#endif /* DWC_DEVICE_ONLY */
13315 +++ b/drivers/usb/dwc_otg/dwc_otg_ifx.c
13317 +/******************************************************************************
13319 +** FILE NAME : dwc_otg_ifx.c
13320 +** PROJECT : Twinpass/Danube
13321 +** MODULES : DWC OTG USB
13323 +** DATE : 12 Auguest 2007
13324 +** AUTHOR : Sung Winder
13325 +** DESCRIPTION : Platform specific initialization.
13326 +** COPYRIGHT : Copyright (c) 2007
13327 +** Infineon Technologies AG
13328 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
13329 +** Hsin-chu City, 300 Taiwan.
13331 +** This program is free software; you can redistribute it and/or modify
13332 +** it under the terms of the GNU General Public License as published by
13333 +** the Free Software Foundation; either version 2 of the License, or
13334 +** (at your option) any later version.
13337 +** $Date $Author $Comment
13338 +** 12 Auguest 2007 Sung Winder Initiate Version
13339 +*******************************************************************************/
13340 +#include "dwc_otg_ifx.h"
13342 +#include <linux/platform_device.h>
13343 +#include <linux/kernel.h>
13344 +#include <linux/ioport.h>
13345 +#include <linux/gpio.h>
13347 +#include <asm/io.h>
13348 +//#include <asm/mach-ifxmips/ifxmips.h>
13349 +#include <lantiq_soc.h>
13351 +#define IFXMIPS_GPIO_BASE_ADDR (0xBE100B00)
13353 +#define IFXMIPS_GPIO_P0_OUT ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0010))
13354 +#define IFXMIPS_GPIO_P1_OUT ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0040))
13355 +#define IFXMIPS_GPIO_P0_IN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0014))
13356 +#define IFXMIPS_GPIO_P1_IN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0044))
13357 +#define IFXMIPS_GPIO_P0_DIR ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0018))
13358 +#define IFXMIPS_GPIO_P1_DIR ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0048))
13359 +#define IFXMIPS_GPIO_P0_ALTSEL0 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x001C))
13360 +#define IFXMIPS_GPIO_P1_ALTSEL0 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x004C))
13361 +#define IFXMIPS_GPIO_P0_ALTSEL1 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0020))
13362 +#define IFXMIPS_GPIO_P1_ALTSEL1 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0050))
13363 +#define IFXMIPS_GPIO_P0_OD ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0024))
13364 +#define IFXMIPS_GPIO_P1_OD ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0054))
13365 +#define IFXMIPS_GPIO_P0_STOFF ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0028))
13366 +#define IFXMIPS_GPIO_P1_STOFF ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0058))
13367 +#define IFXMIPS_GPIO_P0_PUDSEL ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x002C))
13368 +#define IFXMIPS_GPIO_P1_PUDSEL ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x005C))
13369 +#define IFXMIPS_GPIO_P0_PUDEN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0030))
13370 +#define IFXMIPS_GPIO_P1_PUDEN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0060))
13373 +#define writel ltq_w32
13374 +#define readl ltq_r32
13375 +void dwc_otg_power_on (void)
13378 + writel(readl(DANUBE_PMU_PWDCR) | 0x41, DANUBE_PMU_PWDCR);
13379 + // set clock gating
13380 + writel(readl(DANUBE_CGU_IFCCR) | 0x30, DANUBE_CGU_IFCCR);
13382 + writel(readl(DANUBE_PMU_PWDCR) & ~0x1, DANUBE_PMU_PWDCR);
13383 + writel(readl(DANUBE_PMU_PWDCR) & ~0x40, DANUBE_PMU_PWDCR);
13384 + writel(readl(DANUBE_PMU_PWDCR) & ~0x8000, DANUBE_PMU_PWDCR);
13386 +#if 1//defined (DWC_HOST_ONLY)
13387 + // make the hardware be a host controller (default)
13388 + //clear_bit (DANUBE_USBCFG_HDSEL_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13389 + writel(readl(DANUBE_RCU_UBSCFG) & ~(1<<DANUBE_USBCFG_HDSEL_BIT), DANUBE_RCU_UBSCFG);
13391 + //#elif defined (DWC_DEVICE_ONLY)
13392 + /* set the controller to the device mode */
13393 + // set_bit (DANUBE_USBCFG_HDSEL_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13395 +#error "For Danube/Twinpass, it should be HOST or Device Only."
13398 + // set the HC's byte-order to big-endian
13399 + //set_bit (DANUBE_USBCFG_HOST_END_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13400 + writel(readl(DANUBE_RCU_UBSCFG) | (1<<DANUBE_USBCFG_HOST_END_BIT), DANUBE_RCU_UBSCFG);
13401 + //clear_bit (DANUBE_USBCFG_SLV_END_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13402 + writel(readl(DANUBE_RCU_UBSCFG) & ~(1<<DANUBE_USBCFG_SLV_END_BIT), DANUBE_RCU_UBSCFG);
13403 + //writel(0x400, DANUBE_RCU_UBSCFG);
13405 + // PHY configurations.
13406 + writel (0x14014, (volatile unsigned long *)0xbe10103c);
13409 +int ifx_usb_hc_init(unsigned long base_addr, int irq)
13414 +void ifx_usb_hc_remove(void)
13418 +++ b/drivers/usb/dwc_otg/dwc_otg_ifx.h
13420 +/******************************************************************************
13422 +** FILE NAME : dwc_otg_ifx.h
13423 +** PROJECT : Twinpass/Danube
13424 +** MODULES : DWC OTG USB
13426 +** DATE : 12 April 2007
13427 +** AUTHOR : Sung Winder
13428 +** DESCRIPTION : Platform specific initialization.
13429 +** COPYRIGHT : Copyright (c) 2007
13430 +** Infineon Technologies AG
13431 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
13432 +** Hsin-chu City, 300 Taiwan.
13434 +** This program is free software; you can redistribute it and/or modify
13435 +** it under the terms of the GNU General Public License as published by
13436 +** the Free Software Foundation; either version 2 of the License, or
13437 +** (at your option) any later version.
13440 +** $Date $Author $Comment
13441 +** 12 April 2007 Sung Winder Initiate Version
13442 +*******************************************************************************/
13443 +#if !defined(__DWC_OTG_IFX_H__)
13444 +#define __DWC_OTG_IFX_H__
13446 +#include <linux/irq.h>
13449 +// 20070316, winder added.
13451 +#define SZ_256K 0x00040000
13454 +extern void dwc_otg_power_on (void);
13456 +/* FIXME: The current Linux-2.6 do not have these header files, but anyway, we need these. */
13457 +// #include <asm/danube/danube.h>
13458 +// #include <asm/ifx/irq.h>
13460 +/* winder, I used the Danube parameter as default. *
13461 + * We could change this through module param. */
13462 +#define IFX_USB_IOMEM_BASE 0x1e101000
13463 +#define IFX_USB_IOMEM_SIZE SZ_256K
13464 +#define IFX_USB_IRQ LTQ_USB_INT
13467 + * This function is called to set correct clock gating and power.
13468 + * For Twinpass/Danube board.
13470 +#ifndef DANUBE_RCU_BASE_ADDR
13471 +#define DANUBE_RCU_BASE_ADDR (0xBF203000)
13474 +#ifndef DANUBE_CGU
13475 +#define DANUBE_CGU (0xBF103000)
13477 +#ifndef DANUBE_CGU_IFCCR
13478 +/***CGU Interface Clock Control Register***/
13479 +#define DANUBE_CGU_IFCCR ((volatile u32*)(DANUBE_CGU+ 0x0018))
13482 +#ifndef DANUBE_PMU
13483 +#define DANUBE_PMU (KSEG1+0x1F102000)
13485 +#ifndef DANUBE_PMU_PWDCR
13486 +/* PMU Power down Control Register */
13487 +#define DANUBE_PMU_PWDCR ((volatile u32*)(DANUBE_PMU+0x001C))
13491 +#define DANUBE_RCU_UBSCFG ((volatile u32*)(DANUBE_RCU_BASE_ADDR + 0x18))
13492 +#define DANUBE_USBCFG_HDSEL_BIT 11 // 0:host, 1:device
13493 +#define DANUBE_USBCFG_HOST_END_BIT 10 // 0:little_end, 1:big_end
13494 +#define DANUBE_USBCFG_SLV_END_BIT 9 // 0:little_end, 1:big_end
13496 +extern void ltq_mask_and_ack_irq(struct irq_data *d);
13498 +static void inline mask_and_ack_ifx_irq(int x)
13500 + struct irq_data d;
13502 + ltq_mask_and_ack_irq(&d);
13504 +#endif //__DWC_OTG_IFX_H__
13506 +++ b/drivers/usb/dwc_otg/dwc_otg_plat.h
13508 +/* ==========================================================================
13509 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/platform/dwc_otg_plat.h $
13510 + * $Revision: 1.1.1.1 $
13511 + * $Date: 2009-04-17 06:15:34 $
13512 + * $Change: 510301 $
13514 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13515 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13516 + * otherwise expressly agreed to in writing between Synopsys and you.
13518 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13519 + * any End User Software License Agreement or Agreement for Licensed Product
13520 + * with Synopsys or any supplement thereto. You are permitted to use and
13521 + * redistribute this Software in source and binary forms, with or without
13522 + * modification, provided that redistributions of source code must retain this
13523 + * notice. You may not view, use, disclose, copy or distribute this file or
13524 + * any information contained herein except pursuant to this license grant from
13525 + * Synopsys. If you do not agree with this notice, including the disclaimer
13526 + * below, then you are not authorized to use the Software.
13528 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13529 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13530 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13531 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13532 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13533 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13534 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13535 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13536 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13537 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13539 + * ========================================================================== */
13541 +#if !defined(__DWC_OTG_PLAT_H__)
13542 +#define __DWC_OTG_PLAT_H__
13544 +#include <linux/types.h>
13545 +#include <linux/slab.h>
13546 +#include <linux/list.h>
13547 +#include <linux/delay.h>
13548 +#include <asm/io.h>
13553 + * This file contains the Platform Specific constants, interfaces
13554 + * (functions and macros) for Linux.
13557 +/*#if !defined(__LINUX__)
13558 +#error "The contents of this file is Linux specific!!!"
13561 +#include <lantiq_soc.h>
13562 +#define writel ltq_w32
13563 +#define readl ltq_r32
13566 + * Reads the content of a register.
13568 + * @param _reg address of register to read.
13569 + * @return contents of the register.
13573 + * <code>uint32_t dev_ctl = dwc_read_reg32(&dev_regs->dctl);</code>
13575 +static __inline__ uint32_t dwc_read_reg32( volatile uint32_t *_reg)
13577 + return readl(_reg);
13581 + * Writes a register with a 32 bit value.
13583 + * @param _reg address of register to read.
13584 + * @param _value to write to _reg.
13587 + * <code>dwc_write_reg32(&dev_regs->dctl, 0); </code>
13589 +static __inline__ void dwc_write_reg32( volatile uint32_t *_reg, const uint32_t _value)
13591 + writel( _value, _reg );
13595 + * This function modifies bit values in a register. Using the
13596 + * algorithm: (reg_contents & ~clear_mask) | set_mask.
13598 + * @param _reg address of register to read.
13599 + * @param _clear_mask bit mask to be cleared.
13600 + * @param _set_mask bit mask to be set.
13603 + * <code> // Clear the SOF Interrupt Mask bit and <br>
13604 + * // set the OTG Interrupt mask bit, leaving all others as they were.
13605 + * dwc_modify_reg32(&dev_regs->gintmsk, DWC_SOF_INT, DWC_OTG_INT);</code>
13608 + void dwc_modify_reg32( volatile uint32_t *_reg, const uint32_t _clear_mask, const uint32_t _set_mask)
13610 + writel( (readl(_reg) & ~_clear_mask) | _set_mask, _reg );
13615 + * Wrapper for the OS micro-second delay function.
13616 + * @param[in] _usecs Microseconds of delay
13618 +static __inline__ void UDELAY( const uint32_t _usecs )
13620 + udelay( _usecs );
13624 + * Wrapper for the OS milli-second delay function.
13625 + * @param[in] _msecs milliseconds of delay
13627 +static __inline__ void MDELAY( const uint32_t _msecs )
13629 + mdelay( _msecs );
13633 + * Wrapper for the Linux spin_lock. On the ARM (Integrator)
13634 + * spin_lock() is a nop.
13636 + * @param _lock Pointer to the spinlock.
13638 +static __inline__ void SPIN_LOCK( spinlock_t *_lock )
13640 + spin_lock(_lock);
13644 + * Wrapper for the Linux spin_unlock. On the ARM (Integrator)
13645 + * spin_lock() is a nop.
13647 + * @param _lock Pointer to the spinlock.
13649 +static __inline__ void SPIN_UNLOCK( spinlock_t *_lock )
13651 + spin_unlock(_lock);
13655 + * Wrapper (macro) for the Linux spin_lock_irqsave. On the ARM
13656 + * (Integrator) spin_lock() is a nop.
13658 + * @param _l Pointer to the spinlock.
13659 + * @param _f unsigned long for irq flags storage.
13661 +#define SPIN_LOCK_IRQSAVE( _l, _f ) { \
13662 + spin_lock_irqsave(_l,_f); \
13666 + * Wrapper (macro) for the Linux spin_unlock_irqrestore. On the ARM
13667 + * (Integrator) spin_lock() is a nop.
13669 + * @param _l Pointer to the spinlock.
13670 + * @param _f unsigned long for irq flags storage.
13672 +#define SPIN_UNLOCK_IRQRESTORE( _l,_f ) {\
13673 + spin_unlock_irqrestore(_l,_f); \
13678 + * Debugging support vanishes in non-debug builds.
13683 + * The Debug Level bit-mask variable.
13685 +extern uint32_t g_dbg_lvl;
13687 + * Set the Debug Level variable.
13689 +static inline uint32_t SET_DEBUG_LEVEL( const uint32_t _new )
13691 + uint32_t old = g_dbg_lvl;
13692 + g_dbg_lvl = _new;
13696 +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
13697 +#define DBG_CIL (0x2)
13698 +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
13700 +#define DBG_CILV (0x20)
13701 +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
13703 +#define DBG_PCD (0x4)
13704 +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
13706 +#define DBG_PCDV (0x40)
13707 +/** When debug level has the DBG_HCD bit set, display Host debug messages */
13708 +#define DBG_HCD (0x8)
13709 +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
13711 +#define DBG_HCDV (0x80)
13712 +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
13714 +#define DBG_HCD_URB (0x800)
13716 +/** When debug level has any bit set, display debug messages */
13717 +#define DBG_ANY (0xFF)
13719 +/** All debug messages off */
13722 +/** Prefix string for DWC_DEBUG print macros. */
13723 +#define USB_DWC "DWC_otg: "
13726 + * Print a debug message when the Global debug level variable contains
13727 + * the bit defined in <code>lvl</code>.
13729 + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
13730 + * @param[in] x - like printf
13734 + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
13737 + * results in:<br>
13739 + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
13744 +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)printk( KERN_DEBUG USB_DWC x ); }while(0)
13745 +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
13747 +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
13751 +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
13752 +# define DWC_DEBUGP(x...)
13754 +# define CHK_DEBUG_LEVEL(level) (0)
13759 + * Print an Error message.
13761 +#define DWC_ERROR(x...) printk( KERN_ERR USB_DWC x )
13763 + * Print a Warning message.
13765 +#define DWC_WARN(x...) printk( KERN_WARNING USB_DWC x )
13767 + * Print a notice (normal but significant message).
13769 +#define DWC_NOTICE(x...) printk( KERN_NOTICE USB_DWC x )
13771 + * Basic message printing.
13773 +#define DWC_PRINT(x...) printk( KERN_INFO USB_DWC x )
13778 +++ b/drivers/usb/dwc_otg/dwc_otg_regs.h
13780 +/* ==========================================================================
13781 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_regs.h $
13782 + * $Revision: 1.1.1.1 $
13783 + * $Date: 2009-04-17 06:15:34 $
13784 + * $Change: 631780 $
13786 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13787 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13788 + * otherwise expressly agreed to in writing between Synopsys and you.
13790 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13791 + * any End User Software License Agreement or Agreement for Licensed Product
13792 + * with Synopsys or any supplement thereto. You are permitted to use and
13793 + * redistribute this Software in source and binary forms, with or without
13794 + * modification, provided that redistributions of source code must retain this
13795 + * notice. You may not view, use, disclose, copy or distribute this file or
13796 + * any information contained herein except pursuant to this license grant from
13797 + * Synopsys. If you do not agree with this notice, including the disclaimer
13798 + * below, then you are not authorized to use the Software.
13800 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13801 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13802 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13803 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13804 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13805 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13806 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13807 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13808 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13809 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13811 + * ========================================================================== */
13813 +#ifndef __DWC_OTG_REGS_H__
13814 +#define __DWC_OTG_REGS_H__
13819 + * This file contains the data structures for accessing the DWC_otg core registers.
13821 + * The application interfaces with the HS OTG core by reading from and
13822 + * writing to the Control and Status Register (CSR) space through the
13823 + * AHB Slave interface. These registers are 32 bits wide, and the
13824 + * addresses are 32-bit-block aligned.
13825 + * CSRs are classified as follows:
13826 + * - Core Global Registers
13827 + * - Device Mode Registers
13828 + * - Device Global Registers
13829 + * - Device Endpoint Specific Registers
13830 + * - Host Mode Registers
13831 + * - Host Global Registers
13832 + * - Host Port CSRs
13833 + * - Host Channel Specific Registers
13835 + * Only the Core Global registers can be accessed in both Device and
13836 + * Host modes. When the HS OTG core is operating in one mode, either
13837 + * Device or Host, the application must not access registers from the
13838 + * other mode. When the core switches from one mode to another, the
13839 + * registers in the new mode of operation must be reprogrammed as they
13840 + * would be after a power-on reset.
13843 +/****************************************************************************/
13844 +/** DWC_otg Core registers .
13845 + * The dwc_otg_core_global_regs structure defines the size
13846 + * and relative field offsets for the Core Global registers.
13848 +typedef struct dwc_otg_core_global_regs
13850 + /** OTG Control and Status Register. <i>Offset: 000h</i> */
13851 + volatile uint32_t gotgctl;
13852 + /** OTG Interrupt Register. <i>Offset: 004h</i> */
13853 + volatile uint32_t gotgint;
13854 + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
13855 + volatile uint32_t gahbcfg;
13856 +#define DWC_GLBINTRMASK 0x0001
13857 +#define DWC_DMAENABLE 0x0020
13858 +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
13859 +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
13860 +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
13861 +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
13864 + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
13865 + volatile uint32_t gusbcfg;
13866 + /**Core Reset Register. <i>Offset: 010h</i> */
13867 + volatile uint32_t grstctl;
13868 + /**Core Interrupt Register. <i>Offset: 014h</i> */
13869 + volatile uint32_t gintsts;
13870 + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
13871 + volatile uint32_t gintmsk;
13872 + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
13873 + volatile uint32_t grxstsr;
13874 + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
13875 + volatile uint32_t grxstsp;
13876 + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
13877 + volatile uint32_t grxfsiz;
13878 + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
13879 + volatile uint32_t gnptxfsiz;
13880 + /**Non Periodic Transmit FIFO/Queue Status Register (Read
13881 + * Only). <i>Offset: 02Ch</i> */
13882 + volatile uint32_t gnptxsts;
13883 + /**I2C Access Register. <i>Offset: 030h</i> */
13884 + volatile uint32_t gi2cctl;
13885 + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
13886 + volatile uint32_t gpvndctl;
13887 + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
13888 + volatile uint32_t ggpio;
13889 + /**User ID Register. <i>Offset: 03Ch</i> */
13890 + volatile uint32_t guid;
13891 + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
13892 + volatile uint32_t gsnpsid;
13893 + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
13894 + volatile uint32_t ghwcfg1;
13895 + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
13896 + volatile uint32_t ghwcfg2;
13897 +#define DWC_SLAVE_ONLY_ARCH 0
13898 +#define DWC_EXT_DMA_ARCH 1
13899 +#define DWC_INT_DMA_ARCH 2
13901 +#define DWC_MODE_HNP_SRP_CAPABLE 0
13902 +#define DWC_MODE_SRP_ONLY_CAPABLE 1
13903 +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
13904 +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
13905 +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
13906 +#define DWC_MODE_SRP_CAPABLE_HOST 5
13907 +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
13909 + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
13910 + volatile uint32_t ghwcfg3;
13911 + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
13912 + volatile uint32_t ghwcfg4;
13913 + /** Reserved <i>Offset: 054h-0FFh</i> */
13914 + uint32_t reserved[43];
13915 + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
13916 + volatile uint32_t hptxfsiz;
13917 + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
13918 + otherwise Device Transmit FIFO#n Register.
13919 + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
13920 + //volatile uint32_t dptxfsiz[15];
13921 + volatile uint32_t dptxfsiz_dieptxf[15];
13922 +} dwc_otg_core_global_regs_t;
13925 + * This union represents the bit fields of the Core OTG Control
13926 + * and Status Register (GOTGCTL). Set the bits using the bit
13927 + * fields then write the <i>d32</i> value to the register.
13929 +typedef union gotgctl_data
13931 + /** raw register data */
13933 + /** register bits */
13936 + unsigned reserved31_21 : 11;
13937 + unsigned currmod : 1;
13938 + unsigned bsesvld : 1;
13939 + unsigned asesvld : 1;
13940 + unsigned reserved17 : 1;
13941 + unsigned conidsts : 1;
13942 + unsigned reserved15_12 : 4;
13943 + unsigned devhnpen : 1;
13944 + unsigned hstsethnpen : 1;
13945 + unsigned hnpreq : 1;
13946 + unsigned hstnegscs : 1;
13947 + unsigned reserved7_2 : 6;
13948 + unsigned sesreq : 1;
13949 + unsigned sesreqscs : 1;
13954 + * This union represents the bit fields of the Core OTG Interrupt Register
13955 + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
13956 + * value to the register.
13958 +typedef union gotgint_data
13960 + /** raw register data */
13962 + /** register bits */
13965 + /** Current Mode */
13966 + unsigned reserved31_20 : 12;
13967 + /** Debounce Done */
13968 + unsigned debdone : 1;
13969 + /** A-Device Timeout Change */
13970 + unsigned adevtoutchng : 1;
13971 + /** Host Negotiation Detected */
13972 + unsigned hstnegdet : 1;
13973 + unsigned reserver16_10 : 7;
13974 + /** Host Negotiation Success Status Change */
13975 + unsigned hstnegsucstschng : 1;
13976 + /** Session Request Success Status Change */
13977 + unsigned sesreqsucstschng : 1;
13978 + unsigned reserved3_7 : 5;
13979 + /** Session End Detected */
13980 + unsigned sesenddet : 1;
13981 + /** Current Mode */
13982 + unsigned reserved1_0 : 2;
13988 + * This union represents the bit fields of the Core AHB Configuration
13989 + * Register (GAHBCFG). Set/clear the bits using the bit fields then
13990 + * write the <i>d32</i> value to the register.
13992 +typedef union gahbcfg_data
13994 + /** raw register data */
13996 + /** register bits */
13999 +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
14000 +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
14001 + unsigned reserved9_31 : 23;
14002 + unsigned ptxfemplvl : 1;
14003 + unsigned nptxfemplvl_txfemplvl : 1;
14004 +#define DWC_GAHBCFG_DMAENABLE 1
14005 + unsigned reserved : 1;
14006 + unsigned dmaenable : 1;
14007 +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
14008 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
14009 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
14010 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
14011 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
14012 + unsigned hburstlen : 4;
14013 + unsigned glblintrmsk : 1;
14014 +#define DWC_GAHBCFG_GLBINT_ENABLE 1
14020 + * This union represents the bit fields of the Core USB Configuration
14021 + * Register (GUSBCFG). Set the bits using the bit fields then write
14022 + * the <i>d32</i> value to the register.
14024 +typedef union gusbcfg_data
14026 + /** raw register data */
14028 + /** register bits */
14031 + unsigned corrupt_tx_packet: 1; /*fscz*/
14032 + unsigned force_device_mode: 1;
14033 + unsigned force_host_mode: 1;
14034 + unsigned reserved23_28 : 6;
14035 + unsigned term_sel_dl_pulse : 1;
14036 + unsigned ulpi_int_vbus_indicator : 1;
14037 + unsigned ulpi_ext_vbus_drv : 1;
14038 + unsigned ulpi_clk_sus_m : 1;
14039 + unsigned ulpi_auto_res : 1;
14040 + unsigned ulpi_fsls : 1;
14041 + unsigned otgutmifssel : 1;
14042 + unsigned phylpwrclksel : 1;
14043 + unsigned nptxfrwnden : 1;
14044 + unsigned usbtrdtim : 4;
14045 + unsigned hnpcap : 1;
14046 + unsigned srpcap : 1;
14047 + unsigned ddrsel : 1;
14048 + unsigned physel : 1;
14049 + unsigned fsintf : 1;
14050 + unsigned ulpi_utmi_sel : 1;
14051 + unsigned phyif : 1;
14052 + unsigned toutcal : 3;
14057 + * This union represents the bit fields of the Core Reset Register
14058 + * (GRSTCTL). Set/clear the bits using the bit fields then write the
14059 + * <i>d32</i> value to the register.
14061 +typedef union grstctl_data
14063 + /** raw register data */
14065 + /** register bits */
14068 + /** AHB Master Idle. Indicates the AHB Master State
14069 + * Machine is in IDLE condition. */
14070 + unsigned ahbidle : 1;
14071 + /** DMA Request Signal. Indicated DMA request is in
14072 + * probress. Used for debug purpose. */
14073 + unsigned dmareq : 1;
14075 + unsigned reserved29_11 : 19;
14076 + /** TxFIFO Number (TxFNum) (Device and Host).
14078 + * This is the FIFO number which needs to be flushed,
14079 + * using the TxFIFO Flush bit. This field should not
14080 + * be changed until the TxFIFO Flush bit is cleared by
14082 + * - 0x0 : Non Periodic TxFIFO Flush
14083 + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
14084 + * or Periodic TxFIFO in host mode
14085 + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
14087 + * - 0xF : Periodic TxFIFO #15 Flush in device mode
14088 + * - 0x10: Flush all the Transmit NonPeriodic and
14089 + * Transmit Periodic FIFOs in the core
14091 + unsigned txfnum : 5;
14092 + /** TxFIFO Flush (TxFFlsh) (Device and Host).
14094 + * This bit is used to selectively flush a single or
14095 + * all transmit FIFOs. The application must first
14096 + * ensure that the core is not in the middle of a
14097 + * transaction. <p>The application should write into
14098 + * this bit, only after making sure that neither the
14099 + * DMA engine is writing into the TxFIFO nor the MAC
14100 + * is reading the data out of the FIFO. <p>The
14101 + * application should wait until the core clears this
14102 + * bit, before performing any operations. This bit
14103 + * will takes 8 clocks (slowest of PHY or AHB clock)
14106 + unsigned txfflsh : 1;
14107 + /** RxFIFO Flush (RxFFlsh) (Device and Host)
14109 + * The application can flush the entire Receive FIFO
14110 + * using this bit. <p>The application must first
14111 + * ensure that the core is not in the middle of a
14112 + * transaction. <p>The application should write into
14113 + * this bit, only after making sure that neither the
14114 + * DMA engine is reading from the RxFIFO nor the MAC
14115 + * is writing the data in to the FIFO. <p>The
14116 + * application should wait until the bit is cleared
14117 + * before performing any other operations. This bit
14118 + * will takes 8 clocks (slowest of PHY or AHB clock)
14121 + unsigned rxfflsh : 1;
14122 + /** In Token Sequence Learning Queue Flush
14123 + * (INTknQFlsh) (Device Only)
14125 + unsigned intknqflsh : 1;
14126 + /** Host Frame Counter Reset (Host Only)<br>
14128 + * The application can reset the (micro)frame number
14129 + * counter inside the core, using this bit. When the
14130 + * (micro)frame counter is reset, the subsequent SOF
14131 + * sent out by the core, will have a (micro)frame
14134 + unsigned hstfrm : 1;
14135 + /** Hclk Soft Reset
14137 + * The application uses this bit to reset the control logic in
14138 + * the AHB clock domain. Only AHB clock domain pipelines are
14141 + unsigned hsftrst : 1;
14142 + /** Core Soft Reset (CSftRst) (Device and Host)
14144 + * The application can flush the control logic in the
14145 + * entire core using this bit. This bit resets the
14146 + * pipelines in the AHB Clock domain as well as the
14147 + * PHY Clock domain.
14149 + * The state machines are reset to an IDLE state, the
14150 + * control bits in the CSRs are cleared, all the
14151 + * transmit FIFOs and the receive FIFO are flushed.
14153 + * The status mask bits that control the generation of
14154 + * the interrupt, are cleared, to clear the
14155 + * interrupt. The interrupt status bits are not
14156 + * cleared, so the application can get the status of
14157 + * any events that occurred in the core after it has
14160 + * Any transactions on the AHB are terminated as soon
14161 + * as possible following the protocol. Any
14162 + * transactions on the USB are terminated immediately.
14164 + * The configuration settings in the CSRs are
14165 + * unchanged, so the software doesn't have to
14166 + * reprogram these registers (Device
14167 + * Configuration/Host Configuration/Core System
14168 + * Configuration/Core PHY Configuration).
14170 + * The application can write to this bit, any time it
14171 + * wants to reset the core. This is a self clearing
14172 + * bit and the core clears this bit after all the
14173 + * necessary logic is reset in the core, which may
14174 + * take several clocks, depending on the current state
14177 + unsigned csftrst : 1;
14183 + * This union represents the bit fields of the Core Interrupt Mask
14184 + * Register (GINTMSK). Set/clear the bits using the bit fields then
14185 + * write the <i>d32</i> value to the register.
14187 +typedef union gintmsk_data
14189 + /** raw register data */
14191 + /** register bits */
14194 + unsigned wkupintr : 1;
14195 + unsigned sessreqintr : 1;
14196 + unsigned disconnect : 1;
14197 + unsigned conidstschng : 1;
14198 + unsigned reserved27 : 1;
14199 + unsigned ptxfempty : 1;
14200 + unsigned hcintr : 1;
14201 + unsigned portintr : 1;
14202 + unsigned reserved22_23 : 2;
14203 + unsigned incomplisoout : 1;
14204 + unsigned incomplisoin : 1;
14205 + unsigned outepintr : 1;
14206 + unsigned inepintr : 1;
14207 + unsigned epmismatch : 1;
14208 + unsigned reserved16 : 1;
14209 + unsigned eopframe : 1;
14210 + unsigned isooutdrop : 1;
14211 + unsigned enumdone : 1;
14212 + unsigned usbreset : 1;
14213 + unsigned usbsuspend : 1;
14214 + unsigned erlysuspend : 1;
14215 + unsigned i2cintr : 1;
14216 + unsigned reserved8 : 1;
14217 + unsigned goutnakeff : 1;
14218 + unsigned ginnakeff : 1;
14219 + unsigned nptxfempty : 1;
14220 + unsigned rxstsqlvl : 1;
14221 + unsigned sofintr : 1;
14222 + unsigned otgintr : 1;
14223 + unsigned modemismatch : 1;
14224 + unsigned reserved0 : 1;
14228 + * This union represents the bit fields of the Core Interrupt Register
14229 + * (GINTSTS). Set/clear the bits using the bit fields then write the
14230 + * <i>d32</i> value to the register.
14232 +typedef union gintsts_data
14234 + /** raw register data */
14236 +#define DWC_SOF_INTR_MASK 0x0008
14237 + /** register bits */
14240 +#define DWC_HOST_MODE 1
14241 + unsigned wkupintr : 1;
14242 + unsigned sessreqintr : 1;
14243 + unsigned disconnect : 1;
14244 + unsigned conidstschng : 1;
14245 + unsigned reserved27 : 1;
14246 + unsigned ptxfempty : 1;
14247 + unsigned hcintr : 1;
14248 + unsigned portintr : 1;
14249 + unsigned reserved22_23 : 2;
14250 + unsigned incomplisoout : 1;
14251 + unsigned incomplisoin : 1;
14252 + unsigned outepintr : 1;
14253 + unsigned inepint: 1;
14254 + unsigned epmismatch : 1;
14255 + unsigned intokenrx : 1;
14256 + unsigned eopframe : 1;
14257 + unsigned isooutdrop : 1;
14258 + unsigned enumdone : 1;
14259 + unsigned usbreset : 1;
14260 + unsigned usbsuspend : 1;
14261 + unsigned erlysuspend : 1;
14262 + unsigned i2cintr : 1;
14263 + unsigned reserved8 : 1;
14264 + unsigned goutnakeff : 1;
14265 + unsigned ginnakeff : 1;
14266 + unsigned nptxfempty : 1;
14267 + unsigned rxstsqlvl : 1;
14268 + unsigned sofintr : 1;
14269 + unsigned otgintr : 1;
14270 + unsigned modemismatch : 1;
14271 + unsigned curmode : 1;
14277 + * This union represents the bit fields in the Device Receive Status Read and
14278 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
14279 + * element then read out the bits using the <i>b</i>it elements.
14281 +typedef union device_grxsts_data {
14282 + /** raw register data */
14284 + /** register bits */
14286 + unsigned reserved : 7;
14288 +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
14289 +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
14291 +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
14292 +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
14293 +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
14294 + unsigned pktsts : 4;
14295 + unsigned dpid : 2;
14296 + unsigned bcnt : 11;
14297 + unsigned epnum : 4;
14299 +} device_grxsts_data_t;
14302 + * This union represents the bit fields in the Host Receive Status Read and
14303 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
14304 + * element then read out the bits using the <i>b</i>it elements.
14306 +typedef union host_grxsts_data {
14307 + /** raw register data */
14309 + /** register bits */
14311 + unsigned reserved31_21 : 11;
14312 +#define DWC_GRXSTS_PKTSTS_IN 0x2
14313 +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
14314 +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
14315 +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
14316 + unsigned pktsts : 4;
14317 + unsigned dpid : 2;
14318 + unsigned bcnt : 11;
14319 + unsigned chnum : 4;
14321 +} host_grxsts_data_t;
14324 + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
14325 + * GNPTXFSIZ, DPTXFSIZn). Read the register into the <i>d32</i> element then
14326 + * read out the bits using the <i>b</i>it elements.
14328 +typedef union fifosize_data {
14329 + /** raw register data */
14331 + /** register bits */
14333 + unsigned depth : 16;
14334 + unsigned startaddr : 16;
14336 +} fifosize_data_t;
14339 + * This union represents the bit fields in the Non-Periodic Transmit
14340 + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
14341 + * <i>d32</i> element then read out the bits using the <i>b</i>it
14344 +typedef union gnptxsts_data {
14345 + /** raw register data */
14347 + /** register bits */
14349 + unsigned reserved : 1;
14350 + /** Top of the Non-Periodic Transmit Request Queue
14351 + * - bits 30:27 - Channel/EP Number
14352 + * - bits 26:25 - Token Type
14353 + * - bit 24 - Terminate (Last entry for the selected
14355 + * - 2'b00 - IN/OUT
14356 + * - 2'b01 - Zero Length OUT
14357 + * - 2'b10 - PING/Complete Split
14358 + * - 2'b11 - Channel Halt
14361 + unsigned nptxqtop_chnep : 4;
14362 + unsigned nptxqtop_token : 2;
14363 + unsigned nptxqtop_terminate : 1;
14364 + unsigned nptxqspcavail : 8;
14365 + unsigned nptxfspcavail : 16;
14367 +} gnptxsts_data_t;
14370 + * This union represents the bit fields in the Transmit
14371 + * FIFO Status Register (DTXFSTS). Read the register into the
14372 + * <i>d32</i> element then read out the bits using the <i>b</i>it
14375 +typedef union dtxfsts_data /* fscz */ //*
14377 + /** raw register data */
14379 + /** register bits */
14381 + unsigned reserved : 16;
14382 + unsigned txfspcavail : 16;
14387 + * This union represents the bit fields in the I2C Control Register
14388 + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
14389 + * bits using the <i>b</i>it elements.
14391 +typedef union gi2cctl_data {
14392 + /** raw register data */
14394 + /** register bits */
14396 + unsigned bsydne : 1;
14398 + unsigned reserved : 2;
14399 + unsigned i2cdevaddr : 2;
14400 + unsigned i2csuspctl : 1;
14401 + unsigned ack : 1;
14402 + unsigned i2cen : 1;
14403 + unsigned addr : 7;
14404 + unsigned regaddr : 8;
14405 + unsigned rwdata : 8;
14410 + * This union represents the bit fields in the User HW Config1
14411 + * Register. Read the register into the <i>d32</i> element then read
14412 + * out the bits using the <i>b</i>it elements.
14414 +typedef union hwcfg1_data {
14415 + /** raw register data */
14417 + /** register bits */
14419 + unsigned ep_dir15 : 2;
14420 + unsigned ep_dir14 : 2;
14421 + unsigned ep_dir13 : 2;
14422 + unsigned ep_dir12 : 2;
14423 + unsigned ep_dir11 : 2;
14424 + unsigned ep_dir10 : 2;
14425 + unsigned ep_dir9 : 2;
14426 + unsigned ep_dir8 : 2;
14427 + unsigned ep_dir7 : 2;
14428 + unsigned ep_dir6 : 2;
14429 + unsigned ep_dir5 : 2;
14430 + unsigned ep_dir4 : 2;
14431 + unsigned ep_dir3 : 2;
14432 + unsigned ep_dir2 : 2;
14433 + unsigned ep_dir1 : 2;
14434 + unsigned ep_dir0 : 2;
14439 + * This union represents the bit fields in the User HW Config2
14440 + * Register. Read the register into the <i>d32</i> element then read
14441 + * out the bits using the <i>b</i>it elements.
14443 +typedef union hwcfg2_data
14445 + /** raw register data */
14447 + /** register bits */
14450 + unsigned reserved31 : 1;
14451 + unsigned dev_token_q_depth : 5;
14452 + unsigned host_perio_tx_q_depth : 2;
14453 + unsigned nonperio_tx_q_depth : 2;
14454 + unsigned rx_status_q_depth : 2;
14455 + unsigned dynamic_fifo : 1;
14456 + unsigned perio_ep_supported : 1;
14457 + unsigned num_host_chan : 4;
14458 + unsigned num_dev_ep : 4;
14459 + unsigned fs_phy_type : 2;
14460 +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
14461 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
14462 +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
14463 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
14464 + unsigned hs_phy_type : 2;
14465 + unsigned point2point : 1;
14466 + unsigned architecture : 2;
14467 +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
14468 +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
14469 +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
14470 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
14471 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
14472 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
14473 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
14474 + unsigned op_mode : 3;
14479 + * This union represents the bit fields in the User HW Config3
14480 + * Register. Read the register into the <i>d32</i> element then read
14481 + * out the bits using the <i>b</i>it elements.
14483 +typedef union hwcfg3_data
14485 + /** raw register data */
14487 + /** register bits */
14490 + unsigned dfifo_depth : 16;
14491 + unsigned reserved15_13 : 3;
14492 + unsigned ahb_phy_clock_synch : 1;
14493 + unsigned synch_reset_type : 1;
14494 + unsigned optional_features : 1;
14495 + unsigned vendor_ctrl_if : 1;
14496 + unsigned i2c : 1;
14497 + unsigned otg_func : 1;
14498 + unsigned packet_size_cntr_width : 3;
14499 + unsigned xfer_size_cntr_width : 4;
14504 + * This union represents the bit fields in the User HW Config4
14505 + * Register. Read the register into the <i>d32</i> element then read
14506 + * out the bits using the <i>b</i>it elements.
14508 +typedef union hwcfg4_data
14510 + /** raw register data */
14512 + /** register bits */
14514 +unsigned reserved31_30 : 2; /* fscz */
14515 + unsigned num_in_eps : 4;
14516 + unsigned ded_fifo_en : 1;
14518 + unsigned session_end_filt_en : 1;
14519 + unsigned b_valid_filt_en : 1;
14520 + unsigned a_valid_filt_en : 1;
14521 + unsigned vbus_valid_filt_en : 1;
14522 + unsigned iddig_filt_en : 1;
14523 + unsigned num_dev_mode_ctrl_ep : 4;
14524 + unsigned utmi_phy_data_width : 2;
14525 + unsigned min_ahb_freq : 9;
14526 + unsigned power_optimiz : 1;
14527 + unsigned num_dev_perio_in_ep : 4;
14531 +////////////////////////////////////////////
14532 +// Device Registers
14534 + * Device Global Registers. <i>Offsets 800h-BFFh</i>
14536 + * The following structures define the size and relative field offsets
14537 + * for the Device Mode Registers.
14539 + * <i>These registers are visible only in Device mode and must not be
14540 + * accessed in Host mode, as the results are unknown.</i>
14542 +typedef struct dwc_otg_dev_global_regs
14544 + /** Device Configuration Register. <i>Offset 800h</i> */
14545 + volatile uint32_t dcfg;
14546 + /** Device Control Register. <i>Offset: 804h</i> */
14547 + volatile uint32_t dctl;
14548 + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
14549 + volatile uint32_t dsts;
14550 + /** Reserved. <i>Offset: 80Ch</i> */
14552 + /** Device IN Endpoint Common Interrupt Mask
14553 + * Register. <i>Offset: 810h</i> */
14554 + volatile uint32_t diepmsk;
14555 + /** Device OUT Endpoint Common Interrupt Mask
14556 + * Register. <i>Offset: 814h</i> */
14557 + volatile uint32_t doepmsk;
14558 + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
14559 + volatile uint32_t daint;
14560 + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
14562 + volatile uint32_t daintmsk;
14563 + /** Device IN Token Queue Read Register-1 (Read Only).
14564 + * <i>Offset: 820h</i> */
14565 + volatile uint32_t dtknqr1;
14566 + /** Device IN Token Queue Read Register-2 (Read Only).
14567 + * <i>Offset: 824h</i> */
14568 + volatile uint32_t dtknqr2;
14569 + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
14570 + volatile uint32_t dvbusdis;
14571 + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
14572 + volatile uint32_t dvbuspulse;
14573 + /** Device IN Token Queue Read Register-3 (Read Only).
14574 + * Device Thresholding control register (Read/Write)
14575 + * <i>Offset: 830h</i> */
14576 + volatile uint32_t dtknqr3_dthrctl;
14577 + /** Device IN Token Queue Read Register-4 (Read Only). /
14578 + * Device IN EPs empty Inr. Mask Register (Read/Write)
14579 + * <i>Offset: 834h</i> */
14580 + volatile uint32_t dtknqr4_fifoemptymsk;
14581 +} dwc_otg_device_global_regs_t;
14584 + * This union represents the bit fields in the Device Configuration
14585 + * Register. Read the register into the <i>d32</i> member then
14586 + * set/clear the bits using the <i>b</i>it elements. Write the
14587 + * <i>d32</i> member to the dcfg register.
14589 +typedef union dcfg_data
14591 + /** raw register data */
14593 + /** register bits */
14595 + unsigned reserved31_23 : 9;
14596 + /** In Endpoint Mis-match count */
14597 + unsigned epmscnt : 5;
14598 + unsigned reserved13_17 : 5;
14599 + /** Periodic Frame Interval */
14600 +#define DWC_DCFG_FRAME_INTERVAL_80 0
14601 +#define DWC_DCFG_FRAME_INTERVAL_85 1
14602 +#define DWC_DCFG_FRAME_INTERVAL_90 2
14603 +#define DWC_DCFG_FRAME_INTERVAL_95 3
14604 + unsigned perfrint : 2;
14605 + /** Device Addresses */
14606 + unsigned devaddr : 7;
14607 + unsigned reserved3 : 1;
14608 + /** Non Zero Length Status OUT Handshake */
14609 +#define DWC_DCFG_SEND_STALL 1
14610 + unsigned nzstsouthshk : 1;
14611 + /** Device Speed */
14612 + unsigned devspd : 2;
14617 + * This union represents the bit fields in the Device Control
14618 + * Register. Read the register into the <i>d32</i> member then
14619 + * set/clear the bits using the <i>b</i>it elements.
14621 +typedef union dctl_data
14623 + /** raw register data */
14625 + /** register bits */
14627 + unsigned reserved : 20;
14628 + /** Power-On Programming Done */
14629 + unsigned pwronprgdone : 1;
14630 + /** Clear Global OUT NAK */
14631 + unsigned cgoutnak : 1;
14632 + /** Set Global OUT NAK */
14633 + unsigned sgoutnak : 1;
14634 + /** Clear Global Non-Periodic IN NAK */
14635 + unsigned cgnpinnak : 1;
14636 + /** Set Global Non-Periodic IN NAK */
14637 + unsigned sgnpinnak : 1;
14638 + /** Test Control */
14639 + unsigned tstctl : 3;
14640 + /** Global OUT NAK Status */
14641 + unsigned goutnaksts : 1;
14642 + /** Global Non-Periodic IN NAK Status */
14643 + unsigned gnpinnaksts : 1;
14644 + /** Soft Disconnect */
14645 + unsigned sftdiscon : 1;
14646 + /** Remote Wakeup */
14647 + unsigned rmtwkupsig : 1;
14652 + * This union represents the bit fields in the Device Status
14653 + * Register. Read the register into the <i>d32</i> member then
14654 + * set/clear the bits using the <i>b</i>it elements.
14656 +typedef union dsts_data
14658 + /** raw register data */
14660 + /** register bits */
14662 + unsigned reserved22_31 : 10;
14663 + /** Frame or Microframe Number of the received SOF */
14664 + unsigned soffn : 14;
14665 + unsigned reserved4_7: 4;
14666 + /** Erratic Error */
14667 + unsigned errticerr : 1;
14668 + /** Enumerated Speed */
14669 +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
14670 +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
14671 +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
14672 +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
14673 + unsigned enumspd : 2;
14674 + /** Suspend Status */
14675 + unsigned suspsts : 1;
14681 + * This union represents the bit fields in the Device IN EP Interrupt
14682 + * Register and the Device IN EP Common Mask Register.
14684 + * - Read the register into the <i>d32</i> member then set/clear the
14685 + * bits using the <i>b</i>it elements.
14687 +typedef union diepint_data
14689 + /** raw register data */
14691 + /** register bits */
14693 + unsigned reserved07_31 : 23;
14694 + unsigned txfifoundrn : 1;
14695 + /** IN Endpoint HAK Effective mask */
14696 + unsigned emptyintr : 1;
14697 + /** IN Endpoint NAK Effective mask */
14698 + unsigned inepnakeff : 1;
14699 + /** IN Token Received with EP mismatch mask */
14700 + unsigned intknepmis : 1;
14701 + /** IN Token received with TxF Empty mask */
14702 + unsigned intktxfemp : 1;
14703 + /** TimeOUT Handshake mask (non-ISOC EPs) */
14704 + unsigned timeout : 1;
14705 + /** AHB Error mask */
14706 + unsigned ahberr : 1;
14707 + /** Endpoint disable mask */
14708 + unsigned epdisabled : 1;
14709 + /** Transfer complete mask */
14710 + unsigned xfercompl : 1;
14714 + * This union represents the bit fields in the Device IN EP Common
14715 + * Interrupt Mask Register.
14717 +typedef union diepint_data diepmsk_data_t;
14720 + * This union represents the bit fields in the Device OUT EP Interrupt
14721 + * Registerand Device OUT EP Common Interrupt Mask Register.
14723 + * - Read the register into the <i>d32</i> member then set/clear the
14724 + * bits using the <i>b</i>it elements.
14726 +typedef union doepint_data
14728 + /** raw register data */
14730 + /** register bits */
14732 + unsigned reserved04_31 : 27;
14733 + /** OUT Token Received when Endpoint Disabled */
14734 + unsigned outtknepdis : 1;
14735 + /** Setup Phase Done (contorl EPs) */
14736 + unsigned setup : 1;
14738 + unsigned ahberr : 1;
14739 + /** Endpoint disable */
14740 + unsigned epdisabled : 1;
14741 + /** Transfer complete */
14742 + unsigned xfercompl : 1;
14746 + * This union represents the bit fields in the Device OUT EP Common
14747 + * Interrupt Mask Register.
14749 +typedef union doepint_data doepmsk_data_t;
14753 + * This union represents the bit fields in the Device All EP Interrupt
14754 + * and Mask Registers.
14755 + * - Read the register into the <i>d32</i> member then set/clear the
14756 + * bits using the <i>b</i>it elements.
14758 +typedef union daint_data
14760 + /** raw register data */
14762 + /** register bits */
14764 + /** OUT Endpoint bits */
14765 + unsigned out : 16;
14766 + /** IN Endpoint bits */
14767 + unsigned in : 16;
14770 + /** OUT Endpoint bits */
14771 + unsigned outep15 : 1;
14772 + unsigned outep14 : 1;
14773 + unsigned outep13 : 1;
14774 + unsigned outep12 : 1;
14775 + unsigned outep11 : 1;
14776 + unsigned outep10 : 1;
14777 + unsigned outep9 : 1;
14778 + unsigned outep8 : 1;
14779 + unsigned outep7 : 1;
14780 + unsigned outep6 : 1;
14781 + unsigned outep5 : 1;
14782 + unsigned outep4 : 1;
14783 + unsigned outep3 : 1;
14784 + unsigned outep2 : 1;
14785 + unsigned outep1 : 1;
14786 + unsigned outep0 : 1;
14787 + /** IN Endpoint bits */
14788 + unsigned inep15 : 1;
14789 + unsigned inep14 : 1;
14790 + unsigned inep13 : 1;
14791 + unsigned inep12 : 1;
14792 + unsigned inep11 : 1;
14793 + unsigned inep10 : 1;
14794 + unsigned inep9 : 1;
14795 + unsigned inep8 : 1;
14796 + unsigned inep7 : 1;
14797 + unsigned inep6 : 1;
14798 + unsigned inep5 : 1;
14799 + unsigned inep4 : 1;
14800 + unsigned inep3 : 1;
14801 + unsigned inep2 : 1;
14802 + unsigned inep1 : 1;
14803 + unsigned inep0 : 1;
14808 + * This union represents the bit fields in the Device IN Token Queue
14809 + * Read Registers.
14810 + * - Read the register into the <i>d32</i> member.
14811 + * - READ-ONLY Register
14813 +typedef union dtknq1_data
14815 + /** raw register data */
14817 + /** register bits */
14819 + /** EP Numbers of IN Tokens 0 ... 4 */
14820 + unsigned epnums0_5 : 24;
14821 + /** write pointer has wrapped. */
14822 + unsigned wrap_bit : 1;
14824 + unsigned reserved05_06 : 2;
14825 + /** In Token Queue Write Pointer */
14826 + unsigned intknwptr : 5;
14831 + * This union represents Threshold control Register
14832 + * - Read and write the register into the <i>d32</i> member.
14833 + * - READ-WRITABLE Register
14835 +typedef union dthrctl_data //* /*fscz */
14837 + /** raw register data */
14839 + /** register bits */
14842 + unsigned reserved26_31 : 6;
14843 + /** Rx Thr. Length */
14844 + unsigned rx_thr_len : 9;
14845 + /** Rx Thr. Enable */
14846 + unsigned rx_thr_en : 1;
14848 + unsigned reserved11_15 : 5;
14849 + /** Tx Thr. Length */
14850 + unsigned tx_thr_len : 9;
14851 + /** ISO Tx Thr. Enable */
14852 + unsigned iso_thr_en : 1;
14853 + /** non ISO Tx Thr. Enable */
14854 + unsigned non_iso_thr_en : 1;
14860 + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
14863 + * There will be one set of endpoint registers per logical endpoint
14866 + * <i>These registers are visible only in Device mode and must not be
14867 + * accessed in Host mode, as the results are unknown.</i>
14869 +typedef struct dwc_otg_dev_in_ep_regs
14871 + /** Device IN Endpoint Control Register. <i>Offset:900h +
14872 + * (ep_num * 20h) + 00h</i> */
14873 + volatile uint32_t diepctl;
14874 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
14875 + uint32_t reserved04;
14876 + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
14877 + * (ep_num * 20h) + 08h</i> */
14878 + volatile uint32_t diepint;
14879 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
14880 + uint32_t reserved0C;
14881 + /** Device IN Endpoint Transfer Size
14882 + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
14883 + volatile uint32_t dieptsiz;
14884 + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
14885 + * (ep_num * 20h) + 14h</i> */
14886 + volatile uint32_t diepdma;
14887 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 18h - 900h +
14888 + * (ep_num * 20h) + 1Ch</i>*/
14889 + volatile uint32_t dtxfsts;
14890 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 1Ch - 900h +
14891 + * (ep_num * 20h) + 1Ch</i>*/
14892 + uint32_t reserved18;
14893 +} dwc_otg_dev_in_ep_regs_t;
14896 + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
14899 + * There will be one set of endpoint registers per logical endpoint
14902 + * <i>These registers are visible only in Device mode and must not be
14903 + * accessed in Host mode, as the results are unknown.</i>
14905 +typedef struct dwc_otg_dev_out_ep_regs
14907 + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
14908 + * (ep_num * 20h) + 00h</i> */
14909 + volatile uint32_t doepctl;
14910 + /** Device OUT Endpoint Frame number Register. <i>Offset:
14911 + * B00h + (ep_num * 20h) + 04h</i> */
14912 + volatile uint32_t doepfn;
14913 + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
14914 + * (ep_num * 20h) + 08h</i> */
14915 + volatile uint32_t doepint;
14916 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
14917 + uint32_t reserved0C;
14918 + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
14919 + * B00h + (ep_num * 20h) + 10h</i> */
14920 + volatile uint32_t doeptsiz;
14921 + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
14922 + * + (ep_num * 20h) + 14h</i> */
14923 + volatile uint32_t doepdma;
14924 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 18h - B00h +
14925 + * (ep_num * 20h) + 1Ch</i> */
14926 + uint32_t unused[2];
14927 +} dwc_otg_dev_out_ep_regs_t;
14930 + * This union represents the bit fields in the Device EP Control
14931 + * Register. Read the register into the <i>d32</i> member then
14932 + * set/clear the bits using the <i>b</i>it elements.
14934 +typedef union depctl_data
14936 + /** raw register data */
14938 + /** register bits */
14940 + /** Endpoint Enable */
14941 + unsigned epena : 1;
14942 + /** Endpoint Disable */
14943 + unsigned epdis : 1;
14944 + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
14945 + * Writing to this field sets the Endpoint DPID (DPID)
14946 + * field in this register to DATA1 Set Odd
14947 + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
14948 + * Writing to this field sets the Even/Odd
14949 + * (micro)frame (EO_FrNum) field to odd (micro) frame.
14951 + unsigned setd1pid : 1;
14952 + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
14953 + * Writing to this field sets the Endpoint DPID (DPID)
14954 + * field in this register to DATA0. Set Even
14955 + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
14956 + * Writing to this field sets the Even/Odd
14957 + * (micro)frame (EO_FrNum) field to even (micro)
14960 + unsigned setd0pid : 1;
14962 + unsigned snak : 1;
14964 + unsigned cnak : 1;
14965 + /** Tx Fifo Number
14967 + * OUT EPn/OUT EP0 - reserved */
14968 + unsigned txfnum : 4;
14969 + /** Stall Handshake */
14970 + unsigned stall : 1;
14972 + * OUT EPn/OUT EP0
14973 + * IN EPn/IN EP0 - reserved */
14974 + unsigned snp : 1;
14975 + /** Endpoint Type
14977 + * 2'b01: Isochronous
14979 + * 2'b11: Interrupt */
14980 + unsigned eptype : 2;
14981 + /** NAK Status */
14982 + unsigned naksts : 1;
14983 + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
14984 + * This field contains the PID of the packet going to
14985 + * be received or transmitted on this endpoint. The
14986 + * application should program the PID of the first
14987 + * packet going to be received or transmitted on this
14988 + * endpoint , after the endpoint is
14989 + * activated. Application use the SetD1PID and
14990 + * SetD0PID fields of this register to program either
14993 + * The encoding for this field is
14997 + unsigned dpid : 1;
14998 + /** USB Active Endpoint */
14999 + unsigned usbactep : 1;
15000 + /** Next Endpoint
15002 + * OUT EPn/OUT EP0 - reserved */
15003 + unsigned nextep : 4;
15004 + /** Maximum Packet Size
15006 + * IN/OUT EP0 - 2 bits
15007 + * 2'b00: 64 Bytes
15011 +#define DWC_DEP0CTL_MPS_64 0
15012 +#define DWC_DEP0CTL_MPS_32 1
15013 +#define DWC_DEP0CTL_MPS_16 2
15014 +#define DWC_DEP0CTL_MPS_8 3
15015 + unsigned mps : 11;
15020 + * This union represents the bit fields in the Device EP Transfer
15021 + * Size Register. Read the register into the <i>d32</i> member then
15022 + * set/clear the bits using the <i>b</i>it elements.
15024 +typedef union deptsiz_data
15026 + /** raw register data */
15028 + /** register bits */
15030 + unsigned reserved : 1;
15031 + /** Multi Count - Periodic IN endpoints */
15033 + /** Packet Count */
15034 + unsigned pktcnt : 10;
15035 + /** Transfer size */
15036 + unsigned xfersize : 19;
15041 + * This union represents the bit fields in the Device EP 0 Transfer
15042 + * Size Register. Read the register into the <i>d32</i> member then
15043 + * set/clear the bits using the <i>b</i>it elements.
15045 +typedef union deptsiz0_data
15047 + /** raw register data */
15049 + /** register bits */
15051 + unsigned reserved31 : 1;
15052 + /**Setup Packet Count (DOEPTSIZ0 Only) */
15053 + unsigned supcnt : 2;
15055 + unsigned reserved28_20 : 9;
15056 + /** Packet Count */
15057 + unsigned pktcnt : 1;
15059 + unsigned reserved18_7 : 12;
15060 + /** Transfer size */
15061 + unsigned xfersize : 7;
15063 +} deptsiz0_data_t;
15066 +/** Maximum number of Periodic FIFOs */
15067 +#define MAX_PERIO_FIFOS 15
15068 +/** Maximum number of TX FIFOs */
15069 +#define MAX_TX_FIFOS 15
15070 +/** Maximum number of Endpoints/HostChannels */
15071 +#define MAX_EPS_CHANNELS 16
15072 +//#define MAX_EPS_CHANNELS 4
15075 + * The dwc_otg_dev_if structure contains information needed to manage
15076 + * the DWC_otg controller acting in device mode. It represents the
15077 + * programming view of the device-specific aspects of the controller.
15079 +typedef struct dwc_otg_dev_if {
15080 + /** Pointer to device Global registers.
15081 + * Device Global Registers starting at offset 800h
15083 + dwc_otg_device_global_regs_t *dev_global_regs;
15084 +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
15087 + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
15089 + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
15090 +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
15091 +#define DWC_EP_REG_OFFSET 0x20
15093 + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
15094 + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
15095 +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
15097 + /* Device configuration information*/
15098 + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
15099 + //uint8_t num_eps; /**< Number of EPs range: 0-16 (includes EP0) */
15100 + //uint8_t num_perio_eps; /**< # of Periodic EP range: 0-15 */
15102 + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
15103 + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
15105 + /** Size of periodic FIFOs (Bytes) */
15106 + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
15108 + /** Size of Tx FIFOs (Bytes) */
15109 + uint16_t tx_fifo_size[MAX_TX_FIFOS];
15111 + /** Thresholding enable flags and length varaiables **/
15112 + uint16_t rx_thr_en;
15113 + uint16_t iso_tx_thr_en;
15114 + uint16_t non_iso_tx_thr_en;
15116 + uint16_t rx_thr_length;
15117 + uint16_t tx_thr_length;
15118 +} dwc_otg_dev_if_t;
15121 + * This union represents the bit fields in the Power and Clock Gating Control
15122 + * Register. Read the register into the <i>d32</i> member then set/clear the
15123 + * bits using the <i>b</i>it elements.
15125 +typedef union pcgcctl_data
15127 + /** raw register data */
15130 + /** register bits */
15132 + unsigned reserved31_05 : 27;
15133 + /** PHY Suspended */
15134 + unsigned physuspended : 1;
15135 + /** Reset Power Down Modules */
15136 + unsigned rstpdwnmodule : 1;
15137 + /** Power Clamp */
15138 + unsigned pwrclmp : 1;
15140 + unsigned gatehclk : 1;
15142 + unsigned stoppclk : 1;
15146 +/////////////////////////////////////////////////
15147 +// Host Mode Register Structures
15150 + * The Host Global Registers structure defines the size and relative
15151 + * field offsets for the Host Mode Global Registers. Host Global
15152 + * Registers offsets 400h-7FFh.
15154 +typedef struct dwc_otg_host_global_regs
15156 + /** Host Configuration Register. <i>Offset: 400h</i> */
15157 + volatile uint32_t hcfg;
15158 + /** Host Frame Interval Register. <i>Offset: 404h</i> */
15159 + volatile uint32_t hfir;
15160 + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
15161 + volatile uint32_t hfnum;
15162 + /** Reserved. <i>Offset: 40Ch</i> */
15163 + uint32_t reserved40C;
15164 + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
15165 + volatile uint32_t hptxsts;
15166 + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
15167 + volatile uint32_t haint;
15168 + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
15169 + volatile uint32_t haintmsk;
15170 +} dwc_otg_host_global_regs_t;
15173 + * This union represents the bit fields in the Host Configuration Register.
15174 + * Read the register into the <i>d32</i> member then set/clear the bits using
15175 + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
15177 +typedef union hcfg_data
15179 + /** raw register data */
15182 + /** register bits */
15185 + //unsigned reserved31_03 : 29;
15186 + /** FS/LS Only Support */
15187 + unsigned fslssupp : 1;
15188 + /** FS/LS Phy Clock Select */
15189 +#define DWC_HCFG_30_60_MHZ 0
15190 +#define DWC_HCFG_48_MHZ 1
15191 +#define DWC_HCFG_6_MHZ 2
15192 + unsigned fslspclksel : 2;
15197 + * This union represents the bit fields in the Host Frame Remaing/Number
15200 +typedef union hfir_data
15202 + /** raw register data */
15205 + /** register bits */
15207 + unsigned reserved : 16;
15208 + unsigned frint : 16;
15213 + * This union represents the bit fields in the Host Frame Remaing/Number
15216 +typedef union hfnum_data
15218 + /** raw register data */
15221 + /** register bits */
15223 + unsigned frrem : 16;
15224 +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
15225 + unsigned frnum : 16;
15229 +typedef union hptxsts_data
15231 + /** raw register data */
15234 + /** register bits */
15236 + /** Top of the Periodic Transmit Request Queue
15237 + * - bit 24 - Terminate (last entry for the selected channel)
15238 + * - bits 26:25 - Token Type
15239 + * - 2'b00 - Zero length
15241 + * - 2'b10 - Disable
15242 + * - bits 30:27 - Channel Number
15243 + * - bit 31 - Odd/even microframe
15245 + unsigned ptxqtop_odd : 1;
15246 + unsigned ptxqtop_chnum : 4;
15247 + unsigned ptxqtop_token : 2;
15248 + unsigned ptxqtop_terminate : 1;
15249 + unsigned ptxqspcavail : 8;
15250 + unsigned ptxfspcavail : 16;
15255 + * This union represents the bit fields in the Host Port Control and Status
15256 + * Register. Read the register into the <i>d32</i> member then set/clear the
15257 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15258 + * hprt0 register.
15260 +typedef union hprt0_data
15262 + /** raw register data */
15264 + /** register bits */
15266 + unsigned reserved19_31 : 13;
15267 +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
15268 +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
15269 +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
15270 + unsigned prtspd : 2;
15271 + unsigned prttstctl : 4;
15272 + unsigned prtpwr : 1;
15273 + unsigned prtlnsts : 2;
15274 + unsigned reserved9 : 1;
15275 + unsigned prtrst : 1;
15276 + unsigned prtsusp : 1;
15277 + unsigned prtres : 1;
15278 + unsigned prtovrcurrchng : 1;
15279 + unsigned prtovrcurract : 1;
15280 + unsigned prtenchng : 1;
15281 + unsigned prtena : 1;
15282 + unsigned prtconndet : 1;
15283 + unsigned prtconnsts : 1;
15288 + * This union represents the bit fields in the Host All Interrupt
15291 +typedef union haint_data
15293 + /** raw register data */
15295 + /** register bits */
15297 + unsigned reserved : 16;
15298 + unsigned ch15 : 1;
15299 + unsigned ch14 : 1;
15300 + unsigned ch13 : 1;
15301 + unsigned ch12 : 1;
15302 + unsigned ch11 : 1;
15303 + unsigned ch10 : 1;
15304 + unsigned ch9 : 1;
15305 + unsigned ch8 : 1;
15306 + unsigned ch7 : 1;
15307 + unsigned ch6 : 1;
15308 + unsigned ch5 : 1;
15309 + unsigned ch4 : 1;
15310 + unsigned ch3 : 1;
15311 + unsigned ch2 : 1;
15312 + unsigned ch1 : 1;
15313 + unsigned ch0 : 1;
15316 + unsigned reserved : 16;
15317 + unsigned chint : 16;
15322 + * This union represents the bit fields in the Host All Interrupt
15325 +typedef union haintmsk_data
15327 + /** raw register data */
15329 + /** register bits */
15331 + unsigned reserved : 16;
15332 + unsigned ch15 : 1;
15333 + unsigned ch14 : 1;
15334 + unsigned ch13 : 1;
15335 + unsigned ch12 : 1;
15336 + unsigned ch11 : 1;
15337 + unsigned ch10 : 1;
15338 + unsigned ch9 : 1;
15339 + unsigned ch8 : 1;
15340 + unsigned ch7 : 1;
15341 + unsigned ch6 : 1;
15342 + unsigned ch5 : 1;
15343 + unsigned ch4 : 1;
15344 + unsigned ch3 : 1;
15345 + unsigned ch2 : 1;
15346 + unsigned ch1 : 1;
15347 + unsigned ch0 : 1;
15350 + unsigned reserved : 16;
15351 + unsigned chint : 16;
15353 +} haintmsk_data_t;
15356 + * Host Channel Specific Registers. <i>500h-5FCh</i>
15358 +typedef struct dwc_otg_hc_regs
15360 + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
15361 + volatile uint32_t hcchar;
15362 + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
15363 + volatile uint32_t hcsplt;
15364 + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
15365 + volatile uint32_t hcint;
15366 + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
15367 + volatile uint32_t hcintmsk;
15368 + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
15369 + volatile uint32_t hctsiz;
15370 + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
15371 + volatile uint32_t hcdma;
15372 + /** Reserved. <i>Offset: 500h + (chan_num * 20h) + 18h - 500h + (chan_num * 20h) + 1Ch</i> */
15373 + uint32_t reserved[2];
15374 +} dwc_otg_hc_regs_t;
15377 + * This union represents the bit fields in the Host Channel Characteristics
15378 + * Register. Read the register into the <i>d32</i> member then set/clear the
15379 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15380 + * hcchar register.
15382 +typedef union hcchar_data
15384 + /** raw register data */
15387 + /** register bits */
15389 + /** Channel enable */
15390 + unsigned chen : 1;
15391 + /** Channel disable */
15392 + unsigned chdis : 1;
15394 + * Frame to transmit periodic transaction.
15395 + * 0: even, 1: odd
15397 + unsigned oddfrm : 1;
15398 + /** Device address */
15399 + unsigned devaddr : 7;
15400 + /** Packets per frame for periodic transfers. 0 is reserved. */
15401 + unsigned multicnt : 2;
15402 + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
15403 + unsigned eptype : 2;
15404 + /** 0: Full/high speed device, 1: Low speed device */
15405 + unsigned lspddev : 1;
15406 + unsigned reserved : 1;
15407 + /** 0: OUT, 1: IN */
15408 + unsigned epdir : 1;
15409 + /** Endpoint number */
15410 + unsigned epnum : 4;
15411 + /** Maximum packet size in bytes */
15412 + unsigned mps : 11;
15416 +typedef union hcsplt_data
15418 + /** raw register data */
15421 + /** register bits */
15423 + /** Split Enble */
15424 + unsigned spltena : 1;
15426 + unsigned reserved : 14;
15427 + /** Do Complete Split */
15428 + unsigned compsplt : 1;
15429 + /** Transaction Position */
15430 +#define DWC_HCSPLIT_XACTPOS_MID 0
15431 +#define DWC_HCSPLIT_XACTPOS_END 1
15432 +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
15433 +#define DWC_HCSPLIT_XACTPOS_ALL 3
15434 + unsigned xactpos : 2;
15435 + /** Hub Address */
15436 + unsigned hubaddr : 7;
15437 + /** Port Address */
15438 + unsigned prtaddr : 7;
15444 + * This union represents the bit fields in the Host All Interrupt
15447 +typedef union hcint_data
15449 + /** raw register data */
15451 + /** register bits */
15454 + unsigned reserved : 21;
15455 + /** Data Toggle Error */
15456 + unsigned datatglerr : 1;
15457 + /** Frame Overrun */
15458 + unsigned frmovrun : 1;
15459 + /** Babble Error */
15460 + unsigned bblerr : 1;
15461 + /** Transaction Err */
15462 + unsigned xacterr : 1;
15463 + /** NYET Response Received */
15464 + unsigned nyet : 1;
15465 + /** ACK Response Received */
15466 + unsigned ack : 1;
15467 + /** NAK Response Received */
15468 + unsigned nak : 1;
15469 + /** STALL Response Received */
15470 + unsigned stall : 1;
15472 + unsigned ahberr : 1;
15473 + /** Channel Halted */
15474 + unsigned chhltd : 1;
15475 + /** Transfer Complete */
15476 + unsigned xfercomp : 1;
15481 + * This union represents the bit fields in the Host Channel Transfer Size
15482 + * Register. Read the register into the <i>d32</i> member then set/clear the
15483 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15484 + * hcchar register.
15486 +typedef union hctsiz_data
15488 + /** raw register data */
15491 + /** register bits */
15493 + /** Do PING protocol when 1 */
15494 + unsigned dopng : 1;
15496 + * Packet ID for next data packet
15500 + * 3: MDATA (non-Control), SETUP (Control)
15502 +#define DWC_HCTSIZ_DATA0 0
15503 +#define DWC_HCTSIZ_DATA1 2
15504 +#define DWC_HCTSIZ_DATA2 1
15505 +#define DWC_HCTSIZ_MDATA 3
15506 +#define DWC_HCTSIZ_SETUP 3
15507 + unsigned pid : 2;
15508 + /** Data packets to transfer */
15509 + unsigned pktcnt : 10;
15510 + /** Total transfer size in bytes */
15511 + unsigned xfersize : 19;
15516 + * This union represents the bit fields in the Host Channel Interrupt Mask
15517 + * Register. Read the register into the <i>d32</i> member then set/clear the
15518 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15519 + * hcintmsk register.
15521 +typedef union hcintmsk_data
15523 + /** raw register data */
15526 + /** register bits */
15528 + unsigned reserved : 21;
15529 + unsigned datatglerr : 1;
15530 + unsigned frmovrun : 1;
15531 + unsigned bblerr : 1;
15532 + unsigned xacterr : 1;
15533 + unsigned nyet : 1;
15534 + unsigned ack : 1;
15535 + unsigned nak : 1;
15536 + unsigned stall : 1;
15537 + unsigned ahberr : 1;
15538 + unsigned chhltd : 1;
15539 + unsigned xfercompl : 1;
15541 +} hcintmsk_data_t;
15543 +/** OTG Host Interface Structure.
15545 + * The OTG Host Interface Structure structure contains information
15546 + * needed to manage the DWC_otg controller acting in host mode. It
15547 + * represents the programming view of the host-specific aspects of the
15550 +typedef struct dwc_otg_host_if {
15551 + /** Host Global Registers starting at offset 400h.*/
15552 + dwc_otg_host_global_regs_t *host_global_regs;
15553 +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
15555 + /** Host Port 0 Control and Status Register */
15556 + volatile uint32_t *hprt0;
15557 +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
15560 + /** Host Channel Specific Registers at offsets 500h-5FCh. */
15561 + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
15562 +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
15563 +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
15566 + /* Host configuration information */
15567 + /** Number of Host Channels (range: 1-16) */
15568 + uint8_t num_host_channels;
15569 + /** Periodic EPs supported (0: no, 1: yes) */
15570 + uint8_t perio_eps_supported;
15571 + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
15572 + uint16_t perio_tx_fifo_size;
15574 +} dwc_otg_host_if_t;