Lines Matching refs:hsotg

42 static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg)  in dwc2_enable_common_interrupts()  argument
47 dwc2_writel(hsotg, 0xffffffff, GOTGINT); in dwc2_enable_common_interrupts()
50 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_enable_common_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()
66 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_enable_common_interrupts()
69 static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg) in dwc2_gahbcfg_init() argument
71 u32 ahbcfg = dwc2_readl(hsotg, GAHBCFG); in dwc2_gahbcfg_init()
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()
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()
98 dwc2_writel(hsotg, ahbcfg, GAHBCFG); in dwc2_gahbcfg_init()
103 static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) in dwc2_gusbcfg_init() argument
107 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_gusbcfg_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()
131 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_gusbcfg_init()
134 static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg) in dwc2_vbus_supply_init() argument
136 if (hsotg->vbus_supply) in dwc2_vbus_supply_init()
137 return regulator_enable(hsotg->vbus_supply); in dwc2_vbus_supply_init()
142 static int dwc2_vbus_supply_exit(struct dwc2_hsotg *hsotg) in dwc2_vbus_supply_exit() argument
144 if (hsotg->vbus_supply) in dwc2_vbus_supply_exit()
145 return regulator_disable(hsotg->vbus_supply); in dwc2_vbus_supply_exit()
155 static void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg) in dwc2_enable_host_interrupts() argument
159 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_enable_host_interrupts()
162 dwc2_writel(hsotg, 0, GINTMSK); in dwc2_enable_host_interrupts()
163 dwc2_writel(hsotg, 0, HAINTMSK); in dwc2_enable_host_interrupts()
166 dwc2_enable_common_interrupts(hsotg); in dwc2_enable_host_interrupts()
169 intmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_enable_host_interrupts()
171 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_enable_host_interrupts()
179 static void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg) in dwc2_disable_host_interrupts() argument
181 u32 intmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_disable_host_interrupts()
186 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_disable_host_interrupts()
196 static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg) in dwc2_calculate_dynamic_fifo() argument
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()
252 dev_err(hsotg->dev, "invalid fifo sizes\n"); in dwc2_calculate_dynamic_fifo()
255 static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) in dwc2_config_fifos() argument
257 struct dwc2_core_params *params = &hsotg->params; in dwc2_config_fifos()
263 dwc2_calculate_dynamic_fifo(hsotg); in dwc2_config_fifos()
266 grxfsiz = dwc2_readl(hsotg, GRXFSIZ); in dwc2_config_fifos()
267 dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); in dwc2_config_fifos()
271 dwc2_writel(hsotg, grxfsiz, GRXFSIZ); in dwc2_config_fifos()
272 dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", in dwc2_config_fifos()
273 dwc2_readl(hsotg, GRXFSIZ)); in dwc2_config_fifos()
276 dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n", in dwc2_config_fifos()
277 dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_config_fifos()
282 dwc2_writel(hsotg, nptxfsiz, GNPTXFSIZ); in dwc2_config_fifos()
283 dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n", in dwc2_config_fifos()
284 dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_config_fifos()
287 dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n", in dwc2_config_fifos()
288 dwc2_readl(hsotg, HPTXFSIZ)); in dwc2_config_fifos()
294 dwc2_writel(hsotg, hptxfsiz, HPTXFSIZ); in dwc2_config_fifos()
295 dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n", in dwc2_config_fifos()
296 dwc2_readl(hsotg, HPTXFSIZ)); 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()
305 dfifocfg = dwc2_readl(hsotg, GDFIFOCFG); in dwc2_config_fifos()
312 dwc2_writel(hsotg, dfifocfg, GDFIFOCFG); in dwc2_config_fifos()
326 u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg) in dwc2_calc_frame_interval() argument
332 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_calc_frame_interval()
333 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_calc_frame_interval()
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()
373 void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes) in dwc2_read_packet() argument
385 dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes); in dwc2_read_packet()
388 *data_buf = dwc2_readl(hsotg, HCFIFO(0)); in dwc2_read_packet()
402 static void dwc2_dump_channel_info(struct dwc2_hsotg *hsotg, in dwc2_dump_channel_info() argument
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()
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()
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()
462 static void dwc2_host_start(struct dwc2_hsotg *hsotg) in dwc2_host_start() argument
464 struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_host_start()
466 hcd->self.is_b_host = dwc2_hcd_is_b_host(hsotg); in dwc2_host_start()
470 static void dwc2_host_disconnect(struct dwc2_hsotg *hsotg) in dwc2_host_disconnect() argument
472 struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_host_disconnect()
477 static void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context, in dwc2_host_hub_info() argument
495 static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg, in dwc2_hc_enable_slave_ints() argument
503 dev_vdbg(hsotg->dev, "control/bulk\n"); in dwc2_hc_enable_slave_ints()
531 dev_vdbg(hsotg->dev, "intr\n"); in dwc2_hc_enable_slave_ints()
553 dev_vdbg(hsotg->dev, "isoc\n"); 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()
573 static void dwc2_hc_enable_dma_ints(struct dwc2_hsotg *hsotg, in dwc2_hc_enable_dma_ints() argument
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()
596 dev_vdbg(hsotg->dev, "setting ACK\n"); 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()
610 static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg, in dwc2_hc_enable_ints() argument
615 if (hsotg->params.host_dma) { in dwc2_hc_enable_ints()
617 dev_vdbg(hsotg->dev, "DMA enabled\n"); in dwc2_hc_enable_ints()
618 dwc2_hc_enable_dma_ints(hsotg, chan); in dwc2_hc_enable_ints()
621 dev_vdbg(hsotg->dev, "DMA disabled\n"); in dwc2_hc_enable_ints()
622 dwc2_hc_enable_slave_ints(hsotg, chan); in dwc2_hc_enable_ints()
626 intmsk = dwc2_readl(hsotg, HAINTMSK); in dwc2_hc_enable_ints()
628 dwc2_writel(hsotg, intmsk, HAINTMSK); in dwc2_hc_enable_ints()
630 dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk); in dwc2_hc_enable_ints()
633 intmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hc_enable_ints()
635 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_hc_enable_ints()
637 dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk); in dwc2_hc_enable_ints()
651 static void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) in dwc2_hc_init() argument
659 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_init()
664 dwc2_writel(hsotg, hcintmsk, HCINT(hc_num)); in dwc2_hc_init()
667 dwc2_hc_enable_ints(hsotg, chan); in dwc2_hc_init()
681 dwc2_writel(hsotg, hcchar, HCCHAR(hc_num)); 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()
690 dev_vdbg(hsotg->dev, " Ep Num: %d\n", in dwc2_hc_init()
692 dev_vdbg(hsotg->dev, " Is In: %d\n", in dwc2_hc_init()
694 dev_vdbg(hsotg->dev, " Is Low Speed: %d\n", in dwc2_hc_init()
696 dev_vdbg(hsotg->dev, " Ep Type: %d\n", in dwc2_hc_init()
698 dev_vdbg(hsotg->dev, " Max Pkt: %d\n", in dwc2_hc_init()
705 dev_vdbg(hsotg->dev, in dwc2_hc_init()
718 dev_vdbg(hsotg->dev, " comp split %d\n", in dwc2_hc_init()
720 dev_vdbg(hsotg->dev, " xact pos %d\n", in dwc2_hc_init()
722 dev_vdbg(hsotg->dev, " hub addr %d\n", in dwc2_hc_init()
724 dev_vdbg(hsotg->dev, " hub port %d\n", in dwc2_hc_init()
726 dev_vdbg(hsotg->dev, " is_in %d\n", in dwc2_hc_init()
728 dev_vdbg(hsotg->dev, " Max Pkt %d\n", in dwc2_hc_init()
730 dev_vdbg(hsotg->dev, " xferlen %d\n", in dwc2_hc_init()
735 dwc2_writel(hsotg, hcsplt, HCSPLT(hc_num)); in dwc2_hc_init()
766 void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, in dwc2_hc_halt() argument
772 dev_vdbg(hsotg->dev, "%s()\n", __func__); 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()
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()
821 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
843 dev_vdbg(hsotg->dev, 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()
871 dev_vdbg(hsotg->dev, "control/bulk\n"); in dwc2_hc_halt()
872 nptxsts = dwc2_readl(hsotg, GNPTXSTS); 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()
880 hptxsts = dwc2_readl(hsotg, HPTXSTS); 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()
898 dev_vdbg(hsotg->dev, "Channel enabled\n"); in dwc2_hc_halt()
903 dev_vdbg(hsotg->dev, "Channel disabled\n"); in dwc2_hc_halt()
908 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 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()
914 dev_vdbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hc_halt()
916 dev_vdbg(hsotg->dev, " halt_status: %d\n", in dwc2_hc_halt()
930 void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) in dwc2_hc_cleanup() argument
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()
958 static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, in dwc2_hc_set_even_odd_frame() argument
999 fifo_space = (dwc2_readl(hsotg, HPTXSTS) & in dwc2_hc_set_even_odd_frame()
1002 (hsotg->params.host_perio_tx_fifo_size - in dwc2_hc_set_even_odd_frame()
1018 frame_number = dwc2_hcd_get_future_frame_number(hsotg, xfer_us); in dwc2_hc_set_even_odd_frame()
1031 dwc2_sch_vdbg(hsotg, in dwc2_hc_set_even_odd_frame()
1093 static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg, in dwc2_hc_write_packet() argument
1103 dev_vdbg(hsotg->dev, "%s()\n", __func__); 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()
1139 static void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, in dwc2_hc_do_ping() argument
1146 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 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()
1192 static void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, in dwc2_hc_start_transfer() argument
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()
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()
1209 dwc2_hc_do_ping(hsotg, chan); in dwc2_hc_start_transfer()
1215 dev_vdbg(hsotg->dev, "ping, DMA\n"); in dwc2_hc_start_transfer()
1222 dev_vdbg(hsotg->dev, "split\n"); in dwc2_hc_start_transfer()
1247 dev_vdbg(hsotg->dev, "no split\n"); 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()
1322 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 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()
1340 dev_vdbg(hsotg->dev, "align_buf\n"); 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()
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()
1363 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); in dwc2_hc_start_transfer()
1366 dev_warn(hsotg->dev, 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()
1387 if (!hsotg->params.host_dma && in dwc2_hc_start_transfer()
1390 dwc2_hc_write_packet(hsotg, chan); in dwc2_hc_start_transfer()
1407 void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg, in dwc2_hc_start_transfer_ddma() argument
1430 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_start_transfer_ddma()
1432 dev_vdbg(hsotg->dev, " Start PID: %d\n", 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()
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()
1448 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1454 dev_warn(hsotg->dev, 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()
1496 static int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg, in dwc2_hc_continue_transfer() argument
1500 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_continue_transfer()
1524 u32 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1526 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); 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()
1542 u32 hcchar = dwc2_readl(hsotg, in dwc2_hc_continue_transfer()
1545 dwc2_hc_set_even_odd_frame(hsotg, chan, in dwc2_hc_continue_transfer()
1550 dwc2_hc_write_packet(hsotg, chan); in dwc2_hc_continue_transfer()
1570 static void dwc2_kill_urbs_in_qh_list(struct dwc2_hsotg *hsotg, in dwc2_kill_urbs_in_qh_list() argument
1579 dwc2_host_complete(hsotg, qtd, -ECONNRESET); in dwc2_kill_urbs_in_qh_list()
1580 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_kill_urbs_in_qh_list()
1585 static void dwc2_qh_list_free(struct dwc2_hsotg *hsotg, in dwc2_qh_list_free() argument
1596 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_qh_list_free()
1599 dwc2_kill_urbs_in_qh_list(hsotg, qh_list); in dwc2_qh_list_free()
1602 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_qh_list_free()
1607 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_qh_list_free()
1612 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_qh_list_free()
1613 dwc2_hcd_qh_free(hsotg, qh); 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()
1628 static void dwc2_kill_all_urbs(struct dwc2_hsotg *hsotg) in dwc2_kill_all_urbs() argument
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()
1644 void dwc2_hcd_start(struct dwc2_hsotg *hsotg) in dwc2_hcd_start() argument
1648 if (hsotg->op_state == OTG_STATE_B_HOST) { in dwc2_hcd_start()
1654 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_start()
1656 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_start()
1659 queue_delayed_work(hsotg->wq_otg, &hsotg->start_work, in dwc2_hcd_start()
1664 static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg) in dwc2_hcd_cleanup_channels() argument
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()
1677 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1681 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1687 channel = hsotg->hc_ptr_array[i]; in dwc2_hcd_cleanup_channels()
1690 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1694 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1697 dwc2_hc_cleanup(hsotg, channel); in dwc2_hcd_cleanup_channels()
1698 list_add_tail(&channel->hc_list_entry, &hsotg->free_hc_list); 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()
1723 void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) in dwc2_hcd_connect() argument
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()
1740 void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) in dwc2_hcd_disconnect() argument
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()
1754 intr = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_disconnect()
1756 dwc2_writel(hsotg, intr, GINTMSK); in dwc2_hcd_disconnect()
1758 dwc2_writel(hsotg, intr, GINTSTS); in dwc2_hcd_disconnect()
1765 if (dwc2_is_device_mode(hsotg)) { 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()
1768 dwc2_writel(hsotg, 0, HPRT0); in dwc2_hcd_disconnect()
1771 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_disconnect()
1775 dwc2_kill_all_urbs(hsotg); in dwc2_hcd_disconnect()
1777 if (dwc2_is_host_mode(hsotg)) in dwc2_hcd_disconnect()
1779 dwc2_hcd_cleanup_channels(hsotg); in dwc2_hcd_disconnect()
1781 dwc2_host_disconnect(hsotg); in dwc2_hcd_disconnect()
1796 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_disconnect()
1798 dwc2_hcd_connect(hsotg); in dwc2_hcd_disconnect()
1807 static void dwc2_hcd_rem_wakeup(struct dwc2_hsotg *hsotg) in dwc2_hcd_rem_wakeup() argument
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()
1825 void dwc2_hcd_stop(struct dwc2_hsotg *hsotg) in dwc2_hcd_stop() argument
1827 dev_dbg(hsotg->dev, "DWC OTG HCD STOP\n"); in dwc2_hcd_stop()
1836 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_stop()
1839 dev_dbg(hsotg->dev, "PortPower off\n"); in dwc2_hcd_stop()
1840 dwc2_writel(hsotg, 0, HPRT0); in dwc2_hcd_stop()
1844 static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_enqueue() argument
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()
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()
1864 u32 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_urb_enqueue()
1875 retval = dwc2_hcd_qtd_add(hsotg, qtd, qh); in dwc2_hcd_urb_enqueue()
1877 dev_err(hsotg->dev, in dwc2_hcd_urb_enqueue()
1883 intr_mask = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_urb_enqueue()
1895 tr_type = dwc2_hcd_select_transactions(hsotg); in dwc2_hcd_urb_enqueue()
1897 dwc2_hcd_queue_transactions(hsotg, tr_type); in dwc2_hcd_urb_enqueue()
1904 static int dwc2_hcd_urb_dequeue(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_dequeue() argument
1912 dev_dbg(hsotg->dev, "## Urb QTD is NULL ##\n"); in dwc2_hcd_urb_dequeue()
1918 dev_dbg(hsotg->dev, "## Urb QTD QH is NULL ##\n"); 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()
1947 dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); in dwc2_hcd_urb_dequeue()
1949 dwc2_hcd_qh_deactivate(hsotg, qh, 0); in dwc2_hcd_urb_dequeue()
1952 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_urb_dequeue()
1955 dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); in dwc2_hcd_urb_dequeue()
1962 static int dwc2_hcd_endpoint_disable(struct dwc2_hsotg *hsotg, in dwc2_hcd_endpoint_disable() argument
1970 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
1980 dev_err(hsotg->dev, 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()
1996 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_endpoint_disable()
2000 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_hcd_endpoint_disable()
2007 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2009 dwc2_hcd_qh_free(hsotg, qh); in dwc2_hcd_endpoint_disable()
2015 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2021 static int dwc2_hcd_endpoint_reset(struct dwc2_hsotg *hsotg, in dwc2_hcd_endpoint_reset() argument
2041 int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup) in dwc2_core_init() argument
2046 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_init()
2048 usbcfg = dwc2_readl(hsotg, GUSBCFG); 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()
2060 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_core_init()
2070 retval = dwc2_core_reset(hsotg, false); in dwc2_core_init()
2072 dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", in dwc2_core_init()
2081 retval = dwc2_phy_init(hsotg, initial_setup); in dwc2_core_init()
2086 retval = dwc2_gahbcfg_init(hsotg); in dwc2_core_init()
2091 dwc2_gusbcfg_init(hsotg); in dwc2_core_init()
2094 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_init()
2096 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_init()
2099 hsotg->srp_success = 0; in dwc2_core_init()
2102 dwc2_enable_common_interrupts(hsotg); in dwc2_core_init()
2108 if (dwc2_is_host_mode(hsotg)) { 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()
2129 static void dwc2_core_host_init(struct dwc2_hsotg *hsotg) in dwc2_core_host_init() argument
2133 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_host_init()
2143 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_core_host_init()
2145 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_core_host_init()
2148 dwc2_writel(hsotg, 0, PCGCTL); in dwc2_core_host_init()
2151 dwc2_init_fs_ls_pclk_sel(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()
2154 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_core_host_init()
2156 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_core_host_init()
2164 if (hsotg->params.reload_ctl) { in dwc2_core_host_init()
2165 hfir = dwc2_readl(hsotg, HFIR); in dwc2_core_host_init()
2167 dwc2_writel(hsotg, hfir, HFIR); 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()
2180 dev_err(hsotg->dev, in dwc2_core_host_init()
2182 hsotg->params.dma_desc_enable = false; in dwc2_core_host_init()
2184 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_core_host_init()
2186 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_core_host_init()
2191 dwc2_config_fifos(hsotg); in dwc2_core_host_init()
2195 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_host_init()
2197 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_host_init()
2200 dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */); in dwc2_core_host_init()
2201 dwc2_flush_rx_fifo(hsotg); in dwc2_core_host_init()
2204 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_host_init()
2206 dwc2_writel(hsotg, otgctl, GOTGCTL); 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()
2215 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_core_host_init()
2220 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_core_host_init()
2226 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_core_host_init()
2230 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_core_host_init()
2231 dev_dbg(hsotg->dev, "%s: Halt channel %d\n", in dwc2_core_host_init()
2234 if (dwc2_hsotg_wait_bit_clear(hsotg, HCCHAR(i), in dwc2_core_host_init()
2237 dev_warn(hsotg->dev, in dwc2_core_host_init()
2246 dwc2_enable_acg(hsotg); 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()
2251 u32 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_core_host_init()
2253 dev_dbg(hsotg->dev, "Init: Power Port (%d)\n", in dwc2_core_host_init()
2257 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_core_host_init()
2261 dwc2_enable_host_interrupts(hsotg); in dwc2_core_host_init()
2269 static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg) in dwc2_hcd_reinit() argument
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()
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()
2298 dwc2_hc_cleanup(hsotg, chan); in dwc2_hcd_reinit()
2302 dwc2_core_host_init(hsotg); in dwc2_hcd_reinit()
2305 static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg, in dwc2_hc_init_split() argument
2314 dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port); in dwc2_hc_init_split()
2319 static void dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg, in dwc2_hc_init_xfer() argument
2332 dev_vdbg(hsotg->dev, " Control setup transaction\n"); in dwc2_hc_init_xfer()
2336 if (hsotg->params.host_dma) in dwc2_hc_init_xfer()
2344 dev_vdbg(hsotg->dev, " Control data transaction\n"); in dwc2_hc_init_xfer()
2353 dev_vdbg(hsotg->dev, " Control status transaction\n"); 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()
2381 if (hsotg->params.dma_desc_enable) in dwc2_hc_init_xfer()
2387 if (hsotg->params.host_dma) { in dwc2_hc_init_xfer()
2409 static int dwc2_alloc_split_dma_aligned_buf(struct dwc2_hsotg *hsotg, in dwc2_alloc_split_dma_aligned_buf() argument
2413 if (!hsotg->unaligned_cache || 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()
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()
2544 static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) in dwc2_assign_and_init_hc() argument
2551 dev_vdbg(hsotg->dev, "%s(%p,%p)\n", __func__, hsotg, qh); in dwc2_assign_and_init_hc()
2554 dev_dbg(hsotg->dev, "No QTDs in QH list\n"); 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()
2563 chan = list_first_entry(&hsotg->free_hc_list, struct dwc2_host_chan, in dwc2_assign_and_init_hc()
2610 if (hsotg->params.host_dma) in dwc2_assign_and_init_hc()
2620 dwc2_hc_init_split(hsotg, chan, qtd, urb); in dwc2_assign_and_init_hc()
2625 dwc2_hc_init_xfer(hsotg, chan, qtd); in dwc2_assign_and_init_hc()
2628 if (hsotg->params.host_dma && qh->do_split && in dwc2_assign_and_init_hc()
2630 dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); in dwc2_assign_and_init_hc()
2631 if (dwc2_alloc_split_dma_aligned_buf(hsotg, qh, chan)) { in dwc2_assign_and_init_hc()
2632 dev_err(hsotg->dev, in dwc2_assign_and_init_hc()
2638 &hsotg->free_hc_list); in dwc2_assign_and_init_hc()
2648 WARN_ON_ONCE(hsotg->params.host_dma && in dwc2_assign_and_init_hc()
2661 if (hsotg->params.dma_desc_enable) { in dwc2_assign_and_init_hc()
2666 dwc2_hc_init(hsotg, chan); in dwc2_assign_and_init_hc()
2682 struct dwc2_hsotg *hsotg) in dwc2_hcd_select_transactions() argument
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()
2704 if (dwc2_assign_and_init_hc(hsotg, qh)) in dwc2_hcd_select_transactions()
2713 &hsotg->periodic_sched_assigned); in dwc2_hcd_select_transactions()
2722 num_channels = hsotg->params.host_channels; in dwc2_hcd_select_transactions()
2723 qh_ptr = hsotg->non_periodic_sched_inactive.next; in dwc2_hcd_select_transactions()
2724 while (qh_ptr != &hsotg->non_periodic_sched_inactive) { in dwc2_hcd_select_transactions()
2725 if (!hsotg->params.uframe_sched && in dwc2_hcd_select_transactions()
2726 hsotg->non_periodic_channels >= num_channels - in dwc2_hcd_select_transactions()
2727 hsotg->periodic_channels) in dwc2_hcd_select_transactions()
2729 if (list_empty(&hsotg->free_hc_list)) in dwc2_hcd_select_transactions()
2732 if (hsotg->params.uframe_sched) { in dwc2_hcd_select_transactions()
2733 if (hsotg->available_host_channels < 1) in dwc2_hcd_select_transactions()
2735 hsotg->available_host_channels--; in dwc2_hcd_select_transactions()
2738 if (dwc2_assign_and_init_hc(hsotg, qh)) in dwc2_hcd_select_transactions()
2747 &hsotg->non_periodic_sched_active); in dwc2_hcd_select_transactions()
2754 if (!hsotg->params.uframe_sched) in dwc2_hcd_select_transactions()
2755 hsotg->non_periodic_channels++; in dwc2_hcd_select_transactions()
2782 static int dwc2_queue_transaction(struct dwc2_hsotg *hsotg, in dwc2_queue_transaction() argument
2791 &hsotg->split_order); in dwc2_queue_transaction()
2793 if (hsotg->params.host_dma && chan->qh) { in dwc2_queue_transaction()
2794 if (hsotg->params.dma_desc_enable) { in dwc2_queue_transaction()
2797 dwc2_hcd_start_xfer_ddma(hsotg, chan->qh); in dwc2_queue_transaction()
2801 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2807 dwc2_hc_halt(hsotg, chan, chan->halt_status); in dwc2_queue_transaction()
2810 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2815 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2818 retval = dwc2_hc_continue_transfer(hsotg, chan); in dwc2_queue_transaction()
2825 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2828 retval = dwc2_hc_continue_transfer(hsotg, chan); in dwc2_queue_transaction()
2844 static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg) in dwc2_process_periodic_channels() argument
2857 if (list_empty(&hsotg->periodic_sched_assigned)) in dwc2_process_periodic_channels()
2861 dev_vdbg(hsotg->dev, "Queue periodic transactions\n"); in dwc2_process_periodic_channels()
2863 tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_process_periodic_channels()
2870 dev_vdbg(hsotg->dev, " P Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2872 dev_vdbg(hsotg->dev, " P Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2876 qh_ptr = hsotg->periodic_sched_assigned.next; in dwc2_process_periodic_channels()
2877 while (qh_ptr != &hsotg->periodic_sched_assigned) { in dwc2_process_periodic_channels()
2878 tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_process_periodic_channels()
2903 if (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2905 hsotg->queuing_high_bandwidth = 1; in dwc2_process_periodic_channels()
2909 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_periodic_channels()
2922 if (hsotg->params.host_dma || status == 0 || in dwc2_process_periodic_channels()
2930 &hsotg->periodic_sched_queued); in dwc2_process_periodic_channels()
2933 hsotg->queuing_high_bandwidth = 0; in dwc2_process_periodic_channels()
2939 (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2940 !list_empty(&hsotg->periodic_sched_assigned))) { in dwc2_process_periodic_channels()
2948 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_periodic_channels()
2951 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_periodic_channels()
2961 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_periodic_channels()
2964 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_periodic_channels()
2978 static void dwc2_process_non_periodic_channels(struct dwc2_hsotg *hsotg) in dwc2_process_non_periodic_channels() argument
2991 dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n"); in dwc2_process_non_periodic_channels()
2993 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
2998 dev_vdbg(hsotg->dev, " NP Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3000 dev_vdbg(hsotg->dev, " NP Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3007 if (hsotg->non_periodic_qh_ptr == &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3008 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3009 orig_qh_ptr = hsotg->non_periodic_qh_ptr; in dwc2_process_non_periodic_channels()
3016 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3019 if (!hsotg->params.host_dma && qspcavail == 0) { in dwc2_process_non_periodic_channels()
3024 qh = list_entry(hsotg->non_periodic_qh_ptr, struct dwc2_qh, in dwc2_process_non_periodic_channels()
3035 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_non_periodic_channels()
3045 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3046 if (hsotg->non_periodic_qh_ptr == in dwc2_process_non_periodic_channels()
3047 &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3048 hsotg->non_periodic_qh_ptr = in dwc2_process_non_periodic_channels()
3049 hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3050 } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr); in dwc2_process_non_periodic_channels()
3052 if (!hsotg->params.host_dma) { in dwc2_process_non_periodic_channels()
3053 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3058 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3061 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3073 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_non_periodic_channels()
3075 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_non_periodic_channels()
3084 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_non_periodic_channels()
3086 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_non_periodic_channels()
3102 void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg, in dwc2_hcd_queue_transactions() argument
3106 dev_vdbg(hsotg->dev, "Queue Transactions\n"); in dwc2_hcd_queue_transactions()
3111 dwc2_process_periodic_channels(hsotg); in dwc2_hcd_queue_transactions()
3116 if (!list_empty(&hsotg->non_periodic_sched_active)) { in dwc2_hcd_queue_transactions()
3117 dwc2_process_non_periodic_channels(hsotg); in dwc2_hcd_queue_transactions()
3123 u32 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_queue_transactions()
3126 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_hcd_queue_transactions()
3133 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_conn_id_status_change() local
3139 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_conn_id_status_change()
3141 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_conn_id_status_change()
3142 dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl); in dwc2_conn_id_status_change()
3143 dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n", in dwc2_conn_id_status_change()
3148 dwc2_vbus_supply_exit(hsotg); in dwc2_conn_id_status_change()
3150 dev_dbg(hsotg->dev, "connId B\n"); in dwc2_conn_id_status_change()
3151 if (hsotg->bus_suspended) { in dwc2_conn_id_status_change()
3152 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3154 dwc2_port_resume(hsotg); in dwc2_conn_id_status_change()
3156 while (!dwc2_is_device_mode(hsotg)) { in dwc2_conn_id_status_change()
3157 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3159 dwc2_is_host_mode(hsotg) ? "Host" : in dwc2_conn_id_status_change()
3167 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_conn_id_status_change()
3174 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3182 if (hsotg->in_ppd && hsotg->lx_state == DWC2_L2) in dwc2_conn_id_status_change()
3183 dwc2_exit_partial_power_down(hsotg, 0, false); in dwc2_conn_id_status_change()
3185 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_conn_id_status_change()
3186 dwc2_core_init(hsotg, false); in dwc2_conn_id_status_change()
3187 dwc2_enable_global_interrupts(hsotg); in dwc2_conn_id_status_change()
3188 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3189 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_conn_id_status_change()
3190 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3192 dwc2_enable_acg(hsotg); in dwc2_conn_id_status_change()
3193 dwc2_hsotg_core_connect(hsotg); in dwc2_conn_id_status_change()
3197 dev_dbg(hsotg->dev, "connId A\n"); in dwc2_conn_id_status_change()
3198 while (!dwc2_is_host_mode(hsotg)) { in dwc2_conn_id_status_change()
3199 dev_info(hsotg->dev, "Waiting for Host Mode, Mode=%s\n", in dwc2_conn_id_status_change()
3200 dwc2_is_host_mode(hsotg) ? in dwc2_conn_id_status_change()
3207 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3210 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3211 dwc2_hsotg_disconnect(hsotg); in dwc2_conn_id_status_change()
3212 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3214 hsotg->op_state = OTG_STATE_A_HOST; in dwc2_conn_id_status_change()
3216 dwc2_core_init(hsotg, false); in dwc2_conn_id_status_change()
3217 dwc2_enable_global_interrupts(hsotg); in dwc2_conn_id_status_change()
3218 dwc2_hcd_start(hsotg); in dwc2_conn_id_status_change()
3224 struct dwc2_hsotg *hsotg = from_timer(hsotg, t, wkp_timer); in dwc2_wakeup_detected() local
3227 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_wakeup_detected()
3233 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_wakeup_detected()
3234 dev_dbg(hsotg->dev, "Resume: HPRT0=%0x\n", hprt0); in dwc2_wakeup_detected()
3236 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_wakeup_detected()
3237 dev_dbg(hsotg->dev, "Clear Resume: HPRT0=%0x\n", in dwc2_wakeup_detected()
3238 dwc2_readl(hsotg, HPRT0)); in dwc2_wakeup_detected()
3240 dwc2_hcd_rem_wakeup(hsotg); in dwc2_wakeup_detected()
3241 hsotg->bus_suspended = false; in dwc2_wakeup_detected()
3244 hsotg->lx_state = DWC2_L0; in dwc2_wakeup_detected()
3247 static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg) in dwc2_host_is_b_hnp_enabled() argument
3249 struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_host_is_b_hnp_enabled()
3265 int dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) in dwc2_port_suspend() argument
3272 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_port_suspend()
3274 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_suspend()
3276 if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) { in dwc2_port_suspend()
3277 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_port_suspend()
3279 dwc2_writel(hsotg, gotgctl, GOTGCTL); in dwc2_port_suspend()
3280 hsotg->op_state = OTG_STATE_A_SUSPEND; in dwc2_port_suspend()
3283 switch (hsotg->params.power_down) { in dwc2_port_suspend()
3285 ret = dwc2_enter_partial_power_down(hsotg); in dwc2_port_suspend()
3287 dev_err(hsotg->dev, in dwc2_port_suspend()
3297 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3298 ret = dwc2_enter_hibernation(hsotg, 1); in dwc2_port_suspend()
3300 dev_err(hsotg->dev, "enter hibernation failed.\n"); in dwc2_port_suspend()
3301 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_suspend()
3308 if (!hsotg->params.no_clock_gating) in dwc2_port_suspend()
3309 dwc2_host_enter_clock_gating(hsotg); in dwc2_port_suspend()
3314 if (dwc2_host_is_b_hnp_enabled(hsotg)) { in dwc2_port_suspend()
3315 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_port_suspend()
3317 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_port_suspend()
3319 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3323 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3339 int dwc2_port_resume(struct dwc2_hsotg *hsotg) in dwc2_port_resume() argument
3344 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3346 switch (hsotg->params.power_down) { in dwc2_port_resume()
3348 ret = dwc2_exit_partial_power_down(hsotg, 0, true); in dwc2_port_resume()
3350 dev_err(hsotg->dev, in dwc2_port_resume()
3355 ret = dwc2_exit_hibernation(hsotg, 0, 0, 1); in dwc2_port_resume()
3357 dev_err(hsotg->dev, "exit hibernation failed.\n"); in dwc2_port_resume()
3364 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3365 dwc2_host_exit_clock_gating(hsotg, 0); in dwc2_port_resume()
3366 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3370 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3376 static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, in dwc2_hcd_hub_control() argument
3389 dev_dbg(hsotg->dev, "ClearHubFeature %1xh\n", wvalue); in dwc2_hcd_hub_control()
3399 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3411 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3413 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3415 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3419 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3422 if (hsotg->bus_suspended) in dwc2_hcd_hub_control()
3423 retval = dwc2_port_resume(hsotg); in dwc2_hcd_hub_control()
3427 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3429 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3432 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3434 dwc2_vbus_supply_exit(hsotg); in dwc2_hcd_hub_control()
3438 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3447 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3449 hsotg->flags.b.port_connect_status_change = 0; in dwc2_hcd_hub_control()
3454 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3456 hsotg->flags.b.port_reset_change = 0; in dwc2_hcd_hub_control()
3464 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3466 hsotg->flags.b.port_enable_change = 0; in dwc2_hcd_hub_control()
3475 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3477 hsotg->flags.b.port_suspend_change = 0; in dwc2_hcd_hub_control()
3481 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3483 hsotg->flags.b.port_l1_change = 0; in dwc2_hcd_hub_control()
3487 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3489 hsotg->flags.b.port_over_current_change = 0; in dwc2_hcd_hub_control()
3494 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3501 dev_dbg(hsotg->dev, "GetHubDescriptor\n"); in dwc2_hcd_hub_control()
3516 dev_dbg(hsotg->dev, "GetHubStatus\n"); in dwc2_hcd_hub_control()
3521 dev_vdbg(hsotg->dev, in dwc2_hcd_hub_control()
3523 hsotg->flags.d32); in dwc2_hcd_hub_control()
3528 if (hsotg->flags.b.port_connect_status_change) in dwc2_hcd_hub_control()
3530 if (hsotg->flags.b.port_enable_change) in dwc2_hcd_hub_control()
3532 if (hsotg->flags.b.port_suspend_change) in dwc2_hcd_hub_control()
3534 if (hsotg->flags.b.port_l1_change) in dwc2_hcd_hub_control()
3536 if (hsotg->flags.b.port_reset_change) in dwc2_hcd_hub_control()
3538 if (hsotg->flags.b.port_over_current_change) { in dwc2_hcd_hub_control()
3539 dev_warn(hsotg->dev, "Overcurrent change detected\n"); in dwc2_hcd_hub_control()
3543 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_hub_control()
3555 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_hub_control()
3556 dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); in dwc2_hcd_hub_control()
3581 if (hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_hub_control()
3586 if (hsotg->new_connection && in dwc2_hcd_hub_control()
3594 dev_info(hsotg->dev, "Enabling descriptor DMA mode\n"); in dwc2_hcd_hub_control()
3595 hsotg->params.dma_desc_enable = true; in dwc2_hcd_hub_control()
3596 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_hcd_hub_control()
3598 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_hcd_hub_control()
3599 hsotg->new_connection = false; in dwc2_hcd_hub_control()
3603 dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); in dwc2_hcd_hub_control()
3608 dev_dbg(hsotg->dev, "SetHubFeature\n"); in dwc2_hcd_hub_control()
3613 dev_dbg(hsotg->dev, "SetPortFeature\n"); in dwc2_hcd_hub_control()
3617 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_hub_control()
3630 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3632 if (windex != hsotg->otg_port) in dwc2_hcd_hub_control()
3634 if (!hsotg->bus_suspended) in dwc2_hcd_hub_control()
3635 retval = dwc2_port_suspend(hsotg, windex); in dwc2_hcd_hub_control()
3639 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3641 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3644 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3646 dwc2_vbus_supply_init(hsotg); in dwc2_hcd_hub_control()
3650 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3653 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3655 if (hsotg->hibernated) { in dwc2_hcd_hub_control()
3656 retval = dwc2_exit_hibernation(hsotg, 0, 1, 1); in dwc2_hcd_hub_control()
3658 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3662 if (hsotg->in_ppd) { in dwc2_hcd_hub_control()
3663 retval = dwc2_exit_partial_power_down(hsotg, 1, in dwc2_hcd_hub_control()
3666 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3670 if (hsotg->params.power_down == in dwc2_hcd_hub_control()
3671 DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended) in dwc2_hcd_hub_control()
3672 dwc2_host_exit_clock_gating(hsotg, 0); in dwc2_hcd_hub_control()
3674 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_hcd_hub_control()
3676 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_hcd_hub_control()
3678 dwc2_writel(hsotg, 0, PCGCTL); in dwc2_hcd_hub_control()
3680 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3690 if (!dwc2_hcd_is_b_host(hsotg)) { in dwc2_hcd_hub_control()
3692 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3694 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3696 dwc2_vbus_supply_init(hsotg); in dwc2_hcd_hub_control()
3702 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3703 hsotg->lx_state = DWC2_L0; /* Now back to On state */ in dwc2_hcd_hub_control()
3707 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3713 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3714 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3718 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3723 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3733 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3742 static int dwc2_hcd_is_status_changed(struct dwc2_hsotg *hsotg, int port) in dwc2_hcd_is_status_changed() argument
3749 retval = (hsotg->flags.b.port_connect_status_change || in dwc2_hcd_is_status_changed()
3750 hsotg->flags.b.port_reset_change || in dwc2_hcd_is_status_changed()
3751 hsotg->flags.b.port_enable_change || in dwc2_hcd_is_status_changed()
3752 hsotg->flags.b.port_suspend_change || in dwc2_hcd_is_status_changed()
3753 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3756 dev_dbg(hsotg->dev, in dwc2_hcd_is_status_changed()
3758 dev_dbg(hsotg->dev, " port_connect_status_change: %d\n", in dwc2_hcd_is_status_changed()
3759 hsotg->flags.b.port_connect_status_change); in dwc2_hcd_is_status_changed()
3760 dev_dbg(hsotg->dev, " port_reset_change: %d\n", in dwc2_hcd_is_status_changed()
3761 hsotg->flags.b.port_reset_change); in dwc2_hcd_is_status_changed()
3762 dev_dbg(hsotg->dev, " port_enable_change: %d\n", in dwc2_hcd_is_status_changed()
3763 hsotg->flags.b.port_enable_change); in dwc2_hcd_is_status_changed()
3764 dev_dbg(hsotg->dev, " port_suspend_change: %d\n", in dwc2_hcd_is_status_changed()
3765 hsotg->flags.b.port_suspend_change); in dwc2_hcd_is_status_changed()
3766 dev_dbg(hsotg->dev, " port_over_current_change: %d\n", in dwc2_hcd_is_status_changed()
3767 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3773 int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) in dwc2_hcd_get_frame_number() argument
3775 u32 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_get_frame_number()
3778 dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n", in dwc2_hcd_get_frame_number()
3784 int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us) in dwc2_hcd_get_future_frame_number() argument
3786 u32 hprt = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_get_future_frame_number()
3787 u32 hfir = dwc2_readl(hsotg, HFIR); in dwc2_hcd_get_future_frame_number()
3788 u32 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_get_future_frame_number()
3813 int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg) in dwc2_hcd_is_b_host() argument
3815 return hsotg->op_state == OTG_STATE_B_HOST; in dwc2_hcd_is_b_host()
3818 static struct dwc2_hcd_urb *dwc2_hcd_urb_alloc(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_alloc() argument
3830 static void dwc2_hcd_urb_set_pipeinfo(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_set_pipeinfo() argument
3838 dev_vdbg(hsotg->dev, in dwc2_hcd_urb_set_pipeinfo()
3853 void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg) in dwc2_hcd_dump_state() argument
3864 num_channels = hsotg->params.host_channels; in dwc2_hcd_dump_state()
3865 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3866 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3868 dev_dbg(hsotg->dev, "HCD State:\n"); in dwc2_hcd_dump_state()
3869 dev_dbg(hsotg->dev, " Num channels: %d\n", num_channels); in dwc2_hcd_dump_state()
3872 chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_dump_state()
3873 dev_dbg(hsotg->dev, " Channel %d:\n", i); in dwc2_hcd_dump_state()
3874 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3877 dev_dbg(hsotg->dev, " speed: %d\n", chan->speed); in dwc2_hcd_dump_state()
3878 dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); in dwc2_hcd_dump_state()
3879 dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); in dwc2_hcd_dump_state()
3880 dev_dbg(hsotg->dev, " data_pid_start: %d\n", in dwc2_hcd_dump_state()
3882 dev_dbg(hsotg->dev, " multi_count: %d\n", chan->multi_count); in dwc2_hcd_dump_state()
3883 dev_dbg(hsotg->dev, " xfer_started: %d\n", in dwc2_hcd_dump_state()
3885 dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); in dwc2_hcd_dump_state()
3886 dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", in dwc2_hcd_dump_state()
3888 dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); in dwc2_hcd_dump_state()
3889 dev_dbg(hsotg->dev, " xfer_count: %d\n", chan->xfer_count); in dwc2_hcd_dump_state()
3890 dev_dbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hcd_dump_state()
3892 dev_dbg(hsotg->dev, " halt_pending: %d\n", in dwc2_hcd_dump_state()
3894 dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); in dwc2_hcd_dump_state()
3895 dev_dbg(hsotg->dev, " do_split: %d\n", chan->do_split); in dwc2_hcd_dump_state()
3896 dev_dbg(hsotg->dev, " complete_split: %d\n", in dwc2_hcd_dump_state()
3898 dev_dbg(hsotg->dev, " hub_addr: %d\n", chan->hub_addr); in dwc2_hcd_dump_state()
3899 dev_dbg(hsotg->dev, " hub_port: %d\n", chan->hub_port); in dwc2_hcd_dump_state()
3900 dev_dbg(hsotg->dev, " xact_pos: %d\n", chan->xact_pos); in dwc2_hcd_dump_state()
3901 dev_dbg(hsotg->dev, " requests: %d\n", chan->requests); in dwc2_hcd_dump_state()
3902 dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); in dwc2_hcd_dump_state()
3907 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_dump_state()
3908 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_dump_state()
3909 hctsiz = dwc2_readl(hsotg, HCTSIZ(i)); in dwc2_hcd_dump_state()
3910 hcint = dwc2_readl(hsotg, HCINT(i)); in dwc2_hcd_dump_state()
3911 hcintmsk = dwc2_readl(hsotg, HCINTMSK(i)); in dwc2_hcd_dump_state()
3912 dev_dbg(hsotg->dev, " hfnum: 0x%08x\n", hfnum); in dwc2_hcd_dump_state()
3913 dev_dbg(hsotg->dev, " hcchar: 0x%08x\n", hcchar); in dwc2_hcd_dump_state()
3914 dev_dbg(hsotg->dev, " hctsiz: 0x%08x\n", hctsiz); in dwc2_hcd_dump_state()
3915 dev_dbg(hsotg->dev, " hcint: 0x%08x\n", hcint); in dwc2_hcd_dump_state()
3916 dev_dbg(hsotg->dev, " hcintmsk: 0x%08x\n", hcintmsk); in dwc2_hcd_dump_state()
3926 dev_dbg(hsotg->dev, " URB Info:\n"); in dwc2_hcd_dump_state()
3927 dev_dbg(hsotg->dev, " qtd: %p, urb: %p\n", in dwc2_hcd_dump_state()
3930 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3936 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3940 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3943 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3946 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3949 dev_dbg(hsotg->dev, " actual_length: %d\n", in dwc2_hcd_dump_state()
3955 dev_dbg(hsotg->dev, " non_periodic_channels: %d\n", in dwc2_hcd_dump_state()
3956 hsotg->non_periodic_channels); in dwc2_hcd_dump_state()
3957 dev_dbg(hsotg->dev, " periodic_channels: %d\n", in dwc2_hcd_dump_state()
3958 hsotg->periodic_channels); in dwc2_hcd_dump_state()
3959 dev_dbg(hsotg->dev, " periodic_usecs: %d\n", hsotg->periodic_usecs); in dwc2_hcd_dump_state()
3960 np_tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_hcd_dump_state()
3961 dev_dbg(hsotg->dev, " NP Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3963 dev_dbg(hsotg->dev, " NP Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3965 p_tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_hcd_dump_state()
3966 dev_dbg(hsotg->dev, " P Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3968 dev_dbg(hsotg->dev, " P Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3970 dwc2_dump_global_registers(hsotg); in dwc2_hcd_dump_state()
3971 dwc2_dump_host_registers(hsotg); in dwc2_hcd_dump_state()
3972 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3974 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3979 struct dwc2_hsotg *hsotg; member
3988 return p->hsotg; in dwc2_hcd_to_hsotg()
4011 struct dwc2_tt *dwc2_host_get_tt_info(struct dwc2_hsotg *hsotg, void *context, in dwc2_host_get_tt_info() argument
4059 void dwc2_host_put_tt_info(struct dwc2_hsotg *hsotg, struct dwc2_tt *dwc_tt) in dwc2_host_put_tt_info() argument
4074 int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context) in dwc2_host_get_speed() argument
4113 void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, in dwc2_host_complete() argument
4120 dev_dbg(hsotg->dev, "## %s: qtd is NULL ##\n", __func__); in dwc2_host_complete()
4125 dev_dbg(hsotg->dev, "## %s: qtd->urb is NULL ##\n", __func__); in dwc2_host_complete()
4131 dev_dbg(hsotg->dev, "## %s: urb->priv is NULL ##\n", __func__); in dwc2_host_complete()
4138 dev_vdbg(hsotg->dev, in dwc2_host_complete()
4158 dev_vdbg(hsotg->dev, " ISO Desc %d status %d\n", in dwc2_host_complete()
4174 dwc2_free_bus_bandwidth(dwc2_hsotg_to_hcd(hsotg), in dwc2_host_complete()
4175 dwc2_hcd_get_ep_bandwidth(hsotg, ep), in dwc2_host_complete()
4179 usb_hcd_unlink_urb_from_ep(dwc2_hsotg_to_hcd(hsotg), urb); in dwc2_host_complete()
4184 usb_hcd_giveback_urb(dwc2_hsotg_to_hcd(hsotg), urb, status); in dwc2_host_complete()
4192 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_start_func() local
4195 dev_dbg(hsotg->dev, "%s() %p\n", __func__, hsotg); in dwc2_hcd_start_func()
4196 dwc2_host_start(hsotg); in dwc2_hcd_start_func()
4204 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_reset_func() local
4209 dev_dbg(hsotg->dev, "USB RESET function called\n"); in dwc2_hcd_reset_func()
4211 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4213 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_reset_func()
4215 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_reset_func()
4216 hsotg->flags.b.port_reset_change = 1; in dwc2_hcd_reset_func()
4218 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4223 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_phy_reset_func() local
4227 ret = phy_reset(hsotg->phy); in dwc2_hcd_phy_reset_func()
4229 dev_warn(hsotg->dev, "PHY reset failed\n"); in dwc2_hcd_phy_reset_func()
4245 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_start() local
4251 dev_dbg(hsotg->dev, "DWC OTG HCD START\n"); in _dwc2_hcd_start()
4253 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4254 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_start()
4258 if (dwc2_is_device_mode(hsotg)) { in _dwc2_hcd_start()
4259 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4263 dwc2_hcd_reinit(hsotg); in _dwc2_hcd_start()
4265 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_start()
4269 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4270 ret = dwc2_vbus_supply_init(hsotg); in _dwc2_hcd_start()
4273 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4278 dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n"); in _dwc2_hcd_start()
4283 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4294 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_stop() local
4299 dwc2_disable_host_interrupts(hsotg); in _dwc2_hcd_stop()
4304 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_stop()
4305 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_stop()
4307 dwc2_hcd_disconnect(hsotg, true); in _dwc2_hcd_stop()
4308 dwc2_hcd_stop(hsotg); in _dwc2_hcd_stop()
4309 hsotg->lx_state = DWC2_L3; in _dwc2_hcd_stop()
4312 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_stop()
4316 dwc2_vbus_supply_exit(hsotg); in _dwc2_hcd_stop()
4323 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_suspend() local
4327 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4329 if (dwc2_is_device_mode(hsotg)) in _dwc2_hcd_suspend()
4332 if (hsotg->lx_state != DWC2_L0) in _dwc2_hcd_suspend()
4338 if (hsotg->op_state == OTG_STATE_B_PERIPHERAL) in _dwc2_hcd_suspend()
4341 if (hsotg->bus_suspended) in _dwc2_hcd_suspend()
4344 if (hsotg->flags.b.port_connect_status == 0) in _dwc2_hcd_suspend()
4347 switch (hsotg->params.power_down) { in _dwc2_hcd_suspend()
4350 ret = dwc2_enter_partial_power_down(hsotg); in _dwc2_hcd_suspend()
4352 dev_err(hsotg->dev, in _dwc2_hcd_suspend()
4359 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4360 ret = dwc2_enter_hibernation(hsotg, 1); in _dwc2_hcd_suspend()
4362 dev_err(hsotg->dev, "enter hibernation failed\n"); in _dwc2_hcd_suspend()
4363 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4373 if (!hsotg->params.no_clock_gating) { in _dwc2_hcd_suspend()
4374 dwc2_host_enter_clock_gating(hsotg); in _dwc2_hcd_suspend()
4384 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4385 dwc2_vbus_supply_exit(hsotg); in _dwc2_hcd_suspend()
4386 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4389 if (!IS_ERR_OR_NULL(hsotg->uphy)) { in _dwc2_hcd_suspend()
4390 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4391 usb_phy_set_suspend(hsotg->uphy, true); in _dwc2_hcd_suspend()
4392 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4396 hsotg->lx_state = DWC2_L2; in _dwc2_hcd_suspend()
4398 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4405 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_resume() local
4410 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4412 if (dwc2_is_device_mode(hsotg)) in _dwc2_hcd_resume()
4415 if (hsotg->lx_state != DWC2_L2) in _dwc2_hcd_resume()
4418 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_resume()
4426 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4430 switch (hsotg->params.power_down) { in _dwc2_hcd_resume()
4432 ret = dwc2_exit_partial_power_down(hsotg, 0, true); in _dwc2_hcd_resume()
4434 dev_err(hsotg->dev, in _dwc2_hcd_resume()
4443 ret = dwc2_exit_hibernation(hsotg, 0, 0, 1); in _dwc2_hcd_resume()
4445 dev_err(hsotg->dev, "exit hibernation failed.\n"); in _dwc2_hcd_resume()
4458 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4459 dwc2_host_exit_clock_gating(hsotg, 0); in _dwc2_hcd_resume()
4465 dwc2_core_init(hsotg, false); in _dwc2_hcd_resume()
4466 dwc2_enable_global_interrupts(hsotg); in _dwc2_hcd_resume()
4467 dwc2_hcd_reinit(hsotg); in _dwc2_hcd_resume()
4468 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4477 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4482 hsotg->flags.b.port_suspend_change = 1; in _dwc2_hcd_resume()
4489 if (!IS_ERR_OR_NULL(hsotg->uphy)) { in _dwc2_hcd_resume()
4490 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4491 usb_phy_set_suspend(hsotg->uphy, false); in _dwc2_hcd_resume()
4492 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4496 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4497 dwc2_vbus_supply_init(hsotg); in _dwc2_hcd_resume()
4501 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4507 dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET | in _dwc2_hcd_resume()
4511 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4513 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4515 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4523 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_get_frame_number() local
4525 return dwc2_hcd_get_frame_number(hsotg); in _dwc2_hcd_get_frame_number()
4532 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_dump_urb_info() local
4536 dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb); in dwc2_dump_urb_info()
4537 dev_vdbg(hsotg->dev, " Device address: %d\n", in dwc2_dump_urb_info()
4539 dev_vdbg(hsotg->dev, " Endpoint: %d, %s\n", in dwc2_dump_urb_info()
4558 dev_vdbg(hsotg->dev, " Endpoint type: %s %s (%s)\n", pipetype, in dwc2_dump_urb_info()
4577 dev_vdbg(hsotg->dev, " Speed: %s\n", speed); in dwc2_dump_urb_info()
4578 dev_vdbg(hsotg->dev, " Max packet size: %d (%d mult)\n", in dwc2_dump_urb_info()
4582 dev_vdbg(hsotg->dev, " Data buffer length: %d\n", in dwc2_dump_urb_info()
4584 dev_vdbg(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n", in dwc2_dump_urb_info()
4586 dev_vdbg(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n", in dwc2_dump_urb_info()
4588 dev_vdbg(hsotg->dev, " Interval: %d\n", urb->interval); in dwc2_dump_urb_info()
4594 dev_vdbg(hsotg->dev, " ISO Desc %d:\n", i); in dwc2_dump_urb_info()
4595 dev_vdbg(hsotg->dev, " offset: %d, length %d\n", in dwc2_dump_urb_info()
4611 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_urb_enqueue() local
4626 gr = &hsotg->gr_backup; in _dwc2_hcd_urb_enqueue()
4629 dev_vdbg(hsotg->dev, "DWC OTG HCD URB Enqueue\n"); in _dwc2_hcd_urb_enqueue()
4633 if (hsotg->hibernated) { in _dwc2_hcd_urb_enqueue()
4635 retval = dwc2_exit_hibernation(hsotg, 0, 0, 1); in _dwc2_hcd_urb_enqueue()
4637 retval = dwc2_exit_hibernation(hsotg, 0, 0, 0); in _dwc2_hcd_urb_enqueue()
4640 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4644 if (hsotg->in_ppd) { in _dwc2_hcd_urb_enqueue()
4645 retval = dwc2_exit_partial_power_down(hsotg, 0, true); in _dwc2_hcd_urb_enqueue()
4647 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4651 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && in _dwc2_hcd_urb_enqueue()
4652 hsotg->bus_suspended) { in _dwc2_hcd_urb_enqueue()
4653 if (dwc2_is_device_mode(hsotg)) in _dwc2_hcd_urb_enqueue()
4654 dwc2_gadget_exit_clock_gating(hsotg, 0); in _dwc2_hcd_urb_enqueue()
4656 dwc2_host_exit_clock_gating(hsotg, 0); in _dwc2_hcd_urb_enqueue()
4664 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4665 if (!dwc2_hcd_is_bandwidth_allocated(hsotg, ep)) in _dwc2_hcd_urb_enqueue()
4667 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4685 dwc2_urb = dwc2_hcd_urb_alloc(hsotg, urb->number_of_packets, in _dwc2_hcd_urb_enqueue()
4690 dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, usb_pipedevice(urb->pipe), in _dwc2_hcd_urb_enqueue()
4700 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4732 qh = dwc2_hcd_qh_create(hsotg, dwc2_urb, mem_flags); in _dwc2_hcd_urb_enqueue()
4747 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4752 retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, qh, qtd); in _dwc2_hcd_urb_enqueue()
4758 dwc2_hcd_get_ep_bandwidth(hsotg, ep), in _dwc2_hcd_urb_enqueue()
4762 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4772 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4780 dwc2_hcd_qh_unlink(hsotg, qh); in _dwc2_hcd_urb_enqueue()
4784 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh); in _dwc2_hcd_urb_enqueue()
4785 dwc2_hcd_qh_free(hsotg, qh); in _dwc2_hcd_urb_enqueue()
4799 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_urb_dequeue() local
4803 dev_dbg(hsotg->dev, "DWC OTG HCD URB Dequeue\n"); in _dwc2_hcd_urb_dequeue()
4806 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4813 dev_dbg(hsotg->dev, "## urb->hcpriv is NULL ##\n"); in _dwc2_hcd_urb_dequeue()
4817 rc = dwc2_hcd_urb_dequeue(hsotg, urb->hcpriv); in _dwc2_hcd_urb_dequeue()
4825 spin_unlock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4827 spin_lock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4829 dev_dbg(hsotg->dev, "Called usb_hcd_giveback_urb()\n"); in _dwc2_hcd_urb_dequeue()
4830 dev_dbg(hsotg->dev, " urb->status = %d\n", urb->status); in _dwc2_hcd_urb_dequeue()
4832 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4845 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_endpoint_disable() local
4847 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_disable()
4850 dwc2_hcd_endpoint_disable(hsotg, ep, 250); in _dwc2_hcd_endpoint_disable()
4861 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_endpoint_reset() local
4864 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_reset()
4868 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4869 dwc2_hcd_endpoint_reset(hsotg, ep); in _dwc2_hcd_endpoint_reset()
4870 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4882 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_irq() local
4884 return dwc2_handle_hcd_intr(hsotg); in _dwc2_hcd_irq()
4895 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_hub_status_data() local
4897 buf[0] = dwc2_hcd_is_status_changed(hsotg, 1) << 1; in _dwc2_hcd_hub_status_data()
4914 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_clear_tt_buffer_complete() local
4922 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4925 if (hsotg->flags.b.port_connect_status) in _dwc2_hcd_clear_tt_buffer_complete()
4926 dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_ALL); in _dwc2_hcd_clear_tt_buffer_complete()
4928 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4937 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_change_bus_speed() local
4939 if (hsotg->params.speed == speed) in dwc2_change_bus_speed()
4942 hsotg->params.speed = speed; in dwc2_change_bus_speed()
4943 queue_work(hsotg->wq_otg, &hsotg->wf_otg); in dwc2_change_bus_speed()
4948 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_free_dev() local
4950 if (!hsotg->params.change_speed_quirk) in dwc2_free_dev()
4958 dev_info(hsotg->dev, "Set speed to default high-speed\n"); in dwc2_free_dev()
4965 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_reset_device() local
4967 if (!hsotg->params.change_speed_quirk) in dwc2_reset_device()
4971 dev_info(hsotg->dev, "Set speed to high-speed\n"); in dwc2_reset_device()
4979 dev_info(hsotg->dev, "Set speed to full-speed\n"); in dwc2_reset_device()
5017 static void dwc2_hcd_free(struct dwc2_hsotg *hsotg) in dwc2_hcd_free() argument
5023 dev_dbg(hsotg->dev, "DWC OTG HCD FREE\n"); in dwc2_hcd_free()
5026 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_inactive); in dwc2_hcd_free()
5027 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_waiting); in dwc2_hcd_free()
5028 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_active); in dwc2_hcd_free()
5029 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_inactive); in dwc2_hcd_free()
5030 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_ready); in dwc2_hcd_free()
5031 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_assigned); in dwc2_hcd_free()
5032 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_queued); in dwc2_hcd_free()
5036 struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_free()
5039 dev_dbg(hsotg->dev, "HCD Free channel #%i, chan=%p\n", in dwc2_hcd_free()
5041 hsotg->hc_ptr_array[i] = NULL; in dwc2_hcd_free()
5046 if (hsotg->params.host_dma) { in dwc2_hcd_free()
5047 if (hsotg->status_buf) { in dwc2_hcd_free()
5048 dma_free_coherent(hsotg->dev, DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_free()
5049 hsotg->status_buf, in dwc2_hcd_free()
5050 hsotg->status_buf_dma); in dwc2_hcd_free()
5051 hsotg->status_buf = NULL; in dwc2_hcd_free()
5054 kfree(hsotg->status_buf); in dwc2_hcd_free()
5055 hsotg->status_buf = NULL; in dwc2_hcd_free()
5058 ahbcfg = dwc2_readl(hsotg, GAHBCFG); in dwc2_hcd_free()
5062 dwc2_writel(hsotg, ahbcfg, GAHBCFG); in dwc2_hcd_free()
5063 dwc2_writel(hsotg, 0, GINTMSK); in dwc2_hcd_free()
5065 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) { in dwc2_hcd_free()
5066 dctl = dwc2_readl(hsotg, DCTL); in dwc2_hcd_free()
5068 dwc2_writel(hsotg, dctl, DCTL); in dwc2_hcd_free()
5071 if (hsotg->wq_otg) { in dwc2_hcd_free()
5072 if (!cancel_work_sync(&hsotg->wf_otg)) in dwc2_hcd_free()
5073 flush_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
5074 destroy_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
5077 cancel_work_sync(&hsotg->phy_reset_work); in dwc2_hcd_free()
5079 del_timer(&hsotg->wkp_timer); in dwc2_hcd_free()
5082 static void dwc2_hcd_release(struct dwc2_hsotg *hsotg) in dwc2_hcd_release() argument
5085 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_release()
5087 dwc2_hcd_free(hsotg); in dwc2_hcd_release()
5096 int dwc2_hcd_init(struct dwc2_hsotg *hsotg) in dwc2_hcd_init() argument
5098 struct platform_device *pdev = to_platform_device(hsotg->dev); in dwc2_hcd_init()
5109 dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); in dwc2_hcd_init()
5113 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_hcd_init()
5114 dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); in dwc2_hcd_init()
5117 hsotg->frame_num_array = kcalloc(FRAME_NUM_ARRAY_SIZE, in dwc2_hcd_init()
5118 sizeof(*hsotg->frame_num_array), in dwc2_hcd_init()
5120 if (!hsotg->frame_num_array) in dwc2_hcd_init()
5122 hsotg->last_frame_num_array = in dwc2_hcd_init()
5124 sizeof(*hsotg->last_frame_num_array), GFP_KERNEL); in dwc2_hcd_init()
5125 if (!hsotg->last_frame_num_array) in dwc2_hcd_init()
5128 hsotg->last_frame_num = HFNUM_MAX_FRNUM; in dwc2_hcd_init()
5131 if (hsotg->params.host_dma && in dwc2_hcd_init()
5132 !hsotg->dev->dma_mask) { in dwc2_hcd_init()
5133 dev_warn(hsotg->dev, in dwc2_hcd_init()
5135 hsotg->params.host_dma = false; in dwc2_hcd_init()
5136 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5140 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5141 if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5142 dev_warn(hsotg->dev, "can't set DMA mask\n"); in dwc2_hcd_init()
5143 if (dma_set_coherent_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5144 dev_warn(hsotg->dev, "can't set coherent DMA mask\n"); in dwc2_hcd_init()
5147 if (hsotg->params.change_speed_quirk) { in dwc2_hcd_init()
5152 if (hsotg->params.host_dma) in dwc2_hcd_init()
5155 hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev)); in dwc2_hcd_init()
5169 ((struct wrapper_priv_data *)&hcd->hcd_priv)->hsotg = hsotg; in dwc2_hcd_init()
5170 hsotg->priv = hcd; in dwc2_hcd_init()
5176 dwc2_disable_global_interrupts(hsotg); in dwc2_hcd_init()
5179 retval = dwc2_core_init(hsotg, true); in dwc2_hcd_init()
5185 hsotg->wq_otg = alloc_ordered_workqueue("dwc2", 0); in dwc2_hcd_init()
5186 if (!hsotg->wq_otg) { in dwc2_hcd_init()
5187 dev_err(hsotg->dev, "Failed to create workqueue\n"); in dwc2_hcd_init()
5190 INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change); in dwc2_hcd_init()
5192 timer_setup(&hsotg->wkp_timer, dwc2_wakeup_detected, 0); in dwc2_hcd_init()
5195 INIT_LIST_HEAD(&hsotg->non_periodic_sched_inactive); in dwc2_hcd_init()
5196 INIT_LIST_HEAD(&hsotg->non_periodic_sched_waiting); in dwc2_hcd_init()
5197 INIT_LIST_HEAD(&hsotg->non_periodic_sched_active); in dwc2_hcd_init()
5200 INIT_LIST_HEAD(&hsotg->periodic_sched_inactive); in dwc2_hcd_init()
5201 INIT_LIST_HEAD(&hsotg->periodic_sched_ready); in dwc2_hcd_init()
5202 INIT_LIST_HEAD(&hsotg->periodic_sched_assigned); in dwc2_hcd_init()
5203 INIT_LIST_HEAD(&hsotg->periodic_sched_queued); in dwc2_hcd_init()
5205 INIT_LIST_HEAD(&hsotg->split_order); in dwc2_hcd_init()
5211 INIT_LIST_HEAD(&hsotg->free_hc_list); in dwc2_hcd_init()
5212 num_channels = hsotg->params.host_channels; in dwc2_hcd_init()
5213 memset(&hsotg->hc_ptr_array[0], 0, sizeof(hsotg->hc_ptr_array)); in dwc2_hcd_init()
5221 hsotg->hc_ptr_array[i] = channel; in dwc2_hcd_init()
5225 INIT_DELAYED_WORK(&hsotg->start_work, dwc2_hcd_start_func); in dwc2_hcd_init()
5226 INIT_DELAYED_WORK(&hsotg->reset_work, dwc2_hcd_reset_func); in dwc2_hcd_init()
5227 INIT_WORK(&hsotg->phy_reset_work, dwc2_hcd_phy_reset_func); in dwc2_hcd_init()
5235 if (hsotg->params.host_dma) in dwc2_hcd_init()
5236 hsotg->status_buf = dma_alloc_coherent(hsotg->dev, in dwc2_hcd_init()
5238 &hsotg->status_buf_dma, GFP_KERNEL); in dwc2_hcd_init()
5240 hsotg->status_buf = kzalloc(DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_init()
5243 if (!hsotg->status_buf) in dwc2_hcd_init()
5251 if (hsotg->params.dma_desc_enable || in dwc2_hcd_init()
5252 hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_init()
5253 hsotg->desc_gen_cache = kmem_cache_create("dwc2-gen-desc", in dwc2_hcd_init()
5257 if (!hsotg->desc_gen_cache) { in dwc2_hcd_init()
5258 dev_err(hsotg->dev, in dwc2_hcd_init()
5265 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5266 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5269 hsotg->desc_hsisoc_cache = kmem_cache_create("dwc2-hsisoc-desc", in dwc2_hcd_init()
5272 if (!hsotg->desc_hsisoc_cache) { in dwc2_hcd_init()
5273 dev_err(hsotg->dev, in dwc2_hcd_init()
5276 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5282 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5283 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5287 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5292 hsotg->unaligned_cache = kmem_cache_create("dwc2-unaligned-dma", in dwc2_hcd_init()
5295 if (!hsotg->unaligned_cache) in dwc2_hcd_init()
5296 dev_err(hsotg->dev, in dwc2_hcd_init()
5300 hsotg->otg_port = 1; in dwc2_hcd_init()
5301 hsotg->frame_list = NULL; in dwc2_hcd_init()
5302 hsotg->frame_list_dma = 0; in dwc2_hcd_init()
5303 hsotg->periodic_qh_count = 0; in dwc2_hcd_init()
5306 hsotg->lx_state = DWC2_L3; in dwc2_hcd_init()
5308 hcd->self.otg_port = hsotg->otg_port; in dwc2_hcd_init()
5313 hcd->tpl_support = of_usb_host_tpl_support(hsotg->dev->of_node); in dwc2_hcd_init()
5315 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_init()
5316 otg_set_host(hsotg->uphy->otg, &hcd->self); in dwc2_hcd_init()
5323 retval = usb_add_hcd(hcd, hsotg->irq, IRQF_SHARED); in dwc2_hcd_init()
5329 dwc2_hcd_dump_state(hsotg); in dwc2_hcd_init()
5331 dwc2_enable_global_interrupts(hsotg); in dwc2_hcd_init()
5336 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_init()
5337 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_init()
5338 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5340 dwc2_hcd_release(hsotg); in dwc2_hcd_init()
5346 kfree(hsotg->last_frame_num_array); in dwc2_hcd_init()
5347 kfree(hsotg->frame_num_array); in dwc2_hcd_init()
5350 dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval); in dwc2_hcd_init()
5358 void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) in dwc2_hcd_remove() argument
5362 dev_dbg(hsotg->dev, "DWC OTG HCD REMOVE\n"); in dwc2_hcd_remove()
5364 hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_hcd_remove()
5365 dev_dbg(hsotg->dev, "hsotg->hcd = %p\n", hcd); in dwc2_hcd_remove()
5368 dev_dbg(hsotg->dev, "%s: dwc2_hsotg_to_hcd(hsotg) NULL!\n", in dwc2_hcd_remove()
5373 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_remove()
5374 otg_set_host(hsotg->uphy->otg, NULL); in dwc2_hcd_remove()
5377 hsotg->priv = NULL; in dwc2_hcd_remove()
5379 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_remove()
5380 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_remove()
5381 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_remove()
5383 dwc2_hcd_release(hsotg); in dwc2_hcd_remove()
5387 kfree(hsotg->last_frame_num_array); in dwc2_hcd_remove()
5388 kfree(hsotg->frame_num_array); in dwc2_hcd_remove()
5399 int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) in dwc2_backup_host_registers() argument
5404 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_backup_host_registers()
5407 hr = &hsotg->hr_backup; in dwc2_backup_host_registers()
5408 hr->hcfg = dwc2_readl(hsotg, HCFG); in dwc2_backup_host_registers()
5409 hr->haintmsk = dwc2_readl(hsotg, HAINTMSK); in dwc2_backup_host_registers()
5410 for (i = 0; i < hsotg->params.host_channels; ++i) in dwc2_backup_host_registers()
5411 hr->hcintmsk[i] = dwc2_readl(hsotg, HCINTMSK(i)); in dwc2_backup_host_registers()
5413 hr->hprt0 = dwc2_read_hprt0(hsotg); in dwc2_backup_host_registers()
5414 hr->hfir = dwc2_readl(hsotg, HFIR); in dwc2_backup_host_registers()
5415 hr->hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ); in dwc2_backup_host_registers()
5428 int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) in dwc2_restore_host_registers() argument
5433 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_restore_host_registers()
5436 hr = &hsotg->hr_backup; in dwc2_restore_host_registers()
5438 dev_err(hsotg->dev, "%s: no host registers to restore\n", in dwc2_restore_host_registers()
5444 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_restore_host_registers()
5445 dwc2_writel(hsotg, hr->haintmsk, HAINTMSK); in dwc2_restore_host_registers()
5447 for (i = 0; i < hsotg->params.host_channels; ++i) in dwc2_restore_host_registers()
5448 dwc2_writel(hsotg, hr->hcintmsk[i], HCINTMSK(i)); in dwc2_restore_host_registers()
5450 dwc2_writel(hsotg, hr->hprt0, HPRT0); in dwc2_restore_host_registers()
5451 dwc2_writel(hsotg, hr->hfir, HFIR); in dwc2_restore_host_registers()
5452 dwc2_writel(hsotg, hr->hptxfsiz, HPTXFSIZ); in dwc2_restore_host_registers()
5453 hsotg->frame_number = 0; in dwc2_restore_host_registers()
5463 int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg) in dwc2_host_enter_hibernation() argument
5472 dev_dbg(hsotg->dev, "Preparing host for hibernation\n"); in dwc2_host_enter_hibernation()
5473 ret = dwc2_backup_global_registers(hsotg); in dwc2_host_enter_hibernation()
5475 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_host_enter_hibernation()
5479 ret = dwc2_backup_host_registers(hsotg); in dwc2_host_enter_hibernation()
5481 dev_err(hsotg->dev, "%s: failed to backup host registers\n", in dwc2_host_enter_hibernation()
5487 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_enter_hibernation()
5490 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_enter_hibernation()
5493 if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 5000)) in dwc2_host_enter_hibernation()
5494 dev_warn(hsotg->dev, "Suspend wasn't generated\n"); in dwc2_host_enter_hibernation()
5500 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5501 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_hibernation()
5503 gusbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_host_enter_hibernation()
5507 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_hibernation()
5509 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_hibernation()
5512 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5514 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5518 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5520 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5523 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_hibernation()
5525 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_hibernation()
5530 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5532 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5536 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5540 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5544 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5546 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5550 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5552 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5554 hsotg->hibernated = 1; in dwc2_host_enter_hibernation()
5555 hsotg->bus_suspended = 1; in dwc2_host_enter_hibernation()
5556 dev_dbg(hsotg->dev, "Host hibernation completed\n"); in dwc2_host_enter_hibernation()
5557 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5573 int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, in dwc2_host_exit_hibernation() argument
5582 gr = &hsotg->gr_backup; in dwc2_host_exit_hibernation()
5583 hr = &hsotg->hr_backup; in dwc2_host_exit_hibernation()
5585 dev_dbg(hsotg->dev, in dwc2_host_exit_hibernation()
5589 dwc2_hib_restore_common(hsotg, rem_wakeup, 1); in dwc2_host_exit_hibernation()
5590 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5600 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_host_exit_hibernation()
5603 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_exit_hibernation()
5605 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_exit_hibernation()
5609 dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); in dwc2_host_exit_hibernation()
5610 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_host_exit_hibernation()
5613 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_exit_hibernation()
5615 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_exit_hibernation()
5622 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5631 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5636 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5639 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5644 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5647 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_exit_hibernation()
5651 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5653 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_exit_hibernation()
5656 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_host_exit_hibernation()
5659 ret = dwc2_restore_global_registers(hsotg); in dwc2_host_exit_hibernation()
5661 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_host_exit_hibernation()
5667 ret = dwc2_restore_host_registers(hsotg); in dwc2_host_exit_hibernation()
5669 dev_err(hsotg->dev, "%s: failed to restore host registers\n", in dwc2_host_exit_hibernation()
5675 dwc2_hcd_rem_wakeup(hsotg); in dwc2_host_exit_hibernation()
5681 hsotg->flags.b.port_connect_status_change = 1; in dwc2_host_exit_hibernation()
5684 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5685 hsotg->bus_suspended = 0; in dwc2_host_exit_hibernation()
5686 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_hibernation()
5687 dev_dbg(hsotg->dev, "Host hibernation restore complete\n"); in dwc2_host_exit_hibernation()
5720 int dwc2_host_enter_partial_power_down(struct dwc2_hsotg *hsotg) in dwc2_host_enter_partial_power_down() argument
5726 dev_dbg(hsotg->dev, "Entering host partial power down started.\n"); in dwc2_host_enter_partial_power_down()
5729 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_host_enter_partial_power_down()
5731 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_enter_partial_power_down()
5735 if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 3000)) in dwc2_host_enter_partial_power_down()
5736 dev_warn(hsotg->dev, "Suspend wasn't generated\n"); in dwc2_host_enter_partial_power_down()
5739 ret = dwc2_backup_global_registers(hsotg); in dwc2_host_enter_partial_power_down()
5741 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_host_enter_partial_power_down()
5746 ret = dwc2_backup_host_registers(hsotg); in dwc2_host_enter_partial_power_down()
5748 dev_err(hsotg->dev, "%s: failed to backup host registers\n", in dwc2_host_enter_partial_power_down()
5757 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_host_enter_partial_power_down()
5760 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_partial_power_down()
5763 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_partial_power_down()
5767 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_partial_power_down()
5771 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_partial_power_down()
5774 hsotg->in_ppd = 1; in dwc2_host_enter_partial_power_down()
5775 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_partial_power_down()
5776 hsotg->bus_suspended = true; in dwc2_host_enter_partial_power_down()
5778 dev_dbg(hsotg->dev, "Entering host partial power down completed.\n"); in dwc2_host_enter_partial_power_down()
5795 int dwc2_host_exit_partial_power_down(struct dwc2_hsotg *hsotg, in dwc2_host_exit_partial_power_down() argument
5802 dev_dbg(hsotg->dev, "Exiting host partial power down started.\n"); in dwc2_host_exit_partial_power_down()
5804 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_exit_partial_power_down()
5806 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_exit_partial_power_down()
5809 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_exit_partial_power_down()
5811 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_exit_partial_power_down()
5814 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_exit_partial_power_down()
5816 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_exit_partial_power_down()
5820 ret = dwc2_restore_global_registers(hsotg); in dwc2_host_exit_partial_power_down()
5822 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_host_exit_partial_power_down()
5827 ret = dwc2_restore_host_registers(hsotg); in dwc2_host_exit_partial_power_down()
5829 dev_err(hsotg->dev, "%s: failed to restore host registers\n", in dwc2_host_exit_partial_power_down()
5836 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_host_exit_partial_power_down()
5839 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_partial_power_down()
5844 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_host_exit_partial_power_down()
5846 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_partial_power_down()
5848 hsotg->bus_suspended = false; in dwc2_host_exit_partial_power_down()
5851 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_host_exit_partial_power_down()
5853 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_partial_power_down()
5856 dwc2_hcd_connect(hsotg); in dwc2_host_exit_partial_power_down()
5858 mod_timer(&hsotg->wkp_timer, in dwc2_host_exit_partial_power_down()
5863 hsotg->in_ppd = 0; in dwc2_host_exit_partial_power_down()
5864 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_partial_power_down()
5866 dev_dbg(hsotg->dev, "Exiting host partial power down completed.\n"); in dwc2_host_exit_partial_power_down()
5877 void dwc2_host_enter_clock_gating(struct dwc2_hsotg *hsotg) in dwc2_host_enter_clock_gating() argument
5882 dev_dbg(hsotg->dev, "Entering host clock gating.\n"); in dwc2_host_enter_clock_gating()
5885 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_host_enter_clock_gating()
5887 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_enter_clock_gating()
5890 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_clock_gating()
5892 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_host_enter_clock_gating()
5896 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_clock_gating()
5898 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_host_enter_clock_gating()
5901 hsotg->bus_suspended = true; in dwc2_host_enter_clock_gating()
5902 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_clock_gating()
5913 void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeup) in dwc2_host_exit_clock_gating() argument
5918 dev_dbg(hsotg->dev, "Exiting host clock gating.\n"); in dwc2_host_exit_clock_gating()
5921 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_exit_clock_gating()
5923 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_host_exit_clock_gating()
5927 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_exit_clock_gating()
5929 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_host_exit_clock_gating()
5933 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_host_exit_clock_gating()
5936 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_clock_gating()
5944 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_host_exit_clock_gating()
5946 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_clock_gating()
5948 hsotg->bus_suspended = false; in dwc2_host_exit_clock_gating()
5949 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_clock_gating()
5951 mod_timer(&hsotg->wkp_timer, in dwc2_host_exit_clock_gating()