Lines Matching +full:overcurrent +full:- +full:retry

1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * hcd.c - DesignWare HS OTG Controller host-mode routines
5 * Copyright (C) 2004-2013 Synopsys, Inc.
17 #include <linux/dma-mapping.h>
37 * dwc2_enable_common_interrupts() - Initializes the commmon interrupts,
55 if (!hsotg->params.host_dma) in dwc2_enable_common_interrupts()
57 if (!hsotg->params.external_id_pin_ctl) in dwc2_enable_common_interrupts()
63 if (dwc2_is_device_mode(hsotg) && hsotg->params.lpm) in dwc2_enable_common_interrupts()
73 switch (hsotg->hw_params.arch) { in dwc2_gahbcfg_init()
75 dev_err(hsotg->dev, "External DMA Mode not supported\n"); in dwc2_gahbcfg_init()
76 return -EINVAL; in dwc2_gahbcfg_init()
79 dev_dbg(hsotg->dev, "Internal DMA Mode\n"); in dwc2_gahbcfg_init()
80 if (hsotg->params.ahbcfg != -1) { in dwc2_gahbcfg_init()
82 ahbcfg |= hsotg->params.ahbcfg & in dwc2_gahbcfg_init()
89 dev_dbg(hsotg->dev, "Slave Only Mode\n"); in dwc2_gahbcfg_init()
93 if (hsotg->params.host_dma) in dwc2_gahbcfg_init()
96 hsotg->params.dma_desc_enable = false; in dwc2_gahbcfg_init()
110 switch (hsotg->hw_params.op_mode) { in dwc2_gusbcfg_init()
112 if (hsotg->params.otg_caps.hnp_support && in dwc2_gusbcfg_init()
113 hsotg->params.otg_caps.srp_support) in dwc2_gusbcfg_init()
120 if (hsotg->params.otg_caps.srp_support) in dwc2_gusbcfg_init()
136 if (hsotg->vbus_supply) in dwc2_vbus_supply_init()
137 return regulator_enable(hsotg->vbus_supply); in dwc2_vbus_supply_init()
144 if (hsotg->vbus_supply) in dwc2_vbus_supply_exit()
145 return regulator_disable(hsotg->vbus_supply); in dwc2_vbus_supply_exit()
151 * dwc2_enable_host_interrupts() - Enables the Host mode interrupts
159 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_enable_host_interrupts()
175 * dwc2_disable_host_interrupts() - Disables the Host Mode interrupts
190 * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size
198 struct dwc2_core_params *params = &hsotg->params; in dwc2_calculate_dynamic_fifo()
199 struct dwc2_hw_params *hw = &hsotg->hw_params; in dwc2_calculate_dynamic_fifo()
202 total_fifo_size = hw->total_fifo_size; in dwc2_calculate_dynamic_fifo()
203 rxfsiz = params->host_rx_fifo_size; in dwc2_calculate_dynamic_fifo()
204 nptxfsiz = params->host_nperio_tx_fifo_size; in dwc2_calculate_dynamic_fifo()
205 ptxfsiz = params->host_perio_tx_fifo_size; in dwc2_calculate_dynamic_fifo()
211 * non-periodic as 512. in dwc2_calculate_dynamic_fifo()
220 rxfsiz = 516 + hw->host_channels; in dwc2_calculate_dynamic_fifo()
223 * min non-periodic tx fifo depth in dwc2_calculate_dynamic_fifo()
224 * 2 * (largest non-periodic USB packet used / 4) in dwc2_calculate_dynamic_fifo()
236 params->host_rx_fifo_size = rxfsiz; in dwc2_calculate_dynamic_fifo()
237 params->host_nperio_tx_fifo_size = nptxfsiz; in dwc2_calculate_dynamic_fifo()
238 params->host_perio_tx_fifo_size = ptxfsiz; in dwc2_calculate_dynamic_fifo()
252 dev_err(hsotg->dev, "invalid fifo sizes\n"); in dwc2_calculate_dynamic_fifo()
257 struct dwc2_core_params *params = &hsotg->params; in dwc2_config_fifos()
260 if (!params->enable_dynamic_fifo) in dwc2_config_fifos()
267 dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); in dwc2_config_fifos()
269 grxfsiz |= params->host_rx_fifo_size << in dwc2_config_fifos()
272 dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", in dwc2_config_fifos()
275 /* Non-periodic Tx FIFO */ in dwc2_config_fifos()
276 dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n", in dwc2_config_fifos()
278 nptxfsiz = params->host_nperio_tx_fifo_size << in dwc2_config_fifos()
280 nptxfsiz |= params->host_rx_fifo_size << in dwc2_config_fifos()
283 dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n", in dwc2_config_fifos()
287 dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n", in dwc2_config_fifos()
289 hptxfsiz = params->host_perio_tx_fifo_size << in dwc2_config_fifos()
291 hptxfsiz |= (params->host_rx_fifo_size + in dwc2_config_fifos()
292 params->host_nperio_tx_fifo_size) << in dwc2_config_fifos()
295 dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n", in dwc2_config_fifos()
298 if (hsotg->params.en_multiple_tx_fifo && in dwc2_config_fifos()
299 hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_91a) { in dwc2_config_fifos()
302 * Global DFIFOCFG calculation for Host mode - in dwc2_config_fifos()
307 dfifocfg |= (params->host_rx_fifo_size + in dwc2_config_fifos()
308 params->host_nperio_tx_fifo_size + in dwc2_config_fifos()
309 params->host_perio_tx_fifo_size) << in dwc2_config_fifos()
317 * dwc2_calc_frame_interval() - Calculates the correct frame Interval value for
338 if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type == in dwc2_calc_frame_interval()
351 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI) in dwc2_calc_frame_interval()
354 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) in dwc2_calc_frame_interval()
359 return 125 * clock - 1; in dwc2_calc_frame_interval()
362 return 1000 * clock - 1; in dwc2_calc_frame_interval()
366 * dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination
385 dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes); in dwc2_read_packet()
392 * dwc2_dump_channel_info() - Prints the state of a host channel
406 int num_channels = hsotg->params.host_channels; in dwc2_dump_channel_info()
417 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_dump_channel_info()
418 hcsplt = dwc2_readl(hsotg, HCSPLT(chan->hc_num)); in dwc2_dump_channel_info()
419 hctsiz = dwc2_readl(hsotg, HCTSIZ(chan->hc_num)); in dwc2_dump_channel_info()
420 hc_dma = dwc2_readl(hsotg, HCDMA(chan->hc_num)); in dwc2_dump_channel_info()
422 dev_dbg(hsotg->dev, " Assigned to channel %p:\n", chan); in dwc2_dump_channel_info()
423 dev_dbg(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", in dwc2_dump_channel_info()
425 dev_dbg(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", in dwc2_dump_channel_info()
427 dev_dbg(hsotg->dev, " dev_addr: %d, ep_num: %d, ep_is_in: %d\n", in dwc2_dump_channel_info()
428 chan->dev_addr, chan->ep_num, chan->ep_is_in); in dwc2_dump_channel_info()
429 dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); in dwc2_dump_channel_info()
430 dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); in dwc2_dump_channel_info()
431 dev_dbg(hsotg->dev, " data_pid_start: %d\n", chan->data_pid_start); in dwc2_dump_channel_info()
432 dev_dbg(hsotg->dev, " xfer_started: %d\n", chan->xfer_started); in dwc2_dump_channel_info()
433 dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); in dwc2_dump_channel_info()
434 dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); in dwc2_dump_channel_info()
435 dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", in dwc2_dump_channel_info()
436 (unsigned long)chan->xfer_dma); in dwc2_dump_channel_info()
437 dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); in dwc2_dump_channel_info()
438 dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); in dwc2_dump_channel_info()
439 dev_dbg(hsotg->dev, " NP inactive sched:\n"); in dwc2_dump_channel_info()
440 list_for_each_entry(qh, &hsotg->non_periodic_sched_inactive, in dwc2_dump_channel_info()
442 dev_dbg(hsotg->dev, " %p\n", qh); in dwc2_dump_channel_info()
443 dev_dbg(hsotg->dev, " NP waiting sched:\n"); in dwc2_dump_channel_info()
444 list_for_each_entry(qh, &hsotg->non_periodic_sched_waiting, in dwc2_dump_channel_info()
446 dev_dbg(hsotg->dev, " %p\n", qh); in dwc2_dump_channel_info()
447 dev_dbg(hsotg->dev, " NP active sched:\n"); in dwc2_dump_channel_info()
448 list_for_each_entry(qh, &hsotg->non_periodic_sched_active, in dwc2_dump_channel_info()
450 dev_dbg(hsotg->dev, " %p\n", qh); in dwc2_dump_channel_info()
451 dev_dbg(hsotg->dev, " Channels:\n"); in dwc2_dump_channel_info()
453 struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; in dwc2_dump_channel_info()
455 dev_dbg(hsotg->dev, " %2d: %p\n", i, chan); in dwc2_dump_channel_info()
466 hcd->self.is_b_host = dwc2_hcd_is_b_host(hsotg); in dwc2_host_start()
474 hcd->self.is_b_host = 0; in dwc2_host_disconnect()
482 if (urb->dev->tt) in dwc2_host_hub_info()
483 *hub_addr = urb->dev->tt->hub->devnum; in dwc2_host_hub_info()
486 *hub_port = urb->dev->ttport; in dwc2_host_hub_info()
500 switch (chan->ep_type) { in dwc2_hc_enable_slave_ints()
503 dev_vdbg(hsotg->dev, "control/bulk\n"); in dwc2_hc_enable_slave_ints()
508 if (chan->ep_is_in) { in dwc2_hc_enable_slave_ints()
513 if (chan->do_ping) in dwc2_hc_enable_slave_ints()
517 if (chan->do_split) { in dwc2_hc_enable_slave_ints()
519 if (chan->complete_split) in dwc2_hc_enable_slave_ints()
525 if (chan->error_state) in dwc2_hc_enable_slave_ints()
531 dev_vdbg(hsotg->dev, "intr\n"); in dwc2_hc_enable_slave_ints()
539 if (chan->ep_is_in) in dwc2_hc_enable_slave_ints()
541 if (chan->error_state) in dwc2_hc_enable_slave_ints()
543 if (chan->do_split) { in dwc2_hc_enable_slave_ints()
544 if (chan->complete_split) in dwc2_hc_enable_slave_ints()
553 dev_vdbg(hsotg->dev, "isoc\n"); in dwc2_hc_enable_slave_ints()
558 if (chan->ep_is_in) { in dwc2_hc_enable_slave_ints()
564 dev_err(hsotg->dev, "## Unknown EP type ##\n"); in dwc2_hc_enable_slave_ints()
568 dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); in dwc2_hc_enable_slave_ints()
570 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); in dwc2_hc_enable_slave_ints()
582 if (!hsotg->params.dma_desc_enable) { in dwc2_hc_enable_dma_ints()
584 dev_vdbg(hsotg->dev, "desc DMA disabled\n"); in dwc2_hc_enable_dma_ints()
588 dev_vdbg(hsotg->dev, "desc DMA enabled\n"); in dwc2_hc_enable_dma_ints()
589 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_hc_enable_dma_ints()
593 if (chan->error_state && !chan->do_split && in dwc2_hc_enable_dma_ints()
594 chan->ep_type != USB_ENDPOINT_XFER_ISOC) { in dwc2_hc_enable_dma_ints()
596 dev_vdbg(hsotg->dev, "setting ACK\n"); in dwc2_hc_enable_dma_ints()
598 if (chan->ep_is_in) { in dwc2_hc_enable_dma_ints()
600 if (chan->ep_type != USB_ENDPOINT_XFER_INT) in dwc2_hc_enable_dma_ints()
605 dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); in dwc2_hc_enable_dma_ints()
607 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); in dwc2_hc_enable_dma_ints()
615 if (hsotg->params.host_dma) { in dwc2_hc_enable_ints()
617 dev_vdbg(hsotg->dev, "DMA enabled\n"); in dwc2_hc_enable_ints()
621 dev_vdbg(hsotg->dev, "DMA disabled\n"); in dwc2_hc_enable_ints()
627 intmsk |= 1 << chan->hc_num; in dwc2_hc_enable_ints()
630 dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk); in dwc2_hc_enable_ints()
637 dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk); in dwc2_hc_enable_ints()
641 * dwc2_hc_init() - Prepares a host channel for transferring packets to/from
653 u8 hc_num = chan->hc_num; in dwc2_hc_init()
659 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_init()
673 hcchar = chan->dev_addr << HCCHAR_DEVADDR_SHIFT & HCCHAR_DEVADDR_MASK; in dwc2_hc_init()
674 hcchar |= chan->ep_num << HCCHAR_EPNUM_SHIFT & HCCHAR_EPNUM_MASK; in dwc2_hc_init()
675 if (chan->ep_is_in) in dwc2_hc_init()
677 if (chan->speed == USB_SPEED_LOW) in dwc2_hc_init()
679 hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK; in dwc2_hc_init()
680 hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK; in dwc2_hc_init()
683 dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n", in dwc2_hc_init()
686 dev_vdbg(hsotg->dev, "%s: Channel %d\n", in dwc2_hc_init()
688 dev_vdbg(hsotg->dev, " Dev Addr: %d\n", in dwc2_hc_init()
689 chan->dev_addr); in dwc2_hc_init()
690 dev_vdbg(hsotg->dev, " Ep Num: %d\n", in dwc2_hc_init()
691 chan->ep_num); in dwc2_hc_init()
692 dev_vdbg(hsotg->dev, " Is In: %d\n", in dwc2_hc_init()
693 chan->ep_is_in); in dwc2_hc_init()
694 dev_vdbg(hsotg->dev, " Is Low Speed: %d\n", in dwc2_hc_init()
695 chan->speed == USB_SPEED_LOW); in dwc2_hc_init()
696 dev_vdbg(hsotg->dev, " Ep Type: %d\n", in dwc2_hc_init()
697 chan->ep_type); in dwc2_hc_init()
698 dev_vdbg(hsotg->dev, " Max Pkt: %d\n", in dwc2_hc_init()
699 chan->max_packet); in dwc2_hc_init()
703 if (chan->do_split) { in dwc2_hc_init()
705 dev_vdbg(hsotg->dev, in dwc2_hc_init()
706 "Programming HC %d with split --> %s\n", in dwc2_hc_init()
708 chan->complete_split ? "CSPLIT" : "SSPLIT"); in dwc2_hc_init()
709 if (chan->complete_split) in dwc2_hc_init()
711 hcsplt |= chan->xact_pos << HCSPLT_XACTPOS_SHIFT & in dwc2_hc_init()
713 hcsplt |= chan->hub_addr << HCSPLT_HUBADDR_SHIFT & in dwc2_hc_init()
715 hcsplt |= chan->hub_port << HCSPLT_PRTADDR_SHIFT & in dwc2_hc_init()
718 dev_vdbg(hsotg->dev, " comp split %d\n", in dwc2_hc_init()
719 chan->complete_split); in dwc2_hc_init()
720 dev_vdbg(hsotg->dev, " xact pos %d\n", in dwc2_hc_init()
721 chan->xact_pos); in dwc2_hc_init()
722 dev_vdbg(hsotg->dev, " hub addr %d\n", in dwc2_hc_init()
723 chan->hub_addr); in dwc2_hc_init()
724 dev_vdbg(hsotg->dev, " hub port %d\n", in dwc2_hc_init()
725 chan->hub_port); in dwc2_hc_init()
726 dev_vdbg(hsotg->dev, " is_in %d\n", in dwc2_hc_init()
727 chan->ep_is_in); in dwc2_hc_init()
728 dev_vdbg(hsotg->dev, " Max Pkt %d\n", in dwc2_hc_init()
729 chan->max_packet); in dwc2_hc_init()
730 dev_vdbg(hsotg->dev, " xferlen %d\n", in dwc2_hc_init()
731 chan->xfer_len); in dwc2_hc_init()
739 * dwc2_hc_halt() - Attempts to halt a host channel
772 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_halt()
776 * for non-split periodic channels. At the end of the next in dwc2_hc_halt()
780 if ((hsotg->params.g_dma && !hsotg->params.g_dma_desc) || in dwc2_hc_halt()
781 hsotg->hw_params.arch == GHWCFG2_EXT_DMA_ARCH) { in dwc2_hc_halt()
782 if (!chan->do_split && in dwc2_hc_halt()
783 (chan->ep_type == USB_ENDPOINT_XFER_ISOC || in dwc2_hc_halt()
784 chan->ep_type == USB_ENDPOINT_XFER_INT)) { in dwc2_hc_halt()
785 dev_err(hsotg->dev, "%s() Channel can't be halted\n", in dwc2_hc_halt()
792 dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status); in dwc2_hc_halt()
804 dev_vdbg(hsotg->dev, "dequeue/error\n"); in dwc2_hc_halt()
805 dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); in dwc2_hc_halt()
812 dwc2_writel(hsotg, ~hcintmsk, HCINT(chan->hc_num)); in dwc2_hc_halt()
819 chan->halt_status = halt_status; in dwc2_hc_halt()
821 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
837 if (chan->halt_pending) { in dwc2_hc_halt()
843 dev_vdbg(hsotg->dev, in dwc2_hc_halt()
844 "*** %s: Channel %d, chan->halt_pending already set ***\n", in dwc2_hc_halt()
845 __func__, chan->hc_num); in dwc2_hc_halt()
849 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
853 if (!hsotg->params.dma_desc_enable) { in dwc2_hc_halt()
855 dev_vdbg(hsotg->dev, "desc DMA disabled\n"); in dwc2_hc_halt()
859 dev_dbg(hsotg->dev, "desc DMA enabled\n"); in dwc2_hc_halt()
863 if (!hsotg->params.host_dma) { in dwc2_hc_halt()
865 dev_vdbg(hsotg->dev, "DMA not enabled\n"); in dwc2_hc_halt()
869 if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || in dwc2_hc_halt()
870 chan->ep_type == USB_ENDPOINT_XFER_BULK) { in dwc2_hc_halt()
871 dev_vdbg(hsotg->dev, "control/bulk\n"); in dwc2_hc_halt()
874 dev_vdbg(hsotg->dev, "Disabling channel\n"); in dwc2_hc_halt()
879 dev_vdbg(hsotg->dev, "isoc/intr\n"); in dwc2_hc_halt()
882 hsotg->queuing_high_bandwidth) { in dwc2_hc_halt()
884 dev_vdbg(hsotg->dev, "Disabling channel\n"); in dwc2_hc_halt()
890 dev_vdbg(hsotg->dev, "DMA enabled\n"); in dwc2_hc_halt()
893 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
894 chan->halt_status = halt_status; in dwc2_hc_halt()
898 dev_vdbg(hsotg->dev, "Channel enabled\n"); in dwc2_hc_halt()
899 chan->halt_pending = 1; in dwc2_hc_halt()
900 chan->halt_on_queue = 0; in dwc2_hc_halt()
903 dev_vdbg(hsotg->dev, "Channel disabled\n"); in dwc2_hc_halt()
904 chan->halt_on_queue = 1; in dwc2_hc_halt()
908 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_halt()
909 chan->hc_num); in dwc2_hc_halt()
910 dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n", in dwc2_hc_halt()
912 dev_vdbg(hsotg->dev, " halt_pending: %d\n", in dwc2_hc_halt()
913 chan->halt_pending); in dwc2_hc_halt()
914 dev_vdbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hc_halt()
915 chan->halt_on_queue); in dwc2_hc_halt()
916 dev_vdbg(hsotg->dev, " halt_status: %d\n", in dwc2_hc_halt()
917 chan->halt_status); in dwc2_hc_halt()
922 * dwc2_hc_cleanup() - Clears the transfer state for a host channel
934 chan->xfer_started = 0; in dwc2_hc_cleanup()
936 list_del_init(&chan->split_order_list_entry); in dwc2_hc_cleanup()
942 dwc2_writel(hsotg, 0, HCINTMSK(chan->hc_num)); in dwc2_hc_cleanup()
945 dwc2_writel(hsotg, hcintmsk, HCINT(chan->hc_num)); in dwc2_hc_cleanup()
949 * dwc2_hc_set_even_odd_frame() - Sets the channel property that indicates in
956 * This function has no effect on non-periodic transfers
961 if (chan->ep_type == USB_ENDPOINT_XFER_INT || in dwc2_hc_set_even_odd_frame()
962 chan->ep_type == USB_ENDPOINT_XFER_ISOC) { in dwc2_hc_set_even_odd_frame()
995 host_speed = (chan->speed != USB_SPEED_HIGH && in dwc2_hc_set_even_odd_frame()
996 !chan->do_split) ? chan->speed : USB_SPEED_HIGH; in dwc2_hc_set_even_odd_frame()
1002 (hsotg->params.host_perio_tx_fifo_size - in dwc2_hc_set_even_odd_frame()
1010 * transfers. This should be an over-estimate and that should in dwc2_hc_set_even_odd_frame()
1014 chan->xfer_len + bytes_in_fifo); in dwc2_hc_set_even_odd_frame()
1021 wire_frame = dwc2_frame_num_inc(chan->qh->next_active_frame, 1); in dwc2_hc_set_even_odd_frame()
1033 chan->qh, wire_frame, frame_number, in dwc2_hc_set_even_odd_frame()
1046 chan->qh->next_active_frame = in dwc2_hc_set_even_odd_frame()
1060 if (chan->speed == USB_SPEED_HIGH) { in dwc2_set_pid_isoc()
1061 if (chan->ep_is_in) { in dwc2_set_pid_isoc()
1062 if (chan->multi_count == 1) in dwc2_set_pid_isoc()
1063 chan->data_pid_start = DWC2_HC_PID_DATA0; in dwc2_set_pid_isoc()
1064 else if (chan->multi_count == 2) in dwc2_set_pid_isoc()
1065 chan->data_pid_start = DWC2_HC_PID_DATA1; in dwc2_set_pid_isoc()
1067 chan->data_pid_start = DWC2_HC_PID_DATA2; in dwc2_set_pid_isoc()
1069 if (chan->multi_count == 1) in dwc2_set_pid_isoc()
1070 chan->data_pid_start = DWC2_HC_PID_DATA0; in dwc2_set_pid_isoc()
1072 chan->data_pid_start = DWC2_HC_PID_MDATA; in dwc2_set_pid_isoc()
1075 chan->data_pid_start = DWC2_HC_PID_DATA0; in dwc2_set_pid_isoc()
1080 * dwc2_hc_write_packet() - Writes a packet into the Tx FIFO associated with
1087 * with a non-periodic EP, the non-periodic Tx FIFO is written. For a channel
1100 u32 *data_buf = (u32 *)chan->xfer_buf; in dwc2_hc_write_packet()
1103 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_write_packet()
1105 remaining_count = chan->xfer_len - chan->xfer_count; in dwc2_hc_write_packet()
1106 if (remaining_count > chan->max_packet) in dwc2_hc_write_packet()
1107 byte_count = chan->max_packet; in dwc2_hc_write_packet()
1116 dwc2_writel(hsotg, *data_buf, HCFIFO(chan->hc_num)); in dwc2_hc_write_packet()
1122 dwc2_writel(hsotg, data, HCFIFO(chan->hc_num)); in dwc2_hc_write_packet()
1126 chan->xfer_count += byte_count; in dwc2_hc_write_packet()
1127 chan->xfer_buf += byte_count; in dwc2_hc_write_packet()
1131 * dwc2_hc_do_ping() - Starts a PING transfer
1146 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_do_ping()
1147 chan->hc_num); in dwc2_hc_do_ping()
1151 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_do_ping()
1153 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_do_ping()
1156 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_do_ping()
1160 * dwc2_hc_start_transfer() - Does the setup for a data transfer for a host
1195 u32 max_hc_xfer_size = hsotg->params.max_transfer_size; in dwc2_hc_start_transfer()
1196 u16 max_hc_pkt_count = hsotg->params.max_packet_count; in dwc2_hc_start_transfer()
1203 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_start_transfer()
1205 if (chan->do_ping) { in dwc2_hc_start_transfer()
1206 if (!hsotg->params.host_dma) { in dwc2_hc_start_transfer()
1208 dev_vdbg(hsotg->dev, "ping, no DMA\n"); in dwc2_hc_start_transfer()
1210 chan->xfer_started = 1; in dwc2_hc_start_transfer()
1215 dev_vdbg(hsotg->dev, "ping, DMA\n"); in dwc2_hc_start_transfer()
1220 if (chan->do_split) { in dwc2_hc_start_transfer()
1222 dev_vdbg(hsotg->dev, "split\n"); in dwc2_hc_start_transfer()
1225 if (chan->complete_split && !chan->ep_is_in) in dwc2_hc_start_transfer()
1230 chan->xfer_len = 0; in dwc2_hc_start_transfer()
1231 else if (chan->ep_is_in || chan->xfer_len > chan->max_packet) in dwc2_hc_start_transfer()
1232 chan->xfer_len = chan->max_packet; in dwc2_hc_start_transfer()
1233 else if (!chan->ep_is_in && chan->xfer_len > 188) in dwc2_hc_start_transfer()
1234 chan->xfer_len = 188; in dwc2_hc_start_transfer()
1236 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & in dwc2_hc_start_transfer()
1240 if (chan->ep_type == USB_ENDPOINT_XFER_INT || in dwc2_hc_start_transfer()
1241 chan->ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_hc_start_transfer()
1247 dev_vdbg(hsotg->dev, "no split\n"); in dwc2_hc_start_transfer()
1252 if (chan->ep_type == USB_ENDPOINT_XFER_INT || in dwc2_hc_start_transfer()
1253 chan->ep_type == USB_ENDPOINT_XFER_ISOC) { in dwc2_hc_start_transfer()
1262 chan->multi_count * chan->max_packet; in dwc2_hc_start_transfer()
1264 if (chan->xfer_len > max_periodic_len) in dwc2_hc_start_transfer()
1265 chan->xfer_len = max_periodic_len; in dwc2_hc_start_transfer()
1266 } else if (chan->xfer_len > max_hc_xfer_size) { in dwc2_hc_start_transfer()
1271 chan->xfer_len = in dwc2_hc_start_transfer()
1272 max_hc_xfer_size - chan->max_packet + 1; in dwc2_hc_start_transfer()
1275 if (chan->xfer_len > 0) { in dwc2_hc_start_transfer()
1276 num_packets = (chan->xfer_len + chan->max_packet - 1) / in dwc2_hc_start_transfer()
1277 chan->max_packet; in dwc2_hc_start_transfer()
1280 chan->xfer_len = num_packets * chan->max_packet; in dwc2_hc_start_transfer()
1281 } else if (chan->ep_is_in) { in dwc2_hc_start_transfer()
1288 chan->xfer_len = num_packets * chan->max_packet; in dwc2_hc_start_transfer()
1295 if (chan->ep_type == USB_ENDPOINT_XFER_INT || in dwc2_hc_start_transfer()
1296 chan->ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_hc_start_transfer()
1301 chan->multi_count = num_packets; in dwc2_hc_start_transfer()
1303 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_hc_start_transfer()
1306 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & in dwc2_hc_start_transfer()
1309 /* The ec_mc gets the multi_count for non-split */ in dwc2_hc_start_transfer()
1310 ec_mc = chan->multi_count; in dwc2_hc_start_transfer()
1313 chan->start_pkt_count = num_packets; in dwc2_hc_start_transfer()
1315 hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & in dwc2_hc_start_transfer()
1317 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_start_transfer()
1319 dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n", in dwc2_hc_start_transfer()
1320 hctsiz, chan->hc_num); in dwc2_hc_start_transfer()
1322 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_start_transfer()
1323 chan->hc_num); in dwc2_hc_start_transfer()
1324 dev_vdbg(hsotg->dev, " Xfer Size: %d\n", in dwc2_hc_start_transfer()
1327 dev_vdbg(hsotg->dev, " Num Pkts: %d\n", in dwc2_hc_start_transfer()
1330 dev_vdbg(hsotg->dev, " Start PID: %d\n", in dwc2_hc_start_transfer()
1335 if (hsotg->params.host_dma) { in dwc2_hc_start_transfer()
1338 if (chan->align_buf) { in dwc2_hc_start_transfer()
1340 dev_vdbg(hsotg->dev, "align_buf\n"); in dwc2_hc_start_transfer()
1341 dma_addr = chan->align_buf; in dwc2_hc_start_transfer()
1343 dma_addr = chan->xfer_dma; in dwc2_hc_start_transfer()
1345 dwc2_writel(hsotg, (u32)dma_addr, HCDMA(chan->hc_num)); in dwc2_hc_start_transfer()
1348 dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n", in dwc2_hc_start_transfer()
1349 (unsigned long)dma_addr, chan->hc_num); in dwc2_hc_start_transfer()
1353 if (chan->do_split) { in dwc2_hc_start_transfer()
1354 u32 hcsplt = dwc2_readl(hsotg, HCSPLT(chan->hc_num)); in dwc2_hc_start_transfer()
1357 dwc2_writel(hsotg, hcsplt, HCSPLT(chan->hc_num)); in dwc2_hc_start_transfer()
1360 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer()
1366 dev_warn(hsotg->dev, in dwc2_hc_start_transfer()
1368 __func__, chan->hc_num, hcchar); in dwc2_hc_start_transfer()
1375 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", in dwc2_hc_start_transfer()
1379 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer()
1381 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, in dwc2_hc_start_transfer()
1382 chan->hc_num); in dwc2_hc_start_transfer()
1384 chan->xfer_started = 1; in dwc2_hc_start_transfer()
1385 chan->requests++; in dwc2_hc_start_transfer()
1387 if (!hsotg->params.host_dma && in dwc2_hc_start_transfer()
1388 !chan->ep_is_in && chan->xfer_len > 0) in dwc2_hc_start_transfer()
1394 * dwc2_hc_start_transfer_ddma() - Does the setup for a data transfer for a
1402 * with micro-frame bitmap.
1413 if (chan->do_ping) in dwc2_hc_start_transfer_ddma()
1416 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_hc_start_transfer_ddma()
1420 hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & in dwc2_hc_start_transfer_ddma()
1423 /* 0 - 1 descriptor, 1 - 2 descriptors, etc */ in dwc2_hc_start_transfer_ddma()
1424 hctsiz |= (chan->ntd - 1) << TSIZ_NTD_SHIFT & TSIZ_NTD_MASK; in dwc2_hc_start_transfer_ddma()
1426 /* Non-zero only for high-speed interrupt endpoints */ in dwc2_hc_start_transfer_ddma()
1427 hctsiz |= chan->schinfo << TSIZ_SCHINFO_SHIFT & TSIZ_SCHINFO_MASK; in dwc2_hc_start_transfer_ddma()
1430 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_start_transfer_ddma()
1431 chan->hc_num); in dwc2_hc_start_transfer_ddma()
1432 dev_vdbg(hsotg->dev, " Start PID: %d\n", in dwc2_hc_start_transfer_ddma()
1433 chan->data_pid_start); in dwc2_hc_start_transfer_ddma()
1434 dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1); in dwc2_hc_start_transfer_ddma()
1437 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1439 dma_sync_single_for_device(hsotg->dev, chan->desc_list_addr, in dwc2_hc_start_transfer_ddma()
1440 chan->desc_list_sz, DMA_TO_DEVICE); in dwc2_hc_start_transfer_ddma()
1442 dwc2_writel(hsotg, chan->desc_list_addr, HCDMA(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1445 dev_vdbg(hsotg->dev, "Wrote %pad to HCDMA(%d)\n", in dwc2_hc_start_transfer_ddma()
1446 &chan->desc_list_addr, chan->hc_num); in dwc2_hc_start_transfer_ddma()
1448 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1450 hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & in dwc2_hc_start_transfer_ddma()
1454 dev_warn(hsotg->dev, in dwc2_hc_start_transfer_ddma()
1456 __func__, chan->hc_num, hcchar); in dwc2_hc_start_transfer_ddma()
1463 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", in dwc2_hc_start_transfer_ddma()
1467 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1469 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, in dwc2_hc_start_transfer_ddma()
1470 chan->hc_num); in dwc2_hc_start_transfer_ddma()
1472 chan->xfer_started = 1; in dwc2_hc_start_transfer_ddma()
1473 chan->requests++; in dwc2_hc_start_transfer_ddma()
1477 * dwc2_hc_continue_transfer() - Continues a data transfer that was started by
1500 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_continue_transfer()
1501 chan->hc_num); in dwc2_hc_continue_transfer()
1503 if (chan->do_split) in dwc2_hc_continue_transfer()
1507 if (chan->data_pid_start == DWC2_HC_PID_SETUP) in dwc2_hc_continue_transfer()
1511 if (chan->ep_is_in) { in dwc2_hc_continue_transfer()
1514 * back-to-back INs are issued and NAKs are received for both, in dwc2_hc_continue_transfer()
1524 u32 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1530 dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n", in dwc2_hc_continue_transfer()
1532 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1533 chan->requests++; in dwc2_hc_continue_transfer()
1539 if (chan->xfer_count < chan->xfer_len) { in dwc2_hc_continue_transfer()
1540 if (chan->ep_type == USB_ENDPOINT_XFER_INT || in dwc2_hc_continue_transfer()
1541 chan->ep_type == USB_ENDPOINT_XFER_ISOC) { in dwc2_hc_continue_transfer()
1543 HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1551 chan->requests++; in dwc2_hc_continue_transfer()
1566 * -ETIMEDOUT and frees the QTD.
1577 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, in dwc2_kill_urbs_in_qh_list()
1579 dwc2_host_complete(hsotg, qtd, -ECONNRESET); in dwc2_kill_urbs_in_qh_list()
1592 if (!qh_list->next) in dwc2_qh_list_free()
1596 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_qh_list_free()
1605 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, in dwc2_qh_list_free()
1609 if (qh->channel && qh->channel->qh == qh) in dwc2_qh_list_free()
1610 qh->channel->qh = NULL; in dwc2_qh_list_free()
1612 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_qh_list_free()
1614 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_qh_list_free()
1617 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_qh_list_free()
1621 * Responds with an error status of -ETIMEDOUT to all URBs in the non-periodic
1630 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_inactive); in dwc2_kill_all_urbs()
1631 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_waiting); in dwc2_kill_all_urbs()
1632 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_active); in dwc2_kill_all_urbs()
1633 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_inactive); in dwc2_kill_all_urbs()
1634 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_ready); in dwc2_kill_all_urbs()
1635 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_assigned); in dwc2_kill_all_urbs()
1636 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_queued); in dwc2_kill_all_urbs()
1640 * dwc2_hcd_start() - Starts the HCD when switching to Host mode
1648 if (hsotg->op_state == OTG_STATE_B_HOST) { in dwc2_hcd_start()
1659 queue_delayed_work(hsotg->wq_otg, &hsotg->start_work, in dwc2_hcd_start()
1666 int num_channels = hsotg->params.host_channels; in dwc2_hcd_cleanup_channels()
1671 if (!hsotg->params.host_dma) { in dwc2_hcd_cleanup_channels()
1674 channel = hsotg->hc_ptr_array[i]; in dwc2_hcd_cleanup_channels()
1675 if (!list_empty(&channel->hc_list_entry)) in dwc2_hcd_cleanup_channels()
1687 channel = hsotg->hc_ptr_array[i]; in dwc2_hcd_cleanup_channels()
1688 if (!list_empty(&channel->hc_list_entry)) in dwc2_hcd_cleanup_channels()
1698 list_add_tail(&channel->hc_list_entry, &hsotg->free_hc_list); in dwc2_hcd_cleanup_channels()
1704 channel->qh = NULL; in dwc2_hcd_cleanup_channels()
1707 if (hsotg->params.uframe_sched) { in dwc2_hcd_cleanup_channels()
1708 hsotg->available_host_channels = in dwc2_hcd_cleanup_channels()
1709 hsotg->params.host_channels; in dwc2_hcd_cleanup_channels()
1711 hsotg->non_periodic_channels = 0; in dwc2_hcd_cleanup_channels()
1712 hsotg->periodic_channels = 0; in dwc2_hcd_cleanup_channels()
1717 * dwc2_hcd_connect() - Handles connect of the HCD
1725 if (hsotg->lx_state != DWC2_L0) in dwc2_hcd_connect()
1726 usb_hcd_resume_root_hub(hsotg->priv); in dwc2_hcd_connect()
1728 hsotg->flags.b.port_connect_status_change = 1; in dwc2_hcd_connect()
1729 hsotg->flags.b.port_connect_status = 1; in dwc2_hcd_connect()
1733 * dwc2_hcd_disconnect() - Handles disconnect of the HCD
1746 hsotg->flags.b.port_connect_status_change = 1; in dwc2_hcd_disconnect()
1747 hsotg->flags.b.port_connect_status = 0; in dwc2_hcd_disconnect()
1766 if (hsotg->op_state != OTG_STATE_A_SUSPEND) { in dwc2_hcd_disconnect()
1767 dev_dbg(hsotg->dev, "Disconnect: PortPower off\n"); in dwc2_hcd_disconnect()
1789 * 4. dwc2_port_intr() - clears connect interrupt in dwc2_hcd_disconnect()
1790 * 5. dwc2_handle_common_intr() - calls here in dwc2_hcd_disconnect()
1803 * dwc2_hcd_rem_wakeup() - Handles Remote Wakeup
1809 if (hsotg->bus_suspended) { in dwc2_hcd_rem_wakeup()
1810 hsotg->flags.b.port_suspend_change = 1; in dwc2_hcd_rem_wakeup()
1811 usb_hcd_resume_root_hub(hsotg->priv); in dwc2_hcd_rem_wakeup()
1814 if (hsotg->lx_state == DWC2_L1) in dwc2_hcd_rem_wakeup()
1815 hsotg->flags.b.port_l1_change = 1; in dwc2_hcd_rem_wakeup()
1819 * dwc2_hcd_stop() - Halts the DWC_otg host mode operations in a clean manner
1827 dev_dbg(hsotg->dev, "DWC OTG HCD STOP\n"); in dwc2_hcd_stop()
1835 /* Turn off all host-specific interrupts */ in dwc2_hcd_stop()
1839 dev_dbg(hsotg->dev, "PortPower off\n"); in dwc2_hcd_stop()
1852 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_urb_enqueue()
1854 dev_err(hsotg->dev, "Not connected\n"); in dwc2_hcd_urb_enqueue()
1855 return -ENODEV; in dwc2_hcd_urb_enqueue()
1858 dev_speed = dwc2_host_get_speed(hsotg, urb->priv); in dwc2_hcd_urb_enqueue()
1862 (hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) && in dwc2_hcd_urb_enqueue()
1863 (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI)) { in dwc2_hcd_urb_enqueue()
1868 return -ENODEV; in dwc2_hcd_urb_enqueue()
1872 return -EINVAL; in dwc2_hcd_urb_enqueue()
1877 dev_err(hsotg->dev, in dwc2_hcd_urb_enqueue()
1887 if (qtd->qh->ep_type == USB_ENDPOINT_XFER_BULK && in dwc2_hcd_urb_enqueue()
1888 !(qtd->urb->flags & URB_GIVEBACK_ASAP)) in dwc2_hcd_urb_enqueue()
1910 urb_qtd = urb->qtd; in dwc2_hcd_urb_dequeue()
1912 dev_dbg(hsotg->dev, "## Urb QTD is NULL ##\n"); in dwc2_hcd_urb_dequeue()
1913 return -EINVAL; in dwc2_hcd_urb_dequeue()
1916 qh = urb_qtd->qh; in dwc2_hcd_urb_dequeue()
1918 dev_dbg(hsotg->dev, "## Urb QTD QH is NULL ##\n"); in dwc2_hcd_urb_dequeue()
1919 return -EINVAL; in dwc2_hcd_urb_dequeue()
1922 urb->priv = NULL; in dwc2_hcd_urb_dequeue()
1924 if (urb_qtd->in_process && qh->channel) { in dwc2_hcd_urb_dequeue()
1925 dwc2_dump_channel_info(hsotg, qh->channel); in dwc2_hcd_urb_dequeue()
1928 if (hsotg->flags.b.port_connect_status) in dwc2_hcd_urb_dequeue()
1936 dwc2_hc_halt(hsotg, qh->channel, in dwc2_hcd_urb_dequeue()
1944 if (!hsotg->params.dma_desc_enable) { in dwc2_hcd_urb_dequeue()
1945 u8 in_process = urb_qtd->in_process; in dwc2_hcd_urb_dequeue()
1950 qh->channel = NULL; in dwc2_hcd_urb_dequeue()
1951 } else if (list_empty(&qh->qtd_list)) { in dwc2_hcd_urb_dequeue()
1963 struct usb_host_endpoint *ep, int retry) in dwc2_hcd_endpoint_disable() argument
1970 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
1972 qh = ep->hcpriv; in dwc2_hcd_endpoint_disable()
1974 rc = -EINVAL; in dwc2_hcd_endpoint_disable()
1978 while (!list_empty(&qh->qtd_list) && retry--) { in dwc2_hcd_endpoint_disable()
1979 if (retry == 0) { in dwc2_hcd_endpoint_disable()
1980 dev_err(hsotg->dev, in dwc2_hcd_endpoint_disable()
1982 rc = -EBUSY; in dwc2_hcd_endpoint_disable()
1986 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
1988 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
1989 qh = ep->hcpriv; in dwc2_hcd_endpoint_disable()
1991 rc = -EINVAL; in dwc2_hcd_endpoint_disable()
1999 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) in dwc2_hcd_endpoint_disable()
2002 ep->hcpriv = NULL; in dwc2_hcd_endpoint_disable()
2004 if (qh->channel && qh->channel->qh == qh) in dwc2_hcd_endpoint_disable()
2005 qh->channel->qh = NULL; in dwc2_hcd_endpoint_disable()
2007 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2014 ep->hcpriv = NULL; in dwc2_hcd_endpoint_disable()
2015 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2024 struct dwc2_qh *qh = ep->hcpriv; in dwc2_hcd_endpoint_reset()
2027 return -EINVAL; in dwc2_hcd_endpoint_reset()
2029 qh->data_toggle = DWC2_HC_PID_DATA0; in dwc2_hcd_endpoint_reset()
2035 * dwc2_core_init() - Initializes the DWC_otg controller registers and
2046 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_init()
2052 if (hsotg->params.phy_ulpi_ext_vbus) in dwc2_core_init()
2057 if (hsotg->params.ts_dline) in dwc2_core_init()
2065 * We only need to reset the controller if this is a re-init. in dwc2_core_init()
2072 dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", in dwc2_core_init()
2098 /* Clear the SRP success bit for FS-I2c */ in dwc2_core_init()
2099 hsotg->srp_success = 0; in dwc2_core_init()
2109 dev_dbg(hsotg->dev, "Host Mode\n"); in dwc2_core_init()
2110 hsotg->op_state = OTG_STATE_A_HOST; in dwc2_core_init()
2112 dev_dbg(hsotg->dev, "Device Mode\n"); in dwc2_core_init()
2113 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_core_init()
2120 * dwc2_core_host_init() - Initializes the DWC_otg controller registers for
2133 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_host_init()
2152 if (hsotg->params.speed == DWC2_SPEED_PARAM_FULL || in dwc2_core_host_init()
2153 hsotg->params.speed == DWC2_SPEED_PARAM_LOW) { in dwc2_core_host_init()
2164 if (hsotg->params.reload_ctl) { in dwc2_core_host_init()
2170 if (hsotg->params.dma_desc_enable) { in dwc2_core_host_init()
2171 u32 op_mode = hsotg->hw_params.op_mode; in dwc2_core_host_init()
2173 if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a || in dwc2_core_host_init()
2174 !hsotg->hw_params.dma_desc_enable || in dwc2_core_host_init()
2178 dev_err(hsotg->dev, in dwc2_core_host_init()
2179 "Hardware does not support descriptor DMA mode -\n"); in dwc2_core_host_init()
2180 dev_err(hsotg->dev, in dwc2_core_host_init()
2182 hsotg->params.dma_desc_enable = false; in dwc2_core_host_init()
2193 /* TODO - check this */ in dwc2_core_host_init()
2208 if (!hsotg->params.dma_desc_enable) { in dwc2_core_host_init()
2213 num_channels = hsotg->params.host_channels; in dwc2_core_host_init()
2231 dev_dbg(hsotg->dev, "%s: Halt channel %d\n", in dwc2_core_host_init()
2237 dev_warn(hsotg->dev, in dwc2_core_host_init()
2249 dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state); in dwc2_core_host_init()
2250 if (hsotg->op_state == OTG_STATE_A_HOST) { in dwc2_core_host_init()
2253 dev_dbg(hsotg->dev, "Init: Power Port (%d)\n", in dwc2_core_host_init()
2275 hsotg->flags.d32 = 0; in dwc2_hcd_reinit()
2276 hsotg->non_periodic_qh_ptr = &hsotg->non_periodic_sched_active; in dwc2_hcd_reinit()
2278 if (hsotg->params.uframe_sched) { in dwc2_hcd_reinit()
2279 hsotg->available_host_channels = in dwc2_hcd_reinit()
2280 hsotg->params.host_channels; in dwc2_hcd_reinit()
2282 hsotg->non_periodic_channels = 0; in dwc2_hcd_reinit()
2283 hsotg->periodic_channels = 0; in dwc2_hcd_reinit()
2290 list_for_each_entry_safe(chan, chan_tmp, &hsotg->free_hc_list, in dwc2_hcd_reinit()
2292 list_del_init(&chan->hc_list_entry); in dwc2_hcd_reinit()
2294 num_channels = hsotg->params.host_channels; in dwc2_hcd_reinit()
2296 chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_reinit()
2297 list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list); in dwc2_hcd_reinit()
2311 chan->do_split = 1; in dwc2_hc_init_split()
2312 chan->xact_pos = qtd->isoc_split_pos; in dwc2_hc_init_split()
2313 chan->complete_split = qtd->complete_split; in dwc2_hc_init_split()
2314 dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port); in dwc2_hc_init_split()
2315 chan->hub_addr = (u8)hub_addr; in dwc2_hc_init_split()
2316 chan->hub_port = (u8)hub_port; in dwc2_hc_init_split()
2323 struct dwc2_hcd_urb *urb = qtd->urb; in dwc2_hc_init_xfer()
2326 switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) { in dwc2_hc_init_xfer()
2328 chan->ep_type = USB_ENDPOINT_XFER_CONTROL; in dwc2_hc_init_xfer()
2330 switch (qtd->control_phase) { in dwc2_hc_init_xfer()
2332 dev_vdbg(hsotg->dev, " Control setup transaction\n"); in dwc2_hc_init_xfer()
2333 chan->do_ping = 0; in dwc2_hc_init_xfer()
2334 chan->ep_is_in = 0; in dwc2_hc_init_xfer()
2335 chan->data_pid_start = DWC2_HC_PID_SETUP; in dwc2_hc_init_xfer()
2336 if (hsotg->params.host_dma) in dwc2_hc_init_xfer()
2337 chan->xfer_dma = urb->setup_dma; in dwc2_hc_init_xfer()
2339 chan->xfer_buf = urb->setup_packet; in dwc2_hc_init_xfer()
2340 chan->xfer_len = 8; in dwc2_hc_init_xfer()
2344 dev_vdbg(hsotg->dev, " Control data transaction\n"); in dwc2_hc_init_xfer()
2345 chan->data_pid_start = qtd->data_toggle; in dwc2_hc_init_xfer()
2353 dev_vdbg(hsotg->dev, " Control status transaction\n"); in dwc2_hc_init_xfer()
2354 if (urb->length == 0) in dwc2_hc_init_xfer()
2355 chan->ep_is_in = 1; in dwc2_hc_init_xfer()
2357 chan->ep_is_in = in dwc2_hc_init_xfer()
2358 dwc2_hcd_is_pipe_out(&urb->pipe_info); in dwc2_hc_init_xfer()
2359 if (chan->ep_is_in) in dwc2_hc_init_xfer()
2360 chan->do_ping = 0; in dwc2_hc_init_xfer()
2361 chan->data_pid_start = DWC2_HC_PID_DATA1; in dwc2_hc_init_xfer()
2362 chan->xfer_len = 0; in dwc2_hc_init_xfer()
2363 if (hsotg->params.host_dma) in dwc2_hc_init_xfer()
2364 chan->xfer_dma = hsotg->status_buf_dma; in dwc2_hc_init_xfer()
2366 chan->xfer_buf = hsotg->status_buf; in dwc2_hc_init_xfer()
2372 chan->ep_type = USB_ENDPOINT_XFER_BULK; in dwc2_hc_init_xfer()
2376 chan->ep_type = USB_ENDPOINT_XFER_INT; in dwc2_hc_init_xfer()
2380 chan->ep_type = USB_ENDPOINT_XFER_ISOC; in dwc2_hc_init_xfer()
2381 if (hsotg->params.dma_desc_enable) in dwc2_hc_init_xfer()
2384 frame_desc = &urb->iso_descs[qtd->isoc_frame_index]; in dwc2_hc_init_xfer()
2385 frame_desc->status = 0; in dwc2_hc_init_xfer()
2387 if (hsotg->params.host_dma) { in dwc2_hc_init_xfer()
2388 chan->xfer_dma = urb->dma; in dwc2_hc_init_xfer()
2389 chan->xfer_dma += frame_desc->offset + in dwc2_hc_init_xfer()
2390 qtd->isoc_split_offset; in dwc2_hc_init_xfer()
2392 chan->xfer_buf = urb->buf; in dwc2_hc_init_xfer()
2393 chan->xfer_buf += frame_desc->offset + in dwc2_hc_init_xfer()
2394 qtd->isoc_split_offset; in dwc2_hc_init_xfer()
2397 chan->xfer_len = frame_desc->length - qtd->isoc_split_offset; in dwc2_hc_init_xfer()
2399 if (chan->xact_pos == DWC2_HCSPLT_XACTPOS_ALL) { in dwc2_hc_init_xfer()
2400 if (chan->xfer_len <= 188) in dwc2_hc_init_xfer()
2401 chan->xact_pos = DWC2_HCSPLT_XACTPOS_ALL; in dwc2_hc_init_xfer()
2403 chan->xact_pos = DWC2_HCSPLT_XACTPOS_BEGIN; in dwc2_hc_init_xfer()
2413 if (!hsotg->unaligned_cache || in dwc2_alloc_split_dma_aligned_buf()
2414 chan->max_packet > DWC2_KMEM_UNALIGNED_BUF_SIZE) in dwc2_alloc_split_dma_aligned_buf()
2415 return -ENOMEM; in dwc2_alloc_split_dma_aligned_buf()
2417 if (!qh->dw_align_buf) { in dwc2_alloc_split_dma_aligned_buf()
2418 qh->dw_align_buf = kmem_cache_alloc(hsotg->unaligned_cache, in dwc2_alloc_split_dma_aligned_buf()
2420 if (!qh->dw_align_buf) in dwc2_alloc_split_dma_aligned_buf()
2421 return -ENOMEM; in dwc2_alloc_split_dma_aligned_buf()
2424 qh->dw_align_buf_dma = dma_map_single(hsotg->dev, qh->dw_align_buf, in dwc2_alloc_split_dma_aligned_buf()
2428 if (dma_mapping_error(hsotg->dev, qh->dw_align_buf_dma)) { in dwc2_alloc_split_dma_aligned_buf()
2429 dev_err(hsotg->dev, "can't map align_buf\n"); in dwc2_alloc_split_dma_aligned_buf()
2430 chan->align_buf = 0; in dwc2_alloc_split_dma_aligned_buf()
2431 return -EINVAL; in dwc2_alloc_split_dma_aligned_buf()
2434 chan->align_buf = qh->dw_align_buf_dma; in dwc2_alloc_split_dma_aligned_buf()
2445 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER)) in dwc2_free_dma_aligned_buffer()
2448 /* Restore urb->transfer_buffer from the end of the allocated area */ in dwc2_free_dma_aligned_buffer()
2450 PTR_ALIGN(urb->transfer_buffer + urb->transfer_buffer_length, in dwc2_free_dma_aligned_buffer()
2452 sizeof(urb->transfer_buffer)); in dwc2_free_dma_aligned_buffer()
2455 if (usb_pipeisoc(urb->pipe)) in dwc2_free_dma_aligned_buffer()
2456 length = urb->transfer_buffer_length; in dwc2_free_dma_aligned_buffer()
2458 length = urb->actual_length; in dwc2_free_dma_aligned_buffer()
2460 memcpy(stored_xfer_buffer, urb->transfer_buffer, length); in dwc2_free_dma_aligned_buffer()
2462 kfree(urb->transfer_buffer); in dwc2_free_dma_aligned_buffer()
2463 urb->transfer_buffer = stored_xfer_buffer; in dwc2_free_dma_aligned_buffer()
2465 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER; in dwc2_free_dma_aligned_buffer()
2473 if (urb->num_sgs || urb->sg || in dwc2_alloc_dma_aligned_buffer()
2474 urb->transfer_buffer_length == 0 || in dwc2_alloc_dma_aligned_buffer()
2475 !((uintptr_t)urb->transfer_buffer & (DWC2_USB_DMA_ALIGN - 1))) in dwc2_alloc_dma_aligned_buffer()
2483 kmalloc_size = urb->transfer_buffer_length + in dwc2_alloc_dma_aligned_buffer()
2484 (dma_get_cache_alignment() - 1) + in dwc2_alloc_dma_aligned_buffer()
2485 sizeof(urb->transfer_buffer); in dwc2_alloc_dma_aligned_buffer()
2489 return -ENOMEM; in dwc2_alloc_dma_aligned_buffer()
2492 * Position value of original urb->transfer_buffer pointer to the end in dwc2_alloc_dma_aligned_buffer()
2495 memcpy(PTR_ALIGN(kmalloc_ptr + urb->transfer_buffer_length, in dwc2_alloc_dma_aligned_buffer()
2497 &urb->transfer_buffer, sizeof(urb->transfer_buffer)); in dwc2_alloc_dma_aligned_buffer()
2500 memcpy(kmalloc_ptr, urb->transfer_buffer, in dwc2_alloc_dma_aligned_buffer()
2501 urb->transfer_buffer_length); in dwc2_alloc_dma_aligned_buffer()
2502 urb->transfer_buffer = kmalloc_ptr; in dwc2_alloc_dma_aligned_buffer()
2504 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER; in dwc2_alloc_dma_aligned_buffer()
2515 WARN_ON_ONCE(urb->setup_dma && in dwc2_map_urb_for_dma()
2516 (urb->setup_dma & (DWC2_USB_DMA_ALIGN - 1))); in dwc2_map_urb_for_dma()
2536 * dwc2_assign_and_init_hc() - Assigns transactions from a QTD to a free host
2551 dev_vdbg(hsotg->dev, "%s(%p,%p)\n", __func__, hsotg, qh); in dwc2_assign_and_init_hc()
2553 if (list_empty(&qh->qtd_list)) { in dwc2_assign_and_init_hc()
2554 dev_dbg(hsotg->dev, "No QTDs in QH list\n"); in dwc2_assign_and_init_hc()
2555 return -ENOMEM; in dwc2_assign_and_init_hc()
2558 if (list_empty(&hsotg->free_hc_list)) { in dwc2_assign_and_init_hc()
2559 dev_dbg(hsotg->dev, "No free channel to assign\n"); in dwc2_assign_and_init_hc()
2560 return -ENOMEM; in dwc2_assign_and_init_hc()
2563 chan = list_first_entry(&hsotg->free_hc_list, struct dwc2_host_chan, in dwc2_assign_and_init_hc()
2567 list_del_init(&chan->hc_list_entry); in dwc2_assign_and_init_hc()
2569 qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry); in dwc2_assign_and_init_hc()
2570 urb = qtd->urb; in dwc2_assign_and_init_hc()
2571 qh->channel = chan; in dwc2_assign_and_init_hc()
2572 qtd->in_process = 1; in dwc2_assign_and_init_hc()
2578 chan->dev_addr = dwc2_hcd_get_dev_addr(&urb->pipe_info); in dwc2_assign_and_init_hc()
2579 chan->ep_num = dwc2_hcd_get_ep_num(&urb->pipe_info); in dwc2_assign_and_init_hc()
2580 chan->speed = qh->dev_speed; in dwc2_assign_and_init_hc()
2581 chan->max_packet = qh->maxp; in dwc2_assign_and_init_hc()
2583 chan->xfer_started = 0; in dwc2_assign_and_init_hc()
2584 chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS; in dwc2_assign_and_init_hc()
2585 chan->error_state = (qtd->error_count > 0); in dwc2_assign_and_init_hc()
2586 chan->halt_on_queue = 0; in dwc2_assign_and_init_hc()
2587 chan->halt_pending = 0; in dwc2_assign_and_init_hc()
2588 chan->requests = 0; in dwc2_assign_and_init_hc()
2597 chan->ep_is_in = (dwc2_hcd_is_pipe_in(&urb->pipe_info) != 0); in dwc2_assign_and_init_hc()
2598 if (chan->ep_is_in) in dwc2_assign_and_init_hc()
2599 chan->do_ping = 0; in dwc2_assign_and_init_hc()
2601 chan->do_ping = qh->ping_state; in dwc2_assign_and_init_hc()
2603 chan->data_pid_start = qh->data_toggle; in dwc2_assign_and_init_hc()
2604 chan->multi_count = 1; in dwc2_assign_and_init_hc()
2606 if (urb->actual_length > urb->length && in dwc2_assign_and_init_hc()
2607 !dwc2_hcd_is_pipe_in(&urb->pipe_info)) in dwc2_assign_and_init_hc()
2608 urb->actual_length = urb->length; in dwc2_assign_and_init_hc()
2610 if (hsotg->params.host_dma) in dwc2_assign_and_init_hc()
2611 chan->xfer_dma = urb->dma + urb->actual_length; in dwc2_assign_and_init_hc()
2613 chan->xfer_buf = (u8 *)urb->buf + urb->actual_length; in dwc2_assign_and_init_hc()
2615 chan->xfer_len = urb->length - urb->actual_length; in dwc2_assign_and_init_hc()
2616 chan->xfer_count = 0; in dwc2_assign_and_init_hc()
2619 if (qh->do_split) in dwc2_assign_and_init_hc()
2622 chan->do_split = 0; in dwc2_assign_and_init_hc()
2627 /* For non-dword aligned buffers */ in dwc2_assign_and_init_hc()
2628 if (hsotg->params.host_dma && qh->do_split && in dwc2_assign_and_init_hc()
2629 chan->ep_is_in && (chan->xfer_dma & 0x3)) { in dwc2_assign_and_init_hc()
2630 dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); in dwc2_assign_and_init_hc()
2632 dev_err(hsotg->dev, in dwc2_assign_and_init_hc()
2633 "Failed to allocate memory to handle non-aligned buffer\n"); in dwc2_assign_and_init_hc()
2635 chan->align_buf = 0; in dwc2_assign_and_init_hc()
2636 chan->multi_count = 0; in dwc2_assign_and_init_hc()
2637 list_add_tail(&chan->hc_list_entry, in dwc2_assign_and_init_hc()
2638 &hsotg->free_hc_list); in dwc2_assign_and_init_hc()
2639 qtd->in_process = 0; in dwc2_assign_and_init_hc()
2640 qh->channel = NULL; in dwc2_assign_and_init_hc()
2641 return -ENOMEM; in dwc2_assign_and_init_hc()
2645 * We assume that DMA is always aligned in non-split in dwc2_assign_and_init_hc()
2648 WARN_ON_ONCE(hsotg->params.host_dma && in dwc2_assign_and_init_hc()
2649 (chan->xfer_dma & 0x3)); in dwc2_assign_and_init_hc()
2650 chan->align_buf = 0; in dwc2_assign_and_init_hc()
2653 if (chan->ep_type == USB_ENDPOINT_XFER_INT || in dwc2_assign_and_init_hc()
2654 chan->ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_assign_and_init_hc()
2659 chan->multi_count = qh->maxp_mult; in dwc2_assign_and_init_hc()
2661 if (hsotg->params.dma_desc_enable) { in dwc2_assign_and_init_hc()
2662 chan->desc_list_addr = qh->desc_list_dma; in dwc2_assign_and_init_hc()
2663 chan->desc_list_sz = qh->desc_list_sz; in dwc2_assign_and_init_hc()
2667 chan->qh = qh; in dwc2_assign_and_init_hc()
2673 * dwc2_hcd_select_transactions() - Selects transactions from the HCD transfer
2690 dev_vdbg(hsotg->dev, " Select Transactions\n"); in dwc2_hcd_select_transactions()
2694 qh_ptr = hsotg->periodic_sched_ready.next; in dwc2_hcd_select_transactions()
2695 while (qh_ptr != &hsotg->periodic_sched_ready) { in dwc2_hcd_select_transactions()
2696 if (list_empty(&hsotg->free_hc_list)) in dwc2_hcd_select_transactions()
2698 if (hsotg->params.uframe_sched) { in dwc2_hcd_select_transactions()
2699 if (hsotg->available_host_channels <= 1) in dwc2_hcd_select_transactions()
2701 hsotg->available_host_channels--; in dwc2_hcd_select_transactions()
2705 if (hsotg->params.uframe_sched) in dwc2_hcd_select_transactions()
2706 hsotg->available_host_channels++; in dwc2_hcd_select_transactions()
2714 qh_ptr = qh_ptr->next; in dwc2_hcd_select_transactions()
2715 list_move_tail(&qh->qh_list_entry, in dwc2_hcd_select_transactions()
2716 &hsotg->periodic_sched_assigned); in dwc2_hcd_select_transactions()
2721 * Process entries in the inactive portion of the non-periodic in dwc2_hcd_select_transactions()
2725 num_channels = hsotg->params.host_channels; in dwc2_hcd_select_transactions()
2726 qh_ptr = hsotg->non_periodic_sched_inactive.next; in dwc2_hcd_select_transactions()
2727 while (qh_ptr != &hsotg->non_periodic_sched_inactive) { in dwc2_hcd_select_transactions()
2728 if (!hsotg->params.uframe_sched && in dwc2_hcd_select_transactions()
2729 hsotg->non_periodic_channels >= num_channels - in dwc2_hcd_select_transactions()
2730 hsotg->periodic_channels) in dwc2_hcd_select_transactions()
2732 if (list_empty(&hsotg->free_hc_list)) in dwc2_hcd_select_transactions()
2735 if (hsotg->params.uframe_sched) { in dwc2_hcd_select_transactions()
2736 if (hsotg->available_host_channels < 1) in dwc2_hcd_select_transactions()
2738 hsotg->available_host_channels--; in dwc2_hcd_select_transactions()
2742 if (hsotg->params.uframe_sched) in dwc2_hcd_select_transactions()
2743 hsotg->available_host_channels++; in dwc2_hcd_select_transactions()
2748 * Move the QH from the non-periodic inactive schedule to the in dwc2_hcd_select_transactions()
2749 * non-periodic active schedule in dwc2_hcd_select_transactions()
2751 qh_ptr = qh_ptr->next; in dwc2_hcd_select_transactions()
2752 list_move_tail(&qh->qh_list_entry, in dwc2_hcd_select_transactions()
2753 &hsotg->non_periodic_sched_active); in dwc2_hcd_select_transactions()
2760 if (!hsotg->params.uframe_sched) in dwc2_hcd_select_transactions()
2761 hsotg->non_periodic_channels++; in dwc2_hcd_select_transactions()
2768 * dwc2_queue_transaction() - Attempts to queue a single transaction request for
2769 * a host channel associated with either a periodic or non-periodic transfer
2773 * non-periodic transfer
2775 * for periodic transfers or the non-periodic Tx FIFO
2776 * for non-periodic transfers
2780 * transfer, -1 if there is insufficient space in the Tx FIFO
2794 if (chan->do_split) in dwc2_queue_transaction()
2796 list_move_tail(&chan->split_order_list_entry, in dwc2_queue_transaction()
2797 &hsotg->split_order); in dwc2_queue_transaction()
2799 if (hsotg->params.host_dma && chan->qh) { in dwc2_queue_transaction()
2800 if (hsotg->params.dma_desc_enable) { in dwc2_queue_transaction()
2801 if (!chan->xfer_started || in dwc2_queue_transaction()
2802 chan->ep_type == USB_ENDPOINT_XFER_ISOC) { in dwc2_queue_transaction()
2803 dwc2_hcd_start_xfer_ddma(hsotg, chan->qh); in dwc2_queue_transaction()
2804 chan->qh->ping_state = 0; in dwc2_queue_transaction()
2806 } else if (!chan->xfer_started) { in dwc2_queue_transaction()
2808 chan->qh->ping_state = 0; in dwc2_queue_transaction()
2810 } else if (chan->halt_pending) { in dwc2_queue_transaction()
2812 } else if (chan->halt_on_queue) { in dwc2_queue_transaction()
2813 dwc2_hc_halt(hsotg, chan, chan->halt_status); in dwc2_queue_transaction()
2814 } else if (chan->do_ping) { in dwc2_queue_transaction()
2815 if (!chan->xfer_started) in dwc2_queue_transaction()
2817 } else if (!chan->ep_is_in || in dwc2_queue_transaction()
2818 chan->data_pid_start == DWC2_HC_PID_SETUP) { in dwc2_queue_transaction()
2819 if ((fifo_dwords_avail * 4) >= chan->max_packet) { in dwc2_queue_transaction()
2820 if (!chan->xfer_started) { in dwc2_queue_transaction()
2827 retval = -1; in dwc2_queue_transaction()
2830 if (!chan->xfer_started) { in dwc2_queue_transaction()
2863 if (list_empty(&hsotg->periodic_sched_assigned)) in dwc2_process_periodic_channels()
2867 dev_vdbg(hsotg->dev, "Queue periodic transactions\n"); in dwc2_process_periodic_channels()
2876 dev_vdbg(hsotg->dev, " P Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2878 dev_vdbg(hsotg->dev, " P Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2882 qh_ptr = hsotg->periodic_sched_assigned.next; in dwc2_process_periodic_channels()
2883 while (qh_ptr != &hsotg->periodic_sched_assigned) { in dwc2_process_periodic_channels()
2893 if (!qh->channel) { in dwc2_process_periodic_channels()
2894 qh_ptr = qh_ptr->next; in dwc2_process_periodic_channels()
2899 if (qh->tt_buffer_dirty) { in dwc2_process_periodic_channels()
2900 qh_ptr = qh_ptr->next; in dwc2_process_periodic_channels()
2905 * Set a flag if we're queuing high-bandwidth in slave mode. in dwc2_process_periodic_channels()
2907 * the middle of multiple high-bandwidth packets getting queued. in dwc2_process_periodic_channels()
2909 if (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2910 qh->channel->multi_count > 1) in dwc2_process_periodic_channels()
2911 hsotg->queuing_high_bandwidth = 1; in dwc2_process_periodic_channels()
2915 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_periodic_channels()
2923 * nothing more to do or the high-bandwidth request count is in dwc2_process_periodic_channels()
2926 * high-bandwidth transfers. in dwc2_process_periodic_channels()
2928 if (hsotg->params.host_dma || status == 0 || in dwc2_process_periodic_channels()
2929 qh->channel->requests == qh->channel->multi_count) { in dwc2_process_periodic_channels()
2930 qh_ptr = qh_ptr->next; in dwc2_process_periodic_channels()
2935 list_move_tail(&qh->qh_list_entry, in dwc2_process_periodic_channels()
2936 &hsotg->periodic_sched_queued); in dwc2_process_periodic_channels()
2939 hsotg->queuing_high_bandwidth = 0; in dwc2_process_periodic_channels()
2945 (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2946 !list_empty(&hsotg->periodic_sched_assigned))) { in dwc2_process_periodic_channels()
2950 * FIFO empty interrupt. (Always use the half-empty in dwc2_process_periodic_channels()
2976 * Processes active non-periodic channels and queues transactions for these
2997 dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n"); in dwc2_process_non_periodic_channels()
3004 dev_vdbg(hsotg->dev, " NP Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3006 dev_vdbg(hsotg->dev, " NP Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3010 * Keep track of the starting point. Skip over the start-of-list in dwc2_process_non_periodic_channels()
3013 if (hsotg->non_periodic_qh_ptr == &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3014 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3015 orig_qh_ptr = hsotg->non_periodic_qh_ptr; in dwc2_process_non_periodic_channels()
3025 if (!hsotg->params.host_dma && qspcavail == 0) { in dwc2_process_non_periodic_channels()
3030 qh = list_entry(hsotg->non_periodic_qh_ptr, struct dwc2_qh, in dwc2_process_non_periodic_channels()
3032 if (!qh->channel) in dwc2_process_non_periodic_channels()
3036 if (qh->tt_buffer_dirty) in dwc2_process_non_periodic_channels()
3041 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_non_periodic_channels()
3050 /* Advance to next QH, skipping start-of-list entry */ in dwc2_process_non_periodic_channels()
3051 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3052 if (hsotg->non_periodic_qh_ptr == in dwc2_process_non_periodic_channels()
3053 &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3054 hsotg->non_periodic_qh_ptr = in dwc2_process_non_periodic_channels()
3055 hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3056 } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr); in dwc2_process_non_periodic_channels()
3058 if (!hsotg->params.host_dma) { in dwc2_process_non_periodic_channels()
3064 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3067 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3074 * queue or Tx FIFO empties. Enable the non-periodic in dwc2_process_non_periodic_channels()
3075 * Tx FIFO empty interrupt. (Always use the half-empty in dwc2_process_non_periodic_channels()
3098 * dwc2_hcd_queue_transactions() - Processes the currently active host channels
3103 * @tr_type: The type(s) of transactions to queue (non-periodic, periodic,
3112 dev_vdbg(hsotg->dev, "Queue Transactions\n"); in dwc2_hcd_queue_transactions()
3119 /* Process host channels associated with non-periodic transfers */ in dwc2_hcd_queue_transactions()
3122 if (!list_empty(&hsotg->non_periodic_sched_active)) { in dwc2_hcd_queue_transactions()
3127 * there are no non-periodic transfers to process in dwc2_hcd_queue_transactions()
3145 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_conn_id_status_change()
3148 dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl); in dwc2_conn_id_status_change()
3149 dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n", in dwc2_conn_id_status_change()
3152 /* B-Device connector (Device Mode) */ in dwc2_conn_id_status_change()
3156 dev_dbg(hsotg->dev, "connId B\n"); in dwc2_conn_id_status_change()
3157 if (hsotg->bus_suspended) { in dwc2_conn_id_status_change()
3158 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3163 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3180 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3188 if (hsotg->in_ppd && hsotg->lx_state == DWC2_L2) in dwc2_conn_id_status_change()
3191 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_conn_id_status_change()
3194 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3196 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3202 /* A-Device connector (Host Mode) */ in dwc2_conn_id_status_change()
3203 dev_dbg(hsotg->dev, "connId A\n"); in dwc2_conn_id_status_change()
3205 dev_info(hsotg->dev, "Waiting for Host Mode, Mode=%s\n", in dwc2_conn_id_status_change()
3213 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3216 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3218 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3220 hsotg->op_state = OTG_STATE_A_HOST; in dwc2_conn_id_status_change()
3233 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_wakeup_detected()
3240 dev_dbg(hsotg->dev, "Resume: HPRT0=%0x\n", hprt0); in dwc2_wakeup_detected()
3243 dev_dbg(hsotg->dev, "Clear Resume: HPRT0=%0x\n", in dwc2_wakeup_detected()
3247 hsotg->bus_suspended = false; in dwc2_wakeup_detected()
3250 hsotg->lx_state = DWC2_L0; in dwc2_wakeup_detected()
3257 return hcd->self.b_hnp_enable; in dwc2_host_is_b_hnp_enabled()
3261 * dwc2_port_suspend() - Put controller in suspend mode for host.
3266 * Return: non-zero if failed to enter suspend mode for host.
3278 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_port_suspend()
3280 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_suspend()
3282 if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) { in dwc2_port_suspend()
3286 hsotg->op_state = OTG_STATE_A_SUSPEND; in dwc2_port_suspend()
3289 switch (hsotg->params.power_down) { in dwc2_port_suspend()
3293 dev_err(hsotg->dev, in dwc2_port_suspend()
3303 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3306 dev_err(hsotg->dev, "enter hibernation failed.\n"); in dwc2_port_suspend()
3307 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_suspend()
3314 if (!hsotg->params.no_clock_gating) in dwc2_port_suspend()
3325 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3329 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3336 * dwc2_port_resume() - Exit controller from suspend mode for host.
3340 * Return: non-zero if failed to exit suspend mode for host.
3350 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3352 switch (hsotg->params.power_down) { in dwc2_port_resume()
3356 dev_err(hsotg->dev, in dwc2_port_resume()
3363 dev_err(hsotg->dev, "exit hibernation failed.\n"); in dwc2_port_resume()
3370 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3372 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3376 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3381 /* Handles hub class-specific requests */
3395 dev_dbg(hsotg->dev, "ClearHubFeature %1xh\n", wvalue); in dwc2_hcd_hub_control()
3404 retval = -EINVAL; in dwc2_hcd_hub_control()
3405 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3417 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3425 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3428 if (hsotg->bus_suspended) in dwc2_hcd_hub_control()
3433 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3444 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3453 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3455 hsotg->flags.b.port_connect_status_change = 0; in dwc2_hcd_hub_control()
3460 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3462 hsotg->flags.b.port_reset_change = 0; in dwc2_hcd_hub_control()
3470 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3472 hsotg->flags.b.port_enable_change = 0; in dwc2_hcd_hub_control()
3481 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3483 hsotg->flags.b.port_suspend_change = 0; in dwc2_hcd_hub_control()
3487 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3489 hsotg->flags.b.port_l1_change = 0; in dwc2_hcd_hub_control()
3493 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3495 hsotg->flags.b.port_over_current_change = 0; in dwc2_hcd_hub_control()
3499 retval = -EINVAL; in dwc2_hcd_hub_control()
3500 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3507 dev_dbg(hsotg->dev, "GetHubDescriptor\n"); in dwc2_hcd_hub_control()
3509 hub_desc->bDescLength = 9; in dwc2_hcd_hub_control()
3510 hub_desc->bDescriptorType = USB_DT_HUB; in dwc2_hcd_hub_control()
3511 hub_desc->bNbrPorts = 1; in dwc2_hcd_hub_control()
3512 hub_desc->wHubCharacteristics = in dwc2_hcd_hub_control()
3515 hub_desc->bPwrOn2PwrGood = 1; in dwc2_hcd_hub_control()
3516 hub_desc->bHubContrCurrent = 0; in dwc2_hcd_hub_control()
3517 hub_desc->u.hs.DeviceRemovable[0] = 0; in dwc2_hcd_hub_control()
3518 hub_desc->u.hs.DeviceRemovable[1] = 0xff; in dwc2_hcd_hub_control()
3522 dev_dbg(hsotg->dev, "GetHubStatus\n"); in dwc2_hcd_hub_control()
3527 dev_vdbg(hsotg->dev, in dwc2_hcd_hub_control()
3529 hsotg->flags.d32); in dwc2_hcd_hub_control()
3534 if (hsotg->flags.b.port_connect_status_change) in dwc2_hcd_hub_control()
3536 if (hsotg->flags.b.port_enable_change) in dwc2_hcd_hub_control()
3538 if (hsotg->flags.b.port_suspend_change) in dwc2_hcd_hub_control()
3540 if (hsotg->flags.b.port_l1_change) in dwc2_hcd_hub_control()
3542 if (hsotg->flags.b.port_reset_change) in dwc2_hcd_hub_control()
3544 if (hsotg->flags.b.port_over_current_change) { in dwc2_hcd_hub_control()
3545 dev_warn(hsotg->dev, "Overcurrent change detected\n"); in dwc2_hcd_hub_control()
3560 dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); in dwc2_hcd_hub_control()
3585 if (hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_hub_control()
3590 if (hsotg->new_connection && in dwc2_hcd_hub_control()
3598 dev_info(hsotg->dev, "Enabling descriptor DMA mode\n"); in dwc2_hcd_hub_control()
3599 hsotg->params.dma_desc_enable = true; in dwc2_hcd_hub_control()
3603 hsotg->new_connection = false; in dwc2_hcd_hub_control()
3607 dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); in dwc2_hcd_hub_control()
3612 dev_dbg(hsotg->dev, "SetHubFeature\n"); in dwc2_hcd_hub_control()
3617 dev_dbg(hsotg->dev, "SetPortFeature\n"); in dwc2_hcd_hub_control()
3632 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3633 "SetPortFeature - USB_PORT_FEAT_SUSPEND\n"); in dwc2_hcd_hub_control()
3634 if (windex != hsotg->otg_port) in dwc2_hcd_hub_control()
3636 if (!hsotg->bus_suspended) in dwc2_hcd_hub_control()
3641 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3642 "SetPortFeature - USB_PORT_FEAT_POWER\n"); in dwc2_hcd_hub_control()
3652 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3653 "SetPortFeature - USB_PORT_FEAT_RESET\n"); in dwc2_hcd_hub_control()
3657 if (hsotg->hibernated) { in dwc2_hcd_hub_control()
3660 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3664 if (hsotg->in_ppd) { in dwc2_hcd_hub_control()
3668 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3672 if (hsotg->params.power_down == in dwc2_hcd_hub_control()
3673 DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended) in dwc2_hcd_hub_control()
3688 * When B-Host the Port reset bit is set in the Start in dwc2_hcd_hub_control()
3694 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3705 hsotg->lx_state = DWC2_L0; /* Now back to On state */ in dwc2_hcd_hub_control()
3709 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3710 "SetPortFeature - USB_PORT_FEAT_INDICATOR\n"); in dwc2_hcd_hub_control()
3716 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3717 "SetPortFeature - USB_PORT_FEAT_TEST\n"); in dwc2_hcd_hub_control()
3724 retval = -EINVAL; in dwc2_hcd_hub_control()
3725 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3734 retval = -EINVAL; in dwc2_hcd_hub_control()
3735 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3749 return -EINVAL; in dwc2_hcd_is_status_changed()
3751 retval = (hsotg->flags.b.port_connect_status_change || in dwc2_hcd_is_status_changed()
3752 hsotg->flags.b.port_reset_change || in dwc2_hcd_is_status_changed()
3753 hsotg->flags.b.port_enable_change || in dwc2_hcd_is_status_changed()
3754 hsotg->flags.b.port_suspend_change || in dwc2_hcd_is_status_changed()
3755 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3758 dev_dbg(hsotg->dev, in dwc2_hcd_is_status_changed()
3760 dev_dbg(hsotg->dev, " port_connect_status_change: %d\n", in dwc2_hcd_is_status_changed()
3761 hsotg->flags.b.port_connect_status_change); in dwc2_hcd_is_status_changed()
3762 dev_dbg(hsotg->dev, " port_reset_change: %d\n", in dwc2_hcd_is_status_changed()
3763 hsotg->flags.b.port_reset_change); in dwc2_hcd_is_status_changed()
3764 dev_dbg(hsotg->dev, " port_enable_change: %d\n", in dwc2_hcd_is_status_changed()
3765 hsotg->flags.b.port_enable_change); in dwc2_hcd_is_status_changed()
3766 dev_dbg(hsotg->dev, " port_suspend_change: %d\n", in dwc2_hcd_is_status_changed()
3767 hsotg->flags.b.port_suspend_change); in dwc2_hcd_is_status_changed()
3768 dev_dbg(hsotg->dev, " port_over_current_change: %d\n", in dwc2_hcd_is_status_changed()
3769 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3780 dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n", in dwc2_hcd_get_frame_number()
3809 phy_clks = (interval - remaining) + in dwc2_hcd_get_future_frame_number()
3817 return hsotg->op_state == OTG_STATE_B_HOST; in dwc2_hcd_is_b_host()
3828 urb->packet_count = iso_desc_count; in dwc2_hcd_urb_alloc()
3840 dev_vdbg(hsotg->dev, in dwc2_hcd_urb_set_pipeinfo()
3843 urb->pipe_info.dev_addr = dev_addr; in dwc2_hcd_urb_set_pipeinfo()
3844 urb->pipe_info.ep_num = ep_num; in dwc2_hcd_urb_set_pipeinfo()
3845 urb->pipe_info.pipe_type = ep_type; in dwc2_hcd_urb_set_pipeinfo()
3846 urb->pipe_info.pipe_dir = ep_dir; in dwc2_hcd_urb_set_pipeinfo()
3847 urb->pipe_info.maxp = maxp; in dwc2_hcd_urb_set_pipeinfo()
3848 urb->pipe_info.maxp_mult = maxp_mult; in dwc2_hcd_urb_set_pipeinfo()
3866 num_channels = hsotg->params.host_channels; in dwc2_hcd_dump_state()
3867 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3868 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3870 dev_dbg(hsotg->dev, "HCD State:\n"); in dwc2_hcd_dump_state()
3871 dev_dbg(hsotg->dev, " Num channels: %d\n", num_channels); in dwc2_hcd_dump_state()
3874 chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_dump_state()
3875 dev_dbg(hsotg->dev, " Channel %d:\n", i); in dwc2_hcd_dump_state()
3876 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3878 chan->dev_addr, chan->ep_num, chan->ep_is_in); in dwc2_hcd_dump_state()
3879 dev_dbg(hsotg->dev, " speed: %d\n", chan->speed); in dwc2_hcd_dump_state()
3880 dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); in dwc2_hcd_dump_state()
3881 dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); in dwc2_hcd_dump_state()
3882 dev_dbg(hsotg->dev, " data_pid_start: %d\n", in dwc2_hcd_dump_state()
3883 chan->data_pid_start); in dwc2_hcd_dump_state()
3884 dev_dbg(hsotg->dev, " multi_count: %d\n", chan->multi_count); in dwc2_hcd_dump_state()
3885 dev_dbg(hsotg->dev, " xfer_started: %d\n", in dwc2_hcd_dump_state()
3886 chan->xfer_started); in dwc2_hcd_dump_state()
3887 dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); in dwc2_hcd_dump_state()
3888 dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", in dwc2_hcd_dump_state()
3889 (unsigned long)chan->xfer_dma); in dwc2_hcd_dump_state()
3890 dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); in dwc2_hcd_dump_state()
3891 dev_dbg(hsotg->dev, " xfer_count: %d\n", chan->xfer_count); in dwc2_hcd_dump_state()
3892 dev_dbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hcd_dump_state()
3893 chan->halt_on_queue); in dwc2_hcd_dump_state()
3894 dev_dbg(hsotg->dev, " halt_pending: %d\n", in dwc2_hcd_dump_state()
3895 chan->halt_pending); in dwc2_hcd_dump_state()
3896 dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); in dwc2_hcd_dump_state()
3897 dev_dbg(hsotg->dev, " do_split: %d\n", chan->do_split); in dwc2_hcd_dump_state()
3898 dev_dbg(hsotg->dev, " complete_split: %d\n", in dwc2_hcd_dump_state()
3899 chan->complete_split); in dwc2_hcd_dump_state()
3900 dev_dbg(hsotg->dev, " hub_addr: %d\n", chan->hub_addr); in dwc2_hcd_dump_state()
3901 dev_dbg(hsotg->dev, " hub_port: %d\n", chan->hub_port); in dwc2_hcd_dump_state()
3902 dev_dbg(hsotg->dev, " xact_pos: %d\n", chan->xact_pos); in dwc2_hcd_dump_state()
3903 dev_dbg(hsotg->dev, " requests: %d\n", chan->requests); in dwc2_hcd_dump_state()
3904 dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); in dwc2_hcd_dump_state()
3906 if (chan->xfer_started) { in dwc2_hcd_dump_state()
3914 dev_dbg(hsotg->dev, " hfnum: 0x%08x\n", hfnum); in dwc2_hcd_dump_state()
3915 dev_dbg(hsotg->dev, " hcchar: 0x%08x\n", hcchar); in dwc2_hcd_dump_state()
3916 dev_dbg(hsotg->dev, " hctsiz: 0x%08x\n", hctsiz); in dwc2_hcd_dump_state()
3917 dev_dbg(hsotg->dev, " hcint: 0x%08x\n", hcint); in dwc2_hcd_dump_state()
3918 dev_dbg(hsotg->dev, " hcintmsk: 0x%08x\n", hcintmsk); in dwc2_hcd_dump_state()
3921 if (!(chan->xfer_started && chan->qh)) in dwc2_hcd_dump_state()
3924 list_for_each_entry(qtd, &chan->qh->qtd_list, qtd_list_entry) { in dwc2_hcd_dump_state()
3925 if (!qtd->in_process) in dwc2_hcd_dump_state()
3927 urb = qtd->urb; in dwc2_hcd_dump_state()
3928 dev_dbg(hsotg->dev, " URB Info:\n"); in dwc2_hcd_dump_state()
3929 dev_dbg(hsotg->dev, " qtd: %p, urb: %p\n", in dwc2_hcd_dump_state()
3932 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3934 dwc2_hcd_get_dev_addr(&urb->pipe_info), in dwc2_hcd_dump_state()
3935 dwc2_hcd_get_ep_num(&urb->pipe_info), in dwc2_hcd_dump_state()
3936 dwc2_hcd_is_pipe_in(&urb->pipe_info) ? in dwc2_hcd_dump_state()
3938 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3940 dwc2_hcd_get_maxp(&urb->pipe_info), in dwc2_hcd_dump_state()
3941 dwc2_hcd_get_maxp_mult(&urb->pipe_info)); in dwc2_hcd_dump_state()
3942 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3944 urb->buf); in dwc2_hcd_dump_state()
3945 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3947 (unsigned long)urb->dma); in dwc2_hcd_dump_state()
3948 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3950 urb->length); in dwc2_hcd_dump_state()
3951 dev_dbg(hsotg->dev, " actual_length: %d\n", in dwc2_hcd_dump_state()
3952 urb->actual_length); in dwc2_hcd_dump_state()
3957 dev_dbg(hsotg->dev, " non_periodic_channels: %d\n", in dwc2_hcd_dump_state()
3958 hsotg->non_periodic_channels); in dwc2_hcd_dump_state()
3959 dev_dbg(hsotg->dev, " periodic_channels: %d\n", in dwc2_hcd_dump_state()
3960 hsotg->periodic_channels); in dwc2_hcd_dump_state()
3961 dev_dbg(hsotg->dev, " periodic_usecs: %d\n", hsotg->periodic_usecs); in dwc2_hcd_dump_state()
3963 dev_dbg(hsotg->dev, " NP Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3965 dev_dbg(hsotg->dev, " NP Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3968 dev_dbg(hsotg->dev, " P Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3970 dev_dbg(hsotg->dev, " P Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3974 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3976 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3989 p = (struct wrapper_priv_data *)&hcd->hcd_priv; in dwc2_hcd_to_hsotg()
3990 return p->hsotg; in dwc2_hcd_to_hsotg()
3994 * dwc2_host_get_tt_info() - Get the dwc2_tt associated with context
4019 if (urb->dev->tt) { in dwc2_host_get_tt_info()
4020 *ttport = urb->dev->ttport; in dwc2_host_get_tt_info()
4022 dwc_tt = urb->dev->tt->hcpriv; in dwc2_host_get_tt_info()
4031 sizeof(dwc_tt->periodic_bitmaps[0]); in dwc2_host_get_tt_info()
4032 if (urb->dev->tt->multi) in dwc2_host_get_tt_info()
4033 bitmap_size *= urb->dev->tt->hub->maxchild; in dwc2_host_get_tt_info()
4040 dwc_tt->usb_tt = urb->dev->tt; in dwc2_host_get_tt_info()
4041 dwc_tt->usb_tt->hcpriv = dwc_tt; in dwc2_host_get_tt_info()
4044 dwc_tt->refcount++; in dwc2_host_get_tt_info()
4051 * dwc2_host_put_tt_info() - Put the dwc2_tt from dwc2_host_get_tt_info()
4063 /* Model kfree and make put of NULL a no-op */ in dwc2_host_put_tt_info()
4067 WARN_ON(dwc_tt->refcount < 1); in dwc2_host_put_tt_info()
4069 dwc_tt->refcount--; in dwc2_host_put_tt_info()
4070 if (!dwc_tt->refcount) { in dwc2_host_put_tt_info()
4071 dwc_tt->usb_tt->hcpriv = NULL; in dwc2_host_put_tt_info()
4080 return urb->dev->speed; in dwc2_host_get_speed()
4088 if (urb->interval) in dwc2_allocate_bus_bandwidth()
4089 bus->bandwidth_allocated += bw / urb->interval; in dwc2_allocate_bus_bandwidth()
4090 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) in dwc2_allocate_bus_bandwidth()
4091 bus->bandwidth_isoc_reqs++; in dwc2_allocate_bus_bandwidth()
4093 bus->bandwidth_int_reqs++; in dwc2_allocate_bus_bandwidth()
4101 if (urb->interval) in dwc2_free_bus_bandwidth()
4102 bus->bandwidth_allocated -= bw / urb->interval; in dwc2_free_bus_bandwidth()
4103 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) in dwc2_free_bus_bandwidth()
4104 bus->bandwidth_isoc_reqs--; in dwc2_free_bus_bandwidth()
4106 bus->bandwidth_int_reqs--; in dwc2_free_bus_bandwidth()
4122 dev_dbg(hsotg->dev, "## %s: qtd is NULL ##\n", __func__); in dwc2_host_complete()
4126 if (!qtd->urb) { in dwc2_host_complete()
4127 dev_dbg(hsotg->dev, "## %s: qtd->urb is NULL ##\n", __func__); in dwc2_host_complete()
4131 urb = qtd->urb->priv; in dwc2_host_complete()
4133 dev_dbg(hsotg->dev, "## %s: urb->priv is NULL ##\n", __func__); in dwc2_host_complete()
4137 urb->actual_length = dwc2_hcd_urb_get_actual_length(qtd->urb); in dwc2_host_complete()
4140 dev_vdbg(hsotg->dev, in dwc2_host_complete()
4141 "%s: urb %p device %d ep %d-%s status %d actual %d\n", in dwc2_host_complete()
4142 __func__, urb, usb_pipedevice(urb->pipe), in dwc2_host_complete()
4143 usb_pipeendpoint(urb->pipe), in dwc2_host_complete()
4144 usb_pipein(urb->pipe) ? "IN" : "OUT", status, in dwc2_host_complete()
4145 urb->actual_length); in dwc2_host_complete()
4147 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { in dwc2_host_complete()
4148 if (!hsotg->params.dma_desc_enable) in dwc2_host_complete()
4149 urb->start_frame = qtd->qh->start_active_frame; in dwc2_host_complete()
4150 urb->error_count = dwc2_hcd_urb_get_error_count(qtd->urb); in dwc2_host_complete()
4151 for (i = 0; i < urb->number_of_packets; ++i) { in dwc2_host_complete()
4152 urb->iso_frame_desc[i].actual_length = in dwc2_host_complete()
4154 qtd->urb, i); in dwc2_host_complete()
4155 urb->iso_frame_desc[i].status = in dwc2_host_complete()
4156 dwc2_hcd_urb_get_iso_desc_status(qtd->urb, i); in dwc2_host_complete()
4160 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS && dbg_perio()) { in dwc2_host_complete()
4161 for (i = 0; i < urb->number_of_packets; i++) in dwc2_host_complete()
4162 dev_vdbg(hsotg->dev, " ISO Desc %d status %d\n", in dwc2_host_complete()
4163 i, urb->iso_frame_desc[i].status); in dwc2_host_complete()
4166 urb->status = status; in dwc2_host_complete()
4168 if ((urb->transfer_flags & URB_SHORT_NOT_OK) && in dwc2_host_complete()
4169 urb->actual_length < urb->transfer_buffer_length) in dwc2_host_complete()
4170 urb->status = -EREMOTEIO; in dwc2_host_complete()
4173 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS || in dwc2_host_complete()
4174 usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { in dwc2_host_complete()
4175 struct usb_host_endpoint *ep = urb->ep; in dwc2_host_complete()
4184 urb->hcpriv = NULL; in dwc2_host_complete()
4185 kfree(qtd->urb); in dwc2_host_complete()
4186 qtd->urb = NULL; in dwc2_host_complete()
4192 * Work queue function for starting the HCD when A-Cable is connected
4199 dev_dbg(hsotg->dev, "%s() %p\n", __func__, hsotg); in dwc2_hcd_start_func()
4213 dev_dbg(hsotg->dev, "USB RESET function called\n"); in dwc2_hcd_reset_func()
4215 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4220 hsotg->flags.b.port_reset_change = 1; in dwc2_hcd_reset_func()
4222 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4231 ret = phy_reset(hsotg->phy); in dwc2_hcd_phy_reset_func()
4233 dev_warn(hsotg->dev, "PHY reset failed\n"); in dwc2_hcd_phy_reset_func()
4255 dev_dbg(hsotg->dev, "DWC OTG HCD START\n"); in _dwc2_hcd_start()
4257 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4258 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_start()
4259 hcd->state = HC_STATE_RUNNING; in _dwc2_hcd_start()
4260 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_start()
4263 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4273 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4277 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4281 if (bus->root_hub) { in _dwc2_hcd_start()
4282 dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n"); in _dwc2_hcd_start()
4287 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4302 /* Turn off all host-specific interrupts */ in _dwc2_hcd_stop()
4306 synchronize_irq(hcd->irq); in _dwc2_hcd_stop()
4308 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_stop()
4313 hsotg->lx_state = DWC2_L3; in _dwc2_hcd_stop()
4314 hcd->state = HC_STATE_HALT; in _dwc2_hcd_stop()
4315 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_stop()
4316 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_stop()
4331 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4336 if (hsotg->lx_state != DWC2_L0) in _dwc2_hcd_suspend()
4342 if (hsotg->op_state == OTG_STATE_B_PERIPHERAL) in _dwc2_hcd_suspend()
4345 if (hsotg->bus_suspended) in _dwc2_hcd_suspend()
4351 switch (hsotg->params.power_down) { in _dwc2_hcd_suspend()
4356 dev_err(hsotg->dev, in _dwc2_hcd_suspend()
4359 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_suspend()
4363 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4366 dev_err(hsotg->dev, "enter hibernation failed\n"); in _dwc2_hcd_suspend()
4367 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4370 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_suspend()
4377 if (!hsotg->params.no_clock_gating) { in _dwc2_hcd_suspend()
4381 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_suspend()
4388 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4390 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4393 if (!IS_ERR_OR_NULL(hsotg->uphy)) { in _dwc2_hcd_suspend()
4394 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4395 usb_phy_set_suspend(hsotg->uphy, true); in _dwc2_hcd_suspend()
4396 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4400 hsotg->lx_state = DWC2_L2; in _dwc2_hcd_suspend()
4402 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4414 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4419 if (hsotg->lx_state != DWC2_L2) in _dwc2_hcd_resume()
4430 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_resume()
4431 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4435 switch (hsotg->params.power_down) { in _dwc2_hcd_resume()
4439 dev_err(hsotg->dev, in _dwc2_hcd_resume()
4445 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_resume()
4450 dev_err(hsotg->dev, "exit hibernation failed.\n"); in _dwc2_hcd_resume()
4456 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_resume()
4463 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4473 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4479 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in _dwc2_hcd_resume()
4482 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4487 hsotg->flags.b.port_suspend_change = 1; in _dwc2_hcd_resume()
4494 if (!IS_ERR_OR_NULL(hsotg->uphy)) { in _dwc2_hcd_resume()
4495 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4496 usb_phy_set_suspend(hsotg->uphy, false); in _dwc2_hcd_resume()
4497 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4501 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4504 /* Wait for controller to correctly update D+/D- level */ in _dwc2_hcd_resume()
4506 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4516 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4518 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4520 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4541 dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb); in dwc2_dump_urb_info()
4542 dev_vdbg(hsotg->dev, " Device address: %d\n", in dwc2_dump_urb_info()
4543 usb_pipedevice(urb->pipe)); in dwc2_dump_urb_info()
4544 dev_vdbg(hsotg->dev, " Endpoint: %d, %s\n", in dwc2_dump_urb_info()
4545 usb_pipeendpoint(urb->pipe), in dwc2_dump_urb_info()
4546 usb_pipein(urb->pipe) ? "IN" : "OUT"); in dwc2_dump_urb_info()
4548 switch (usb_pipetype(urb->pipe)) { in dwc2_dump_urb_info()
4563 dev_vdbg(hsotg->dev, " Endpoint type: %s %s (%s)\n", pipetype, in dwc2_dump_urb_info()
4564 usb_urb_dir_in(urb) ? "IN" : "OUT", usb_pipein(urb->pipe) ? in dwc2_dump_urb_info()
4567 switch (urb->dev->speed) { in dwc2_dump_urb_info()
4582 dev_vdbg(hsotg->dev, " Speed: %s\n", speed); in dwc2_dump_urb_info()
4583 dev_vdbg(hsotg->dev, " Max packet size: %d (%d mult)\n", in dwc2_dump_urb_info()
4584 usb_endpoint_maxp(&urb->ep->desc), in dwc2_dump_urb_info()
4585 usb_endpoint_maxp_mult(&urb->ep->desc)); in dwc2_dump_urb_info()
4587 dev_vdbg(hsotg->dev, " Data buffer length: %d\n", in dwc2_dump_urb_info()
4588 urb->transfer_buffer_length); in dwc2_dump_urb_info()
4589 dev_vdbg(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n", in dwc2_dump_urb_info()
4590 urb->transfer_buffer, (unsigned long)urb->transfer_dma); in dwc2_dump_urb_info()
4591 dev_vdbg(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n", in dwc2_dump_urb_info()
4592 urb->setup_packet, (unsigned long)urb->setup_dma); in dwc2_dump_urb_info()
4593 dev_vdbg(hsotg->dev, " Interval: %d\n", urb->interval); in dwc2_dump_urb_info()
4595 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { in dwc2_dump_urb_info()
4598 for (i = 0; i < urb->number_of_packets; i++) { in dwc2_dump_urb_info()
4599 dev_vdbg(hsotg->dev, " ISO Desc %d:\n", i); in dwc2_dump_urb_info()
4600 dev_vdbg(hsotg->dev, " offset: %d, length %d\n", in dwc2_dump_urb_info()
4601 urb->iso_frame_desc[i].offset, in dwc2_dump_urb_info()
4602 urb->iso_frame_desc[i].length); in dwc2_dump_urb_info()
4617 struct usb_host_endpoint *ep = urb->ep; in _dwc2_hcd_urb_enqueue()
4631 gr = &hsotg->gr_backup; in _dwc2_hcd_urb_enqueue()
4634 dev_vdbg(hsotg->dev, "DWC OTG HCD URB Enqueue\n"); in _dwc2_hcd_urb_enqueue()
4638 if (hsotg->hibernated) { in _dwc2_hcd_urb_enqueue()
4639 if (gr->gotgctl & GOTGCTL_CURMODE_HOST) in _dwc2_hcd_urb_enqueue()
4645 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4649 if (hsotg->in_ppd) { in _dwc2_hcd_urb_enqueue()
4652 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4656 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && in _dwc2_hcd_urb_enqueue()
4657 hsotg->bus_suspended && !hsotg->params.no_clock_gating) { in _dwc2_hcd_urb_enqueue()
4665 return -EINVAL; in _dwc2_hcd_urb_enqueue()
4667 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS || in _dwc2_hcd_urb_enqueue()
4668 usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { in _dwc2_hcd_urb_enqueue()
4669 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4672 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4675 switch (usb_pipetype(urb->pipe)) { in _dwc2_hcd_urb_enqueue()
4690 dwc2_urb = dwc2_hcd_urb_alloc(hsotg, urb->number_of_packets, in _dwc2_hcd_urb_enqueue()
4693 return -ENOMEM; in _dwc2_hcd_urb_enqueue()
4695 dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, usb_pipedevice(urb->pipe), in _dwc2_hcd_urb_enqueue()
4696 usb_pipeendpoint(urb->pipe), ep_type, in _dwc2_hcd_urb_enqueue()
4697 usb_pipein(urb->pipe), in _dwc2_hcd_urb_enqueue()
4698 usb_endpoint_maxp(&ep->desc), in _dwc2_hcd_urb_enqueue()
4699 usb_endpoint_maxp_mult(&ep->desc)); in _dwc2_hcd_urb_enqueue()
4701 buf = urb->transfer_buffer; in _dwc2_hcd_urb_enqueue()
4704 if (!buf && (urb->transfer_dma & 3)) { in _dwc2_hcd_urb_enqueue()
4705 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4708 retval = -EINVAL; in _dwc2_hcd_urb_enqueue()
4713 if (!(urb->transfer_flags & URB_NO_INTERRUPT)) in _dwc2_hcd_urb_enqueue()
4715 if (urb->transfer_flags & URB_ZERO_PACKET) in _dwc2_hcd_urb_enqueue()
4718 dwc2_urb->priv = urb; in _dwc2_hcd_urb_enqueue()
4719 dwc2_urb->buf = buf; in _dwc2_hcd_urb_enqueue()
4720 dwc2_urb->dma = urb->transfer_dma; in _dwc2_hcd_urb_enqueue()
4721 dwc2_urb->length = urb->transfer_buffer_length; in _dwc2_hcd_urb_enqueue()
4722 dwc2_urb->setup_packet = urb->setup_packet; in _dwc2_hcd_urb_enqueue()
4723 dwc2_urb->setup_dma = urb->setup_dma; in _dwc2_hcd_urb_enqueue()
4724 dwc2_urb->flags = tflags; in _dwc2_hcd_urb_enqueue()
4725 dwc2_urb->interval = urb->interval; in _dwc2_hcd_urb_enqueue()
4726 dwc2_urb->status = -EINPROGRESS; in _dwc2_hcd_urb_enqueue()
4728 for (i = 0; i < urb->number_of_packets; ++i) in _dwc2_hcd_urb_enqueue()
4730 urb->iso_frame_desc[i].offset, in _dwc2_hcd_urb_enqueue()
4731 urb->iso_frame_desc[i].length); in _dwc2_hcd_urb_enqueue()
4733 urb->hcpriv = dwc2_urb; in _dwc2_hcd_urb_enqueue()
4734 qh = (struct dwc2_qh *)ep->hcpriv; in _dwc2_hcd_urb_enqueue()
4739 retval = -ENOMEM; in _dwc2_hcd_urb_enqueue()
4742 ep->hcpriv = qh; in _dwc2_hcd_urb_enqueue()
4748 retval = -ENOMEM; in _dwc2_hcd_urb_enqueue()
4752 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4767 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4772 dwc2_urb->priv = NULL; in _dwc2_hcd_urb_enqueue()
4774 if (qh_allocated && qh->channel && qh->channel->qh == qh) in _dwc2_hcd_urb_enqueue()
4775 qh->channel->qh = NULL; in _dwc2_hcd_urb_enqueue()
4777 urb->hcpriv = NULL; in _dwc2_hcd_urb_enqueue()
4778 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4784 ep->hcpriv = NULL; in _dwc2_hcd_urb_enqueue()
4787 list_for_each_entry_safe(qtd2, qtd2_tmp, &qh->qtd_list, in _dwc2_hcd_urb_enqueue()
4808 dev_dbg(hsotg->dev, "DWC OTG HCD URB Dequeue\n"); in _dwc2_hcd_urb_dequeue()
4811 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4817 if (!urb->hcpriv) { in _dwc2_hcd_urb_dequeue()
4818 dev_dbg(hsotg->dev, "## urb->hcpriv is NULL ##\n"); in _dwc2_hcd_urb_dequeue()
4822 rc = dwc2_hcd_urb_dequeue(hsotg, urb->hcpriv); in _dwc2_hcd_urb_dequeue()
4826 kfree(urb->hcpriv); in _dwc2_hcd_urb_dequeue()
4827 urb->hcpriv = NULL; in _dwc2_hcd_urb_dequeue()
4830 spin_unlock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4832 spin_lock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4834 dev_dbg(hsotg->dev, "Called usb_hcd_giveback_urb()\n"); in _dwc2_hcd_urb_dequeue()
4835 dev_dbg(hsotg->dev, " urb->status = %d\n", urb->status); in _dwc2_hcd_urb_dequeue()
4837 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4852 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_disable()
4853 "DWC OTG HCD EP DISABLE: bEndpointAddress=0x%02x, ep->hcpriv=%p\n", in _dwc2_hcd_endpoint_disable()
4854 ep->desc.bEndpointAddress, ep->hcpriv); in _dwc2_hcd_endpoint_disable()
4869 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_reset()
4871 ep->desc.bEndpointAddress); in _dwc2_hcd_endpoint_reset()
4873 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4875 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4906 /* Handles hub class-specific requests */
4923 qh = ep->hcpriv; in _dwc2_hcd_clear_tt_buffer_complete()
4927 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4928 qh->tt_buffer_dirty = 0; in _dwc2_hcd_clear_tt_buffer_complete()
4930 if (hsotg->flags.b.port_connect_status) in _dwc2_hcd_clear_tt_buffer_complete()
4933 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4944 if (hsotg->params.speed == speed) in dwc2_change_bus_speed()
4947 hsotg->params.speed = speed; in dwc2_change_bus_speed()
4948 queue_work(hsotg->wq_otg, &hsotg->wf_otg); in dwc2_change_bus_speed()
4955 if (!hsotg->params.change_speed_quirk) in dwc2_free_dev()
4959 * On removal, set speed to default high-speed. in dwc2_free_dev()
4961 if (udev->parent && udev->parent->speed > USB_SPEED_UNKNOWN && in dwc2_free_dev()
4962 udev->parent->speed < USB_SPEED_HIGH) { in dwc2_free_dev()
4963 dev_info(hsotg->dev, "Set speed to default high-speed\n"); in dwc2_free_dev()
4972 if (!hsotg->params.change_speed_quirk) in dwc2_reset_device()
4975 if (udev->speed == USB_SPEED_HIGH) { in dwc2_reset_device()
4976 dev_info(hsotg->dev, "Set speed to high-speed\n"); in dwc2_reset_device()
4978 } else if ((udev->speed == USB_SPEED_FULL || in dwc2_reset_device()
4979 udev->speed == USB_SPEED_LOW)) { in dwc2_reset_device()
4981 * Change speed setting to full-speed if there's in dwc2_reset_device()
4982 * a full-speed or low-speed device plugged in. in dwc2_reset_device()
4984 dev_info(hsotg->dev, "Set speed to full-speed\n"); in dwc2_reset_device()
5028 dev_dbg(hsotg->dev, "DWC OTG HCD FREE\n"); in dwc2_hcd_free()
5031 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_inactive); in dwc2_hcd_free()
5032 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_waiting); in dwc2_hcd_free()
5033 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_active); in dwc2_hcd_free()
5034 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_inactive); in dwc2_hcd_free()
5035 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_ready); in dwc2_hcd_free()
5036 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_assigned); in dwc2_hcd_free()
5037 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_queued); in dwc2_hcd_free()
5041 struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_free()
5044 dev_dbg(hsotg->dev, "HCD Free channel #%i, chan=%p\n", in dwc2_hcd_free()
5046 hsotg->hc_ptr_array[i] = NULL; in dwc2_hcd_free()
5051 if (hsotg->params.host_dma) { in dwc2_hcd_free()
5052 if (hsotg->status_buf) { in dwc2_hcd_free()
5053 dma_free_coherent(hsotg->dev, DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_free()
5054 hsotg->status_buf, in dwc2_hcd_free()
5055 hsotg->status_buf_dma); in dwc2_hcd_free()
5056 hsotg->status_buf = NULL; in dwc2_hcd_free()
5059 kfree(hsotg->status_buf); in dwc2_hcd_free()
5060 hsotg->status_buf = NULL; in dwc2_hcd_free()
5070 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) { in dwc2_hcd_free()
5076 if (hsotg->wq_otg) { in dwc2_hcd_free()
5077 if (!cancel_work_sync(&hsotg->wf_otg)) in dwc2_hcd_free()
5078 flush_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
5079 destroy_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
5082 cancel_work_sync(&hsotg->phy_reset_work); in dwc2_hcd_free()
5084 del_timer(&hsotg->wkp_timer); in dwc2_hcd_free()
5089 /* Turn off all host-specific interrupts */ in dwc2_hcd_release()
5098 * USB bus with the core and calls the hc_driver->start() function. It returns
5103 struct platform_device *pdev = to_platform_device(hsotg->dev); in dwc2_hcd_init()
5112 return -ENODEV; in dwc2_hcd_init()
5114 dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); in dwc2_hcd_init()
5116 retval = -ENOMEM; in dwc2_hcd_init()
5119 dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); in dwc2_hcd_init()
5122 hsotg->frame_num_array = kcalloc(FRAME_NUM_ARRAY_SIZE, in dwc2_hcd_init()
5123 sizeof(*hsotg->frame_num_array), in dwc2_hcd_init()
5125 if (!hsotg->frame_num_array) in dwc2_hcd_init()
5127 hsotg->last_frame_num_array = in dwc2_hcd_init()
5129 sizeof(*hsotg->last_frame_num_array), GFP_KERNEL); in dwc2_hcd_init()
5130 if (!hsotg->last_frame_num_array) in dwc2_hcd_init()
5133 hsotg->last_frame_num = HFNUM_MAX_FRNUM; in dwc2_hcd_init()
5136 if (hsotg->params.host_dma && in dwc2_hcd_init()
5137 !hsotg->dev->dma_mask) { in dwc2_hcd_init()
5138 dev_warn(hsotg->dev, in dwc2_hcd_init()
5140 hsotg->params.host_dma = false; in dwc2_hcd_init()
5141 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5145 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5146 if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5147 dev_warn(hsotg->dev, "can't set DMA mask\n"); in dwc2_hcd_init()
5148 if (dma_set_coherent_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5149 dev_warn(hsotg->dev, "can't set coherent DMA mask\n"); in dwc2_hcd_init()
5152 if (hsotg->params.change_speed_quirk) { in dwc2_hcd_init()
5157 if (hsotg->params.host_dma) in dwc2_hcd_init()
5160 hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev)); in dwc2_hcd_init()
5164 hcd->has_tt = 1; in dwc2_hcd_init()
5168 retval = -EINVAL; in dwc2_hcd_init()
5171 hcd->rsrc_start = res->start; in dwc2_hcd_init()
5172 hcd->rsrc_len = resource_size(res); in dwc2_hcd_init()
5174 ((struct wrapper_priv_data *)&hcd->hcd_priv)->hsotg = hsotg; in dwc2_hcd_init()
5175 hsotg->priv = hcd; in dwc2_hcd_init()
5189 retval = -ENOMEM; in dwc2_hcd_init()
5190 hsotg->wq_otg = alloc_ordered_workqueue("dwc2", 0); in dwc2_hcd_init()
5191 if (!hsotg->wq_otg) { in dwc2_hcd_init()
5192 dev_err(hsotg->dev, "Failed to create workqueue\n"); in dwc2_hcd_init()
5195 INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change); in dwc2_hcd_init()
5197 timer_setup(&hsotg->wkp_timer, dwc2_wakeup_detected, 0); in dwc2_hcd_init()
5199 /* Initialize the non-periodic schedule */ in dwc2_hcd_init()
5200 INIT_LIST_HEAD(&hsotg->non_periodic_sched_inactive); in dwc2_hcd_init()
5201 INIT_LIST_HEAD(&hsotg->non_periodic_sched_waiting); in dwc2_hcd_init()
5202 INIT_LIST_HEAD(&hsotg->non_periodic_sched_active); in dwc2_hcd_init()
5205 INIT_LIST_HEAD(&hsotg->periodic_sched_inactive); in dwc2_hcd_init()
5206 INIT_LIST_HEAD(&hsotg->periodic_sched_ready); in dwc2_hcd_init()
5207 INIT_LIST_HEAD(&hsotg->periodic_sched_assigned); in dwc2_hcd_init()
5208 INIT_LIST_HEAD(&hsotg->periodic_sched_queued); in dwc2_hcd_init()
5210 INIT_LIST_HEAD(&hsotg->split_order); in dwc2_hcd_init()
5216 INIT_LIST_HEAD(&hsotg->free_hc_list); in dwc2_hcd_init()
5217 num_channels = hsotg->params.host_channels; in dwc2_hcd_init()
5218 memset(&hsotg->hc_ptr_array[0], 0, sizeof(hsotg->hc_ptr_array)); in dwc2_hcd_init()
5224 channel->hc_num = i; in dwc2_hcd_init()
5225 INIT_LIST_HEAD(&channel->split_order_list_entry); in dwc2_hcd_init()
5226 hsotg->hc_ptr_array[i] = channel; in dwc2_hcd_init()
5230 INIT_DELAYED_WORK(&hsotg->start_work, dwc2_hcd_start_func); in dwc2_hcd_init()
5231 INIT_DELAYED_WORK(&hsotg->reset_work, dwc2_hcd_reset_func); in dwc2_hcd_init()
5232 INIT_WORK(&hsotg->phy_reset_work, dwc2_hcd_phy_reset_func); in dwc2_hcd_init()
5240 if (hsotg->params.host_dma) in dwc2_hcd_init()
5241 hsotg->status_buf = dma_alloc_coherent(hsotg->dev, in dwc2_hcd_init()
5243 &hsotg->status_buf_dma, GFP_KERNEL); in dwc2_hcd_init()
5245 hsotg->status_buf = kzalloc(DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_init()
5248 if (!hsotg->status_buf) in dwc2_hcd_init()
5256 if (hsotg->params.dma_desc_enable || in dwc2_hcd_init()
5257 hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_init()
5258 hsotg->desc_gen_cache = kmem_cache_create("dwc2-gen-desc", in dwc2_hcd_init()
5262 if (!hsotg->desc_gen_cache) { in dwc2_hcd_init()
5263 dev_err(hsotg->dev, in dwc2_hcd_init()
5270 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5271 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5274 hsotg->desc_hsisoc_cache = kmem_cache_create("dwc2-hsisoc-desc", in dwc2_hcd_init()
5277 if (!hsotg->desc_hsisoc_cache) { in dwc2_hcd_init()
5278 dev_err(hsotg->dev, in dwc2_hcd_init()
5281 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5287 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5288 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5292 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5294 * Create kmem caches to handle non-aligned buffer in dwc2_hcd_init()
5297 hsotg->unaligned_cache = kmem_cache_create("dwc2-unaligned-dma", in dwc2_hcd_init()
5300 if (!hsotg->unaligned_cache) in dwc2_hcd_init()
5301 dev_err(hsotg->dev, in dwc2_hcd_init()
5305 hsotg->otg_port = 1; in dwc2_hcd_init()
5306 hsotg->frame_list = NULL; in dwc2_hcd_init()
5307 hsotg->frame_list_dma = 0; in dwc2_hcd_init()
5308 hsotg->periodic_qh_count = 0; in dwc2_hcd_init()
5311 hsotg->lx_state = DWC2_L3; in dwc2_hcd_init()
5313 hcd->self.otg_port = hsotg->otg_port; in dwc2_hcd_init()
5316 hcd->self.sg_tablesize = 0; in dwc2_hcd_init()
5318 hcd->tpl_support = of_usb_host_tpl_support(hsotg->dev->of_node); in dwc2_hcd_init()
5320 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_init()
5321 otg_set_host(hsotg->uphy->otg, &hcd->self); in dwc2_hcd_init()
5328 retval = usb_add_hcd(hcd, hsotg->irq, IRQF_SHARED); in dwc2_hcd_init()
5332 device_wakeup_enable(hcd->self.controller); in dwc2_hcd_init()
5341 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_init()
5342 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_init()
5343 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5351 kfree(hsotg->last_frame_num_array); in dwc2_hcd_init()
5352 kfree(hsotg->frame_num_array); in dwc2_hcd_init()
5355 dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval); in dwc2_hcd_init()
5367 dev_dbg(hsotg->dev, "DWC OTG HCD REMOVE\n"); in dwc2_hcd_remove()
5370 dev_dbg(hsotg->dev, "hsotg->hcd = %p\n", hcd); in dwc2_hcd_remove()
5373 dev_dbg(hsotg->dev, "%s: dwc2_hsotg_to_hcd(hsotg) NULL!\n", in dwc2_hcd_remove()
5378 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_remove()
5379 otg_set_host(hsotg->uphy->otg, NULL); in dwc2_hcd_remove()
5382 hsotg->priv = NULL; in dwc2_hcd_remove()
5384 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_remove()
5385 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_remove()
5386 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_remove()
5392 kfree(hsotg->last_frame_num_array); in dwc2_hcd_remove()
5393 kfree(hsotg->frame_num_array); in dwc2_hcd_remove()
5398 * dwc2_backup_host_registers() - Backup controller host registers.
5409 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_backup_host_registers()
5412 hr = &hsotg->hr_backup; in dwc2_backup_host_registers()
5413 hr->hcfg = dwc2_readl(hsotg, HCFG); in dwc2_backup_host_registers()
5414 hr->hflbaddr = dwc2_readl(hsotg, HFLBADDR); in dwc2_backup_host_registers()
5415 hr->haintmsk = dwc2_readl(hsotg, HAINTMSK); in dwc2_backup_host_registers()
5416 for (i = 0; i < hsotg->params.host_channels; ++i) { in dwc2_backup_host_registers()
5417 hr->hcchar[i] = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_backup_host_registers()
5418 hr->hcsplt[i] = dwc2_readl(hsotg, HCSPLT(i)); in dwc2_backup_host_registers()
5419 hr->hcintmsk[i] = dwc2_readl(hsotg, HCINTMSK(i)); in dwc2_backup_host_registers()
5420 hr->hctsiz[i] = dwc2_readl(hsotg, HCTSIZ(i)); in dwc2_backup_host_registers()
5421 hr->hcidma[i] = dwc2_readl(hsotg, HCDMA(i)); in dwc2_backup_host_registers()
5422 hr->hcidmab[i] = dwc2_readl(hsotg, HCDMAB(i)); in dwc2_backup_host_registers()
5425 hr->hprt0 = dwc2_read_hprt0(hsotg); in dwc2_backup_host_registers()
5426 hr->hfir = dwc2_readl(hsotg, HFIR); in dwc2_backup_host_registers()
5427 hr->hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ); in dwc2_backup_host_registers()
5428 hr->valid = true; in dwc2_backup_host_registers()
5434 * dwc2_restore_host_registers() - Restore controller host registers.
5445 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_restore_host_registers()
5448 hr = &hsotg->hr_backup; in dwc2_restore_host_registers()
5449 if (!hr->valid) { in dwc2_restore_host_registers()
5450 dev_err(hsotg->dev, "%s: no host registers to restore\n", in dwc2_restore_host_registers()
5452 return -EINVAL; in dwc2_restore_host_registers()
5454 hr->valid = false; in dwc2_restore_host_registers()
5456 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_restore_host_registers()
5457 dwc2_writel(hsotg, hr->hflbaddr, HFLBADDR); in dwc2_restore_host_registers()
5458 dwc2_writel(hsotg, hr->haintmsk, HAINTMSK); in dwc2_restore_host_registers()
5460 for (i = 0; i < hsotg->params.host_channels; ++i) { in dwc2_restore_host_registers()
5461 dwc2_writel(hsotg, hr->hcchar[i], HCCHAR(i)); in dwc2_restore_host_registers()
5462 dwc2_writel(hsotg, hr->hcsplt[i], HCSPLT(i)); in dwc2_restore_host_registers()
5463 dwc2_writel(hsotg, hr->hcintmsk[i], HCINTMSK(i)); in dwc2_restore_host_registers()
5464 dwc2_writel(hsotg, hr->hctsiz[i], HCTSIZ(i)); in dwc2_restore_host_registers()
5465 dwc2_writel(hsotg, hr->hcidma[i], HCDMA(i)); in dwc2_restore_host_registers()
5466 dwc2_writel(hsotg, hr->hcidmab[i], HCDMAB(i)); in dwc2_restore_host_registers()
5469 dwc2_writel(hsotg, hr->hprt0, HPRT0); in dwc2_restore_host_registers()
5470 dwc2_writel(hsotg, hr->hfir, HFIR); in dwc2_restore_host_registers()
5471 dwc2_writel(hsotg, hr->hptxfsiz, HPTXFSIZ); in dwc2_restore_host_registers()
5472 hsotg->frame_number = 0; in dwc2_restore_host_registers()
5478 * dwc2_host_enter_hibernation() - Put controller in Hibernation.
5491 dev_dbg(hsotg->dev, "Preparing host for hibernation\n"); in dwc2_host_enter_hibernation()
5494 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_host_enter_hibernation()
5500 dev_err(hsotg->dev, "%s: failed to backup host registers\n", in dwc2_host_enter_hibernation()
5513 dev_warn(hsotg->dev, "Suspend wasn't generated\n"); in dwc2_host_enter_hibernation()
5519 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5520 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_hibernation()
5578 hsotg->hibernated = 1; in dwc2_host_enter_hibernation()
5579 hsotg->bus_suspended = 1; in dwc2_host_enter_hibernation()
5580 dev_dbg(hsotg->dev, "Host hibernation completed\n"); in dwc2_host_enter_hibernation()
5581 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5592 * Return: non-zero if failed to enter to hibernation.
5595 * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
5606 gr = &hsotg->gr_backup; in dwc2_host_exit_hibernation()
5607 hr = &hsotg->hr_backup; in dwc2_host_exit_hibernation()
5609 dev_dbg(hsotg->dev, in dwc2_host_exit_hibernation()
5614 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5626 /* De-assert Restore */ in dwc2_host_exit_hibernation()
5633 dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); in dwc2_host_exit_hibernation()
5634 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_host_exit_hibernation()
5641 /* De-assert Wakeup Logic */ in dwc2_host_exit_hibernation()
5642 if (!(rem_wakeup && hsotg->hw_params.snpsid >= DWC2_CORE_REV_4_30a)) { in dwc2_host_exit_hibernation()
5649 hprt0 = hr->hprt0; in dwc2_host_exit_hibernation()
5655 hprt0 = hr->hprt0; in dwc2_host_exit_hibernation()
5672 /* De-assert Wakeup Logic */ in dwc2_host_exit_hibernation()
5673 if ((rem_wakeup && hsotg->hw_params.snpsid >= DWC2_CORE_REV_4_30a)) { in dwc2_host_exit_hibernation()
5699 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_host_exit_hibernation()
5707 dev_err(hsotg->dev, "%s: failed to restore host registers\n", in dwc2_host_exit_hibernation()
5715 * Change "port_connect_status_change" flag to re-enumerate, in dwc2_host_exit_hibernation()
5719 hsotg->flags.b.port_connect_status_change = 1; in dwc2_host_exit_hibernation()
5722 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5723 hsotg->bus_suspended = 0; in dwc2_host_exit_hibernation()
5724 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_hibernation()
5725 dev_dbg(hsotg->dev, "Host hibernation restore complete\n"); in dwc2_host_exit_hibernation()
5731 struct usb_device *root_hub = dwc2_hsotg_to_hcd(dwc2)->self.root_hub; in dwc2_host_can_poweroff_phy()
5734 if (!device_may_wakeup(dwc2->dev)) in dwc2_host_can_poweroff_phy()
5749 * dwc2_host_enter_partial_power_down() - Put controller in partial
5754 * Return: non-zero if failed to enter host partial power down.
5764 dev_dbg(hsotg->dev, "Entering host partial power down started.\n"); in dwc2_host_enter_partial_power_down()
5774 dev_warn(hsotg->dev, "Suspend wasn't generated\n"); in dwc2_host_enter_partial_power_down()
5779 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_host_enter_partial_power_down()
5786 dev_err(hsotg->dev, "%s: failed to backup host registers\n", in dwc2_host_enter_partial_power_down()
5812 hsotg->in_ppd = 1; in dwc2_host_enter_partial_power_down()
5813 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_partial_power_down()
5814 hsotg->bus_suspended = true; in dwc2_host_enter_partial_power_down()
5816 dev_dbg(hsotg->dev, "Entering host partial power down completed.\n"); in dwc2_host_enter_partial_power_down()
5822 * dwc2_host_exit_partial_power_down() - Exit controller from host partial
5829 * Return: non-zero if failed to exit host partial power down.
5840 dev_dbg(hsotg->dev, "Exiting host partial power down started.\n"); in dwc2_host_exit_partial_power_down()
5860 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_host_exit_partial_power_down()
5867 dev_err(hsotg->dev, "%s: failed to restore host registers\n", in dwc2_host_exit_partial_power_down()
5886 hsotg->bus_suspended = false; in dwc2_host_exit_partial_power_down()
5896 mod_timer(&hsotg->wkp_timer, in dwc2_host_exit_partial_power_down()
5901 hsotg->in_ppd = 0; in dwc2_host_exit_partial_power_down()
5902 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_partial_power_down()
5904 dev_dbg(hsotg->dev, "Exiting host partial power down completed.\n"); in dwc2_host_exit_partial_power_down()
5909 * dwc2_host_enter_clock_gating() - Put controller in clock gating.
5920 dev_dbg(hsotg->dev, "Entering host clock gating.\n"); in dwc2_host_enter_clock_gating()
5939 hsotg->bus_suspended = true; in dwc2_host_enter_clock_gating()
5940 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_clock_gating()
5944 * dwc2_host_exit_clock_gating() - Exit controller from clock gating.
5956 dev_dbg(hsotg->dev, "Exiting host clock gating.\n"); in dwc2_host_exit_clock_gating()
5986 hsotg->bus_suspended = false; in dwc2_host_exit_clock_gating()
5987 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_clock_gating()
5989 mod_timer(&hsotg->wkp_timer, in dwc2_host_exit_clock_gating()