Lines Matching refs:hsotg
59 static void dwc2_port_resume(struct dwc2_hsotg *hsotg);
73 static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg) in dwc2_enable_common_interrupts() argument
78 dwc2_writel(hsotg, 0xffffffff, GOTGINT); in dwc2_enable_common_interrupts()
81 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_enable_common_interrupts()
86 if (!hsotg->params.host_dma) in dwc2_enable_common_interrupts()
88 if (!hsotg->params.external_id_pin_ctl) in dwc2_enable_common_interrupts()
94 if (dwc2_is_device_mode(hsotg) && hsotg->params.lpm) in dwc2_enable_common_interrupts()
97 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_enable_common_interrupts()
100 static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg) in dwc2_gahbcfg_init() argument
102 u32 ahbcfg = dwc2_readl(hsotg, GAHBCFG); in dwc2_gahbcfg_init()
104 switch (hsotg->hw_params.arch) { in dwc2_gahbcfg_init()
106 dev_err(hsotg->dev, "External DMA Mode not supported\n"); in dwc2_gahbcfg_init()
110 dev_dbg(hsotg->dev, "Internal DMA Mode\n"); in dwc2_gahbcfg_init()
111 if (hsotg->params.ahbcfg != -1) { in dwc2_gahbcfg_init()
113 ahbcfg |= hsotg->params.ahbcfg & in dwc2_gahbcfg_init()
120 dev_dbg(hsotg->dev, "Slave Only Mode\n"); in dwc2_gahbcfg_init()
124 if (hsotg->params.host_dma) in dwc2_gahbcfg_init()
127 hsotg->params.dma_desc_enable = false; in dwc2_gahbcfg_init()
129 dwc2_writel(hsotg, ahbcfg, GAHBCFG); in dwc2_gahbcfg_init()
134 static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) in dwc2_gusbcfg_init() argument
138 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_gusbcfg_init()
141 switch (hsotg->hw_params.op_mode) { in dwc2_gusbcfg_init()
143 if (hsotg->params.otg_cap == in dwc2_gusbcfg_init()
146 if (hsotg->params.otg_cap != in dwc2_gusbcfg_init()
154 if (hsotg->params.otg_cap != in dwc2_gusbcfg_init()
166 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_gusbcfg_init()
169 static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg) in dwc2_vbus_supply_init() argument
171 if (hsotg->vbus_supply) in dwc2_vbus_supply_init()
172 return regulator_enable(hsotg->vbus_supply); in dwc2_vbus_supply_init()
177 static int dwc2_vbus_supply_exit(struct dwc2_hsotg *hsotg) in dwc2_vbus_supply_exit() argument
179 if (hsotg->vbus_supply) in dwc2_vbus_supply_exit()
180 return regulator_disable(hsotg->vbus_supply); in dwc2_vbus_supply_exit()
190 static void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg) in dwc2_enable_host_interrupts() argument
194 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_enable_host_interrupts()
197 dwc2_writel(hsotg, 0, GINTMSK); in dwc2_enable_host_interrupts()
198 dwc2_writel(hsotg, 0, HAINTMSK); in dwc2_enable_host_interrupts()
201 dwc2_enable_common_interrupts(hsotg); in dwc2_enable_host_interrupts()
204 intmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_enable_host_interrupts()
206 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_enable_host_interrupts()
214 static void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg) in dwc2_disable_host_interrupts() argument
216 u32 intmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_disable_host_interrupts()
221 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_disable_host_interrupts()
231 static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg) in dwc2_calculate_dynamic_fifo() argument
233 struct dwc2_core_params *params = &hsotg->params; in dwc2_calculate_dynamic_fifo()
234 struct dwc2_hw_params *hw = &hsotg->hw_params; in dwc2_calculate_dynamic_fifo()
287 dev_err(hsotg->dev, "invalid fifo sizes\n"); in dwc2_calculate_dynamic_fifo()
290 static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) in dwc2_config_fifos() argument
292 struct dwc2_core_params *params = &hsotg->params; in dwc2_config_fifos()
298 dwc2_calculate_dynamic_fifo(hsotg); in dwc2_config_fifos()
301 grxfsiz = dwc2_readl(hsotg, GRXFSIZ); in dwc2_config_fifos()
302 dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); in dwc2_config_fifos()
306 dwc2_writel(hsotg, grxfsiz, GRXFSIZ); in dwc2_config_fifos()
307 dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", in dwc2_config_fifos()
308 dwc2_readl(hsotg, GRXFSIZ)); in dwc2_config_fifos()
311 dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n", in dwc2_config_fifos()
312 dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_config_fifos()
317 dwc2_writel(hsotg, nptxfsiz, GNPTXFSIZ); in dwc2_config_fifos()
318 dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n", in dwc2_config_fifos()
319 dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_config_fifos()
322 dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n", in dwc2_config_fifos()
323 dwc2_readl(hsotg, HPTXFSIZ)); in dwc2_config_fifos()
329 dwc2_writel(hsotg, hptxfsiz, HPTXFSIZ); in dwc2_config_fifos()
330 dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n", in dwc2_config_fifos()
331 dwc2_readl(hsotg, HPTXFSIZ)); in dwc2_config_fifos()
333 if (hsotg->params.en_multiple_tx_fifo && in dwc2_config_fifos()
334 hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_91a) { in dwc2_config_fifos()
340 dfifocfg = dwc2_readl(hsotg, GDFIFOCFG); in dwc2_config_fifos()
347 dwc2_writel(hsotg, dfifocfg, GDFIFOCFG); in dwc2_config_fifos()
361 u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg) in dwc2_calc_frame_interval() argument
367 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_calc_frame_interval()
368 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_calc_frame_interval()
373 if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type == in dwc2_calc_frame_interval()
386 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI) in dwc2_calc_frame_interval()
389 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) in dwc2_calc_frame_interval()
408 void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes) in dwc2_read_packet() argument
420 dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes); in dwc2_read_packet()
423 *data_buf = dwc2_readl(hsotg, HCFIFO(0)); in dwc2_read_packet()
437 static void dwc2_dump_channel_info(struct dwc2_hsotg *hsotg, in dwc2_dump_channel_info() argument
441 int num_channels = hsotg->params.host_channels; in dwc2_dump_channel_info()
452 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_dump_channel_info()
453 hcsplt = dwc2_readl(hsotg, HCSPLT(chan->hc_num)); in dwc2_dump_channel_info()
454 hctsiz = dwc2_readl(hsotg, HCTSIZ(chan->hc_num)); in dwc2_dump_channel_info()
455 hc_dma = dwc2_readl(hsotg, HCDMA(chan->hc_num)); in dwc2_dump_channel_info()
457 dev_dbg(hsotg->dev, " Assigned to channel %p:\n", chan); in dwc2_dump_channel_info()
458 dev_dbg(hsotg->dev, " hcchar 0x%08x, hcsplt 0x%08x\n", in dwc2_dump_channel_info()
460 dev_dbg(hsotg->dev, " hctsiz 0x%08x, hc_dma 0x%08x\n", in dwc2_dump_channel_info()
462 dev_dbg(hsotg->dev, " dev_addr: %d, ep_num: %d, ep_is_in: %d\n", in dwc2_dump_channel_info()
464 dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); in dwc2_dump_channel_info()
465 dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); in dwc2_dump_channel_info()
466 dev_dbg(hsotg->dev, " data_pid_start: %d\n", chan->data_pid_start); in dwc2_dump_channel_info()
467 dev_dbg(hsotg->dev, " xfer_started: %d\n", chan->xfer_started); in dwc2_dump_channel_info()
468 dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); in dwc2_dump_channel_info()
469 dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); in dwc2_dump_channel_info()
470 dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", in dwc2_dump_channel_info()
472 dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); in dwc2_dump_channel_info()
473 dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); in dwc2_dump_channel_info()
474 dev_dbg(hsotg->dev, " NP inactive sched:\n"); in dwc2_dump_channel_info()
475 list_for_each_entry(qh, &hsotg->non_periodic_sched_inactive, in dwc2_dump_channel_info()
477 dev_dbg(hsotg->dev, " %p\n", qh); in dwc2_dump_channel_info()
478 dev_dbg(hsotg->dev, " NP waiting sched:\n"); in dwc2_dump_channel_info()
479 list_for_each_entry(qh, &hsotg->non_periodic_sched_waiting, in dwc2_dump_channel_info()
481 dev_dbg(hsotg->dev, " %p\n", qh); in dwc2_dump_channel_info()
482 dev_dbg(hsotg->dev, " NP active sched:\n"); in dwc2_dump_channel_info()
483 list_for_each_entry(qh, &hsotg->non_periodic_sched_active, in dwc2_dump_channel_info()
485 dev_dbg(hsotg->dev, " %p\n", qh); in dwc2_dump_channel_info()
486 dev_dbg(hsotg->dev, " Channels:\n"); in dwc2_dump_channel_info()
488 struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; in dwc2_dump_channel_info()
490 dev_dbg(hsotg->dev, " %2d: %p\n", i, chan); in dwc2_dump_channel_info()
497 static void dwc2_host_start(struct dwc2_hsotg *hsotg) in dwc2_host_start() argument
499 struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_host_start()
501 hcd->self.is_b_host = dwc2_hcd_is_b_host(hsotg); in dwc2_host_start()
505 static void dwc2_host_disconnect(struct dwc2_hsotg *hsotg) in dwc2_host_disconnect() argument
507 struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_host_disconnect()
512 static void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context, in dwc2_host_hub_info() argument
530 static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg, in dwc2_hc_enable_slave_ints() argument
538 dev_vdbg(hsotg->dev, "control/bulk\n"); in dwc2_hc_enable_slave_ints()
566 dev_vdbg(hsotg->dev, "intr\n"); in dwc2_hc_enable_slave_ints()
588 dev_vdbg(hsotg->dev, "isoc\n"); in dwc2_hc_enable_slave_ints()
599 dev_err(hsotg->dev, "## Unknown EP type ##\n"); in dwc2_hc_enable_slave_ints()
603 dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); in dwc2_hc_enable_slave_ints()
605 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); in dwc2_hc_enable_slave_ints()
608 static void dwc2_hc_enable_dma_ints(struct dwc2_hsotg *hsotg, in dwc2_hc_enable_dma_ints() argument
617 if (!hsotg->params.dma_desc_enable) { in dwc2_hc_enable_dma_ints()
619 dev_vdbg(hsotg->dev, "desc DMA disabled\n"); in dwc2_hc_enable_dma_ints()
623 dev_vdbg(hsotg->dev, "desc DMA enabled\n"); in dwc2_hc_enable_dma_ints()
631 dev_vdbg(hsotg->dev, "setting ACK\n"); in dwc2_hc_enable_dma_ints()
640 dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); in dwc2_hc_enable_dma_ints()
642 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); in dwc2_hc_enable_dma_ints()
645 static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg, in dwc2_hc_enable_ints() argument
650 if (hsotg->params.host_dma) { in dwc2_hc_enable_ints()
652 dev_vdbg(hsotg->dev, "DMA enabled\n"); in dwc2_hc_enable_ints()
653 dwc2_hc_enable_dma_ints(hsotg, chan); in dwc2_hc_enable_ints()
656 dev_vdbg(hsotg->dev, "DMA disabled\n"); in dwc2_hc_enable_ints()
657 dwc2_hc_enable_slave_ints(hsotg, chan); in dwc2_hc_enable_ints()
661 intmsk = dwc2_readl(hsotg, HAINTMSK); in dwc2_hc_enable_ints()
663 dwc2_writel(hsotg, intmsk, HAINTMSK); in dwc2_hc_enable_ints()
665 dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk); in dwc2_hc_enable_ints()
668 intmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hc_enable_ints()
670 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_hc_enable_ints()
672 dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk); in dwc2_hc_enable_ints()
686 static void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) in dwc2_hc_init() argument
694 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_init()
699 dwc2_writel(hsotg, hcintmsk, HCINT(hc_num)); in dwc2_hc_init()
702 dwc2_hc_enable_ints(hsotg, chan); in dwc2_hc_init()
716 dwc2_writel(hsotg, hcchar, HCCHAR(hc_num)); in dwc2_hc_init()
718 dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n", in dwc2_hc_init()
721 dev_vdbg(hsotg->dev, "%s: Channel %d\n", in dwc2_hc_init()
723 dev_vdbg(hsotg->dev, " Dev Addr: %d\n", in dwc2_hc_init()
725 dev_vdbg(hsotg->dev, " Ep Num: %d\n", in dwc2_hc_init()
727 dev_vdbg(hsotg->dev, " Is In: %d\n", in dwc2_hc_init()
729 dev_vdbg(hsotg->dev, " Is Low Speed: %d\n", in dwc2_hc_init()
731 dev_vdbg(hsotg->dev, " Ep Type: %d\n", in dwc2_hc_init()
733 dev_vdbg(hsotg->dev, " Max Pkt: %d\n", in dwc2_hc_init()
740 dev_vdbg(hsotg->dev, in dwc2_hc_init()
753 dev_vdbg(hsotg->dev, " comp split %d\n", in dwc2_hc_init()
755 dev_vdbg(hsotg->dev, " xact pos %d\n", in dwc2_hc_init()
757 dev_vdbg(hsotg->dev, " hub addr %d\n", in dwc2_hc_init()
759 dev_vdbg(hsotg->dev, " hub port %d\n", in dwc2_hc_init()
761 dev_vdbg(hsotg->dev, " is_in %d\n", in dwc2_hc_init()
763 dev_vdbg(hsotg->dev, " Max Pkt %d\n", in dwc2_hc_init()
765 dev_vdbg(hsotg->dev, " xferlen %d\n", in dwc2_hc_init()
770 dwc2_writel(hsotg, hcsplt, HCSPLT(hc_num)); in dwc2_hc_init()
801 void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, in dwc2_hc_halt() argument
807 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_halt()
815 if ((hsotg->params.host_dma && !hsotg->params.dma_desc_enable) || in dwc2_hc_halt()
816 hsotg->hw_params.arch == GHWCFG2_EXT_DMA_ARCH) { in dwc2_hc_halt()
822 dev_err(hsotg->dev, "%s() Channel can't be halted\n", in dwc2_hc_halt()
829 dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status); in dwc2_hc_halt()
841 dev_vdbg(hsotg->dev, "dequeue/error\n"); in dwc2_hc_halt()
842 dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); in dwc2_hc_halt()
849 dwc2_writel(hsotg, ~hcintmsk, HCINT(chan->hc_num)); in dwc2_hc_halt()
858 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
880 dev_vdbg(hsotg->dev, in dwc2_hc_halt()
886 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
890 if (!hsotg->params.dma_desc_enable) { in dwc2_hc_halt()
892 dev_vdbg(hsotg->dev, "desc DMA disabled\n"); in dwc2_hc_halt()
896 dev_dbg(hsotg->dev, "desc DMA enabled\n"); in dwc2_hc_halt()
900 if (!hsotg->params.host_dma) { in dwc2_hc_halt()
902 dev_vdbg(hsotg->dev, "DMA not enabled\n"); in dwc2_hc_halt()
908 dev_vdbg(hsotg->dev, "control/bulk\n"); in dwc2_hc_halt()
909 nptxsts = dwc2_readl(hsotg, GNPTXSTS); in dwc2_hc_halt()
911 dev_vdbg(hsotg->dev, "Disabling channel\n"); in dwc2_hc_halt()
916 dev_vdbg(hsotg->dev, "isoc/intr\n"); in dwc2_hc_halt()
917 hptxsts = dwc2_readl(hsotg, HPTXSTS); in dwc2_hc_halt()
919 hsotg->queuing_high_bandwidth) { in dwc2_hc_halt()
921 dev_vdbg(hsotg->dev, "Disabling channel\n"); in dwc2_hc_halt()
927 dev_vdbg(hsotg->dev, "DMA enabled\n"); in dwc2_hc_halt()
930 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
935 dev_vdbg(hsotg->dev, "Channel enabled\n"); in dwc2_hc_halt()
940 dev_vdbg(hsotg->dev, "Channel disabled\n"); in dwc2_hc_halt()
945 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_halt()
947 dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n", in dwc2_hc_halt()
949 dev_vdbg(hsotg->dev, " halt_pending: %d\n", in dwc2_hc_halt()
951 dev_vdbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hc_halt()
953 dev_vdbg(hsotg->dev, " halt_status: %d\n", in dwc2_hc_halt()
967 void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) in dwc2_hc_cleanup() argument
979 dwc2_writel(hsotg, 0, HCINTMSK(chan->hc_num)); in dwc2_hc_cleanup()
982 dwc2_writel(hsotg, hcintmsk, HCINT(chan->hc_num)); in dwc2_hc_cleanup()
995 static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, in dwc2_hc_set_even_odd_frame() argument
1036 fifo_space = (dwc2_readl(hsotg, HPTXSTS) & in dwc2_hc_set_even_odd_frame()
1039 (hsotg->params.host_perio_tx_fifo_size - in dwc2_hc_set_even_odd_frame()
1055 frame_number = dwc2_hcd_get_future_frame_number(hsotg, xfer_us); in dwc2_hc_set_even_odd_frame()
1068 dwc2_sch_vdbg(hsotg, in dwc2_hc_set_even_odd_frame()
1130 static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg, in dwc2_hc_write_packet() argument
1140 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_write_packet()
1153 dwc2_writel(hsotg, *data_buf, HCFIFO(chan->hc_num)); in dwc2_hc_write_packet()
1159 dwc2_writel(hsotg, data, HCFIFO(chan->hc_num)); in dwc2_hc_write_packet()
1176 static void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, in dwc2_hc_do_ping() argument
1183 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_do_ping()
1188 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_do_ping()
1190 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_do_ping()
1193 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_do_ping()
1229 static void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, in dwc2_hc_start_transfer() argument
1232 u32 max_hc_xfer_size = hsotg->params.max_transfer_size; in dwc2_hc_start_transfer()
1233 u16 max_hc_pkt_count = hsotg->params.max_packet_count; in dwc2_hc_start_transfer()
1240 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_start_transfer()
1243 if (!hsotg->params.host_dma) { in dwc2_hc_start_transfer()
1245 dev_vdbg(hsotg->dev, "ping, no DMA\n"); in dwc2_hc_start_transfer()
1246 dwc2_hc_do_ping(hsotg, chan); in dwc2_hc_start_transfer()
1252 dev_vdbg(hsotg->dev, "ping, DMA\n"); in dwc2_hc_start_transfer()
1259 dev_vdbg(hsotg->dev, "split\n"); in dwc2_hc_start_transfer()
1284 dev_vdbg(hsotg->dev, "no split\n"); in dwc2_hc_start_transfer()
1354 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_start_transfer()
1356 dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n", in dwc2_hc_start_transfer()
1359 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_start_transfer()
1361 dev_vdbg(hsotg->dev, " Xfer Size: %d\n", in dwc2_hc_start_transfer()
1364 dev_vdbg(hsotg->dev, " Num Pkts: %d\n", in dwc2_hc_start_transfer()
1367 dev_vdbg(hsotg->dev, " Start PID: %d\n", in dwc2_hc_start_transfer()
1372 if (hsotg->params.host_dma) { in dwc2_hc_start_transfer()
1377 dev_vdbg(hsotg->dev, "align_buf\n"); in dwc2_hc_start_transfer()
1382 dwc2_writel(hsotg, (u32)dma_addr, HCDMA(chan->hc_num)); in dwc2_hc_start_transfer()
1385 dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n", in dwc2_hc_start_transfer()
1391 u32 hcsplt = dwc2_readl(hsotg, HCSPLT(chan->hc_num)); in dwc2_hc_start_transfer()
1394 dwc2_writel(hsotg, hcsplt, HCSPLT(chan->hc_num)); in dwc2_hc_start_transfer()
1397 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer()
1400 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); in dwc2_hc_start_transfer()
1403 dev_warn(hsotg->dev, in dwc2_hc_start_transfer()
1412 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", in dwc2_hc_start_transfer()
1416 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer()
1418 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, in dwc2_hc_start_transfer()
1424 if (!hsotg->params.host_dma && in dwc2_hc_start_transfer()
1427 dwc2_hc_write_packet(hsotg, chan); in dwc2_hc_start_transfer()
1444 void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg, in dwc2_hc_start_transfer_ddma() argument
1467 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_start_transfer_ddma()
1469 dev_vdbg(hsotg->dev, " Start PID: %d\n", in dwc2_hc_start_transfer_ddma()
1471 dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1); in dwc2_hc_start_transfer_ddma()
1474 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1476 dma_sync_single_for_device(hsotg->dev, chan->desc_list_addr, in dwc2_hc_start_transfer_ddma()
1479 dwc2_writel(hsotg, chan->desc_list_addr, HCDMA(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1482 dev_vdbg(hsotg->dev, "Wrote %pad to HCDMA(%d)\n", in dwc2_hc_start_transfer_ddma()
1485 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1491 dev_warn(hsotg->dev, in dwc2_hc_start_transfer_ddma()
1500 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", in dwc2_hc_start_transfer_ddma()
1504 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1506 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, in dwc2_hc_start_transfer_ddma()
1533 static int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg, in dwc2_hc_continue_transfer() argument
1537 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_continue_transfer()
1561 u32 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1563 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); in dwc2_hc_continue_transfer()
1567 dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n", in dwc2_hc_continue_transfer()
1569 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1579 u32 hcchar = dwc2_readl(hsotg, in dwc2_hc_continue_transfer()
1582 dwc2_hc_set_even_odd_frame(hsotg, chan, in dwc2_hc_continue_transfer()
1587 dwc2_hc_write_packet(hsotg, chan); in dwc2_hc_continue_transfer()
1607 static void dwc2_kill_urbs_in_qh_list(struct dwc2_hsotg *hsotg, in dwc2_kill_urbs_in_qh_list() argument
1616 dwc2_host_complete(hsotg, qtd, -ECONNRESET); in dwc2_kill_urbs_in_qh_list()
1617 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_kill_urbs_in_qh_list()
1622 static void dwc2_qh_list_free(struct dwc2_hsotg *hsotg, in dwc2_qh_list_free() argument
1633 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_qh_list_free()
1636 dwc2_kill_urbs_in_qh_list(hsotg, qh_list); in dwc2_qh_list_free()
1639 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_qh_list_free()
1644 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_qh_list_free()
1649 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_qh_list_free()
1650 dwc2_hcd_qh_free(hsotg, qh); in dwc2_qh_list_free()
1651 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_qh_list_free()
1654 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_qh_list_free()
1665 static void dwc2_kill_all_urbs(struct dwc2_hsotg *hsotg) in dwc2_kill_all_urbs() argument
1667 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_inactive); in dwc2_kill_all_urbs()
1668 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_waiting); in dwc2_kill_all_urbs()
1669 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_active); in dwc2_kill_all_urbs()
1670 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_inactive); in dwc2_kill_all_urbs()
1671 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_ready); in dwc2_kill_all_urbs()
1672 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_assigned); in dwc2_kill_all_urbs()
1673 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_queued); in dwc2_kill_all_urbs()
1681 void dwc2_hcd_start(struct dwc2_hsotg *hsotg) in dwc2_hcd_start() argument
1685 if (hsotg->op_state == OTG_STATE_B_HOST) { in dwc2_hcd_start()
1691 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_start()
1693 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_start()
1696 queue_delayed_work(hsotg->wq_otg, &hsotg->start_work, in dwc2_hcd_start()
1701 static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg) in dwc2_hcd_cleanup_channels() argument
1703 int num_channels = hsotg->params.host_channels; in dwc2_hcd_cleanup_channels()
1708 if (!hsotg->params.host_dma) { in dwc2_hcd_cleanup_channels()
1711 channel = hsotg->hc_ptr_array[i]; in dwc2_hcd_cleanup_channels()
1714 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1718 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1724 channel = hsotg->hc_ptr_array[i]; in dwc2_hcd_cleanup_channels()
1727 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1731 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1734 dwc2_hc_cleanup(hsotg, channel); in dwc2_hcd_cleanup_channels()
1735 list_add_tail(&channel->hc_list_entry, &hsotg->free_hc_list); in dwc2_hcd_cleanup_channels()
1744 if (hsotg->params.uframe_sched) { in dwc2_hcd_cleanup_channels()
1745 hsotg->available_host_channels = in dwc2_hcd_cleanup_channels()
1746 hsotg->params.host_channels; in dwc2_hcd_cleanup_channels()
1748 hsotg->non_periodic_channels = 0; in dwc2_hcd_cleanup_channels()
1749 hsotg->periodic_channels = 0; in dwc2_hcd_cleanup_channels()
1760 void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) in dwc2_hcd_connect() argument
1762 if (hsotg->lx_state != DWC2_L0) in dwc2_hcd_connect()
1763 usb_hcd_resume_root_hub(hsotg->priv); in dwc2_hcd_connect()
1765 hsotg->flags.b.port_connect_status_change = 1; in dwc2_hcd_connect()
1766 hsotg->flags.b.port_connect_status = 1; in dwc2_hcd_connect()
1777 void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) in dwc2_hcd_disconnect() argument
1783 hsotg->flags.b.port_connect_status_change = 1; in dwc2_hcd_disconnect()
1784 hsotg->flags.b.port_connect_status = 0; in dwc2_hcd_disconnect()
1791 intr = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_disconnect()
1793 dwc2_writel(hsotg, intr, GINTMSK); in dwc2_hcd_disconnect()
1795 dwc2_writel(hsotg, intr, GINTSTS); in dwc2_hcd_disconnect()
1802 if (dwc2_is_device_mode(hsotg)) { in dwc2_hcd_disconnect()
1803 if (hsotg->op_state != OTG_STATE_A_SUSPEND) { in dwc2_hcd_disconnect()
1804 dev_dbg(hsotg->dev, "Disconnect: PortPower off\n"); in dwc2_hcd_disconnect()
1805 dwc2_writel(hsotg, 0, HPRT0); in dwc2_hcd_disconnect()
1808 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_disconnect()
1812 dwc2_kill_all_urbs(hsotg); in dwc2_hcd_disconnect()
1814 if (dwc2_is_host_mode(hsotg)) in dwc2_hcd_disconnect()
1816 dwc2_hcd_cleanup_channels(hsotg); in dwc2_hcd_disconnect()
1818 dwc2_host_disconnect(hsotg); in dwc2_hcd_disconnect()
1832 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_disconnect()
1836 dwc2_hcd_connect(hsotg); in dwc2_hcd_disconnect()
1837 else if (hsotg->lx_state != DWC2_L0) in dwc2_hcd_disconnect()
1838 usb_hcd_resume_root_hub(hsotg->priv); in dwc2_hcd_disconnect()
1846 static void dwc2_hcd_rem_wakeup(struct dwc2_hsotg *hsotg) in dwc2_hcd_rem_wakeup() argument
1848 if (hsotg->bus_suspended) { in dwc2_hcd_rem_wakeup()
1849 hsotg->flags.b.port_suspend_change = 1; in dwc2_hcd_rem_wakeup()
1850 usb_hcd_resume_root_hub(hsotg->priv); in dwc2_hcd_rem_wakeup()
1853 if (hsotg->lx_state == DWC2_L1) in dwc2_hcd_rem_wakeup()
1854 hsotg->flags.b.port_l1_change = 1; in dwc2_hcd_rem_wakeup()
1864 void dwc2_hcd_stop(struct dwc2_hsotg *hsotg) in dwc2_hcd_stop() argument
1866 dev_dbg(hsotg->dev, "DWC OTG HCD STOP\n"); in dwc2_hcd_stop()
1875 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_stop()
1878 dev_dbg(hsotg->dev, "PortPower off\n"); in dwc2_hcd_stop()
1879 dwc2_writel(hsotg, 0, HPRT0); in dwc2_hcd_stop()
1883 static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_enqueue() argument
1891 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_urb_enqueue()
1893 dev_err(hsotg->dev, "Not connected\n"); in dwc2_hcd_urb_enqueue()
1897 dev_speed = dwc2_host_get_speed(hsotg, urb->priv); in dwc2_hcd_urb_enqueue()
1901 (hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) && in dwc2_hcd_urb_enqueue()
1902 (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI)) { in dwc2_hcd_urb_enqueue()
1903 u32 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_urb_enqueue()
1914 retval = dwc2_hcd_qtd_add(hsotg, qtd, qh); in dwc2_hcd_urb_enqueue()
1916 dev_err(hsotg->dev, in dwc2_hcd_urb_enqueue()
1922 intr_mask = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_urb_enqueue()
1934 tr_type = dwc2_hcd_select_transactions(hsotg); in dwc2_hcd_urb_enqueue()
1936 dwc2_hcd_queue_transactions(hsotg, tr_type); in dwc2_hcd_urb_enqueue()
1943 static int dwc2_hcd_urb_dequeue(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_dequeue() argument
1951 dev_dbg(hsotg->dev, "## Urb QTD is NULL ##\n"); in dwc2_hcd_urb_dequeue()
1957 dev_dbg(hsotg->dev, "## Urb QTD QH is NULL ##\n"); in dwc2_hcd_urb_dequeue()
1964 dwc2_dump_channel_info(hsotg, qh->channel); in dwc2_hcd_urb_dequeue()
1967 if (hsotg->flags.b.port_connect_status) in dwc2_hcd_urb_dequeue()
1975 dwc2_hc_halt(hsotg, qh->channel, in dwc2_hcd_urb_dequeue()
1983 if (!hsotg->params.dma_desc_enable) { in dwc2_hcd_urb_dequeue()
1986 dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); in dwc2_hcd_urb_dequeue()
1988 dwc2_hcd_qh_deactivate(hsotg, qh, 0); in dwc2_hcd_urb_dequeue()
1991 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_urb_dequeue()
1994 dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); in dwc2_hcd_urb_dequeue()
2001 static int dwc2_hcd_endpoint_disable(struct dwc2_hsotg *hsotg, in dwc2_hcd_endpoint_disable() argument
2009 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2019 dev_err(hsotg->dev, in dwc2_hcd_endpoint_disable()
2025 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2027 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2035 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_endpoint_disable()
2039 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_hcd_endpoint_disable()
2046 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2048 dwc2_hcd_qh_free(hsotg, qh); in dwc2_hcd_endpoint_disable()
2054 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2060 static int dwc2_hcd_endpoint_reset(struct dwc2_hsotg *hsotg, in dwc2_hcd_endpoint_reset() argument
2080 int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup) in dwc2_core_init() argument
2085 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_init()
2087 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_core_init()
2091 if (hsotg->params.phy_ulpi_ext_vbus) in dwc2_core_init()
2096 if (hsotg->params.ts_dline) in dwc2_core_init()
2099 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_core_init()
2109 retval = dwc2_core_reset(hsotg, false); in dwc2_core_init()
2111 dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", in dwc2_core_init()
2120 retval = dwc2_phy_init(hsotg, initial_setup); in dwc2_core_init()
2125 retval = dwc2_gahbcfg_init(hsotg); in dwc2_core_init()
2130 dwc2_gusbcfg_init(hsotg); in dwc2_core_init()
2133 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_init()
2135 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_init()
2138 hsotg->srp_success = 0; in dwc2_core_init()
2141 dwc2_enable_common_interrupts(hsotg); in dwc2_core_init()
2147 if (dwc2_is_host_mode(hsotg)) { in dwc2_core_init()
2148 dev_dbg(hsotg->dev, "Host Mode\n"); in dwc2_core_init()
2149 hsotg->op_state = OTG_STATE_A_HOST; in dwc2_core_init()
2151 dev_dbg(hsotg->dev, "Device Mode\n"); in dwc2_core_init()
2152 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_core_init()
2168 static void dwc2_core_host_init(struct dwc2_hsotg *hsotg) in dwc2_core_host_init() argument
2172 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_host_init()
2182 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_core_host_init()
2184 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_core_host_init()
2187 dwc2_writel(hsotg, 0, PCGCTL); in dwc2_core_host_init()
2190 dwc2_init_fs_ls_pclk_sel(hsotg); in dwc2_core_host_init()
2191 if (hsotg->params.speed == DWC2_SPEED_PARAM_FULL || in dwc2_core_host_init()
2192 hsotg->params.speed == DWC2_SPEED_PARAM_LOW) { in dwc2_core_host_init()
2193 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_core_host_init()
2195 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_core_host_init()
2203 if (hsotg->params.reload_ctl) { in dwc2_core_host_init()
2204 hfir = dwc2_readl(hsotg, HFIR); in dwc2_core_host_init()
2206 dwc2_writel(hsotg, hfir, HFIR); in dwc2_core_host_init()
2209 if (hsotg->params.dma_desc_enable) { in dwc2_core_host_init()
2210 u32 op_mode = hsotg->hw_params.op_mode; in dwc2_core_host_init()
2212 if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a || in dwc2_core_host_init()
2213 !hsotg->hw_params.dma_desc_enable || in dwc2_core_host_init()
2217 dev_err(hsotg->dev, in dwc2_core_host_init()
2219 dev_err(hsotg->dev, in dwc2_core_host_init()
2221 hsotg->params.dma_desc_enable = false; in dwc2_core_host_init()
2223 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_core_host_init()
2225 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_core_host_init()
2230 dwc2_config_fifos(hsotg); in dwc2_core_host_init()
2234 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_host_init()
2236 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_host_init()
2239 dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */); in dwc2_core_host_init()
2240 dwc2_flush_rx_fifo(hsotg); in dwc2_core_host_init()
2243 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_host_init()
2245 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_host_init()
2247 if (!hsotg->params.dma_desc_enable) { in dwc2_core_host_init()
2252 num_channels = hsotg->params.host_channels; in dwc2_core_host_init()
2254 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_core_host_init()
2259 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_core_host_init()
2265 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_core_host_init()
2269 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_core_host_init()
2270 dev_dbg(hsotg->dev, "%s: Halt channel %d\n", in dwc2_core_host_init()
2273 if (dwc2_hsotg_wait_bit_clear(hsotg, HCCHAR(i), in dwc2_core_host_init()
2276 dev_warn(hsotg->dev, in dwc2_core_host_init()
2285 dwc2_enable_acg(hsotg); in dwc2_core_host_init()
2288 dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state); in dwc2_core_host_init()
2289 if (hsotg->op_state == OTG_STATE_A_HOST) { in dwc2_core_host_init()
2290 u32 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_core_host_init()
2292 dev_dbg(hsotg->dev, "Init: Power Port (%d)\n", in dwc2_core_host_init()
2296 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_core_host_init()
2300 dwc2_enable_host_interrupts(hsotg); in dwc2_core_host_init()
2308 static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg) in dwc2_hcd_reinit() argument
2314 hsotg->flags.d32 = 0; in dwc2_hcd_reinit()
2315 hsotg->non_periodic_qh_ptr = &hsotg->non_periodic_sched_active; in dwc2_hcd_reinit()
2317 if (hsotg->params.uframe_sched) { in dwc2_hcd_reinit()
2318 hsotg->available_host_channels = in dwc2_hcd_reinit()
2319 hsotg->params.host_channels; in dwc2_hcd_reinit()
2321 hsotg->non_periodic_channels = 0; in dwc2_hcd_reinit()
2322 hsotg->periodic_channels = 0; in dwc2_hcd_reinit()
2329 list_for_each_entry_safe(chan, chan_tmp, &hsotg->free_hc_list, in dwc2_hcd_reinit()
2333 num_channels = hsotg->params.host_channels; in dwc2_hcd_reinit()
2335 chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_reinit()
2336 list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list); in dwc2_hcd_reinit()
2337 dwc2_hc_cleanup(hsotg, chan); in dwc2_hcd_reinit()
2341 dwc2_core_host_init(hsotg); in dwc2_hcd_reinit()
2344 static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg, in dwc2_hc_init_split() argument
2353 dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port); in dwc2_hc_init_split()
2358 static void dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg, in dwc2_hc_init_xfer() argument
2371 dev_vdbg(hsotg->dev, " Control setup transaction\n"); in dwc2_hc_init_xfer()
2375 if (hsotg->params.host_dma) in dwc2_hc_init_xfer()
2383 dev_vdbg(hsotg->dev, " Control data transaction\n"); in dwc2_hc_init_xfer()
2392 dev_vdbg(hsotg->dev, " Control status transaction\n"); in dwc2_hc_init_xfer()
2402 if (hsotg->params.host_dma) in dwc2_hc_init_xfer()
2403 chan->xfer_dma = hsotg->status_buf_dma; in dwc2_hc_init_xfer()
2405 chan->xfer_buf = hsotg->status_buf; in dwc2_hc_init_xfer()
2420 if (hsotg->params.dma_desc_enable) in dwc2_hc_init_xfer()
2426 if (hsotg->params.host_dma) { in dwc2_hc_init_xfer()
2448 static int dwc2_alloc_qh_dma_aligned_buf(struct dwc2_hsotg *hsotg, in dwc2_alloc_qh_dma_aligned_buf() argument
2455 if (!hsotg->unaligned_cache || in dwc2_alloc_qh_dma_aligned_buf()
2460 qh->dw_align_buf = kmem_cache_alloc(hsotg->unaligned_cache, in dwc2_alloc_qh_dma_aligned_buf()
2478 qh->dw_align_buf_dma = dma_map_single(hsotg->dev, qh->dw_align_buf, in dwc2_alloc_qh_dma_aligned_buf()
2482 if (dma_mapping_error(hsotg->dev, qh->dw_align_buf_dma)) { in dwc2_alloc_qh_dma_aligned_buf()
2483 dev_err(hsotg->dev, "can't map align_buf\n"); in dwc2_alloc_qh_dma_aligned_buf()
2598 static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) in dwc2_assign_and_init_hc() argument
2605 dev_vdbg(hsotg->dev, "%s(%p,%p)\n", __func__, hsotg, qh); in dwc2_assign_and_init_hc()
2608 dev_dbg(hsotg->dev, "No QTDs in QH list\n"); in dwc2_assign_and_init_hc()
2612 if (list_empty(&hsotg->free_hc_list)) { in dwc2_assign_and_init_hc()
2613 dev_dbg(hsotg->dev, "No free channel to assign\n"); in dwc2_assign_and_init_hc()
2617 chan = list_first_entry(&hsotg->free_hc_list, struct dwc2_host_chan, in dwc2_assign_and_init_hc()
2664 if (hsotg->params.host_dma) in dwc2_assign_and_init_hc()
2674 dwc2_hc_init_split(hsotg, chan, qtd, urb); in dwc2_assign_and_init_hc()
2679 dwc2_hc_init_xfer(hsotg, chan, qtd); in dwc2_assign_and_init_hc()
2682 if (hsotg->params.host_dma && (chan->xfer_dma & 0x3) && in dwc2_assign_and_init_hc()
2684 dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); in dwc2_assign_and_init_hc()
2685 if (dwc2_alloc_qh_dma_aligned_buf(hsotg, qh, qtd, chan)) { in dwc2_assign_and_init_hc()
2686 dev_err(hsotg->dev, in dwc2_assign_and_init_hc()
2692 &hsotg->free_hc_list); in dwc2_assign_and_init_hc()
2702 WARN_ON_ONCE(hsotg->params.host_dma && in dwc2_assign_and_init_hc()
2715 if (hsotg->params.dma_desc_enable) { in dwc2_assign_and_init_hc()
2720 dwc2_hc_init(hsotg, chan); in dwc2_assign_and_init_hc()
2736 struct dwc2_hsotg *hsotg) in dwc2_hcd_select_transactions() argument
2744 dev_vdbg(hsotg->dev, " Select Transactions\n"); in dwc2_hcd_select_transactions()
2748 qh_ptr = hsotg->periodic_sched_ready.next; in dwc2_hcd_select_transactions()
2749 while (qh_ptr != &hsotg->periodic_sched_ready) { in dwc2_hcd_select_transactions()
2750 if (list_empty(&hsotg->free_hc_list)) in dwc2_hcd_select_transactions()
2752 if (hsotg->params.uframe_sched) { in dwc2_hcd_select_transactions()
2753 if (hsotg->available_host_channels <= 1) in dwc2_hcd_select_transactions()
2755 hsotg->available_host_channels--; in dwc2_hcd_select_transactions()
2758 if (dwc2_assign_and_init_hc(hsotg, qh)) in dwc2_hcd_select_transactions()
2767 &hsotg->periodic_sched_assigned); in dwc2_hcd_select_transactions()
2776 num_channels = hsotg->params.host_channels; in dwc2_hcd_select_transactions()
2777 qh_ptr = hsotg->non_periodic_sched_inactive.next; in dwc2_hcd_select_transactions()
2778 while (qh_ptr != &hsotg->non_periodic_sched_inactive) { in dwc2_hcd_select_transactions()
2779 if (!hsotg->params.uframe_sched && in dwc2_hcd_select_transactions()
2780 hsotg->non_periodic_channels >= num_channels - in dwc2_hcd_select_transactions()
2781 hsotg->periodic_channels) in dwc2_hcd_select_transactions()
2783 if (list_empty(&hsotg->free_hc_list)) in dwc2_hcd_select_transactions()
2786 if (hsotg->params.uframe_sched) { in dwc2_hcd_select_transactions()
2787 if (hsotg->available_host_channels < 1) in dwc2_hcd_select_transactions()
2789 hsotg->available_host_channels--; in dwc2_hcd_select_transactions()
2792 if (dwc2_assign_and_init_hc(hsotg, qh)) in dwc2_hcd_select_transactions()
2801 &hsotg->non_periodic_sched_active); in dwc2_hcd_select_transactions()
2808 if (!hsotg->params.uframe_sched) in dwc2_hcd_select_transactions()
2809 hsotg->non_periodic_channels++; in dwc2_hcd_select_transactions()
2836 static int dwc2_queue_transaction(struct dwc2_hsotg *hsotg, in dwc2_queue_transaction() argument
2845 &hsotg->split_order); in dwc2_queue_transaction()
2847 if (hsotg->params.host_dma && chan->qh) { in dwc2_queue_transaction()
2848 if (hsotg->params.dma_desc_enable) { in dwc2_queue_transaction()
2851 dwc2_hcd_start_xfer_ddma(hsotg, chan->qh); in dwc2_queue_transaction()
2855 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2861 dwc2_hc_halt(hsotg, chan, chan->halt_status); in dwc2_queue_transaction()
2864 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2869 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2871 } else if (!hsotg->params.host_dma) { in dwc2_queue_transaction()
2872 retval = dwc2_hc_continue_transfer(hsotg, chan); in dwc2_queue_transaction()
2879 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2881 } else if (!hsotg->params.host_dma) { in dwc2_queue_transaction()
2882 retval = dwc2_hc_continue_transfer(hsotg, chan); in dwc2_queue_transaction()
2898 static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg) in dwc2_process_periodic_channels() argument
2911 if (list_empty(&hsotg->periodic_sched_assigned)) in dwc2_process_periodic_channels()
2915 dev_vdbg(hsotg->dev, "Queue periodic transactions\n"); in dwc2_process_periodic_channels()
2917 tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_process_periodic_channels()
2924 dev_vdbg(hsotg->dev, " P Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2926 dev_vdbg(hsotg->dev, " P Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2930 qh_ptr = hsotg->periodic_sched_assigned.next; in dwc2_process_periodic_channels()
2931 while (qh_ptr != &hsotg->periodic_sched_assigned) { in dwc2_process_periodic_channels()
2932 tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_process_periodic_channels()
2957 if (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2959 hsotg->queuing_high_bandwidth = 1; in dwc2_process_periodic_channels()
2963 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_periodic_channels()
2976 if (hsotg->params.host_dma || status == 0 || in dwc2_process_periodic_channels()
2984 &hsotg->periodic_sched_queued); in dwc2_process_periodic_channels()
2987 hsotg->queuing_high_bandwidth = 0; in dwc2_process_periodic_channels()
2993 (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2994 !list_empty(&hsotg->periodic_sched_assigned))) { in dwc2_process_periodic_channels()
3002 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_periodic_channels()
3005 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_periodic_channels()
3015 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_periodic_channels()
3018 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_periodic_channels()
3032 static void dwc2_process_non_periodic_channels(struct dwc2_hsotg *hsotg) in dwc2_process_non_periodic_channels() argument
3045 dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n"); in dwc2_process_non_periodic_channels()
3047 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3052 dev_vdbg(hsotg->dev, " NP Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3054 dev_vdbg(hsotg->dev, " NP Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3061 if (hsotg->non_periodic_qh_ptr == &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3062 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3063 orig_qh_ptr = hsotg->non_periodic_qh_ptr; in dwc2_process_non_periodic_channels()
3070 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3073 if (!hsotg->params.host_dma && qspcavail == 0) { in dwc2_process_non_periodic_channels()
3078 qh = list_entry(hsotg->non_periodic_qh_ptr, struct dwc2_qh, in dwc2_process_non_periodic_channels()
3089 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_non_periodic_channels()
3099 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3100 if (hsotg->non_periodic_qh_ptr == in dwc2_process_non_periodic_channels()
3101 &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3102 hsotg->non_periodic_qh_ptr = in dwc2_process_non_periodic_channels()
3103 hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3104 } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr); in dwc2_process_non_periodic_channels()
3106 if (!hsotg->params.host_dma) { in dwc2_process_non_periodic_channels()
3107 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3112 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3115 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3127 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_non_periodic_channels()
3129 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_non_periodic_channels()
3138 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_non_periodic_channels()
3140 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_non_periodic_channels()
3156 void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg, in dwc2_hcd_queue_transactions() argument
3160 dev_vdbg(hsotg->dev, "Queue Transactions\n"); in dwc2_hcd_queue_transactions()
3165 dwc2_process_periodic_channels(hsotg); in dwc2_hcd_queue_transactions()
3170 if (!list_empty(&hsotg->non_periodic_sched_active)) { in dwc2_hcd_queue_transactions()
3171 dwc2_process_non_periodic_channels(hsotg); in dwc2_hcd_queue_transactions()
3177 u32 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_queue_transactions()
3180 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_hcd_queue_transactions()
3187 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_conn_id_status_change() local
3193 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_conn_id_status_change()
3195 if (!hsotg->ll_phy_enabled && dwc2_is_host_mode(hsotg)) in dwc2_conn_id_status_change()
3196 dwc2_lowlevel_phy_enable(hsotg); in dwc2_conn_id_status_change()
3198 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_conn_id_status_change()
3199 dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl); in dwc2_conn_id_status_change()
3200 dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n", in dwc2_conn_id_status_change()
3205 dwc2_vbus_supply_exit(hsotg); in dwc2_conn_id_status_change()
3207 dev_dbg(hsotg->dev, "connId B\n"); in dwc2_conn_id_status_change()
3208 if (hsotg->bus_suspended) { in dwc2_conn_id_status_change()
3209 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3211 dwc2_port_resume(hsotg); in dwc2_conn_id_status_change()
3213 while (!dwc2_is_device_mode(hsotg)) { in dwc2_conn_id_status_change()
3214 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3216 dwc2_is_host_mode(hsotg) ? "Host" : in dwc2_conn_id_status_change()
3224 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_conn_id_status_change()
3231 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3233 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_conn_id_status_change()
3234 dwc2_core_init(hsotg, false); in dwc2_conn_id_status_change()
3235 dwc2_enable_global_interrupts(hsotg); in dwc2_conn_id_status_change()
3236 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3237 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_conn_id_status_change()
3238 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3240 dwc2_enable_acg(hsotg); in dwc2_conn_id_status_change()
3241 dwc2_hsotg_core_connect(hsotg); in dwc2_conn_id_status_change()
3245 dev_dbg(hsotg->dev, "connId A\n"); in dwc2_conn_id_status_change()
3246 while (!dwc2_is_host_mode(hsotg)) { in dwc2_conn_id_status_change()
3247 dev_info(hsotg->dev, "Waiting for Host Mode, Mode=%s\n", in dwc2_conn_id_status_change()
3248 dwc2_is_host_mode(hsotg) ? in dwc2_conn_id_status_change()
3255 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3258 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3259 dwc2_hsotg_disconnect(hsotg); in dwc2_conn_id_status_change()
3260 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3262 hsotg->op_state = OTG_STATE_A_HOST; in dwc2_conn_id_status_change()
3264 dwc2_core_init(hsotg, false); in dwc2_conn_id_status_change()
3265 dwc2_enable_global_interrupts(hsotg); in dwc2_conn_id_status_change()
3266 dwc2_hcd_start(hsotg); in dwc2_conn_id_status_change()
3272 struct dwc2_hsotg *hsotg = from_timer(hsotg, t, wkp_timer); in dwc2_wakeup_detected() local
3275 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_wakeup_detected()
3281 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_wakeup_detected()
3282 dev_dbg(hsotg->dev, "Resume: HPRT0=%0x\n", hprt0); in dwc2_wakeup_detected()
3284 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_wakeup_detected()
3285 dev_dbg(hsotg->dev, "Clear Resume: HPRT0=%0x\n", in dwc2_wakeup_detected()
3286 dwc2_readl(hsotg, HPRT0)); in dwc2_wakeup_detected()
3288 dwc2_hcd_rem_wakeup(hsotg); in dwc2_wakeup_detected()
3289 hsotg->bus_suspended = false; in dwc2_wakeup_detected()
3292 hsotg->lx_state = DWC2_L0; in dwc2_wakeup_detected()
3295 static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg) in dwc2_host_is_b_hnp_enabled() argument
3297 struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_host_is_b_hnp_enabled()
3303 static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) in dwc2_port_suspend() argument
3310 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_port_suspend()
3312 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_suspend()
3314 if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) { in dwc2_port_suspend()
3315 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_port_suspend()
3317 dwc2_writel(hsotg, gotgctl, GOTGCTL); in dwc2_port_suspend()
3318 hsotg->op_state = OTG_STATE_A_SUSPEND; in dwc2_port_suspend()
3321 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_port_suspend()
3323 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_port_suspend()
3325 hsotg->bus_suspended = true; in dwc2_port_suspend()
3331 if (!hsotg->params.power_down) { in dwc2_port_suspend()
3333 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_port_suspend()
3335 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_port_suspend()
3340 if (dwc2_host_is_b_hnp_enabled(hsotg)) { in dwc2_port_suspend()
3341 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_port_suspend()
3343 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_port_suspend()
3345 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3349 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3354 static void dwc2_port_resume(struct dwc2_hsotg *hsotg) in dwc2_port_resume() argument
3360 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3366 if (!hsotg->params.power_down) { in dwc2_port_resume()
3367 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_port_resume()
3369 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_port_resume()
3370 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3372 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3375 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_port_resume()
3378 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_port_resume()
3379 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3383 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3384 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_port_resume()
3386 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_port_resume()
3387 hsotg->bus_suspended = false; in dwc2_port_resume()
3388 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3392 static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, in dwc2_hcd_hub_control() argument
3405 dev_dbg(hsotg->dev, "ClearHubFeature %1xh\n", wvalue); in dwc2_hcd_hub_control()
3415 dev_err(hsotg->dev, 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()
3431 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3435 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3438 if (hsotg->bus_suspended) { in dwc2_hcd_hub_control()
3439 if (hsotg->hibernated) in dwc2_hcd_hub_control()
3440 dwc2_exit_hibernation(hsotg, 0, 0, 1); in dwc2_hcd_hub_control()
3442 dwc2_port_resume(hsotg); in dwc2_hcd_hub_control()
3447 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3449 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3452 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3454 dwc2_vbus_supply_exit(hsotg); in dwc2_hcd_hub_control()
3458 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3467 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3469 hsotg->flags.b.port_connect_status_change = 0; in dwc2_hcd_hub_control()
3474 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3476 hsotg->flags.b.port_reset_change = 0; in dwc2_hcd_hub_control()
3484 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3486 hsotg->flags.b.port_enable_change = 0; in dwc2_hcd_hub_control()
3495 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3497 hsotg->flags.b.port_suspend_change = 0; in dwc2_hcd_hub_control()
3501 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3503 hsotg->flags.b.port_l1_change = 0; in dwc2_hcd_hub_control()
3507 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3509 hsotg->flags.b.port_over_current_change = 0; in dwc2_hcd_hub_control()
3514 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3521 dev_dbg(hsotg->dev, "GetHubDescriptor\n"); in dwc2_hcd_hub_control()
3536 dev_dbg(hsotg->dev, "GetHubStatus\n"); in dwc2_hcd_hub_control()
3541 dev_vdbg(hsotg->dev, in dwc2_hcd_hub_control()
3543 hsotg->flags.d32); in dwc2_hcd_hub_control()
3548 if (hsotg->flags.b.port_connect_status_change) in dwc2_hcd_hub_control()
3550 if (hsotg->flags.b.port_enable_change) in dwc2_hcd_hub_control()
3552 if (hsotg->flags.b.port_suspend_change) in dwc2_hcd_hub_control()
3554 if (hsotg->flags.b.port_l1_change) in dwc2_hcd_hub_control()
3556 if (hsotg->flags.b.port_reset_change) in dwc2_hcd_hub_control()
3558 if (hsotg->flags.b.port_over_current_change) { in dwc2_hcd_hub_control()
3559 dev_warn(hsotg->dev, "Overcurrent change detected\n"); in dwc2_hcd_hub_control()
3563 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_hub_control()
3575 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_hub_control()
3576 dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); in dwc2_hcd_hub_control()
3601 if (hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_hub_control()
3606 if (hsotg->new_connection && in dwc2_hcd_hub_control()
3614 dev_info(hsotg->dev, "Enabling descriptor DMA mode\n"); in dwc2_hcd_hub_control()
3615 hsotg->params.dma_desc_enable = true; in dwc2_hcd_hub_control()
3616 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_hcd_hub_control()
3618 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_hcd_hub_control()
3619 hsotg->new_connection = false; in dwc2_hcd_hub_control()
3623 dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); in dwc2_hcd_hub_control()
3628 dev_dbg(hsotg->dev, "SetHubFeature\n"); in dwc2_hcd_hub_control()
3633 dev_dbg(hsotg->dev, "SetPortFeature\n"); in dwc2_hcd_hub_control()
3637 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_hub_control()
3650 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3652 if (windex != hsotg->otg_port) in dwc2_hcd_hub_control()
3654 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_HIBERNATION) in dwc2_hcd_hub_control()
3655 dwc2_enter_hibernation(hsotg, 1); in dwc2_hcd_hub_control()
3657 dwc2_port_suspend(hsotg, windex); in dwc2_hcd_hub_control()
3661 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3663 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3666 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3668 dwc2_vbus_supply_init(hsotg); in dwc2_hcd_hub_control()
3672 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_HIBERNATION && in dwc2_hcd_hub_control()
3673 hsotg->hibernated) in dwc2_hcd_hub_control()
3674 dwc2_exit_hibernation(hsotg, 0, 1, 1); in dwc2_hcd_hub_control()
3675 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3676 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3678 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_hcd_hub_control()
3680 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_hcd_hub_control()
3682 dwc2_writel(hsotg, 0, PCGCTL); in dwc2_hcd_hub_control()
3684 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3694 if (!dwc2_hcd_is_b_host(hsotg)) { in dwc2_hcd_hub_control()
3696 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3698 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3700 dwc2_vbus_supply_init(hsotg); in dwc2_hcd_hub_control()
3706 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3707 hsotg->lx_state = DWC2_L0; /* Now back to On state */ in dwc2_hcd_hub_control()
3711 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3717 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3718 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3722 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3727 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3737 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3746 static int dwc2_hcd_is_status_changed(struct dwc2_hsotg *hsotg, int port) in dwc2_hcd_is_status_changed() argument
3753 retval = (hsotg->flags.b.port_connect_status_change || in dwc2_hcd_is_status_changed()
3754 hsotg->flags.b.port_reset_change || in dwc2_hcd_is_status_changed()
3755 hsotg->flags.b.port_enable_change || in dwc2_hcd_is_status_changed()
3756 hsotg->flags.b.port_suspend_change || in dwc2_hcd_is_status_changed()
3757 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3760 dev_dbg(hsotg->dev, in dwc2_hcd_is_status_changed()
3762 dev_dbg(hsotg->dev, " port_connect_status_change: %d\n", in dwc2_hcd_is_status_changed()
3763 hsotg->flags.b.port_connect_status_change); in dwc2_hcd_is_status_changed()
3764 dev_dbg(hsotg->dev, " port_reset_change: %d\n", in dwc2_hcd_is_status_changed()
3765 hsotg->flags.b.port_reset_change); in dwc2_hcd_is_status_changed()
3766 dev_dbg(hsotg->dev, " port_enable_change: %d\n", in dwc2_hcd_is_status_changed()
3767 hsotg->flags.b.port_enable_change); in dwc2_hcd_is_status_changed()
3768 dev_dbg(hsotg->dev, " port_suspend_change: %d\n", in dwc2_hcd_is_status_changed()
3769 hsotg->flags.b.port_suspend_change); in dwc2_hcd_is_status_changed()
3770 dev_dbg(hsotg->dev, " port_over_current_change: %d\n", in dwc2_hcd_is_status_changed()
3771 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3777 int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) in dwc2_hcd_get_frame_number() argument
3779 u32 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_get_frame_number()
3782 dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n", in dwc2_hcd_get_frame_number()
3788 int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us) in dwc2_hcd_get_future_frame_number() argument
3790 u32 hprt = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_get_future_frame_number()
3791 u32 hfir = dwc2_readl(hsotg, HFIR); in dwc2_hcd_get_future_frame_number()
3792 u32 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_get_future_frame_number()
3817 int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg) in dwc2_hcd_is_b_host() argument
3819 return hsotg->op_state == OTG_STATE_B_HOST; in dwc2_hcd_is_b_host()
3822 static struct dwc2_hcd_urb *dwc2_hcd_urb_alloc(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_alloc() argument
3834 static void dwc2_hcd_urb_set_pipeinfo(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_set_pipeinfo() argument
3842 dev_vdbg(hsotg->dev, in dwc2_hcd_urb_set_pipeinfo()
3857 void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg) in dwc2_hcd_dump_state() argument
3868 num_channels = hsotg->params.host_channels; in dwc2_hcd_dump_state()
3869 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3870 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3872 dev_dbg(hsotg->dev, "HCD State:\n"); in dwc2_hcd_dump_state()
3873 dev_dbg(hsotg->dev, " Num channels: %d\n", num_channels); in dwc2_hcd_dump_state()
3876 chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_dump_state()
3877 dev_dbg(hsotg->dev, " Channel %d:\n", i); in dwc2_hcd_dump_state()
3878 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3881 dev_dbg(hsotg->dev, " speed: %d\n", chan->speed); in dwc2_hcd_dump_state()
3882 dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); in dwc2_hcd_dump_state()
3883 dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); in dwc2_hcd_dump_state()
3884 dev_dbg(hsotg->dev, " data_pid_start: %d\n", in dwc2_hcd_dump_state()
3886 dev_dbg(hsotg->dev, " multi_count: %d\n", chan->multi_count); in dwc2_hcd_dump_state()
3887 dev_dbg(hsotg->dev, " xfer_started: %d\n", in dwc2_hcd_dump_state()
3889 dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); in dwc2_hcd_dump_state()
3890 dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", in dwc2_hcd_dump_state()
3892 dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); in dwc2_hcd_dump_state()
3893 dev_dbg(hsotg->dev, " xfer_count: %d\n", chan->xfer_count); in dwc2_hcd_dump_state()
3894 dev_dbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hcd_dump_state()
3896 dev_dbg(hsotg->dev, " halt_pending: %d\n", in dwc2_hcd_dump_state()
3898 dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); in dwc2_hcd_dump_state()
3899 dev_dbg(hsotg->dev, " do_split: %d\n", chan->do_split); in dwc2_hcd_dump_state()
3900 dev_dbg(hsotg->dev, " complete_split: %d\n", in dwc2_hcd_dump_state()
3902 dev_dbg(hsotg->dev, " hub_addr: %d\n", chan->hub_addr); in dwc2_hcd_dump_state()
3903 dev_dbg(hsotg->dev, " hub_port: %d\n", chan->hub_port); in dwc2_hcd_dump_state()
3904 dev_dbg(hsotg->dev, " xact_pos: %d\n", chan->xact_pos); in dwc2_hcd_dump_state()
3905 dev_dbg(hsotg->dev, " requests: %d\n", chan->requests); in dwc2_hcd_dump_state()
3906 dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); in dwc2_hcd_dump_state()
3911 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_dump_state()
3912 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_dump_state()
3913 hctsiz = dwc2_readl(hsotg, HCTSIZ(i)); in dwc2_hcd_dump_state()
3914 hcint = dwc2_readl(hsotg, HCINT(i)); in dwc2_hcd_dump_state()
3915 hcintmsk = dwc2_readl(hsotg, HCINTMSK(i)); in dwc2_hcd_dump_state()
3916 dev_dbg(hsotg->dev, " hfnum: 0x%08x\n", hfnum); in dwc2_hcd_dump_state()
3917 dev_dbg(hsotg->dev, " hcchar: 0x%08x\n", hcchar); in dwc2_hcd_dump_state()
3918 dev_dbg(hsotg->dev, " hctsiz: 0x%08x\n", hctsiz); in dwc2_hcd_dump_state()
3919 dev_dbg(hsotg->dev, " hcint: 0x%08x\n", hcint); in dwc2_hcd_dump_state()
3920 dev_dbg(hsotg->dev, " hcintmsk: 0x%08x\n", hcintmsk); in dwc2_hcd_dump_state()
3930 dev_dbg(hsotg->dev, " URB Info:\n"); in dwc2_hcd_dump_state()
3931 dev_dbg(hsotg->dev, " qtd: %p, urb: %p\n", in dwc2_hcd_dump_state()
3934 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3940 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3944 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3947 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3950 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3953 dev_dbg(hsotg->dev, " actual_length: %d\n", in dwc2_hcd_dump_state()
3959 dev_dbg(hsotg->dev, " non_periodic_channels: %d\n", in dwc2_hcd_dump_state()
3960 hsotg->non_periodic_channels); in dwc2_hcd_dump_state()
3961 dev_dbg(hsotg->dev, " periodic_channels: %d\n", in dwc2_hcd_dump_state()
3962 hsotg->periodic_channels); in dwc2_hcd_dump_state()
3963 dev_dbg(hsotg->dev, " periodic_usecs: %d\n", hsotg->periodic_usecs); in dwc2_hcd_dump_state()
3964 np_tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_hcd_dump_state()
3965 dev_dbg(hsotg->dev, " NP Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3967 dev_dbg(hsotg->dev, " NP Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3969 p_tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_hcd_dump_state()
3970 dev_dbg(hsotg->dev, " P Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3972 dev_dbg(hsotg->dev, " P Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3974 dwc2_dump_global_registers(hsotg); in dwc2_hcd_dump_state()
3975 dwc2_dump_host_registers(hsotg); in dwc2_hcd_dump_state()
3976 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3978 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3983 struct dwc2_hsotg *hsotg; member
3992 return p->hsotg; in dwc2_hcd_to_hsotg()
4015 struct dwc2_tt *dwc2_host_get_tt_info(struct dwc2_hsotg *hsotg, void *context, in dwc2_host_get_tt_info() argument
4063 void dwc2_host_put_tt_info(struct dwc2_hsotg *hsotg, struct dwc2_tt *dwc_tt) in dwc2_host_put_tt_info() argument
4078 int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context) in dwc2_host_get_speed() argument
4117 void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, in dwc2_host_complete() argument
4124 dev_dbg(hsotg->dev, "## %s: qtd is NULL ##\n", __func__); in dwc2_host_complete()
4129 dev_dbg(hsotg->dev, "## %s: qtd->urb is NULL ##\n", __func__); in dwc2_host_complete()
4135 dev_dbg(hsotg->dev, "## %s: urb->priv is NULL ##\n", __func__); in dwc2_host_complete()
4142 dev_vdbg(hsotg->dev, in dwc2_host_complete()
4162 dev_vdbg(hsotg->dev, " ISO Desc %d status %d\n", in dwc2_host_complete()
4178 dwc2_free_bus_bandwidth(dwc2_hsotg_to_hcd(hsotg), in dwc2_host_complete()
4179 dwc2_hcd_get_ep_bandwidth(hsotg, ep), in dwc2_host_complete()
4183 usb_hcd_unlink_urb_from_ep(dwc2_hsotg_to_hcd(hsotg), urb); in dwc2_host_complete()
4188 usb_hcd_giveback_urb(dwc2_hsotg_to_hcd(hsotg), urb, status); in dwc2_host_complete()
4196 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_start_func() local
4199 dev_dbg(hsotg->dev, "%s() %p\n", __func__, hsotg); in dwc2_hcd_start_func()
4200 dwc2_host_start(hsotg); in dwc2_hcd_start_func()
4208 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_reset_func() local
4213 dev_dbg(hsotg->dev, "USB RESET function called\n"); in dwc2_hcd_reset_func()
4215 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4217 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_reset_func()
4219 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_reset_func()
4220 hsotg->flags.b.port_reset_change = 1; in dwc2_hcd_reset_func()
4222 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4227 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_phy_reset_func() local
4231 ret = phy_reset(hsotg->phy); in dwc2_hcd_phy_reset_func()
4233 dev_warn(hsotg->dev, "PHY reset failed\n"); in dwc2_hcd_phy_reset_func()
4249 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_start() local
4255 dev_dbg(hsotg->dev, "DWC OTG HCD START\n"); in _dwc2_hcd_start()
4257 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4258 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_start()
4262 if (dwc2_is_device_mode(hsotg)) { in _dwc2_hcd_start()
4263 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4267 dwc2_hcd_reinit(hsotg); in _dwc2_hcd_start()
4269 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_start()
4273 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4274 ret = dwc2_vbus_supply_init(hsotg); in _dwc2_hcd_start()
4277 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4282 dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n"); in _dwc2_hcd_start()
4287 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4298 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_stop() local
4303 dwc2_disable_host_interrupts(hsotg); in _dwc2_hcd_stop()
4308 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_stop()
4309 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_stop()
4311 dwc2_hcd_disconnect(hsotg, true); in _dwc2_hcd_stop()
4312 dwc2_hcd_stop(hsotg); in _dwc2_hcd_stop()
4313 hsotg->lx_state = DWC2_L3; in _dwc2_hcd_stop()
4316 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_stop()
4320 dwc2_vbus_supply_exit(hsotg); in _dwc2_hcd_stop()
4327 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_suspend() local
4333 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4335 if (dwc2_is_device_mode(hsotg)) in _dwc2_hcd_suspend()
4338 if (hsotg->lx_state != DWC2_L0) in _dwc2_hcd_suspend()
4344 if (hsotg->op_state == OTG_STATE_B_PERIPHERAL) in _dwc2_hcd_suspend()
4347 if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL || in _dwc2_hcd_suspend()
4348 hsotg->flags.b.port_connect_status == 0) in _dwc2_hcd_suspend()
4355 if (!hsotg->bus_suspended) { in _dwc2_hcd_suspend()
4356 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_suspend()
4359 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) in _dwc2_hcd_suspend()
4361 dwc2_writel(hsotg, hprt0, HPRT0); in _dwc2_hcd_suspend()
4363 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_suspend()
4364 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4365 dwc2_vbus_supply_exit(hsotg); in _dwc2_hcd_suspend()
4366 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4368 pcgctl = readl(hsotg->regs + PCGCTL); in _dwc2_hcd_suspend()
4370 writel(pcgctl, hsotg->regs + PCGCTL); in _dwc2_hcd_suspend()
4374 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_suspend()
4376 ret = dwc2_enter_partial_power_down(hsotg); in _dwc2_hcd_suspend()
4379 dev_err(hsotg->dev, 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 if (hsotg->params.power_down > DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_resume()
4419 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4428 if (!IS_ERR_OR_NULL(hsotg->uphy)) { in _dwc2_hcd_resume()
4429 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4430 usb_phy_set_suspend(hsotg->uphy, false); in _dwc2_hcd_resume()
4431 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4434 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_resume()
4443 ret = dwc2_exit_partial_power_down(hsotg, true); in _dwc2_hcd_resume()
4445 dev_err(hsotg->dev, "exit partial_power_down failed\n"); in _dwc2_hcd_resume()
4447 pcgctl = readl(hsotg->regs + PCGCTL); in _dwc2_hcd_resume()
4449 writel(pcgctl, hsotg->regs + PCGCTL); in _dwc2_hcd_resume()
4452 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4454 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4456 if (hsotg->bus_suspended) { in _dwc2_hcd_resume()
4457 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4458 hsotg->flags.b.port_suspend_change = 1; in _dwc2_hcd_resume()
4459 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4460 dwc2_port_resume(hsotg); in _dwc2_hcd_resume()
4462 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_resume()
4463 dwc2_vbus_supply_init(hsotg); in _dwc2_hcd_resume()
4473 dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET | in _dwc2_hcd_resume()
4481 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4489 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_get_frame_number() local
4491 return dwc2_hcd_get_frame_number(hsotg); in _dwc2_hcd_get_frame_number()
4498 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_dump_urb_info() local
4502 dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb); in dwc2_dump_urb_info()
4503 dev_vdbg(hsotg->dev, " Device address: %d\n", in dwc2_dump_urb_info()
4505 dev_vdbg(hsotg->dev, " Endpoint: %d, %s\n", in dwc2_dump_urb_info()
4524 dev_vdbg(hsotg->dev, " Endpoint type: %s %s (%s)\n", pipetype, in dwc2_dump_urb_info()
4543 dev_vdbg(hsotg->dev, " Speed: %s\n", speed); in dwc2_dump_urb_info()
4544 dev_vdbg(hsotg->dev, " Max packet size: %d (%d mult)\n", in dwc2_dump_urb_info()
4548 dev_vdbg(hsotg->dev, " Data buffer length: %d\n", in dwc2_dump_urb_info()
4550 dev_vdbg(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n", in dwc2_dump_urb_info()
4552 dev_vdbg(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n", in dwc2_dump_urb_info()
4554 dev_vdbg(hsotg->dev, " Interval: %d\n", urb->interval); in dwc2_dump_urb_info()
4560 dev_vdbg(hsotg->dev, " ISO Desc %d:\n", i); in dwc2_dump_urb_info()
4561 dev_vdbg(hsotg->dev, " offset: %d, length %d\n", in dwc2_dump_urb_info()
4577 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_urb_enqueue() local
4592 dev_vdbg(hsotg->dev, "DWC OTG HCD URB Enqueue\n"); in _dwc2_hcd_urb_enqueue()
4601 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4602 if (!dwc2_hcd_is_bandwidth_allocated(hsotg, ep)) in _dwc2_hcd_urb_enqueue()
4604 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4622 dwc2_urb = dwc2_hcd_urb_alloc(hsotg, urb->number_of_packets, in _dwc2_hcd_urb_enqueue()
4627 dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, usb_pipedevice(urb->pipe), in _dwc2_hcd_urb_enqueue()
4637 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4669 qh = dwc2_hcd_qh_create(hsotg, dwc2_urb, mem_flags); in _dwc2_hcd_urb_enqueue()
4684 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4689 retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, qh, qtd); in _dwc2_hcd_urb_enqueue()
4695 dwc2_hcd_get_ep_bandwidth(hsotg, ep), in _dwc2_hcd_urb_enqueue()
4699 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4709 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4717 dwc2_hcd_qh_unlink(hsotg, qh); in _dwc2_hcd_urb_enqueue()
4721 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh); in _dwc2_hcd_urb_enqueue()
4722 dwc2_hcd_qh_free(hsotg, qh); in _dwc2_hcd_urb_enqueue()
4736 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_urb_dequeue() local
4740 dev_dbg(hsotg->dev, "DWC OTG HCD URB Dequeue\n"); in _dwc2_hcd_urb_dequeue()
4743 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4750 dev_dbg(hsotg->dev, "## urb->hcpriv is NULL ##\n"); in _dwc2_hcd_urb_dequeue()
4754 rc = dwc2_hcd_urb_dequeue(hsotg, urb->hcpriv); in _dwc2_hcd_urb_dequeue()
4762 spin_unlock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4764 spin_lock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4766 dev_dbg(hsotg->dev, "Called usb_hcd_giveback_urb()\n"); in _dwc2_hcd_urb_dequeue()
4767 dev_dbg(hsotg->dev, " urb->status = %d\n", urb->status); in _dwc2_hcd_urb_dequeue()
4769 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4782 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_endpoint_disable() local
4784 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_disable()
4787 dwc2_hcd_endpoint_disable(hsotg, ep, 250); in _dwc2_hcd_endpoint_disable()
4798 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_endpoint_reset() local
4801 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_reset()
4805 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4806 dwc2_hcd_endpoint_reset(hsotg, ep); in _dwc2_hcd_endpoint_reset()
4807 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4819 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_irq() local
4821 return dwc2_handle_hcd_intr(hsotg); in _dwc2_hcd_irq()
4832 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_hub_status_data() local
4834 buf[0] = dwc2_hcd_is_status_changed(hsotg, 1) << 1; in _dwc2_hcd_hub_status_data()
4851 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_clear_tt_buffer_complete() local
4859 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4862 if (hsotg->flags.b.port_connect_status) in _dwc2_hcd_clear_tt_buffer_complete()
4863 dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_ALL); in _dwc2_hcd_clear_tt_buffer_complete()
4865 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4874 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_change_bus_speed() local
4876 if (hsotg->params.speed == speed) in dwc2_change_bus_speed()
4879 hsotg->params.speed = speed; in dwc2_change_bus_speed()
4880 queue_work(hsotg->wq_otg, &hsotg->wf_otg); in dwc2_change_bus_speed()
4885 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_free_dev() local
4887 if (!hsotg->params.change_speed_quirk) in dwc2_free_dev()
4895 dev_info(hsotg->dev, "Set speed to default high-speed\n"); in dwc2_free_dev()
4902 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_reset_device() local
4904 if (!hsotg->params.change_speed_quirk) in dwc2_reset_device()
4908 dev_info(hsotg->dev, "Set speed to high-speed\n"); in dwc2_reset_device()
4916 dev_info(hsotg->dev, "Set speed to full-speed\n"); in dwc2_reset_device()
4954 static void dwc2_hcd_free(struct dwc2_hsotg *hsotg) in dwc2_hcd_free() argument
4960 dev_dbg(hsotg->dev, "DWC OTG HCD FREE\n"); in dwc2_hcd_free()
4963 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_inactive); in dwc2_hcd_free()
4964 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_waiting); in dwc2_hcd_free()
4965 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_active); in dwc2_hcd_free()
4966 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_inactive); in dwc2_hcd_free()
4967 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_ready); in dwc2_hcd_free()
4968 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_assigned); in dwc2_hcd_free()
4969 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_queued); in dwc2_hcd_free()
4973 struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_free()
4976 dev_dbg(hsotg->dev, "HCD Free channel #%i, chan=%p\n", in dwc2_hcd_free()
4978 hsotg->hc_ptr_array[i] = NULL; in dwc2_hcd_free()
4983 if (hsotg->params.host_dma) { in dwc2_hcd_free()
4984 if (hsotg->status_buf) { in dwc2_hcd_free()
4985 dma_free_coherent(hsotg->dev, DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_free()
4986 hsotg->status_buf, in dwc2_hcd_free()
4987 hsotg->status_buf_dma); in dwc2_hcd_free()
4988 hsotg->status_buf = NULL; in dwc2_hcd_free()
4991 kfree(hsotg->status_buf); in dwc2_hcd_free()
4992 hsotg->status_buf = NULL; in dwc2_hcd_free()
4995 ahbcfg = dwc2_readl(hsotg, GAHBCFG); in dwc2_hcd_free()
4999 dwc2_writel(hsotg, ahbcfg, GAHBCFG); in dwc2_hcd_free()
5000 dwc2_writel(hsotg, 0, GINTMSK); in dwc2_hcd_free()
5002 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) { in dwc2_hcd_free()
5003 dctl = dwc2_readl(hsotg, DCTL); in dwc2_hcd_free()
5005 dwc2_writel(hsotg, dctl, DCTL); in dwc2_hcd_free()
5008 if (hsotg->wq_otg) { in dwc2_hcd_free()
5009 if (!cancel_work_sync(&hsotg->wf_otg)) in dwc2_hcd_free()
5010 flush_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
5011 destroy_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
5014 cancel_work_sync(&hsotg->phy_reset_work); in dwc2_hcd_free()
5016 del_timer(&hsotg->wkp_timer); in dwc2_hcd_free()
5019 static void dwc2_hcd_release(struct dwc2_hsotg *hsotg) in dwc2_hcd_release() argument
5022 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_release()
5024 dwc2_hcd_free(hsotg); in dwc2_hcd_release()
5033 int dwc2_hcd_init(struct dwc2_hsotg *hsotg) in dwc2_hcd_init() argument
5035 struct platform_device *pdev = to_platform_device(hsotg->dev); in dwc2_hcd_init()
5046 dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); in dwc2_hcd_init()
5050 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_hcd_init()
5051 dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); in dwc2_hcd_init()
5054 hsotg->frame_num_array = kcalloc(FRAME_NUM_ARRAY_SIZE, in dwc2_hcd_init()
5055 sizeof(*hsotg->frame_num_array), in dwc2_hcd_init()
5057 if (!hsotg->frame_num_array) in dwc2_hcd_init()
5059 hsotg->last_frame_num_array = in dwc2_hcd_init()
5061 sizeof(*hsotg->last_frame_num_array), GFP_KERNEL); in dwc2_hcd_init()
5062 if (!hsotg->last_frame_num_array) in dwc2_hcd_init()
5065 hsotg->last_frame_num = HFNUM_MAX_FRNUM; in dwc2_hcd_init()
5068 if (hsotg->params.host_dma && in dwc2_hcd_init()
5069 !hsotg->dev->dma_mask) { in dwc2_hcd_init()
5070 dev_warn(hsotg->dev, in dwc2_hcd_init()
5072 hsotg->params.host_dma = false; in dwc2_hcd_init()
5073 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5077 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5078 if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5079 dev_warn(hsotg->dev, "can't set DMA mask\n"); in dwc2_hcd_init()
5080 if (dma_set_coherent_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5081 dev_warn(hsotg->dev, "can't set coherent DMA mask\n"); in dwc2_hcd_init()
5084 if (hsotg->params.change_speed_quirk) { in dwc2_hcd_init()
5089 if (hsotg->params.host_dma) in dwc2_hcd_init()
5092 hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev)); in dwc2_hcd_init()
5106 ((struct wrapper_priv_data *)&hcd->hcd_priv)->hsotg = hsotg; in dwc2_hcd_init()
5107 hsotg->priv = hcd; in dwc2_hcd_init()
5113 dwc2_disable_global_interrupts(hsotg); in dwc2_hcd_init()
5116 retval = dwc2_core_init(hsotg, true); in dwc2_hcd_init()
5122 hsotg->wq_otg = alloc_ordered_workqueue("dwc2", 0); in dwc2_hcd_init()
5123 if (!hsotg->wq_otg) { in dwc2_hcd_init()
5124 dev_err(hsotg->dev, "Failed to create workqueue\n"); in dwc2_hcd_init()
5127 INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change); in dwc2_hcd_init()
5129 timer_setup(&hsotg->wkp_timer, dwc2_wakeup_detected, 0); in dwc2_hcd_init()
5132 INIT_LIST_HEAD(&hsotg->non_periodic_sched_inactive); in dwc2_hcd_init()
5133 INIT_LIST_HEAD(&hsotg->non_periodic_sched_waiting); in dwc2_hcd_init()
5134 INIT_LIST_HEAD(&hsotg->non_periodic_sched_active); in dwc2_hcd_init()
5137 INIT_LIST_HEAD(&hsotg->periodic_sched_inactive); in dwc2_hcd_init()
5138 INIT_LIST_HEAD(&hsotg->periodic_sched_ready); in dwc2_hcd_init()
5139 INIT_LIST_HEAD(&hsotg->periodic_sched_assigned); in dwc2_hcd_init()
5140 INIT_LIST_HEAD(&hsotg->periodic_sched_queued); in dwc2_hcd_init()
5142 INIT_LIST_HEAD(&hsotg->split_order); in dwc2_hcd_init()
5148 INIT_LIST_HEAD(&hsotg->free_hc_list); in dwc2_hcd_init()
5149 num_channels = hsotg->params.host_channels; in dwc2_hcd_init()
5150 memset(&hsotg->hc_ptr_array[0], 0, sizeof(hsotg->hc_ptr_array)); in dwc2_hcd_init()
5158 hsotg->hc_ptr_array[i] = channel; in dwc2_hcd_init()
5162 INIT_DELAYED_WORK(&hsotg->start_work, dwc2_hcd_start_func); in dwc2_hcd_init()
5163 INIT_DELAYED_WORK(&hsotg->reset_work, dwc2_hcd_reset_func); in dwc2_hcd_init()
5164 INIT_WORK(&hsotg->phy_reset_work, dwc2_hcd_phy_reset_func); in dwc2_hcd_init()
5172 if (hsotg->params.host_dma) in dwc2_hcd_init()
5173 hsotg->status_buf = dma_alloc_coherent(hsotg->dev, in dwc2_hcd_init()
5175 &hsotg->status_buf_dma, GFP_KERNEL); in dwc2_hcd_init()
5177 hsotg->status_buf = kzalloc(DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_init()
5180 if (!hsotg->status_buf) in dwc2_hcd_init()
5188 if (hsotg->params.dma_desc_enable || in dwc2_hcd_init()
5189 hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_init()
5190 hsotg->desc_gen_cache = kmem_cache_create("dwc2-gen-desc", in dwc2_hcd_init()
5194 if (!hsotg->desc_gen_cache) { in dwc2_hcd_init()
5195 dev_err(hsotg->dev, in dwc2_hcd_init()
5202 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5203 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5206 hsotg->desc_hsisoc_cache = kmem_cache_create("dwc2-hsisoc-desc", in dwc2_hcd_init()
5209 if (!hsotg->desc_hsisoc_cache) { in dwc2_hcd_init()
5210 dev_err(hsotg->dev, in dwc2_hcd_init()
5213 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5219 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5220 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5224 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5229 hsotg->unaligned_cache = kmem_cache_create("dwc2-unaligned-dma", in dwc2_hcd_init()
5232 if (!hsotg->unaligned_cache) in dwc2_hcd_init()
5233 dev_err(hsotg->dev, in dwc2_hcd_init()
5237 hsotg->otg_port = 1; in dwc2_hcd_init()
5238 hsotg->frame_list = NULL; in dwc2_hcd_init()
5239 hsotg->frame_list_dma = 0; in dwc2_hcd_init()
5240 hsotg->periodic_qh_count = 0; in dwc2_hcd_init()
5243 hsotg->lx_state = DWC2_L3; in dwc2_hcd_init()
5245 hcd->self.otg_port = hsotg->otg_port; in dwc2_hcd_init()
5250 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_init()
5251 otg_set_host(hsotg->uphy->otg, &hcd->self); in dwc2_hcd_init()
5265 retval = usb_add_hcd(hcd, hsotg->irq, IRQF_SHARED); in dwc2_hcd_init()
5271 dwc2_hcd_dump_state(hsotg); in dwc2_hcd_init()
5273 dwc2_enable_global_interrupts(hsotg); in dwc2_hcd_init()
5278 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_init()
5279 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_init()
5280 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5282 dwc2_hcd_release(hsotg); in dwc2_hcd_init()
5288 kfree(hsotg->last_frame_num_array); in dwc2_hcd_init()
5289 kfree(hsotg->frame_num_array); in dwc2_hcd_init()
5292 dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval); in dwc2_hcd_init()
5300 void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) in dwc2_hcd_remove() argument
5304 dev_dbg(hsotg->dev, "DWC OTG HCD REMOVE\n"); in dwc2_hcd_remove()
5306 hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_hcd_remove()
5307 dev_dbg(hsotg->dev, "hsotg->hcd = %p\n", hcd); in dwc2_hcd_remove()
5310 dev_dbg(hsotg->dev, "%s: dwc2_hsotg_to_hcd(hsotg) NULL!\n", in dwc2_hcd_remove()
5315 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_remove()
5316 otg_set_host(hsotg->uphy->otg, NULL); in dwc2_hcd_remove()
5319 hsotg->priv = NULL; in dwc2_hcd_remove()
5321 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_remove()
5322 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_remove()
5323 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_remove()
5325 dwc2_hcd_release(hsotg); in dwc2_hcd_remove()
5329 kfree(hsotg->last_frame_num_array); in dwc2_hcd_remove()
5330 kfree(hsotg->frame_num_array); in dwc2_hcd_remove()
5341 int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) in dwc2_backup_host_registers() argument
5346 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_backup_host_registers()
5349 hr = &hsotg->hr_backup; in dwc2_backup_host_registers()
5350 hr->hcfg = dwc2_readl(hsotg, HCFG); in dwc2_backup_host_registers()
5351 hr->haintmsk = dwc2_readl(hsotg, HAINTMSK); in dwc2_backup_host_registers()
5352 for (i = 0; i < hsotg->params.host_channels; ++i) in dwc2_backup_host_registers()
5353 hr->hcintmsk[i] = dwc2_readl(hsotg, HCINTMSK(i)); in dwc2_backup_host_registers()
5355 hr->hprt0 = dwc2_read_hprt0(hsotg); in dwc2_backup_host_registers()
5356 hr->hfir = dwc2_readl(hsotg, HFIR); in dwc2_backup_host_registers()
5357 hr->hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ); in dwc2_backup_host_registers()
5370 int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) in dwc2_restore_host_registers() argument
5375 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_restore_host_registers()
5378 hr = &hsotg->hr_backup; in dwc2_restore_host_registers()
5380 dev_err(hsotg->dev, "%s: no host registers to restore\n", in dwc2_restore_host_registers()
5386 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_restore_host_registers()
5387 dwc2_writel(hsotg, hr->haintmsk, HAINTMSK); in dwc2_restore_host_registers()
5389 for (i = 0; i < hsotg->params.host_channels; ++i) in dwc2_restore_host_registers()
5390 dwc2_writel(hsotg, hr->hcintmsk[i], HCINTMSK(i)); in dwc2_restore_host_registers()
5392 dwc2_writel(hsotg, hr->hprt0, HPRT0); in dwc2_restore_host_registers()
5393 dwc2_writel(hsotg, hr->hfir, HFIR); in dwc2_restore_host_registers()
5394 dwc2_writel(hsotg, hr->hptxfsiz, HPTXFSIZ); in dwc2_restore_host_registers()
5395 hsotg->frame_number = 0; in dwc2_restore_host_registers()
5405 int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg) in dwc2_host_enter_hibernation() argument
5414 dev_dbg(hsotg->dev, "Preparing host for hibernation\n"); in dwc2_host_enter_hibernation()
5415 ret = dwc2_backup_global_registers(hsotg); in dwc2_host_enter_hibernation()
5417 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_host_enter_hibernation()
5421 ret = dwc2_backup_host_registers(hsotg); in dwc2_host_enter_hibernation()
5423 dev_err(hsotg->dev, "%s: failed to backup host registers\n", in dwc2_host_enter_hibernation()
5429 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_enter_hibernation()
5432 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_enter_hibernation()
5435 if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 5000)) in dwc2_host_enter_hibernation()
5436 dev_warn(hsotg->dev, "Suspend wasn't generated\n"); in dwc2_host_enter_hibernation()
5442 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5443 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_hibernation()
5445 gusbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_host_enter_hibernation()
5449 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_hibernation()
5451 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_hibernation()
5454 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5456 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5460 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5462 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5465 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_hibernation()
5467 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_hibernation()
5472 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5474 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5478 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5482 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5486 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5488 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5492 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5494 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5496 hsotg->hibernated = 1; in dwc2_host_enter_hibernation()
5497 hsotg->bus_suspended = 1; in dwc2_host_enter_hibernation()
5498 dev_dbg(hsotg->dev, "Host hibernation completed\n"); in dwc2_host_enter_hibernation()
5499 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5515 int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, in dwc2_host_exit_hibernation() argument
5524 gr = &hsotg->gr_backup; in dwc2_host_exit_hibernation()
5525 hr = &hsotg->hr_backup; in dwc2_host_exit_hibernation()
5527 dev_dbg(hsotg->dev, in dwc2_host_exit_hibernation()
5531 dwc2_hib_restore_common(hsotg, rem_wakeup, 1); in dwc2_host_exit_hibernation()
5532 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5542 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_host_exit_hibernation()
5545 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_exit_hibernation()
5547 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_exit_hibernation()
5551 dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); in dwc2_host_exit_hibernation()
5552 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_host_exit_hibernation()
5555 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_exit_hibernation()
5557 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_exit_hibernation()
5564 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5573 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5578 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5581 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5586 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5589 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_exit_hibernation()
5593 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5595 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_exit_hibernation()
5598 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_host_exit_hibernation()
5601 ret = dwc2_restore_global_registers(hsotg); in dwc2_host_exit_hibernation()
5603 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_host_exit_hibernation()
5609 ret = dwc2_restore_host_registers(hsotg); in dwc2_host_exit_hibernation()
5611 dev_err(hsotg->dev, "%s: failed to restore host registers\n", in dwc2_host_exit_hibernation()
5617 dwc2_hcd_rem_wakeup(hsotg); in dwc2_host_exit_hibernation()
5623 hsotg->flags.b.port_connect_status_change = 1; in dwc2_host_exit_hibernation()
5626 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5627 hsotg->bus_suspended = 0; in dwc2_host_exit_hibernation()
5628 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_hibernation()
5629 dev_dbg(hsotg->dev, "Host hibernation restore complete\n"); in dwc2_host_exit_hibernation()