Lines Matching refs:hsotg

52 static inline void dwc2_set_bit(struct dwc2_hsotg *hsotg, u32 offset, u32 val)  in dwc2_set_bit()  argument
54 dwc2_writel(hsotg, dwc2_readl(hsotg, offset) | val, offset); in dwc2_set_bit()
57 static inline void dwc2_clear_bit(struct dwc2_hsotg *hsotg, u32 offset, u32 val) in dwc2_clear_bit() argument
59 dwc2_writel(hsotg, dwc2_readl(hsotg, offset) & ~val, offset); in dwc2_clear_bit()
62 static inline struct dwc2_hsotg_ep *index_to_ep(struct dwc2_hsotg *hsotg, in index_to_ep() argument
66 return hsotg->eps_in[ep_index]; in index_to_ep()
68 return hsotg->eps_out[ep_index]; in index_to_ep()
72 static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg);
93 static inline bool using_dma(struct dwc2_hsotg *hsotg) in using_dma() argument
95 return hsotg->params.g_dma; in using_dma()
104 static inline bool using_desc_dma(struct dwc2_hsotg *hsotg) in using_desc_dma() argument
106 return hsotg->params.g_dma_desc; in using_desc_dma()
150 static void dwc2_hsotg_en_gsint(struct dwc2_hsotg *hsotg, u32 ints) in dwc2_hsotg_en_gsint() argument
152 u32 gsintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_en_gsint()
158 dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); in dwc2_hsotg_en_gsint()
159 dwc2_writel(hsotg, new_gsintmsk, GINTMSK); in dwc2_hsotg_en_gsint()
168 static void dwc2_hsotg_disable_gsint(struct dwc2_hsotg *hsotg, u32 ints) in dwc2_hsotg_disable_gsint() argument
170 u32 gsintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_disable_gsint()
176 dwc2_writel(hsotg, new_gsintmsk, GINTMSK); in dwc2_hsotg_disable_gsint()
189 static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg, in dwc2_hsotg_ctrl_epint() argument
201 daint = dwc2_readl(hsotg, DAINTMSK); in dwc2_hsotg_ctrl_epint()
206 dwc2_writel(hsotg, daint, DAINTMSK); in dwc2_hsotg_ctrl_epint()
215 int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg) in dwc2_hsotg_tx_fifo_count() argument
217 if (hsotg->hw_params.en_multiple_tx_fifo) in dwc2_hsotg_tx_fifo_count()
219 return hsotg->hw_params.num_dev_in_eps; in dwc2_hsotg_tx_fifo_count()
222 return hsotg->hw_params.num_dev_perio_in_ep; in dwc2_hsotg_tx_fifo_count()
231 int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg) in dwc2_hsotg_tx_fifo_total_depth() argument
237 np_tx_fifo_size = min_t(u32, hsotg->hw_params.dev_nperio_tx_fifo_size, in dwc2_hsotg_tx_fifo_total_depth()
238 hsotg->params.g_np_tx_fifo_size); in dwc2_hsotg_tx_fifo_total_depth()
241 tx_addr_max = hsotg->hw_params.total_fifo_size; in dwc2_hsotg_tx_fifo_total_depth()
243 addr = hsotg->params.g_rx_fifo_size + np_tx_fifo_size; in dwc2_hsotg_tx_fifo_total_depth()
256 static void dwc2_gadget_wkup_alert_handler(struct dwc2_hsotg *hsotg) in dwc2_gadget_wkup_alert_handler() argument
261 gintsts2 = dwc2_readl(hsotg, GINTSTS2); in dwc2_gadget_wkup_alert_handler()
262 gintmsk2 = dwc2_readl(hsotg, GINTMSK2); in dwc2_gadget_wkup_alert_handler()
265 dev_dbg(hsotg->dev, "%s: Wkup_Alert_Int\n", __func__); in dwc2_gadget_wkup_alert_handler()
266 dwc2_set_bit(hsotg, GINTSTS2, GINTSTS2_WKUP_ALERT_INT); in dwc2_gadget_wkup_alert_handler()
267 dwc2_set_bit(hsotg, DCTL, DCTL_RMTWKUPSIG); in dwc2_gadget_wkup_alert_handler()
277 int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg) in dwc2_hsotg_tx_fifo_average_depth() argument
282 tx_fifo_depth = dwc2_hsotg_tx_fifo_total_depth(hsotg); in dwc2_hsotg_tx_fifo_average_depth()
284 tx_fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); in dwc2_hsotg_tx_fifo_average_depth()
296 static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) in dwc2_hsotg_init_fifo() argument
303 u32 *txfsz = hsotg->params.g_tx_fifo_size; in dwc2_hsotg_init_fifo()
306 WARN_ON(hsotg->fifo_map); in dwc2_hsotg_init_fifo()
307 hsotg->fifo_map = 0; in dwc2_hsotg_init_fifo()
310 dwc2_writel(hsotg, hsotg->params.g_rx_fifo_size, GRXFSIZ); in dwc2_hsotg_init_fifo()
311 dwc2_writel(hsotg, (hsotg->params.g_rx_fifo_size << in dwc2_hsotg_init_fifo()
313 (hsotg->params.g_np_tx_fifo_size << FIFOSIZE_DEPTH_SHIFT), in dwc2_hsotg_init_fifo()
324 addr = hsotg->params.g_rx_fifo_size + hsotg->params.g_np_tx_fifo_size; in dwc2_hsotg_init_fifo()
336 WARN_ONCE(addr + txfsz[ep] > hsotg->fifo_mem, in dwc2_hsotg_init_fifo()
340 dwc2_writel(hsotg, val, DPTXFSIZN(ep)); in dwc2_hsotg_init_fifo()
341 val = dwc2_readl(hsotg, DPTXFSIZN(ep)); in dwc2_hsotg_init_fifo()
344 dwc2_writel(hsotg, hsotg->hw_params.total_fifo_size | in dwc2_hsotg_init_fifo()
352 dwc2_writel(hsotg, GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH | in dwc2_hsotg_init_fifo()
358 val = dwc2_readl(hsotg, GRSTCTL); in dwc2_hsotg_init_fifo()
364 dev_err(hsotg->dev, in dwc2_hsotg_init_fifo()
373 dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout); in dwc2_hsotg_init_fifo()
418 static void dwc2_hsotg_unmap_dma(struct dwc2_hsotg *hsotg, in dwc2_hsotg_unmap_dma() argument
424 usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->dir_in); in dwc2_hsotg_unmap_dma()
435 static int dwc2_gadget_alloc_ctrl_desc_chains(struct dwc2_hsotg *hsotg) in dwc2_gadget_alloc_ctrl_desc_chains() argument
437 hsotg->setup_desc[0] = in dwc2_gadget_alloc_ctrl_desc_chains()
438 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
440 &hsotg->setup_desc_dma[0], in dwc2_gadget_alloc_ctrl_desc_chains()
442 if (!hsotg->setup_desc[0]) in dwc2_gadget_alloc_ctrl_desc_chains()
445 hsotg->setup_desc[1] = in dwc2_gadget_alloc_ctrl_desc_chains()
446 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
448 &hsotg->setup_desc_dma[1], in dwc2_gadget_alloc_ctrl_desc_chains()
450 if (!hsotg->setup_desc[1]) in dwc2_gadget_alloc_ctrl_desc_chains()
453 hsotg->ctrl_in_desc = in dwc2_gadget_alloc_ctrl_desc_chains()
454 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
456 &hsotg->ctrl_in_desc_dma, in dwc2_gadget_alloc_ctrl_desc_chains()
458 if (!hsotg->ctrl_in_desc) in dwc2_gadget_alloc_ctrl_desc_chains()
461 hsotg->ctrl_out_desc = in dwc2_gadget_alloc_ctrl_desc_chains()
462 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
464 &hsotg->ctrl_out_desc_dma, in dwc2_gadget_alloc_ctrl_desc_chains()
466 if (!hsotg->ctrl_out_desc) in dwc2_gadget_alloc_ctrl_desc_chains()
491 static int dwc2_hsotg_write_fifo(struct dwc2_hsotg *hsotg, in dwc2_hsotg_write_fifo() argument
496 u32 gnptxsts = dwc2_readl(hsotg, GNPTXSTS); in dwc2_hsotg_write_fifo()
510 if (periodic && !hsotg->dedicated_fifos) { in dwc2_hsotg_write_fifo()
511 u32 epsize = dwc2_readl(hsotg, DIEPTSIZ(hs_ep->index)); in dwc2_hsotg_write_fifo()
527 dwc2_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_write_fifo()
531 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", in dwc2_hsotg_write_fifo()
540 dev_dbg(hsotg->dev, "%s: => can_write1=%d\n", in dwc2_hsotg_write_fifo()
544 dev_dbg(hsotg->dev, "%s: => can_write2=%d\n", in dwc2_hsotg_write_fifo()
548 dwc2_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_write_fifo()
551 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { in dwc2_hsotg_write_fifo()
552 can_write = dwc2_readl(hsotg, in dwc2_hsotg_write_fifo()
559 dev_dbg(hsotg->dev, in dwc2_hsotg_write_fifo()
563 dwc2_hsotg_en_gsint(hsotg, GINTSTS_NPTXFEMP); in dwc2_hsotg_write_fifo()
573 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", in dwc2_hsotg_write_fifo()
593 if (!hsotg->dedicated_fifos) in dwc2_hsotg_write_fifo()
594 dwc2_hsotg_en_gsint(hsotg, in dwc2_hsotg_write_fifo()
622 if (!hsotg->dedicated_fifos) in dwc2_hsotg_write_fifo()
623 dwc2_hsotg_en_gsint(hsotg, in dwc2_hsotg_write_fifo()
628 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", in dwc2_hsotg_write_fifo()
643 dwc2_writel_rep(hsotg, EPFIFO(hs_ep->index), data, to_write); in dwc2_hsotg_write_fifo()
693 static u32 dwc2_hsotg_read_frameno(struct dwc2_hsotg *hsotg) in dwc2_hsotg_read_frameno() argument
697 dsts = dwc2_readl(hsotg, DSTS); in dwc2_hsotg_read_frameno()
883 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_fill_isoc_desc() local
897 dev_dbg(hsotg->dev, "%s: desc chain full\n", __func__); in dwc2_gadget_fill_isoc_desc()
905 dev_dbg(hsotg->dev, "%s: Filling ep %d, dir %s isoc desc # %d\n", in dwc2_gadget_fill_isoc_desc()
953 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_start_isoc_ddma() local
965 dev_dbg(hsotg->dev, "%s: No requests in queue\n", __func__); in dwc2_gadget_start_isoc_ddma()
996 dwc2_writel(hsotg, hs_ep->desc_list_dma, dma_reg); in dwc2_gadget_start_isoc_ddma()
998 ctrl = dwc2_readl(hsotg, depctl); in dwc2_gadget_start_isoc_ddma()
1000 dwc2_writel(hsotg, ctrl, depctl); in dwc2_gadget_start_isoc_ddma()
1013 static void dwc2_hsotg_start_req(struct dwc2_hsotg *hsotg, in dwc2_hsotg_start_req() argument
1032 dev_err(hsotg->dev, "%s: active request\n", __func__); in dwc2_hsotg_start_req()
1036 dev_err(hsotg->dev, in dwc2_hsotg_start_req()
1047 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", in dwc2_hsotg_start_req()
1048 __func__, dwc2_readl(hsotg, epctrl_reg), index, in dwc2_hsotg_start_req()
1052 ctrl = dwc2_readl(hsotg, epctrl_reg); in dwc2_hsotg_start_req()
1055 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); in dwc2_hsotg_start_req()
1060 dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n", in dwc2_hsotg_start_req()
1063 if (!using_desc_dma(hsotg)) in dwc2_hsotg_start_req()
1071 dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n", in dwc2_hsotg_start_req()
1087 dev_err(hsotg->dev, "req length > maxpacket*mc\n"); in dwc2_hsotg_start_req()
1113 dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", in dwc2_hsotg_start_req()
1119 if (using_desc_dma(hsotg)) { in dwc2_hsotg_start_req()
1136 if (!index && hsotg->ep0_state == DWC2_EP0_DATA_OUT && in dwc2_hsotg_start_req()
1145 dwc2_writel(hsotg, hs_ep->desc_list_dma, dma_reg); in dwc2_hsotg_start_req()
1147 dev_dbg(hsotg->dev, "%s: %08x pad => 0x%08x\n", in dwc2_hsotg_start_req()
1151 dwc2_writel(hsotg, epsize, epsize_reg); in dwc2_hsotg_start_req()
1153 if (using_dma(hsotg) && !continuing && (length != 0)) { in dwc2_hsotg_start_req()
1159 dwc2_writel(hsotg, ureq->dma, dma_reg); in dwc2_hsotg_start_req()
1161 dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", in dwc2_hsotg_start_req()
1167 hs_ep->target_frame = dwc2_hsotg_read_frameno(hsotg); in dwc2_hsotg_start_req()
1178 dev_dbg(hsotg->dev, "ep0 state:%d\n", hsotg->ep0_state); in dwc2_hsotg_start_req()
1181 if (!(index == 0 && hsotg->ep0_state == DWC2_EP0_SETUP)) in dwc2_hsotg_start_req()
1184 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in dwc2_hsotg_start_req()
1185 dwc2_writel(hsotg, ctrl, epctrl_reg); in dwc2_hsotg_start_req()
1195 if (dir_in && !using_dma(hsotg)) { in dwc2_hsotg_start_req()
1199 dwc2_hsotg_write_fifo(hsotg, hs_ep, hs_req); in dwc2_hsotg_start_req()
1208 if (!(dwc2_readl(hsotg, epctrl_reg) & DXEPCTL_EPENA)) in dwc2_hsotg_start_req()
1209 dev_dbg(hsotg->dev, in dwc2_hsotg_start_req()
1211 index, dwc2_readl(hsotg, epctrl_reg)); in dwc2_hsotg_start_req()
1213 dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", in dwc2_hsotg_start_req()
1214 __func__, dwc2_readl(hsotg, epctrl_reg)); in dwc2_hsotg_start_req()
1217 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); in dwc2_hsotg_start_req()
1232 static int dwc2_hsotg_map_dma(struct dwc2_hsotg *hsotg, in dwc2_hsotg_map_dma() argument
1238 ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); in dwc2_hsotg_map_dma()
1245 dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n", in dwc2_hsotg_map_dma()
1251 static int dwc2_hsotg_handle_unaligned_buf_start(struct dwc2_hsotg *hsotg, in dwc2_hsotg_handle_unaligned_buf_start() argument
1258 if (!using_dma(hsotg) || !((long)req_buf & 3)) in dwc2_hsotg_handle_unaligned_buf_start()
1263 dev_dbg(hsotg->dev, "%s: %s: buf=%p length=%d\n", __func__, in dwc2_hsotg_handle_unaligned_buf_start()
1269 dev_err(hsotg->dev, in dwc2_hsotg_handle_unaligned_buf_start()
1284 dwc2_hsotg_handle_unaligned_buf_complete(struct dwc2_hsotg *hsotg, in dwc2_hsotg_handle_unaligned_buf_complete() argument
1289 if (!using_dma(hsotg) || !hs_req->saved_req_buf) in dwc2_hsotg_handle_unaligned_buf_complete()
1292 dev_dbg(hsotg->dev, "%s: %s: status=%d actual-length=%d\n", __func__, in dwc2_hsotg_handle_unaligned_buf_complete()
1316 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_target_frame_elapsed() local
1318 u32 current_frame = hsotg->frame_number; in dwc2_gadget_target_frame_elapsed()
1339 static int dwc2_gadget_set_ep0_desc_chain(struct dwc2_hsotg *hsotg, in dwc2_gadget_set_ep0_desc_chain() argument
1342 switch (hsotg->ep0_state) { in dwc2_gadget_set_ep0_desc_chain()
1345 hs_ep->desc_list = hsotg->setup_desc[0]; in dwc2_gadget_set_ep0_desc_chain()
1346 hs_ep->desc_list_dma = hsotg->setup_desc_dma[0]; in dwc2_gadget_set_ep0_desc_chain()
1350 hs_ep->desc_list = hsotg->ctrl_in_desc; in dwc2_gadget_set_ep0_desc_chain()
1351 hs_ep->desc_list_dma = hsotg->ctrl_in_desc_dma; in dwc2_gadget_set_ep0_desc_chain()
1354 hs_ep->desc_list = hsotg->ctrl_out_desc; in dwc2_gadget_set_ep0_desc_chain()
1355 hs_ep->desc_list_dma = hsotg->ctrl_out_desc_dma; in dwc2_gadget_set_ep0_desc_chain()
1358 dev_err(hsotg->dev, "invalid EP 0 state in queue %d\n", in dwc2_gadget_set_ep0_desc_chain()
1359 hsotg->ep0_state); in dwc2_gadget_set_ep0_desc_chain()
1514 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_complete_oursetup() local
1516 dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); in dwc2_hsotg_complete_oursetup()
1529 static struct dwc2_hsotg_ep *ep_from_windex(struct dwc2_hsotg *hsotg, in ep_from_windex() argument
1539 if (idx > hsotg->num_of_eps) in ep_from_windex()
1542 ep = index_to_ep(hsotg, idx, dir); in ep_from_windex()
1556 int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode) in dwc2_hsotg_set_test_mode() argument
1558 int dctl = dwc2_readl(hsotg, DCTL); in dwc2_hsotg_set_test_mode()
1572 dwc2_writel(hsotg, dctl, DCTL); in dwc2_hsotg_set_test_mode()
1586 static int dwc2_hsotg_send_reply(struct dwc2_hsotg *hsotg, in dwc2_hsotg_send_reply() argument
1594 dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length); in dwc2_hsotg_send_reply()
1597 hsotg->ep0_reply = req; in dwc2_hsotg_send_reply()
1599 dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__); in dwc2_hsotg_send_reply()
1603 req->buf = hsotg->ep0_buff; in dwc2_hsotg_send_reply()
1617 dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__); in dwc2_hsotg_send_reply()
1629 static int dwc2_hsotg_process_req_status(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_req_status() argument
1632 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_req_status()
1637 dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__); in dwc2_hsotg_process_req_status()
1640 dev_warn(hsotg->dev, "%s: direction out?\n", __func__); in dwc2_hsotg_process_req_status()
1659 ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); in dwc2_hsotg_process_req_status()
1673 ret = dwc2_hsotg_send_reply(hsotg, ep0, &reply, 2); in dwc2_hsotg_process_req_status()
1675 dev_err(hsotg->dev, "%s: failed to send reply\n", __func__); in dwc2_hsotg_process_req_status()
1707 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_start_next_request() local
1714 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, false); in dwc2_gadget_start_next_request()
1721 dev_dbg(hsotg->dev, "%s: No more ISOC-IN requests\n", in dwc2_gadget_start_next_request()
1724 dev_dbg(hsotg->dev, "%s: No more ISOC-OUT requests\n", in dwc2_gadget_start_next_request()
1726 mask = dwc2_readl(hsotg, epmsk_reg); in dwc2_gadget_start_next_request()
1728 dwc2_writel(hsotg, mask, epmsk_reg); in dwc2_gadget_start_next_request()
1737 static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_req_feature() argument
1740 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_req_feature()
1750 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", in dwc2_hsotg_process_req_feature()
1761 hsotg->remote_wakeup_allowed = 1; in dwc2_hsotg_process_req_feature()
1770 hsotg->test_mode = wIndex >> 8; in dwc2_hsotg_process_req_feature()
1771 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_req_feature()
1773 dev_err(hsotg->dev, in dwc2_hsotg_process_req_feature()
1784 ep = ep_from_windex(hsotg, wIndex); in dwc2_hsotg_process_req_feature()
1786 dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n", in dwc2_hsotg_process_req_feature()
1797 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_req_feature()
1799 dev_err(hsotg->dev, in dwc2_hsotg_process_req_feature()
1819 spin_unlock(&hsotg->lock); in dwc2_hsotg_process_req_feature()
1822 spin_lock(&hsotg->lock); in dwc2_hsotg_process_req_feature()
1843 static void dwc2_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg);
1851 static void dwc2_hsotg_stall_ep0(struct dwc2_hsotg *hsotg) in dwc2_hsotg_stall_ep0() argument
1853 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_stall_ep0()
1857 dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); in dwc2_hsotg_stall_ep0()
1865 ctrl = dwc2_readl(hsotg, reg); in dwc2_hsotg_stall_ep0()
1868 dwc2_writel(hsotg, ctrl, reg); in dwc2_hsotg_stall_ep0()
1870 dev_dbg(hsotg->dev, in dwc2_hsotg_stall_ep0()
1872 ctrl, reg, dwc2_readl(hsotg, reg)); in dwc2_hsotg_stall_ep0()
1878 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_stall_ep0()
1890 static void dwc2_hsotg_process_control(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_control() argument
1893 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_control()
1897 dev_dbg(hsotg->dev, in dwc2_hsotg_process_control()
1904 hsotg->ep0_state = DWC2_EP0_STATUS_IN; in dwc2_hsotg_process_control()
1907 hsotg->ep0_state = DWC2_EP0_DATA_IN; in dwc2_hsotg_process_control()
1910 hsotg->ep0_state = DWC2_EP0_DATA_OUT; in dwc2_hsotg_process_control()
1916 hsotg->connected = 1; in dwc2_hsotg_process_control()
1917 dcfg = dwc2_readl(hsotg, DCFG); in dwc2_hsotg_process_control()
1921 dwc2_writel(hsotg, dcfg, DCFG); in dwc2_hsotg_process_control()
1923 dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); in dwc2_hsotg_process_control()
1925 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_control()
1929 ret = dwc2_hsotg_process_req_status(hsotg, ctrl); in dwc2_hsotg_process_control()
1934 ret = dwc2_hsotg_process_req_feature(hsotg, ctrl); in dwc2_hsotg_process_control()
1941 if (ret == 0 && hsotg->driver) { in dwc2_hsotg_process_control()
1942 spin_unlock(&hsotg->lock); in dwc2_hsotg_process_control()
1943 ret = hsotg->driver->setup(&hsotg->gadget, ctrl); in dwc2_hsotg_process_control()
1944 spin_lock(&hsotg->lock); in dwc2_hsotg_process_control()
1946 dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); in dwc2_hsotg_process_control()
1949 hsotg->delayed_status = false; in dwc2_hsotg_process_control()
1951 hsotg->delayed_status = true; in dwc2_hsotg_process_control()
1959 dwc2_hsotg_stall_ep0(hsotg); in dwc2_hsotg_process_control()
1974 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_complete_setup() local
1977 dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); in dwc2_hsotg_complete_setup()
1981 spin_lock(&hsotg->lock); in dwc2_hsotg_complete_setup()
1983 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_complete_setup()
1985 dwc2_hsotg_process_control(hsotg, req->buf); in dwc2_hsotg_complete_setup()
1986 spin_unlock(&hsotg->lock); in dwc2_hsotg_complete_setup()
1996 static void dwc2_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg) in dwc2_hsotg_enqueue_setup() argument
1998 struct usb_request *req = hsotg->ctrl_req; in dwc2_hsotg_enqueue_setup()
2002 dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__); in dwc2_hsotg_enqueue_setup()
2006 req->buf = hsotg->ctrl_buff; in dwc2_hsotg_enqueue_setup()
2010 dev_dbg(hsotg->dev, "%s already queued???\n", __func__); in dwc2_hsotg_enqueue_setup()
2014 hsotg->eps_out[0]->dir_in = 0; in dwc2_hsotg_enqueue_setup()
2015 hsotg->eps_out[0]->send_zlp = 0; in dwc2_hsotg_enqueue_setup()
2016 hsotg->ep0_state = DWC2_EP0_SETUP; in dwc2_hsotg_enqueue_setup()
2018 ret = dwc2_hsotg_ep_queue(&hsotg->eps_out[0]->ep, req, GFP_ATOMIC); in dwc2_hsotg_enqueue_setup()
2020 dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); in dwc2_hsotg_enqueue_setup()
2028 static void dwc2_hsotg_program_zlp(struct dwc2_hsotg *hsotg, in dwc2_hsotg_program_zlp() argument
2037 dev_dbg(hsotg->dev, "Sending zero-length packet on ep%d\n", in dwc2_hsotg_program_zlp()
2040 dev_dbg(hsotg->dev, "Receiving zero-length packet on ep%d\n", in dwc2_hsotg_program_zlp()
2042 if (using_desc_dma(hsotg)) { in dwc2_hsotg_program_zlp()
2047 dwc2_gadget_set_ep0_desc_chain(hsotg, hs_ep); in dwc2_hsotg_program_zlp()
2051 dwc2_writel(hsotg, DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | in dwc2_hsotg_program_zlp()
2056 ctrl = dwc2_readl(hsotg, epctl_reg); in dwc2_hsotg_program_zlp()
2060 dwc2_writel(hsotg, ctrl, epctl_reg); in dwc2_hsotg_program_zlp()
2076 static void dwc2_hsotg_complete_request(struct dwc2_hsotg *hsotg, in dwc2_hsotg_complete_request() argument
2082 dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); in dwc2_hsotg_complete_request()
2086 dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", in dwc2_hsotg_complete_request()
2097 if (using_dma(hsotg)) in dwc2_hsotg_complete_request()
2098 dwc2_hsotg_unmap_dma(hsotg, hs_ep, hs_req); in dwc2_hsotg_complete_request()
2100 dwc2_hsotg_handle_unaligned_buf_complete(hsotg, hs_ep, hs_req); in dwc2_hsotg_complete_request()
2111 spin_unlock(&hsotg->lock); in dwc2_hsotg_complete_request()
2113 spin_lock(&hsotg->lock); in dwc2_hsotg_complete_request()
2117 if (using_desc_dma(hsotg) && hs_ep->isochronous) in dwc2_hsotg_complete_request()
2141 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_complete_isoc_request_ddma() local
2155 dev_warn(hsotg->dev, "%s: ISOC EP queue empty\n", __func__); in dwc2_gadget_complete_isoc_request_ddma()
2180 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_gadget_complete_isoc_request_ddma()
2200 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_handle_isoc_bna() local
2203 dwc2_flush_rx_fifo(hsotg); in dwc2_gadget_handle_isoc_bna()
2204 dwc2_hsotg_complete_request(hsotg, hs_ep, get_ep_head(hs_ep), 0); in dwc2_gadget_handle_isoc_bna()
2221 static void dwc2_hsotg_rx_data(struct dwc2_hsotg *hsotg, int ep_idx, int size) in dwc2_hsotg_rx_data() argument
2223 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[ep_idx]; in dwc2_hsotg_rx_data()
2230 u32 epctl = dwc2_readl(hsotg, DOEPCTL(ep_idx)); in dwc2_hsotg_rx_data()
2233 dev_dbg(hsotg->dev, in dwc2_hsotg_rx_data()
2239 (void)dwc2_readl(hsotg, EPFIFO(ep_idx)); in dwc2_hsotg_rx_data()
2248 dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", in dwc2_hsotg_rx_data()
2269 dwc2_readl_rep(hsotg, EPFIFO(ep_idx), in dwc2_hsotg_rx_data()
2285 static void dwc2_hsotg_ep0_zlp(struct dwc2_hsotg *hsotg, bool dir_in) in dwc2_hsotg_ep0_zlp() argument
2288 hsotg->eps_out[0]->dir_in = dir_in; in dwc2_hsotg_ep0_zlp()
2289 hsotg->ep0_state = dir_in ? DWC2_EP0_STATUS_IN : DWC2_EP0_STATUS_OUT; in dwc2_hsotg_ep0_zlp()
2291 dwc2_hsotg_program_zlp(hsotg, hsotg->eps_out[0]); in dwc2_hsotg_ep0_zlp()
2294 static void dwc2_hsotg_change_ep_iso_parity(struct dwc2_hsotg *hsotg, in dwc2_hsotg_change_ep_iso_parity() argument
2299 ctrl = dwc2_readl(hsotg, epctl_reg); in dwc2_hsotg_change_ep_iso_parity()
2304 dwc2_writel(hsotg, ctrl, epctl_reg); in dwc2_hsotg_change_ep_iso_parity()
2316 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_get_xfersize_ddma() local
2330 dev_err(hsotg->dev, "descriptor %d closed with %x\n", in dwc2_gadget_get_xfersize_ddma()
2347 static void dwc2_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, int epnum) in dwc2_hsotg_handle_outdone() argument
2349 u32 epsize = dwc2_readl(hsotg, DOEPTSIZ(epnum)); in dwc2_hsotg_handle_outdone()
2350 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[epnum]; in dwc2_hsotg_handle_outdone()
2357 dev_dbg(hsotg->dev, "%s: no request active\n", __func__); in dwc2_hsotg_handle_outdone()
2361 if (epnum == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_OUT) { in dwc2_hsotg_handle_outdone()
2362 dev_dbg(hsotg->dev, "zlp packet received\n"); in dwc2_hsotg_handle_outdone()
2363 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_handle_outdone()
2364 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_handle_outdone()
2368 if (using_desc_dma(hsotg)) in dwc2_hsotg_handle_outdone()
2371 if (using_dma(hsotg)) { in dwc2_hsotg_handle_outdone()
2391 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, true); in dwc2_hsotg_handle_outdone()
2396 dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", in dwc2_hsotg_handle_outdone()
2406 if (!using_desc_dma(hsotg) && epnum == 0 && in dwc2_hsotg_handle_outdone()
2407 hsotg->ep0_state == DWC2_EP0_DATA_OUT) { in dwc2_hsotg_handle_outdone()
2409 if (!hsotg->delayed_status) in dwc2_hsotg_handle_outdone()
2410 dwc2_hsotg_ep0_zlp(hsotg, true); in dwc2_hsotg_handle_outdone()
2417 if (!using_dma(hsotg)) { in dwc2_hsotg_handle_outdone()
2419 dwc2_hsotg_change_ep_iso_parity(hsotg, DOEPCTL(epnum)); in dwc2_hsotg_handle_outdone()
2425 if (!using_desc_dma(hsotg) && hs_ep->isochronous) in dwc2_hsotg_handle_outdone()
2426 req->frame_number = hsotg->frame_number; in dwc2_hsotg_handle_outdone()
2428 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, result); in dwc2_hsotg_handle_outdone()
2447 static void dwc2_hsotg_handle_rx(struct dwc2_hsotg *hsotg) in dwc2_hsotg_handle_rx() argument
2449 u32 grxstsr = dwc2_readl(hsotg, GRXSTSP); in dwc2_hsotg_handle_rx()
2452 WARN_ON(using_dma(hsotg)); in dwc2_hsotg_handle_rx()
2460 dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", in dwc2_hsotg_handle_rx()
2465 dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); in dwc2_hsotg_handle_rx()
2469 dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", in dwc2_hsotg_handle_rx()
2470 dwc2_hsotg_read_frameno(hsotg)); in dwc2_hsotg_handle_rx()
2472 if (!using_dma(hsotg)) in dwc2_hsotg_handle_rx()
2473 dwc2_hsotg_handle_outdone(hsotg, epnum); in dwc2_hsotg_handle_rx()
2477 dev_dbg(hsotg->dev, in dwc2_hsotg_handle_rx()
2479 dwc2_hsotg_read_frameno(hsotg), in dwc2_hsotg_handle_rx()
2480 dwc2_readl(hsotg, DOEPCTL(0))); in dwc2_hsotg_handle_rx()
2486 if (hsotg->ep0_state == DWC2_EP0_SETUP) in dwc2_hsotg_handle_rx()
2487 dwc2_hsotg_handle_outdone(hsotg, epnum); in dwc2_hsotg_handle_rx()
2491 dwc2_hsotg_rx_data(hsotg, epnum, size); in dwc2_hsotg_handle_rx()
2495 dev_dbg(hsotg->dev, in dwc2_hsotg_handle_rx()
2497 dwc2_hsotg_read_frameno(hsotg), in dwc2_hsotg_handle_rx()
2498 dwc2_readl(hsotg, DOEPCTL(0))); in dwc2_hsotg_handle_rx()
2500 WARN_ON(hsotg->ep0_state != DWC2_EP0_SETUP); in dwc2_hsotg_handle_rx()
2502 dwc2_hsotg_rx_data(hsotg, epnum, size); in dwc2_hsotg_handle_rx()
2506 dev_warn(hsotg->dev, "%s: unknown status %08x\n", in dwc2_hsotg_handle_rx()
2509 dwc2_hsotg_dump(hsotg); in dwc2_hsotg_handle_rx()
2547 static void dwc2_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg, in dwc2_hsotg_set_ep_maxpacket() argument
2554 hs_ep = index_to_ep(hsotg, ep, dir_in); in dwc2_hsotg_set_ep_maxpacket()
2577 reg = dwc2_readl(hsotg, DIEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2580 dwc2_writel(hsotg, reg, DIEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2582 reg = dwc2_readl(hsotg, DOEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2585 dwc2_writel(hsotg, reg, DOEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2591 dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); in dwc2_hsotg_set_ep_maxpacket()
2599 static void dwc2_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx) in dwc2_hsotg_txfifo_flush() argument
2601 dwc2_writel(hsotg, GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, in dwc2_hsotg_txfifo_flush()
2605 if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_TXFFLSH, 100)) in dwc2_hsotg_txfifo_flush()
2606 dev_warn(hsotg->dev, "%s: timeout flushing fifo GRSTCTL_TXFFLSH\n", in dwc2_hsotg_txfifo_flush()
2618 static int dwc2_hsotg_trytx(struct dwc2_hsotg *hsotg, in dwc2_hsotg_trytx() argument
2629 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, in dwc2_hsotg_trytx()
2635 dev_dbg(hsotg->dev, "trying to write more for ep%d\n", in dwc2_hsotg_trytx()
2637 return dwc2_hsotg_write_fifo(hsotg, hs_ep, hs_req); in dwc2_hsotg_trytx()
2651 static void dwc2_hsotg_complete_in(struct dwc2_hsotg *hsotg, in dwc2_hsotg_complete_in() argument
2655 u32 epsize = dwc2_readl(hsotg, DIEPTSIZ(hs_ep->index)); in dwc2_hsotg_complete_in()
2659 dev_dbg(hsotg->dev, "XferCompl but no req\n"); in dwc2_hsotg_complete_in()
2664 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_IN) { in dwc2_hsotg_complete_in()
2665 dev_dbg(hsotg->dev, "zlp packet sent\n"); in dwc2_hsotg_complete_in()
2673 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_complete_in()
2674 if (hsotg->test_mode) { in dwc2_hsotg_complete_in()
2677 ret = dwc2_hsotg_set_test_mode(hsotg, hsotg->test_mode); in dwc2_hsotg_complete_in()
2679 dev_dbg(hsotg->dev, "Invalid Test #%d\n", in dwc2_hsotg_complete_in()
2680 hsotg->test_mode); in dwc2_hsotg_complete_in()
2681 dwc2_hsotg_stall_ep0(hsotg); in dwc2_hsotg_complete_in()
2685 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_complete_in()
2698 if (using_desc_dma(hsotg)) { in dwc2_hsotg_complete_in()
2701 dev_err(hsotg->dev, "error parsing DDMA results %d\n", in dwc2_hsotg_complete_in()
2711 dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n", in dwc2_hsotg_complete_in()
2715 dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", in dwc2_hsotg_complete_in()
2719 dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); in dwc2_hsotg_complete_in()
2720 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, true); in dwc2_hsotg_complete_in()
2726 dwc2_hsotg_program_zlp(hsotg, hs_ep); in dwc2_hsotg_complete_in()
2732 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_DATA_IN) { in dwc2_hsotg_complete_in()
2734 dwc2_hsotg_ep0_zlp(hsotg, false); in dwc2_hsotg_complete_in()
2738 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_complete_in()
2750 static u32 dwc2_gadget_read_ep_interrupts(struct dwc2_hsotg *hsotg, in dwc2_gadget_read_ep_interrupts() argument
2759 mask = dwc2_readl(hsotg, epmsk_reg); in dwc2_gadget_read_ep_interrupts()
2760 diepempmsk = dwc2_readl(hsotg, DIEPEMPMSK); in dwc2_gadget_read_ep_interrupts()
2764 ints = dwc2_readl(hsotg, epint_reg); in dwc2_gadget_read_ep_interrupts()
2784 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_handle_ep_disabled() local
2789 int dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_handle_ep_disabled()
2791 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); in dwc2_gadget_handle_ep_disabled()
2794 int epctl = dwc2_readl(hsotg, epctl_reg); in dwc2_gadget_handle_ep_disabled()
2796 dwc2_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); in dwc2_gadget_handle_ep_disabled()
2799 dwc2_hsotg_complete_in(hsotg, hs_ep); in dwc2_gadget_handle_ep_disabled()
2804 int dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_handle_ep_disabled()
2807 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_handle_ep_disabled()
2814 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_handle_ep_disabled()
2821 dev_dbg(hsotg->dev, "%s: complete_ep 0x%p, ep->queue empty!\n", in dwc2_gadget_handle_ep_disabled()
2829 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, in dwc2_gadget_handle_ep_disabled()
2833 hsotg->frame_number = dwc2_hsotg_read_frameno(hsotg); in dwc2_gadget_handle_ep_disabled()
2852 struct dwc2_hsotg *hsotg = ep->parent; in dwc2_gadget_handle_out_token_ep_disabled() local
2859 if (using_desc_dma(hsotg)) { in dwc2_gadget_handle_out_token_ep_disabled()
2862 ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_out_token_ep_disabled()
2872 ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_out_token_ep_disabled()
2875 ctrl = dwc2_readl(hsotg, DOEPCTL(ep->index)); in dwc2_gadget_handle_out_token_ep_disabled()
2881 dwc2_writel(hsotg, ctrl, DOEPCTL(ep->index)); in dwc2_gadget_handle_out_token_ep_disabled()
2885 doepmsk = dwc2_readl(hsotg, DOEPMSK); in dwc2_gadget_handle_out_token_ep_disabled()
2887 dwc2_writel(hsotg, doepmsk, DOEPMSK); in dwc2_gadget_handle_out_token_ep_disabled()
2906 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_handle_nak() local
2914 if (using_desc_dma(hsotg)) { in dwc2_gadget_handle_nak()
2915 hs_ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_nak()
2921 if (hsotg->params.service_interval) { in dwc2_gadget_handle_nak()
2938 hs_ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_nak()
2940 u32 ctrl = dwc2_readl(hsotg, in dwc2_gadget_handle_nak()
2947 dwc2_writel(hsotg, ctrl, DIEPCTL(hs_ep->index)); in dwc2_gadget_handle_nak()
2950 dwc2_hsotg_complete_request(hsotg, hs_ep, in dwc2_gadget_handle_nak()
2954 if (!using_desc_dma(hsotg)) in dwc2_gadget_handle_nak()
2966 static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, in dwc2_hsotg_epint() argument
2969 struct dwc2_hsotg_ep *hs_ep = index_to_ep(hsotg, idx, dir_in); in dwc2_hsotg_epint()
2976 ints = dwc2_gadget_read_ep_interrupts(hsotg, idx, dir_in); in dwc2_hsotg_epint()
2977 ctrl = dwc2_readl(hsotg, epctl_reg); in dwc2_hsotg_epint()
2980 dwc2_writel(hsotg, ints, epint_reg); in dwc2_hsotg_epint()
2983 dev_err(hsotg->dev, "%s:Interrupt for unconfigured ep%d(%s)\n", in dwc2_hsotg_epint()
2988 dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", in dwc2_hsotg_epint()
3001 if (using_desc_dma(hsotg) && idx == 0 && !hs_ep->dir_in && in dwc2_hsotg_epint()
3002 hsotg->ep0_state == DWC2_EP0_SETUP && !(ints & DXEPINT_SETUP)) in dwc2_hsotg_epint()
3006 dev_dbg(hsotg->dev, in dwc2_hsotg_epint()
3008 __func__, dwc2_readl(hsotg, epctl_reg), in dwc2_hsotg_epint()
3009 dwc2_readl(hsotg, epsiz_reg)); in dwc2_hsotg_epint()
3012 if (using_desc_dma(hsotg) && hs_ep->isochronous) { in dwc2_hsotg_epint()
3025 dwc2_hsotg_complete_in(hsotg, hs_ep); in dwc2_hsotg_epint()
3030 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_epint()
3031 } else if (using_dma(hsotg)) { in dwc2_hsotg_epint()
3039 dwc2_hsotg_handle_outdone(hsotg, idx); in dwc2_hsotg_epint()
3053 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); in dwc2_hsotg_epint()
3056 dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); in dwc2_hsotg_epint()
3058 if (using_dma(hsotg) && idx == 0) { in dwc2_hsotg_epint()
3069 dwc2_hsotg_handle_outdone(hsotg, 0); in dwc2_hsotg_epint()
3074 dev_dbg(hsotg->dev, "%s: StsPhseRcvd\n", __func__); in dwc2_hsotg_epint()
3077 if (hsotg->ep0_state == DWC2_EP0_DATA_OUT) { in dwc2_hsotg_epint()
3079 if (using_desc_dma(hsotg)) { in dwc2_hsotg_epint()
3080 if (!hsotg->delayed_status) in dwc2_hsotg_epint()
3081 dwc2_hsotg_ep0_zlp(hsotg, true); in dwc2_hsotg_epint()
3090 dwc2_set_bit(hsotg, DIEPCTL(0), in dwc2_hsotg_epint()
3098 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); in dwc2_hsotg_epint()
3101 dev_dbg(hsotg->dev, "%s: BNA interrupt\n", __func__); in dwc2_hsotg_epint()
3109 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", in dwc2_hsotg_epint()
3115 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", in dwc2_hsotg_epint()
3120 if (hsotg->dedicated_fifos && in dwc2_hsotg_epint()
3122 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", in dwc2_hsotg_epint()
3124 if (!using_dma(hsotg)) in dwc2_hsotg_epint()
3125 dwc2_hsotg_trytx(hsotg, hs_ep); in dwc2_hsotg_epint()
3137 static void dwc2_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) in dwc2_hsotg_irq_enumdone() argument
3139 u32 dsts = dwc2_readl(hsotg, DSTS); in dwc2_hsotg_irq_enumdone()
3148 dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); in dwc2_hsotg_irq_enumdone()
3160 hsotg->gadget.speed = USB_SPEED_FULL; in dwc2_hsotg_irq_enumdone()
3166 hsotg->gadget.speed = USB_SPEED_HIGH; in dwc2_hsotg_irq_enumdone()
3172 hsotg->gadget.speed = USB_SPEED_LOW; in dwc2_hsotg_irq_enumdone()
3182 dev_info(hsotg->dev, "new device is %s\n", in dwc2_hsotg_irq_enumdone()
3183 usb_speed_string(hsotg->gadget.speed)); in dwc2_hsotg_irq_enumdone()
3193 dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0, 1); in dwc2_hsotg_irq_enumdone()
3194 dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0, 0); in dwc2_hsotg_irq_enumdone()
3195 for (i = 1; i < hsotg->num_of_eps; i++) { in dwc2_hsotg_irq_enumdone()
3196 if (hsotg->eps_in[i]) in dwc2_hsotg_irq_enumdone()
3197 dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, in dwc2_hsotg_irq_enumdone()
3199 if (hsotg->eps_out[i]) in dwc2_hsotg_irq_enumdone()
3200 dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, in dwc2_hsotg_irq_enumdone()
3207 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_irq_enumdone()
3209 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_irq_enumdone()
3210 dwc2_readl(hsotg, DIEPCTL0), in dwc2_hsotg_irq_enumdone()
3211 dwc2_readl(hsotg, DOEPCTL0)); in dwc2_hsotg_irq_enumdone()
3223 static void kill_all_requests(struct dwc2_hsotg *hsotg, in kill_all_requests() argument
3234 dwc2_hsotg_complete_request(hsotg, ep, req, result); in kill_all_requests()
3237 if (!hsotg->dedicated_fifos) in kill_all_requests()
3239 size = (dwc2_readl(hsotg, DTXFSTS(ep->fifo_index)) & 0xffff) * 4; in kill_all_requests()
3241 dwc2_hsotg_txfifo_flush(hsotg, ep->fifo_index); in kill_all_requests()
3252 void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_disconnect() argument
3256 if (!hsotg->connected) in dwc2_hsotg_disconnect()
3259 hsotg->connected = 0; in dwc2_hsotg_disconnect()
3260 hsotg->test_mode = 0; in dwc2_hsotg_disconnect()
3263 for (ep = 0; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_disconnect()
3264 if (hsotg->eps_in[ep]) in dwc2_hsotg_disconnect()
3265 kill_all_requests(hsotg, hsotg->eps_in[ep], in dwc2_hsotg_disconnect()
3267 if (hsotg->eps_out[ep]) in dwc2_hsotg_disconnect()
3268 kill_all_requests(hsotg, hsotg->eps_out[ep], in dwc2_hsotg_disconnect()
3272 call_gadget(hsotg, disconnect); in dwc2_hsotg_disconnect()
3273 hsotg->lx_state = DWC2_L3; in dwc2_hsotg_disconnect()
3275 usb_gadget_set_state(&hsotg->gadget, USB_STATE_NOTATTACHED); in dwc2_hsotg_disconnect()
3283 static void dwc2_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic) in dwc2_hsotg_irq_fifoempty() argument
3289 for (epno = 0; epno < hsotg->num_of_eps; epno++) { in dwc2_hsotg_irq_fifoempty()
3290 ep = index_to_ep(hsotg, epno, 1); in dwc2_hsotg_irq_fifoempty()
3302 ret = dwc2_hsotg_trytx(hsotg, ep); in dwc2_hsotg_irq_fifoempty()
3321 void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, in dwc2_hsotg_core_init_disconnected() argument
3331 kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); in dwc2_hsotg_core_init_disconnected()
3334 if (dwc2_core_reset(hsotg, true)) in dwc2_hsotg_core_init_disconnected()
3338 for (ep = 1; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_core_init_disconnected()
3339 if (hsotg->eps_in[ep]) in dwc2_hsotg_core_init_disconnected()
3340 dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_core_init_disconnected()
3341 if (hsotg->eps_out[ep]) in dwc2_hsotg_core_init_disconnected()
3342 dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_core_init_disconnected()
3352 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_hsotg_core_init_disconnected()
3358 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_hsotg_core_init_disconnected()
3360 dwc2_phy_init(hsotg, true); in dwc2_hsotg_core_init_disconnected()
3362 dwc2_hsotg_init_fifo(hsotg); in dwc2_hsotg_core_init_disconnected()
3365 dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_init_disconnected()
3369 switch (hsotg->params.speed) { in dwc2_hsotg_core_init_disconnected()
3374 if (hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS) in dwc2_hsotg_core_init_disconnected()
3383 if (hsotg->params.ipg_isoc_en) in dwc2_hsotg_core_init_disconnected()
3386 dwc2_writel(hsotg, dcfg, DCFG); in dwc2_hsotg_core_init_disconnected()
3389 dwc2_writel(hsotg, 0xffffffff, GOTGINT); in dwc2_hsotg_core_init_disconnected()
3392 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_hsotg_core_init_disconnected()
3400 if (!using_desc_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
3403 if (!hsotg->params.external_id_pin_ctl) in dwc2_hsotg_core_init_disconnected()
3406 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_hsotg_core_init_disconnected()
3408 if (using_dma(hsotg)) { in dwc2_hsotg_core_init_disconnected()
3409 dwc2_writel(hsotg, GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | in dwc2_hsotg_core_init_disconnected()
3410 hsotg->params.ahbcfg, in dwc2_hsotg_core_init_disconnected()
3414 if (using_desc_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
3415 dwc2_set_bit(hsotg, DCFG, DCFG_DESCDMA_EN); in dwc2_hsotg_core_init_disconnected()
3418 dwc2_writel(hsotg, ((hsotg->dedicated_fifos) ? in dwc2_hsotg_core_init_disconnected()
3430 dwc2_writel(hsotg, ((hsotg->dedicated_fifos && !using_dma(hsotg)) ? in dwc2_hsotg_core_init_disconnected()
3440 dwc2_writel(hsotg, (using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | in dwc2_hsotg_core_init_disconnected()
3447 if (using_desc_dma(hsotg)) { in dwc2_hsotg_core_init_disconnected()
3448 dwc2_set_bit(hsotg, DOEPMSK, DOEPMSK_BNAMSK); in dwc2_hsotg_core_init_disconnected()
3449 dwc2_set_bit(hsotg, DIEPMSK, DIEPMSK_BNAININTRMSK); in dwc2_hsotg_core_init_disconnected()
3453 if (using_desc_dma(hsotg) && hsotg->params.service_interval) in dwc2_hsotg_core_init_disconnected()
3454 dwc2_set_bit(hsotg, DCTL, DCTL_SERVICE_INTERVAL_SUPPORTED); in dwc2_hsotg_core_init_disconnected()
3456 dwc2_writel(hsotg, 0, DAINTMSK); in dwc2_hsotg_core_init_disconnected()
3458 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_core_init_disconnected()
3459 dwc2_readl(hsotg, DIEPCTL0), in dwc2_hsotg_core_init_disconnected()
3460 dwc2_readl(hsotg, DOEPCTL0)); in dwc2_hsotg_core_init_disconnected()
3463 dwc2_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); in dwc2_hsotg_core_init_disconnected()
3470 if (!using_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
3471 dwc2_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); in dwc2_hsotg_core_init_disconnected()
3474 dwc2_hsotg_ctrl_epint(hsotg, 0, 0, 1); in dwc2_hsotg_core_init_disconnected()
3475 dwc2_hsotg_ctrl_epint(hsotg, 0, 1, 1); in dwc2_hsotg_core_init_disconnected()
3478 dwc2_set_bit(hsotg, DCTL, DCTL_PWRONPRGDONE); in dwc2_hsotg_core_init_disconnected()
3480 dwc2_clear_bit(hsotg, DCTL, DCTL_PWRONPRGDONE); in dwc2_hsotg_core_init_disconnected()
3483 dev_dbg(hsotg->dev, "DCTL=0x%08x\n", dwc2_readl(hsotg, DCTL)); in dwc2_hsotg_core_init_disconnected()
3491 dwc2_writel(hsotg, DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | in dwc2_hsotg_core_init_disconnected()
3494 dwc2_writel(hsotg, dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in dwc2_hsotg_core_init_disconnected()
3500 dwc2_writel(hsotg, dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in dwc2_hsotg_core_init_disconnected()
3507 dwc2_set_bit(hsotg, DCTL, val); in dwc2_hsotg_core_init_disconnected()
3510 dwc2_gadget_init_lpm(hsotg); in dwc2_hsotg_core_init_disconnected()
3513 if (using_desc_dma(hsotg) && hsotg->params.service_interval) in dwc2_hsotg_core_init_disconnected()
3514 dwc2_gadget_program_ref_clk(hsotg); in dwc2_hsotg_core_init_disconnected()
3519 hsotg->lx_state = DWC2_L0; in dwc2_hsotg_core_init_disconnected()
3521 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_core_init_disconnected()
3523 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_core_init_disconnected()
3524 dwc2_readl(hsotg, DIEPCTL0), in dwc2_hsotg_core_init_disconnected()
3525 dwc2_readl(hsotg, DOEPCTL0)); in dwc2_hsotg_core_init_disconnected()
3528 static void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_core_disconnect() argument
3531 dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_disconnect()
3534 void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_core_connect() argument
3537 dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_connect()
3553 static void dwc2_gadget_handle_incomplete_isoc_in(struct dwc2_hsotg *hsotg) in dwc2_gadget_handle_incomplete_isoc_in() argument
3560 dev_dbg(hsotg->dev, "Incomplete isoc in interrupt received:\n"); in dwc2_gadget_handle_incomplete_isoc_in()
3562 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_gadget_handle_incomplete_isoc_in()
3564 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_gadget_handle_incomplete_isoc_in()
3565 hs_ep = hsotg->eps_in[idx]; in dwc2_gadget_handle_incomplete_isoc_in()
3570 epctrl = dwc2_readl(hsotg, DIEPCTL(idx)); in dwc2_gadget_handle_incomplete_isoc_in()
3575 dwc2_writel(hsotg, epctrl, DIEPCTL(idx)); in dwc2_gadget_handle_incomplete_isoc_in()
3580 dwc2_writel(hsotg, GINTSTS_INCOMPL_SOIN, GINTSTS); in dwc2_gadget_handle_incomplete_isoc_in()
3596 static void dwc2_gadget_handle_incomplete_isoc_out(struct dwc2_hsotg *hsotg) in dwc2_gadget_handle_incomplete_isoc_out() argument
3605 dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__); in dwc2_gadget_handle_incomplete_isoc_out()
3607 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_gadget_handle_incomplete_isoc_out()
3610 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_gadget_handle_incomplete_isoc_out()
3611 hs_ep = hsotg->eps_out[idx]; in dwc2_gadget_handle_incomplete_isoc_out()
3616 epctrl = dwc2_readl(hsotg, DOEPCTL(idx)); in dwc2_gadget_handle_incomplete_isoc_out()
3620 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_gadget_handle_incomplete_isoc_out()
3622 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_gadget_handle_incomplete_isoc_out()
3624 gintsts = dwc2_readl(hsotg, GINTSTS); in dwc2_gadget_handle_incomplete_isoc_out()
3626 dwc2_set_bit(hsotg, DCTL, DCTL_SGOUTNAK); in dwc2_gadget_handle_incomplete_isoc_out()
3633 dwc2_writel(hsotg, GINTSTS_INCOMPL_SOOUT, GINTSTS); in dwc2_gadget_handle_incomplete_isoc_out()
3643 struct dwc2_hsotg *hsotg = pw; in dwc2_hsotg_irq() local
3648 if (!dwc2_is_device_mode(hsotg)) in dwc2_hsotg_irq()
3651 spin_lock(&hsotg->lock); in dwc2_hsotg_irq()
3653 gintsts = dwc2_readl(hsotg, GINTSTS); in dwc2_hsotg_irq()
3654 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_irq()
3656 dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", in dwc2_hsotg_irq()
3662 dev_dbg(hsotg->dev, "%s: USBRstDet\n", __func__); in dwc2_hsotg_irq()
3664 dwc2_writel(hsotg, GINTSTS_RESETDET, GINTSTS); in dwc2_hsotg_irq()
3667 if (hsotg->lx_state == DWC2_L2) { in dwc2_hsotg_irq()
3668 dwc2_exit_partial_power_down(hsotg, true); in dwc2_hsotg_irq()
3669 hsotg->lx_state = DWC2_L0; in dwc2_hsotg_irq()
3674 u32 usb_status = dwc2_readl(hsotg, GOTGCTL); in dwc2_hsotg_irq()
3675 u32 connected = hsotg->connected; in dwc2_hsotg_irq()
3677 dev_dbg(hsotg->dev, "%s: USBRst\n", __func__); in dwc2_hsotg_irq()
3678 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", in dwc2_hsotg_irq()
3679 dwc2_readl(hsotg, GNPTXSTS)); in dwc2_hsotg_irq()
3681 dwc2_writel(hsotg, GINTSTS_USBRST, GINTSTS); in dwc2_hsotg_irq()
3684 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_irq()
3687 dwc2_clear_bit(hsotg, DCFG, DCFG_DEVADDR_MASK); in dwc2_hsotg_irq()
3690 dwc2_hsotg_core_init_disconnected(hsotg, true); in dwc2_hsotg_irq()
3694 dwc2_writel(hsotg, GINTSTS_ENUMDONE, GINTSTS); in dwc2_hsotg_irq()
3696 dwc2_hsotg_irq_enumdone(hsotg); in dwc2_hsotg_irq()
3700 u32 daint = dwc2_readl(hsotg, DAINT); in dwc2_hsotg_irq()
3701 u32 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_hsotg_irq()
3709 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); in dwc2_hsotg_irq()
3711 for (ep = 0; ep < hsotg->num_of_eps && daint_out; in dwc2_hsotg_irq()
3714 dwc2_hsotg_epint(hsotg, ep, 0); in dwc2_hsotg_irq()
3717 for (ep = 0; ep < hsotg->num_of_eps && daint_in; in dwc2_hsotg_irq()
3720 dwc2_hsotg_epint(hsotg, ep, 1); in dwc2_hsotg_irq()
3727 dev_dbg(hsotg->dev, "NPTxFEmp\n"); in dwc2_hsotg_irq()
3735 dwc2_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); in dwc2_hsotg_irq()
3736 dwc2_hsotg_irq_fifoempty(hsotg, false); in dwc2_hsotg_irq()
3740 dev_dbg(hsotg->dev, "PTxFEmp\n"); in dwc2_hsotg_irq()
3744 dwc2_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_irq()
3745 dwc2_hsotg_irq_fifoempty(hsotg, true); in dwc2_hsotg_irq()
3755 dwc2_hsotg_handle_rx(hsotg); in dwc2_hsotg_irq()
3759 dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); in dwc2_hsotg_irq()
3760 dwc2_writel(hsotg, GINTSTS_ERLYSUSP, GINTSTS); in dwc2_hsotg_irq()
3776 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_hsotg_irq()
3779 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_irq()
3781 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_hsotg_irq()
3783 dev_dbg(hsotg->dev, "GOUTNakEff triggered\n"); in dwc2_hsotg_irq()
3784 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_irq()
3785 hs_ep = hsotg->eps_out[idx]; in dwc2_hsotg_irq()
3790 epctrl = dwc2_readl(hsotg, DOEPCTL(idx)); in dwc2_hsotg_irq()
3795 dwc2_writel(hsotg, epctrl, DOEPCTL(idx)); in dwc2_hsotg_irq()
3803 dev_info(hsotg->dev, "GINNakEff triggered\n"); in dwc2_hsotg_irq()
3805 dwc2_set_bit(hsotg, DCTL, DCTL_CGNPINNAK); in dwc2_hsotg_irq()
3807 dwc2_hsotg_dump(hsotg); in dwc2_hsotg_irq()
3811 dwc2_gadget_handle_incomplete_isoc_in(hsotg); in dwc2_hsotg_irq()
3814 dwc2_gadget_handle_incomplete_isoc_out(hsotg); in dwc2_hsotg_irq()
3825 if (hsotg->params.service_interval) in dwc2_hsotg_irq()
3826 dwc2_gadget_wkup_alert_handler(hsotg); in dwc2_hsotg_irq()
3828 spin_unlock(&hsotg->lock); in dwc2_hsotg_irq()
3833 static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg, in dwc2_hsotg_ep_stop_xfr() argument
3844 dev_dbg(hsotg->dev, "%s: stopping transfer on %s\n", __func__, in dwc2_hsotg_ep_stop_xfr()
3848 if (hsotg->dedicated_fifos || hs_ep->periodic) { in dwc2_hsotg_ep_stop_xfr()
3849 dwc2_set_bit(hsotg, epctrl_reg, DXEPCTL_SNAK); in dwc2_hsotg_ep_stop_xfr()
3851 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, in dwc2_hsotg_ep_stop_xfr()
3853 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
3857 dwc2_set_bit(hsotg, DCTL, DCTL_SGNPINNAK); in dwc2_hsotg_ep_stop_xfr()
3859 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, in dwc2_hsotg_ep_stop_xfr()
3861 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
3866 if (!(dwc2_readl(hsotg, GINTSTS) & GINTSTS_GOUTNAKEFF)) in dwc2_hsotg_ep_stop_xfr()
3867 dwc2_set_bit(hsotg, DCTL, DCTL_SGOUTNAK); in dwc2_hsotg_ep_stop_xfr()
3870 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, in dwc2_hsotg_ep_stop_xfr()
3872 dev_warn(hsotg->dev, "%s: timeout GINTSTS.GOUTNAKEFF\n", in dwc2_hsotg_ep_stop_xfr()
3877 dwc2_set_bit(hsotg, epctrl_reg, DXEPCTL_EPDIS | DXEPCTL_SNAK); in dwc2_hsotg_ep_stop_xfr()
3880 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, DXEPINT_EPDISBLD, 100)) in dwc2_hsotg_ep_stop_xfr()
3881 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
3885 dwc2_set_bit(hsotg, epint_reg, DXEPINT_EPDISBLD); in dwc2_hsotg_ep_stop_xfr()
3890 if (hsotg->dedicated_fifos || hs_ep->periodic) in dwc2_hsotg_ep_stop_xfr()
3896 dwc2_flush_tx_fifo(hsotg, fifo_index); in dwc2_hsotg_ep_stop_xfr()
3899 if (!hsotg->dedicated_fifos && !hs_ep->periodic) in dwc2_hsotg_ep_stop_xfr()
3900 dwc2_set_bit(hsotg, DCTL, DCTL_CGNPINNAK); in dwc2_hsotg_ep_stop_xfr()
3904 dwc2_set_bit(hsotg, DCTL, DCTL_CGOUTNAK); in dwc2_hsotg_ep_stop_xfr()
3919 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_enable() local
3933 dev_dbg(hsotg->dev, in dwc2_hsotg_ep_enable()
3940 dev_err(hsotg->dev, "%s: called for EP 0\n", __func__); in dwc2_hsotg_ep_enable()
3946 dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__); in dwc2_hsotg_ep_enable()
3955 if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC && in dwc2_hsotg_ep_enable()
3957 dev_err(hsotg->dev, in dwc2_hsotg_ep_enable()
3963 if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC && in dwc2_hsotg_ep_enable()
3965 dev_err(hsotg->dev, in dwc2_hsotg_ep_enable()
3973 epctrl = dwc2_readl(hsotg, epctrl_reg); in dwc2_hsotg_ep_enable()
3975 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", in dwc2_hsotg_ep_enable()
3978 if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_hsotg_ep_enable()
3984 if (using_desc_dma(hsotg) && !hs_ep->desc_list) { in dwc2_hsotg_ep_enable()
3985 hs_ep->desc_list = dmam_alloc_coherent(hsotg->dev, in dwc2_hsotg_ep_enable()
3994 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_ep_enable()
4006 dwc2_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps, mc, dir_in); in dwc2_hsotg_ep_enable()
4025 mask = dwc2_readl(hsotg, DIEPMSK); in dwc2_hsotg_ep_enable()
4027 dwc2_writel(hsotg, mask, DIEPMSK); in dwc2_hsotg_ep_enable()
4029 mask = dwc2_readl(hsotg, DOEPMSK); in dwc2_hsotg_ep_enable()
4031 dwc2_writel(hsotg, mask, DOEPMSK); in dwc2_hsotg_ep_enable()
4043 if (hsotg->gadget.speed == USB_SPEED_HIGH) in dwc2_hsotg_ep_enable()
4058 if (dir_in && hsotg->dedicated_fifos) { in dwc2_hsotg_ep_enable()
4063 for (i = 1; i < hsotg->num_of_eps; ++i) { in dwc2_hsotg_ep_enable()
4064 if (hsotg->fifo_map & (1 << i)) in dwc2_hsotg_ep_enable()
4066 val = dwc2_readl(hsotg, DPTXFSIZN(i)); in dwc2_hsotg_ep_enable()
4077 dev_err(hsotg->dev, in dwc2_hsotg_ep_enable()
4083 hsotg->fifo_map |= 1 << fifo_index; in dwc2_hsotg_ep_enable()
4099 if (hsotg->gadget.speed == USB_SPEED_FULL && in dwc2_hsotg_ep_enable()
4105 u32 gsnpsid = dwc2_readl(hsotg, GSNPSID); in dwc2_hsotg_ep_enable()
4114 dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", in dwc2_hsotg_ep_enable()
4117 dwc2_writel(hsotg, epctrl, epctrl_reg); in dwc2_hsotg_ep_enable()
4118 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", in dwc2_hsotg_ep_enable()
4119 __func__, dwc2_readl(hsotg, epctrl_reg)); in dwc2_hsotg_ep_enable()
4122 dwc2_hsotg_ctrl_epint(hsotg, index, dir_in, 1); in dwc2_hsotg_ep_enable()
4125 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_ep_enable()
4128 if (ret && using_desc_dma(hsotg) && hs_ep->desc_list) { in dwc2_hsotg_ep_enable()
4129 dmam_free_coherent(hsotg->dev, desc_num * in dwc2_hsotg_ep_enable()
4145 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_disable() local
4151 dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); in dwc2_hsotg_ep_disable()
4153 if (ep == &hsotg->eps_out[0]->ep) { in dwc2_hsotg_ep_disable()
4154 dev_err(hsotg->dev, "%s: called for ep0\n", __func__); in dwc2_hsotg_ep_disable()
4158 if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) { in dwc2_hsotg_ep_disable()
4159 dev_err(hsotg->dev, "%s: called in host mode?\n", __func__); in dwc2_hsotg_ep_disable()
4165 ctrl = dwc2_readl(hsotg, epctrl_reg); in dwc2_hsotg_ep_disable()
4168 dwc2_hsotg_ep_stop_xfr(hsotg, hs_ep); in dwc2_hsotg_ep_disable()
4174 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in dwc2_hsotg_ep_disable()
4175 dwc2_writel(hsotg, ctrl, epctrl_reg); in dwc2_hsotg_ep_disable()
4178 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); in dwc2_hsotg_ep_disable()
4181 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN); in dwc2_hsotg_ep_disable()
4183 hsotg->fifo_map &= ~(1 << hs_ep->fifo_index); in dwc2_hsotg_ep_disable()
4193 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_disable_lock() local
4197 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_ep_disable_lock()
4199 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_ep_disable_lock()
4363 static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg) in dwc2_hsotg_init() argument
4367 dwc2_writel(hsotg, DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | in dwc2_hsotg_init()
4371 dwc2_writel(hsotg, DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | in dwc2_hsotg_init()
4375 dwc2_writel(hsotg, 0, DAINTMSK); in dwc2_hsotg_init()
4378 dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_init()
4382 dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", in dwc2_hsotg_init()
4383 dwc2_readl(hsotg, GRXFSIZ), in dwc2_hsotg_init()
4384 dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_hsotg_init()
4386 dwc2_hsotg_init_fifo(hsotg); in dwc2_hsotg_init()
4388 if (using_dma(hsotg)) in dwc2_hsotg_init()
4389 dwc2_set_bit(hsotg, GAHBCFG, GAHBCFG_DMA_EN); in dwc2_hsotg_init()
4403 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_udc_start() local
4407 if (!hsotg) { in dwc2_hsotg_udc_start()
4413 dev_err(hsotg->dev, "%s: no driver\n", __func__); in dwc2_hsotg_udc_start()
4418 dev_err(hsotg->dev, "%s: bad speed\n", __func__); in dwc2_hsotg_udc_start()
4421 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); in dwc2_hsotg_udc_start()
4425 WARN_ON(hsotg->driver); in dwc2_hsotg_udc_start()
4428 hsotg->driver = driver; in dwc2_hsotg_udc_start()
4429 hsotg->gadget.dev.of_node = hsotg->dev->of_node; in dwc2_hsotg_udc_start()
4430 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_udc_start()
4432 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { in dwc2_hsotg_udc_start()
4433 ret = dwc2_lowlevel_hw_enable(hsotg); in dwc2_hsotg_udc_start()
4438 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_udc_start()
4439 otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget); in dwc2_hsotg_udc_start()
4441 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_udc_start()
4442 if (dwc2_hw_is_device(hsotg)) { in dwc2_hsotg_udc_start()
4443 dwc2_hsotg_init(hsotg); in dwc2_hsotg_udc_start()
4444 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_udc_start()
4447 hsotg->enabled = 0; in dwc2_hsotg_udc_start()
4448 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_udc_start()
4450 gadget->sg_supported = using_desc_dma(hsotg); in dwc2_hsotg_udc_start()
4451 dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); in dwc2_hsotg_udc_start()
4456 hsotg->driver = NULL; in dwc2_hsotg_udc_start()
4468 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_udc_stop() local
4472 if (!hsotg) in dwc2_hsotg_udc_stop()
4476 for (ep = 1; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_udc_stop()
4477 if (hsotg->eps_in[ep]) in dwc2_hsotg_udc_stop()
4478 dwc2_hsotg_ep_disable_lock(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_udc_stop()
4479 if (hsotg->eps_out[ep]) in dwc2_hsotg_udc_stop()
4480 dwc2_hsotg_ep_disable_lock(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_udc_stop()
4483 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_udc_stop()
4485 hsotg->driver = NULL; in dwc2_hsotg_udc_stop()
4486 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_udc_stop()
4487 hsotg->enabled = 0; in dwc2_hsotg_udc_stop()
4489 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_udc_stop()
4491 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_udc_stop()
4492 otg_set_peripheral(hsotg->uphy->otg, NULL); in dwc2_hsotg_udc_stop()
4494 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_hsotg_udc_stop()
4495 dwc2_lowlevel_hw_disable(hsotg); in dwc2_hsotg_udc_stop()
4520 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_pullup() local
4523 dev_dbg(hsotg->dev, "%s: is_on: %d op_state: %d\n", __func__, is_on, in dwc2_hsotg_pullup()
4524 hsotg->op_state); in dwc2_hsotg_pullup()
4527 if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) { in dwc2_hsotg_pullup()
4528 hsotg->enabled = is_on; in dwc2_hsotg_pullup()
4532 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_pullup()
4534 hsotg->enabled = 1; in dwc2_hsotg_pullup()
4535 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_pullup()
4537 dwc2_enable_acg(hsotg); in dwc2_hsotg_pullup()
4538 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_pullup()
4540 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_pullup()
4541 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_pullup()
4542 hsotg->enabled = 0; in dwc2_hsotg_pullup()
4545 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_pullup()
4546 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_pullup()
4553 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_vbus_session() local
4556 dev_dbg(hsotg->dev, "%s: is_active: %d\n", __func__, is_active); in dwc2_hsotg_vbus_session()
4557 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_vbus_session()
4563 if (hsotg->lx_state == DWC2_L2) in dwc2_hsotg_vbus_session()
4564 dwc2_exit_partial_power_down(hsotg, false); in dwc2_hsotg_vbus_session()
4567 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_hsotg_vbus_session()
4569 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_vbus_session()
4570 if (hsotg->enabled) { in dwc2_hsotg_vbus_session()
4572 dwc2_enable_acg(hsotg); in dwc2_hsotg_vbus_session()
4573 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_vbus_session()
4576 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_vbus_session()
4577 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_vbus_session()
4580 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_vbus_session()
4593 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_vbus_draw() local
4595 if (IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_vbus_draw()
4597 return usb_phy_set_power(hsotg->uphy, mA); in dwc2_hsotg_vbus_draw()
4620 static void dwc2_hsotg_initep(struct dwc2_hsotg *hsotg, in dwc2_hsotg_initep() argument
4644 list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); in dwc2_hsotg_initep()
4646 hs_ep->parent = hsotg; in dwc2_hsotg_initep()
4649 if (hsotg->params.speed == DWC2_SPEED_PARAM_LOW) in dwc2_hsotg_initep()
4659 if (hsotg->params.speed != DWC2_SPEED_PARAM_LOW) { in dwc2_hsotg_initep()
4676 if (using_dma(hsotg)) { in dwc2_hsotg_initep()
4680 dwc2_writel(hsotg, next, DIEPCTL(epnum)); in dwc2_hsotg_initep()
4682 dwc2_writel(hsotg, next, DOEPCTL(epnum)); in dwc2_hsotg_initep()
4692 static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) in dwc2_hsotg_hw_cfg() argument
4700 hsotg->num_of_eps = hsotg->hw_params.num_dev_ep; in dwc2_hsotg_hw_cfg()
4703 hsotg->num_of_eps++; in dwc2_hsotg_hw_cfg()
4705 hsotg->eps_in[0] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
4708 if (!hsotg->eps_in[0]) in dwc2_hsotg_hw_cfg()
4711 hsotg->eps_out[0] = hsotg->eps_in[0]; in dwc2_hsotg_hw_cfg()
4713 cfg = hsotg->hw_params.dev_ep_dirs; in dwc2_hsotg_hw_cfg()
4714 for (i = 1, cfg >>= 2; i < hsotg->num_of_eps; i++, cfg >>= 2) { in dwc2_hsotg_hw_cfg()
4718 hsotg->eps_in[i] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
4720 if (!hsotg->eps_in[i]) in dwc2_hsotg_hw_cfg()
4725 hsotg->eps_out[i] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
4727 if (!hsotg->eps_out[i]) in dwc2_hsotg_hw_cfg()
4732 hsotg->fifo_mem = hsotg->hw_params.total_fifo_size; in dwc2_hsotg_hw_cfg()
4733 hsotg->dedicated_fifos = hsotg->hw_params.en_multiple_tx_fifo; in dwc2_hsotg_hw_cfg()
4735 dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", in dwc2_hsotg_hw_cfg()
4736 hsotg->num_of_eps, in dwc2_hsotg_hw_cfg()
4737 hsotg->dedicated_fifos ? "dedicated" : "shared", in dwc2_hsotg_hw_cfg()
4738 hsotg->fifo_mem); in dwc2_hsotg_hw_cfg()
4747 static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg) in dwc2_hsotg_dump() argument
4750 struct device *dev = hsotg->dev; in dwc2_hsotg_dump()
4755 dwc2_readl(hsotg, DCFG), dwc2_readl(hsotg, DCTL), in dwc2_hsotg_dump()
4756 dwc2_readl(hsotg, DIEPMSK)); in dwc2_hsotg_dump()
4759 dwc2_readl(hsotg, GAHBCFG), dwc2_readl(hsotg, GHWCFG1)); in dwc2_hsotg_dump()
4762 dwc2_readl(hsotg, GRXFSIZ), dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_hsotg_dump()
4766 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_dump()
4767 val = dwc2_readl(hsotg, DPTXFSIZN(idx)); in dwc2_hsotg_dump()
4773 for (idx = 0; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_dump()
4776 dwc2_readl(hsotg, DIEPCTL(idx)), in dwc2_hsotg_dump()
4777 dwc2_readl(hsotg, DIEPTSIZ(idx)), in dwc2_hsotg_dump()
4778 dwc2_readl(hsotg, DIEPDMA(idx))); in dwc2_hsotg_dump()
4780 val = dwc2_readl(hsotg, DOEPCTL(idx)); in dwc2_hsotg_dump()
4783 idx, dwc2_readl(hsotg, DOEPCTL(idx)), in dwc2_hsotg_dump()
4784 dwc2_readl(hsotg, DOEPTSIZ(idx)), in dwc2_hsotg_dump()
4785 dwc2_readl(hsotg, DOEPDMA(idx))); in dwc2_hsotg_dump()
4789 dwc2_readl(hsotg, DVBUSDIS), dwc2_readl(hsotg, DVBUSPULSE)); in dwc2_hsotg_dump()
4798 int dwc2_gadget_init(struct dwc2_hsotg *hsotg) in dwc2_gadget_init() argument
4800 struct device *dev = hsotg->dev; in dwc2_gadget_init()
4806 hsotg->params.g_np_tx_fifo_size); in dwc2_gadget_init()
4807 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->params.g_rx_fifo_size); in dwc2_gadget_init()
4809 hsotg->gadget.max_speed = USB_SPEED_HIGH; in dwc2_gadget_init()
4810 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops; in dwc2_gadget_init()
4811 hsotg->gadget.name = dev_name(dev); in dwc2_gadget_init()
4812 hsotg->remote_wakeup_allowed = 0; in dwc2_gadget_init()
4814 if (hsotg->params.lpm) in dwc2_gadget_init()
4815 hsotg->gadget.lpm_capable = true; in dwc2_gadget_init()
4817 if (hsotg->dr_mode == USB_DR_MODE_OTG) in dwc2_gadget_init()
4818 hsotg->gadget.is_otg = 1; in dwc2_gadget_init()
4819 else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_gadget_init()
4820 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_gadget_init()
4822 ret = dwc2_hsotg_hw_cfg(hsotg); in dwc2_gadget_init()
4824 dev_err(hsotg->dev, "Hardware configuration failed: %d\n", ret); in dwc2_gadget_init()
4828 hsotg->ctrl_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
4830 if (!hsotg->ctrl_buff) in dwc2_gadget_init()
4833 hsotg->ep0_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
4835 if (!hsotg->ep0_buff) in dwc2_gadget_init()
4838 if (using_desc_dma(hsotg)) { in dwc2_gadget_init()
4839 ret = dwc2_gadget_alloc_ctrl_desc_chains(hsotg); in dwc2_gadget_init()
4844 ret = devm_request_irq(hsotg->dev, hsotg->irq, dwc2_hsotg_irq, in dwc2_gadget_init()
4845 IRQF_SHARED, dev_name(hsotg->dev), hsotg); in dwc2_gadget_init()
4853 if (hsotg->num_of_eps == 0) { in dwc2_gadget_init()
4860 INIT_LIST_HEAD(&hsotg->gadget.ep_list); in dwc2_gadget_init()
4861 hsotg->gadget.ep0 = &hsotg->eps_out[0]->ep; in dwc2_gadget_init()
4865 hsotg->ctrl_req = dwc2_hsotg_ep_alloc_request(&hsotg->eps_out[0]->ep, in dwc2_gadget_init()
4867 if (!hsotg->ctrl_req) { in dwc2_gadget_init()
4873 for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) { in dwc2_gadget_init()
4874 if (hsotg->eps_in[epnum]) in dwc2_gadget_init()
4875 dwc2_hsotg_initep(hsotg, hsotg->eps_in[epnum], in dwc2_gadget_init()
4877 if (hsotg->eps_out[epnum]) in dwc2_gadget_init()
4878 dwc2_hsotg_initep(hsotg, hsotg->eps_out[epnum], in dwc2_gadget_init()
4882 ret = usb_add_gadget_udc(dev, &hsotg->gadget); in dwc2_gadget_init()
4884 dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, in dwc2_gadget_init()
4885 hsotg->ctrl_req); in dwc2_gadget_init()
4888 dwc2_hsotg_dump(hsotg); in dwc2_gadget_init()
4898 int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg) in dwc2_hsotg_remove() argument
4900 usb_del_gadget_udc(&hsotg->gadget); in dwc2_hsotg_remove()
4901 dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req); in dwc2_hsotg_remove()
4906 int dwc2_hsotg_suspend(struct dwc2_hsotg *hsotg) in dwc2_hsotg_suspend() argument
4910 if (hsotg->lx_state != DWC2_L0) in dwc2_hsotg_suspend()
4913 if (hsotg->driver) { in dwc2_hsotg_suspend()
4916 dev_info(hsotg->dev, "suspending usb gadget %s\n", in dwc2_hsotg_suspend()
4917 hsotg->driver->driver.name); in dwc2_hsotg_suspend()
4919 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_suspend()
4920 if (hsotg->enabled) in dwc2_hsotg_suspend()
4921 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_suspend()
4922 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_suspend()
4923 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_suspend()
4924 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_suspend()
4926 for (ep = 0; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_suspend()
4927 if (hsotg->eps_in[ep]) in dwc2_hsotg_suspend()
4928 dwc2_hsotg_ep_disable_lock(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_suspend()
4929 if (hsotg->eps_out[ep]) in dwc2_hsotg_suspend()
4930 dwc2_hsotg_ep_disable_lock(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_suspend()
4937 int dwc2_hsotg_resume(struct dwc2_hsotg *hsotg) in dwc2_hsotg_resume() argument
4941 if (hsotg->lx_state == DWC2_L2) in dwc2_hsotg_resume()
4944 if (hsotg->driver) { in dwc2_hsotg_resume()
4945 dev_info(hsotg->dev, "resuming usb gadget %s\n", in dwc2_hsotg_resume()
4946 hsotg->driver->driver.name); in dwc2_hsotg_resume()
4948 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_resume()
4949 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_resume()
4950 if (hsotg->enabled) { in dwc2_hsotg_resume()
4952 dwc2_enable_acg(hsotg); in dwc2_hsotg_resume()
4953 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_resume()
4955 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_resume()
4968 int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg) in dwc2_backup_device_registers() argument
4973 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_backup_device_registers()
4976 dr = &hsotg->dr_backup; in dwc2_backup_device_registers()
4978 dr->dcfg = dwc2_readl(hsotg, DCFG); in dwc2_backup_device_registers()
4979 dr->dctl = dwc2_readl(hsotg, DCTL); in dwc2_backup_device_registers()
4980 dr->daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_backup_device_registers()
4981 dr->diepmsk = dwc2_readl(hsotg, DIEPMSK); in dwc2_backup_device_registers()
4982 dr->doepmsk = dwc2_readl(hsotg, DOEPMSK); in dwc2_backup_device_registers()
4984 for (i = 0; i < hsotg->num_of_eps; i++) { in dwc2_backup_device_registers()
4986 dr->diepctl[i] = dwc2_readl(hsotg, DIEPCTL(i)); in dwc2_backup_device_registers()
4994 dr->dieptsiz[i] = dwc2_readl(hsotg, DIEPTSIZ(i)); in dwc2_backup_device_registers()
4995 dr->diepdma[i] = dwc2_readl(hsotg, DIEPDMA(i)); in dwc2_backup_device_registers()
4998 dr->doepctl[i] = dwc2_readl(hsotg, DOEPCTL(i)); in dwc2_backup_device_registers()
5006 dr->doeptsiz[i] = dwc2_readl(hsotg, DOEPTSIZ(i)); in dwc2_backup_device_registers()
5007 dr->doepdma[i] = dwc2_readl(hsotg, DOEPDMA(i)); in dwc2_backup_device_registers()
5008 dr->dtxfsiz[i] = dwc2_readl(hsotg, DPTXFSIZN(i)); in dwc2_backup_device_registers()
5024 int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup) in dwc2_restore_device_registers() argument
5029 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_restore_device_registers()
5032 dr = &hsotg->dr_backup; in dwc2_restore_device_registers()
5034 dev_err(hsotg->dev, "%s: no device registers to restore\n", in dwc2_restore_device_registers()
5041 dwc2_writel(hsotg, dr->dctl, DCTL); in dwc2_restore_device_registers()
5043 dwc2_writel(hsotg, dr->daintmsk, DAINTMSK); in dwc2_restore_device_registers()
5044 dwc2_writel(hsotg, dr->diepmsk, DIEPMSK); in dwc2_restore_device_registers()
5045 dwc2_writel(hsotg, dr->doepmsk, DOEPMSK); in dwc2_restore_device_registers()
5047 for (i = 0; i < hsotg->num_of_eps; i++) { in dwc2_restore_device_registers()
5049 dwc2_writel(hsotg, dr->dieptsiz[i], DIEPTSIZ(i)); in dwc2_restore_device_registers()
5050 dwc2_writel(hsotg, dr->diepdma[i], DIEPDMA(i)); in dwc2_restore_device_registers()
5051 dwc2_writel(hsotg, dr->doeptsiz[i], DOEPTSIZ(i)); in dwc2_restore_device_registers()
5057 if (hsotg->params.g_dma_desc && in dwc2_restore_device_registers()
5059 dr->diepdma[i] = hsotg->eps_in[i]->desc_list_dma; in dwc2_restore_device_registers()
5060 dwc2_writel(hsotg, dr->dtxfsiz[i], DPTXFSIZN(i)); in dwc2_restore_device_registers()
5061 dwc2_writel(hsotg, dr->diepctl[i], DIEPCTL(i)); in dwc2_restore_device_registers()
5063 dwc2_writel(hsotg, dr->doeptsiz[i], DOEPTSIZ(i)); in dwc2_restore_device_registers()
5069 if (hsotg->params.g_dma_desc && in dwc2_restore_device_registers()
5071 dr->doepdma[i] = hsotg->eps_out[i]->desc_list_dma; in dwc2_restore_device_registers()
5072 dwc2_writel(hsotg, dr->doepdma[i], DOEPDMA(i)); in dwc2_restore_device_registers()
5073 dwc2_writel(hsotg, dr->doepctl[i], DOEPCTL(i)); in dwc2_restore_device_registers()
5085 void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) in dwc2_gadget_init_lpm() argument
5089 if (!hsotg->params.lpm) in dwc2_gadget_init_lpm()
5093 val |= hsotg->params.hird_threshold_en ? GLPMCFG_HIRD_THRES_EN : 0; in dwc2_gadget_init_lpm()
5094 val |= hsotg->params.lpm_clock_gating ? GLPMCFG_ENBLSLPM : 0; in dwc2_gadget_init_lpm()
5095 val |= hsotg->params.hird_threshold << GLPMCFG_HIRD_THRES_SHIFT; in dwc2_gadget_init_lpm()
5096 val |= hsotg->params.besl ? GLPMCFG_ENBESL : 0; in dwc2_gadget_init_lpm()
5099 dwc2_writel(hsotg, val, GLPMCFG); in dwc2_gadget_init_lpm()
5100 dev_dbg(hsotg->dev, "GLPMCFG=0x%08x\n", dwc2_readl(hsotg, GLPMCFG)); in dwc2_gadget_init_lpm()
5103 if (hsotg->params.service_interval) in dwc2_gadget_init_lpm()
5104 dwc2_set_bit(hsotg, GINTMSK2, GINTMSK2_WKUP_ALERT_INT_MSK); in dwc2_gadget_init_lpm()
5113 void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg) in dwc2_gadget_program_ref_clk() argument
5118 val |= hsotg->params.ref_clk_per << GREFCLK_REFCLKPER_SHIFT; in dwc2_gadget_program_ref_clk()
5119 val |= hsotg->params.sof_cnt_wkup_alert << in dwc2_gadget_program_ref_clk()
5122 dwc2_writel(hsotg, val, GREFCLK); in dwc2_gadget_program_ref_clk()
5123 dev_dbg(hsotg->dev, "GREFCLK=0x%08x\n", dwc2_readl(hsotg, GREFCLK)); in dwc2_gadget_program_ref_clk()
5133 int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg) in dwc2_gadget_enter_hibernation() argument
5139 hsotg->lx_state = DWC2_L2; in dwc2_gadget_enter_hibernation()
5140 dev_dbg(hsotg->dev, "Start of hibernation completed\n"); in dwc2_gadget_enter_hibernation()
5141 ret = dwc2_backup_global_registers(hsotg); in dwc2_gadget_enter_hibernation()
5143 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_gadget_enter_hibernation()
5147 ret = dwc2_backup_device_registers(hsotg); in dwc2_gadget_enter_hibernation()
5149 dev_err(hsotg->dev, "%s: failed to backup device registers\n", in dwc2_gadget_enter_hibernation()
5156 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5160 hsotg->hibernated = 1; in dwc2_gadget_enter_hibernation()
5163 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5165 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5169 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5173 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5177 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5179 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5183 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5185 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5189 hsotg->gr_backup.gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5190 dev_dbg(hsotg->dev, "Hibernation completed\n"); in dwc2_gadget_enter_hibernation()
5206 int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg, in dwc2_gadget_exit_hibernation() argument
5216 gr = &hsotg->gr_backup; in dwc2_gadget_exit_hibernation()
5217 dr = &hsotg->dr_backup; in dwc2_gadget_exit_hibernation()
5219 if (!hsotg->hibernated) { in dwc2_gadget_exit_hibernation()
5220 dev_dbg(hsotg->dev, "Already exited from Hibernation\n"); in dwc2_gadget_exit_hibernation()
5223 dev_dbg(hsotg->dev, in dwc2_gadget_exit_hibernation()
5227 dwc2_hib_restore_common(hsotg, rem_wakeup, 0); in dwc2_gadget_exit_hibernation()
5231 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_gadget_exit_hibernation()
5235 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_exit_hibernation()
5237 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_exit_hibernation()
5241 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_gadget_exit_hibernation()
5243 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_gadget_exit_hibernation()
5247 dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); in dwc2_gadget_exit_hibernation()
5248 dwc2_writel(hsotg, dr->dcfg, DCFG); in dwc2_gadget_exit_hibernation()
5249 dwc2_writel(hsotg, dr->dctl, DCTL); in dwc2_gadget_exit_hibernation()
5252 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_exit_hibernation()
5254 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_exit_hibernation()
5259 dwc2_writel(hsotg, dr->dctl | DCTL_RMTWKUPSIG, DCTL); in dwc2_gadget_exit_hibernation()
5263 dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_exit_hibernation()
5265 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_exit_hibernation()
5270 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_gadget_exit_hibernation()
5273 ret = dwc2_restore_global_registers(hsotg); in dwc2_gadget_exit_hibernation()
5275 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_gadget_exit_hibernation()
5281 ret = dwc2_restore_device_registers(hsotg, rem_wakeup); in dwc2_gadget_exit_hibernation()
5283 dev_err(hsotg->dev, "%s: failed to restore device registers\n", in dwc2_gadget_exit_hibernation()
5290 dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_exit_hibernation()
5292 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_exit_hibernation()
5295 hsotg->hibernated = 0; in dwc2_gadget_exit_hibernation()
5296 hsotg->lx_state = DWC2_L0; in dwc2_gadget_exit_hibernation()
5297 dev_dbg(hsotg->dev, "Hibernation recovery completes here\n"); in dwc2_gadget_exit_hibernation()