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.g_dma && !hsotg->params.g_dma_desc) || in dwc2_hc_halt()
816 hsotg->hw_params.arch == GHWCFG2_EXT_DMA_ARCH) { in dwc2_hc_halt()
820 dev_err(hsotg->dev, "%s() Channel can't be halted\n", in dwc2_hc_halt()
827 dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status); in dwc2_hc_halt()
839 dev_vdbg(hsotg->dev, "dequeue/error\n"); in dwc2_hc_halt()
840 dwc2_writel(hsotg, hcintmsk, HCINTMSK(chan->hc_num)); in dwc2_hc_halt()
847 dwc2_writel(hsotg, ~hcintmsk, HCINT(chan->hc_num)); in dwc2_hc_halt()
856 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
878 dev_vdbg(hsotg->dev, in dwc2_hc_halt()
884 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
888 if (!hsotg->params.dma_desc_enable) { in dwc2_hc_halt()
890 dev_vdbg(hsotg->dev, "desc DMA disabled\n"); in dwc2_hc_halt()
894 dev_dbg(hsotg->dev, "desc DMA enabled\n"); in dwc2_hc_halt()
898 if (!hsotg->params.host_dma) { in dwc2_hc_halt()
900 dev_vdbg(hsotg->dev, "DMA not enabled\n"); in dwc2_hc_halt()
906 dev_vdbg(hsotg->dev, "control/bulk\n"); in dwc2_hc_halt()
907 nptxsts = dwc2_readl(hsotg, GNPTXSTS); in dwc2_hc_halt()
909 dev_vdbg(hsotg->dev, "Disabling channel\n"); in dwc2_hc_halt()
914 dev_vdbg(hsotg->dev, "isoc/intr\n"); in dwc2_hc_halt()
915 hptxsts = dwc2_readl(hsotg, HPTXSTS); in dwc2_hc_halt()
917 hsotg->queuing_high_bandwidth) { in dwc2_hc_halt()
919 dev_vdbg(hsotg->dev, "Disabling channel\n"); in dwc2_hc_halt()
925 dev_vdbg(hsotg->dev, "DMA enabled\n"); in dwc2_hc_halt()
928 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_halt()
933 dev_vdbg(hsotg->dev, "Channel enabled\n"); in dwc2_hc_halt()
938 dev_vdbg(hsotg->dev, "Channel disabled\n"); in dwc2_hc_halt()
943 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_halt()
945 dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n", in dwc2_hc_halt()
947 dev_vdbg(hsotg->dev, " halt_pending: %d\n", in dwc2_hc_halt()
949 dev_vdbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hc_halt()
951 dev_vdbg(hsotg->dev, " halt_status: %d\n", in dwc2_hc_halt()
965 void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) in dwc2_hc_cleanup() argument
977 dwc2_writel(hsotg, 0, HCINTMSK(chan->hc_num)); in dwc2_hc_cleanup()
980 dwc2_writel(hsotg, hcintmsk, HCINT(chan->hc_num)); in dwc2_hc_cleanup()
993 static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, in dwc2_hc_set_even_odd_frame() argument
1034 fifo_space = (dwc2_readl(hsotg, HPTXSTS) & in dwc2_hc_set_even_odd_frame()
1037 (hsotg->params.host_perio_tx_fifo_size - in dwc2_hc_set_even_odd_frame()
1053 frame_number = dwc2_hcd_get_future_frame_number(hsotg, xfer_us); in dwc2_hc_set_even_odd_frame()
1066 dwc2_sch_vdbg(hsotg, in dwc2_hc_set_even_odd_frame()
1128 static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg, in dwc2_hc_write_packet() argument
1138 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_write_packet()
1151 dwc2_writel(hsotg, *data_buf, HCFIFO(chan->hc_num)); in dwc2_hc_write_packet()
1157 dwc2_writel(hsotg, data, HCFIFO(chan->hc_num)); in dwc2_hc_write_packet()
1174 static void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, in dwc2_hc_do_ping() argument
1181 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_do_ping()
1186 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_do_ping()
1188 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_do_ping()
1191 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_do_ping()
1227 static void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, in dwc2_hc_start_transfer() argument
1230 u32 max_hc_xfer_size = hsotg->params.max_transfer_size; in dwc2_hc_start_transfer()
1231 u16 max_hc_pkt_count = hsotg->params.max_packet_count; in dwc2_hc_start_transfer()
1238 dev_vdbg(hsotg->dev, "%s()\n", __func__); in dwc2_hc_start_transfer()
1241 if (!hsotg->params.host_dma) { in dwc2_hc_start_transfer()
1243 dev_vdbg(hsotg->dev, "ping, no DMA\n"); in dwc2_hc_start_transfer()
1244 dwc2_hc_do_ping(hsotg, chan); in dwc2_hc_start_transfer()
1250 dev_vdbg(hsotg->dev, "ping, DMA\n"); in dwc2_hc_start_transfer()
1257 dev_vdbg(hsotg->dev, "split\n"); in dwc2_hc_start_transfer()
1282 dev_vdbg(hsotg->dev, "no split\n"); in dwc2_hc_start_transfer()
1351 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_start_transfer()
1353 dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n", in dwc2_hc_start_transfer()
1356 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_start_transfer()
1358 dev_vdbg(hsotg->dev, " Xfer Size: %d\n", in dwc2_hc_start_transfer()
1361 dev_vdbg(hsotg->dev, " Num Pkts: %d\n", in dwc2_hc_start_transfer()
1364 dev_vdbg(hsotg->dev, " Start PID: %d\n", in dwc2_hc_start_transfer()
1369 if (hsotg->params.host_dma) { in dwc2_hc_start_transfer()
1374 dev_vdbg(hsotg->dev, "align_buf\n"); in dwc2_hc_start_transfer()
1379 dwc2_writel(hsotg, (u32)dma_addr, HCDMA(chan->hc_num)); in dwc2_hc_start_transfer()
1382 dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n", in dwc2_hc_start_transfer()
1388 u32 hcsplt = dwc2_readl(hsotg, HCSPLT(chan->hc_num)); in dwc2_hc_start_transfer()
1391 dwc2_writel(hsotg, hcsplt, HCSPLT(chan->hc_num)); in dwc2_hc_start_transfer()
1394 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer()
1397 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); in dwc2_hc_start_transfer()
1400 dev_warn(hsotg->dev, in dwc2_hc_start_transfer()
1409 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", in dwc2_hc_start_transfer()
1413 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer()
1415 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, in dwc2_hc_start_transfer()
1421 if (!hsotg->params.host_dma && in dwc2_hc_start_transfer()
1424 dwc2_hc_write_packet(hsotg, chan); in dwc2_hc_start_transfer()
1441 void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg, in dwc2_hc_start_transfer_ddma() argument
1464 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_start_transfer_ddma()
1466 dev_vdbg(hsotg->dev, " Start PID: %d\n", in dwc2_hc_start_transfer_ddma()
1468 dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1); in dwc2_hc_start_transfer_ddma()
1471 dwc2_writel(hsotg, hctsiz, HCTSIZ(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1473 dma_sync_single_for_device(hsotg->dev, chan->desc_list_addr, in dwc2_hc_start_transfer_ddma()
1476 dwc2_writel(hsotg, chan->desc_list_addr, HCDMA(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1479 dev_vdbg(hsotg->dev, "Wrote %pad to HCDMA(%d)\n", in dwc2_hc_start_transfer_ddma()
1482 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1488 dev_warn(hsotg->dev, in dwc2_hc_start_transfer_ddma()
1497 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", in dwc2_hc_start_transfer_ddma()
1501 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_start_transfer_ddma()
1503 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, in dwc2_hc_start_transfer_ddma()
1530 static int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg, in dwc2_hc_continue_transfer() argument
1534 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, in dwc2_hc_continue_transfer()
1558 u32 hcchar = dwc2_readl(hsotg, HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1560 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); in dwc2_hc_continue_transfer()
1564 dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n", in dwc2_hc_continue_transfer()
1566 dwc2_writel(hsotg, hcchar, HCCHAR(chan->hc_num)); in dwc2_hc_continue_transfer()
1576 u32 hcchar = dwc2_readl(hsotg, in dwc2_hc_continue_transfer()
1579 dwc2_hc_set_even_odd_frame(hsotg, chan, in dwc2_hc_continue_transfer()
1584 dwc2_hc_write_packet(hsotg, chan); in dwc2_hc_continue_transfer()
1604 static void dwc2_kill_urbs_in_qh_list(struct dwc2_hsotg *hsotg, in dwc2_kill_urbs_in_qh_list() argument
1613 dwc2_host_complete(hsotg, qtd, -ECONNRESET); in dwc2_kill_urbs_in_qh_list()
1614 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_kill_urbs_in_qh_list()
1619 static void dwc2_qh_list_free(struct dwc2_hsotg *hsotg, in dwc2_qh_list_free() argument
1630 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_qh_list_free()
1633 dwc2_kill_urbs_in_qh_list(hsotg, qh_list); in dwc2_qh_list_free()
1636 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_qh_list_free()
1641 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_qh_list_free()
1646 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_qh_list_free()
1647 dwc2_hcd_qh_free(hsotg, qh); in dwc2_qh_list_free()
1648 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_qh_list_free()
1651 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_qh_list_free()
1662 static void dwc2_kill_all_urbs(struct dwc2_hsotg *hsotg) in dwc2_kill_all_urbs() argument
1664 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_inactive); in dwc2_kill_all_urbs()
1665 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_waiting); in dwc2_kill_all_urbs()
1666 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_active); in dwc2_kill_all_urbs()
1667 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_inactive); in dwc2_kill_all_urbs()
1668 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_ready); in dwc2_kill_all_urbs()
1669 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_assigned); in dwc2_kill_all_urbs()
1670 dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_queued); in dwc2_kill_all_urbs()
1678 void dwc2_hcd_start(struct dwc2_hsotg *hsotg) in dwc2_hcd_start() argument
1682 if (hsotg->op_state == OTG_STATE_B_HOST) { in dwc2_hcd_start()
1688 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_start()
1690 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_start()
1693 queue_delayed_work(hsotg->wq_otg, &hsotg->start_work, in dwc2_hcd_start()
1698 static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg) in dwc2_hcd_cleanup_channels() argument
1700 int num_channels = hsotg->params.host_channels; in dwc2_hcd_cleanup_channels()
1705 if (!hsotg->params.host_dma) { in dwc2_hcd_cleanup_channels()
1708 channel = hsotg->hc_ptr_array[i]; in dwc2_hcd_cleanup_channels()
1711 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1715 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1721 channel = hsotg->hc_ptr_array[i]; in dwc2_hcd_cleanup_channels()
1724 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1728 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_hcd_cleanup_channels()
1731 dwc2_hc_cleanup(hsotg, channel); in dwc2_hcd_cleanup_channels()
1732 list_add_tail(&channel->hc_list_entry, &hsotg->free_hc_list); in dwc2_hcd_cleanup_channels()
1741 if (hsotg->params.uframe_sched) { in dwc2_hcd_cleanup_channels()
1742 hsotg->available_host_channels = in dwc2_hcd_cleanup_channels()
1743 hsotg->params.host_channels; in dwc2_hcd_cleanup_channels()
1745 hsotg->non_periodic_channels = 0; in dwc2_hcd_cleanup_channels()
1746 hsotg->periodic_channels = 0; in dwc2_hcd_cleanup_channels()
1757 void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) in dwc2_hcd_connect() argument
1759 if (hsotg->lx_state != DWC2_L0) in dwc2_hcd_connect()
1760 usb_hcd_resume_root_hub(hsotg->priv); in dwc2_hcd_connect()
1762 hsotg->flags.b.port_connect_status_change = 1; in dwc2_hcd_connect()
1763 hsotg->flags.b.port_connect_status = 1; in dwc2_hcd_connect()
1774 void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) in dwc2_hcd_disconnect() argument
1780 hsotg->flags.b.port_connect_status_change = 1; in dwc2_hcd_disconnect()
1781 hsotg->flags.b.port_connect_status = 0; in dwc2_hcd_disconnect()
1788 intr = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_disconnect()
1790 dwc2_writel(hsotg, intr, GINTMSK); in dwc2_hcd_disconnect()
1792 dwc2_writel(hsotg, intr, GINTSTS); in dwc2_hcd_disconnect()
1799 if (dwc2_is_device_mode(hsotg)) { in dwc2_hcd_disconnect()
1800 if (hsotg->op_state != OTG_STATE_A_SUSPEND) { in dwc2_hcd_disconnect()
1801 dev_dbg(hsotg->dev, "Disconnect: PortPower off\n"); in dwc2_hcd_disconnect()
1802 dwc2_writel(hsotg, 0, HPRT0); in dwc2_hcd_disconnect()
1805 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_disconnect()
1809 dwc2_kill_all_urbs(hsotg); in dwc2_hcd_disconnect()
1811 if (dwc2_is_host_mode(hsotg)) in dwc2_hcd_disconnect()
1813 dwc2_hcd_cleanup_channels(hsotg); in dwc2_hcd_disconnect()
1815 dwc2_host_disconnect(hsotg); in dwc2_hcd_disconnect()
1830 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_disconnect()
1832 dwc2_hcd_connect(hsotg); in dwc2_hcd_disconnect()
1841 static void dwc2_hcd_rem_wakeup(struct dwc2_hsotg *hsotg) in dwc2_hcd_rem_wakeup() argument
1843 if (hsotg->bus_suspended) { in dwc2_hcd_rem_wakeup()
1844 hsotg->flags.b.port_suspend_change = 1; in dwc2_hcd_rem_wakeup()
1845 usb_hcd_resume_root_hub(hsotg->priv); in dwc2_hcd_rem_wakeup()
1848 if (hsotg->lx_state == DWC2_L1) in dwc2_hcd_rem_wakeup()
1849 hsotg->flags.b.port_l1_change = 1; in dwc2_hcd_rem_wakeup()
1859 void dwc2_hcd_stop(struct dwc2_hsotg *hsotg) in dwc2_hcd_stop() argument
1861 dev_dbg(hsotg->dev, "DWC OTG HCD STOP\n"); in dwc2_hcd_stop()
1870 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_stop()
1873 dev_dbg(hsotg->dev, "PortPower off\n"); in dwc2_hcd_stop()
1874 dwc2_writel(hsotg, 0, HPRT0); in dwc2_hcd_stop()
1878 static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_enqueue() argument
1886 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_urb_enqueue()
1888 dev_err(hsotg->dev, "Not connected\n"); in dwc2_hcd_urb_enqueue()
1892 dev_speed = dwc2_host_get_speed(hsotg, urb->priv); in dwc2_hcd_urb_enqueue()
1896 (hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) && in dwc2_hcd_urb_enqueue()
1897 (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI)) { in dwc2_hcd_urb_enqueue()
1898 u32 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_urb_enqueue()
1909 retval = dwc2_hcd_qtd_add(hsotg, qtd, qh); in dwc2_hcd_urb_enqueue()
1911 dev_err(hsotg->dev, in dwc2_hcd_urb_enqueue()
1917 intr_mask = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_urb_enqueue()
1929 tr_type = dwc2_hcd_select_transactions(hsotg); in dwc2_hcd_urb_enqueue()
1931 dwc2_hcd_queue_transactions(hsotg, tr_type); in dwc2_hcd_urb_enqueue()
1938 static int dwc2_hcd_urb_dequeue(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_dequeue() argument
1946 dev_dbg(hsotg->dev, "## Urb QTD is NULL ##\n"); in dwc2_hcd_urb_dequeue()
1952 dev_dbg(hsotg->dev, "## Urb QTD QH is NULL ##\n"); in dwc2_hcd_urb_dequeue()
1959 dwc2_dump_channel_info(hsotg, qh->channel); in dwc2_hcd_urb_dequeue()
1962 if (hsotg->flags.b.port_connect_status) in dwc2_hcd_urb_dequeue()
1970 dwc2_hc_halt(hsotg, qh->channel, in dwc2_hcd_urb_dequeue()
1978 if (!hsotg->params.dma_desc_enable) { in dwc2_hcd_urb_dequeue()
1981 dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); in dwc2_hcd_urb_dequeue()
1983 dwc2_hcd_qh_deactivate(hsotg, qh, 0); in dwc2_hcd_urb_dequeue()
1986 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_urb_dequeue()
1989 dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh); in dwc2_hcd_urb_dequeue()
1996 static int dwc2_hcd_endpoint_disable(struct dwc2_hsotg *hsotg, in dwc2_hcd_endpoint_disable() argument
2004 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2014 dev_err(hsotg->dev, in dwc2_hcd_endpoint_disable()
2020 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2022 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2030 dwc2_hcd_qh_unlink(hsotg, qh); in dwc2_hcd_endpoint_disable()
2034 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); in dwc2_hcd_endpoint_disable()
2041 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2043 dwc2_hcd_qh_free(hsotg, qh); in dwc2_hcd_endpoint_disable()
2049 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_endpoint_disable()
2055 static int dwc2_hcd_endpoint_reset(struct dwc2_hsotg *hsotg, in dwc2_hcd_endpoint_reset() argument
2075 int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup) in dwc2_core_init() argument
2080 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_init()
2082 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_core_init()
2086 if (hsotg->params.phy_ulpi_ext_vbus) in dwc2_core_init()
2091 if (hsotg->params.ts_dline) in dwc2_core_init()
2094 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_core_init()
2104 retval = dwc2_core_reset(hsotg, false); in dwc2_core_init()
2106 dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", in dwc2_core_init()
2115 retval = dwc2_phy_init(hsotg, initial_setup); in dwc2_core_init()
2120 retval = dwc2_gahbcfg_init(hsotg); in dwc2_core_init()
2125 dwc2_gusbcfg_init(hsotg); in dwc2_core_init()
2128 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_init()
2130 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_init()
2133 hsotg->srp_success = 0; in dwc2_core_init()
2136 dwc2_enable_common_interrupts(hsotg); in dwc2_core_init()
2142 if (dwc2_is_host_mode(hsotg)) { in dwc2_core_init()
2143 dev_dbg(hsotg->dev, "Host Mode\n"); in dwc2_core_init()
2144 hsotg->op_state = OTG_STATE_A_HOST; in dwc2_core_init()
2146 dev_dbg(hsotg->dev, "Device Mode\n"); in dwc2_core_init()
2147 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_core_init()
2163 static void dwc2_core_host_init(struct dwc2_hsotg *hsotg) in dwc2_core_host_init() argument
2167 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); in dwc2_core_host_init()
2177 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_core_host_init()
2179 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_core_host_init()
2182 dwc2_writel(hsotg, 0, PCGCTL); in dwc2_core_host_init()
2185 dwc2_init_fs_ls_pclk_sel(hsotg); in dwc2_core_host_init()
2186 if (hsotg->params.speed == DWC2_SPEED_PARAM_FULL || in dwc2_core_host_init()
2187 hsotg->params.speed == DWC2_SPEED_PARAM_LOW) { in dwc2_core_host_init()
2188 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_core_host_init()
2190 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_core_host_init()
2198 if (hsotg->params.reload_ctl) { in dwc2_core_host_init()
2199 hfir = dwc2_readl(hsotg, HFIR); in dwc2_core_host_init()
2201 dwc2_writel(hsotg, hfir, HFIR); in dwc2_core_host_init()
2204 if (hsotg->params.dma_desc_enable) { in dwc2_core_host_init()
2205 u32 op_mode = hsotg->hw_params.op_mode; in dwc2_core_host_init()
2207 if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a || in dwc2_core_host_init()
2208 !hsotg->hw_params.dma_desc_enable || in dwc2_core_host_init()
2212 dev_err(hsotg->dev, in dwc2_core_host_init()
2214 dev_err(hsotg->dev, in dwc2_core_host_init()
2216 hsotg->params.dma_desc_enable = false; in dwc2_core_host_init()
2218 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_core_host_init()
2220 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_core_host_init()
2225 dwc2_config_fifos(hsotg); in dwc2_core_host_init()
2229 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_host_init()
2231 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_host_init()
2234 dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */); in dwc2_core_host_init()
2235 dwc2_flush_rx_fifo(hsotg); in dwc2_core_host_init()
2238 otgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_core_host_init()
2240 dwc2_writel(hsotg, otgctl, GOTGCTL); in dwc2_core_host_init()
2242 if (!hsotg->params.dma_desc_enable) { in dwc2_core_host_init()
2247 num_channels = hsotg->params.host_channels; in dwc2_core_host_init()
2249 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_core_host_init()
2254 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_core_host_init()
2260 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_core_host_init()
2264 dwc2_writel(hsotg, hcchar, HCCHAR(i)); in dwc2_core_host_init()
2265 dev_dbg(hsotg->dev, "%s: Halt channel %d\n", in dwc2_core_host_init()
2268 if (dwc2_hsotg_wait_bit_clear(hsotg, HCCHAR(i), in dwc2_core_host_init()
2271 dev_warn(hsotg->dev, in dwc2_core_host_init()
2280 dwc2_enable_acg(hsotg); in dwc2_core_host_init()
2283 dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state); in dwc2_core_host_init()
2284 if (hsotg->op_state == OTG_STATE_A_HOST) { in dwc2_core_host_init()
2285 u32 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_core_host_init()
2287 dev_dbg(hsotg->dev, "Init: Power Port (%d)\n", in dwc2_core_host_init()
2291 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_core_host_init()
2295 dwc2_enable_host_interrupts(hsotg); in dwc2_core_host_init()
2303 static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg) in dwc2_hcd_reinit() argument
2309 hsotg->flags.d32 = 0; in dwc2_hcd_reinit()
2310 hsotg->non_periodic_qh_ptr = &hsotg->non_periodic_sched_active; in dwc2_hcd_reinit()
2312 if (hsotg->params.uframe_sched) { in dwc2_hcd_reinit()
2313 hsotg->available_host_channels = in dwc2_hcd_reinit()
2314 hsotg->params.host_channels; in dwc2_hcd_reinit()
2316 hsotg->non_periodic_channels = 0; in dwc2_hcd_reinit()
2317 hsotg->periodic_channels = 0; in dwc2_hcd_reinit()
2324 list_for_each_entry_safe(chan, chan_tmp, &hsotg->free_hc_list, in dwc2_hcd_reinit()
2328 num_channels = hsotg->params.host_channels; in dwc2_hcd_reinit()
2330 chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_reinit()
2331 list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list); in dwc2_hcd_reinit()
2332 dwc2_hc_cleanup(hsotg, chan); in dwc2_hcd_reinit()
2336 dwc2_core_host_init(hsotg); in dwc2_hcd_reinit()
2339 static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg, in dwc2_hc_init_split() argument
2348 dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port); in dwc2_hc_init_split()
2353 static void dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg, in dwc2_hc_init_xfer() argument
2366 dev_vdbg(hsotg->dev, " Control setup transaction\n"); in dwc2_hc_init_xfer()
2370 if (hsotg->params.host_dma) in dwc2_hc_init_xfer()
2378 dev_vdbg(hsotg->dev, " Control data transaction\n"); in dwc2_hc_init_xfer()
2387 dev_vdbg(hsotg->dev, " Control status transaction\n"); in dwc2_hc_init_xfer()
2397 if (hsotg->params.host_dma) in dwc2_hc_init_xfer()
2398 chan->xfer_dma = hsotg->status_buf_dma; in dwc2_hc_init_xfer()
2400 chan->xfer_buf = hsotg->status_buf; in dwc2_hc_init_xfer()
2415 if (hsotg->params.dma_desc_enable) in dwc2_hc_init_xfer()
2421 if (hsotg->params.host_dma) { in dwc2_hc_init_xfer()
2443 static int dwc2_alloc_split_dma_aligned_buf(struct dwc2_hsotg *hsotg, in dwc2_alloc_split_dma_aligned_buf() argument
2447 if (!hsotg->unaligned_cache || in dwc2_alloc_split_dma_aligned_buf()
2452 qh->dw_align_buf = kmem_cache_alloc(hsotg->unaligned_cache, in dwc2_alloc_split_dma_aligned_buf()
2458 qh->dw_align_buf_dma = dma_map_single(hsotg->dev, qh->dw_align_buf, in dwc2_alloc_split_dma_aligned_buf()
2462 if (dma_mapping_error(hsotg->dev, qh->dw_align_buf_dma)) { in dwc2_alloc_split_dma_aligned_buf()
2463 dev_err(hsotg->dev, "can't map align_buf\n"); in dwc2_alloc_split_dma_aligned_buf()
2578 static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) in dwc2_assign_and_init_hc() argument
2585 dev_vdbg(hsotg->dev, "%s(%p,%p)\n", __func__, hsotg, qh); in dwc2_assign_and_init_hc()
2588 dev_dbg(hsotg->dev, "No QTDs in QH list\n"); in dwc2_assign_and_init_hc()
2592 if (list_empty(&hsotg->free_hc_list)) { in dwc2_assign_and_init_hc()
2593 dev_dbg(hsotg->dev, "No free channel to assign\n"); in dwc2_assign_and_init_hc()
2597 chan = list_first_entry(&hsotg->free_hc_list, struct dwc2_host_chan, in dwc2_assign_and_init_hc()
2644 if (hsotg->params.host_dma) in dwc2_assign_and_init_hc()
2654 dwc2_hc_init_split(hsotg, chan, qtd, urb); in dwc2_assign_and_init_hc()
2659 dwc2_hc_init_xfer(hsotg, chan, qtd); in dwc2_assign_and_init_hc()
2662 if (hsotg->params.host_dma && qh->do_split && in dwc2_assign_and_init_hc()
2664 dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); in dwc2_assign_and_init_hc()
2665 if (dwc2_alloc_split_dma_aligned_buf(hsotg, qh, chan)) { in dwc2_assign_and_init_hc()
2666 dev_err(hsotg->dev, in dwc2_assign_and_init_hc()
2672 &hsotg->free_hc_list); in dwc2_assign_and_init_hc()
2682 WARN_ON_ONCE(hsotg->params.host_dma && in dwc2_assign_and_init_hc()
2695 if (hsotg->params.dma_desc_enable) { in dwc2_assign_and_init_hc()
2700 dwc2_hc_init(hsotg, chan); in dwc2_assign_and_init_hc()
2716 struct dwc2_hsotg *hsotg) in dwc2_hcd_select_transactions() argument
2724 dev_vdbg(hsotg->dev, " Select Transactions\n"); in dwc2_hcd_select_transactions()
2728 qh_ptr = hsotg->periodic_sched_ready.next; in dwc2_hcd_select_transactions()
2729 while (qh_ptr != &hsotg->periodic_sched_ready) { in dwc2_hcd_select_transactions()
2730 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->periodic_sched_assigned); in dwc2_hcd_select_transactions()
2756 num_channels = hsotg->params.host_channels; in dwc2_hcd_select_transactions()
2757 qh_ptr = hsotg->non_periodic_sched_inactive.next; in dwc2_hcd_select_transactions()
2758 while (qh_ptr != &hsotg->non_periodic_sched_inactive) { in dwc2_hcd_select_transactions()
2759 if (!hsotg->params.uframe_sched && in dwc2_hcd_select_transactions()
2760 hsotg->non_periodic_channels >= num_channels - in dwc2_hcd_select_transactions()
2761 hsotg->periodic_channels) in dwc2_hcd_select_transactions()
2763 if (list_empty(&hsotg->free_hc_list)) in dwc2_hcd_select_transactions()
2766 if (hsotg->params.uframe_sched) { in dwc2_hcd_select_transactions()
2767 if (hsotg->available_host_channels < 1) in dwc2_hcd_select_transactions()
2769 hsotg->available_host_channels--; in dwc2_hcd_select_transactions()
2772 if (dwc2_assign_and_init_hc(hsotg, qh)) in dwc2_hcd_select_transactions()
2781 &hsotg->non_periodic_sched_active); in dwc2_hcd_select_transactions()
2788 if (!hsotg->params.uframe_sched) in dwc2_hcd_select_transactions()
2789 hsotg->non_periodic_channels++; in dwc2_hcd_select_transactions()
2816 static int dwc2_queue_transaction(struct dwc2_hsotg *hsotg, in dwc2_queue_transaction() argument
2825 &hsotg->split_order); in dwc2_queue_transaction()
2827 if (hsotg->params.host_dma) { in dwc2_queue_transaction()
2828 if (hsotg->params.dma_desc_enable) { in dwc2_queue_transaction()
2831 dwc2_hcd_start_xfer_ddma(hsotg, chan->qh); in dwc2_queue_transaction()
2835 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2841 dwc2_hc_halt(hsotg, chan, chan->halt_status); in dwc2_queue_transaction()
2844 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2849 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2852 retval = dwc2_hc_continue_transfer(hsotg, chan); in dwc2_queue_transaction()
2859 dwc2_hc_start_transfer(hsotg, chan); in dwc2_queue_transaction()
2862 retval = dwc2_hc_continue_transfer(hsotg, chan); in dwc2_queue_transaction()
2878 static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg) in dwc2_process_periodic_channels() argument
2891 if (list_empty(&hsotg->periodic_sched_assigned)) in dwc2_process_periodic_channels()
2895 dev_vdbg(hsotg->dev, "Queue periodic transactions\n"); in dwc2_process_periodic_channels()
2897 tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_process_periodic_channels()
2904 dev_vdbg(hsotg->dev, " P Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2906 dev_vdbg(hsotg->dev, " P Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_periodic_channels()
2910 qh_ptr = hsotg->periodic_sched_assigned.next; in dwc2_process_periodic_channels()
2911 while (qh_ptr != &hsotg->periodic_sched_assigned) { in dwc2_process_periodic_channels()
2912 tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_process_periodic_channels()
2937 if (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2939 hsotg->queuing_high_bandwidth = 1; in dwc2_process_periodic_channels()
2943 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_periodic_channels()
2956 if (hsotg->params.host_dma || status == 0 || in dwc2_process_periodic_channels()
2964 &hsotg->periodic_sched_queued); in dwc2_process_periodic_channels()
2967 hsotg->queuing_high_bandwidth = 0; in dwc2_process_periodic_channels()
2973 (!hsotg->params.host_dma && in dwc2_process_periodic_channels()
2974 !list_empty(&hsotg->periodic_sched_assigned))) { in dwc2_process_periodic_channels()
2982 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_periodic_channels()
2985 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_periodic_channels()
2995 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_periodic_channels()
2998 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_periodic_channels()
3012 static void dwc2_process_non_periodic_channels(struct dwc2_hsotg *hsotg) in dwc2_process_non_periodic_channels() argument
3025 dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n"); in dwc2_process_non_periodic_channels()
3027 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3032 dev_vdbg(hsotg->dev, " NP Tx Req Queue Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3034 dev_vdbg(hsotg->dev, " NP Tx FIFO Space Avail (before queue): %d\n", in dwc2_process_non_periodic_channels()
3041 if (hsotg->non_periodic_qh_ptr == &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3042 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3043 orig_qh_ptr = hsotg->non_periodic_qh_ptr; in dwc2_process_non_periodic_channels()
3050 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3053 if (!hsotg->params.host_dma && qspcavail == 0) { in dwc2_process_non_periodic_channels()
3058 qh = list_entry(hsotg->non_periodic_qh_ptr, struct dwc2_qh, in dwc2_process_non_periodic_channels()
3069 status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail); in dwc2_process_non_periodic_channels()
3079 hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3080 if (hsotg->non_periodic_qh_ptr == in dwc2_process_non_periodic_channels()
3081 &hsotg->non_periodic_sched_active) in dwc2_process_non_periodic_channels()
3082 hsotg->non_periodic_qh_ptr = in dwc2_process_non_periodic_channels()
3083 hsotg->non_periodic_qh_ptr->next; in dwc2_process_non_periodic_channels()
3084 } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr); in dwc2_process_non_periodic_channels()
3086 if (!hsotg->params.host_dma) { in dwc2_process_non_periodic_channels()
3087 tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_process_non_periodic_channels()
3092 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3095 dev_vdbg(hsotg->dev, in dwc2_process_non_periodic_channels()
3107 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_non_periodic_channels()
3109 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_non_periodic_channels()
3118 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_process_non_periodic_channels()
3120 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_process_non_periodic_channels()
3136 void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg, in dwc2_hcd_queue_transactions() argument
3140 dev_vdbg(hsotg->dev, "Queue Transactions\n"); in dwc2_hcd_queue_transactions()
3145 dwc2_process_periodic_channels(hsotg); in dwc2_hcd_queue_transactions()
3150 if (!list_empty(&hsotg->non_periodic_sched_active)) { in dwc2_hcd_queue_transactions()
3151 dwc2_process_non_periodic_channels(hsotg); in dwc2_hcd_queue_transactions()
3157 u32 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hcd_queue_transactions()
3160 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_hcd_queue_transactions()
3167 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_conn_id_status_change() local
3173 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_conn_id_status_change()
3175 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_conn_id_status_change()
3176 dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl); in dwc2_conn_id_status_change()
3177 dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n", in dwc2_conn_id_status_change()
3182 dwc2_vbus_supply_exit(hsotg); in dwc2_conn_id_status_change()
3184 dev_dbg(hsotg->dev, "connId B\n"); in dwc2_conn_id_status_change()
3185 if (hsotg->bus_suspended) { in dwc2_conn_id_status_change()
3186 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3188 dwc2_port_resume(hsotg); in dwc2_conn_id_status_change()
3190 while (!dwc2_is_device_mode(hsotg)) { in dwc2_conn_id_status_change()
3191 dev_info(hsotg->dev, in dwc2_conn_id_status_change()
3193 dwc2_is_host_mode(hsotg) ? "Host" : in dwc2_conn_id_status_change()
3201 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_conn_id_status_change()
3208 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3210 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_conn_id_status_change()
3211 dwc2_core_init(hsotg, false); in dwc2_conn_id_status_change()
3212 dwc2_enable_global_interrupts(hsotg); in dwc2_conn_id_status_change()
3213 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3214 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_conn_id_status_change()
3215 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3217 dwc2_enable_acg(hsotg); in dwc2_conn_id_status_change()
3218 dwc2_hsotg_core_connect(hsotg); in dwc2_conn_id_status_change()
3222 dev_dbg(hsotg->dev, "connId A\n"); in dwc2_conn_id_status_change()
3223 while (!dwc2_is_host_mode(hsotg)) { in dwc2_conn_id_status_change()
3224 dev_info(hsotg->dev, "Waiting for Host Mode, Mode=%s\n", in dwc2_conn_id_status_change()
3225 dwc2_is_host_mode(hsotg) ? in dwc2_conn_id_status_change()
3232 dev_err(hsotg->dev, in dwc2_conn_id_status_change()
3235 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3236 dwc2_hsotg_disconnect(hsotg); in dwc2_conn_id_status_change()
3237 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_conn_id_status_change()
3239 hsotg->op_state = OTG_STATE_A_HOST; in dwc2_conn_id_status_change()
3241 dwc2_core_init(hsotg, false); in dwc2_conn_id_status_change()
3242 dwc2_enable_global_interrupts(hsotg); in dwc2_conn_id_status_change()
3243 dwc2_hcd_start(hsotg); in dwc2_conn_id_status_change()
3249 struct dwc2_hsotg *hsotg = from_timer(hsotg, t, wkp_timer); in dwc2_wakeup_detected() local
3252 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_wakeup_detected()
3258 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_wakeup_detected()
3259 dev_dbg(hsotg->dev, "Resume: HPRT0=%0x\n", hprt0); in dwc2_wakeup_detected()
3261 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_wakeup_detected()
3262 dev_dbg(hsotg->dev, "Clear Resume: HPRT0=%0x\n", in dwc2_wakeup_detected()
3263 dwc2_readl(hsotg, HPRT0)); in dwc2_wakeup_detected()
3265 dwc2_hcd_rem_wakeup(hsotg); in dwc2_wakeup_detected()
3266 hsotg->bus_suspended = false; in dwc2_wakeup_detected()
3269 hsotg->lx_state = DWC2_L0; in dwc2_wakeup_detected()
3272 static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg) in dwc2_host_is_b_hnp_enabled() argument
3274 struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_host_is_b_hnp_enabled()
3280 static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex) in dwc2_port_suspend() argument
3287 dev_dbg(hsotg->dev, "%s()\n", __func__); in dwc2_port_suspend()
3289 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_suspend()
3291 if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) { in dwc2_port_suspend()
3292 gotgctl = dwc2_readl(hsotg, GOTGCTL); in dwc2_port_suspend()
3294 dwc2_writel(hsotg, gotgctl, GOTGCTL); in dwc2_port_suspend()
3295 hsotg->op_state = OTG_STATE_A_SUSPEND; in dwc2_port_suspend()
3298 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_port_suspend()
3300 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_port_suspend()
3302 hsotg->bus_suspended = true; in dwc2_port_suspend()
3308 if (!hsotg->params.power_down) { in dwc2_port_suspend()
3310 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_port_suspend()
3312 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_port_suspend()
3317 if (dwc2_host_is_b_hnp_enabled(hsotg)) { in dwc2_port_suspend()
3318 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_port_suspend()
3320 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_port_suspend()
3322 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3326 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_suspend()
3331 static void dwc2_port_resume(struct dwc2_hsotg *hsotg) in dwc2_port_resume() argument
3337 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3343 if (!hsotg->params.power_down) { in dwc2_port_resume()
3344 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_port_resume()
3346 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_port_resume()
3347 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3349 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3352 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_port_resume()
3355 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_port_resume()
3356 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3360 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_port_resume()
3361 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_port_resume()
3363 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_port_resume()
3364 hsotg->bus_suspended = false; in dwc2_port_resume()
3365 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_port_resume()
3369 static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq, in dwc2_hcd_hub_control() argument
3382 dev_dbg(hsotg->dev, "ClearHubFeature %1xh\n", wvalue); in dwc2_hcd_hub_control()
3392 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3404 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3406 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3408 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3412 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3415 if (hsotg->bus_suspended) { in dwc2_hcd_hub_control()
3416 if (hsotg->hibernated) in dwc2_hcd_hub_control()
3417 dwc2_exit_hibernation(hsotg, 0, 0, 1); in dwc2_hcd_hub_control()
3419 dwc2_port_resume(hsotg); in dwc2_hcd_hub_control()
3424 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3426 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3429 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3431 dwc2_vbus_supply_exit(hsotg); in dwc2_hcd_hub_control()
3435 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3444 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3446 hsotg->flags.b.port_connect_status_change = 0; in dwc2_hcd_hub_control()
3451 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3453 hsotg->flags.b.port_reset_change = 0; in dwc2_hcd_hub_control()
3461 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3463 hsotg->flags.b.port_enable_change = 0; in dwc2_hcd_hub_control()
3472 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3474 hsotg->flags.b.port_suspend_change = 0; in dwc2_hcd_hub_control()
3478 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3480 hsotg->flags.b.port_l1_change = 0; in dwc2_hcd_hub_control()
3484 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3486 hsotg->flags.b.port_over_current_change = 0; in dwc2_hcd_hub_control()
3491 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3498 dev_dbg(hsotg->dev, "GetHubDescriptor\n"); in dwc2_hcd_hub_control()
3513 dev_dbg(hsotg->dev, "GetHubStatus\n"); in dwc2_hcd_hub_control()
3518 dev_vdbg(hsotg->dev, in dwc2_hcd_hub_control()
3520 hsotg->flags.d32); in dwc2_hcd_hub_control()
3525 if (hsotg->flags.b.port_connect_status_change) in dwc2_hcd_hub_control()
3527 if (hsotg->flags.b.port_enable_change) in dwc2_hcd_hub_control()
3529 if (hsotg->flags.b.port_suspend_change) in dwc2_hcd_hub_control()
3531 if (hsotg->flags.b.port_l1_change) in dwc2_hcd_hub_control()
3533 if (hsotg->flags.b.port_reset_change) in dwc2_hcd_hub_control()
3535 if (hsotg->flags.b.port_over_current_change) { in dwc2_hcd_hub_control()
3536 dev_warn(hsotg->dev, "Overcurrent change detected\n"); in dwc2_hcd_hub_control()
3540 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_hub_control()
3552 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_hub_control()
3553 dev_vdbg(hsotg->dev, " HPRT0: 0x%08x\n", hprt0); in dwc2_hcd_hub_control()
3578 if (hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_hub_control()
3583 if (hsotg->new_connection && in dwc2_hcd_hub_control()
3591 dev_info(hsotg->dev, "Enabling descriptor DMA mode\n"); in dwc2_hcd_hub_control()
3592 hsotg->params.dma_desc_enable = true; in dwc2_hcd_hub_control()
3593 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_hcd_hub_control()
3595 dwc2_writel(hsotg, hcfg, HCFG); in dwc2_hcd_hub_control()
3596 hsotg->new_connection = false; in dwc2_hcd_hub_control()
3600 dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); in dwc2_hcd_hub_control()
3605 dev_dbg(hsotg->dev, "SetHubFeature\n"); in dwc2_hcd_hub_control()
3610 dev_dbg(hsotg->dev, "SetPortFeature\n"); in dwc2_hcd_hub_control()
3614 if (!hsotg->flags.b.port_connect_status) { in dwc2_hcd_hub_control()
3627 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3629 if (windex != hsotg->otg_port) in dwc2_hcd_hub_control()
3631 if (hsotg->params.power_down == 2) in dwc2_hcd_hub_control()
3632 dwc2_enter_hibernation(hsotg, 1); in dwc2_hcd_hub_control()
3634 dwc2_port_suspend(hsotg, windex); in dwc2_hcd_hub_control()
3638 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3640 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3643 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3645 dwc2_vbus_supply_init(hsotg); in dwc2_hcd_hub_control()
3649 if (hsotg->params.power_down == 2 && in dwc2_hcd_hub_control()
3650 hsotg->hibernated) in dwc2_hcd_hub_control()
3651 dwc2_exit_hibernation(hsotg, 0, 1, 1); in dwc2_hcd_hub_control()
3652 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3653 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3655 pcgctl = dwc2_readl(hsotg, PCGCTL); in dwc2_hcd_hub_control()
3657 dwc2_writel(hsotg, pcgctl, PCGCTL); in dwc2_hcd_hub_control()
3659 dwc2_writel(hsotg, 0, PCGCTL); in dwc2_hcd_hub_control()
3661 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3671 if (!dwc2_hcd_is_b_host(hsotg)) { in dwc2_hcd_hub_control()
3673 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3675 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3677 dwc2_vbus_supply_init(hsotg); in dwc2_hcd_hub_control()
3683 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3684 hsotg->lx_state = DWC2_L0; /* Now back to On state */ in dwc2_hcd_hub_control()
3688 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3694 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_hub_control()
3695 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3699 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_hub_control()
3704 dev_err(hsotg->dev, in dwc2_hcd_hub_control()
3714 dev_dbg(hsotg->dev, in dwc2_hcd_hub_control()
3723 static int dwc2_hcd_is_status_changed(struct dwc2_hsotg *hsotg, int port) in dwc2_hcd_is_status_changed() argument
3730 retval = (hsotg->flags.b.port_connect_status_change || in dwc2_hcd_is_status_changed()
3731 hsotg->flags.b.port_reset_change || in dwc2_hcd_is_status_changed()
3732 hsotg->flags.b.port_enable_change || in dwc2_hcd_is_status_changed()
3733 hsotg->flags.b.port_suspend_change || in dwc2_hcd_is_status_changed()
3734 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3737 dev_dbg(hsotg->dev, in dwc2_hcd_is_status_changed()
3739 dev_dbg(hsotg->dev, " port_connect_status_change: %d\n", in dwc2_hcd_is_status_changed()
3740 hsotg->flags.b.port_connect_status_change); in dwc2_hcd_is_status_changed()
3741 dev_dbg(hsotg->dev, " port_reset_change: %d\n", in dwc2_hcd_is_status_changed()
3742 hsotg->flags.b.port_reset_change); in dwc2_hcd_is_status_changed()
3743 dev_dbg(hsotg->dev, " port_enable_change: %d\n", in dwc2_hcd_is_status_changed()
3744 hsotg->flags.b.port_enable_change); in dwc2_hcd_is_status_changed()
3745 dev_dbg(hsotg->dev, " port_suspend_change: %d\n", in dwc2_hcd_is_status_changed()
3746 hsotg->flags.b.port_suspend_change); in dwc2_hcd_is_status_changed()
3747 dev_dbg(hsotg->dev, " port_over_current_change: %d\n", in dwc2_hcd_is_status_changed()
3748 hsotg->flags.b.port_over_current_change); in dwc2_hcd_is_status_changed()
3754 int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) in dwc2_hcd_get_frame_number() argument
3756 u32 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_get_frame_number()
3759 dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n", in dwc2_hcd_get_frame_number()
3765 int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us) in dwc2_hcd_get_future_frame_number() argument
3767 u32 hprt = dwc2_readl(hsotg, HPRT0); in dwc2_hcd_get_future_frame_number()
3768 u32 hfir = dwc2_readl(hsotg, HFIR); in dwc2_hcd_get_future_frame_number()
3769 u32 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_get_future_frame_number()
3794 int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg) in dwc2_hcd_is_b_host() argument
3796 return hsotg->op_state == OTG_STATE_B_HOST; in dwc2_hcd_is_b_host()
3799 static struct dwc2_hcd_urb *dwc2_hcd_urb_alloc(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_alloc() argument
3811 static void dwc2_hcd_urb_set_pipeinfo(struct dwc2_hsotg *hsotg, in dwc2_hcd_urb_set_pipeinfo() argument
3819 dev_vdbg(hsotg->dev, in dwc2_hcd_urb_set_pipeinfo()
3834 void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg) in dwc2_hcd_dump_state() argument
3845 num_channels = hsotg->params.host_channels; in dwc2_hcd_dump_state()
3846 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3847 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3849 dev_dbg(hsotg->dev, "HCD State:\n"); in dwc2_hcd_dump_state()
3850 dev_dbg(hsotg->dev, " Num channels: %d\n", num_channels); in dwc2_hcd_dump_state()
3853 chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_dump_state()
3854 dev_dbg(hsotg->dev, " Channel %d:\n", i); in dwc2_hcd_dump_state()
3855 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3858 dev_dbg(hsotg->dev, " speed: %d\n", chan->speed); in dwc2_hcd_dump_state()
3859 dev_dbg(hsotg->dev, " ep_type: %d\n", chan->ep_type); in dwc2_hcd_dump_state()
3860 dev_dbg(hsotg->dev, " max_packet: %d\n", chan->max_packet); in dwc2_hcd_dump_state()
3861 dev_dbg(hsotg->dev, " data_pid_start: %d\n", in dwc2_hcd_dump_state()
3863 dev_dbg(hsotg->dev, " multi_count: %d\n", chan->multi_count); in dwc2_hcd_dump_state()
3864 dev_dbg(hsotg->dev, " xfer_started: %d\n", in dwc2_hcd_dump_state()
3866 dev_dbg(hsotg->dev, " xfer_buf: %p\n", chan->xfer_buf); in dwc2_hcd_dump_state()
3867 dev_dbg(hsotg->dev, " xfer_dma: %08lx\n", in dwc2_hcd_dump_state()
3869 dev_dbg(hsotg->dev, " xfer_len: %d\n", chan->xfer_len); in dwc2_hcd_dump_state()
3870 dev_dbg(hsotg->dev, " xfer_count: %d\n", chan->xfer_count); in dwc2_hcd_dump_state()
3871 dev_dbg(hsotg->dev, " halt_on_queue: %d\n", in dwc2_hcd_dump_state()
3873 dev_dbg(hsotg->dev, " halt_pending: %d\n", in dwc2_hcd_dump_state()
3875 dev_dbg(hsotg->dev, " halt_status: %d\n", chan->halt_status); in dwc2_hcd_dump_state()
3876 dev_dbg(hsotg->dev, " do_split: %d\n", chan->do_split); in dwc2_hcd_dump_state()
3877 dev_dbg(hsotg->dev, " complete_split: %d\n", in dwc2_hcd_dump_state()
3879 dev_dbg(hsotg->dev, " hub_addr: %d\n", chan->hub_addr); in dwc2_hcd_dump_state()
3880 dev_dbg(hsotg->dev, " hub_port: %d\n", chan->hub_port); in dwc2_hcd_dump_state()
3881 dev_dbg(hsotg->dev, " xact_pos: %d\n", chan->xact_pos); in dwc2_hcd_dump_state()
3882 dev_dbg(hsotg->dev, " requests: %d\n", chan->requests); in dwc2_hcd_dump_state()
3883 dev_dbg(hsotg->dev, " qh: %p\n", chan->qh); in dwc2_hcd_dump_state()
3888 hfnum = dwc2_readl(hsotg, HFNUM); in dwc2_hcd_dump_state()
3889 hcchar = dwc2_readl(hsotg, HCCHAR(i)); in dwc2_hcd_dump_state()
3890 hctsiz = dwc2_readl(hsotg, HCTSIZ(i)); in dwc2_hcd_dump_state()
3891 hcint = dwc2_readl(hsotg, HCINT(i)); in dwc2_hcd_dump_state()
3892 hcintmsk = dwc2_readl(hsotg, HCINTMSK(i)); in dwc2_hcd_dump_state()
3893 dev_dbg(hsotg->dev, " hfnum: 0x%08x\n", hfnum); in dwc2_hcd_dump_state()
3894 dev_dbg(hsotg->dev, " hcchar: 0x%08x\n", hcchar); in dwc2_hcd_dump_state()
3895 dev_dbg(hsotg->dev, " hctsiz: 0x%08x\n", hctsiz); in dwc2_hcd_dump_state()
3896 dev_dbg(hsotg->dev, " hcint: 0x%08x\n", hcint); in dwc2_hcd_dump_state()
3897 dev_dbg(hsotg->dev, " hcintmsk: 0x%08x\n", hcintmsk); in dwc2_hcd_dump_state()
3907 dev_dbg(hsotg->dev, " URB Info:\n"); in dwc2_hcd_dump_state()
3908 dev_dbg(hsotg->dev, " qtd: %p, urb: %p\n", in dwc2_hcd_dump_state()
3911 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3917 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3921 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3924 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3927 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3930 dev_dbg(hsotg->dev, " actual_length: %d\n", in dwc2_hcd_dump_state()
3936 dev_dbg(hsotg->dev, " non_periodic_channels: %d\n", in dwc2_hcd_dump_state()
3937 hsotg->non_periodic_channels); in dwc2_hcd_dump_state()
3938 dev_dbg(hsotg->dev, " periodic_channels: %d\n", in dwc2_hcd_dump_state()
3939 hsotg->periodic_channels); in dwc2_hcd_dump_state()
3940 dev_dbg(hsotg->dev, " periodic_usecs: %d\n", hsotg->periodic_usecs); in dwc2_hcd_dump_state()
3941 np_tx_status = dwc2_readl(hsotg, GNPTXSTS); in dwc2_hcd_dump_state()
3942 dev_dbg(hsotg->dev, " NP Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3944 dev_dbg(hsotg->dev, " NP Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3946 p_tx_status = dwc2_readl(hsotg, HPTXSTS); in dwc2_hcd_dump_state()
3947 dev_dbg(hsotg->dev, " P Tx Req Queue Space Avail: %d\n", in dwc2_hcd_dump_state()
3949 dev_dbg(hsotg->dev, " P Tx FIFO Space Avail: %d\n", in dwc2_hcd_dump_state()
3951 dwc2_dump_global_registers(hsotg); in dwc2_hcd_dump_state()
3952 dwc2_dump_host_registers(hsotg); in dwc2_hcd_dump_state()
3953 dev_dbg(hsotg->dev, in dwc2_hcd_dump_state()
3955 dev_dbg(hsotg->dev, "\n"); in dwc2_hcd_dump_state()
3960 struct dwc2_hsotg *hsotg; member
3969 return p->hsotg; in dwc2_hcd_to_hsotg()
3992 struct dwc2_tt *dwc2_host_get_tt_info(struct dwc2_hsotg *hsotg, void *context, in dwc2_host_get_tt_info() argument
4040 void dwc2_host_put_tt_info(struct dwc2_hsotg *hsotg, struct dwc2_tt *dwc_tt) in dwc2_host_put_tt_info() argument
4055 int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context) in dwc2_host_get_speed() argument
4094 void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, in dwc2_host_complete() argument
4101 dev_dbg(hsotg->dev, "## %s: qtd is NULL ##\n", __func__); in dwc2_host_complete()
4106 dev_dbg(hsotg->dev, "## %s: qtd->urb is NULL ##\n", __func__); in dwc2_host_complete()
4112 dev_dbg(hsotg->dev, "## %s: urb->priv is NULL ##\n", __func__); in dwc2_host_complete()
4119 dev_vdbg(hsotg->dev, in dwc2_host_complete()
4139 dev_vdbg(hsotg->dev, " ISO Desc %d status %d\n", in dwc2_host_complete()
4155 dwc2_free_bus_bandwidth(dwc2_hsotg_to_hcd(hsotg), in dwc2_host_complete()
4156 dwc2_hcd_get_ep_bandwidth(hsotg, ep), in dwc2_host_complete()
4160 usb_hcd_unlink_urb_from_ep(dwc2_hsotg_to_hcd(hsotg), urb); in dwc2_host_complete()
4165 usb_hcd_giveback_urb(dwc2_hsotg_to_hcd(hsotg), urb, status); in dwc2_host_complete()
4173 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_start_func() local
4176 dev_dbg(hsotg->dev, "%s() %p\n", __func__, hsotg); in dwc2_hcd_start_func()
4177 dwc2_host_start(hsotg); in dwc2_hcd_start_func()
4185 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_reset_func() local
4190 dev_dbg(hsotg->dev, "USB RESET function called\n"); in dwc2_hcd_reset_func()
4192 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4194 hprt0 = dwc2_read_hprt0(hsotg); in dwc2_hcd_reset_func()
4196 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_hcd_reset_func()
4197 hsotg->flags.b.port_reset_change = 1; in dwc2_hcd_reset_func()
4199 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hcd_reset_func()
4204 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, in dwc2_hcd_phy_reset_func() local
4208 ret = phy_reset(hsotg->phy); in dwc2_hcd_phy_reset_func()
4210 dev_warn(hsotg->dev, "PHY reset failed\n"); in dwc2_hcd_phy_reset_func()
4226 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_start() local
4232 dev_dbg(hsotg->dev, "DWC OTG HCD START\n"); in _dwc2_hcd_start()
4234 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4235 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_start()
4239 if (dwc2_is_device_mode(hsotg)) { in _dwc2_hcd_start()
4240 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4244 dwc2_hcd_reinit(hsotg); in _dwc2_hcd_start()
4246 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_start()
4250 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4251 ret = dwc2_vbus_supply_init(hsotg); in _dwc2_hcd_start()
4254 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_start()
4259 dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n"); in _dwc2_hcd_start()
4264 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_start()
4275 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_stop() local
4280 dwc2_disable_host_interrupts(hsotg); in _dwc2_hcd_stop()
4285 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_stop()
4286 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_stop()
4288 dwc2_hcd_disconnect(hsotg, true); in _dwc2_hcd_stop()
4289 dwc2_hcd_stop(hsotg); in _dwc2_hcd_stop()
4290 hsotg->lx_state = DWC2_L3; in _dwc2_hcd_stop()
4293 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_stop()
4297 dwc2_vbus_supply_exit(hsotg); in _dwc2_hcd_stop()
4304 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_suspend() local
4310 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4312 if (dwc2_is_device_mode(hsotg)) in _dwc2_hcd_suspend()
4315 if (hsotg->lx_state != DWC2_L0) in _dwc2_hcd_suspend()
4321 if (hsotg->op_state == OTG_STATE_B_PERIPHERAL) in _dwc2_hcd_suspend()
4324 if (hsotg->params.power_down > DWC2_POWER_DOWN_PARAM_PARTIAL) in _dwc2_hcd_suspend()
4331 if (!hsotg->bus_suspended) { in _dwc2_hcd_suspend()
4332 hprt0 = dwc2_read_hprt0(hsotg); in _dwc2_hcd_suspend()
4335 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) in _dwc2_hcd_suspend()
4337 dwc2_writel(hsotg, hprt0, HPRT0); in _dwc2_hcd_suspend()
4339 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_suspend()
4340 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4341 dwc2_vbus_supply_exit(hsotg); in _dwc2_hcd_suspend()
4342 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4344 pcgctl = readl(hsotg->regs + PCGCTL); in _dwc2_hcd_suspend()
4346 writel(pcgctl, hsotg->regs + PCGCTL); in _dwc2_hcd_suspend()
4350 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_suspend()
4352 ret = dwc2_enter_partial_power_down(hsotg); in _dwc2_hcd_suspend()
4355 dev_err(hsotg->dev, in _dwc2_hcd_suspend()
4365 if (!IS_ERR_OR_NULL(hsotg->uphy)) { in _dwc2_hcd_suspend()
4366 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4367 usb_phy_set_suspend(hsotg->uphy, true); in _dwc2_hcd_suspend()
4368 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4372 hsotg->lx_state = DWC2_L2; in _dwc2_hcd_suspend()
4374 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_suspend()
4381 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_resume() local
4386 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4388 if (dwc2_is_device_mode(hsotg)) in _dwc2_hcd_resume()
4391 if (hsotg->lx_state != DWC2_L2) in _dwc2_hcd_resume()
4394 if (hsotg->params.power_down > DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_resume()
4395 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4404 if (!IS_ERR_OR_NULL(hsotg->uphy)) { in _dwc2_hcd_resume()
4405 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4406 usb_phy_set_suspend(hsotg->uphy, false); in _dwc2_hcd_resume()
4407 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4410 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_resume()
4419 ret = dwc2_exit_partial_power_down(hsotg, true); in _dwc2_hcd_resume()
4421 dev_err(hsotg->dev, "exit partial_power_down failed\n"); in _dwc2_hcd_resume()
4423 pcgctl = readl(hsotg->regs + PCGCTL); in _dwc2_hcd_resume()
4425 writel(pcgctl, hsotg->regs + PCGCTL); in _dwc2_hcd_resume()
4428 hsotg->lx_state = DWC2_L0; in _dwc2_hcd_resume()
4430 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4432 if (hsotg->bus_suspended) { in _dwc2_hcd_resume()
4433 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_resume()
4434 hsotg->flags.b.port_suspend_change = 1; in _dwc2_hcd_resume()
4435 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4436 dwc2_port_resume(hsotg); in _dwc2_hcd_resume()
4438 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { in _dwc2_hcd_resume()
4439 dwc2_vbus_supply_init(hsotg); in _dwc2_hcd_resume()
4449 dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET | in _dwc2_hcd_resume()
4457 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_resume()
4465 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_get_frame_number() local
4467 return dwc2_hcd_get_frame_number(hsotg); in _dwc2_hcd_get_frame_number()
4474 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_dump_urb_info() local
4478 dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb); in dwc2_dump_urb_info()
4479 dev_vdbg(hsotg->dev, " Device address: %d\n", in dwc2_dump_urb_info()
4481 dev_vdbg(hsotg->dev, " Endpoint: %d, %s\n", in dwc2_dump_urb_info()
4500 dev_vdbg(hsotg->dev, " Endpoint type: %s %s (%s)\n", pipetype, in dwc2_dump_urb_info()
4519 dev_vdbg(hsotg->dev, " Speed: %s\n", speed); in dwc2_dump_urb_info()
4520 dev_vdbg(hsotg->dev, " Max packet size: %d (%d mult)\n", in dwc2_dump_urb_info()
4524 dev_vdbg(hsotg->dev, " Data buffer length: %d\n", in dwc2_dump_urb_info()
4526 dev_vdbg(hsotg->dev, " Transfer buffer: %p, Transfer DMA: %08lx\n", in dwc2_dump_urb_info()
4528 dev_vdbg(hsotg->dev, " Setup buffer: %p, Setup DMA: %08lx\n", in dwc2_dump_urb_info()
4530 dev_vdbg(hsotg->dev, " Interval: %d\n", urb->interval); in dwc2_dump_urb_info()
4536 dev_vdbg(hsotg->dev, " ISO Desc %d:\n", i); in dwc2_dump_urb_info()
4537 dev_vdbg(hsotg->dev, " offset: %d, length %d\n", in dwc2_dump_urb_info()
4553 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_urb_enqueue() local
4568 dev_vdbg(hsotg->dev, "DWC OTG HCD URB Enqueue\n"); in _dwc2_hcd_urb_enqueue()
4577 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4578 if (!dwc2_hcd_is_bandwidth_allocated(hsotg, ep)) in _dwc2_hcd_urb_enqueue()
4580 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4598 dwc2_urb = dwc2_hcd_urb_alloc(hsotg, urb->number_of_packets, in _dwc2_hcd_urb_enqueue()
4603 dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, usb_pipedevice(urb->pipe), in _dwc2_hcd_urb_enqueue()
4613 dev_err(hsotg->dev, in _dwc2_hcd_urb_enqueue()
4645 qh = dwc2_hcd_qh_create(hsotg, dwc2_urb, mem_flags); in _dwc2_hcd_urb_enqueue()
4660 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4665 retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, qh, qtd); in _dwc2_hcd_urb_enqueue()
4671 dwc2_hcd_get_ep_bandwidth(hsotg, ep), in _dwc2_hcd_urb_enqueue()
4675 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4685 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_enqueue()
4693 dwc2_hcd_qh_unlink(hsotg, qh); in _dwc2_hcd_urb_enqueue()
4697 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh); in _dwc2_hcd_urb_enqueue()
4698 dwc2_hcd_qh_free(hsotg, qh); in _dwc2_hcd_urb_enqueue()
4712 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_urb_dequeue() local
4716 dev_dbg(hsotg->dev, "DWC OTG HCD URB Dequeue\n"); in _dwc2_hcd_urb_dequeue()
4719 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4726 dev_dbg(hsotg->dev, "## urb->hcpriv is NULL ##\n"); in _dwc2_hcd_urb_dequeue()
4730 rc = dwc2_hcd_urb_dequeue(hsotg, urb->hcpriv); in _dwc2_hcd_urb_dequeue()
4738 spin_unlock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4740 spin_lock(&hsotg->lock); in _dwc2_hcd_urb_dequeue()
4742 dev_dbg(hsotg->dev, "Called usb_hcd_giveback_urb()\n"); in _dwc2_hcd_urb_dequeue()
4743 dev_dbg(hsotg->dev, " urb->status = %d\n", urb->status); in _dwc2_hcd_urb_dequeue()
4745 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_urb_dequeue()
4758 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_endpoint_disable() local
4760 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_disable()
4763 dwc2_hcd_endpoint_disable(hsotg, ep, 250); in _dwc2_hcd_endpoint_disable()
4774 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_endpoint_reset() local
4777 dev_dbg(hsotg->dev, in _dwc2_hcd_endpoint_reset()
4781 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4782 dwc2_hcd_endpoint_reset(hsotg, ep); in _dwc2_hcd_endpoint_reset()
4783 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_endpoint_reset()
4795 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_irq() local
4797 return dwc2_handle_hcd_intr(hsotg); in _dwc2_hcd_irq()
4808 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_hub_status_data() local
4810 buf[0] = dwc2_hcd_is_status_changed(hsotg, 1) << 1; in _dwc2_hcd_hub_status_data()
4827 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in _dwc2_hcd_clear_tt_buffer_complete() local
4835 spin_lock_irqsave(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4838 if (hsotg->flags.b.port_connect_status) in _dwc2_hcd_clear_tt_buffer_complete()
4839 dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_ALL); in _dwc2_hcd_clear_tt_buffer_complete()
4841 spin_unlock_irqrestore(&hsotg->lock, flags); in _dwc2_hcd_clear_tt_buffer_complete()
4850 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_change_bus_speed() local
4852 if (hsotg->params.speed == speed) in dwc2_change_bus_speed()
4855 hsotg->params.speed = speed; in dwc2_change_bus_speed()
4856 queue_work(hsotg->wq_otg, &hsotg->wf_otg); in dwc2_change_bus_speed()
4861 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_free_dev() local
4863 if (!hsotg->params.change_speed_quirk) in dwc2_free_dev()
4871 dev_info(hsotg->dev, "Set speed to default high-speed\n"); in dwc2_free_dev()
4878 struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); in dwc2_reset_device() local
4880 if (!hsotg->params.change_speed_quirk) in dwc2_reset_device()
4884 dev_info(hsotg->dev, "Set speed to high-speed\n"); in dwc2_reset_device()
4892 dev_info(hsotg->dev, "Set speed to full-speed\n"); in dwc2_reset_device()
4930 static void dwc2_hcd_free(struct dwc2_hsotg *hsotg) in dwc2_hcd_free() argument
4936 dev_dbg(hsotg->dev, "DWC OTG HCD FREE\n"); in dwc2_hcd_free()
4939 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_inactive); in dwc2_hcd_free()
4940 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_waiting); in dwc2_hcd_free()
4941 dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_active); in dwc2_hcd_free()
4942 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_inactive); in dwc2_hcd_free()
4943 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_ready); in dwc2_hcd_free()
4944 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_assigned); in dwc2_hcd_free()
4945 dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_queued); in dwc2_hcd_free()
4949 struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i]; in dwc2_hcd_free()
4952 dev_dbg(hsotg->dev, "HCD Free channel #%i, chan=%p\n", in dwc2_hcd_free()
4954 hsotg->hc_ptr_array[i] = NULL; in dwc2_hcd_free()
4959 if (hsotg->params.host_dma) { in dwc2_hcd_free()
4960 if (hsotg->status_buf) { in dwc2_hcd_free()
4961 dma_free_coherent(hsotg->dev, DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_free()
4962 hsotg->status_buf, in dwc2_hcd_free()
4963 hsotg->status_buf_dma); in dwc2_hcd_free()
4964 hsotg->status_buf = NULL; in dwc2_hcd_free()
4967 kfree(hsotg->status_buf); in dwc2_hcd_free()
4968 hsotg->status_buf = NULL; in dwc2_hcd_free()
4971 ahbcfg = dwc2_readl(hsotg, GAHBCFG); in dwc2_hcd_free()
4975 dwc2_writel(hsotg, ahbcfg, GAHBCFG); in dwc2_hcd_free()
4976 dwc2_writel(hsotg, 0, GINTMSK); in dwc2_hcd_free()
4978 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) { in dwc2_hcd_free()
4979 dctl = dwc2_readl(hsotg, DCTL); in dwc2_hcd_free()
4981 dwc2_writel(hsotg, dctl, DCTL); in dwc2_hcd_free()
4984 if (hsotg->wq_otg) { in dwc2_hcd_free()
4985 if (!cancel_work_sync(&hsotg->wf_otg)) in dwc2_hcd_free()
4986 flush_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
4987 destroy_workqueue(hsotg->wq_otg); in dwc2_hcd_free()
4990 cancel_work_sync(&hsotg->phy_reset_work); in dwc2_hcd_free()
4992 del_timer(&hsotg->wkp_timer); in dwc2_hcd_free()
4995 static void dwc2_hcd_release(struct dwc2_hsotg *hsotg) in dwc2_hcd_release() argument
4998 dwc2_disable_host_interrupts(hsotg); in dwc2_hcd_release()
5000 dwc2_hcd_free(hsotg); in dwc2_hcd_release()
5009 int dwc2_hcd_init(struct dwc2_hsotg *hsotg) in dwc2_hcd_init() argument
5011 struct platform_device *pdev = to_platform_device(hsotg->dev); in dwc2_hcd_init()
5022 dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); in dwc2_hcd_init()
5026 hcfg = dwc2_readl(hsotg, HCFG); in dwc2_hcd_init()
5027 dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); in dwc2_hcd_init()
5030 hsotg->frame_num_array = kcalloc(FRAME_NUM_ARRAY_SIZE, in dwc2_hcd_init()
5031 sizeof(*hsotg->frame_num_array), in dwc2_hcd_init()
5033 if (!hsotg->frame_num_array) in dwc2_hcd_init()
5035 hsotg->last_frame_num_array = in dwc2_hcd_init()
5037 sizeof(*hsotg->last_frame_num_array), GFP_KERNEL); in dwc2_hcd_init()
5038 if (!hsotg->last_frame_num_array) in dwc2_hcd_init()
5041 hsotg->last_frame_num = HFNUM_MAX_FRNUM; in dwc2_hcd_init()
5044 if (hsotg->params.host_dma && in dwc2_hcd_init()
5045 !hsotg->dev->dma_mask) { in dwc2_hcd_init()
5046 dev_warn(hsotg->dev, in dwc2_hcd_init()
5048 hsotg->params.host_dma = false; in dwc2_hcd_init()
5049 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5053 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5054 if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5055 dev_warn(hsotg->dev, "can't set DMA mask\n"); in dwc2_hcd_init()
5056 if (dma_set_coherent_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0) in dwc2_hcd_init()
5057 dev_warn(hsotg->dev, "can't set coherent DMA mask\n"); in dwc2_hcd_init()
5060 if (hsotg->params.change_speed_quirk) { in dwc2_hcd_init()
5065 if (hsotg->params.host_dma) in dwc2_hcd_init()
5068 hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev)); in dwc2_hcd_init()
5078 ((struct wrapper_priv_data *)&hcd->hcd_priv)->hsotg = hsotg; in dwc2_hcd_init()
5079 hsotg->priv = hcd; in dwc2_hcd_init()
5085 dwc2_disable_global_interrupts(hsotg); in dwc2_hcd_init()
5088 retval = dwc2_core_init(hsotg, true); in dwc2_hcd_init()
5094 hsotg->wq_otg = alloc_ordered_workqueue("dwc2", 0); in dwc2_hcd_init()
5095 if (!hsotg->wq_otg) { in dwc2_hcd_init()
5096 dev_err(hsotg->dev, "Failed to create workqueue\n"); in dwc2_hcd_init()
5099 INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change); in dwc2_hcd_init()
5101 timer_setup(&hsotg->wkp_timer, dwc2_wakeup_detected, 0); in dwc2_hcd_init()
5104 INIT_LIST_HEAD(&hsotg->non_periodic_sched_inactive); in dwc2_hcd_init()
5105 INIT_LIST_HEAD(&hsotg->non_periodic_sched_waiting); in dwc2_hcd_init()
5106 INIT_LIST_HEAD(&hsotg->non_periodic_sched_active); in dwc2_hcd_init()
5109 INIT_LIST_HEAD(&hsotg->periodic_sched_inactive); in dwc2_hcd_init()
5110 INIT_LIST_HEAD(&hsotg->periodic_sched_ready); in dwc2_hcd_init()
5111 INIT_LIST_HEAD(&hsotg->periodic_sched_assigned); in dwc2_hcd_init()
5112 INIT_LIST_HEAD(&hsotg->periodic_sched_queued); in dwc2_hcd_init()
5114 INIT_LIST_HEAD(&hsotg->split_order); in dwc2_hcd_init()
5120 INIT_LIST_HEAD(&hsotg->free_hc_list); in dwc2_hcd_init()
5121 num_channels = hsotg->params.host_channels; in dwc2_hcd_init()
5122 memset(&hsotg->hc_ptr_array[0], 0, sizeof(hsotg->hc_ptr_array)); in dwc2_hcd_init()
5130 hsotg->hc_ptr_array[i] = channel; in dwc2_hcd_init()
5134 INIT_DELAYED_WORK(&hsotg->start_work, dwc2_hcd_start_func); in dwc2_hcd_init()
5135 INIT_DELAYED_WORK(&hsotg->reset_work, dwc2_hcd_reset_func); in dwc2_hcd_init()
5136 INIT_WORK(&hsotg->phy_reset_work, dwc2_hcd_phy_reset_func); in dwc2_hcd_init()
5144 if (hsotg->params.host_dma) in dwc2_hcd_init()
5145 hsotg->status_buf = dma_alloc_coherent(hsotg->dev, in dwc2_hcd_init()
5147 &hsotg->status_buf_dma, GFP_KERNEL); in dwc2_hcd_init()
5149 hsotg->status_buf = kzalloc(DWC2_HCD_STATUS_BUF_SIZE, in dwc2_hcd_init()
5152 if (!hsotg->status_buf) in dwc2_hcd_init()
5160 if (hsotg->params.dma_desc_enable || in dwc2_hcd_init()
5161 hsotg->params.dma_desc_fs_enable) { in dwc2_hcd_init()
5162 hsotg->desc_gen_cache = kmem_cache_create("dwc2-gen-desc", in dwc2_hcd_init()
5166 if (!hsotg->desc_gen_cache) { in dwc2_hcd_init()
5167 dev_err(hsotg->dev, in dwc2_hcd_init()
5174 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5175 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5178 hsotg->desc_hsisoc_cache = kmem_cache_create("dwc2-hsisoc-desc", in dwc2_hcd_init()
5181 if (!hsotg->desc_hsisoc_cache) { in dwc2_hcd_init()
5182 dev_err(hsotg->dev, in dwc2_hcd_init()
5185 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5191 hsotg->params.dma_desc_enable = false; in dwc2_hcd_init()
5192 hsotg->params.dma_desc_fs_enable = false; in dwc2_hcd_init()
5196 if (hsotg->params.host_dma) { in dwc2_hcd_init()
5201 hsotg->unaligned_cache = kmem_cache_create("dwc2-unaligned-dma", in dwc2_hcd_init()
5204 if (!hsotg->unaligned_cache) in dwc2_hcd_init()
5205 dev_err(hsotg->dev, in dwc2_hcd_init()
5209 hsotg->otg_port = 1; in dwc2_hcd_init()
5210 hsotg->frame_list = NULL; in dwc2_hcd_init()
5211 hsotg->frame_list_dma = 0; in dwc2_hcd_init()
5212 hsotg->periodic_qh_count = 0; in dwc2_hcd_init()
5215 hsotg->lx_state = DWC2_L3; in dwc2_hcd_init()
5217 hcd->self.otg_port = hsotg->otg_port; in dwc2_hcd_init()
5222 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_init()
5223 otg_set_host(hsotg->uphy->otg, &hcd->self); in dwc2_hcd_init()
5230 retval = usb_add_hcd(hcd, hsotg->irq, IRQF_SHARED); in dwc2_hcd_init()
5236 dwc2_hcd_dump_state(hsotg); in dwc2_hcd_init()
5238 dwc2_enable_global_interrupts(hsotg); in dwc2_hcd_init()
5243 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_init()
5244 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_init()
5245 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_init()
5247 dwc2_hcd_release(hsotg); in dwc2_hcd_init()
5253 kfree(hsotg->last_frame_num_array); in dwc2_hcd_init()
5254 kfree(hsotg->frame_num_array); in dwc2_hcd_init()
5257 dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval); in dwc2_hcd_init()
5265 void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) in dwc2_hcd_remove() argument
5269 dev_dbg(hsotg->dev, "DWC OTG HCD REMOVE\n"); in dwc2_hcd_remove()
5271 hcd = dwc2_hsotg_to_hcd(hsotg); in dwc2_hcd_remove()
5272 dev_dbg(hsotg->dev, "hsotg->hcd = %p\n", hcd); in dwc2_hcd_remove()
5275 dev_dbg(hsotg->dev, "%s: dwc2_hsotg_to_hcd(hsotg) NULL!\n", in dwc2_hcd_remove()
5280 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hcd_remove()
5281 otg_set_host(hsotg->uphy->otg, NULL); in dwc2_hcd_remove()
5284 hsotg->priv = NULL; in dwc2_hcd_remove()
5286 kmem_cache_destroy(hsotg->unaligned_cache); in dwc2_hcd_remove()
5287 kmem_cache_destroy(hsotg->desc_hsisoc_cache); in dwc2_hcd_remove()
5288 kmem_cache_destroy(hsotg->desc_gen_cache); in dwc2_hcd_remove()
5290 dwc2_hcd_release(hsotg); in dwc2_hcd_remove()
5294 kfree(hsotg->last_frame_num_array); in dwc2_hcd_remove()
5295 kfree(hsotg->frame_num_array); in dwc2_hcd_remove()
5306 int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) in dwc2_backup_host_registers() argument
5311 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_backup_host_registers()
5314 hr = &hsotg->hr_backup; in dwc2_backup_host_registers()
5315 hr->hcfg = dwc2_readl(hsotg, HCFG); in dwc2_backup_host_registers()
5316 hr->haintmsk = dwc2_readl(hsotg, HAINTMSK); in dwc2_backup_host_registers()
5317 for (i = 0; i < hsotg->params.host_channels; ++i) in dwc2_backup_host_registers()
5318 hr->hcintmsk[i] = dwc2_readl(hsotg, HCINTMSK(i)); in dwc2_backup_host_registers()
5320 hr->hprt0 = dwc2_read_hprt0(hsotg); in dwc2_backup_host_registers()
5321 hr->hfir = dwc2_readl(hsotg, HFIR); in dwc2_backup_host_registers()
5322 hr->hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ); in dwc2_backup_host_registers()
5335 int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) in dwc2_restore_host_registers() argument
5340 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_restore_host_registers()
5343 hr = &hsotg->hr_backup; in dwc2_restore_host_registers()
5345 dev_err(hsotg->dev, "%s: no host registers to restore\n", in dwc2_restore_host_registers()
5351 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_restore_host_registers()
5352 dwc2_writel(hsotg, hr->haintmsk, HAINTMSK); in dwc2_restore_host_registers()
5354 for (i = 0; i < hsotg->params.host_channels; ++i) in dwc2_restore_host_registers()
5355 dwc2_writel(hsotg, hr->hcintmsk[i], HCINTMSK(i)); in dwc2_restore_host_registers()
5357 dwc2_writel(hsotg, hr->hprt0, HPRT0); in dwc2_restore_host_registers()
5358 dwc2_writel(hsotg, hr->hfir, HFIR); in dwc2_restore_host_registers()
5359 dwc2_writel(hsotg, hr->hptxfsiz, HPTXFSIZ); in dwc2_restore_host_registers()
5360 hsotg->frame_number = 0; in dwc2_restore_host_registers()
5370 int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg) in dwc2_host_enter_hibernation() argument
5379 dev_dbg(hsotg->dev, "Preparing host for hibernation\n"); in dwc2_host_enter_hibernation()
5380 ret = dwc2_backup_global_registers(hsotg); in dwc2_host_enter_hibernation()
5382 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_host_enter_hibernation()
5386 ret = dwc2_backup_host_registers(hsotg); in dwc2_host_enter_hibernation()
5388 dev_err(hsotg->dev, "%s: failed to backup host registers\n", in dwc2_host_enter_hibernation()
5394 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_enter_hibernation()
5397 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_enter_hibernation()
5400 if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 3000)) in dwc2_host_enter_hibernation()
5401 dev_warn(hsotg->dev, "Suspend wasn't generated\n"); in dwc2_host_enter_hibernation()
5407 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5408 hsotg->lx_state = DWC2_L2; in dwc2_host_enter_hibernation()
5410 gusbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_host_enter_hibernation()
5414 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_hibernation()
5416 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_hibernation()
5419 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5421 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5425 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5427 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5430 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_host_enter_hibernation()
5432 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_host_enter_hibernation()
5437 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5439 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5443 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5447 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5451 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5453 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5457 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_enter_hibernation()
5459 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_enter_hibernation()
5461 hsotg->hibernated = 1; in dwc2_host_enter_hibernation()
5462 hsotg->bus_suspended = 1; in dwc2_host_enter_hibernation()
5463 dev_dbg(hsotg->dev, "Host hibernation completed\n"); in dwc2_host_enter_hibernation()
5464 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_host_enter_hibernation()
5480 int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, in dwc2_host_exit_hibernation() argument
5489 gr = &hsotg->gr_backup; in dwc2_host_exit_hibernation()
5490 hr = &hsotg->hr_backup; in dwc2_host_exit_hibernation()
5492 dev_dbg(hsotg->dev, in dwc2_host_exit_hibernation()
5496 dwc2_hib_restore_common(hsotg, rem_wakeup, 1); in dwc2_host_exit_hibernation()
5497 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5507 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_host_exit_hibernation()
5510 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_exit_hibernation()
5512 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_exit_hibernation()
5516 dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); in dwc2_host_exit_hibernation()
5517 dwc2_writel(hsotg, hr->hcfg, HCFG); in dwc2_host_exit_hibernation()
5520 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_host_exit_hibernation()
5522 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_host_exit_hibernation()
5529 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5538 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5543 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5546 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5551 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5554 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_exit_hibernation()
5558 dwc2_writel(hsotg, hprt0, HPRT0); in dwc2_host_exit_hibernation()
5560 hprt0 = dwc2_readl(hsotg, HPRT0); in dwc2_host_exit_hibernation()
5563 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_host_exit_hibernation()
5566 ret = dwc2_restore_global_registers(hsotg); in dwc2_host_exit_hibernation()
5568 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_host_exit_hibernation()
5574 ret = dwc2_restore_host_registers(hsotg); in dwc2_host_exit_hibernation()
5576 dev_err(hsotg->dev, "%s: failed to restore host registers\n", in dwc2_host_exit_hibernation()
5581 dwc2_hcd_rem_wakeup(hsotg); in dwc2_host_exit_hibernation()
5583 hsotg->hibernated = 0; in dwc2_host_exit_hibernation()
5584 hsotg->bus_suspended = 0; in dwc2_host_exit_hibernation()
5585 hsotg->lx_state = DWC2_L0; in dwc2_host_exit_hibernation()
5586 dev_dbg(hsotg->dev, "Host hibernation restore complete\n"); in dwc2_host_exit_hibernation()