1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_hcd.c $
7 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9 * otherwise expressly agreed to in writing between Synopsys and you.
11 * The Software IS NOT an item of Licensed Software or Licensed Product under
12 * any End User Software License Agreement or Agreement for Licensed Product
13 * with Synopsys or any supplement thereto. You are permitted to use and
14 * redistribute this Software in source and binary forms, with or without
15 * modification, provided that redistributions of source code must retain this
16 * notice. You may not view, use, disclose, copy or distribute this file or
17 * any information contained herein except pursuant to this license grant from
18 * Synopsys. If you do not agree with this notice, including the disclaimer
19 * below, then you are not authorized to use the Software.
21 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32 * ========================================================================== */
33 #ifndef DWC_DEVICE_ONLY
38 * This file contains the implementation of the HCD. In Linux, the HCD
39 * implements the hc_driver API.
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/moduleparam.h>
44 #include <linux/init.h>
45 #include <linux/device.h>
46 #include <linux/errno.h>
47 #include <linux/list.h>
48 #include <linux/interrupt.h>
49 #include <linux/string.h>
50 #include <linux/dma-mapping.h>
51 #include <linux/irq.h>
52 #include <linux/platform_device.h>
54 #include "dwc_otg_driver.h"
55 #include "dwc_otg_hcd.h"
56 #include "dwc_otg_regs.h"
58 static int dwc_otg_hcd_suspend(struct usb_hcd *hcd)
61 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (hcd);
62 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
64 pcgcctl_data_t pcgcctl;
67 if(core_if->op_state == B_PERIPHERAL)
69 DWC_PRINT("%s, usb device mode\n", __func__);
72 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
73 DWC_PRINT("%s, HPRT0:0x%x\n",__func__,hprt0.d32);
80 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
83 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
84 DWC_PRINT("%s, HPRT0:0x%x\n",__func__,hprt0.d32);
90 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
94 pcgcctl.d32 = dwc_read_reg32(core_if->pcgcctl);
95 pcgcctl.b.pwrclmp = 1;//power clamp
96 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
98 //pcgcctl.b.rstpdwnmodule = 1;//reset PDM
99 pcgcctl.b.stoppclk = 1;//stop phy clk
100 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
107 static int dwc_otg_hcd_resume(struct usb_hcd *hcd)
110 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (hcd);
111 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
113 pcgcctl_data_t pcgcctl;
114 gintmsk_data_t gintmsk;
116 if(core_if->op_state == B_PERIPHERAL)
118 DWC_PRINT("%s, usb device mode\n", __func__);
124 pcgcctl.d32 = dwc_read_reg32(core_if->pcgcctl);;
125 pcgcctl.b.stoppclk = 0;//stop phy clk
126 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
128 pcgcctl.b.pwrclmp = 0;//power clamp
129 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
134 gintmsk.d32 = dwc_read_reg32(&core_if->core_global_regs->gintmsk);
135 gintmsk.b.portintr = 0;
136 dwc_write_reg32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
138 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
139 DWC_PRINT("%s, HPRT0:0x%x\n",__func__,hprt0.d32);
143 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
145 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
146 DWC_PRINT("%s, HPRT0:0x%x\n",__func__,hprt0.d32);
151 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
155 hprt0.b.prtconndet = 1;
156 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
158 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
159 DWC_PRINT("%s, HPRT0:0x%x\n",__func__,hprt0.d32);
161 gintmsk.b.portintr = 1;
162 dwc_write_reg32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
168 static const char dwc_otg_hcd_name [] = "dwc_otg_hcd";
170 static const struct hc_driver dwc_otg_hc_driver = {
172 .description = dwc_otg_hcd_name,
173 .product_desc = "DWC OTG Controller",
174 .hcd_priv_size = sizeof(dwc_otg_hcd_t),
176 .irq = dwc_otg_hcd_irq,
178 .flags = HCD_MEMORY | HCD_USB2,
181 .start = dwc_otg_hcd_start,
186 * core/hcd.c call hcd->driver->bus_suspend
187 * otherwise system can not be suspended
190 .bus_suspend = dwc_otg_hcd_suspend,
191 .bus_resume = dwc_otg_hcd_resume,
193 .stop = dwc_otg_hcd_stop,
195 .urb_enqueue = dwc_otg_hcd_urb_enqueue,
196 .urb_dequeue = dwc_otg_hcd_urb_dequeue,
197 .endpoint_disable = dwc_otg_hcd_endpoint_disable,
199 .get_frame_number = dwc_otg_hcd_get_frame_number,
201 .hub_status_data = dwc_otg_hcd_hub_status_data,
202 .hub_control = dwc_otg_hcd_hub_control,
207 #ifdef CONFIG_USB11_HOST
208 static const struct hc_driver host11_hc_driver = {
210 .description = "host11_hcd",
211 .product_desc = "DWC OTG Controller",
212 .hcd_priv_size = sizeof(dwc_otg_hcd_t),
214 .irq = dwc_otg_hcd_irq,
216 .flags = HCD_MEMORY | HCD_USB2,
219 .start = dwc_otg_hcd_start,
224 * core/hcd.c call hcd->driver->bus_suspend
225 * otherwise system can not be suspended
228 .bus_suspend = dwc_otg_hcd_suspend,
229 .bus_resume = dwc_otg_hcd_resume,
231 .stop = dwc_otg_hcd_stop,
233 .urb_enqueue = dwc_otg_hcd_urb_enqueue,
234 .urb_dequeue = dwc_otg_hcd_urb_dequeue,
235 .endpoint_disable = dwc_otg_hcd_endpoint_disable,
237 .get_frame_number = dwc_otg_hcd_get_frame_number,
239 .hub_status_data = dwc_otg_hcd_hub_status_data,
240 .hub_control = dwc_otg_hcd_hub_control,
245 #ifdef CONFIG_USB20_HOST
246 static const struct hc_driver host20_hc_driver = {
248 .description = "host20_hcd",
249 .product_desc = "DWC OTG Controller",
250 .hcd_priv_size = sizeof(dwc_otg_hcd_t),
252 .irq = dwc_otg_hcd_irq,
254 .flags = HCD_MEMORY | HCD_USB2,
257 .start = dwc_otg_hcd_start,
262 * core/hcd.c call hcd->driver->bus_suspend
263 * otherwise system can not be suspended
266 .bus_suspend = dwc_otg_hcd_suspend,
267 .bus_resume = dwc_otg_hcd_resume,
269 .stop = dwc_otg_hcd_stop,
271 .urb_enqueue = dwc_otg_hcd_urb_enqueue,
272 .urb_dequeue = dwc_otg_hcd_urb_dequeue,
273 .endpoint_disable = dwc_otg_hcd_endpoint_disable,
275 .get_frame_number = dwc_otg_hcd_get_frame_number,
277 .hub_status_data = dwc_otg_hcd_hub_status_data,
278 .hub_control = dwc_otg_hcd_hub_control,
285 * Work queue function for starting the HCD when A-Cable is connected.
286 * The dwc_otg_hcd_start() must be called in a process context.
288 static void hcd_start_func(struct work_struct *work)
290 dwc_otg_hcd_t *dwc_otg_hcd = container_of(work, dwc_otg_hcd_t, start_work);
291 struct usb_hcd *hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
293 DWC_DEBUGPL(DBG_HCDV, "%s() %p %p\n", __func__, dwc_otg_hcd, hcd);
295 dwc_otg_hcd_start(hcd);
300 * HCD Callback function for starting the HCD when A-Cable is
303 * @param _p void pointer to the <code>struct usb_hcd</code>
305 static int32_t dwc_otg_hcd_start_cb(void *_p)
307 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_p);
308 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
311 if (core_if->op_state == B_HOST) {
313 * Reset the port. During a HNP mode switch the reset
314 * needs to occur within 1ms and have a duration of at
317 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
319 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
320 ((struct usb_hcd *)_p)->self.is_b_host = 1;
322 ((struct usb_hcd *)_p)->self.is_b_host = 0;
325 /* Need to start the HCD in a non-interrupt context. */
326 // INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func, _p);
327 INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
328 schedule_work(&dwc_otg_hcd->start_work);
335 * HCD Callback function for stopping the HCD.
337 * @param _p void pointer to the <code>struct usb_hcd</code>
339 static int32_t dwc_otg_hcd_stop_cb( void *_p )
341 struct usb_hcd *usb_hcd = (struct usb_hcd *)_p;
342 DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
343 dwc_otg_hcd_stop( usb_hcd );
347 static void del_xfer_timers(dwc_otg_hcd_t *_hcd)
351 int num_channels = _hcd->core_if->core_params->host_channels;
352 for (i = 0; i < num_channels; i++) {
353 del_timer(&_hcd->core_if->hc_xfer_timer[i]);
358 static void del_timers(dwc_otg_hcd_t *_hcd)
360 del_xfer_timers(_hcd);
361 del_timer(&_hcd->conn_timer);
365 * Processes all the URBs in a single list of QHs. Completes them with
366 * -ETIMEDOUT and frees the QTD.
368 static void kill_urbs_in_qh_list(dwc_otg_hcd_t *_hcd, struct list_head *_qh_list)
370 struct list_head *qh_item;
372 struct list_head *qtd_item;
375 list_for_each(qh_item, _qh_list) {
376 qh = list_entry(qh_item, dwc_otg_qh_t, qh_list_entry);
377 for (qtd_item = qh->qtd_list.next;
378 qtd_item != &qh->qtd_list;
379 qtd_item = qh->qtd_list.next) {
380 qtd = list_entry(qtd_item, dwc_otg_qtd_t, qtd_list_entry);
381 if (qtd->urb != NULL) {
382 dwc_otg_hcd_complete_urb(_hcd, qtd->urb,
385 dwc_otg_hcd_qtd_remove_and_free(qtd);
391 * Responds with an error status of ETIMEDOUT to all URBs in the non-periodic
392 * and periodic schedules. The QTD associated with each URB is removed from
393 * the schedule and freed. This function may be called when a disconnect is
394 * detected or when the HCD is being stopped.
396 static void kill_all_urbs(dwc_otg_hcd_t *_hcd)
398 kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_inactive);
399 kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_active);
400 kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_inactive);
401 kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_ready);
402 kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_assigned);
403 kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_queued);
407 * HCD Callback function for disconnect of the HCD.
409 * @param _p void pointer to the <code>struct usb_hcd</code>
411 static int32_t dwc_otg_hcd_disconnect_cb( void *_p )
414 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
416 //DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
419 * Set status flags for the hub driver.
421 // DWC_PRINT("dwc_otg_hcd_disconnect_cb");
422 dwc_otg_hcd->flags.b.port_connect_status_change = 1;
423 dwc_otg_hcd->flags.b.port_connect_status = 0;
426 * Shutdown any transfers in process by clearing the Tx FIFO Empty
427 * interrupt mask and status bits and disabling subsequent host
428 * channel interrupts.
431 intr.b.nptxfempty = 1;
432 intr.b.ptxfempty = 1;
434 dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, intr.d32, 0);
435 dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintsts, intr.d32, 0);
437 del_timers(dwc_otg_hcd);
440 * Turn off the vbus power only if the core has transitioned to device
441 * mode. If still in host mode, need to keep power on to detect a
444 if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
445 if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
446 hprt0_data_t hprt0 = { .d32=0 };
447 DWC_PRINT("Disconnect: PortPower off\n");
449 dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
452 dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
455 /* Respond with an error status to all URBs in the schedule. */
456 kill_all_urbs(dwc_otg_hcd);
458 if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
459 /* Clean up any host channels that were in use. */
463 dwc_otg_hc_regs_t *hc_regs;
464 hcchar_data_t hcchar;
466 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
468 if (!dwc_otg_hcd->core_if->dma_enable) {
469 /* Flush out any channel requests in slave mode. */
470 for (i = 0; i < num_channels; i++) {
471 channel = dwc_otg_hcd->hc_ptr_array[i];
472 if (list_empty(&channel->hc_list_entry)) {
473 hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
474 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
479 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
485 for (i = 0; i < num_channels; i++) {
486 channel = dwc_otg_hcd->hc_ptr_array[i];
487 if (list_empty(&channel->hc_list_entry)) {
488 hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
489 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
491 /* Halt the channel. */
493 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
496 dwc_otg_hc_cleanup(dwc_otg_hcd->core_if, channel);
497 list_add_tail(&channel->hc_list_entry,
498 &dwc_otg_hcd->free_hc_list);
503 /* A disconnect will end the session so the B-Device is no
504 * longer a B-host. */
505 ((struct usb_hcd *)_p)->self.is_b_host = 0;
510 * Connection timeout function. An OTG host is required to display a
511 * message if the device does not connect within 10 seconds.
513 void dwc_otg_hcd_connect_timeout( unsigned long _ptr )
515 DWC_DEBUGPL(DBG_HCDV, "%s(%x)\n", __func__, (int)_ptr);
516 DWC_PRINT( "Connect Timeout\n");
517 DWC_ERROR( "Device Not Connected/Responding\n" );
521 * Start the connection timer. An OTG host is required to display a
522 * message if the device does not connect within 10 seconds. The
523 * timer is deleted if a port connect interrupt occurs before the
526 static void dwc_otg_hcd_start_connect_timer( dwc_otg_hcd_t *_hcd)
528 init_timer( &_hcd->conn_timer );
529 _hcd->conn_timer.function = dwc_otg_hcd_connect_timeout;
530 _hcd->conn_timer.data = (unsigned long)0;
531 _hcd->conn_timer.expires = jiffies + (HZ*10);
532 add_timer( &_hcd->conn_timer );
536 * HCD Callback function for disconnect of the HCD.
538 * @param _p void pointer to the <code>struct usb_hcd</code>
540 static int32_t dwc_otg_hcd_session_start_cb( void *_p )
542 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
543 DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
544 dwc_otg_hcd_start_connect_timer( dwc_otg_hcd );
549 * HCD Callback structure for handling mode switching.
551 static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
552 .start = dwc_otg_hcd_start_cb,
553 .stop = dwc_otg_hcd_stop_cb,
554 .disconnect = dwc_otg_hcd_disconnect_cb,
555 .session_start = dwc_otg_hcd_session_start_cb,
560 * Reset tasklet function
562 static void reset_tasklet_func (unsigned long data)
564 dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t*)data;
565 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
568 DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
570 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
572 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
576 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
577 dwc_otg_hcd->flags.b.port_reset_change = 1;
582 static struct tasklet_struct reset_tasklet = {
585 .count = ATOMIC_INIT(0),
586 .func = reset_tasklet_func,
591 * Initializes the HCD. This function allocates memory for and initializes the
592 * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
593 * USB bus with the core and calls the hc_driver->start() function. It returns
594 * a negative error on failure.
596 extern uint32_t g_dbg_lvl;
597 int __devinit dwc_otg_hcd_init(struct device *dev)
599 struct usb_hcd *hcd = NULL;
600 dwc_otg_hcd_t *dwc_otg_hcd = NULL;
601 dwc_otg_device_t *otg_dev = dev->platform_data;
608 #if 1 //kaiker .these code must execute before usb_create_hcd
609 /* Set device flags indicating whether the HCD supports DMA. */
610 static u64 usb_dmamask = 0xffffffffUL;
611 if (otg_dev->core_if->dma_enable) {
612 dev->dma_mask = &usb_dmamask;
613 dev->coherent_dma_mask = ~0;
615 dev->dma_mask = (void *)0;
616 dev->coherent_dma_mask = 0;
619 DWC_PRINT("dwc_otg_hcd_init everest\n");
623 * Allocate memory for the base HCD plus the DWC OTG HCD.
624 * Initialize the base HCD.
626 hcd = usb_create_hcd(&dwc_otg_hc_driver, dev, dev_name(dev));
631 hcd->regs = otg_dev->base;
632 hcd->self.otg_port = 1;
634 /* Initialize the DWC OTG HCD. */
635 dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
637 spin_lock_init(&dwc_otg_hcd->global_lock);
639 dwc_otg_hcd->core_if = otg_dev->core_if;
640 otg_dev->hcd = dwc_otg_hcd;
642 /* Register the HCD CIL Callbacks */
643 dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
644 &hcd_cil_callbacks, hcd);
646 /* Initialize the non-periodic schedule. */
647 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
648 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
650 /* Initialize the periodic schedule. */
651 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
652 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
653 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
654 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
657 * Create a host channel descriptor for each host channel implemented
658 * in the controller. Initialize the channel descriptor array.
660 INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
661 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
662 for (i = 0; i < num_channels; i++) {
663 channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
664 if (channel == NULL) {
666 DWC_ERROR("%s: host channel allocation failed\n", __func__);
669 memset(channel, 0, sizeof(dwc_hc_t));
671 dwc_otg_hcd->hc_ptr_array[i] = channel;
673 init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
676 DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
679 /* Initialize the Connection timeout timer. */
680 init_timer( &dwc_otg_hcd->conn_timer );
682 /* Initialize reset tasklet. */
683 reset_tasklet.data = (unsigned long) dwc_otg_hcd;
684 dwc_otg_hcd->reset_tasklet = &reset_tasklet;
686 * Finish generic HCD initialization and start the HCD. This function
687 * allocates the DMA buffer pool, registers the USB bus, requests the
688 * IRQ line, and calls dwc_otg_hcd_start method.
690 retval = usb_add_hcd(hcd, platform_get_irq(to_platform_device(dev), 0),
693 DWC_ERROR("usb_add_hcd fail,everest\n");
697 * Allocate space for storing data on status transactions. Normally no
698 * data is sent, but this space acts as a bit bucket. This must be
699 * done after usb_add_hcd since that function allocates the DMA buffer
702 if (otg_dev->core_if->dma_enable) {
703 dwc_otg_hcd->status_buf =
704 dma_alloc_coherent(dev,
705 DWC_OTG_HCD_STATUS_BUF_SIZE,
706 &dwc_otg_hcd->status_buf_dma,
707 GFP_KERNEL | GFP_DMA);
709 dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
712 if (dwc_otg_hcd->status_buf == NULL) {
714 DWC_ERROR("%s: status_buf allocation failed\n", __func__);
718 DWC_PRINT("%s end,everest\n",__func__);
719 // DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
720 // dev->bus_id, hcd->self.busnum);
724 /* Error conditions */
728 dwc_otg_hcd_free(hcd);
732 DWC_PRINT("dwc_otg_hcd_init error,everest\n");
736 #ifdef CONFIG_USB11_HOST
737 static dwc_otg_cil_callbacks_t host11_cil_callbacks = {
738 .start = dwc_otg_hcd_start_cb,
739 .stop = dwc_otg_hcd_stop_cb,
740 .disconnect = dwc_otg_hcd_disconnect_cb,
741 .session_start = dwc_otg_hcd_session_start_cb,
745 static struct tasklet_struct host11_reset_tasklet = {
748 .count = ATOMIC_INIT(0),
749 .func = reset_tasklet_func,
753 int __devinit host11_hcd_init(struct device *dev)
755 struct usb_hcd *hcd = NULL;
756 dwc_otg_hcd_t *dwc_otg_hcd = NULL;
757 dwc_otg_device_t *otg_dev = dev->platform_data;
764 #if 1 //kaiker .these code must execute before usb_create_hcd
765 /* Set device flags indicating whether the HCD supports DMA. */
766 static u64 usb_dmamask = 0xffffffffUL;
767 if (otg_dev->core_if->dma_enable) {
768 // DWC_PRINT("Using DMA mode\n");
769 dev->dma_mask = &usb_dmamask;
770 dev->coherent_dma_mask = ~0;
772 // DWC_PRINT("Using Slave mode\n");
773 dev->dma_mask = (void *)0;
774 dev->coherent_dma_mask = 0;
777 DWC_PRINT("%s everest\n",__func__);
780 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
783 * Allocate memory for the base HCD plus the DWC OTG HCD.
784 * Initialize the base HCD.
786 hcd = usb_create_hcd(&host11_hc_driver, dev, dev_name(dev));
791 hcd->regs = otg_dev->base;
792 hcd->self.otg_port = 1;
794 /* Initialize the DWC OTG HCD. */
795 dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
796 dwc_otg_hcd->core_if = otg_dev->core_if;
797 otg_dev->hcd = dwc_otg_hcd;
799 spin_lock_init(&dwc_otg_hcd->global_lock);
802 /* Register the HCD CIL Callbacks */
803 dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
804 &host11_cil_callbacks, hcd);
806 /* Initialize the non-periodic schedule. */
807 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
808 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
810 /* Initialize the periodic schedule. */
811 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
812 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
813 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
814 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
817 * Create a host channel descriptor for each host channel implemented
818 * in the controller. Initialize the channel descriptor array.
820 INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
821 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
822 for (i = 0; i < num_channels; i++) {
823 channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
824 if (channel == NULL) {
826 DWC_ERROR("%s: host channel allocation failed\n", __func__);
829 memset(channel, 0, sizeof(dwc_hc_t));
831 dwc_otg_hcd->hc_ptr_array[i] = channel;
833 init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
836 DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
839 /* Initialize the Connection timeout timer. */
840 init_timer( &dwc_otg_hcd->conn_timer );
842 /* Initialize reset tasklet. */
843 host11_reset_tasklet.data = (unsigned long) dwc_otg_hcd;
844 dwc_otg_hcd->reset_tasklet = &host11_reset_tasklet;
846 * Finish generic HCD initialization and start the HCD. This function
847 * allocates the DMA buffer pool, registers the USB bus, requests the
848 * IRQ line, and calls dwc_otg_hcd_start method.
850 retval = usb_add_hcd(hcd, platform_get_irq(to_platform_device(dev), 0),
853 DWC_ERROR("usb_add_hcd fail,everest\n");
857 * Allocate space for storing data on status transactions. Normally no
858 * data is sent, but this space acts as a bit bucket. This must be
859 * done after usb_add_hcd since that function allocates the DMA buffer
862 if (otg_dev->core_if->dma_enable) {
863 dwc_otg_hcd->status_buf =
864 dma_alloc_coherent(dev,
865 DWC_OTG_HCD_STATUS_BUF_SIZE,
866 &dwc_otg_hcd->status_buf_dma,
867 GFP_KERNEL | GFP_DMA);
869 dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
872 if (dwc_otg_hcd->status_buf == NULL) {
874 DWC_ERROR("%s: status_buf allocation failed\n", __func__);
878 DWC_PRINT("%s end,everest\n",__func__);
879 // DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
880 // dev->bus_id, hcd->self.busnum);
884 /* Error conditions */
888 dwc_otg_hcd_free(hcd);
892 DWC_PRINT("dwc_otg_hcd_init error,everest\n");
896 #ifdef CONFIG_USB20_HOST
897 static dwc_otg_cil_callbacks_t host20_cil_callbacks = {
898 .start = dwc_otg_hcd_start_cb,
899 .stop = dwc_otg_hcd_stop_cb,
900 .disconnect = dwc_otg_hcd_disconnect_cb,
901 .session_start = dwc_otg_hcd_session_start_cb,
905 static struct tasklet_struct host20_reset_tasklet = {
908 .count = ATOMIC_INIT(0),
909 .func = reset_tasklet_func,
913 int __devinit host20_hcd_init(struct device *dev)
915 struct usb_hcd *hcd = NULL;
916 dwc_otg_hcd_t *dwc_otg_hcd = NULL;
917 dwc_otg_device_t *otg_dev = dev->platform_data;
924 #if 1 //kaiker .these code must execute before usb_create_hcd
925 /* Set device flags indicating whether the HCD supports DMA. */
926 static u64 usb_dmamask = 0xffffffffUL;
927 if (otg_dev->core_if->dma_enable) {
928 // DWC_PRINT("Using DMA mode\n");
929 dev->dma_mask = &usb_dmamask;
930 dev->coherent_dma_mask = ~0;
932 // DWC_PRINT("Using Slave mode\n");
933 dev->dma_mask = (void *)0;
934 dev->coherent_dma_mask = 0;
937 DWC_PRINT("%s everest\n",__func__);
940 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
943 * Allocate memory for the base HCD plus the DWC OTG HCD.
944 * Initialize the base HCD.
946 hcd = usb_create_hcd(&host20_hc_driver, dev, dev_name(dev));
951 hcd->regs = otg_dev->base;
952 hcd->self.otg_port = 1;
954 /* Initialize the DWC OTG HCD. */
955 dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
956 dwc_otg_hcd->core_if = otg_dev->core_if;
957 otg_dev->hcd = dwc_otg_hcd;
959 spin_lock_init(&dwc_otg_hcd->global_lock);
962 /* Register the HCD CIL Callbacks */
963 dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
964 &host20_cil_callbacks, hcd);
966 /* Initialize the non-periodic schedule. */
967 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
968 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
970 /* Initialize the periodic schedule. */
971 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
972 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
973 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
974 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
977 * Create a host channel descriptor for each host channel implemented
978 * in the controller. Initialize the channel descriptor array.
980 INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
981 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
982 for (i = 0; i < num_channels; i++) {
983 channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
984 if (channel == NULL) {
986 DWC_ERROR("%s: host channel allocation failed\n", __func__);
989 memset(channel, 0, sizeof(dwc_hc_t));
991 dwc_otg_hcd->hc_ptr_array[i] = channel;
993 init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
996 DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
999 /* Initialize the Connection timeout timer. */
1000 init_timer( &dwc_otg_hcd->conn_timer );
1002 /* Initialize reset tasklet. */
1003 host20_reset_tasklet.data = (unsigned long) dwc_otg_hcd;
1004 dwc_otg_hcd->reset_tasklet = &host20_reset_tasklet;
1006 * Finish generic HCD initialization and start the HCD. This function
1007 * allocates the DMA buffer pool, registers the USB bus, requests the
1008 * IRQ line, and calls dwc_otg_hcd_start method.
1010 retval = usb_add_hcd(hcd, platform_get_irq(to_platform_device(dev), 0),
1013 DWC_ERROR("usb_add_hcd fail,everest\n");
1017 * Allocate space for storing data on status transactions. Normally no
1018 * data is sent, but this space acts as a bit bucket. This must be
1019 * done after usb_add_hcd since that function allocates the DMA buffer
1022 if (otg_dev->core_if->dma_enable) {
1023 dwc_otg_hcd->status_buf =
1024 dma_alloc_coherent(dev,
1025 DWC_OTG_HCD_STATUS_BUF_SIZE,
1026 &dwc_otg_hcd->status_buf_dma,
1027 GFP_KERNEL | GFP_DMA);
1029 dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
1032 if (dwc_otg_hcd->status_buf == NULL) {
1034 DWC_ERROR("%s: status_buf allocation failed\n", __func__);
1038 DWC_PRINT("%s end,everest\n",__func__);
1039 // DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
1040 // dev->bus_id, hcd->self.busnum);
1044 /* Error conditions */
1046 usb_remove_hcd(hcd);
1048 dwc_otg_hcd_free(hcd);
1052 DWC_PRINT("dwc_otg_hcd_init error,everest\n");
1059 * Frees memory and resources associated with the HCD and deregisters the bus.
1061 void dwc_otg_hcd_remove(struct device *dev)
1063 dwc_otg_device_t *otg_dev = dev->platform_data;
1064 dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
1065 struct usb_hcd *hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
1067 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE\n");
1069 /* Turn off all interrupts */
1070 dwc_write_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0);
1071 dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gahbcfg, 1, 0);
1073 usb_remove_hcd(hcd);
1074 dwc_otg_hcd_free(hcd);
1081 /* =========================================================================
1082 * Linux HC Driver Functions
1083 * ========================================================================= */
1086 * Initializes dynamic portions of the DWC_otg HCD state.
1088 static void hcd_reinit(dwc_otg_hcd_t *_hcd)
1090 struct list_head *item;
1094 DWC_DEBUGPL(DBG_HCD, "%s: Enter\n", __func__);
1096 _hcd->flags.d32 = 0;
1098 _hcd->non_periodic_qh_ptr = &_hcd->non_periodic_sched_active;
1099 _hcd->non_periodic_channels = 0;
1100 _hcd->periodic_channels = 0;
1103 * Put all channels in the free channel list and clean up channel
1106 item = _hcd->free_hc_list.next;
1107 while (item != &_hcd->free_hc_list) {
1109 item = _hcd->free_hc_list.next;
1111 num_channels = _hcd->core_if->core_params->host_channels;
1112 for (i = 0; i < num_channels; i++) {
1113 channel = _hcd->hc_ptr_array[i];
1114 list_add_tail(&channel->hc_list_entry, &_hcd->free_hc_list);
1115 dwc_otg_hc_cleanup(_hcd->core_if, channel);
1118 /* Initialize the DWC core for host mode operation. */
1119 dwc_otg_core_host_init(_hcd->core_if);
1122 /** Initializes the DWC_otg controller and its root hub and prepares it for host
1123 * mode operation. Activates the root port. Returns 0 on success and a negative
1124 * error code on failure. */
1125 int dwc_otg_hcd_start(struct usb_hcd *_hcd)
1127 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1128 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
1129 unsigned long flags;
1131 struct usb_bus *bus;
1133 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
1134 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1136 DWC_PRINT("dwc_otg_hcd_start! everest\n");
1137 bus = hcd_to_bus(_hcd);
1138 _hcd->state = HC_STATE_RUNNING;
1140 /* Initialize and connect root hub if one is not already attached */
1141 if (bus->root_hub) {
1142 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
1143 /* Inform the HUB driver to resume. */
1144 usb_hcd_resume_root_hub(_hcd);
1150 struct usb_device *udev;6
1151 udev = usb_alloc_dev(NULL, bus, 0);
1152 udev->speed = USB_SPEED_HIGH;
1154 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
1159 if ((retval = usb_hcd_register_root_hub(udev, _hcd)) != 0) {
1160 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error registering %d\n", retval);
1165 /* Initialize the bus state. If the core is in Device Mode
1166 * HALT the USB bus and return. */
1167 if (dwc_otg_is_device_mode (core_if)) {
1168 DWC_PRINT("dwc_otg_hcd_start controller in device mode,everest\n");
1169 //_hcd->state = HC_STATE_HALT;
1172 hcd_reinit(dwc_otg_hcd);
1174 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1179 static void qh_list_free(dwc_otg_hcd_t *_hcd, struct list_head *_qh_list)
1181 struct list_head *item;
1184 if (_qh_list->next == NULL) {
1185 /* The list hasn't been initialized yet. */
1189 /* Ensure there are no QTDs or URBs left. */
1190 kill_urbs_in_qh_list(_hcd, _qh_list);
1192 for (item = _qh_list->next; item != _qh_list; item = _qh_list->next) {
1193 qh = list_entry(item, dwc_otg_qh_t, qh_list_entry);
1194 dwc_otg_hcd_qh_remove_and_free(_hcd, qh);
1199 * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
1202 void dwc_otg_hcd_stop(struct usb_hcd *_hcd)
1204 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1205 hprt0_data_t hprt0 = { .d32=0 };
1207 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
1209 /* Turn off all host-specific interrupts. */
1210 dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
1213 * The root hub should be disconnected before this function is called.
1214 * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
1215 * and the QH lists (via ..._hcd_endpoint_disable).
1218 /* Turn off the vbus power */
1219 DWC_PRINT("PortPower off\n");
1221 dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
1227 /** Returns the current frame number. */
1228 int dwc_otg_hcd_get_frame_number(struct usb_hcd *_hcd)
1230 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1233 hfnum.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->
1234 host_if->host_global_regs->hfnum);
1237 DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n", hfnum.b.frnum);
1239 return hfnum.b.frnum;
1243 * Frees secondary storage associated with the dwc_otg_hcd structure contained
1244 * in the struct usb_hcd field.
1246 void dwc_otg_hcd_free(struct usb_hcd *_hcd)
1248 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1251 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
1253 del_timers(dwc_otg_hcd);
1255 /* Free memory for QH/QTD lists */
1256 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
1257 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
1258 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
1259 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
1260 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
1261 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
1263 /* Free memory for the host channels. */
1264 for (i = 0; i < MAX_EPS_CHANNELS; i++) {
1265 dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
1267 DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n", i, hc);
1272 if (dwc_otg_hcd->core_if->dma_enable) {
1273 if (dwc_otg_hcd->status_buf_dma) {
1274 dma_free_coherent(_hcd->self.controller,
1275 DWC_OTG_HCD_STATUS_BUF_SIZE,
1276 dwc_otg_hcd->status_buf,
1277 dwc_otg_hcd->status_buf_dma);
1279 } else if (dwc_otg_hcd->status_buf != NULL) {
1280 kfree(dwc_otg_hcd->status_buf);
1288 static void dump_urb_info(struct urb *_urb, char* _fn_name)
1290 DWC_PRINT(" Device address: %d\n", usb_pipedevice(_urb->pipe));
1291 DWC_PRINT(" Endpoint: %d, %s\n", usb_pipeendpoint(_urb->pipe),
1292 (usb_pipein(_urb->pipe) ? "IN" : "OUT"));
1293 DWC_PRINT(" Endpoint type: %s\n",
1295 switch (usb_pipetype(_urb->pipe)) {
1296 case PIPE_CONTROL: pipetype = "CONTROL"; break;
1297 case PIPE_BULK: pipetype = "BULK"; break;
1298 case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
1299 case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
1300 default: pipetype = "UNKNOWN"; break;
1302 DWC_PRINT(" Speed: %s\n",
1304 switch (_urb->dev->speed) {
1305 case USB_SPEED_HIGH: speed = "HIGH"; break;
1306 case USB_SPEED_FULL: speed = "FULL"; break;
1307 case USB_SPEED_LOW: speed = "LOW"; break;
1308 default: speed = "UNKNOWN"; break;
1310 DWC_PRINT(" Max packet size: %d\n",
1311 usb_maxpacket(_urb->dev, _urb->pipe, usb_pipeout(_urb->pipe)));
1312 DWC_PRINT(" Data buffer length: %d\n", _urb->transfer_buffer_length);
1313 DWC_PRINT(" Transfer buffer: %p, Transfer DMA: %p\n",
1314 _urb->transfer_buffer, (void *)_urb->transfer_dma);
1315 DWC_PRINT(" Setup buffer: %p, Setup DMA: %p\n",
1316 _urb->setup_packet, (void *)_urb->setup_dma);
1317 DWC_PRINT(" Interval: %d\n", _urb->interval);
1318 if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
1320 for (i = 0; i < _urb->number_of_packets; i++) {
1321 DWC_PRINT(" ISO Desc %d:\n", i);
1322 DWC_PRINT(" offset: %d, length %d\n",
1323 _urb->iso_frame_desc[i].offset,
1324 _urb->iso_frame_desc[i].length);
1329 static void dump_channel_info(dwc_otg_hcd_t *_hcd,
1332 if (qh->channel != NULL) {
1333 dwc_hc_t *hc = qh->channel;
1334 struct list_head *item;
1335 dwc_otg_qh_t *qh_item;
1336 int num_channels = _hcd->core_if->core_params->host_channels;
1339 dwc_otg_hc_regs_t *hc_regs;
1340 hcchar_data_t hcchar;
1341 hcsplt_data_t hcsplt;
1342 hctsiz_data_t hctsiz;
1345 hc_regs = _hcd->core_if->host_if->hc_regs[hc->hc_num];
1346 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1347 hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
1348 hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
1349 hcdma = dwc_read_reg32(&hc_regs->hcdma);
1351 DWC_PRINT(" Assigned to channel %p:\n", hc);
1352 DWC_PRINT(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
1353 DWC_PRINT(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
1354 DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
1355 hc->dev_addr, hc->ep_num, hc->ep_is_in);
1356 DWC_PRINT(" ep_type: %d\n", hc->ep_type);
1357 DWC_PRINT(" max_packet: %d\n", hc->max_packet);
1358 DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
1359 DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
1360 DWC_PRINT(" halt_status: %d\n", hc->halt_status);
1361 DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
1362 DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
1363 DWC_PRINT(" qh: %p\n", hc->qh);
1364 DWC_PRINT(" NP inactive sched:\n");
1365 list_for_each(item, &_hcd->non_periodic_sched_inactive) {
1366 qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
1367 DWC_PRINT(" %p\n", qh_item);
1369 DWC_PRINT(" NP active sched:\n");
1370 list_for_each(item, &_hcd->non_periodic_sched_active) {
1371 qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
1372 DWC_PRINT(" %p\n", qh_item);
1374 DWC_PRINT(" Channels: \n");
1375 for (i = 0; i < num_channels; i++) {
1376 dwc_hc_t *hc = _hcd->hc_ptr_array[i];
1377 DWC_PRINT(" %2d: %p\n", i, hc);
1383 /** Starts processing a USB transfer request specified by a USB Request Block
1384 * (URB). mem_flags indicates the type of memory allocation to use while
1385 * processing this URB. */
1386 int dwc_otg_hcd_urb_enqueue(struct usb_hcd *_hcd,
1391 dwc_otg_hcd_t * dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1392 dwc_otg_qtd_t * qtd;
1393 unsigned long flags;
1395 retval = usb_hcd_link_urb_to_ep(_hcd, _urb);
1398 DWC_PRINT("%s, usb_hcd_link_urb_to_ep error\n", __func__);
1401 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1404 * Make sure the start of frame interrupt is enabled now that
1405 * we know we should have queued data. The SOF interrupt
1406 * handler automatically disables itself when idle to reduce
1407 * the number of interrupts. See dwc_otg_hcd_handle_sof_intr()
1410 dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0,
1414 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
1415 dump_urb_info(_urb, "dwc_otg_hcd_urb_enqueue");
1418 if (!dwc_otg_hcd->flags.b.port_connect_status) {
1419 /* No longer connected. */
1423 qtd = dwc_otg_hcd_qtd_create(_urb);
1425 DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
1429 retval = dwc_otg_hcd_qtd_add(qtd, dwc_otg_hcd);
1431 DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
1432 "Error status %d\n", retval);
1433 dwc_otg_hcd_qtd_free(qtd);
1436 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1441 /** Aborts/cancels a USB transfer request. Always returns 0 to indicate
1443 int dwc_otg_hcd_urb_dequeue(struct usb_hcd *_hcd, struct urb *_urb, int _status)
1445 unsigned long flags;
1446 dwc_otg_hcd_t * dwc_otg_hcd;
1447 dwc_otg_qtd_t * urb_qtd;
1449 struct usb_host_endpoint *_ep = _urb->ep;//dwc_urb_to_endpoint(_urb);
1452 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
1453 urb_qtd = (dwc_otg_qtd_t *) _urb->hcpriv;
1456 DWC_PRINT("%s=====================================================\n",__func__);
1457 DWC_PRINT("urb->ep is null\n");
1460 qh = (dwc_otg_qh_t *) _ep->hcpriv;
1461 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1462 retval = usb_hcd_check_unlink_urb(_hcd, _urb, _status);
1464 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1469 DWC_PRINT("%s,urb_qtd is null\n",__func__);
1472 dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1475 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
1476 dump_urb_info(_urb, "dwc_otg_hcd_urb_dequeue");
1477 if (urb_qtd == qh->qtd_in_process) {
1478 dump_channel_info(dwc_otg_hcd, qh);
1484 if (urb_qtd == qh->qtd_in_process) {
1485 /* The QTD is in process (it has been assigned to a channel). */
1486 if (dwc_otg_hcd->flags.b.port_connect_status) {
1489 * If still connected (i.e. in host mode), halt the
1490 * channel so it can be used for other transfers. If
1491 * no longer connected, the host registers can't be
1492 * written to halt the channel since the core is in
1495 dwc_otg_hc_halt(dwc_otg_hcd->core_if, qh->channel,
1496 DWC_OTG_HC_XFER_URB_DEQUEUE);
1501 * Free the QTD and clean up the associated QH. Leave the QH in the
1502 * schedule if it has any remaining QTDs.
1504 dwc_otg_hcd_qtd_remove_and_free(urb_qtd);
1505 if (urb_qtd == qh->qtd_in_process) {
1506 dwc_otg_hcd_qh_deactivate(dwc_otg_hcd, qh, 0);
1508 qh->qtd_in_process = NULL;
1509 } else if (list_empty(&qh->qtd_list)) {
1510 dwc_otg_hcd_qh_remove(dwc_otg_hcd, qh);
1513 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1514 _urb->hcpriv = NULL;
1515 usb_hcd_unlink_urb_from_ep(_hcd, _urb);
1516 /* Higher layer software sets URB status. */
1517 usb_hcd_giveback_urb(_hcd, _urb, _status);
1518 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
1519 DWC_PRINT("Called usb_hcd_giveback_urb()\n");
1520 DWC_PRINT(" urb->status = %d\n", _status);
1526 /** Frees resources in the DWC_otg controller related to a given endpoint. Also
1527 * clears state in the HCD related to the endpoint. Any URBs for the endpoint
1528 * must already be dequeued. */
1529 void dwc_otg_hcd_endpoint_disable(struct usb_hcd *_hcd,
1530 struct usb_host_endpoint *_ep)
1533 unsigned long flags;
1535 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1537 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1539 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
1540 "endpoint=%d\n", _ep->desc.bEndpointAddress,
1541 dwc_ep_addr_to_endpoint(_ep->desc.bEndpointAddress));
1543 qh = (dwc_otg_qh_t *)(_ep->hcpriv);
1546 /** Check that the QTD list is really empty */
1547 if (!list_empty(&qh->qtd_list)) {
1548 DWC_WARN("DWC OTG HCD EP DISABLE:"
1549 " QTD List for this endpoint is not empty\n");
1553 dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
1557 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1562 /** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
1563 * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
1566 * This function is called by the USB core when an interrupt occurs */
1567 irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *_hcd)
1570 unsigned long flags;
1571 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1573 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1575 result = IRQ_RETVAL(dwc_otg_hcd_handle_intr(dwc_otg_hcd));
1577 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1582 /** Creates Status Change bitmap for the root hub and root port. The bitmap is
1583 * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
1584 * is the status change indicator for the single root port. Returns 1 if either
1585 * change indicator is 1, otherwise returns 0. */
1586 int dwc_otg_hcd_hub_status_data(struct usb_hcd *_hcd,
1589 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1592 _buf[0] |= (dwc_otg_hcd->flags.b.port_connect_status_change ||
1593 dwc_otg_hcd->flags.b.port_reset_change ||
1594 dwc_otg_hcd->flags.b.port_enable_change ||
1595 dwc_otg_hcd->flags.b.port_suspend_change ||
1596 dwc_otg_hcd->flags.b.port_over_current_change) << 1;
1600 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
1601 " Root port status changed\n");
1602 DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
1603 dwc_otg_hcd->flags.b.port_connect_status_change);
1604 DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
1605 dwc_otg_hcd->flags.b.port_reset_change);
1606 DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
1607 dwc_otg_hcd->flags.b.port_enable_change);
1608 DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
1609 dwc_otg_hcd->flags.b.port_suspend_change);
1610 DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
1611 dwc_otg_hcd->flags.b.port_over_current_change);
1614 return (_buf[0] != 0);
1617 #ifdef DWC_HS_ELECT_TST
1619 * Quick and dirty hack to implement the HS Electrical Test
1620 * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
1622 * This code was copied from our userspace app "hset". It sends a
1623 * Get Device Descriptor control sequence in two parts, first the
1624 * Setup packet by itself, followed some time later by the In and
1625 * Ack packets. Rather than trying to figure out how to add this
1626 * functionality to the normal driver code, we just hijack the
1627 * hardware, using these two function to drive the hardware
1631 dwc_otg_core_global_regs_t *global_regs;
1632 dwc_otg_host_global_regs_t *hc_global_regs;
1633 dwc_otg_hc_regs_t *hc_regs;
1634 uint32_t *data_fifo;
1636 static void do_setup(void)
1638 gintsts_data_t gintsts;
1639 hctsiz_data_t hctsiz;
1640 hcchar_data_t hcchar;
1645 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
1648 dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
1651 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1652 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1655 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1656 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1659 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1660 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1663 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1664 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1667 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1670 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1673 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1676 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1677 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1680 * Send Setup packet (Get Device Descriptor)
1683 /* Make sure channel is disabled */
1684 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1685 if (hcchar.b.chen) {
1686 //fprintf(stderr, "Channel already enabled 1, HCCHAR = %08x\n", hcchar.d32);
1688 // hcchar.b.chen = 1;
1689 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
1694 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1695 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1698 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1699 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1702 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1703 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1706 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1707 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1710 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1713 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1716 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1718 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1719 //if (hcchar.b.chen) {
1720 // fprintf(stderr, "** Channel _still_ enabled 1, HCCHAR = %08x **\n", hcchar.d32);
1726 hctsiz.b.xfersize = 8;
1727 hctsiz.b.pktcnt = 1;
1728 hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
1729 dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
1732 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1733 hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
1738 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
1740 /* Fill FIFO with Setup data for Get Device Descriptor */
1741 data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
1742 dwc_write_reg32(data_fifo++, 0x01000680);
1743 dwc_write_reg32(data_fifo++, 0x00080000);
1745 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1746 //fprintf(stderr, "Waiting for HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
1748 /* Wait for host channel interrupt */
1750 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1751 } while (gintsts.b.hcintr == 0);
1753 //fprintf(stderr, "Got HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
1755 /* Disable HCINTs */
1756 dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
1758 /* Disable HAINTs */
1759 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
1762 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1763 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1766 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1767 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1770 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1771 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1774 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1777 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1780 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1783 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1784 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1787 static void do_in_ack(void)
1789 gintsts_data_t gintsts;
1790 hctsiz_data_t hctsiz;
1791 hcchar_data_t hcchar;
1794 host_grxsts_data_t grxsts;
1797 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
1800 dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
1803 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1804 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1807 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1808 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1811 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1812 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1815 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1816 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1819 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1822 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1825 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1828 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1829 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1832 * Receive Control In packet
1835 /* Make sure channel is disabled */
1836 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1837 if (hcchar.b.chen) {
1838 //fprintf(stderr, "Channel already enabled 2, HCCHAR = %08x\n", hcchar.d32);
1841 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
1846 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1847 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1850 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1851 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1854 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1855 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1858 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1859 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1862 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1865 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1868 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1870 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1871 //if (hcchar.b.chen) {
1872 // fprintf(stderr, "** Channel _still_ enabled 2, HCCHAR = %08x **\n", hcchar.d32);
1878 hctsiz.b.xfersize = 8;
1879 hctsiz.b.pktcnt = 1;
1880 hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
1881 dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
1884 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1885 hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
1890 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
1892 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1893 //fprintf(stderr, "Waiting for RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
1895 /* Wait for receive status queue interrupt */
1897 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1898 } while (gintsts.b.rxstsqlvl == 0);
1900 //fprintf(stderr, "Got RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
1903 grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
1904 //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
1906 /* Clear RXSTSQLVL in GINTSTS */
1908 gintsts.b.rxstsqlvl = 1;
1909 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1911 switch (grxsts.b.pktsts) {
1912 case DWC_GRXSTS_PKTSTS_IN:
1913 /* Read the data into the host buffer */
1914 if (grxsts.b.bcnt > 0) {
1916 int word_count = (grxsts.b.bcnt + 3) / 4;
1918 data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
1920 for (i = 0; i < word_count; i++) {
1921 (void)dwc_read_reg32(data_fifo++);
1925 //fprintf(stderr, "Received %u bytes\n", (unsigned)grxsts.b.bcnt);
1929 //fprintf(stderr, "** Unexpected GRXSTS packet status 1 **\n");
1933 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1934 //fprintf(stderr, "Waiting for RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
1936 /* Wait for receive status queue interrupt */
1938 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1939 } while (gintsts.b.rxstsqlvl == 0);
1941 //fprintf(stderr, "Got RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
1944 grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
1945 //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
1947 /* Clear RXSTSQLVL in GINTSTS */
1949 gintsts.b.rxstsqlvl = 1;
1950 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1952 switch (grxsts.b.pktsts) {
1953 case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
1957 //fprintf(stderr, "** Unexpected GRXSTS packet status 2 **\n");
1961 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1962 //fprintf(stderr, "Waiting for HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
1964 /* Wait for host channel interrupt */
1966 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1967 } while (gintsts.b.hcintr == 0);
1969 //fprintf(stderr, "Got HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
1972 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1973 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1976 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1977 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1980 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1981 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1984 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1987 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1990 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1993 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1994 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2001 * Send handshake packet
2005 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2006 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2009 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2010 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2013 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2014 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2017 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2020 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2023 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2026 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2027 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2029 /* Make sure channel is disabled */
2030 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2031 if (hcchar.b.chen) {
2032 //fprintf(stderr, "Channel already enabled 3, HCCHAR = %08x\n", hcchar.d32);
2035 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2040 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2041 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2044 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2045 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2048 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2049 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2052 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2053 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2056 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2059 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2062 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2064 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2065 //if (hcchar.b.chen) {
2066 // fprintf(stderr, "** Channel _still_ enabled 3, HCCHAR = %08x **\n", hcchar.d32);
2072 hctsiz.b.xfersize = 0;
2073 hctsiz.b.pktcnt = 1;
2074 hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
2075 dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2078 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2079 hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
2084 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2086 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2087 //fprintf(stderr, "Waiting for HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
2089 /* Wait for host channel interrupt */
2091 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2092 } while (gintsts.b.hcintr == 0);
2094 //fprintf(stderr, "Got HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
2096 /* Disable HCINTs */
2097 dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
2099 /* Disable HAINTs */
2100 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
2103 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2104 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2107 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2108 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2111 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2112 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2115 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2118 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2121 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2124 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2125 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2127 #endif /* DWC_HS_ELECT_TST */
2129 /** Handles hub class-specific requests.*/
2130 int dwc_otg_hcd_hub_control(struct usb_hcd *_hcd,
2138 unsigned long flags;
2140 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
2141 dwc_otg_core_if_t *core_if = hcd_to_dwc_otg_hcd (_hcd)->core_if;
2142 struct usb_hub_descriptor *desc;
2143 hprt0_data_t hprt0 = {.d32 = 0};
2145 uint32_t port_status;
2146 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
2149 case ClearHubFeature:
2150 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2151 "ClearHubFeature 0x%x\n", _wValue);
2153 case C_HUB_LOCAL_POWER:
2154 case C_HUB_OVER_CURRENT:
2155 /* Nothing required here */
2159 DWC_ERROR ("DWC OTG HCD - "
2160 "ClearHubFeature request %xh unknown\n", _wValue);
2163 case ClearPortFeature:
2164 if (!_wIndex || _wIndex > 1)
2168 case USB_PORT_FEAT_ENABLE:
2169 DWC_DEBUGPL (DBG_ANY, "DWC OTG HCD HUB CONTROL - "
2170 "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
2171 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2173 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2175 case USB_PORT_FEAT_SUSPEND:
2176 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2177 "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
2178 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2180 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2181 /* Clear Resume bit */
2184 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2186 case USB_PORT_FEAT_POWER:
2187 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2188 "ClearPortFeature USB_PORT_FEAT_POWER\n");
2189 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2191 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2193 case USB_PORT_FEAT_INDICATOR:
2194 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2195 "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
2196 /* Port inidicator not supported */
2198 case USB_PORT_FEAT_C_CONNECTION:
2199 /* Clears drivers internal connect status change
2201 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2202 "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
2203 dwc_otg_hcd->flags.b.port_connect_status_change = 0;
2205 case USB_PORT_FEAT_C_RESET:
2206 /* Clears the driver's internal Port Reset Change
2208 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2209 "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
2210 dwc_otg_hcd->flags.b.port_reset_change = 0;
2212 case USB_PORT_FEAT_C_ENABLE:
2213 /* Clears the driver's internal Port
2214 * Enable/Disable Change flag */
2215 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2216 "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
2217 dwc_otg_hcd->flags.b.port_enable_change = 0;
2219 case USB_PORT_FEAT_C_SUSPEND:
2220 /* Clears the driver's internal Port Suspend
2221 * Change flag, which is set when resume signaling on
2222 * the host port is complete */
2223 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2224 "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
2225 dwc_otg_hcd->flags.b.port_suspend_change = 0;
2227 case USB_PORT_FEAT_C_OVER_CURRENT:
2228 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2229 "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
2230 dwc_otg_hcd->flags.b.port_over_current_change = 0;
2234 DWC_ERROR ("DWC OTG HCD - "
2235 "ClearPortFeature request %xh "
2236 "unknown or unsupported\n", _wValue);
2239 case GetHubDescriptor:
2240 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2241 "GetHubDescriptor\n");
2242 desc = (struct usb_hub_descriptor *)_buf;
2243 desc->bDescLength = 9;
2244 desc->bDescriptorType = 0x29;
2245 desc->bNbrPorts = 1;
2246 desc->wHubCharacteristics = 0x08;
2247 desc->bPwrOn2PwrGood = 1;
2248 desc->bHubContrCurrent = 0;
2249 desc->bitmap[0] = 0;
2250 desc->bitmap[1] = 0xff;
2253 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2255 memset (_buf, 0, 4);
2258 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2261 if (!_wIndex || _wIndex > 1)
2266 if (dwc_otg_hcd->flags.b.port_connect_status_change)
2267 port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
2269 if (dwc_otg_hcd->flags.b.port_enable_change)
2270 port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
2272 if (dwc_otg_hcd->flags.b.port_suspend_change)
2273 port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
2275 if (dwc_otg_hcd->flags.b.port_reset_change)
2276 port_status |= (1 << USB_PORT_FEAT_C_RESET);
2278 if (dwc_otg_hcd->flags.b.port_over_current_change) {
2279 DWC_ERROR("Device Not Supported\n");
2280 port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
2283 if (!dwc_otg_hcd->flags.b.port_connect_status) {
2285 * The port is disconnected, which means the core is
2286 * either in device mode or it soon will be. Just
2287 * return 0's for the remainder of the port status
2288 * since the port register can't be read if the core
2289 * is in device mode.
2291 *((__le32 *) _buf) = cpu_to_le32(port_status);
2295 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
2296 DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
2298 if (hprt0.b.prtconnsts)
2299 port_status |= (1 << USB_PORT_FEAT_CONNECTION);
2302 port_status |= (1 << USB_PORT_FEAT_ENABLE);
2304 if (hprt0.b.prtsusp)
2305 port_status |= (1 << USB_PORT_FEAT_SUSPEND);
2307 if (hprt0.b.prtovrcurract)
2308 port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
2311 port_status |= (1 << USB_PORT_FEAT_RESET);
2314 port_status |= (1 << USB_PORT_FEAT_POWER);
2316 if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
2317 port_status |= (1 << USB_PORT_FEAT_HIGHSPEED);
2319 else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
2320 port_status |= (1 << USB_PORT_FEAT_LOWSPEED);
2322 if (hprt0.b.prttstctl)
2323 port_status |= (1 << USB_PORT_FEAT_TEST);
2325 /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
2327 *((__le32 *) _buf) = cpu_to_le32(port_status);
2331 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2333 /* No HUB features supported */
2335 case SetPortFeature:
2336 if (_wValue != USB_PORT_FEAT_TEST && (!_wIndex || _wIndex > 1))
2339 if (!dwc_otg_hcd->flags.b.port_connect_status) {
2341 * The port is disconnected, which means the core is
2342 * either in device mode or it soon will be. Just
2343 * return without doing anything since the port
2344 * register can't be written if the core is in device
2351 case USB_PORT_FEAT_SUSPEND:
2352 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2353 "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
2354 if (_hcd->self.otg_port == _wIndex &&
2355 _hcd->self.b_hnp_enable) {
2356 gotgctl_data_t gotgctl = {.d32=0};
2357 gotgctl.b.hstsethnpen = 1;
2358 dwc_modify_reg32( &core_if->core_global_regs->gotgctl,
2360 core_if->op_state = A_SUSPEND;
2362 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2363 hprt0.b.prtsusp = 1;
2364 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2365 //DWC_PRINT( "SUSPEND: HPRT0=%0x\n", hprt0.d32);
2366 /* Suspend the Phy Clock */
2368 pcgcctl_data_t pcgcctl = {.d32=0};
2369 pcgcctl.b.stoppclk = 1;
2370 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
2373 /* For HNP the bus must be suspended for at least 200ms.*/
2374 if (_hcd->self.b_hnp_enable) {
2376 //DWC_PRINT( "SUSPEND: wait complete! (%d)\n", _hcd->state);
2379 case USB_PORT_FEAT_POWER:
2380 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2381 "SetPortFeature - USB_PORT_FEAT_POWER\n");
2382 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2384 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2386 case USB_PORT_FEAT_RESET:
2387 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2388 "SetPortFeature - USB_PORT_FEAT_RESET\n");
2389 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2390 /* When B-Host the Port reset bit is set in
2391 * the Start HCD Callback function, so that
2392 * the reset is started within 1ms of the HNP
2393 * success interrupt. */
2394 if (!_hcd->self.is_b_host) {
2396 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2398 /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
2401 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2404 #ifdef DWC_HS_ELECT_TST
2405 case USB_PORT_FEAT_TEST:
2408 gintmsk_data_t gintmsk;
2410 t = (_wIndex >> 8); /* MSB wIndex USB */
2411 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2412 "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
2413 warn("USB_PORT_FEAT_TEST %d\n", t);
2415 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2416 hprt0.b.prttstctl = t;
2417 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2419 /* Setup global vars with reg addresses (quick and
2420 * dirty hack, should be cleaned up)
2422 global_regs = core_if->core_global_regs;
2423 hc_global_regs = core_if->host_if->host_global_regs;
2424 hc_regs = (dwc_otg_hc_regs_t *)((char *)global_regs + 0x500);
2425 data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
2427 if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
2428 /* Save current interrupt mask */
2429 gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
2431 /* Disable all interrupts while we muck with
2432 * the hardware directly
2434 dwc_write_reg32(&global_regs->gintmsk, 0);
2436 /* 15 second delay per the test spec */
2439 /* Drive suspend on the root port */
2440 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2441 hprt0.b.prtsusp = 1;
2443 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2445 /* 15 second delay per the test spec */
2448 /* Drive resume on the root port */
2449 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2450 hprt0.b.prtsusp = 0;
2452 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2455 /* Clear the resume bit */
2457 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2459 /* Restore interrupts */
2460 dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
2461 } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
2462 /* Save current interrupt mask */
2463 gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
2465 /* Disable all interrupts while we muck with
2466 * the hardware directly
2468 dwc_write_reg32(&global_regs->gintmsk, 0);
2470 /* 15 second delay per the test spec */
2473 /* Send the Setup packet */
2476 /* 15 second delay so nothing else happens for awhile */
2479 /* Restore interrupts */
2480 dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
2481 } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
2482 /* Save current interrupt mask */
2483 gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
2485 /* Disable all interrupts while we muck with
2486 * the hardware directly
2488 dwc_write_reg32(&global_regs->gintmsk, 0);
2490 /* Send the Setup packet */
2493 /* 15 second delay so nothing else happens for awhile */
2496 /* Send the In and Ack packets */
2499 /* 15 second delay so nothing else happens for awhile */
2502 /* Restore interrupts */
2503 dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
2508 #endif /* DWC_HS_ELECT_TST */
2510 case USB_PORT_FEAT_INDICATOR:
2511 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2512 "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
2517 DWC_ERROR ("DWC OTG HCD - "
2518 "SetPortFeature request %xh "
2519 "unknown or unsupported\n", _wValue);
2526 DWC_WARN ("DWC OTG HCD - "
2527 "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
2528 _typeReq, _wIndex, _wValue);
2532 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
2538 * Assigns transactions from a QTD to a free host channel and initializes the
2539 * host channel to perform the transactions. The host channel is removed from
2542 * @param _hcd The HCD state structure.
2543 * @param _qh Transactions from the first QTD for this QH are selected and
2544 * assigned to a free host channel.
2546 static void assign_and_init_hc(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
2552 DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p)\n", __func__, _hcd, _qh);
2553 hc = list_entry(_hcd->free_hc_list.next, dwc_hc_t, hc_list_entry);
2555 /* Remove the host channel from the free list. */
2556 list_del_init(&hc->hc_list_entry);
2558 qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
2561 _qh->qtd_in_process = qtd;
2564 * Use usb_pipedevice to determine device address. This address is
2565 * 0 before the SET_ADDRESS command and the correct address afterward.
2567 hc->dev_addr = usb_pipedevice(urb->pipe);
2568 hc->ep_num = usb_pipeendpoint(urb->pipe);
2570 if (urb->dev->speed == USB_SPEED_LOW) {
2571 hc->speed = DWC_OTG_EP_SPEED_LOW;
2573 * yk@rk 20101216 fix bandwidth check error when full/low speed
2576 _hcd->core_if->core_params->speed = DWC_SPEED_PARAM_FULL;
2577 } else if (urb->dev->speed == USB_SPEED_FULL) {
2578 hc->speed = DWC_OTG_EP_SPEED_FULL;
2580 * yk@rk 20101216 fix bandwidth check error when full/low speed
2581 * device connected. warning: only support 1 device at root hub.
2583 _hcd->core_if->core_params->speed = DWC_SPEED_PARAM_FULL;
2585 hc->speed = DWC_OTG_EP_SPEED_HIGH;
2588 hc->max_packet = dwc_max_packet(_qh->maxp);
2590 hc->xfer_started = 0;
2591 hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
2592 hc->error_state = (qtd->error_count > 0);
2593 hc->halt_on_queue = 0;
2594 hc->halt_pending = 0;
2598 * The following values may be modified in the transfer type section
2599 * below. The xfer_len value may be reduced when the transfer is
2600 * started to accommodate the max widths of the XferSize and PktCnt
2601 * fields in the HCTSIZn register.
2603 hc->do_ping = _qh->ping_state;
2604 hc->ep_is_in = (usb_pipein(urb->pipe) != 0);
2605 hc->data_pid_start = _qh->data_toggle;
2606 hc->multi_count = 1;
2608 if (_hcd->core_if->dma_enable) {
2609 hc->xfer_buff = (uint8_t *)urb->transfer_dma + urb->actual_length;
2611 hc->xfer_buff = (uint8_t *)urb->transfer_buffer + urb->actual_length;
2613 hc->xfer_len = urb->transfer_buffer_length - urb->actual_length;
2617 * Set the split attributes
2620 if (_qh->do_split) {
2622 hc->xact_pos = qtd->isoc_split_pos;
2623 hc->complete_split = qtd->complete_split;
2624 hc->hub_addr = urb->dev->tt->hub->devnum;
2625 hc->port_addr = urb->dev->ttport;
2628 switch (usb_pipetype(urb->pipe)) {
2630 hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
2631 switch (qtd->control_phase) {
2632 case DWC_OTG_CONTROL_SETUP:
2633 DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
2636 hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
2637 if (_hcd->core_if->dma_enable) {
2638 hc->xfer_buff = (uint8_t *)urb->setup_dma;
2640 hc->xfer_buff = (uint8_t *)urb->setup_packet;
2644 case DWC_OTG_CONTROL_DATA:
2645 DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
2646 hc->data_pid_start = qtd->data_toggle;
2648 case DWC_OTG_CONTROL_STATUS:
2650 * Direction is opposite of data direction or IN if no
2653 DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
2654 if (urb->transfer_buffer_length == 0) {
2657 hc->ep_is_in = (usb_pipein(urb->pipe) != USB_DIR_IN);
2662 hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
2664 if (_hcd->core_if->dma_enable) {
2665 hc->xfer_buff = (uint8_t *)_hcd->status_buf_dma;
2667 hc->xfer_buff = (uint8_t *)_hcd->status_buf;
2673 hc->ep_type = DWC_OTG_EP_TYPE_BULK;
2675 case PIPE_INTERRUPT:
2676 hc->ep_type = DWC_OTG_EP_TYPE_INTR;
2678 case PIPE_ISOCHRONOUS:
2680 struct usb_iso_packet_descriptor *frame_desc;
2681 frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
2682 hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
2683 if (_hcd->core_if->dma_enable) {
2684 hc->xfer_buff = (uint8_t *)urb->transfer_dma;
2686 hc->xfer_buff = (uint8_t *)urb->transfer_buffer;
2688 hc->xfer_buff += frame_desc->offset + qtd->isoc_split_offset;
2689 hc->xfer_len = frame_desc->length - qtd->isoc_split_offset;
2691 if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
2692 if (hc->xfer_len <= 188) {
2693 hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
2696 hc->xact_pos = DWC_HCSPLIT_XACTPOS_BEGIN;
2703 if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2704 hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2706 * This value may be modified when the transfer is started to
2707 * reflect the actual transfer length.
2709 hc->multi_count = dwc_hb_mult(_qh->maxp);
2712 dwc_otg_hc_init(_hcd->core_if, hc);
2717 * This function selects transactions from the HCD transfer schedule and
2718 * assigns them to available host channels. It is called from HCD interrupt
2719 * handler functions.
2721 * @param _hcd The HCD state structure.
2723 * @return The types of new transactions that were assigned to host channels.
2725 dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd)
2727 struct list_head *qh_ptr;
2730 dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
2733 DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
2736 /* Process entries in the periodic ready list. */
2737 qh_ptr = _hcd->periodic_sched_ready.next;
2738 while (qh_ptr != &_hcd->periodic_sched_ready &&
2739 !list_empty(&_hcd->free_hc_list)) {
2741 qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2742 assign_and_init_hc(_hcd, qh);
2745 * Move the QH from the periodic ready schedule to the
2746 * periodic assigned schedule.
2748 qh_ptr = qh_ptr->next;
2749 list_move(&qh->qh_list_entry, &_hcd->periodic_sched_assigned);
2751 ret_val = DWC_OTG_TRANSACTION_PERIODIC;
2755 * Process entries in the inactive portion of the non-periodic
2756 * schedule. Some free host channels may not be used if they are
2757 * reserved for periodic transfers.
2759 qh_ptr = _hcd->non_periodic_sched_inactive.next;
2760 num_channels = _hcd->core_if->core_params->host_channels;
2761 while (qh_ptr != &_hcd->non_periodic_sched_inactive &&
2763 (_hcd->non_periodic_channels <
2764 num_channels - _hcd->periodic_channels) &&
2766 !list_empty(&_hcd->free_hc_list)) {
2768 qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2769 assign_and_init_hc(_hcd, qh);
2772 * Move the QH from the non-periodic inactive schedule to the
2773 * non-periodic active schedule.
2775 qh_ptr = qh_ptr->next;
2776 list_move(&qh->qh_list_entry, &_hcd->non_periodic_sched_active);
2778 if (ret_val == DWC_OTG_TRANSACTION_NONE) {
2779 ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
2781 ret_val = DWC_OTG_TRANSACTION_ALL;
2784 _hcd->non_periodic_channels++;
2791 * Attempts to queue a single transaction request for a host channel
2792 * associated with either a periodic or non-periodic transfer. This function
2793 * assumes that there is space available in the appropriate request queue. For
2794 * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
2795 * is available in the appropriate Tx FIFO.
2797 * @param _hcd The HCD state structure.
2798 * @param _hc Host channel descriptor associated with either a periodic or
2799 * non-periodic transfer.
2800 * @param _fifo_dwords_avail Number of DWORDs available in the periodic Tx
2801 * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
2804 * @return 1 if a request is queued and more requests may be needed to
2805 * complete the transfer, 0 if no more requests are required for this
2806 * transfer, -1 if there is insufficient space in the Tx FIFO.
2808 static int queue_transaction(dwc_otg_hcd_t *_hcd,
2810 uint16_t _fifo_dwords_avail)
2814 if (_hcd->core_if->dma_enable) {
2815 if (!_hc->xfer_started) {
2816 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
2817 _hc->qh->ping_state = 0;
2820 } else if (_hc->halt_pending) {
2821 /* Don't queue a request if the channel has been halted. */
2823 } else if (_hc->halt_on_queue) {
2824 dwc_otg_hc_halt(_hcd->core_if, _hc, _hc->halt_status);
2826 } else if (_hc->do_ping) {
2827 if (!_hc->xfer_started) {
2828 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
2831 } else if (!_hc->ep_is_in ||
2832 _hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
2833 if ((_fifo_dwords_avail * 4) >= _hc->max_packet) {
2834 if (!_hc->xfer_started) {
2835 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
2838 retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
2844 if (!_hc->xfer_started) {
2845 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
2848 retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
2856 * Processes active non-periodic channels and queues transactions for these
2857 * channels to the DWC_otg controller. After queueing transactions, the NP Tx
2858 * FIFO Empty interrupt is enabled if there are more transactions to queue as
2859 * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
2860 * FIFO Empty interrupt is disabled.
2862 static void process_non_periodic_channels(dwc_otg_hcd_t *_hcd)
2864 gnptxsts_data_t tx_status;
2865 struct list_head *orig_qh_ptr;
2868 int no_queue_space = 0;
2869 int no_fifo_space = 0;
2872 dwc_otg_core_global_regs_t *global_regs = _hcd->core_if->core_global_regs;
2874 DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
2876 tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
2877 DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (before queue): %d\n",
2878 tx_status.b.nptxqspcavail);
2879 DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
2880 tx_status.b.nptxfspcavail);
2883 * Keep track of the starting point. Skip over the start-of-list
2886 if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
2887 _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
2889 orig_qh_ptr = _hcd->non_periodic_qh_ptr;
2892 * Process once through the active list or until no more space is
2893 * available in the request queue or the Tx FIFO.
2896 tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
2897 if (!_hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
2902 qh = list_entry(_hcd->non_periodic_qh_ptr, dwc_otg_qh_t, qh_list_entry);
2903 status = queue_transaction(_hcd, qh->channel, tx_status.b.nptxfspcavail);
2907 } else if (status < 0) {
2912 /* Advance to next QH, skipping start-of-list entry. */
2913 _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
2914 if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
2915 _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
2918 } while (_hcd->non_periodic_qh_ptr != orig_qh_ptr);
2920 if (!_hcd->core_if->dma_enable) {
2921 gintmsk_data_t intr_mask = {.d32 = 0};
2922 intr_mask.b.nptxfempty = 1;
2925 tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
2926 DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (after queue): %d\n",
2927 tx_status.b.nptxqspcavail);
2928 DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (after queue): %d\n",
2929 tx_status.b.nptxfspcavail);
2931 if (more_to_do || no_queue_space || no_fifo_space) {
2933 * May need to queue more transactions as the request
2934 * queue or Tx FIFO empties. Enable the non-periodic
2935 * Tx FIFO empty interrupt. (Always use the half-empty
2936 * level to ensure that new requests are loaded as
2937 * soon as possible.)
2939 dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
2942 * Disable the Tx FIFO empty interrupt since there are
2943 * no more transactions that need to be queued right
2944 * now. This function is called from interrupt
2945 * handlers to queue more transactions as transfer
2948 dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
2954 * Processes periodic channels for the next frame and queues transactions for
2955 * these channels to the DWC_otg controller. After queueing transactions, the
2956 * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
2957 * to queue as Periodic Tx FIFO or request queue space becomes available.
2958 * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
2960 static void process_periodic_channels(dwc_otg_hcd_t *_hcd)
2962 hptxsts_data_t tx_status;
2963 struct list_head *qh_ptr;
2966 int no_queue_space = 0;
2967 int no_fifo_space = 0;
2969 dwc_otg_host_global_regs_t *host_regs;
2970 host_regs = _hcd->core_if->host_if->host_global_regs;
2972 DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
2974 tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
2975 DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (before queue): %d\n",
2976 tx_status.b.ptxqspcavail);
2977 DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
2978 tx_status.b.ptxfspcavail);
2981 qh_ptr = _hcd->periodic_sched_assigned.next;
2982 while (qh_ptr != &_hcd->periodic_sched_assigned) {
2983 tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
2984 if (tx_status.b.ptxqspcavail == 0) {
2989 qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2992 * Set a flag if we're queuing high-bandwidth in slave mode.
2993 * The flag prevents any halts to get into the request queue in
2994 * the middle of multiple high-bandwidth packets getting queued.
2996 if ((!_hcd->core_if->dma_enable) &&
2997 (qh->channel->multi_count > 1))
2999 _hcd->core_if->queuing_high_bandwidth = 1;
3002 status = queue_transaction(_hcd, qh->channel, tx_status.b.ptxfspcavail);
3009 * In Slave mode, stay on the current transfer until there is
3010 * nothing more to do or the high-bandwidth request count is
3011 * reached. In DMA mode, only need to queue one request. The
3012 * controller automatically handles multiple packets for
3013 * high-bandwidth transfers.
3015 if (_hcd->core_if->dma_enable ||
3017 qh->channel->requests == qh->channel->multi_count)) {
3018 qh_ptr = qh_ptr->next;
3020 * Move the QH from the periodic assigned schedule to
3021 * the periodic queued schedule.
3023 list_move(&qh->qh_list_entry, &_hcd->periodic_sched_queued);
3025 /* done queuing high bandwidth */
3026 _hcd->core_if->queuing_high_bandwidth = 0;
3030 if (!_hcd->core_if->dma_enable) {
3031 dwc_otg_core_global_regs_t *global_regs;
3032 gintmsk_data_t intr_mask = {.d32 = 0};
3034 global_regs = _hcd->core_if->core_global_regs;
3035 intr_mask.b.ptxfempty = 1;
3037 tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
3038 DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (after queue): %d\n",
3039 tx_status.b.ptxqspcavail);
3040 DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (after queue): %d\n",
3041 tx_status.b.ptxfspcavail);
3043 if (!(list_empty(&_hcd->periodic_sched_assigned)) ||
3044 no_queue_space || no_fifo_space) {
3046 * May need to queue more transactions as the request
3047 * queue or Tx FIFO empties. Enable the periodic Tx
3048 * FIFO empty interrupt. (Always use the half-empty
3049 * level to ensure that new requests are loaded as
3050 * soon as possible.)
3052 dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
3055 * Disable the Tx FIFO empty interrupt since there are
3056 * no more transactions that need to be queued right
3057 * now. This function is called from interrupt
3058 * handlers to queue more transactions as transfer
3061 dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
3067 * This function processes the currently active host channels and queues
3068 * transactions for these channels to the DWC_otg controller. It is called
3069 * from HCD interrupt handler functions.
3071 * @param _hcd The HCD state structure.
3072 * @param _tr_type The type(s) of transactions to queue (non-periodic,
3073 * periodic, or both).
3075 void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
3076 dwc_otg_transaction_type_e _tr_type)
3079 DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
3081 /* Process host channels associated with periodic transfers. */
3082 if ((_tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
3083 _tr_type == DWC_OTG_TRANSACTION_ALL) &&
3084 !list_empty(&_hcd->periodic_sched_assigned)) {
3086 process_periodic_channels(_hcd);
3089 /* Process host channels associated with non-periodic transfers. */
3090 if ((_tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
3091 _tr_type == DWC_OTG_TRANSACTION_ALL)) {
3092 if (!list_empty(&_hcd->non_periodic_sched_active)) {
3093 process_non_periodic_channels(_hcd);
3096 * Ensure NP Tx FIFO empty interrupt is disabled when
3097 * there are no non-periodic transfers to process.
3099 gintmsk_data_t gintmsk = {.d32 = 0};
3100 gintmsk.b.nptxfempty = 1;
3101 dwc_modify_reg32(&_hcd->core_if->core_global_regs->gintmsk,
3108 * Sets the final status of an URB and returns it to the device driver. Any
3109 * required cleanup of the URB is performed.
3111 void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t * _hcd, struct urb *_urb,
3113 __releases(_hcd->lock)
3114 __acquires(_hcd->lock)
3118 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
3119 DWC_PRINT("%s: urb %p, device %d, ep %d %s, status=%d\n",
3120 __func__, _urb, usb_pipedevice(_urb->pipe),
3121 usb_pipeendpoint(_urb->pipe),
3122 usb_pipein(_urb->pipe) ? "IN" : "OUT", _status);
3123 if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
3125 for (i = 0; i < _urb->number_of_packets; i++) {
3126 DWC_PRINT(" ISO Desc %d status: %d\n",
3127 i, _urb->iso_frame_desc[i].status);
3134 _urb->hcpriv = NULL;
3135 usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(_hcd), _urb);
3136 spin_unlock(&_hcd->lock);
3137 usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(_hcd), _urb, _status);
3138 spin_lock(&_hcd->lock);
3143 * Returns the Queue Head for an URB.
3145 dwc_otg_qh_t * dwc_urb_to_qh(struct urb *_urb)
3147 struct usb_host_endpoint *ep = dwc_urb_to_endpoint(_urb);
3148 return (dwc_otg_qh_t *) ep->hcpriv;
3152 void dwc_print_setup_data (uint8_t *setup)
3155 if (CHK_DEBUG_LEVEL(DBG_HCD)){
3156 DWC_PRINT("Setup Data = MSB ");
3157 for (i=7; i>=0; i--) DWC_PRINT ("%02x ", setup[i]);
3159 DWC_PRINT(" bmRequestType Tranfer = %s\n", (setup[0]&0x80) ? "Device-to-Host" : "Host-to-Device");
3160 DWC_PRINT(" bmRequestType Type = ");
3161 switch ((setup[0]&0x60) >> 5) {
3162 case 0: DWC_PRINT("Standard\n"); break;
3163 case 1: DWC_PRINT("Class\n"); break;
3164 case 2: DWC_PRINT("Vendor\n"); break;
3165 case 3: DWC_PRINT("Reserved\n"); break;
3167 DWC_PRINT(" bmRequestType Recipient = ");
3168 switch (setup[0]&0x1f) {
3169 case 0: DWC_PRINT("Device\n"); break;
3170 case 1: DWC_PRINT("Interface\n"); break;
3171 case 2: DWC_PRINT("Endpoint\n"); break;
3172 case 3: DWC_PRINT("Other\n"); break;
3173 default: DWC_PRINT("Reserved\n"); break;
3175 DWC_PRINT(" bRequest = 0x%0x\n", setup[1]);
3176 DWC_PRINT(" wValue = 0x%0x\n", *((uint16_t *)&setup[2]));
3177 DWC_PRINT(" wIndex = 0x%0x\n", *((uint16_t *)&setup[4]));
3178 DWC_PRINT(" wLength = 0x%0x\n\n", *((uint16_t *)&setup[6]));
3183 void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd) {
3185 DWC_PRINT("Frame remaining at SOF:\n");
3186 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3187 _hcd->frrem_samples, _hcd->frrem_accum,
3188 (_hcd->frrem_samples > 0) ?
3189 _hcd->frrem_accum/_hcd->frrem_samples : 0);
3192 DWC_PRINT("Frame remaining at start_transfer (uframe 7):\n");
3193 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3194 _hcd->core_if->hfnum_7_samples, _hcd->core_if->hfnum_7_frrem_accum,
3195 (_hcd->core_if->hfnum_7_samples > 0) ?
3196 _hcd->core_if->hfnum_7_frrem_accum/_hcd->core_if->hfnum_7_samples : 0);
3197 DWC_PRINT("Frame remaining at start_transfer (uframe 0):\n");
3198 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3199 _hcd->core_if->hfnum_0_samples, _hcd->core_if->hfnum_0_frrem_accum,
3200 (_hcd->core_if->hfnum_0_samples > 0) ?
3201 _hcd->core_if->hfnum_0_frrem_accum/_hcd->core_if->hfnum_0_samples : 0);
3202 DWC_PRINT("Frame remaining at start_transfer (uframe 1-6):\n");
3203 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3204 _hcd->core_if->hfnum_other_samples, _hcd->core_if->hfnum_other_frrem_accum,
3205 (_hcd->core_if->hfnum_other_samples > 0) ?
3206 _hcd->core_if->hfnum_other_frrem_accum/_hcd->core_if->hfnum_other_samples : 0);
3209 DWC_PRINT("Frame remaining at sample point A (uframe 7):\n");
3210 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3211 _hcd->hfnum_7_samples_a, _hcd->hfnum_7_frrem_accum_a,
3212 (_hcd->hfnum_7_samples_a > 0) ?
3213 _hcd->hfnum_7_frrem_accum_a/_hcd->hfnum_7_samples_a : 0);
3214 DWC_PRINT("Frame remaining at sample point A (uframe 0):\n");
3215 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3216 _hcd->hfnum_0_samples_a, _hcd->hfnum_0_frrem_accum_a,
3217 (_hcd->hfnum_0_samples_a > 0) ?
3218 _hcd->hfnum_0_frrem_accum_a/_hcd->hfnum_0_samples_a : 0);
3219 DWC_PRINT("Frame remaining at sample point A (uframe 1-6):\n");
3220 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3221 _hcd->hfnum_other_samples_a, _hcd->hfnum_other_frrem_accum_a,
3222 (_hcd->hfnum_other_samples_a > 0) ?
3223 _hcd->hfnum_other_frrem_accum_a/_hcd->hfnum_other_samples_a : 0);
3226 DWC_PRINT("Frame remaining at sample point B (uframe 7):\n");
3227 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3228 _hcd->hfnum_7_samples_b, _hcd->hfnum_7_frrem_accum_b,
3229 (_hcd->hfnum_7_samples_b > 0) ?
3230 _hcd->hfnum_7_frrem_accum_b/_hcd->hfnum_7_samples_b : 0);
3231 DWC_PRINT("Frame remaining at sample point B (uframe 0):\n");
3232 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3233 _hcd->hfnum_0_samples_b, _hcd->hfnum_0_frrem_accum_b,
3234 (_hcd->hfnum_0_samples_b > 0) ?
3235 _hcd->hfnum_0_frrem_accum_b/_hcd->hfnum_0_samples_b : 0);
3236 DWC_PRINT("Frame remaining at sample point B (uframe 1-6):\n");
3237 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3238 _hcd->hfnum_other_samples_b, _hcd->hfnum_other_frrem_accum_b,
3239 (_hcd->hfnum_other_samples_b > 0) ?
3240 _hcd->hfnum_other_frrem_accum_b/_hcd->hfnum_other_samples_b : 0);
3244 void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd)
3249 gnptxsts_data_t np_tx_status;
3250 hptxsts_data_t p_tx_status;
3252 num_channels = _hcd->core_if->core_params->host_channels;
3254 DWC_PRINT("************************************************************\n");
3255 DWC_PRINT("HCD State:\n");
3256 DWC_PRINT(" Num channels: %d\n", num_channels);
3257 for (i = 0; i < num_channels; i++) {
3258 dwc_hc_t *hc = _hcd->hc_ptr_array[i];
3259 DWC_PRINT(" Channel %d:\n", i);
3260 DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
3261 hc->dev_addr, hc->ep_num, hc->ep_is_in);
3262 DWC_PRINT(" speed: %d\n", hc->speed);
3263 DWC_PRINT(" ep_type: %d\n", hc->ep_type);
3264 DWC_PRINT(" max_packet: %d\n", hc->max_packet);
3265 DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
3266 DWC_PRINT(" multi_count: %d\n", hc->multi_count);
3267 DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
3268 DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
3269 DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
3270 DWC_PRINT(" xfer_count: %d\n", hc->xfer_count);
3271 DWC_PRINT(" halt_on_queue: %d\n", hc->halt_on_queue);
3272 DWC_PRINT(" halt_pending: %d\n", hc->halt_pending);
3273 DWC_PRINT(" halt_status: %d\n", hc->halt_status);
3274 DWC_PRINT(" do_split: %d\n", hc->do_split);
3275 DWC_PRINT(" complete_split: %d\n", hc->complete_split);
3276 DWC_PRINT(" hub_addr: %d\n", hc->hub_addr);
3277 DWC_PRINT(" port_addr: %d\n", hc->port_addr);
3278 DWC_PRINT(" xact_pos: %d\n", hc->xact_pos);
3279 DWC_PRINT(" requests: %d\n", hc->requests);
3280 DWC_PRINT(" qh: %p\n", hc->qh);
3281 if (hc->xfer_started) {
3283 hcchar_data_t hcchar;
3284 hctsiz_data_t hctsiz;
3286 hcintmsk_data_t hcintmsk;
3287 hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
3288 hcchar.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcchar);
3289 hctsiz.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hctsiz);
3290 hcint.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcint);
3291 hcintmsk.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcintmsk);
3292 DWC_PRINT(" hfnum: 0x%08x\n", hfnum.d32);
3293 DWC_PRINT(" hcchar: 0x%08x\n", hcchar.d32);
3294 DWC_PRINT(" hctsiz: 0x%08x\n", hctsiz.d32);
3295 DWC_PRINT(" hcint: 0x%08x\n", hcint.d32);
3296 DWC_PRINT(" hcintmsk: 0x%08x\n", hcintmsk.d32);
3298 if (hc->xfer_started && (hc->qh != NULL) && (hc->qh->qtd_in_process != NULL)) {
3301 qtd = hc->qh->qtd_in_process;
3303 DWC_PRINT(" URB Info:\n");
3304 DWC_PRINT(" qtd: %p, urb: %p\n", qtd, urb);
3306 DWC_PRINT(" Dev: %d, EP: %d %s\n",
3307 usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe),
3308 usb_pipein(urb->pipe) ? "IN" : "OUT");
3309 DWC_PRINT(" Max packet size: %d\n",
3310 usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
3311 DWC_PRINT(" transfer_buffer: %p\n", urb->transfer_buffer);
3312 DWC_PRINT(" transfer_dma: %p\n", (void *)urb->transfer_dma);
3313 DWC_PRINT(" transfer_buffer_length: %d\n", urb->transfer_buffer_length);
3314 DWC_PRINT(" actual_length: %d\n", urb->actual_length);
3318 DWC_PRINT(" non_periodic_channels: %d\n", _hcd->non_periodic_channels);
3319 DWC_PRINT(" periodic_channels: %d\n", _hcd->periodic_channels);
3320 DWC_PRINT(" periodic_usecs: %d\n", _hcd->periodic_usecs);
3321 np_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->core_global_regs->gnptxsts);
3322 DWC_PRINT(" NP Tx Req Queue Space Avail: %d\n", np_tx_status.b.nptxqspcavail);
3323 DWC_PRINT(" NP Tx FIFO Space Avail: %d\n", np_tx_status.b.nptxfspcavail);
3324 p_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hptxsts);
3325 DWC_PRINT(" P Tx Req Queue Space Avail: %d\n", p_tx_status.b.ptxqspcavail);
3326 DWC_PRINT(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
3327 dwc_otg_hcd_dump_frrem(_hcd);
3328 dwc_otg_dump_global_registers(_hcd->core_if);
3329 dwc_otg_dump_host_registers(_hcd->core_if);
3330 DWC_PRINT("************************************************************\n");
3334 #endif /* DWC_DEVICE_ONLY */