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/clk.h>
42 #include <linux/kernel.h>
43 #include <linux/module.h>
44 #include <linux/moduleparam.h>
45 #include <linux/init.h>
46 #include <linux/device.h>
47 #include <linux/errno.h>
48 #include <linux/list.h>
49 #include <linux/interrupt.h>
50 #include <linux/string.h>
51 #include <linux/dma-mapping.h>
52 #include <linux/irq.h>
53 #include <linux/platform_device.h>
55 #include "dwc_otg_driver.h"
56 #include "dwc_otg_hcd.h"
57 #include "dwc_otg_regs.h"
59 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;
66 if(core_if->op_state == B_PERIPHERAL)
68 DWC_PRINT("%s, usb device mode\n", __func__);
71 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
72 if((!dwc_otg_hcd->host_enabled)||(!hprt0.b.prtena))
74 DWC_PRINT("%s suspend, HPRT0:0x%x\n",hcd->self.bus_name,hprt0.d32);
75 if(hprt0.b.prtconnsts) // usb device connected
83 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
86 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
92 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
95 pcgcctl.d32 = dwc_read_reg32(core_if->pcgcctl);
96 pcgcctl.b.pwrclmp = 1;//power clamp
97 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
99 //pcgcctl.b.rstpdwnmodule = 1;//reset PDM
100 pcgcctl.b.stoppclk = 1;//stop phy clk
101 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
103 else //no device connect
105 if (core_if->hcd_cb && core_if->hcd_cb->suspend) {
106 core_if->hcd_cb->suspend( core_if->hcd_cb->p, 0);
110 #ifndef CONFIG_DWC_REMOTE_WAKEUP
111 clk_disable(core_if->otg_dev->phyclk);
112 clk_disable(core_if->otg_dev->ahbclk);
118 static int dwc_otg_hcd_resume(struct usb_hcd *hcd)
120 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (hcd);
121 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
123 pcgcctl_data_t pcgcctl;
124 gintmsk_data_t gintmsk;
126 if(core_if->op_state == B_PERIPHERAL)
128 DWC_PRINT("%s, usb device mode\n", __func__);
131 if(!dwc_otg_hcd->host_enabled)
133 #ifndef CONFIG_DWC_REMOTE_WAKEUP
134 clk_enable(core_if->otg_dev->phyclk);
135 clk_enable(core_if->otg_dev->ahbclk);
139 pcgcctl.d32 = dwc_read_reg32(core_if->pcgcctl);;
140 pcgcctl.b.stoppclk = 0;//stop phy clk
141 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
143 pcgcctl.b.pwrclmp = 0;//power clamp
144 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
147 gintmsk.d32 = dwc_read_reg32(&core_if->core_global_regs->gintmsk);
148 gintmsk.b.portintr = 0;
149 dwc_write_reg32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
151 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
154 DWC_PRINT("%s resume, HPRT0:0x%x\n",hcd->self.bus_name,hprt0.d32);
155 if(hprt0.b.prtconnsts)
157 //hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
158 //DWC_PRINT("%s, HPRT0:0x%x\n",hcd->self.bus_name,hprt0.d32);
162 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
164 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
165 //DWC_PRINT("%s, HPRT0:0x%x\n",hcd->self.bus_name,hprt0.d32);
170 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
174 hprt0.b.prtconndet = 1;
175 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
177 //hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
178 //DWC_PRINT("%s, HPRT0:0x%x\n",hcd->self.bus_name,hprt0.d32);
184 if (core_if->hcd_cb && core_if->hcd_cb->suspend) {
185 core_if->hcd_cb->suspend( core_if->hcd_cb->p, 1);
188 gintmsk.b.portintr = 1;
189 dwc_write_reg32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
194 static const char dwc_otg_hcd_name [] = "dwc_otg_hcd";
196 static const struct hc_driver dwc_otg_hc_driver = {
198 .description = dwc_otg_hcd_name,
199 .product_desc = "DWC OTG Controller",
200 .hcd_priv_size = sizeof(dwc_otg_hcd_t),
202 .irq = dwc_otg_hcd_irq,
204 .flags = HCD_MEMORY | HCD_USB2,
207 .start = dwc_otg_hcd_start,
212 * core/hcd.c call hcd->driver->bus_suspend
213 * otherwise system can not be suspended
216 .bus_suspend = dwc_otg_hcd_suspend,
217 .bus_resume = dwc_otg_hcd_resume,
219 .stop = dwc_otg_hcd_stop,
221 .urb_enqueue = dwc_otg_hcd_urb_enqueue,
222 .urb_dequeue = dwc_otg_hcd_urb_dequeue,
223 .endpoint_disable = dwc_otg_hcd_endpoint_disable,
225 .get_frame_number = dwc_otg_hcd_get_frame_number,
227 .hub_status_data = dwc_otg_hcd_hub_status_data,
228 .hub_control = dwc_otg_hcd_hub_control,
233 #ifdef CONFIG_USB11_HOST
234 static const struct hc_driver host11_hc_driver = {
236 .description = "host11_hcd",
237 .product_desc = "DWC OTG Controller",
238 .hcd_priv_size = sizeof(dwc_otg_hcd_t),
240 .irq = dwc_otg_hcd_irq,
242 .flags = HCD_MEMORY | HCD_USB2,
245 .start = dwc_otg_hcd_start,
250 * core/hcd.c call hcd->driver->bus_suspend
251 * otherwise system can not be suspended
254 .bus_suspend = dwc_otg_hcd_suspend,
255 .bus_resume = dwc_otg_hcd_resume,
257 .stop = dwc_otg_hcd_stop,
259 .urb_enqueue = dwc_otg_hcd_urb_enqueue,
260 .urb_dequeue = dwc_otg_hcd_urb_dequeue,
261 .endpoint_disable = dwc_otg_hcd_endpoint_disable,
263 .get_frame_number = dwc_otg_hcd_get_frame_number,
265 .hub_status_data = dwc_otg_hcd_hub_status_data,
266 .hub_control = dwc_otg_hcd_hub_control,
271 #ifdef CONFIG_USB20_HOST
272 static const struct hc_driver host20_hc_driver = {
274 .description = "host20_hcd",
275 .product_desc = "DWC OTG Controller",
276 .hcd_priv_size = sizeof(dwc_otg_hcd_t),
278 .irq = dwc_otg_hcd_irq,
280 .flags = HCD_MEMORY | HCD_USB2,
283 .start = dwc_otg_hcd_start,
288 * core/hcd.c call hcd->driver->bus_suspend
289 * otherwise system can not be suspended
292 .bus_suspend = dwc_otg_hcd_suspend,
293 .bus_resume = dwc_otg_hcd_resume,
295 .stop = dwc_otg_hcd_stop,
297 .urb_enqueue = dwc_otg_hcd_urb_enqueue,
298 .urb_dequeue = dwc_otg_hcd_urb_dequeue,
299 .endpoint_disable = dwc_otg_hcd_endpoint_disable,
301 .get_frame_number = dwc_otg_hcd_get_frame_number,
303 .hub_status_data = dwc_otg_hcd_hub_status_data,
304 .hub_control = dwc_otg_hcd_hub_control,
311 * Work queue function for starting the HCD when A-Cable is connected.
312 * The dwc_otg_hcd_start() must be called in a process context.
314 static void hcd_start_func(struct work_struct *work)
316 dwc_otg_hcd_t *dwc_otg_hcd = container_of(work, dwc_otg_hcd_t, start_work);
317 struct usb_hcd *hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
319 DWC_DEBUGPL(DBG_HCDV, "%s() %p %p\n", __func__, dwc_otg_hcd, hcd);
321 dwc_otg_hcd_start(hcd);
326 * HCD Callback function for starting the HCD when A-Cable is
329 * @param _p void pointer to the <code>struct usb_hcd</code>
331 static int32_t dwc_otg_hcd_start_cb(void *_p)
333 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_p);
334 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
337 if (core_if->op_state == B_HOST) {
339 * Reset the port. During a HNP mode switch the reset
340 * needs to occur within 1ms and have a duration of at
343 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
345 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
346 ((struct usb_hcd *)_p)->self.is_b_host = 1;
348 ((struct usb_hcd *)_p)->self.is_b_host = 0;
351 /* Need to start the HCD in a non-interrupt context. */
352 // INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func, _p);
353 INIT_WORK(&dwc_otg_hcd->start_work, hcd_start_func);
354 schedule_work(&dwc_otg_hcd->start_work);
361 * HCD Callback function for stopping the HCD.
363 * @param _p void pointer to the <code>struct usb_hcd</code>
365 static int32_t dwc_otg_hcd_stop_cb( void *_p )
367 struct usb_hcd *usb_hcd = (struct usb_hcd *)_p;
368 DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
369 dwc_otg_hcd_stop( usb_hcd );
373 static void del_xfer_timers(dwc_otg_hcd_t *_hcd)
377 int num_channels = _hcd->core_if->core_params->host_channels;
378 for (i = 0; i < num_channels; i++) {
379 del_timer(&_hcd->core_if->hc_xfer_timer[i]);
384 static void del_timers(dwc_otg_hcd_t *_hcd)
386 del_xfer_timers(_hcd);
387 del_timer(&_hcd->conn_timer);
391 * Processes all the URBs in a single list of QHs. Completes them with
392 * -ETIMEDOUT and frees the QTD.
394 static void kill_urbs_in_qh_list(dwc_otg_hcd_t *_hcd, struct list_head *_qh_list)
396 struct list_head *qh_item;
398 struct list_head *qtd_item;
402 list_for_each(qh_item, _qh_list) {
403 qh = list_entry(qh_item, dwc_otg_qh_t, qh_list_entry);
404 for (qtd_item = qh->qtd_list.next;
405 qtd_item != &qh->qtd_list;
406 qtd_item = qh->qtd_list.next) {
407 qtd = list_entry(qtd_item, dwc_otg_qtd_t, qtd_list_entry);
408 if (qtd->urb != NULL) {
411 // urb will be re entry to ep->urb_list if use ETIMEOUT
412 dwc_otg_hcd_complete_urb(_hcd, urb,
413 -ESHUTDOWN);//ETIMEDOUT,ENOENT
415 dwc_otg_hcd_qtd_remove_and_free(qtd);
421 * Responds with an error status of ETIMEDOUT to all URBs in the non-periodic
422 * and periodic schedules. The QTD associated with each URB is removed from
423 * the schedule and freed. This function may be called when a disconnect is
424 * detected or when the HCD is being stopped.
426 static void kill_all_urbs(dwc_otg_hcd_t *_hcd)
428 kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_inactive);
429 kill_urbs_in_qh_list(_hcd, &_hcd->non_periodic_sched_active);
430 kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_inactive);
431 // kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_ready);
432 // kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_assigned);
433 // kill_urbs_in_qh_list(_hcd, &_hcd->periodic_sched_queued);
435 extern void release_channel(dwc_otg_hcd_t *_hcd,
438 dwc_otg_halt_status_e _halt_status);
441 * HCD Callback function for disconnect of the HCD.
443 * @param _p void pointer to the <code>struct usb_hcd</code>
445 static int32_t dwc_otg_hcd_disconnect_cb( void *_p )
448 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
450 //DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
453 * Set status flags for the hub driver.
455 dwc_otg_hcd->flags.b.port_connect_status_change = 1;
456 dwc_otg_hcd->flags.b.port_connect_status = 0;
459 * Shutdown any transfers in process by clearing the Tx FIFO Empty
460 * interrupt mask and status bits and disabling subsequent host
461 * channel interrupts.
464 intr.b.nptxfempty = 1;
465 intr.b.ptxfempty = 1;
467 dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, intr.d32, 0);
468 dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintsts, intr.d32, 0);
470 // del_timers(dwc_otg_hcd);
473 * Turn off the vbus power only if the core has transitioned to device
474 * mode. If still in host mode, need to keep power on to detect a
477 if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
478 if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
479 hprt0_data_t hprt0 = { .d32=0 };
480 DWC_PRINT("Disconnect: PortPower off\n");
482 dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
485 dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
488 spin_lock(&dwc_otg_hcd->global_lock);
489 /* Respond with an error status to all URBs in the schedule. */
490 kill_all_urbs(dwc_otg_hcd);
491 spin_unlock(&dwc_otg_hcd->global_lock);
493 if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
494 /* Clean up any host channels that were in use. */
498 dwc_otg_hc_regs_t *hc_regs;
499 hcchar_data_t hcchar;
501 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
503 if (!dwc_otg_hcd->core_if->dma_enable) {
504 /* Flush out any channel requests in slave mode. */
505 for (i = 0; i < num_channels; i++) {
506 channel = dwc_otg_hcd->hc_ptr_array[i];
507 if (list_empty(&channel->hc_list_entry)) {
508 hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
509 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
514 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
520 for (i = 0; i < num_channels; i++) {
521 channel = dwc_otg_hcd->hc_ptr_array[i];
522 if (list_empty(&channel->hc_list_entry)) {
523 hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[i];
524 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
526 /* Halt the channel. */
528 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
531 release_channel(dwc_otg_hcd, channel, NULL, DWC_OTG_HC_XFER_URB_DEQUEUE);
533 dwc_otg_hc_cleanup(dwc_otg_hcd->core_if, channel);
534 list_add_tail(&channel->hc_list_entry,
535 &dwc_otg_hcd->free_hc_list);
541 /* A disconnect will end the session so the B-Device is no
542 * longer a B-host. */
543 ((struct usb_hcd *)_p)->self.is_b_host = 0;
548 * Connection timeout function. An OTG host is required to display a
549 * message if the device does not connect within 10 seconds.
551 void dwc_otg_hcd_connect_timeout( unsigned long _ptr )
553 DWC_DEBUGPL(DBG_HCDV, "%s(%x)\n", __func__, (int)_ptr);
554 DWC_PRINT( "Connect Timeout\n");
555 DWC_ERROR( "Device Not Connected/Responding\n" );
559 * Start the connection timer. An OTG host is required to display a
560 * message if the device does not connect within 10 seconds. The
561 * timer is deleted if a port connect interrupt occurs before the
564 static void dwc_otg_hcd_start_connect_timer( dwc_otg_hcd_t *_hcd)
566 init_timer( &_hcd->conn_timer );
567 _hcd->conn_timer.function = dwc_otg_hcd_connect_timeout;
568 _hcd->conn_timer.data = (unsigned long)0;
569 _hcd->conn_timer.expires = jiffies + (HZ*10);
570 add_timer( &_hcd->conn_timer );
574 * HCD Callback function for disconnect of the HCD.
576 * @param _p void pointer to the <code>struct usb_hcd</code>
578 static int32_t dwc_otg_hcd_session_start_cb( void *_p )
580 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_p);
581 DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _p);
582 // dwc_otg_hcd_start_connect_timer( dwc_otg_hcd );
587 * suspend: 0 usb phy enable
590 static int32_t dwc_otg_phy_suspend_cb( void *_p, int suspend)
592 #ifdef CONFIG_ARCH_RK29
593 unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON);
596 *otg_phy_con1 |= (0x01<<2);
597 *otg_phy_con1 |= (0x01<<3); // exit suspend.
598 *otg_phy_con1 &= ~(0x01<<2);
600 DWC_DEBUGPL(DBG_PCDV, "enable usb phy\n");
604 *otg_phy_con1 |= (0x01<<2);
605 *otg_phy_con1 &= ~(0x01<<3); // enter suspend.
606 DWC_DEBUGPL(DBG_PCDV, "disable usb phy\n");
609 #ifdef CONFIG_ARCH_RK30
610 unsigned int * otg_phy_con1 = (unsigned int*)(USBGRF_UOC0_CON2);
612 *otg_phy_con1 = ((0x01<<2)<<16); // exit suspend.
613 DWC_DEBUGPL(DBG_PCDV, "enable usb phy\n");
616 *otg_phy_con1 = 0x554|(0xfff<<16); // enter suspend.
618 DWC_DEBUGPL(DBG_PCDV, "disable usb phy\n");
625 * HCD Callback structure for handling mode switching.
627 static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
628 .start = dwc_otg_hcd_start_cb,
629 .stop = dwc_otg_hcd_stop_cb,
630 .disconnect = dwc_otg_hcd_disconnect_cb,
631 .session_start = dwc_otg_hcd_session_start_cb,
632 .suspend = dwc_otg_phy_suspend_cb,
637 * Reset tasklet function
639 static void reset_tasklet_func (unsigned long data)
641 dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t*)data;
642 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
645 DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
647 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
649 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
653 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
654 dwc_otg_hcd->flags.b.port_reset_change = 1;
659 static struct tasklet_struct reset_tasklet = {
662 .count = ATOMIC_INIT(0),
663 .func = reset_tasklet_func,
666 #ifdef CONFIG_ARCH_RK30
667 static void dwc_otg_hcd_enable(struct work_struct *work)
669 dwc_otg_hcd_t *dwc_otg_hcd;
670 dwc_otg_core_if_t *_core_if;
672 dwc_otg_hcd = container_of(work, dwc_otg_hcd_t, host_enable_work.work);
673 _core_if = dwc_otg_hcd->core_if;
675 if(dwc_otg_hcd->host_enabled == dwc_otg_hcd->host_setenable){
676 // DWC_PRINT("%s, enable flag %d\n", __func__, dwc_otg_hcd->host_setenable);
680 dwc_otg_hcd->host_enabled = dwc_otg_hcd->host_setenable;
681 if(dwc_otg_hcd->host_setenable == 0) // enable -> disable
683 DWC_PRINT("%s, disable host controller\n", __func__);
685 if (_core_if->hcd_cb && _core_if->hcd_cb->disconnect) {
686 _core_if->hcd_cb->disconnect( _core_if->hcd_cb->p );
689 if (_core_if->hcd_cb && _core_if->hcd_cb->stop) {
690 _core_if->hcd_cb->stop( _core_if->hcd_cb->p );
692 if (_core_if->hcd_cb && _core_if->hcd_cb->suspend) {
693 _core_if->hcd_cb->suspend( _core_if->hcd_cb->p, 0);
696 // clk_disable(otg_dev->phyclk);
697 // clk_disable(otg_dev->ahbclk);
699 else if(dwc_otg_hcd->host_setenable == 1)
701 DWC_PRINT("%s, enable host controller\n", __func__);
702 // clk_enable(otg_dev->phyclk);
703 // clk_enable(otg_dev->ahbclk);
704 if (_core_if->hcd_cb && _core_if->hcd_cb->suspend) {
705 _core_if->hcd_cb->suspend( _core_if->hcd_cb->p, 1);
708 if (_core_if->hcd_cb && _core_if->hcd_cb->start) {
709 _core_if->hcd_cb->start( _core_if->hcd_cb->p );
714 static void dwc_otg_hcd_connect_detect(unsigned long pdata)
716 dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *)pdata;
717 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
718 unsigned int usbgrf_status = *(unsigned int*)(USBGRF_SOC_STATUS0);
721 local_irq_save(flags);
723 // DWC_PRINT("%s hprt %x, grfstatus 0x%x\n", __func__, dwc_read_reg32(core_if->host_if->hprt0), usbgrf_status& (7<<22));
724 if(usbgrf_status & (7<<22)){
725 // usb device connected
726 dwc_otg_hcd->host_setenable = 1;
729 // no device, suspend host
730 if((dwc_read_reg32(core_if->host_if->hprt0) & 1) == 0)
731 dwc_otg_hcd->host_setenable = 0;
734 if(dwc_otg_hcd->host_setenable != dwc_otg_hcd->host_enabled){
735 DWC_PRINT("%s schedule delaywork \n", __func__, dwc_read_reg32(core_if->host_if->hprt0), usbgrf_status& (7<<22));
736 schedule_delayed_work(&dwc_otg_hcd->host_enable_work, 8);
738 // dwc_otg_hcd->connect_detect_timer.expires = jiffies + (HZ<<1); /* 1 s */
739 mod_timer(&dwc_otg_hcd->connect_detect_timer,jiffies + (HZ<<1));
740 local_irq_restore(flags);
745 * Initializes the HCD. This function allocates memory for and initializes the
746 * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
747 * USB bus with the core and calls the hc_driver->start() function. It returns
748 * a negative error on failure.
750 extern uint32_t g_dbg_lvl;
751 int __devinit dwc_otg_hcd_init(struct device *dev)
753 struct usb_hcd *hcd = NULL;
754 dwc_otg_hcd_t *dwc_otg_hcd = NULL;
755 dwc_otg_device_t *otg_dev = dev->platform_data;
762 #if 1 //kaiker .these code must execute before usb_create_hcd
763 /* Set device flags indicating whether the HCD supports DMA. */
764 static u64 usb_dmamask = 0xffffffffUL;
765 if (otg_dev->core_if->dma_enable) {
766 dev->dma_mask = &usb_dmamask;
767 dev->coherent_dma_mask = ~0;
769 dev->dma_mask = (void *)0;
770 dev->coherent_dma_mask = 0;
776 * Allocate memory for the base HCD plus the DWC OTG HCD.
777 * Initialize the base HCD.
779 hcd = usb_create_hcd(&dwc_otg_hc_driver, dev, dev_name(dev));
784 hcd->regs = otg_dev->base;
785 hcd->self.otg_port = 1;
787 /* Initialize the DWC OTG HCD. */
788 dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
790 spin_lock_init(&dwc_otg_hcd->global_lock);
792 dwc_otg_hcd->core_if = otg_dev->core_if;
793 otg_dev->hcd = dwc_otg_hcd;
795 #ifdef CONFIG_USB20_OTG_EN
796 dwc_otg_hcd->host_enabled = 1;
798 dwc_otg_hcd->host_enabled = 0;
801 /* Register the HCD CIL Callbacks */
802 dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
803 &hcd_cil_callbacks, hcd);
805 /* Initialize the non-periodic schedule. */
806 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
807 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
809 /* Initialize the periodic schedule. */
810 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
811 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
812 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
813 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
816 * Create a host channel descriptor for each host channel implemented
817 * in the controller. Initialize the channel descriptor array.
819 INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
820 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
821 for (i = 0; i < num_channels; i++) {
822 channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
823 if (channel == NULL) {
825 DWC_ERROR("%s: host channel allocation failed\n", __func__);
828 memset(channel, 0, sizeof(dwc_hc_t));
830 dwc_otg_hcd->hc_ptr_array[i] = channel;
832 init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
835 DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
838 /* Initialize the Connection timeout timer. */
839 // init_timer( &dwc_otg_hcd->conn_timer );
841 /* Initialize reset tasklet. */
842 reset_tasklet.data = (unsigned long) dwc_otg_hcd;
843 dwc_otg_hcd->reset_tasklet = &reset_tasklet;
845 * Finish generic HCD initialization and start the HCD. This function
846 * allocates the DMA buffer pool, registers the USB bus, requests the
847 * IRQ line, and calls dwc_otg_hcd_start method.
849 retval = usb_add_hcd(hcd, platform_get_irq(to_platform_device(dev), 0),
852 DWC_ERROR("usb_add_hcd fail,everest\n");
856 * Allocate space for storing data on status transactions. Normally no
857 * data is sent, but this space acts as a bit bucket. This must be
858 * done after usb_add_hcd since that function allocates the DMA buffer
861 if (otg_dev->core_if->dma_enable) {
862 dwc_otg_hcd->status_buf =
863 dma_alloc_coherent(dev,
864 DWC_OTG_HCD_STATUS_BUF_SIZE,
865 &dwc_otg_hcd->status_buf_dma,
866 GFP_KERNEL | GFP_DMA);
868 dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
871 if (dwc_otg_hcd->status_buf == NULL) {
873 DWC_ERROR("%s: status_buf allocation failed\n", __func__);
877 // DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
878 // dev->bus_id, hcd->self.busnum);
882 /* Error conditions */
886 dwc_otg_hcd_free(hcd);
890 DWC_PRINT("dwc_otg_hcd_init error,everest\n");
894 #ifdef CONFIG_USB11_HOST
896 * suspend: 0 usb phy enable
899 static int32_t host11_phy_suspend_cb( void *_p, int suspend)
901 unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON);
904 *otg_phy_con1 &= ~(0x01<<28);
905 DWC_DEBUGPL(DBG_PCDV, "enable usb phy\n");
909 *otg_phy_con1 |= (0x01<<28);
910 DWC_DEBUGPL(DBG_PCDV, "disable usb phy\n");
915 static dwc_otg_cil_callbacks_t host11_cil_callbacks = {
916 .start = dwc_otg_hcd_start_cb,
917 .stop = dwc_otg_hcd_stop_cb,
918 .disconnect = dwc_otg_hcd_disconnect_cb,
919 .session_start = dwc_otg_hcd_session_start_cb,
920 .suspend = host11_phy_suspend_cb,
924 static struct tasklet_struct host11_reset_tasklet = {
927 .count = ATOMIC_INIT(0),
928 .func = reset_tasklet_func,
932 int __devinit host11_hcd_init(struct device *dev)
934 struct usb_hcd *hcd = NULL;
935 dwc_otg_hcd_t *dwc_otg_hcd = NULL;
936 dwc_otg_device_t *otg_dev = dev->platform_data;
943 #if 1 //kaiker .these code must execute before usb_create_hcd
944 /* Set device flags indicating whether the HCD supports DMA. */
945 static u64 usb_dmamask = 0xffffffffUL;
946 if (otg_dev->core_if->dma_enable) {
947 // DWC_PRINT("Using DMA mode\n");
948 dev->dma_mask = &usb_dmamask;
949 dev->coherent_dma_mask = ~0;
951 // DWC_PRINT("Using Slave mode\n");
952 dev->dma_mask = (void *)0;
953 dev->coherent_dma_mask = 0;
958 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
961 * Allocate memory for the base HCD plus the DWC OTG HCD.
962 * Initialize the base HCD.
964 hcd = usb_create_hcd(&host11_hc_driver, dev, dev_name(dev));
969 hcd->regs = otg_dev->base;
970 hcd->self.otg_port = 1;
972 /* Initialize the DWC OTG HCD. */
973 dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
974 dwc_otg_hcd->core_if = otg_dev->core_if;
975 otg_dev->hcd = dwc_otg_hcd;
977 #ifdef CONFIG_USB11_HOST_EN
978 dwc_otg_hcd->host_enabled = 1;
980 dwc_otg_hcd->host_enabled = 0;
983 spin_lock_init(&dwc_otg_hcd->global_lock);
986 /* Register the HCD CIL Callbacks */
987 dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
988 &host11_cil_callbacks, hcd);
990 /* Initialize the non-periodic schedule. */
991 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
992 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
994 /* Initialize the periodic schedule. */
995 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
996 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
997 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
998 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
1001 * Create a host channel descriptor for each host channel implemented
1002 * in the controller. Initialize the channel descriptor array.
1004 INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
1005 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
1006 for (i = 0; i < num_channels; i++) {
1007 channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
1008 if (channel == NULL) {
1010 DWC_ERROR("%s: host channel allocation failed\n", __func__);
1013 memset(channel, 0, sizeof(dwc_hc_t));
1014 channel->hc_num = i;
1015 dwc_otg_hcd->hc_ptr_array[i] = channel;
1017 init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
1020 DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
1023 /* Initialize the Connection timeout timer. */
1024 // init_timer( &dwc_otg_hcd->conn_timer );
1026 /* Initialize reset tasklet. */
1027 host11_reset_tasklet.data = (unsigned long) dwc_otg_hcd;
1028 dwc_otg_hcd->reset_tasklet = &host11_reset_tasklet;
1030 * Finish generic HCD initialization and start the HCD. This function
1031 * allocates the DMA buffer pool, registers the USB bus, requests the
1032 * IRQ line, and calls dwc_otg_hcd_start method.
1034 retval = usb_add_hcd(hcd, platform_get_irq(to_platform_device(dev), 0),
1037 DWC_ERROR("usb_add_hcd fail,everest\n");
1041 * Allocate space for storing data on status transactions. Normally no
1042 * data is sent, but this space acts as a bit bucket. This must be
1043 * done after usb_add_hcd since that function allocates the DMA buffer
1046 if (otg_dev->core_if->dma_enable) {
1047 dwc_otg_hcd->status_buf =
1048 dma_alloc_coherent(dev,
1049 DWC_OTG_HCD_STATUS_BUF_SIZE,
1050 &dwc_otg_hcd->status_buf_dma,
1051 GFP_KERNEL | GFP_DMA);
1053 dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
1056 if (dwc_otg_hcd->status_buf == NULL) {
1058 DWC_ERROR("%s: status_buf allocation failed\n", __func__);
1062 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Initialized HCD, bus=%s, usbbus=%d\n",
1063 _lmdev->dev.bus_id, hcd->self.busnum);
1067 /* Error conditions */
1069 usb_remove_hcd(hcd);
1071 dwc_otg_hcd_free(hcd);
1075 DWC_PRINT("dwc_otg_hcd_init error,everest\n");
1079 #ifdef CONFIG_USB20_HOST
1082 * suspend: 0 usb phy enable
1085 static int32_t host20_phy_suspend_cb( void *_p, int suspend)
1087 #ifdef CONFIG_ARCH_RK29
1088 unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON);
1091 regval = *otg_phy_con1;
1094 regval |= (0x01<<14); // exit suspend.
1095 regval &= ~(0x01<<13);
1097 DWC_DEBUGPL(DBG_PCDV, "enable usb phy\n");
1101 regval &= ~(0x01<<14); // exit suspend.
1102 regval |= (0x01<<13); // software control
1103 DWC_DEBUGPL(DBG_PCDV, "disable usb phy\n");
1105 *otg_phy_con1 = regval;
1108 #ifdef CONFIG_ARCH_RK30
1109 unsigned int * otg_phy_con1 = (unsigned int*)(USBGRF_UOC1_CON2);
1111 *otg_phy_con1 = ((0x01<<2)<<16); // exit suspend.
1112 DWC_DEBUGPL(DBG_PCDV, "enable usb phy\n");
1115 *otg_phy_con1 = 0x554|(0xfff<<16); // enter suspend.
1117 DWC_DEBUGPL(DBG_PCDV, "disable usb phy\n");
1123 static dwc_otg_cil_callbacks_t host20_cil_callbacks = {
1124 .start = dwc_otg_hcd_start_cb,
1125 .stop = dwc_otg_hcd_stop_cb,
1126 .disconnect = dwc_otg_hcd_disconnect_cb,
1127 .session_start = dwc_otg_hcd_session_start_cb,
1128 .suspend = host20_phy_suspend_cb,
1132 static struct tasklet_struct host20_reset_tasklet = {
1135 .count = ATOMIC_INIT(0),
1136 .func = reset_tasklet_func,
1140 int __devinit host20_hcd_init(struct device *dev)
1142 struct usb_hcd *hcd = NULL;
1143 dwc_otg_hcd_t *dwc_otg_hcd = NULL;
1144 dwc_otg_device_t *otg_dev = dev->platform_data;
1151 #if 1 //kaiker .these code must execute before usb_create_hcd
1152 /* Set device flags indicating whether the HCD supports DMA. */
1153 static u64 usb_dmamask = 0xffffffffUL;
1154 if (otg_dev->core_if->dma_enable) {
1155 // DWC_PRINT("Using DMA mode\n");
1156 dev->dma_mask = &usb_dmamask;
1157 dev->coherent_dma_mask = ~0;
1159 // DWC_PRINT("Using Slave mode\n");
1160 dev->dma_mask = (void *)0;
1161 dev->coherent_dma_mask = 0;
1164 // g_dbg_lvl = 0xff;
1166 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT\n");
1169 * Allocate memory for the base HCD plus the DWC OTG HCD.
1170 * Initialize the base HCD.
1172 hcd = usb_create_hcd(&host20_hc_driver, dev, dev_name(dev));
1177 hcd->regs = otg_dev->base;
1178 hcd->self.otg_port = 1;
1180 /* Initialize the DWC OTG HCD. */
1181 dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
1182 dwc_otg_hcd->core_if = otg_dev->core_if;
1183 otg_dev->hcd = dwc_otg_hcd;
1185 #ifdef CONFIG_USB20_HOST_EN
1186 dwc_otg_hcd->host_enabled = 1;
1188 dwc_otg_hcd->host_enabled = 0;
1191 spin_lock_init(&dwc_otg_hcd->global_lock);
1193 /* Register the HCD CIL Callbacks */
1194 dwc_otg_cil_register_hcd_callbacks(otg_dev->core_if,
1195 &host20_cil_callbacks, hcd);
1197 /* Initialize the non-periodic schedule. */
1198 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_inactive);
1199 INIT_LIST_HEAD(&dwc_otg_hcd->non_periodic_sched_active);
1201 /* Initialize the periodic schedule. */
1202 INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_inactive);
1203 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_ready);
1204 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_assigned);
1205 // INIT_LIST_HEAD(&dwc_otg_hcd->periodic_sched_queued);
1208 * Create a host channel descriptor for each host channel implemented
1209 * in the controller. Initialize the channel descriptor array.
1211 INIT_LIST_HEAD(&dwc_otg_hcd->free_hc_list);
1212 num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
1213 for (i = 0; i < num_channels; i++) {
1214 channel = kmalloc(sizeof(dwc_hc_t), GFP_KERNEL);
1215 if (channel == NULL) {
1217 DWC_ERROR("%s: host channel allocation failed\n", __func__);
1220 memset(channel, 0, sizeof(dwc_hc_t));
1221 channel->hc_num = i;
1222 dwc_otg_hcd->hc_ptr_array[i] = channel;
1224 init_timer(&dwc_otg_hcd->core_if->hc_xfer_timer[i]);
1227 DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i, channel);
1230 /* Initialize the Connection timeout timer. */
1231 //init_timer( &dwc_otg_hcd->conn_timer );
1233 /* Initialize reset tasklet. */
1234 host20_reset_tasklet.data = (unsigned long) dwc_otg_hcd;
1235 dwc_otg_hcd->reset_tasklet = &host20_reset_tasklet;
1237 * Finish generic HCD initialization and start the HCD. This function
1238 * allocates the DMA buffer pool, registers the USB bus, requests the
1239 * IRQ line, and calls dwc_otg_hcd_start method.
1241 retval = usb_add_hcd(hcd, platform_get_irq(to_platform_device(dev), 0),
1244 DWC_ERROR("usb_add_hcd fail,everest\n");
1248 * Allocate space for storing data on status transactions. Normally no
1249 * data is sent, but this space acts as a bit bucket. This must be
1250 * done after usb_add_hcd since that function allocates the DMA buffer
1253 if (otg_dev->core_if->dma_enable) {
1254 dwc_otg_hcd->status_buf =
1255 dma_alloc_coherent(dev,
1256 DWC_OTG_HCD_STATUS_BUF_SIZE,
1257 &dwc_otg_hcd->status_buf_dma,
1258 GFP_KERNEL | GFP_DMA);
1260 dwc_otg_hcd->status_buf = kmalloc(DWC_OTG_HCD_STATUS_BUF_SIZE,
1263 if (dwc_otg_hcd->status_buf == NULL) {
1265 DWC_ERROR("%s: status_buf allocation failed\n", __func__);
1269 #ifdef CONFIG_ARCH_RK30
1270 dwc_otg_hcd->connect_detect_timer.function = dwc_otg_hcd_connect_detect;
1271 dwc_otg_hcd->connect_detect_timer.data = (unsigned long)(dwc_otg_hcd);
1272 init_timer( &dwc_otg_hcd->connect_detect_timer);
1273 mod_timer(&dwc_otg_hcd->connect_detect_timer, jiffies+(HZ<<3));
1275 INIT_DELAYED_WORK(&dwc_otg_hcd->host_enable_work, dwc_otg_hcd_enable);
1279 /* Error conditions */
1281 usb_remove_hcd(hcd);
1283 dwc_otg_hcd_free(hcd);
1287 DWC_PRINT("dwc_otg_hcd_init error,everest\n");
1295 * Frees memory and resources associated with the HCD and deregisters the bus.
1297 void dwc_otg_hcd_remove(struct device *dev)
1299 dwc_otg_device_t *otg_dev = dev->platform_data;
1300 dwc_otg_hcd_t *dwc_otg_hcd = otg_dev->hcd;
1301 struct usb_hcd *hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
1303 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE\n");
1305 /* Turn off all interrupts */
1306 dwc_write_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0);
1307 dwc_modify_reg32 (&dwc_otg_hcd->core_if->core_global_regs->gahbcfg, 1, 0);
1309 usb_remove_hcd(hcd);
1310 dwc_otg_hcd_free(hcd);
1317 /* =========================================================================
1318 * Linux HC Driver Functions
1319 * ========================================================================= */
1322 * Initializes dynamic portions of the DWC_otg HCD state.
1324 static void hcd_reinit(dwc_otg_hcd_t *_hcd)
1326 struct list_head *item;
1330 DWC_DEBUGPL(DBG_HCD, "%s: Enter\n", __func__);
1332 _hcd->flags.d32 = 0;
1334 _hcd->non_periodic_qh_ptr = &_hcd->non_periodic_sched_active;
1335 _hcd->non_periodic_channels = 0;
1336 _hcd->periodic_channels = 0;
1339 * Put all channels in the free channel list and clean up channel
1342 item = _hcd->free_hc_list.next;
1343 while (item != &_hcd->free_hc_list) {
1345 item = _hcd->free_hc_list.next;
1347 num_channels = _hcd->core_if->core_params->host_channels;
1348 for (i = 0; i < num_channels; i++) {
1349 channel = _hcd->hc_ptr_array[i];
1350 list_add_tail(&channel->hc_list_entry, &_hcd->free_hc_list);
1351 dwc_otg_hc_cleanup(_hcd->core_if, channel);
1354 /* Initialize the DWC core for host mode operation. */
1355 dwc_otg_core_host_init(_hcd->core_if);
1358 /** Initializes the DWC_otg controller and its root hub and prepares it for host
1359 * mode operation. Activates the root port. Returns 0 on success and a negative
1360 * error code on failure. */
1361 int dwc_otg_hcd_start(struct usb_hcd *_hcd)
1363 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1364 dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
1365 unsigned long flags;
1367 struct usb_bus *bus;
1369 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
1370 local_irq_save(flags);
1372 bus = hcd_to_bus(_hcd);
1373 _hcd->state = HC_STATE_RUNNING;
1375 /* Initialize and connect root hub if one is not already attached */
1376 if (bus->root_hub) {
1377 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
1378 /* Inform the HUB driver to resume. */
1379 usb_hcd_resume_root_hub(_hcd);
1385 struct usb_device *udev;6
1386 udev = usb_alloc_dev(NULL, bus, 0);
1387 udev->speed = USB_SPEED_HIGH;
1389 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error udev alloc\n");
1394 if ((retval = usb_hcd_register_root_hub(udev, _hcd)) != 0) {
1395 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Error registering %d\n", retval);
1400 /* Initialize the bus state. If the core is in Device Mode
1401 * HALT the USB bus and return. */
1402 if (!dwc_otg_hcd->host_enabled || dwc_otg_is_device_mode (core_if)) {
1403 DWC_PRINT("dwc_otg_hcd_start controller in device mode,everest\n");
1404 //_hcd->state = HC_STATE_HALT;
1407 hcd_reinit(dwc_otg_hcd);
1409 local_irq_restore(flags);
1414 static void qh_list_free(dwc_otg_hcd_t *_hcd, struct list_head *_qh_list)
1416 struct list_head *item;
1419 if (_qh_list->next == NULL) {
1420 /* The list hasn't been initialized yet. */
1424 /* Ensure there are no QTDs or URBs left. */
1425 kill_urbs_in_qh_list(_hcd, _qh_list);
1427 for (item = _qh_list->next; item != _qh_list; item = _qh_list->next) {
1428 qh = list_entry(item, dwc_otg_qh_t, qh_list_entry);
1429 dwc_otg_hcd_qh_remove_and_free(_hcd, qh);
1434 * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
1437 void dwc_otg_hcd_stop(struct usb_hcd *_hcd)
1439 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1440 hprt0_data_t hprt0 = { .d32=0 };
1442 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
1444 /* Turn off all host-specific interrupts. */
1445 dwc_otg_disable_host_interrupts( dwc_otg_hcd->core_if );
1448 * The root hub should be disconnected before this function is called.
1449 * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
1450 * and the QH lists (via ..._hcd_endpoint_disable).
1453 /* Turn off the vbus power */
1454 DWC_PRINT("PortPower off\n");
1456 dwc_write_reg32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0.d32);
1462 /** Returns the current frame number. */
1463 int dwc_otg_hcd_get_frame_number(struct usb_hcd *_hcd)
1465 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1468 hfnum.d32 = dwc_read_reg32(&dwc_otg_hcd->core_if->
1469 host_if->host_global_regs->hfnum);
1472 DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n", hfnum.b.frnum);
1474 return hfnum.b.frnum;
1478 * Frees secondary storage associated with the dwc_otg_hcd structure contained
1479 * in the struct usb_hcd field.
1481 void dwc_otg_hcd_free(struct usb_hcd *_hcd)
1483 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1486 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
1488 // del_timers(dwc_otg_hcd);
1490 /* Free memory for QH/QTD lists */
1491 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
1492 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
1493 qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
1494 // qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
1495 // qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
1496 // qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
1498 /* Free memory for the host channels. */
1499 for (i = 0; i < MAX_EPS_CHANNELS; i++) {
1500 dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
1502 DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n", i, hc);
1507 if (dwc_otg_hcd->core_if->dma_enable) {
1508 if (dwc_otg_hcd->status_buf_dma) {
1509 dma_free_coherent(_hcd->self.controller,
1510 DWC_OTG_HCD_STATUS_BUF_SIZE,
1511 dwc_otg_hcd->status_buf,
1512 dwc_otg_hcd->status_buf_dma);
1514 } else if (dwc_otg_hcd->status_buf != NULL) {
1515 kfree(dwc_otg_hcd->status_buf);
1522 static void dump_urb_info(struct urb *_urb, char* _fn_name)
1524 DWC_PRINT(" Device address: %d\n", usb_pipedevice(_urb->pipe));
1525 DWC_PRINT(" Endpoint: %d, %s\n", usb_pipeendpoint(_urb->pipe),
1526 (usb_pipein(_urb->pipe) ? "IN" : "OUT"));
1527 DWC_PRINT(" Endpoint type: %s\n",
1529 switch (usb_pipetype(_urb->pipe)) {
1530 case PIPE_CONTROL: pipetype = "CONTROL"; break;
1531 case PIPE_BULK: pipetype = "BULK"; break;
1532 case PIPE_INTERRUPT: pipetype = "INTERRUPT"; break;
1533 case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
1534 default: pipetype = "UNKNOWN"; break;
1536 DWC_PRINT(" Speed: %s\n",
1538 switch (_urb->dev->speed) {
1539 case USB_SPEED_HIGH: speed = "HIGH"; break;
1540 case USB_SPEED_FULL: speed = "FULL"; break;
1541 case USB_SPEED_LOW: speed = "LOW"; break;
1542 default: speed = "UNKNOWN"; break;
1544 DWC_PRINT(" Max packet size: %d\n",
1545 usb_maxpacket(_urb->dev, _urb->pipe, usb_pipeout(_urb->pipe)));
1546 DWC_PRINT(" Data buffer length: %d\n", _urb->transfer_buffer_length);
1547 DWC_PRINT(" Transfer buffer: %p, Transfer DMA: %p\n",
1548 _urb->transfer_buffer, (void *)_urb->transfer_dma);
1549 DWC_PRINT(" Setup buffer: %p, Setup DMA: %p\n",
1550 _urb->setup_packet, (void *)_urb->setup_dma);
1551 DWC_PRINT(" Interval: %d\n", _urb->interval);
1552 if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
1554 for (i = 0; i < _urb->number_of_packets; i++) {
1555 DWC_PRINT(" ISO Desc %d:\n", i);
1556 DWC_PRINT(" offset: %d, length %d\n",
1557 _urb->iso_frame_desc[i].offset,
1558 _urb->iso_frame_desc[i].length);
1563 static void dump_channel_info(dwc_otg_hcd_t *_hcd,
1566 if (qh->channel != NULL) {
1567 dwc_hc_t *hc = qh->channel;
1568 struct list_head *item;
1569 dwc_otg_qh_t *qh_item;
1570 int num_channels = _hcd->core_if->core_params->host_channels;
1573 dwc_otg_hc_regs_t *hc_regs;
1574 hcchar_data_t hcchar;
1575 hcsplt_data_t hcsplt;
1576 hctsiz_data_t hctsiz;
1579 hc_regs = _hcd->core_if->host_if->hc_regs[hc->hc_num];
1580 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1581 hcsplt.d32 = dwc_read_reg32(&hc_regs->hcsplt);
1582 hctsiz.d32 = dwc_read_reg32(&hc_regs->hctsiz);
1583 hcdma = dwc_read_reg32(&hc_regs->hcdma);
1585 DWC_PRINT(" Assigned to channel %p:\n", hc);
1586 DWC_PRINT(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
1587 DWC_PRINT(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
1588 DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
1589 hc->dev_addr, hc->ep_num, hc->ep_is_in);
1590 DWC_PRINT(" ep_type: %d\n", hc->ep_type);
1591 DWC_PRINT(" max_packet: %d\n", hc->max_packet);
1592 DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
1593 DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
1594 DWC_PRINT(" halt_status: %d\n", hc->halt_status);
1595 DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
1596 DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
1597 DWC_PRINT(" qh: %p\n", hc->qh);
1598 DWC_PRINT(" NP inactive sched:\n");
1599 list_for_each(item, &_hcd->non_periodic_sched_inactive) {
1600 qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
1601 DWC_PRINT(" %p\n", qh_item);
1603 DWC_PRINT(" NP active sched:\n");
1604 list_for_each(item, &_hcd->non_periodic_sched_active) {
1605 qh_item = list_entry(item, dwc_otg_qh_t, qh_list_entry);
1606 DWC_PRINT(" %p\n", qh_item);
1608 DWC_PRINT(" Channels: \n");
1609 for (i = 0; i < num_channels; i++) {
1610 dwc_hc_t *hc = _hcd->hc_ptr_array[i];
1611 DWC_PRINT(" %2d: %p\n", i, hc);
1617 /** Starts processing a USB transfer request specified by a USB Request Block
1618 * (URB). mem_flags indicates the type of memory allocation to use while
1619 * processing this URB. */
1620 int dwc_otg_hcd_urb_enqueue(struct usb_hcd *_hcd,
1625 dwc_otg_hcd_t * dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1626 dwc_otg_qtd_t * qtd;
1628 if(atomic_read(&_urb->use_count)>1){
1631 DWC_PRINT("%s urb %p already in queue, qtd %p, count%d\n", __func__, _urb, _urb->hcpriv, atomic_read(&_urb->use_count));
1635 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
1636 dump_urb_info(_urb, "dwc_otg_hcd_urb_enqueue");
1639 if (!dwc_otg_hcd->flags.b.port_connect_status) {
1640 DWC_ERROR("DWC OTG No longer connected\n");
1641 /* No longer connected. */
1645 qtd = dwc_otg_hcd_qtd_create(_urb);
1647 DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
1651 retval = dwc_otg_hcd_qtd_add(qtd, dwc_otg_hcd);
1653 DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
1654 "Error status %d\n", retval);
1655 dwc_otg_hcd_qtd_free(qtd);
1659 * Make sure the start of frame interrupt is enabled now that
1660 * we know we should have queued data. The SOF interrupt
1661 * handler automatically disables itself when idle to reduce
1662 * the number of interrupts. See dwc_otg_hcd_handle_sof_intr()
1665 dwc_modify_reg32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk, 0,
1672 /** Aborts/cancels a USB transfer request. Always returns 0 to indicate
1674 int dwc_otg_hcd_urb_dequeue(struct usb_hcd *_hcd, struct urb *_urb, int _status)
1676 unsigned long flags;
1677 dwc_otg_hcd_t * dwc_otg_hcd;
1678 dwc_otg_qtd_t * urb_qtd;
1680 struct usb_host_endpoint *_ep;
1682 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
1684 if(((uint32_t)_urb&0xf0000000)==0)
1685 DWC_PRINT("%s urb is %p\n", __func__, _urb);
1687 _ep = dwc_urb_to_endpoint(_urb);
1690 DWC_PRINT("%s=====================================================\n",__func__);
1691 DWC_PRINT("urb->ep is null\n");
1695 urb_qtd = (dwc_otg_qtd_t *) _urb->hcpriv;
1696 if(((uint32_t)urb_qtd&0xf0000000) == 0)
1698 DWC_PRINT("%s,urb_qtd is %p urb %p, count %d\n",__func__, urb_qtd, _urb, atomic_read(&_urb->use_count));
1699 if((atomic_read(&_urb->use_count)) == 0)
1704 qh = (dwc_otg_qh_t *) _ep->hcpriv;
1705 dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1706 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1709 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
1710 dump_urb_info(_urb, "dwc_otg_hcd_urb_dequeue");
1711 if (urb_qtd == qh->qtd_in_process) {
1712 dump_channel_info(dwc_otg_hcd, qh);
1718 if (urb_qtd == qh->qtd_in_process) {
1719 /* The QTD is in process (it has been assigned to a channel). */
1720 if (dwc_otg_hcd->flags.b.port_connect_status) {
1722 * If still connected (i.e. in host mode), halt the
1723 * channel so it can be used for other transfers. If
1724 * no longer connected, the host registers can't be
1725 * written to halt the channel since the core is in
1728 dwc_otg_hc_halt(dwc_otg_hcd->core_if, qh->channel,
1729 DWC_OTG_HC_XFER_URB_DEQUEUE);
1734 * Free the QTD and clean up the associated QH. Leave the QH in the
1735 * schedule if it has any remaining QTDs.
1737 dwc_otg_hcd_qtd_remove_and_free(urb_qtd);
1738 if (urb_qtd == qh->qtd_in_process) {
1739 dwc_otg_hcd_qh_deactivate(dwc_otg_hcd, qh, 0);
1741 qh->qtd_in_process = NULL;
1742 } else if (list_empty(&qh->qtd_list)) {
1743 dwc_otg_hcd_qh_remove(dwc_otg_hcd, qh);
1746 _urb->hcpriv = NULL;
1747 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1748 /* Higher layer software sets URB status. */
1749 usb_hcd_giveback_urb(_hcd, _urb, _status);
1750 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
1751 DWC_PRINT("Called usb_hcd_giveback_urb()\n");
1752 DWC_PRINT(" urb->status = %d\n", _status);
1758 /** Frees resources in the DWC_otg controller related to a given endpoint. Also
1759 * clears state in the HCD related to the endpoint. Any URBs for the endpoint
1760 * must already be dequeued. */
1761 void dwc_otg_hcd_endpoint_disable(struct usb_hcd *_hcd,
1762 struct usb_host_endpoint *_ep)
1765 unsigned long flags;
1767 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(_hcd);
1769 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1771 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
1772 "endpoint=%d\n", _ep->desc.bEndpointAddress,
1773 dwc_ep_addr_to_endpoint(_ep->desc.bEndpointAddress));
1775 qh = (dwc_otg_qh_t *)(_ep->hcpriv);
1778 /** Check that the QTD list is really empty */
1779 if (!list_empty(&qh->qtd_list)) {
1780 DWC_WARN("DWC OTG HCD EP DISABLE:"
1781 " QTD List for this endpoint is not empty\n");
1785 dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd, qh);
1789 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1794 /** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
1795 * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
1798 * This function is called by the USB core when an interrupt occurs */
1799 irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *_hcd)
1802 unsigned long flags;
1803 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1805 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
1807 result = IRQ_RETVAL(dwc_otg_hcd_handle_intr(dwc_otg_hcd));
1809 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
1814 /** Creates Status Change bitmap for the root hub and root port. The bitmap is
1815 * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
1816 * is the status change indicator for the single root port. Returns 1 if either
1817 * change indicator is 1, otherwise returns 0. */
1818 int dwc_otg_hcd_hub_status_data(struct usb_hcd *_hcd,
1821 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
1824 _buf[0] |= (dwc_otg_hcd->flags.b.port_connect_status_change ||
1825 dwc_otg_hcd->flags.b.port_reset_change ||
1826 dwc_otg_hcd->flags.b.port_enable_change ||
1827 dwc_otg_hcd->flags.b.port_suspend_change ||
1828 dwc_otg_hcd->flags.b.port_over_current_change) << 1;
1832 DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
1833 " Root port status changed\n");
1834 DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
1835 dwc_otg_hcd->flags.b.port_connect_status_change);
1836 DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
1837 dwc_otg_hcd->flags.b.port_reset_change);
1838 DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
1839 dwc_otg_hcd->flags.b.port_enable_change);
1840 DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
1841 dwc_otg_hcd->flags.b.port_suspend_change);
1842 DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
1843 dwc_otg_hcd->flags.b.port_over_current_change);
1846 return (_buf[0] != 0);
1849 #ifdef DWC_HS_ELECT_TST
1851 * Quick and dirty hack to implement the HS Electrical Test
1852 * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
1854 * This code was copied from our userspace app "hset". It sends a
1855 * Get Device Descriptor control sequence in two parts, first the
1856 * Setup packet by itself, followed some time later by the In and
1857 * Ack packets. Rather than trying to figure out how to add this
1858 * functionality to the normal driver code, we just hijack the
1859 * hardware, using these two function to drive the hardware
1863 dwc_otg_core_global_regs_t *global_regs;
1864 dwc_otg_host_global_regs_t *hc_global_regs;
1865 dwc_otg_hc_regs_t *hc_regs;
1866 uint32_t *data_fifo;
1868 static void do_setup(void)
1870 gintsts_data_t gintsts;
1871 hctsiz_data_t hctsiz;
1872 hcchar_data_t hcchar;
1877 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
1880 dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
1883 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1884 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1887 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1888 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1891 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1892 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1895 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1896 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1899 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1902 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1905 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1908 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1909 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1912 * Send Setup packet (Get Device Descriptor)
1915 /* Make sure channel is disabled */
1916 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1917 if (hcchar.b.chen) {
1918 //fprintf(stderr, "Channel already enabled 1, HCCHAR = %08x\n", hcchar.d32);
1920 // hcchar.b.chen = 1;
1921 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
1926 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1927 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
1930 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1931 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1934 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1935 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
1938 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1939 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
1942 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
1945 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
1948 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
1950 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1951 //if (hcchar.b.chen) {
1952 // fprintf(stderr, "** Channel _still_ enabled 1, HCCHAR = %08x **\n", hcchar.d32);
1958 hctsiz.b.xfersize = 8;
1959 hctsiz.b.pktcnt = 1;
1960 hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
1961 dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
1964 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
1965 hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
1970 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
1972 /* Fill FIFO with Setup data for Get Device Descriptor */
1973 data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
1974 dwc_write_reg32(data_fifo++, 0x01000680);
1975 dwc_write_reg32(data_fifo++, 0x00080000);
1977 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1978 //fprintf(stderr, "Waiting for HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
1980 /* Wait for host channel interrupt */
1982 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
1983 } while (gintsts.b.hcintr == 0);
1985 //fprintf(stderr, "Got HCINTR intr 1, GINTSTS = %08x\n", gintsts.d32);
1987 /* Disable HCINTs */
1988 dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
1990 /* Disable HAINTs */
1991 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
1994 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
1995 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
1998 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
1999 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2002 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2003 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2006 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2009 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2012 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2015 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2016 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2019 static void do_in_ack(void)
2021 gintsts_data_t gintsts;
2022 hctsiz_data_t hctsiz;
2023 hcchar_data_t hcchar;
2026 host_grxsts_data_t grxsts;
2029 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0001);
2032 dwc_write_reg32(&hc_regs->hcintmsk, 0x04a3);
2035 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2036 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2039 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2040 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2043 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2044 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2047 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2048 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2051 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2054 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2057 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2060 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2061 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2064 * Receive Control In packet
2067 /* Make sure channel is disabled */
2068 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2069 if (hcchar.b.chen) {
2070 //fprintf(stderr, "Channel already enabled 2, HCCHAR = %08x\n", hcchar.d32);
2073 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2078 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2079 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2082 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2083 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2086 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2087 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2090 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2091 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2094 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2097 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2100 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2102 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2103 //if (hcchar.b.chen) {
2104 // fprintf(stderr, "** Channel _still_ enabled 2, HCCHAR = %08x **\n", hcchar.d32);
2110 hctsiz.b.xfersize = 8;
2111 hctsiz.b.pktcnt = 1;
2112 hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
2113 dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2116 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2117 hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
2122 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2124 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2125 //fprintf(stderr, "Waiting for RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
2127 /* Wait for receive status queue interrupt */
2129 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2130 } while (gintsts.b.rxstsqlvl == 0);
2132 //fprintf(stderr, "Got RXSTSQLVL intr 1, GINTSTS = %08x\n", gintsts.d32);
2135 grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
2136 //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
2138 /* Clear RXSTSQLVL in GINTSTS */
2140 gintsts.b.rxstsqlvl = 1;
2141 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2143 switch (grxsts.b.pktsts) {
2144 case DWC_GRXSTS_PKTSTS_IN:
2145 /* Read the data into the host buffer */
2146 if (grxsts.b.bcnt > 0) {
2148 int word_count = (grxsts.b.bcnt + 3) / 4;
2150 data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
2152 for (i = 0; i < word_count; i++) {
2153 (void)dwc_read_reg32(data_fifo++);
2157 //fprintf(stderr, "Received %u bytes\n", (unsigned)grxsts.b.bcnt);
2161 //fprintf(stderr, "** Unexpected GRXSTS packet status 1 **\n");
2165 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2166 //fprintf(stderr, "Waiting for RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
2168 /* Wait for receive status queue interrupt */
2170 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2171 } while (gintsts.b.rxstsqlvl == 0);
2173 //fprintf(stderr, "Got RXSTSQLVL intr 2, GINTSTS = %08x\n", gintsts.d32);
2176 grxsts.d32 = dwc_read_reg32(&global_regs->grxstsp);
2177 //fprintf(stderr, "GRXSTS: %08x\n", grxsts.d32);
2179 /* Clear RXSTSQLVL in GINTSTS */
2181 gintsts.b.rxstsqlvl = 1;
2182 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2184 switch (grxsts.b.pktsts) {
2185 case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
2189 //fprintf(stderr, "** Unexpected GRXSTS packet status 2 **\n");
2193 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2194 //fprintf(stderr, "Waiting for HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
2196 /* Wait for host channel interrupt */
2198 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2199 } while (gintsts.b.hcintr == 0);
2201 //fprintf(stderr, "Got HCINTR intr 2, GINTSTS = %08x\n", gintsts.d32);
2204 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2205 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2208 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2209 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2212 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2213 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2216 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2219 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2222 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2225 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2226 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2233 * Send handshake packet
2237 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2238 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2241 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2242 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2245 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2246 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2249 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2252 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2255 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2258 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2259 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2261 /* Make sure channel is disabled */
2262 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2263 if (hcchar.b.chen) {
2264 //fprintf(stderr, "Channel already enabled 3, HCCHAR = %08x\n", hcchar.d32);
2267 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2272 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2273 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2276 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2277 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2280 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2281 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2284 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2285 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2288 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2291 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2294 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2296 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2297 //if (hcchar.b.chen) {
2298 // fprintf(stderr, "** Channel _still_ enabled 3, HCCHAR = %08x **\n", hcchar.d32);
2304 hctsiz.b.xfersize = 0;
2305 hctsiz.b.pktcnt = 1;
2306 hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
2307 dwc_write_reg32(&hc_regs->hctsiz, hctsiz.d32);
2310 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2311 hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
2316 dwc_write_reg32(&hc_regs->hcchar, hcchar.d32);
2318 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2319 //fprintf(stderr, "Waiting for HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
2321 /* Wait for host channel interrupt */
2323 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2324 } while (gintsts.b.hcintr == 0);
2326 //fprintf(stderr, "Got HCINTR intr 3, GINTSTS = %08x\n", gintsts.d32);
2328 /* Disable HCINTs */
2329 dwc_write_reg32(&hc_regs->hcintmsk, 0x0000);
2331 /* Disable HAINTs */
2332 dwc_write_reg32(&hc_global_regs->haintmsk, 0x0000);
2335 haint.d32 = dwc_read_reg32(&hc_global_regs->haint);
2336 //fprintf(stderr, "HAINT: %08x\n", haint.d32);
2339 hcint.d32 = dwc_read_reg32(&hc_regs->hcint);
2340 //fprintf(stderr, "HCINT: %08x\n", hcint.d32);
2343 hcchar.d32 = dwc_read_reg32(&hc_regs->hcchar);
2344 //fprintf(stderr, "HCCHAR: %08x\n", hcchar.d32);
2347 dwc_write_reg32(&hc_regs->hcint, hcint.d32);
2350 dwc_write_reg32(&hc_global_regs->haint, haint.d32);
2353 dwc_write_reg32(&global_regs->gintsts, gintsts.d32);
2356 gintsts.d32 = dwc_read_reg32(&global_regs->gintsts);
2357 //fprintf(stderr, "GINTSTS: %08x\n", gintsts.d32);
2359 #endif /* DWC_HS_ELECT_TST */
2361 /** Handles hub class-specific requests.*/
2362 int dwc_otg_hcd_hub_control(struct usb_hcd *_hcd,
2370 unsigned long flags;
2372 dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd (_hcd);
2373 dwc_otg_core_if_t *core_if = hcd_to_dwc_otg_hcd (_hcd)->core_if;
2374 struct usb_hub_descriptor *desc;
2375 hprt0_data_t hprt0 = {.d32 = 0};
2377 uint32_t port_status;
2378 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
2381 case ClearHubFeature:
2382 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2383 "ClearHubFeature 0x%x\n", _wValue);
2385 case C_HUB_LOCAL_POWER:
2386 case C_HUB_OVER_CURRENT:
2387 /* Nothing required here */
2391 DWC_ERROR ("DWC OTG HCD - "
2392 "ClearHubFeature request %xh unknown\n", _wValue);
2395 case ClearPortFeature:
2396 if (!_wIndex || _wIndex > 1)
2400 case USB_PORT_FEAT_ENABLE:
2401 DWC_DEBUGPL (DBG_ANY, "DWC OTG HCD HUB CONTROL - "
2402 "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
2403 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2405 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2407 case USB_PORT_FEAT_SUSPEND:
2408 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2409 "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
2410 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2412 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2413 /* Clear Resume bit */
2414 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
2416 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
2418 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2420 case USB_PORT_FEAT_POWER:
2421 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2422 "ClearPortFeature USB_PORT_FEAT_POWER\n");
2423 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2425 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2427 case USB_PORT_FEAT_INDICATOR:
2428 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2429 "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
2430 /* Port inidicator not supported */
2432 case USB_PORT_FEAT_C_CONNECTION:
2433 /* Clears drivers internal connect status change
2435 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2436 "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
2437 dwc_otg_hcd->flags.b.port_connect_status_change = 0;
2439 case USB_PORT_FEAT_C_RESET:
2440 /* Clears the driver's internal Port Reset Change
2442 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2443 "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
2444 dwc_otg_hcd->flags.b.port_reset_change = 0;
2446 case USB_PORT_FEAT_C_ENABLE:
2447 /* Clears the driver's internal Port
2448 * Enable/Disable Change flag */
2449 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2450 "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
2451 dwc_otg_hcd->flags.b.port_enable_change = 0;
2453 case USB_PORT_FEAT_C_SUSPEND:
2454 /* Clears the driver's internal Port Suspend
2455 * Change flag, which is set when resume signaling on
2456 * the host port is complete */
2457 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2458 "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
2459 dwc_otg_hcd->flags.b.port_suspend_change = 0;
2461 case USB_PORT_FEAT_C_OVER_CURRENT:
2462 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2463 "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
2464 dwc_otg_hcd->flags.b.port_over_current_change = 0;
2468 DWC_ERROR ("DWC OTG HCD - "
2469 "ClearPortFeature request %xh "
2470 "unknown or unsupported\n", _wValue);
2473 case GetHubDescriptor:
2474 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2475 "GetHubDescriptor\n");
2476 desc = (struct usb_hub_descriptor *)_buf;
2477 desc->bDescLength = 9;
2478 desc->bDescriptorType = 0x29;
2479 desc->bNbrPorts = 1;
2480 desc->wHubCharacteristics = 0x08;
2481 desc->bPwrOn2PwrGood = 1;
2482 desc->bHubContrCurrent = 0;
2483 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
2484 desc->u.hs.DeviceRemovable[0] = 0;
2485 desc->u.hs.DeviceRemovable[1] = 0xff;
2487 desc->bitmap[0] = 0;
2488 desc->bitmap[1] = 0xff;
2492 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2494 memset (_buf, 0, 4);
2497 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2500 if (!_wIndex || _wIndex > 1)
2505 if (dwc_otg_hcd->flags.b.port_connect_status_change)
2506 port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
2508 if (dwc_otg_hcd->flags.b.port_enable_change)
2509 port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
2511 if (dwc_otg_hcd->flags.b.port_suspend_change)
2512 port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
2514 if (dwc_otg_hcd->flags.b.port_reset_change)
2515 port_status |= (1 << USB_PORT_FEAT_C_RESET);
2517 if (dwc_otg_hcd->flags.b.port_over_current_change) {
2518 DWC_ERROR("Device Not Supported\n");
2519 port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
2522 if (!dwc_otg_hcd->flags.b.port_connect_status) {
2524 * The port is disconnected, which means the core is
2525 * either in device mode or it soon will be. Just
2526 * return 0's for the remainder of the port status
2527 * since the port register can't be read if the core
2528 * is in device mode.
2530 *((__le32 *) _buf) = cpu_to_le32(port_status);
2534 hprt0.d32 = dwc_read_reg32(core_if->host_if->hprt0);
2535 DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
2537 if (hprt0.b.prtconnsts)
2538 port_status |= (1 << USB_PORT_FEAT_CONNECTION);
2541 port_status |= (1 << USB_PORT_FEAT_ENABLE);
2543 if (hprt0.b.prtsusp)
2544 port_status |= (1 << USB_PORT_FEAT_SUSPEND);
2546 if (hprt0.b.prtovrcurract)
2547 port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
2550 port_status |= (1 << USB_PORT_FEAT_RESET);
2553 port_status |= (1 << USB_PORT_FEAT_POWER);
2555 if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
2556 port_status |= USB_PORT_STAT_HIGH_SPEED;
2558 else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
2559 port_status |= USB_PORT_STAT_LOW_SPEED;
2561 if (hprt0.b.prttstctl)
2562 port_status |= (1 << USB_PORT_FEAT_TEST);
2564 /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
2566 *((__le32 *) _buf) = cpu_to_le32(port_status);
2570 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2572 /* No HUB features supported */
2574 case SetPortFeature:
2575 if (_wValue != USB_PORT_FEAT_TEST && (!_wIndex || _wIndex > 1))
2578 if (!dwc_otg_hcd->flags.b.port_connect_status) {
2580 * The port is disconnected, which means the core is
2581 * either in device mode or it soon will be. Just
2582 * return without doing anything since the port
2583 * register can't be written if the core is in device
2590 case USB_PORT_FEAT_SUSPEND:
2591 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2592 "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
2593 if (_hcd->self.otg_port == _wIndex &&
2594 _hcd->self.b_hnp_enable) {
2595 gotgctl_data_t gotgctl = {.d32=0};
2596 gotgctl.b.hstsethnpen = 1;
2597 dwc_modify_reg32( &core_if->core_global_regs->gotgctl,
2599 core_if->op_state = A_SUSPEND;
2601 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2602 hprt0.b.prtsusp = 1;
2603 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2604 //DWC_PRINT( "SUSPEND: HPRT0=%0x\n", hprt0.d32);
2605 /* Suspend the Phy Clock */
2607 pcgcctl_data_t pcgcctl = {.d32=0};
2608 pcgcctl.b.stoppclk = 1;
2609 dwc_write_reg32(core_if->pcgcctl, pcgcctl.d32);
2612 /* For HNP the bus must be suspended for at least 200ms.*/
2613 if (_hcd->self.b_hnp_enable) {
2614 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
2616 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
2617 //DWC_PRINT( "SUSPEND: wait complete! (%d)\n", _hcd->state);
2620 case USB_PORT_FEAT_POWER:
2621 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2622 "SetPortFeature - USB_PORT_FEAT_POWER\n");
2623 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2625 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2627 case USB_PORT_FEAT_RESET:
2628 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2629 "SetPortFeature - USB_PORT_FEAT_RESET\n");
2630 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2631 /* When B-Host the Port reset bit is set in
2632 * the Start HCD Callback function, so that
2633 * the reset is started within 1ms of the HNP
2634 * success interrupt. */
2635 if (!_hcd->self.is_b_host) {
2637 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2639 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
2640 /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
2641 // kever @rk 20110712
2642 // can not use mdelay(60) while irq disable
2645 spin_lock_irqsave(&dwc_otg_hcd->global_lock, flags);
2647 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2650 #ifdef DWC_HS_ELECT_TST
2651 case USB_PORT_FEAT_TEST:
2654 gintmsk_data_t gintmsk;
2656 t = (_wIndex >> 8); /* MSB wIndex USB */
2657 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2658 "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
2659 warn("USB_PORT_FEAT_TEST %d\n", t);
2661 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2662 hprt0.b.prttstctl = t;
2663 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2665 /* Setup global vars with reg addresses (quick and
2666 * dirty hack, should be cleaned up)
2668 global_regs = core_if->core_global_regs;
2669 hc_global_regs = core_if->host_if->host_global_regs;
2670 hc_regs = (dwc_otg_hc_regs_t *)((char *)global_regs + 0x500);
2671 data_fifo = (uint32_t *)((char *)global_regs + 0x1000);
2673 if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
2674 /* Save current interrupt mask */
2675 gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
2677 /* Disable all interrupts while we muck with
2678 * the hardware directly
2680 dwc_write_reg32(&global_regs->gintmsk, 0);
2682 /* 15 second delay per the test spec */
2685 /* Drive suspend on the root port */
2686 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2687 hprt0.b.prtsusp = 1;
2689 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2691 /* 15 second delay per the test spec */
2694 /* Drive resume on the root port */
2695 hprt0.d32 = dwc_otg_read_hprt0 (core_if);
2696 hprt0.b.prtsusp = 0;
2698 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2701 /* Clear the resume bit */
2703 dwc_write_reg32(core_if->host_if->hprt0, hprt0.d32);
2705 /* Restore interrupts */
2706 dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
2707 } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
2708 /* Save current interrupt mask */
2709 gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
2711 /* Disable all interrupts while we muck with
2712 * the hardware directly
2714 dwc_write_reg32(&global_regs->gintmsk, 0);
2716 /* 15 second delay per the test spec */
2719 /* Send the Setup packet */
2722 /* 15 second delay so nothing else happens for awhile */
2725 /* Restore interrupts */
2726 dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
2727 } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
2728 /* Save current interrupt mask */
2729 gintmsk.d32 = dwc_read_reg32(&global_regs->gintmsk);
2731 /* Disable all interrupts while we muck with
2732 * the hardware directly
2734 dwc_write_reg32(&global_regs->gintmsk, 0);
2736 /* Send the Setup packet */
2739 /* 15 second delay so nothing else happens for awhile */
2742 /* Send the In and Ack packets */
2745 /* 15 second delay so nothing else happens for awhile */
2748 /* Restore interrupts */
2749 dwc_write_reg32(&global_regs->gintmsk, gintmsk.d32);
2754 #endif /* DWC_HS_ELECT_TST */
2756 case USB_PORT_FEAT_INDICATOR:
2757 DWC_DEBUGPL (DBG_HCD, "DWC OTG HCD HUB CONTROL - "
2758 "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
2763 DWC_ERROR ("DWC OTG HCD - "
2764 "SetPortFeature request %xh "
2765 "unknown or unsupported\n", _wValue);
2772 DWC_WARN ("DWC OTG HCD - "
2773 "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
2774 _typeReq, _wIndex, _wValue);
2778 spin_unlock_irqrestore(&dwc_otg_hcd->global_lock, flags);
2784 * Assigns transactions from a QTD to a free host channel and initializes the
2785 * host channel to perform the transactions. The host channel is removed from
2788 * @param _hcd The HCD state structure.
2789 * @param _qh Transactions from the first QTD for this QH are selected and
2790 * assigned to a free host channel.
2792 static void assign_and_init_hc(dwc_otg_hcd_t *_hcd, dwc_otg_qh_t *_qh)
2798 DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p)\n", __func__, _hcd, _qh);
2799 hc = list_entry(_hcd->free_hc_list.next, dwc_hc_t, hc_list_entry);
2801 /* Remove the host channel from the free list. */
2802 list_del_init(&hc->hc_list_entry);
2804 qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry);
2807 _qh->qtd_in_process = qtd;
2810 * Use usb_pipedevice to determine device address. This address is
2811 * 0 before the SET_ADDRESS command and the correct address afterward.
2813 hc->dev_addr = usb_pipedevice(urb->pipe);
2814 hc->ep_num = usb_pipeendpoint(urb->pipe);
2816 if (urb->dev->speed == USB_SPEED_LOW) {
2817 hc->speed = DWC_OTG_EP_SPEED_LOW;
2819 * yk@rk 20101216 fix bandwidth check error when full/low speed
2822 _hcd->core_if->core_params->speed = DWC_SPEED_PARAM_FULL;
2823 } else if (urb->dev->speed == USB_SPEED_FULL) {
2824 hc->speed = DWC_OTG_EP_SPEED_FULL;
2826 * yk@rk 20101216 fix bandwidth check error when full/low speed
2827 * device connected. warning: only support 1 device at root hub.
2829 _hcd->core_if->core_params->speed = DWC_SPEED_PARAM_FULL;
2831 hc->speed = DWC_OTG_EP_SPEED_HIGH;
2834 hc->max_packet = dwc_max_packet(_qh->maxp);
2836 hc->xfer_started = 0;
2837 hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
2838 hc->error_state = (qtd->error_count > 0);
2839 hc->halt_on_queue = 0;
2840 hc->halt_pending = 0;
2844 * The following values may be modified in the transfer type section
2845 * below. The xfer_len value may be reduced when the transfer is
2846 * started to accommodate the max widths of the XferSize and PktCnt
2847 * fields in the HCTSIZn register.
2849 hc->do_ping = _qh->ping_state;
2850 hc->ep_is_in = (usb_pipein(urb->pipe) != 0);
2851 hc->data_pid_start = _qh->data_toggle;
2852 hc->multi_count = 1;
2854 if (_hcd->core_if->dma_enable) {
2855 hc->xfer_buff = (uint8_t *)urb->transfer_dma + urb->actual_length;
2857 hc->xfer_buff = (uint8_t *)urb->transfer_buffer + urb->actual_length;
2859 hc->xfer_len = urb->transfer_buffer_length - urb->actual_length;
2863 * Set the split attributes
2866 if (_qh->do_split) {
2868 hc->xact_pos = qtd->isoc_split_pos;
2869 hc->complete_split = qtd->complete_split;
2870 hc->hub_addr = urb->dev->tt->hub->devnum;
2871 hc->port_addr = urb->dev->ttport;
2874 switch (usb_pipetype(urb->pipe)) {
2876 hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
2877 switch (qtd->control_phase) {
2878 case DWC_OTG_CONTROL_SETUP:
2879 DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
2882 hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
2883 if (_hcd->core_if->dma_enable) {
2884 hc->xfer_buff = (uint8_t *)urb->setup_dma;
2886 hc->xfer_buff = (uint8_t *)urb->setup_packet;
2890 case DWC_OTG_CONTROL_DATA:
2891 DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
2892 hc->data_pid_start = qtd->data_toggle;
2894 case DWC_OTG_CONTROL_STATUS:
2896 * Direction is opposite of data direction or IN if no
2899 DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
2900 if (urb->transfer_buffer_length == 0) {
2903 hc->ep_is_in = (usb_pipein(urb->pipe) != USB_DIR_IN);
2908 hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
2910 if (_hcd->core_if->dma_enable) {
2911 hc->xfer_buff = (uint8_t *)_hcd->status_buf_dma;
2913 hc->xfer_buff = (uint8_t *)_hcd->status_buf;
2919 hc->ep_type = DWC_OTG_EP_TYPE_BULK;
2921 case PIPE_INTERRUPT:
2922 hc->ep_type = DWC_OTG_EP_TYPE_INTR;
2924 case PIPE_ISOCHRONOUS:
2926 struct usb_iso_packet_descriptor *frame_desc;
2927 frame_desc = &urb->iso_frame_desc[qtd->isoc_frame_index];
2928 hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
2929 if (_hcd->core_if->dma_enable) {
2930 hc->xfer_buff = (uint8_t *)urb->transfer_dma;
2932 hc->xfer_buff = (uint8_t *)urb->transfer_buffer;
2934 hc->xfer_buff += frame_desc->offset + qtd->isoc_split_offset;
2935 hc->xfer_len = frame_desc->length - qtd->isoc_split_offset;
2937 if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
2938 if (hc->xfer_len <= 188) {
2939 hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
2942 hc->xact_pos = DWC_HCSPLIT_XACTPOS_BEGIN;
2949 if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
2950 hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
2952 * This value may be modified when the transfer is started to
2953 * reflect the actual transfer length.
2955 hc->multi_count = dwc_hb_mult(_qh->maxp);
2958 dwc_otg_hc_init(_hcd->core_if, hc);
2963 * This function selects transactions from the HCD transfer schedule and
2964 * assigns them to available host channels. It is called from HCD interrupt
2965 * handler functions.
2967 * @param _hcd The HCD state structure.
2969 * @return The types of new transactions that were assigned to host channels.
2971 dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *_hcd)
2973 struct list_head *qh_ptr;
2976 dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
2979 DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
2982 /* Process entries in the periodic ready list. */
2983 qh_ptr = _hcd->periodic_sched_inactive.next;
2984 while ((qh_ptr != &_hcd->periodic_sched_inactive)&&
2985 !list_empty(&_hcd->free_hc_list)) {
2986 qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
2987 if(qh->qh_state != QH_READY){
2988 qh_ptr = qh_ptr->next;
2992 assign_and_init_hc(_hcd, qh);
2995 * Move the QH from the periodic ready schedule to the
2996 * periodic assigned schedule.
2998 qh_ptr = qh_ptr->next;
2999 //list_move_tail(&qh->qh_list_entry, &_hcd->periodic_sched_assigned);
3000 qh->qh_state = QH_ASSIGNED;
3002 ret_val = DWC_OTG_TRANSACTION_PERIODIC;
3006 * Process entries in the inactive portion of the non-periodic
3007 * schedule. Some free host channels may not be used if they are
3008 * reserved for periodic transfers.
3010 qh_ptr = _hcd->non_periodic_sched_inactive.next;
3011 num_channels = _hcd->core_if->core_params->host_channels;
3012 while (qh_ptr != &_hcd->non_periodic_sched_inactive &&
3014 (_hcd->non_periodic_channels <
3015 num_channels - _hcd->periodic_channels) &&
3017 !list_empty(&_hcd->free_hc_list)) {
3019 qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
3020 assign_and_init_hc(_hcd, qh);
3023 * Move the QH from the non-periodic inactive schedule to the
3024 * non-periodic active schedule.
3026 qh_ptr = qh_ptr->next;
3027 list_move_tail(&qh->qh_list_entry, &_hcd->non_periodic_sched_active);
3029 if (ret_val == DWC_OTG_TRANSACTION_NONE) {
3030 ret_val = DWC_OTG_TRANSACTION_NON_PERIODIC;
3032 ret_val = DWC_OTG_TRANSACTION_ALL;
3035 _hcd->non_periodic_channels++;
3042 * Attempts to queue a single transaction request for a host channel
3043 * associated with either a periodic or non-periodic transfer. This function
3044 * assumes that there is space available in the appropriate request queue. For
3045 * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
3046 * is available in the appropriate Tx FIFO.
3048 * @param _hcd The HCD state structure.
3049 * @param _hc Host channel descriptor associated with either a periodic or
3050 * non-periodic transfer.
3051 * @param _fifo_dwords_avail Number of DWORDs available in the periodic Tx
3052 * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
3055 * @return 1 if a request is queued and more requests may be needed to
3056 * complete the transfer, 0 if no more requests are required for this
3057 * transfer, -1 if there is insufficient space in the Tx FIFO.
3059 static int queue_transaction(dwc_otg_hcd_t *_hcd,
3061 uint16_t _fifo_dwords_avail)
3065 if (_hcd->core_if->dma_enable) {
3066 if (!_hc->xfer_started) {
3067 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
3068 _hc->qh->ping_state = 0;
3071 } else if (_hc->halt_pending) {
3072 /* Don't queue a request if the channel has been halted. */
3074 } else if (_hc->halt_on_queue) {
3075 dwc_otg_hc_halt(_hcd->core_if, _hc, _hc->halt_status);
3077 } else if (_hc->do_ping) {
3078 if (!_hc->xfer_started) {
3079 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
3082 } else if (!_hc->ep_is_in ||
3083 _hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
3084 if ((_fifo_dwords_avail * 4) >= _hc->max_packet) {
3085 if (!_hc->xfer_started) {
3086 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
3089 retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
3095 if (!_hc->xfer_started) {
3096 dwc_otg_hc_start_transfer(_hcd->core_if, _hc);
3099 retval = dwc_otg_hc_continue_transfer(_hcd->core_if, _hc);
3107 * Processes active non-periodic channels and queues transactions for these
3108 * channels to the DWC_otg controller. After queueing transactions, the NP Tx
3109 * FIFO Empty interrupt is enabled if there are more transactions to queue as
3110 * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
3111 * FIFO Empty interrupt is disabled.
3113 static void process_non_periodic_channels(dwc_otg_hcd_t *_hcd)
3115 gnptxsts_data_t tx_status;
3116 struct list_head *orig_qh_ptr;
3119 int no_queue_space = 0;
3120 int no_fifo_space = 0;
3123 dwc_otg_core_global_regs_t *global_regs = _hcd->core_if->core_global_regs;
3125 DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
3127 tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
3128 DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (before queue): %d\n",
3129 tx_status.b.nptxqspcavail);
3130 DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
3131 tx_status.b.nptxfspcavail);
3134 * Keep track of the starting point. Skip over the start-of-list
3137 if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
3138 _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
3140 orig_qh_ptr = _hcd->non_periodic_qh_ptr;
3143 * Process once through the active list or until no more space is
3144 * available in the request queue or the Tx FIFO.
3147 tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
3148 if (!_hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
3153 qh = list_entry(_hcd->non_periodic_qh_ptr, dwc_otg_qh_t, qh_list_entry);
3154 status = queue_transaction(_hcd, qh->channel, tx_status.b.nptxfspcavail);
3158 } else if (status < 0) {
3163 /* Advance to next QH, skipping start-of-list entry. */
3164 _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
3165 if (_hcd->non_periodic_qh_ptr == &_hcd->non_periodic_sched_active) {
3166 _hcd->non_periodic_qh_ptr = _hcd->non_periodic_qh_ptr->next;
3169 } while (_hcd->non_periodic_qh_ptr != orig_qh_ptr);
3171 if (!_hcd->core_if->dma_enable) {
3172 gintmsk_data_t intr_mask = {.d32 = 0};
3173 intr_mask.b.nptxfempty = 1;
3176 tx_status.d32 = dwc_read_reg32(&global_regs->gnptxsts);
3177 DWC_DEBUGPL(DBG_HCDV, " NP Tx Req Queue Space Avail (after queue): %d\n",
3178 tx_status.b.nptxqspcavail);
3179 DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (after queue): %d\n",
3180 tx_status.b.nptxfspcavail);
3182 if (more_to_do || no_queue_space || no_fifo_space) {
3184 * May need to queue more transactions as the request
3185 * queue or Tx FIFO empties. Enable the non-periodic
3186 * Tx FIFO empty interrupt. (Always use the half-empty
3187 * level to ensure that new requests are loaded as
3188 * soon as possible.)
3190 dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
3193 * Disable the Tx FIFO empty interrupt since there are
3194 * no more transactions that need to be queued right
3195 * now. This function is called from interrupt
3196 * handlers to queue more transactions as transfer
3199 dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
3205 * Processes periodic channels for the next frame and queues transactions for
3206 * these channels to the DWC_otg controller. After queueing transactions, the
3207 * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
3208 * to queue as Periodic Tx FIFO or request queue space becomes available.
3209 * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
3211 static void process_periodic_channels(dwc_otg_hcd_t *_hcd)
3213 hptxsts_data_t tx_status;
3214 struct list_head *qh_ptr;
3217 int no_queue_space = 0;
3218 int no_fifo_space = 0;
3220 dwc_otg_host_global_regs_t *host_regs;
3221 host_regs = _hcd->core_if->host_if->host_global_regs;
3223 DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
3225 tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
3226 DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (before queue): %d\n",
3227 tx_status.b.ptxqspcavail);
3228 DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
3229 tx_status.b.ptxfspcavail);
3232 qh_ptr = _hcd->periodic_sched_inactive.next;
3233 while (qh_ptr != &_hcd->periodic_sched_inactive) {
3234 tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
3235 if (tx_status.b.ptxqspcavail == 0) {
3240 qh = list_entry(qh_ptr, dwc_otg_qh_t, qh_list_entry);
3241 if(qh->qh_state != QH_ASSIGNED){
3242 qh_ptr = qh_ptr->next;
3247 * Set a flag if we're queuing high-bandwidth in slave mode.
3248 * The flag prevents any halts to get into the request queue in
3249 * the middle of multiple high-bandwidth packets getting queued.
3251 if ((!_hcd->core_if->dma_enable) &&
3252 (qh->channel->multi_count > 1))
3254 _hcd->core_if->queuing_high_bandwidth = 1;
3257 status = queue_transaction(_hcd, qh->channel, tx_status.b.ptxfspcavail);
3264 * In Slave mode, stay on the current transfer until there is
3265 * nothing more to do or the high-bandwidth request count is
3266 * reached. In DMA mode, only need to queue one request. The
3267 * controller automatically handles multiple packets for
3268 * high-bandwidth transfers.
3270 if (_hcd->core_if->dma_enable ||
3272 qh->channel->requests == qh->channel->multi_count)) {
3273 qh_ptr = qh_ptr->next;
3275 * Move the QH from the periodic assigned schedule to
3276 * the periodic queued schedule.
3278 //list_move_tail(&qh->qh_list_entry, &_hcd->periodic_sched_queued);
3279 qh->qh_state = QH_QUEUED;
3281 /* done queuing high bandwidth */
3282 _hcd->core_if->queuing_high_bandwidth = 0;
3286 if (!_hcd->core_if->dma_enable) {
3287 dwc_otg_core_global_regs_t *global_regs;
3288 gintmsk_data_t intr_mask = {.d32 = 0};
3290 global_regs = _hcd->core_if->core_global_regs;
3291 intr_mask.b.ptxfempty = 1;
3293 tx_status.d32 = dwc_read_reg32(&host_regs->hptxsts);
3294 DWC_DEBUGPL(DBG_HCDV, " P Tx Req Queue Space Avail (after queue): %d\n",
3295 tx_status.b.ptxqspcavail);
3296 DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (after queue): %d\n",
3297 tx_status.b.ptxfspcavail);
3299 if (//!(list_empty(&_hcd->periodic_sched_assigned)) ||
3300 no_queue_space || no_fifo_space) {
3302 * May need to queue more transactions as the request
3303 * queue or Tx FIFO empties. Enable the periodic Tx
3304 * FIFO empty interrupt. (Always use the half-empty
3305 * level to ensure that new requests are loaded as
3306 * soon as possible.)
3308 dwc_modify_reg32(&global_regs->gintmsk, 0, intr_mask.d32);
3311 * Disable the Tx FIFO empty interrupt since there are
3312 * no more transactions that need to be queued right
3313 * now. This function is called from interrupt
3314 * handlers to queue more transactions as transfer
3317 dwc_modify_reg32(&global_regs->gintmsk, intr_mask.d32, 0);
3323 * This function processes the currently active host channels and queues
3324 * transactions for these channels to the DWC_otg controller. It is called
3325 * from HCD interrupt handler functions.
3327 * @param _hcd The HCD state structure.
3328 * @param _tr_type The type(s) of transactions to queue (non-periodic,
3329 * periodic, or both).
3331 void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *_hcd,
3332 dwc_otg_transaction_type_e _tr_type)
3335 DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
3337 /* Process host channels associated with periodic transfers. */
3338 if ((_tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
3339 _tr_type == DWC_OTG_TRANSACTION_ALL) //&&
3340 //!list_empty(&_hcd->periodic_sched_assigned)
3343 process_periodic_channels(_hcd);
3346 /* Process host channels associated with non-periodic transfers. */
3347 if ((_tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
3348 _tr_type == DWC_OTG_TRANSACTION_ALL)) {
3349 if (!list_empty(&_hcd->non_periodic_sched_active)) {
3350 process_non_periodic_channels(_hcd);
3353 * Ensure NP Tx FIFO empty interrupt is disabled when
3354 * there are no non-periodic transfers to process.
3356 gintmsk_data_t gintmsk = {.d32 = 0};
3357 gintmsk.b.nptxfempty = 1;
3358 dwc_modify_reg32(&_hcd->core_if->core_global_regs->gintmsk,
3365 * Sets the final status of an URB and returns it to the device driver. Any
3366 * required cleanup of the URB is performed.
3368 void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t * _hcd, struct urb *_urb,
3370 __releases(_hcd->lock)
3371 __acquires(_hcd->lock)
3375 if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
3376 DWC_PRINT("%s: urb %p, device %d, ep %d %s, status=%d\n",
3377 __func__, _urb, usb_pipedevice(_urb->pipe),
3378 usb_pipeendpoint(_urb->pipe),
3379 usb_pipein(_urb->pipe) ? "IN" : "OUT", _status);
3380 if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS) {
3382 for (i = 0; i < _urb->number_of_packets; i++) {
3383 DWC_PRINT(" ISO Desc %d status: %d\n",
3384 i, _urb->iso_frame_desc[i].status);
3390 _urb->status = _status;
3391 _urb->hcpriv = NULL;
3392 spin_unlock(&_hcd->global_lock);
3393 usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(_hcd), _urb, _status);
3394 spin_lock(&_hcd->global_lock);
3397 void dwc_otg_clear_halt(struct urb *_urb)
3399 struct dwc_otg_qh *_qh;
3400 struct usb_host_endpoint *ep = dwc_urb_to_endpoint(_urb);
3401 if((ep)&&(ep->hcpriv))
3403 _qh = (dwc_otg_qh_t *) ep->hcpriv;
3404 _qh->data_toggle = 0;
3408 * Returns the Queue Head for an URB.
3410 dwc_otg_qh_t * dwc_urb_to_qh(struct urb *_urb)
3412 struct usb_host_endpoint *ep = dwc_urb_to_endpoint(_urb);
3413 return (dwc_otg_qh_t *) ep->hcpriv;
3417 void dwc_print_setup_data (uint8_t *setup)
3420 if (CHK_DEBUG_LEVEL(DBG_HCD)){
3421 DWC_PRINT("Setup Data = MSB ");
3422 for (i=7; i>=0; i--) DWC_PRINT ("%02x ", setup[i]);
3424 DWC_PRINT(" bmRequestType Tranfer = %s\n", (setup[0]&0x80) ? "Device-to-Host" : "Host-to-Device");
3425 DWC_PRINT(" bmRequestType Type = ");
3426 switch ((setup[0]&0x60) >> 5) {
3427 case 0: DWC_PRINT("Standard\n"); break;
3428 case 1: DWC_PRINT("Class\n"); break;
3429 case 2: DWC_PRINT("Vendor\n"); break;
3430 case 3: DWC_PRINT("Reserved\n"); break;
3432 DWC_PRINT(" bmRequestType Recipient = ");
3433 switch (setup[0]&0x1f) {
3434 case 0: DWC_PRINT("Device\n"); break;
3435 case 1: DWC_PRINT("Interface\n"); break;
3436 case 2: DWC_PRINT("Endpoint\n"); break;
3437 case 3: DWC_PRINT("Other\n"); break;
3438 default: DWC_PRINT("Reserved\n"); break;
3440 DWC_PRINT(" bRequest = 0x%0x\n", setup[1]);
3441 DWC_PRINT(" wValue = 0x%0x\n", *((uint16_t *)&setup[2]));
3442 DWC_PRINT(" wIndex = 0x%0x\n", *((uint16_t *)&setup[4]));
3443 DWC_PRINT(" wLength = 0x%0x\n\n", *((uint16_t *)&setup[6]));
3448 void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *_hcd) {
3450 DWC_PRINT("Frame remaining at SOF:\n");
3451 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3452 _hcd->frrem_samples, _hcd->frrem_accum,
3453 (_hcd->frrem_samples > 0) ?
3454 _hcd->frrem_accum/_hcd->frrem_samples : 0);
3457 DWC_PRINT("Frame remaining at start_transfer (uframe 7):\n");
3458 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3459 _hcd->core_if->hfnum_7_samples, _hcd->core_if->hfnum_7_frrem_accum,
3460 (_hcd->core_if->hfnum_7_samples > 0) ?
3461 _hcd->core_if->hfnum_7_frrem_accum/_hcd->core_if->hfnum_7_samples : 0);
3462 DWC_PRINT("Frame remaining at start_transfer (uframe 0):\n");
3463 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3464 _hcd->core_if->hfnum_0_samples, _hcd->core_if->hfnum_0_frrem_accum,
3465 (_hcd->core_if->hfnum_0_samples > 0) ?
3466 _hcd->core_if->hfnum_0_frrem_accum/_hcd->core_if->hfnum_0_samples : 0);
3467 DWC_PRINT("Frame remaining at start_transfer (uframe 1-6):\n");
3468 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3469 _hcd->core_if->hfnum_other_samples, _hcd->core_if->hfnum_other_frrem_accum,
3470 (_hcd->core_if->hfnum_other_samples > 0) ?
3471 _hcd->core_if->hfnum_other_frrem_accum/_hcd->core_if->hfnum_other_samples : 0);
3474 DWC_PRINT("Frame remaining at sample point A (uframe 7):\n");
3475 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3476 _hcd->hfnum_7_samples_a, _hcd->hfnum_7_frrem_accum_a,
3477 (_hcd->hfnum_7_samples_a > 0) ?
3478 _hcd->hfnum_7_frrem_accum_a/_hcd->hfnum_7_samples_a : 0);
3479 DWC_PRINT("Frame remaining at sample point A (uframe 0):\n");
3480 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3481 _hcd->hfnum_0_samples_a, _hcd->hfnum_0_frrem_accum_a,
3482 (_hcd->hfnum_0_samples_a > 0) ?
3483 _hcd->hfnum_0_frrem_accum_a/_hcd->hfnum_0_samples_a : 0);
3484 DWC_PRINT("Frame remaining at sample point A (uframe 1-6):\n");
3485 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3486 _hcd->hfnum_other_samples_a, _hcd->hfnum_other_frrem_accum_a,
3487 (_hcd->hfnum_other_samples_a > 0) ?
3488 _hcd->hfnum_other_frrem_accum_a/_hcd->hfnum_other_samples_a : 0);
3491 DWC_PRINT("Frame remaining at sample point B (uframe 7):\n");
3492 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3493 _hcd->hfnum_7_samples_b, _hcd->hfnum_7_frrem_accum_b,
3494 (_hcd->hfnum_7_samples_b > 0) ?
3495 _hcd->hfnum_7_frrem_accum_b/_hcd->hfnum_7_samples_b : 0);
3496 DWC_PRINT("Frame remaining at sample point B (uframe 0):\n");
3497 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3498 _hcd->hfnum_0_samples_b, _hcd->hfnum_0_frrem_accum_b,
3499 (_hcd->hfnum_0_samples_b > 0) ?
3500 _hcd->hfnum_0_frrem_accum_b/_hcd->hfnum_0_samples_b : 0);
3501 DWC_PRINT("Frame remaining at sample point B (uframe 1-6):\n");
3502 DWC_PRINT(" samples %u, accum %llu, avg %llu\n",
3503 _hcd->hfnum_other_samples_b, _hcd->hfnum_other_frrem_accum_b,
3504 (_hcd->hfnum_other_samples_b > 0) ?
3505 _hcd->hfnum_other_frrem_accum_b/_hcd->hfnum_other_samples_b : 0);
3509 void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *_hcd)
3514 gnptxsts_data_t np_tx_status;
3515 hptxsts_data_t p_tx_status;
3517 num_channels = _hcd->core_if->core_params->host_channels;
3519 DWC_PRINT("************************************************************\n");
3520 DWC_PRINT("HCD State:\n");
3521 DWC_PRINT(" Num channels: %d\n", num_channels);
3522 for (i = 0; i < num_channels; i++) {
3523 dwc_hc_t *hc = _hcd->hc_ptr_array[i];
3524 DWC_PRINT(" Channel %d:\n", i);
3525 DWC_PRINT(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
3526 hc->dev_addr, hc->ep_num, hc->ep_is_in);
3527 DWC_PRINT(" speed: %d\n", hc->speed);
3528 DWC_PRINT(" ep_type: %d\n", hc->ep_type);
3529 DWC_PRINT(" max_packet: %d\n", hc->max_packet);
3530 DWC_PRINT(" data_pid_start: %d\n", hc->data_pid_start);
3531 DWC_PRINT(" multi_count: %d\n", hc->multi_count);
3532 DWC_PRINT(" xfer_started: %d\n", hc->xfer_started);
3533 DWC_PRINT(" xfer_buff: %p\n", hc->xfer_buff);
3534 DWC_PRINT(" xfer_len: %d\n", hc->xfer_len);
3535 DWC_PRINT(" xfer_count: %d\n", hc->xfer_count);
3536 DWC_PRINT(" halt_on_queue: %d\n", hc->halt_on_queue);
3537 DWC_PRINT(" halt_pending: %d\n", hc->halt_pending);
3538 DWC_PRINT(" halt_status: %d\n", hc->halt_status);
3539 DWC_PRINT(" do_split: %d\n", hc->do_split);
3540 DWC_PRINT(" complete_split: %d\n", hc->complete_split);
3541 DWC_PRINT(" hub_addr: %d\n", hc->hub_addr);
3542 DWC_PRINT(" port_addr: %d\n", hc->port_addr);
3543 DWC_PRINT(" xact_pos: %d\n", hc->xact_pos);
3544 DWC_PRINT(" requests: %d\n", hc->requests);
3545 DWC_PRINT(" qh: %p\n", hc->qh);
3546 if (hc->xfer_started) {
3548 hcchar_data_t hcchar;
3549 hctsiz_data_t hctsiz;
3551 hcintmsk_data_t hcintmsk;
3552 hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum);
3553 hcchar.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcchar);
3554 hctsiz.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hctsiz);
3555 hcint.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcint);
3556 hcintmsk.d32 = dwc_read_reg32(&_hcd->core_if->host_if->hc_regs[i]->hcintmsk);
3557 DWC_PRINT(" hfnum: 0x%08x\n", hfnum.d32);
3558 DWC_PRINT(" hcchar: 0x%08x\n", hcchar.d32);
3559 DWC_PRINT(" hctsiz: 0x%08x\n", hctsiz.d32);
3560 DWC_PRINT(" hcint: 0x%08x\n", hcint.d32);
3561 DWC_PRINT(" hcintmsk: 0x%08x\n", hcintmsk.d32);
3563 if (hc->xfer_started && (hc->qh != NULL) && (hc->qh->qtd_in_process != NULL)) {
3566 qtd = hc->qh->qtd_in_process;
3568 DWC_PRINT(" URB Info:\n");
3569 DWC_PRINT(" qtd: %p, urb: %p\n", qtd, urb);
3571 DWC_PRINT(" Dev: %d, EP: %d %s\n",
3572 usb_pipedevice(urb->pipe), usb_pipeendpoint(urb->pipe),
3573 usb_pipein(urb->pipe) ? "IN" : "OUT");
3574 DWC_PRINT(" Max packet size: %d\n",
3575 usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
3576 DWC_PRINT(" transfer_buffer: %p\n", urb->transfer_buffer);
3577 DWC_PRINT(" transfer_dma: %p\n", (void *)urb->transfer_dma);
3578 DWC_PRINT(" transfer_buffer_length: %d\n", urb->transfer_buffer_length);
3579 DWC_PRINT(" actual_length: %d\n", urb->actual_length);
3583 DWC_PRINT(" non_periodic_channels: %d\n", _hcd->non_periodic_channels);
3584 DWC_PRINT(" periodic_channels: %d\n", _hcd->periodic_channels);
3585 DWC_PRINT(" periodic_usecs: %d\n", _hcd->periodic_usecs);
3586 np_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->core_global_regs->gnptxsts);
3587 DWC_PRINT(" NP Tx Req Queue Space Avail: %d\n", np_tx_status.b.nptxqspcavail);
3588 DWC_PRINT(" NP Tx FIFO Space Avail: %d\n", np_tx_status.b.nptxfspcavail);
3589 p_tx_status.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hptxsts);
3590 DWC_PRINT(" P Tx Req Queue Space Avail: %d\n", p_tx_status.b.ptxqspcavail);
3591 DWC_PRINT(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
3592 dwc_otg_hcd_dump_frrem(_hcd);
3593 dwc_otg_dump_global_registers(_hcd->core_if);
3594 dwc_otg_dump_host_registers(_hcd->core_if);
3595 DWC_PRINT("************************************************************\n");
3599 #endif /* DWC_DEVICE_ONLY */