9176770426799e90195ce35fc71ac60cda3570fb
[openwrt/openwrt.git] / target / linux / lantiq / patches / 700-dwc_otg.patch
1 --- a/drivers/usb/Kconfig
2 +++ b/drivers/usb/Kconfig
3 @@ -111,6 +111,8 @@
4
5 source "drivers/usb/host/Kconfig"
6
7 +source "drivers/usb/dwc_otg/Kconfig"
8 +
9 source "drivers/usb/musb/Kconfig"
10
11 source "drivers/usb/class/Kconfig"
12 --- a/drivers/usb/Makefile
13 +++ b/drivers/usb/Makefile
14 @@ -27,6 +27,8 @@
15
16 obj-$(CONFIG_USB_WUSB) += wusbcore/
17
18 +obj-$(CONFIG_DWC_OTG) += dwc_otg/
19 +
20 obj-$(CONFIG_USB_ACM) += class/
21 obj-$(CONFIG_USB_PRINTER) += class/
22 obj-$(CONFIG_USB_WDM) += class/
23 --- /dev/null
24 +++ b/drivers/usb/dwc_otg/Kconfig
25 @@ -0,0 +1,37 @@
26 +config DWC_OTG
27 + tristate "Synopsis DWC_OTG support"
28 + depends on USB
29 + help
30 + This driver supports Synopsis DWC_OTG IP core
31 + embebbed on many SOCs (ralink, infineon, etc)
32 +
33 +choice
34 + prompt "USB Operation Mode"
35 + depends on DWC_OTG
36 + default DWC_OTG_HOST_ONLY
37 +
38 +config DWC_OTG_HOST_ONLY
39 + bool "HOST ONLY MODE"
40 + depends on DWC_OTG
41 +
42 +config DWC_OTG_DEVICE_ONLY
43 + bool "DEVICE ONLY MODE"
44 + depends on DWC_OTG
45 +endchoice
46 +
47 +choice
48 + prompt "Platform"
49 + depends on DWC_OTG
50 + default DWC_OTG_LANTIQ
51 +
52 +config DWC_OTG_LANTIQ
53 + bool "Lantiq"
54 + depends on LANTIQ
55 + help
56 + Danube USB Host Controller
57 + platform support
58 +endchoice
59 +
60 +config DWC_OTG_DEBUG
61 + bool "Enable debug mode"
62 + depends on DWC_OTG
63 --- /dev/null
64 +++ b/drivers/usb/dwc_otg/Makefile
65 @@ -0,0 +1,39 @@
66 +#
67 +# Makefile for DWC_otg Highspeed USB controller driver
68 +#
69 +
70 +ifeq ($(CONFIG_DWC_OTG_DEBUG),y)
71 +EXTRA_CFLAGS += -DDEBUG
72 +endif
73 +
74 +# Use one of the following flags to compile the software in host-only or
75 +# device-only mode based on the configuration selected by the user
76 +ifeq ($(CONFIG_DWC_OTG_HOST_ONLY),y)
77 + EXTRA_CFLAGS += -DDWC_OTG_HOST_ONLY -DDWC_HOST_ONLY
78 + EXTRA_CFLAGS += -DDWC_OTG_EN_ISOC -DDWC_EN_ISOC
79 +else ifeq ($(CONFIG_DWC_OTG_DEVICE_ONLY),y)
80 + EXTRA_CFLAGS += -DDWC_OTG_DEVICE_ONLY
81 +else
82 + EXTRA_CFLAGS += -DDWC_OTG_MODE
83 +endif
84 +
85 +# EXTRA_CFLAGS += -DDWC_HS_ELECT_TST
86 +# EXTRA_CFLAGS += -DDWC_OTG_EXT_CHG_PUMP
87 +
88 +ifeq ($(CONFIG_DWC_OTG_LANTIQ),y)
89 + EXTRA_CFLAGS += -Dlinux -D__LINUX__ -DDWC_OTG_IFX -DDWC_OTG_HOST_ONLY -DDWC_HOST_ONLY -D__KERNEL__
90 +endif
91 +ifeq ($(CONFIG_DWC_OTG_LANTIQ),m)
92 + EXTRA_CFLAGS += -Dlinux -D__LINUX__ -DDWC_OTG_IFX -DDWC_HOST_ONLY -DMODULE -D__KERNEL__ -DDEBUG
93 +endif
94 +
95 +obj-$(CONFIG_DWC_OTG) := dwc_otg.o
96 +dwc_otg-objs := dwc_otg_hcd.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o
97 +#dwc_otg-objs += dwc_otg_pcd.o dwc_otg_pcd_intr.o
98 +dwc_otg-objs += dwc_otg_attr.o
99 +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
100 +dwc_otg-objs += dwc_otg_ifx.o
101 +dwc_otg-objs += dwc_otg_driver.o
102 +
103 +#obj-$(CONFIG_DWC_OTG_IFX) := dwc_otg_ifx.o
104 +#dwc_otg_ifx-objs := dwc_otg_ifx.o
105 --- /dev/null
106 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.c
107 @@ -0,0 +1,802 @@
108 +/* ==========================================================================
109 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_attr.c $
110 + * $Revision: 1.1.1.1 $
111 + * $Date: 2009-04-17 06:15:34 $
112 + * $Change: 537387 $
113 + *
114 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
115 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
116 + * otherwise expressly agreed to in writing between Synopsys and you.
117 + *
118 + * The Software IS NOT an item of Licensed Software or Licensed Product under
119 + * any End User Software License Agreement or Agreement for Licensed Product
120 + * with Synopsys or any supplement thereto. You are permitted to use and
121 + * redistribute this Software in source and binary forms, with or without
122 + * modification, provided that redistributions of source code must retain this
123 + * notice. You may not view, use, disclose, copy or distribute this file or
124 + * any information contained herein except pursuant to this license grant from
125 + * Synopsys. If you do not agree with this notice, including the disclaimer
126 + * below, then you are not authorized to use the Software.
127 + *
128 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
129 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
130 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
131 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
132 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
133 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
134 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
135 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
136 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
137 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
138 + * DAMAGE.
139 + * ========================================================================== */
140 +
141 +/** @file
142 + *
143 + * The diagnostic interface will provide access to the controller for
144 + * bringing up the hardware and testing. The Linux driver attributes
145 + * feature will be used to provide the Linux Diagnostic
146 + * Interface. These attributes are accessed through sysfs.
147 + */
148 +
149 +/** @page "Linux Module Attributes"
150 + *
151 + * The Linux module attributes feature is used to provide the Linux
152 + * Diagnostic Interface. These attributes are accessed through sysfs.
153 + * The diagnostic interface will provide access to the controller for
154 + * bringing up the hardware and testing.
155 +
156 +
157 + The following table shows the attributes.
158 + <table>
159 + <tr>
160 + <td><b> Name</b></td>
161 + <td><b> Description</b></td>
162 + <td><b> Access</b></td>
163 + </tr>
164 +
165 + <tr>
166 + <td> mode </td>
167 + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
168 + <td> Read</td>
169 + </tr>
170 +
171 + <tr>
172 + <td> hnpcapable </td>
173 + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
174 + Read returns the current value.</td>
175 + <td> Read/Write</td>
176 + </tr>
177 +
178 + <tr>
179 + <td> srpcapable </td>
180 + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
181 + Read returns the current value.</td>
182 + <td> Read/Write</td>
183 + </tr>
184 +
185 + <tr>
186 + <td> hnp </td>
187 + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
188 + <td> Read/Write</td>
189 + </tr>
190 +
191 + <tr>
192 + <td> srp </td>
193 + <td> Initiates the Session Request Protocol. Read returns the status.</td>
194 + <td> Read/Write</td>
195 + </tr>
196 +
197 + <tr>
198 + <td> buspower </td>
199 + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
200 + <td> Read/Write</td>
201 + </tr>
202 +
203 + <tr>
204 + <td> bussuspend </td>
205 + <td> Suspends the USB bus.</td>
206 + <td> Read/Write</td>
207 + </tr>
208 +
209 + <tr>
210 + <td> busconnected </td>
211 + <td> Gets the connection status of the bus</td>
212 + <td> Read</td>
213 + </tr>
214 +
215 + <tr>
216 + <td> gotgctl </td>
217 + <td> Gets or sets the Core Control Status Register.</td>
218 + <td> Read/Write</td>
219 + </tr>
220 +
221 + <tr>
222 + <td> gusbcfg </td>
223 + <td> Gets or sets the Core USB Configuration Register</td>
224 + <td> Read/Write</td>
225 + </tr>
226 +
227 + <tr>
228 + <td> grxfsiz </td>
229 + <td> Gets or sets the Receive FIFO Size Register</td>
230 + <td> Read/Write</td>
231 + </tr>
232 +
233 + <tr>
234 + <td> gnptxfsiz </td>
235 + <td> Gets or sets the non-periodic Transmit Size Register</td>
236 + <td> Read/Write</td>
237 + </tr>
238 +
239 + <tr>
240 + <td> gpvndctl </td>
241 + <td> Gets or sets the PHY Vendor Control Register</td>
242 + <td> Read/Write</td>
243 + </tr>
244 +
245 + <tr>
246 + <td> ggpio </td>
247 + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
248 + or sets the upper 16 bits.</td>
249 + <td> Read/Write</td>
250 + </tr>
251 +
252 + <tr>
253 + <td> guid </td>
254 + <td> Gets or sets the value of the User ID Register</td>
255 + <td> Read/Write</td>
256 + </tr>
257 +
258 + <tr>
259 + <td> gsnpsid </td>
260 + <td> Gets the value of the Synopsys ID Regester</td>
261 + <td> Read</td>
262 + </tr>
263 +
264 + <tr>
265 + <td> devspeed </td>
266 + <td> Gets or sets the device speed setting in the DCFG register</td>
267 + <td> Read/Write</td>
268 + </tr>
269 +
270 + <tr>
271 + <td> enumspeed </td>
272 + <td> Gets the device enumeration Speed.</td>
273 + <td> Read</td>
274 + </tr>
275 +
276 + <tr>
277 + <td> hptxfsiz </td>
278 + <td> Gets the value of the Host Periodic Transmit FIFO</td>
279 + <td> Read</td>
280 + </tr>
281 +
282 + <tr>
283 + <td> hprt0 </td>
284 + <td> Gets or sets the value in the Host Port Control and Status Register</td>
285 + <td> Read/Write</td>
286 + </tr>
287 +
288 + <tr>
289 + <td> regoffset </td>
290 + <td> Sets the register offset for the next Register Access</td>
291 + <td> Read/Write</td>
292 + </tr>
293 +
294 + <tr>
295 + <td> regvalue </td>
296 + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
297 + <td> Read/Write</td>
298 + </tr>
299 +
300 + <tr>
301 + <td> remote_wakeup </td>
302 + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
303 + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
304 + Wakeup signalling bit in the Device Control Register is set for 1
305 + milli-second.</td>
306 + <td> Read/Write</td>
307 + </tr>
308 +
309 + <tr>
310 + <td> regdump </td>
311 + <td> Dumps the contents of core registers.</td>
312 + <td> Read</td>
313 + </tr>
314 +
315 + <tr>
316 + <td> hcddump </td>
317 + <td> Dumps the current HCD state.</td>
318 + <td> Read</td>
319 + </tr>
320 +
321 + <tr>
322 + <td> hcd_frrem </td>
323 + <td> Shows the average value of the Frame Remaining
324 + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
325 + occurs. This can be used to determine the average interrupt latency. Also
326 + shows the average Frame Remaining value for start_transfer and the "a" and
327 + "b" sample points. The "a" and "b" sample points may be used during debugging
328 + bto determine how long it takes to execute a section of the HCD code.</td>
329 + <td> Read</td>
330 + </tr>
331 +
332 + <tr>
333 + <td> rd_reg_test </td>
334 + <td> Displays the time required to read the GNPTXFSIZ register many times
335 + (the output shows the number of times the register is read).
336 + <td> Read</td>
337 + </tr>
338 +
339 + <tr>
340 + <td> wr_reg_test </td>
341 + <td> Displays the time required to write the GNPTXFSIZ register many times
342 + (the output shows the number of times the register is written).
343 + <td> Read</td>
344 + </tr>
345 +
346 + </table>
347 +
348 + Example usage:
349 + To get the current mode:
350 + cat /sys/devices/lm0/mode
351 +
352 + To power down the USB:
353 + echo 0 > /sys/devices/lm0/buspower
354 + */
355 +#include <linux/kernel.h>
356 +#include <linux/module.h>
357 +#include <linux/moduleparam.h>
358 +#include <linux/init.h>
359 +#include <linux/device.h>
360 +#include <linux/errno.h>
361 +#include <linux/types.h>
362 +#include <linux/stat.h> /* permission constants */
363 +
364 +#include <asm/io.h>
365 +
366 +#include "dwc_otg_plat.h"
367 +#include "dwc_otg_attr.h"
368 +#include "dwc_otg_driver.h"
369 +// #include "dwc_otg_pcd.h"
370 +#include "dwc_otg_hcd.h"
371 +
372 +// 20070316, winder added.
373 +#ifndef SZ_256K
374 +#define SZ_256K 0x00040000
375 +#endif
376 +
377 +/*
378 + * MACROs for defining sysfs attribute
379 + */
380 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
381 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
382 +{ \
383 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
384 + uint32_t val; \
385 + val = dwc_read_reg32 (_addr_); \
386 + val = (val & (_mask_)) >> _shift_; \
387 + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
388 +}
389 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
390 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, const char *buf, size_t count) \
391 +{ \
392 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
393 + uint32_t set = simple_strtoul(buf, NULL, 16); \
394 + uint32_t clear = set; \
395 + clear = ((~clear) << _shift_) & _mask_; \
396 + set = (set << _shift_) & _mask_; \
397 + dev_dbg(_dev, "Storing Address=0x%08x Set=0x%08x Clear=0x%08x\n", (uint32_t)_addr_, set, clear); \
398 + dwc_modify_reg32(_addr_, clear, set); \
399 + return count; \
400 +}
401 +
402 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
403 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
404 +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
405 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
406 +
407 +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
408 +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \
409 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
410 +
411 +/*
412 + * MACROs for defining sysfs attribute for 32-bit registers
413 + */
414 +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
415 +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
416 +{ \
417 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
418 + uint32_t val; \
419 + val = dwc_read_reg32 (_addr_); \
420 + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
421 +}
422 +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
423 +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, const char *buf, size_t count) \
424 +{ \
425 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\
426 + uint32_t val = simple_strtoul(buf, NULL, 16); \
427 + dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \
428 + dwc_write_reg32(_addr_, val); \
429 + return count; \
430 +}
431 +
432 +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
433 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
434 +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \
435 +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
436 +
437 +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
438 +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \
439 +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
440 +
441 +
442 +/** @name Functions for Show/Store of Attributes */
443 +/**@{*/
444 +
445 +/**
446 + * Show the register offset of the Register Access.
447 + */
448 +static ssize_t regoffset_show( struct device *_dev, struct device_attribute *attr, char *buf)
449 +{
450 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
451 + return snprintf(buf, sizeof("0xFFFFFFFF\n")+1,"0x%08x\n", otg_dev->reg_offset);
452 +}
453 +
454 +/**
455 + * Set the register offset for the next Register Access Read/Write
456 + */
457 +static ssize_t regoffset_store( struct device *_dev, struct device_attribute *attr, const char *buf,
458 + size_t count )
459 +{
460 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
461 + uint32_t offset = simple_strtoul(buf, NULL, 16);
462 + //dev_dbg(_dev, "Offset=0x%08x\n", offset);
463 + if (offset < SZ_256K ) {
464 + otg_dev->reg_offset = offset;
465 + }
466 + else {
467 + dev_err( _dev, "invalid offset\n" );
468 + }
469 +
470 + return count;
471 +}
472 +DEVICE_ATTR(regoffset, S_IRUGO|S_IWUSR, regoffset_show, regoffset_store);
473 +
474 +/**
475 + * Show the value of the register at the offset in the reg_offset
476 + * attribute.
477 + */
478 +static ssize_t regvalue_show( struct device *_dev, struct device_attribute *attr, char *buf)
479 +{
480 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
481 + uint32_t val;
482 + volatile uint32_t *addr;
483 +
484 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
485 + /* Calculate the address */
486 + addr = (uint32_t*)(otg_dev->reg_offset +
487 + (uint8_t*)otg_dev->base);
488 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
489 + val = dwc_read_reg32( addr );
490 + return snprintf(buf, sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n")+1,
491 + "Reg@0x%06x = 0x%08x\n",
492 + otg_dev->reg_offset, val);
493 + }
494 + else {
495 + dev_err(_dev, "Invalid offset (0x%0x)\n",
496 + otg_dev->reg_offset);
497 + return sprintf(buf, "invalid offset\n" );
498 + }
499 +}
500 +
501 +/**
502 + * Store the value in the register at the offset in the reg_offset
503 + * attribute.
504 + *
505 + */
506 +static ssize_t regvalue_store( struct device *_dev, struct device_attribute *attr, const char *buf,
507 + size_t count )
508 +{
509 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
510 + volatile uint32_t * addr;
511 + uint32_t val = simple_strtoul(buf, NULL, 16);
512 + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
513 + if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
514 + /* Calculate the address */
515 + addr = (uint32_t*)(otg_dev->reg_offset +
516 + (uint8_t*)otg_dev->base);
517 + //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr);
518 + dwc_write_reg32( addr, val );
519 + }
520 + else {
521 + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
522 + otg_dev->reg_offset);
523 + }
524 + return count;
525 +}
526 +DEVICE_ATTR(regvalue, S_IRUGO|S_IWUSR, regvalue_show, regvalue_store);
527 +
528 +/*
529 + * Attributes
530 + */
531 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<20),20,"Mode");
532 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<9),9,"Mode");
533 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<8),8,"Mode");
534 +
535 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
536 +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
537 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected,otg_dev->core_if->host_if->hprt0,0x01,0,"Bus Connected");
538 +
539 +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl,&(otg_dev->core_if->core_global_regs->gotgctl),"GOTGCTL");
540 +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,&(otg_dev->core_if->core_global_regs->gusbcfg),"GUSBCFG");
541 +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,&(otg_dev->core_if->core_global_regs->grxfsiz),"GRXFSIZ");
542 +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,&(otg_dev->core_if->core_global_regs->gnptxfsiz),"GNPTXFSIZ");
543 +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,&(otg_dev->core_if->core_global_regs->gpvndctl),"GPVNDCTL");
544 +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,&(otg_dev->core_if->core_global_regs->ggpio),"GGPIO");
545 +DWC_OTG_DEVICE_ATTR_REG32_RW(guid,&(otg_dev->core_if->core_global_regs->guid),"GUID");
546 +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,&(otg_dev->core_if->core_global_regs->gsnpsid),"GSNPSID");
547 +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dcfg),0x3,0,"Device Speed");
548 +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dsts),0x6,1,"Device Enumeration Speed");
549 +
550 +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,&(otg_dev->core_if->core_global_regs->hptxfsiz),"HPTXFSIZ");
551 +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0,otg_dev->core_if->host_if->hprt0,"HPRT0");
552 +
553 +
554 +/**
555 + * @todo Add code to initiate the HNP.
556 + */
557 +/**
558 + * Show the HNP status bit
559 + */
560 +static ssize_t hnp_show( struct device *_dev, struct device_attribute *attr, char *buf)
561 +{
562 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
563 + gotgctl_data_t val;
564 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
565 + return sprintf (buf, "HstNegScs = 0x%x\n", val.b.hstnegscs);
566 +}
567 +
568 +/**
569 + * Set the HNP Request bit
570 + */
571 +static ssize_t hnp_store( struct device *_dev, struct device_attribute *attr, const char *buf,
572 + size_t count )
573 +{
574 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
575 + uint32_t in = simple_strtoul(buf, NULL, 16);
576 + uint32_t *addr = (uint32_t *)&(otg_dev->core_if->core_global_regs->gotgctl);
577 + gotgctl_data_t mem;
578 + mem.d32 = dwc_read_reg32(addr);
579 + mem.b.hnpreq = in;
580 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
581 + dwc_write_reg32(addr, mem.d32);
582 + return count;
583 +}
584 +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
585 +
586 +/**
587 + * @todo Add code to initiate the SRP.
588 + */
589 +/**
590 + * Show the SRP status bit
591 + */
592 +static ssize_t srp_show( struct device *_dev, struct device_attribute *attr, char *buf)
593 +{
594 +#ifndef DWC_HOST_ONLY
595 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
596 + gotgctl_data_t val;
597 + val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl));
598 + return sprintf (buf, "SesReqScs = 0x%x\n", val.b.sesreqscs);
599 +#else
600 + return sprintf(buf, "Host Only Mode!\n");
601 +#endif
602 +}
603 +
604 +/**
605 + * Set the SRP Request bit
606 + */
607 +static ssize_t srp_store( struct device *_dev, struct device_attribute *attr, const char *buf,
608 + size_t count )
609 +{
610 +#ifndef DWC_HOST_ONLY
611 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
612 + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
613 +#endif
614 + return count;
615 +}
616 +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
617 +
618 +/**
619 + * @todo Need to do more for power on/off?
620 + */
621 +/**
622 + * Show the Bus Power status
623 + */
624 +static ssize_t buspower_show( struct device *_dev, struct device_attribute *attr, char *buf)
625 +{
626 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
627 + hprt0_data_t val;
628 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
629 + return sprintf (buf, "Bus Power = 0x%x\n", val.b.prtpwr);
630 +}
631 +
632 +
633 +/**
634 + * Set the Bus Power status
635 + */
636 +static ssize_t buspower_store( struct device *_dev, struct device_attribute *attr, const char *buf,
637 + size_t count )
638 +{
639 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
640 + uint32_t on = simple_strtoul(buf, NULL, 16);
641 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
642 + hprt0_data_t mem;
643 +
644 + mem.d32 = dwc_read_reg32(addr);
645 + mem.b.prtpwr = on;
646 +
647 + //dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
648 + dwc_write_reg32(addr, mem.d32);
649 +
650 + return count;
651 +}
652 +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
653 +
654 +/**
655 + * @todo Need to do more for suspend?
656 + */
657 +/**
658 + * Show the Bus Suspend status
659 + */
660 +static ssize_t bussuspend_show( struct device *_dev, struct device_attribute *attr, char *buf)
661 +{
662 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
663 + hprt0_data_t val;
664 + val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0);
665 + return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
666 +}
667 +
668 +/**
669 + * Set the Bus Suspend status
670 + */
671 +static ssize_t bussuspend_store( struct device *_dev, struct device_attribute *attr, const char *buf,
672 + size_t count )
673 +{
674 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
675 + uint32_t in = simple_strtoul(buf, NULL, 16);
676 + uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0;
677 + hprt0_data_t mem;
678 + mem.d32 = dwc_read_reg32(addr);
679 + mem.b.prtsusp = in;
680 + dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32);
681 + dwc_write_reg32(addr, mem.d32);
682 + return count;
683 +}
684 +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
685 +
686 +/**
687 + * Show the status of Remote Wakeup.
688 + */
689 +static ssize_t remote_wakeup_show( struct device *_dev, struct device_attribute *attr, char *buf)
690 +{
691 +#ifndef DWC_HOST_ONLY
692 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
693 + dctl_data_t val;
694 + val.d32 = dwc_read_reg32( &otg_dev->core_if->dev_if->dev_global_regs->dctl);
695 + return sprintf( buf, "Remote Wakeup = %d Enabled = %d\n",
696 + val.b.rmtwkupsig, otg_dev->pcd->remote_wakeup_enable);
697 +#else
698 + return sprintf(buf, "Host Only Mode!\n");
699 +#endif
700 +}
701 +
702 +/**
703 + * Initiate a remote wakeup of the host. The Device control register
704 + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
705 + * flag is set.
706 + *
707 + */
708 +static ssize_t remote_wakeup_store( struct device *_dev, struct device_attribute *attr, const char *buf,
709 + size_t count )
710 +{
711 +#ifndef DWC_HOST_ONLY
712 + uint32_t val = simple_strtoul(buf, NULL, 16);
713 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
714 + if (val&1) {
715 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
716 + }
717 + else {
718 + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
719 + }
720 +#endif
721 + return count;
722 +}
723 +DEVICE_ATTR(remote_wakeup, S_IRUGO|S_IWUSR, remote_wakeup_show,
724 + remote_wakeup_store);
725 +
726 +/**
727 + * Dump global registers and either host or device registers (depending on the
728 + * current mode of the core).
729 + */
730 +static ssize_t regdump_show( struct device *_dev, struct device_attribute *attr, char *buf)
731 +{
732 +#ifdef DEBUG
733 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
734 + printk("%s otg_dev=0x%p\n", __FUNCTION__, otg_dev);
735 +
736 + dwc_otg_dump_global_registers( otg_dev->core_if);
737 + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
738 + dwc_otg_dump_host_registers( otg_dev->core_if);
739 + } else {
740 + dwc_otg_dump_dev_registers( otg_dev->core_if);
741 + }
742 +#endif
743 +
744 + return sprintf( buf, "Register Dump\n" );
745 +}
746 +
747 +DEVICE_ATTR(regdump, S_IRUGO|S_IWUSR, regdump_show, 0);
748 +
749 +/**
750 + * Dump the current hcd state.
751 + */
752 +static ssize_t hcddump_show( struct device *_dev, struct device_attribute *attr, char *buf)
753 +{
754 +#ifndef DWC_DEVICE_ONLY
755 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
756 + dwc_otg_hcd_dump_state(otg_dev->hcd);
757 +#endif
758 + return sprintf( buf, "HCD Dump\n" );
759 +}
760 +
761 +DEVICE_ATTR(hcddump, S_IRUGO|S_IWUSR, hcddump_show, 0);
762 +
763 +/**
764 + * Dump the average frame remaining at SOF. This can be used to
765 + * determine average interrupt latency. Frame remaining is also shown for
766 + * start transfer and two additional sample points.
767 + */
768 +static ssize_t hcd_frrem_show( struct device *_dev, struct device_attribute *attr, char *buf)
769 +{
770 +#ifndef DWC_DEVICE_ONLY
771 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
772 + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
773 +#endif
774 + return sprintf( buf, "HCD Dump Frame Remaining\n" );
775 +}
776 +
777 +DEVICE_ATTR(hcd_frrem, S_IRUGO|S_IWUSR, hcd_frrem_show, 0);
778 +
779 +/**
780 + * Displays the time required to read the GNPTXFSIZ register many times (the
781 + * output shows the number of times the register is read).
782 + */
783 +#define RW_REG_COUNT 10000000
784 +#define MSEC_PER_JIFFIE 1000/HZ
785 +static ssize_t rd_reg_test_show( struct device *_dev, struct device_attribute *attr, char *buf)
786 +{
787 + int i;
788 + int time;
789 + int start_jiffies;
790 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
791 +
792 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
793 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
794 + start_jiffies = jiffies;
795 + for (i = 0; i < RW_REG_COUNT; i++) {
796 + dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
797 + }
798 + time = jiffies - start_jiffies;
799 + return sprintf( buf, "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
800 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time );
801 +}
802 +
803 +DEVICE_ATTR(rd_reg_test, S_IRUGO|S_IWUSR, rd_reg_test_show, 0);
804 +
805 +/**
806 + * Displays the time required to write the GNPTXFSIZ register many times (the
807 + * output shows the number of times the register is written).
808 + */
809 +static ssize_t wr_reg_test_show( struct device *_dev, struct device_attribute *attr, char *buf)
810 +{
811 + int i;
812 + int time;
813 + int start_jiffies;
814 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
815 + uint32_t reg_val;
816 +
817 + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
818 + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
819 + reg_val = dwc_read_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz);
820 + start_jiffies = jiffies;
821 + for (i = 0; i < RW_REG_COUNT; i++) {
822 + dwc_write_reg32(&otg_dev->core_if->core_global_regs->gnptxfsiz, reg_val);
823 + }
824 + time = jiffies - start_jiffies;
825 + return sprintf( buf, "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
826 + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
827 +}
828 +
829 +DEVICE_ATTR(wr_reg_test, S_IRUGO|S_IWUSR, wr_reg_test_show, 0);
830 +/**@}*/
831 +
832 +/**
833 + * Create the device files
834 + */
835 +void dwc_otg_attr_create (struct device *_dev)
836 +{
837 + int retval;
838 +
839 + retval = device_create_file(_dev, &dev_attr_regoffset);
840 + retval += device_create_file(_dev, &dev_attr_regvalue);
841 + retval += device_create_file(_dev, &dev_attr_mode);
842 + retval += device_create_file(_dev, &dev_attr_hnpcapable);
843 + retval += device_create_file(_dev, &dev_attr_srpcapable);
844 + retval += device_create_file(_dev, &dev_attr_hnp);
845 + retval += device_create_file(_dev, &dev_attr_srp);
846 + retval += device_create_file(_dev, &dev_attr_buspower);
847 + retval += device_create_file(_dev, &dev_attr_bussuspend);
848 + retval += device_create_file(_dev, &dev_attr_busconnected);
849 + retval += device_create_file(_dev, &dev_attr_gotgctl);
850 + retval += device_create_file(_dev, &dev_attr_gusbcfg);
851 + retval += device_create_file(_dev, &dev_attr_grxfsiz);
852 + retval += device_create_file(_dev, &dev_attr_gnptxfsiz);
853 + retval += device_create_file(_dev, &dev_attr_gpvndctl);
854 + retval += device_create_file(_dev, &dev_attr_ggpio);
855 + retval += device_create_file(_dev, &dev_attr_guid);
856 + retval += device_create_file(_dev, &dev_attr_gsnpsid);
857 + retval += device_create_file(_dev, &dev_attr_devspeed);
858 + retval += device_create_file(_dev, &dev_attr_enumspeed);
859 + retval += device_create_file(_dev, &dev_attr_hptxfsiz);
860 + retval += device_create_file(_dev, &dev_attr_hprt0);
861 + retval += device_create_file(_dev, &dev_attr_remote_wakeup);
862 + retval += device_create_file(_dev, &dev_attr_regdump);
863 + retval += device_create_file(_dev, &dev_attr_hcddump);
864 + retval += device_create_file(_dev, &dev_attr_hcd_frrem);
865 + retval += device_create_file(_dev, &dev_attr_rd_reg_test);
866 + retval += device_create_file(_dev, &dev_attr_wr_reg_test);
867 +
868 + if(retval != 0)
869 + {
870 + DWC_PRINT("cannot create sysfs device files.\n");
871 + // DWC_PRINT("killing own sysfs device files!\n");
872 + dwc_otg_attr_remove(_dev);
873 + }
874 +}
875 +
876 +/**
877 + * Remove the device files
878 + */
879 +void dwc_otg_attr_remove (struct device *_dev)
880 +{
881 + device_remove_file(_dev, &dev_attr_regoffset);
882 + device_remove_file(_dev, &dev_attr_regvalue);
883 + device_remove_file(_dev, &dev_attr_mode);
884 + device_remove_file(_dev, &dev_attr_hnpcapable);
885 + device_remove_file(_dev, &dev_attr_srpcapable);
886 + device_remove_file(_dev, &dev_attr_hnp);
887 + device_remove_file(_dev, &dev_attr_srp);
888 + device_remove_file(_dev, &dev_attr_buspower);
889 + device_remove_file(_dev, &dev_attr_bussuspend);
890 + device_remove_file(_dev, &dev_attr_busconnected);
891 + device_remove_file(_dev, &dev_attr_gotgctl);
892 + device_remove_file(_dev, &dev_attr_gusbcfg);
893 + device_remove_file(_dev, &dev_attr_grxfsiz);
894 + device_remove_file(_dev, &dev_attr_gnptxfsiz);
895 + device_remove_file(_dev, &dev_attr_gpvndctl);
896 + device_remove_file(_dev, &dev_attr_ggpio);
897 + device_remove_file(_dev, &dev_attr_guid);
898 + device_remove_file(_dev, &dev_attr_gsnpsid);
899 + device_remove_file(_dev, &dev_attr_devspeed);
900 + device_remove_file(_dev, &dev_attr_enumspeed);
901 + device_remove_file(_dev, &dev_attr_hptxfsiz);
902 + device_remove_file(_dev, &dev_attr_hprt0);
903 + device_remove_file(_dev, &dev_attr_remote_wakeup);
904 + device_remove_file(_dev, &dev_attr_regdump);
905 + device_remove_file(_dev, &dev_attr_hcddump);
906 + device_remove_file(_dev, &dev_attr_hcd_frrem);
907 + device_remove_file(_dev, &dev_attr_rd_reg_test);
908 + device_remove_file(_dev, &dev_attr_wr_reg_test);
909 +}
910 --- /dev/null
911 +++ b/drivers/usb/dwc_otg/dwc_otg_attr.h
912 @@ -0,0 +1,67 @@
913 +/* ==========================================================================
914 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_attr.h $
915 + * $Revision: 1.1.1.1 $
916 + * $Date: 2009-04-17 06:15:34 $
917 + * $Change: 510275 $
918 + *
919 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
920 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
921 + * otherwise expressly agreed to in writing between Synopsys and you.
922 + *
923 + * The Software IS NOT an item of Licensed Software or Licensed Product under
924 + * any End User Software License Agreement or Agreement for Licensed Product
925 + * with Synopsys or any supplement thereto. You are permitted to use and
926 + * redistribute this Software in source and binary forms, with or without
927 + * modification, provided that redistributions of source code must retain this
928 + * notice. You may not view, use, disclose, copy or distribute this file or
929 + * any information contained herein except pursuant to this license grant from
930 + * Synopsys. If you do not agree with this notice, including the disclaimer
931 + * below, then you are not authorized to use the Software.
932 + *
933 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
934 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
935 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
936 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
937 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
938 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
939 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
940 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
941 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
942 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
943 + * DAMAGE.
944 + * ========================================================================== */
945 +
946 +#if !defined(__DWC_OTG_ATTR_H__)
947 +#define __DWC_OTG_ATTR_H__
948 +
949 +/** @file
950 + * This file contains the interface to the Linux device attributes.
951 + */
952 +extern struct device_attribute dev_attr_regoffset;
953 +extern struct device_attribute dev_attr_regvalue;
954 +
955 +extern struct device_attribute dev_attr_mode;
956 +extern struct device_attribute dev_attr_hnpcapable;
957 +extern struct device_attribute dev_attr_srpcapable;
958 +extern struct device_attribute dev_attr_hnp;
959 +extern struct device_attribute dev_attr_srp;
960 +extern struct device_attribute dev_attr_buspower;
961 +extern struct device_attribute dev_attr_bussuspend;
962 +extern struct device_attribute dev_attr_busconnected;
963 +extern struct device_attribute dev_attr_gotgctl;
964 +extern struct device_attribute dev_attr_gusbcfg;
965 +extern struct device_attribute dev_attr_grxfsiz;
966 +extern struct device_attribute dev_attr_gnptxfsiz;
967 +extern struct device_attribute dev_attr_gpvndctl;
968 +extern struct device_attribute dev_attr_ggpio;
969 +extern struct device_attribute dev_attr_guid;
970 +extern struct device_attribute dev_attr_gsnpsid;
971 +extern struct device_attribute dev_attr_devspeed;
972 +extern struct device_attribute dev_attr_enumspeed;
973 +extern struct device_attribute dev_attr_hptxfsiz;
974 +extern struct device_attribute dev_attr_hprt0;
975 +
976 +void dwc_otg_attr_create (struct device *_dev);
977 +void dwc_otg_attr_remove (struct device *_dev);
978 +
979 +#endif
980 --- /dev/null
981 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.c
982 @@ -0,0 +1,3025 @@
983 +/* ==========================================================================
984 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil.c $
985 + * $Revision: 1.1.1.1 $
986 + * $Date: 2009-04-17 06:15:34 $
987 + * $Change: 631780 $
988 + *
989 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
990 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
991 + * otherwise expressly agreed to in writing between Synopsys and you.
992 + *
993 + * The Software IS NOT an item of Licensed Software or Licensed Product under
994 + * any End User Software License Agreement or Agreement for Licensed Product
995 + * with Synopsys or any supplement thereto. You are permitted to use and
996 + * redistribute this Software in source and binary forms, with or without
997 + * modification, provided that redistributions of source code must retain this
998 + * notice. You may not view, use, disclose, copy or distribute this file or
999 + * any information contained herein except pursuant to this license grant from
1000 + * Synopsys. If you do not agree with this notice, including the disclaimer
1001 + * below, then you are not authorized to use the Software.
1002 + *
1003 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
1004 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1005 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1006 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
1007 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1008 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1009 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1010 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1011 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1012 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1013 + * DAMAGE.
1014 + * ========================================================================== */
1015 +
1016 +/** @file
1017 + *
1018 + * The Core Interface Layer provides basic services for accessing and
1019 + * managing the DWC_otg hardware. These services are used by both the
1020 + * Host Controller Driver and the Peripheral Controller Driver.
1021 + *
1022 + * The CIL manages the memory map for the core so that the HCD and PCD
1023 + * don't have to do this separately. It also handles basic tasks like
1024 + * reading/writing the registers and data FIFOs in the controller.
1025 + * Some of the data access functions provide encapsulation of several
1026 + * operations required to perform a task, such as writing multiple
1027 + * registers to start a transfer. Finally, the CIL performs basic
1028 + * services that are not specific to either the host or device modes
1029 + * of operation. These services include management of the OTG Host
1030 + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
1031 + * Diagnostic API is also provided to allow testing of the controller
1032 + * hardware.
1033 + *
1034 + * The Core Interface Layer has the following requirements:
1035 + * - Provides basic controller operations.
1036 + * - Minimal use of OS services.
1037 + * - The OS services used will be abstracted by using inline functions
1038 + * or macros.
1039 + *
1040 + */
1041 +#include <asm/unaligned.h>
1042 +
1043 +#ifdef DEBUG
1044 +#include <linux/jiffies.h>
1045 +#endif
1046 +
1047 +#include "dwc_otg_plat.h"
1048 +
1049 +#include "dwc_otg_regs.h"
1050 +#include "dwc_otg_cil.h"
1051 +
1052 +/**
1053 + * This function is called to initialize the DWC_otg CSR data
1054 + * structures. The register addresses in the device and host
1055 + * structures are initialized from the base address supplied by the
1056 + * caller. The calling function must make the OS calls to get the
1057 + * base address of the DWC_otg controller registers. The core_params
1058 + * argument holds the parameters that specify how the core should be
1059 + * configured.
1060 + *
1061 + * @param[in] _reg_base_addr Base address of DWC_otg core registers
1062 + * @param[in] _core_params Pointer to the core configuration parameters
1063 + *
1064 + */
1065 +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
1066 + dwc_otg_core_params_t *_core_params)
1067 +{
1068 + dwc_otg_core_if_t *core_if = 0;
1069 + dwc_otg_dev_if_t *dev_if = 0;
1070 + dwc_otg_host_if_t *host_if = 0;
1071 + uint8_t *reg_base = (uint8_t *)_reg_base_addr;
1072 + int i = 0;
1073 +
1074 + DWC_DEBUGPL(DBG_CILV, "%s(%p,%p)\n", __func__, _reg_base_addr, _core_params);
1075 +
1076 + core_if = kmalloc( sizeof(dwc_otg_core_if_t), GFP_KERNEL);
1077 + if (core_if == 0) {
1078 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_core_if_t failed\n");
1079 + return 0;
1080 + }
1081 + memset(core_if, 0, sizeof(dwc_otg_core_if_t));
1082 +
1083 + core_if->core_params = _core_params;
1084 + core_if->core_global_regs = (dwc_otg_core_global_regs_t *)reg_base;
1085 + /*
1086 + * Allocate the Device Mode structures.
1087 + */
1088 + dev_if = kmalloc( sizeof(dwc_otg_dev_if_t), GFP_KERNEL);
1089 + if (dev_if == 0) {
1090 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
1091 + kfree( core_if );
1092 + return 0;
1093 + }
1094 +
1095 + dev_if->dev_global_regs =
1096 + (dwc_otg_device_global_regs_t *)(reg_base + DWC_DEV_GLOBAL_REG_OFFSET);
1097 +
1098 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1099 + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
1100 + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
1101 + (i * DWC_EP_REG_OFFSET));
1102 +
1103 + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
1104 + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
1105 + (i * DWC_EP_REG_OFFSET));
1106 + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
1107 + i, &dev_if->in_ep_regs[i]->diepctl);
1108 + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
1109 + i, &dev_if->out_ep_regs[i]->doepctl);
1110 + }
1111 + dev_if->speed = 0; // unknown
1112 + //dev_if->num_eps = MAX_EPS_CHANNELS;
1113 + //dev_if->num_perio_eps = 0;
1114 +
1115 + core_if->dev_if = dev_if;
1116 + /*
1117 + * Allocate the Host Mode structures.
1118 + */
1119 + host_if = kmalloc( sizeof(dwc_otg_host_if_t), GFP_KERNEL);
1120 + if (host_if == 0) {
1121 + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_host_if_t failed\n");
1122 + kfree( dev_if );
1123 + kfree( core_if );
1124 + return 0;
1125 + }
1126 +
1127 + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
1128 + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
1129 + host_if->hprt0 = (uint32_t*)(reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
1130 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1131 + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
1132 + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
1133 + (i * DWC_OTG_CHAN_REGS_OFFSET));
1134 + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
1135 + i, &host_if->hc_regs[i]->hcchar);
1136 + }
1137 + host_if->num_host_channels = MAX_EPS_CHANNELS;
1138 + core_if->host_if = host_if;
1139 +
1140 + for (i=0; i<MAX_EPS_CHANNELS; i++) {
1141 + core_if->data_fifo[i] =
1142 + (uint32_t *)(reg_base + DWC_OTG_DATA_FIFO_OFFSET +
1143 + (i * DWC_OTG_DATA_FIFO_SIZE));
1144 + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08x\n",
1145 + i, (unsigned)core_if->data_fifo[i]);
1146 + } // for loop.
1147 +
1148 + core_if->pcgcctl = (uint32_t*)(reg_base + DWC_OTG_PCGCCTL_OFFSET);
1149 +
1150 + /*
1151 + * Store the contents of the hardware configuration registers here for
1152 + * easy access later.
1153 + */
1154 + core_if->hwcfg1.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg1);
1155 + core_if->hwcfg2.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg2);
1156 + core_if->hwcfg3.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg3);
1157 + core_if->hwcfg4.d32 = dwc_read_reg32(&core_if->core_global_regs->ghwcfg4);
1158 +
1159 + DWC_DEBUGPL(DBG_CILV,"hwcfg1=%08x\n",core_if->hwcfg1.d32);
1160 + DWC_DEBUGPL(DBG_CILV,"hwcfg2=%08x\n",core_if->hwcfg2.d32);
1161 + DWC_DEBUGPL(DBG_CILV,"hwcfg3=%08x\n",core_if->hwcfg3.d32);
1162 + DWC_DEBUGPL(DBG_CILV,"hwcfg4=%08x\n",core_if->hwcfg4.d32);
1163 +
1164 +
1165 + DWC_DEBUGPL(DBG_CILV,"op_mode=%0x\n",core_if->hwcfg2.b.op_mode);
1166 + DWC_DEBUGPL(DBG_CILV,"arch=%0x\n",core_if->hwcfg2.b.architecture);
1167 + DWC_DEBUGPL(DBG_CILV,"num_dev_ep=%d\n",core_if->hwcfg2.b.num_dev_ep);
1168 + DWC_DEBUGPL(DBG_CILV,"num_host_chan=%d\n",core_if->hwcfg2.b.num_host_chan);
1169 + DWC_DEBUGPL(DBG_CILV,"nonperio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.nonperio_tx_q_depth);
1170 + DWC_DEBUGPL(DBG_CILV,"host_perio_tx_q_depth=0x%0x\n",core_if->hwcfg2.b.host_perio_tx_q_depth);
1171 + DWC_DEBUGPL(DBG_CILV,"dev_token_q_depth=0x%0x\n",core_if->hwcfg2.b.dev_token_q_depth);
1172 +
1173 + DWC_DEBUGPL(DBG_CILV,"Total FIFO SZ=%d\n", core_if->hwcfg3.b.dfifo_depth);
1174 + DWC_DEBUGPL(DBG_CILV,"xfer_size_cntr_width=%0x\n", core_if->hwcfg3.b.xfer_size_cntr_width);
1175 +
1176 + /*
1177 + * Set the SRP sucess bit for FS-I2c
1178 + */
1179 + core_if->srp_success = 0;
1180 + core_if->srp_timer_started = 0;
1181 +
1182 + return core_if;
1183 +}
1184 +/**
1185 + * This function frees the structures allocated by dwc_otg_cil_init().
1186 + *
1187 + * @param[in] _core_if The core interface pointer returned from
1188 + * dwc_otg_cil_init().
1189 + *
1190 + */
1191 +void dwc_otg_cil_remove( dwc_otg_core_if_t *_core_if )
1192 +{
1193 + /* Disable all interrupts */
1194 + dwc_modify_reg32( &_core_if->core_global_regs->gahbcfg, 1, 0);
1195 + dwc_write_reg32( &_core_if->core_global_regs->gintmsk, 0);
1196 +
1197 + if ( _core_if->dev_if ) {
1198 + kfree( _core_if->dev_if );
1199 + }
1200 + if ( _core_if->host_if ) {
1201 + kfree( _core_if->host_if );
1202 + }
1203 + kfree( _core_if );
1204 +}
1205 +
1206 +/**
1207 + * This function enables the controller's Global Interrupt in the AHB Config
1208 + * register.
1209 + *
1210 + * @param[in] _core_if Programming view of DWC_otg controller.
1211 + */
1212 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if )
1213 +{
1214 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1215 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
1216 + dwc_modify_reg32(&_core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
1217 +}
1218 +/**
1219 + * This function disables the controller's Global Interrupt in the AHB Config
1220 + * register.
1221 + *
1222 + * @param[in] _core_if Programming view of DWC_otg controller.
1223 + */
1224 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if )
1225 +{
1226 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1227 + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
1228 + dwc_modify_reg32(&_core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
1229 +}
1230 +
1231 +/**
1232 + * This function initializes the commmon interrupts, used in both
1233 + * device and host modes.
1234 + *
1235 + * @param[in] _core_if Programming view of the DWC_otg controller
1236 + *
1237 + */
1238 +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t *_core_if)
1239 +{
1240 + dwc_otg_core_global_regs_t *global_regs =
1241 + _core_if->core_global_regs;
1242 + gintmsk_data_t intr_mask = { .d32 = 0};
1243 + /* Clear any pending OTG Interrupts */
1244 + dwc_write_reg32( &global_regs->gotgint, 0xFFFFFFFF);
1245 + /* Clear any pending interrupts */
1246 + dwc_write_reg32( &global_regs->gintsts, 0xFFFFFFFF);
1247 + /*
1248 + * Enable the interrupts in the GINTMSK.
1249 + */
1250 + intr_mask.b.modemismatch = 1;
1251 + intr_mask.b.otgintr = 1;
1252 + if (!_core_if->dma_enable) {
1253 + intr_mask.b.rxstsqlvl = 1;
1254 + }
1255 + intr_mask.b.conidstschng = 1;
1256 + intr_mask.b.wkupintr = 1;
1257 + intr_mask.b.disconnect = 1;
1258 + intr_mask.b.usbsuspend = 1;
1259 + intr_mask.b.sessreqintr = 1;
1260 + dwc_write_reg32( &global_regs->gintmsk, intr_mask.d32);
1261 +}
1262 +
1263 +/**
1264 + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
1265 + * type.
1266 + */
1267 +static void init_fslspclksel(dwc_otg_core_if_t *_core_if)
1268 +{
1269 + uint32_t val;
1270 + hcfg_data_t hcfg;
1271 +
1272 + if (((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1273 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1274 + (_core_if->core_params->ulpi_fs_ls)) ||
1275 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS))
1276 + {
1277 + /* Full speed PHY */
1278 + val = DWC_HCFG_48_MHZ;
1279 + } else {
1280 + /* High speed PHY running at full speed or high speed */
1281 + val = DWC_HCFG_30_60_MHZ;
1282 + }
1283 +
1284 + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
1285 + hcfg.d32 = dwc_read_reg32(&_core_if->host_if->host_global_regs->hcfg);
1286 + hcfg.b.fslspclksel = val;
1287 + dwc_write_reg32(&_core_if->host_if->host_global_regs->hcfg, hcfg.d32);
1288 +}
1289 +
1290 +/**
1291 + * Initializes the DevSpd field of the DCFG register depending on the PHY type
1292 + * and the enumeration speed of the device.
1293 + */
1294 +static void init_devspd(dwc_otg_core_if_t *_core_if)
1295 +{
1296 + uint32_t val;
1297 + dcfg_data_t dcfg;
1298 +
1299 + if (((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1300 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1301 + (_core_if->core_params->ulpi_fs_ls)) ||
1302 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS))
1303 + {
1304 + /* Full speed PHY */
1305 + val = 0x3;
1306 + } else if (_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
1307 + /* High speed PHY running at full speed */
1308 + val = 0x1;
1309 + } else {
1310 + /* High speed PHY running at high speed */
1311 + val = 0x0;
1312 + }
1313 +
1314 + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
1315 + dcfg.d32 = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->dcfg);
1316 + dcfg.b.devspd = val;
1317 + dwc_write_reg32(&_core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
1318 +}
1319 +
1320 +/**
1321 + * This function calculates the number of IN EPS
1322 + * using GHWCFG1 and GHWCFG2 registers values
1323 + *
1324 + * @param _pcd the pcd structure.
1325 + */
1326 +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * _core_if)
1327 +{
1328 + uint32_t num_in_eps = 0;
1329 + uint32_t num_eps = _core_if->hwcfg2.b.num_dev_ep;
1330 + uint32_t hwcfg1 = _core_if->hwcfg1.d32 >> 2;
1331 + uint32_t num_tx_fifos = _core_if->hwcfg4.b.num_in_eps;
1332 + int i;
1333 + for (i = 0; i < num_eps; ++i) {
1334 + if (!(hwcfg1 & 0x1))
1335 + num_in_eps++;
1336 + hwcfg1 >>= 2;
1337 + }
1338 + if (_core_if->hwcfg4.b.ded_fifo_en) {
1339 + num_in_eps = (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
1340 + }
1341 + return num_in_eps;
1342 +}
1343 +
1344 +
1345 +/**
1346 + * This function calculates the number of OUT EPS
1347 + * using GHWCFG1 and GHWCFG2 registers values
1348 + *
1349 + * @param _pcd the pcd structure.
1350 + */
1351 +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * _core_if)
1352 +{
1353 + uint32_t num_out_eps = 0;
1354 + uint32_t num_eps = _core_if->hwcfg2.b.num_dev_ep;
1355 + uint32_t hwcfg1 = _core_if->hwcfg1.d32 >> 2;
1356 + int i;
1357 + for (i = 0; i < num_eps; ++i) {
1358 + if (!(hwcfg1 & 0x2))
1359 + num_out_eps++;
1360 + hwcfg1 >>= 2;
1361 + }
1362 + return num_out_eps;
1363 +}
1364 +/**
1365 + * This function initializes the DWC_otg controller registers and
1366 + * prepares the core for device mode or host mode operation.
1367 + *
1368 + * @param _core_if Programming view of the DWC_otg controller
1369 + *
1370 + */
1371 +void dwc_otg_core_init(dwc_otg_core_if_t *_core_if)
1372 +{
1373 + dwc_otg_core_global_regs_t * global_regs = _core_if->core_global_regs;
1374 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1375 + int i = 0;
1376 + gahbcfg_data_t ahbcfg = { .d32 = 0};
1377 + gusbcfg_data_t usbcfg = { .d32 = 0 };
1378 + gi2cctl_data_t i2cctl = {.d32 = 0};
1379 +
1380 + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p)\n",_core_if);
1381 +
1382 + /* Common Initialization */
1383 +
1384 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1385 + DWC_DEBUGPL(DBG_CIL, "USB config register: 0x%08x\n", usbcfg.d32);
1386 +
1387 + /* Program the ULPI External VBUS bit if needed */
1388 + //usbcfg.b.ulpi_ext_vbus_drv = 1;
1389 + //usbcfg.b.ulpi_ext_vbus_drv = 0;
1390 + usbcfg.b.ulpi_ext_vbus_drv =
1391 + (_core_if->core_params->phy_ulpi_ext_vbus == DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
1392 +
1393 + /* Set external TS Dline pulsing */
1394 + usbcfg.b.term_sel_dl_pulse = (_core_if->core_params->ts_dline == 1) ? 1 : 0;
1395 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1396 +
1397 + /* Reset the Controller */
1398 + dwc_otg_core_reset( _core_if );
1399 +
1400 + /* Initialize parameters from Hardware configuration registers. */
1401 +#if 0
1402 + dev_if->num_eps = _core_if->hwcfg2.b.num_dev_ep;
1403 + dev_if->num_perio_eps = _core_if->hwcfg4.b.num_dev_perio_in_ep;
1404 +#else
1405 + dev_if->num_in_eps = calc_num_in_eps(_core_if);
1406 + dev_if->num_out_eps = calc_num_out_eps(_core_if);
1407 +#endif
1408 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
1409 + _core_if->hwcfg4.b.num_dev_perio_in_ep);
1410 + DWC_DEBUGPL(DBG_CIL, "Is power optimization enabled? %s\n",
1411 + _core_if->hwcfg4.b.power_optimiz ? "Yes" : "No");
1412 + DWC_DEBUGPL(DBG_CIL, "vbus_valid filter enabled? %s\n",
1413 + _core_if->hwcfg4.b.vbus_valid_filt_en ? "Yes" : "No");
1414 + DWC_DEBUGPL(DBG_CIL, "iddig filter enabled? %s\n",
1415 + _core_if->hwcfg4.b.iddig_filt_en ? "Yes" : "No");
1416 +
1417 + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",_core_if->hwcfg4.b.num_dev_perio_in_ep);
1418 + for (i=0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
1419 + dev_if->perio_tx_fifo_size[i] =
1420 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
1421 + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n", i,
1422 + dev_if->perio_tx_fifo_size[i]);
1423 + }
1424 + for (i = 0; i < _core_if->hwcfg4.b.num_in_eps; i++) {
1425 + dev_if->tx_fifo_size[i] =
1426 + dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]) >> 16;
1427 + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n", i,
1428 + dev_if->perio_tx_fifo_size[i]);
1429 + }
1430 +
1431 + _core_if->total_fifo_size = _core_if->hwcfg3.b.dfifo_depth;
1432 + _core_if->rx_fifo_size = dwc_read_reg32(&global_regs->grxfsiz);
1433 + _core_if->nperio_tx_fifo_size = dwc_read_reg32(&global_regs->gnptxfsiz) >> 16;
1434 +
1435 + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", _core_if->total_fifo_size);
1436 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", _core_if->rx_fifo_size);
1437 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n", _core_if->nperio_tx_fifo_size);
1438 +
1439 + /* This programming sequence needs to happen in FS mode before any other
1440 + * programming occurs */
1441 + if ((_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
1442 + (_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
1443 + /* If FS mode with FS PHY */
1444 +
1445 + /* core_init() is now called on every switch so only call the
1446 + * following for the first time through. */
1447 + if (!_core_if->phy_init_done) {
1448 + _core_if->phy_init_done = 1;
1449 + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
1450 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1451 + usbcfg.b.physel = 1;
1452 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1453 +
1454 + /* Reset after a PHY select */
1455 + dwc_otg_core_reset( _core_if );
1456 + }
1457 +
1458 + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
1459 + * do this on HNP Dev/Host mode switches (done in dev_init and
1460 + * host_init). */
1461 + if (dwc_otg_is_host_mode(_core_if)) {
1462 + DWC_DEBUGPL(DBG_CIL, "host mode\n");
1463 + init_fslspclksel(_core_if);
1464 + } else {
1465 + DWC_DEBUGPL(DBG_CIL, "device mode\n");
1466 + init_devspd(_core_if);
1467 + }
1468 +
1469 + if (_core_if->core_params->i2c_enable) {
1470 + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
1471 + /* Program GUSBCFG.OtgUtmifsSel to I2C */
1472 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1473 + usbcfg.b.otgutmifssel = 1;
1474 + dwc_write_reg32 (&global_regs->gusbcfg, usbcfg.d32);
1475 +
1476 + /* Program GI2CCTL.I2CEn */
1477 + i2cctl.d32 = dwc_read_reg32(&global_regs->gi2cctl);
1478 + i2cctl.b.i2cdevaddr = 1;
1479 + i2cctl.b.i2cen = 0;
1480 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
1481 + i2cctl.b.i2cen = 1;
1482 + dwc_write_reg32 (&global_regs->gi2cctl, i2cctl.d32);
1483 + }
1484 +
1485 + } /* endif speed == DWC_SPEED_PARAM_FULL */
1486 + else {
1487 + /* High speed PHY. */
1488 + if (!_core_if->phy_init_done) {
1489 + _core_if->phy_init_done = 1;
1490 + DWC_DEBUGPL(DBG_CIL, "High spped PHY\n");
1491 + /* HS PHY parameters. These parameters are preserved
1492 + * during soft reset so only program the first time. Do
1493 + * a soft reset immediately after setting phyif. */
1494 + usbcfg.b.ulpi_utmi_sel = _core_if->core_params->phy_type;
1495 + if (usbcfg.b.ulpi_utmi_sel == 2) { // winder
1496 + DWC_DEBUGPL(DBG_CIL, "ULPI\n");
1497 + /* ULPI interface */
1498 + usbcfg.b.phyif = 0;
1499 + usbcfg.b.ddrsel = _core_if->core_params->phy_ulpi_ddr;
1500 + } else {
1501 + /* UTMI+ interface */
1502 + if (_core_if->core_params->phy_utmi_width == 16) {
1503 + usbcfg.b.phyif = 1;
1504 + DWC_DEBUGPL(DBG_CIL, "UTMI+ 16\n");
1505 + } else {
1506 + DWC_DEBUGPL(DBG_CIL, "UTMI+ 8\n");
1507 + usbcfg.b.phyif = 0;
1508 + }
1509 + }
1510 + dwc_write_reg32( &global_regs->gusbcfg, usbcfg.d32);
1511 +
1512 + /* Reset after setting the PHY parameters */
1513 + dwc_otg_core_reset( _core_if );
1514 + }
1515 + }
1516 +
1517 + if ((_core_if->hwcfg2.b.hs_phy_type == 2) &&
1518 + (_core_if->hwcfg2.b.fs_phy_type == 1) &&
1519 + (_core_if->core_params->ulpi_fs_ls))
1520 + {
1521 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
1522 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1523 + usbcfg.b.ulpi_fsls = 1;
1524 + usbcfg.b.ulpi_clk_sus_m = 1;
1525 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
1526 + } else {
1527 + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS=0\n");
1528 + usbcfg.d32 = dwc_read_reg32(&global_regs->gusbcfg);
1529 + usbcfg.b.ulpi_fsls = 0;
1530 + usbcfg.b.ulpi_clk_sus_m = 0;
1531 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
1532 + }
1533 +
1534 + /* Program the GAHBCFG Register.*/
1535 + switch (_core_if->hwcfg2.b.architecture){
1536 +
1537 + case DWC_SLAVE_ONLY_ARCH:
1538 + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
1539 + ahbcfg.b.nptxfemplvl_txfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
1540 + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
1541 + _core_if->dma_enable = 0;
1542 + break;
1543 +
1544 + case DWC_EXT_DMA_ARCH:
1545 + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
1546 + ahbcfg.b.hburstlen = _core_if->core_params->dma_burst_size;
1547 + _core_if->dma_enable = (_core_if->core_params->dma_enable != 0);
1548 + break;
1549 +
1550 + case DWC_INT_DMA_ARCH:
1551 + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
1552 + //ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR;
1553 + ahbcfg.b.hburstlen = DWC_GAHBCFG_INT_DMA_BURST_INCR4;
1554 + _core_if->dma_enable = (_core_if->core_params->dma_enable != 0);
1555 + break;
1556 + }
1557 + ahbcfg.b.dmaenable = _core_if->dma_enable;
1558 + dwc_write_reg32(&global_regs->gahbcfg, ahbcfg.d32);
1559 + _core_if->en_multiple_tx_fifo = _core_if->hwcfg4.b.ded_fifo_en;
1560 +
1561 + /*
1562 + * Program the GUSBCFG register.
1563 + */
1564 + usbcfg.d32 = dwc_read_reg32( &global_regs->gusbcfg );
1565 +
1566 + switch (_core_if->hwcfg2.b.op_mode) {
1567 + case DWC_MODE_HNP_SRP_CAPABLE:
1568 + usbcfg.b.hnpcap = (_core_if->core_params->otg_cap ==
1569 + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
1570 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1571 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1572 + break;
1573 +
1574 + case DWC_MODE_SRP_ONLY_CAPABLE:
1575 + usbcfg.b.hnpcap = 0;
1576 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1577 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1578 + break;
1579 +
1580 + case DWC_MODE_NO_HNP_SRP_CAPABLE:
1581 + usbcfg.b.hnpcap = 0;
1582 + usbcfg.b.srpcap = 0;
1583 + break;
1584 +
1585 + case DWC_MODE_SRP_CAPABLE_DEVICE:
1586 + usbcfg.b.hnpcap = 0;
1587 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1588 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1589 + break;
1590 +
1591 + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
1592 + usbcfg.b.hnpcap = 0;
1593 + usbcfg.b.srpcap = 0;
1594 + break;
1595 +
1596 + case DWC_MODE_SRP_CAPABLE_HOST:
1597 + usbcfg.b.hnpcap = 0;
1598 + usbcfg.b.srpcap = (_core_if->core_params->otg_cap !=
1599 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
1600 + break;
1601 +
1602 + case DWC_MODE_NO_SRP_CAPABLE_HOST:
1603 + usbcfg.b.hnpcap = 0;
1604 + usbcfg.b.srpcap = 0;
1605 + break;
1606 + }
1607 +
1608 + dwc_write_reg32( &global_regs->gusbcfg, usbcfg.d32);
1609 +
1610 + /* Enable common interrupts */
1611 + dwc_otg_enable_common_interrupts( _core_if );
1612 +
1613 + /* Do device or host intialization based on mode during PCD
1614 + * and HCD initialization */
1615 + if (dwc_otg_is_host_mode( _core_if )) {
1616 + DWC_DEBUGPL(DBG_ANY, "Host Mode\n" );
1617 + _core_if->op_state = A_HOST;
1618 + } else {
1619 + DWC_DEBUGPL(DBG_ANY, "Device Mode\n" );
1620 + _core_if->op_state = B_PERIPHERAL;
1621 +#ifdef DWC_DEVICE_ONLY
1622 + dwc_otg_core_dev_init( _core_if );
1623 +#endif
1624 + }
1625 +}
1626 +
1627 +
1628 +/**
1629 + * This function enables the Device mode interrupts.
1630 + *
1631 + * @param _core_if Programming view of DWC_otg controller
1632 + */
1633 +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if)
1634 +{
1635 + gintmsk_data_t intr_mask = { .d32 = 0};
1636 + dwc_otg_core_global_regs_t * global_regs = _core_if->core_global_regs;
1637 +
1638 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
1639 +
1640 + /* Disable all interrupts. */
1641 + dwc_write_reg32( &global_regs->gintmsk, 0);
1642 +
1643 + /* Clear any pending interrupts */
1644 + dwc_write_reg32( &global_regs->gintsts, 0xFFFFFFFF);
1645 +
1646 + /* Enable the common interrupts */
1647 + dwc_otg_enable_common_interrupts( _core_if );
1648 +
1649 + /* Enable interrupts */
1650 + intr_mask.b.usbreset = 1;
1651 + intr_mask.b.enumdone = 1;
1652 + //intr_mask.b.epmismatch = 1;
1653 + intr_mask.b.inepintr = 1;
1654 + intr_mask.b.outepintr = 1;
1655 + intr_mask.b.erlysuspend = 1;
1656 + if (_core_if->en_multiple_tx_fifo == 0) {
1657 + intr_mask.b.epmismatch = 1;
1658 + }
1659 +
1660 + /** @todo NGS: Should this be a module parameter? */
1661 + intr_mask.b.isooutdrop = 1;
1662 + intr_mask.b.eopframe = 1;
1663 + intr_mask.b.incomplisoin = 1;
1664 + intr_mask.b.incomplisoout = 1;
1665 +
1666 + dwc_modify_reg32( &global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1667 +
1668 + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
1669 + dwc_read_reg32( &global_regs->gintmsk));
1670 +}
1671 +
1672 +/**
1673 + * This function initializes the DWC_otg controller registers for
1674 + * device mode.
1675 + *
1676 + * @param _core_if Programming view of DWC_otg controller
1677 + *
1678 + */
1679 +void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if)
1680 +{
1681 + dwc_otg_core_global_regs_t *global_regs =
1682 + _core_if->core_global_regs;
1683 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
1684 + dwc_otg_core_params_t *params = _core_if->core_params;
1685 + dcfg_data_t dcfg = {.d32 = 0};
1686 + grstctl_t resetctl = { .d32=0 };
1687 + int i;
1688 + uint32_t rx_fifo_size;
1689 + fifosize_data_t nptxfifosize;
1690 + fifosize_data_t txfifosize;
1691 + dthrctl_data_t dthrctl;
1692 +
1693 + fifosize_data_t ptxfifosize;
1694 +
1695 + /* Restart the Phy Clock */
1696 + dwc_write_reg32(_core_if->pcgcctl, 0);
1697 +
1698 + /* Device configuration register */
1699 + init_devspd(_core_if);
1700 + dcfg.d32 = dwc_read_reg32( &dev_if->dev_global_regs->dcfg);
1701 + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
1702 + dwc_write_reg32( &dev_if->dev_global_regs->dcfg, dcfg.d32 );
1703 +
1704 + /* Configure data FIFO sizes */
1705 + if ( _core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo ) {
1706 +
1707 + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n", _core_if->total_fifo_size);
1708 + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n", params->dev_rx_fifo_size);
1709 + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n", params->dev_nperio_tx_fifo_size);
1710 +
1711 + /* Rx FIFO */
1712 + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
1713 + dwc_read_reg32(&global_regs->grxfsiz));
1714 + rx_fifo_size = params->dev_rx_fifo_size;
1715 + dwc_write_reg32( &global_regs->grxfsiz, rx_fifo_size );
1716 + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
1717 + dwc_read_reg32(&global_regs->grxfsiz));
1718 +
1719 + /** Set Periodic Tx FIFO Mask all bits 0 */
1720 + _core_if->p_tx_msk = 0;
1721 +
1722 + /** Set Tx FIFO Mask all bits 0 */
1723 + _core_if->tx_msk = 0;
1724 + if (_core_if->en_multiple_tx_fifo == 0) {
1725 + /* Non-periodic Tx FIFO */
1726 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
1727 + dwc_read_reg32(&global_regs->gnptxfsiz));
1728 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
1729 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
1730 + dwc_write_reg32( &global_regs->gnptxfsiz, nptxfifosize.d32 );
1731 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
1732 + dwc_read_reg32(&global_regs->gnptxfsiz));
1733 +
1734 +
1735 + /**@todo NGS: Fix Periodic FIFO Sizing! */
1736 + /*
1737 + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
1738 + * Indexes of the FIFO size module parameters in the
1739 + * dev_perio_tx_fifo_size array and the FIFO size registers in
1740 + * the dptxfsiz array run from 0 to 14.
1741 + */
1742 + /** @todo Finish debug of this */
1743 + ptxfifosize.b.startaddr =
1744 + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
1745 + for (i = 0; i < _core_if->hwcfg4.b.num_dev_perio_in_ep;i++) {
1746 + ptxfifosize.b.depth = params->dev_perio_tx_fifo_size[i];
1747 + DWC_DEBUGPL(DBG_CIL,"initial dptxfsiz_dieptxf[%d]=%08x\n",
1748 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1749 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i],ptxfifosize.d32);
1750 + DWC_DEBUGPL(DBG_CIL,"new dptxfsiz_dieptxf[%d]=%08x\n",
1751 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1752 + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
1753 + }
1754 + } else {
1755 +
1756 + /*
1757 + * Tx FIFOs These FIFOs are numbered from 1 to 15.
1758 + * Indexes of the FIFO size module parameters in the
1759 + * dev_tx_fifo_size array and the FIFO size registers in
1760 + * the dptxfsiz_dieptxf array run from 0 to 14.
1761 + */
1762 +
1763 + /* Non-periodic Tx FIFO */
1764 + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
1765 + dwc_read_reg32(&global_regs->gnptxfsiz));
1766 + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
1767 + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
1768 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
1769 + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
1770 + dwc_read_reg32(&global_regs->gnptxfsiz));
1771 + txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
1772 + for (i = 1;i < _core_if->hwcfg4.b.num_dev_perio_in_ep;i++) {
1773 + txfifosize.b.depth = params->dev_tx_fifo_size[i];
1774 + DWC_DEBUGPL(DBG_CIL,"initial dptxfsiz_dieptxf[%d]=%08x\n",
1775 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i]));
1776 + dwc_write_reg32(&global_regs->dptxfsiz_dieptxf[i - 1],txfifosize.d32);
1777 + DWC_DEBUGPL(DBG_CIL,"new dptxfsiz_dieptxf[%d]=%08x\n",
1778 + i,dwc_read_reg32(&global_regs->dptxfsiz_dieptxf[i-1]));
1779 + txfifosize.b.startaddr += txfifosize.b.depth;
1780 + }
1781 + }
1782 + }
1783 + /* Flush the FIFOs */
1784 + dwc_otg_flush_tx_fifo(_core_if, 0x10); /* all Tx FIFOs */
1785 + dwc_otg_flush_rx_fifo(_core_if);
1786 +
1787 + /* Flush the Learning Queue. */
1788 + resetctl.b.intknqflsh = 1;
1789 + dwc_write_reg32( &_core_if->core_global_regs->grstctl, resetctl.d32);
1790 +
1791 + /* Clear all pending Device Interrupts */
1792 + dwc_write_reg32( &dev_if->dev_global_regs->diepmsk, 0 );
1793 + dwc_write_reg32( &dev_if->dev_global_regs->doepmsk, 0 );
1794 + dwc_write_reg32( &dev_if->dev_global_regs->daint, 0xFFFFFFFF );
1795 + dwc_write_reg32( &dev_if->dev_global_regs->daintmsk, 0 );
1796 +
1797 + for (i = 0; i <= dev_if->num_in_eps; i++) {
1798 + depctl_data_t depctl;
1799 + depctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[i]->diepctl);
1800 + if (depctl.b.epena) {
1801 + depctl.d32 = 0;
1802 + depctl.b.epdis = 1;
1803 + depctl.b.snak = 1;
1804 + } else {
1805 + depctl.d32 = 0;
1806 + }
1807 + dwc_write_reg32( &dev_if->in_ep_regs[i]->diepctl, depctl.d32);
1808 +
1809 + dwc_write_reg32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
1810 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepdma, 0);
1811 + dwc_write_reg32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
1812 + }
1813 + for (i = 0; i <= dev_if->num_out_eps; i++) {
1814 + depctl_data_t depctl;
1815 + depctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[i]->doepctl);
1816 + if (depctl.b.epena) {
1817 + depctl.d32 = 0;
1818 + depctl.b.epdis = 1;
1819 + depctl.b.snak = 1;
1820 + } else {
1821 + depctl.d32 = 0;
1822 + }
1823 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepctl, depctl.d32);
1824 +
1825 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->dieptsiz, 0);
1826 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doeptsiz, 0);
1827 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->diepdma, 0);
1828 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepdma, 0);
1829 + //dwc_write_reg32( &dev_if->in_ep_regs[i]->diepint, 0xFF);
1830 + dwc_write_reg32( &dev_if->out_ep_regs[i]->doepint, 0xFF);
1831 + }
1832 +
1833 + if (_core_if->en_multiple_tx_fifo && _core_if->dma_enable) {
1834 + dev_if->non_iso_tx_thr_en = _core_if->core_params->thr_ctl & 0x1;
1835 + dev_if->iso_tx_thr_en = (_core_if->core_params->thr_ctl >> 1) & 0x1;
1836 + dev_if->rx_thr_en = (_core_if->core_params->thr_ctl >> 2) & 0x1;
1837 + dev_if->rx_thr_length = _core_if->core_params->rx_thr_length;
1838 + dev_if->tx_thr_length = _core_if->core_params->tx_thr_length;
1839 + dthrctl.d32 = 0;
1840 + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
1841 + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
1842 + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
1843 + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
1844 + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
1845 + dwc_write_reg32(&dev_if->dev_global_regs->dtknqr3_dthrctl,dthrctl.d32);
1846 + DWC_DEBUGPL(DBG_CIL, "Non ISO Tx Thr - %d\nISO Tx Thr - %d\n"
1847 + "Rx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
1848 + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
1849 + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
1850 + dthrctl.b.rx_thr_len);
1851 + }
1852 + dwc_otg_enable_device_interrupts( _core_if );
1853 + {
1854 + diepmsk_data_t msk = {.d32 = 0};
1855 + msk.b.txfifoundrn = 1;
1856 + dwc_modify_reg32(&dev_if->dev_global_regs->diepmsk, msk.d32,msk.d32);
1857 +}
1858 +}
1859 +
1860 +/**
1861 + * This function enables the Host mode interrupts.
1862 + *
1863 + * @param _core_if Programming view of DWC_otg controller
1864 + */
1865 +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if)
1866 +{
1867 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
1868 + gintmsk_data_t intr_mask = {.d32 = 0};
1869 +
1870 + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
1871 +
1872 + /* Disable all interrupts. */
1873 + dwc_write_reg32(&global_regs->gintmsk, 0);
1874 +
1875 + /* Clear any pending interrupts. */
1876 + dwc_write_reg32(&global_regs->gintsts, 0xFFFFFFFF);
1877 +
1878 + /* Enable the common interrupts */
1879 + dwc_otg_enable_common_interrupts(_core_if);
1880 +
1881 + /*
1882 + * Enable host mode interrupts without disturbing common
1883 + * interrupts.
1884 + */
1885 + intr_mask.b.sofintr = 1;
1886 + intr_mask.b.portintr = 1;
1887 + intr_mask.b.hcintr = 1;
1888 +
1889 + //dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1890 + //dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
1891 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
1892 +}
1893 +
1894 +/**
1895 + * This function disables the Host Mode interrupts.
1896 + *
1897 + * @param _core_if Programming view of DWC_otg controller
1898 + */
1899 +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if)
1900 +{
1901 + dwc_otg_core_global_regs_t *global_regs =
1902 + _core_if->core_global_regs;
1903 + gintmsk_data_t intr_mask = {.d32 = 0};
1904 +
1905 + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
1906 +
1907 + /*
1908 + * Disable host mode interrupts without disturbing common
1909 + * interrupts.
1910 + */
1911 + intr_mask.b.sofintr = 1;
1912 + intr_mask.b.portintr = 1;
1913 + intr_mask.b.hcintr = 1;
1914 + intr_mask.b.ptxfempty = 1;
1915 + intr_mask.b.nptxfempty = 1;
1916 +
1917 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
1918 +}
1919 +
1920 +#if 1
1921 +/* currently not used, keep it here as if needed later */
1922 +static int phy_read(dwc_otg_core_if_t * _core_if, int addr)
1923 +{
1924 + u32 val;
1925 + int timeout = 10;
1926 +
1927 + dwc_write_reg32(&_core_if->core_global_regs->gpvndctl,
1928 + 0x02000000 | (addr << 16));
1929 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1930 + while (((val & 0x08000000) == 0) && (timeout--)) {
1931 + udelay(1000);
1932 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1933 + }
1934 + val = dwc_read_reg32(&_core_if->core_global_regs->gpvndctl);
1935 + printk("%s: addr=%02x regval=%02x\n", __func__, addr, val & 0x000000ff);
1936 +
1937 + return 0;
1938 +}
1939 +#endif
1940 +
1941 +/**
1942 + * This function initializes the DWC_otg controller registers for
1943 + * host mode.
1944 + *
1945 + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
1946 + * request queues. Host channels are reset to ensure that they are ready for
1947 + * performing transfers.
1948 + *
1949 + * @param _core_if Programming view of DWC_otg controller
1950 + *
1951 + */
1952 +void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if)
1953 +{
1954 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
1955 + dwc_otg_host_if_t *host_if = _core_if->host_if;
1956 + dwc_otg_core_params_t *params = _core_if->core_params;
1957 + hprt0_data_t hprt0 = {.d32 = 0};
1958 + fifosize_data_t nptxfifosize;
1959 + fifosize_data_t ptxfifosize;
1960 + int i;
1961 + hcchar_data_t hcchar;
1962 + hcfg_data_t hcfg;
1963 + dwc_otg_hc_regs_t *hc_regs;
1964 + int num_channels;
1965 + gotgctl_data_t gotgctl = {.d32 = 0};
1966 +
1967 + DWC_DEBUGPL(DBG_CILV,"%s(%p)\n", __func__, _core_if);
1968 +
1969 + /* Restart the Phy Clock */
1970 + dwc_write_reg32(_core_if->pcgcctl, 0);
1971 +
1972 + /* Initialize Host Configuration Register */
1973 + init_fslspclksel(_core_if);
1974 + if (_core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
1975 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
1976 + hcfg.b.fslssupp = 1;
1977 + dwc_write_reg32(&host_if->host_global_regs->hcfg, hcfg.d32);
1978 + }
1979 +
1980 + /* Configure data FIFO sizes */
1981 + if (_core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
1982 + DWC_DEBUGPL(DBG_CIL,"Total FIFO Size=%d\n", _core_if->total_fifo_size);
1983 + DWC_DEBUGPL(DBG_CIL,"Rx FIFO Size=%d\n", params->host_rx_fifo_size);
1984 + DWC_DEBUGPL(DBG_CIL,"NP Tx FIFO Size=%d\n", params->host_nperio_tx_fifo_size);
1985 + DWC_DEBUGPL(DBG_CIL,"P Tx FIFO Size=%d\n", params->host_perio_tx_fifo_size);
1986 +
1987 + /* Rx FIFO */
1988 + DWC_DEBUGPL(DBG_CIL,"initial grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
1989 + dwc_write_reg32(&global_regs->grxfsiz, params->host_rx_fifo_size);
1990 + DWC_DEBUGPL(DBG_CIL,"new grxfsiz=%08x\n", dwc_read_reg32(&global_regs->grxfsiz));
1991 +
1992 + /* Non-periodic Tx FIFO */
1993 + DWC_DEBUGPL(DBG_CIL,"initial gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
1994 + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
1995 + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
1996 + dwc_write_reg32(&global_regs->gnptxfsiz, nptxfifosize.d32);
1997 + DWC_DEBUGPL(DBG_CIL,"new gnptxfsiz=%08x\n", dwc_read_reg32(&global_regs->gnptxfsiz));
1998 +
1999 + /* Periodic Tx FIFO */
2000 + DWC_DEBUGPL(DBG_CIL,"initial hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
2001 + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
2002 + ptxfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
2003 + dwc_write_reg32(&global_regs->hptxfsiz, ptxfifosize.d32);
2004 + DWC_DEBUGPL(DBG_CIL,"new hptxfsiz=%08x\n", dwc_read_reg32(&global_regs->hptxfsiz));
2005 + }
2006 +
2007 + /* Clear Host Set HNP Enable in the OTG Control Register */
2008 + gotgctl.b.hstsethnpen = 1;
2009 + dwc_modify_reg32( &global_regs->gotgctl, gotgctl.d32, 0);
2010 +
2011 + /* Make sure the FIFOs are flushed. */
2012 + dwc_otg_flush_tx_fifo(_core_if, 0x10 /* all Tx FIFOs */);
2013 + dwc_otg_flush_rx_fifo(_core_if);
2014 +
2015 + /* Flush out any leftover queued requests. */
2016 + num_channels = _core_if->core_params->host_channels;
2017 + for (i = 0; i < num_channels; i++) {
2018 + hc_regs = _core_if->host_if->hc_regs[i];
2019 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2020 + hcchar.b.chen = 0;
2021 + hcchar.b.chdis = 1;
2022 + hcchar.b.epdir = 0;
2023 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2024 + }
2025 +
2026 + /* Halt all channels to put them into a known state. */
2027 + for (i = 0; i < num_channels; i++) {
2028 + int count = 0;
2029 + hc_regs = _core_if->host_if->hc_regs[i];
2030 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2031 + hcchar.b.chen = 1;
2032 + hcchar.b.chdis = 1;
2033 + hcchar.b.epdir = 0;
2034 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2035 + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d\n", __func__, i);
2036 + do {
2037 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2038 + if (++count > 200) {
2039 + DWC_ERROR("%s: Unable to clear halt on channel %d\n",
2040 + __func__, i);
2041 + break;
2042 + }
2043 + udelay(100);
2044 + } while (hcchar.b.chen);
2045 + }
2046 +
2047 + /* Turn on the vbus power. */
2048 + DWC_PRINT("Init: Port Power? op_state=%d\n", _core_if->op_state);
2049 + if (_core_if->op_state == A_HOST){
2050 + hprt0.d32 = dwc_otg_read_hprt0(_core_if);
2051 + DWC_PRINT("Init: Power Port (%d)\n", hprt0.b.prtpwr);
2052 + if (hprt0.b.prtpwr == 0 ) {
2053 + hprt0.b.prtpwr = 1;
2054 + dwc_write_reg32(host_if->hprt0, hprt0.d32);
2055 + }
2056 + }
2057 +
2058 + dwc_otg_enable_host_interrupts( _core_if );
2059 +}
2060 +
2061 +/**
2062 + * Prepares a host channel for transferring packets to/from a specific
2063 + * endpoint. The HCCHARn register is set up with the characteristics specified
2064 + * in _hc. Host channel interrupts that may need to be serviced while this
2065 + * transfer is in progress are enabled.
2066 + *
2067 + * @param _core_if Programming view of DWC_otg controller
2068 + * @param _hc Information needed to initialize the host channel
2069 + */
2070 +void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2071 +{
2072 + uint32_t intr_enable;
2073 + hcintmsk_data_t hc_intr_mask;
2074 + gintmsk_data_t gintmsk = {.d32 = 0};
2075 + hcchar_data_t hcchar;
2076 + hcsplt_data_t hcsplt;
2077 +
2078 + uint8_t hc_num = _hc->hc_num;
2079 + dwc_otg_host_if_t *host_if = _core_if->host_if;
2080 + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
2081 +
2082 + /* Clear old interrupt conditions for this host channel. */
2083 + hc_intr_mask.d32 = 0xFFFFFFFF;
2084 + hc_intr_mask.b.reserved = 0;
2085 + dwc_write_reg32(&hc_regs->hcint, hc_intr_mask.d32);
2086 +
2087 + /* Enable channel interrupts required for this transfer. */
2088 + hc_intr_mask.d32 = 0;
2089 + hc_intr_mask.b.chhltd = 1;
2090 + if (_core_if->dma_enable) {
2091 + hc_intr_mask.b.ahberr = 1;
2092 + if (_hc->error_state && !_hc->do_split &&
2093 + _hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
2094 + hc_intr_mask.b.ack = 1;
2095 + if (_hc->ep_is_in) {
2096 + hc_intr_mask.b.datatglerr = 1;
2097 + if (_hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
2098 + hc_intr_mask.b.nak = 1;
2099 + }
2100 + }
2101 + }
2102 + } else {
2103 + switch (_hc->ep_type) {
2104 + case DWC_OTG_EP_TYPE_CONTROL:
2105 + case DWC_OTG_EP_TYPE_BULK:
2106 + hc_intr_mask.b.xfercompl = 1;
2107 + hc_intr_mask.b.stall = 1;
2108 + hc_intr_mask.b.xacterr = 1;
2109 + hc_intr_mask.b.datatglerr = 1;
2110 + if (_hc->ep_is_in) {
2111 + hc_intr_mask.b.bblerr = 1;
2112 + } else {
2113 + hc_intr_mask.b.nak = 1;
2114 + hc_intr_mask.b.nyet = 1;
2115 + if (_hc->do_ping) {
2116 + hc_intr_mask.b.ack = 1;
2117 + }
2118 + }
2119 +
2120 + if (_hc->do_split) {
2121 + hc_intr_mask.b.nak = 1;
2122 + if (_hc->complete_split) {
2123 + hc_intr_mask.b.nyet = 1;
2124 + }
2125 + else {
2126 + hc_intr_mask.b.ack = 1;
2127 + }
2128 + }
2129 +
2130 + if (_hc->error_state) {
2131 + hc_intr_mask.b.ack = 1;
2132 + }
2133 + break;
2134 + case DWC_OTG_EP_TYPE_INTR:
2135 + hc_intr_mask.b.xfercompl = 1;
2136 + hc_intr_mask.b.nak = 1;
2137 + hc_intr_mask.b.stall = 1;
2138 + hc_intr_mask.b.xacterr = 1;
2139 + hc_intr_mask.b.datatglerr = 1;
2140 + hc_intr_mask.b.frmovrun = 1;
2141 +
2142 + if (_hc->ep_is_in) {
2143 + hc_intr_mask.b.bblerr = 1;
2144 + }
2145 + if (_hc->error_state) {
2146 + hc_intr_mask.b.ack = 1;
2147 + }
2148 + if (_hc->do_split) {
2149 + if (_hc->complete_split) {
2150 + hc_intr_mask.b.nyet = 1;
2151 + }
2152 + else {
2153 + hc_intr_mask.b.ack = 1;
2154 + }
2155 + }
2156 + break;
2157 + case DWC_OTG_EP_TYPE_ISOC:
2158 + hc_intr_mask.b.xfercompl = 1;
2159 + hc_intr_mask.b.frmovrun = 1;
2160 + hc_intr_mask.b.ack = 1;
2161 +
2162 + if (_hc->ep_is_in) {
2163 + hc_intr_mask.b.xacterr = 1;
2164 + hc_intr_mask.b.bblerr = 1;
2165 + }
2166 + break;
2167 + }
2168 + }
2169 + dwc_write_reg32(&hc_regs->hcintmsk, hc_intr_mask.d32);
2170 +
2171 + /* Enable the top level host channel interrupt. */
2172 + intr_enable = (1 << hc_num);
2173 + dwc_modify_reg32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
2174 +
2175 + /* Make sure host channel interrupts are enabled. */
2176 + gintmsk.b.hcintr = 1;
2177 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
2178 +
2179 + /*
2180 + * Program the HCCHARn register with the endpoint characteristics for
2181 + * the current transfer.
2182 + */
2183 + hcchar.d32 = 0;
2184 + hcchar.b.devaddr = _hc->dev_addr;
2185 + hcchar.b.epnum = _hc->ep_num;
2186 + hcchar.b.epdir = _hc->ep_is_in;
2187 + hcchar.b.lspddev = (_hc->speed == DWC_OTG_EP_SPEED_LOW);
2188 + hcchar.b.eptype = _hc->ep_type;
2189 + hcchar.b.mps = _hc->max_packet;
2190 +
2191 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
2192 +
2193 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2194 + DWC_DEBUGPL(DBG_HCDV, " Dev Addr: %d\n", hcchar.b.devaddr);
2195 + DWC_DEBUGPL(DBG_HCDV, " Ep Num: %d\n", hcchar.b.epnum);
2196 + DWC_DEBUGPL(DBG_HCDV, " Is In: %d\n", hcchar.b.epdir);
2197 + DWC_DEBUGPL(DBG_HCDV, " Is Low Speed: %d\n", hcchar.b.lspddev);
2198 + DWC_DEBUGPL(DBG_HCDV, " Ep Type: %d\n", hcchar.b.eptype);
2199 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
2200 + DWC_DEBUGPL(DBG_HCDV, " Multi Cnt: %d\n", hcchar.b.multicnt);
2201 +
2202 + /*
2203 + * Program the HCSPLIT register for SPLITs
2204 + */
2205 + hcsplt.d32 = 0;
2206 + if (_hc->do_split) {
2207 + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n", _hc->hc_num,
2208 + _hc->complete_split ? "CSPLIT" : "SSPLIT");
2209 + hcsplt.b.compsplt = _hc->complete_split;
2210 + hcsplt.b.xactpos = _hc->xact_pos;
2211 + hcsplt.b.hubaddr = _hc->hub_addr;
2212 + hcsplt.b.prtaddr = _hc->port_addr;
2213 + DWC_DEBUGPL(DBG_HCDV, " comp split %d\n", _hc->complete_split);
2214 + DWC_DEBUGPL(DBG_HCDV, " xact pos %d\n", _hc->xact_pos);
2215 + DWC_DEBUGPL(DBG_HCDV, " hub addr %d\n", _hc->hub_addr);
2216 + DWC_DEBUGPL(DBG_HCDV, " port addr %d\n", _hc->port_addr);
2217 + DWC_DEBUGPL(DBG_HCDV, " is_in %d\n", _hc->ep_is_in);
2218 + DWC_DEBUGPL(DBG_HCDV, " Max Pkt: %d\n", hcchar.b.mps);
2219 + DWC_DEBUGPL(DBG_HCDV, " xferlen: %d\n", _hc->xfer_len);
2220 + }
2221 + dwc_write_reg32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
2222 +
2223 +}
2224 +
2225 +/**
2226 + * Attempts to halt a host channel. This function should only be called in
2227 + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
2228 + * normal circumstances in DMA mode, the controller halts the channel when the
2229 + * transfer is complete or a condition occurs that requires application
2230 + * intervention.
2231 + *
2232 + * In slave mode, checks for a free request queue entry, then sets the Channel
2233 + * Enable and Channel Disable bits of the Host Channel Characteristics
2234 + * register of the specified channel to intiate the halt. If there is no free
2235 + * request queue entry, sets only the Channel Disable bit of the HCCHARn
2236 + * register to flush requests for this channel. In the latter case, sets a
2237 + * flag to indicate that the host channel needs to be halted when a request
2238 + * queue slot is open.
2239 + *
2240 + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
2241 + * HCCHARn register. The controller ensures there is space in the request
2242 + * queue before submitting the halt request.
2243 + *
2244 + * Some time may elapse before the core flushes any posted requests for this
2245 + * host channel and halts. The Channel Halted interrupt handler completes the
2246 + * deactivation of the host channel.
2247 + *
2248 + * @param _core_if Controller register interface.
2249 + * @param _hc Host channel to halt.
2250 + * @param _halt_status Reason for halting the channel.
2251 + */
2252 +void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
2253 + dwc_hc_t *_hc,
2254 + dwc_otg_halt_status_e _halt_status)
2255 +{
2256 + gnptxsts_data_t nptxsts;
2257 + hptxsts_data_t hptxsts;
2258 + hcchar_data_t hcchar;
2259 + dwc_otg_hc_regs_t *hc_regs;
2260 + dwc_otg_core_global_regs_t *global_regs;
2261 + dwc_otg_host_global_regs_t *host_global_regs;
2262 +
2263 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2264 + global_regs = _core_if->core_global_regs;
2265 + host_global_regs = _core_if->host_if->host_global_regs;
2266 +
2267 + WARN_ON(_halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS);
2268 +
2269 + if (_halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
2270 + _halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
2271 + /*
2272 + * Disable all channel interrupts except Ch Halted. The QTD
2273 + * and QH state associated with this transfer has been cleared
2274 + * (in the case of URB_DEQUEUE), so the channel needs to be
2275 + * shut down carefully to prevent crashes.
2276 + */
2277 + hcintmsk_data_t hcintmsk;
2278 + hcintmsk.d32 = 0;
2279 + hcintmsk.b.chhltd = 1;
2280 + dwc_write_reg32(&hc_regs->hcintmsk, hcintmsk.d32);
2281 +
2282 + /*
2283 + * Make sure no other interrupts besides halt are currently
2284 + * pending. Handling another interrupt could cause a crash due
2285 + * to the QTD and QH state.
2286 + */
2287 + dwc_write_reg32(&hc_regs->hcint, ~hcintmsk.d32);
2288 +
2289 + /*
2290 + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
2291 + * even if the channel was already halted for some other
2292 + * reason.
2293 + */
2294 + _hc->halt_status = _halt_status;
2295 +
2296 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2297 + if (hcchar.b.chen == 0) {
2298 + /*
2299 + * The channel is either already halted or it hasn't
2300 + * started yet. In DMA mode, the transfer may halt if
2301 + * it finishes normally or a condition occurs that
2302 + * requires driver intervention. Don't want to halt
2303 + * the channel again. In either Slave or DMA mode,
2304 + * it's possible that the transfer has been assigned
2305 + * to a channel, but not started yet when an URB is
2306 + * dequeued. Don't want to halt a channel that hasn't
2307 + * started yet.
2308 + */
2309 + return;
2310 + }
2311 + }
2312 +
2313 + if (_hc->halt_pending) {
2314 + /*
2315 + * A halt has already been issued for this channel. This might
2316 + * happen when a transfer is aborted by a higher level in
2317 + * the stack.
2318 + */
2319 +#ifdef DEBUG
2320 + DWC_PRINT("*** %s: Channel %d, _hc->halt_pending already set ***\n",
2321 + __func__, _hc->hc_num);
2322 +
2323 +/* dwc_otg_dump_global_registers(_core_if); */
2324 +/* dwc_otg_dump_host_registers(_core_if); */
2325 +#endif
2326 + return;
2327 + }
2328 +
2329 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2330 + hcchar.b.chen = 1;
2331 + hcchar.b.chdis = 1;
2332 +
2333 + if (!_core_if->dma_enable) {
2334 + /* Check for space in the request queue to issue the halt. */
2335 + if (_hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
2336 + _hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
2337 + nptxsts.d32 = dwc_read_reg32(&global_regs->gnptxsts);
2338 + if (nptxsts.b.nptxqspcavail == 0) {
2339 + hcchar.b.chen = 0;
2340 + }
2341 + } else {
2342 + hptxsts.d32 = dwc_read_reg32(&host_global_regs->hptxsts);
2343 + if ((hptxsts.b.ptxqspcavail == 0) || (_core_if->queuing_high_bandwidth)) {
2344 + hcchar.b.chen = 0;
2345 + }
2346 + }
2347 + }
2348 +
2349 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2350 +
2351 + _hc->halt_status = _halt_status;
2352 +
2353 + if (hcchar.b.chen) {
2354 + _hc->halt_pending = 1;
2355 + _hc->halt_on_queue = 0;
2356 + } else {
2357 + _hc->halt_on_queue = 1;
2358 + }
2359 +
2360 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2361 + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
2362 + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", _hc->halt_pending);
2363 + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", _hc->halt_on_queue);
2364 + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", _hc->halt_status);
2365 +
2366 + return;
2367 +}
2368 +
2369 +/**
2370 + * Clears the transfer state for a host channel. This function is normally
2371 + * called after a transfer is done and the host channel is being released.
2372 + *
2373 + * @param _core_if Programming view of DWC_otg controller.
2374 + * @param _hc Identifies the host channel to clean up.
2375 + */
2376 +void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2377 +{
2378 + dwc_otg_hc_regs_t *hc_regs;
2379 +
2380 + _hc->xfer_started = 0;
2381 +
2382 + /*
2383 + * Clear channel interrupt enables and any unhandled channel interrupt
2384 + * conditions.
2385 + */
2386 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2387 + dwc_write_reg32(&hc_regs->hcintmsk, 0);
2388 + dwc_write_reg32(&hc_regs->hcint, 0xFFFFFFFF);
2389 +
2390 +#ifdef DEBUG
2391 + del_timer(&_core_if->hc_xfer_timer[_hc->hc_num]);
2392 + {
2393 + hcchar_data_t hcchar;
2394 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2395 + if (hcchar.b.chdis) {
2396 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
2397 + __func__, _hc->hc_num, hcchar.d32);
2398 + }
2399 + }
2400 +#endif
2401 +}
2402 +
2403 +/**
2404 + * Sets the channel property that indicates in which frame a periodic transfer
2405 + * should occur. This is always set to the _next_ frame. This function has no
2406 + * effect on non-periodic transfers.
2407 + *
2408 + * @param _core_if Programming view of DWC_otg controller.
2409 + * @param _hc Identifies the host channel to set up and its properties.
2410 + * @param _hcchar Current value of the HCCHAR register for the specified host
2411 + * channel.
2412 + */
2413 +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t *_core_if,
2414 + dwc_hc_t *_hc,
2415 + hcchar_data_t *_hcchar)
2416 +{
2417 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2418 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2419 + hfnum_data_t hfnum;
2420 + hfnum.d32 = dwc_read_reg32(&_core_if->host_if->host_global_regs->hfnum);
2421 + /* 1 if _next_ frame is odd, 0 if it's even */
2422 + _hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
2423 +#ifdef DEBUG
2424 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR && _hc->do_split && !_hc->complete_split) {
2425 + switch (hfnum.b.frnum & 0x7) {
2426 + case 7:
2427 + _core_if->hfnum_7_samples++;
2428 + _core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
2429 + break;
2430 + case 0:
2431 + _core_if->hfnum_0_samples++;
2432 + _core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
2433 + break;
2434 + default:
2435 + _core_if->hfnum_other_samples++;
2436 + _core_if->hfnum_other_frrem_accum += hfnum.b.frrem;
2437 + break;
2438 + }
2439 + }
2440 +#endif
2441 + }
2442 +}
2443 +
2444 +#ifdef DEBUG
2445 +static void hc_xfer_timeout(unsigned long _ptr)
2446 +{
2447 + hc_xfer_info_t *xfer_info = (hc_xfer_info_t *)_ptr;
2448 + int hc_num = xfer_info->hc->hc_num;
2449 + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
2450 + DWC_WARN(" start_hcchar_val 0x%08x\n", xfer_info->core_if->start_hcchar_val[hc_num]);
2451 +}
2452 +#endif
2453 +
2454 +/*
2455 + * This function does the setup for a data transfer for a host channel and
2456 + * starts the transfer. May be called in either Slave mode or DMA mode. In
2457 + * Slave mode, the caller must ensure that there is sufficient space in the
2458 + * request queue and Tx Data FIFO.
2459 + *
2460 + * For an OUT transfer in Slave mode, it loads a data packet into the
2461 + * appropriate FIFO. If necessary, additional data packets will be loaded in
2462 + * the Host ISR.
2463 + *
2464 + * For an IN transfer in Slave mode, a data packet is requested. The data
2465 + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
2466 + * additional data packets are requested in the Host ISR.
2467 + *
2468 + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
2469 + * register along with a packet count of 1 and the channel is enabled. This
2470 + * causes a single PING transaction to occur. Other fields in HCTSIZ are
2471 + * simply set to 0 since no data transfer occurs in this case.
2472 + *
2473 + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
2474 + * all the information required to perform the subsequent data transfer. In
2475 + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
2476 + * controller performs the entire PING protocol, then starts the data
2477 + * transfer.
2478 + *
2479 + * @param _core_if Programming view of DWC_otg controller.
2480 + * @param _hc Information needed to initialize the host channel. The xfer_len
2481 + * value may be reduced to accommodate the max widths of the XferSize and
2482 + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
2483 + * to reflect the final xfer_len value.
2484 + */
2485 +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2486 +{
2487 + hcchar_data_t hcchar;
2488 + hctsiz_data_t hctsiz;
2489 + uint16_t num_packets;
2490 + uint32_t max_hc_xfer_size = _core_if->core_params->max_transfer_size;
2491 + uint16_t max_hc_pkt_count = _core_if->core_params->max_packet_count;
2492 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2493 +
2494 + hctsiz.d32 = 0;
2495 +
2496 + if (_hc->do_ping) {
2497 + if (!_core_if->dma_enable) {
2498 + dwc_otg_hc_do_ping(_core_if, _hc);
2499 + _hc->xfer_started = 1;
2500 + return;
2501 + } else {
2502 + hctsiz.b.dopng = 1;
2503 + }
2504 + }
2505 +
2506 + if (_hc->do_split) {
2507 + num_packets = 1;
2508 +
2509 + if (_hc->complete_split && !_hc->ep_is_in) {
2510 + /* For CSPLIT OUT Transfer, set the size to 0 so the
2511 + * core doesn't expect any data written to the FIFO */
2512 + _hc->xfer_len = 0;
2513 + } else if (_hc->ep_is_in || (_hc->xfer_len > _hc->max_packet)) {
2514 + _hc->xfer_len = _hc->max_packet;
2515 + } else if (!_hc->ep_is_in && (_hc->xfer_len > 188)) {
2516 + _hc->xfer_len = 188;
2517 + }
2518 +
2519 + hctsiz.b.xfersize = _hc->xfer_len;
2520 + } else {
2521 + /*
2522 + * Ensure that the transfer length and packet count will fit
2523 + * in the widths allocated for them in the HCTSIZn register.
2524 + */
2525 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2526 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2527 + /*
2528 + * Make sure the transfer size is no larger than one
2529 + * (micro)frame's worth of data. (A check was done
2530 + * when the periodic transfer was accepted to ensure
2531 + * that a (micro)frame's worth of data can be
2532 + * programmed into a channel.)
2533 + */
2534 + uint32_t max_periodic_len = _hc->multi_count * _hc->max_packet;
2535 + if (_hc->xfer_len > max_periodic_len) {
2536 + _hc->xfer_len = max_periodic_len;
2537 + } else {
2538 + }
2539 + } else if (_hc->xfer_len > max_hc_xfer_size) {
2540 + /* Make sure that xfer_len is a multiple of max packet size. */
2541 + _hc->xfer_len = max_hc_xfer_size - _hc->max_packet + 1;
2542 + }
2543 +
2544 + if (_hc->xfer_len > 0) {
2545 + num_packets = (_hc->xfer_len + _hc->max_packet - 1) / _hc->max_packet;
2546 + if (num_packets > max_hc_pkt_count) {
2547 + num_packets = max_hc_pkt_count;
2548 + _hc->xfer_len = num_packets * _hc->max_packet;
2549 + }
2550 + } else {
2551 + /* Need 1 packet for transfer length of 0. */
2552 + num_packets = 1;
2553 + }
2554 +
2555 + if (_hc->ep_is_in) {
2556 + /* Always program an integral # of max packets for IN transfers. */
2557 + _hc->xfer_len = num_packets * _hc->max_packet;
2558 + }
2559 +
2560 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2561 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2562 + /*
2563 + * Make sure that the multi_count field matches the
2564 + * actual transfer length.
2565 + */
2566 + _hc->multi_count = num_packets;
2567 +
2568 + }
2569 +
2570 + if (_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2571 + /* Set up the initial PID for the transfer. */
2572 + if (_hc->speed == DWC_OTG_EP_SPEED_HIGH) {
2573 + if (_hc->ep_is_in) {
2574 + if (_hc->multi_count == 1) {
2575 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2576 + } else if (_hc->multi_count == 2) {
2577 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
2578 + } else {
2579 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
2580 + }
2581 + } else {
2582 + if (_hc->multi_count == 1) {
2583 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2584 + } else {
2585 + _hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
2586 + }
2587 + }
2588 + } else {
2589 + _hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
2590 + }
2591 + }
2592 +
2593 + hctsiz.b.xfersize = _hc->xfer_len;
2594 + }
2595 +
2596 + _hc->start_pkt_count = num_packets;
2597 + hctsiz.b.pktcnt = num_packets;
2598 + hctsiz.b.pid = _hc->data_pid_start;
2599 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2600 +
2601 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2602 + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
2603 + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
2604 + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
2605 +
2606 + if (_core_if->dma_enable) {
2607 +#ifdef DEBUG
2608 +if(((uint32_t)_hc->xfer_buff)%4)
2609 +printk("dwc_otg_hc_start_transfer _hc->xfer_buff not 4 byte alignment\n");
2610 +#endif
2611 + dwc_write_reg32(&hc_regs->hcdma, (uint32_t)_hc->xfer_buff);
2612 + }
2613 +
2614 + /* Start the split */
2615 + if (_hc->do_split) {
2616 + hcsplt_data_t hcsplt;
2617 + hcsplt.d32 = dwc_read_reg32 (&hc_regs->hcsplt);
2618 + hcsplt.b.spltena = 1;
2619 + dwc_write_reg32(&hc_regs->hcsplt, hcsplt.d32);
2620 + }
2621 +
2622 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2623 + hcchar.b.multicnt = _hc->multi_count;
2624 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2625 +#ifdef DEBUG
2626 + _core_if->start_hcchar_val[_hc->hc_num] = hcchar.d32;
2627 + if (hcchar.b.chdis) {
2628 + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
2629 + __func__, _hc->hc_num, hcchar.d32);
2630 + }
2631 +#endif
2632 +
2633 + /* Set host channel enable after all other setup is complete. */
2634 + hcchar.b.chen = 1;
2635 + hcchar.b.chdis = 0;
2636 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2637 +
2638 + _hc->xfer_started = 1;
2639 + _hc->requests++;
2640 +
2641 + if (!_core_if->dma_enable && !_hc->ep_is_in && _hc->xfer_len > 0) {
2642 + /* Load OUT packet into the appropriate Tx FIFO. */
2643 + dwc_otg_hc_write_packet(_core_if, _hc);
2644 + }
2645 +
2646 +#ifdef DEBUG
2647 + /* Start a timer for this transfer. */
2648 + _core_if->hc_xfer_timer[_hc->hc_num].function = hc_xfer_timeout;
2649 + _core_if->hc_xfer_info[_hc->hc_num].core_if = _core_if;
2650 + _core_if->hc_xfer_info[_hc->hc_num].hc = _hc;
2651 + _core_if->hc_xfer_timer[_hc->hc_num].data = (unsigned long)(&_core_if->hc_xfer_info[_hc->hc_num]);
2652 + _core_if->hc_xfer_timer[_hc->hc_num].expires = jiffies + (HZ*10);
2653 + add_timer(&_core_if->hc_xfer_timer[_hc->hc_num]);
2654 +#endif
2655 +}
2656 +
2657 +/**
2658 + * This function continues a data transfer that was started by previous call
2659 + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
2660 + * sufficient space in the request queue and Tx Data FIFO. This function
2661 + * should only be called in Slave mode. In DMA mode, the controller acts
2662 + * autonomously to complete transfers programmed to a host channel.
2663 + *
2664 + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
2665 + * if there is any data remaining to be queued. For an IN transfer, another
2666 + * data packet is always requested. For the SETUP phase of a control transfer,
2667 + * this function does nothing.
2668 + *
2669 + * @return 1 if a new request is queued, 0 if no more requests are required
2670 + * for this transfer.
2671 + */
2672 +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2673 +{
2674 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2675 +
2676 + if (_hc->do_split) {
2677 + /* SPLITs always queue just once per channel */
2678 + return 0;
2679 + } else if (_hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
2680 + /* SETUPs are queued only once since they can't be NAKed. */
2681 + return 0;
2682 + } else if (_hc->ep_is_in) {
2683 + /*
2684 + * Always queue another request for other IN transfers. If
2685 + * back-to-back INs are issued and NAKs are received for both,
2686 + * the driver may still be processing the first NAK when the
2687 + * second NAK is received. When the interrupt handler clears
2688 + * the NAK interrupt for the first NAK, the second NAK will
2689 + * not be seen. So we can't depend on the NAK interrupt
2690 + * handler to requeue a NAKed request. Instead, IN requests
2691 + * are issued each time this function is called. When the
2692 + * transfer completes, the extra requests for the channel will
2693 + * be flushed.
2694 + */
2695 + hcchar_data_t hcchar;
2696 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2697 +
2698 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2699 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2700 + hcchar.b.chen = 1;
2701 + hcchar.b.chdis = 0;
2702 + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n", hcchar.d32);
2703 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2704 + _hc->requests++;
2705 + return 1;
2706 + } else {
2707 + /* OUT transfers. */
2708 + if (_hc->xfer_count < _hc->xfer_len) {
2709 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2710 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2711 + hcchar_data_t hcchar;
2712 + dwc_otg_hc_regs_t *hc_regs;
2713 + hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2714 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2715 + hc_set_even_odd_frame(_core_if, _hc, &hcchar);
2716 + }
2717 +
2718 + /* Load OUT packet into the appropriate Tx FIFO. */
2719 + dwc_otg_hc_write_packet(_core_if, _hc);
2720 + _hc->requests++;
2721 + return 1;
2722 + } else {
2723 + return 0;
2724 + }
2725 + }
2726 +}
2727 +
2728 +/**
2729 + * Starts a PING transfer. This function should only be called in Slave mode.
2730 + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
2731 + */
2732 +void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2733 +{
2734 + hcchar_data_t hcchar;
2735 + hctsiz_data_t hctsiz;
2736 + dwc_otg_hc_regs_t *hc_regs = _core_if->host_if->hc_regs[_hc->hc_num];
2737 +
2738 + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _hc->hc_num);
2739 +
2740 + hctsiz.d32 = 0;
2741 + hctsiz.b.dopng = 1;
2742 + hctsiz.b.pktcnt = 1;
2743 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2744 +
2745 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2746 + hcchar.b.chen = 1;
2747 + hcchar.b.chdis = 0;
2748 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2749 +}
2750 +
2751 +/*
2752 + * This function writes a packet into the Tx FIFO associated with the Host
2753 + * Channel. For a channel associated with a non-periodic EP, the non-periodic
2754 + * Tx FIFO is written. For a channel associated with a periodic EP, the
2755 + * periodic Tx FIFO is written. This function should only be called in Slave
2756 + * mode.
2757 + *
2758 + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
2759 + * then number of bytes written to the Tx FIFO.
2760 + */
2761 +void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
2762 +{
2763 + uint32_t i;
2764 + uint32_t remaining_count;
2765 + uint32_t byte_count;
2766 + uint32_t dword_count;
2767 +
2768 + uint32_t *data_buff = (uint32_t *)(_hc->xfer_buff);
2769 + uint32_t *data_fifo = _core_if->data_fifo[_hc->hc_num];
2770 +
2771 + remaining_count = _hc->xfer_len - _hc->xfer_count;
2772 + if (remaining_count > _hc->max_packet) {
2773 + byte_count = _hc->max_packet;
2774 + } else {
2775 + byte_count = remaining_count;
2776 + }
2777 +
2778 + dword_count = (byte_count + 3) / 4;
2779 +
2780 + if ((((unsigned long)data_buff) & 0x3) == 0) {
2781 + /* xfer_buff is DWORD aligned. */
2782 + for (i = 0; i < dword_count; i++, data_buff++) {
2783 + dwc_write_reg32(data_fifo, *data_buff);
2784 + }
2785 + } else {
2786 + /* xfer_buff is not DWORD aligned. */
2787 + for (i = 0; i < dword_count; i++, data_buff++) {
2788 + dwc_write_reg32(data_fifo, get_unaligned(data_buff));
2789 + }
2790 + }
2791 +
2792 + _hc->xfer_count += byte_count;
2793 + _hc->xfer_buff += byte_count;
2794 +}
2795 +
2796 +/**
2797 + * Gets the current USB frame number. This is the frame number from the last
2798 + * SOF packet.
2799 + */
2800 +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if)
2801 +{
2802 + dsts_data_t dsts;
2803 + dsts.d32 = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->dsts);
2804 +
2805 + /* read current frame/microfreme number from DSTS register */
2806 + return dsts.b.soffn;
2807 +}
2808 +
2809 +/**
2810 + * This function reads a setup packet from the Rx FIFO into the destination
2811 + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
2812 + * Interrupt routine when a SETUP packet has been received in Slave mode.
2813 + *
2814 + * @param _core_if Programming view of DWC_otg controller.
2815 + * @param _dest Destination buffer for packet data.
2816 + */
2817 +void dwc_otg_read_setup_packet(dwc_otg_core_if_t *_core_if, uint32_t *_dest)
2818 +{
2819 + /* Get the 8 bytes of a setup transaction data */
2820 +
2821 + /* Pop 2 DWORDS off the receive data FIFO into memory */
2822 + _dest[0] = dwc_read_reg32(_core_if->data_fifo[0]);
2823 + _dest[1] = dwc_read_reg32(_core_if->data_fifo[0]);
2824 + //_dest[0] = dwc_read_datafifo32(_core_if->data_fifo[0]);
2825 + //_dest[1] = dwc_read_datafifo32(_core_if->data_fifo[0]);
2826 +}
2827 +
2828 +
2829 +/**
2830 + * This function enables EP0 OUT to receive SETUP packets and configures EP0
2831 + * IN for transmitting packets. It is normally called when the
2832 + * "Enumeration Done" interrupt occurs.
2833 + *
2834 + * @param _core_if Programming view of DWC_otg controller.
2835 + * @param _ep The EP0 data.
2836 + */
2837 +void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2838 +{
2839 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
2840 + dsts_data_t dsts;
2841 + depctl_data_t diepctl;
2842 + depctl_data_t doepctl;
2843 + dctl_data_t dctl ={.d32=0};
2844 +
2845 + /* Read the Device Status and Endpoint 0 Control registers */
2846 + dsts.d32 = dwc_read_reg32(&dev_if->dev_global_regs->dsts);
2847 + diepctl.d32 = dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl);
2848 + doepctl.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl);
2849 +
2850 + /* Set the MPS of the IN EP based on the enumeration speed */
2851 + switch (dsts.b.enumspd) {
2852 + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
2853 + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
2854 + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
2855 + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
2856 + break;
2857 + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
2858 + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
2859 + break;
2860 + }
2861 +
2862 + dwc_write_reg32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
2863 +
2864 + /* Enable OUT EP for receive */
2865 + doepctl.b.epena = 1;
2866 + dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
2867 +
2868 +#ifdef VERBOSE
2869 + DWC_DEBUGPL(DBG_PCDV,"doepctl0=%0x\n",
2870 + dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl));
2871 + DWC_DEBUGPL(DBG_PCDV,"diepctl0=%0x\n",
2872 + dwc_read_reg32(&dev_if->in_ep_regs[0]->diepctl));
2873 +#endif
2874 + dctl.b.cgnpinnak = 1;
2875 + dwc_modify_reg32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
2876 + DWC_DEBUGPL(DBG_PCDV,"dctl=%0x\n",
2877 + dwc_read_reg32(&dev_if->dev_global_regs->dctl));
2878 +}
2879 +
2880 +/**
2881 + * This function activates an EP. The Device EP control register for
2882 + * the EP is configured as defined in the ep structure. Note: This
2883 + * function is not used for EP0.
2884 + *
2885 + * @param _core_if Programming view of DWC_otg controller.
2886 + * @param _ep The EP to activate.
2887 + */
2888 +void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2889 +{
2890 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
2891 + depctl_data_t depctl;
2892 + volatile uint32_t *addr;
2893 + daint_data_t daintmsk = {.d32=0};
2894 +
2895 + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, _ep->num,
2896 + (_ep->is_in?"IN":"OUT"));
2897 +
2898 + /* Read DEPCTLn register */
2899 + if (_ep->is_in == 1) {
2900 + addr = &dev_if->in_ep_regs[_ep->num]->diepctl;
2901 + daintmsk.ep.in = 1<<_ep->num;
2902 + } else {
2903 + addr = &dev_if->out_ep_regs[_ep->num]->doepctl;
2904 + daintmsk.ep.out = 1<<_ep->num;
2905 + }
2906 +
2907 + /* If the EP is already active don't change the EP Control
2908 + * register. */
2909 + depctl.d32 = dwc_read_reg32(addr);
2910 + if (!depctl.b.usbactep) {
2911 + depctl.b.mps = _ep->maxpacket;
2912 + depctl.b.eptype = _ep->type;
2913 + depctl.b.txfnum = _ep->tx_fifo_num;
2914 +
2915 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
2916 + depctl.b.setd0pid = 1; // ???
2917 + } else {
2918 + depctl.b.setd0pid = 1;
2919 + }
2920 + depctl.b.usbactep = 1;
2921 +
2922 + dwc_write_reg32(addr, depctl.d32);
2923 + DWC_DEBUGPL(DBG_PCDV,"DEPCTL=%08x\n", dwc_read_reg32(addr));
2924 + }
2925 +
2926 +
2927 + /* Enable the Interrupt for this EP */
2928 + dwc_modify_reg32(&dev_if->dev_global_regs->daintmsk,
2929 + 0, daintmsk.d32);
2930 + DWC_DEBUGPL(DBG_PCDV,"DAINTMSK=%0x\n",
2931 + dwc_read_reg32(&dev_if->dev_global_regs->daintmsk));
2932 + _ep->stall_clear_flag = 0;
2933 + return;
2934 +}
2935 +
2936 +/**
2937 + * This function deactivates an EP. This is done by clearing the USB Active
2938 + * EP bit in the Device EP control register. Note: This function is not used
2939 + * for EP0. EP0 cannot be deactivated.
2940 + *
2941 + * @param _core_if Programming view of DWC_otg controller.
2942 + * @param _ep The EP to deactivate.
2943 + */
2944 +void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2945 +{
2946 + depctl_data_t depctl ={.d32 = 0};
2947 + volatile uint32_t *addr;
2948 + daint_data_t daintmsk = {.d32=0};
2949 +
2950 + /* Read DEPCTLn register */
2951 + if (_ep->is_in == 1) {
2952 + addr = &_core_if->dev_if->in_ep_regs[_ep->num]->diepctl;
2953 + daintmsk.ep.in = 1<<_ep->num;
2954 + } else {
2955 + addr = &_core_if->dev_if->out_ep_regs[_ep->num]->doepctl;
2956 + daintmsk.ep.out = 1<<_ep->num;
2957 + }
2958 +
2959 + depctl.b.usbactep = 0;
2960 + dwc_write_reg32(addr, depctl.d32);
2961 +
2962 + /* Disable the Interrupt for this EP */
2963 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->daintmsk,
2964 + daintmsk.d32, 0);
2965 +
2966 + return;
2967 +}
2968 +
2969 +/**
2970 + * This function does the setup for a data transfer for an EP and
2971 + * starts the transfer. For an IN transfer, the packets will be
2972 + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
2973 + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
2974 + *
2975 + * @param _core_if Programming view of DWC_otg controller.
2976 + * @param _ep The EP to start the transfer on.
2977 + */
2978 +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
2979 +{
2980 + /** @todo Refactor this funciton to check the transfer size
2981 + * count value does not execed the number bits in the Transfer
2982 + * count register. */
2983 + depctl_data_t depctl;
2984 + deptsiz_data_t deptsiz;
2985 + gintmsk_data_t intr_mask = { .d32 = 0};
2986 +
2987 +#ifdef CHECK_PACKET_COUNTER_WIDTH
2988 + const uint32_t MAX_XFER_SIZE =
2989 + _core_if->core_params->max_transfer_size;
2990 + const uint32_t MAX_PKT_COUNT =
2991 + _core_if->core_params->max_packet_count;
2992 + uint32_t num_packets;
2993 + uint32_t transfer_len;
2994 + dwc_otg_dev_out_ep_regs_t *out_regs =
2995 + _core_if->dev_if->out_ep_regs[_ep->num];
2996 + dwc_otg_dev_in_ep_regs_t *in_regs =
2997 + _core_if->dev_if->in_ep_regs[_ep->num];
2998 + gnptxsts_data_t txstatus;
2999 +
3000 + int lvl = SET_DEBUG_LEVEL(DBG_PCD);
3001 +
3002 +
3003 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3004 + "xfer_buff=%p start_xfer_buff=%p\n",
3005 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3006 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff);
3007 +
3008 + transfer_len = _ep->xfer_len - _ep->xfer_count;
3009 + if (transfer_len > MAX_XFER_SIZE) {
3010 + transfer_len = MAX_XFER_SIZE;
3011 + }
3012 + if (transfer_len == 0) {
3013 + num_packets = 1;
3014 + /* OUT EP to recieve Zero-length packet set transfer
3015 + * size to maxpacket size. */
3016 + if (!_ep->is_in) {
3017 + transfer_len = _ep->maxpacket;
3018 + }
3019 + } else {
3020 + num_packets =
3021 + (transfer_len + _ep->maxpacket - 1) / _ep->maxpacket;
3022 + if (num_packets > MAX_PKT_COUNT) {
3023 + num_packets = MAX_PKT_COUNT;
3024 + }
3025 + }
3026 + DWC_DEBUGPL(DBG_PCD, "transfer_len=%d #pckt=%d\n", transfer_len,
3027 + num_packets);
3028 +
3029 + deptsiz.b.xfersize = transfer_len;
3030 + deptsiz.b.pktcnt = num_packets;
3031 +
3032 + /* IN endpoint */
3033 + if (_ep->is_in == 1) {
3034 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3035 + } else {/* OUT endpoint */
3036 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
3037 + }
3038 +
3039 + /* EP enable, IN data in FIFO */
3040 + depctl.b.cnak = 1;
3041 + depctl.b.epena = 1;
3042 + /* IN endpoint */
3043 + if (_ep->is_in == 1) {
3044 + txstatus.d32 =
3045 + dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3046 + if (txstatus.b.nptxqspcavail == 0) {
3047 + DWC_DEBUGPL(DBG_ANY, "TX Queue Full (0x%0x)\n",
3048 + txstatus.d32);
3049 + return;
3050 + }
3051 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3052 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3053 + /**
3054 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3055 + * data will be written into the fifo by the ISR.
3056 + */
3057 + if (_core_if->dma_enable) {
3058 + dwc_write_reg32(&in_regs->diepdma, (uint32_t) _ep->xfer_buff);
3059 + } else {
3060 + if (_core_if->en_multiple_tx_fifo == 0) {
3061 + intr_mask.b.nptxfempty = 1;
3062 + dwc_modify_reg32( &_core_if->core_global_regs->gintsts,
3063 + intr_mask.d32, 0);
3064 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3065 + intr_mask.d32, intr_mask.d32);
3066 + } else {
3067 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3068 + if (_ep->xfer_len > 0 &&
3069 + _ep->type != DWC_OTG_EP_TYPE_ISOC) {
3070 + uint32_t fifoemptymsk = 0;
3071 + fifoemptymsk = (0x1 << _ep->num);
3072 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->
3073 + dtknqr4_fifoemptymsk,0, fifoemptymsk);
3074 + }
3075 + }
3076 + }
3077 + } else { /* OUT endpoint */
3078 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3079 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
3080 + if (_core_if->dma_enable) {
3081 + dwc_write_reg32(&out_regs->doepdma,(uint32_t) _ep->xfer_buff);
3082 + }
3083 + }
3084 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
3085 + dwc_read_reg32(&out_regs->doepctl),
3086 + dwc_read_reg32(&out_regs->doeptsiz));
3087 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
3088 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk),
3089 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
3090 +
3091 + SET_DEBUG_LEVEL(lvl);
3092 +#endif
3093 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
3094 +
3095 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3096 + "xfer_buff=%p start_xfer_buff=%p\n",
3097 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3098 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff);
3099 +
3100 + /* IN endpoint */
3101 + if (_ep->is_in == 1) {
3102 + dwc_otg_dev_in_ep_regs_t * in_regs = _core_if->dev_if->in_ep_regs[_ep->num];
3103 + gnptxsts_data_t gtxstatus;
3104 + gtxstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3105 + if (_core_if->en_multiple_tx_fifo == 0 &&
3106 + gtxstatus.b.nptxqspcavail == 0) {
3107 +#ifdef DEBUG
3108 + DWC_PRINT("TX Queue Full (0x%0x)\n", gtxstatus.d32);
3109 +#endif
3110 + //return;
3111 + MDELAY(100); //james
3112 + }
3113 +
3114 + depctl.d32 = dwc_read_reg32(&(in_regs->diepctl));
3115 + deptsiz.d32 = dwc_read_reg32(&(in_regs->dieptsiz));
3116 +
3117 + /* Zero Length Packet? */
3118 + if (_ep->xfer_len == 0) {
3119 + deptsiz.b.xfersize = 0;
3120 + deptsiz.b.pktcnt = 1;
3121 + } else {
3122 +
3123 + /* Program the transfer size and packet count
3124 + * as follows: xfersize = N * maxpacket +
3125 + * short_packet pktcnt = N + (short_packet
3126 + * exist ? 1 : 0)
3127 + */
3128 + deptsiz.b.xfersize = _ep->xfer_len;
3129 + deptsiz.b.pktcnt = (_ep->xfer_len - 1 + _ep->maxpacket) / _ep->maxpacket;
3130 + }
3131 +
3132 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3133 +
3134 + /* Write the DMA register */
3135 + if (_core_if->dma_enable) {
3136 +#if 1 // winder
3137 + dma_cache_wback_inv((unsigned long) _ep->xfer_buff, _ep->xfer_len); // winder
3138 + dwc_write_reg32 (&(in_regs->diepdma),
3139 + CPHYSADDR((uint32_t)_ep->xfer_buff)); // winder
3140 +#else
3141 + dwc_write_reg32 (&(in_regs->diepdma),
3142 + (uint32_t)_ep->dma_addr);
3143 +#endif
3144 + } else {
3145 + if (_ep->type != DWC_OTG_EP_TYPE_ISOC) {
3146 + /**
3147 + * Enable the Non-Periodic Tx FIFO empty interrupt,
3148 + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
3149 + * the data will be written into the fifo by the ISR.
3150 + */
3151 + if (_core_if->en_multiple_tx_fifo == 0) {
3152 + intr_mask.b.nptxfempty = 1;
3153 + dwc_modify_reg32( &_core_if->core_global_regs->gintsts,
3154 + intr_mask.d32, 0);
3155 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3156 + intr_mask.d32, intr_mask.d32);
3157 + } else {
3158 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3159 + if (_ep->xfer_len > 0) {
3160 + uint32_t fifoemptymsk = 0;
3161 + fifoemptymsk = 1 << _ep->num;
3162 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->
3163 + dtknqr4_fifoemptymsk,0,fifoemptymsk);
3164 + }
3165 + }
3166 + }
3167 + }
3168 +
3169 + /* EP enable, IN data in FIFO */
3170 + depctl.b.cnak = 1;
3171 + depctl.b.epena = 1;
3172 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3173 +
3174 + if (_core_if->dma_enable) {
3175 + depctl.d32 = dwc_read_reg32 (&_core_if->dev_if->in_ep_regs[0]->diepctl);
3176 + depctl.b.nextep = _ep->num;
3177 + dwc_write_reg32 (&_core_if->dev_if->in_ep_regs[0]->diepctl, depctl.d32);
3178 +
3179 + }
3180 + } else {
3181 + /* OUT endpoint */
3182 + dwc_otg_dev_out_ep_regs_t * out_regs = _core_if->dev_if->out_ep_regs[_ep->num];
3183 +
3184 + depctl.d32 = dwc_read_reg32(&(out_regs->doepctl));
3185 + deptsiz.d32 = dwc_read_reg32(&(out_regs->doeptsiz));
3186 +
3187 + /* Program the transfer size and packet count as follows:
3188 + *
3189 + * pktcnt = N
3190 + * xfersize = N * maxpacket
3191 + */
3192 + if (_ep->xfer_len == 0) {
3193 + /* Zero Length Packet */
3194 + deptsiz.b.xfersize = _ep->maxpacket;
3195 + deptsiz.b.pktcnt = 1;
3196 + } else {
3197 + deptsiz.b.pktcnt = (_ep->xfer_len + (_ep->maxpacket - 1)) / _ep->maxpacket;
3198 + deptsiz.b.xfersize = deptsiz.b.pktcnt * _ep->maxpacket;
3199 + }
3200 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3201 +
3202 + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
3203 + _ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
3204 +
3205 + if (_core_if->dma_enable) {
3206 +#if 1 // winder
3207 + dwc_write_reg32 (&(out_regs->doepdma),
3208 + CPHYSADDR((uint32_t)_ep->xfer_buff)); // winder
3209 +#else
3210 + dwc_write_reg32 (&(out_regs->doepdma),
3211 + (uint32_t)_ep->dma_addr);
3212 +#endif
3213 + }
3214 +
3215 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
3216 + /** @todo NGS: dpid is read-only. Use setd0pid
3217 + * or setd1pid. */
3218 + if (_ep->even_odd_frame) {
3219 + depctl.b.setd1pid = 1;
3220 + } else {
3221 + depctl.b.setd0pid = 1;
3222 + }
3223 + }
3224 +
3225 + /* EP enable */
3226 + depctl.b.cnak = 1;
3227 + depctl.b.epena = 1;
3228 +
3229 + dwc_write_reg32(&out_regs->doepctl, depctl.d32);
3230 +
3231 + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
3232 + dwc_read_reg32(&out_regs->doepctl),
3233 + dwc_read_reg32(&out_regs->doeptsiz));
3234 + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
3235 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk),
3236 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
3237 + }
3238 +}
3239 +
3240 +
3241 +/**
3242 + * This function does the setup for a data transfer for EP0 and starts
3243 + * the transfer. For an IN transfer, the packets will be loaded into
3244 + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
3245 + * unloaded from the Rx FIFO in the ISR.
3246 + *
3247 + * @param _core_if Programming view of DWC_otg controller.
3248 + * @param _ep The EP0 data.
3249 + */
3250 +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3251 +{
3252 + volatile depctl_data_t depctl;
3253 + volatile deptsiz0_data_t deptsiz;
3254 + gintmsk_data_t intr_mask = { .d32 = 0};
3255 +
3256 + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
3257 + "xfer_buff=%p start_xfer_buff=%p total_len=%d\n",
3258 + _ep->num, (_ep->is_in?"IN":"OUT"), _ep->xfer_len,
3259 + _ep->xfer_count, _ep->xfer_buff, _ep->start_xfer_buff,
3260 + _ep->total_len);
3261 + _ep->total_len = _ep->xfer_len;
3262 +
3263 + /* IN endpoint */
3264 + if (_ep->is_in == 1) {
3265 + dwc_otg_dev_in_ep_regs_t * in_regs = _core_if->dev_if->in_ep_regs[0];
3266 + gnptxsts_data_t gtxstatus;
3267 + gtxstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
3268 + if (_core_if->en_multiple_tx_fifo == 0 &&
3269 + gtxstatus.b.nptxqspcavail == 0) {
3270 +#ifdef DEBUG
3271 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3272 + DWC_DEBUGPL(DBG_PCD,"DIEPCTL0=%0x\n",
3273 + dwc_read_reg32(&in_regs->diepctl));
3274 + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
3275 + deptsiz.d32, deptsiz.b.xfersize,deptsiz.b.pktcnt);
3276 + DWC_PRINT("TX Queue or FIFO Full (0x%0x)\n", gtxstatus.d32);
3277 +#endif /* */
3278 + printk("TX Queue or FIFO Full!!!!\n"); // test-only
3279 + //return;
3280 + MDELAY(100); //james
3281 + }
3282 +
3283 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3284 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3285 +
3286 + /* Zero Length Packet? */
3287 + if (_ep->xfer_len == 0) {
3288 + deptsiz.b.xfersize = 0;
3289 + deptsiz.b.pktcnt = 1;
3290 + } else {
3291 + /* Program the transfer size and packet count
3292 + * as follows: xfersize = N * maxpacket +
3293 + * short_packet pktcnt = N + (short_packet
3294 + * exist ? 1 : 0)
3295 + */
3296 + if (_ep->xfer_len > _ep->maxpacket) {
3297 + _ep->xfer_len = _ep->maxpacket;
3298 + deptsiz.b.xfersize = _ep->maxpacket;
3299 + }
3300 + else {
3301 + deptsiz.b.xfersize = _ep->xfer_len;
3302 + }
3303 + deptsiz.b.pktcnt = 1;
3304 +
3305 + }
3306 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3307 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
3308 + _ep->xfer_len, deptsiz.b.xfersize,deptsiz.b.pktcnt, deptsiz.d32);
3309 +
3310 + /* Write the DMA register */
3311 + if (_core_if->dma_enable) {
3312 + dwc_write_reg32(&(in_regs->diepdma), (uint32_t) _ep->dma_addr);
3313 + }
3314 +
3315 + /* EP enable, IN data in FIFO */
3316 + depctl.b.cnak = 1;
3317 + depctl.b.epena = 1;
3318 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3319 +
3320 + /**
3321 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3322 + * data will be written into the fifo by the ISR.
3323 + */
3324 + if (!_core_if->dma_enable) {
3325 + if (_core_if->en_multiple_tx_fifo == 0) {
3326 + intr_mask.b.nptxfempty = 1;
3327 + dwc_modify_reg32(&_core_if->core_global_regs->gintsts, intr_mask.d32, 0);
3328 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, intr_mask.d32,
3329 + intr_mask.d32);
3330 + } else {
3331 + /* Enable the Tx FIFO Empty Interrupt for this EP */
3332 + if (_ep->xfer_len > 0) {
3333 + uint32_t fifoemptymsk = 0;
3334 + fifoemptymsk |= 1 << _ep->num;
3335 + dwc_modify_reg32(&_core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
3336 + 0, fifoemptymsk);
3337 + }
3338 +
3339 + }
3340 + }
3341 + } else {
3342 + /* OUT endpoint */
3343 + dwc_otg_dev_out_ep_regs_t * out_regs = _core_if->dev_if->out_ep_regs[_ep->num];
3344 +
3345 + depctl.d32 = dwc_read_reg32(&out_regs->doepctl);
3346 + deptsiz.d32 = dwc_read_reg32(&out_regs->doeptsiz);
3347 +
3348 + /* Program the transfer size and packet count as follows:
3349 + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
3350 + * pktcnt = N */
3351 + if (_ep->xfer_len == 0) {
3352 + /* Zero Length Packet */
3353 + deptsiz.b.xfersize = _ep->maxpacket;
3354 + deptsiz.b.pktcnt = 1;
3355 + } else {
3356 + deptsiz.b.pktcnt = (_ep->xfer_len + (_ep->maxpacket - 1)) / _ep->maxpacket;
3357 + deptsiz.b.xfersize = deptsiz.b.pktcnt * _ep->maxpacket;
3358 + }
3359 +
3360 + dwc_write_reg32(&out_regs->doeptsiz, deptsiz.d32);
3361 + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
3362 + _ep->xfer_len, deptsiz.b.xfersize,deptsiz.b.pktcnt);
3363 +
3364 + if (_core_if->dma_enable) {
3365 + dwc_write_reg32(&(out_regs->doepdma), (uint32_t) _ep->dma_addr);
3366 + }
3367 +
3368 + /* EP enable */
3369 + depctl.b.cnak = 1;
3370 + depctl.b.epena = 1;
3371 + dwc_write_reg32 (&(out_regs->doepctl), depctl.d32);
3372 + }
3373 +}
3374 +
3375 +/**
3376 + * This function continues control IN transfers started by
3377 + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
3378 + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
3379 + * bit for the packet count.
3380 + *
3381 + * @param _core_if Programming view of DWC_otg controller.
3382 + * @param _ep The EP0 data.
3383 + */
3384 +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3385 +{
3386 + depctl_data_t depctl;
3387 + deptsiz0_data_t deptsiz;
3388 + gintmsk_data_t intr_mask = { .d32 = 0};
3389 +
3390 + if (_ep->is_in == 1) {
3391 + dwc_otg_dev_in_ep_regs_t *in_regs =
3392 + _core_if->dev_if->in_ep_regs[0];
3393 + gnptxsts_data_t tx_status = {.d32 = 0};
3394 +
3395 + tx_status.d32 = dwc_read_reg32( &_core_if->core_global_regs->gnptxsts );
3396 + /** @todo Should there be check for room in the Tx
3397 + * Status Queue. If not remove the code above this comment. */
3398 +
3399 + depctl.d32 = dwc_read_reg32(&in_regs->diepctl);
3400 + deptsiz.d32 = dwc_read_reg32(&in_regs->dieptsiz);
3401 +
3402 + /* Program the transfer size and packet count
3403 + * as follows: xfersize = N * maxpacket +
3404 + * short_packet pktcnt = N + (short_packet
3405 + * exist ? 1 : 0)
3406 + */
3407 + deptsiz.b.xfersize = (_ep->total_len - _ep->xfer_count) > _ep->maxpacket ? _ep->maxpacket :
3408 + (_ep->total_len - _ep->xfer_count);
3409 + deptsiz.b.pktcnt = 1;
3410 + _ep->xfer_len += deptsiz.b.xfersize;
3411 +
3412 + dwc_write_reg32(&in_regs->dieptsiz, deptsiz.d32);
3413 + DWC_DEBUGPL(DBG_PCDV, "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
3414 + _ep->xfer_len,
3415 + deptsiz.b.xfersize, deptsiz.b.pktcnt, deptsiz.d32);
3416 +
3417 + /* Write the DMA register */
3418 + if (_core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
3419 + dwc_write_reg32 (&(in_regs->diepdma),
3420 + CPHYSADDR((uint32_t)_ep->dma_addr)); // winder
3421 + }
3422 +
3423 + /* EP enable, IN data in FIFO */
3424 + depctl.b.cnak = 1;
3425 + depctl.b.epena = 1;
3426 + dwc_write_reg32(&in_regs->diepctl, depctl.d32);
3427 +
3428 + /**
3429 + * Enable the Non-Periodic Tx FIFO empty interrupt, the
3430 + * data will be written into the fifo by the ISR.
3431 + */
3432 + if (!_core_if->dma_enable) {
3433 + /* First clear it from GINTSTS */
3434 + intr_mask.b.nptxfempty = 1;
3435 + dwc_write_reg32( &_core_if->core_global_regs->gintsts,
3436 + intr_mask.d32 );
3437 +
3438 + dwc_modify_reg32( &_core_if->core_global_regs->gintmsk,
3439 + intr_mask.d32, intr_mask.d32);
3440 + }
3441 +
3442 + }
3443 +
3444 +}
3445 +
3446 +#ifdef DEBUG
3447 +void dump_msg(const u8 *buf, unsigned int length)
3448 +{
3449 + unsigned int start, num, i;
3450 + char line[52], *p;
3451 +
3452 + if (length >= 512)
3453 + return;
3454 + start = 0;
3455 + while (length > 0) {
3456 + num = min(length, 16u);
3457 + p = line;
3458 + for (i = 0; i < num; ++i) {
3459 + if (i == 8)
3460 + *p++ = ' ';
3461 + sprintf(p, " %02x", buf[i]);
3462 + p += 3;
3463 + }
3464 + *p = 0;
3465 + DWC_PRINT( "%6x: %s\n", start, line);
3466 + buf += num;
3467 + start += num;
3468 + length -= num;
3469 + }
3470 +}
3471 +#else
3472 +static inline void dump_msg(const u8 *buf, unsigned int length)
3473 +{
3474 +}
3475 +#endif
3476 +
3477 +/**
3478 + * This function writes a packet into the Tx FIFO associated with the
3479 + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
3480 + * periodic EPs the periodic Tx FIFO associated with the EP is written
3481 + * with all packets for the next micro-frame.
3482 + *
3483 + * @param _core_if Programming view of DWC_otg controller.
3484 + * @param _ep The EP to write packet for.
3485 + * @param _dma Indicates if DMA is being used.
3486 + */
3487 +void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma)
3488 +{
3489 + /**
3490 + * The buffer is padded to DWORD on a per packet basis in
3491 + * slave/dma mode if the MPS is not DWORD aligned. The last
3492 + * packet, if short, is also padded to a multiple of DWORD.
3493 + *
3494 + * ep->xfer_buff always starts DWORD aligned in memory and is a
3495 + * multiple of DWORD in length
3496 + *
3497 + * ep->xfer_len can be any number of bytes
3498 + *
3499 + * ep->xfer_count is a multiple of ep->maxpacket until the last
3500 + * packet
3501 + *
3502 + * FIFO access is DWORD */
3503 +
3504 + uint32_t i;
3505 + uint32_t byte_count;
3506 + uint32_t dword_count;
3507 + uint32_t *fifo;
3508 + uint32_t *data_buff = (uint32_t *)_ep->xfer_buff;
3509 +
3510 + //DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, _core_if, _ep);
3511 + if (_ep->xfer_count >= _ep->xfer_len) {
3512 + DWC_WARN("%s() No data for EP%d!!!\n", __func__, _ep->num);
3513 + return;
3514 + }
3515 +
3516 + /* Find the byte length of the packet either short packet or MPS */
3517 + if ((_ep->xfer_len - _ep->xfer_count) < _ep->maxpacket) {
3518 + byte_count = _ep->xfer_len - _ep->xfer_count;
3519 + }
3520 + else {
3521 + byte_count = _ep->maxpacket;
3522 + }
3523 +
3524 + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
3525 + * is not a multiple of DWORD */
3526 + dword_count = (byte_count + 3) / 4;
3527 +
3528 +#ifdef VERBOSE
3529 + dump_msg(_ep->xfer_buff, byte_count);
3530 +#endif
3531 + if (_ep->type == DWC_OTG_EP_TYPE_ISOC) {
3532 + /**@todo NGS Where are the Periodic Tx FIFO addresses
3533 + * intialized? What should this be? */
3534 + fifo = _core_if->data_fifo[_ep->tx_fifo_num];
3535 + } else {
3536 + fifo = _core_if->data_fifo[_ep->num];
3537 + }
3538 +
3539 + DWC_DEBUGPL((DBG_PCDV|DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
3540 + fifo, data_buff, *data_buff, byte_count);
3541 +
3542 +
3543 + if (!_dma) {
3544 + for (i=0; i<dword_count; i++, data_buff++) {
3545 + dwc_write_reg32( fifo, *data_buff );
3546 + }
3547 + }
3548 +
3549 + _ep->xfer_count += byte_count;
3550 + _ep->xfer_buff += byte_count;
3551 +#if 1 // winder, why do we need this??
3552 + _ep->dma_addr += byte_count;
3553 +#endif
3554 +}
3555 +
3556 +/**
3557 + * Set the EP STALL.
3558 + *
3559 + * @param _core_if Programming view of DWC_otg controller.
3560 + * @param _ep The EP to set the stall on.
3561 + */
3562 +void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3563 +{
3564 + depctl_data_t depctl;
3565 + volatile uint32_t *depctl_addr;
3566 +
3567 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _ep->num,
3568 + (_ep->is_in?"IN":"OUT"));
3569 +
3570 + if (_ep->is_in == 1) {
3571 + depctl_addr = &(_core_if->dev_if->in_ep_regs[_ep->num]->diepctl);
3572 + depctl.d32 = dwc_read_reg32(depctl_addr);
3573 +
3574 + /* set the disable and stall bits */
3575 + if (depctl.b.epena) {
3576 + depctl.b.epdis = 1;
3577 + }
3578 + depctl.b.stall = 1;
3579 + dwc_write_reg32(depctl_addr, depctl.d32);
3580 +
3581 + } else {
3582 + depctl_addr = &(_core_if->dev_if->out_ep_regs[_ep->num]->doepctl);
3583 + depctl.d32 = dwc_read_reg32(depctl_addr);
3584 +
3585 + /* set the stall bit */
3586 + depctl.b.stall = 1;
3587 + dwc_write_reg32(depctl_addr, depctl.d32);
3588 + }
3589 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
3590 + return;
3591 +}
3592 +
3593 +/**
3594 + * Clear the EP STALL.
3595 + *
3596 + * @param _core_if Programming view of DWC_otg controller.
3597 + * @param _ep The EP to clear stall from.
3598 + */
3599 +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep)
3600 +{
3601 + depctl_data_t depctl;
3602 + volatile uint32_t *depctl_addr;
3603 +
3604 + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, _ep->num,
3605 + (_ep->is_in?"IN":"OUT"));
3606 +
3607 + if (_ep->is_in == 1) {
3608 + depctl_addr = &(_core_if->dev_if->in_ep_regs[_ep->num]->diepctl);
3609 + } else {
3610 + depctl_addr = &(_core_if->dev_if->out_ep_regs[_ep->num]->doepctl);
3611 + }
3612 +
3613 + depctl.d32 = dwc_read_reg32(depctl_addr);
3614 +
3615 + /* clear the stall bits */
3616 + depctl.b.stall = 0;
3617 +
3618 + /*
3619 + * USB Spec 9.4.5: For endpoints using data toggle, regardless
3620 + * of whether an endpoint has the Halt feature set, a
3621 + * ClearFeature(ENDPOINT_HALT) request always results in the
3622 + * data toggle being reinitialized to DATA0.
3623 + */
3624 + if (_ep->type == DWC_OTG_EP_TYPE_INTR ||
3625 + _ep->type == DWC_OTG_EP_TYPE_BULK) {
3626 + depctl.b.setd0pid = 1; /* DATA0 */
3627 + }
3628 +
3629 + dwc_write_reg32(depctl_addr, depctl.d32);
3630 + DWC_DEBUGPL(DBG_PCD,"DEPCTL=%0x\n",dwc_read_reg32(depctl_addr));
3631 + return;
3632 +}
3633 +
3634 +/**
3635 + * This function reads a packet from the Rx FIFO into the destination
3636 + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
3637 + *
3638 + * @param _core_if Programming view of DWC_otg controller.
3639 + * @param _dest Destination buffer for the packet.
3640 + * @param _bytes Number of bytes to copy to the destination.
3641 + */
3642 +void dwc_otg_read_packet(dwc_otg_core_if_t *_core_if,
3643 + uint8_t *_dest,
3644 + uint16_t _bytes)
3645 +{
3646 + int i;
3647 + int word_count = (_bytes + 3) / 4;
3648 +
3649 + volatile uint32_t *fifo = _core_if->data_fifo[0];
3650 + uint32_t *data_buff = (uint32_t *)_dest;
3651 +
3652 + /**
3653 + * @todo Account for the case where _dest is not dword aligned. This
3654 + * requires reading data from the FIFO into a uint32_t temp buffer,
3655 + * then moving it into the data buffer.
3656 + */
3657 +
3658 + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
3659 + _core_if, _dest, _bytes);
3660 +
3661 + for (i=0; i<word_count; i++, data_buff++) {
3662 + *data_buff = dwc_read_reg32(fifo);
3663 + }
3664 +
3665 + return;
3666 +}
3667 +
3668 +
3669 +#ifdef DEBUG
3670 +/**
3671 + * This functions reads the device registers and prints them
3672 + *
3673 + * @param _core_if Programming view of DWC_otg controller.
3674 + */
3675 +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if)
3676 +{
3677 + int i;
3678 + volatile uint32_t *addr;
3679 +
3680 + DWC_PRINT("Device Global Registers\n");
3681 + addr=&_core_if->dev_if->dev_global_regs->dcfg;
3682 + DWC_PRINT("DCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3683 + addr=&_core_if->dev_if->dev_global_regs->dctl;
3684 + DWC_PRINT("DCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3685 + addr=&_core_if->dev_if->dev_global_regs->dsts;
3686 + DWC_PRINT("DSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3687 + addr=&_core_if->dev_if->dev_global_regs->diepmsk;
3688 + DWC_PRINT("DIEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3689 + addr=&_core_if->dev_if->dev_global_regs->doepmsk;
3690 + DWC_PRINT("DOEPMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3691 + addr=&_core_if->dev_if->dev_global_regs->daint;
3692 + DWC_PRINT("DAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3693 + addr=&_core_if->dev_if->dev_global_regs->dtknqr1;
3694 + DWC_PRINT("DTKNQR1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3695 + if (_core_if->hwcfg2.b.dev_token_q_depth > 6) {
3696 + addr=&_core_if->dev_if->dev_global_regs->dtknqr2;
3697 + DWC_PRINT("DTKNQR2 @0x%08X : 0x%08X\n",
3698 + (uint32_t)addr,dwc_read_reg32(addr));
3699 + }
3700 +
3701 + addr=&_core_if->dev_if->dev_global_regs->dvbusdis;
3702 + DWC_PRINT("DVBUSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3703 +
3704 + addr=&_core_if->dev_if->dev_global_regs->dvbuspulse;
3705 + DWC_PRINT("DVBUSPULSE @0x%08X : 0x%08X\n",
3706 + (uint32_t)addr,dwc_read_reg32(addr));
3707 +
3708 + if (_core_if->hwcfg2.b.dev_token_q_depth > 14) {
3709 + addr = &_core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
3710 + DWC_PRINT("DTKNQR3 @0x%08X : 0x%08X\n",
3711 + (uint32_t)addr, dwc_read_reg32(addr));
3712 + }
3713 +
3714 + if (_core_if->hwcfg2.b.dev_token_q_depth > 22) {
3715 + addr = &_core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
3716 + DWC_PRINT("DTKNQR4 @0x%08X : 0x%08X\n", (uint32_t) addr,
3717 + dwc_read_reg32(addr));
3718 + }
3719 + for (i = 0; i <= _core_if->dev_if->num_in_eps; i++) {
3720 + DWC_PRINT("Device IN EP %d Registers\n", i);
3721 + addr=&_core_if->dev_if->in_ep_regs[i]->diepctl;
3722 + DWC_PRINT("DIEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3723 + addr=&_core_if->dev_if->in_ep_regs[i]->diepint;
3724 + DWC_PRINT("DIEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3725 + addr=&_core_if->dev_if->in_ep_regs[i]->dieptsiz;
3726 + DWC_PRINT("DIETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3727 + addr=&_core_if->dev_if->in_ep_regs[i]->diepdma;
3728 + DWC_PRINT("DIEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3729 +
3730 +addr = &_core_if->dev_if->in_ep_regs[i]->dtxfsts;
3731 + DWC_PRINT("DTXFSTS @0x%08X : 0x%08X\n", (uint32_t) addr,
3732 + dwc_read_reg32(addr));
3733 + }
3734 + for (i = 0; i <= _core_if->dev_if->num_out_eps; i++) {
3735 + DWC_PRINT("Device OUT EP %d Registers\n", i);
3736 + addr=&_core_if->dev_if->out_ep_regs[i]->doepctl;
3737 + DWC_PRINT("DOEPCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3738 + addr=&_core_if->dev_if->out_ep_regs[i]->doepfn;
3739 + DWC_PRINT("DOEPFN @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3740 + addr=&_core_if->dev_if->out_ep_regs[i]->doepint;
3741 + DWC_PRINT("DOEPINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3742 + addr=&_core_if->dev_if->out_ep_regs[i]->doeptsiz;
3743 + DWC_PRINT("DOETSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3744 + addr=&_core_if->dev_if->out_ep_regs[i]->doepdma;
3745 + DWC_PRINT("DOEPDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3746 + }
3747 + return;
3748 +}
3749 +
3750 +/**
3751 + * This function reads the host registers and prints them
3752 + *
3753 + * @param _core_if Programming view of DWC_otg controller.
3754 + */
3755 +void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if)
3756 +{
3757 + int i;
3758 + volatile uint32_t *addr;
3759 +
3760 + DWC_PRINT("Host Global Registers\n");
3761 + addr=&_core_if->host_if->host_global_regs->hcfg;
3762 + DWC_PRINT("HCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3763 + addr=&_core_if->host_if->host_global_regs->hfir;
3764 + DWC_PRINT("HFIR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3765 + addr=&_core_if->host_if->host_global_regs->hfnum;
3766 + DWC_PRINT("HFNUM @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3767 + addr=&_core_if->host_if->host_global_regs->hptxsts;
3768 + DWC_PRINT("HPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3769 + addr=&_core_if->host_if->host_global_regs->haint;
3770 + DWC_PRINT("HAINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3771 + addr=&_core_if->host_if->host_global_regs->haintmsk;
3772 + DWC_PRINT("HAINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3773 + addr=_core_if->host_if->hprt0;
3774 + DWC_PRINT("HPRT0 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3775 +
3776 + for (i=0; i<_core_if->core_params->host_channels; i++) {
3777 + DWC_PRINT("Host Channel %d Specific Registers\n", i);
3778 + addr=&_core_if->host_if->hc_regs[i]->hcchar;
3779 + DWC_PRINT("HCCHAR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3780 + addr=&_core_if->host_if->hc_regs[i]->hcsplt;
3781 + DWC_PRINT("HCSPLT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3782 + addr=&_core_if->host_if->hc_regs[i]->hcint;
3783 + DWC_PRINT("HCINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3784 + addr=&_core_if->host_if->hc_regs[i]->hcintmsk;
3785 + DWC_PRINT("HCINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3786 + addr=&_core_if->host_if->hc_regs[i]->hctsiz;
3787 + DWC_PRINT("HCTSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3788 + addr=&_core_if->host_if->hc_regs[i]->hcdma;
3789 + DWC_PRINT("HCDMA @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3790 +
3791 + }
3792 + return;
3793 +}
3794 +
3795 +/**
3796 + * This function reads the core global registers and prints them
3797 + *
3798 + * @param _core_if Programming view of DWC_otg controller.
3799 + */
3800 +void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if)
3801 +{
3802 + int i;
3803 + volatile uint32_t *addr;
3804 +
3805 + DWC_PRINT("Core Global Registers\n");
3806 + addr=&_core_if->core_global_regs->gotgctl;
3807 + DWC_PRINT("GOTGCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3808 + addr=&_core_if->core_global_regs->gotgint;
3809 + DWC_PRINT("GOTGINT @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3810 + addr=&_core_if->core_global_regs->gahbcfg;
3811 + DWC_PRINT("GAHBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3812 + addr=&_core_if->core_global_regs->gusbcfg;
3813 + DWC_PRINT("GUSBCFG @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3814 + addr=&_core_if->core_global_regs->grstctl;
3815 + DWC_PRINT("GRSTCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3816 + addr=&_core_if->core_global_regs->gintsts;
3817 + DWC_PRINT("GINTSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3818 + addr=&_core_if->core_global_regs->gintmsk;
3819 + DWC_PRINT("GINTMSK @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3820 + addr=&_core_if->core_global_regs->grxstsr;
3821 + DWC_PRINT("GRXSTSR @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3822 + //addr=&_core_if->core_global_regs->grxstsp;
3823 + //DWC_PRINT("GRXSTSP @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3824 + addr=&_core_if->core_global_regs->grxfsiz;
3825 + DWC_PRINT("GRXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3826 + addr=&_core_if->core_global_regs->gnptxfsiz;
3827 + DWC_PRINT("GNPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3828 + addr=&_core_if->core_global_regs->gnptxsts;
3829 + DWC_PRINT("GNPTXSTS @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3830 + addr=&_core_if->core_global_regs->gi2cctl;
3831 + DWC_PRINT("GI2CCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3832 + addr=&_core_if->core_global_regs->gpvndctl;
3833 + DWC_PRINT("GPVNDCTL @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3834 + addr=&_core_if->core_global_regs->ggpio;
3835 + DWC_PRINT("GGPIO @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3836 + addr=&_core_if->core_global_regs->guid;
3837 + DWC_PRINT("GUID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3838 + addr=&_core_if->core_global_regs->gsnpsid;
3839 + DWC_PRINT("GSNPSID @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3840 + addr=&_core_if->core_global_regs->ghwcfg1;
3841 + DWC_PRINT("GHWCFG1 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3842 + addr=&_core_if->core_global_regs->ghwcfg2;
3843 + DWC_PRINT("GHWCFG2 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3844 + addr=&_core_if->core_global_regs->ghwcfg3;
3845 + DWC_PRINT("GHWCFG3 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3846 + addr=&_core_if->core_global_regs->ghwcfg4;
3847 + DWC_PRINT("GHWCFG4 @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3848 + addr=&_core_if->core_global_regs->hptxfsiz;
3849 + DWC_PRINT("HPTXFSIZ @0x%08X : 0x%08X\n",(uint32_t)addr,dwc_read_reg32(addr));
3850 +
3851 + for (i=0; i<_core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
3852 + addr=&_core_if->core_global_regs->dptxfsiz_dieptxf[i];
3853 + DWC_PRINT("DPTXFSIZ[%d] @0x%08X : 0x%08X\n",i,(uint32_t)addr,dwc_read_reg32(addr));
3854 + }
3855 +
3856 +}
3857 +#endif
3858 +
3859 +/**
3860 + * Flush a Tx FIFO.
3861 + *
3862 + * @param _core_if Programming view of DWC_otg controller.
3863 + * @param _num Tx FIFO to flush.
3864 + */
3865 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
3866 + const int _num )
3867 +{
3868 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3869 + volatile grstctl_t greset = { .d32 = 0};
3870 + int count = 0;
3871 +
3872 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "Flush Tx FIFO %d\n", _num);
3873 +
3874 + greset.b.txfflsh = 1;
3875 + greset.b.txfnum = _num;
3876 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3877 +
3878 + do {
3879 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3880 + if (++count > 10000){
3881 + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
3882 + __func__, greset.d32,
3883 + dwc_read_reg32( &global_regs->gnptxsts));
3884 + break;
3885 + }
3886 +
3887 + udelay(1);
3888 + } while (greset.b.txfflsh == 1);
3889 + /* Wait for 3 PHY Clocks*/
3890 + UDELAY(1);
3891 +}
3892 +
3893 +/**
3894 + * Flush Rx FIFO.
3895 + *
3896 + * @param _core_if Programming view of DWC_otg controller.
3897 + */
3898 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if )
3899 +{
3900 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3901 + volatile grstctl_t greset = { .d32 = 0};
3902 + int count = 0;
3903 +
3904 + DWC_DEBUGPL((DBG_CIL|DBG_PCDV), "%s\n", __func__);
3905 + /*
3906 + *
3907 + */
3908 + greset.b.rxfflsh = 1;
3909 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3910 +
3911 + do {
3912 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3913 + if (++count > 10000){
3914 + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
3915 + greset.d32);
3916 + break;
3917 + }
3918 + } while (greset.b.rxfflsh == 1);
3919 + /* Wait for 3 PHY Clocks*/
3920 + UDELAY(1);
3921 +}
3922 +
3923 +/**
3924 + * Do core a soft reset of the core. Be careful with this because it
3925 + * resets all the internal state machines of the core.
3926 + */
3927 +
3928 +void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if)
3929 +{
3930 + dwc_otg_core_global_regs_t *global_regs = _core_if->core_global_regs;
3931 + volatile grstctl_t greset = { .d32 = 0};
3932 + int count = 0;
3933 +
3934 + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
3935 + /* Wait for AHB master IDLE state. */
3936 + do {
3937 + UDELAY(10);
3938 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3939 + if (++count > 100000){
3940 + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x %x\n", __func__,
3941 + greset.d32, greset.b.ahbidle);
3942 + return;
3943 + }
3944 + } while (greset.b.ahbidle == 0);
3945 +
3946 +// winder add.
3947 +#if 1
3948 + /* Note: Actually, I don't exactly why we need to put delay here. */
3949 + MDELAY(100);
3950 +#endif
3951 + /* Core Soft Reset */
3952 + count = 0;
3953 + greset.b.csftrst = 1;
3954 + dwc_write_reg32( &global_regs->grstctl, greset.d32 );
3955 +// winder add.
3956 +#if 1
3957 + /* Note: Actually, I don't exactly why we need to put delay here. */
3958 + MDELAY(100);
3959 +#endif
3960 + do {
3961 + greset.d32 = dwc_read_reg32( &global_regs->grstctl);
3962 + if (++count > 10000){
3963 + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n", __func__,
3964 + greset.d32);
3965 + break;
3966 + }
3967 + udelay(1);
3968 + } while (greset.b.csftrst == 1);
3969 + /* Wait for 3 PHY Clocks*/
3970 + //DWC_PRINT("100ms\n");
3971 + MDELAY(100);
3972 +}
3973 +
3974 +
3975 +
3976 +/**
3977 + * Register HCD callbacks. The callbacks are used to start and stop
3978 + * the HCD for interrupt processing.
3979 + *
3980 + * @param _core_if Programming view of DWC_otg controller.
3981 + * @param _cb the HCD callback structure.
3982 + * @param _p pointer to be passed to callback function (usb_hcd*).
3983 + */
3984 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
3985 + dwc_otg_cil_callbacks_t *_cb,
3986 + void *_p)
3987 +{
3988 + _core_if->hcd_cb = _cb;
3989 + _cb->p = _p;
3990 +}
3991 +
3992 +/**
3993 + * Register PCD callbacks. The callbacks are used to start and stop
3994 + * the PCD for interrupt processing.
3995 + *
3996 + * @param _core_if Programming view of DWC_otg controller.
3997 + * @param _cb the PCD callback structure.
3998 + * @param _p pointer to be passed to callback function (pcd*).
3999 + */
4000 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
4001 + dwc_otg_cil_callbacks_t *_cb,
4002 + void *_p)
4003 +{
4004 + _core_if->pcd_cb = _cb;
4005 + _cb->p = _p;
4006 +}
4007 +
4008 --- /dev/null
4009 +++ b/drivers/usb/dwc_otg/dwc_otg_cil.h
4010 @@ -0,0 +1,911 @@
4011 +/* ==========================================================================
4012 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil.h $
4013 + * $Revision: 1.1.1.1 $
4014 + * $Date: 2009-04-17 06:15:34 $
4015 + * $Change: 631780 $
4016 + *
4017 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
4018 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
4019 + * otherwise expressly agreed to in writing between Synopsys and you.
4020 + *
4021 + * The Software IS NOT an item of Licensed Software or Licensed Product under
4022 + * any End User Software License Agreement or Agreement for Licensed Product
4023 + * with Synopsys or any supplement thereto. You are permitted to use and
4024 + * redistribute this Software in source and binary forms, with or without
4025 + * modification, provided that redistributions of source code must retain this
4026 + * notice. You may not view, use, disclose, copy or distribute this file or
4027 + * any information contained herein except pursuant to this license grant from
4028 + * Synopsys. If you do not agree with this notice, including the disclaimer
4029 + * below, then you are not authorized to use the Software.
4030 + *
4031 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
4032 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4033 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4034 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
4035 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
4036 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
4037 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
4038 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4039 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4040 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
4041 + * DAMAGE.
4042 + * ========================================================================== */
4043 +
4044 +#if !defined(__DWC_CIL_H__)
4045 +#define __DWC_CIL_H__
4046 +
4047 +#include "dwc_otg_plat.h"
4048 +
4049 +#include "dwc_otg_regs.h"
4050 +#ifdef DEBUG
4051 +#include "linux/timer.h"
4052 +#endif
4053 +
4054 +/* the OTG capabilities. */
4055 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
4056 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
4057 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
4058 +/* the maximum speed of operation in host and device mode. */
4059 +#define DWC_SPEED_PARAM_HIGH 0
4060 +#define DWC_SPEED_PARAM_FULL 1
4061 +/* the PHY clock rate in low power mode when connected to a
4062 + * Low Speed device in host mode. */
4063 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
4064 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
4065 +/* the type of PHY interface to use. */
4066 +#define DWC_PHY_TYPE_PARAM_FS 0
4067 +#define DWC_PHY_TYPE_PARAM_UTMI 1
4068 +#define DWC_PHY_TYPE_PARAM_ULPI 2
4069 +/* whether to use the internal or external supply to
4070 + * drive the vbus with a ULPI phy. */
4071 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
4072 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
4073 +/* EP type. */
4074 +
4075 +/**
4076 + * @file
4077 + * This file contains the interface to the Core Interface Layer.
4078 + */
4079 +
4080 +/**
4081 + * The <code>dwc_ep</code> structure represents the state of a single
4082 + * endpoint when acting in device mode. It contains the data items
4083 + * needed for an endpoint to be activated and transfer packets.
4084 + */
4085 +typedef struct dwc_ep {
4086 + /** EP number used for register address lookup */
4087 + uint8_t num;
4088 + /** EP direction 0 = OUT */
4089 + unsigned is_in : 1;
4090 + /** EP active. */
4091 + unsigned active : 1;
4092 +
4093 + /** Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic Tx FIFO
4094 + If dedicated Tx FIFOs are enabled for all IN Eps - Tx FIFO # FOR IN EPs*/
4095 + unsigned tx_fifo_num : 4;
4096 + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
4097 + unsigned type : 2;
4098 +#define DWC_OTG_EP_TYPE_CONTROL 0
4099 +#define DWC_OTG_EP_TYPE_ISOC 1
4100 +#define DWC_OTG_EP_TYPE_BULK 2
4101 +#define DWC_OTG_EP_TYPE_INTR 3
4102 +
4103 + /** DATA start PID for INTR and BULK EP */
4104 + unsigned data_pid_start : 1;
4105 + /** Frame (even/odd) for ISOC EP */
4106 + unsigned even_odd_frame : 1;
4107 + /** Max Packet bytes */
4108 + unsigned maxpacket : 11;
4109 +
4110 + /** @name Transfer state */
4111 + /** @{ */
4112 +
4113 + /**
4114 + * Pointer to the beginning of the transfer buffer -- do not modify
4115 + * during transfer.
4116 + */
4117 +
4118 + uint32_t dma_addr;
4119 +
4120 + uint8_t *start_xfer_buff;
4121 + /** pointer to the transfer buffer */
4122 + uint8_t *xfer_buff;
4123 + /** Number of bytes to transfer */
4124 + unsigned xfer_len : 19;
4125 + /** Number of bytes transferred. */
4126 + unsigned xfer_count : 19;
4127 + /** Sent ZLP */
4128 + unsigned sent_zlp : 1;
4129 + /** Total len for control transfer */
4130 + unsigned total_len : 19;
4131 +
4132 + /** stall clear flag */
4133 + unsigned stall_clear_flag : 1;
4134 +
4135 + /** @} */
4136 +} dwc_ep_t;
4137 +
4138 +/*
4139 + * Reasons for halting a host channel.
4140 + */
4141 +typedef enum dwc_otg_halt_status {
4142 + DWC_OTG_HC_XFER_NO_HALT_STATUS,
4143 + DWC_OTG_HC_XFER_COMPLETE,
4144 + DWC_OTG_HC_XFER_URB_COMPLETE,
4145 + DWC_OTG_HC_XFER_ACK,
4146 + DWC_OTG_HC_XFER_NAK,
4147 + DWC_OTG_HC_XFER_NYET,
4148 + DWC_OTG_HC_XFER_STALL,
4149 + DWC_OTG_HC_XFER_XACT_ERR,
4150 + DWC_OTG_HC_XFER_FRAME_OVERRUN,
4151 + DWC_OTG_HC_XFER_BABBLE_ERR,
4152 + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
4153 + DWC_OTG_HC_XFER_AHB_ERR,
4154 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
4155 + DWC_OTG_HC_XFER_URB_DEQUEUE
4156 +} dwc_otg_halt_status_e;
4157 +
4158 +/**
4159 + * Host channel descriptor. This structure represents the state of a single
4160 + * host channel when acting in host mode. It contains the data items needed to
4161 + * transfer packets to an endpoint via a host channel.
4162 + */
4163 +typedef struct dwc_hc {
4164 + /** Host channel number used for register address lookup */
4165 + uint8_t hc_num;
4166 +
4167 + /** Device to access */
4168 + unsigned dev_addr : 7;
4169 +
4170 + /** EP to access */
4171 + unsigned ep_num : 4;
4172 +
4173 + /** EP direction. 0: OUT, 1: IN */
4174 + unsigned ep_is_in : 1;
4175 +
4176 + /**
4177 + * EP speed.
4178 + * One of the following values:
4179 + * - DWC_OTG_EP_SPEED_LOW
4180 + * - DWC_OTG_EP_SPEED_FULL
4181 + * - DWC_OTG_EP_SPEED_HIGH
4182 + */
4183 + unsigned speed : 2;
4184 +#define DWC_OTG_EP_SPEED_LOW 0
4185 +#define DWC_OTG_EP_SPEED_FULL 1
4186 +#define DWC_OTG_EP_SPEED_HIGH 2
4187 +
4188 + /**
4189 + * Endpoint type.
4190 + * One of the following values:
4191 + * - DWC_OTG_EP_TYPE_CONTROL: 0
4192 + * - DWC_OTG_EP_TYPE_ISOC: 1
4193 + * - DWC_OTG_EP_TYPE_BULK: 2
4194 + * - DWC_OTG_EP_TYPE_INTR: 3
4195 + */
4196 + unsigned ep_type : 2;
4197 +
4198 + /** Max packet size in bytes */
4199 + unsigned max_packet : 11;
4200 +
4201 + /**
4202 + * PID for initial transaction.
4203 + * 0: DATA0,<br>
4204 + * 1: DATA2,<br>
4205 + * 2: DATA1,<br>
4206 + * 3: MDATA (non-Control EP),
4207 + * SETUP (Control EP)
4208 + */
4209 + unsigned data_pid_start : 2;
4210 +#define DWC_OTG_HC_PID_DATA0 0
4211 +#define DWC_OTG_HC_PID_DATA2 1
4212 +#define DWC_OTG_HC_PID_DATA1 2
4213 +#define DWC_OTG_HC_PID_MDATA 3
4214 +#define DWC_OTG_HC_PID_SETUP 3
4215 +
4216 + /** Number of periodic transactions per (micro)frame */
4217 + unsigned multi_count: 2;
4218 +
4219 + /** @name Transfer State */
4220 + /** @{ */
4221 +
4222 + /** Pointer to the current transfer buffer position. */
4223 + uint8_t *xfer_buff;
4224 + /** Total number of bytes to transfer. */
4225 + uint32_t xfer_len;
4226 + /** Number of bytes transferred so far. */
4227 + uint32_t xfer_count;
4228 + /** Packet count at start of transfer.*/
4229 + uint16_t start_pkt_count;
4230 +
4231 + /**
4232 + * Flag to indicate whether the transfer has been started. Set to 1 if
4233 + * it has been started, 0 otherwise.
4234 + */
4235 + uint8_t xfer_started;
4236 +
4237 + /**
4238 + * Set to 1 to indicate that a PING request should be issued on this
4239 + * channel. If 0, process normally.
4240 + */
4241 + uint8_t do_ping;
4242 +
4243 + /**
4244 + * Set to 1 to indicate that the error count for this transaction is
4245 + * non-zero. Set to 0 if the error count is 0.
4246 + */
4247 + uint8_t error_state;
4248 +
4249 + /**
4250 + * Set to 1 to indicate that this channel should be halted the next
4251 + * time a request is queued for the channel. This is necessary in
4252 + * slave mode if no request queue space is available when an attempt
4253 + * is made to halt the channel.
4254 + */
4255 + uint8_t halt_on_queue;
4256 +
4257 + /**
4258 + * Set to 1 if the host channel has been halted, but the core is not
4259 + * finished flushing queued requests. Otherwise 0.
4260 + */
4261 + uint8_t halt_pending;
4262 +
4263 + /**
4264 + * Reason for halting the host channel.
4265 + */
4266 + dwc_otg_halt_status_e halt_status;
4267 +
4268 + /*
4269 + * Split settings for the host channel
4270 + */
4271 + uint8_t do_split; /**< Enable split for the channel */
4272 + uint8_t complete_split; /**< Enable complete split */
4273 + uint8_t hub_addr; /**< Address of high speed hub */
4274 +
4275 + uint8_t port_addr; /**< Port of the low/full speed device */
4276 + /** Split transaction position
4277 + * One of the following values:
4278 + * - DWC_HCSPLIT_XACTPOS_MID
4279 + * - DWC_HCSPLIT_XACTPOS_BEGIN
4280 + * - DWC_HCSPLIT_XACTPOS_END
4281 + * - DWC_HCSPLIT_XACTPOS_ALL */
4282 + uint8_t xact_pos;
4283 +
4284 + /** Set when the host channel does a short read. */
4285 + uint8_t short_read;
4286 +
4287 + /**
4288 + * Number of requests issued for this channel since it was assigned to
4289 + * the current transfer (not counting PINGs).
4290 + */
4291 + uint8_t requests;
4292 +
4293 + /**
4294 + * Queue Head for the transfer being processed by this channel.
4295 + */
4296 + struct dwc_otg_qh *qh;
4297 +
4298 + /** @} */
4299 +
4300 + /** Entry in list of host channels. */
4301 + struct list_head hc_list_entry;
4302 +} dwc_hc_t;
4303 +
4304 +/**
4305 + * The following parameters may be specified when starting the module. These
4306 + * parameters define how the DWC_otg controller should be configured.
4307 + * Parameter values are passed to the CIL initialization function
4308 + * dwc_otg_cil_init.
4309 + */
4310 +
4311 +typedef struct dwc_otg_core_params
4312 +{
4313 + int32_t opt;
4314 +//#define dwc_param_opt_default 1
4315 + /**
4316 + * Specifies the OTG capabilities. The driver will automatically
4317 + * detect the value for this parameter if none is specified.
4318 + * 0 - HNP and SRP capable (default)
4319 + * 1 - SRP Only capable
4320 + * 2 - No HNP/SRP capable
4321 + */
4322 + int32_t otg_cap;
4323 +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
4324 +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
4325 +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
4326 +//#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
4327 + /**
4328 + * Specifies whether to use slave or DMA mode for accessing the data
4329 + * FIFOs. The driver will automatically detect the value for this
4330 + * parameter if none is specified.
4331 + * 0 - Slave
4332 + * 1 - DMA (default, if available)
4333 + */
4334 + int32_t dma_enable;
4335 +//#define dwc_param_dma_enable_default 1
4336 + /** The DMA Burst size (applicable only for External DMA
4337 + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
4338 + */
4339 + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
4340 +//#define dwc_param_dma_burst_size_default 32
4341 + /**
4342 + * Specifies the maximum speed of operation in host and device mode.
4343 + * The actual speed depends on the speed of the attached device and
4344 + * the value of phy_type. The actual speed depends on the speed of the
4345 + * attached device.
4346 + * 0 - High Speed (default)
4347 + * 1 - Full Speed
4348 + */
4349 + int32_t speed;
4350 +//#define dwc_param_speed_default 0
4351 +#define DWC_SPEED_PARAM_HIGH 0
4352 +#define DWC_SPEED_PARAM_FULL 1
4353 +
4354 + /** Specifies whether low power mode is supported when attached
4355 + * to a Full Speed or Low Speed device in host mode.
4356 + * 0 - Don't support low power mode (default)
4357 + * 1 - Support low power mode
4358 + */
4359 + int32_t host_support_fs_ls_low_power;
4360 +//#define dwc_param_host_support_fs_ls_low_power_default 0
4361 + /** Specifies the PHY clock rate in low power mode when connected to a
4362 + * Low Speed device in host mode. This parameter is applicable only if
4363 + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
4364 + * then defaults to 6 MHZ otherwise 48 MHZ.
4365 + *
4366 + * 0 - 48 MHz
4367 + * 1 - 6 MHz
4368 + */
4369 + int32_t host_ls_low_power_phy_clk;
4370 +//#define dwc_param_host_ls_low_power_phy_clk_default 0
4371 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
4372 +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
4373 + /**
4374 + * 0 - Use cC FIFO size parameters
4375 + * 1 - Allow dynamic FIFO sizing (default)
4376 + */
4377 + int32_t enable_dynamic_fifo;
4378 +//#define dwc_param_enable_dynamic_fifo_default 1
4379 + /** Total number of 4-byte words in the data FIFO memory. This
4380 + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
4381 + * Tx FIFOs.
4382 + * 32 to 32768 (default 8192)
4383 + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
4384 + */
4385 + int32_t data_fifo_size;
4386 +//#define dwc_param_data_fifo_size_default 8192
4387 + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
4388 + * FIFO sizing is enabled.
4389 + * 16 to 32768 (default 1064)
4390 + */
4391 + int32_t dev_rx_fifo_size;
4392 +//#define dwc_param_dev_rx_fifo_size_default 1064
4393 + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
4394 + * when dynamic FIFO sizing is enabled.
4395 + * 16 to 32768 (default 1024)
4396 + */
4397 + int32_t dev_nperio_tx_fifo_size;
4398 +//#define dwc_param_dev_nperio_tx_fifo_size_default 1024
4399 + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
4400 + * mode when dynamic FIFO sizing is enabled.
4401 + * 4 to 768 (default 256)
4402 + */
4403 + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
4404 +//#define dwc_param_dev_perio_tx_fifo_size_default 256
4405 + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
4406 + * FIFO sizing is enabled.
4407 + * 16 to 32768 (default 1024)
4408 + */
4409 + int32_t host_rx_fifo_size;
4410 +//#define dwc_param_host_rx_fifo_size_default 1024
4411 + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
4412 + * when Dynamic FIFO sizing is enabled in the core.
4413 + * 16 to 32768 (default 1024)
4414 + */
4415 + int32_t host_nperio_tx_fifo_size;
4416 +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
4417 + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
4418 + * FIFO sizing is enabled.
4419 + * 16 to 32768 (default 1024)
4420 + */
4421 + int32_t host_perio_tx_fifo_size;
4422 +//#define dwc_param_host_perio_tx_fifo_size_default 1024
4423 + /** The maximum transfer size supported in bytes.
4424 + * 2047 to 65,535 (default 65,535)
4425 + */
4426 + int32_t max_transfer_size;
4427 +//#define dwc_param_max_transfer_size_default 65535
4428 + /** The maximum number of packets in a transfer.
4429 + * 15 to 511 (default 511)
4430 + */
4431 + int32_t max_packet_count;
4432 +//#define dwc_param_max_packet_count_default 511
4433 + /** The number of host channel registers to use.
4434 + * 1 to 16 (default 12)
4435 + * Note: The FPGA configuration supports a maximum of 12 host channels.
4436 + */
4437 + int32_t host_channels;
4438 +//#define dwc_param_host_channels_default 12
4439 + /** The number of endpoints in addition to EP0 available for device
4440 + * mode operations.
4441 + * 1 to 15 (default 6 IN and OUT)
4442 + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
4443 + * endpoints in addition to EP0.
4444 + */
4445 + int32_t dev_endpoints;
4446 +//#define dwc_param_dev_endpoints_default 6
4447 + /**
4448 + * Specifies the type of PHY interface to use. By default, the driver
4449 + * will automatically detect the phy_type.
4450 + *
4451 + * 0 - Full Speed PHY
4452 + * 1 - UTMI+ (default)
4453 + * 2 - ULPI
4454 + */
4455 + int32_t phy_type;
4456 +#define DWC_PHY_TYPE_PARAM_FS 0
4457 +#define DWC_PHY_TYPE_PARAM_UTMI 1
4458 +#define DWC_PHY_TYPE_PARAM_ULPI 2
4459 +//#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
4460 + /**
4461 + * Specifies the UTMI+ Data Width. This parameter is
4462 + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
4463 + * PHY_TYPE, this parameter indicates the data width between
4464 + * the MAC and the ULPI Wrapper.) Also, this parameter is
4465 + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
4466 + * to "8 and 16 bits", meaning that the core has been
4467 + * configured to work at either data path width.
4468 + *
4469 + * 8 or 16 bits (default 16)
4470 + */
4471 + int32_t phy_utmi_width;
4472 +//#define dwc_param_phy_utmi_width_default 16
4473 + /**
4474 + * Specifies whether the ULPI operates at double or single
4475 + * data rate. This parameter is only applicable if PHY_TYPE is
4476 + * ULPI.
4477 + *
4478 + * 0 - single data rate ULPI interface with 8 bit wide data
4479 + * bus (default)
4480 + * 1 - double data rate ULPI interface with 4 bit wide data
4481 + * bus
4482 + */
4483 + int32_t phy_ulpi_ddr;
4484 +//#define dwc_param_phy_ulpi_ddr_default 0
4485 + /**
4486 + * Specifies whether to use the internal or external supply to
4487 + * drive the vbus with a ULPI phy.
4488 + */
4489 + int32_t phy_ulpi_ext_vbus;
4490 +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
4491 +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
4492 +//#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
4493 + /**
4494 + * Specifies whether to use the I2Cinterface for full speed PHY. This
4495 + * parameter is only applicable if PHY_TYPE is FS.
4496 + * 0 - No (default)
4497 + * 1 - Yes
4498 + */
4499 + int32_t i2c_enable;
4500 +//#define dwc_param_i2c_enable_default 0
4501 +
4502 + int32_t ulpi_fs_ls;
4503 +//#define dwc_param_ulpi_fs_ls_default 0
4504 +
4505 + int32_t ts_dline;
4506 +//#define dwc_param_ts_dline_default 0
4507 +
4508 + /**
4509 + * Specifies whether dedicated transmit FIFOs are
4510 + * enabled for non periodic IN endpoints in device mode
4511 + * 0 - No
4512 + * 1 - Yes
4513 + */
4514 + int32_t en_multiple_tx_fifo;
4515 +#define dwc_param_en_multiple_tx_fifo_default 1
4516 +
4517 + /** Number of 4-byte words in each of the Tx FIFOs in device
4518 + * mode when dynamic FIFO sizing is enabled.
4519 + * 4 to 768 (default 256)
4520 + */
4521 + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
4522 +#define dwc_param_dev_tx_fifo_size_default 256
4523 +
4524 + /** Thresholding enable flag-
4525 + * bit 0 - enable non-ISO Tx thresholding
4526 + * bit 1 - enable ISO Tx thresholding
4527 + * bit 2 - enable Rx thresholding
4528 + */
4529 + uint32_t thr_ctl;
4530 +#define dwc_param_thr_ctl_default 0
4531 +
4532 + /** Thresholding length for Tx
4533 + * FIFOs in 32 bit DWORDs
4534 + */
4535 + uint32_t tx_thr_length;
4536 +#define dwc_param_tx_thr_length_default 64
4537 +
4538 + /** Thresholding length for Rx
4539 + * FIFOs in 32 bit DWORDs
4540 + */
4541 + uint32_t rx_thr_length;
4542 +#define dwc_param_rx_thr_length_default 64
4543 +} dwc_otg_core_params_t;
4544 +
4545 +#ifdef DEBUG
4546 +struct dwc_otg_core_if;
4547 +typedef struct hc_xfer_info
4548 +{
4549 + struct dwc_otg_core_if *core_if;
4550 + dwc_hc_t *hc;
4551 +} hc_xfer_info_t;
4552 +#endif
4553 +
4554 +/**
4555 + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
4556 + * the DWC_otg controller acting in either host or device mode. It
4557 + * represents the programming view of the controller as a whole.
4558 + */
4559 +typedef struct dwc_otg_core_if
4560 +{
4561 + /** Parameters that define how the core should be configured.*/
4562 + dwc_otg_core_params_t *core_params;
4563 +
4564 + /** Core Global registers starting at offset 000h. */
4565 + dwc_otg_core_global_regs_t *core_global_regs;
4566 +
4567 + /** Device-specific information */
4568 + dwc_otg_dev_if_t *dev_if;
4569 + /** Host-specific information */
4570 + dwc_otg_host_if_t *host_if;
4571 +
4572 + /*
4573 + * Set to 1 if the core PHY interface bits in USBCFG have been
4574 + * initialized.
4575 + */
4576 + uint8_t phy_init_done;
4577 +
4578 + /*
4579 + * SRP Success flag, set by srp success interrupt in FS I2C mode
4580 + */
4581 + uint8_t srp_success;
4582 + uint8_t srp_timer_started;
4583 +
4584 + /* Common configuration information */
4585 + /** Power and Clock Gating Control Register */
4586 + volatile uint32_t *pcgcctl;
4587 +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
4588 +
4589 + /** Push/pop addresses for endpoints or host channels.*/
4590 + uint32_t *data_fifo[MAX_EPS_CHANNELS];
4591 +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
4592 +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
4593 +
4594 + /** Total RAM for FIFOs (Bytes) */
4595 + uint16_t total_fifo_size;
4596 + /** Size of Rx FIFO (Bytes) */
4597 + uint16_t rx_fifo_size;
4598 + /** Size of Non-periodic Tx FIFO (Bytes) */
4599 + uint16_t nperio_tx_fifo_size;
4600 +
4601 + /** 1 if DMA is enabled, 0 otherwise. */
4602 + uint8_t dma_enable;
4603 +
4604 + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
4605 + uint8_t en_multiple_tx_fifo;
4606 +
4607 + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
4608 + * process of being queued */
4609 + uint8_t queuing_high_bandwidth;
4610 +
4611 + /** Hardware Configuration -- stored here for convenience.*/
4612 + hwcfg1_data_t hwcfg1;
4613 + hwcfg2_data_t hwcfg2;
4614 + hwcfg3_data_t hwcfg3;
4615 + hwcfg4_data_t hwcfg4;
4616 +
4617 + /** The operational State, during transations
4618 + * (a_host>>a_peripherial and b_device=>b_host) this may not
4619 + * match the core but allows the software to determine
4620 + * transitions.
4621 + */
4622 + uint8_t op_state;
4623 +
4624 + /**
4625 + * Set to 1 if the HCD needs to be restarted on a session request
4626 + * interrupt. This is required if no connector ID status change has
4627 + * occurred since the HCD was last disconnected.
4628 + */
4629 + uint8_t restart_hcd_on_session_req;
4630 +
4631 + /** HCD callbacks */
4632 + /** A-Device is a_host */
4633 +#define A_HOST (1)
4634 + /** A-Device is a_suspend */
4635 +#define A_SUSPEND (2)
4636 + /** A-Device is a_peripherial */
4637 +#define A_PERIPHERAL (3)
4638 + /** B-Device is operating as a Peripheral. */
4639 +#define B_PERIPHERAL (4)
4640 + /** B-Device is operating as a Host. */
4641 +#define B_HOST (5)
4642 +
4643 + /** HCD callbacks */
4644 + struct dwc_otg_cil_callbacks *hcd_cb;
4645 + /** PCD callbacks */
4646 + struct dwc_otg_cil_callbacks *pcd_cb;
4647 +
4648 + /** Device mode Periodic Tx FIFO Mask */
4649 + uint32_t p_tx_msk;
4650 + /** Device mode Periodic Tx FIFO Mask */
4651 + uint32_t tx_msk;
4652 +
4653 +#ifdef DEBUG
4654 + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
4655 +
4656 + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
4657 + struct timer_list hc_xfer_timer[MAX_EPS_CHANNELS];
4658 +
4659 +#if 1 // winder
4660 + uint32_t hfnum_7_samples;
4661 + uint32_t hfnum_7_frrem_accum;
4662 + uint32_t hfnum_0_samples;
4663 + uint32_t hfnum_0_frrem_accum;
4664 + uint32_t hfnum_other_samples;
4665 + uint32_t hfnum_other_frrem_accum;
4666 +#else
4667 + uint32_t hfnum_7_samples;
4668 + uint64_t hfnum_7_frrem_accum;
4669 + uint32_t hfnum_0_samples;
4670 + uint64_t hfnum_0_frrem_accum;
4671 + uint32_t hfnum_other_samples;
4672 + uint64_t hfnum_other_frrem_accum;
4673 +#endif
4674 + resource_size_t phys_addr; /* Added to support PLB DMA : phys-virt mapping */
4675 +#endif
4676 +
4677 +} dwc_otg_core_if_t;
4678 +
4679 +/*
4680 + * The following functions support initialization of the CIL driver component
4681 + * and the DWC_otg controller.
4682 + */
4683 +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t *_reg_base_addr,
4684 + dwc_otg_core_params_t *_core_params);
4685 +extern void dwc_otg_cil_remove(dwc_otg_core_if_t *_core_if);
4686 +extern void dwc_otg_core_init(dwc_otg_core_if_t *_core_if);
4687 +extern void dwc_otg_core_host_init(dwc_otg_core_if_t *_core_if);
4688 +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if);
4689 +extern void dwc_otg_enable_global_interrupts( dwc_otg_core_if_t *_core_if );
4690 +extern void dwc_otg_disable_global_interrupts( dwc_otg_core_if_t *_core_if );
4691 +
4692 +/** @name Device CIL Functions
4693 + * The following functions support managing the DWC_otg controller in device
4694 + * mode.
4695 + */
4696 +/**@{*/
4697 +extern void dwc_otg_wakeup(dwc_otg_core_if_t *_core_if);
4698 +extern void dwc_otg_read_setup_packet (dwc_otg_core_if_t *_core_if, uint32_t *_dest);
4699 +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t *_core_if);
4700 +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4701 +extern void dwc_otg_ep_activate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4702 +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4703 +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4704 +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4705 +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4706 +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep, int _dma);
4707 +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4708 +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t *_core_if, dwc_ep_t *_ep);
4709 +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t *_core_if);
4710 +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t *_core_if);
4711 +/**@}*/
4712 +
4713 +/** @name Host CIL Functions
4714 + * The following functions support managing the DWC_otg controller in host
4715 + * mode.
4716 + */
4717 +/**@{*/
4718 +extern void dwc_otg_hc_init(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4719 +extern void dwc_otg_hc_halt(dwc_otg_core_if_t *_core_if,
4720 + dwc_hc_t *_hc,
4721 + dwc_otg_halt_status_e _halt_status);
4722 +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4723 +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4724 +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4725 +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4726 +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc);
4727 +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t *_core_if);
4728 +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t *_core_if);
4729 +
4730 +/**
4731 + * This function Reads HPRT0 in preparation to modify. It keeps the
4732 + * WC bits 0 so that if they are read as 1, they won't clear when you
4733 + * write it back
4734 + */
4735 +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t *_core_if)
4736 +{
4737 + hprt0_data_t hprt0;
4738 + hprt0.d32 = dwc_read_reg32(_core_if->host_if->hprt0);
4739 + hprt0.b.prtena = 0;
4740 + hprt0.b.prtconndet = 0;
4741 + hprt0.b.prtenchng = 0;
4742 + hprt0.b.prtovrcurrchng = 0;
4743 + return hprt0.d32;
4744 +}
4745 +
4746 +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t *_core_if);
4747 +/**@}*/
4748 +
4749 +/** @name Common CIL Functions
4750 + * The following functions support managing the DWC_otg controller in either
4751 + * device or host mode.
4752 + */
4753 +/**@{*/
4754 +
4755 +extern void dwc_otg_read_packet(dwc_otg_core_if_t *core_if,
4756 + uint8_t *dest,
4757 + uint16_t bytes);
4758 +
4759 +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t *_core_if);
4760 +
4761 +extern void dwc_otg_flush_tx_fifo( dwc_otg_core_if_t *_core_if,
4762 + const int _num );
4763 +extern void dwc_otg_flush_rx_fifo( dwc_otg_core_if_t *_core_if );
4764 +extern void dwc_otg_core_reset( dwc_otg_core_if_t *_core_if );
4765 +
4766 +#define NP_TXFIFO_EMPTY -1
4767 +#define MAX_NP_TXREQUEST_Q_SLOTS 8
4768 +/**
4769 + * This function returns the endpoint number of the request at
4770 + * the top of non-periodic TX FIFO, or -1 if the request FIFO is
4771 + * empty.
4772 + */
4773 +static inline int dwc_otg_top_nptxfifo_epnum(dwc_otg_core_if_t *_core_if) {
4774 + gnptxsts_data_t txstatus = {.d32 = 0};
4775 +
4776 + txstatus.d32 = dwc_read_reg32(&_core_if->core_global_regs->gnptxsts);
4777 + return (txstatus.b.nptxqspcavail == MAX_NP_TXREQUEST_Q_SLOTS ?
4778 + -1 : txstatus.b.nptxqtop_chnep);
4779 +}
4780 +/**
4781 + * This function returns the Core Interrupt register.
4782 + */
4783 +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t *_core_if) {
4784 + return (dwc_read_reg32(&_core_if->core_global_regs->gintsts) &
4785 + dwc_read_reg32(&_core_if->core_global_regs->gintmsk));
4786 +}
4787 +
4788 +/**
4789 + * This function returns the OTG Interrupt register.
4790 + */
4791 +static inline uint32_t dwc_otg_read_otg_intr (dwc_otg_core_if_t *_core_if) {
4792 + return (dwc_read_reg32 (&_core_if->core_global_regs->gotgint));
4793 +}
4794 +
4795 +/**
4796 + * This function reads the Device All Endpoints Interrupt register and
4797 + * returns the IN endpoint interrupt bits.
4798 + */
4799 +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *_core_if) {
4800 + uint32_t v;
4801 + v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
4802 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
4803 + return (v & 0xffff);
4804 +
4805 +}
4806 +
4807 +/**
4808 + * This function reads the Device All Endpoints Interrupt register and
4809 + * returns the OUT endpoint interrupt bits.
4810 + */
4811 +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *_core_if) {
4812 + uint32_t v;
4813 + v = dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daint) &
4814 + dwc_read_reg32(&_core_if->dev_if->dev_global_regs->daintmsk);
4815 + return ((v & 0xffff0000) >> 16);
4816 +}
4817 +
4818 +/**
4819 + * This function returns the Device IN EP Interrupt register
4820 + */
4821 +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t *_core_if,
4822 + dwc_ep_t *_ep)
4823 +{
4824 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4825 + uint32_t v, msk, emp;
4826 + msk = dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
4827 + emp = dwc_read_reg32(&dev_if->dev_global_regs->dtknqr4_fifoemptymsk);
4828 + msk |= ((emp >> _ep->num) & 0x1) << 7;
4829 + v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) & msk;
4830 +/*
4831 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4832 + uint32_t v;
4833 + v = dwc_read_reg32(&dev_if->in_ep_regs[_ep->num]->diepint) &
4834 + dwc_read_reg32(&dev_if->dev_global_regs->diepmsk);
4835 +*/
4836 + return v;
4837 +}
4838 +/**
4839 + * This function returns the Device OUT EP Interrupt register
4840 + */
4841 +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *_core_if,
4842 + dwc_ep_t *_ep)
4843 +{
4844 + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
4845 + uint32_t v;
4846 + v = dwc_read_reg32( &dev_if->out_ep_regs[_ep->num]->doepint) &
4847 + dwc_read_reg32(&dev_if->dev_global_regs->doepmsk);
4848 + return v;
4849 +}
4850 +
4851 +/**
4852 + * This function returns the Host All Channel Interrupt register
4853 + */
4854 +static inline uint32_t dwc_otg_read_host_all_channels_intr (dwc_otg_core_if_t *_core_if)
4855 +{
4856 + return (dwc_read_reg32 (&_core_if->host_if->host_global_regs->haint));
4857 +}
4858 +
4859 +static inline uint32_t dwc_otg_read_host_channel_intr (dwc_otg_core_if_t *_core_if, dwc_hc_t *_hc)
4860 +{
4861 + return (dwc_read_reg32 (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
4862 +}
4863 +
4864 +
4865 +/**
4866 + * This function returns the mode of the operation, host or device.
4867 + *
4868 + * @return 0 - Device Mode, 1 - Host Mode
4869 + */
4870 +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t *_core_if) {
4871 + return (dwc_read_reg32( &_core_if->core_global_regs->gintsts ) & 0x1);
4872 +}
4873 +
4874 +static inline uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t *_core_if)
4875 +{
4876 + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
4877 +}
4878 +static inline uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t *_core_if)
4879 +{
4880 + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
4881 +}
4882 +
4883 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if );
4884 +
4885 +
4886 +/**@}*/
4887 +
4888 +/**
4889 + * DWC_otg CIL callback structure. This structure allows the HCD and
4890 + * PCD to register functions used for starting and stopping the PCD
4891 + * and HCD for role change on for a DRD.
4892 + */
4893 +typedef struct dwc_otg_cil_callbacks
4894 +{
4895 + /** Start function for role change */
4896 + int (*start) (void *_p);
4897 + /** Stop Function for role change */
4898 + int (*stop) (void *_p);
4899 + /** Disconnect Function for role change */
4900 + int (*disconnect) (void *_p);
4901 + /** Resume/Remote wakeup Function */
4902 + int (*resume_wakeup) (void *_p);
4903 + /** Suspend function */
4904 + int (*suspend) (void *_p);
4905 + /** Session Start (SRP) */
4906 + int (*session_start) (void *_p);
4907 + /** Pointer passed to start() and stop() */
4908 + void *p;
4909 +} dwc_otg_cil_callbacks_t;
4910 +
4911 +
4912 +
4913 +extern void dwc_otg_cil_register_pcd_callbacks( dwc_otg_core_if_t *_core_if,
4914 + dwc_otg_cil_callbacks_t *_cb,
4915 + void *_p);
4916 +extern void dwc_otg_cil_register_hcd_callbacks( dwc_otg_core_if_t *_core_if,
4917 + dwc_otg_cil_callbacks_t *_cb,
4918 + void *_p);
4919 +
4920 +
4921 +#endif
4922 --- /dev/null
4923 +++ b/drivers/usb/dwc_otg/dwc_otg_cil_ifx.h
4924 @@ -0,0 +1,58 @@
4925 +/******************************************************************************
4926 +**
4927 +** FILE NAME : dwc_otg_cil_ifx.h
4928 +** PROJECT : Twinpass/Danube
4929 +** MODULES : DWC OTG USB
4930 +**
4931 +** DATE : 07 Sep. 2007
4932 +** AUTHOR : Sung Winder
4933 +** DESCRIPTION : Default param value.
4934 +** COPYRIGHT : Copyright (c) 2007
4935 +** Infineon Technologies AG
4936 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
4937 +** Hsin-chu City, 300 Taiwan.
4938 +**
4939 +** This program is free software; you can redistribute it and/or modify
4940 +** it under the terms of the GNU General Public License as published by
4941 +** the Free Software Foundation; either version 2 of the License, or
4942 +** (at your option) any later version.
4943 +**
4944 +** HISTORY
4945 +** $Date $Author $Comment
4946 +** 12 April 2007 Sung Winder Initiate Version
4947 +*******************************************************************************/
4948 +#if !defined(__DWC_OTG_CIL_IFX_H__)
4949 +#define __DWC_OTG_CIL_IFX_H__
4950 +
4951 +/* ================ Default param value ================== */
4952 +#define dwc_param_opt_default 1
4953 +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE
4954 +#define dwc_param_dma_enable_default 1
4955 +#define dwc_param_dma_burst_size_default 32
4956 +#define dwc_param_speed_default DWC_SPEED_PARAM_HIGH
4957 +#define dwc_param_host_support_fs_ls_low_power_default 0
4958 +#define dwc_param_host_ls_low_power_phy_clk_default DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ
4959 +#define dwc_param_enable_dynamic_fifo_default 1
4960 +#define dwc_param_data_fifo_size_default 2048
4961 +#define dwc_param_dev_rx_fifo_size_default 1024
4962 +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
4963 +#define dwc_param_dev_perio_tx_fifo_size_default 768
4964 +#define dwc_param_host_rx_fifo_size_default 640
4965 +#define dwc_param_host_nperio_tx_fifo_size_default 640
4966 +#define dwc_param_host_perio_tx_fifo_size_default 768
4967 +#define dwc_param_max_transfer_size_default 65535
4968 +#define dwc_param_max_packet_count_default 511
4969 +#define dwc_param_host_channels_default 16
4970 +#define dwc_param_dev_endpoints_default 6
4971 +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
4972 +#define dwc_param_phy_utmi_width_default 16
4973 +#define dwc_param_phy_ulpi_ddr_default 0
4974 +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
4975 +#define dwc_param_i2c_enable_default 0
4976 +#define dwc_param_ulpi_fs_ls_default 0
4977 +#define dwc_param_ts_dline_default 0
4978 +
4979 +/* ======================================================= */
4980 +
4981 +#endif // __DWC_OTG_CIL_IFX_H__
4982 +
4983 --- /dev/null
4984 +++ b/drivers/usb/dwc_otg/dwc_otg_cil_intr.c
4985 @@ -0,0 +1,708 @@
4986 +/* ==========================================================================
4987 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_cil_intr.c $
4988 + * $Revision: 1.1.1.1 $
4989 + * $Date: 2009-04-17 06:15:34 $
4990 + * $Change: 553126 $
4991 + *
4992 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
4993 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
4994 + * otherwise expressly agreed to in writing between Synopsys and you.
4995 + *
4996 + * The Software IS NOT an item of Licensed Software or Licensed Product under
4997 + * any End User Software License Agreement or Agreement for Licensed Product
4998 + * with Synopsys or any supplement thereto. You are permitted to use and
4999 + * redistribute this Software in source and binary forms, with or without
5000 + * modification, provided that redistributions of source code must retain this
5001 + * notice. You may not view, use, disclose, copy or distribute this file or
5002 + * any information contained herein except pursuant to this license grant from
5003 + * Synopsys. If you do not agree with this notice, including the disclaimer
5004 + * below, then you are not authorized to use the Software.
5005 + *
5006 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
5007 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5008 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5009 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
5010 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5011 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5012 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5013 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5014 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5015 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
5016 + * DAMAGE.
5017 + * ========================================================================== */
5018 +
5019 +/** @file
5020 + *
5021 + * The Core Interface Layer provides basic services for accessing and
5022 + * managing the DWC_otg hardware. These services are used by both the
5023 + * Host Controller Driver and the Peripheral Controller Driver.
5024 + *
5025 + * This file contains the Common Interrupt handlers.
5026 + */
5027 +#include "dwc_otg_plat.h"
5028 +#include "dwc_otg_regs.h"
5029 +#include "dwc_otg_cil.h"
5030 +
5031 +#ifdef DEBUG
5032 +inline const char *op_state_str( dwc_otg_core_if_t *_core_if )
5033 +{
5034 + return (_core_if->op_state==A_HOST?"a_host":
5035 + (_core_if->op_state==A_SUSPEND?"a_suspend":
5036 + (_core_if->op_state==A_PERIPHERAL?"a_peripheral":
5037 + (_core_if->op_state==B_PERIPHERAL?"b_peripheral":
5038 + (_core_if->op_state==B_HOST?"b_host":
5039 + "unknown")))));
5040 +}
5041 +#endif
5042 +
5043 +/** This function will log a debug message
5044 + *
5045 + * @param _core_if Programming view of DWC_otg controller.
5046 + */
5047 +int32_t dwc_otg_handle_mode_mismatch_intr (dwc_otg_core_if_t *_core_if)
5048 +{
5049 + gintsts_data_t gintsts;
5050 + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
5051 + dwc_otg_mode(_core_if) ? "Host" : "Device");
5052 +
5053 + /* Clear interrupt */
5054 + gintsts.d32 = 0;
5055 + gintsts.b.modemismatch = 1;
5056 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5057 + return 1;
5058 +}
5059 +
5060 +/** Start the HCD. Helper function for using the HCD callbacks.
5061 + *
5062 + * @param _core_if Programming view of DWC_otg controller.
5063 + */
5064 +static inline void hcd_start( dwc_otg_core_if_t *_core_if )
5065 +{
5066 + if (_core_if->hcd_cb && _core_if->hcd_cb->start) {
5067 + _core_if->hcd_cb->start( _core_if->hcd_cb->p );
5068 + }
5069 +}
5070 +/** Stop the HCD. Helper function for using the HCD callbacks.
5071 + *
5072 + * @param _core_if Programming view of DWC_otg controller.
5073 + */
5074 +static inline void hcd_stop( dwc_otg_core_if_t *_core_if )
5075 +{
5076 + if (_core_if->hcd_cb && _core_if->hcd_cb->stop) {
5077 + _core_if->hcd_cb->stop( _core_if->hcd_cb->p );
5078 + }
5079 +}
5080 +/** Disconnect the HCD. Helper function for using the HCD callbacks.
5081 + *
5082 + * @param _core_if Programming view of DWC_otg controller.
5083 + */
5084 +static inline void hcd_disconnect( dwc_otg_core_if_t *_core_if )
5085 +{
5086 + if (_core_if->hcd_cb && _core_if->hcd_cb->disconnect) {
5087 + _core_if->hcd_cb->disconnect( _core_if->hcd_cb->p );
5088 + }
5089 +}
5090 +/** Inform the HCD the a New Session has begun. Helper function for
5091 + * using the HCD callbacks.
5092 + *
5093 + * @param _core_if Programming view of DWC_otg controller.
5094 + */
5095 +static inline void hcd_session_start( dwc_otg_core_if_t *_core_if )
5096 +{
5097 + if (_core_if->hcd_cb && _core_if->hcd_cb->session_start) {
5098 + _core_if->hcd_cb->session_start( _core_if->hcd_cb->p );
5099 + }
5100 +}
5101 +
5102 +/** Start the PCD. Helper function for using the PCD callbacks.
5103 + *
5104 + * @param _core_if Programming view of DWC_otg controller.
5105 + */
5106 +static inline void pcd_start( dwc_otg_core_if_t *_core_if )
5107 +{
5108 + if (_core_if->pcd_cb && _core_if->pcd_cb->start ) {
5109 + _core_if->pcd_cb->start( _core_if->pcd_cb->p );
5110 + }
5111 +}
5112 +/** Stop the PCD. Helper function for using the PCD callbacks.
5113 + *
5114 + * @param _core_if Programming view of DWC_otg controller.
5115 + */
5116 +static inline void pcd_stop( dwc_otg_core_if_t *_core_if )
5117 +{
5118 + if (_core_if->pcd_cb && _core_if->pcd_cb->stop ) {
5119 + _core_if->pcd_cb->stop( _core_if->pcd_cb->p );
5120 + }
5121 +}
5122 +/** Suspend the PCD. Helper function for using the PCD callbacks.
5123 + *
5124 + * @param _core_if Programming view of DWC_otg controller.
5125 + */
5126 +static inline void pcd_suspend( dwc_otg_core_if_t *_core_if )
5127 +{
5128 + if (_core_if->pcd_cb && _core_if->pcd_cb->suspend ) {
5129 + _core_if->pcd_cb->suspend( _core_if->pcd_cb->p );
5130 + }
5131 +}
5132 +/** Resume the PCD. Helper function for using the PCD callbacks.
5133 + *
5134 + * @param _core_if Programming view of DWC_otg controller.
5135 + */
5136 +static inline void pcd_resume( dwc_otg_core_if_t *_core_if )
5137 +{
5138 + if (_core_if->pcd_cb && _core_if->pcd_cb->resume_wakeup ) {
5139 + _core_if->pcd_cb->resume_wakeup( _core_if->pcd_cb->p );
5140 + }
5141 +}
5142 +
5143 +/**
5144 + * This function handles the OTG Interrupts. It reads the OTG
5145 + * Interrupt Register (GOTGINT) to determine what interrupt has
5146 + * occurred.
5147 + *
5148 + * @param _core_if Programming view of DWC_otg controller.
5149 + */
5150 +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t *_core_if)
5151 +{
5152 + dwc_otg_core_global_regs_t *global_regs =
5153 + _core_if->core_global_regs;
5154 + gotgint_data_t gotgint;
5155 + gotgctl_data_t gotgctl;
5156 + gintmsk_data_t gintmsk;
5157 +
5158 + gotgint.d32 = dwc_read_reg32( &global_regs->gotgint);
5159 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5160 + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
5161 + op_state_str(_core_if));
5162 + //DWC_DEBUGPL(DBG_CIL, "gotgctl=%08x\n", gotgctl.d32 );
5163 +
5164 + if (gotgint.b.sesenddet) {
5165 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5166 + "Session End Detected++ (%s)\n",
5167 + op_state_str(_core_if));
5168 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5169 +
5170 + if (_core_if->op_state == B_HOST) {
5171 + pcd_start( _core_if );
5172 + _core_if->op_state = B_PERIPHERAL;
5173 + } else {
5174 + /* If not B_HOST and Device HNP still set. HNP
5175 + * Did not succeed!*/
5176 + if (gotgctl.b.devhnpen) {
5177 + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
5178 + DWC_ERROR( "Device Not Connected/Responding!\n" );
5179 + }
5180 +
5181 + /* If Session End Detected the B-Cable has
5182 + * been disconnected. */
5183 + /* Reset PCD and Gadget driver to a
5184 + * clean state. */
5185 + pcd_stop(_core_if);
5186 + }
5187 + gotgctl.d32 = 0;
5188 + gotgctl.b.devhnpen = 1;
5189 + dwc_modify_reg32( &global_regs->gotgctl,
5190 + gotgctl.d32, 0);
5191 + }
5192 + if (gotgint.b.sesreqsucstschng) {
5193 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5194 + "Session Reqeust Success Status Change++\n");
5195 + gotgctl.d32 = dwc_read_reg32( &global_regs->gotgctl);
5196 + if (gotgctl.b.sesreqscs) {
5197 + if ((_core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
5198 + (_core_if->core_params->i2c_enable)) {
5199 + _core_if->srp_success = 1;
5200 + }
5201 + else {
5202 + pcd_resume( _core_if );
5203 + /* Clear Session Request */
5204 + gotgctl.d32 = 0;
5205 + gotgctl.b.sesreq = 1;
5206 + dwc_modify_reg32( &global_regs->gotgctl,
5207 + gotgctl.d32, 0);
5208 + }
5209 + }
5210 + }
5211 + if (gotgint.b.hstnegsucstschng) {
5212 + /* Print statements during the HNP interrupt handling
5213 + * can cause it to fail.*/
5214 + gotgctl.d32 = dwc_read_reg32(&global_regs->gotgctl);
5215 + if (gotgctl.b.hstnegscs) {
5216 + if (dwc_otg_is_host_mode(_core_if) ) {
5217 + _core_if->op_state = B_HOST;
5218 + /*
5219 + * Need to disable SOF interrupt immediately.
5220 + * When switching from device to host, the PCD
5221 + * interrupt handler won't handle the
5222 + * interrupt if host mode is already set. The
5223 + * HCD interrupt handler won't get called if
5224 + * the HCD state is HALT. This means that the
5225 + * interrupt does not get handled and Linux
5226 + * complains loudly.
5227 + */
5228 + gintmsk.d32 = 0;
5229 + gintmsk.b.sofintr = 1;
5230 + dwc_modify_reg32(&global_regs->gintmsk,
5231 + gintmsk.d32, 0);
5232 + pcd_stop(_core_if);
5233 + /*
5234 + * Initialize the Core for Host mode.
5235 + */
5236 + hcd_start( _core_if );
5237 + _core_if->op_state = B_HOST;
5238 + }
5239 + } else {
5240 + gotgctl.d32 = 0;
5241 + gotgctl.b.hnpreq = 1;
5242 + gotgctl.b.devhnpen = 1;
5243 + dwc_modify_reg32( &global_regs->gotgctl,
5244 + gotgctl.d32, 0);
5245 + DWC_DEBUGPL( DBG_ANY, "HNP Failed\n");
5246 + DWC_ERROR( "Device Not Connected/Responding\n" );
5247 + }
5248 + }
5249 + if (gotgint.b.hstnegdet) {
5250 + /* The disconnect interrupt is set at the same time as
5251 + * Host Negotiation Detected. During the mode
5252 + * switch all interrupts are cleared so the disconnect
5253 + * interrupt handler will not get executed.
5254 + */
5255 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5256 + "Host Negotiation Detected++ (%s)\n",
5257 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"));
5258 + if (dwc_otg_is_device_mode(_core_if)){
5259 + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",_core_if->op_state);
5260 + hcd_disconnect( _core_if );
5261 + pcd_start( _core_if );
5262 + _core_if->op_state = A_PERIPHERAL;
5263 + } else {
5264 + /*
5265 + * Need to disable SOF interrupt immediately. When
5266 + * switching from device to host, the PCD interrupt
5267 + * handler won't handle the interrupt if host mode is
5268 + * already set. The HCD interrupt handler won't get
5269 + * called if the HCD state is HALT. This means that
5270 + * the interrupt does not get handled and Linux
5271 + * complains loudly.
5272 + */
5273 + gintmsk.d32 = 0;
5274 + gintmsk.b.sofintr = 1;
5275 + dwc_modify_reg32(&global_regs->gintmsk,
5276 + gintmsk.d32, 0);
5277 + pcd_stop( _core_if );
5278 + hcd_start( _core_if );
5279 + _core_if->op_state = A_HOST;
5280 + }
5281 + }
5282 + if (gotgint.b.adevtoutchng) {
5283 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5284 + "A-Device Timeout Change++\n");
5285 + }
5286 + if (gotgint.b.debdone) {
5287 + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
5288 + "Debounce Done++\n");
5289 + }
5290 +
5291 + /* Clear GOTGINT */
5292 + dwc_write_reg32 (&_core_if->core_global_regs->gotgint, gotgint.d32);
5293 +
5294 + return 1;
5295 +}
5296 +
5297 +/**
5298 + * This function handles the Connector ID Status Change Interrupt. It
5299 + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
5300 + * is a Device to Host Mode transition or a Host Mode to Device
5301 + * Transition.
5302 + *
5303 + * This only occurs when the cable is connected/removed from the PHY
5304 + * connector.
5305 + *
5306 + * @param _core_if Programming view of DWC_otg controller.
5307 + */
5308 +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t *_core_if)
5309 +{
5310 + uint32_t count = 0;
5311 +
5312 + gintsts_data_t gintsts = { .d32 = 0 };
5313 + gintmsk_data_t gintmsk = { .d32 = 0 };
5314 + gotgctl_data_t gotgctl = { .d32 = 0 };
5315 +
5316 + /*
5317 + * Need to disable SOF interrupt immediately. If switching from device
5318 + * to host, the PCD interrupt handler won't handle the interrupt if
5319 + * host mode is already set. The HCD interrupt handler won't get
5320 + * called if the HCD state is HALT. This means that the interrupt does
5321 + * not get handled and Linux complains loudly.
5322 + */
5323 + gintmsk.b.sofintr = 1;
5324 + dwc_modify_reg32(&_core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
5325 +
5326 + DWC_DEBUGPL(DBG_CIL, " ++Connector ID Status Change Interrupt++ (%s)\n",
5327 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"));
5328 + gotgctl.d32 = dwc_read_reg32(&_core_if->core_global_regs->gotgctl);
5329 + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
5330 + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
5331 +
5332 + /* B-Device connector (Device Mode) */
5333 + if (gotgctl.b.conidsts) {
5334 + /* Wait for switch to device mode. */
5335 + while (!dwc_otg_is_device_mode(_core_if) ){
5336 + DWC_PRINT("Waiting for Peripheral Mode, Mode=%s\n",
5337 + (dwc_otg_is_host_mode(_core_if)?"Host":"Peripheral"));
5338 + MDELAY(100);
5339 + if (++count > 10000) *(uint32_t*)NULL=0;
5340 + }
5341 + _core_if->op_state = B_PERIPHERAL;
5342 + dwc_otg_core_init(_core_if);
5343 + dwc_otg_enable_global_interrupts(_core_if);
5344 + pcd_start( _core_if );
5345 + } else {
5346 + /* A-Device connector (Host Mode) */
5347 + while (!dwc_otg_is_host_mode(_core_if) ) {
5348 + DWC_PRINT("Waiting for Host Mode, Mode=%s\n",
5349 + (dwc_otg_is_host_mode(_core_if)?"Host":"Peripheral"));
5350 + MDELAY(100);
5351 + if (++count > 10000) *(uint32_t*)NULL=0;
5352 + }
5353 + _core_if->op_state = A_HOST;
5354 + /*
5355 + * Initialize the Core for Host mode.
5356 + */
5357 + dwc_otg_core_init(_core_if);
5358 + dwc_otg_enable_global_interrupts(_core_if);
5359 + hcd_start( _core_if );
5360 + }
5361 +
5362 + /* Set flag and clear interrupt */
5363 + gintsts.b.conidstschng = 1;
5364 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5365 +
5366 + return 1;
5367 +}
5368 +
5369 +/**
5370 + * This interrupt indicates that a device is initiating the Session
5371 + * Request Protocol to request the host to turn on bus power so a new
5372 + * session can begin. The handler responds by turning on bus power. If
5373 + * the DWC_otg controller is in low power mode, the handler brings the
5374 + * controller out of low power mode before turning on bus power.
5375 + *
5376 + * @param _core_if Programming view of DWC_otg controller.
5377 + */
5378 +int32_t dwc_otg_handle_session_req_intr( dwc_otg_core_if_t *_core_if )
5379 +{
5380 +#ifndef DWC_HOST_ONLY // winder
5381 + hprt0_data_t hprt0;
5382 +#endif
5383 + gintsts_data_t gintsts;
5384 +
5385 +#ifndef DWC_HOST_ONLY
5386 + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
5387 +
5388 + if (dwc_otg_is_device_mode(_core_if) ) {
5389 + DWC_PRINT("SRP: Device mode\n");
5390 + } else {
5391 + DWC_PRINT("SRP: Host mode\n");
5392 +
5393 + /* Turn on the port power bit. */
5394 + hprt0.d32 = dwc_otg_read_hprt0( _core_if );
5395 + hprt0.b.prtpwr = 1;
5396 + dwc_write_reg32(_core_if->host_if->hprt0, hprt0.d32);
5397 +
5398 + /* Start the Connection timer. So a message can be displayed
5399 + * if connect does not occur within 10 seconds. */
5400 + hcd_session_start( _core_if );
5401 + }
5402 +#endif
5403 +
5404 + /* Clear interrupt */
5405 + gintsts.d32 = 0;
5406 + gintsts.b.sessreqintr = 1;
5407 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5408 +
5409 + return 1;
5410 +}
5411 +
5412 +/**
5413 + * This interrupt indicates that the DWC_otg controller has detected a
5414 + * resume or remote wakeup sequence. If the DWC_otg controller is in
5415 + * low power mode, the handler must brings the controller out of low
5416 + * power mode. The controller automatically begins resume
5417 + * signaling. The handler schedules a time to stop resume signaling.
5418 + */
5419 +int32_t dwc_otg_handle_wakeup_detected_intr( dwc_otg_core_if_t *_core_if )
5420 +{
5421 + gintsts_data_t gintsts;
5422 +
5423 + DWC_DEBUGPL(DBG_ANY, "++Resume and Remote Wakeup Detected Interrupt++\n");
5424 +
5425 + if (dwc_otg_is_device_mode(_core_if) ) {
5426 + dctl_data_t dctl = {.d32=0};
5427 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
5428 + dwc_read_reg32( &_core_if->dev_if->dev_global_regs->dsts));
5429 +#ifdef PARTIAL_POWER_DOWN
5430 + if (_core_if->hwcfg4.b.power_optimiz) {
5431 + pcgcctl_data_t power = {.d32=0};
5432 +
5433 + power.d32 = dwc_read_reg32( _core_if->pcgcctl );
5434 + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n", power.d32);
5435 +
5436 + power.b.stoppclk = 0;
5437 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5438 +
5439 + power.b.pwrclmp = 0;
5440 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5441 +
5442 + power.b.rstpdwnmodule = 0;
5443 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5444 + }
5445 +#endif
5446 + /* Clear the Remote Wakeup Signalling */
5447 + dctl.b.rmtwkupsig = 1;
5448 + dwc_modify_reg32( &_core_if->dev_if->dev_global_regs->dctl,
5449 + dctl.d32, 0 );
5450 +
5451 + if (_core_if->pcd_cb && _core_if->pcd_cb->resume_wakeup) {
5452 + _core_if->pcd_cb->resume_wakeup( _core_if->pcd_cb->p );
5453 + }
5454 +
5455 + } else {
5456 + /*
5457 + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
5458 + * so that OPT tests pass with all PHYs).
5459 + */
5460 + hprt0_data_t hprt0 = {.d32=0};
5461 + pcgcctl_data_t pcgcctl = {.d32=0};
5462 + /* Restart the Phy Clock */
5463 + pcgcctl.b.stoppclk = 1;
5464 + dwc_modify_reg32(_core_if->pcgcctl, pcgcctl.d32, 0);
5465 + UDELAY(10);
5466 +
5467 + /* Now wait for 70 ms. */
5468 + hprt0.d32 = dwc_otg_read_hprt0( _core_if );
5469 + DWC_DEBUGPL(DBG_ANY,"Resume: HPRT0=%0x\n", hprt0.d32);
5470 + MDELAY(70);
5471 + hprt0.b.prtres = 0; /* Resume */
5472 + dwc_write_reg32(_core_if->host_if->hprt0, hprt0.d32);
5473 + DWC_DEBUGPL(DBG_ANY,"Clear Resume: HPRT0=%0x\n", dwc_read_reg32(_core_if->host_if->hprt0));
5474 + }
5475 +
5476 + /* Clear interrupt */
5477 + gintsts.d32 = 0;
5478 + gintsts.b.wkupintr = 1;
5479 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5480 +
5481 + return 1;
5482 +}
5483 +
5484 +/**
5485 + * This interrupt indicates that a device has been disconnected from
5486 + * the root port.
5487 + */
5488 +int32_t dwc_otg_handle_disconnect_intr( dwc_otg_core_if_t *_core_if)
5489 +{
5490 + gintsts_data_t gintsts;
5491 +
5492 + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
5493 + (dwc_otg_is_host_mode(_core_if)?"Host":"Device"),
5494 + op_state_str(_core_if));
5495 +
5496 +/** @todo Consolidate this if statement. */
5497 +#ifndef DWC_HOST_ONLY
5498 + if (_core_if->op_state == B_HOST) {
5499 + /* If in device mode Disconnect and stop the HCD, then
5500 + * start the PCD. */
5501 + hcd_disconnect( _core_if );
5502 + pcd_start( _core_if );
5503 + _core_if->op_state = B_PERIPHERAL;
5504 + } else if (dwc_otg_is_device_mode(_core_if)) {
5505 + gotgctl_data_t gotgctl = { .d32 = 0 };
5506 + gotgctl.d32 = dwc_read_reg32(&_core_if->core_global_regs->gotgctl);
5507 + if (gotgctl.b.hstsethnpen==1) {
5508 + /* Do nothing, if HNP in process the OTG
5509 + * interrupt "Host Negotiation Detected"
5510 + * interrupt will do the mode switch.
5511 + */
5512 + } else if (gotgctl.b.devhnpen == 0) {
5513 + /* If in device mode Disconnect and stop the HCD, then
5514 + * start the PCD. */
5515 + hcd_disconnect( _core_if );
5516 + pcd_start( _core_if );
5517 + _core_if->op_state = B_PERIPHERAL;
5518 + } else {
5519 + DWC_DEBUGPL(DBG_ANY,"!a_peripheral && !devhnpen\n");
5520 + }
5521 + } else {
5522 + if (_core_if->op_state == A_HOST) {
5523 + /* A-Cable still connected but device disconnected. */
5524 + hcd_disconnect( _core_if );
5525 + }
5526 + }
5527 +#endif
5528 +/* Without OTG, we should use the disconnect function!? winder added.*/
5529 +#if 1 // NO OTG, so host only!!
5530 + hcd_disconnect( _core_if );
5531 +#endif
5532 +
5533 + gintsts.d32 = 0;
5534 + gintsts.b.disconnect = 1;
5535 + dwc_write_reg32 (&_core_if->core_global_regs->gintsts, gintsts.d32);
5536 + return 1;
5537 +}
5538 +/**
5539 + * This interrupt indicates that SUSPEND state has been detected on
5540 + * the USB.
5541 + *
5542 + * For HNP the USB Suspend interrupt signals the change from
5543 + * "a_peripheral" to "a_host".
5544 + *
5545 + * When power management is enabled the core will be put in low power
5546 + * mode.
5547 + */
5548 +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t *_core_if )
5549 +{
5550 + dsts_data_t dsts;
5551 + gintsts_data_t gintsts;
5552 +
5553 + //805141:<IFTW-fchang>.removed DWC_DEBUGPL(DBG_ANY,"USB SUSPEND\n");
5554 +
5555 + if (dwc_otg_is_device_mode( _core_if ) ) {
5556 + /* Check the Device status register to determine if the Suspend
5557 + * state is active. */
5558 + dsts.d32 = dwc_read_reg32( &_core_if->dev_if->dev_global_regs->dsts);
5559 + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
5560 + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
5561 + "HWCFG4.power Optimize=%d\n",
5562 + dsts.b.suspsts, _core_if->hwcfg4.b.power_optimiz);
5563 +
5564 +
5565 +#ifdef PARTIAL_POWER_DOWN
5566 +/** @todo Add a module parameter for power management. */
5567 +
5568 + if (dsts.b.suspsts && _core_if->hwcfg4.b.power_optimiz) {
5569 + pcgcctl_data_t power = {.d32=0};
5570 + DWC_DEBUGPL(DBG_CIL, "suspend\n");
5571 +
5572 + power.b.pwrclmp = 1;
5573 + dwc_write_reg32( _core_if->pcgcctl, power.d32);
5574 +
5575 + power.b.rstpdwnmodule = 1;
5576 + dwc_modify_reg32( _core_if->pcgcctl, 0, power.d32);
5577 +
5578 + power.b.stoppclk = 1;
5579 + dwc_modify_reg32( _core_if->pcgcctl, 0, power.d32);
5580 +
5581 + } else {
5582 + DWC_DEBUGPL(DBG_ANY,"disconnect?\n");
5583 + }
5584 +#endif
5585 + /* PCD callback for suspend. */
5586 + pcd_suspend(_core_if);
5587 + } else {
5588 + if (_core_if->op_state == A_PERIPHERAL) {
5589 + DWC_DEBUGPL(DBG_ANY,"a_peripheral->a_host\n");
5590 + /* Clear the a_peripheral flag, back to a_host. */
5591 + pcd_stop( _core_if );
5592 + hcd_start( _core_if );
5593 + _core_if->op_state = A_HOST;
5594 + }
5595 + }
5596 +
5597 + /* Clear interrupt */
5598 + gintsts.d32 = 0;
5599 + gintsts.b.usbsuspend = 1;
5600 + dwc_write_reg32( &_core_if->core_global_regs->gintsts, gintsts.d32);
5601 +
5602 + return 1;
5603 +}
5604 +
5605 +
5606 +/**
5607 + * This function returns the Core Interrupt register.
5608 + */
5609 +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t *_core_if)
5610 +{
5611 + gintsts_data_t gintsts;
5612 + gintmsk_data_t gintmsk;
5613 + gintmsk_data_t gintmsk_common = {.d32=0};
5614 + gintmsk_common.b.wkupintr = 1;
5615 + gintmsk_common.b.sessreqintr = 1;
5616 + gintmsk_common.b.conidstschng = 1;
5617 + gintmsk_common.b.otgintr = 1;
5618 + gintmsk_common.b.modemismatch = 1;
5619 + gintmsk_common.b.disconnect = 1;
5620 + gintmsk_common.b.usbsuspend = 1;
5621 + /** @todo: The port interrupt occurs while in device
5622 + * mode. Added code to CIL to clear the interrupt for now!
5623 + */
5624 + gintmsk_common.b.portintr = 1;
5625 +
5626 + gintsts.d32 = dwc_read_reg32(&_core_if->core_global_regs->gintsts);
5627 + gintmsk.d32 = dwc_read_reg32(&_core_if->core_global_regs->gintmsk);
5628 +#ifdef DEBUG
5629 + /* if any common interrupts set */
5630 + if (gintsts.d32 & gintmsk_common.d32) {
5631 + DWC_DEBUGPL(DBG_ANY, "gintsts=%08x gintmsk=%08x\n",
5632 + gintsts.d32, gintmsk.d32);
5633 + }
5634 +#endif
5635 +
5636 + return ((gintsts.d32 & gintmsk.d32 ) & gintmsk_common.d32);
5637 +
5638 +}
5639 +
5640 +/**
5641 + * Common interrupt handler.
5642 + *
5643 + * The common interrupts are those that occur in both Host and Device mode.
5644 + * This handler handles the following interrupts:
5645 + * - Mode Mismatch Interrupt
5646 + * - Disconnect Interrupt
5647 + * - OTG Interrupt
5648 + * - Connector ID Status Change Interrupt
5649 + * - Session Request Interrupt.
5650 + * - Resume / Remote Wakeup Detected Interrupt.
5651 + *
5652 + */
5653 +extern int32_t dwc_otg_handle_common_intr( dwc_otg_core_if_t *_core_if )
5654 +{
5655 + int retval = 0;
5656 + gintsts_data_t gintsts;
5657 +
5658 + gintsts.d32 = dwc_otg_read_common_intr(_core_if);
5659 +
5660 + if (gintsts.b.modemismatch) {
5661 + retval |= dwc_otg_handle_mode_mismatch_intr( _core_if );
5662 + }
5663 + if (gintsts.b.otgintr) {
5664 + retval |= dwc_otg_handle_otg_intr( _core_if );
5665 + }
5666 + if (gintsts.b.conidstschng) {
5667 + retval |= dwc_otg_handle_conn_id_status_change_intr( _core_if );
5668 + }
5669 + if (gintsts.b.disconnect) {
5670 + retval |= dwc_otg_handle_disconnect_intr( _core_if );
5671 + }
5672 + if (gintsts.b.sessreqintr) {
5673 + retval |= dwc_otg_handle_session_req_intr( _core_if );
5674 + }
5675 + if (gintsts.b.wkupintr) {
5676 + retval |= dwc_otg_handle_wakeup_detected_intr( _core_if );
5677 + }
5678 + if (gintsts.b.usbsuspend) {
5679 + retval |= dwc_otg_handle_usb_suspend_intr( _core_if );
5680 + }
5681 + if (gintsts.b.portintr && dwc_otg_is_device_mode(_core_if)) {
5682 + /* The port interrupt occurs while in device mode with HPRT0
5683 + * Port Enable/Disable.
5684 + */
5685 + gintsts.d32 = 0;
5686 + gintsts.b.portintr = 1;
5687 + dwc_write_reg32(&_core_if->core_global_regs->gintsts,
5688 + gintsts.d32);
5689 + retval |= 1;
5690 +
5691 + }
5692 + return retval;
5693 +}
5694 --- /dev/null
5695 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.c
5696 @@ -0,0 +1,1264 @@
5697 +/* ==========================================================================
5698 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.c $
5699 + * $Revision: 1.1.1.1 $
5700 + * $Date: 2009-04-17 06:15:34 $
5701 + * $Change: 631780 $
5702 + *
5703 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
5704 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
5705 + * otherwise expressly agreed to in writing between Synopsys and you.
5706 + *
5707 + * The Software IS NOT an item of Licensed Software or Licensed Product under
5708 + * any End User Software License Agreement or Agreement for Licensed Product
5709 + * with Synopsys or any supplement thereto. You are permitted to use and
5710 + * redistribute this Software in source and binary forms, with or without
5711 + * modification, provided that redistributions of source code must retain this
5712 + * notice. You may not view, use, disclose, copy or distribute this file or
5713 + * any information contained herein except pursuant to this license grant from
5714 + * Synopsys. If you do not agree with this notice, including the disclaimer
5715 + * below, then you are not authorized to use the Software.
5716 + *
5717 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
5718 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5719 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5720 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
5721 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5722 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5723 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5724 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5725 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5726 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
5727 + * DAMAGE.
5728 + * ========================================================================== */
5729 +
5730 +/** @file
5731 + * The dwc_otg_driver module provides the initialization and cleanup entry
5732 + * points for the DWC_otg driver. This module will be dynamically installed
5733 + * after Linux is booted using the insmod command. When the module is
5734 + * installed, the dwc_otg_init function is called. When the module is
5735 + * removed (using rmmod), the dwc_otg_cleanup function is called.
5736 + *
5737 + * This module also defines a data structure for the dwc_otg_driver, which is
5738 + * used in conjunction with the standard ARM lm_device structure. These
5739 + * structures allow the OTG driver to comply with the standard Linux driver
5740 + * model in which devices and drivers are registered with a bus driver. This
5741 + * has the benefit that Linux can expose attributes of the driver and device
5742 + * in its special sysfs file system. Users can then read or write files in
5743 + * this file system to perform diagnostics on the driver components or the
5744 + * device.
5745 + */
5746 +
5747 +#include <linux/kernel.h>
5748 +#include <linux/module.h>
5749 +#include <linux/moduleparam.h>
5750 +#include <linux/init.h>
5751 +
5752 +#include <linux/device.h>
5753 +#include <linux/platform_device.h>
5754 +
5755 +#include <linux/errno.h>
5756 +#include <linux/types.h>
5757 +#include <linux/stat.h> /* permission constants */
5758 +#include <linux/irq.h>
5759 +#include <asm/io.h>
5760 +
5761 +#include "dwc_otg_plat.h"
5762 +#include "dwc_otg_attr.h"
5763 +#include "dwc_otg_driver.h"
5764 +#include "dwc_otg_cil.h"
5765 +#include "dwc_otg_cil_ifx.h"
5766 +
5767 +// #include "dwc_otg_pcd.h" // device
5768 +#include "dwc_otg_hcd.h" // host
5769 +
5770 +#include "dwc_otg_ifx.h" // for Infineon platform specific.
5771 +
5772 +#define DWC_DRIVER_VERSION "2.60a 22-NOV-2006"
5773 +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
5774 +
5775 +const char dwc_driver_name[] = "dwc_otg";
5776 +
5777 +static unsigned long dwc_iomem_base = IFX_USB_IOMEM_BASE;
5778 +int dwc_irq = LQ_USB_INT;
5779 +//int dwc_irq = 54;
5780 +//int dwc_irq = IFXMIPS_USB_OC_INT;
5781 +
5782 +extern int ifx_usb_hc_init(unsigned long base_addr, int irq);
5783 +extern void ifx_usb_hc_remove(void);
5784 +
5785 +/*-------------------------------------------------------------------------*/
5786 +/* Encapsulate the module parameter settings */
5787 +
5788 +static dwc_otg_core_params_t dwc_otg_module_params = {
5789 + .opt = -1,
5790 + .otg_cap = -1,
5791 + .dma_enable = -1,
5792 + .dma_burst_size = -1,
5793 + .speed = -1,
5794 + .host_support_fs_ls_low_power = -1,
5795 + .host_ls_low_power_phy_clk = -1,
5796 + .enable_dynamic_fifo = -1,
5797 + .data_fifo_size = -1,
5798 + .dev_rx_fifo_size = -1,
5799 + .dev_nperio_tx_fifo_size = -1,
5800 + .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 */
5801 + .host_rx_fifo_size = -1,
5802 + .host_nperio_tx_fifo_size = -1,
5803 + .host_perio_tx_fifo_size = -1,
5804 + .max_transfer_size = -1,
5805 + .max_packet_count = -1,
5806 + .host_channels = -1,
5807 + .dev_endpoints = -1,
5808 + .phy_type = -1,
5809 + .phy_utmi_width = -1,
5810 + .phy_ulpi_ddr = -1,
5811 + .phy_ulpi_ext_vbus = -1,
5812 + .i2c_enable = -1,
5813 + .ulpi_fs_ls = -1,
5814 + .ts_dline = -1,
5815 + .en_multiple_tx_fifo = -1,
5816 + .dev_tx_fifo_size = { /* dev_tx_fifo_size */
5817 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
5818 + }, /* 15 */
5819 + .thr_ctl = -1,
5820 + .tx_thr_length = -1,
5821 + .rx_thr_length = -1,
5822 +};
5823 +
5824 +/**
5825 + * This function shows the Driver Version.
5826 + */
5827 +static ssize_t version_show(struct device_driver *dev, char *buf)
5828 +{
5829 + return snprintf(buf, sizeof(DWC_DRIVER_VERSION)+2,"%s\n",
5830 + DWC_DRIVER_VERSION);
5831 +}
5832 +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
5833 +
5834 +/**
5835 + * Global Debug Level Mask.
5836 + */
5837 +uint32_t g_dbg_lvl = 0xff; /* OFF */
5838 +
5839 +/**
5840 + * This function shows the driver Debug Level.
5841 + */
5842 +static ssize_t dbg_level_show(struct device_driver *_drv, char *_buf)
5843 +{
5844 + return sprintf(_buf, "0x%0x\n", g_dbg_lvl);
5845 +}
5846 +/**
5847 + * This function stores the driver Debug Level.
5848 + */
5849 +static ssize_t dbg_level_store(struct device_driver *_drv, const char *_buf,
5850 + size_t _count)
5851 +{
5852 + g_dbg_lvl = simple_strtoul(_buf, NULL, 16);
5853 + return _count;
5854 +}
5855 +static DRIVER_ATTR(debuglevel, S_IRUGO|S_IWUSR, dbg_level_show, dbg_level_store);
5856 +
5857 +/**
5858 + * This function is called during module intialization to verify that
5859 + * the module parameters are in a valid state.
5860 + */
5861 +static int check_parameters(dwc_otg_core_if_t *core_if)
5862 +{
5863 + int i;
5864 + int retval = 0;
5865 +
5866 +/* Checks if the parameter is outside of its valid range of values */
5867 +#define DWC_OTG_PARAM_TEST(_param_,_low_,_high_) \
5868 + ((dwc_otg_module_params._param_ < (_low_)) || \
5869 + (dwc_otg_module_params._param_ > (_high_)))
5870 +
5871 +/* If the parameter has been set by the user, check that the parameter value is
5872 + * within the value range of values. If not, report a module error. */
5873 +#define DWC_OTG_PARAM_ERR(_param_,_low_,_high_,_string_) \
5874 + do { \
5875 + if (dwc_otg_module_params._param_ != -1) { \
5876 + if (DWC_OTG_PARAM_TEST(_param_,(_low_),(_high_))) { \
5877 + DWC_ERROR("`%d' invalid for parameter `%s'\n", \
5878 + dwc_otg_module_params._param_, _string_); \
5879 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
5880 + retval ++; \
5881 + } \
5882 + } \
5883 + } while (0)
5884 +
5885 + DWC_OTG_PARAM_ERR(opt,0,1,"opt");
5886 + DWC_OTG_PARAM_ERR(otg_cap,0,2,"otg_cap");
5887 + DWC_OTG_PARAM_ERR(dma_enable,0,1,"dma_enable");
5888 + DWC_OTG_PARAM_ERR(speed,0,1,"speed");
5889 + DWC_OTG_PARAM_ERR(host_support_fs_ls_low_power,0,1,"host_support_fs_ls_low_power");
5890 + DWC_OTG_PARAM_ERR(host_ls_low_power_phy_clk,0,1,"host_ls_low_power_phy_clk");
5891 + DWC_OTG_PARAM_ERR(enable_dynamic_fifo,0,1,"enable_dynamic_fifo");
5892 + DWC_OTG_PARAM_ERR(data_fifo_size,32,32768,"data_fifo_size");
5893 + DWC_OTG_PARAM_ERR(dev_rx_fifo_size,16,32768,"dev_rx_fifo_size");
5894 + DWC_OTG_PARAM_ERR(dev_nperio_tx_fifo_size,16,32768,"dev_nperio_tx_fifo_size");
5895 + DWC_OTG_PARAM_ERR(host_rx_fifo_size,16,32768,"host_rx_fifo_size");
5896 + DWC_OTG_PARAM_ERR(host_nperio_tx_fifo_size,16,32768,"host_nperio_tx_fifo_size");
5897 + DWC_OTG_PARAM_ERR(host_perio_tx_fifo_size,16,32768,"host_perio_tx_fifo_size");
5898 + DWC_OTG_PARAM_ERR(max_transfer_size,2047,524288,"max_transfer_size");
5899 + DWC_OTG_PARAM_ERR(max_packet_count,15,511,"max_packet_count");
5900 + DWC_OTG_PARAM_ERR(host_channels,1,16,"host_channels");
5901 + DWC_OTG_PARAM_ERR(dev_endpoints,1,15,"dev_endpoints");
5902 + DWC_OTG_PARAM_ERR(phy_type,0,2,"phy_type");
5903 + DWC_OTG_PARAM_ERR(phy_ulpi_ddr,0,1,"phy_ulpi_ddr");
5904 + DWC_OTG_PARAM_ERR(phy_ulpi_ext_vbus,0,1,"phy_ulpi_ext_vbus");
5905 + DWC_OTG_PARAM_ERR(i2c_enable,0,1,"i2c_enable");
5906 + DWC_OTG_PARAM_ERR(ulpi_fs_ls,0,1,"ulpi_fs_ls");
5907 + DWC_OTG_PARAM_ERR(ts_dline,0,1,"ts_dline");
5908 +
5909 + if (dwc_otg_module_params.dma_burst_size != -1) {
5910 + if (DWC_OTG_PARAM_TEST(dma_burst_size,1,1) &&
5911 + DWC_OTG_PARAM_TEST(dma_burst_size,4,4) &&
5912 + DWC_OTG_PARAM_TEST(dma_burst_size,8,8) &&
5913 + DWC_OTG_PARAM_TEST(dma_burst_size,16,16) &&
5914 + DWC_OTG_PARAM_TEST(dma_burst_size,32,32) &&
5915 + DWC_OTG_PARAM_TEST(dma_burst_size,64,64) &&
5916 + DWC_OTG_PARAM_TEST(dma_burst_size,128,128) &&
5917 + DWC_OTG_PARAM_TEST(dma_burst_size,256,256))
5918 + {
5919 + DWC_ERROR("`%d' invalid for parameter `dma_burst_size'\n",
5920 + dwc_otg_module_params.dma_burst_size);
5921 + dwc_otg_module_params.dma_burst_size = 32;
5922 + retval ++;
5923 + }
5924 + }
5925 +
5926 + if (dwc_otg_module_params.phy_utmi_width != -1) {
5927 + if (DWC_OTG_PARAM_TEST(phy_utmi_width,8,8) &&
5928 + DWC_OTG_PARAM_TEST(phy_utmi_width,16,16))
5929 + {
5930 + DWC_ERROR("`%d' invalid for parameter `phy_utmi_width'\n",
5931 + dwc_otg_module_params.phy_utmi_width);
5932 + //dwc_otg_module_params.phy_utmi_width = 16;
5933 + dwc_otg_module_params.phy_utmi_width = 8;
5934 + retval ++;
5935 + }
5936 + }
5937 +
5938 + for (i=0; i<15; i++) {
5939 + /** @todo should be like above */
5940 + //DWC_OTG_PARAM_ERR(dev_perio_tx_fifo_size[i],4,768,"dev_perio_tx_fifo_size");
5941 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
5942 + if (DWC_OTG_PARAM_TEST(dev_perio_tx_fifo_size[i],4,768)) {
5943 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
5944 + dwc_otg_module_params.dev_perio_tx_fifo_size[i], "dev_perio_tx_fifo_size", i);
5945 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
5946 + retval ++;
5947 + }
5948 + }
5949 + }
5950 +
5951 + DWC_OTG_PARAM_ERR(en_multiple_tx_fifo, 0, 1, "en_multiple_tx_fifo");
5952 + for (i = 0; i < 15; i++) {
5953 + /** @todo should be like above */
5954 + //DWC_OTG_PARAM_ERR(dev_tx_fifo_size[i],4,768,"dev_tx_fifo_size");
5955 + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
5956 + if (DWC_OTG_PARAM_TEST(dev_tx_fifo_size[i], 4, 768)) {
5957 + DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
5958 + dwc_otg_module_params.dev_tx_fifo_size[i],
5959 + "dev_tx_fifo_size", i);
5960 + dwc_otg_module_params.dev_tx_fifo_size[i] =
5961 + dwc_param_dev_tx_fifo_size_default;
5962 + retval++;
5963 + }
5964 + }
5965 + }
5966 + DWC_OTG_PARAM_ERR(thr_ctl, 0, 7, "thr_ctl");
5967 + DWC_OTG_PARAM_ERR(tx_thr_length, 8, 128, "tx_thr_length");
5968 + DWC_OTG_PARAM_ERR(rx_thr_length, 8, 128, "rx_thr_length");
5969 +
5970 + /* At this point, all module parameters that have been set by the user
5971 + * are valid, and those that have not are left unset. Now set their
5972 + * default values and/or check the parameters against the hardware
5973 + * configurations of the OTG core. */
5974 +
5975 +
5976 +
5977 +/* This sets the parameter to the default value if it has not been set by the
5978 + * user */
5979 +#define DWC_OTG_PARAM_SET_DEFAULT(_param_) \
5980 + ({ \
5981 + int changed = 1; \
5982 + if (dwc_otg_module_params._param_ == -1) { \
5983 + changed = 0; \
5984 + dwc_otg_module_params._param_ = dwc_param_##_param_##_default; \
5985 + } \
5986 + changed; \
5987 + })
5988 +
5989 +/* This checks the macro agains the hardware configuration to see if it is
5990 + * valid. It is possible that the default value could be invalid. In this
5991 + * case, it will report a module error if the user touched the parameter.
5992 + * Otherwise it will adjust the value without any error. */
5993 +#define DWC_OTG_PARAM_CHECK_VALID(_param_,_str_,_is_valid_,_set_valid_) \
5994 + ({ \
5995 + int changed = DWC_OTG_PARAM_SET_DEFAULT(_param_); \
5996 + int error = 0; \
5997 + if (!(_is_valid_)) { \
5998 + if (changed) { \
5999 + DWC_ERROR("`%d' invalid for parameter `%s'. Check HW configuration.\n", dwc_otg_module_params._param_,_str_); \
6000 + error = 1; \
6001 + } \
6002 + dwc_otg_module_params._param_ = (_set_valid_); \
6003 + } \
6004 + error; \
6005 + })
6006 +
6007 + /* OTG Cap */
6008 + retval += DWC_OTG_PARAM_CHECK_VALID(otg_cap,"otg_cap",
6009 + ({
6010 + int valid;
6011 + valid = 1;
6012 + switch (dwc_otg_module_params.otg_cap) {
6013 + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
6014 + if (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) valid = 0;
6015 + break;
6016 + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
6017 + if ((core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) &&
6018 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) &&
6019 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) &&
6020 + (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST))
6021 + {
6022 + valid = 0;
6023 + }
6024 + break;
6025 + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
6026 + /* always valid */
6027 + break;
6028 + }
6029 + valid;
6030 + }),
6031 + (((core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) ||
6032 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) ||
6033 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
6034 + (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
6035 + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
6036 + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE));
6037 +
6038 + retval += DWC_OTG_PARAM_CHECK_VALID(dma_enable,"dma_enable",
6039 + ((dwc_otg_module_params.dma_enable == 1) && (core_if->hwcfg2.b.architecture == 0)) ? 0 : 1,
6040 + 0);
6041 +
6042 + retval += DWC_OTG_PARAM_CHECK_VALID(opt,"opt",
6043 + 1,
6044 + 0);
6045 +
6046 + DWC_OTG_PARAM_SET_DEFAULT(dma_burst_size);
6047 +
6048 + retval += DWC_OTG_PARAM_CHECK_VALID(host_support_fs_ls_low_power,
6049 + "host_support_fs_ls_low_power",
6050 + 1, 0);
6051 +
6052 + retval += DWC_OTG_PARAM_CHECK_VALID(enable_dynamic_fifo,
6053 + "enable_dynamic_fifo",
6054 + ((dwc_otg_module_params.enable_dynamic_fifo == 0) ||
6055 + (core_if->hwcfg2.b.dynamic_fifo == 1)), 0);
6056 +
6057 +
6058 + retval += DWC_OTG_PARAM_CHECK_VALID(data_fifo_size,
6059 + "data_fifo_size",
6060 + (dwc_otg_module_params.data_fifo_size <= core_if->hwcfg3.b.dfifo_depth),
6061 + core_if->hwcfg3.b.dfifo_depth);
6062 +
6063 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_rx_fifo_size,
6064 + "dev_rx_fifo_size",
6065 + (dwc_otg_module_params.dev_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
6066 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
6067 +
6068 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_nperio_tx_fifo_size,
6069 + "dev_nperio_tx_fifo_size",
6070 + (dwc_otg_module_params.dev_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
6071 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
6072 +
6073 + retval += DWC_OTG_PARAM_CHECK_VALID(host_rx_fifo_size,
6074 + "host_rx_fifo_size",
6075 + (dwc_otg_module_params.host_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
6076 + dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
6077 +
6078 +
6079 + retval += DWC_OTG_PARAM_CHECK_VALID(host_nperio_tx_fifo_size,
6080 + "host_nperio_tx_fifo_size",
6081 + (dwc_otg_module_params.host_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
6082 + (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
6083 +
6084 + retval += DWC_OTG_PARAM_CHECK_VALID(host_perio_tx_fifo_size,
6085 + "host_perio_tx_fifo_size",
6086 + (dwc_otg_module_params.host_perio_tx_fifo_size <= ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16))),
6087 + ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16)));
6088 +
6089 + retval += DWC_OTG_PARAM_CHECK_VALID(max_transfer_size,
6090 + "max_transfer_size",
6091 + (dwc_otg_module_params.max_transfer_size < (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))),
6092 + ((1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1));
6093 +
6094 + retval += DWC_OTG_PARAM_CHECK_VALID(max_packet_count,
6095 + "max_packet_count",
6096 + (dwc_otg_module_params.max_packet_count < (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))),
6097 + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1));
6098 +
6099 + retval += DWC_OTG_PARAM_CHECK_VALID(host_channels,
6100 + "host_channels",
6101 + (dwc_otg_module_params.host_channels <= (core_if->hwcfg2.b.num_host_chan + 1)),
6102 + (core_if->hwcfg2.b.num_host_chan + 1));
6103 +
6104 + retval += DWC_OTG_PARAM_CHECK_VALID(dev_endpoints,
6105 + "dev_endpoints",
6106 + (dwc_otg_module_params.dev_endpoints <= (core_if->hwcfg2.b.num_dev_ep)),
6107 + core_if->hwcfg2.b.num_dev_ep);
6108 +
6109 +/*
6110 + * Define the following to disable the FS PHY Hardware checking. This is for
6111 + * internal testing only.
6112 + *
6113 + * #define NO_FS_PHY_HW_CHECKS
6114 + */
6115 +
6116 +#ifdef NO_FS_PHY_HW_CHECKS
6117 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
6118 + "phy_type", 1, 0);
6119 +#else
6120 + retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
6121 + "phy_type",
6122 + ({
6123 + int valid = 0;
6124 + if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_UTMI) &&
6125 + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
6126 + (core_if->hwcfg2.b.hs_phy_type == 3)))
6127 + {
6128 + valid = 1;
6129 + }
6130 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_ULPI) &&
6131 + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
6132 + (core_if->hwcfg2.b.hs_phy_type == 3)))
6133 + {
6134 + valid = 1;
6135 + }
6136 + else if ((dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) &&
6137 + (core_if->hwcfg2.b.fs_phy_type == 1))
6138 + {
6139 + valid = 1;
6140 + }
6141 + valid;
6142 + }),
6143 + ({
6144 + int set = DWC_PHY_TYPE_PARAM_FS;
6145 + if (core_if->hwcfg2.b.hs_phy_type) {
6146 + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
6147 + (core_if->hwcfg2.b.hs_phy_type == 1)) {
6148 + set = DWC_PHY_TYPE_PARAM_UTMI;
6149 + }
6150 + else {
6151 + set = DWC_PHY_TYPE_PARAM_ULPI;
6152 + }
6153 + }
6154 + set;
6155 + }));
6156 +#endif
6157 +
6158 + retval += DWC_OTG_PARAM_CHECK_VALID(speed,"speed",
6159 + (dwc_otg_module_params.speed == 0) && (dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1,
6160 + dwc_otg_module_params.phy_type == DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
6161 +
6162 + retval += DWC_OTG_PARAM_CHECK_VALID(host_ls_low_power_phy_clk,
6163 + "host_ls_low_power_phy_clk",
6164 + ((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),
6165 + ((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));
6166 +
6167 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ddr);
6168 + DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ext_vbus);
6169 + DWC_OTG_PARAM_SET_DEFAULT(phy_utmi_width);
6170 + DWC_OTG_PARAM_SET_DEFAULT(ulpi_fs_ls);
6171 + DWC_OTG_PARAM_SET_DEFAULT(ts_dline);
6172 +
6173 +#ifdef NO_FS_PHY_HW_CHECKS
6174 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
6175 + "i2c_enable", 1, 0);
6176 +#else
6177 + retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
6178 + "i2c_enable",
6179 + (dwc_otg_module_params.i2c_enable == 1) && (core_if->hwcfg3.b.i2c == 0) ? 0 : 1,
6180 + 0);
6181 +#endif
6182 +
6183 + for (i=0; i<16; i++) {
6184 +
6185 + int changed = 1;
6186 + int error = 0;
6187 +
6188 + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] == -1) {
6189 + changed = 0;
6190 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
6191 + }
6192 + if (!(dwc_otg_module_params.dev_perio_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
6193 + if (changed) {
6194 + 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);
6195 + error = 1;
6196 + }
6197 + dwc_otg_module_params.dev_perio_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
6198 + }
6199 + retval += error;
6200 + }
6201 +
6202 + retval += DWC_OTG_PARAM_CHECK_VALID(en_multiple_tx_fifo,
6203 + "en_multiple_tx_fifo",
6204 + ((dwc_otg_module_params.en_multiple_tx_fifo == 1) &&
6205 + (core_if->hwcfg4.b.ded_fifo_en == 0)) ? 0 : 1, 0);
6206 +
6207 + for (i = 0; i < 16; i++) {
6208 + int changed = 1;
6209 + int error = 0;
6210 + if (dwc_otg_module_params.dev_tx_fifo_size[i] == -1) {
6211 + changed = 0;
6212 + dwc_otg_module_params.dev_tx_fifo_size[i] =
6213 + dwc_param_dev_tx_fifo_size_default;
6214 + }
6215 + if (!(dwc_otg_module_params.dev_tx_fifo_size[i] <=
6216 + (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i])))) {
6217 + if (changed) {
6218 + DWC_ERROR("%d' invalid for parameter `dev_perio_fifo_size_%d'."
6219 + "Check HW configuration.\n",dwc_otg_module_params.dev_tx_fifo_size[i],i);
6220 + error = 1;
6221 + }
6222 + dwc_otg_module_params.dev_tx_fifo_size[i] =
6223 + dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
6224 + }
6225 + retval += error;
6226 + }
6227 + DWC_OTG_PARAM_SET_DEFAULT(thr_ctl);
6228 + DWC_OTG_PARAM_SET_DEFAULT(tx_thr_length);
6229 + DWC_OTG_PARAM_SET_DEFAULT(rx_thr_length);
6230 + return retval;
6231 +} // check_parameters
6232 +
6233 +
6234 +/**
6235 + * This function is the top level interrupt handler for the Common
6236 + * (Device and host modes) interrupts.
6237 + */
6238 +static irqreturn_t dwc_otg_common_irq(int _irq, void *_dev)
6239 +{
6240 + dwc_otg_device_t *otg_dev = _dev;
6241 + int32_t retval = IRQ_NONE;
6242 +
6243 + retval = dwc_otg_handle_common_intr( otg_dev->core_if );
6244 +
6245 + mask_and_ack_ifx_irq (_irq);
6246 +
6247 + return IRQ_RETVAL(retval);
6248 +}
6249 +
6250 +
6251 +/**
6252 + * This function is called when a DWC_OTG device is unregistered with the
6253 + * dwc_otg_driver. This happens, for example, when the rmmod command is
6254 + * executed. The device may or may not be electrically present. If it is
6255 + * present, the driver stops device processing. Any resources used on behalf
6256 + * of this device are freed.
6257 + *
6258 + * @return
6259 + */
6260 +static int
6261 +dwc_otg_driver_remove(struct platform_device *_dev)
6262 +{
6263 + //dwc_otg_device_t *otg_dev = dev_get_drvdata(&_dev->dev);
6264 + dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
6265 +
6266 + DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, _dev);
6267 +
6268 + if (otg_dev == NULL) {
6269 + /* Memory allocation for the dwc_otg_device failed. */
6270 + return 0;
6271 + }
6272 +
6273 + /*
6274 + * Free the IRQ
6275 + */
6276 + if (otg_dev->common_irq_installed) {
6277 + free_irq( otg_dev->irq, otg_dev );
6278 + }
6279 +
6280 +#ifndef DWC_DEVICE_ONLY
6281 + if (otg_dev->hcd != NULL) {
6282 + dwc_otg_hcd_remove(&_dev->dev);
6283 + }
6284 +#endif
6285 + printk("after removehcd\n");
6286 +
6287 +// Note: Integrate HOST and DEVICE(Gadget) is not planned yet.
6288 +#ifndef DWC_HOST_ONLY
6289 + if (otg_dev->pcd != NULL) {
6290 + dwc_otg_pcd_remove(otg_dev);
6291 + }
6292 +#endif
6293 + if (otg_dev->core_if != NULL) {
6294 + dwc_otg_cil_remove( otg_dev->core_if );
6295 + }
6296 + printk("after removecil\n");
6297 +
6298 + /*
6299 + * Remove the device attributes
6300 + */
6301 + dwc_otg_attr_remove(&_dev->dev);
6302 + printk("after removeattr\n");
6303 +
6304 + /*
6305 + * Return the memory.
6306 + */
6307 + if (otg_dev->base != NULL) {
6308 + iounmap(otg_dev->base);
6309 + }
6310 + if (otg_dev->phys_addr != 0) {
6311 + release_mem_region(otg_dev->phys_addr, otg_dev->base_len);
6312 + }
6313 + kfree(otg_dev);
6314 +
6315 + /*
6316 + * Clear the drvdata pointer.
6317 + */
6318 + //dev_set_drvdata(&_dev->dev, 0);
6319 + platform_set_drvdata(_dev, 0);
6320 + return 0;
6321 +}
6322 +
6323 +/**
6324 + * This function is called when an DWC_OTG device is bound to a
6325 + * dwc_otg_driver. It creates the driver components required to
6326 + * control the device (CIL, HCD, and PCD) and it initializes the
6327 + * device. The driver components are stored in a dwc_otg_device
6328 + * structure. A reference to the dwc_otg_device is saved in the
6329 + * lm_device. This allows the driver to access the dwc_otg_device
6330 + * structure on subsequent calls to driver methods for this device.
6331 + *
6332 + * @return
6333 + */
6334 +static int __devinit
6335 +dwc_otg_driver_probe(struct platform_device *_dev)
6336 +{
6337 + int retval = 0;
6338 + dwc_otg_device_t *dwc_otg_device;
6339 + int32_t snpsid;
6340 + struct resource *res;
6341 + gusbcfg_data_t usbcfg = {.d32 = 0};
6342 +
6343 + dev_dbg(&_dev->dev, "dwc_otg_driver_probe (%p)\n", _dev);
6344 +
6345 + dwc_otg_device = kmalloc(sizeof(dwc_otg_device_t), GFP_KERNEL);
6346 + if (dwc_otg_device == 0) {
6347 + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
6348 + retval = -ENOMEM;
6349 + goto fail;
6350 + }
6351 + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
6352 + dwc_otg_device->reg_offset = 0xFFFFFFFF;
6353 +
6354 + /*
6355 + * Retrieve the memory and IRQ resources.
6356 + */
6357 + dwc_otg_device->irq = platform_get_irq(_dev, 0);
6358 + if (dwc_otg_device->irq == 0) {
6359 + dev_err(&_dev->dev, "no device irq\n");
6360 + retval = -ENODEV;
6361 + goto fail;
6362 + }
6363 + dev_dbg(&_dev->dev, "OTG - device irq: %d\n", dwc_otg_device->irq);
6364 + res = platform_get_resource(_dev, IORESOURCE_MEM, 0);
6365 + if (res == NULL) {
6366 + dev_err(&_dev->dev, "no CSR address\n");
6367 + retval = -ENODEV;
6368 + goto fail;
6369 + }
6370 + dev_dbg(&_dev->dev, "OTG - ioresource_mem start0x%08x: end:0x%08x\n",
6371 + (unsigned)res->start, (unsigned)res->end);
6372 + dwc_otg_device->phys_addr = res->start;
6373 + dwc_otg_device->base_len = res->end - res->start + 1;
6374 + if (request_mem_region(dwc_otg_device->phys_addr, dwc_otg_device->base_len,
6375 + dwc_driver_name) == NULL) {
6376 + dev_err(&_dev->dev, "request_mem_region failed\n");
6377 + retval = -EBUSY;
6378 + goto fail;
6379 + }
6380 +
6381 + /*
6382 + * Map the DWC_otg Core memory into virtual address space.
6383 + */
6384 + dwc_otg_device->base = ioremap_nocache(dwc_otg_device->phys_addr, dwc_otg_device->base_len);
6385 + if (dwc_otg_device->base == NULL) {
6386 + dev_err(&_dev->dev, "ioremap() failed\n");
6387 + retval = -ENOMEM;
6388 + goto fail;
6389 + }
6390 + dev_dbg(&_dev->dev, "mapped base=0x%08x\n", (unsigned)dwc_otg_device->base);
6391 +
6392 + /*
6393 + * Attempt to ensure this device is really a DWC_otg Controller.
6394 + * Read and verify the SNPSID register contents. The value should be
6395 + * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
6396 + */
6397 + snpsid = dwc_read_reg32((uint32_t *)((uint8_t *)dwc_otg_device->base + 0x40));
6398 + if ((snpsid & 0xFFFFF000) != 0x4F542000) {
6399 + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n", snpsid);
6400 + retval = -EINVAL;
6401 + goto fail;
6402 + }
6403 +
6404 + /*
6405 + * Initialize driver data to point to the global DWC_otg
6406 + * Device structure.
6407 + */
6408 + platform_set_drvdata(_dev, dwc_otg_device);
6409 + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
6410 + dwc_otg_device->core_if = dwc_otg_cil_init( dwc_otg_device->base, &dwc_otg_module_params);
6411 + if (dwc_otg_device->core_if == 0) {
6412 + dev_err(&_dev->dev, "CIL initialization failed!\n");
6413 + retval = -ENOMEM;
6414 + goto fail;
6415 + }
6416 +
6417 + /*
6418 + * Validate parameter values.
6419 + */
6420 + if (check_parameters(dwc_otg_device->core_if) != 0) {
6421 + retval = -EINVAL;
6422 + goto fail;
6423 + }
6424 +
6425 + /* Added for PLB DMA phys virt mapping */
6426 + //dwc_otg_device->core_if->phys_addr = dwc_otg_device->phys_addr;
6427 + /*
6428 + * Create Device Attributes in sysfs
6429 + */
6430 + dwc_otg_attr_create (&_dev->dev);
6431 +
6432 + /*
6433 + * Disable the global interrupt until all the interrupt
6434 + * handlers are installed.
6435 + */
6436 + dwc_otg_disable_global_interrupts( dwc_otg_device->core_if );
6437 + /*
6438 + * Install the interrupt handler for the common interrupts before
6439 + * enabling common interrupts in core_init below.
6440 + */
6441 + DWC_DEBUGPL( DBG_CIL, "registering (common) handler for irq%d\n", dwc_otg_device->irq);
6442 +
6443 + retval = request_irq((unsigned int)dwc_otg_device->irq, dwc_otg_common_irq,
6444 + //SA_INTERRUPT|SA_SHIRQ, "dwc_otg", (void *)dwc_otg_device );
6445 + IRQF_SHARED, "dwc_otg", (void *)dwc_otg_device );
6446 + //IRQF_DISABLED, "dwc_otg", (void *)dwc_otg_device );
6447 + if (retval != 0) {
6448 + DWC_ERROR("request of irq%d failed retval: %d\n", dwc_otg_device->irq, retval);
6449 + retval = -EBUSY;
6450 + goto fail;
6451 + } else {
6452 + dwc_otg_device->common_irq_installed = 1;
6453 + }
6454 +
6455 + /*
6456 + * Initialize the DWC_otg core.
6457 + */
6458 + dwc_otg_core_init( dwc_otg_device->core_if );
6459 +
6460 +
6461 +#ifndef DWC_HOST_ONLY // otg device mode. (gadget.)
6462 + /*
6463 + * Initialize the PCD
6464 + */
6465 + retval = dwc_otg_pcd_init(dwc_otg_device);
6466 + if (retval != 0) {
6467 + DWC_ERROR("dwc_otg_pcd_init failed\n");
6468 + dwc_otg_device->pcd = NULL;
6469 + goto fail;
6470 + }
6471 +#endif // DWC_HOST_ONLY
6472 +
6473 +#ifndef DWC_DEVICE_ONLY // otg host mode. (HCD)
6474 + /*
6475 + * Initialize the HCD
6476 + */
6477 +#if 1 /*fscz*/
6478 + /* force_host_mode */
6479 + usbcfg.d32 = dwc_read_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg);
6480 + usbcfg.b.force_host_mode = 1;
6481 + dwc_write_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg, usbcfg.d32);
6482 +#endif
6483 + retval = dwc_otg_hcd_init(&_dev->dev, dwc_otg_device);
6484 + if (retval != 0) {
6485 + DWC_ERROR("dwc_otg_hcd_init failed\n");
6486 + dwc_otg_device->hcd = NULL;
6487 + goto fail;
6488 + }
6489 +#endif // DWC_DEVICE_ONLY
6490 +
6491 + /*
6492 + * Enable the global interrupt after all the interrupt
6493 + * handlers are installed.
6494 + */
6495 + dwc_otg_enable_global_interrupts( dwc_otg_device->core_if );
6496 +#if 0 /*fscz*/
6497 + usbcfg.d32 = dwc_read_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg);
6498 + usbcfg.b.force_host_mode = 0;
6499 + dwc_write_reg32(&dwc_otg_device->core_if->core_global_regs ->gusbcfg, usbcfg.d32);
6500 +#endif
6501 +
6502 +
6503 + return 0;
6504 +
6505 +fail:
6506 + dwc_otg_driver_remove(_dev);
6507 + return retval;
6508 +}
6509 +
6510 +/**
6511 + * This structure defines the methods to be called by a bus driver
6512 + * during the lifecycle of a device on that bus. Both drivers and
6513 + * devices are registered with a bus driver. The bus driver matches
6514 + * devices to drivers based on information in the device and driver
6515 + * structures.
6516 + *
6517 + * The probe function is called when the bus driver matches a device
6518 + * to this driver. The remove function is called when a device is
6519 + * unregistered with the bus driver.
6520 + */
6521 +struct platform_driver dwc_otg_driver = {
6522 + .probe = dwc_otg_driver_probe,
6523 + .remove = dwc_otg_driver_remove,
6524 +// .suspend = dwc_otg_driver_suspend,
6525 +// .resume = dwc_otg_driver_resume,
6526 + .driver = {
6527 + .name = dwc_driver_name,
6528 + .owner = THIS_MODULE,
6529 + },
6530 +};
6531 +EXPORT_SYMBOL(dwc_otg_driver);
6532 +
6533 +/**
6534 + * This function is called when the dwc_otg_driver is installed with the
6535 + * insmod command. It registers the dwc_otg_driver structure with the
6536 + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
6537 + * to be called. In addition, the bus driver will automatically expose
6538 + * attributes defined for the device and driver in the special sysfs file
6539 + * system.
6540 + *
6541 + * @return
6542 + */
6543 +static int __init dwc_otg_init(void)
6544 +{
6545 + int retval = 0;
6546 +
6547 + printk(KERN_INFO "%s: version %s\n", dwc_driver_name, DWC_DRIVER_VERSION);
6548 +
6549 + // ifxmips setup
6550 + retval = ifx_usb_hc_init(dwc_iomem_base, dwc_irq);
6551 + if (retval < 0)
6552 + {
6553 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6554 + return retval;
6555 + }
6556 + dwc_otg_power_on(); // ifx only!!
6557 +
6558 +
6559 + retval = platform_driver_register(&dwc_otg_driver);
6560 +
6561 + if (retval < 0) {
6562 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6563 + goto error1;
6564 + }
6565 +
6566 + retval = driver_create_file(&dwc_otg_driver.driver, &driver_attr_version);
6567 + if (retval < 0)
6568 + {
6569 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6570 + goto error2;
6571 + }
6572 + retval = driver_create_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
6573 + if (retval < 0)
6574 + {
6575 + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
6576 + goto error3;
6577 + }
6578 + return retval;
6579 +
6580 +
6581 +error3:
6582 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
6583 +error2:
6584 + driver_unregister(&dwc_otg_driver.driver);
6585 +error1:
6586 + ifx_usb_hc_remove();
6587 + return retval;
6588 +}
6589 +module_init(dwc_otg_init);
6590 +
6591 +/**
6592 + * This function is called when the driver is removed from the kernel
6593 + * with the rmmod command. The driver unregisters itself with its bus
6594 + * driver.
6595 + *
6596 + */
6597 +static void __exit dwc_otg_cleanup(void)
6598 +{
6599 + printk(KERN_DEBUG "dwc_otg_cleanup()\n");
6600 +
6601 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
6602 + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
6603 +
6604 + platform_driver_unregister(&dwc_otg_driver);
6605 + ifx_usb_hc_remove();
6606 +
6607 + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
6608 +}
6609 +module_exit(dwc_otg_cleanup);
6610 +
6611 +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
6612 +MODULE_AUTHOR("Synopsys Inc.");
6613 +MODULE_LICENSE("GPL");
6614 +
6615 +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
6616 +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
6617 +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
6618 +MODULE_PARM_DESC(opt, "OPT Mode");
6619 +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
6620 +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
6621 +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int, 0444);
6622 +MODULE_PARM_DESC(dma_burst_size, "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
6623 +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
6624 +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
6625 +module_param_named(host_support_fs_ls_low_power, dwc_otg_module_params.host_support_fs_ls_low_power, int, 0444);
6626 +MODULE_PARM_DESC(host_support_fs_ls_low_power, "Support Low Power w/FS or LS 0=Support 1=Don't Support");
6627 +module_param_named(host_ls_low_power_phy_clk, dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
6628 +MODULE_PARM_DESC(host_ls_low_power_phy_clk, "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
6629 +module_param_named(enable_dynamic_fifo, dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
6630 +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
6631 +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int, 0444);
6632 +MODULE_PARM_DESC(data_fifo_size, "Total number of words in the data FIFO memory 32-32768");
6633 +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size, int, 0444);
6634 +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
6635 +module_param_named(dev_nperio_tx_fifo_size, dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
6636 +MODULE_PARM_DESC(dev_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
6637 +module_param_named(dev_perio_tx_fifo_size_1, dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
6638 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1, "Number of words in the periodic Tx FIFO 4-768");
6639 +module_param_named(dev_perio_tx_fifo_size_2, dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
6640 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2, "Number of words in the periodic Tx FIFO 4-768");
6641 +module_param_named(dev_perio_tx_fifo_size_3, dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
6642 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3, "Number of words in the periodic Tx FIFO 4-768");
6643 +module_param_named(dev_perio_tx_fifo_size_4, dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
6644 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4, "Number of words in the periodic Tx FIFO 4-768");
6645 +module_param_named(dev_perio_tx_fifo_size_5, dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
6646 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5, "Number of words in the periodic Tx FIFO 4-768");
6647 +module_param_named(dev_perio_tx_fifo_size_6, dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
6648 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6, "Number of words in the periodic Tx FIFO 4-768");
6649 +module_param_named(dev_perio_tx_fifo_size_7, dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
6650 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7, "Number of words in the periodic Tx FIFO 4-768");
6651 +module_param_named(dev_perio_tx_fifo_size_8, dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
6652 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8, "Number of words in the periodic Tx FIFO 4-768");
6653 +module_param_named(dev_perio_tx_fifo_size_9, dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
6654 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9, "Number of words in the periodic Tx FIFO 4-768");
6655 +module_param_named(dev_perio_tx_fifo_size_10, dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
6656 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10, "Number of words in the periodic Tx FIFO 4-768");
6657 +module_param_named(dev_perio_tx_fifo_size_11, dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
6658 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11, "Number of words in the periodic Tx FIFO 4-768");
6659 +module_param_named(dev_perio_tx_fifo_size_12, dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
6660 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12, "Number of words in the periodic Tx FIFO 4-768");
6661 +module_param_named(dev_perio_tx_fifo_size_13, dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
6662 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13, "Number of words in the periodic Tx FIFO 4-768");
6663 +module_param_named(dev_perio_tx_fifo_size_14, dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
6664 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14, "Number of words in the periodic Tx FIFO 4-768");
6665 +module_param_named(dev_perio_tx_fifo_size_15, dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
6666 +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15, "Number of words in the periodic Tx FIFO 4-768");
6667 +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size, int, 0444);
6668 +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
6669 +module_param_named(host_nperio_tx_fifo_size, dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
6670 +MODULE_PARM_DESC(host_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
6671 +module_param_named(host_perio_tx_fifo_size, dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
6672 +MODULE_PARM_DESC(host_perio_tx_fifo_size, "Number of words in the host periodic Tx FIFO 16-32768");
6673 +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size, int, 0444);
6674 +/** @todo Set the max to 512K, modify checks */
6675 +MODULE_PARM_DESC(max_transfer_size, "The maximum transfer size supported in bytes 2047-65535");
6676 +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count, int, 0444);
6677 +MODULE_PARM_DESC(max_packet_count, "The maximum number of packets in a transfer 15-511");
6678 +module_param_named(host_channels, dwc_otg_module_params.host_channels, int, 0444);
6679 +MODULE_PARM_DESC(host_channels, "The number of host channel registers to use 1-16");
6680 +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int, 0444);
6681 +MODULE_PARM_DESC(dev_endpoints, "The number of endpoints in addition to EP0 available for device mode 1-15");
6682 +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
6683 +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
6684 +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int, 0444);
6685 +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
6686 +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
6687 +MODULE_PARM_DESC(phy_ulpi_ddr, "ULPI at double or single data rate 0=Single 1=Double");
6688 +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus, int, 0444);
6689 +MODULE_PARM_DESC(phy_ulpi_ext_vbus, "ULPI PHY using internal or external vbus 0=Internal");
6690 +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
6691 +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
6692 +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
6693 +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
6694 +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
6695 +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
6696 +module_param_named(debug, g_dbg_lvl, int, 0444);
6697 +MODULE_PARM_DESC(debug, "0");
6698 +module_param_named(en_multiple_tx_fifo,
6699 + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
6700 +MODULE_PARM_DESC(en_multiple_tx_fifo,
6701 + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
6702 +module_param_named(dev_tx_fifo_size_1,
6703 + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
6704 +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
6705 +module_param_named(dev_tx_fifo_size_2,
6706 + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
6707 +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
6708 +module_param_named(dev_tx_fifo_size_3,
6709 + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
6710 +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
6711 +module_param_named(dev_tx_fifo_size_4,
6712 + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
6713 +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
6714 +module_param_named(dev_tx_fifo_size_5,
6715 + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
6716 +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
6717 +module_param_named(dev_tx_fifo_size_6,
6718 + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
6719 +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
6720 +module_param_named(dev_tx_fifo_size_7,
6721 + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
6722 +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
6723 +module_param_named(dev_tx_fifo_size_8,
6724 + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
6725 +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
6726 +module_param_named(dev_tx_fifo_size_9,
6727 + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
6728 +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
6729 +module_param_named(dev_tx_fifo_size_10,
6730 + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
6731 +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
6732 +module_param_named(dev_tx_fifo_size_11,
6733 + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
6734 +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
6735 +module_param_named(dev_tx_fifo_size_12,
6736 + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
6737 +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
6738 +module_param_named(dev_tx_fifo_size_13,
6739 + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
6740 +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
6741 +module_param_named(dev_tx_fifo_size_14,
6742 + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
6743 +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
6744 +module_param_named(dev_tx_fifo_size_15,
6745 + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
6746 +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
6747 +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
6748 +MODULE_PARM_DESC(thr_ctl, "Thresholding enable flag bit"
6749 + "0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
6750 +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int, 0444);
6751 +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
6752 +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int, 0444);
6753 +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
6754 +module_param_named (iomem_base, dwc_iomem_base, ulong, 0444);
6755 +MODULE_PARM_DESC (dwc_iomem_base, "The base address of the DWC_OTG register.");
6756 +module_param_named (irq, dwc_irq, int, 0444);
6757 +MODULE_PARM_DESC (dwc_irq, "The interrupt number");
6758 +
6759 +/** @page "Module Parameters"
6760 + *
6761 + * The following parameters may be specified when starting the module.
6762 + * These parameters define how the DWC_otg controller should be
6763 + * configured. Parameter values are passed to the CIL initialization
6764 + * function dwc_otg_cil_init
6765 + *
6766 + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
6767 + *
6768 +
6769 + <table>
6770 + <tr><td>Parameter Name</td><td>Meaning</td></tr>
6771 +
6772 + <tr>
6773 + <td>otg_cap</td>
6774 + <td>Specifies the OTG capabilities. The driver will automatically detect the
6775 + value for this parameter if none is specified.
6776 + - 0: HNP and SRP capable (default, if available)
6777 + - 1: SRP Only capable
6778 + - 2: No HNP/SRP capable
6779 + </td></tr>
6780 +
6781 + <tr>
6782 + <td>dma_enable</td>
6783 + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
6784 + The driver will automatically detect the value for this parameter if none is
6785 + specified.
6786 + - 0: Slave
6787 + - 1: DMA (default, if available)
6788 + </td></tr>
6789 +
6790 + <tr>
6791 + <td>dma_burst_size</td>
6792 + <td>The DMA Burst size (applicable only for External DMA Mode).
6793 + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
6794 + </td></tr>
6795 +
6796 + <tr>
6797 + <td>speed</td>
6798 + <td>Specifies the maximum speed of operation in host and device mode. The
6799 + actual speed depends on the speed of the attached device and the value of
6800 + phy_type.
6801 + - 0: High Speed (default)
6802 + - 1: Full Speed
6803 + </td></tr>
6804 +
6805 + <tr>
6806 + <td>host_support_fs_ls_low_power</td>
6807 + <td>Specifies whether low power mode is supported when attached to a Full
6808 + Speed or Low Speed device in host mode.
6809 + - 0: Don't support low power mode (default)
6810 + - 1: Support low power mode
6811 + </td></tr>
6812 +
6813 + <tr>
6814 + <td>host_ls_low_power_phy_clk</td>
6815 + <td>Specifies the PHY clock rate in low power mode when connected to a Low
6816 + Speed device in host mode. This parameter is applicable only if
6817 + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
6818 + - 0: 48 MHz (default)
6819 + - 1: 6 MHz
6820 + </td></tr>
6821 +
6822 + <tr>
6823 + <td>enable_dynamic_fifo</td>
6824 + <td> Specifies whether FIFOs may be resized by the driver software.
6825 + - 0: Use cC FIFO size parameters
6826 + - 1: Allow dynamic FIFO sizing (default)
6827 + </td></tr>
6828 +
6829 + <tr>
6830 + <td>data_fifo_size</td>
6831 + <td>Total number of 4-byte words in the data FIFO memory. This memory
6832 + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
6833 + - Values: 32 to 32768 (default 8192)
6834 +
6835 + Note: The total FIFO memory depth in the FPGA configuration is 8192.
6836 + </td></tr>
6837 +
6838 + <tr>
6839 + <td>dev_rx_fifo_size</td>
6840 + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
6841 + FIFO sizing is enabled.
6842 + - Values: 16 to 32768 (default 1064)
6843 + </td></tr>
6844 +
6845 + <tr>
6846 + <td>dev_nperio_tx_fifo_size</td>
6847 + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
6848 + dynamic FIFO sizing is enabled.
6849 + - Values: 16 to 32768 (default 1024)
6850 + </td></tr>
6851 +
6852 + <tr>
6853 + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
6854 + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
6855 + when dynamic FIFO sizing is enabled.
6856 + - Values: 4 to 768 (default 256)
6857 + </td></tr>
6858 +
6859 + <tr>
6860 + <td>host_rx_fifo_size</td>
6861 + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
6862 + sizing is enabled.
6863 + - Values: 16 to 32768 (default 1024)
6864 + </td></tr>
6865 +
6866 + <tr>
6867 + <td>host_nperio_tx_fifo_size</td>
6868 + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
6869 + dynamic FIFO sizing is enabled in the core.
6870 + - Values: 16 to 32768 (default 1024)
6871 + </td></tr>
6872 +
6873 + <tr>
6874 + <td>host_perio_tx_fifo_size</td>
6875 + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
6876 + sizing is enabled.
6877 + - Values: 16 to 32768 (default 1024)
6878 + </td></tr>
6879 +
6880 + <tr>
6881 + <td>max_transfer_size</td>
6882 + <td>The maximum transfer size supported in bytes.
6883 + - Values: 2047 to 65,535 (default 65,535)
6884 + </td></tr>
6885 +
6886 + <tr>
6887 + <td>max_packet_count</td>
6888 + <td>The maximum number of packets in a transfer.
6889 + - Values: 15 to 511 (default 511)
6890 + </td></tr>
6891 +
6892 + <tr>
6893 + <td>host_channels</td>
6894 + <td>The number of host channel registers to use.
6895 + - Values: 1 to 16 (default 12)
6896 +
6897 + Note: The FPGA configuration supports a maximum of 12 host channels.
6898 + </td></tr>
6899 +
6900 + <tr>
6901 + <td>dev_endpoints</td>
6902 + <td>The number of endpoints in addition to EP0 available for device mode
6903 + operations.
6904 + - Values: 1 to 15 (default 6 IN and OUT)
6905 +
6906 + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
6907 + addition to EP0.
6908 + </td></tr>
6909 +
6910 + <tr>
6911 + <td>phy_type</td>
6912 + <td>Specifies the type of PHY interface to use. By default, the driver will
6913 + automatically detect the phy_type.
6914 + - 0: Full Speed
6915 + - 1: UTMI+ (default, if available)
6916 + - 2: ULPI
6917 + </td></tr>
6918 +
6919 + <tr>
6920 + <td>phy_utmi_width</td>
6921 + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
6922 + phy_type of UTMI+. Also, this parameter is applicable only if the
6923 + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
6924 + core has been configured to work at either data path width.
6925 + - Values: 8 or 16 bits (default 16)
6926 + </td></tr>
6927 +
6928 + <tr>
6929 + <td>phy_ulpi_ddr</td>
6930 + <td>Specifies whether the ULPI operates at double or single data rate. This
6931 + parameter is only applicable if phy_type is ULPI.
6932 + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
6933 + - 1: double data rate ULPI interface with 4 bit wide data bus
6934 + </td></tr>
6935 +
6936 + <tr>
6937 + <td>i2c_enable</td>
6938 + <td>Specifies whether to use the I2C interface for full speed PHY. This
6939 + parameter is only applicable if PHY_TYPE is FS.
6940 + - 0: Disabled (default)
6941 + - 1: Enabled
6942 + </td></tr>
6943 +
6944 + <tr>
6945 + <td>otg_en_multiple_tx_fifo</td>
6946 + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
6947 + The driver will automatically detect the value for this parameter if none is
6948 + specified.
6949 + - 0: Disabled
6950 + - 1: Enabled (default, if available)
6951 + </td></tr>
6952 +
6953 + <tr>
6954 + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
6955 + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
6956 + when dynamic FIFO sizing is enabled.
6957 + - Values: 4 to 768 (default 256)
6958 + </td></tr>
6959 +
6960 +*/
6961 --- /dev/null
6962 +++ b/drivers/usb/dwc_otg/dwc_otg_driver.h
6963 @@ -0,0 +1,84 @@
6964 +/* ==========================================================================
6965 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.h $
6966 + * $Revision: 1.1.1.1 $
6967 + * $Date: 2009-04-17 06:15:34 $
6968 + * $Change: 510275 $
6969 + *
6970 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
6971 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
6972 + * otherwise expressly agreed to in writing between Synopsys and you.
6973 + *
6974 + * The Software IS NOT an item of Licensed Software or Licensed Product under
6975 + * any End User Software License Agreement or Agreement for Licensed Product
6976 + * with Synopsys or any supplement thereto. You are permitted to use and
6977 + * redistribute this Software in source and binary forms, with or without
6978 + * modification, provided that redistributions of source code must retain this
6979 + * notice. You may not view, use, disclose, copy or distribute this file or
6980 + * any information contained herein except pursuant to this license grant from
6981 + * Synopsys. If you do not agree with this notice, including the disclaimer
6982 + * below, then you are not authorized to use the Software.
6983 + *
6984 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
6985 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6986 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6987 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
6988 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
6989 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
6990 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
6991 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6992 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6993 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
6994 + * DAMAGE.
6995 + * ========================================================================== */
6996 +
6997 +#if !defined(__DWC_OTG_DRIVER_H__)
6998 +#define __DWC_OTG_DRIVER_H__
6999 +
7000 +/** @file
7001 + * This file contains the interface to the Linux driver.
7002 + */
7003 +#include "dwc_otg_cil.h"
7004 +
7005 +/* Type declarations */
7006 +struct dwc_otg_pcd;
7007 +struct dwc_otg_hcd;
7008 +
7009 +/**
7010 + * This structure is a wrapper that encapsulates the driver components used to
7011 + * manage a single DWC_otg controller.
7012 + */
7013 +typedef struct dwc_otg_device
7014 +{
7015 + /** Base address returned from ioremap() */
7016 + void *base;
7017 +
7018 + /** Pointer to the core interface structure. */
7019 + dwc_otg_core_if_t *core_if;
7020 +
7021 + /** Register offset for Diagnostic API.*/
7022 + uint32_t reg_offset;
7023 +
7024 + /** Pointer to the PCD structure. */
7025 + struct dwc_otg_pcd *pcd;
7026 +
7027 + /** Pointer to the HCD structure. */
7028 + struct dwc_otg_hcd *hcd;
7029 +
7030 + /** Flag to indicate whether the common IRQ handler is installed. */
7031 + uint8_t common_irq_installed;
7032 +
7033 + /** Interrupt request number. */
7034 + unsigned int irq;
7035 +
7036 + /** Physical address of Control and Status registers, used by
7037 + * release_mem_region().
7038 + */
7039 + resource_size_t phys_addr;
7040 +
7041 + /** Length of memory region, used by release_mem_region(). */
7042 + unsigned long base_len;
7043 +} dwc_otg_device_t;
7044 +
7045 +//#define dev_dbg(fake, format, arg...) printk(KERN_CRIT __FILE__ ":%d: " format "\n" , __LINE__, ## arg)
7046 +
7047 +#endif
7048 --- /dev/null
7049 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.c
7050 @@ -0,0 +1,2870 @@
7051 +/* ==========================================================================
7052 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd.c $
7053 + * $Revision: 1.1.1.1 $
7054 + * $Date: 2009-04-17 06:15:34 $
7055 + * $Change: 631780 $
7056 + *
7057 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
7058 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
7059 + * otherwise expressly agreed to in writing between Synopsys and you.
7060 + *
7061 + * The Software IS NOT an item of Licensed Software or Licensed Product under
7062 + * any End User Software License Agreement or Agreement for Licensed Product
7063 + * with Synopsys or any supplement thereto. You are permitted to use and
7064 + * redistribute this Software in source and binary forms, with or without
7065 + * modification, provided that redistributions of source code must retain this
7066 + * notice. You may not view, use, disclose, copy or distribute this file or
7067 + * any information contained herein except pursuant to this license grant from
7068 + * Synopsys. If you do not agree with this notice, including the disclaimer
7069 + * below, then you are not authorized to use the Software.
7070 + *
7071 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
7072 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7073 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7074 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
7075 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7076 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7077 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7078 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7079 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7080 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
7081 + * DAMAGE.
7082 + * ========================================================================== */
7083 +#ifndef DWC_DEVICE_ONLY
7084 +
7085 +/**
7086 + * @file
7087 + *
7088 + * This file contains the implementation of the HCD. In Linux, the HCD
7089 + * implements the hc_driver API.
7090 + */
7091 +#include <linux/kernel.h>
7092 +#include <linux/module.h>
7093 +#include <linux/moduleparam.h>
7094 +#include <linux/init.h>
7095 +
7096 +#include <linux/device.h>
7097 +
7098 +#include <linux/errno.h>
7099 +#include <linux/list.h>
7100 +#include <linux/interrupt.h>
7101 +#include <linux/string.h>
7102 +
7103 +#include <linux/dma-mapping.h>
7104 +
7105 +#include "dwc_otg_driver.h"
7106 +#include "dwc_otg_hcd.h"
7107 +#include "dwc_otg_regs.h"
7108 +
7109 +#include <asm/irq.h>
7110 +#include "dwc_otg_ifx.h" // for Infineon platform specific.
7111 +extern atomic_t release_later;
7112 +
7113 +static u64 dma_mask = DMA_BIT_MASK(32);
7114 +
7115 +static const char dwc_otg_hcd_name [] = "dwc_otg_hcd";
7116 +static const struct hc_driver dwc_otg_hc_driver =
7117 +{
7118 + .description = dwc_otg_hcd_name,
7119 + .product_desc = "DWC OTG Controller",
7120 + .hcd_priv_size = sizeof(dwc_otg_hcd_t),
7121 + .irq = dwc_otg_hcd_irq,
7122 + .flags = HCD_MEMORY | HCD_USB2,
7123 + //.reset =
7124 + .start = dwc_otg_hcd_start,
7125 + //.suspend =
7126 + //.resume =
7127 + .stop = dwc_otg_hcd_stop,
7128 + .urb_enqueue = dwc_otg_hcd_urb_enqueue,
7129 + .urb_dequeue = dwc_otg_hcd_urb_dequeue,
7130 + .endpoint_disable = dwc_otg_hcd_endpoint_disable,
7131 + .get_frame_number = dwc_otg_hcd_get_frame_number,
7132 + .hub_status_data = dwc_otg_hcd_hub_status_data,
7133 + .hub_control = dwc_otg_hcd_hub_control,
7134 + //.hub_suspend =
7135 + //.hub_resume =
7136 +};
7137 +
7138 +
7139 +/**
7140 + * Work queue function for starting the HCD when A-Cable is connected.
7141 + * The dwc_otg_hcd_start() must be called in a process context.
7142 + */
7143 +static void hcd_start_func(struct work_struct *work)
7144 +{
7145 + struct dwc_otg_hcd *priv =
7146 + container_of(work, struct dwc_otg_hcd, start_work);
7147 + struct usb_hcd *usb_hcd = (struct usb_hcd *)priv->_p;
7148 + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, usb_hcd);
7149 + if (usb_hcd) {
7150 + dwc_otg_hcd_start(usb_hcd);
7151 + }
7152 +}
7153 +
7154 +
7155 +/**
7156 + * HCD Callback function for starting the HCD when A-Cable is
7157 + * connected.
7158 + *
7159 + * @param _p void pointer to the <code>struct usb_hcd</code>
7160 + */
7161 +static int32_t dwc_otg_hcd_start_cb(void *_p)
7162 +{
7163 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_p);
7164 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
7165 + hprt0_data_t hprt0;
7166 + if (core_if->op_state == B_HOST) {
7167 + /*
7168 + * Reset the port. During a HNP mode switch the reset
7169 + * needs to occur within 1ms and have a duration of at
7170 + * least 50ms.
7171 + */
7172 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
7173 + hprt0.b.prtrst = 1;
7174 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7175 + ((struct usb_hcd *)_p)->self.is_b_host = 1;
7176 + } else {
7177 + ((struct usb_hcd *)_p)->self.is_b_host = 0;
7178 + }
7179 + /* Need to start the HCD in a non-interrupt context. */
7180 + INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
7181 + dwc_otg_hcd->_p = _p;
7182 + schedule_work(&dwc_otg_hcd->start_work);
7183 + return 1;
7184 +}
7185 +
7186 +
7187 +/**
7188 + * HCD Callback function for stopping the HCD.
7189 + *
7190 + * @param _p void pointer to the <code>struct usb_hcd</code>
7191 + */
7192 +static int32_t dwc_otg_hcd_stop_cb( void *_p )
7193 +{
7194 + struct usb_hcd *usb_hcd = (struct usb_hcd *)_p;
7195 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7196 + dwc_otg_hcd_stop( usb_hcd );
7197 + return 1;
7198 +}
7199 +static void del_xfer_timers(dwc_otg_hcd_t *_hcd)
7200 +{
7201 +#ifdef DEBUG
7202 + int i;
7203 + int num_channels = _hcd->core_if->core_params->host_channels;
7204 + for (i = 0; i < num_channels; i++) {
7205 + del_timer(&_hcd->core_if->hc_xfer_timer[i]);
7206 + }
7207 +#endif /* */
7208 +}
7209 +
7210 +static void del_timers(dwc_otg_hcd_t *_hcd)
7211 +{
7212 + del_xfer_timers(_hcd);
7213 + del_timer(&_hcd->conn_timer);
7214 +}
7215 +
7216 +/**
7217 + * Processes all the URBs in a single list of QHs. Completes them with
7218 + * -ETIMEDOUT and frees the QTD.
7219 + */
7220 +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * _hcd,
7221 + struct list_head *_qh_list)
7222 +{
7223 + struct list_head *qh_item;
7224 + dwc_otg_qh_t *qh;
7225 + struct list_head *qtd_item;
7226 + dwc_otg_qtd_t *qtd;
7227 +
7228 + list_for_each(qh_item, _qh_list) {
7229 + qh = list_entry(qh_item, dwc_otg_qh_t, qh_list_entry);
7230 + for (qtd_item = qh->qtd_list.next; qtd_item != &qh->qtd_list;
7231 + qtd_item = qh->qtd_list.next) {
7232 + qtd = list_entry(qtd_item, dwc_otg_qtd_t, qtd_list_entry);
7233 + if (qtd->urb != NULL) {
7234 + dwc_otg_hcd_complete_urb(_hcd, qtd->urb,-ETIMEDOUT);
7235 + }
7236 + dwc_otg_hcd_qtd_remove_and_free(qtd);
7237 + }
7238 + }
7239 +}
7240 +
7241 +/**
7242 + * Responds with an error status of ETIMEDOUT to all URBs in the non-periodic
7243 + * and periodic schedules. The QTD associated with each URB is removed from
7244 + * the schedule and freed. This function may be called when a disconnect is
7245 + * detected or when the HCD is being stopped.
7246 + */
7247 +static void kill_all_urbs(dwc_otg_hcd_t *_hcd)
7248 +{
7249 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_deferred);
7250 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_inactive);
7251 + kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_active);
7252 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_inactive);
7253 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_ready);
7254 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_assigned);
7255 + kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_queued);
7256 +}
7257 +
7258 +/**
7259 + * HCD Callback function for disconnect of the HCD.
7260 + *
7261 + * @param _p void pointer to the <code>struct usb_hcd</code>
7262 + */
7263 +static int32_t dwc_otg_hcd_disconnect_cb( void *_p )
7264 +{
7265 + gintsts_data_t intr;
7266 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
7267 +
7268 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7269 +
7270 + /*
7271 + * Set status flags for the hub driver.
7272 + */
7273 + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
7274 + dwc_otg_hcd->flags.b.port_connect_status = 0;
7275 +
7276 + /*
7277 + * Shutdown any transfers in process by clearing the Tx FIFO Empty
7278 + * interrupt mask and status bits and disabling subsequent host
7279 + * channel interrupts.
7280 + */
7281 + intr.d32 = 0;
7282 + intr.b.nptxfempty = 1;
7283 + intr.b.ptxfempty = 1;
7284 + intr.b.hcintr = 1;
7285 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, intr.d32, 0);
7286 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintsts, intr.d32, 0);
7287 +
7288 + del_timers(dwc_otg_hcd);
7289 +
7290 + /*
7291 + * Turn off the vbus power only if the core has transitioned to device
7292 + * mode. If still in host mode, need to keep power on to detect a
7293 + * reconnection.
7294 + */
7295 + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
7296 + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
7297 + hprt0_data_t hprt0 = { .d32=0 };
7298 + DWC_PRINT("Disconnect: PortPower off\n");
7299 + hprt0.b.prtpwr = 0;
7300 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
7301 + }
7302 +
7303 + dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
7304 + }
7305 +
7306 + /* Respond with an error status to all URBs in the schedule. */
7307 + kill_all_urbs(dwc_otg_hcd);
7308 +
7309 + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
7310 + /* Clean up any host channels that were in use. */
7311 + int num_channels;
7312 + int i;
7313 + dwc_hc_t *channel;
7314 + dwc_otg_hc_regs_t *hc_regs;
7315 + hcchar_data_t hcchar;
7316 +
7317 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
7318 +
7319 + if (!dwc_otg_hcd->core_if->dma_enable) {
7320 + /* Flush out any channel requests in slave mode. */
7321 + for (i = 0; i < num_channels; i++) {
7322 + channel = dwc_otg_hcd->hc_ptr_array[i];
7323 + if (list_empty(&channel->hc_list_entry)) {
7324 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
7325 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7326 + if (hcchar.b.chen) {
7327 + hcchar.b.chen = 0;
7328 + hcchar.b.chdis = 1;
7329 + hcchar.b.epdir = 0;
7330 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
7331 + }
7332 + }
7333 + }
7334 + }
7335 +
7336 + for (i = 0; i < num_channels; i++) {
7337 + channel = dwc_otg_hcd->hc_ptr_array[i];
7338 + if (list_empty(&channel->hc_list_entry)) {
7339 + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
7340 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7341 + if (hcchar.b.chen) {
7342 + /* Halt the channel. */
7343 + hcchar.b.chdis = 1;
7344 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
7345 + }
7346 +
7347 + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if, channel);
7348 + list_add_tail(&channel->hc_list_entry,
7349 + &dwc_otg_hcd->free_hc_list);
7350 + }
7351 + }
7352 + }
7353 +
7354 + /* A disconnect will end the session so the B-Device is no
7355 + * longer a B-host. */
7356 + ((struct usb_hcd *)_p)->self.is_b_host = 0;
7357 +
7358 + return 1;
7359 +}
7360 +
7361 +/**
7362 + * Connection timeout function. An OTG host is required to display a
7363 + * message if the device does not connect within 10 seconds.
7364 + */
7365 +void dwc_otg_hcd_connect_timeout( unsigned long _ptr )
7366 +{
7367 + DWC_DEBUGPL(DBG_HCDV, "%s(%x)\n", __func__, (int)_ptr);
7368 + DWC_PRINT( "Connect Timeout\n");
7369 + DWC_ERROR( "Device Not Connected/Responding\n" );
7370 +}
7371 +
7372 +/**
7373 + * Start the connection timer. An OTG host is required to display a
7374 + * message if the device does not connect within 10 seconds. The
7375 + * timer is deleted if a port connect interrupt occurs before the
7376 + * timer expires.
7377 + */
7378 +static void dwc_otg_hcd_start_connect_timer( dwc_otg_hcd_t *_hcd)
7379 +{
7380 + init_timer( &_hcd->conn_timer );
7381 + _hcd->conn_timer.function = dwc_otg_hcd_connect_timeout;
7382 + _hcd->conn_timer.data = (unsigned long)0;
7383 + _hcd->conn_timer.expires = jiffies + (HZ*10);
7384 + add_timer( &_hcd->conn_timer );
7385 +}
7386 +
7387 +/**
7388 + * HCD Callback function for disconnect of the HCD.
7389 + *
7390 + * @param _p void pointer to the <code>struct usb_hcd</code>
7391 + */
7392 +static int32_t dwc_otg_hcd_session_start_cb( void *_p )
7393 +{
7394 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
7395 + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
7396 + dwc_otg_hcd_start_connect_timer( dwc_otg_hcd );
7397 + return 1;
7398 +}
7399 +
7400 +/**
7401 + * HCD Callback structure for handling mode switching.
7402 + */
7403 +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
7404 + .start = dwc_otg_hcd_start_cb,
7405 + .stop = dwc_otg_hcd_stop_cb,
7406 + .disconnect = dwc_otg_hcd_disconnect_cb,
7407 + .session_start = dwc_otg_hcd_session_start_cb,
7408 + .p = 0,
7409 +};
7410 +
7411 +
7412 +/**
7413 + * Reset tasklet function
7414 + */
7415 +static void reset_tasklet_func (unsigned long data)
7416 +{
7417 + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t*)data;
7418 + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
7419 + hprt0_data_t hprt0;
7420 +
7421 + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
7422 +
7423 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
7424 + hprt0.b.prtrst = 1;
7425 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7426 + mdelay (60);
7427 +
7428 + hprt0.b.prtrst = 0;
7429 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
7430 + dwc_otg_hcd->flags.b.port_reset_change = 1;
7431 +
7432 + return;
7433 +}
7434 +
7435 +static struct tasklet_struct reset_tasklet = {
7436 + .next = NULL,
7437 + .state = 0,
7438 + .count = ATOMIC_INIT(0),
7439 + .func = reset_tasklet_func,
7440 + .data = 0,
7441 +};
7442 +
7443 +/**
7444 + * Initializes the HCD. This function allocates memory for and initializes the
7445 + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
7446 + * USB bus with the core and calls the hc_driver->start() function. It returns
7447 + * a negative error on failure.
7448 + */
7449 +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
7450 +
7451 +int __devinit dwc_otg_hcd_init(struct device *_dev, dwc_otg_device_t * dwc_otg_device)
7452 +{
7453 + struct usb_hcd *hcd = NULL;
7454 + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
7455 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
7456 +
7457 + int num_channels;
7458 + int i;
7459 + dwc_hc_t *channel;
7460 +
7461 + int retval = 0;
7462 +
7463 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
7464 +
7465 + /*
7466 + * Allocate memory for the base HCD plus the DWC OTG HCD.
7467 + * Initialize the base HCD.
7468 + */
7469 + hcd = usb_create_hcd(&dwc_otg_hc_driver, _dev, dev_name(_dev));
7470 + if (hcd == NULL) {
7471 + retval = -ENOMEM;
7472 + goto error1;
7473 + }
7474 + dev_set_drvdata(_dev, dwc_otg_device); /* fscz restore */
7475 + hcd->regs = otg_dev->base;
7476 + hcd->rsrc_start = (int)otg_dev->base;
7477 +
7478 + hcd->self.otg_port = 1;
7479 +
7480 + /* Initialize the DWC OTG HCD. */
7481 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
7482 + dwc_otg_hcd->core_if = otg_dev->core_if;
7483 + otg_dev->hcd = dwc_otg_hcd;
7484 +
7485 + /* Register the HCD CIL Callbacks */
7486 + dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
7487 + &hcd_cil_callbacks, hcd);
7488 +
7489 + /* Initialize the non-periodic schedule. */
7490 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
7491 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
7492 + INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_deferred);
7493 +
7494 + /* Initialize the periodic schedule. */
7495 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
7496 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
7497 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
7498 + INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
7499 +
7500 + /*
7501 + * Create a host channel descriptor for each host channel implemented
7502 + * in the controller. Initialize the channel descriptor array.
7503 + */
7504 + INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
7505 + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
7506 + for (i = 0; i < num_channels; i++) {
7507 + channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
7508 + if (channel == NULL) {
7509 + retval = -ENOMEM;
7510 + DWC_ERROR("%s: host channel allocation failed\n", __func__);
7511 + goto error2;
7512 + }
7513 + memset(channel, 0, sizeof(dwc_hc_t));
7514 + channel->hc_num = i;
7515 + dwc_otg_hcd->hc_ptr_array[i] = channel;
7516 +#ifdef DEBUG
7517 + init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
7518 +#endif
7519 +
7520 + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
7521 + }
7522 +
7523 + /* Initialize the Connection timeout timer. */
7524 + init_timer( &dwc_otg_hcd->conn_timer );
7525 +
7526 + /* Initialize reset tasklet. */
7527 + reset_tasklet.data = (unsigned long) dwc_otg_hcd;
7528 + dwc_otg_hcd->reset_tasklet = &reset_tasklet;
7529 +
7530 + /* Set device flags indicating whether the HCD supports DMA. */
7531 + if (otg_dev->core_if->dma_enable) {
7532 + DWC_PRINT("Using DMA mode\n");
7533 + //_dev->dma_mask = (void *)~0;
7534 + //_dev->coherent_dma_mask = ~0;
7535 + _dev->dma_mask = &dma_mask;
7536 + _dev->coherent_dma_mask = DMA_BIT_MASK(32);
7537 + } else {
7538 + DWC_PRINT("Using Slave mode\n");
7539 + _dev->dma_mask = (void *)0;
7540 + _dev->coherent_dma_mask = 0;
7541 + }
7542 +
7543 + init_hcd_usecs(dwc_otg_hcd);
7544 + /*
7545 + * Finish generic HCD initialization and start the HCD. This function
7546 + * allocates the DMA buffer pool, registers the USB bus, requests the
7547 + * IRQ line, and calls dwc_otg_hcd_start method.
7548 + */
7549 + retval = usb_add_hcd(hcd, otg_dev->irq, IRQF_SHARED);
7550 + if (retval < 0) {
7551 + goto error2;
7552 + }
7553 +
7554 + /*
7555 + * Allocate space for storing data on status transactions. Normally no
7556 + * data is sent, but this space acts as a bit bucket. This must be
7557 + * done after usb_add_hcd since that function allocates the DMA buffer
7558 + * pool.
7559 + */
7560 + if (otg_dev->core_if->dma_enable) {
7561 + dwc_otg_hcd->status_buf =
7562 + dma_alloc_coherent(_dev,
7563 + DWC_OTG_HCD_STATUS_BUF_SIZE,
7564 + &dwc_otg_hcd->status_buf_dma,
7565 + GFP_KERNEL | GFP_DMA);
7566 + } else {
7567 + dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
7568 + GFP_KERNEL);
7569 + }
7570 + if (dwc_otg_hcd->status_buf == NULL) {
7571 + retval = -ENOMEM;
7572 + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
7573 + goto error3;
7574 + }
7575 +
7576 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
7577 + dev_name(_dev), hcd->self.busnum);
7578 +
7579 + return 0;
7580 +
7581 + /* Error conditions */
7582 +error3:
7583 + usb_remove_hcd(hcd);
7584 +error2:
7585 + dwc_otg_hcd_free(hcd);
7586 + usb_put_hcd(hcd);
7587 +error1:
7588 + return retval;
7589 +}
7590 +
7591 +/**
7592 + * Removes the HCD.
7593 + * Frees memory and resources associated with the HCD and deregisters the bus.
7594 + */
7595 +void dwc_otg_hcd_remove(struct device *_dev)
7596 +{
7597 + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
7598 + dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
7599 + struct usb_hcd *hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
7600 +
7601 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE\n");
7602 +
7603 + /* Turn off all interrupts */
7604 + dwc_write_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0);
7605 + dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gahbcfg, 1, 0);
7606 +
7607 + usb_remove_hcd(hcd);
7608 +
7609 + dwc_otg_hcd_free(hcd);
7610 +
7611 + usb_put_hcd(hcd);
7612 +
7613 + return;
7614 +}
7615 +
7616 +
7617 +/* =========================================================================
7618 + * Linux HC Driver Functions
7619 + * ========================================================================= */
7620 +
7621 +/**
7622 + * Initializes dynamic portions of the DWC_otg HCD state.
7623 + */
7624 +static void hcd_reinit(dwc_otg_hcd_t *_hcd)
7625 +{
7626 + struct list_head *item;
7627 + int num_channels;
7628 + int i;
7629 + dwc_hc_t *channel;
7630 +
7631 + _hcd->flags.d32 = 0;
7632 +
7633 + _hcd->non_periodic_qh_ptr = &_hcd->non_periodic_sched_active;
7634 + _hcd->available_host_channels = _hcd->core_if->core_params->host_channels;
7635 +
7636 + /*
7637 + * Put all channels in the free channel list and clean up channel
7638 + * states.
7639 + */
7640 + item = _hcd->free_hc_list.next;
7641 + while (item != &_hcd->free_hc_list) {
7642 + list_del(item);
7643 + item = _hcd->free_hc_list.next;
7644 + }
7645 + num_channels = _hcd->core_if->core_params->host_channels;
7646 + for (i = 0; i < num_channels; i++) {
7647 + channel = _hcd->hc_ptr_array[i];
7648 + list_add_tail(&channel->hc_list_entry, &_hcd->free_hc_list);
7649 + dwc_otg_hc_cleanup(_hcd->core_if, channel);
7650 + }
7651 +
7652 + /* Initialize the DWC core for host mode operation. */
7653 + dwc_otg_core_host_init(_hcd->core_if);
7654 +}
7655 +
7656 +/** Initializes the DWC_otg controller and its root hub and prepares it for host
7657 + * mode operation. Activates the root port. Returns 0 on success and a negative
7658 + * error code on failure. */
7659 +int dwc_otg_hcd_start(struct usb_hcd *_hcd)
7660 +{
7661 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7662 + dwc_otg_core_if_t * core_if = dwc_otg_hcd->core_if;
7663 + struct usb_bus *bus;
7664 +
7665 + // int retval;
7666 +
7667 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
7668 +
7669 + bus = hcd_to_bus(_hcd);
7670 +
7671 + /* Initialize the bus state. If the core is in Device Mode
7672 + * HALT the USB bus and return. */
7673 + if (dwc_otg_is_device_mode (core_if)) {
7674 + _hcd->state = HC_STATE_HALT;
7675 + return 0;
7676 + }
7677 + _hcd->state = HC_STATE_RUNNING;
7678 +
7679 + /* Initialize and connect root hub if one is not already attached */
7680 + if (bus->root_hub) {
7681 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
7682 + /* Inform the HUB driver to resume. */
7683 + usb_hcd_resume_root_hub(_hcd);
7684 + }
7685 + else {
7686 +#if 0
7687 + struct usb_device *udev;
7688 + udev = usb_alloc_dev(NULL, bus, 0);
7689 + if (!udev) {
7690 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
7691 + return -ENODEV;
7692 + }
7693 + udev->speed = USB_SPEED_HIGH;
7694 + /* Not needed - VJ
7695 + if ((retval = usb_hcd_register_root_hub(udev, _hcd)) != 0) {
7696 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error registering %d\n", retval);
7697 + return -ENODEV;
7698 + }
7699 + */
7700 +#else
7701 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
7702 +#endif
7703 + }
7704 +
7705 + hcd_reinit(dwc_otg_hcd);
7706 +
7707 + return 0;
7708 +}
7709 +
7710 +static void qh_list_free(dwc_otg_hcd_t *_hcd, struct list_head *_qh_list)
7711 +{
7712 + struct list_head *item;
7713 + dwc_otg_qh_t *qh;
7714 +
7715 + if (_qh_list->next == NULL) {
7716 + /* The list hasn't been initialized yet. */
7717 + return;
7718 + }
7719 +
7720 + /* Ensure there are no QTDs or URBs left. */
7721 + kill_urbs_in_qh_list(_hcd, _qh_list);
7722 +
7723 + for (item = _qh_list->next; item != _qh_list; item = _qh_list->next) {
7724 + qh = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7725 + dwc_otg_hcd_qh_remove_and_free(_hcd, qh);
7726 + }
7727 +}
7728 +
7729 +/**
7730 + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
7731 + * stopped.
7732 + */
7733 +void dwc_otg_hcd_stop(struct usb_hcd *_hcd)
7734 +{
7735 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7736 + hprt0_data_t hprt0 = { .d32=0 };
7737 +
7738 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
7739 +
7740 + /* Turn off all host-specific interrupts. */
7741 + dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
7742 +
7743 + /*
7744 + * The root hub should be disconnected before this function is called.
7745 + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
7746 + * and the QH lists (via ..._hcd_endpoint_disable).
7747 + */
7748 +
7749 + /* Turn off the vbus power */
7750 + DWC_PRINT("PortPower off\n");
7751 + hprt0.b.prtpwr = 0;
7752 + dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
7753 +
7754 + return;
7755 +}
7756 +
7757 +
7758 +/** Returns the current frame number. */
7759 +int dwc_otg_hcd_get_frame_number(struct usb_hcd *_hcd)
7760 +{
7761 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7762 + hfnum_data_t hfnum;
7763 +
7764 + hfnum.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->
7765 + host_if->host_global_regs->hfnum);
7766 +
7767 +#ifdef DEBUG_SOF
7768 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n", hfnum.b.frnum);
7769 +#endif
7770 + return hfnum.b.frnum;
7771 +}
7772 +
7773 +/**
7774 + * Frees secondary storage associated with the dwc_otg_hcd structure contained
7775 + * in the struct usb_hcd field.
7776 + */
7777 +void dwc_otg_hcd_free(struct usb_hcd *_hcd)
7778 +{
7779 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7780 + int i;
7781 +
7782 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
7783 +
7784 + del_timers(dwc_otg_hcd);
7785 +
7786 + /* Free memory for QH/QTD lists */
7787 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
7788 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_deferred);
7789 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
7790 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
7791 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
7792 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
7793 + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
7794 +
7795 + /* Free memory for the host channels. */
7796 + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
7797 + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
7798 + if (hc != NULL) {
7799 + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n", i, hc);
7800 + kfree(hc);
7801 + }
7802 + }
7803 +
7804 + if (dwc_otg_hcd->core_if->dma_enable) {
7805 + if (dwc_otg_hcd->status_buf_dma) {
7806 + dma_free_coherent(_hcd->self.controller,
7807 + DWC_OTG_HCD_STATUS_BUF_SIZE,
7808 + dwc_otg_hcd->status_buf,
7809 + dwc_otg_hcd->status_buf_dma);
7810 + }
7811 + } else if (dwc_otg_hcd->status_buf != NULL) {
7812 + kfree(dwc_otg_hcd->status_buf);
7813 + }
7814 +
7815 + return;
7816 +}
7817 +
7818 +
7819 +#ifdef DEBUG
7820 +static void dump_urb_info(struct urb *_urb, char* _fn_name)
7821 +{
7822 + DWC_PRINT("%s, urb %p\n", _fn_name, _urb);
7823 + DWC_PRINT(" Device address: %d\n", usb_pipedevice(_urb->pipe));
7824 + DWC_PRINT(" Endpoint: %d, %s\n", usb_pipeendpoint(_urb->pipe),
7825 + (usb_pipein(_urb->pipe) ? "IN" : "OUT"));
7826 + DWC_PRINT(" Endpoint type: %s\n",
7827 + ({char *pipetype;
7828 + switch (usb_pipetype(_urb->pipe)) {
7829 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
7830 + case PIPE_BULK: pipetype = "BULK"; break;
7831 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
7832 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
7833 + default: pipetype = "UNKNOWN"; break;
7834 + }; pipetype;}));
7835 + DWC_PRINT(" Speed: %s\n",
7836 + ({char *speed;
7837 + switch (_urb->dev->speed) {
7838 + case USB_SPEED_HIGH: speed = "HIGH"; break;
7839 + case USB_SPEED_FULL: speed = "FULL"; break;
7840 + case USB_SPEED_LOW: speed = "LOW"; break;
7841 + default: speed = "UNKNOWN"; break;
7842 + }; speed;}));
7843 + DWC_PRINT(" Max packet size: %d\n",
7844 + usb_maxpacket(_urb->dev, _urb->pipe, usb_pipeout(_urb->pipe)));
7845 + DWC_PRINT(" Data buffer length: %d\n", _urb->transfer_buffer_length);
7846 + DWC_PRINT(" Transfer buffer: %p, Transfer DMA: %p\n",
7847 + _urb->transfer_buffer, (void *)_urb->transfer_dma);
7848 + DWC_PRINT(" Setup buffer: %p, Setup DMA: %p\n",
7849 + _urb->setup_packet, (void *)_urb->setup_dma);
7850 + DWC_PRINT(" Interval: %d\n", _urb->interval);
7851 + if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
7852 + int i;
7853 + for (i = 0; i < _urb->number_of_packets; i++) {
7854 + DWC_PRINT(" ISO Desc %d:\n", i);
7855 + DWC_PRINT(" offset: %d, length %d\n",
7856 + _urb->iso_frame_desc[i].offset,
7857 + _urb->iso_frame_desc[i].length);
7858 + }
7859 + }
7860 +}
7861 +
7862 +static void dump_channel_info(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *qh)
7863 +{
7864 + if (qh->channel != NULL) {
7865 + dwc_hc_t *hc = qh->channel;
7866 + struct list_head *item;
7867 + dwc_otg_qh_t *qh_item;
7868 + int num_channels = _hcd->core_if->core_params->host_channels;
7869 + int i;
7870 +
7871 + dwc_otg_hc_regs_t *hc_regs;
7872 + hcchar_data_t hcchar;
7873 + hcsplt_data_t hcsplt;
7874 + hctsiz_data_t hctsiz;
7875 + uint32_t hcdma;
7876 +
7877 + hc_regs = _hcd->core_if->host_if->hc_regs[hc->hc_num];
7878 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
7879 + hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
7880 + hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
7881 + hcdma = dwc_read_reg32(&hc_regs->hcdma);
7882 +
7883 + DWC_PRINT(" Assigned to channel %p:\n", hc);
7884 + DWC_PRINT(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
7885 + DWC_PRINT(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
7886 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
7887 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
7888 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
7889 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
7890 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
7891 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
7892 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
7893 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
7894 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
7895 + DWC_PRINT(" qh: %p\n", hc->qh);
7896 + DWC_PRINT(" NP inactive sched:\n");
7897 + list_for_each(item, &_hcd->non_periodic_sched_inactive) {
7898 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7899 + DWC_PRINT(" %p\n", qh_item);
7900 + } DWC_PRINT(" NP active sched:\n");
7901 + list_for_each(item, &_hcd->non_periodic_sched_deferred) {
7902 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7903 + DWC_PRINT(" %p\n", qh_item);
7904 + } DWC_PRINT(" NP deferred sched:\n");
7905 + list_for_each(item, &_hcd->non_periodic_sched_active) {
7906 + qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
7907 + DWC_PRINT(" %p\n", qh_item);
7908 + } DWC_PRINT(" Channels: \n");
7909 + for (i = 0; i < num_channels; i++) {
7910 + dwc_hc_t *hc = _hcd->hc_ptr_array[i];
7911 + DWC_PRINT(" %2d: %p\n", i, hc);
7912 + }
7913 + }
7914 +}
7915 +#endif // DEBUG
7916 +
7917 +/** Starts processing a USB transfer request specified by a USB Request Block
7918 + * (URB). mem_flags indicates the type of memory allocation to use while
7919 + * processing this URB. */
7920 +int dwc_otg_hcd_urb_enqueue(struct usb_hcd *_hcd,
7921 + struct urb *_urb,
7922 + gfp_t _mem_flags)
7923 +{
7924 + unsigned long flags;
7925 + int retval;
7926 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
7927 + dwc_otg_qtd_t *qtd;
7928 +
7929 + local_irq_save(flags);
7930 + retval = usb_hcd_link_urb_to_ep(_hcd, _urb);
7931 + if (retval) {
7932 + local_irq_restore(flags);
7933 + return retval;
7934 + }
7935 +#ifdef DEBUG
7936 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
7937 + dump_urb_info(_urb, "dwc_otg_hcd_urb_enqueue");
7938 + }
7939 +#endif // DEBUG
7940 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
7941 + /* No longer connected. */
7942 + local_irq_restore(flags);
7943 + return -ENODEV;
7944 + }
7945 +
7946 + qtd = dwc_otg_hcd_qtd_create (_urb);
7947 + if (qtd == NULL) {
7948 + local_irq_restore(flags);
7949 + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
7950 + return -ENOMEM;
7951 + }
7952 +
7953 + retval = dwc_otg_hcd_qtd_add (qtd, dwc_otg_hcd);
7954 + if (retval < 0) {
7955 + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
7956 + "Error status %d\n", retval);
7957 + dwc_otg_hcd_qtd_free(qtd);
7958 + }
7959 +
7960 + local_irq_restore (flags);
7961 + return retval;
7962 +}
7963 +
7964 +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
7965 + * success. */
7966 +int dwc_otg_hcd_urb_dequeue(struct usb_hcd *_hcd, struct urb *_urb, int _status)
7967 +{
7968 + unsigned long flags;
7969 + dwc_otg_hcd_t *dwc_otg_hcd;
7970 + dwc_otg_qtd_t *urb_qtd;
7971 + dwc_otg_qh_t *qh;
7972 + int retval;
7973 + //struct usb_host_endpoint *_ep = NULL;
7974 +
7975 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
7976 +
7977 + local_irq_save(flags);
7978 +
7979 + retval = usb_hcd_check_unlink_urb(_hcd, _urb, _status);
7980 + if (retval) {
7981 + local_irq_restore(flags);
7982 + return retval;
7983 + }
7984 +
7985 + dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
7986 + urb_qtd = (dwc_otg_qtd_t *)_urb->hcpriv;
7987 + if (urb_qtd == NULL) {
7988 + printk("urb_qtd is NULL for _urb %08x\n",(unsigned)_urb);
7989 + goto done;
7990 + }
7991 + qh = (dwc_otg_qh_t *) urb_qtd->qtd_qh_ptr;
7992 + if (qh == NULL) {
7993 + goto done;
7994 + }
7995 +
7996 +#ifdef DEBUG
7997 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
7998 + dump_urb_info(_urb, "dwc_otg_hcd_urb_dequeue");
7999 + if (urb_qtd == qh->qtd_in_process) {
8000 + dump_channel_info(dwc_otg_hcd, qh);
8001 + }
8002 + }
8003 +#endif // DEBUG
8004 +
8005 + if (urb_qtd == qh->qtd_in_process) {
8006 + /* The QTD is in process (it has been assigned to a channel). */
8007 +
8008 + if (dwc_otg_hcd->flags.b.port_connect_status) {
8009 + /*
8010 + * If still connected (i.e. in host mode), halt the
8011 + * channel so it can be used for other transfers. If
8012 + * no longer connected, the host registers can't be
8013 + * written to halt the channel since the core is in
8014 + * device mode.
8015 + */
8016 + dwc_otg_hc_halt(dwc_otg_hcd->core_if, qh->channel,
8017 + DWC_OTG_HC_XFER_URB_DEQUEUE);
8018 + }
8019 + }
8020 +
8021 + /*
8022 + * Free the QTD and clean up the associated QH. Leave the QH in the
8023 + * schedule if it has any remaining QTDs.
8024 + */
8025 + dwc_otg_hcd_qtd_remove_and_free(urb_qtd);
8026 + if (urb_qtd == qh->qtd_in_process) {
8027 + dwc_otg_hcd_qh_deactivate(dwc_otg_hcd, qh, 0);
8028 + qh->channel = NULL;
8029 + qh->qtd_in_process = NULL;
8030 + } else if (list_empty(&qh->qtd_list)) {
8031 + dwc_otg_hcd_qh_remove(dwc_otg_hcd, qh);
8032 + }
8033 +
8034 +done:
8035 + local_irq_restore(flags);
8036 + _urb->hcpriv = NULL;
8037 +
8038 + /* Higher layer software sets URB status. */
8039 + usb_hcd_unlink_urb_from_ep(_hcd, _urb);
8040 + usb_hcd_giveback_urb(_hcd, _urb, _status);
8041 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
8042 + DWC_PRINT("Called usb_hcd_giveback_urb()\n");
8043 + DWC_PRINT(" urb->status = %d\n", _urb->status);
8044 + }
8045 +
8046 + return 0;
8047 +}
8048 +
8049 +
8050 +/** Frees resources in the DWC_otg controller related to a given endpoint. Also
8051 + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
8052 + * must already be dequeued. */
8053 +void dwc_otg_hcd_endpoint_disable(struct usb_hcd *_hcd,
8054 + struct usb_host_endpoint *_ep)
8055 +
8056 +{
8057 + dwc_otg_qh_t *qh;
8058 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
8059 +
8060 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
8061 + "endpoint=%d\n", _ep->desc.bEndpointAddress,
8062 + dwc_ep_addr_to_endpoint(_ep->desc.bEndpointAddress));
8063 +
8064 + qh = (dwc_otg_qh_t *)(_ep->hcpriv);
8065 + if (qh != NULL) {
8066 +#ifdef DEBUG
8067 + /** Check that the QTD list is really empty */
8068 + if (!list_empty(&qh->qtd_list)) {
8069 + DWC_WARN("DWC OTG HCD EP DISABLE:"
8070 + " QTD List for this endpoint is not empty\n");
8071 + }
8072 +#endif // DEBUG
8073 +
8074 + dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
8075 + _ep->hcpriv = NULL;
8076 + }
8077 +
8078 + return;
8079 +}
8080 +extern int dwc_irq;
8081 +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
8082 + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
8083 + * interrupt.
8084 + *
8085 + * This function is called by the USB core when an interrupt occurs */
8086 +irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *_hcd)
8087 +{
8088 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8089 +
8090 + mask_and_ack_ifx_irq (dwc_irq);
8091 + return IRQ_RETVAL(dwc_otg_hcd_handle_intr(dwc_otg_hcd));
8092 +}
8093 +
8094 +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
8095 + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
8096 + * is the status change indicator for the single root port. Returns 1 if either
8097 + * change indicator is 1, otherwise returns 0. */
8098 +int dwc_otg_hcd_hub_status_data(struct usb_hcd *_hcd, char *_buf)
8099 +{
8100 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8101 +
8102 + _buf[0] = 0;
8103 + _buf[0] |= (dwc_otg_hcd->flags.b.port_connect_status_change ||
8104 + dwc_otg_hcd->flags.b.port_reset_change ||
8105 + dwc_otg_hcd->flags.b.port_enable_change ||
8106 + dwc_otg_hcd->flags.b.port_suspend_change ||
8107 + dwc_otg_hcd->flags.b.port_over_current_change) << 1;
8108 +
8109 +#ifdef DEBUG
8110 + if (_buf[0]) {
8111 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
8112 + " Root port status changed\n");
8113 + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
8114 + dwc_otg_hcd->flags.b.port_connect_status_change);
8115 + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
8116 + dwc_otg_hcd->flags.b.port_reset_change);
8117 + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
8118 + dwc_otg_hcd->flags.b.port_enable_change);
8119 + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
8120 + dwc_otg_hcd->flags.b.port_suspend_change);
8121 + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
8122 + dwc_otg_hcd->flags.b.port_over_current_change);
8123 + }
8124 +#endif // DEBUG
8125 + return (_buf[0] != 0);
8126 +}
8127 +
8128 +#ifdef DWC_HS_ELECT_TST
8129 +/*
8130 + * Quick and dirty hack to implement the HS Electrical Test
8131 + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
8132 + *
8133 + * This code was copied from our userspace app "hset". It sends a
8134 + * Get Device Descriptor control sequence in two parts, first the
8135 + * Setup packet by itself, followed some time later by the In and
8136 + * Ack packets. Rather than trying to figure out how to add this
8137 + * functionality to the normal driver code, we just hijack the
8138 + * hardware, using these two function to drive the hardware
8139 + * directly.
8140 + */
8141 +
8142 +dwc_otg_core_global_regs_t *global_regs;
8143 +dwc_otg_host_global_regs_t *hc_global_regs;
8144 +dwc_otg_hc_regs_t *hc_regs;
8145 +uint32_t *data_fifo;
8146 +
8147 +static void do_setup(void)
8148 +{
8149 + gintsts_data_t gintsts;
8150 + hctsiz_data_t hctsiz;
8151 + hcchar_data_t hcchar;
8152 + haint_data_t haint;
8153 + hcint_data_t hcint;
8154 +
8155 + /* Enable HAINTs */
8156 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
8157 +
8158 + /* Enable HCINTs */
8159 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
8160 +
8161 + /* Read GINTSTS */
8162 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8163 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8164 +
8165 + /* Read HAINT */
8166 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8167 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8168 +
8169 + /* Read HCINT */
8170 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8171 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8172 +
8173 + /* Read HCCHAR */
8174 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8175 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8176 +
8177 + /* Clear HCINT */
8178 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8179 +
8180 + /* Clear HAINT */
8181 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8182 +
8183 + /* Clear GINTSTS */
8184 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8185 +
8186 + /* Read GINTSTS */
8187 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8188 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8189 +
8190 + /*
8191 + * Send Setup packet (Get Device Descriptor)
8192 + */
8193 +
8194 + /* Make sure channel is disabled */
8195 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8196 + if (hcchar.b.chen) {
8197 + //fprintf(stderr, "Channel already enabled 1, HCCHAR = %08x\n", hcchar.d32);
8198 + hcchar.b.chdis = 1;
8199 + // hcchar.b.chen = 1;
8200 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8201 + //sleep(1);
8202 + MDELAY(1000);
8203 +
8204 + /* Read GINTSTS */
8205 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8206 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8207 +
8208 + /* Read HAINT */
8209 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8210 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8211 +
8212 + /* Read HCINT */
8213 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8214 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8215 +
8216 + /* Read HCCHAR */
8217 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8218 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8219 +
8220 + /* Clear HCINT */
8221 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8222 +
8223 + /* Clear HAINT */
8224 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8225 +
8226 + /* Clear GINTSTS */
8227 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8228 +
8229 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8230 + //if (hcchar.b.chen) {
8231 + // fprintf(stderr, "** Channel _still_ enabled 1, HCCHAR = %08x **\n", hcchar.d32);
8232 + //}
8233 + }
8234 +
8235 + /* Set HCTSIZ */
8236 + hctsiz.d32 = 0;
8237 + hctsiz.b.xfersize = 8;
8238 + hctsiz.b.pktcnt = 1;
8239 + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
8240 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8241 +
8242 + /* Set HCCHAR */
8243 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8244 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8245 + hcchar.b.epdir = 0;
8246 + hcchar.b.epnum = 0;
8247 + hcchar.b.mps = 8;
8248 + hcchar.b.chen = 1;
8249 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8250 +
8251 + /* Fill FIFO with Setup data for Get Device Descriptor */
8252 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8253 + dwc_write_reg32(data_fifo++, 0x01000680);
8254 + dwc_write_reg32(data_fifo++, 0x00080000);
8255 +
8256 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8257 + //fprintf(stderr, "Waiting for HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
8258 +
8259 + /* Wait for host channel interrupt */
8260 + do {
8261 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8262 + } while (gintsts.b.hcintr == 0);
8263 +
8264 + //fprintf(stderr, "Got HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
8265 +
8266 + /* Disable HCINTs */
8267 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
8268 +
8269 + /* Disable HAINTs */
8270 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
8271 +
8272 + /* Read HAINT */
8273 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8274 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8275 +
8276 + /* Read HCINT */
8277 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8278 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8279 +
8280 + /* Read HCCHAR */
8281 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8282 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8283 +
8284 + /* Clear HCINT */
8285 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8286 +
8287 + /* Clear HAINT */
8288 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8289 +
8290 + /* Clear GINTSTS */
8291 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8292 +
8293 + /* Read GINTSTS */
8294 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8295 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8296 +}
8297 +
8298 +static void do_in_ack(void)
8299 +{
8300 + gintsts_data_t gintsts;
8301 + hctsiz_data_t hctsiz;
8302 + hcchar_data_t hcchar;
8303 + haint_data_t haint;
8304 + hcint_data_t hcint;
8305 + host_grxsts_data_t grxsts;
8306 +
8307 + /* Enable HAINTs */
8308 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
8309 +
8310 + /* Enable HCINTs */
8311 + dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
8312 +
8313 + /* Read GINTSTS */
8314 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8315 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8316 +
8317 + /* Read HAINT */
8318 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8319 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8320 +
8321 + /* Read HCINT */
8322 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8323 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8324 +
8325 + /* Read HCCHAR */
8326 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8327 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8328 +
8329 + /* Clear HCINT */
8330 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8331 +
8332 + /* Clear HAINT */
8333 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8334 +
8335 + /* Clear GINTSTS */
8336 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8337 +
8338 + /* Read GINTSTS */
8339 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8340 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8341 +
8342 + /*
8343 + * Receive Control In packet
8344 + */
8345 +
8346 + /* Make sure channel is disabled */
8347 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8348 + if (hcchar.b.chen) {
8349 + //fprintf(stderr, "Channel already enabled 2, HCCHAR = %08x\n", hcchar.d32);
8350 + hcchar.b.chdis = 1;
8351 + hcchar.b.chen = 1;
8352 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8353 + //sleep(1);
8354 + MDELAY(1000);
8355 +
8356 + /* Read GINTSTS */
8357 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8358 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8359 +
8360 + /* Read HAINT */
8361 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8362 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8363 +
8364 + /* Read HCINT */
8365 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8366 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8367 +
8368 + /* Read HCCHAR */
8369 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8370 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8371 +
8372 + /* Clear HCINT */
8373 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8374 +
8375 + /* Clear HAINT */
8376 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8377 +
8378 + /* Clear GINTSTS */
8379 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8380 +
8381 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8382 + //if (hcchar.b.chen) {
8383 + // fprintf(stderr, "** Channel _still_ enabled 2, HCCHAR = %08x **\n", hcchar.d32);
8384 + //}
8385 + }
8386 +
8387 + /* Set HCTSIZ */
8388 + hctsiz.d32 = 0;
8389 + hctsiz.b.xfersize = 8;
8390 + hctsiz.b.pktcnt = 1;
8391 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
8392 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8393 +
8394 + /* Set HCCHAR */
8395 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8396 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8397 + hcchar.b.epdir = 1;
8398 + hcchar.b.epnum = 0;
8399 + hcchar.b.mps = 8;
8400 + hcchar.b.chen = 1;
8401 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8402 +
8403 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8404 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
8405 +
8406 + /* Wait for receive status queue interrupt */
8407 + do {
8408 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8409 + } while (gintsts.b.rxstsqlvl == 0);
8410 +
8411 + //fprintf(stderr, "Got RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
8412 +
8413 + /* Read RXSTS */
8414 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
8415 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
8416 +
8417 + /* Clear RXSTSQLVL in GINTSTS */
8418 + gintsts.d32 = 0;
8419 + gintsts.b.rxstsqlvl = 1;
8420 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8421 +
8422 + switch (grxsts.b.pktsts) {
8423 + case DWC_GRXSTS_PKTSTS_IN:
8424 + /* Read the data into the host buffer */
8425 + if (grxsts.b.bcnt > 0) {
8426 + int i;
8427 + int word_count = (grxsts.b.bcnt + 3) / 4;
8428 +
8429 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8430 +
8431 + for (i = 0; i < word_count; i++) {
8432 + (void)dwc_read_reg32(data_fifo++);
8433 + }
8434 + }
8435 +
8436 + //fprintf(stderr, "Received %u bytes\n", (unsigned)grxsts.b.bcnt);
8437 + break;
8438 +
8439 + default:
8440 + //fprintf(stderr, "** Unexpected GRXSTS packet status 1 **\n");
8441 + break;
8442 + }
8443 +
8444 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8445 + //fprintf(stderr, "Waiting for RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
8446 +
8447 + /* Wait for receive status queue interrupt */
8448 + do {
8449 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8450 + } while (gintsts.b.rxstsqlvl == 0);
8451 +
8452 + //fprintf(stderr, "Got RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
8453 +
8454 + /* Read RXSTS */
8455 + grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
8456 + //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
8457 +
8458 + /* Clear RXSTSQLVL in GINTSTS */
8459 + gintsts.d32 = 0;
8460 + gintsts.b.rxstsqlvl = 1;
8461 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8462 +
8463 + switch (grxsts.b.pktsts) {
8464 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
8465 + break;
8466 +
8467 + default:
8468 + //fprintf(stderr, "** Unexpected GRXSTS packet status 2 **\n");
8469 + break;
8470 + }
8471 +
8472 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8473 + //fprintf(stderr, "Waiting for HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
8474 +
8475 + /* Wait for host channel interrupt */
8476 + do {
8477 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8478 + } while (gintsts.b.hcintr == 0);
8479 +
8480 + //fprintf(stderr, "Got HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
8481 +
8482 + /* Read HAINT */
8483 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8484 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8485 +
8486 + /* Read HCINT */
8487 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8488 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8489 +
8490 + /* Read HCCHAR */
8491 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8492 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8493 +
8494 + /* Clear HCINT */
8495 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8496 +
8497 + /* Clear HAINT */
8498 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8499 +
8500 + /* Clear GINTSTS */
8501 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8502 +
8503 + /* Read GINTSTS */
8504 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8505 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8506 +
8507 + // usleep(100000);
8508 + // mdelay(100);
8509 + MDELAY(1);
8510 +
8511 + /*
8512 + * Send handshake packet
8513 + */
8514 +
8515 + /* Read HAINT */
8516 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8517 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8518 +
8519 + /* Read HCINT */
8520 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8521 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8522 +
8523 + /* Read HCCHAR */
8524 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8525 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8526 +
8527 + /* Clear HCINT */
8528 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8529 +
8530 + /* Clear HAINT */
8531 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8532 +
8533 + /* Clear GINTSTS */
8534 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8535 +
8536 + /* Read GINTSTS */
8537 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8538 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8539 +
8540 + /* Make sure channel is disabled */
8541 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8542 + if (hcchar.b.chen) {
8543 + //fprintf(stderr, "Channel already enabled 3, HCCHAR = %08x\n", hcchar.d32);
8544 + hcchar.b.chdis = 1;
8545 + hcchar.b.chen = 1;
8546 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8547 + //sleep(1);
8548 + MDELAY(1000);
8549 +
8550 + /* Read GINTSTS */
8551 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8552 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8553 +
8554 + /* Read HAINT */
8555 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8556 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8557 +
8558 + /* Read HCINT */
8559 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8560 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8561 +
8562 + /* Read HCCHAR */
8563 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8564 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8565 +
8566 + /* Clear HCINT */
8567 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8568 +
8569 + /* Clear HAINT */
8570 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8571 +
8572 + /* Clear GINTSTS */
8573 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8574 +
8575 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8576 + //if (hcchar.b.chen) {
8577 + // fprintf(stderr, "** Channel _still_ enabled 3, HCCHAR = %08x **\n", hcchar.d32);
8578 + //}
8579 + }
8580 +
8581 + /* Set HCTSIZ */
8582 + hctsiz.d32 = 0;
8583 + hctsiz.b.xfersize = 0;
8584 + hctsiz.b.pktcnt = 1;
8585 + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
8586 + dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
8587 +
8588 + /* Set HCCHAR */
8589 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8590 + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
8591 + hcchar.b.epdir = 0;
8592 + hcchar.b.epnum = 0;
8593 + hcchar.b.mps = 8;
8594 + hcchar.b.chen = 1;
8595 + dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
8596 +
8597 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8598 + //fprintf(stderr, "Waiting for HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
8599 +
8600 + /* Wait for host channel interrupt */
8601 + do {
8602 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8603 + } while (gintsts.b.hcintr == 0);
8604 +
8605 + //fprintf(stderr, "Got HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
8606 +
8607 + /* Disable HCINTs */
8608 + dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
8609 +
8610 + /* Disable HAINTs */
8611 + dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
8612 +
8613 + /* Read HAINT */
8614 + haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
8615 + //fprintf(stderr, "HAINT: %08x\n", haint.d32);
8616 +
8617 + /* Read HCINT */
8618 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
8619 + //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
8620 +
8621 + /* Read HCCHAR */
8622 + hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
8623 + //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
8624 +
8625 + /* Clear HCINT */
8626 + dwc_write_reg32(&hc_regs->hcint, hcint.d32);
8627 +
8628 + /* Clear HAINT */
8629 + dwc_write_reg32(&hc_global_regs->haint, haint.d32);
8630 +
8631 + /* Clear GINTSTS */
8632 + dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
8633 +
8634 + /* Read GINTSTS */
8635 + gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
8636 + //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
8637 +}
8638 +#endif /* DWC_HS_ELECT_TST */
8639 +
8640 +/** Handles hub class-specific requests.*/
8641 +int dwc_otg_hcd_hub_control(struct usb_hcd *_hcd,
8642 + u16 _typeReq,
8643 + u16 _wValue,
8644 + u16 _wIndex,
8645 + char *_buf,
8646 + u16 _wLength)
8647 +{
8648 + int retval = 0;
8649 +
8650 + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
8651 + dwc_otg_core_if_t *core_if = hcd_to_dwc_otg_hcd (_hcd)->core_if;
8652 + struct usb_hub_descriptor *desc;
8653 + hprt0_data_t hprt0 = {.d32 = 0};
8654 +
8655 + uint32_t port_status;
8656 +
8657 + switch (_typeReq) {
8658 + case ClearHubFeature:
8659 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8660 + "ClearHubFeature 0x%x\n", _wValue);
8661 + switch (_wValue) {
8662 + case C_HUB_LOCAL_POWER:
8663 + case C_HUB_OVER_CURRENT:
8664 + /* Nothing required here */
8665 + break;
8666 + default:
8667 + retval = -EINVAL;
8668 + DWC_ERROR ("DWC OTG HCD - "
8669 + "ClearHubFeature request %xh unknown\n", _wValue);
8670 + }
8671 + break;
8672 + case ClearPortFeature:
8673 + if (!_wIndex || _wIndex > 1)
8674 + goto error;
8675 +
8676 + switch (_wValue) {
8677 + case USB_PORT_FEAT_ENABLE:
8678 + DWC_DEBUGPL (DBG_ANY, "DWC OTG HCD HUB CONTROL - "
8679 + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
8680 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8681 + hprt0.b.prtena = 1;
8682 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8683 + break;
8684 + case USB_PORT_FEAT_SUSPEND:
8685 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8686 + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
8687 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8688 + hprt0.b.prtres = 1;
8689 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8690 + /* Clear Resume bit */
8691 + mdelay (100);
8692 + hprt0.b.prtres = 0;
8693 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8694 + break;
8695 + case USB_PORT_FEAT_POWER:
8696 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8697 + "ClearPortFeature USB_PORT_FEAT_POWER\n");
8698 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8699 + hprt0.b.prtpwr = 0;
8700 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8701 + break;
8702 + case USB_PORT_FEAT_INDICATOR:
8703 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8704 + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
8705 + /* Port inidicator not supported */
8706 + break;
8707 + case USB_PORT_FEAT_C_CONNECTION:
8708 + /* Clears drivers internal connect status change
8709 + * flag */
8710 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8711 + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
8712 + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
8713 + break;
8714 + case USB_PORT_FEAT_C_RESET:
8715 + /* Clears the driver's internal Port Reset Change
8716 + * flag */
8717 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8718 + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
8719 + dwc_otg_hcd->flags.b.port_reset_change = 0;
8720 + break;
8721 + case USB_PORT_FEAT_C_ENABLE:
8722 + /* Clears the driver's internal Port
8723 + * Enable/Disable Change flag */
8724 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8725 + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
8726 + dwc_otg_hcd->flags.b.port_enable_change = 0;
8727 + break;
8728 + case USB_PORT_FEAT_C_SUSPEND:
8729 + /* Clears the driver's internal Port Suspend
8730 + * Change flag, which is set when resume signaling on
8731 + * the host port is complete */
8732 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8733 + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
8734 + dwc_otg_hcd->flags.b.port_suspend_change = 0;
8735 + break;
8736 + case USB_PORT_FEAT_C_OVER_CURRENT:
8737 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8738 + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
8739 + dwc_otg_hcd->flags.b.port_over_current_change = 0;
8740 + break;
8741 + default:
8742 + retval = -EINVAL;
8743 + DWC_ERROR ("DWC OTG HCD - "
8744 + "ClearPortFeature request %xh "
8745 + "unknown or unsupported\n", _wValue);
8746 + }
8747 + break;
8748 + case GetHubDescriptor:
8749 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8750 + "GetHubDescriptor\n");
8751 + desc = (struct usb_hub_descriptor *)_buf;
8752 + desc->bDescLength = 9;
8753 + desc->bDescriptorType = 0x29;
8754 + desc->bNbrPorts = 1;
8755 + desc->wHubCharacteristics = 0x08;
8756 + desc->bPwrOn2PwrGood = 1;
8757 + desc->bHubContrCurrent = 0;
8758 + desc->bitmap[0] = 0;
8759 + desc->bitmap[1] = 0xff;
8760 + break;
8761 + case GetHubStatus:
8762 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8763 + "GetHubStatus\n");
8764 + memset (_buf, 0, 4);
8765 + break;
8766 + case GetPortStatus:
8767 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8768 + "GetPortStatus\n");
8769 +
8770 + if (!_wIndex || _wIndex > 1)
8771 + goto error;
8772 +
8773 + port_status = 0;
8774 +
8775 + if (dwc_otg_hcd->flags.b.port_connect_status_change)
8776 + port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
8777 +
8778 + if (dwc_otg_hcd->flags.b.port_enable_change)
8779 + port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
8780 +
8781 + if (dwc_otg_hcd->flags.b.port_suspend_change)
8782 + port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
8783 +
8784 + if (dwc_otg_hcd->flags.b.port_reset_change)
8785 + port_status |= (1 << USB_PORT_FEAT_C_RESET);
8786 +
8787 + if (dwc_otg_hcd->flags.b.port_over_current_change) {
8788 + DWC_ERROR("Device Not Supported\n");
8789 + port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
8790 + }
8791 +
8792 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
8793 + printk("DISCONNECTED PORT\n");
8794 + /*
8795 + * The port is disconnected, which means the core is
8796 + * either in device mode or it soon will be. Just
8797 + * return 0's for the remainder of the port status
8798 + * since the port register can't be read if the core
8799 + * is in device mode.
8800 + */
8801 +#if 1 // winder.
8802 + *((u32 *) _buf) = cpu_to_le32(port_status);
8803 +#else
8804 + *((__le32 *) _buf) = cpu_to_le32(port_status);
8805 +#endif
8806 + break;
8807 + }
8808 +
8809 + hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
8810 + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
8811 +
8812 + if (hprt0.b.prtconnsts)
8813 + port_status |= (1 << USB_PORT_FEAT_CONNECTION);
8814 +
8815 + if (hprt0.b.prtena)
8816 + port_status |= (1 << USB_PORT_FEAT_ENABLE);
8817 +
8818 + if (hprt0.b.prtsusp)
8819 + port_status |= (1 << USB_PORT_FEAT_SUSPEND);
8820 +
8821 + if (hprt0.b.prtovrcurract)
8822 + port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
8823 +
8824 + if (hprt0.b.prtrst)
8825 + port_status |= (1 << USB_PORT_FEAT_RESET);
8826 +
8827 + if (hprt0.b.prtpwr)
8828 + port_status |= (1 << USB_PORT_FEAT_POWER);
8829 +
8830 + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
8831 + port_status |= USB_PORT_STAT_HIGH_SPEED;
8832 +
8833 + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
8834 + port_status |= (1 << USB_PORT_FEAT_LOWSPEED);
8835 +
8836 + if (hprt0.b.prttstctl)
8837 + port_status |= (1 << USB_PORT_FEAT_TEST);
8838 +
8839 + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
8840 +#if 1 // winder.
8841 + *((u32 *) _buf) = cpu_to_le32(port_status);
8842 +#else
8843 + *((__le32 *) _buf) = cpu_to_le32(port_status);
8844 +#endif
8845 +
8846 + break;
8847 + case SetHubFeature:
8848 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8849 + "SetHubFeature\n");
8850 + /* No HUB features supported */
8851 + break;
8852 + case SetPortFeature:
8853 + if (_wValue != USB_PORT_FEAT_TEST && (!_wIndex || _wIndex > 1))
8854 + goto error;
8855 +
8856 + if (!dwc_otg_hcd->flags.b.port_connect_status) {
8857 + /*
8858 + * The port is disconnected, which means the core is
8859 + * either in device mode or it soon will be. Just
8860 + * return without doing anything since the port
8861 + * register can't be written if the core is in device
8862 + * mode.
8863 + */
8864 + break;
8865 + }
8866 +
8867 + switch (_wValue) {
8868 + case USB_PORT_FEAT_SUSPEND:
8869 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8870 + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
8871 + if (_hcd->self.otg_port == _wIndex
8872 + && _hcd->self.b_hnp_enable) {
8873 + gotgctl_data_t gotgctl = {.d32=0};
8874 + gotgctl.b.hstsethnpen = 1;
8875 + dwc_modify_reg32(&core_if->core_global_regs->
8876 + gotgctl, 0, gotgctl.d32);
8877 + core_if->op_state = A_SUSPEND;
8878 + }
8879 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8880 + hprt0.b.prtsusp = 1;
8881 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8882 + //DWC_PRINT( "SUSPEND: HPRT0=%0x\n", hprt0.d32);
8883 + /* Suspend the Phy Clock */
8884 + {
8885 + pcgcctl_data_t pcgcctl = {.d32=0};
8886 + pcgcctl.b.stoppclk = 1;
8887 + dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
8888 + }
8889 +
8890 + /* For HNP the bus must be suspended for at least 200ms.*/
8891 + if (_hcd->self.b_hnp_enable) {
8892 + mdelay(200);
8893 + //DWC_PRINT( "SUSPEND: wait complete! (%d)\n", _hcd->state);
8894 + }
8895 + break;
8896 + case USB_PORT_FEAT_POWER:
8897 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8898 + "SetPortFeature - USB_PORT_FEAT_POWER\n");
8899 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8900 + hprt0.b.prtpwr = 1;
8901 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8902 + break;
8903 + case USB_PORT_FEAT_RESET:
8904 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8905 + "SetPortFeature - USB_PORT_FEAT_RESET\n");
8906 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8907 + /* TODO: Is this for OTG protocol??
8908 + * We shoudl remove OTG totally for Danube system.
8909 + * But, in the future, maybe we need this.
8910 + */
8911 +#if 1 // winder
8912 + hprt0.b.prtrst = 1;
8913 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8914 +#else
8915 + /* When B-Host the Port reset bit is set in
8916 + * the Start HCD Callback function, so that
8917 + * the reset is started within 1ms of the HNP
8918 + * success interrupt. */
8919 + if (!_hcd->self.is_b_host) {
8920 + hprt0.b.prtrst = 1;
8921 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8922 + }
8923 +#endif
8924 + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
8925 + MDELAY (60);
8926 + hprt0.b.prtrst = 0;
8927 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8928 + break;
8929 +
8930 +#ifdef DWC_HS_ELECT_TST
8931 + case USB_PORT_FEAT_TEST:
8932 + {
8933 + uint32_t t;
8934 + gintmsk_data_t gintmsk;
8935 +
8936 + t = (_wIndex >> 8); /* MSB wIndex USB */
8937 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
8938 + "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
8939 + printk("USB_PORT_FEAT_TEST %d\n", t);
8940 + if (t < 6) {
8941 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8942 + hprt0.b.prttstctl = t;
8943 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8944 + } else {
8945 + /* Setup global vars with reg addresses (quick and
8946 + * dirty hack, should be cleaned up)
8947 + */
8948 + global_regs = core_if->core_global_regs;
8949 + hc_global_regs = core_if->host_if->host_global_regs;
8950 + hc_regs = (dwc_otg_hc_regs_t *)((char *)global_regs + 0x500);
8951 + data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
8952 +
8953 + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
8954 + /* Save current interrupt mask */
8955 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
8956 +
8957 + /* Disable all interrupts while we muck with
8958 + * the hardware directly
8959 + */
8960 + dwc_write_reg32(&global_regs->gintmsk, 0);
8961 +
8962 + /* 15 second delay per the test spec */
8963 + mdelay(15000);
8964 +
8965 + /* Drive suspend on the root port */
8966 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8967 + hprt0.b.prtsusp = 1;
8968 + hprt0.b.prtres = 0;
8969 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8970 +
8971 + /* 15 second delay per the test spec */
8972 + mdelay(15000);
8973 +
8974 + /* Drive resume on the root port */
8975 + hprt0.d32 = dwc_otg_read_hprt0 (core_if);
8976 + hprt0.b.prtsusp = 0;
8977 + hprt0.b.prtres = 1;
8978 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8979 + mdelay(100);
8980 +
8981 + /* Clear the resume bit */
8982 + hprt0.b.prtres = 0;
8983 + dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
8984 +
8985 + /* Restore interrupts */
8986 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
8987 + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
8988 + /* Save current interrupt mask */
8989 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
8990 +
8991 + /* Disable all interrupts while we muck with
8992 + * the hardware directly
8993 + */
8994 + dwc_write_reg32(&global_regs->gintmsk, 0);
8995 +
8996 + /* 15 second delay per the test spec */
8997 + mdelay(15000);
8998 +
8999 + /* Send the Setup packet */
9000 + do_setup();
9001 +
9002 + /* 15 second delay so nothing else happens for awhile */
9003 + mdelay(15000);
9004 +
9005 + /* Restore interrupts */
9006 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
9007 + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
9008 + /* Save current interrupt mask */
9009 + gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
9010 +
9011 + /* Disable all interrupts while we muck with
9012 + * the hardware directly
9013 + */
9014 + dwc_write_reg32(&global_regs->gintmsk, 0);
9015 +
9016 + /* Send the Setup packet */
9017 + do_setup();
9018 +
9019 + /* 15 second delay so nothing else happens for awhile */
9020 + mdelay(15000);
9021 +
9022 + /* Send the In and Ack packets */
9023 + do_in_ack();
9024 +
9025 + /* 15 second delay so nothing else happens for awhile */
9026 + mdelay(15000);
9027 +
9028 + /* Restore interrupts */
9029 + dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
9030 + }
9031 + }
9032 + break;
9033 + }
9034 +#endif /* DWC_HS_ELECT_TST */
9035 +
9036 + case USB_PORT_FEAT_INDICATOR:
9037 + DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
9038 + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
9039 + /* Not supported */
9040 + break;
9041 + default:
9042 + retval = -EINVAL;
9043 + DWC_ERROR ("DWC OTG HCD - "
9044 + "SetPortFeature request %xh "
9045 + "unknown or unsupported\n", _wValue);
9046 + break;
9047 + }
9048 + break;
9049 + default:
9050 +error:
9051 + retval = -EINVAL;
9052 + DWC_WARN ("DWC OTG HCD - "
9053 + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
9054 + _typeReq, _wIndex, _wValue);
9055 + break;
9056 + }
9057 +
9058 + return retval;
9059 +}
9060 +
9061 +
9062 +/**
9063 + * Assigns transactions from a QTD to a free host channel and initializes the
9064 + * host channel to perform the transactions. The host channel is removed from
9065 + * the free list.
9066 + *
9067 + * @param _hcd The HCD state structure.
9068 + * @param _qh Transactions from the first QTD for this QH are selected and
9069 + * assigned to a free host channel.
9070 + */
9071 +static void assign_and_init_hc(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
9072 +{
9073 + dwc_hc_t *hc;
9074 + dwc_otg_qtd_t *qtd;
9075 + struct urb *urb;
9076 +
9077 + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p)\n", __func__, _hcd, _qh);
9078 +
9079 + hc = list_entry(_hcd->free_hc_list.next, dwc_hc_t, hc_list_entry);
9080 +
9081 + /* Remove the host channel from the free list. */
9082 + list_del_init(&hc->hc_list_entry);
9083 +
9084 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
9085 + urb = qtd->urb;
9086 + _qh->channel = hc;
9087 + _qh->qtd_in_process = qtd;
9088 +
9089 + /*
9090 + * Use usb_pipedevice to determine device address. This address is
9091 + * 0 before the SET_ADDRESS command and the correct address afterward.
9092 + */
9093 + hc->dev_addr = usb_pipedevice(urb->pipe);
9094 + hc->ep_num = usb_pipeendpoint(urb->pipe);
9095 +
9096 + if (urb->dev->speed == USB_SPEED_LOW) {
9097 + hc->speed = DWC_OTG_EP_SPEED_LOW;
9098 + } else if (urb->dev->speed == USB_SPEED_FULL) {
9099 + hc->speed = DWC_OTG_EP_SPEED_FULL;
9100 + } else {
9101 + hc->speed = DWC_OTG_EP_SPEED_HIGH;
9102 + }
9103 + hc->max_packet = dwc_max_packet(_qh->maxp);
9104 +
9105 + hc->xfer_started = 0;
9106 + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
9107 + hc->error_state = (qtd->error_count > 0);
9108 + hc->halt_on_queue = 0;
9109 + hc->halt_pending = 0;
9110 + hc->requests = 0;
9111 +
9112 + /*
9113 + * The following values may be modified in the transfer type section
9114 + * below. The xfer_len value may be reduced when the transfer is
9115 + * started to accommodate the max widths of the XferSize and PktCnt
9116 + * fields in the HCTSIZn register.
9117 + */
9118 + hc->do_ping = _qh->ping_state;
9119 + hc->ep_is_in = (usb_pipein(urb->pipe) != 0);
9120 + hc->data_pid_start = _qh->data_toggle;
9121 + hc->multi_count = 1;
9122 +
9123 + if (_hcd->core_if->dma_enable) {
9124 + hc->xfer_buff = (uint8_t *)(u32)urb->transfer_dma + urb->actual_length;
9125 + } else {
9126 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer + urb->actual_length;
9127 + }
9128 + hc->xfer_len = urb->transfer_buffer_length - urb->actual_length;
9129 + hc->xfer_count = 0;
9130 +
9131 + /*
9132 + * Set the split attributes
9133 + */
9134 + hc->do_split = 0;
9135 + if (_qh->do_split) {
9136 + hc->do_split = 1;
9137 + hc->xact_pos = qtd->isoc_split_pos;
9138 + hc->complete_split = qtd->complete_split;
9139 + hc->hub_addr = urb->dev->tt->hub->devnum;
9140 + hc->port_addr = urb->dev->ttport;
9141 + }
9142 +
9143 + switch (usb_pipetype(urb->pipe)) {
9144 + case PIPE_CONTROL:
9145 + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
9146 + switch (qtd->control_phase) {
9147 + case DWC_OTG_CONTROL_SETUP:
9148 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
9149 + hc->do_ping = 0;
9150 + hc->ep_is_in = 0;
9151 + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
9152 + if (_hcd->core_if->dma_enable) {
9153 + hc->xfer_buff = (uint8_t *)(u32)urb->setup_dma;
9154 + } else {
9155 + hc->xfer_buff = (uint8_t *)urb->setup_packet;
9156 + }
9157 + hc->xfer_len = 8;
9158 + break;
9159 + case DWC_OTG_CONTROL_DATA:
9160 + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
9161 + hc->data_pid_start = qtd->data_toggle;
9162 + break;
9163 + case DWC_OTG_CONTROL_STATUS:
9164 + /*
9165 + * Direction is opposite of data direction or IN if no
9166 + * data.
9167 + */
9168 + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
9169 + if (urb->transfer_buffer_length == 0) {
9170 + hc->ep_is_in = 1;
9171 + } else {
9172 + hc->ep_is_in = (usb_pipein(urb->pipe) != USB_DIR_IN);
9173 + }
9174 + if (hc->ep_is_in) {
9175 + hc->do_ping = 0;
9176 + }
9177 + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
9178 + hc->xfer_len = 0;
9179 + if (_hcd->core_if->dma_enable) {
9180 + hc->xfer_buff = (uint8_t *)_hcd->status_buf_dma;
9181 + } else {
9182 + hc->xfer_buff = (uint8_t *)_hcd->status_buf;
9183 + }
9184 + break;
9185 + }
9186 + break;
9187 + case PIPE_BULK:
9188 + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
9189 + break;
9190 + case PIPE_INTERRUPT:
9191 + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
9192 + break;
9193 + case PIPE_ISOCHRONOUS:
9194 + {
9195 + struct usb_iso_packet_descriptor *frame_desc;
9196 + frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
9197 + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
9198 + if (_hcd->core_if->dma_enable) {
9199 + hc->xfer_buff = (uint8_t *)(u32)urb->transfer_dma;
9200 + } else {
9201 + hc->xfer_buff = (uint8_t *)urb->transfer_buffer;
9202 + }
9203 + hc->xfer_buff += frame_desc->offset + qtd->isoc_split_offset;
9204 + hc->xfer_len = frame_desc->length - qtd->isoc_split_offset;
9205 +
9206 + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
9207 + if (hc->xfer_len <= 188) {
9208 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
9209 + }
9210 + else {
9211 + hc->xact_pos = DWC_HCSPLIT_XACTPOS_BEGIN;
9212 + }
9213 + }
9214 + }
9215 + break;
9216 + }
9217 +
9218 + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
9219 + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
9220 + /*
9221 + * This value may be modified when the transfer is started to
9222 + * reflect the actual transfer length.
9223 + */
9224 + hc->multi_count = dwc_hb_mult(_qh->maxp);
9225 + }
9226 +
9227 + dwc_otg_hc_init(_hcd->core_if, hc);
9228 + hc->qh = _qh;
9229 +}
9230 +#define DEBUG_HOST_CHANNELS
9231 +#ifdef DEBUG_HOST_CHANNELS
9232 +static int last_sel_trans_num_per_scheduled = 0;
9233 +module_param(last_sel_trans_num_per_scheduled, int, 0444);
9234 +
9235 +static int last_sel_trans_num_nonper_scheduled = 0;
9236 +module_param(last_sel_trans_num_nonper_scheduled, int, 0444);
9237 +
9238 +static int last_sel_trans_num_avail_hc_at_start = 0;
9239 +module_param(last_sel_trans_num_avail_hc_at_start, int, 0444);
9240 +
9241 +static int last_sel_trans_num_avail_hc_at_end = 0;
9242 +module_param(last_sel_trans_num_avail_hc_at_end, int, 0444);
9243 +#endif /* DEBUG_HOST_CHANNELS */
9244 +
9245 +/**
9246 + * This function selects transactions from the HCD transfer schedule and
9247 + * assigns them to available host channels. It is called from HCD interrupt
9248 + * handler functions.
9249 + *
9250 + * @param _hcd The HCD state structure.
9251 + *
9252 + * @return The types of new transactions that were assigned to host channels.
9253 + */
9254 +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd)
9255 +{
9256 + struct list_head *qh_ptr;
9257 + dwc_otg_qh_t *qh;
9258 + int num_channels;
9259 + unsigned long flags;
9260 + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
9261 +
9262 +#ifdef DEBUG_SOF
9263 + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
9264 +#endif /* */
9265 +
9266 +#ifdef DEBUG_HOST_CHANNELS
9267 + last_sel_trans_num_per_scheduled = 0;
9268 + last_sel_trans_num_nonper_scheduled = 0;
9269 + last_sel_trans_num_avail_hc_at_start = _hcd->available_host_channels;
9270 +#endif /* DEBUG_HOST_CHANNELS */
9271 +
9272 + /* Process entries in the periodic ready list. */
9273 + num_channels = _hcd->core_if->core_params->host_channels;
9274 + qh_ptr = _hcd->periodic_sched_ready.next;
9275 + while (qh_ptr != &_hcd->periodic_sched_ready
9276 + && !list_empty(&_hcd->free_hc_list)) {
9277 +
9278 + // Make sure we leave one channel for non periodic transactions.
9279 + local_irq_save(flags);
9280 + if (_hcd->available_host_channels <= 1) {
9281 + local_irq_restore(flags);
9282 + break;
9283 + }
9284 + _hcd->available_host_channels--;
9285 + local_irq_restore(flags);
9286 +#ifdef DEBUG_HOST_CHANNELS
9287 + last_sel_trans_num_per_scheduled++;
9288 +#endif /* DEBUG_HOST_CHANNELS */
9289 +
9290 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9291 + assign_and_init_hc(_hcd, qh);
9292 +
9293 + /*
9294 + * Move the QH from the periodic ready schedule to the
9295 + * periodic assigned schedule.
9296 + */
9297 + qh_ptr = qh_ptr->next;
9298 + local_irq_save(flags);
9299 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_assigned);
9300 + local_irq_restore(flags);
9301 + ret_val = DWC_OTG_TRANSACTION_PERIODIC;
9302 + }
9303 +
9304 + /*
9305 + * Process entries in the deferred portion of the non-periodic list.
9306 + * A NAK put them here and, at the right time, they need to be
9307 + * placed on the sched_inactive list.
9308 + */
9309 + qh_ptr = _hcd->non_periodic_sched_deferred.next;
9310 + while (qh_ptr != &_hcd->non_periodic_sched_deferred) {
9311 + uint16_t frame_number =
9312 + dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
9313 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9314 + qh_ptr = qh_ptr->next;
9315 +
9316 + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
9317 + // NAK did this
9318 + /*
9319 + * Move the QH from the non periodic deferred schedule to
9320 + * the non periodic inactive schedule.
9321 + */
9322 + local_irq_save(flags);
9323 + list_move(&qh->qh_list_entry,
9324 + &_hcd->non_periodic_sched_inactive);
9325 + local_irq_restore(flags);
9326 + }
9327 + }
9328 +
9329 + /*
9330 + * Process entries in the inactive portion of the non-periodic
9331 + * schedule. Some free host channels may not be used if they are
9332 + * reserved for periodic transfers.
9333 + */
9334 + qh_ptr = _hcd->non_periodic_sched_inactive.next;
9335 + num_channels = _hcd->core_if->core_params->host_channels;
9336 + while (qh_ptr != &_hcd->non_periodic_sched_inactive
9337 + && !list_empty(&_hcd->free_hc_list)) {
9338 +
9339 + local_irq_save(flags);
9340 + if (_hcd->available_host_channels < 1) {
9341 + local_irq_restore(flags);
9342 + break;
9343 + }
9344 + _hcd->available_host_channels--;
9345 + local_irq_restore(flags);
9346 +#ifdef DEBUG_HOST_CHANNELS
9347 + last_sel_trans_num_nonper_scheduled++;
9348 +#endif /* DEBUG_HOST_CHANNELS */
9349 +
9350 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9351 + assign_and_init_hc(_hcd, qh);
9352 +
9353 + /*
9354 + * Move the QH from the non-periodic inactive schedule to the
9355 + * non-periodic active schedule.
9356 + */
9357 + qh_ptr = qh_ptr->next;
9358 + local_irq_save(flags);
9359 + list_move(&qh->qh_list_entry, &_hcd->non_periodic_sched_active);
9360 + local_irq_restore(flags);
9361 +
9362 + if (ret_val == DWC_OTG_TRANSACTION_NONE) {
9363 + ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
9364 + } else {
9365 + ret_val = DWC_OTG_TRANSACTION_ALL;
9366 + }
9367 +
9368 + }
9369 +#ifdef DEBUG_HOST_CHANNELS
9370 + last_sel_trans_num_avail_hc_at_end = _hcd->available_host_channels;
9371 +#endif /* DEBUG_HOST_CHANNELS */
9372 +
9373 + return ret_val;
9374 +}
9375 +
9376 +/**
9377 + * Attempts to queue a single transaction request for a host channel
9378 + * associated with either a periodic or non-periodic transfer. This function
9379 + * assumes that there is space available in the appropriate request queue. For
9380 + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
9381 + * is available in the appropriate Tx FIFO.
9382 + *
9383 + * @param _hcd The HCD state structure.
9384 + * @param _hc Host channel descriptor associated with either a periodic or
9385 + * non-periodic transfer.
9386 + * @param _fifo_dwords_avail Number of DWORDs available in the periodic Tx
9387 + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
9388 + * transfers.
9389 + *
9390 + * @return 1 if a request is queued and more requests may be needed to
9391 + * complete the transfer, 0 if no more requests are required for this
9392 + * transfer, -1 if there is insufficient space in the Tx FIFO.
9393 + */
9394 +static int queue_transaction(dwc_otg_hcd_t *_hcd,
9395 + dwc_hc_t *_hc,
9396 + uint16_t _fifo_dwords_avail)
9397 +{
9398 + int retval;
9399 +
9400 + if (_hcd->core_if->dma_enable) {
9401 + if (!_hc->xfer_started) {
9402 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9403 + _hc->qh->ping_state = 0;
9404 + }
9405 + retval = 0;
9406 + } else if (_hc->halt_pending) {
9407 + /* Don't queue a request if the channel has been halted. */
9408 + retval = 0;
9409 + } else if (_hc->halt_on_queue) {
9410 + dwc_otg_hc_halt(_hcd->core_if, _hc, _hc->halt_status);
9411 + retval = 0;
9412 + } else if (_hc->do_ping) {
9413 + if (!_hc->xfer_started) {
9414 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9415 + }
9416 + retval = 0;
9417 + } else if (!_hc->ep_is_in ||
9418 + _hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
9419 + if ((_fifo_dwords_avail * 4) >= _hc->max_packet) {
9420 + if (!_hc->xfer_started) {
9421 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9422 + retval = 1;
9423 + } else {
9424 + retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
9425 + }
9426 + } else {
9427 + retval = -1;
9428 + }
9429 + } else {
9430 + if (!_hc->xfer_started) {
9431 + dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
9432 + retval = 1;
9433 + } else {
9434 + retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
9435 + }
9436 + }
9437 +
9438 + return retval;
9439 +}
9440 +
9441 +/**
9442 + * Processes active non-periodic channels and queues transactions for these
9443 + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
9444 + * FIFO Empty interrupt is enabled if there are more transactions to queue as
9445 + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
9446 + * FIFO Empty interrupt is disabled.
9447 + */
9448 +static void process_non_periodic_channels(dwc_otg_hcd_t *_hcd)
9449 +{
9450 + gnptxsts_data_t tx_status;
9451 + struct list_head *orig_qh_ptr;
9452 + dwc_otg_qh_t *qh;
9453 + int status;
9454 + int no_queue_space = 0;
9455 + int no_fifo_space = 0;
9456 + int more_to_do = 0;
9457 +
9458 + dwc_otg_core_global_regs_t *global_regs = _hcd->core_if->core_global_regs;
9459 +
9460 + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
9461 +#ifdef DEBUG
9462 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9463 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (before queue): %d\n",
9464 + tx_status.b.nptxqspcavail);
9465 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
9466 + tx_status.b.nptxfspcavail);
9467 +#endif
9468 + /*
9469 + * Keep track of the starting point. Skip over the start-of-list
9470 + * entry.
9471 + */
9472 + if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
9473 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9474 + }
9475 + orig_qh_ptr = _hcd->non_periodic_qh_ptr;
9476 +
9477 + /*
9478 + * Process once through the active list or until no more space is
9479 + * available in the request queue or the Tx FIFO.
9480 + */
9481 + do {
9482 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9483 + if (!_hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
9484 + no_queue_space = 1;
9485 + break;
9486 + }
9487 +
9488 + qh = list_entry(_hcd->non_periodic_qh_ptr, dwc_otg_qh_t, qh_list_entry);
9489 + status = queue_transaction(_hcd, qh->channel, tx_status.b.nptxfspcavail);
9490 +
9491 + if (status > 0) {
9492 + more_to_do = 1;
9493 + } else if (status < 0) {
9494 + no_fifo_space = 1;
9495 + break;
9496 + }
9497 +
9498 + /* Advance to next QH, skipping start-of-list entry. */
9499 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9500 + if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
9501 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
9502 + }
9503 +
9504 + } while (_hcd->non_periodic_qh_ptr != orig_qh_ptr);
9505 +
9506 + if (!_hcd->core_if->dma_enable) {
9507 + gintmsk_data_t intr_mask = {.d32 = 0};
9508 + intr_mask.b.nptxfempty = 1;
9509 +
9510 +#ifdef DEBUG
9511 + tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
9512 + DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (after queue): %d\n",
9513 + tx_status.b.nptxqspcavail);
9514 + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (after queue): %d\n",
9515 + tx_status.b.nptxfspcavail);
9516 +#endif
9517 + if (more_to_do || no_queue_space || no_fifo_space) {
9518 + /*
9519 + * May need to queue more transactions as the request
9520 + * queue or Tx FIFO empties. Enable the non-periodic
9521 + * Tx FIFO empty interrupt. (Always use the half-empty
9522 + * level to ensure that new requests are loaded as
9523 + * soon as possible.)
9524 + */
9525 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
9526 + } else {
9527 + /*
9528 + * Disable the Tx FIFO empty interrupt since there are
9529 + * no more transactions that need to be queued right
9530 + * now. This function is called from interrupt
9531 + * handlers to queue more transactions as transfer
9532 + * states change.
9533 + */
9534 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
9535 + }
9536 + }
9537 +}
9538 +
9539 +/**
9540 + * Processes periodic channels for the next frame and queues transactions for
9541 + * these channels to the DWC_otg controller. After queueing transactions, the
9542 + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
9543 + * to queue as Periodic Tx FIFO or request queue space becomes available.
9544 + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
9545 + */
9546 +static void process_periodic_channels(dwc_otg_hcd_t *_hcd)
9547 +{
9548 + hptxsts_data_t tx_status;
9549 + struct list_head *qh_ptr;
9550 + dwc_otg_qh_t *qh;
9551 + int status;
9552 + int no_queue_space = 0;
9553 + int no_fifo_space = 0;
9554 +
9555 + dwc_otg_host_global_regs_t *host_regs;
9556 + host_regs = _hcd->core_if->host_if->host_global_regs;
9557 +
9558 + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
9559 +#ifdef DEBUG
9560 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9561 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (before queue): %d\n",
9562 + tx_status.b.ptxqspcavail);
9563 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
9564 + tx_status.b.ptxfspcavail);
9565 +#endif
9566 +
9567 + qh_ptr = _hcd->periodic_sched_assigned.next;
9568 + while (qh_ptr != &_hcd->periodic_sched_assigned) {
9569 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9570 + if (tx_status.b.ptxqspcavail == 0) {
9571 + no_queue_space = 1;
9572 + break;
9573 + }
9574 +
9575 + qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
9576 +
9577 + /*
9578 + * Set a flag if we're queuing high-bandwidth in slave mode.
9579 + * The flag prevents any halts to get into the request queue in
9580 + * the middle of multiple high-bandwidth packets getting queued.
9581 + */
9582 + if ((!_hcd->core_if->dma_enable) &&
9583 + (qh->channel->multi_count > 1))
9584 + {
9585 + _hcd->core_if->queuing_high_bandwidth = 1;
9586 + }
9587 +
9588 + status = queue_transaction(_hcd, qh->channel, tx_status.b.ptxfspcavail);
9589 + if (status < 0) {
9590 + no_fifo_space = 1;
9591 + break;
9592 + }
9593 +
9594 + /*
9595 + * In Slave mode, stay on the current transfer until there is
9596 + * nothing more to do or the high-bandwidth request count is
9597 + * reached. In DMA mode, only need to queue one request. The
9598 + * controller automatically handles multiple packets for
9599 + * high-bandwidth transfers.
9600 + */
9601 + if (_hcd->core_if->dma_enable ||
9602 + (status == 0 ||
9603 + qh->channel->requests == qh->channel->multi_count)) {
9604 + qh_ptr = qh_ptr->next;
9605 + /*
9606 + * Move the QH from the periodic assigned schedule to
9607 + * the periodic queued schedule.
9608 + */
9609 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_queued);
9610 +
9611 + /* done queuing high bandwidth */
9612 + _hcd->core_if->queuing_high_bandwidth = 0;
9613 + }
9614 + }
9615 +
9616 + if (!_hcd->core_if->dma_enable) {
9617 + dwc_otg_core_global_regs_t *global_regs;
9618 + gintmsk_data_t intr_mask = {.d32 = 0};
9619 +
9620 + global_regs = _hcd->core_if->core_global_regs;
9621 + intr_mask.b.ptxfempty = 1;
9622 +#ifdef DEBUG
9623 + tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
9624 + DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (after queue): %d\n",
9625 + tx_status.b.ptxqspcavail);
9626 + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (after queue): %d\n",
9627 + tx_status.b.ptxfspcavail);
9628 +#endif
9629 + if (!(list_empty(&_hcd->periodic_sched_assigned)) ||
9630 + no_queue_space || no_fifo_space) {
9631 + /*
9632 + * May need to queue more transactions as the request
9633 + * queue or Tx FIFO empties. Enable the periodic Tx
9634 + * FIFO empty interrupt. (Always use the half-empty
9635 + * level to ensure that new requests are loaded as
9636 + * soon as possible.)
9637 + */
9638 + dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
9639 + } else {
9640 + /*
9641 + * Disable the Tx FIFO empty interrupt since there are
9642 + * no more transactions that need to be queued right
9643 + * now. This function is called from interrupt
9644 + * handlers to queue more transactions as transfer
9645 + * states change.
9646 + */
9647 + dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
9648 + }
9649 + }
9650 +}
9651 +
9652 +/**
9653 + * This function processes the currently active host channels and queues
9654 + * transactions for these channels to the DWC_otg controller. It is called
9655 + * from HCD interrupt handler functions.
9656 + *
9657 + * @param _hcd The HCD state structure.
9658 + * @param _tr_type The type(s) of transactions to queue (non-periodic,
9659 + * periodic, or both).
9660 + */
9661 +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
9662 + dwc_otg_transaction_type_e _tr_type)
9663 +{
9664 +#ifdef DEBUG_SOF
9665 + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
9666 +#endif
9667 + /* Process host channels associated with periodic transfers. */
9668 + if ((_tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
9669 + _tr_type == DWC_OTG_TRANSACTION_ALL) &&
9670 + !list_empty(&_hcd->periodic_sched_assigned)) {
9671 +
9672 + process_periodic_channels(_hcd);
9673 + }
9674 +
9675 + /* Process host channels associated with non-periodic transfers. */
9676 + if ((_tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
9677 + _tr_type == DWC_OTG_TRANSACTION_ALL)) {
9678 + if (!list_empty(&_hcd->non_periodic_sched_active)) {
9679 + process_non_periodic_channels(_hcd);
9680 + } else {
9681 + /*
9682 + * Ensure NP Tx FIFO empty interrupt is disabled when
9683 + * there are no non-periodic transfers to process.
9684 + */
9685 + gintmsk_data_t gintmsk = {.d32 = 0};
9686 + gintmsk.b.nptxfempty = 1;
9687 + dwc_modify_reg32(&_hcd->core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
9688 + }
9689 + }
9690 +}
9691 +
9692 +/**
9693 + * Sets the final status of an URB and returns it to the device driver. Any
9694 + * required cleanup of the URB is performed.
9695 + */
9696 +void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t * _hcd, struct urb *_urb,
9697 + int _status)
9698 + __releases(_hcd->lock)
9699 +__acquires(_hcd->lock)
9700 +{
9701 +#ifdef DEBUG
9702 + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
9703 + DWC_PRINT("%s: urb %p, device %d, ep %d %s, status=%d\n",
9704 + __func__, _urb, usb_pipedevice(_urb->pipe),
9705 + usb_pipeendpoint(_urb->pipe),
9706 + usb_pipein(_urb->pipe) ? "IN" : "OUT", _status);
9707 + if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
9708 + int i;
9709 + for (i = 0; i < _urb->number_of_packets; i++) {
9710 + DWC_PRINT(" ISO Desc %d status: %d\n",
9711 + i, _urb->iso_frame_desc[i].status);
9712 + }
9713 + }
9714 + }
9715 +#endif
9716 +
9717 + _urb->status = _status;
9718 + _urb->hcpriv = NULL;
9719 + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(_hcd), _urb);
9720 + spin_unlock(&_hcd->lock);
9721 + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(_hcd), _urb, _status);
9722 + spin_lock(&_hcd->lock);
9723 +}
9724 +
9725 +/*
9726 + * Returns the Queue Head for an URB.
9727 + */
9728 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *_urb)
9729 +{
9730 + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(_urb);
9731 + return (dwc_otg_qh_t *)ep->hcpriv;
9732 +}
9733 +
9734 +#ifdef DEBUG
9735 +void dwc_print_setup_data (uint8_t *setup)
9736 +{
9737 + int i;
9738 + if (CHK_DEBUG_LEVEL(DBG_HCD)){
9739 + DWC_PRINT("Setup Data = MSB ");
9740 + for (i=7; i>=0; i--) DWC_PRINT ("%02x ", setup[i]);
9741 + DWC_PRINT("\n");
9742 + DWC_PRINT(" bmRequestType Tranfer = %s\n", (setup[0]&0x80) ? "Device-to-Host" : "Host-to-Device");
9743 + DWC_PRINT(" bmRequestType Type = ");
9744 + switch ((setup[0]&0x60) >> 5) {
9745 + case 0: DWC_PRINT("Standard\n"); break;
9746 + case 1: DWC_PRINT("Class\n"); break;
9747 + case 2: DWC_PRINT("Vendor\n"); break;
9748 + case 3: DWC_PRINT("Reserved\n"); break;
9749 + }
9750 + DWC_PRINT(" bmRequestType Recipient = ");
9751 + switch (setup[0]&0x1f) {
9752 + case 0: DWC_PRINT("Device\n"); break;
9753 + case 1: DWC_PRINT("Interface\n"); break;
9754 + case 2: DWC_PRINT("Endpoint\n"); break;
9755 + case 3: DWC_PRINT("Other\n"); break;
9756 + default: DWC_PRINT("Reserved\n"); break;
9757 + }
9758 + DWC_PRINT(" bRequest = 0x%0x\n", setup[1]);
9759 + DWC_PRINT(" wValue = 0x%0x\n", *((uint16_t *)&setup[2]));
9760 + DWC_PRINT(" wIndex = 0x%0x\n", *((uint16_t *)&setup[4]));
9761 + DWC_PRINT(" wLength = 0x%0x\n\n", *((uint16_t *)&setup[6]));
9762 + }
9763 +}
9764 +#endif
9765 +
9766 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd) {
9767 +#ifdef DEBUG
9768 +#if 0
9769 + DWC_PRINT("Frame remaining at SOF:\n");
9770 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9771 + _hcd->frrem_samples, _hcd->frrem_accum,
9772 + (_hcd->frrem_samples > 0) ?
9773 + _hcd->frrem_accum/_hcd->frrem_samples : 0);
9774 +
9775 + DWC_PRINT("\n");
9776 + DWC_PRINT("Frame remaining at start_transfer (uframe 7):\n");
9777 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9778 + _hcd->core_if->hfnum_7_samples, _hcd->core_if->hfnum_7_frrem_accum,
9779 + (_hcd->core_if->hfnum_7_samples > 0) ?
9780 + _hcd->core_if->hfnum_7_frrem_accum/_hcd->core_if->hfnum_7_samples : 0);
9781 + DWC_PRINT("Frame remaining at start_transfer (uframe 0):\n");
9782 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9783 + _hcd->core_if->hfnum_0_samples, _hcd->core_if->hfnum_0_frrem_accum,
9784 + (_hcd->core_if->hfnum_0_samples > 0) ?
9785 + _hcd->core_if->hfnum_0_frrem_accum/_hcd->core_if->hfnum_0_samples : 0);
9786 + DWC_PRINT("Frame remaining at start_transfer (uframe 1-6):\n");
9787 + DWC_PRINT(" samples %u, accum %u, avg %u\n",
9788 + _hcd->core_if->hfnum_other_samples, _hcd->core_if->hfnum_other_frrem_accum,
9789 + (_hcd->core_if->hfnum_other_samples > 0) ?
9790 + _hcd->core_if->hfnum_other_frrem_accum/_hcd->core_if->hfnum_other_samples : 0);
9791 +
9792 + DWC_PRINT("\n");
9793 + DWC_PRINT("Frame remaining at sample point A (uframe 7):\n");
9794 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9795 + _hcd->hfnum_7_samples_a, _hcd->hfnum_7_frrem_accum_a,
9796 + (_hcd->hfnum_7_samples_a > 0) ?
9797 + _hcd->hfnum_7_frrem_accum_a/_hcd->hfnum_7_samples_a : 0);
9798 + DWC_PRINT("Frame remaining at sample point A (uframe 0):\n");
9799 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9800 + _hcd->hfnum_0_samples_a, _hcd->hfnum_0_frrem_accum_a,
9801 + (_hcd->hfnum_0_samples_a > 0) ?
9802 + _hcd->hfnum_0_frrem_accum_a/_hcd->hfnum_0_samples_a : 0);
9803 + DWC_PRINT("Frame remaining at sample point A (uframe 1-6):\n");
9804 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9805 + _hcd->hfnum_other_samples_a, _hcd->hfnum_other_frrem_accum_a,
9806 + (_hcd->hfnum_other_samples_a > 0) ?
9807 + _hcd->hfnum_other_frrem_accum_a/_hcd->hfnum_other_samples_a : 0);
9808 +
9809 + DWC_PRINT("\n");
9810 + DWC_PRINT("Frame remaining at sample point B (uframe 7):\n");
9811 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9812 + _hcd->hfnum_7_samples_b, _hcd->hfnum_7_frrem_accum_b,
9813 + (_hcd->hfnum_7_samples_b > 0) ?
9814 + _hcd->hfnum_7_frrem_accum_b/_hcd->hfnum_7_samples_b : 0);
9815 + DWC_PRINT("Frame remaining at sample point B (uframe 0):\n");
9816 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9817 + _hcd->hfnum_0_samples_b, _hcd->hfnum_0_frrem_accum_b,
9818 + (_hcd->hfnum_0_samples_b > 0) ?
9819 + _hcd->hfnum_0_frrem_accum_b/_hcd->hfnum_0_samples_b : 0);
9820 + DWC_PRINT("Frame remaining at sample point B (uframe 1-6):\n");
9821 + DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
9822 + _hcd->hfnum_other_samples_b, _hcd->hfnum_other_frrem_accum_b,
9823 + (_hcd->hfnum_other_samples_b > 0) ?
9824 + _hcd->hfnum_other_frrem_accum_b/_hcd->hfnum_other_samples_b : 0);
9825 +#endif
9826 +#endif
9827 +}
9828 +
9829 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd)
9830 +{
9831 +#ifdef DEBUG
9832 + int num_channels;
9833 + int i;
9834 + gnptxsts_data_t np_tx_status;
9835 + hptxsts_data_t p_tx_status;
9836 +
9837 + num_channels = _hcd->core_if->core_params->host_channels;
9838 + DWC_PRINT("\n");
9839 + DWC_PRINT("************************************************************\n");
9840 + DWC_PRINT("HCD State:\n");
9841 + DWC_PRINT(" Num channels: %d\n", num_channels);
9842 + for (i = 0; i < num_channels; i++) {
9843 + dwc_hc_t *hc = _hcd->hc_ptr_array[i];
9844 + DWC_PRINT(" Channel %d:\n", i);
9845 + DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
9846 + hc->dev_addr, hc->ep_num, hc->ep_is_in);
9847 + DWC_PRINT(" speed: %d\n", hc->speed);
9848 + DWC_PRINT(" ep_type: %d\n", hc->ep_type);
9849 + DWC_PRINT(" max_packet: %d\n", hc->max_packet);
9850 + DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
9851 + DWC_PRINT(" multi_count: %d\n", hc->multi_count);
9852 + DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
9853 + DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
9854 + DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
9855 + DWC_PRINT(" xfer_count: %d\n", hc->xfer_count);
9856 + DWC_PRINT(" halt_on_queue: %d\n", hc->halt_on_queue);
9857 + DWC_PRINT(" halt_pending: %d\n", hc->halt_pending);
9858 + DWC_PRINT(" halt_status: %d\n", hc->halt_status);
9859 + DWC_PRINT(" do_split: %d\n", hc->do_split);
9860 + DWC_PRINT(" complete_split: %d\n", hc->complete_split);
9861 + DWC_PRINT(" hub_addr: %d\n", hc->hub_addr);
9862 + DWC_PRINT(" port_addr: %d\n", hc->port_addr);
9863 + DWC_PRINT(" xact_pos: %d\n", hc->xact_pos);
9864 + DWC_PRINT(" requests: %d\n", hc->requests);
9865 + DWC_PRINT(" qh: %p\n", hc->qh);
9866 + if (hc->xfer_started) {
9867 + hfnum_data_t hfnum;
9868 + hcchar_data_t hcchar;
9869 + hctsiz_data_t hctsiz;
9870 + hcint_data_t hcint;
9871 + hcintmsk_data_t hcintmsk;
9872 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
9873 + hcchar.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcchar);
9874 + hctsiz.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hctsiz);
9875 + hcint.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcint);
9876 + hcintmsk.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcintmsk);
9877 + DWC_PRINT(" hfnum: 0x%08x\n", hfnum.d32);
9878 + DWC_PRINT(" hcchar: 0x%08x\n", hcchar.d32);
9879 + DWC_PRINT(" hctsiz: 0x%08x\n", hctsiz.d32);
9880 + DWC_PRINT(" hcint: 0x%08x\n", hcint.d32);
9881 + DWC_PRINT(" hcintmsk: 0x%08x\n", hcintmsk.d32);
9882 + }
9883 + if (hc->xfer_started && (hc->qh != NULL) && (hc->qh->qtd_in_process != NULL)) {
9884 + dwc_otg_qtd_t *qtd;
9885 + struct urb *urb;
9886 + qtd = hc->qh->qtd_in_process;
9887 + urb = qtd->urb;
9888 + DWC_PRINT(" URB Info:\n");
9889 + DWC_PRINT(" qtd: %p, urb: %p\n", qtd, urb);
9890 + if (urb != NULL) {
9891 + DWC_PRINT(" Dev: %d, EP: %d %s\n",
9892 + usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe),
9893 + usb_pipein(urb->pipe) ? "IN" : "OUT");
9894 + DWC_PRINT(" Max packet size: %d\n",
9895 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
9896 + DWC_PRINT(" transfer_buffer: %p\n", urb->transfer_buffer);
9897 + DWC_PRINT(" transfer_dma: %p\n", (void *)urb->transfer_dma);
9898 + DWC_PRINT(" transfer_buffer_length: %d\n", urb->transfer_buffer_length);
9899 + DWC_PRINT(" actual_length: %d\n", urb->actual_length);
9900 + }
9901 + }
9902 + }
9903 + //DWC_PRINT(" non_periodic_channels: %d\n", _hcd->non_periodic_channels);
9904 + //DWC_PRINT(" periodic_channels: %d\n", _hcd->periodic_channels);
9905 + DWC_PRINT(" available_channels: %d\n", _hcd->available_host_channels);
9906 + DWC_PRINT(" periodic_usecs: %d\n", _hcd->periodic_usecs);
9907 + np_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->core_global_regs->gnptxsts);
9908 + DWC_PRINT(" NP Tx Req Queue Space Avail: %d\n", np_tx_status.b.nptxqspcavail);
9909 + DWC_PRINT(" NP Tx FIFO Space Avail: %d\n", np_tx_status.b.nptxfspcavail);
9910 + p_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hptxsts);
9911 + DWC_PRINT(" P Tx Req Queue Space Avail: %d\n", p_tx_status.b.ptxqspcavail);
9912 + DWC_PRINT(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
9913 + dwc_otg_hcd_dump_frrem(_hcd);
9914 + dwc_otg_dump_global_registers(_hcd->core_if);
9915 + dwc_otg_dump_host_registers(_hcd->core_if);
9916 + DWC_PRINT("************************************************************\n");
9917 + DWC_PRINT("\n");
9918 +#endif
9919 +}
9920 +#endif /* DWC_DEVICE_ONLY */
9921 --- /dev/null
9922 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd.h
9923 @@ -0,0 +1,676 @@
9924 +/* ==========================================================================
9925 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd.h $
9926 + * $Revision: 1.1.1.1 $
9927 + * $Date: 2009-04-17 06:15:34 $
9928 + * $Change: 537387 $
9929 + *
9930 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
9931 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9932 + * otherwise expressly agreed to in writing between Synopsys and you.
9933 + *
9934 + * The Software IS NOT an item of Licensed Software or Licensed Product under
9935 + * any End User Software License Agreement or Agreement for Licensed Product
9936 + * with Synopsys or any supplement thereto. You are permitted to use and
9937 + * redistribute this Software in source and binary forms, with or without
9938 + * modification, provided that redistributions of source code must retain this
9939 + * notice. You may not view, use, disclose, copy or distribute this file or
9940 + * any information contained herein except pursuant to this license grant from
9941 + * Synopsys. If you do not agree with this notice, including the disclaimer
9942 + * below, then you are not authorized to use the Software.
9943 + *
9944 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
9945 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9946 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9947 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
9948 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
9949 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
9950 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
9951 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9952 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9953 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
9954 + * DAMAGE.
9955 + * ========================================================================== */
9956 +#ifndef DWC_DEVICE_ONLY
9957 +#if !defined(__DWC_HCD_H__)
9958 +#define __DWC_HCD_H__
9959 +
9960 +#include <linux/list.h>
9961 +#include <linux/usb.h>
9962 +#include <linux/usb/hcd.h>
9963 +
9964 +struct lm_device;
9965 +struct dwc_otg_device;
9966 +
9967 +#include "dwc_otg_cil.h"
9968 +//#include "dwc_otg_ifx.h" // winder
9969 +
9970 +
9971 +/**
9972 + * @file
9973 + *
9974 + * This file contains the structures, constants, and interfaces for
9975 + * the Host Contoller Driver (HCD).
9976 + *
9977 + * The Host Controller Driver (HCD) is responsible for translating requests
9978 + * from the USB Driver into the appropriate actions on the DWC_otg controller.
9979 + * It isolates the USBD from the specifics of the controller by providing an
9980 + * API to the USBD.
9981 + */
9982 +
9983 +/**
9984 + * Phases for control transfers.
9985 + */
9986 +typedef enum dwc_otg_control_phase {
9987 + DWC_OTG_CONTROL_SETUP,
9988 + DWC_OTG_CONTROL_DATA,
9989 + DWC_OTG_CONTROL_STATUS
9990 +} dwc_otg_control_phase_e;
9991 +
9992 +/** Transaction types. */
9993 +typedef enum dwc_otg_transaction_type {
9994 + DWC_OTG_TRANSACTION_NONE,
9995 + DWC_OTG_TRANSACTION_PERIODIC,
9996 + DWC_OTG_TRANSACTION_NON_PERIODIC,
9997 + DWC_OTG_TRANSACTION_ALL
9998 +} dwc_otg_transaction_type_e;
9999 +
10000 +/**
10001 + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
10002 + * interrupt, or isochronous transfer. A single QTD is created for each URB
10003 + * (of one of these types) submitted to the HCD. The transfer associated with
10004 + * a QTD may require one or multiple transactions.
10005 + *
10006 + * A QTD is linked to a Queue Head, which is entered in either the
10007 + * non-periodic or periodic schedule for execution. When a QTD is chosen for
10008 + * execution, some or all of its transactions may be executed. After
10009 + * execution, the state of the QTD is updated. The QTD may be retired if all
10010 + * its transactions are complete or if an error occurred. Otherwise, it
10011 + * remains in the schedule so more transactions can be executed later.
10012 + */
10013 +struct dwc_otg_qh;
10014 +typedef struct dwc_otg_qtd {
10015 + /**
10016 + * Determines the PID of the next data packet for the data phase of
10017 + * control transfers. Ignored for other transfer types.<br>
10018 + * One of the following values:
10019 + * - DWC_OTG_HC_PID_DATA0
10020 + * - DWC_OTG_HC_PID_DATA1
10021 + */
10022 + uint8_t data_toggle;
10023 +
10024 + /** Current phase for control transfers (Setup, Data, or Status). */
10025 + dwc_otg_control_phase_e control_phase;
10026 +
10027 + /** Keep track of the current split type
10028 + * for FS/LS endpoints on a HS Hub */
10029 + uint8_t complete_split;
10030 +
10031 + /** How many bytes transferred during SSPLIT OUT */
10032 + uint32_t ssplit_out_xfer_count;
10033 +
10034 + /**
10035 + * Holds the number of bus errors that have occurred for a transaction
10036 + * within this transfer.
10037 + */
10038 + uint8_t error_count;
10039 +
10040 + /**
10041 + * Index of the next frame descriptor for an isochronous transfer. A
10042 + * frame descriptor describes the buffer position and length of the
10043 + * data to be transferred in the next scheduled (micro)frame of an
10044 + * isochronous transfer. It also holds status for that transaction.
10045 + * The frame index starts at 0.
10046 + */
10047 + int isoc_frame_index;
10048 +
10049 + /** Position of the ISOC split on full/low speed */
10050 + uint8_t isoc_split_pos;
10051 +
10052 + /** Position of the ISOC split in the buffer for the current frame */
10053 + uint16_t isoc_split_offset;
10054 +
10055 + /** URB for this transfer */
10056 + struct urb *urb;
10057 +
10058 + /** This list of QTDs */
10059 + struct list_head qtd_list_entry;
10060 +
10061 + /* Field to track the qh pointer */
10062 + struct dwc_otg_qh *qtd_qh_ptr;
10063 +} dwc_otg_qtd_t;
10064 +
10065 +/**
10066 + * A Queue Head (QH) holds the static characteristics of an endpoint and
10067 + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
10068 + * be entered in either the non-periodic or periodic schedule.
10069 + */
10070 +typedef struct dwc_otg_qh {
10071 + /**
10072 + * Endpoint type.
10073 + * One of the following values:
10074 + * - USB_ENDPOINT_XFER_CONTROL
10075 + * - USB_ENDPOINT_XFER_ISOC
10076 + * - USB_ENDPOINT_XFER_BULK
10077 + * - USB_ENDPOINT_XFER_INT
10078 + */
10079 + uint8_t ep_type;
10080 + uint8_t ep_is_in;
10081 +
10082 + /** wMaxPacketSize Field of Endpoint Descriptor. */
10083 + uint16_t maxp;
10084 +
10085 + /**
10086 + * Determines the PID of the next data packet for non-control
10087 + * transfers. Ignored for control transfers.<br>
10088 + * One of the following values:
10089 + * - DWC_OTG_HC_PID_DATA0
10090 + * - DWC_OTG_HC_PID_DATA1
10091 + */
10092 + uint8_t data_toggle;
10093 +
10094 + /** Ping state if 1. */
10095 + uint8_t ping_state;
10096 +
10097 + /**
10098 + * List of QTDs for this QH.
10099 + */
10100 + struct list_head qtd_list;
10101 +
10102 + /** Host channel currently processing transfers for this QH. */
10103 + dwc_hc_t *channel;
10104 +
10105 + /** QTD currently assigned to a host channel for this QH. */
10106 + dwc_otg_qtd_t *qtd_in_process;
10107 +
10108 + /** Full/low speed endpoint on high-speed hub requires split. */
10109 + uint8_t do_split;
10110 +
10111 + /** @name Periodic schedule information */
10112 + /** @{ */
10113 +
10114 + /** Bandwidth in microseconds per (micro)frame. */
10115 + uint8_t usecs;
10116 +
10117 + /** Interval between transfers in (micro)frames. */
10118 + uint16_t interval;
10119 +
10120 + /**
10121 + * (micro)frame to initialize a periodic transfer. The transfer
10122 + * executes in the following (micro)frame.
10123 + */
10124 + uint16_t sched_frame;
10125 +
10126 + /** (micro)frame at which last start split was initialized. */
10127 + uint16_t start_split_frame;
10128 +
10129 + /** @} */
10130 +
10131 + uint16_t speed;
10132 + uint16_t frame_usecs[8];
10133 + /** Entry for QH in either the periodic or non-periodic schedule. */
10134 + struct list_head qh_list_entry;
10135 +} dwc_otg_qh_t;
10136 +
10137 +/**
10138 + * This structure holds the state of the HCD, including the non-periodic and
10139 + * periodic schedules.
10140 + */
10141 +typedef struct dwc_otg_hcd {
10142 + spinlock_t lock;
10143 +
10144 + /** DWC OTG Core Interface Layer */
10145 + dwc_otg_core_if_t *core_if;
10146 +
10147 + /** Internal DWC HCD Flags */
10148 + volatile union dwc_otg_hcd_internal_flags {
10149 + uint32_t d32;
10150 + struct {
10151 + unsigned port_connect_status_change : 1;
10152 + unsigned port_connect_status : 1;
10153 + unsigned port_reset_change : 1;
10154 + unsigned port_enable_change : 1;
10155 + unsigned port_suspend_change : 1;
10156 + unsigned port_over_current_change : 1;
10157 + unsigned reserved : 27;
10158 + } b;
10159 + } flags;
10160 +
10161 + /**
10162 + * Inactive items in the non-periodic schedule. This is a list of
10163 + * Queue Heads. Transfers associated with these Queue Heads are not
10164 + * currently assigned to a host channel.
10165 + */
10166 + struct list_head non_periodic_sched_inactive;
10167 +
10168 + /**
10169 + * Deferred items in the non-periodic schedule. This is a list of
10170 + * Queue Heads. Transfers associated with these Queue Heads are not
10171 + * currently assigned to a host channel.
10172 + * When we get an NAK, the QH goes here.
10173 + */
10174 + struct list_head non_periodic_sched_deferred;
10175 +
10176 + /**
10177 + * Active items in the non-periodic schedule. This is a list of
10178 + * Queue Heads. Transfers associated with these Queue Heads are
10179 + * currently assigned to a host channel.
10180 + */
10181 + struct list_head non_periodic_sched_active;
10182 +
10183 + /**
10184 + * Pointer to the next Queue Head to process in the active
10185 + * non-periodic schedule.
10186 + */
10187 + struct list_head *non_periodic_qh_ptr;
10188 +
10189 + /**
10190 + * Inactive items in the periodic schedule. This is a list of QHs for
10191 + * periodic transfers that are _not_ scheduled for the next frame.
10192 + * Each QH in the list has an interval counter that determines when it
10193 + * needs to be scheduled for execution. This scheduling mechanism
10194 + * allows only a simple calculation for periodic bandwidth used (i.e.
10195 + * must assume that all periodic transfers may need to execute in the
10196 + * same frame). However, it greatly simplifies scheduling and should
10197 + * be sufficient for the vast majority of OTG hosts, which need to
10198 + * connect to a small number of peripherals at one time.
10199 + *
10200 + * Items move from this list to periodic_sched_ready when the QH
10201 + * interval counter is 0 at SOF.
10202 + */
10203 + struct list_head periodic_sched_inactive;
10204 +
10205 + /**
10206 + * List of periodic QHs that are ready for execution in the next
10207 + * frame, but have not yet been assigned to host channels.
10208 + *
10209 + * Items move from this list to periodic_sched_assigned as host
10210 + * channels become available during the current frame.
10211 + */
10212 + struct list_head periodic_sched_ready;
10213 +
10214 + /**
10215 + * List of periodic QHs to be executed in the next frame that are
10216 + * assigned to host channels.
10217 + *
10218 + * Items move from this list to periodic_sched_queued as the
10219 + * transactions for the QH are queued to the DWC_otg controller.
10220 + */
10221 + struct list_head periodic_sched_assigned;
10222 +
10223 + /**
10224 + * List of periodic QHs that have been queued for execution.
10225 + *
10226 + * Items move from this list to either periodic_sched_inactive or
10227 + * periodic_sched_ready when the channel associated with the transfer
10228 + * is released. If the interval for the QH is 1, the item moves to
10229 + * periodic_sched_ready because it must be rescheduled for the next
10230 + * frame. Otherwise, the item moves to periodic_sched_inactive.
10231 + */
10232 + struct list_head periodic_sched_queued;
10233 +
10234 + /**
10235 + * Total bandwidth claimed so far for periodic transfers. This value
10236 + * is in microseconds per (micro)frame. The assumption is that all
10237 + * periodic transfers may occur in the same (micro)frame.
10238 + */
10239 + uint16_t periodic_usecs;
10240 +
10241 + /**
10242 + * Total bandwidth claimed so far for all periodic transfers
10243 + * in a frame.
10244 + * This will include a mixture of HS and FS transfers.
10245 + * Units are microseconds per (micro)frame.
10246 + * We have a budget per frame and have to schedule
10247 + * transactions accordingly.
10248 + * Watch out for the fact that things are actually scheduled for the
10249 + * "next frame".
10250 + */
10251 + uint16_t frame_usecs[8];
10252 +
10253 + /**
10254 + * Frame number read from the core at SOF. The value ranges from 0 to
10255 + * DWC_HFNUM_MAX_FRNUM.
10256 + */
10257 + uint16_t frame_number;
10258 +
10259 + /**
10260 + * Free host channels in the controller. This is a list of
10261 + * dwc_hc_t items.
10262 + */
10263 + struct list_head free_hc_list;
10264 +
10265 + /**
10266 + * Number of available host channels.
10267 + */
10268 + int available_host_channels;
10269 +
10270 + /**
10271 + * Array of pointers to the host channel descriptors. Allows accessing
10272 + * a host channel descriptor given the host channel number. This is
10273 + * useful in interrupt handlers.
10274 + */
10275 + dwc_hc_t *hc_ptr_array[MAX_EPS_CHANNELS];
10276 +
10277 + /**
10278 + * Buffer to use for any data received during the status phase of a
10279 + * control transfer. Normally no data is transferred during the status
10280 + * phase. This buffer is used as a bit bucket.
10281 + */
10282 + uint8_t *status_buf;
10283 +
10284 + /**
10285 + * DMA address for status_buf.
10286 + */
10287 + dma_addr_t status_buf_dma;
10288 +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
10289 +
10290 + /**
10291 + * Structure to allow starting the HCD in a non-interrupt context
10292 + * during an OTG role change.
10293 + */
10294 + struct work_struct start_work;
10295 + struct usb_hcd *_p;
10296 +
10297 + /**
10298 + * Connection timer. An OTG host must display a message if the device
10299 + * does not connect. Started when the VBus power is turned on via
10300 + * sysfs attribute "buspower".
10301 + */
10302 + struct timer_list conn_timer;
10303 +
10304 + /* Tasket to do a reset */
10305 + struct tasklet_struct *reset_tasklet;
10306 +
10307 +#ifdef DEBUG
10308 + uint32_t frrem_samples;
10309 + uint64_t frrem_accum;
10310 +
10311 + uint32_t hfnum_7_samples_a;
10312 + uint64_t hfnum_7_frrem_accum_a;
10313 + uint32_t hfnum_0_samples_a;
10314 + uint64_t hfnum_0_frrem_accum_a;
10315 + uint32_t hfnum_other_samples_a;
10316 + uint64_t hfnum_other_frrem_accum_a;
10317 +
10318 + uint32_t hfnum_7_samples_b;
10319 + uint64_t hfnum_7_frrem_accum_b;
10320 + uint32_t hfnum_0_samples_b;
10321 + uint64_t hfnum_0_frrem_accum_b;
10322 + uint32_t hfnum_other_samples_b;
10323 + uint64_t hfnum_other_frrem_accum_b;
10324 +#endif
10325 +
10326 +} dwc_otg_hcd_t;
10327 +
10328 +/** Gets the dwc_otg_hcd from a struct usb_hcd */
10329 +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
10330 +{
10331 + return (dwc_otg_hcd_t *)(hcd->hcd_priv);
10332 +}
10333 +
10334 +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
10335 +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t *dwc_otg_hcd)
10336 +{
10337 + return container_of((void *)dwc_otg_hcd, struct usb_hcd, hcd_priv);
10338 +}
10339 +
10340 +/** @name HCD Create/Destroy Functions */
10341 +/** @{ */
10342 +extern int __devinit dwc_otg_hcd_init(struct device *_dev, dwc_otg_device_t * dwc_otg_device);
10343 +extern void dwc_otg_hcd_remove(struct device *_dev);
10344 +/** @} */
10345 +
10346 +/** @name Linux HC Driver API Functions */
10347 +/** @{ */
10348 +
10349 +extern int dwc_otg_hcd_start(struct usb_hcd *hcd);
10350 +extern void dwc_otg_hcd_stop(struct usb_hcd *hcd);
10351 +extern int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd);
10352 +extern void dwc_otg_hcd_free(struct usb_hcd *hcd);
10353 +
10354 +extern int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
10355 + struct urb *urb,
10356 + gfp_t mem_flags);
10357 +extern int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
10358 + struct urb *urb,
10359 + int status);
10360 +extern irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
10361 +
10362 +extern void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
10363 + struct usb_host_endpoint *ep);
10364 +
10365 +extern int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd,
10366 + char *buf);
10367 +extern int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
10368 + u16 typeReq,
10369 + u16 wValue,
10370 + u16 wIndex,
10371 + char *buf,
10372 + u16 wLength);
10373 +
10374 +/** @} */
10375 +
10376 +/** @name Transaction Execution Functions */
10377 +/** @{ */
10378 +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd);
10379 +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
10380 + dwc_otg_transaction_type_e _tr_type);
10381 +extern void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *_hcd, struct urb *_urb,
10382 + int _status);
10383 +/** @} */
10384 +
10385 +/** @name Interrupt Handler Functions */
10386 +/** @{ */
10387 +extern int32_t dwc_otg_hcd_handle_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10388 +extern int32_t dwc_otg_hcd_handle_sof_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10389 +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10390 +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10391 +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10392 +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *_dwc_otg_hcd);
10393 +extern int32_t dwc_otg_hcd_handle_port_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10394 +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10395 +extern int32_t dwc_otg_hcd_handle_disconnect_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10396 +extern int32_t dwc_otg_hcd_handle_hc_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10397 +extern int32_t dwc_otg_hcd_handle_hc_n_intr (dwc_otg_hcd_t *_dwc_otg_hcd, uint32_t _num);
10398 +extern int32_t dwc_otg_hcd_handle_session_req_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10399 +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr (dwc_otg_hcd_t *_dwc_otg_hcd);
10400 +/** @} */
10401 +
10402 +
10403 +/** @name Schedule Queue Functions */
10404 +/** @{ */
10405 +
10406 +/* Implemented in dwc_otg_hcd_queue.c */
10407 +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *_hcd, struct urb *_urb);
10408 +extern void dwc_otg_hcd_qh_init (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, struct urb *_urb);
10409 +extern void dwc_otg_hcd_qh_free (dwc_otg_qh_t *_qh);
10410 +extern int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh);
10411 +extern void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh);
10412 +extern void dwc_otg_hcd_qh_deactivate (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int sched_csplit);
10413 +extern int dwc_otg_hcd_qh_deferr (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int delay);
10414 +
10415 +/** Remove and free a QH */
10416 +static inline void dwc_otg_hcd_qh_remove_and_free (dwc_otg_hcd_t *_hcd,
10417 + dwc_otg_qh_t *_qh)
10418 +{
10419 + dwc_otg_hcd_qh_remove (_hcd, _qh);
10420 + dwc_otg_hcd_qh_free (_qh);
10421 +}
10422 +
10423 +/** Allocates memory for a QH structure.
10424 + * @return Returns the memory allocate or NULL on error. */
10425 +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc (void)
10426 +{
10427 +#ifdef _SC_BUILD_
10428 + return (dwc_otg_qh_t *) kmalloc (sizeof(dwc_otg_qh_t), GFP_ATOMIC);
10429 +#else
10430 + return (dwc_otg_qh_t *) kmalloc (sizeof(dwc_otg_qh_t), GFP_KERNEL);
10431 +#endif
10432 +}
10433 +
10434 +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *urb);
10435 +extern void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *qtd, struct urb *urb);
10436 +extern int dwc_otg_hcd_qtd_add (dwc_otg_qtd_t *qtd, dwc_otg_hcd_t *dwc_otg_hcd);
10437 +
10438 +/** Allocates memory for a QTD structure.
10439 + * @return Returns the memory allocate or NULL on error. */
10440 +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc (void)
10441 +{
10442 +#ifdef _SC_BUILD_
10443 + return (dwc_otg_qtd_t *) kmalloc (sizeof(dwc_otg_qtd_t), GFP_ATOMIC);
10444 +#else
10445 + return (dwc_otg_qtd_t *) kmalloc (sizeof(dwc_otg_qtd_t), GFP_KERNEL);
10446 +#endif
10447 +}
10448 +
10449 +/** Frees the memory for a QTD structure. QTD should already be removed from
10450 + * list.
10451 + * @param[in] _qtd QTD to free.*/
10452 +static inline void dwc_otg_hcd_qtd_free (dwc_otg_qtd_t *_qtd)
10453 +{
10454 + kfree (_qtd);
10455 +}
10456 +
10457 +/** Removes a QTD from list.
10458 + * @param[in] _qtd QTD to remove from list. */
10459 +static inline void dwc_otg_hcd_qtd_remove (dwc_otg_qtd_t *_qtd)
10460 +{
10461 + unsigned long flags;
10462 + local_irq_save (flags);
10463 + list_del (&_qtd->qtd_list_entry);
10464 + local_irq_restore (flags);
10465 +}
10466 +
10467 +/** Remove and free a QTD */
10468 +static inline void dwc_otg_hcd_qtd_remove_and_free (dwc_otg_qtd_t *_qtd)
10469 +{
10470 + dwc_otg_hcd_qtd_remove (_qtd);
10471 + dwc_otg_hcd_qtd_free (_qtd);
10472 +}
10473 +
10474 +/** @} */
10475 +
10476 +
10477 +/** @name Internal Functions */
10478 +/** @{ */
10479 +dwc_otg_qh_t *dwc_urb_to_qh(struct urb *_urb);
10480 +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd);
10481 +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd);
10482 +/** @} */
10483 +
10484 +
10485 +/** Gets the usb_host_endpoint associated with an URB. */
10486 +static inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *_urb)
10487 +{
10488 + struct usb_device *dev = _urb->dev;
10489 + int ep_num = usb_pipeendpoint(_urb->pipe);
10490 + if (usb_pipein(_urb->pipe))
10491 + return dev->ep_in[ep_num];
10492 + else
10493 + return dev->ep_out[ep_num];
10494 +}
10495 +
10496 +/**
10497 + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
10498 + * qualified with its direction (possible 32 endpoints per device).
10499 + */
10500 +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) \
10501 + ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
10502 + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
10503 +
10504 +/** Gets the QH that contains the list_head */
10505 +#define dwc_list_to_qh(_list_head_ptr_) (container_of(_list_head_ptr_,dwc_otg_qh_t,qh_list_entry))
10506 +
10507 +/** Gets the QTD that contains the list_head */
10508 +#define dwc_list_to_qtd(_list_head_ptr_) (container_of(_list_head_ptr_,dwc_otg_qtd_t,qtd_list_entry))
10509 +
10510 +/** Check if QH is non-periodic */
10511 +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == USB_ENDPOINT_XFER_BULK) || \
10512 + (_qh_ptr_->ep_type == USB_ENDPOINT_XFER_CONTROL))
10513 +
10514 +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
10515 +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
10516 +
10517 +/** Packet size for any kind of endpoint descriptor */
10518 +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
10519 +
10520 +/**
10521 + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
10522 + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
10523 + * frame number when the max frame number is reached.
10524 + */
10525 +static inline int dwc_frame_num_le(uint16_t _frame1, uint16_t _frame2)
10526 +{
10527 + return ((_frame2 - _frame1) & DWC_HFNUM_MAX_FRNUM) <=
10528 + (DWC_HFNUM_MAX_FRNUM >> 1);
10529 +}
10530 +
10531 +/**
10532 + * Returns true if _frame1 is greater than _frame2. The comparison is done
10533 + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
10534 + * number when the max frame number is reached.
10535 + */
10536 +static inline int dwc_frame_num_gt(uint16_t _frame1, uint16_t _frame2)
10537 +{
10538 + return (_frame1 != _frame2) &&
10539 + (((_frame1 - _frame2) & DWC_HFNUM_MAX_FRNUM) <
10540 + (DWC_HFNUM_MAX_FRNUM >> 1));
10541 +}
10542 +
10543 +/**
10544 + * Increments _frame by the amount specified by _inc. The addition is done
10545 + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
10546 + */
10547 +static inline uint16_t dwc_frame_num_inc(uint16_t _frame, uint16_t _inc)
10548 +{
10549 + return (_frame + _inc) & DWC_HFNUM_MAX_FRNUM;
10550 +}
10551 +
10552 +static inline uint16_t dwc_full_frame_num (uint16_t _frame)
10553 +{
10554 + return ((_frame) & DWC_HFNUM_MAX_FRNUM) >> 3;
10555 +}
10556 +
10557 +static inline uint16_t dwc_micro_frame_num (uint16_t _frame)
10558 +{
10559 + return (_frame) & 0x7;
10560 +}
10561 +
10562 +#ifdef DEBUG
10563 +/**
10564 + * Macro to sample the remaining PHY clocks left in the current frame. This
10565 + * may be used during debugging to determine the average time it takes to
10566 + * execute sections of code. There are two possible sample points, "a" and
10567 + * "b", so the _letter argument must be one of these values.
10568 + *
10569 + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
10570 + * example, "cat /sys/devices/lm0/hcd_frrem".
10571 + */
10572 +#define dwc_sample_frrem(_hcd, _qh, _letter) \
10573 +{ \
10574 + hfnum_data_t hfnum; \
10575 + dwc_otg_qtd_t *qtd; \
10576 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
10577 + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
10578 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
10579 + switch (hfnum.b.frnum & 0x7) { \
10580 + case 7: \
10581 + _hcd->hfnum_7_samples_##_letter++; \
10582 + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
10583 + break; \
10584 + case 0: \
10585 + _hcd->hfnum_0_samples_##_letter++; \
10586 + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
10587 + break; \
10588 + default: \
10589 + _hcd->hfnum_other_samples_##_letter++; \
10590 + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
10591 + break; \
10592 + } \
10593 + } \
10594 +}
10595 +#else // DEBUG
10596 +#define dwc_sample_frrem(_hcd, _qh, _letter)
10597 +#endif // DEBUG
10598 +#endif // __DWC_HCD_H__
10599 +#endif /* DWC_DEVICE_ONLY */
10600 --- /dev/null
10601 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
10602 @@ -0,0 +1,1841 @@
10603 +/* ==========================================================================
10604 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd_intr.c $
10605 + * $Revision: 1.1.1.1 $
10606 + * $Date: 2009-04-17 06:15:34 $
10607 + * $Change: 553126 $
10608 + *
10609 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
10610 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
10611 + * otherwise expressly agreed to in writing between Synopsys and you.
10612 + *
10613 + * The Software IS NOT an item of Licensed Software or Licensed Product under
10614 + * any End User Software License Agreement or Agreement for Licensed Product
10615 + * with Synopsys or any supplement thereto. You are permitted to use and
10616 + * redistribute this Software in source and binary forms, with or without
10617 + * modification, provided that redistributions of source code must retain this
10618 + * notice. You may not view, use, disclose, copy or distribute this file or
10619 + * any information contained herein except pursuant to this license grant from
10620 + * Synopsys. If you do not agree with this notice, including the disclaimer
10621 + * below, then you are not authorized to use the Software.
10622 + *
10623 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
10624 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10625 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10626 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
10627 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10628 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
10629 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
10630 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10631 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10632 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
10633 + * DAMAGE.
10634 + * ========================================================================== */
10635 +#ifndef DWC_DEVICE_ONLY
10636 +
10637 +#include "dwc_otg_driver.h"
10638 +#include "dwc_otg_hcd.h"
10639 +#include "dwc_otg_regs.h"
10640 +
10641 +const int erratum_usb09_patched = 0;
10642 +const int deferral_on = 1;
10643 +const int nak_deferral_delay = 8;
10644 +const int nyet_deferral_delay = 1;
10645 +/** @file
10646 + * This file contains the implementation of the HCD Interrupt handlers.
10647 + */
10648 +
10649 +/** This function handles interrupts for the HCD. */
10650 +int32_t dwc_otg_hcd_handle_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10651 +{
10652 + int retval = 0;
10653 +
10654 + dwc_otg_core_if_t *core_if = _dwc_otg_hcd->core_if;
10655 + gintsts_data_t gintsts;
10656 +#ifdef DEBUG
10657 + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
10658 +#endif
10659 +
10660 + /* Check if HOST Mode */
10661 + if (dwc_otg_is_host_mode(core_if)) {
10662 + gintsts.d32 = dwc_otg_read_core_intr(core_if);
10663 + if (!gintsts.d32) {
10664 + return 0;
10665 + }
10666 +
10667 +#ifdef DEBUG
10668 + /* Don't print debug message in the interrupt handler on SOF */
10669 +# ifndef DEBUG_SOF
10670 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10671 +# endif
10672 + DWC_DEBUGPL (DBG_HCD, "\n");
10673 +#endif
10674 +
10675 +#ifdef DEBUG
10676 +# ifndef DEBUG_SOF
10677 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10678 +# endif
10679 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n", gintsts.d32);
10680 +#endif
10681 +
10682 + if (gintsts.b.sofintr) {
10683 + retval |= dwc_otg_hcd_handle_sof_intr (_dwc_otg_hcd);
10684 + }
10685 + if (gintsts.b.rxstsqlvl) {
10686 + retval |= dwc_otg_hcd_handle_rx_status_q_level_intr (_dwc_otg_hcd);
10687 + }
10688 + if (gintsts.b.nptxfempty) {
10689 + retval |= dwc_otg_hcd_handle_np_tx_fifo_empty_intr (_dwc_otg_hcd);
10690 + }
10691 + if (gintsts.b.i2cintr) {
10692 + /** @todo Implement i2cintr handler. */
10693 + }
10694 + if (gintsts.b.portintr) {
10695 + retval |= dwc_otg_hcd_handle_port_intr (_dwc_otg_hcd);
10696 + }
10697 + if (gintsts.b.hcintr) {
10698 + retval |= dwc_otg_hcd_handle_hc_intr (_dwc_otg_hcd);
10699 + }
10700 + if (gintsts.b.ptxfempty) {
10701 + retval |= dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (_dwc_otg_hcd);
10702 + }
10703 +#ifdef DEBUG
10704 +# ifndef DEBUG_SOF
10705 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10706 +# endif
10707 + {
10708 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Finished Servicing Interrupts\n");
10709 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
10710 + dwc_read_reg32(&global_regs->gintsts));
10711 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
10712 + dwc_read_reg32(&global_regs->gintmsk));
10713 + }
10714 +#endif
10715 +
10716 +#ifdef DEBUG
10717 +# ifndef DEBUG_SOF
10718 + if (gintsts.d32 != DWC_SOF_INTR_MASK)
10719 +# endif
10720 + DWC_DEBUGPL (DBG_HCD, "\n");
10721 +#endif
10722 +
10723 + }
10724 +
10725 + return retval;
10726 +}
10727 +
10728 +#ifdef DWC_TRACK_MISSED_SOFS
10729 +#warning Compiling code to track missed SOFs
10730 +#define FRAME_NUM_ARRAY_SIZE 1000
10731 +/**
10732 + * This function is for debug only.
10733 + */
10734 +static inline void track_missed_sofs(uint16_t _curr_frame_number) {
10735 + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
10736 + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
10737 + static int frame_num_idx = 0;
10738 + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
10739 + static int dumped_frame_num_array = 0;
10740 +
10741 + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
10742 + if ((((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) != _curr_frame_number)) {
10743 + frame_num_array[frame_num_idx] = _curr_frame_number;
10744 + last_frame_num_array[frame_num_idx++] = last_frame_num;
10745 + }
10746 + } else if (!dumped_frame_num_array) {
10747 + int i;
10748 + printk(KERN_EMERG USB_DWC "Frame Last Frame\n");
10749 + printk(KERN_EMERG USB_DWC "----- ----------\n");
10750 + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
10751 + printk(KERN_EMERG USB_DWC "0x%04x 0x%04x\n",
10752 + frame_num_array[i], last_frame_num_array[i]);
10753 + }
10754 + dumped_frame_num_array = 1;
10755 + }
10756 + last_frame_num = _curr_frame_number;
10757 +}
10758 +#endif
10759 +
10760 +/**
10761 + * Handles the start-of-frame interrupt in host mode. Non-periodic
10762 + * transactions may be queued to the DWC_otg controller for the current
10763 + * (micro)frame. Periodic transactions may be queued to the controller for the
10764 + * next (micro)frame.
10765 + */
10766 +int32_t dwc_otg_hcd_handle_sof_intr (dwc_otg_hcd_t *_hcd)
10767 +{
10768 + hfnum_data_t hfnum;
10769 + struct list_head *qh_entry;
10770 + dwc_otg_qh_t *qh;
10771 + dwc_otg_transaction_type_e tr_type;
10772 + gintsts_data_t gintsts = {.d32 = 0};
10773 +
10774 + hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
10775 +
10776 +#ifdef DEBUG_SOF
10777 + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
10778 +#endif
10779 +
10780 + _hcd->frame_number = hfnum.b.frnum;
10781 +
10782 +#ifdef DEBUG
10783 + _hcd->frrem_accum += hfnum.b.frrem;
10784 + _hcd->frrem_samples++;
10785 +#endif
10786 +
10787 +#ifdef DWC_TRACK_MISSED_SOFS
10788 + track_missed_sofs(_hcd->frame_number);
10789 +#endif
10790 +
10791 + /* Determine whether any periodic QHs should be executed. */
10792 + qh_entry = _hcd->periodic_sched_inactive.next;
10793 + while (qh_entry != &_hcd->periodic_sched_inactive) {
10794 + qh = list_entry(qh_entry, dwc_otg_qh_t, qh_list_entry);
10795 + qh_entry = qh_entry->next;
10796 + if (dwc_frame_num_le(qh->sched_frame, _hcd->frame_number)) {
10797 + /*
10798 + * Move QH to the ready list to be executed next
10799 + * (micro)frame.
10800 + */
10801 + list_move(&qh->qh_list_entry, &_hcd->periodic_sched_ready);
10802 + }
10803 + }
10804 +
10805 + tr_type = dwc_otg_hcd_select_transactions(_hcd);
10806 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
10807 + dwc_otg_hcd_queue_transactions(_hcd, tr_type);
10808 + }
10809 +
10810 + /* Clear interrupt */
10811 + gintsts.b.sofintr = 1;
10812 + dwc_write_reg32(&_hcd->core_if->core_global_regs->gintsts, gintsts.d32);
10813 +
10814 + return 1;
10815 +}
10816 +
10817 +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
10818 + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
10819 + * memory if the DWC_otg controller is operating in Slave mode. */
10820 +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10821 +{
10822 + host_grxsts_data_t grxsts;
10823 + dwc_hc_t *hc = NULL;
10824 +
10825 + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
10826 +
10827 + grxsts.d32 = dwc_read_reg32(&_dwc_otg_hcd->core_if->core_global_regs->grxstsp);
10828 +
10829 + hc = _dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
10830 +
10831 + /* Packet Status */
10832 + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
10833 + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
10834 + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid, hc->data_pid_start);
10835 + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
10836 +
10837 + switch (grxsts.b.pktsts) {
10838 + case DWC_GRXSTS_PKTSTS_IN:
10839 + /* Read the data into the host buffer. */
10840 + if (grxsts.b.bcnt > 0) {
10841 + dwc_otg_read_packet(_dwc_otg_hcd->core_if,
10842 + hc->xfer_buff,
10843 + grxsts.b.bcnt);
10844 +
10845 + /* Update the HC fields for the next packet received. */
10846 + hc->xfer_count += grxsts.b.bcnt;
10847 + hc->xfer_buff += grxsts.b.bcnt;
10848 + }
10849 +
10850 + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
10851 + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
10852 + case DWC_GRXSTS_PKTSTS_CH_HALTED:
10853 + /* Handled in interrupt, just ignore data */
10854 + break;
10855 + default:
10856 + DWC_ERROR ("RX_STS_Q Interrupt: Unknown status %d\n", grxsts.b.pktsts);
10857 + break;
10858 + }
10859 +
10860 + return 1;
10861 +}
10862 +
10863 +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
10864 + * data packets may be written to the FIFO for OUT transfers. More requests
10865 + * may be written to the non-periodic request queue for IN transfers. This
10866 + * interrupt is enabled only in Slave mode. */
10867 +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10868 +{
10869 + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
10870 + dwc_otg_hcd_queue_transactions(_dwc_otg_hcd,
10871 + DWC_OTG_TRANSACTION_NON_PERIODIC);
10872 + return 1;
10873 +}
10874 +
10875 +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
10876 + * packets may be written to the FIFO for OUT transfers. More requests may be
10877 + * written to the periodic request queue for IN transfers. This interrupt is
10878 + * enabled only in Slave mode. */
10879 +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10880 +{
10881 + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
10882 + dwc_otg_hcd_queue_transactions(_dwc_otg_hcd,
10883 + DWC_OTG_TRANSACTION_PERIODIC);
10884 + return 1;
10885 +}
10886 +
10887 +/** There are multiple conditions that can cause a port interrupt. This function
10888 + * determines which interrupt conditions have occurred and handles them
10889 + * appropriately. */
10890 +int32_t dwc_otg_hcd_handle_port_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
10891 +{
10892 + int retval = 0;
10893 + hprt0_data_t hprt0;
10894 + hprt0_data_t hprt0_modify;
10895 +
10896 + hprt0.d32 = dwc_read_reg32(_dwc_otg_hcd->core_if->host_if->hprt0);
10897 + hprt0_modify.d32 = dwc_read_reg32(_dwc_otg_hcd->core_if->host_if->hprt0);
10898 +
10899 + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
10900 + * GINTSTS */
10901 +
10902 + hprt0_modify.b.prtena = 0;
10903 + hprt0_modify.b.prtconndet = 0;
10904 + hprt0_modify.b.prtenchng = 0;
10905 + hprt0_modify.b.prtovrcurrchng = 0;
10906 +
10907 + /* Port Connect Detected
10908 + * Set flag and clear if detected */
10909 + if (hprt0.b.prtconndet) {
10910 + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
10911 + "Port Connect Detected--\n", hprt0.d32);
10912 + _dwc_otg_hcd->flags.b.port_connect_status_change = 1;
10913 + _dwc_otg_hcd->flags.b.port_connect_status = 1;
10914 + hprt0_modify.b.prtconndet = 1;
10915 +
10916 + /* B-Device has connected, Delete the connection timer. */
10917 + del_timer( &_dwc_otg_hcd->conn_timer );
10918 +
10919 + /* The Hub driver asserts a reset when it sees port connect
10920 + * status change flag */
10921 + retval |= 1;
10922 + }
10923 +
10924 + /* Port Enable Changed
10925 + * Clear if detected - Set internal flag if disabled */
10926 + if (hprt0.b.prtenchng) {
10927 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
10928 + "Port Enable Changed--\n", hprt0.d32);
10929 + hprt0_modify.b.prtenchng = 1;
10930 + if (hprt0.b.prtena == 1) {
10931 + int do_reset = 0;
10932 + dwc_otg_core_params_t *params = _dwc_otg_hcd->core_if->core_params;
10933 + dwc_otg_core_global_regs_t *global_regs = _dwc_otg_hcd->core_if->core_global_regs;
10934 + dwc_otg_host_if_t *host_if = _dwc_otg_hcd->core_if->host_if;
10935 +
10936 + /* Check if we need to adjust the PHY clock speed for
10937 + * low power and adjust it */
10938 + if (params->host_support_fs_ls_low_power)
10939 + {
10940 + gusbcfg_data_t usbcfg;
10941 +
10942 + usbcfg.d32 = dwc_read_reg32 (&global_regs->gusbcfg);
10943 +
10944 + if ((hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED) ||
10945 + (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED))
10946 + {
10947 + /*
10948 + * Low power
10949 + */
10950 + hcfg_data_t hcfg;
10951 + if (usbcfg.b.phylpwrclksel == 0) {
10952 + /* Set PHY low power clock select for FS/LS devices */
10953 + usbcfg.b.phylpwrclksel = 1;
10954 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
10955 + do_reset = 1;
10956 + }
10957 +
10958 + hcfg.d32 = dwc_read_reg32(&host_if->host_global_regs->hcfg);
10959 +
10960 + if ((hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED) &&
10961 + (params->host_ls_low_power_phy_clk ==
10962 + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ))
10963 + {
10964 + /* 6 MHZ */
10965 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
10966 + if (hcfg.b.fslspclksel != DWC_HCFG_6_MHZ) {
10967 + hcfg.b.fslspclksel = DWC_HCFG_6_MHZ;
10968 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
10969 + hcfg.d32);
10970 + do_reset = 1;
10971 + }
10972 + }
10973 + else {
10974 + /* 48 MHZ */
10975 + DWC_DEBUGPL(DBG_CIL, "FS_PHY programming HCFG to 48 MHz ()\n");
10976 + if (hcfg.b.fslspclksel != DWC_HCFG_48_MHZ) {
10977 + hcfg.b.fslspclksel = DWC_HCFG_48_MHZ;
10978 + dwc_write_reg32(&host_if->host_global_regs->hcfg,
10979 + hcfg.d32);
10980 + do_reset = 1;
10981 + }
10982 + }
10983 + }
10984 + else {
10985 + /*
10986 + * Not low power
10987 + */
10988 + if (usbcfg.b.phylpwrclksel == 1) {
10989 + usbcfg.b.phylpwrclksel = 0;
10990 + dwc_write_reg32(&global_regs->gusbcfg, usbcfg.d32);
10991 + do_reset = 1;
10992 + }
10993 + }
10994 +
10995 + if (do_reset) {
10996 + tasklet_schedule(_dwc_otg_hcd->reset_tasklet);
10997 + }
10998 + }
10999 +
11000 + if (!do_reset) {
11001 + /* Port has been enabled set the reset change flag */
11002 + _dwc_otg_hcd->flags.b.port_reset_change = 1;
11003 + }
11004 +
11005 + } else {
11006 + _dwc_otg_hcd->flags.b.port_enable_change = 1;
11007 + }
11008 + retval |= 1;
11009 + }
11010 +
11011 + /** Overcurrent Change Interrupt */
11012 + if (hprt0.b.prtovrcurrchng) {
11013 + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
11014 + "Port Overcurrent Changed--\n", hprt0.d32);
11015 + _dwc_otg_hcd->flags.b.port_over_current_change = 1;
11016 + hprt0_modify.b.prtovrcurrchng = 1;
11017 + retval |= 1;
11018 + }
11019 +
11020 + /* Clear Port Interrupts */
11021 + dwc_write_reg32(_dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
11022 +
11023 + return retval;
11024 +}
11025 +
11026 +
11027 +/** This interrupt indicates that one or more host channels has a pending
11028 + * interrupt. There are multiple conditions that can cause each host channel
11029 + * interrupt. This function determines which conditions have occurred for each
11030 + * host channel interrupt and handles them appropriately. */
11031 +int32_t dwc_otg_hcd_handle_hc_intr (dwc_otg_hcd_t *_dwc_otg_hcd)
11032 +{
11033 + int i;
11034 + int retval = 0;
11035 + haint_data_t haint;
11036 +
11037 + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
11038 + * GINTSTS */
11039 +
11040 + haint.d32 = dwc_otg_read_host_all_channels_intr(_dwc_otg_hcd->core_if);
11041 +
11042 + for (i=0; i<_dwc_otg_hcd->core_if->core_params->host_channels; i++) {
11043 + if (haint.b2.chint & (1 << i)) {
11044 + retval |= dwc_otg_hcd_handle_hc_n_intr (_dwc_otg_hcd, i);
11045 + }
11046 + }
11047 +
11048 + return retval;
11049 +}
11050 +
11051 +/* Macro used to clear one channel interrupt */
11052 +#define clear_hc_int(_hc_regs_,_intr_) \
11053 +do { \
11054 + hcint_data_t hcint_clear = {.d32 = 0}; \
11055 + hcint_clear.b._intr_ = 1; \
11056 + dwc_write_reg32(&((_hc_regs_)->hcint), hcint_clear.d32); \
11057 +} while (0)
11058 +
11059 +/*
11060 + * Macro used to disable one channel interrupt. Channel interrupts are
11061 + * disabled when the channel is halted or released by the interrupt handler.
11062 + * There is no need to handle further interrupts of that type until the
11063 + * channel is re-assigned. In fact, subsequent handling may cause crashes
11064 + * because the channel structures are cleaned up when the channel is released.
11065 + */
11066 +#define disable_hc_int(_hc_regs_,_intr_) \
11067 +do { \
11068 + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
11069 + hcintmsk.b._intr_ = 1; \
11070 + dwc_modify_reg32(&((_hc_regs_)->hcintmsk), hcintmsk.d32, 0); \
11071 +} while (0)
11072 +
11073 +/**
11074 + * Gets the actual length of a transfer after the transfer halts. _halt_status
11075 + * holds the reason for the halt.
11076 + *
11077 + * For IN transfers where _halt_status is DWC_OTG_HC_XFER_COMPLETE,
11078 + * *_short_read is set to 1 upon return if less than the requested
11079 + * number of bytes were transferred. Otherwise, *_short_read is set to 0 upon
11080 + * return. _short_read may also be NULL on entry, in which case it remains
11081 + * unchanged.
11082 + */
11083 +static uint32_t get_actual_xfer_length(dwc_hc_t *_hc,
11084 + dwc_otg_hc_regs_t *_hc_regs,
11085 + dwc_otg_qtd_t *_qtd,
11086 + dwc_otg_halt_status_e _halt_status,
11087 + int *_short_read)
11088 +{
11089 + hctsiz_data_t hctsiz;
11090 + uint32_t length;
11091 +
11092 + if (_short_read != NULL) {
11093 + *_short_read = 0;
11094 + }
11095 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11096 +
11097 + if (_halt_status == DWC_OTG_HC_XFER_COMPLETE) {
11098 + if (_hc->ep_is_in) {
11099 + length = _hc->xfer_len - hctsiz.b.xfersize;
11100 + if (_short_read != NULL) {
11101 + *_short_read = (hctsiz.b.xfersize != 0);
11102 + }
11103 + } else if (_hc->qh->do_split) {
11104 + length = _qtd->ssplit_out_xfer_count;
11105 + } else {
11106 + length = _hc->xfer_len;
11107 + }
11108 + } else {
11109 + /*
11110 + * Must use the hctsiz.pktcnt field to determine how much data
11111 + * has been transferred. This field reflects the number of
11112 + * packets that have been transferred via the USB. This is
11113 + * always an integral number of packets if the transfer was
11114 + * halted before its normal completion. (Can't use the
11115 + * hctsiz.xfersize field because that reflects the number of
11116 + * bytes transferred via the AHB, not the USB).
11117 + */
11118 + length = (_hc->start_pkt_count - hctsiz.b.pktcnt) * _hc->max_packet;
11119 + }
11120 +
11121 + return length;
11122 +}
11123 +
11124 +/**
11125 + * Updates the state of the URB after a Transfer Complete interrupt on the
11126 + * host channel. Updates the actual_length field of the URB based on the
11127 + * number of bytes transferred via the host channel. Sets the URB status
11128 + * if the data transfer is finished.
11129 + *
11130 + * @return 1 if the data transfer specified by the URB is completely finished,
11131 + * 0 otherwise.
11132 + */
11133 +static int update_urb_state_xfer_comp(dwc_hc_t *_hc,
11134 + dwc_otg_hc_regs_t * _hc_regs, struct urb *_urb,
11135 + dwc_otg_qtd_t * _qtd, int *status)
11136 +{
11137 + int xfer_done = 0;
11138 + int short_read = 0;
11139 +
11140 + _urb->actual_length += get_actual_xfer_length(_hc, _hc_regs, _qtd,
11141 + DWC_OTG_HC_XFER_COMPLETE,
11142 + &short_read);
11143 +
11144 + if (short_read || (_urb->actual_length == _urb->transfer_buffer_length)) {
11145 + xfer_done = 1;
11146 + if (short_read && (_urb->transfer_flags & URB_SHORT_NOT_OK)) {
11147 + *status = -EREMOTEIO;
11148 + } else {
11149 + *status = 0;
11150 + }
11151 + }
11152 +
11153 +#ifdef DEBUG
11154 + {
11155 + hctsiz_data_t hctsiz;
11156 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11157 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
11158 + __func__, (_hc->ep_is_in ? "IN" : "OUT"), _hc->hc_num);
11159 + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", _hc->xfer_len);
11160 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n", hctsiz.b.xfersize);
11161 + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
11162 + _urb->transfer_buffer_length);
11163 + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n", _urb->actual_length);
11164 + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
11165 + short_read, xfer_done);
11166 + }
11167 +#endif
11168 +
11169 + return xfer_done;
11170 +}
11171 +
11172 +/*
11173 + * Save the starting data toggle for the next transfer. The data toggle is
11174 + * saved in the QH for non-control transfers and it's saved in the QTD for
11175 + * control transfers.
11176 + */
11177 +static void save_data_toggle(dwc_hc_t *_hc,
11178 + dwc_otg_hc_regs_t *_hc_regs,
11179 + dwc_otg_qtd_t *_qtd)
11180 +{
11181 + hctsiz_data_t hctsiz;
11182 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11183 +
11184 + if (_hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
11185 + dwc_otg_qh_t *qh = _hc->qh;
11186 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
11187 + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
11188 + } else {
11189 + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
11190 + }
11191 + } else {
11192 + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
11193 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
11194 + } else {
11195 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
11196 + }
11197 + }
11198 +}
11199 +
11200 +/**
11201 + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
11202 + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
11203 + * still linked to the QH, the QH is added to the end of the inactive
11204 + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
11205 + * schedule if no more QTDs are linked to the QH.
11206 + */
11207 +static void deactivate_qh(dwc_otg_hcd_t *_hcd,
11208 + dwc_otg_qh_t *_qh,
11209 + int free_qtd)
11210 +{
11211 + int continue_split = 0;
11212 + dwc_otg_qtd_t *qtd;
11213 +
11214 + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, _hcd, _qh, free_qtd);
11215 +
11216 + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
11217 +
11218 + if (qtd->complete_split) {
11219 + continue_split = 1;
11220 + }
11221 + else if ((qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID) ||
11222 + (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))
11223 + {
11224 + continue_split = 1;
11225 + }
11226 +
11227 + if (free_qtd) {
11228 + /*
11229 + * Note that this was previously a call to
11230 + * dwc_otg_hcd_qtd_remove_and_free(qtd), which frees the qtd.
11231 + * However, that call frees the qtd memory, and we continue in the
11232 + * interrupt logic to access it many more times, including writing
11233 + * to it. With slub debugging on, it is clear that we were writing
11234 + * to memory we had freed.
11235 + * Call this instead, and now I have moved the freeing of the memory to
11236 + * the end of processing this interrupt.
11237 + */
11238 + //dwc_otg_hcd_qtd_remove_and_free(qtd);
11239 + dwc_otg_hcd_qtd_remove(qtd);
11240 +
11241 + continue_split = 0;
11242 + }
11243 +
11244 + _qh->channel = NULL;
11245 + _qh->qtd_in_process = NULL;
11246 + dwc_otg_hcd_qh_deactivate(_hcd, _qh, continue_split);
11247 +}
11248 +
11249 +/**
11250 + * Updates the state of an Isochronous URB when the transfer is stopped for
11251 + * any reason. The fields of the current entry in the frame descriptor array
11252 + * are set based on the transfer state and the input _halt_status. Completes
11253 + * the Isochronous URB if all the URB frames have been completed.
11254 + *
11255 + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
11256 + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
11257 + */
11258 +static dwc_otg_halt_status_e
11259 +update_isoc_urb_state(dwc_otg_hcd_t *_hcd,
11260 + dwc_hc_t *_hc,
11261 + dwc_otg_hc_regs_t *_hc_regs,
11262 + dwc_otg_qtd_t *_qtd,
11263 + dwc_otg_halt_status_e _halt_status)
11264 +{
11265 + struct urb *urb = _qtd->urb;
11266 + dwc_otg_halt_status_e ret_val = _halt_status;
11267 + struct usb_iso_packet_descriptor *frame_desc;
11268 +
11269 + frame_desc = &urb->iso_frame_desc[_qtd->isoc_frame_index];
11270 + switch (_halt_status) {
11271 + case DWC_OTG_HC_XFER_COMPLETE:
11272 + frame_desc->status = 0;
11273 + frame_desc->actual_length =
11274 + get_actual_xfer_length(_hc, _hc_regs, _qtd,
11275 + _halt_status, NULL);
11276 + break;
11277 + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
11278 + urb->error_count++;
11279 + if (_hc->ep_is_in) {
11280 + frame_desc->status = -ENOSR;
11281 + } else {
11282 + frame_desc->status = -ECOMM;
11283 + }
11284 + frame_desc->actual_length = 0;
11285 + break;
11286 + case DWC_OTG_HC_XFER_BABBLE_ERR:
11287 + urb->error_count++;
11288 + frame_desc->status = -EOVERFLOW;
11289 + /* Don't need to update actual_length in this case. */
11290 + break;
11291 + case DWC_OTG_HC_XFER_XACT_ERR:
11292 + urb->error_count++;
11293 + frame_desc->status = -EPROTO;
11294 + frame_desc->actual_length =
11295 + get_actual_xfer_length(_hc, _hc_regs, _qtd,
11296 + _halt_status, NULL);
11297 + default:
11298 + DWC_ERROR("%s: Unhandled _halt_status (%d)\n", __func__,
11299 + _halt_status);
11300 + BUG();
11301 + break;
11302 + }
11303 +
11304 + if (++_qtd->isoc_frame_index == urb->number_of_packets) {
11305 + /*
11306 + * urb->status is not used for isoc transfers.
11307 + * The individual frame_desc statuses are used instead.
11308 + */
11309 + dwc_otg_hcd_complete_urb(_hcd, urb, 0);
11310 + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
11311 + } else {
11312 + ret_val = DWC_OTG_HC_XFER_COMPLETE;
11313 + }
11314 +
11315 + return ret_val;
11316 +}
11317 +
11318 +/**
11319 + * Releases a host channel for use by other transfers. Attempts to select and
11320 + * queue more transactions since at least one host channel is available.
11321 + *
11322 + * @param _hcd The HCD state structure.
11323 + * @param _hc The host channel to release.
11324 + * @param _qtd The QTD associated with the host channel. This QTD may be freed
11325 + * if the transfer is complete or an error has occurred.
11326 + * @param _halt_status Reason the channel is being released. This status
11327 + * determines the actions taken by this function.
11328 + */
11329 +static void release_channel(dwc_otg_hcd_t *_hcd,
11330 + dwc_hc_t *_hc,
11331 + dwc_otg_qtd_t *_qtd,
11332 + dwc_otg_halt_status_e _halt_status,
11333 + int *must_free)
11334 +{
11335 + dwc_otg_transaction_type_e tr_type;
11336 + int free_qtd;
11337 + dwc_otg_qh_t * _qh;
11338 + int deact = 1;
11339 + int retry_delay = 1;
11340 + unsigned long flags;
11341 +
11342 + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d\n", __func__,
11343 + _hc->hc_num, _halt_status);
11344 +
11345 + switch (_halt_status) {
11346 + case DWC_OTG_HC_XFER_NYET:
11347 + case DWC_OTG_HC_XFER_NAK:
11348 + if (_halt_status == DWC_OTG_HC_XFER_NYET) {
11349 + retry_delay = nyet_deferral_delay;
11350 + } else {
11351 + retry_delay = nak_deferral_delay;
11352 + }
11353 + free_qtd = 0;
11354 + if (deferral_on && _hc->do_split) {
11355 + _qh = _hc->qh;
11356 + if (_qh) {
11357 + deact = dwc_otg_hcd_qh_deferr(_hcd, _qh , retry_delay);
11358 + }
11359 + }
11360 + break;
11361 + case DWC_OTG_HC_XFER_URB_COMPLETE:
11362 + free_qtd = 1;
11363 + break;
11364 + case DWC_OTG_HC_XFER_AHB_ERR:
11365 + case DWC_OTG_HC_XFER_STALL:
11366 + case DWC_OTG_HC_XFER_BABBLE_ERR:
11367 + free_qtd = 1;
11368 + break;
11369 + case DWC_OTG_HC_XFER_XACT_ERR:
11370 + if (_qtd->error_count >= 3) {
11371 + DWC_DEBUGPL(DBG_HCDV, " Complete URB with transaction error\n");
11372 + free_qtd = 1;
11373 + //_qtd->urb->status = -EPROTO;
11374 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPROTO);
11375 + } else {
11376 + free_qtd = 0;
11377 + }
11378 + break;
11379 + case DWC_OTG_HC_XFER_URB_DEQUEUE:
11380 + /*
11381 + * The QTD has already been removed and the QH has been
11382 + * deactivated. Don't want to do anything except release the
11383 + * host channel and try to queue more transfers.
11384 + */
11385 + goto cleanup;
11386 + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
11387 + DWC_ERROR("%s: No halt_status, channel %d\n", __func__, _hc->hc_num);
11388 + free_qtd = 0;
11389 + break;
11390 + default:
11391 + free_qtd = 0;
11392 + break;
11393 + }
11394 + if (free_qtd) {
11395 + /* Only change must_free to true (do not set to zero here -- it is
11396 + * pre-initialized to zero).
11397 + */
11398 + *must_free = 1;
11399 + }
11400 + if (deact) {
11401 + deactivate_qh(_hcd, _hc->qh, free_qtd);
11402 + }
11403 + cleanup:
11404 + /*
11405 + * Release the host channel for use by other transfers. The cleanup
11406 + * function clears the channel interrupt enables and conditions, so
11407 + * there's no need to clear the Channel Halted interrupt separately.
11408 + */
11409 + dwc_otg_hc_cleanup(_hcd->core_if, _hc);
11410 + list_add_tail(&_hc->hc_list_entry, &_hcd->free_hc_list);
11411 +
11412 + local_irq_save(flags);
11413 + _hcd->available_host_channels++;
11414 + local_irq_restore(flags);
11415 + /* Try to queue more transfers now that there's a free channel, */
11416 + /* unless erratum_usb09_patched is set */
11417 + if (!erratum_usb09_patched) {
11418 + tr_type = dwc_otg_hcd_select_transactions(_hcd);
11419 + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
11420 + dwc_otg_hcd_queue_transactions(_hcd, tr_type);
11421 + }
11422 + }
11423 +}
11424 +
11425 +/**
11426 + * Halts a host channel. If the channel cannot be halted immediately because
11427 + * the request queue is full, this function ensures that the FIFO empty
11428 + * interrupt for the appropriate queue is enabled so that the halt request can
11429 + * be queued when there is space in the request queue.
11430 + *
11431 + * This function may also be called in DMA mode. In that case, the channel is
11432 + * simply released since the core always halts the channel automatically in
11433 + * DMA mode.
11434 + */
11435 +static void halt_channel(dwc_otg_hcd_t *_hcd,
11436 + dwc_hc_t *_hc,
11437 + dwc_otg_qtd_t *_qtd,
11438 + dwc_otg_halt_status_e _halt_status, int *must_free)
11439 +{
11440 + if (_hcd->core_if->dma_enable) {
11441 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11442 + return;
11443 + }
11444 +
11445 + /* Slave mode processing... */
11446 + dwc_otg_hc_halt(_hcd->core_if, _hc, _halt_status);
11447 +
11448 + if (_hc->halt_on_queue) {
11449 + gintmsk_data_t gintmsk = {.d32 = 0};
11450 + dwc_otg_core_global_regs_t *global_regs;
11451 + global_regs = _hcd->core_if->core_global_regs;
11452 +
11453 + if (_hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
11454 + _hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
11455 + /*
11456 + * Make sure the Non-periodic Tx FIFO empty interrupt
11457 + * is enabled so that the non-periodic schedule will
11458 + * be processed.
11459 + */
11460 + gintmsk.b.nptxfempty = 1;
11461 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
11462 + } else {
11463 + /*
11464 + * Move the QH from the periodic queued schedule to
11465 + * the periodic assigned schedule. This allows the
11466 + * halt to be queued when the periodic schedule is
11467 + * processed.
11468 + */
11469 + list_move(&_hc->qh->qh_list_entry,
11470 + &_hcd->periodic_sched_assigned);
11471 +
11472 + /*
11473 + * Make sure the Periodic Tx FIFO Empty interrupt is
11474 + * enabled so that the periodic schedule will be
11475 + * processed.
11476 + */
11477 + gintmsk.b.ptxfempty = 1;
11478 + dwc_modify_reg32(&global_regs->gintmsk, 0, gintmsk.d32);
11479 + }
11480 + }
11481 +}
11482 +
11483 +/**
11484 + * Performs common cleanup for non-periodic transfers after a Transfer
11485 + * Complete interrupt. This function should be called after any endpoint type
11486 + * specific handling is finished to release the host channel.
11487 + */
11488 +static void complete_non_periodic_xfer(dwc_otg_hcd_t *_hcd,
11489 + dwc_hc_t *_hc,
11490 + dwc_otg_hc_regs_t *_hc_regs,
11491 + dwc_otg_qtd_t *_qtd,
11492 + dwc_otg_halt_status_e _halt_status, int *must_free)
11493 +{
11494 + hcint_data_t hcint;
11495 +
11496 + _qtd->error_count = 0;
11497 +
11498 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
11499 + if (hcint.b.nyet) {
11500 + /*
11501 + * Got a NYET on the last transaction of the transfer. This
11502 + * means that the endpoint should be in the PING state at the
11503 + * beginning of the next transfer.
11504 + */
11505 + _hc->qh->ping_state = 1;
11506 + clear_hc_int(_hc_regs,nyet);
11507 + }
11508 +
11509 + /*
11510 + * Always halt and release the host channel to make it available for
11511 + * more transfers. There may still be more phases for a control
11512 + * transfer or more data packets for a bulk transfer at this point,
11513 + * but the host channel is still halted. A channel will be reassigned
11514 + * to the transfer when the non-periodic schedule is processed after
11515 + * the channel is released. This allows transactions to be queued
11516 + * properly via dwc_otg_hcd_queue_transactions, which also enables the
11517 + * Tx FIFO Empty interrupt if necessary.
11518 + */
11519 + if (_hc->ep_is_in) {
11520 + /*
11521 + * IN transfers in Slave mode require an explicit disable to
11522 + * halt the channel. (In DMA mode, this call simply releases
11523 + * the channel.)
11524 + */
11525 + halt_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11526 + } else {
11527 + /*
11528 + * The channel is automatically disabled by the core for OUT
11529 + * transfers in Slave mode.
11530 + */
11531 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11532 + }
11533 +}
11534 +
11535 +/**
11536 + * Performs common cleanup for periodic transfers after a Transfer Complete
11537 + * interrupt. This function should be called after any endpoint type specific
11538 + * handling is finished to release the host channel.
11539 + */
11540 +static void complete_periodic_xfer(dwc_otg_hcd_t *_hcd,
11541 + dwc_hc_t *_hc,
11542 + dwc_otg_hc_regs_t *_hc_regs,
11543 + dwc_otg_qtd_t *_qtd,
11544 + dwc_otg_halt_status_e _halt_status, int *must_free)
11545 +{
11546 + hctsiz_data_t hctsiz;
11547 + _qtd->error_count = 0;
11548 +
11549 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11550 + if (!_hc->ep_is_in || hctsiz.b.pktcnt == 0) {
11551 + /* Core halts channel in these cases. */
11552 + release_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11553 + } else {
11554 + /* Flush any outstanding requests from the Tx queue. */
11555 + halt_channel(_hcd, _hc, _qtd, _halt_status, must_free);
11556 + }
11557 +}
11558 +
11559 +/**
11560 + * Handles a host channel Transfer Complete interrupt. This handler may be
11561 + * called in either DMA mode or Slave mode.
11562 + */
11563 +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t *_hcd,
11564 + dwc_hc_t *_hc,
11565 + dwc_otg_hc_regs_t *_hc_regs,
11566 + dwc_otg_qtd_t *_qtd, int *must_free)
11567 +{
11568 + int urb_xfer_done;
11569 + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
11570 + struct urb *urb = _qtd->urb;
11571 + int pipe_type = usb_pipetype(urb->pipe);
11572 + int status = -EINPROGRESS;
11573 +
11574 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11575 + "Transfer Complete--\n", _hc->hc_num);
11576 +
11577 + /*
11578 + * Handle xfer complete on CSPLIT.
11579 + */
11580 + if (_hc->qh->do_split) {
11581 + _qtd->complete_split = 0;
11582 + }
11583 +
11584 + /* Update the QTD and URB states. */
11585 + switch (pipe_type) {
11586 + case PIPE_CONTROL:
11587 + switch (_qtd->control_phase) {
11588 + case DWC_OTG_CONTROL_SETUP:
11589 + if (urb->transfer_buffer_length > 0) {
11590 + _qtd->control_phase = DWC_OTG_CONTROL_DATA;
11591 + } else {
11592 + _qtd->control_phase = DWC_OTG_CONTROL_STATUS;
11593 + }
11594 + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
11595 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11596 + break;
11597 + case DWC_OTG_CONTROL_DATA: {
11598 + urb_xfer_done = update_urb_state_xfer_comp(_hc, _hc_regs,urb, _qtd, &status);
11599 + if (urb_xfer_done) {
11600 + _qtd->control_phase = DWC_OTG_CONTROL_STATUS;
11601 + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
11602 + } else {
11603 + save_data_toggle(_hc, _hc_regs, _qtd);
11604 + }
11605 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11606 + break;
11607 + }
11608 + case DWC_OTG_CONTROL_STATUS:
11609 + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
11610 + if (status == -EINPROGRESS) {
11611 + status = 0;
11612 + }
11613 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11614 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
11615 + break;
11616 + }
11617 +
11618 + complete_non_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,
11619 + halt_status, must_free);
11620 + break;
11621 + case PIPE_BULK:
11622 + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
11623 + urb_xfer_done = update_urb_state_xfer_comp(_hc, _hc_regs, urb, _qtd, &status);
11624 + if (urb_xfer_done) {
11625 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11626 + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
11627 + } else {
11628 + halt_status = DWC_OTG_HC_XFER_COMPLETE;
11629 + }
11630 +
11631 + save_data_toggle(_hc, _hc_regs, _qtd);
11632 + complete_non_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,halt_status, must_free);
11633 + break;
11634 + case PIPE_INTERRUPT:
11635 + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
11636 + update_urb_state_xfer_comp(_hc, _hc_regs, urb, _qtd, &status);
11637 +
11638 + /*
11639 + * Interrupt URB is done on the first transfer complete
11640 + * interrupt.
11641 + */
11642 + dwc_otg_hcd_complete_urb(_hcd, urb, status);
11643 + save_data_toggle(_hc, _hc_regs, _qtd);
11644 + complete_periodic_xfer(_hcd, _hc, _hc_regs, _qtd,
11645 + DWC_OTG_HC_XFER_URB_COMPLETE, must_free);
11646 + break;
11647 + case PIPE_ISOCHRONOUS:
11648 + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
11649 + if (_qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL)
11650 + {
11651 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
11652 + DWC_OTG_HC_XFER_COMPLETE);
11653 + }
11654 + complete_periodic_xfer(_hcd, _hc, _hc_regs, _qtd, halt_status, must_free);
11655 + break;
11656 + }
11657 +
11658 + disable_hc_int(_hc_regs,xfercompl);
11659 +
11660 + return 1;
11661 +}
11662 +
11663 +/**
11664 + * Handles a host channel STALL interrupt. This handler may be called in
11665 + * either DMA mode or Slave mode.
11666 + */
11667 +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t *_hcd,
11668 + dwc_hc_t *_hc,
11669 + dwc_otg_hc_regs_t *_hc_regs,
11670 + dwc_otg_qtd_t *_qtd, int *must_free)
11671 +{
11672 + struct urb *urb = _qtd->urb;
11673 + int pipe_type = usb_pipetype(urb->pipe);
11674 +
11675 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11676 + "STALL Received--\n", _hc->hc_num);
11677 +
11678 + if (pipe_type == PIPE_CONTROL) {
11679 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPIPE);
11680 + }
11681 +
11682 + if (pipe_type == PIPE_BULK || pipe_type == PIPE_INTERRUPT) {
11683 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EPIPE);
11684 + /*
11685 + * USB protocol requires resetting the data toggle for bulk
11686 + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
11687 + * setup command is issued to the endpoint. Anticipate the
11688 + * CLEAR_FEATURE command since a STALL has occurred and reset
11689 + * the data toggle now.
11690 + */
11691 + _hc->qh->data_toggle = 0;
11692 + }
11693 +
11694 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_STALL, must_free);
11695 + disable_hc_int(_hc_regs,stall);
11696 +
11697 + return 1;
11698 +}
11699 +
11700 +/*
11701 + * Updates the state of the URB when a transfer has been stopped due to an
11702 + * abnormal condition before the transfer completes. Modifies the
11703 + * actual_length field of the URB to reflect the number of bytes that have
11704 + * actually been transferred via the host channel.
11705 + */
11706 +static void update_urb_state_xfer_intr(dwc_hc_t *_hc,
11707 + dwc_otg_hc_regs_t *_hc_regs,
11708 + struct urb *_urb,
11709 + dwc_otg_qtd_t *_qtd,
11710 + dwc_otg_halt_status_e _halt_status)
11711 +{
11712 + uint32_t bytes_transferred = get_actual_xfer_length(_hc, _hc_regs, _qtd,
11713 + _halt_status, NULL);
11714 + _urb->actual_length += bytes_transferred;
11715 +
11716 +#ifdef DEBUG
11717 + {
11718 + hctsiz_data_t hctsiz;
11719 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
11720 + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
11721 + __func__, (_hc->ep_is_in ? "IN" : "OUT"), _hc->hc_num);
11722 + DWC_DEBUGPL(DBG_HCDV, " _hc->start_pkt_count %d\n", _hc->start_pkt_count);
11723 + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
11724 + DWC_DEBUGPL(DBG_HCDV, " _hc->max_packet %d\n", _hc->max_packet);
11725 + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n", bytes_transferred);
11726 + DWC_DEBUGPL(DBG_HCDV, " _urb->actual_length %d\n", _urb->actual_length);
11727 + DWC_DEBUGPL(DBG_HCDV, " _urb->transfer_buffer_length %d\n",
11728 + _urb->transfer_buffer_length);
11729 + }
11730 +#endif
11731 +}
11732 +
11733 +/**
11734 + * Handles a host channel NAK interrupt. This handler may be called in either
11735 + * DMA mode or Slave mode.
11736 + */
11737 +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t *_hcd,
11738 + dwc_hc_t *_hc,
11739 + dwc_otg_hc_regs_t *_hc_regs,
11740 + dwc_otg_qtd_t *_qtd, int *must_free)
11741 +{
11742 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11743 + "NAK Received--\n", _hc->hc_num);
11744 +
11745 + /*
11746 + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
11747 + * interrupt. Re-start the SSPLIT transfer.
11748 + */
11749 + if (_hc->do_split) {
11750 + if (_hc->complete_split) {
11751 + _qtd->error_count = 0;
11752 + }
11753 + _qtd->complete_split = 0;
11754 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11755 + goto handle_nak_done;
11756 + }
11757 +
11758 + switch (usb_pipetype(_qtd->urb->pipe)) {
11759 + case PIPE_CONTROL:
11760 + case PIPE_BULK:
11761 + if (_hcd->core_if->dma_enable && _hc->ep_is_in) {
11762 + /*
11763 + * NAK interrupts are enabled on bulk/control IN
11764 + * transfers in DMA mode for the sole purpose of
11765 + * resetting the error count after a transaction error
11766 + * occurs. The core will continue transferring data.
11767 + */
11768 + _qtd->error_count = 0;
11769 + goto handle_nak_done;
11770 + }
11771 +
11772 + /*
11773 + * NAK interrupts normally occur during OUT transfers in DMA
11774 + * or Slave mode. For IN transfers, more requests will be
11775 + * queued as request queue space is available.
11776 + */
11777 + _qtd->error_count = 0;
11778 +
11779 + if (!_hc->qh->ping_state) {
11780 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb,
11781 + _qtd, DWC_OTG_HC_XFER_NAK);
11782 + save_data_toggle(_hc, _hc_regs, _qtd);
11783 + if (_qtd->urb->dev->speed == USB_SPEED_HIGH) {
11784 + _hc->qh->ping_state = 1;
11785 + }
11786 + }
11787 +
11788 + /*
11789 + * Halt the channel so the transfer can be re-started from
11790 + * the appropriate point or the PING protocol will
11791 + * start/continue.
11792 + */
11793 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11794 + break;
11795 + case PIPE_INTERRUPT:
11796 + _qtd->error_count = 0;
11797 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NAK, must_free);
11798 + break;
11799 + case PIPE_ISOCHRONOUS:
11800 + /* Should never get called for isochronous transfers. */
11801 + BUG();
11802 + break;
11803 + }
11804 +
11805 + handle_nak_done:
11806 + disable_hc_int(_hc_regs,nak);
11807 +
11808 + return 1;
11809 +}
11810 +
11811 +/**
11812 + * Handles a host channel ACK interrupt. This interrupt is enabled when
11813 + * performing the PING protocol in Slave mode, when errors occur during
11814 + * either Slave mode or DMA mode, and during Start Split transactions.
11815 + */
11816 +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t *_hcd,
11817 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
11818 +{
11819 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11820 + "ACK Received--\n", _hc->hc_num);
11821 +
11822 + if (_hc->do_split) {
11823 + /*
11824 + * Handle ACK on SSPLIT.
11825 + * ACK should not occur in CSPLIT.
11826 + */
11827 + if ((!_hc->ep_is_in) && (_hc->data_pid_start != DWC_OTG_HC_PID_SETUP)) {
11828 + _qtd->ssplit_out_xfer_count = _hc->xfer_len;
11829 + }
11830 + if (!(_hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !_hc->ep_is_in)) {
11831 + /* Don't need complete for isochronous out transfers. */
11832 + _qtd->complete_split = 1;
11833 + }
11834 +
11835 + /* ISOC OUT */
11836 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && !_hc->ep_is_in) {
11837 + switch (_hc->xact_pos) {
11838 + case DWC_HCSPLIT_XACTPOS_ALL:
11839 + break;
11840 + case DWC_HCSPLIT_XACTPOS_END:
11841 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
11842 + _qtd->isoc_split_offset = 0;
11843 + break;
11844 + case DWC_HCSPLIT_XACTPOS_BEGIN:
11845 + case DWC_HCSPLIT_XACTPOS_MID:
11846 + /*
11847 + * For BEGIN or MID, calculate the length for
11848 + * the next microframe to determine the correct
11849 + * SSPLIT token, either MID or END.
11850 + */
11851 + do {
11852 + struct usb_iso_packet_descriptor *frame_desc;
11853 +
11854 + frame_desc = &_qtd->urb->iso_frame_desc[_qtd->isoc_frame_index];
11855 + _qtd->isoc_split_offset += 188;
11856 +
11857 + if ((frame_desc->length - _qtd->isoc_split_offset) <= 188) {
11858 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_END;
11859 + }
11860 + else {
11861 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_MID;
11862 + }
11863 +
11864 + } while(0);
11865 + break;
11866 + }
11867 + } else {
11868 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_ACK, must_free);
11869 + }
11870 + } else {
11871 + _qtd->error_count = 0;
11872 +
11873 + if (_hc->qh->ping_state) {
11874 + _hc->qh->ping_state = 0;
11875 + /*
11876 + * Halt the channel so the transfer can be re-started
11877 + * from the appropriate point. This only happens in
11878 + * Slave mode. In DMA mode, the ping_state is cleared
11879 + * when the transfer is started because the core
11880 + * automatically executes the PING, then the transfer.
11881 + */
11882 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_ACK, must_free);
11883 + } else {
11884 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
11885 + }
11886 + }
11887 +
11888 + /*
11889 + * If the ACK occurred when _not_ in the PING state, let the channel
11890 + * continue transferring data after clearing the error count.
11891 + */
11892 +
11893 + disable_hc_int(_hc_regs,ack);
11894 +
11895 + return 1;
11896 +}
11897 +
11898 +/**
11899 + * Handles a host channel NYET interrupt. This interrupt should only occur on
11900 + * Bulk and Control OUT endpoints and for complete split transactions. If a
11901 + * NYET occurs at the same time as a Transfer Complete interrupt, it is
11902 + * handled in the xfercomp interrupt handler, not here. This handler may be
11903 + * called in either DMA mode or Slave mode.
11904 + */
11905 +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t *_hcd,
11906 + dwc_hc_t *_hc,
11907 + dwc_otg_hc_regs_t *_hc_regs,
11908 + dwc_otg_qtd_t *_qtd, int *must_free)
11909 +{
11910 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11911 + "NYET Received--\n", _hc->hc_num);
11912 +
11913 + /*
11914 + * NYET on CSPLIT
11915 + * re-do the CSPLIT immediately on non-periodic
11916 + */
11917 + if ((_hc->do_split) && (_hc->complete_split)) {
11918 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_INTR) ||
11919 + (_hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
11920 + int frnum = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
11921 +
11922 + if (dwc_full_frame_num(frnum) !=
11923 + dwc_full_frame_num(_hc->qh->sched_frame)) {
11924 + /*
11925 + * No longer in the same full speed frame.
11926 + * Treat this as a transaction error.
11927 + */
11928 +#if 0
11929 + /** @todo Fix system performance so this can
11930 + * be treated as an error. Right now complete
11931 + * splits cannot be scheduled precisely enough
11932 + * due to other system activity, so this error
11933 + * occurs regularly in Slave mode.
11934 + */
11935 + _qtd->error_count++;
11936 +#endif
11937 + _qtd->complete_split = 0;
11938 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
11939 + /** @todo add support for isoc release */
11940 + goto handle_nyet_done;
11941 + }
11942 + }
11943 +
11944 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NYET, must_free);
11945 + goto handle_nyet_done;
11946 + }
11947 +
11948 + _hc->qh->ping_state = 1;
11949 + _qtd->error_count = 0;
11950 +
11951 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb, _qtd,
11952 + DWC_OTG_HC_XFER_NYET);
11953 + save_data_toggle(_hc, _hc_regs, _qtd);
11954 +
11955 + /*
11956 + * Halt the channel and re-start the transfer so the PING
11957 + * protocol will start.
11958 + */
11959 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_NYET, must_free);
11960 +
11961 +handle_nyet_done:
11962 + disable_hc_int(_hc_regs,nyet);
11963 + clear_hc_int(_hc_regs, nyet);
11964 + return 1;
11965 +}
11966 +
11967 +/**
11968 + * Handles a host channel babble interrupt. This handler may be called in
11969 + * either DMA mode or Slave mode.
11970 + */
11971 +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t *_hcd,
11972 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
11973 +{
11974 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
11975 + "Babble Error--\n", _hc->hc_num);
11976 + if (_hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
11977 + dwc_otg_hcd_complete_urb(_hcd, _qtd->urb, -EOVERFLOW);
11978 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_BABBLE_ERR, must_free);
11979 + } else {
11980 + dwc_otg_halt_status_e halt_status;
11981 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
11982 + DWC_OTG_HC_XFER_BABBLE_ERR);
11983 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
11984 + }
11985 + disable_hc_int(_hc_regs,bblerr);
11986 + return 1;
11987 +}
11988 +
11989 +/**
11990 + * Handles a host channel AHB error interrupt. This handler is only called in
11991 + * DMA mode.
11992 + */
11993 +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t *_hcd,
11994 + dwc_hc_t *_hc,
11995 + dwc_otg_hc_regs_t *_hc_regs,
11996 + dwc_otg_qtd_t *_qtd)
11997 +{
11998 + hcchar_data_t hcchar;
11999 + hcsplt_data_t hcsplt;
12000 + hctsiz_data_t hctsiz;
12001 + uint32_t hcdma;
12002 + struct urb *urb = _qtd->urb;
12003 +
12004 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12005 + "AHB Error--\n", _hc->hc_num);
12006 +
12007 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12008 + hcsplt.d32 = dwc_read_reg32(&_hc_regs->hcsplt);
12009 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
12010 + hcdma = dwc_read_reg32(&_hc_regs->hcdma);
12011 +
12012 + DWC_ERROR("AHB ERROR, Channel %d\n", _hc->hc_num);
12013 + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
12014 + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
12015 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
12016 + DWC_ERROR(" Device address: %d\n", usb_pipedevice(urb->pipe));
12017 + DWC_ERROR(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
12018 + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
12019 + DWC_ERROR(" Endpoint type: %s\n",
12020 + ({char *pipetype;
12021 + switch (usb_pipetype(urb->pipe)) {
12022 + case PIPE_CONTROL: pipetype = "CONTROL"; break;
12023 + case PIPE_BULK: pipetype = "BULK"; break;
12024 + case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
12025 + case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
12026 + default: pipetype = "UNKNOWN"; break;
12027 + }; pipetype;}));
12028 + DWC_ERROR(" Speed: %s\n",
12029 + ({char *speed;
12030 + switch (urb->dev->speed) {
12031 + case USB_SPEED_HIGH: speed = "HIGH"; break;
12032 + case USB_SPEED_FULL: speed = "FULL"; break;
12033 + case USB_SPEED_LOW: speed = "LOW"; break;
12034 + default: speed = "UNKNOWN"; break;
12035 + }; speed;}));
12036 + DWC_ERROR(" Max packet size: %d\n",
12037 + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
12038 + DWC_ERROR(" Data buffer length: %d\n", urb->transfer_buffer_length);
12039 + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
12040 + urb->transfer_buffer, (void *)(u32)urb->transfer_dma);
12041 + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
12042 + urb->setup_packet, (void *)(u32)urb->setup_dma);
12043 + DWC_ERROR(" Interval: %d\n", urb->interval);
12044 +
12045 + dwc_otg_hcd_complete_urb(_hcd, urb, -EIO);
12046 +
12047 + /*
12048 + * Force a channel halt. Don't call halt_channel because that won't
12049 + * write to the HCCHARn register in DMA mode to force the halt.
12050 + */
12051 + dwc_otg_hc_halt(_hcd->core_if, _hc, DWC_OTG_HC_XFER_AHB_ERR);
12052 +
12053 + disable_hc_int(_hc_regs,ahberr);
12054 + return 1;
12055 +}
12056 +
12057 +/**
12058 + * Handles a host channel transaction error interrupt. This handler may be
12059 + * called in either DMA mode or Slave mode.
12060 + */
12061 +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t *_hcd,
12062 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12063 +{
12064 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12065 + "Transaction Error--\n", _hc->hc_num);
12066 +
12067 + switch (usb_pipetype(_qtd->urb->pipe)) {
12068 + case PIPE_CONTROL:
12069 + case PIPE_BULK:
12070 + _qtd->error_count++;
12071 + if (!_hc->qh->ping_state) {
12072 + update_urb_state_xfer_intr(_hc, _hc_regs, _qtd->urb,
12073 + _qtd, DWC_OTG_HC_XFER_XACT_ERR);
12074 + save_data_toggle(_hc, _hc_regs, _qtd);
12075 + if (!_hc->ep_is_in && _qtd->urb->dev->speed == USB_SPEED_HIGH) {
12076 + _hc->qh->ping_state = 1;
12077 + }
12078 + }
12079 +
12080 + /*
12081 + * Halt the channel so the transfer can be re-started from
12082 + * the appropriate point or the PING protocol will start.
12083 + */
12084 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
12085 + break;
12086 + case PIPE_INTERRUPT:
12087 + _qtd->error_count++;
12088 + if ((_hc->do_split) && (_hc->complete_split)) {
12089 + _qtd->complete_split = 0;
12090 + }
12091 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_XACT_ERR, must_free);
12092 + break;
12093 + case PIPE_ISOCHRONOUS:
12094 + {
12095 + dwc_otg_halt_status_e halt_status;
12096 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
12097 + DWC_OTG_HC_XFER_XACT_ERR);
12098 +
12099 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
12100 + }
12101 + break;
12102 + }
12103 +
12104 +
12105 + disable_hc_int(_hc_regs,xacterr);
12106 +
12107 + return 1;
12108 +}
12109 +
12110 +/**
12111 + * Handles a host channel frame overrun interrupt. This handler may be called
12112 + * in either DMA mode or Slave mode.
12113 + */
12114 +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t *_hcd,
12115 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12116 +{
12117 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12118 + "Frame Overrun--\n", _hc->hc_num);
12119 +
12120 + switch (usb_pipetype(_qtd->urb->pipe)) {
12121 + case PIPE_CONTROL:
12122 + case PIPE_BULK:
12123 + break;
12124 + case PIPE_INTERRUPT:
12125 + halt_channel(_hcd, _hc, _qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN, must_free);
12126 + break;
12127 + case PIPE_ISOCHRONOUS:
12128 + {
12129 + dwc_otg_halt_status_e halt_status;
12130 + halt_status = update_isoc_urb_state(_hcd, _hc, _hc_regs, _qtd,
12131 + DWC_OTG_HC_XFER_FRAME_OVERRUN);
12132 +
12133 + halt_channel(_hcd, _hc, _qtd, halt_status, must_free);
12134 + }
12135 + break;
12136 + }
12137 +
12138 + disable_hc_int(_hc_regs,frmovrun);
12139 +
12140 + return 1;
12141 +}
12142 +
12143 +/**
12144 + * Handles a host channel data toggle error interrupt. This handler may be
12145 + * called in either DMA mode or Slave mode.
12146 + */
12147 +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t *_hcd,
12148 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12149 +{
12150 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12151 + "Data Toggle Error--\n", _hc->hc_num);
12152 +
12153 + if (_hc->ep_is_in) {
12154 + _qtd->error_count = 0;
12155 + } else {
12156 + DWC_ERROR("Data Toggle Error on OUT transfer,"
12157 + "channel %d\n", _hc->hc_num);
12158 + }
12159 +
12160 + disable_hc_int(_hc_regs,datatglerr);
12161 +
12162 + return 1;
12163 +}
12164 +
12165 +#ifdef DEBUG
12166 +/**
12167 + * This function is for debug only. It checks that a valid halt status is set
12168 + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
12169 + * taken and a warning is issued.
12170 + * @return 1 if halt status is ok, 0 otherwise.
12171 + */
12172 +static inline int halt_status_ok(dwc_otg_hcd_t *_hcd,
12173 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12174 +{
12175 + hcchar_data_t hcchar;
12176 + hctsiz_data_t hctsiz;
12177 + hcint_data_t hcint;
12178 + hcintmsk_data_t hcintmsk;
12179 + hcsplt_data_t hcsplt;
12180 +
12181 + if (_hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
12182 + /*
12183 + * This code is here only as a check. This condition should
12184 + * never happen. Ignore the halt if it does occur.
12185 + */
12186 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12187 + hctsiz.d32 = dwc_read_reg32(&_hc_regs->hctsiz);
12188 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
12189 + hcintmsk.d32 = dwc_read_reg32(&_hc_regs->hcintmsk);
12190 + hcsplt.d32 = dwc_read_reg32(&_hc_regs->hcsplt);
12191 + DWC_WARN("%s: _hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
12192 + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
12193 + "hcint 0x%08x, hcintmsk 0x%08x, "
12194 + "hcsplt 0x%08x, qtd->complete_split %d\n",
12195 + __func__, _hc->hc_num, hcchar.d32, hctsiz.d32,
12196 + hcint.d32, hcintmsk.d32,
12197 + hcsplt.d32, _qtd->complete_split);
12198 +
12199 + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
12200 + __func__, _hc->hc_num);
12201 + DWC_WARN("\n");
12202 + clear_hc_int(_hc_regs,chhltd);
12203 + return 0;
12204 + }
12205 +
12206 + /*
12207 + * This code is here only as a check. hcchar.chdis should
12208 + * never be set when the halt interrupt occurs. Halt the
12209 + * channel again if it does occur.
12210 + */
12211 + hcchar.d32 = dwc_read_reg32(&_hc_regs->hcchar);
12212 + if (hcchar.b.chdis) {
12213 + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
12214 + "hcchar 0x%08x, trying to halt again\n",
12215 + __func__, hcchar.d32);
12216 + clear_hc_int(_hc_regs,chhltd);
12217 + _hc->halt_pending = 0;
12218 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12219 + return 0;
12220 + }
12221 +
12222 + return 1;
12223 +}
12224 +#endif
12225 +
12226 +/**
12227 + * Handles a host Channel Halted interrupt in DMA mode. This handler
12228 + * determines the reason the channel halted and proceeds accordingly.
12229 + */
12230 +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t *_hcd,
12231 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12232 +{
12233 + hcint_data_t hcint;
12234 + hcintmsk_data_t hcintmsk;
12235 +
12236 + if (_hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
12237 + _hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
12238 + /*
12239 + * Just release the channel. A dequeue can happen on a
12240 + * transfer timeout. In the case of an AHB Error, the channel
12241 + * was forced to halt because there's no way to gracefully
12242 + * recover.
12243 + */
12244 + release_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12245 + return;
12246 + }
12247 +
12248 + /* Read the HCINTn register to determine the cause for the halt. */
12249 + hcint.d32 = dwc_read_reg32(&_hc_regs->hcint);
12250 + hcintmsk.d32 = dwc_read_reg32(&_hc_regs->hcintmsk);
12251 +
12252 + if (hcint.b.xfercomp) {
12253 + /** @todo This is here because of a possible hardware bug. Spec
12254 + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
12255 + * interrupt w/ACK bit set should occur, but I only see the
12256 + * XFERCOMP bit, even with it masked out. This is a workaround
12257 + * for that behavior. Should fix this when hardware is fixed.
12258 + */
12259 + if ((_hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!_hc->ep_is_in)) {
12260 + handle_hc_ack_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12261 + }
12262 + handle_hc_xfercomp_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12263 + } else if (hcint.b.stall) {
12264 + handle_hc_stall_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12265 + } else if (hcint.b.xacterr) {
12266 + /*
12267 + * Must handle xacterr before nak or ack. Could get a xacterr
12268 + * at the same time as either of these on a BULK/CONTROL OUT
12269 + * that started with a PING. The xacterr takes precedence.
12270 + */
12271 + handle_hc_xacterr_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12272 + } else if (hcint.b.nyet) {
12273 + /*
12274 + * Must handle nyet before nak or ack. Could get a nyet at the
12275 + * same time as either of those on a BULK/CONTROL OUT that
12276 + * started with a PING. The nyet takes precedence.
12277 + */
12278 + handle_hc_nyet_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12279 + } else if (hcint.b.bblerr) {
12280 + handle_hc_babble_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12281 + } else if (hcint.b.frmovrun) {
12282 + handle_hc_frmovrun_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12283 + } else if (hcint.b.datatglerr) {
12284 + handle_hc_datatglerr_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12285 + _hc->qh->data_toggle = 0;
12286 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12287 + } else if (hcint.b.nak && !hcintmsk.b.nak) {
12288 + /*
12289 + * If nak is not masked, it's because a non-split IN transfer
12290 + * is in an error state. In that case, the nak is handled by
12291 + * the nak interrupt handler, not here. Handle nak here for
12292 + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
12293 + * rewinding the buffer pointer.
12294 + */
12295 + handle_hc_nak_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12296 + } else if (hcint.b.ack && !hcintmsk.b.ack) {
12297 + /*
12298 + * If ack is not masked, it's because a non-split IN transfer
12299 + * is in an error state. In that case, the ack is handled by
12300 + * the ack interrupt handler, not here. Handle ack here for
12301 + * split transfers. Start splits halt on ACK.
12302 + */
12303 + handle_hc_ack_intr(_hcd, _hc, _hc_regs, _qtd, must_free);
12304 + } else {
12305 + if (_hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
12306 + _hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
12307 + /*
12308 + * A periodic transfer halted with no other channel
12309 + * interrupts set. Assume it was halted by the core
12310 + * because it could not be completed in its scheduled
12311 + * (micro)frame.
12312 + */
12313 +#ifdef DEBUG
12314 + DWC_PRINT("%s: Halt channel %d (assume incomplete periodic transfer)\n",
12315 + __func__, _hc->hc_num);
12316 +#endif /* */
12317 + halt_channel(_hcd, _hc, _qtd,
12318 + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE, must_free);
12319 + } else {
12320 +#ifdef DEBUG
12321 + DWC_ERROR("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
12322 + "for halting is unknown, nyet %d, hcint 0x%08x, intsts 0x%08x\n",
12323 + __func__, _hc->hc_num, hcint.b.nyet, hcint.d32,
12324 + dwc_read_reg32(&_hcd->core_if->core_global_regs->gintsts));
12325 +#endif
12326 + halt_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12327 + }
12328 + }
12329 +}
12330 +
12331 +/**
12332 + * Handles a host channel Channel Halted interrupt.
12333 + *
12334 + * In slave mode, this handler is called only when the driver specifically
12335 + * requests a halt. This occurs during handling other host channel interrupts
12336 + * (e.g. nak, xacterr, stall, nyet, etc.).
12337 + *
12338 + * In DMA mode, this is the interrupt that occurs when the core has finished
12339 + * processing a transfer on a channel. Other host channel interrupts (except
12340 + * ahberr) are disabled in DMA mode.
12341 + */
12342 +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t *_hcd,
12343 + dwc_hc_t * _hc, dwc_otg_hc_regs_t * _hc_regs, dwc_otg_qtd_t * _qtd, int *must_free)
12344 +{
12345 + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
12346 + "Channel Halted--\n", _hc->hc_num);
12347 +
12348 + if (_hcd->core_if->dma_enable) {
12349 + handle_hc_chhltd_intr_dma(_hcd, _hc, _hc_regs, _qtd, must_free);
12350 + } else {
12351 +#ifdef DEBUG
12352 + if (!halt_status_ok(_hcd, _hc, _hc_regs, _qtd, must_free)) {
12353 + return 1;
12354 + }
12355 +#endif /* */
12356 + release_channel(_hcd, _hc, _qtd, _hc->halt_status, must_free);
12357 + }
12358 +
12359 + return 1;
12360 +}
12361 +
12362 +/** Handles interrupt for a specific Host Channel */
12363 +int32_t dwc_otg_hcd_handle_hc_n_intr (dwc_otg_hcd_t *_dwc_otg_hcd, uint32_t _num)
12364 +{
12365 + int must_free = 0;
12366 + int retval = 0;
12367 + hcint_data_t hcint;
12368 + hcintmsk_data_t hcintmsk;
12369 + dwc_hc_t *hc;
12370 + dwc_otg_hc_regs_t *hc_regs;
12371 + dwc_otg_qtd_t *qtd;
12372 +
12373 + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", _num);
12374 +
12375 + hc = _dwc_otg_hcd->hc_ptr_array[_num];
12376 + hc_regs = _dwc_otg_hcd->core_if->host_if->hc_regs[_num];
12377 + qtd = list_entry(hc->qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
12378 +
12379 + hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
12380 + hcintmsk.d32 = dwc_read_reg32(&hc_regs->hcintmsk);
12381 + DWC_DEBUGPL(DBG_HCDV, " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
12382 + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
12383 + hcint.d32 = hcint.d32 & hcintmsk.d32;
12384 +
12385 + if (!_dwc_otg_hcd->core_if->dma_enable) {
12386 + if ((hcint.b.chhltd) && (hcint.d32 != 0x2)) {
12387 + hcint.b.chhltd = 0;
12388 + }
12389 + }
12390 +
12391 + if (hcint.b.xfercomp) {
12392 + retval |= handle_hc_xfercomp_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12393 + /*
12394 + * If NYET occurred at same time as Xfer Complete, the NYET is
12395 + * handled by the Xfer Complete interrupt handler. Don't want
12396 + * to call the NYET interrupt handler in this case.
12397 + */
12398 + hcint.b.nyet = 0;
12399 + }
12400 + if (hcint.b.chhltd) {
12401 + retval |= handle_hc_chhltd_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12402 + }
12403 + if (hcint.b.ahberr) {
12404 + retval |= handle_hc_ahberr_intr(_dwc_otg_hcd, hc, hc_regs, qtd);
12405 + }
12406 + if (hcint.b.stall) {
12407 + retval |= handle_hc_stall_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12408 + }
12409 + if (hcint.b.nak) {
12410 + retval |= handle_hc_nak_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12411 + }
12412 + if (hcint.b.ack) {
12413 + retval |= handle_hc_ack_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12414 + }
12415 + if (hcint.b.nyet) {
12416 + retval |= handle_hc_nyet_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12417 + }
12418 + if (hcint.b.xacterr) {
12419 + retval |= handle_hc_xacterr_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12420 + }
12421 + if (hcint.b.bblerr) {
12422 + retval |= handle_hc_babble_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12423 + }
12424 + if (hcint.b.frmovrun) {
12425 + retval |= handle_hc_frmovrun_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12426 + }
12427 + if (hcint.b.datatglerr) {
12428 + retval |= handle_hc_datatglerr_intr(_dwc_otg_hcd, hc, hc_regs, qtd, &must_free);
12429 + }
12430 +
12431 + /*
12432 + * Logic to free the qtd here, at the end of the hc intr
12433 + * processing, if the handling of this interrupt determined
12434 + * that it needs to be freed.
12435 + */
12436 + if (must_free) {
12437 + /* Free the qtd here now that we are done using it. */
12438 + dwc_otg_hcd_qtd_free(qtd);
12439 + }
12440 + return retval;
12441 +}
12442 +
12443 +#endif /* DWC_DEVICE_ONLY */
12444 --- /dev/null
12445 +++ b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
12446 @@ -0,0 +1,794 @@
12447 +/* ==========================================================================
12448 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd_queue.c $
12449 + * $Revision: 1.1.1.1 $
12450 + * $Date: 2009-04-17 06:15:34 $
12451 + * $Change: 537387 $
12452 + *
12453 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
12454 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
12455 + * otherwise expressly agreed to in writing between Synopsys and you.
12456 + *
12457 + * The Software IS NOT an item of Licensed Software or Licensed Product under
12458 + * any End User Software License Agreement or Agreement for Licensed Product
12459 + * with Synopsys or any supplement thereto. You are permitted to use and
12460 + * redistribute this Software in source and binary forms, with or without
12461 + * modification, provided that redistributions of source code must retain this
12462 + * notice. You may not view, use, disclose, copy or distribute this file or
12463 + * any information contained herein except pursuant to this license grant from
12464 + * Synopsys. If you do not agree with this notice, including the disclaimer
12465 + * below, then you are not authorized to use the Software.
12466 + *
12467 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
12468 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12469 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
12470 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
12471 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
12472 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12473 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
12474 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
12475 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
12476 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
12477 + * DAMAGE.
12478 + * ========================================================================== */
12479 +#ifndef DWC_DEVICE_ONLY
12480 +
12481 +/**
12482 + * @file
12483 + *
12484 + * This file contains the functions to manage Queue Heads and Queue
12485 + * Transfer Descriptors.
12486 + */
12487 +#include <linux/kernel.h>
12488 +#include <linux/module.h>
12489 +#include <linux/moduleparam.h>
12490 +#include <linux/init.h>
12491 +#include <linux/device.h>
12492 +#include <linux/errno.h>
12493 +#include <linux/list.h>
12494 +#include <linux/interrupt.h>
12495 +#include <linux/string.h>
12496 +
12497 +#include "dwc_otg_driver.h"
12498 +#include "dwc_otg_hcd.h"
12499 +#include "dwc_otg_regs.h"
12500 +
12501 +/**
12502 + * This function allocates and initializes a QH.
12503 + *
12504 + * @param _hcd The HCD state structure for the DWC OTG controller.
12505 + * @param[in] _urb Holds the information about the device/endpoint that we need
12506 + * to initialize the QH.
12507 + *
12508 + * @return Returns pointer to the newly allocated QH, or NULL on error. */
12509 +dwc_otg_qh_t *dwc_otg_hcd_qh_create (dwc_otg_hcd_t *_hcd, struct urb *_urb)
12510 +{
12511 + dwc_otg_qh_t *qh;
12512 +
12513 + /* Allocate memory */
12514 + /** @todo add memflags argument */
12515 + qh = dwc_otg_hcd_qh_alloc ();
12516 + if (qh == NULL) {
12517 + return NULL;
12518 + }
12519 +
12520 + dwc_otg_hcd_qh_init (_hcd, qh, _urb);
12521 + return qh;
12522 +}
12523 +
12524 +/** Free each QTD in the QH's QTD-list then free the QH. QH should already be
12525 + * removed from a list. QTD list should already be empty if called from URB
12526 + * Dequeue.
12527 + *
12528 + * @param[in] _qh The QH to free.
12529 + */
12530 +void dwc_otg_hcd_qh_free (dwc_otg_qh_t *_qh)
12531 +{
12532 + dwc_otg_qtd_t *qtd;
12533 + struct list_head *pos;
12534 + unsigned long flags;
12535 +
12536 + /* Free each QTD in the QTD list */
12537 + local_irq_save (flags);
12538 + for (pos = _qh->qtd_list.next;
12539 + pos != &_qh->qtd_list;
12540 + pos = _qh->qtd_list.next)
12541 + {
12542 + list_del (pos);
12543 + qtd = dwc_list_to_qtd (pos);
12544 + dwc_otg_hcd_qtd_free (qtd);
12545 + }
12546 + local_irq_restore (flags);
12547 +
12548 + kfree (_qh);
12549 + return;
12550 +}
12551 +
12552 +/** Initializes a QH structure.
12553 + *
12554 + * @param[in] _hcd The HCD state structure for the DWC OTG controller.
12555 + * @param[in] _qh The QH to init.
12556 + * @param[in] _urb Holds the information about the device/endpoint that we need
12557 + * to initialize the QH. */
12558 +#define SCHEDULE_SLOP 10
12559 +void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, struct urb *_urb)
12560 +{
12561 + memset (_qh, 0, sizeof (dwc_otg_qh_t));
12562 +
12563 + /* Initialize QH */
12564 + switch (usb_pipetype(_urb->pipe)) {
12565 + case PIPE_CONTROL:
12566 + _qh->ep_type = USB_ENDPOINT_XFER_CONTROL;
12567 + break;
12568 + case PIPE_BULK:
12569 + _qh->ep_type = USB_ENDPOINT_XFER_BULK;
12570 + break;
12571 + case PIPE_ISOCHRONOUS:
12572 + _qh->ep_type = USB_ENDPOINT_XFER_ISOC;
12573 + break;
12574 + case PIPE_INTERRUPT:
12575 + _qh->ep_type = USB_ENDPOINT_XFER_INT;
12576 + break;
12577 + }
12578 +
12579 + _qh->ep_is_in = usb_pipein(_urb->pipe) ? 1 : 0;
12580 +
12581 + _qh->data_toggle = DWC_OTG_HC_PID_DATA0;
12582 + _qh->maxp = usb_maxpacket(_urb->dev, _urb->pipe, !(usb_pipein(_urb->pipe)));
12583 + INIT_LIST_HEAD(&_qh->qtd_list);
12584 + INIT_LIST_HEAD(&_qh->qh_list_entry);
12585 + _qh->channel = NULL;
12586 +
12587 + /* FS/LS Enpoint on HS Hub
12588 + * NOT virtual root hub */
12589 + _qh->do_split = 0;
12590 + _qh->speed = _urb->dev->speed;
12591 + if (((_urb->dev->speed == USB_SPEED_LOW) ||
12592 + (_urb->dev->speed == USB_SPEED_FULL)) &&
12593 + (_urb->dev->tt) && (_urb->dev->tt->hub) && (_urb->dev->tt->hub->devnum != 1)) {
12594 + DWC_DEBUGPL(DBG_HCD, "QH init: EP %d: TT found at hub addr %d, for port %d\n",
12595 + usb_pipeendpoint(_urb->pipe), _urb->dev->tt->hub->devnum,
12596 + _urb->dev->ttport);
12597 + _qh->do_split = 1;
12598 + }
12599 +
12600 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT ||
12601 + _qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
12602 + /* Compute scheduling parameters once and save them. */
12603 + hprt0_data_t hprt;
12604 +
12605 + /** @todo Account for split transfers in the bus time. */
12606 + int bytecount = dwc_hb_mult(_qh->maxp) * dwc_max_packet(_qh->maxp);
12607 + _qh->usecs = NS_TO_US(usb_calc_bus_time(_urb->dev->speed,
12608 + usb_pipein(_urb->pipe),
12609 + (_qh->ep_type == USB_ENDPOINT_XFER_ISOC),bytecount));
12610 +
12611 + /* Start in a slightly future (micro)frame. */
12612 + _qh->sched_frame = dwc_frame_num_inc(_hcd->frame_number, SCHEDULE_SLOP);
12613 + _qh->interval = _urb->interval;
12614 +#if 0
12615 + /* Increase interrupt polling rate for debugging. */
12616 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12617 + _qh->interval = 8;
12618 + }
12619 +#endif
12620 + hprt.d32 = dwc_read_reg32(_hcd->core_if->host_if->hprt0);
12621 + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
12622 + ((_urb->dev->speed == USB_SPEED_LOW) ||
12623 + (_urb->dev->speed == USB_SPEED_FULL)))
12624 + {
12625 + _qh->interval *= 8;
12626 + _qh->sched_frame |= 0x7;
12627 + _qh->start_split_frame = _qh->sched_frame;
12628 + }
12629 + }
12630 +
12631 + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
12632 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", _qh);
12633 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
12634 + _urb->dev->devnum);
12635 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
12636 + usb_pipeendpoint(_urb->pipe),
12637 + usb_pipein(_urb->pipe) == USB_DIR_IN ? "IN" : "OUT");
12638 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n",
12639 + ({ char *speed; switch (_urb->dev->speed) {
12640 + case USB_SPEED_LOW: speed = "low"; break;
12641 + case USB_SPEED_FULL: speed = "full"; break;
12642 + case USB_SPEED_HIGH: speed = "high"; break;
12643 + default: speed = "?"; break;
12644 + }; speed;}));
12645 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n",
12646 + ({ char *type; switch (_qh->ep_type) {
12647 + case USB_ENDPOINT_XFER_ISOC: type = "isochronous"; break;
12648 + case USB_ENDPOINT_XFER_INT: type = "interrupt"; break;
12649 + case USB_ENDPOINT_XFER_CONTROL: type = "control"; break;
12650 + case USB_ENDPOINT_XFER_BULK: type = "bulk"; break;
12651 + default: type = "?"; break;
12652 + }; type;}));
12653 +#ifdef DEBUG
12654 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12655 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
12656 + _qh->usecs);
12657 + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
12658 + _qh->interval);
12659 + }
12660 +#endif
12661 +
12662 + return;
12663 +}
12664 +
12665 +/**
12666 + * Microframe scheduler
12667 + * track the total use in hcd->frame_usecs
12668 + * keep each qh use in qh->frame_usecs
12669 + * when surrendering the qh then donate the time back
12670 + */
12671 +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
12672 +
12673 +/*
12674 + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
12675 + */
12676 +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
12677 +{
12678 + int i;
12679 + for (i=0; i<8; i++) {
12680 + _hcd->frame_usecs[i] = max_uframe_usecs[i];
12681 + }
12682 + return 0;
12683 +}
12684 +
12685 +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12686 +{
12687 + int i;
12688 + unsigned short utime;
12689 + int t_left;
12690 + int ret;
12691 + int done;
12692 +
12693 + ret = -1;
12694 + utime = _qh->usecs;
12695 + t_left = utime;
12696 + i = 0;
12697 + done = 0;
12698 + while (done == 0) {
12699 + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
12700 + if (utime <= _hcd->frame_usecs[i]) {
12701 + _hcd->frame_usecs[i] -= utime;
12702 + _qh->frame_usecs[i] += utime;
12703 + t_left -= utime;
12704 + ret = i;
12705 + done = 1;
12706 + return ret;
12707 + } else {
12708 + i++;
12709 + if (i == 8) {
12710 + done = 1;
12711 + ret = -1;
12712 + }
12713 + }
12714 + }
12715 + return ret;
12716 +}
12717 +
12718 +/*
12719 + * use this for FS apps that can span multiple uframes
12720 + */
12721 +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12722 +{
12723 + int i;
12724 + int j;
12725 + unsigned short utime;
12726 + int t_left;
12727 + int ret;
12728 + int done;
12729 + unsigned short xtime;
12730 +
12731 + ret = -1;
12732 + utime = _qh->usecs;
12733 + t_left = utime;
12734 + i = 0;
12735 + done = 0;
12736 +loop:
12737 + while (done == 0) {
12738 + if(_hcd->frame_usecs[i] <= 0) {
12739 + i++;
12740 + if (i == 8) {
12741 + done = 1;
12742 + ret = -1;
12743 + }
12744 + goto loop;
12745 + }
12746 +
12747 + /*
12748 + * we need n consequtive slots
12749 + * so use j as a start slot j plus j+1 must be enough time (for now)
12750 + */
12751 + xtime= _hcd->frame_usecs[i];
12752 + for (j = i+1 ; j < 8 ; j++ ) {
12753 + /*
12754 + * if we add this frame remaining time to xtime we may
12755 + * be OK, if not we need to test j for a complete frame
12756 + */
12757 + if ((xtime+_hcd->frame_usecs[j]) < utime) {
12758 + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
12759 + j = 8;
12760 + ret = -1;
12761 + continue;
12762 + }
12763 + }
12764 + if (xtime >= utime) {
12765 + ret = i;
12766 + j = 8; /* stop loop with a good value ret */
12767 + continue;
12768 + }
12769 + /* add the frame time to x time */
12770 + xtime += _hcd->frame_usecs[j];
12771 + /* we must have a fully available next frame or break */
12772 + if ((xtime < utime)
12773 + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
12774 + ret = -1;
12775 + j = 8; /* stop loop with a bad value ret */
12776 + continue;
12777 + }
12778 + }
12779 + if (ret >= 0) {
12780 + t_left = utime;
12781 + for (j = i; (t_left>0) && (j < 8); j++ ) {
12782 + t_left -= _hcd->frame_usecs[j];
12783 + if ( t_left <= 0 ) {
12784 + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
12785 + _hcd->frame_usecs[j]= -t_left;
12786 + ret = i;
12787 + done = 1;
12788 + } else {
12789 + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
12790 + _hcd->frame_usecs[j] = 0;
12791 + }
12792 + }
12793 + } else {
12794 + i++;
12795 + if (i == 8) {
12796 + done = 1;
12797 + ret = -1;
12798 + }
12799 + }
12800 + }
12801 + return ret;
12802 +}
12803 +
12804 +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12805 +{
12806 + int ret;
12807 + ret = -1;
12808 +
12809 + if (_qh->speed == USB_SPEED_HIGH) {
12810 + /* if this is a hs transaction we need a full frame */
12811 + ret = find_single_uframe(_hcd, _qh);
12812 + } else {
12813 + /* if this is a fs transaction we may need a sequence of frames */
12814 + ret = find_multi_uframe(_hcd, _qh);
12815 + }
12816 + return ret;
12817 +}
12818 +
12819 +/**
12820 + * Checks that the max transfer size allowed in a host channel is large enough
12821 + * to handle the maximum data transfer in a single (micro)frame for a periodic
12822 + * transfer.
12823 + *
12824 + * @param _hcd The HCD state structure for the DWC OTG controller.
12825 + * @param _qh QH for a periodic endpoint.
12826 + *
12827 + * @return 0 if successful, negative error code otherwise.
12828 + */
12829 +static int check_max_xfer_size(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12830 +{
12831 + int status;
12832 + uint32_t max_xfer_size;
12833 + uint32_t max_channel_xfer_size;
12834 +
12835 + status = 0;
12836 +
12837 + max_xfer_size = dwc_max_packet(_qh->maxp) * dwc_hb_mult(_qh->maxp);
12838 + max_channel_xfer_size = _hcd->core_if->core_params->max_transfer_size;
12839 +
12840 + if (max_xfer_size > max_channel_xfer_size) {
12841 + DWC_NOTICE("%s: Periodic xfer length %d > "
12842 + "max xfer length for channel %d\n",
12843 + __func__, max_xfer_size, max_channel_xfer_size);
12844 + status = -ENOSPC;
12845 + }
12846 +
12847 + return status;
12848 +}
12849 +
12850 +/**
12851 + * Schedules an interrupt or isochronous transfer in the periodic schedule.
12852 + *
12853 + * @param _hcd The HCD state structure for the DWC OTG controller.
12854 + * @param _qh QH for the periodic transfer. The QH should already contain the
12855 + * scheduling information.
12856 + *
12857 + * @return 0 if successful, negative error code otherwise.
12858 + */
12859 +static int schedule_periodic(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12860 +{
12861 + int status = 0;
12862 +
12863 + int frame;
12864 + status = find_uframe(_hcd, _qh);
12865 + frame = -1;
12866 + if (status == 0) {
12867 + frame = 7;
12868 + } else {
12869 + if (status > 0 )
12870 + frame = status-1;
12871 + }
12872 +
12873 + /* Set the new frame up */
12874 + if (frame > -1) {
12875 + _qh->sched_frame &= ~0x7;
12876 + _qh->sched_frame |= (frame & 7);
12877 + }
12878 +
12879 + if (status != -1 )
12880 + status = 0;
12881 + if (status) {
12882 + DWC_NOTICE("%s: Insufficient periodic bandwidth for "
12883 + "periodic transfer.\n", __func__);
12884 + return status;
12885 + }
12886 +
12887 + status = check_max_xfer_size(_hcd, _qh);
12888 + if (status) {
12889 + DWC_NOTICE("%s: Channel max transfer size too small "
12890 + "for periodic transfer.\n", __func__);
12891 + return status;
12892 + }
12893 +
12894 + /* Always start in the inactive schedule. */
12895 + list_add_tail(&_qh->qh_list_entry, &_hcd->periodic_sched_inactive);
12896 +
12897 +
12898 + /* Update claimed usecs per (micro)frame. */
12899 + _hcd->periodic_usecs += _qh->usecs;
12900 +
12901 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
12902 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_allocated += _qh->usecs / _qh->interval;
12903 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12904 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_int_reqs++;
12905 + DWC_DEBUGPL(DBG_HCD, "Scheduled intr: qh %p, usecs %d, period %d\n",
12906 + _qh, _qh->usecs, _qh->interval);
12907 + } else {
12908 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_isoc_reqs++;
12909 + DWC_DEBUGPL(DBG_HCD, "Scheduled isoc: qh %p, usecs %d, period %d\n",
12910 + _qh, _qh->usecs, _qh->interval);
12911 + }
12912 +
12913 + return status;
12914 +}
12915 +
12916 +/**
12917 + * This function adds a QH to either the non periodic or periodic schedule if
12918 + * it is not already in the schedule. If the QH is already in the schedule, no
12919 + * action is taken.
12920 + *
12921 + * @return 0 if successful, negative error code otherwise.
12922 + */
12923 +int dwc_otg_hcd_qh_add (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12924 +{
12925 + unsigned long flags;
12926 + int status = 0;
12927 +
12928 + local_irq_save(flags);
12929 +
12930 + if (!list_empty(&_qh->qh_list_entry)) {
12931 + /* QH already in a schedule. */
12932 + goto done;
12933 + }
12934 +
12935 + /* Add the new QH to the appropriate schedule */
12936 + if (dwc_qh_is_non_per(_qh)) {
12937 + /* Always start in the inactive schedule. */
12938 + list_add_tail(&_qh->qh_list_entry, &_hcd->non_periodic_sched_inactive);
12939 + } else {
12940 + status = schedule_periodic(_hcd, _qh);
12941 + }
12942 +
12943 + done:
12944 + local_irq_restore(flags);
12945 +
12946 + return status;
12947 +}
12948 +
12949 +/**
12950 + * This function adds a QH to the non periodic deferred schedule.
12951 + *
12952 + * @return 0 if successful, negative error code otherwise.
12953 + */
12954 +int dwc_otg_hcd_qh_add_deferred(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
12955 +{
12956 + unsigned long flags;
12957 + local_irq_save(flags);
12958 + if (!list_empty(&_qh->qh_list_entry)) {
12959 + /* QH already in a schedule. */
12960 + goto done;
12961 + }
12962 +
12963 + /* Add the new QH to the non periodic deferred schedule */
12964 + if (dwc_qh_is_non_per(_qh)) {
12965 + list_add_tail(&_qh->qh_list_entry,
12966 + &_hcd->non_periodic_sched_deferred);
12967 + }
12968 +done:
12969 + local_irq_restore(flags);
12970 + return 0;
12971 +}
12972 +
12973 +/**
12974 + * Removes an interrupt or isochronous transfer from the periodic schedule.
12975 + *
12976 + * @param _hcd The HCD state structure for the DWC OTG controller.
12977 + * @param _qh QH for the periodic transfer.
12978 + */
12979 +static void deschedule_periodic(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
12980 +{
12981 + int i;
12982 + list_del_init(&_qh->qh_list_entry);
12983 +
12984 +
12985 + /* Update claimed usecs per (micro)frame. */
12986 + _hcd->periodic_usecs -= _qh->usecs;
12987 +
12988 + for (i = 0; i < 8; i++) {
12989 + _hcd->frame_usecs[i] += _qh->frame_usecs[i];
12990 + _qh->frame_usecs[i] = 0;
12991 + }
12992 + /* Update average periodic bandwidth claimed and # periodic reqs for usbfs. */
12993 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_allocated -= _qh->usecs / _qh->interval;
12994 +
12995 + if (_qh->ep_type == USB_ENDPOINT_XFER_INT) {
12996 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_int_reqs--;
12997 + DWC_DEBUGPL(DBG_HCD, "Descheduled intr: qh %p, usecs %d, period %d\n",
12998 + _qh, _qh->usecs, _qh->interval);
12999 + } else {
13000 + hcd_to_bus(dwc_otg_hcd_to_hcd(_hcd))->bandwidth_isoc_reqs--;
13001 + DWC_DEBUGPL(DBG_HCD, "Descheduled isoc: qh %p, usecs %d, period %d\n",
13002 + _qh, _qh->usecs, _qh->interval);
13003 + }
13004 +}
13005 +
13006 +/**
13007 + * Removes a QH from either the non-periodic or periodic schedule. Memory is
13008 + * not freed.
13009 + *
13010 + * @param[in] _hcd The HCD state structure.
13011 + * @param[in] _qh QH to remove from schedule. */
13012 +void dwc_otg_hcd_qh_remove (dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
13013 +{
13014 + unsigned long flags;
13015 +
13016 + local_irq_save(flags);
13017 +
13018 + if (list_empty(&_qh->qh_list_entry)) {
13019 + /* QH is not in a schedule. */
13020 + goto done;
13021 + }
13022 +
13023 + if (dwc_qh_is_non_per(_qh)) {
13024 + if (_hcd->non_periodic_qh_ptr == &_qh->qh_list_entry) {
13025 + _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
13026 + }
13027 + list_del_init(&_qh->qh_list_entry);
13028 + } else {
13029 + deschedule_periodic(_hcd, _qh);
13030 + }
13031 +
13032 + done:
13033 + local_irq_restore(flags);
13034 +}
13035 +
13036 +/**
13037 + * Defers a QH. For non-periodic QHs, removes the QH from the active
13038 + * non-periodic schedule. The QH is added to the deferred non-periodic
13039 + * schedule if any QTDs are still attached to the QH.
13040 + */
13041 +int dwc_otg_hcd_qh_deferr(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh, int delay)
13042 +{
13043 + int deact = 1;
13044 + unsigned long flags;
13045 + local_irq_save(flags);
13046 + if (dwc_qh_is_non_per(_qh)) {
13047 + _qh->sched_frame =
13048 + dwc_frame_num_inc(_hcd->frame_number,
13049 + delay);
13050 + _qh->channel = NULL;
13051 + _qh->qtd_in_process = NULL;
13052 + deact = 0;
13053 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13054 + if (!list_empty(&_qh->qtd_list)) {
13055 + /* Add back to deferred non-periodic schedule. */
13056 + dwc_otg_hcd_qh_add_deferred(_hcd, _qh);
13057 + }
13058 + }
13059 + local_irq_restore(flags);
13060 + return deact;
13061 +}
13062 +
13063 +/**
13064 + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
13065 + * non-periodic schedule. The QH is added to the inactive non-periodic
13066 + * schedule if any QTDs are still attached to the QH.
13067 + *
13068 + * For periodic QHs, the QH is removed from the periodic queued schedule. If
13069 + * there are any QTDs still attached to the QH, the QH is added to either the
13070 + * periodic inactive schedule or the periodic ready schedule and its next
13071 + * scheduled frame is calculated. The QH is placed in the ready schedule if
13072 + * the scheduled frame has been reached already. Otherwise it's placed in the
13073 + * inactive schedule. If there are no QTDs attached to the QH, the QH is
13074 + * completely removed from the periodic schedule.
13075 + */
13076 +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh, int sched_next_periodic_split)
13077 +{
13078 + unsigned long flags;
13079 + local_irq_save(flags);
13080 +
13081 + if (dwc_qh_is_non_per(_qh)) {
13082 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13083 + if (!list_empty(&_qh->qtd_list)) {
13084 + /* Add back to inactive non-periodic schedule. */
13085 + dwc_otg_hcd_qh_add(_hcd, _qh);
13086 + }
13087 + } else {
13088 + uint16_t frame_number = dwc_otg_hcd_get_frame_number(dwc_otg_hcd_to_hcd(_hcd));
13089 +
13090 + if (_qh->do_split) {
13091 + /* Schedule the next continuing periodic split transfer */
13092 + if (sched_next_periodic_split) {
13093 +
13094 + _qh->sched_frame = frame_number;
13095 + if (dwc_frame_num_le(frame_number,
13096 + dwc_frame_num_inc(_qh->start_split_frame, 1))) {
13097 + /*
13098 + * Allow one frame to elapse after start
13099 + * split microframe before scheduling
13100 + * complete split, but DONT if we are
13101 + * doing the next start split in the
13102 + * same frame for an ISOC out.
13103 + */
13104 + if ((_qh->ep_type != USB_ENDPOINT_XFER_ISOC) || (_qh->ep_is_in != 0)) {
13105 + _qh->sched_frame = dwc_frame_num_inc(_qh->sched_frame, 1);
13106 + }
13107 + }
13108 + } else {
13109 + _qh->sched_frame = dwc_frame_num_inc(_qh->start_split_frame,
13110 + _qh->interval);
13111 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13112 + _qh->sched_frame = frame_number;
13113 + }
13114 + _qh->sched_frame |= 0x7;
13115 + _qh->start_split_frame = _qh->sched_frame;
13116 + }
13117 + } else {
13118 + _qh->sched_frame = dwc_frame_num_inc(_qh->sched_frame, _qh->interval);
13119 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13120 + _qh->sched_frame = frame_number;
13121 + }
13122 + }
13123 +
13124 + if (list_empty(&_qh->qtd_list)) {
13125 + dwc_otg_hcd_qh_remove(_hcd, _qh);
13126 + } else {
13127 + /*
13128 + * Remove from periodic_sched_queued and move to
13129 + * appropriate queue.
13130 + */
13131 + if (dwc_frame_num_le(_qh->sched_frame, frame_number)) {
13132 + list_move(&_qh->qh_list_entry,
13133 + &_hcd->periodic_sched_ready);
13134 + } else {
13135 + list_move(&_qh->qh_list_entry,
13136 + &_hcd->periodic_sched_inactive);
13137 + }
13138 + }
13139 + }
13140 +
13141 + local_irq_restore(flags);
13142 +}
13143 +
13144 +/**
13145 + * This function allocates and initializes a QTD.
13146 + *
13147 + * @param[in] _urb The URB to create a QTD from. Each URB-QTD pair will end up
13148 + * pointing to each other so each pair should have a unique correlation.
13149 + *
13150 + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
13151 +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create (struct urb *_urb)
13152 +{
13153 + dwc_otg_qtd_t *qtd;
13154 +
13155 + qtd = dwc_otg_hcd_qtd_alloc ();
13156 + if (qtd == NULL) {
13157 + return NULL;
13158 + }
13159 +
13160 + dwc_otg_hcd_qtd_init (qtd, _urb);
13161 + return qtd;
13162 +}
13163 +
13164 +/**
13165 + * Initializes a QTD structure.
13166 + *
13167 + * @param[in] _qtd The QTD to initialize.
13168 + * @param[in] _urb The URB to use for initialization. */
13169 +void dwc_otg_hcd_qtd_init (dwc_otg_qtd_t *_qtd, struct urb *_urb)
13170 +{
13171 + memset (_qtd, 0, sizeof (dwc_otg_qtd_t));
13172 + _qtd->urb = _urb;
13173 + if (usb_pipecontrol(_urb->pipe)) {
13174 + /*
13175 + * The only time the QTD data toggle is used is on the data
13176 + * phase of control transfers. This phase always starts with
13177 + * DATA1.
13178 + */
13179 + _qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
13180 + _qtd->control_phase = DWC_OTG_CONTROL_SETUP;
13181 + }
13182 +
13183 + /* start split */
13184 + _qtd->complete_split = 0;
13185 + _qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
13186 + _qtd->isoc_split_offset = 0;
13187 +
13188 + /* Store the qtd ptr in the urb to reference what QTD. */
13189 + _urb->hcpriv = _qtd;
13190 + return;
13191 +}
13192 +
13193 +/**
13194 + * This function adds a QTD to the QTD-list of a QH. It will find the correct
13195 + * QH to place the QTD into. If it does not find a QH, then it will create a
13196 + * new QH. If the QH to which the QTD is added is not currently scheduled, it
13197 + * is placed into the proper schedule based on its EP type.
13198 + *
13199 + * @param[in] _qtd The QTD to add
13200 + * @param[in] _dwc_otg_hcd The DWC HCD structure
13201 + *
13202 + * @return 0 if successful, negative error code otherwise.
13203 + */
13204 +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * _qtd, dwc_otg_hcd_t * _dwc_otg_hcd)
13205 +{
13206 + struct usb_host_endpoint *ep;
13207 + dwc_otg_qh_t *qh;
13208 + unsigned long flags;
13209 + int retval = 0;
13210 + struct urb *urb = _qtd->urb;
13211 +
13212 + local_irq_save(flags);
13213 +
13214 + /*
13215 + * Get the QH which holds the QTD-list to insert to. Create QH if it
13216 + * doesn't exist.
13217 + */
13218 + ep = dwc_urb_to_endpoint(urb);
13219 + qh = (dwc_otg_qh_t *)ep->hcpriv;
13220 + if (qh == NULL) {
13221 + qh = dwc_otg_hcd_qh_create (_dwc_otg_hcd, urb);
13222 + if (qh == NULL) {
13223 + retval = -1;
13224 + goto done;
13225 + }
13226 + ep->hcpriv = qh;
13227 + }
13228 +
13229 + _qtd->qtd_qh_ptr = qh;
13230 + retval = dwc_otg_hcd_qh_add(_dwc_otg_hcd, qh);
13231 + if (retval == 0) {
13232 + list_add_tail(&_qtd->qtd_list_entry, &qh->qtd_list);
13233 + }
13234 +
13235 + done:
13236 + local_irq_restore(flags);
13237 + return retval;
13238 +}
13239 +
13240 +#endif /* DWC_DEVICE_ONLY */
13241 --- /dev/null
13242 +++ b/drivers/usb/dwc_otg/dwc_otg_ifx.c
13243 @@ -0,0 +1,176 @@
13244 +/******************************************************************************
13245 +**
13246 +** FILE NAME : dwc_otg_ifx.c
13247 +** PROJECT : Twinpass/Danube
13248 +** MODULES : DWC OTG USB
13249 +**
13250 +** DATE : 12 Auguest 2007
13251 +** AUTHOR : Sung Winder
13252 +** DESCRIPTION : Platform specific initialization.
13253 +** COPYRIGHT : Copyright (c) 2007
13254 +** Infineon Technologies AG
13255 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
13256 +** Hsin-chu City, 300 Taiwan.
13257 +**
13258 +** This program is free software; you can redistribute it and/or modify
13259 +** it under the terms of the GNU General Public License as published by
13260 +** the Free Software Foundation; either version 2 of the License, or
13261 +** (at your option) any later version.
13262 +**
13263 +** HISTORY
13264 +** $Date $Author $Comment
13265 +** 12 Auguest 2007 Sung Winder Initiate Version
13266 +*******************************************************************************/
13267 +#include "dwc_otg_ifx.h"
13268 +
13269 +#include <linux/platform_device.h>
13270 +#include <linux/kernel.h>
13271 +#include <linux/ioport.h>
13272 +#include <linux/gpio.h>
13273 +
13274 +#include <asm/io.h>
13275 +//#include <asm/mach-ifxmips/ifxmips.h>
13276 +#include <xway.h>
13277 +
13278 +#define IFXMIPS_GPIO_BASE_ADDR (0xBE100B00)
13279 +
13280 +#define IFXMIPS_GPIO_P0_OUT ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0010))
13281 +#define IFXMIPS_GPIO_P1_OUT ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0040))
13282 +#define IFXMIPS_GPIO_P0_IN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0014))
13283 +#define IFXMIPS_GPIO_P1_IN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0044))
13284 +#define IFXMIPS_GPIO_P0_DIR ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0018))
13285 +#define IFXMIPS_GPIO_P1_DIR ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0048))
13286 +#define IFXMIPS_GPIO_P0_ALTSEL0 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x001C))
13287 +#define IFXMIPS_GPIO_P1_ALTSEL0 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x004C))
13288 +#define IFXMIPS_GPIO_P0_ALTSEL1 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0020))
13289 +#define IFXMIPS_GPIO_P1_ALTSEL1 ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0050))
13290 +#define IFXMIPS_GPIO_P0_OD ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0024))
13291 +#define IFXMIPS_GPIO_P1_OD ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0054))
13292 +#define IFXMIPS_GPIO_P0_STOFF ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0028))
13293 +#define IFXMIPS_GPIO_P1_STOFF ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0058))
13294 +#define IFXMIPS_GPIO_P0_PUDSEL ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x002C))
13295 +#define IFXMIPS_GPIO_P1_PUDSEL ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x005C))
13296 +#define IFXMIPS_GPIO_P0_PUDEN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0030))
13297 +#define IFXMIPS_GPIO_P1_PUDEN ((u32 *)(IFXMIPS_GPIO_BASE_ADDR + 0x0060))
13298 +
13299 +
13300 +extern void lq_enable_irq(unsigned int irq_nr);
13301 +#define writel lq_w32
13302 +#define readl lq_r32
13303 +void dwc_otg_power_on (void)
13304 +{
13305 + // GPIOs
13306 + gpio_request(28, "USB_POWER");
13307 + gpio_direction_output(28, 1);
13308 + /*
13309 + writel(readl(IFXMIPS_GPIO_P0_DIR) | (0x4000), IFXMIPS_GPIO_P0_DIR);
13310 + writel(readl(IFXMIPS_GPIO_P0_OD) | (0x4000), IFXMIPS_GPIO_P0_OD);
13311 + writel(readl(IFXMIPS_GPIO_P0_ALTSEL0) & ~(0x4000), IFXMIPS_GPIO_P0_ALTSEL0);
13312 + writel(readl(IFXMIPS_GPIO_P0_ALTSEL1) & ~(0x4000), IFXMIPS_GPIO_P0_ALTSEL1);
13313 + writel(readl(IFXMIPS_GPIO_P0_OUT) | (0x4000), IFXMIPS_GPIO_P0_OUT);
13314 +*/
13315 +/* writel(readl(IFXMIPS_GPIO_P1_DIR) | (0x1000), IFXMIPS_GPIO_P1_DIR);
13316 + writel(readl(IFXMIPS_GPIO_P1_OD) | (0x1000), IFXMIPS_GPIO_P1_OD);
13317 + writel(readl(IFXMIPS_GPIO_P1_ALTSEL0) & ~(0x1000), IFXMIPS_GPIO_P1_ALTSEL0);
13318 + writel(readl(IFXMIPS_GPIO_P1_ALTSEL1) & ~(0x1000), IFXMIPS_GPIO_P1_ALTSEL1);
13319 + writel(readl(IFXMIPS_GPIO_P1_OUT) | (0x1000), IFXMIPS_GPIO_P1_OUT);
13320 +*/
13321 + // clear power
13322 + //set_bit (0, DANUBE_PMU_PWDCR);
13323 + //set_bit (6, DANUBE_PMU_PWDCR);
13324 + writel(readl(DANUBE_PMU_PWDCR) | 0x41, DANUBE_PMU_PWDCR);
13325 +
13326 + // set clock gating
13327 + //set_bit (4, (volatile unsigned long *)DANUBE_CGU_IFCCR);
13328 + //set_bit (5, (volatile unsigned long *)DANUBE_CGU_IFCCR);
13329 + writel(readl(DANUBE_CGU_IFCCR) | 0x30, DANUBE_CGU_IFCCR);
13330 +
13331 + // set power
13332 + //clear_bit (0, (volatile unsigned long *)DANUBE_PMU_PWDCR);
13333 + writel(readl(DANUBE_PMU_PWDCR) & ~0x1, DANUBE_PMU_PWDCR);
13334 + //clear_bit (6, (volatile unsigned long *)DANUBE_PMU_PWDCR);
13335 + writel(readl(DANUBE_PMU_PWDCR) & ~0x40, DANUBE_PMU_PWDCR);
13336 + //clear_bit (15, (volatile unsigned long *)DANUBE_PMU_PWDCR);
13337 + writel(readl(DANUBE_PMU_PWDCR) & ~0x8000, DANUBE_PMU_PWDCR);
13338 + //writel(readl(DANUBE_PMU_PWDCR) & ~0x8041, DANUBE_PMU_PWDCR);
13339 +
13340 +#if 1//defined (DWC_HOST_ONLY)
13341 + // make the hardware be a host controller (default)
13342 + //clear_bit (DANUBE_USBCFG_HDSEL_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13343 + writel(readl(DANUBE_RCU_UBSCFG) & ~(1<<DANUBE_USBCFG_HDSEL_BIT), DANUBE_RCU_UBSCFG);
13344 +
13345 + //#elif defined (DWC_DEVICE_ONLY)
13346 + /* set the controller to the device mode */
13347 + // set_bit (DANUBE_USBCFG_HDSEL_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13348 +#else
13349 +#error "For Danube/Twinpass, it should be HOST or Device Only."
13350 +#endif
13351 +
13352 + // set the HC's byte-order to big-endian
13353 + //set_bit (DANUBE_USBCFG_HOST_END_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13354 + writel(readl(DANUBE_RCU_UBSCFG) | (1<<DANUBE_USBCFG_HOST_END_BIT), DANUBE_RCU_UBSCFG);
13355 + //clear_bit (DANUBE_USBCFG_SLV_END_BIT, (volatile unsigned long *)DANUBE_RCU_UBSCFG);
13356 + writel(readl(DANUBE_RCU_UBSCFG) & ~(1<<DANUBE_USBCFG_SLV_END_BIT), DANUBE_RCU_UBSCFG);
13357 + //writel(0x400, DANUBE_RCU_UBSCFG);
13358 +
13359 + // PHY configurations.
13360 + writel (0x14014, (volatile unsigned long *)0xbe10103c);
13361 +}
13362 +
13363 +static void release_platform_dev(struct device * dev)
13364 +{
13365 + printk("IFX dwc_otg USB platform_dev release\n");
13366 + dev->parent = NULL;
13367 +}
13368 +
13369 +static struct resource resources[] =
13370 +{
13371 + [0] = {
13372 + .name = "dwc_otg_membase",
13373 + .start = IFX_USB_IOMEM_BASE,
13374 + .end = IFX_USB_IOMEM_BASE + IFX_USB_IOMEM_SIZE - 1,
13375 + .flags = IORESOURCE_MEM,
13376 + },
13377 + [1] = {
13378 + .name = "dwc_otg_irq",
13379 + .start = IFX_USB_IRQ,
13380 + .flags = IORESOURCE_IRQ,
13381 + },
13382 +};
13383 +
13384 +static u64 dwc_dmamask = (u32)0x1fffffff;
13385 +
13386 +static struct platform_device platform_dev = {
13387 + .dev = {
13388 + .release = release_platform_dev,
13389 + .dma_mask = &dwc_dmamask,
13390 + },
13391 + .resource = resources,
13392 + .num_resources = ARRAY_SIZE(resources),
13393 +};
13394 +
13395 +extern const char dwc_driver_name[];
13396 +int ifx_usb_hc_init(unsigned long base_addr, int irq)
13397 +{
13398 + if (platform_dev.dev.parent)
13399 + return -EBUSY;
13400 +
13401 + /* finish seting up the platform device */
13402 + //resources[0].start = base_addr;
13403 + //resources[0].end = base_addr + SZ_256K;
13404 +
13405 + //resources[1].start = irq;
13406 +
13407 + /* The driver core will probe for us. We know sl811-hcd has been
13408 + * initialized already because of the link order dependency.
13409 + */
13410 + platform_dev.name = dwc_driver_name;
13411 + lq_enable_irq(resources[1].start);
13412 +
13413 + return platform_device_register(&platform_dev);
13414 +}
13415 +
13416 +void ifx_usb_hc_remove(void)
13417 +{
13418 + platform_device_unregister(&platform_dev);
13419 +}
13420 --- /dev/null
13421 +++ b/drivers/usb/dwc_otg/dwc_otg_ifx.h
13422 @@ -0,0 +1,79 @@
13423 +/******************************************************************************
13424 +**
13425 +** FILE NAME : dwc_otg_ifx.h
13426 +** PROJECT : Twinpass/Danube
13427 +** MODULES : DWC OTG USB
13428 +**
13429 +** DATE : 12 April 2007
13430 +** AUTHOR : Sung Winder
13431 +** DESCRIPTION : Platform specific initialization.
13432 +** COPYRIGHT : Copyright (c) 2007
13433 +** Infineon Technologies AG
13434 +** 2F, No.2, Li-Hsin Rd., Hsinchu Science Park,
13435 +** Hsin-chu City, 300 Taiwan.
13436 +**
13437 +** This program is free software; you can redistribute it and/or modify
13438 +** it under the terms of the GNU General Public License as published by
13439 +** the Free Software Foundation; either version 2 of the License, or
13440 +** (at your option) any later version.
13441 +**
13442 +** HISTORY
13443 +** $Date $Author $Comment
13444 +** 12 April 2007 Sung Winder Initiate Version
13445 +*******************************************************************************/
13446 +#if !defined(__DWC_OTG_IFX_H__)
13447 +#define __DWC_OTG_IFX_H__
13448 +
13449 +#include <irq.h>
13450 +
13451 +// 20070316, winder added.
13452 +#ifndef SZ_256K
13453 +#define SZ_256K 0x00040000
13454 +#endif
13455 +
13456 +extern void dwc_otg_power_on (void);
13457 +
13458 +/* FIXME: The current Linux-2.6 do not have these header files, but anyway, we need these. */
13459 +// #include <asm/danube/danube.h>
13460 +// #include <asm/ifx/irq.h>
13461 +
13462 +/* winder, I used the Danube parameter as default. *
13463 + * We could change this through module param. */
13464 +#define IFX_USB_IOMEM_BASE 0x1e101000
13465 +#define IFX_USB_IOMEM_SIZE SZ_256K
13466 +#define IFX_USB_IRQ LQ_USB_INT
13467 +
13468 +/**
13469 + * This function is called to set correct clock gating and power.
13470 + * For Twinpass/Danube board.
13471 + */
13472 +#ifndef DANUBE_RCU_BASE_ADDR
13473 +#define DANUBE_RCU_BASE_ADDR (0xBF203000)
13474 +#endif
13475 +
13476 +#ifndef DANUBE_CGU
13477 +#define DANUBE_CGU (0xBF103000)
13478 +#endif
13479 +#ifndef DANUBE_CGU_IFCCR
13480 +/***CGU Interface Clock Control Register***/
13481 +#define DANUBE_CGU_IFCCR ((volatile u32*)(DANUBE_CGU+ 0x0018))
13482 +#endif
13483 +
13484 +#ifndef DANUBE_PMU
13485 +#define DANUBE_PMU (KSEG1+0x1F102000)
13486 +#endif
13487 +#ifndef DANUBE_PMU_PWDCR
13488 +/* PMU Power down Control Register */
13489 +#define DANUBE_PMU_PWDCR ((volatile u32*)(DANUBE_PMU+0x001C))
13490 +#endif
13491 +
13492 +
13493 +#define DANUBE_RCU_UBSCFG ((volatile u32*)(DANUBE_RCU_BASE_ADDR + 0x18))
13494 +#define DANUBE_USBCFG_HDSEL_BIT 11 // 0:host, 1:device
13495 +#define DANUBE_USBCFG_HOST_END_BIT 10 // 0:little_end, 1:big_end
13496 +#define DANUBE_USBCFG_SLV_END_BIT 9 // 0:little_end, 1:big_end
13497 +
13498 +extern void lq_mask_and_ack_irq (unsigned int irq_nr);
13499 +#define mask_and_ack_ifx_irq lq_mask_and_ack_irq
13500 +
13501 +#endif //__DWC_OTG_IFX_H__
13502 --- /dev/null
13503 +++ b/drivers/usb/dwc_otg/dwc_otg_plat.h
13504 @@ -0,0 +1,269 @@
13505 +/* ==========================================================================
13506 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/platform/dwc_otg_plat.h $
13507 + * $Revision: 1.1.1.1 $
13508 + * $Date: 2009-04-17 06:15:34 $
13509 + * $Change: 510301 $
13510 + *
13511 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13512 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13513 + * otherwise expressly agreed to in writing between Synopsys and you.
13514 + *
13515 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13516 + * any End User Software License Agreement or Agreement for Licensed Product
13517 + * with Synopsys or any supplement thereto. You are permitted to use and
13518 + * redistribute this Software in source and binary forms, with or without
13519 + * modification, provided that redistributions of source code must retain this
13520 + * notice. You may not view, use, disclose, copy or distribute this file or
13521 + * any information contained herein except pursuant to this license grant from
13522 + * Synopsys. If you do not agree with this notice, including the disclaimer
13523 + * below, then you are not authorized to use the Software.
13524 + *
13525 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13526 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13527 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13528 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13529 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13530 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13531 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13532 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13533 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13534 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13535 + * DAMAGE.
13536 + * ========================================================================== */
13537 +
13538 +#if !defined(__DWC_OTG_PLAT_H__)
13539 +#define __DWC_OTG_PLAT_H__
13540 +
13541 +#include <linux/types.h>
13542 +#include <linux/slab.h>
13543 +#include <linux/list.h>
13544 +#include <linux/delay.h>
13545 +#include <asm/io.h>
13546 +
13547 +/**
13548 + * @file
13549 + *
13550 + * This file contains the Platform Specific constants, interfaces
13551 + * (functions and macros) for Linux.
13552 + *
13553 + */
13554 +/*#if !defined(__LINUX__)
13555 +#error "The contents of this file is Linux specific!!!"
13556 +#endif
13557 +*/
13558 +#include <xway.h>
13559 +#define writel lq_w32
13560 +#define readl lq_r32
13561 +
13562 +/**
13563 + * Reads the content of a register.
13564 + *
13565 + * @param _reg address of register to read.
13566 + * @return contents of the register.
13567 + *
13568 +
13569 + * Usage:<br>
13570 + * <code>uint32_t dev_ctl = dwc_read_reg32(&dev_regs->dctl);</code>
13571 + */
13572 +static __inline__ uint32_t dwc_read_reg32( volatile uint32_t *_reg)
13573 +{
13574 + return readl(_reg);
13575 +};
13576 +
13577 +/**
13578 + * Writes a register with a 32 bit value.
13579 + *
13580 + * @param _reg address of register to read.
13581 + * @param _value to write to _reg.
13582 + *
13583 + * Usage:<br>
13584 + * <code>dwc_write_reg32(&dev_regs->dctl, 0); </code>
13585 + */
13586 +static __inline__ void dwc_write_reg32( volatile uint32_t *_reg, const uint32_t _value)
13587 +{
13588 + writel( _value, _reg );
13589 +};
13590 +
13591 +/**
13592 + * This function modifies bit values in a register. Using the
13593 + * algorithm: (reg_contents & ~clear_mask) | set_mask.
13594 + *
13595 + * @param _reg address of register to read.
13596 + * @param _clear_mask bit mask to be cleared.
13597 + * @param _set_mask bit mask to be set.
13598 + *
13599 + * Usage:<br>
13600 + * <code> // Clear the SOF Interrupt Mask bit and <br>
13601 + * // set the OTG Interrupt mask bit, leaving all others as they were.
13602 + * dwc_modify_reg32(&dev_regs->gintmsk, DWC_SOF_INT, DWC_OTG_INT);</code>
13603 + */
13604 +static __inline__
13605 + void dwc_modify_reg32( volatile uint32_t *_reg, const uint32_t _clear_mask, const uint32_t _set_mask)
13606 +{
13607 + writel( (readl(_reg) & ~_clear_mask) | _set_mask, _reg );
13608 +};
13609 +
13610 +
13611 +/**
13612 + * Wrapper for the OS micro-second delay function.
13613 + * @param[in] _usecs Microseconds of delay
13614 + */
13615 +static __inline__ void UDELAY( const uint32_t _usecs )
13616 +{
13617 + udelay( _usecs );
13618 +}
13619 +
13620 +/**
13621 + * Wrapper for the OS milli-second delay function.
13622 + * @param[in] _msecs milliseconds of delay
13623 + */
13624 +static __inline__ void MDELAY( const uint32_t _msecs )
13625 +{
13626 + mdelay( _msecs );
13627 +}
13628 +
13629 +/**
13630 + * Wrapper for the Linux spin_lock. On the ARM (Integrator)
13631 + * spin_lock() is a nop.
13632 + *
13633 + * @param _lock Pointer to the spinlock.
13634 + */
13635 +static __inline__ void SPIN_LOCK( spinlock_t *_lock )
13636 +{
13637 + spin_lock(_lock);
13638 +}
13639 +
13640 +/**
13641 + * Wrapper for the Linux spin_unlock. On the ARM (Integrator)
13642 + * spin_lock() is a nop.
13643 + *
13644 + * @param _lock Pointer to the spinlock.
13645 + */
13646 +static __inline__ void SPIN_UNLOCK( spinlock_t *_lock )
13647 +{
13648 + spin_unlock(_lock);
13649 +}
13650 +
13651 +/**
13652 + * Wrapper (macro) for the Linux spin_lock_irqsave. On the ARM
13653 + * (Integrator) spin_lock() is a nop.
13654 + *
13655 + * @param _l Pointer to the spinlock.
13656 + * @param _f unsigned long for irq flags storage.
13657 + */
13658 +#define SPIN_LOCK_IRQSAVE( _l, _f ) { \
13659 + spin_lock_irqsave(_l,_f); \
13660 + }
13661 +
13662 +/**
13663 + * Wrapper (macro) for the Linux spin_unlock_irqrestore. On the ARM
13664 + * (Integrator) spin_lock() is a nop.
13665 + *
13666 + * @param _l Pointer to the spinlock.
13667 + * @param _f unsigned long for irq flags storage.
13668 + */
13669 +#define SPIN_UNLOCK_IRQRESTORE( _l,_f ) {\
13670 + spin_unlock_irqrestore(_l,_f); \
13671 + }
13672 +
13673 +
13674 +/*
13675 + * Debugging support vanishes in non-debug builds.
13676 + */
13677 +
13678 +
13679 +/**
13680 + * The Debug Level bit-mask variable.
13681 + */
13682 +extern uint32_t g_dbg_lvl;
13683 +/**
13684 + * Set the Debug Level variable.
13685 + */
13686 +static inline uint32_t SET_DEBUG_LEVEL( const uint32_t _new )
13687 +{
13688 + uint32_t old = g_dbg_lvl;
13689 + g_dbg_lvl = _new;
13690 + return old;
13691 +}
13692 +
13693 +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
13694 +#define DBG_CIL (0x2)
13695 +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
13696 + * messages */
13697 +#define DBG_CILV (0x20)
13698 +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
13699 + * messages */
13700 +#define DBG_PCD (0x4)
13701 +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
13702 + * messages */
13703 +#define DBG_PCDV (0x40)
13704 +/** When debug level has the DBG_HCD bit set, display Host debug messages */
13705 +#define DBG_HCD (0x8)
13706 +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
13707 + * messages */
13708 +#define DBG_HCDV (0x80)
13709 +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
13710 + * mode. */
13711 +#define DBG_HCD_URB (0x800)
13712 +
13713 +/** When debug level has any bit set, display debug messages */
13714 +#define DBG_ANY (0xFF)
13715 +
13716 +/** All debug messages off */
13717 +#define DBG_OFF 0
13718 +
13719 +/** Prefix string for DWC_DEBUG print macros. */
13720 +#define USB_DWC "DWC_otg: "
13721 +
13722 +/**
13723 + * Print a debug message when the Global debug level variable contains
13724 + * the bit defined in <code>lvl</code>.
13725 + *
13726 + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
13727 + * @param[in] x - like printf
13728 + *
13729 + * Example:<p>
13730 + * <code>
13731 + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
13732 + * </code>
13733 + * <br>
13734 + * results in:<br>
13735 + * <code>
13736 + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
13737 + * </code>
13738 + */
13739 +#ifdef DEBUG
13740 +
13741 +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)printk( KERN_DEBUG USB_DWC x ); }while(0)
13742 +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
13743 +
13744 +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
13745 +
13746 +#else
13747 +
13748 +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
13749 +# define DWC_DEBUGP(x...)
13750 +
13751 +# define CHK_DEBUG_LEVEL(level) (0)
13752 +
13753 +#endif /*DEBUG*/
13754 +
13755 +/**
13756 + * Print an Error message.
13757 + */
13758 +#define DWC_ERROR(x...) printk( KERN_ERR USB_DWC x )
13759 +/**
13760 + * Print a Warning message.
13761 + */
13762 +#define DWC_WARN(x...) printk( KERN_WARNING USB_DWC x )
13763 +/**
13764 + * Print a notice (normal but significant message).
13765 + */
13766 +#define DWC_NOTICE(x...) printk( KERN_NOTICE USB_DWC x )
13767 +/**
13768 + * Basic message printing.
13769 + */
13770 +#define DWC_PRINT(x...) printk( KERN_INFO USB_DWC x )
13771 +
13772 +#endif
13773 +
13774 --- /dev/null
13775 +++ b/drivers/usb/dwc_otg/dwc_otg_regs.h
13776 @@ -0,0 +1,1797 @@
13777 +/* ==========================================================================
13778 + * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_regs.h $
13779 + * $Revision: 1.1.1.1 $
13780 + * $Date: 2009-04-17 06:15:34 $
13781 + * $Change: 631780 $
13782 + *
13783 + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
13784 + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
13785 + * otherwise expressly agreed to in writing between Synopsys and you.
13786 + *
13787 + * The Software IS NOT an item of Licensed Software or Licensed Product under
13788 + * any End User Software License Agreement or Agreement for Licensed Product
13789 + * with Synopsys or any supplement thereto. You are permitted to use and
13790 + * redistribute this Software in source and binary forms, with or without
13791 + * modification, provided that redistributions of source code must retain this
13792 + * notice. You may not view, use, disclose, copy or distribute this file or
13793 + * any information contained herein except pursuant to this license grant from
13794 + * Synopsys. If you do not agree with this notice, including the disclaimer
13795 + * below, then you are not authorized to use the Software.
13796 + *
13797 + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
13798 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13799 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13800 + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
13801 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13802 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
13803 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
13804 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13805 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13806 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
13807 + * DAMAGE.
13808 + * ========================================================================== */
13809 +
13810 +#ifndef __DWC_OTG_REGS_H__
13811 +#define __DWC_OTG_REGS_H__
13812 +
13813 +/**
13814 + * @file
13815 + *
13816 + * This file contains the data structures for accessing the DWC_otg core registers.
13817 + *
13818 + * The application interfaces with the HS OTG core by reading from and
13819 + * writing to the Control and Status Register (CSR) space through the
13820 + * AHB Slave interface. These registers are 32 bits wide, and the
13821 + * addresses are 32-bit-block aligned.
13822 + * CSRs are classified as follows:
13823 + * - Core Global Registers
13824 + * - Device Mode Registers
13825 + * - Device Global Registers
13826 + * - Device Endpoint Specific Registers
13827 + * - Host Mode Registers
13828 + * - Host Global Registers
13829 + * - Host Port CSRs
13830 + * - Host Channel Specific Registers
13831 + *
13832 + * Only the Core Global registers can be accessed in both Device and
13833 + * Host modes. When the HS OTG core is operating in one mode, either
13834 + * Device or Host, the application must not access registers from the
13835 + * other mode. When the core switches from one mode to another, the
13836 + * registers in the new mode of operation must be reprogrammed as they
13837 + * would be after a power-on reset.
13838 + */
13839 +
13840 +/****************************************************************************/
13841 +/** DWC_otg Core registers .
13842 + * The dwc_otg_core_global_regs structure defines the size
13843 + * and relative field offsets for the Core Global registers.
13844 + */
13845 +typedef struct dwc_otg_core_global_regs
13846 +{
13847 + /** OTG Control and Status Register. <i>Offset: 000h</i> */
13848 + volatile uint32_t gotgctl;
13849 + /** OTG Interrupt Register. <i>Offset: 004h</i> */
13850 + volatile uint32_t gotgint;
13851 + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
13852 + volatile uint32_t gahbcfg;
13853 +#define DWC_GLBINTRMASK 0x0001
13854 +#define DWC_DMAENABLE 0x0020
13855 +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
13856 +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
13857 +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
13858 +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
13859 +
13860 +
13861 + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
13862 + volatile uint32_t gusbcfg;
13863 + /**Core Reset Register. <i>Offset: 010h</i> */
13864 + volatile uint32_t grstctl;
13865 + /**Core Interrupt Register. <i>Offset: 014h</i> */
13866 + volatile uint32_t gintsts;
13867 + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
13868 + volatile uint32_t gintmsk;
13869 + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
13870 + volatile uint32_t grxstsr;
13871 + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
13872 + volatile uint32_t grxstsp;
13873 + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
13874 + volatile uint32_t grxfsiz;
13875 + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
13876 + volatile uint32_t gnptxfsiz;
13877 + /**Non Periodic Transmit FIFO/Queue Status Register (Read
13878 + * Only). <i>Offset: 02Ch</i> */
13879 + volatile uint32_t gnptxsts;
13880 + /**I2C Access Register. <i>Offset: 030h</i> */
13881 + volatile uint32_t gi2cctl;
13882 + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
13883 + volatile uint32_t gpvndctl;
13884 + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
13885 + volatile uint32_t ggpio;
13886 + /**User ID Register. <i>Offset: 03Ch</i> */
13887 + volatile uint32_t guid;
13888 + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
13889 + volatile uint32_t gsnpsid;
13890 + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
13891 + volatile uint32_t ghwcfg1;
13892 + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
13893 + volatile uint32_t ghwcfg2;
13894 +#define DWC_SLAVE_ONLY_ARCH 0
13895 +#define DWC_EXT_DMA_ARCH 1
13896 +#define DWC_INT_DMA_ARCH 2
13897 +
13898 +#define DWC_MODE_HNP_SRP_CAPABLE 0
13899 +#define DWC_MODE_SRP_ONLY_CAPABLE 1
13900 +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
13901 +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
13902 +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
13903 +#define DWC_MODE_SRP_CAPABLE_HOST 5
13904 +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
13905 +
13906 + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
13907 + volatile uint32_t ghwcfg3;
13908 + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
13909 + volatile uint32_t ghwcfg4;
13910 + /** Reserved <i>Offset: 054h-0FFh</i> */
13911 + uint32_t reserved[43];
13912 + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
13913 + volatile uint32_t hptxfsiz;
13914 + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
13915 + otherwise Device Transmit FIFO#n Register.
13916 + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
13917 + //volatile uint32_t dptxfsiz[15];
13918 + volatile uint32_t dptxfsiz_dieptxf[15];
13919 +} dwc_otg_core_global_regs_t;
13920 +
13921 +/**
13922 + * This union represents the bit fields of the Core OTG Control
13923 + * and Status Register (GOTGCTL). Set the bits using the bit
13924 + * fields then write the <i>d32</i> value to the register.
13925 + */
13926 +typedef union gotgctl_data
13927 +{
13928 + /** raw register data */
13929 + uint32_t d32;
13930 + /** register bits */
13931 + struct
13932 + {
13933 + unsigned reserved31_21 : 11;
13934 + unsigned currmod : 1;
13935 + unsigned bsesvld : 1;
13936 + unsigned asesvld : 1;
13937 + unsigned reserved17 : 1;
13938 + unsigned conidsts : 1;
13939 + unsigned reserved15_12 : 4;
13940 + unsigned devhnpen : 1;
13941 + unsigned hstsethnpen : 1;
13942 + unsigned hnpreq : 1;
13943 + unsigned hstnegscs : 1;
13944 + unsigned reserved7_2 : 6;
13945 + unsigned sesreq : 1;
13946 + unsigned sesreqscs : 1;
13947 + } b;
13948 +} gotgctl_data_t;
13949 +
13950 +/**
13951 + * This union represents the bit fields of the Core OTG Interrupt Register
13952 + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
13953 + * value to the register.
13954 + */
13955 +typedef union gotgint_data
13956 +{
13957 + /** raw register data */
13958 + uint32_t d32;
13959 + /** register bits */
13960 + struct
13961 + {
13962 + /** Current Mode */
13963 + unsigned reserved31_20 : 12;
13964 + /** Debounce Done */
13965 + unsigned debdone : 1;
13966 + /** A-Device Timeout Change */
13967 + unsigned adevtoutchng : 1;
13968 + /** Host Negotiation Detected */
13969 + unsigned hstnegdet : 1;
13970 + unsigned reserver16_10 : 7;
13971 + /** Host Negotiation Success Status Change */
13972 + unsigned hstnegsucstschng : 1;
13973 + /** Session Request Success Status Change */
13974 + unsigned sesreqsucstschng : 1;
13975 + unsigned reserved3_7 : 5;
13976 + /** Session End Detected */
13977 + unsigned sesenddet : 1;
13978 + /** Current Mode */
13979 + unsigned reserved1_0 : 2;
13980 + } b;
13981 +} gotgint_data_t;
13982 +
13983 +
13984 +/**
13985 + * This union represents the bit fields of the Core AHB Configuration
13986 + * Register (GAHBCFG). Set/clear the bits using the bit fields then
13987 + * write the <i>d32</i> value to the register.
13988 + */
13989 +typedef union gahbcfg_data
13990 +{
13991 + /** raw register data */
13992 + uint32_t d32;
13993 + /** register bits */
13994 + struct
13995 + {
13996 +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
13997 +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
13998 + unsigned reserved9_31 : 23;
13999 + unsigned ptxfemplvl : 1;
14000 + unsigned nptxfemplvl_txfemplvl : 1;
14001 +#define DWC_GAHBCFG_DMAENABLE 1
14002 + unsigned reserved : 1;
14003 + unsigned dmaenable : 1;
14004 +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
14005 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
14006 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
14007 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
14008 +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
14009 + unsigned hburstlen : 4;
14010 + unsigned glblintrmsk : 1;
14011 +#define DWC_GAHBCFG_GLBINT_ENABLE 1
14012 +
14013 + } b;
14014 +} gahbcfg_data_t;
14015 +
14016 +/**
14017 + * This union represents the bit fields of the Core USB Configuration
14018 + * Register (GUSBCFG). Set the bits using the bit fields then write
14019 + * the <i>d32</i> value to the register.
14020 + */
14021 +typedef union gusbcfg_data
14022 +{
14023 + /** raw register data */
14024 + uint32_t d32;
14025 + /** register bits */
14026 + struct
14027 + {
14028 + unsigned corrupt_tx_packet: 1; /*fscz*/
14029 + unsigned force_device_mode: 1;
14030 + unsigned force_host_mode: 1;
14031 + unsigned reserved23_28 : 6;
14032 + unsigned term_sel_dl_pulse : 1;
14033 + unsigned ulpi_int_vbus_indicator : 1;
14034 + unsigned ulpi_ext_vbus_drv : 1;
14035 + unsigned ulpi_clk_sus_m : 1;
14036 + unsigned ulpi_auto_res : 1;
14037 + unsigned ulpi_fsls : 1;
14038 + unsigned otgutmifssel : 1;
14039 + unsigned phylpwrclksel : 1;
14040 + unsigned nptxfrwnden : 1;
14041 + unsigned usbtrdtim : 4;
14042 + unsigned hnpcap : 1;
14043 + unsigned srpcap : 1;
14044 + unsigned ddrsel : 1;
14045 + unsigned physel : 1;
14046 + unsigned fsintf : 1;
14047 + unsigned ulpi_utmi_sel : 1;
14048 + unsigned phyif : 1;
14049 + unsigned toutcal : 3;
14050 + } b;
14051 +} gusbcfg_data_t;
14052 +
14053 +/**
14054 + * This union represents the bit fields of the Core Reset Register
14055 + * (GRSTCTL). Set/clear the bits using the bit fields then write the
14056 + * <i>d32</i> value to the register.
14057 + */
14058 +typedef union grstctl_data
14059 +{
14060 + /** raw register data */
14061 + uint32_t d32;
14062 + /** register bits */
14063 + struct
14064 + {
14065 + /** AHB Master Idle. Indicates the AHB Master State
14066 + * Machine is in IDLE condition. */
14067 + unsigned ahbidle : 1;
14068 + /** DMA Request Signal. Indicated DMA request is in
14069 + * probress. Used for debug purpose. */
14070 + unsigned dmareq : 1;
14071 + /** Reserved */
14072 + unsigned reserved29_11 : 19;
14073 + /** TxFIFO Number (TxFNum) (Device and Host).
14074 + *
14075 + * This is the FIFO number which needs to be flushed,
14076 + * using the TxFIFO Flush bit. This field should not
14077 + * be changed until the TxFIFO Flush bit is cleared by
14078 + * the core.
14079 + * - 0x0 : Non Periodic TxFIFO Flush
14080 + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
14081 + * or Periodic TxFIFO in host mode
14082 + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
14083 + * - ...
14084 + * - 0xF : Periodic TxFIFO #15 Flush in device mode
14085 + * - 0x10: Flush all the Transmit NonPeriodic and
14086 + * Transmit Periodic FIFOs in the core
14087 + */
14088 + unsigned txfnum : 5;
14089 + /** TxFIFO Flush (TxFFlsh) (Device and Host).
14090 + *
14091 + * This bit is used to selectively flush a single or
14092 + * all transmit FIFOs. The application must first
14093 + * ensure that the core is not in the middle of a
14094 + * transaction. <p>The application should write into
14095 + * this bit, only after making sure that neither the
14096 + * DMA engine is writing into the TxFIFO nor the MAC
14097 + * is reading the data out of the FIFO. <p>The
14098 + * application should wait until the core clears this
14099 + * bit, before performing any operations. This bit
14100 + * will takes 8 clocks (slowest of PHY or AHB clock)
14101 + * to clear.
14102 + */
14103 + unsigned txfflsh : 1;
14104 + /** RxFIFO Flush (RxFFlsh) (Device and Host)
14105 + *
14106 + * The application can flush the entire Receive FIFO
14107 + * using this bit. <p>The application must first
14108 + * ensure that the core is not in the middle of a
14109 + * transaction. <p>The application should write into
14110 + * this bit, only after making sure that neither the
14111 + * DMA engine is reading from the RxFIFO nor the MAC
14112 + * is writing the data in to the FIFO. <p>The
14113 + * application should wait until the bit is cleared
14114 + * before performing any other operations. This bit
14115 + * will takes 8 clocks (slowest of PHY or AHB clock)
14116 + * to clear.
14117 + */
14118 + unsigned rxfflsh : 1;
14119 + /** In Token Sequence Learning Queue Flush
14120 + * (INTknQFlsh) (Device Only)
14121 + */
14122 + unsigned intknqflsh : 1;
14123 + /** Host Frame Counter Reset (Host Only)<br>
14124 + *
14125 + * The application can reset the (micro)frame number
14126 + * counter inside the core, using this bit. When the
14127 + * (micro)frame counter is reset, the subsequent SOF
14128 + * sent out by the core, will have a (micro)frame
14129 + * number of 0.
14130 + */
14131 + unsigned hstfrm : 1;
14132 + /** Hclk Soft Reset
14133 + *
14134 + * The application uses this bit to reset the control logic in
14135 + * the AHB clock domain. Only AHB clock domain pipelines are
14136 + * reset.
14137 + */
14138 + unsigned hsftrst : 1;
14139 + /** Core Soft Reset (CSftRst) (Device and Host)
14140 + *
14141 + * The application can flush the control logic in the
14142 + * entire core using this bit. This bit resets the
14143 + * pipelines in the AHB Clock domain as well as the
14144 + * PHY Clock domain.
14145 + *
14146 + * The state machines are reset to an IDLE state, the
14147 + * control bits in the CSRs are cleared, all the
14148 + * transmit FIFOs and the receive FIFO are flushed.
14149 + *
14150 + * The status mask bits that control the generation of
14151 + * the interrupt, are cleared, to clear the
14152 + * interrupt. The interrupt status bits are not
14153 + * cleared, so the application can get the status of
14154 + * any events that occurred in the core after it has
14155 + * set this bit.
14156 + *
14157 + * Any transactions on the AHB are terminated as soon
14158 + * as possible following the protocol. Any
14159 + * transactions on the USB are terminated immediately.
14160 + *
14161 + * The configuration settings in the CSRs are
14162 + * unchanged, so the software doesn't have to
14163 + * reprogram these registers (Device
14164 + * Configuration/Host Configuration/Core System
14165 + * Configuration/Core PHY Configuration).
14166 + *
14167 + * The application can write to this bit, any time it
14168 + * wants to reset the core. This is a self clearing
14169 + * bit and the core clears this bit after all the
14170 + * necessary logic is reset in the core, which may
14171 + * take several clocks, depending on the current state
14172 + * of the core.
14173 + */
14174 + unsigned csftrst : 1;
14175 + } b;
14176 +} grstctl_t;
14177 +
14178 +
14179 +/**
14180 + * This union represents the bit fields of the Core Interrupt Mask
14181 + * Register (GINTMSK). Set/clear the bits using the bit fields then
14182 + * write the <i>d32</i> value to the register.
14183 + */
14184 +typedef union gintmsk_data
14185 +{
14186 + /** raw register data */
14187 + uint32_t d32;
14188 + /** register bits */
14189 + struct
14190 + {
14191 + unsigned wkupintr : 1;
14192 + unsigned sessreqintr : 1;
14193 + unsigned disconnect : 1;
14194 + unsigned conidstschng : 1;
14195 + unsigned reserved27 : 1;
14196 + unsigned ptxfempty : 1;
14197 + unsigned hcintr : 1;
14198 + unsigned portintr : 1;
14199 + unsigned reserved22_23 : 2;
14200 + unsigned incomplisoout : 1;
14201 + unsigned incomplisoin : 1;
14202 + unsigned outepintr : 1;
14203 + unsigned inepintr : 1;
14204 + unsigned epmismatch : 1;
14205 + unsigned reserved16 : 1;
14206 + unsigned eopframe : 1;
14207 + unsigned isooutdrop : 1;
14208 + unsigned enumdone : 1;
14209 + unsigned usbreset : 1;
14210 + unsigned usbsuspend : 1;
14211 + unsigned erlysuspend : 1;
14212 + unsigned i2cintr : 1;
14213 + unsigned reserved8 : 1;
14214 + unsigned goutnakeff : 1;
14215 + unsigned ginnakeff : 1;
14216 + unsigned nptxfempty : 1;
14217 + unsigned rxstsqlvl : 1;
14218 + unsigned sofintr : 1;
14219 + unsigned otgintr : 1;
14220 + unsigned modemismatch : 1;
14221 + unsigned reserved0 : 1;
14222 + } b;
14223 +} gintmsk_data_t;
14224 +/**
14225 + * This union represents the bit fields of the Core Interrupt Register
14226 + * (GINTSTS). Set/clear the bits using the bit fields then write the
14227 + * <i>d32</i> value to the register.
14228 + */
14229 +typedef union gintsts_data
14230 +{
14231 + /** raw register data */
14232 + uint32_t d32;
14233 +#define DWC_SOF_INTR_MASK 0x0008
14234 + /** register bits */
14235 + struct
14236 + {
14237 +#define DWC_HOST_MODE 1
14238 + unsigned wkupintr : 1;
14239 + unsigned sessreqintr : 1;
14240 + unsigned disconnect : 1;
14241 + unsigned conidstschng : 1;
14242 + unsigned reserved27 : 1;
14243 + unsigned ptxfempty : 1;
14244 + unsigned hcintr : 1;
14245 + unsigned portintr : 1;
14246 + unsigned reserved22_23 : 2;
14247 + unsigned incomplisoout : 1;
14248 + unsigned incomplisoin : 1;
14249 + unsigned outepintr : 1;
14250 + unsigned inepint: 1;
14251 + unsigned epmismatch : 1;
14252 + unsigned intokenrx : 1;
14253 + unsigned eopframe : 1;
14254 + unsigned isooutdrop : 1;
14255 + unsigned enumdone : 1;
14256 + unsigned usbreset : 1;
14257 + unsigned usbsuspend : 1;
14258 + unsigned erlysuspend : 1;
14259 + unsigned i2cintr : 1;
14260 + unsigned reserved8 : 1;
14261 + unsigned goutnakeff : 1;
14262 + unsigned ginnakeff : 1;
14263 + unsigned nptxfempty : 1;
14264 + unsigned rxstsqlvl : 1;
14265 + unsigned sofintr : 1;
14266 + unsigned otgintr : 1;
14267 + unsigned modemismatch : 1;
14268 + unsigned curmode : 1;
14269 + } b;
14270 +} gintsts_data_t;
14271 +
14272 +
14273 +/**
14274 + * This union represents the bit fields in the Device Receive Status Read and
14275 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
14276 + * element then read out the bits using the <i>b</i>it elements.
14277 + */
14278 +typedef union device_grxsts_data {
14279 + /** raw register data */
14280 + uint32_t d32;
14281 + /** register bits */
14282 + struct {
14283 + unsigned reserved : 7;
14284 + unsigned fn : 4;
14285 +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
14286 +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
14287 +
14288 +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
14289 +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
14290 +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
14291 + unsigned pktsts : 4;
14292 + unsigned dpid : 2;
14293 + unsigned bcnt : 11;
14294 + unsigned epnum : 4;
14295 + } b;
14296 +} device_grxsts_data_t;
14297 +
14298 +/**
14299 + * This union represents the bit fields in the Host Receive Status Read and
14300 + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
14301 + * element then read out the bits using the <i>b</i>it elements.
14302 + */
14303 +typedef union host_grxsts_data {
14304 + /** raw register data */
14305 + uint32_t d32;
14306 + /** register bits */
14307 + struct {
14308 + unsigned reserved31_21 : 11;
14309 +#define DWC_GRXSTS_PKTSTS_IN 0x2
14310 +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
14311 +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
14312 +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
14313 + unsigned pktsts : 4;
14314 + unsigned dpid : 2;
14315 + unsigned bcnt : 11;
14316 + unsigned chnum : 4;
14317 + } b;
14318 +} host_grxsts_data_t;
14319 +
14320 +/**
14321 + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
14322 + * GNPTXFSIZ, DPTXFSIZn). Read the register into the <i>d32</i> element then
14323 + * read out the bits using the <i>b</i>it elements.
14324 + */
14325 +typedef union fifosize_data {
14326 + /** raw register data */
14327 + uint32_t d32;
14328 + /** register bits */
14329 + struct {
14330 + unsigned depth : 16;
14331 + unsigned startaddr : 16;
14332 + } b;
14333 +} fifosize_data_t;
14334 +
14335 +/**
14336 + * This union represents the bit fields in the Non-Periodic Transmit
14337 + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
14338 + * <i>d32</i> element then read out the bits using the <i>b</i>it
14339 + * elements.
14340 + */
14341 +typedef union gnptxsts_data {
14342 + /** raw register data */
14343 + uint32_t d32;
14344 + /** register bits */
14345 + struct {
14346 + unsigned reserved : 1;
14347 + /** Top of the Non-Periodic Transmit Request Queue
14348 + * - bits 30:27 - Channel/EP Number
14349 + * - bits 26:25 - Token Type
14350 + * - bit 24 - Terminate (Last entry for the selected
14351 + * channel/EP)
14352 + * - 2'b00 - IN/OUT
14353 + * - 2'b01 - Zero Length OUT
14354 + * - 2'b10 - PING/Complete Split
14355 + * - 2'b11 - Channel Halt
14356 +
14357 + */
14358 + unsigned nptxqtop_chnep : 4;
14359 + unsigned nptxqtop_token : 2;
14360 + unsigned nptxqtop_terminate : 1;
14361 + unsigned nptxqspcavail : 8;
14362 + unsigned nptxfspcavail : 16;
14363 + } b;
14364 +} gnptxsts_data_t;
14365 +
14366 +/**
14367 + * This union represents the bit fields in the Transmit
14368 + * FIFO Status Register (DTXFSTS). Read the register into the
14369 + * <i>d32</i> element then read out the bits using the <i>b</i>it
14370 + * elements.
14371 + */
14372 +typedef union dtxfsts_data /* fscz */ //*
14373 +{
14374 + /** raw register data */
14375 + uint32_t d32;
14376 + /** register bits */
14377 + struct {
14378 + unsigned reserved : 16;
14379 + unsigned txfspcavail : 16;
14380 + } b;
14381 +} dtxfsts_data_t;
14382 +
14383 +/**
14384 + * This union represents the bit fields in the I2C Control Register
14385 + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
14386 + * bits using the <i>b</i>it elements.
14387 + */
14388 +typedef union gi2cctl_data {
14389 + /** raw register data */
14390 + uint32_t d32;
14391 + /** register bits */
14392 + struct {
14393 + unsigned bsydne : 1;
14394 + unsigned rw : 1;
14395 + unsigned reserved : 2;
14396 + unsigned i2cdevaddr : 2;
14397 + unsigned i2csuspctl : 1;
14398 + unsigned ack : 1;
14399 + unsigned i2cen : 1;
14400 + unsigned addr : 7;
14401 + unsigned regaddr : 8;
14402 + unsigned rwdata : 8;
14403 + } b;
14404 +} gi2cctl_data_t;
14405 +
14406 +/**
14407 + * This union represents the bit fields in the User HW Config1
14408 + * Register. Read the register into the <i>d32</i> element then read
14409 + * out the bits using the <i>b</i>it elements.
14410 + */
14411 +typedef union hwcfg1_data {
14412 + /** raw register data */
14413 + uint32_t d32;
14414 + /** register bits */
14415 + struct {
14416 + unsigned ep_dir15 : 2;
14417 + unsigned ep_dir14 : 2;
14418 + unsigned ep_dir13 : 2;
14419 + unsigned ep_dir12 : 2;
14420 + unsigned ep_dir11 : 2;
14421 + unsigned ep_dir10 : 2;
14422 + unsigned ep_dir9 : 2;
14423 + unsigned ep_dir8 : 2;
14424 + unsigned ep_dir7 : 2;
14425 + unsigned ep_dir6 : 2;
14426 + unsigned ep_dir5 : 2;
14427 + unsigned ep_dir4 : 2;
14428 + unsigned ep_dir3 : 2;
14429 + unsigned ep_dir2 : 2;
14430 + unsigned ep_dir1 : 2;
14431 + unsigned ep_dir0 : 2;
14432 + } b;
14433 +} hwcfg1_data_t;
14434 +
14435 +/**
14436 + * This union represents the bit fields in the User HW Config2
14437 + * Register. Read the register into the <i>d32</i> element then read
14438 + * out the bits using the <i>b</i>it elements.
14439 + */
14440 +typedef union hwcfg2_data
14441 +{
14442 + /** raw register data */
14443 + uint32_t d32;
14444 + /** register bits */
14445 + struct {
14446 + /* GHWCFG2 */
14447 + unsigned reserved31 : 1;
14448 + unsigned dev_token_q_depth : 5;
14449 + unsigned host_perio_tx_q_depth : 2;
14450 + unsigned nonperio_tx_q_depth : 2;
14451 + unsigned rx_status_q_depth : 2;
14452 + unsigned dynamic_fifo : 1;
14453 + unsigned perio_ep_supported : 1;
14454 + unsigned num_host_chan : 4;
14455 + unsigned num_dev_ep : 4;
14456 + unsigned fs_phy_type : 2;
14457 +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
14458 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
14459 +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
14460 +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
14461 + unsigned hs_phy_type : 2;
14462 + unsigned point2point : 1;
14463 + unsigned architecture : 2;
14464 +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
14465 +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
14466 +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
14467 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
14468 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
14469 +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
14470 +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
14471 + unsigned op_mode : 3;
14472 + } b;
14473 +} hwcfg2_data_t;
14474 +
14475 +/**
14476 + * This union represents the bit fields in the User HW Config3
14477 + * Register. Read the register into the <i>d32</i> element then read
14478 + * out the bits using the <i>b</i>it elements.
14479 + */
14480 +typedef union hwcfg3_data
14481 +{
14482 + /** raw register data */
14483 + uint32_t d32;
14484 + /** register bits */
14485 + struct {
14486 + /* GHWCFG3 */
14487 + unsigned dfifo_depth : 16;
14488 + unsigned reserved15_13 : 3;
14489 + unsigned ahb_phy_clock_synch : 1;
14490 + unsigned synch_reset_type : 1;
14491 + unsigned optional_features : 1;
14492 + unsigned vendor_ctrl_if : 1;
14493 + unsigned i2c : 1;
14494 + unsigned otg_func : 1;
14495 + unsigned packet_size_cntr_width : 3;
14496 + unsigned xfer_size_cntr_width : 4;
14497 + } b;
14498 +} hwcfg3_data_t;
14499 +
14500 +/**
14501 + * This union represents the bit fields in the User HW Config4
14502 + * Register. Read the register into the <i>d32</i> element then read
14503 + * out the bits using the <i>b</i>it elements.
14504 + */
14505 +typedef union hwcfg4_data
14506 +{
14507 + /** raw register data */
14508 + uint32_t d32;
14509 + /** register bits */
14510 + struct {
14511 +unsigned reserved31_30 : 2; /* fscz */
14512 + unsigned num_in_eps : 4;
14513 + unsigned ded_fifo_en : 1;
14514 +
14515 + unsigned session_end_filt_en : 1;
14516 + unsigned b_valid_filt_en : 1;
14517 + unsigned a_valid_filt_en : 1;
14518 + unsigned vbus_valid_filt_en : 1;
14519 + unsigned iddig_filt_en : 1;
14520 + unsigned num_dev_mode_ctrl_ep : 4;
14521 + unsigned utmi_phy_data_width : 2;
14522 + unsigned min_ahb_freq : 9;
14523 + unsigned power_optimiz : 1;
14524 + unsigned num_dev_perio_in_ep : 4;
14525 + } b;
14526 +} hwcfg4_data_t;
14527 +
14528 +////////////////////////////////////////////
14529 +// Device Registers
14530 +/**
14531 + * Device Global Registers. <i>Offsets 800h-BFFh</i>
14532 + *
14533 + * The following structures define the size and relative field offsets
14534 + * for the Device Mode Registers.
14535 + *
14536 + * <i>These registers are visible only in Device mode and must not be
14537 + * accessed in Host mode, as the results are unknown.</i>
14538 + */
14539 +typedef struct dwc_otg_dev_global_regs
14540 +{
14541 + /** Device Configuration Register. <i>Offset 800h</i> */
14542 + volatile uint32_t dcfg;
14543 + /** Device Control Register. <i>Offset: 804h</i> */
14544 + volatile uint32_t dctl;
14545 + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
14546 + volatile uint32_t dsts;
14547 + /** Reserved. <i>Offset: 80Ch</i> */
14548 + uint32_t unused;
14549 + /** Device IN Endpoint Common Interrupt Mask
14550 + * Register. <i>Offset: 810h</i> */
14551 + volatile uint32_t diepmsk;
14552 + /** Device OUT Endpoint Common Interrupt Mask
14553 + * Register. <i>Offset: 814h</i> */
14554 + volatile uint32_t doepmsk;
14555 + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
14556 + volatile uint32_t daint;
14557 + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
14558 + * 81Ch</i> */
14559 + volatile uint32_t daintmsk;
14560 + /** Device IN Token Queue Read Register-1 (Read Only).
14561 + * <i>Offset: 820h</i> */
14562 + volatile uint32_t dtknqr1;
14563 + /** Device IN Token Queue Read Register-2 (Read Only).
14564 + * <i>Offset: 824h</i> */
14565 + volatile uint32_t dtknqr2;
14566 + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
14567 + volatile uint32_t dvbusdis;
14568 + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
14569 + volatile uint32_t dvbuspulse;
14570 + /** Device IN Token Queue Read Register-3 (Read Only).
14571 + * Device Thresholding control register (Read/Write)
14572 + * <i>Offset: 830h</i> */
14573 + volatile uint32_t dtknqr3_dthrctl;
14574 + /** Device IN Token Queue Read Register-4 (Read Only). /
14575 + * Device IN EPs empty Inr. Mask Register (Read/Write)
14576 + * <i>Offset: 834h</i> */
14577 + volatile uint32_t dtknqr4_fifoemptymsk;
14578 +} dwc_otg_device_global_regs_t;
14579 +
14580 +/**
14581 + * This union represents the bit fields in the Device Configuration
14582 + * Register. Read the register into the <i>d32</i> member then
14583 + * set/clear the bits using the <i>b</i>it elements. Write the
14584 + * <i>d32</i> member to the dcfg register.
14585 + */
14586 +typedef union dcfg_data
14587 +{
14588 + /** raw register data */
14589 + uint32_t d32;
14590 + /** register bits */
14591 + struct {
14592 + unsigned reserved31_23 : 9;
14593 + /** In Endpoint Mis-match count */
14594 + unsigned epmscnt : 5;
14595 + unsigned reserved13_17 : 5;
14596 + /** Periodic Frame Interval */
14597 +#define DWC_DCFG_FRAME_INTERVAL_80 0
14598 +#define DWC_DCFG_FRAME_INTERVAL_85 1
14599 +#define DWC_DCFG_FRAME_INTERVAL_90 2
14600 +#define DWC_DCFG_FRAME_INTERVAL_95 3
14601 + unsigned perfrint : 2;
14602 + /** Device Addresses */
14603 + unsigned devaddr : 7;
14604 + unsigned reserved3 : 1;
14605 + /** Non Zero Length Status OUT Handshake */
14606 +#define DWC_DCFG_SEND_STALL 1
14607 + unsigned nzstsouthshk : 1;
14608 + /** Device Speed */
14609 + unsigned devspd : 2;
14610 + } b;
14611 +} dcfg_data_t;
14612 +
14613 +/**
14614 + * This union represents the bit fields in the Device Control
14615 + * Register. Read the register into the <i>d32</i> member then
14616 + * set/clear the bits using the <i>b</i>it elements.
14617 + */
14618 +typedef union dctl_data
14619 +{
14620 + /** raw register data */
14621 + uint32_t d32;
14622 + /** register bits */
14623 + struct {
14624 + unsigned reserved : 20;
14625 + /** Power-On Programming Done */
14626 + unsigned pwronprgdone : 1;
14627 + /** Clear Global OUT NAK */
14628 + unsigned cgoutnak : 1;
14629 + /** Set Global OUT NAK */
14630 + unsigned sgoutnak : 1;
14631 + /** Clear Global Non-Periodic IN NAK */
14632 + unsigned cgnpinnak : 1;
14633 + /** Set Global Non-Periodic IN NAK */
14634 + unsigned sgnpinnak : 1;
14635 + /** Test Control */
14636 + unsigned tstctl : 3;
14637 + /** Global OUT NAK Status */
14638 + unsigned goutnaksts : 1;
14639 + /** Global Non-Periodic IN NAK Status */
14640 + unsigned gnpinnaksts : 1;
14641 + /** Soft Disconnect */
14642 + unsigned sftdiscon : 1;
14643 + /** Remote Wakeup */
14644 + unsigned rmtwkupsig : 1;
14645 + } b;
14646 +} dctl_data_t;
14647 +
14648 +/**
14649 + * This union represents the bit fields in the Device Status
14650 + * Register. Read the register into the <i>d32</i> member then
14651 + * set/clear the bits using the <i>b</i>it elements.
14652 + */
14653 +typedef union dsts_data
14654 +{
14655 + /** raw register data */
14656 + uint32_t d32;
14657 + /** register bits */
14658 + struct {
14659 + unsigned reserved22_31 : 10;
14660 + /** Frame or Microframe Number of the received SOF */
14661 + unsigned soffn : 14;
14662 + unsigned reserved4_7: 4;
14663 + /** Erratic Error */
14664 + unsigned errticerr : 1;
14665 + /** Enumerated Speed */
14666 +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
14667 +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
14668 +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
14669 +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
14670 + unsigned enumspd : 2;
14671 + /** Suspend Status */
14672 + unsigned suspsts : 1;
14673 + } b;
14674 +} dsts_data_t;
14675 +
14676 +
14677 +/**
14678 + * This union represents the bit fields in the Device IN EP Interrupt
14679 + * Register and the Device IN EP Common Mask Register.
14680 + *
14681 + * - Read the register into the <i>d32</i> member then set/clear the
14682 + * bits using the <i>b</i>it elements.
14683 + */
14684 +typedef union diepint_data
14685 +{
14686 + /** raw register data */
14687 + uint32_t d32;
14688 + /** register bits */
14689 + struct {
14690 + unsigned reserved07_31 : 23;
14691 + unsigned txfifoundrn : 1;
14692 + /** IN Endpoint HAK Effective mask */
14693 + unsigned emptyintr : 1;
14694 + /** IN Endpoint NAK Effective mask */
14695 + unsigned inepnakeff : 1;
14696 + /** IN Token Received with EP mismatch mask */
14697 + unsigned intknepmis : 1;
14698 + /** IN Token received with TxF Empty mask */
14699 + unsigned intktxfemp : 1;
14700 + /** TimeOUT Handshake mask (non-ISOC EPs) */
14701 + unsigned timeout : 1;
14702 + /** AHB Error mask */
14703 + unsigned ahberr : 1;
14704 + /** Endpoint disable mask */
14705 + unsigned epdisabled : 1;
14706 + /** Transfer complete mask */
14707 + unsigned xfercompl : 1;
14708 + } b;
14709 +} diepint_data_t;
14710 +/**
14711 + * This union represents the bit fields in the Device IN EP Common
14712 + * Interrupt Mask Register.
14713 + */
14714 +typedef union diepint_data diepmsk_data_t;
14715 +
14716 +/**
14717 + * This union represents the bit fields in the Device OUT EP Interrupt
14718 + * Registerand Device OUT EP Common Interrupt Mask Register.
14719 + *
14720 + * - Read the register into the <i>d32</i> member then set/clear the
14721 + * bits using the <i>b</i>it elements.
14722 + */
14723 +typedef union doepint_data
14724 +{
14725 + /** raw register data */
14726 + uint32_t d32;
14727 + /** register bits */
14728 + struct {
14729 + unsigned reserved04_31 : 27;
14730 + /** OUT Token Received when Endpoint Disabled */
14731 + unsigned outtknepdis : 1;
14732 + /** Setup Phase Done (contorl EPs) */
14733 + unsigned setup : 1;
14734 + /** AHB Error */
14735 + unsigned ahberr : 1;
14736 + /** Endpoint disable */
14737 + unsigned epdisabled : 1;
14738 + /** Transfer complete */
14739 + unsigned xfercompl : 1;
14740 + } b;
14741 +} doepint_data_t;
14742 +/**
14743 + * This union represents the bit fields in the Device OUT EP Common
14744 + * Interrupt Mask Register.
14745 + */
14746 +typedef union doepint_data doepmsk_data_t;
14747 +
14748 +
14749 +/**
14750 + * This union represents the bit fields in the Device All EP Interrupt
14751 + * and Mask Registers.
14752 + * - Read the register into the <i>d32</i> member then set/clear the
14753 + * bits using the <i>b</i>it elements.
14754 + */
14755 +typedef union daint_data
14756 +{
14757 + /** raw register data */
14758 + uint32_t d32;
14759 + /** register bits */
14760 + struct {
14761 + /** OUT Endpoint bits */
14762 + unsigned out : 16;
14763 + /** IN Endpoint bits */
14764 + unsigned in : 16;
14765 + } ep;
14766 + struct {
14767 + /** OUT Endpoint bits */
14768 + unsigned outep15 : 1;
14769 + unsigned outep14 : 1;
14770 + unsigned outep13 : 1;
14771 + unsigned outep12 : 1;
14772 + unsigned outep11 : 1;
14773 + unsigned outep10 : 1;
14774 + unsigned outep9 : 1;
14775 + unsigned outep8 : 1;
14776 + unsigned outep7 : 1;
14777 + unsigned outep6 : 1;
14778 + unsigned outep5 : 1;
14779 + unsigned outep4 : 1;
14780 + unsigned outep3 : 1;
14781 + unsigned outep2 : 1;
14782 + unsigned outep1 : 1;
14783 + unsigned outep0 : 1;
14784 + /** IN Endpoint bits */
14785 + unsigned inep15 : 1;
14786 + unsigned inep14 : 1;
14787 + unsigned inep13 : 1;
14788 + unsigned inep12 : 1;
14789 + unsigned inep11 : 1;
14790 + unsigned inep10 : 1;
14791 + unsigned inep9 : 1;
14792 + unsigned inep8 : 1;
14793 + unsigned inep7 : 1;
14794 + unsigned inep6 : 1;
14795 + unsigned inep5 : 1;
14796 + unsigned inep4 : 1;
14797 + unsigned inep3 : 1;
14798 + unsigned inep2 : 1;
14799 + unsigned inep1 : 1;
14800 + unsigned inep0 : 1;
14801 + } b;
14802 +} daint_data_t;
14803 +
14804 +/**
14805 + * This union represents the bit fields in the Device IN Token Queue
14806 + * Read Registers.
14807 + * - Read the register into the <i>d32</i> member.
14808 + * - READ-ONLY Register
14809 + */
14810 +typedef union dtknq1_data
14811 +{
14812 + /** raw register data */
14813 + uint32_t d32;
14814 + /** register bits */
14815 + struct {
14816 + /** EP Numbers of IN Tokens 0 ... 4 */
14817 + unsigned epnums0_5 : 24;
14818 + /** write pointer has wrapped. */
14819 + unsigned wrap_bit : 1;
14820 + /** Reserved */
14821 + unsigned reserved05_06 : 2;
14822 + /** In Token Queue Write Pointer */
14823 + unsigned intknwptr : 5;
14824 + }b;
14825 +} dtknq1_data_t;
14826 +
14827 +/**
14828 + * This union represents Threshold control Register
14829 + * - Read and write the register into the <i>d32</i> member.
14830 + * - READ-WRITABLE Register
14831 + */
14832 +typedef union dthrctl_data //* /*fscz */
14833 +{
14834 + /** raw register data */
14835 + uint32_t d32;
14836 + /** register bits */
14837 + struct {
14838 + /** Reserved */
14839 + unsigned reserved26_31 : 6;
14840 + /** Rx Thr. Length */
14841 + unsigned rx_thr_len : 9;
14842 + /** Rx Thr. Enable */
14843 + unsigned rx_thr_en : 1;
14844 + /** Reserved */
14845 + unsigned reserved11_15 : 5;
14846 + /** Tx Thr. Length */
14847 + unsigned tx_thr_len : 9;
14848 + /** ISO Tx Thr. Enable */
14849 + unsigned iso_thr_en : 1;
14850 + /** non ISO Tx Thr. Enable */
14851 + unsigned non_iso_thr_en : 1;
14852 +
14853 + }b;
14854 +} dthrctl_data_t;
14855 +
14856 +/**
14857 + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
14858 + * 900h-AFCh</i>
14859 + *
14860 + * There will be one set of endpoint registers per logical endpoint
14861 + * implemented.
14862 + *
14863 + * <i>These registers are visible only in Device mode and must not be
14864 + * accessed in Host mode, as the results are unknown.</i>
14865 + */
14866 +typedef struct dwc_otg_dev_in_ep_regs
14867 +{
14868 + /** Device IN Endpoint Control Register. <i>Offset:900h +
14869 + * (ep_num * 20h) + 00h</i> */
14870 + volatile uint32_t diepctl;
14871 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
14872 + uint32_t reserved04;
14873 + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
14874 + * (ep_num * 20h) + 08h</i> */
14875 + volatile uint32_t diepint;
14876 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
14877 + uint32_t reserved0C;
14878 + /** Device IN Endpoint Transfer Size
14879 + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
14880 + volatile uint32_t dieptsiz;
14881 + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
14882 + * (ep_num * 20h) + 14h</i> */
14883 + volatile uint32_t diepdma;
14884 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 18h - 900h +
14885 + * (ep_num * 20h) + 1Ch</i>*/
14886 + volatile uint32_t dtxfsts;
14887 + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 1Ch - 900h +
14888 + * (ep_num * 20h) + 1Ch</i>*/
14889 + uint32_t reserved18;
14890 +} dwc_otg_dev_in_ep_regs_t;
14891 +
14892 +/**
14893 + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
14894 + * B00h-CFCh</i>
14895 + *
14896 + * There will be one set of endpoint registers per logical endpoint
14897 + * implemented.
14898 + *
14899 + * <i>These registers are visible only in Device mode and must not be
14900 + * accessed in Host mode, as the results are unknown.</i>
14901 + */
14902 +typedef struct dwc_otg_dev_out_ep_regs
14903 +{
14904 + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
14905 + * (ep_num * 20h) + 00h</i> */
14906 + volatile uint32_t doepctl;
14907 + /** Device OUT Endpoint Frame number Register. <i>Offset:
14908 + * B00h + (ep_num * 20h) + 04h</i> */
14909 + volatile uint32_t doepfn;
14910 + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
14911 + * (ep_num * 20h) + 08h</i> */
14912 + volatile uint32_t doepint;
14913 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
14914 + uint32_t reserved0C;
14915 + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
14916 + * B00h + (ep_num * 20h) + 10h</i> */
14917 + volatile uint32_t doeptsiz;
14918 + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
14919 + * + (ep_num * 20h) + 14h</i> */
14920 + volatile uint32_t doepdma;
14921 + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 18h - B00h +
14922 + * (ep_num * 20h) + 1Ch</i> */
14923 + uint32_t unused[2];
14924 +} dwc_otg_dev_out_ep_regs_t;
14925 +
14926 +/**
14927 + * This union represents the bit fields in the Device EP Control
14928 + * Register. Read the register into the <i>d32</i> member then
14929 + * set/clear the bits using the <i>b</i>it elements.
14930 + */
14931 +typedef union depctl_data
14932 +{
14933 + /** raw register data */
14934 + uint32_t d32;
14935 + /** register bits */
14936 + struct {
14937 + /** Endpoint Enable */
14938 + unsigned epena : 1;
14939 + /** Endpoint Disable */
14940 + unsigned epdis : 1;
14941 + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
14942 + * Writing to this field sets the Endpoint DPID (DPID)
14943 + * field in this register to DATA1 Set Odd
14944 + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
14945 + * Writing to this field sets the Even/Odd
14946 + * (micro)frame (EO_FrNum) field to odd (micro) frame.
14947 + */
14948 + unsigned setd1pid : 1;
14949 + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
14950 + * Writing to this field sets the Endpoint DPID (DPID)
14951 + * field in this register to DATA0. Set Even
14952 + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
14953 + * Writing to this field sets the Even/Odd
14954 + * (micro)frame (EO_FrNum) field to even (micro)
14955 + * frame.
14956 + */
14957 + unsigned setd0pid : 1;
14958 + /** Set NAK */
14959 + unsigned snak : 1;
14960 + /** Clear NAK */
14961 + unsigned cnak : 1;
14962 + /** Tx Fifo Number
14963 + * IN EPn/IN EP0
14964 + * OUT EPn/OUT EP0 - reserved */
14965 + unsigned txfnum : 4;
14966 + /** Stall Handshake */
14967 + unsigned stall : 1;
14968 + /** Snoop Mode
14969 + * OUT EPn/OUT EP0
14970 + * IN EPn/IN EP0 - reserved */
14971 + unsigned snp : 1;
14972 + /** Endpoint Type
14973 + * 2'b00: Control
14974 + * 2'b01: Isochronous
14975 + * 2'b10: Bulk
14976 + * 2'b11: Interrupt */
14977 + unsigned eptype : 2;
14978 + /** NAK Status */
14979 + unsigned naksts : 1;
14980 + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
14981 + * This field contains the PID of the packet going to
14982 + * be received or transmitted on this endpoint. The
14983 + * application should program the PID of the first
14984 + * packet going to be received or transmitted on this
14985 + * endpoint , after the endpoint is
14986 + * activated. Application use the SetD1PID and
14987 + * SetD0PID fields of this register to program either
14988 + * D0 or D1 PID.
14989 + *
14990 + * The encoding for this field is
14991 + * - 0: D0
14992 + * - 1: D1
14993 + */
14994 + unsigned dpid : 1;
14995 + /** USB Active Endpoint */
14996 + unsigned usbactep : 1;
14997 + /** Next Endpoint
14998 + * IN EPn/IN EP0
14999 + * OUT EPn/OUT EP0 - reserved */
15000 + unsigned nextep : 4;
15001 + /** Maximum Packet Size
15002 + * IN/OUT EPn
15003 + * IN/OUT EP0 - 2 bits
15004 + * 2'b00: 64 Bytes
15005 + * 2'b01: 32
15006 + * 2'b10: 16
15007 + * 2'b11: 8 */
15008 +#define DWC_DEP0CTL_MPS_64 0
15009 +#define DWC_DEP0CTL_MPS_32 1
15010 +#define DWC_DEP0CTL_MPS_16 2
15011 +#define DWC_DEP0CTL_MPS_8 3
15012 + unsigned mps : 11;
15013 + } b;
15014 +} depctl_data_t;
15015 +
15016 +/**
15017 + * This union represents the bit fields in the Device EP Transfer
15018 + * Size Register. Read the register into the <i>d32</i> member then
15019 + * set/clear the bits using the <i>b</i>it elements.
15020 + */
15021 +typedef union deptsiz_data
15022 +{
15023 + /** raw register data */
15024 + uint32_t d32;
15025 + /** register bits */
15026 + struct {
15027 + unsigned reserved : 1;
15028 + /** Multi Count - Periodic IN endpoints */
15029 + unsigned mc : 2;
15030 + /** Packet Count */
15031 + unsigned pktcnt : 10;
15032 + /** Transfer size */
15033 + unsigned xfersize : 19;
15034 + } b;
15035 +} deptsiz_data_t;
15036 +
15037 +/**
15038 + * This union represents the bit fields in the Device EP 0 Transfer
15039 + * Size Register. Read the register into the <i>d32</i> member then
15040 + * set/clear the bits using the <i>b</i>it elements.
15041 + */
15042 +typedef union deptsiz0_data
15043 +{
15044 + /** raw register data */
15045 + uint32_t d32;
15046 + /** register bits */
15047 + struct {
15048 + unsigned reserved31 : 1;
15049 + /**Setup Packet Count (DOEPTSIZ0 Only) */
15050 + unsigned supcnt : 2;
15051 + /** Reserved */
15052 + unsigned reserved28_20 : 9;
15053 + /** Packet Count */
15054 + unsigned pktcnt : 1;
15055 + /** Reserved */
15056 + unsigned reserved18_7 : 12;
15057 + /** Transfer size */
15058 + unsigned xfersize : 7;
15059 + } b;
15060 +} deptsiz0_data_t;
15061 +
15062 +
15063 +/** Maximum number of Periodic FIFOs */
15064 +#define MAX_PERIO_FIFOS 15
15065 +/** Maximum number of TX FIFOs */
15066 +#define MAX_TX_FIFOS 15
15067 +/** Maximum number of Endpoints/HostChannels */
15068 +#define MAX_EPS_CHANNELS 16
15069 +//#define MAX_EPS_CHANNELS 4
15070 +
15071 +/**
15072 + * The dwc_otg_dev_if structure contains information needed to manage
15073 + * the DWC_otg controller acting in device mode. It represents the
15074 + * programming view of the device-specific aspects of the controller.
15075 + */
15076 +typedef struct dwc_otg_dev_if {
15077 + /** Pointer to device Global registers.
15078 + * Device Global Registers starting at offset 800h
15079 + */
15080 + dwc_otg_device_global_regs_t *dev_global_regs;
15081 +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
15082 +
15083 + /**
15084 + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
15085 + */
15086 + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
15087 +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
15088 +#define DWC_EP_REG_OFFSET 0x20
15089 +
15090 + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
15091 + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
15092 +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
15093 +
15094 + /* Device configuration information*/
15095 + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
15096 + //uint8_t num_eps; /**< Number of EPs range: 0-16 (includes EP0) */
15097 + //uint8_t num_perio_eps; /**< # of Periodic EP range: 0-15 */
15098 + /*fscz */
15099 + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
15100 + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
15101 +
15102 + /** Size of periodic FIFOs (Bytes) */
15103 + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
15104 +
15105 + /** Size of Tx FIFOs (Bytes) */
15106 + uint16_t tx_fifo_size[MAX_TX_FIFOS];
15107 +
15108 + /** Thresholding enable flags and length varaiables **/
15109 + uint16_t rx_thr_en;
15110 + uint16_t iso_tx_thr_en;
15111 + uint16_t non_iso_tx_thr_en;
15112 +
15113 + uint16_t rx_thr_length;
15114 + uint16_t tx_thr_length;
15115 +} dwc_otg_dev_if_t;
15116 +
15117 +/**
15118 + * This union represents the bit fields in the Power and Clock Gating Control
15119 + * Register. Read the register into the <i>d32</i> member then set/clear the
15120 + * bits using the <i>b</i>it elements.
15121 + */
15122 +typedef union pcgcctl_data
15123 +{
15124 + /** raw register data */
15125 + uint32_t d32;
15126 +
15127 + /** register bits */
15128 + struct {
15129 + unsigned reserved31_05 : 27;
15130 + /** PHY Suspended */
15131 + unsigned physuspended : 1;
15132 + /** Reset Power Down Modules */
15133 + unsigned rstpdwnmodule : 1;
15134 + /** Power Clamp */
15135 + unsigned pwrclmp : 1;
15136 + /** Gate Hclk */
15137 + unsigned gatehclk : 1;
15138 + /** Stop Pclk */
15139 + unsigned stoppclk : 1;
15140 + } b;
15141 +} pcgcctl_data_t;
15142 +
15143 +/////////////////////////////////////////////////
15144 +// Host Mode Register Structures
15145 +//
15146 +/**
15147 + * The Host Global Registers structure defines the size and relative
15148 + * field offsets for the Host Mode Global Registers. Host Global
15149 + * Registers offsets 400h-7FFh.
15150 +*/
15151 +typedef struct dwc_otg_host_global_regs
15152 +{
15153 + /** Host Configuration Register. <i>Offset: 400h</i> */
15154 + volatile uint32_t hcfg;
15155 + /** Host Frame Interval Register. <i>Offset: 404h</i> */
15156 + volatile uint32_t hfir;
15157 + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
15158 + volatile uint32_t hfnum;
15159 + /** Reserved. <i>Offset: 40Ch</i> */
15160 + uint32_t reserved40C;
15161 + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
15162 + volatile uint32_t hptxsts;
15163 + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
15164 + volatile uint32_t haint;
15165 + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
15166 + volatile uint32_t haintmsk;
15167 +} dwc_otg_host_global_regs_t;
15168 +
15169 +/**
15170 + * This union represents the bit fields in the Host Configuration Register.
15171 + * Read the register into the <i>d32</i> member then set/clear the bits using
15172 + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
15173 + */
15174 +typedef union hcfg_data
15175 +{
15176 + /** raw register data */
15177 + uint32_t d32;
15178 +
15179 + /** register bits */
15180 + struct {
15181 + /** Reserved */
15182 + //unsigned reserved31_03 : 29;
15183 + /** FS/LS Only Support */
15184 + unsigned fslssupp : 1;
15185 + /** FS/LS Phy Clock Select */
15186 +#define DWC_HCFG_30_60_MHZ 0
15187 +#define DWC_HCFG_48_MHZ 1
15188 +#define DWC_HCFG_6_MHZ 2
15189 + unsigned fslspclksel : 2;
15190 + } b;
15191 +} hcfg_data_t;
15192 +
15193 +/**
15194 + * This union represents the bit fields in the Host Frame Remaing/Number
15195 + * Register.
15196 + */
15197 +typedef union hfir_data
15198 +{
15199 + /** raw register data */
15200 + uint32_t d32;
15201 +
15202 + /** register bits */
15203 + struct {
15204 + unsigned reserved : 16;
15205 + unsigned frint : 16;
15206 + } b;
15207 +} hfir_data_t;
15208 +
15209 +/**
15210 + * This union represents the bit fields in the Host Frame Remaing/Number
15211 + * Register.
15212 + */
15213 +typedef union hfnum_data
15214 +{
15215 + /** raw register data */
15216 + uint32_t d32;
15217 +
15218 + /** register bits */
15219 + struct {
15220 + unsigned frrem : 16;
15221 +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
15222 + unsigned frnum : 16;
15223 + } b;
15224 +} hfnum_data_t;
15225 +
15226 +typedef union hptxsts_data
15227 +{
15228 + /** raw register data */
15229 + uint32_t d32;
15230 +
15231 + /** register bits */
15232 + struct {
15233 + /** Top of the Periodic Transmit Request Queue
15234 + * - bit 24 - Terminate (last entry for the selected channel)
15235 + * - bits 26:25 - Token Type
15236 + * - 2'b00 - Zero length
15237 + * - 2'b01 - Ping
15238 + * - 2'b10 - Disable
15239 + * - bits 30:27 - Channel Number
15240 + * - bit 31 - Odd/even microframe
15241 + */
15242 + unsigned ptxqtop_odd : 1;
15243 + unsigned ptxqtop_chnum : 4;
15244 + unsigned ptxqtop_token : 2;
15245 + unsigned ptxqtop_terminate : 1;
15246 + unsigned ptxqspcavail : 8;
15247 + unsigned ptxfspcavail : 16;
15248 + } b;
15249 +} hptxsts_data_t;
15250 +
15251 +/**
15252 + * This union represents the bit fields in the Host Port Control and Status
15253 + * Register. Read the register into the <i>d32</i> member then set/clear the
15254 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15255 + * hprt0 register.
15256 + */
15257 +typedef union hprt0_data
15258 +{
15259 + /** raw register data */
15260 + uint32_t d32;
15261 + /** register bits */
15262 + struct {
15263 + unsigned reserved19_31 : 13;
15264 +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
15265 +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
15266 +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
15267 + unsigned prtspd : 2;
15268 + unsigned prttstctl : 4;
15269 + unsigned prtpwr : 1;
15270 + unsigned prtlnsts : 2;
15271 + unsigned reserved9 : 1;
15272 + unsigned prtrst : 1;
15273 + unsigned prtsusp : 1;
15274 + unsigned prtres : 1;
15275 + unsigned prtovrcurrchng : 1;
15276 + unsigned prtovrcurract : 1;
15277 + unsigned prtenchng : 1;
15278 + unsigned prtena : 1;
15279 + unsigned prtconndet : 1;
15280 + unsigned prtconnsts : 1;
15281 + } b;
15282 +} hprt0_data_t;
15283 +
15284 +/**
15285 + * This union represents the bit fields in the Host All Interrupt
15286 + * Register.
15287 + */
15288 +typedef union haint_data
15289 +{
15290 + /** raw register data */
15291 + uint32_t d32;
15292 + /** register bits */
15293 + struct {
15294 + unsigned reserved : 16;
15295 + unsigned ch15 : 1;
15296 + unsigned ch14 : 1;
15297 + unsigned ch13 : 1;
15298 + unsigned ch12 : 1;
15299 + unsigned ch11 : 1;
15300 + unsigned ch10 : 1;
15301 + unsigned ch9 : 1;
15302 + unsigned ch8 : 1;
15303 + unsigned ch7 : 1;
15304 + unsigned ch6 : 1;
15305 + unsigned ch5 : 1;
15306 + unsigned ch4 : 1;
15307 + unsigned ch3 : 1;
15308 + unsigned ch2 : 1;
15309 + unsigned ch1 : 1;
15310 + unsigned ch0 : 1;
15311 + } b;
15312 + struct {
15313 + unsigned reserved : 16;
15314 + unsigned chint : 16;
15315 + } b2;
15316 +} haint_data_t;
15317 +
15318 +/**
15319 + * This union represents the bit fields in the Host All Interrupt
15320 + * Register.
15321 + */
15322 +typedef union haintmsk_data
15323 +{
15324 + /** raw register data */
15325 + uint32_t d32;
15326 + /** register bits */
15327 + struct {
15328 + unsigned reserved : 16;
15329 + unsigned ch15 : 1;
15330 + unsigned ch14 : 1;
15331 + unsigned ch13 : 1;
15332 + unsigned ch12 : 1;
15333 + unsigned ch11 : 1;
15334 + unsigned ch10 : 1;
15335 + unsigned ch9 : 1;
15336 + unsigned ch8 : 1;
15337 + unsigned ch7 : 1;
15338 + unsigned ch6 : 1;
15339 + unsigned ch5 : 1;
15340 + unsigned ch4 : 1;
15341 + unsigned ch3 : 1;
15342 + unsigned ch2 : 1;
15343 + unsigned ch1 : 1;
15344 + unsigned ch0 : 1;
15345 + } b;
15346 + struct {
15347 + unsigned reserved : 16;
15348 + unsigned chint : 16;
15349 + } b2;
15350 +} haintmsk_data_t;
15351 +
15352 +/**
15353 + * Host Channel Specific Registers. <i>500h-5FCh</i>
15354 + */
15355 +typedef struct dwc_otg_hc_regs
15356 +{
15357 + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
15358 + volatile uint32_t hcchar;
15359 + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
15360 + volatile uint32_t hcsplt;
15361 + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
15362 + volatile uint32_t hcint;
15363 + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
15364 + volatile uint32_t hcintmsk;
15365 + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
15366 + volatile uint32_t hctsiz;
15367 + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
15368 + volatile uint32_t hcdma;
15369 + /** Reserved. <i>Offset: 500h + (chan_num * 20h) + 18h - 500h + (chan_num * 20h) + 1Ch</i> */
15370 + uint32_t reserved[2];
15371 +} dwc_otg_hc_regs_t;
15372 +
15373 +/**
15374 + * This union represents the bit fields in the Host Channel Characteristics
15375 + * Register. Read the register into the <i>d32</i> member then set/clear the
15376 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15377 + * hcchar register.
15378 + */
15379 +typedef union hcchar_data
15380 +{
15381 + /** raw register data */
15382 + uint32_t d32;
15383 +
15384 + /** register bits */
15385 + struct {
15386 + /** Channel enable */
15387 + unsigned chen : 1;
15388 + /** Channel disable */
15389 + unsigned chdis : 1;
15390 + /**
15391 + * Frame to transmit periodic transaction.
15392 + * 0: even, 1: odd
15393 + */
15394 + unsigned oddfrm : 1;
15395 + /** Device address */
15396 + unsigned devaddr : 7;
15397 + /** Packets per frame for periodic transfers. 0 is reserved. */
15398 + unsigned multicnt : 2;
15399 + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
15400 + unsigned eptype : 2;
15401 + /** 0: Full/high speed device, 1: Low speed device */
15402 + unsigned lspddev : 1;
15403 + unsigned reserved : 1;
15404 + /** 0: OUT, 1: IN */
15405 + unsigned epdir : 1;
15406 + /** Endpoint number */
15407 + unsigned epnum : 4;
15408 + /** Maximum packet size in bytes */
15409 + unsigned mps : 11;
15410 + } b;
15411 +} hcchar_data_t;
15412 +
15413 +typedef union hcsplt_data
15414 +{
15415 + /** raw register data */
15416 + uint32_t d32;
15417 +
15418 + /** register bits */
15419 + struct {
15420 + /** Split Enble */
15421 + unsigned spltena : 1;
15422 + /** Reserved */
15423 + unsigned reserved : 14;
15424 + /** Do Complete Split */
15425 + unsigned compsplt : 1;
15426 + /** Transaction Position */
15427 +#define DWC_HCSPLIT_XACTPOS_MID 0
15428 +#define DWC_HCSPLIT_XACTPOS_END 1
15429 +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
15430 +#define DWC_HCSPLIT_XACTPOS_ALL 3
15431 + unsigned xactpos : 2;
15432 + /** Hub Address */
15433 + unsigned hubaddr : 7;
15434 + /** Port Address */
15435 + unsigned prtaddr : 7;
15436 + } b;
15437 +} hcsplt_data_t;
15438 +
15439 +
15440 +/**
15441 + * This union represents the bit fields in the Host All Interrupt
15442 + * Register.
15443 + */
15444 +typedef union hcint_data
15445 +{
15446 + /** raw register data */
15447 + uint32_t d32;
15448 + /** register bits */
15449 + struct {
15450 + /** Reserved */
15451 + unsigned reserved : 21;
15452 + /** Data Toggle Error */
15453 + unsigned datatglerr : 1;
15454 + /** Frame Overrun */
15455 + unsigned frmovrun : 1;
15456 + /** Babble Error */
15457 + unsigned bblerr : 1;
15458 + /** Transaction Err */
15459 + unsigned xacterr : 1;
15460 + /** NYET Response Received */
15461 + unsigned nyet : 1;
15462 + /** ACK Response Received */
15463 + unsigned ack : 1;
15464 + /** NAK Response Received */
15465 + unsigned nak : 1;
15466 + /** STALL Response Received */
15467 + unsigned stall : 1;
15468 + /** AHB Error */
15469 + unsigned ahberr : 1;
15470 + /** Channel Halted */
15471 + unsigned chhltd : 1;
15472 + /** Transfer Complete */
15473 + unsigned xfercomp : 1;
15474 + } b;
15475 +} hcint_data_t;
15476 +
15477 +/**
15478 + * This union represents the bit fields in the Host Channel Transfer Size
15479 + * Register. Read the register into the <i>d32</i> member then set/clear the
15480 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15481 + * hcchar register.
15482 + */
15483 +typedef union hctsiz_data
15484 +{
15485 + /** raw register data */
15486 + uint32_t d32;
15487 +
15488 + /** register bits */
15489 + struct {
15490 + /** Do PING protocol when 1 */
15491 + unsigned dopng : 1;
15492 + /**
15493 + * Packet ID for next data packet
15494 + * 0: DATA0
15495 + * 1: DATA2
15496 + * 2: DATA1
15497 + * 3: MDATA (non-Control), SETUP (Control)
15498 + */
15499 +#define DWC_HCTSIZ_DATA0 0
15500 +#define DWC_HCTSIZ_DATA1 2
15501 +#define DWC_HCTSIZ_DATA2 1
15502 +#define DWC_HCTSIZ_MDATA 3
15503 +#define DWC_HCTSIZ_SETUP 3
15504 + unsigned pid : 2;
15505 + /** Data packets to transfer */
15506 + unsigned pktcnt : 10;
15507 + /** Total transfer size in bytes */
15508 + unsigned xfersize : 19;
15509 + } b;
15510 +} hctsiz_data_t;
15511 +
15512 +/**
15513 + * This union represents the bit fields in the Host Channel Interrupt Mask
15514 + * Register. Read the register into the <i>d32</i> member then set/clear the
15515 + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
15516 + * hcintmsk register.
15517 + */
15518 +typedef union hcintmsk_data
15519 +{
15520 + /** raw register data */
15521 + uint32_t d32;
15522 +
15523 + /** register bits */
15524 + struct {
15525 + unsigned reserved : 21;
15526 + unsigned datatglerr : 1;
15527 + unsigned frmovrun : 1;
15528 + unsigned bblerr : 1;
15529 + unsigned xacterr : 1;
15530 + unsigned nyet : 1;
15531 + unsigned ack : 1;
15532 + unsigned nak : 1;
15533 + unsigned stall : 1;
15534 + unsigned ahberr : 1;
15535 + unsigned chhltd : 1;
15536 + unsigned xfercompl : 1;
15537 + } b;
15538 +} hcintmsk_data_t;
15539 +
15540 +/** OTG Host Interface Structure.
15541 + *
15542 + * The OTG Host Interface Structure structure contains information
15543 + * needed to manage the DWC_otg controller acting in host mode. It
15544 + * represents the programming view of the host-specific aspects of the
15545 + * controller.
15546 + */
15547 +typedef struct dwc_otg_host_if {
15548 + /** Host Global Registers starting at offset 400h.*/
15549 + dwc_otg_host_global_regs_t *host_global_regs;
15550 +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
15551 +
15552 + /** Host Port 0 Control and Status Register */
15553 + volatile uint32_t *hprt0;
15554 +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
15555 +
15556 +
15557 + /** Host Channel Specific Registers at offsets 500h-5FCh. */
15558 + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
15559 +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
15560 +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
15561 +
15562 +
15563 + /* Host configuration information */
15564 + /** Number of Host Channels (range: 1-16) */
15565 + uint8_t num_host_channels;
15566 + /** Periodic EPs supported (0: no, 1: yes) */
15567 + uint8_t perio_eps_supported;
15568 + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
15569 + uint16_t perio_tx_fifo_size;
15570 +
15571 +} dwc_otg_host_if_t;
15572 +
15573 +#endif
15574 --- a/arch/mips/lantiq/xway/Makefile
15575 +++ b/arch/mips/lantiq/xway/Makefile
15576 @@ -4,3 +4,4 @@
15577 obj-$(CONFIG_LANTIQ_MACH_EASY50712) += mach-easy50712.o
15578 obj-$(CONFIG_LANTIQ_MACH_EASY4010) += mach-easy4010.o
15579 obj-$(CONFIG_LANTIQ_MACH_ARV45XX) += mach-arv45xx.o
15580 +onj-y += dev-dwc_otg.o
15581 --- /dev/null
15582 +++ b/arch/mips/lantiq/xway/dev-dwc_otg.c
15583 @@ -0,0 +1,64 @@
15584 +/*
15585 + * This program is free software; you can redistribute it and/or modify
15586 + * it under the terms of the GNU General Public License as published by
15587 + * the Free Software Foundation; either version 2 of the License, or
15588 + * (at your option) any later version.
15589 + *
15590 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
15591 + */
15592 +
15593 +#include <linux/init.h>
15594 +#include <linux/module.h>
15595 +#include <linux/types.h>
15596 +#include <linux/string.h>
15597 +#include <linux/mtd/physmap.h>
15598 +#include <linux/kernel.h>
15599 +#include <linux/reboot.h>
15600 +#include <linux/platform_device.h>
15601 +#include <linux/leds.h>
15602 +#include <linux/etherdevice.h>
15603 +#include <linux/reboot.h>
15604 +#include <linux/time.h>
15605 +#include <linux/io.h>
15606 +#include <linux/gpio.h>
15607 +#include <linux/leds.h>
15608 +
15609 +#include <asm/bootinfo.h>
15610 +#include <asm/irq.h>
15611 +
15612 +#include <xway.h>
15613 +#include <xway_irq.h>
15614 +#include <lantiq_platform.h>
15615 +
15616 +static struct resource resources[] =
15617 +{
15618 + [0] = {
15619 + .name = "dwc_otg_membase",
15620 + .start = IFX_USB_IOMEM_BASE,
15621 + .end = IFX_USB_IOMEM_BASE + IFX_USB_IOMEM_SIZE - 1,
15622 + .flags = IORESOURCE_MEM,
15623 + },
15624 + [1] = {
15625 + .name = "dwc_otg_irq",
15626 + .start = IFX_USB_IRQ,
15627 + .flags = IORESOURCE_IRQ,
15628 + },
15629 +};
15630 +
15631 +static u64 dwc_dmamask = (u32)0x1fffffff;
15632 +
15633 +static struct platform_device platform_dev = {
15634 + .name = "dwc_otg",
15635 + .dev = {
15636 + .dma_mask = &dwc_dmamask,
15637 + },
15638 + .resource = resources,
15639 + .num_resources = ARRAY_SIZE(resources),
15640 +};
15641 +
15642 +int __init
15643 +xway_register_dwc(int pin)
15644 +{
15645 + lq_enable_irq(resources[1].start);
15646 + return platform_device_register(&platform_dev);
15647 +}
15648 --- /dev/null
15649 +++ b/arch/mips/lantiq/xway/dev-dwc_otg.h
15650 @@ -0,0 +1,17 @@
15651 +/*
15652 + * This program is free software; you can redistribute it and/or modify
15653 + * it under the terms of the GNU General Public License as published by
15654 + * the Free Software Foundation; either version 2 of the License, or
15655 + * (at your option) any later version.
15656 + *
15657 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
15658 + */
15659 +
15660 +#ifndef _LQ_DEV_DWC_H__
15661 +#define _LQ_DEV_DWC_H__
15662 +
15663 +#include <lantiq_platform.h>
15664 +
15665 +extern void __init xway_register_dwc(int pin);
15666 +
15667 +#endif
15668 --- a/arch/mips/lantiq/xway/mach-arv45xx.c
15669 +++ b/arch/mips/lantiq/xway/mach-arv45xx.c
15670 @@ -24,6 +24,7 @@
15671 #include <lantiq_platform.h>
15672
15673 #include "devices.h"
15674 +#include "dev-dwc_otg.h"
15675
15676 #define ARV452_LATCH_SWITCH (1 << 10)
15677
15678 @@ -133,6 +134,7 @@
15679 lq_register_pci(&lq_pci_data);
15680 lq_register_wdt();
15681 arv45xx_register_ethernet();
15682 + xway_register_dwc(14);
15683 }
15684
15685 MIPS_MACHINE(LANTIQ_MACH_ARV4518,
15686 @@ -152,6 +154,7 @@
15687 lq_register_pci(&lq_pci_data);
15688 lq_register_wdt();
15689 arv45xx_register_ethernet();
15690 + xway_register_dwc(28);
15691 }
15692
15693 MIPS_MACHINE(LANTIQ_MACH_ARV452,