Lines Matching refs:hsotg

53 static inline void dwc2_set_bit(struct dwc2_hsotg *hsotg, u32 offset, u32 val)  in dwc2_set_bit()  argument
55 dwc2_writel(hsotg, dwc2_readl(hsotg, offset) | val, offset); in dwc2_set_bit()
58 static inline void dwc2_clear_bit(struct dwc2_hsotg *hsotg, u32 offset, u32 val) in dwc2_clear_bit() argument
60 dwc2_writel(hsotg, dwc2_readl(hsotg, offset) & ~val, offset); in dwc2_clear_bit()
63 static inline struct dwc2_hsotg_ep *index_to_ep(struct dwc2_hsotg *hsotg, in index_to_ep() argument
67 return hsotg->eps_in[ep_index]; in index_to_ep()
69 return hsotg->eps_out[ep_index]; in index_to_ep()
73 static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg);
94 static inline bool using_dma(struct dwc2_hsotg *hsotg) in using_dma() argument
96 return hsotg->params.g_dma; in using_dma()
105 static inline bool using_desc_dma(struct dwc2_hsotg *hsotg) in using_desc_dma() argument
107 return hsotg->params.g_dma_desc; in using_desc_dma()
116 static u32 dwc2_hsotg_read_frameno(struct dwc2_hsotg *hsotg) in dwc2_hsotg_read_frameno() argument
120 dsts = dwc2_readl(hsotg, DSTS); in dwc2_hsotg_read_frameno()
136 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_incr_frame_num() local
137 u32 current_frame = dwc2_hsotg_read_frameno(hsotg); in dwc2_gadget_incr_frame_num()
140 if (hsotg->gadget.speed != USB_SPEED_HIGH) in dwc2_gadget_incr_frame_num()
164 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_dec_frame_num_by_one() local
167 if (hsotg->gadget.speed != USB_SPEED_HIGH) in dwc2_gadget_dec_frame_num_by_one()
181 static void dwc2_hsotg_en_gsint(struct dwc2_hsotg *hsotg, u32 ints) in dwc2_hsotg_en_gsint() argument
183 u32 gsintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_en_gsint()
189 dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); in dwc2_hsotg_en_gsint()
190 dwc2_writel(hsotg, new_gsintmsk, GINTMSK); in dwc2_hsotg_en_gsint()
199 static void dwc2_hsotg_disable_gsint(struct dwc2_hsotg *hsotg, u32 ints) in dwc2_hsotg_disable_gsint() argument
201 u32 gsintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_disable_gsint()
207 dwc2_writel(hsotg, new_gsintmsk, GINTMSK); in dwc2_hsotg_disable_gsint()
220 static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg, in dwc2_hsotg_ctrl_epint() argument
232 daint = dwc2_readl(hsotg, DAINTMSK); in dwc2_hsotg_ctrl_epint()
237 dwc2_writel(hsotg, daint, DAINTMSK); in dwc2_hsotg_ctrl_epint()
246 int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg) in dwc2_hsotg_tx_fifo_count() argument
248 if (hsotg->hw_params.en_multiple_tx_fifo) in dwc2_hsotg_tx_fifo_count()
250 return hsotg->hw_params.num_dev_in_eps; in dwc2_hsotg_tx_fifo_count()
253 return hsotg->hw_params.num_dev_perio_in_ep; in dwc2_hsotg_tx_fifo_count()
262 int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg) in dwc2_hsotg_tx_fifo_total_depth() argument
268 np_tx_fifo_size = min_t(u32, hsotg->hw_params.dev_nperio_tx_fifo_size, in dwc2_hsotg_tx_fifo_total_depth()
269 hsotg->params.g_np_tx_fifo_size); in dwc2_hsotg_tx_fifo_total_depth()
272 tx_addr_max = hsotg->hw_params.total_fifo_size; in dwc2_hsotg_tx_fifo_total_depth()
274 addr = hsotg->params.g_rx_fifo_size + np_tx_fifo_size; in dwc2_hsotg_tx_fifo_total_depth()
287 static void dwc2_gadget_wkup_alert_handler(struct dwc2_hsotg *hsotg) in dwc2_gadget_wkup_alert_handler() argument
292 gintsts2 = dwc2_readl(hsotg, GINTSTS2); in dwc2_gadget_wkup_alert_handler()
293 gintmsk2 = dwc2_readl(hsotg, GINTMSK2); in dwc2_gadget_wkup_alert_handler()
297 dev_dbg(hsotg->dev, "%s: Wkup_Alert_Int\n", __func__); in dwc2_gadget_wkup_alert_handler()
298 dwc2_set_bit(hsotg, GINTSTS2, GINTSTS2_WKUP_ALERT_INT); in dwc2_gadget_wkup_alert_handler()
299 dwc2_set_bit(hsotg, DCTL, DCTL_RMTWKUPSIG); in dwc2_gadget_wkup_alert_handler()
309 int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg) in dwc2_hsotg_tx_fifo_average_depth() argument
314 tx_fifo_depth = dwc2_hsotg_tx_fifo_total_depth(hsotg); in dwc2_hsotg_tx_fifo_average_depth()
316 tx_fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); in dwc2_hsotg_tx_fifo_average_depth()
328 static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) in dwc2_hsotg_init_fifo() argument
335 u32 *txfsz = hsotg->params.g_tx_fifo_size; in dwc2_hsotg_init_fifo()
338 WARN_ON(hsotg->fifo_map); in dwc2_hsotg_init_fifo()
339 hsotg->fifo_map = 0; in dwc2_hsotg_init_fifo()
342 dwc2_writel(hsotg, hsotg->params.g_rx_fifo_size, GRXFSIZ); in dwc2_hsotg_init_fifo()
343 dwc2_writel(hsotg, (hsotg->params.g_rx_fifo_size << in dwc2_hsotg_init_fifo()
345 (hsotg->params.g_np_tx_fifo_size << FIFOSIZE_DEPTH_SHIFT), in dwc2_hsotg_init_fifo()
356 addr = hsotg->params.g_rx_fifo_size + hsotg->params.g_np_tx_fifo_size; in dwc2_hsotg_init_fifo()
368 WARN_ONCE(addr + txfsz[ep] > hsotg->fifo_mem, in dwc2_hsotg_init_fifo()
372 dwc2_writel(hsotg, val, DPTXFSIZN(ep)); in dwc2_hsotg_init_fifo()
373 val = dwc2_readl(hsotg, DPTXFSIZN(ep)); in dwc2_hsotg_init_fifo()
376 dwc2_writel(hsotg, hsotg->hw_params.total_fifo_size | in dwc2_hsotg_init_fifo()
384 dwc2_writel(hsotg, GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH | in dwc2_hsotg_init_fifo()
390 val = dwc2_readl(hsotg, GRSTCTL); in dwc2_hsotg_init_fifo()
396 dev_err(hsotg->dev, in dwc2_hsotg_init_fifo()
405 dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout); in dwc2_hsotg_init_fifo()
450 static void dwc2_hsotg_unmap_dma(struct dwc2_hsotg *hsotg, in dwc2_hsotg_unmap_dma() argument
456 usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->map_dir); in dwc2_hsotg_unmap_dma()
467 static int dwc2_gadget_alloc_ctrl_desc_chains(struct dwc2_hsotg *hsotg) in dwc2_gadget_alloc_ctrl_desc_chains() argument
469 hsotg->setup_desc[0] = in dwc2_gadget_alloc_ctrl_desc_chains()
470 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
472 &hsotg->setup_desc_dma[0], in dwc2_gadget_alloc_ctrl_desc_chains()
474 if (!hsotg->setup_desc[0]) in dwc2_gadget_alloc_ctrl_desc_chains()
477 hsotg->setup_desc[1] = in dwc2_gadget_alloc_ctrl_desc_chains()
478 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
480 &hsotg->setup_desc_dma[1], in dwc2_gadget_alloc_ctrl_desc_chains()
482 if (!hsotg->setup_desc[1]) in dwc2_gadget_alloc_ctrl_desc_chains()
485 hsotg->ctrl_in_desc = in dwc2_gadget_alloc_ctrl_desc_chains()
486 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
488 &hsotg->ctrl_in_desc_dma, in dwc2_gadget_alloc_ctrl_desc_chains()
490 if (!hsotg->ctrl_in_desc) in dwc2_gadget_alloc_ctrl_desc_chains()
493 hsotg->ctrl_out_desc = in dwc2_gadget_alloc_ctrl_desc_chains()
494 dmam_alloc_coherent(hsotg->dev, in dwc2_gadget_alloc_ctrl_desc_chains()
496 &hsotg->ctrl_out_desc_dma, in dwc2_gadget_alloc_ctrl_desc_chains()
498 if (!hsotg->ctrl_out_desc) in dwc2_gadget_alloc_ctrl_desc_chains()
523 static int dwc2_hsotg_write_fifo(struct dwc2_hsotg *hsotg, in dwc2_hsotg_write_fifo() argument
528 u32 gnptxsts = dwc2_readl(hsotg, GNPTXSTS); in dwc2_hsotg_write_fifo()
542 if (periodic && !hsotg->dedicated_fifos) { in dwc2_hsotg_write_fifo()
543 u32 epsize = dwc2_readl(hsotg, DIEPTSIZ(hs_ep->index)); in dwc2_hsotg_write_fifo()
559 dwc2_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_write_fifo()
563 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", in dwc2_hsotg_write_fifo()
572 dev_dbg(hsotg->dev, "%s: => can_write1=%d\n", in dwc2_hsotg_write_fifo()
576 dev_dbg(hsotg->dev, "%s: => can_write2=%d\n", in dwc2_hsotg_write_fifo()
580 dwc2_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_write_fifo()
583 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { in dwc2_hsotg_write_fifo()
584 can_write = dwc2_readl(hsotg, in dwc2_hsotg_write_fifo()
591 dev_dbg(hsotg->dev, in dwc2_hsotg_write_fifo()
595 dwc2_hsotg_en_gsint(hsotg, GINTSTS_NPTXFEMP); in dwc2_hsotg_write_fifo()
605 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", in dwc2_hsotg_write_fifo()
625 if (!hsotg->dedicated_fifos) in dwc2_hsotg_write_fifo()
626 dwc2_hsotg_en_gsint(hsotg, in dwc2_hsotg_write_fifo()
654 if (!hsotg->dedicated_fifos) in dwc2_hsotg_write_fifo()
655 dwc2_hsotg_en_gsint(hsotg, in dwc2_hsotg_write_fifo()
660 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", in dwc2_hsotg_write_fifo()
675 dwc2_writel_rep(hsotg, EPFIFO(hs_ep->index), data, to_write); in dwc2_hsotg_write_fifo()
916 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_fill_isoc_desc() local
929 dev_dbg(hsotg->dev, "%s: desc chain full\n", __func__); in dwc2_gadget_fill_isoc_desc()
937 dev_dbg(hsotg->dev, "%s: Filling ep %d, dir %s isoc desc # %d\n", in dwc2_gadget_fill_isoc_desc()
985 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_start_isoc_ddma() local
997 dev_dbg(hsotg->dev, "%s: No requests in queue\n", __func__); in dwc2_gadget_start_isoc_ddma()
1028 dwc2_writel(hsotg, hs_ep->desc_list_dma, dma_reg); in dwc2_gadget_start_isoc_ddma()
1030 ctrl = dwc2_readl(hsotg, depctl); in dwc2_gadget_start_isoc_ddma()
1032 dwc2_writel(hsotg, ctrl, depctl); in dwc2_gadget_start_isoc_ddma()
1036 static void dwc2_hsotg_complete_request(struct dwc2_hsotg *hsotg,
1051 static void dwc2_hsotg_start_req(struct dwc2_hsotg *hsotg, in dwc2_hsotg_start_req() argument
1070 dev_err(hsotg->dev, "%s: active request\n", __func__); in dwc2_hsotg_start_req()
1074 dev_err(hsotg->dev, in dwc2_hsotg_start_req()
1085 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", in dwc2_hsotg_start_req()
1086 __func__, dwc2_readl(hsotg, epctrl_reg), index, in dwc2_hsotg_start_req()
1090 ctrl = dwc2_readl(hsotg, epctrl_reg); in dwc2_hsotg_start_req()
1093 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); in dwc2_hsotg_start_req()
1098 dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n", in dwc2_hsotg_start_req()
1101 if (!using_desc_dma(hsotg)) in dwc2_hsotg_start_req()
1109 dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n", in dwc2_hsotg_start_req()
1146 dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", in dwc2_hsotg_start_req()
1152 if (using_desc_dma(hsotg)) { in dwc2_hsotg_start_req()
1172 dwc2_writel(hsotg, hs_ep->desc_list_dma, dma_reg); in dwc2_hsotg_start_req()
1174 dev_dbg(hsotg->dev, "%s: %08x pad => 0x%08x\n", in dwc2_hsotg_start_req()
1178 dwc2_writel(hsotg, epsize, epsize_reg); in dwc2_hsotg_start_req()
1180 if (using_dma(hsotg) && !continuing && (length != 0)) { in dwc2_hsotg_start_req()
1186 dwc2_writel(hsotg, ureq->dma, dma_reg); in dwc2_hsotg_start_req()
1188 dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", in dwc2_hsotg_start_req()
1205 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, -ENODATA); in dwc2_hsotg_start_req()
1212 dev_dbg(hsotg->dev, "ep0 state:%d\n", hsotg->ep0_state); in dwc2_hsotg_start_req()
1215 if (!(index == 0 && hsotg->ep0_state == DWC2_EP0_SETUP)) in dwc2_hsotg_start_req()
1218 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in dwc2_hsotg_start_req()
1219 dwc2_writel(hsotg, ctrl, epctrl_reg); in dwc2_hsotg_start_req()
1229 if (dir_in && !using_dma(hsotg)) { in dwc2_hsotg_start_req()
1233 dwc2_hsotg_write_fifo(hsotg, hs_ep, hs_req); in dwc2_hsotg_start_req()
1242 if (!(dwc2_readl(hsotg, epctrl_reg) & DXEPCTL_EPENA)) in dwc2_hsotg_start_req()
1243 dev_dbg(hsotg->dev, in dwc2_hsotg_start_req()
1245 index, dwc2_readl(hsotg, epctrl_reg)); in dwc2_hsotg_start_req()
1247 dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", in dwc2_hsotg_start_req()
1248 __func__, dwc2_readl(hsotg, epctrl_reg)); in dwc2_hsotg_start_req()
1251 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); in dwc2_hsotg_start_req()
1266 static int dwc2_hsotg_map_dma(struct dwc2_hsotg *hsotg, in dwc2_hsotg_map_dma() argument
1273 ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); in dwc2_hsotg_map_dma()
1280 dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n", in dwc2_hsotg_map_dma()
1286 static int dwc2_hsotg_handle_unaligned_buf_start(struct dwc2_hsotg *hsotg, in dwc2_hsotg_handle_unaligned_buf_start() argument
1293 if (!using_dma(hsotg) || !((long)req_buf & 3)) in dwc2_hsotg_handle_unaligned_buf_start()
1298 dev_dbg(hsotg->dev, "%s: %s: buf=%p length=%d\n", __func__, in dwc2_hsotg_handle_unaligned_buf_start()
1304 dev_err(hsotg->dev, in dwc2_hsotg_handle_unaligned_buf_start()
1319 dwc2_hsotg_handle_unaligned_buf_complete(struct dwc2_hsotg *hsotg, in dwc2_hsotg_handle_unaligned_buf_complete() argument
1324 if (!using_dma(hsotg) || !hs_req->saved_req_buf) in dwc2_hsotg_handle_unaligned_buf_complete()
1327 dev_dbg(hsotg->dev, "%s: %s: status=%d actual-length=%d\n", __func__, in dwc2_hsotg_handle_unaligned_buf_complete()
1351 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_target_frame_elapsed() local
1353 u32 current_frame = hsotg->frame_number; in dwc2_gadget_target_frame_elapsed()
1357 if (hsotg->gadget.speed != USB_SPEED_HIGH) in dwc2_gadget_target_frame_elapsed()
1378 static int dwc2_gadget_set_ep0_desc_chain(struct dwc2_hsotg *hsotg, in dwc2_gadget_set_ep0_desc_chain() argument
1381 switch (hsotg->ep0_state) { in dwc2_gadget_set_ep0_desc_chain()
1384 hs_ep->desc_list = hsotg->setup_desc[0]; in dwc2_gadget_set_ep0_desc_chain()
1385 hs_ep->desc_list_dma = hsotg->setup_desc_dma[0]; in dwc2_gadget_set_ep0_desc_chain()
1389 hs_ep->desc_list = hsotg->ctrl_in_desc; in dwc2_gadget_set_ep0_desc_chain()
1390 hs_ep->desc_list_dma = hsotg->ctrl_in_desc_dma; in dwc2_gadget_set_ep0_desc_chain()
1393 hs_ep->desc_list = hsotg->ctrl_out_desc; in dwc2_gadget_set_ep0_desc_chain()
1394 hs_ep->desc_list_dma = hsotg->ctrl_out_desc_dma; in dwc2_gadget_set_ep0_desc_chain()
1397 dev_err(hsotg->dev, "invalid EP 0 state in queue %d\n", in dwc2_gadget_set_ep0_desc_chain()
1398 hsotg->ep0_state); in dwc2_gadget_set_ep0_desc_chain()
1576 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_complete_oursetup() local
1578 dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); in dwc2_hsotg_complete_oursetup()
1591 static struct dwc2_hsotg_ep *ep_from_windex(struct dwc2_hsotg *hsotg, in ep_from_windex() argument
1600 if (idx > hsotg->num_of_eps) in ep_from_windex()
1603 return index_to_ep(hsotg, idx, dir); in ep_from_windex()
1612 int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode) in dwc2_hsotg_set_test_mode() argument
1614 int dctl = dwc2_readl(hsotg, DCTL); in dwc2_hsotg_set_test_mode()
1628 dwc2_writel(hsotg, dctl, DCTL); in dwc2_hsotg_set_test_mode()
1642 static int dwc2_hsotg_send_reply(struct dwc2_hsotg *hsotg, in dwc2_hsotg_send_reply() argument
1650 dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length); in dwc2_hsotg_send_reply()
1653 hsotg->ep0_reply = req; in dwc2_hsotg_send_reply()
1655 dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__); in dwc2_hsotg_send_reply()
1659 req->buf = hsotg->ep0_buff; in dwc2_hsotg_send_reply()
1673 dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__); in dwc2_hsotg_send_reply()
1685 static int dwc2_hsotg_process_req_status(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_req_status() argument
1688 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_req_status()
1694 dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__); in dwc2_hsotg_process_req_status()
1697 dev_warn(hsotg->dev, "%s: direction out?\n", __func__); in dwc2_hsotg_process_req_status()
1703 status = hsotg->gadget.is_selfpowered << in dwc2_hsotg_process_req_status()
1705 status |= hsotg->remote_wakeup_allowed << in dwc2_hsotg_process_req_status()
1716 ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); in dwc2_hsotg_process_req_status()
1730 ret = dwc2_hsotg_send_reply(hsotg, ep0, &reply, 2); in dwc2_hsotg_process_req_status()
1732 dev_err(hsotg->dev, "%s: failed to send reply\n", __func__); in dwc2_hsotg_process_req_status()
1763 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_start_next_request() local
1769 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, false); in dwc2_gadget_start_next_request()
1776 dev_dbg(hsotg->dev, "%s: No more ISOC-IN requests\n", in dwc2_gadget_start_next_request()
1779 dev_dbg(hsotg->dev, "%s: No more ISOC-OUT requests\n", in dwc2_gadget_start_next_request()
1789 static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_req_feature() argument
1792 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_req_feature()
1802 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", in dwc2_hsotg_process_req_feature()
1814 hsotg->remote_wakeup_allowed = 1; in dwc2_hsotg_process_req_feature()
1816 hsotg->remote_wakeup_allowed = 0; in dwc2_hsotg_process_req_feature()
1825 hsotg->test_mode = wIndex >> 8; in dwc2_hsotg_process_req_feature()
1831 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_req_feature()
1833 dev_err(hsotg->dev, in dwc2_hsotg_process_req_feature()
1840 ep = ep_from_windex(hsotg, wIndex); in dwc2_hsotg_process_req_feature()
1842 dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n", in dwc2_hsotg_process_req_feature()
1853 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_req_feature()
1855 dev_err(hsotg->dev, in dwc2_hsotg_process_req_feature()
1875 spin_unlock(&hsotg->lock); in dwc2_hsotg_process_req_feature()
1878 spin_lock(&hsotg->lock); in dwc2_hsotg_process_req_feature()
1899 static void dwc2_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg);
1907 static void dwc2_hsotg_stall_ep0(struct dwc2_hsotg *hsotg) in dwc2_hsotg_stall_ep0() argument
1909 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_stall_ep0()
1913 dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); in dwc2_hsotg_stall_ep0()
1921 ctrl = dwc2_readl(hsotg, reg); in dwc2_hsotg_stall_ep0()
1924 dwc2_writel(hsotg, ctrl, reg); in dwc2_hsotg_stall_ep0()
1926 dev_dbg(hsotg->dev, in dwc2_hsotg_stall_ep0()
1928 ctrl, reg, dwc2_readl(hsotg, reg)); in dwc2_hsotg_stall_ep0()
1934 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_stall_ep0()
1946 static void dwc2_hsotg_process_control(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_control() argument
1949 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_control()
1953 dev_dbg(hsotg->dev, in dwc2_hsotg_process_control()
1960 hsotg->ep0_state = DWC2_EP0_STATUS_IN; in dwc2_hsotg_process_control()
1963 hsotg->ep0_state = DWC2_EP0_DATA_IN; in dwc2_hsotg_process_control()
1966 hsotg->ep0_state = DWC2_EP0_DATA_OUT; in dwc2_hsotg_process_control()
1972 hsotg->connected = 1; in dwc2_hsotg_process_control()
1973 dcfg = dwc2_readl(hsotg, DCFG); in dwc2_hsotg_process_control()
1977 dwc2_writel(hsotg, dcfg, DCFG); in dwc2_hsotg_process_control()
1979 dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); in dwc2_hsotg_process_control()
1981 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_control()
1985 ret = dwc2_hsotg_process_req_status(hsotg, ctrl); in dwc2_hsotg_process_control()
1990 ret = dwc2_hsotg_process_req_feature(hsotg, ctrl); in dwc2_hsotg_process_control()
1997 if (ret == 0 && hsotg->driver) { in dwc2_hsotg_process_control()
1998 spin_unlock(&hsotg->lock); in dwc2_hsotg_process_control()
1999 ret = hsotg->driver->setup(&hsotg->gadget, ctrl); in dwc2_hsotg_process_control()
2000 spin_lock(&hsotg->lock); in dwc2_hsotg_process_control()
2002 dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); in dwc2_hsotg_process_control()
2005 hsotg->delayed_status = false; in dwc2_hsotg_process_control()
2007 hsotg->delayed_status = true; in dwc2_hsotg_process_control()
2015 dwc2_hsotg_stall_ep0(hsotg); in dwc2_hsotg_process_control()
2030 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_complete_setup() local
2033 dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); in dwc2_hsotg_complete_setup()
2037 spin_lock(&hsotg->lock); in dwc2_hsotg_complete_setup()
2039 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_complete_setup()
2041 dwc2_hsotg_process_control(hsotg, req->buf); in dwc2_hsotg_complete_setup()
2042 spin_unlock(&hsotg->lock); in dwc2_hsotg_complete_setup()
2052 static void dwc2_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg) in dwc2_hsotg_enqueue_setup() argument
2054 struct usb_request *req = hsotg->ctrl_req; in dwc2_hsotg_enqueue_setup()
2058 dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__); in dwc2_hsotg_enqueue_setup()
2062 req->buf = hsotg->ctrl_buff; in dwc2_hsotg_enqueue_setup()
2066 dev_dbg(hsotg->dev, "%s already queued???\n", __func__); in dwc2_hsotg_enqueue_setup()
2070 hsotg->eps_out[0]->dir_in = 0; in dwc2_hsotg_enqueue_setup()
2071 hsotg->eps_out[0]->send_zlp = 0; in dwc2_hsotg_enqueue_setup()
2072 hsotg->ep0_state = DWC2_EP0_SETUP; in dwc2_hsotg_enqueue_setup()
2074 ret = dwc2_hsotg_ep_queue(&hsotg->eps_out[0]->ep, req, GFP_ATOMIC); in dwc2_hsotg_enqueue_setup()
2076 dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); in dwc2_hsotg_enqueue_setup()
2084 static void dwc2_hsotg_program_zlp(struct dwc2_hsotg *hsotg, in dwc2_hsotg_program_zlp() argument
2093 dev_dbg(hsotg->dev, "Sending zero-length packet on ep%d\n", in dwc2_hsotg_program_zlp()
2096 dev_dbg(hsotg->dev, "Receiving zero-length packet on ep%d\n", in dwc2_hsotg_program_zlp()
2098 if (using_desc_dma(hsotg)) { in dwc2_hsotg_program_zlp()
2103 dwc2_gadget_set_ep0_desc_chain(hsotg, hs_ep); in dwc2_hsotg_program_zlp()
2107 dwc2_writel(hsotg, DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | in dwc2_hsotg_program_zlp()
2112 ctrl = dwc2_readl(hsotg, epctl_reg); in dwc2_hsotg_program_zlp()
2116 dwc2_writel(hsotg, ctrl, epctl_reg); in dwc2_hsotg_program_zlp()
2132 static void dwc2_hsotg_complete_request(struct dwc2_hsotg *hsotg, in dwc2_hsotg_complete_request() argument
2138 dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); in dwc2_hsotg_complete_request()
2142 dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", in dwc2_hsotg_complete_request()
2153 if (using_dma(hsotg)) in dwc2_hsotg_complete_request()
2154 dwc2_hsotg_unmap_dma(hsotg, hs_ep, hs_req); in dwc2_hsotg_complete_request()
2156 dwc2_hsotg_handle_unaligned_buf_complete(hsotg, hs_ep, hs_req); in dwc2_hsotg_complete_request()
2167 spin_unlock(&hsotg->lock); in dwc2_hsotg_complete_request()
2169 spin_lock(&hsotg->lock); in dwc2_hsotg_complete_request()
2173 if (using_desc_dma(hsotg) && hs_ep->isochronous) in dwc2_hsotg_complete_request()
2197 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_complete_isoc_request_ddma() local
2211 dev_warn(hsotg->dev, "%s: ISOC EP queue empty\n", __func__); in dwc2_gadget_complete_isoc_request_ddma()
2236 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_gadget_complete_isoc_request_ddma()
2256 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_handle_isoc_bna() local
2259 dwc2_flush_rx_fifo(hsotg); in dwc2_gadget_handle_isoc_bna()
2260 dwc2_hsotg_complete_request(hsotg, hs_ep, get_ep_head(hs_ep), 0); in dwc2_gadget_handle_isoc_bna()
2277 static void dwc2_hsotg_rx_data(struct dwc2_hsotg *hsotg, int ep_idx, int size) in dwc2_hsotg_rx_data() argument
2279 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[ep_idx]; in dwc2_hsotg_rx_data()
2286 u32 epctl = dwc2_readl(hsotg, DOEPCTL(ep_idx)); in dwc2_hsotg_rx_data()
2289 dev_dbg(hsotg->dev, in dwc2_hsotg_rx_data()
2295 (void)dwc2_readl(hsotg, EPFIFO(ep_idx)); in dwc2_hsotg_rx_data()
2304 dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", in dwc2_hsotg_rx_data()
2325 dwc2_readl_rep(hsotg, EPFIFO(ep_idx), in dwc2_hsotg_rx_data()
2341 static void dwc2_hsotg_ep0_zlp(struct dwc2_hsotg *hsotg, bool dir_in) in dwc2_hsotg_ep0_zlp() argument
2344 hsotg->eps_out[0]->dir_in = dir_in; in dwc2_hsotg_ep0_zlp()
2345 hsotg->ep0_state = dir_in ? DWC2_EP0_STATUS_IN : DWC2_EP0_STATUS_OUT; in dwc2_hsotg_ep0_zlp()
2347 dwc2_hsotg_program_zlp(hsotg, hsotg->eps_out[0]); in dwc2_hsotg_ep0_zlp()
2360 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_get_xfersize_ddma() local
2383 dev_err(hsotg->dev, "descriptor %d closed with %x\n", in dwc2_gadget_get_xfersize_ddma()
2404 static void dwc2_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, int epnum) in dwc2_hsotg_handle_outdone() argument
2406 u32 epsize = dwc2_readl(hsotg, DOEPTSIZ(epnum)); in dwc2_hsotg_handle_outdone()
2407 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[epnum]; in dwc2_hsotg_handle_outdone()
2414 dev_dbg(hsotg->dev, "%s: no request active\n", __func__); in dwc2_hsotg_handle_outdone()
2418 if (epnum == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_OUT) { in dwc2_hsotg_handle_outdone()
2419 dev_dbg(hsotg->dev, "zlp packet received\n"); in dwc2_hsotg_handle_outdone()
2420 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_handle_outdone()
2421 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_handle_outdone()
2425 if (using_desc_dma(hsotg)) in dwc2_hsotg_handle_outdone()
2428 if (using_dma(hsotg)) { in dwc2_hsotg_handle_outdone()
2448 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, true); in dwc2_hsotg_handle_outdone()
2453 dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", in dwc2_hsotg_handle_outdone()
2463 if (!using_desc_dma(hsotg) && epnum == 0 && in dwc2_hsotg_handle_outdone()
2464 hsotg->ep0_state == DWC2_EP0_DATA_OUT) { in dwc2_hsotg_handle_outdone()
2466 if (!hsotg->delayed_status) in dwc2_hsotg_handle_outdone()
2467 dwc2_hsotg_ep0_zlp(hsotg, true); in dwc2_hsotg_handle_outdone()
2471 if (!using_desc_dma(hsotg) && hs_ep->isochronous) { in dwc2_hsotg_handle_outdone()
2476 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, result); in dwc2_hsotg_handle_outdone()
2495 static void dwc2_hsotg_handle_rx(struct dwc2_hsotg *hsotg) in dwc2_hsotg_handle_rx() argument
2497 u32 grxstsr = dwc2_readl(hsotg, GRXSTSP); in dwc2_hsotg_handle_rx()
2500 WARN_ON(using_dma(hsotg)); in dwc2_hsotg_handle_rx()
2508 dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", in dwc2_hsotg_handle_rx()
2513 dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); in dwc2_hsotg_handle_rx()
2517 dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", in dwc2_hsotg_handle_rx()
2518 dwc2_hsotg_read_frameno(hsotg)); in dwc2_hsotg_handle_rx()
2520 if (!using_dma(hsotg)) in dwc2_hsotg_handle_rx()
2521 dwc2_hsotg_handle_outdone(hsotg, epnum); in dwc2_hsotg_handle_rx()
2525 dev_dbg(hsotg->dev, in dwc2_hsotg_handle_rx()
2527 dwc2_hsotg_read_frameno(hsotg), in dwc2_hsotg_handle_rx()
2528 dwc2_readl(hsotg, DOEPCTL(0))); in dwc2_hsotg_handle_rx()
2534 if (hsotg->ep0_state == DWC2_EP0_SETUP) in dwc2_hsotg_handle_rx()
2535 dwc2_hsotg_handle_outdone(hsotg, epnum); in dwc2_hsotg_handle_rx()
2539 dwc2_hsotg_rx_data(hsotg, epnum, size); in dwc2_hsotg_handle_rx()
2543 dev_dbg(hsotg->dev, in dwc2_hsotg_handle_rx()
2545 dwc2_hsotg_read_frameno(hsotg), in dwc2_hsotg_handle_rx()
2546 dwc2_readl(hsotg, DOEPCTL(0))); in dwc2_hsotg_handle_rx()
2548 WARN_ON(hsotg->ep0_state != DWC2_EP0_SETUP); in dwc2_hsotg_handle_rx()
2550 dwc2_hsotg_rx_data(hsotg, epnum, size); in dwc2_hsotg_handle_rx()
2554 dev_warn(hsotg->dev, "%s: unknown status %08x\n", in dwc2_hsotg_handle_rx()
2557 dwc2_hsotg_dump(hsotg); in dwc2_hsotg_handle_rx()
2595 static void dwc2_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg, in dwc2_hsotg_set_ep_maxpacket() argument
2602 hs_ep = index_to_ep(hsotg, ep, dir_in); in dwc2_hsotg_set_ep_maxpacket()
2625 reg = dwc2_readl(hsotg, DIEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2628 dwc2_writel(hsotg, reg, DIEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2630 reg = dwc2_readl(hsotg, DOEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2633 dwc2_writel(hsotg, reg, DOEPCTL(ep)); in dwc2_hsotg_set_ep_maxpacket()
2639 dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); in dwc2_hsotg_set_ep_maxpacket()
2647 static void dwc2_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx) in dwc2_hsotg_txfifo_flush() argument
2649 dwc2_writel(hsotg, GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, in dwc2_hsotg_txfifo_flush()
2653 if (dwc2_hsotg_wait_bit_clear(hsotg, GRSTCTL, GRSTCTL_TXFFLSH, 100)) in dwc2_hsotg_txfifo_flush()
2654 dev_warn(hsotg->dev, "%s: timeout flushing fifo GRSTCTL_TXFFLSH\n", in dwc2_hsotg_txfifo_flush()
2666 static int dwc2_hsotg_trytx(struct dwc2_hsotg *hsotg, in dwc2_hsotg_trytx() argument
2677 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, in dwc2_hsotg_trytx()
2683 dev_dbg(hsotg->dev, "trying to write more for ep%d\n", in dwc2_hsotg_trytx()
2685 return dwc2_hsotg_write_fifo(hsotg, hs_ep, hs_req); in dwc2_hsotg_trytx()
2699 static void dwc2_hsotg_complete_in(struct dwc2_hsotg *hsotg, in dwc2_hsotg_complete_in() argument
2703 u32 epsize = dwc2_readl(hsotg, DIEPTSIZ(hs_ep->index)); in dwc2_hsotg_complete_in()
2707 dev_dbg(hsotg->dev, "XferCompl but no req\n"); in dwc2_hsotg_complete_in()
2712 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_IN) { in dwc2_hsotg_complete_in()
2713 dev_dbg(hsotg->dev, "zlp packet sent\n"); in dwc2_hsotg_complete_in()
2721 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_complete_in()
2722 if (hsotg->test_mode) { in dwc2_hsotg_complete_in()
2725 ret = dwc2_hsotg_set_test_mode(hsotg, hsotg->test_mode); in dwc2_hsotg_complete_in()
2727 dev_dbg(hsotg->dev, "Invalid Test #%d\n", in dwc2_hsotg_complete_in()
2728 hsotg->test_mode); in dwc2_hsotg_complete_in()
2729 dwc2_hsotg_stall_ep0(hsotg); in dwc2_hsotg_complete_in()
2733 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_complete_in()
2746 if (using_desc_dma(hsotg)) { in dwc2_hsotg_complete_in()
2749 dev_err(hsotg->dev, "error parsing DDMA results %d\n", in dwc2_hsotg_complete_in()
2759 dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n", in dwc2_hsotg_complete_in()
2763 dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", in dwc2_hsotg_complete_in()
2767 dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); in dwc2_hsotg_complete_in()
2768 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, true); in dwc2_hsotg_complete_in()
2775 if (!using_desc_dma(hsotg)) { in dwc2_hsotg_complete_in()
2776 dwc2_hsotg_program_zlp(hsotg, hs_ep); in dwc2_hsotg_complete_in()
2782 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_DATA_IN) { in dwc2_hsotg_complete_in()
2784 dwc2_hsotg_ep0_zlp(hsotg, false); in dwc2_hsotg_complete_in()
2789 if (!using_desc_dma(hsotg) && hs_ep->isochronous) { in dwc2_hsotg_complete_in()
2794 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_complete_in()
2806 static u32 dwc2_gadget_read_ep_interrupts(struct dwc2_hsotg *hsotg, in dwc2_gadget_read_ep_interrupts() argument
2815 mask = dwc2_readl(hsotg, epmsk_reg); in dwc2_gadget_read_ep_interrupts()
2816 diepempmsk = dwc2_readl(hsotg, DIEPEMPMSK); in dwc2_gadget_read_ep_interrupts()
2820 ints = dwc2_readl(hsotg, epint_reg); in dwc2_gadget_read_ep_interrupts()
2840 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_handle_ep_disabled() local
2845 int dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_handle_ep_disabled()
2847 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); in dwc2_gadget_handle_ep_disabled()
2850 int epctl = dwc2_readl(hsotg, epctl_reg); in dwc2_gadget_handle_ep_disabled()
2852 dwc2_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); in dwc2_gadget_handle_ep_disabled()
2855 int dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_handle_ep_disabled()
2858 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_handle_ep_disabled()
2864 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_handle_ep_disabled()
2872 dev_dbg(hsotg->dev, "%s: complete_ep 0x%p, ep->queue empty!\n", in dwc2_gadget_handle_ep_disabled()
2882 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, in dwc2_gadget_handle_ep_disabled()
2887 hsotg->frame_number = dwc2_hsotg_read_frameno(hsotg); in dwc2_gadget_handle_ep_disabled()
2904 struct dwc2_hsotg *hsotg = ep->parent; in dwc2_gadget_handle_out_token_ep_disabled() local
2911 if (using_desc_dma(hsotg)) { in dwc2_gadget_handle_out_token_ep_disabled()
2914 ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_out_token_ep_disabled()
2923 ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_out_token_ep_disabled()
2925 ctrl = dwc2_readl(hsotg, DOEPCTL(ep->index)); in dwc2_gadget_handle_out_token_ep_disabled()
2931 dwc2_writel(hsotg, ctrl, DOEPCTL(ep->index)); in dwc2_gadget_handle_out_token_ep_disabled()
2940 dwc2_hsotg_complete_request(hsotg, ep, hs_req, -ENODATA); in dwc2_gadget_handle_out_token_ep_disabled()
2945 hsotg->frame_number = dwc2_hsotg_read_frameno(hsotg); in dwc2_gadget_handle_out_token_ep_disabled()
2953 static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg,
2972 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_gadget_handle_nak() local
2982 if (using_desc_dma(hsotg)) { in dwc2_gadget_handle_nak()
2983 hs_ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_nak()
2989 if (hsotg->params.service_interval) { in dwc2_gadget_handle_nak()
3006 hs_ep->target_frame = hsotg->frame_number; in dwc2_gadget_handle_nak()
3018 if (!(dwc2_readl(hsotg, GHWCFG2) & in dwc2_gadget_handle_nak()
3020 mask = dwc2_readl(hsotg, DIEPMSK); in dwc2_gadget_handle_nak()
3022 dwc2_writel(hsotg, mask, DIEPMSK); in dwc2_gadget_handle_nak()
3025 ctrl = dwc2_readl(hsotg, in dwc2_gadget_handle_nak()
3032 dwc2_writel(hsotg, ctrl, DIEPCTL(hs_ep->index)); in dwc2_gadget_handle_nak()
3036 if (using_desc_dma(hsotg)) in dwc2_gadget_handle_nak()
3039 ctrl = dwc2_readl(hsotg, DIEPCTL(hs_ep->index)); in dwc2_gadget_handle_nak()
3041 dwc2_hsotg_ep_stop_xfr(hsotg, hs_ep); in dwc2_gadget_handle_nak()
3043 dwc2_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); in dwc2_gadget_handle_nak()
3050 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, -ENODATA); in dwc2_gadget_handle_nak()
3055 hsotg->frame_number = dwc2_hsotg_read_frameno(hsotg); in dwc2_gadget_handle_nak()
3070 static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, in dwc2_hsotg_epint() argument
3073 struct dwc2_hsotg_ep *hs_ep = index_to_ep(hsotg, idx, dir_in); in dwc2_hsotg_epint()
3079 ints = dwc2_gadget_read_ep_interrupts(hsotg, idx, dir_in); in dwc2_hsotg_epint()
3082 dwc2_writel(hsotg, ints, epint_reg); in dwc2_hsotg_epint()
3085 dev_err(hsotg->dev, "%s:Interrupt for unconfigured ep%d(%s)\n", in dwc2_hsotg_epint()
3090 dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", in dwc2_hsotg_epint()
3103 if (using_desc_dma(hsotg) && idx == 0 && !hs_ep->dir_in && in dwc2_hsotg_epint()
3104 hsotg->ep0_state == DWC2_EP0_SETUP && !(ints & DXEPINT_SETUP)) in dwc2_hsotg_epint()
3108 dev_dbg(hsotg->dev, in dwc2_hsotg_epint()
3110 __func__, dwc2_readl(hsotg, epctl_reg), in dwc2_hsotg_epint()
3111 dwc2_readl(hsotg, epsiz_reg)); in dwc2_hsotg_epint()
3114 if (using_desc_dma(hsotg) && hs_ep->isochronous) { in dwc2_hsotg_epint()
3123 dwc2_hsotg_complete_in(hsotg, hs_ep); in dwc2_hsotg_epint()
3126 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_epint()
3127 } else if (using_dma(hsotg)) { in dwc2_hsotg_epint()
3133 dwc2_hsotg_handle_outdone(hsotg, idx); in dwc2_hsotg_epint()
3147 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); in dwc2_hsotg_epint()
3150 dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); in dwc2_hsotg_epint()
3152 if (using_dma(hsotg) && idx == 0) { in dwc2_hsotg_epint()
3163 dwc2_hsotg_handle_outdone(hsotg, 0); in dwc2_hsotg_epint()
3168 dev_dbg(hsotg->dev, "%s: StsPhseRcvd\n", __func__); in dwc2_hsotg_epint()
3171 if (hsotg->ep0_state == DWC2_EP0_DATA_OUT) { in dwc2_hsotg_epint()
3173 if (using_desc_dma(hsotg)) { in dwc2_hsotg_epint()
3174 if (!hsotg->delayed_status) in dwc2_hsotg_epint()
3175 dwc2_hsotg_ep0_zlp(hsotg, true); in dwc2_hsotg_epint()
3184 dwc2_set_bit(hsotg, DIEPCTL(0), in dwc2_hsotg_epint()
3192 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); in dwc2_hsotg_epint()
3195 dev_dbg(hsotg->dev, "%s: BNA interrupt\n", __func__); in dwc2_hsotg_epint()
3203 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", in dwc2_hsotg_epint()
3209 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", in dwc2_hsotg_epint()
3214 if (hsotg->dedicated_fifos && in dwc2_hsotg_epint()
3216 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", in dwc2_hsotg_epint()
3218 if (!using_dma(hsotg)) in dwc2_hsotg_epint()
3219 dwc2_hsotg_trytx(hsotg, hs_ep); in dwc2_hsotg_epint()
3231 static void dwc2_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) in dwc2_hsotg_irq_enumdone() argument
3233 u32 dsts = dwc2_readl(hsotg, DSTS); in dwc2_hsotg_irq_enumdone()
3242 dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); in dwc2_hsotg_irq_enumdone()
3254 hsotg->gadget.speed = USB_SPEED_FULL; in dwc2_hsotg_irq_enumdone()
3260 hsotg->gadget.speed = USB_SPEED_HIGH; in dwc2_hsotg_irq_enumdone()
3266 hsotg->gadget.speed = USB_SPEED_LOW; in dwc2_hsotg_irq_enumdone()
3276 dev_info(hsotg->dev, "new device is %s\n", in dwc2_hsotg_irq_enumdone()
3277 usb_speed_string(hsotg->gadget.speed)); in dwc2_hsotg_irq_enumdone()
3287 dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0, 1); in dwc2_hsotg_irq_enumdone()
3288 dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0, 0); in dwc2_hsotg_irq_enumdone()
3289 for (i = 1; i < hsotg->num_of_eps; i++) { in dwc2_hsotg_irq_enumdone()
3290 if (hsotg->eps_in[i]) in dwc2_hsotg_irq_enumdone()
3291 dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, in dwc2_hsotg_irq_enumdone()
3293 if (hsotg->eps_out[i]) in dwc2_hsotg_irq_enumdone()
3294 dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, in dwc2_hsotg_irq_enumdone()
3301 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_irq_enumdone()
3303 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_irq_enumdone()
3304 dwc2_readl(hsotg, DIEPCTL0), in dwc2_hsotg_irq_enumdone()
3305 dwc2_readl(hsotg, DOEPCTL0)); in dwc2_hsotg_irq_enumdone()
3317 static void kill_all_requests(struct dwc2_hsotg *hsotg, in kill_all_requests() argument
3328 dwc2_hsotg_complete_request(hsotg, ep, req, result); in kill_all_requests()
3331 if (!hsotg->dedicated_fifos) in kill_all_requests()
3333 size = (dwc2_readl(hsotg, DTXFSTS(ep->fifo_index)) & 0xffff) * 4; in kill_all_requests()
3335 dwc2_hsotg_txfifo_flush(hsotg, ep->fifo_index); in kill_all_requests()
3346 void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_disconnect() argument
3350 if (!hsotg->connected) in dwc2_hsotg_disconnect()
3353 hsotg->connected = 0; in dwc2_hsotg_disconnect()
3354 hsotg->test_mode = 0; in dwc2_hsotg_disconnect()
3357 for (ep = 0; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_disconnect()
3358 if (hsotg->eps_in[ep]) in dwc2_hsotg_disconnect()
3359 kill_all_requests(hsotg, hsotg->eps_in[ep], in dwc2_hsotg_disconnect()
3361 if (hsotg->eps_out[ep]) in dwc2_hsotg_disconnect()
3362 kill_all_requests(hsotg, hsotg->eps_out[ep], in dwc2_hsotg_disconnect()
3366 call_gadget(hsotg, disconnect); in dwc2_hsotg_disconnect()
3367 hsotg->lx_state = DWC2_L3; in dwc2_hsotg_disconnect()
3369 usb_gadget_set_state(&hsotg->gadget, USB_STATE_NOTATTACHED); in dwc2_hsotg_disconnect()
3377 static void dwc2_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic) in dwc2_hsotg_irq_fifoempty() argument
3383 for (epno = 0; epno < hsotg->num_of_eps; epno++) { in dwc2_hsotg_irq_fifoempty()
3384 ep = index_to_ep(hsotg, epno, 1); in dwc2_hsotg_irq_fifoempty()
3396 ret = dwc2_hsotg_trytx(hsotg, ep); in dwc2_hsotg_irq_fifoempty()
3415 void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, in dwc2_hsotg_core_init_disconnected() argument
3425 kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); in dwc2_hsotg_core_init_disconnected()
3428 if (dwc2_core_reset(hsotg, true)) in dwc2_hsotg_core_init_disconnected()
3432 for (ep = 1; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_core_init_disconnected()
3433 if (hsotg->eps_in[ep]) in dwc2_hsotg_core_init_disconnected()
3434 dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_core_init_disconnected()
3435 if (hsotg->eps_out[ep]) in dwc2_hsotg_core_init_disconnected()
3436 dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_core_init_disconnected()
3446 usbcfg = dwc2_readl(hsotg, GUSBCFG); in dwc2_hsotg_core_init_disconnected()
3452 dwc2_writel(hsotg, usbcfg, GUSBCFG); in dwc2_hsotg_core_init_disconnected()
3454 dwc2_phy_init(hsotg, true); in dwc2_hsotg_core_init_disconnected()
3456 dwc2_hsotg_init_fifo(hsotg); in dwc2_hsotg_core_init_disconnected()
3459 dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_init_disconnected()
3463 switch (hsotg->params.speed) { in dwc2_hsotg_core_init_disconnected()
3468 if (hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS) in dwc2_hsotg_core_init_disconnected()
3477 if (hsotg->params.ipg_isoc_en) in dwc2_hsotg_core_init_disconnected()
3480 dwc2_writel(hsotg, dcfg, DCFG); in dwc2_hsotg_core_init_disconnected()
3483 dwc2_writel(hsotg, 0xffffffff, GOTGINT); in dwc2_hsotg_core_init_disconnected()
3486 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_hsotg_core_init_disconnected()
3494 if (!using_desc_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
3497 if (!hsotg->params.external_id_pin_ctl) in dwc2_hsotg_core_init_disconnected()
3500 dwc2_writel(hsotg, intmsk, GINTMSK); in dwc2_hsotg_core_init_disconnected()
3502 if (using_dma(hsotg)) { in dwc2_hsotg_core_init_disconnected()
3503 dwc2_writel(hsotg, GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | in dwc2_hsotg_core_init_disconnected()
3504 hsotg->params.ahbcfg, in dwc2_hsotg_core_init_disconnected()
3508 if (using_desc_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
3509 dwc2_set_bit(hsotg, DCFG, DCFG_DESCDMA_EN); in dwc2_hsotg_core_init_disconnected()
3512 dwc2_writel(hsotg, ((hsotg->dedicated_fifos) ? in dwc2_hsotg_core_init_disconnected()
3524 dwc2_writel(hsotg, ((hsotg->dedicated_fifos && !using_dma(hsotg)) ? in dwc2_hsotg_core_init_disconnected()
3534 dwc2_writel(hsotg, (using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | in dwc2_hsotg_core_init_disconnected()
3541 if (using_desc_dma(hsotg)) { in dwc2_hsotg_core_init_disconnected()
3542 dwc2_set_bit(hsotg, DOEPMSK, DOEPMSK_BNAMSK); in dwc2_hsotg_core_init_disconnected()
3543 dwc2_set_bit(hsotg, DIEPMSK, DIEPMSK_BNAININTRMSK); in dwc2_hsotg_core_init_disconnected()
3547 if (using_desc_dma(hsotg) && hsotg->params.service_interval) in dwc2_hsotg_core_init_disconnected()
3548 dwc2_set_bit(hsotg, DCTL, DCTL_SERVICE_INTERVAL_SUPPORTED); in dwc2_hsotg_core_init_disconnected()
3550 dwc2_writel(hsotg, 0, DAINTMSK); in dwc2_hsotg_core_init_disconnected()
3552 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_core_init_disconnected()
3553 dwc2_readl(hsotg, DIEPCTL0), in dwc2_hsotg_core_init_disconnected()
3554 dwc2_readl(hsotg, DOEPCTL0)); in dwc2_hsotg_core_init_disconnected()
3557 dwc2_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); in dwc2_hsotg_core_init_disconnected()
3564 if (!using_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
3565 dwc2_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); in dwc2_hsotg_core_init_disconnected()
3568 dwc2_hsotg_ctrl_epint(hsotg, 0, 0, 1); in dwc2_hsotg_core_init_disconnected()
3569 dwc2_hsotg_ctrl_epint(hsotg, 0, 1, 1); in dwc2_hsotg_core_init_disconnected()
3572 dwc2_set_bit(hsotg, DCTL, DCTL_PWRONPRGDONE); in dwc2_hsotg_core_init_disconnected()
3574 dwc2_clear_bit(hsotg, DCTL, DCTL_PWRONPRGDONE); in dwc2_hsotg_core_init_disconnected()
3577 dev_dbg(hsotg->dev, "DCTL=0x%08x\n", dwc2_readl(hsotg, DCTL)); in dwc2_hsotg_core_init_disconnected()
3585 dwc2_writel(hsotg, DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | in dwc2_hsotg_core_init_disconnected()
3588 dwc2_writel(hsotg, dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in dwc2_hsotg_core_init_disconnected()
3594 dwc2_writel(hsotg, dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in dwc2_hsotg_core_init_disconnected()
3601 dwc2_set_bit(hsotg, DCTL, val); in dwc2_hsotg_core_init_disconnected()
3604 dwc2_gadget_init_lpm(hsotg); in dwc2_hsotg_core_init_disconnected()
3607 if (using_desc_dma(hsotg) && hsotg->params.service_interval) in dwc2_hsotg_core_init_disconnected()
3608 dwc2_gadget_program_ref_clk(hsotg); in dwc2_hsotg_core_init_disconnected()
3613 hsotg->lx_state = DWC2_L0; in dwc2_hsotg_core_init_disconnected()
3615 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_core_init_disconnected()
3617 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_core_init_disconnected()
3618 dwc2_readl(hsotg, DIEPCTL0), in dwc2_hsotg_core_init_disconnected()
3619 dwc2_readl(hsotg, DOEPCTL0)); in dwc2_hsotg_core_init_disconnected()
3622 void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_core_disconnect() argument
3625 dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_disconnect()
3628 void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_core_connect() argument
3631 if (!hsotg->role_sw || (dwc2_readl(hsotg, GOTGCTL) & GOTGCTL_BSESVLD)) in dwc2_hsotg_core_connect()
3632 dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_connect()
3648 static void dwc2_gadget_handle_incomplete_isoc_in(struct dwc2_hsotg *hsotg) in dwc2_gadget_handle_incomplete_isoc_in() argument
3655 dev_dbg(hsotg->dev, "Incomplete isoc in interrupt received:\n"); in dwc2_gadget_handle_incomplete_isoc_in()
3657 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_gadget_handle_incomplete_isoc_in()
3659 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_gadget_handle_incomplete_isoc_in()
3660 hs_ep = hsotg->eps_in[idx]; in dwc2_gadget_handle_incomplete_isoc_in()
3665 epctrl = dwc2_readl(hsotg, DIEPCTL(idx)); in dwc2_gadget_handle_incomplete_isoc_in()
3670 dwc2_writel(hsotg, epctrl, DIEPCTL(idx)); in dwc2_gadget_handle_incomplete_isoc_in()
3675 dwc2_writel(hsotg, GINTSTS_INCOMPL_SOIN, GINTSTS); in dwc2_gadget_handle_incomplete_isoc_in()
3691 static void dwc2_gadget_handle_incomplete_isoc_out(struct dwc2_hsotg *hsotg) in dwc2_gadget_handle_incomplete_isoc_out() argument
3700 dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__); in dwc2_gadget_handle_incomplete_isoc_out()
3702 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_gadget_handle_incomplete_isoc_out()
3705 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_gadget_handle_incomplete_isoc_out()
3706 hs_ep = hsotg->eps_out[idx]; in dwc2_gadget_handle_incomplete_isoc_out()
3711 epctrl = dwc2_readl(hsotg, DOEPCTL(idx)); in dwc2_gadget_handle_incomplete_isoc_out()
3715 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_gadget_handle_incomplete_isoc_out()
3717 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_gadget_handle_incomplete_isoc_out()
3719 gintsts = dwc2_readl(hsotg, GINTSTS); in dwc2_gadget_handle_incomplete_isoc_out()
3721 dwc2_set_bit(hsotg, DCTL, DCTL_SGOUTNAK); in dwc2_gadget_handle_incomplete_isoc_out()
3728 dwc2_writel(hsotg, GINTSTS_INCOMPL_SOOUT, GINTSTS); in dwc2_gadget_handle_incomplete_isoc_out()
3738 struct dwc2_hsotg *hsotg = pw; in dwc2_hsotg_irq() local
3743 if (!dwc2_is_device_mode(hsotg)) in dwc2_hsotg_irq()
3746 spin_lock(&hsotg->lock); in dwc2_hsotg_irq()
3748 gintsts = dwc2_readl(hsotg, GINTSTS); in dwc2_hsotg_irq()
3749 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_irq()
3751 dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", in dwc2_hsotg_irq()
3757 dev_dbg(hsotg->dev, "%s: USBRstDet\n", __func__); in dwc2_hsotg_irq()
3759 dwc2_writel(hsotg, GINTSTS_RESETDET, GINTSTS); in dwc2_hsotg_irq()
3762 if (hsotg->lx_state == DWC2_L2) { in dwc2_hsotg_irq()
3763 dwc2_exit_partial_power_down(hsotg, true); in dwc2_hsotg_irq()
3764 hsotg->lx_state = DWC2_L0; in dwc2_hsotg_irq()
3769 u32 usb_status = dwc2_readl(hsotg, GOTGCTL); in dwc2_hsotg_irq()
3770 u32 connected = hsotg->connected; in dwc2_hsotg_irq()
3772 dev_dbg(hsotg->dev, "%s: USBRst\n", __func__); in dwc2_hsotg_irq()
3773 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", in dwc2_hsotg_irq()
3774 dwc2_readl(hsotg, GNPTXSTS)); in dwc2_hsotg_irq()
3776 dwc2_writel(hsotg, GINTSTS_USBRST, GINTSTS); in dwc2_hsotg_irq()
3779 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_irq()
3782 dwc2_clear_bit(hsotg, DCFG, DCFG_DEVADDR_MASK); in dwc2_hsotg_irq()
3785 dwc2_hsotg_core_init_disconnected(hsotg, true); in dwc2_hsotg_irq()
3789 dwc2_writel(hsotg, GINTSTS_ENUMDONE, GINTSTS); in dwc2_hsotg_irq()
3791 dwc2_hsotg_irq_enumdone(hsotg); in dwc2_hsotg_irq()
3795 u32 daint = dwc2_readl(hsotg, DAINT); in dwc2_hsotg_irq()
3796 u32 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_hsotg_irq()
3804 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); in dwc2_hsotg_irq()
3806 for (ep = 0; ep < hsotg->num_of_eps && daint_out; in dwc2_hsotg_irq()
3809 dwc2_hsotg_epint(hsotg, ep, 0); in dwc2_hsotg_irq()
3812 for (ep = 0; ep < hsotg->num_of_eps && daint_in; in dwc2_hsotg_irq()
3815 dwc2_hsotg_epint(hsotg, ep, 1); in dwc2_hsotg_irq()
3822 dev_dbg(hsotg->dev, "NPTxFEmp\n"); in dwc2_hsotg_irq()
3830 dwc2_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); in dwc2_hsotg_irq()
3831 dwc2_hsotg_irq_fifoempty(hsotg, false); in dwc2_hsotg_irq()
3835 dev_dbg(hsotg->dev, "PTxFEmp\n"); in dwc2_hsotg_irq()
3839 dwc2_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_irq()
3840 dwc2_hsotg_irq_fifoempty(hsotg, true); in dwc2_hsotg_irq()
3850 dwc2_hsotg_handle_rx(hsotg); in dwc2_hsotg_irq()
3854 dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); in dwc2_hsotg_irq()
3855 dwc2_writel(hsotg, GINTSTS_ERLYSUSP, GINTSTS); in dwc2_hsotg_irq()
3871 daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_hsotg_irq()
3874 gintmsk = dwc2_readl(hsotg, GINTMSK); in dwc2_hsotg_irq()
3876 dwc2_writel(hsotg, gintmsk, GINTMSK); in dwc2_hsotg_irq()
3878 dev_dbg(hsotg->dev, "GOUTNakEff triggered\n"); in dwc2_hsotg_irq()
3879 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_irq()
3880 hs_ep = hsotg->eps_out[idx]; in dwc2_hsotg_irq()
3885 epctrl = dwc2_readl(hsotg, DOEPCTL(idx)); in dwc2_hsotg_irq()
3891 dwc2_writel(hsotg, epctrl, DOEPCTL(idx)); in dwc2_hsotg_irq()
3901 dwc2_writel(hsotg, epctrl, DOEPCTL(idx)); in dwc2_hsotg_irq()
3909 dev_info(hsotg->dev, "GINNakEff triggered\n"); in dwc2_hsotg_irq()
3911 dwc2_set_bit(hsotg, DCTL, DCTL_CGNPINNAK); in dwc2_hsotg_irq()
3913 dwc2_hsotg_dump(hsotg); in dwc2_hsotg_irq()
3917 dwc2_gadget_handle_incomplete_isoc_in(hsotg); in dwc2_hsotg_irq()
3920 dwc2_gadget_handle_incomplete_isoc_out(hsotg); in dwc2_hsotg_irq()
3931 if (hsotg->params.service_interval) in dwc2_hsotg_irq()
3932 dwc2_gadget_wkup_alert_handler(hsotg); in dwc2_hsotg_irq()
3934 spin_unlock(&hsotg->lock); in dwc2_hsotg_irq()
3939 static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg, in dwc2_hsotg_ep_stop_xfr() argument
3950 dev_dbg(hsotg->dev, "%s: stopping transfer on %s\n", __func__, in dwc2_hsotg_ep_stop_xfr()
3954 if (hsotg->dedicated_fifos || hs_ep->periodic) { in dwc2_hsotg_ep_stop_xfr()
3955 dwc2_set_bit(hsotg, epctrl_reg, DXEPCTL_SNAK); in dwc2_hsotg_ep_stop_xfr()
3957 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, in dwc2_hsotg_ep_stop_xfr()
3959 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
3963 dwc2_set_bit(hsotg, DCTL, DCTL_SGNPINNAK); in dwc2_hsotg_ep_stop_xfr()
3965 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, in dwc2_hsotg_ep_stop_xfr()
3967 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
3973 dwc2_hsotg_disable_gsint(hsotg, GINTSTS_GOUTNAKEFF); in dwc2_hsotg_ep_stop_xfr()
3975 if (!(dwc2_readl(hsotg, GINTSTS) & GINTSTS_GOUTNAKEFF)) in dwc2_hsotg_ep_stop_xfr()
3976 dwc2_set_bit(hsotg, DCTL, DCTL_SGOUTNAK); in dwc2_hsotg_ep_stop_xfr()
3978 if (!using_dma(hsotg)) { in dwc2_hsotg_ep_stop_xfr()
3980 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, in dwc2_hsotg_ep_stop_xfr()
3982 dev_warn(hsotg->dev, "%s: timeout GINTSTS.RXFLVL\n", in dwc2_hsotg_ep_stop_xfr()
3989 dwc2_readl(hsotg, GRXSTSP); in dwc2_hsotg_ep_stop_xfr()
3994 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, in dwc2_hsotg_ep_stop_xfr()
3996 dev_warn(hsotg->dev, "%s: timeout GINTSTS.GOUTNAKEFF\n", in dwc2_hsotg_ep_stop_xfr()
4001 dwc2_set_bit(hsotg, epctrl_reg, DXEPCTL_EPDIS | DXEPCTL_SNAK); in dwc2_hsotg_ep_stop_xfr()
4004 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, DXEPINT_EPDISBLD, 100)) in dwc2_hsotg_ep_stop_xfr()
4005 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
4009 dwc2_set_bit(hsotg, epint_reg, DXEPINT_EPDISBLD); in dwc2_hsotg_ep_stop_xfr()
4014 if (hsotg->dedicated_fifos || hs_ep->periodic) in dwc2_hsotg_ep_stop_xfr()
4020 dwc2_flush_tx_fifo(hsotg, fifo_index); in dwc2_hsotg_ep_stop_xfr()
4023 if (!hsotg->dedicated_fifos && !hs_ep->periodic) in dwc2_hsotg_ep_stop_xfr()
4024 dwc2_set_bit(hsotg, DCTL, DCTL_CGNPINNAK); in dwc2_hsotg_ep_stop_xfr()
4028 dwc2_set_bit(hsotg, DCTL, DCTL_CGOUTNAK); in dwc2_hsotg_ep_stop_xfr()
4043 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_enable() local
4057 dev_dbg(hsotg->dev, in dwc2_hsotg_ep_enable()
4064 dev_err(hsotg->dev, "%s: called for EP 0\n", __func__); in dwc2_hsotg_ep_enable()
4070 dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__); in dwc2_hsotg_ep_enable()
4079 if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC && in dwc2_hsotg_ep_enable()
4081 dev_err(hsotg->dev, in dwc2_hsotg_ep_enable()
4087 if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC && in dwc2_hsotg_ep_enable()
4089 dev_err(hsotg->dev, in dwc2_hsotg_ep_enable()
4097 epctrl = dwc2_readl(hsotg, epctrl_reg); in dwc2_hsotg_ep_enable()
4099 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", in dwc2_hsotg_ep_enable()
4102 if (using_desc_dma(hsotg) && ep_type == USB_ENDPOINT_XFER_ISOC) in dwc2_hsotg_ep_enable()
4108 if (using_desc_dma(hsotg) && !hs_ep->desc_list) { in dwc2_hsotg_ep_enable()
4109 hs_ep->desc_list = dmam_alloc_coherent(hsotg->dev, in dwc2_hsotg_ep_enable()
4118 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_ep_enable()
4130 dwc2_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps, mc, dir_in); in dwc2_hsotg_ep_enable()
4149 mask = dwc2_readl(hsotg, DIEPMSK); in dwc2_hsotg_ep_enable()
4151 dwc2_writel(hsotg, mask, DIEPMSK); in dwc2_hsotg_ep_enable()
4154 mask = dwc2_readl(hsotg, DOEPMSK); in dwc2_hsotg_ep_enable()
4156 dwc2_writel(hsotg, mask, DOEPMSK); in dwc2_hsotg_ep_enable()
4168 if (hsotg->gadget.speed == USB_SPEED_HIGH) in dwc2_hsotg_ep_enable()
4183 if (dir_in && hsotg->dedicated_fifos) { in dwc2_hsotg_ep_enable()
4184 unsigned fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); in dwc2_hsotg_ep_enable()
4190 if (hsotg->fifo_map & (1 << i)) in dwc2_hsotg_ep_enable()
4192 val = dwc2_readl(hsotg, DPTXFSIZN(i)); in dwc2_hsotg_ep_enable()
4203 dev_err(hsotg->dev, in dwc2_hsotg_ep_enable()
4209 hsotg->fifo_map |= 1 << fifo_index; in dwc2_hsotg_ep_enable()
4225 if (hsotg->gadget.speed == USB_SPEED_FULL && in dwc2_hsotg_ep_enable()
4231 u32 gsnpsid = dwc2_readl(hsotg, GSNPSID); in dwc2_hsotg_ep_enable()
4240 dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", in dwc2_hsotg_ep_enable()
4243 dwc2_writel(hsotg, epctrl, epctrl_reg); in dwc2_hsotg_ep_enable()
4244 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", in dwc2_hsotg_ep_enable()
4245 __func__, dwc2_readl(hsotg, epctrl_reg)); in dwc2_hsotg_ep_enable()
4248 dwc2_hsotg_ctrl_epint(hsotg, index, dir_in, 1); in dwc2_hsotg_ep_enable()
4251 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_ep_enable()
4254 if (ret && using_desc_dma(hsotg) && hs_ep->desc_list) { in dwc2_hsotg_ep_enable()
4255 dmam_free_coherent(hsotg->dev, desc_num * in dwc2_hsotg_ep_enable()
4271 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_disable() local
4277 dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); in dwc2_hsotg_ep_disable()
4279 if (ep == &hsotg->eps_out[0]->ep) { in dwc2_hsotg_ep_disable()
4280 dev_err(hsotg->dev, "%s: called for ep0\n", __func__); in dwc2_hsotg_ep_disable()
4284 if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) { in dwc2_hsotg_ep_disable()
4285 dev_err(hsotg->dev, "%s: called in host mode?\n", __func__); in dwc2_hsotg_ep_disable()
4291 ctrl = dwc2_readl(hsotg, epctrl_reg); in dwc2_hsotg_ep_disable()
4294 dwc2_hsotg_ep_stop_xfr(hsotg, hs_ep); in dwc2_hsotg_ep_disable()
4300 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in dwc2_hsotg_ep_disable()
4301 dwc2_writel(hsotg, ctrl, epctrl_reg); in dwc2_hsotg_ep_disable()
4304 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); in dwc2_hsotg_ep_disable()
4307 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN); in dwc2_hsotg_ep_disable()
4309 hsotg->fifo_map &= ~(1 << hs_ep->fifo_index); in dwc2_hsotg_ep_disable()
4319 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_disable_lock() local
4323 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_ep_disable_lock()
4325 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_ep_disable_lock()
4493 static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg) in dwc2_hsotg_init() argument
4497 dwc2_writel(hsotg, DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | in dwc2_hsotg_init()
4501 dwc2_writel(hsotg, DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | in dwc2_hsotg_init()
4505 dwc2_writel(hsotg, 0, DAINTMSK); in dwc2_hsotg_init()
4508 dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); in dwc2_hsotg_init()
4512 dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", in dwc2_hsotg_init()
4513 dwc2_readl(hsotg, GRXFSIZ), in dwc2_hsotg_init()
4514 dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_hsotg_init()
4516 dwc2_hsotg_init_fifo(hsotg); in dwc2_hsotg_init()
4518 if (using_dma(hsotg)) in dwc2_hsotg_init()
4519 dwc2_set_bit(hsotg, GAHBCFG, GAHBCFG_DMA_EN); in dwc2_hsotg_init()
4533 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_udc_start() local
4537 if (!hsotg) { in dwc2_hsotg_udc_start()
4543 dev_err(hsotg->dev, "%s: no driver\n", __func__); in dwc2_hsotg_udc_start()
4548 dev_err(hsotg->dev, "%s: bad speed\n", __func__); in dwc2_hsotg_udc_start()
4551 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); in dwc2_hsotg_udc_start()
4555 WARN_ON(hsotg->driver); in dwc2_hsotg_udc_start()
4557 hsotg->driver = driver; in dwc2_hsotg_udc_start()
4558 hsotg->gadget.dev.of_node = hsotg->dev->of_node; in dwc2_hsotg_udc_start()
4559 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_udc_start()
4561 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { in dwc2_hsotg_udc_start()
4562 ret = dwc2_lowlevel_hw_enable(hsotg); in dwc2_hsotg_udc_start()
4567 if (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)) { in dwc2_hsotg_udc_start()
4568 if (!hsotg->ll_phy_enabled) { in dwc2_hsotg_udc_start()
4569 ret = dwc2_lowlevel_phy_enable(hsotg); in dwc2_hsotg_udc_start()
4575 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_udc_start()
4576 otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget); in dwc2_hsotg_udc_start()
4578 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_udc_start()
4579 if (dwc2_hw_is_device(hsotg)) { in dwc2_hsotg_udc_start()
4580 dwc2_hsotg_init(hsotg); in dwc2_hsotg_udc_start()
4581 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_udc_start()
4584 hsotg->enabled = 0; in dwc2_hsotg_udc_start()
4585 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_udc_start()
4587 gadget->sg_supported = using_desc_dma(hsotg); in dwc2_hsotg_udc_start()
4588 dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); in dwc2_hsotg_udc_start()
4593 hsotg->driver = NULL; in dwc2_hsotg_udc_start()
4605 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_udc_stop() local
4609 if (!hsotg) in dwc2_hsotg_udc_stop()
4613 for (ep = 1; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_udc_stop()
4614 if (hsotg->eps_in[ep]) in dwc2_hsotg_udc_stop()
4615 dwc2_hsotg_ep_disable_lock(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_udc_stop()
4616 if (hsotg->eps_out[ep]) in dwc2_hsotg_udc_stop()
4617 dwc2_hsotg_ep_disable_lock(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_udc_stop()
4620 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_udc_stop()
4622 hsotg->driver = NULL; in dwc2_hsotg_udc_stop()
4623 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_udc_stop()
4624 hsotg->enabled = 0; in dwc2_hsotg_udc_stop()
4626 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_udc_stop()
4628 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_udc_stop()
4629 otg_set_peripheral(hsotg->uphy->otg, NULL); in dwc2_hsotg_udc_stop()
4631 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_hsotg_udc_stop()
4632 dwc2_lowlevel_hw_disable(hsotg); in dwc2_hsotg_udc_stop()
4634 if (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)) { in dwc2_hsotg_udc_stop()
4635 if (hsotg->ll_phy_enabled) in dwc2_hsotg_udc_stop()
4636 dwc2_lowlevel_phy_disable(hsotg); in dwc2_hsotg_udc_stop()
4663 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_set_selfpowered() local
4666 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_set_selfpowered()
4668 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_set_selfpowered()
4682 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_pullup() local
4685 dev_dbg(hsotg->dev, "%s: is_on: %d op_state: %d\n", __func__, is_on, in dwc2_hsotg_pullup()
4686 hsotg->op_state); in dwc2_hsotg_pullup()
4689 if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) { in dwc2_hsotg_pullup()
4690 hsotg->enabled = is_on; in dwc2_hsotg_pullup()
4694 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_pullup()
4696 hsotg->enabled = 1; in dwc2_hsotg_pullup()
4697 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_pullup()
4699 dwc2_enable_acg(hsotg); in dwc2_hsotg_pullup()
4700 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_pullup()
4702 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_pullup()
4703 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_pullup()
4704 hsotg->enabled = 0; in dwc2_hsotg_pullup()
4707 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_pullup()
4708 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_pullup()
4715 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_vbus_session() local
4718 dev_dbg(hsotg->dev, "%s: is_active: %d\n", __func__, is_active); in dwc2_hsotg_vbus_session()
4719 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_vbus_session()
4725 if (hsotg->lx_state == DWC2_L2) in dwc2_hsotg_vbus_session()
4726 dwc2_exit_partial_power_down(hsotg, false); in dwc2_hsotg_vbus_session()
4729 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_hsotg_vbus_session()
4731 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_vbus_session()
4732 if (hsotg->enabled) { in dwc2_hsotg_vbus_session()
4734 dwc2_enable_acg(hsotg); in dwc2_hsotg_vbus_session()
4735 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_vbus_session()
4738 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_vbus_session()
4739 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_vbus_session()
4742 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_vbus_session()
4755 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_vbus_draw() local
4757 if (IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_vbus_draw()
4759 return usb_phy_set_power(hsotg->uphy, mA); in dwc2_hsotg_vbus_draw()
4783 static void dwc2_hsotg_initep(struct dwc2_hsotg *hsotg, in dwc2_hsotg_initep() argument
4807 list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); in dwc2_hsotg_initep()
4809 hs_ep->parent = hsotg; in dwc2_hsotg_initep()
4812 if (hsotg->params.speed == DWC2_SPEED_PARAM_LOW) in dwc2_hsotg_initep()
4822 if (hsotg->params.speed != DWC2_SPEED_PARAM_LOW) { in dwc2_hsotg_initep()
4839 if (using_dma(hsotg)) { in dwc2_hsotg_initep()
4843 dwc2_writel(hsotg, next, DIEPCTL(epnum)); in dwc2_hsotg_initep()
4845 dwc2_writel(hsotg, next, DOEPCTL(epnum)); in dwc2_hsotg_initep()
4855 static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) in dwc2_hsotg_hw_cfg() argument
4863 hsotg->num_of_eps = hsotg->hw_params.num_dev_ep; in dwc2_hsotg_hw_cfg()
4866 hsotg->num_of_eps++; in dwc2_hsotg_hw_cfg()
4868 hsotg->eps_in[0] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
4871 if (!hsotg->eps_in[0]) in dwc2_hsotg_hw_cfg()
4874 hsotg->eps_out[0] = hsotg->eps_in[0]; in dwc2_hsotg_hw_cfg()
4876 cfg = hsotg->hw_params.dev_ep_dirs; in dwc2_hsotg_hw_cfg()
4877 for (i = 1, cfg >>= 2; i < hsotg->num_of_eps; i++, cfg >>= 2) { in dwc2_hsotg_hw_cfg()
4881 hsotg->eps_in[i] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
4883 if (!hsotg->eps_in[i]) in dwc2_hsotg_hw_cfg()
4888 hsotg->eps_out[i] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
4890 if (!hsotg->eps_out[i]) in dwc2_hsotg_hw_cfg()
4895 hsotg->fifo_mem = hsotg->hw_params.total_fifo_size; in dwc2_hsotg_hw_cfg()
4896 hsotg->dedicated_fifos = hsotg->hw_params.en_multiple_tx_fifo; in dwc2_hsotg_hw_cfg()
4898 dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", in dwc2_hsotg_hw_cfg()
4899 hsotg->num_of_eps, in dwc2_hsotg_hw_cfg()
4900 hsotg->dedicated_fifos ? "dedicated" : "shared", in dwc2_hsotg_hw_cfg()
4901 hsotg->fifo_mem); in dwc2_hsotg_hw_cfg()
4910 static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg) in dwc2_hsotg_dump() argument
4913 struct device *dev = hsotg->dev; in dwc2_hsotg_dump()
4918 dwc2_readl(hsotg, DCFG), dwc2_readl(hsotg, DCTL), in dwc2_hsotg_dump()
4919 dwc2_readl(hsotg, DIEPMSK)); in dwc2_hsotg_dump()
4922 dwc2_readl(hsotg, GAHBCFG), dwc2_readl(hsotg, GHWCFG1)); in dwc2_hsotg_dump()
4925 dwc2_readl(hsotg, GRXFSIZ), dwc2_readl(hsotg, GNPTXFSIZ)); in dwc2_hsotg_dump()
4929 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_dump()
4930 val = dwc2_readl(hsotg, DPTXFSIZN(idx)); in dwc2_hsotg_dump()
4936 for (idx = 0; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_dump()
4939 dwc2_readl(hsotg, DIEPCTL(idx)), in dwc2_hsotg_dump()
4940 dwc2_readl(hsotg, DIEPTSIZ(idx)), in dwc2_hsotg_dump()
4941 dwc2_readl(hsotg, DIEPDMA(idx))); in dwc2_hsotg_dump()
4943 val = dwc2_readl(hsotg, DOEPCTL(idx)); in dwc2_hsotg_dump()
4946 idx, dwc2_readl(hsotg, DOEPCTL(idx)), in dwc2_hsotg_dump()
4947 dwc2_readl(hsotg, DOEPTSIZ(idx)), in dwc2_hsotg_dump()
4948 dwc2_readl(hsotg, DOEPDMA(idx))); in dwc2_hsotg_dump()
4952 dwc2_readl(hsotg, DVBUSDIS), dwc2_readl(hsotg, DVBUSPULSE)); in dwc2_hsotg_dump()
4961 int dwc2_gadget_init(struct dwc2_hsotg *hsotg) in dwc2_gadget_init() argument
4963 struct device *dev = hsotg->dev; in dwc2_gadget_init()
4969 hsotg->params.g_np_tx_fifo_size); in dwc2_gadget_init()
4970 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->params.g_rx_fifo_size); in dwc2_gadget_init()
4972 hsotg->gadget.max_speed = USB_SPEED_HIGH; in dwc2_gadget_init()
4973 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops; in dwc2_gadget_init()
4974 hsotg->gadget.name = dev_name(dev); in dwc2_gadget_init()
4975 hsotg->remote_wakeup_allowed = 0; in dwc2_gadget_init()
4977 if (hsotg->params.lpm) in dwc2_gadget_init()
4978 hsotg->gadget.lpm_capable = true; in dwc2_gadget_init()
4980 if (hsotg->dr_mode == USB_DR_MODE_OTG) in dwc2_gadget_init()
4981 hsotg->gadget.is_otg = 1; in dwc2_gadget_init()
4982 else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_gadget_init()
4983 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_gadget_init()
4985 ret = dwc2_hsotg_hw_cfg(hsotg); in dwc2_gadget_init()
4987 dev_err(hsotg->dev, "Hardware configuration failed: %d\n", ret); in dwc2_gadget_init()
4991 hsotg->ctrl_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
4993 if (!hsotg->ctrl_buff) in dwc2_gadget_init()
4996 hsotg->ep0_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
4998 if (!hsotg->ep0_buff) in dwc2_gadget_init()
5001 if (using_desc_dma(hsotg)) { in dwc2_gadget_init()
5002 ret = dwc2_gadget_alloc_ctrl_desc_chains(hsotg); in dwc2_gadget_init()
5007 ret = devm_request_irq(hsotg->dev, hsotg->irq, dwc2_hsotg_irq, in dwc2_gadget_init()
5008 IRQF_SHARED, dev_name(hsotg->dev), hsotg); in dwc2_gadget_init()
5016 if (hsotg->num_of_eps == 0) { in dwc2_gadget_init()
5023 INIT_LIST_HEAD(&hsotg->gadget.ep_list); in dwc2_gadget_init()
5024 hsotg->gadget.ep0 = &hsotg->eps_out[0]->ep; in dwc2_gadget_init()
5028 hsotg->ctrl_req = dwc2_hsotg_ep_alloc_request(&hsotg->eps_out[0]->ep, in dwc2_gadget_init()
5030 if (!hsotg->ctrl_req) { in dwc2_gadget_init()
5036 for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) { in dwc2_gadget_init()
5037 if (hsotg->eps_in[epnum]) in dwc2_gadget_init()
5038 dwc2_hsotg_initep(hsotg, hsotg->eps_in[epnum], in dwc2_gadget_init()
5040 if (hsotg->eps_out[epnum]) in dwc2_gadget_init()
5041 dwc2_hsotg_initep(hsotg, hsotg->eps_out[epnum], in dwc2_gadget_init()
5045 dwc2_hsotg_dump(hsotg); in dwc2_gadget_init()
5055 int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg) in dwc2_hsotg_remove() argument
5057 usb_del_gadget_udc(&hsotg->gadget); in dwc2_hsotg_remove()
5058 dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req); in dwc2_hsotg_remove()
5063 int dwc2_hsotg_suspend(struct dwc2_hsotg *hsotg) in dwc2_hsotg_suspend() argument
5067 if (hsotg->lx_state != DWC2_L0) in dwc2_hsotg_suspend()
5070 if (hsotg->driver) { in dwc2_hsotg_suspend()
5073 dev_info(hsotg->dev, "suspending usb gadget %s\n", in dwc2_hsotg_suspend()
5074 hsotg->driver->driver.name); in dwc2_hsotg_suspend()
5076 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_suspend()
5077 if (hsotg->enabled) in dwc2_hsotg_suspend()
5078 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_suspend()
5079 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_suspend()
5080 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_suspend()
5081 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_suspend()
5083 for (ep = 1; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_suspend()
5084 if (hsotg->eps_in[ep]) in dwc2_hsotg_suspend()
5085 dwc2_hsotg_ep_disable_lock(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_suspend()
5086 if (hsotg->eps_out[ep]) in dwc2_hsotg_suspend()
5087 dwc2_hsotg_ep_disable_lock(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_suspend()
5094 int dwc2_hsotg_resume(struct dwc2_hsotg *hsotg) in dwc2_hsotg_resume() argument
5098 if (hsotg->lx_state == DWC2_L2) in dwc2_hsotg_resume()
5101 if (hsotg->driver) { in dwc2_hsotg_resume()
5102 dev_info(hsotg->dev, "resuming usb gadget %s\n", in dwc2_hsotg_resume()
5103 hsotg->driver->driver.name); in dwc2_hsotg_resume()
5105 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_resume()
5106 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_resume()
5107 if (hsotg->enabled) { in dwc2_hsotg_resume()
5109 dwc2_enable_acg(hsotg); in dwc2_hsotg_resume()
5110 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_resume()
5112 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_resume()
5125 int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg) in dwc2_backup_device_registers() argument
5130 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_backup_device_registers()
5133 dr = &hsotg->dr_backup; in dwc2_backup_device_registers()
5135 dr->dcfg = dwc2_readl(hsotg, DCFG); in dwc2_backup_device_registers()
5136 dr->dctl = dwc2_readl(hsotg, DCTL); in dwc2_backup_device_registers()
5137 dr->daintmsk = dwc2_readl(hsotg, DAINTMSK); in dwc2_backup_device_registers()
5138 dr->diepmsk = dwc2_readl(hsotg, DIEPMSK); in dwc2_backup_device_registers()
5139 dr->doepmsk = dwc2_readl(hsotg, DOEPMSK); in dwc2_backup_device_registers()
5141 for (i = 0; i < hsotg->num_of_eps; i++) { in dwc2_backup_device_registers()
5143 dr->diepctl[i] = dwc2_readl(hsotg, DIEPCTL(i)); in dwc2_backup_device_registers()
5151 dr->dieptsiz[i] = dwc2_readl(hsotg, DIEPTSIZ(i)); in dwc2_backup_device_registers()
5152 dr->diepdma[i] = dwc2_readl(hsotg, DIEPDMA(i)); in dwc2_backup_device_registers()
5155 dr->doepctl[i] = dwc2_readl(hsotg, DOEPCTL(i)); in dwc2_backup_device_registers()
5163 dr->doeptsiz[i] = dwc2_readl(hsotg, DOEPTSIZ(i)); in dwc2_backup_device_registers()
5164 dr->doepdma[i] = dwc2_readl(hsotg, DOEPDMA(i)); in dwc2_backup_device_registers()
5165 dr->dtxfsiz[i] = dwc2_readl(hsotg, DPTXFSIZN(i)); in dwc2_backup_device_registers()
5181 int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup) in dwc2_restore_device_registers() argument
5186 dev_dbg(hsotg->dev, "%s\n", __func__); in dwc2_restore_device_registers()
5189 dr = &hsotg->dr_backup; in dwc2_restore_device_registers()
5191 dev_err(hsotg->dev, "%s: no device registers to restore\n", in dwc2_restore_device_registers()
5198 dwc2_writel(hsotg, dr->dctl, DCTL); in dwc2_restore_device_registers()
5200 dwc2_writel(hsotg, dr->daintmsk, DAINTMSK); in dwc2_restore_device_registers()
5201 dwc2_writel(hsotg, dr->diepmsk, DIEPMSK); in dwc2_restore_device_registers()
5202 dwc2_writel(hsotg, dr->doepmsk, DOEPMSK); in dwc2_restore_device_registers()
5204 for (i = 0; i < hsotg->num_of_eps; i++) { in dwc2_restore_device_registers()
5206 dwc2_writel(hsotg, dr->dieptsiz[i], DIEPTSIZ(i)); in dwc2_restore_device_registers()
5207 dwc2_writel(hsotg, dr->diepdma[i], DIEPDMA(i)); in dwc2_restore_device_registers()
5208 dwc2_writel(hsotg, dr->doeptsiz[i], DOEPTSIZ(i)); in dwc2_restore_device_registers()
5214 if (hsotg->params.g_dma_desc && in dwc2_restore_device_registers()
5216 dr->diepdma[i] = hsotg->eps_in[i]->desc_list_dma; in dwc2_restore_device_registers()
5217 dwc2_writel(hsotg, dr->dtxfsiz[i], DPTXFSIZN(i)); in dwc2_restore_device_registers()
5218 dwc2_writel(hsotg, dr->diepctl[i], DIEPCTL(i)); in dwc2_restore_device_registers()
5220 dwc2_writel(hsotg, dr->doeptsiz[i], DOEPTSIZ(i)); in dwc2_restore_device_registers()
5226 if (hsotg->params.g_dma_desc && in dwc2_restore_device_registers()
5228 dr->doepdma[i] = hsotg->eps_out[i]->desc_list_dma; in dwc2_restore_device_registers()
5229 dwc2_writel(hsotg, dr->doepdma[i], DOEPDMA(i)); in dwc2_restore_device_registers()
5230 dwc2_writel(hsotg, dr->doepctl[i], DOEPCTL(i)); in dwc2_restore_device_registers()
5242 void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) in dwc2_gadget_init_lpm() argument
5246 if (!hsotg->params.lpm) in dwc2_gadget_init_lpm()
5250 val |= hsotg->params.hird_threshold_en ? GLPMCFG_HIRD_THRES_EN : 0; in dwc2_gadget_init_lpm()
5251 val |= hsotg->params.lpm_clock_gating ? GLPMCFG_ENBLSLPM : 0; in dwc2_gadget_init_lpm()
5252 val |= hsotg->params.hird_threshold << GLPMCFG_HIRD_THRES_SHIFT; in dwc2_gadget_init_lpm()
5253 val |= hsotg->params.besl ? GLPMCFG_ENBESL : 0; in dwc2_gadget_init_lpm()
5256 dwc2_writel(hsotg, val, GLPMCFG); in dwc2_gadget_init_lpm()
5257 dev_dbg(hsotg->dev, "GLPMCFG=0x%08x\n", dwc2_readl(hsotg, GLPMCFG)); in dwc2_gadget_init_lpm()
5260 if (hsotg->params.service_interval) in dwc2_gadget_init_lpm()
5261 dwc2_set_bit(hsotg, GINTMSK2, GINTMSK2_WKUP_ALERT_INT_MSK); in dwc2_gadget_init_lpm()
5270 void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg) in dwc2_gadget_program_ref_clk() argument
5275 val |= hsotg->params.ref_clk_per << GREFCLK_REFCLKPER_SHIFT; in dwc2_gadget_program_ref_clk()
5276 val |= hsotg->params.sof_cnt_wkup_alert << in dwc2_gadget_program_ref_clk()
5279 dwc2_writel(hsotg, val, GREFCLK); in dwc2_gadget_program_ref_clk()
5280 dev_dbg(hsotg->dev, "GREFCLK=0x%08x\n", dwc2_readl(hsotg, GREFCLK)); in dwc2_gadget_program_ref_clk()
5290 int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg) in dwc2_gadget_enter_hibernation() argument
5296 hsotg->lx_state = DWC2_L2; in dwc2_gadget_enter_hibernation()
5297 dev_dbg(hsotg->dev, "Start of hibernation completed\n"); in dwc2_gadget_enter_hibernation()
5298 ret = dwc2_backup_global_registers(hsotg); in dwc2_gadget_enter_hibernation()
5300 dev_err(hsotg->dev, "%s: failed to backup global registers\n", in dwc2_gadget_enter_hibernation()
5304 ret = dwc2_backup_device_registers(hsotg); in dwc2_gadget_enter_hibernation()
5306 dev_err(hsotg->dev, "%s: failed to backup device registers\n", in dwc2_gadget_enter_hibernation()
5313 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5317 hsotg->hibernated = 1; in dwc2_gadget_enter_hibernation()
5320 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5322 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5326 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5330 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5334 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5336 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5340 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5342 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_enter_hibernation()
5346 hsotg->gr_backup.gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_enter_hibernation()
5347 dev_dbg(hsotg->dev, "Hibernation completed\n"); in dwc2_gadget_enter_hibernation()
5363 int dwc2_gadget_exit_hibernation(struct dwc2_hsotg *hsotg, in dwc2_gadget_exit_hibernation() argument
5373 gr = &hsotg->gr_backup; in dwc2_gadget_exit_hibernation()
5374 dr = &hsotg->dr_backup; in dwc2_gadget_exit_hibernation()
5376 if (!hsotg->hibernated) { in dwc2_gadget_exit_hibernation()
5377 dev_dbg(hsotg->dev, "Already exited from Hibernation\n"); in dwc2_gadget_exit_hibernation()
5380 dev_dbg(hsotg->dev, in dwc2_gadget_exit_hibernation()
5384 dwc2_hib_restore_common(hsotg, rem_wakeup, 0); in dwc2_gadget_exit_hibernation()
5388 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_gadget_exit_hibernation()
5392 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_exit_hibernation()
5394 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_exit_hibernation()
5398 pcgcctl = dwc2_readl(hsotg, PCGCTL); in dwc2_gadget_exit_hibernation()
5400 dwc2_writel(hsotg, pcgcctl, PCGCTL); in dwc2_gadget_exit_hibernation()
5404 dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG); in dwc2_gadget_exit_hibernation()
5405 dwc2_writel(hsotg, dr->dcfg, DCFG); in dwc2_gadget_exit_hibernation()
5406 dwc2_writel(hsotg, dr->dctl, DCTL); in dwc2_gadget_exit_hibernation()
5409 gpwrdn = dwc2_readl(hsotg, GPWRDN); in dwc2_gadget_exit_hibernation()
5411 dwc2_writel(hsotg, gpwrdn, GPWRDN); in dwc2_gadget_exit_hibernation()
5416 dwc2_writel(hsotg, dr->dctl | DCTL_RMTWKUPSIG, DCTL); in dwc2_gadget_exit_hibernation()
5420 dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_exit_hibernation()
5422 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_exit_hibernation()
5427 dwc2_writel(hsotg, 0xffffffff, GINTSTS); in dwc2_gadget_exit_hibernation()
5430 ret = dwc2_restore_global_registers(hsotg); in dwc2_gadget_exit_hibernation()
5432 dev_err(hsotg->dev, "%s: failed to restore registers\n", in dwc2_gadget_exit_hibernation()
5438 ret = dwc2_restore_device_registers(hsotg, rem_wakeup); in dwc2_gadget_exit_hibernation()
5440 dev_err(hsotg->dev, "%s: failed to restore device registers\n", in dwc2_gadget_exit_hibernation()
5447 dctl = dwc2_readl(hsotg, DCTL); in dwc2_gadget_exit_hibernation()
5449 dwc2_writel(hsotg, dctl, DCTL); in dwc2_gadget_exit_hibernation()
5452 hsotg->hibernated = 0; in dwc2_gadget_exit_hibernation()
5453 hsotg->lx_state = DWC2_L0; in dwc2_gadget_exit_hibernation()
5454 dev_dbg(hsotg->dev, "Hibernation recovery completes here\n"); in dwc2_gadget_exit_hibernation()