Lines Matching refs:hsotg

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->g_using_dma; in using_dma()
104 static void dwc2_hsotg_en_gsint(struct dwc2_hsotg *hsotg, u32 ints) in dwc2_hsotg_en_gsint() argument
106 u32 gsintmsk = dwc2_readl(hsotg->regs + GINTMSK); in dwc2_hsotg_en_gsint()
112 dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); in dwc2_hsotg_en_gsint()
113 dwc2_writel(new_gsintmsk, hsotg->regs + GINTMSK); in dwc2_hsotg_en_gsint()
122 static void dwc2_hsotg_disable_gsint(struct dwc2_hsotg *hsotg, u32 ints) in dwc2_hsotg_disable_gsint() argument
124 u32 gsintmsk = dwc2_readl(hsotg->regs + GINTMSK); in dwc2_hsotg_disable_gsint()
130 dwc2_writel(new_gsintmsk, hsotg->regs + GINTMSK); in dwc2_hsotg_disable_gsint()
143 static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg, in dwc2_hsotg_ctrl_epint() argument
155 daint = dwc2_readl(hsotg->regs + DAINTMSK); in dwc2_hsotg_ctrl_epint()
160 dwc2_writel(daint, hsotg->regs + DAINTMSK); in dwc2_hsotg_ctrl_epint()
168 static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) in dwc2_hsotg_init_fifo() argument
176 WARN_ON(hsotg->fifo_map); in dwc2_hsotg_init_fifo()
177 hsotg->fifo_map = 0; in dwc2_hsotg_init_fifo()
180 dwc2_writel(hsotg->g_rx_fifo_sz, hsotg->regs + GRXFSIZ); in dwc2_hsotg_init_fifo()
181 dwc2_writel((hsotg->g_rx_fifo_sz << FIFOSIZE_STARTADDR_SHIFT) | in dwc2_hsotg_init_fifo()
182 (hsotg->g_np_g_tx_fifo_sz << FIFOSIZE_DEPTH_SHIFT), in dwc2_hsotg_init_fifo()
183 hsotg->regs + GNPTXFSIZ); in dwc2_hsotg_init_fifo()
193 addr = hsotg->g_rx_fifo_sz + hsotg->g_np_g_tx_fifo_sz; in dwc2_hsotg_init_fifo()
201 if (!hsotg->g_tx_fifo_sz[ep]) in dwc2_hsotg_init_fifo()
204 val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT; in dwc2_hsotg_init_fifo()
205 WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem, in dwc2_hsotg_init_fifo()
207 addr += hsotg->g_tx_fifo_sz[ep]; in dwc2_hsotg_init_fifo()
209 dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep)); in dwc2_hsotg_init_fifo()
218 GRSTCTL_RXFFLSH, hsotg->regs + GRSTCTL); in dwc2_hsotg_init_fifo()
223 val = dwc2_readl(hsotg->regs + GRSTCTL); in dwc2_hsotg_init_fifo()
229 dev_err(hsotg->dev, in dwc2_hsotg_init_fifo()
238 dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout); in dwc2_hsotg_init_fifo()
282 static void dwc2_hsotg_unmap_dma(struct dwc2_hsotg *hsotg, in dwc2_hsotg_unmap_dma() argument
292 usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->dir_in); in dwc2_hsotg_unmap_dma()
311 static int dwc2_hsotg_write_fifo(struct dwc2_hsotg *hsotg, in dwc2_hsotg_write_fifo() argument
316 u32 gnptxsts = dwc2_readl(hsotg->regs + GNPTXSTS); in dwc2_hsotg_write_fifo()
330 if (periodic && !hsotg->dedicated_fifos) { in dwc2_hsotg_write_fifo()
331 u32 epsize = dwc2_readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); in dwc2_hsotg_write_fifo()
347 dwc2_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_write_fifo()
351 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", in dwc2_hsotg_write_fifo()
360 dev_dbg(hsotg->dev, "%s: => can_write1=%d\n", in dwc2_hsotg_write_fifo()
364 dev_dbg(hsotg->dev, "%s: => can_write2=%d\n", in dwc2_hsotg_write_fifo()
368 dwc2_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_write_fifo()
371 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { in dwc2_hsotg_write_fifo()
372 can_write = dwc2_readl(hsotg->regs + DTXFSTS(hs_ep->index)); in dwc2_hsotg_write_fifo()
378 dev_dbg(hsotg->dev, in dwc2_hsotg_write_fifo()
382 dwc2_hsotg_en_gsint(hsotg, GINTSTS_NPTXFEMP); in dwc2_hsotg_write_fifo()
392 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", in dwc2_hsotg_write_fifo()
412 if (!hsotg->dedicated_fifos) in dwc2_hsotg_write_fifo()
413 dwc2_hsotg_en_gsint(hsotg, in dwc2_hsotg_write_fifo()
441 if (!hsotg->dedicated_fifos) in dwc2_hsotg_write_fifo()
442 dwc2_hsotg_en_gsint(hsotg, in dwc2_hsotg_write_fifo()
447 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", in dwc2_hsotg_write_fifo()
462 iowrite32_rep(hsotg->regs + EPFIFO(hs_ep->index), data, to_write); in dwc2_hsotg_write_fifo()
516 static void dwc2_hsotg_start_req(struct dwc2_hsotg *hsotg, in dwc2_hsotg_start_req() argument
534 dev_err(hsotg->dev, "%s: active request\n", __func__); in dwc2_hsotg_start_req()
538 dev_err(hsotg->dev, in dwc2_hsotg_start_req()
548 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", in dwc2_hsotg_start_req()
549 __func__, dwc2_readl(hsotg->regs + epctrl_reg), index, in dwc2_hsotg_start_req()
553 ctrl = dwc2_readl(hsotg->regs + epctrl_reg); in dwc2_hsotg_start_req()
556 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); in dwc2_hsotg_start_req()
561 dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n", in dwc2_hsotg_start_req()
568 dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n", in dwc2_hsotg_start_req()
584 dev_err(hsotg->dev, "req length > maxpacket*mc\n"); in dwc2_hsotg_start_req()
610 dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", in dwc2_hsotg_start_req()
617 dwc2_writel(epsize, hsotg->regs + epsize_reg); in dwc2_hsotg_start_req()
619 if (using_dma(hsotg) && !continuing) { in dwc2_hsotg_start_req()
628 dwc2_writel(ureq->dma, hsotg->regs + dma_reg); in dwc2_hsotg_start_req()
630 dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", in dwc2_hsotg_start_req()
637 dev_dbg(hsotg->dev, "ep0 state:%d\n", hsotg->ep0_state); in dwc2_hsotg_start_req()
640 if (!(index == 0 && hsotg->ep0_state == DWC2_EP0_SETUP)) in dwc2_hsotg_start_req()
643 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in dwc2_hsotg_start_req()
644 dwc2_writel(ctrl, hsotg->regs + epctrl_reg); in dwc2_hsotg_start_req()
654 if (dir_in && !using_dma(hsotg)) { in dwc2_hsotg_start_req()
658 dwc2_hsotg_write_fifo(hsotg, hs_ep, hs_req); in dwc2_hsotg_start_req()
667 hsotg->regs + DIEPINT(index)); in dwc2_hsotg_start_req()
675 if (!(dwc2_readl(hsotg->regs + epctrl_reg) & DXEPCTL_EPENA)) in dwc2_hsotg_start_req()
676 dev_dbg(hsotg->dev, in dwc2_hsotg_start_req()
678 index, dwc2_readl(hsotg->regs + epctrl_reg)); in dwc2_hsotg_start_req()
680 dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", in dwc2_hsotg_start_req()
681 __func__, dwc2_readl(hsotg->regs + epctrl_reg)); in dwc2_hsotg_start_req()
684 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); in dwc2_hsotg_start_req()
699 static int dwc2_hsotg_map_dma(struct dwc2_hsotg *hsotg, in dwc2_hsotg_map_dma() argument
710 ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); in dwc2_hsotg_map_dma()
717 dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n", in dwc2_hsotg_map_dma()
723 static int dwc2_hsotg_handle_unaligned_buf_start(struct dwc2_hsotg *hsotg, in dwc2_hsotg_handle_unaligned_buf_start() argument
729 if (!using_dma(hsotg) || !((long)req_buf & 3)) in dwc2_hsotg_handle_unaligned_buf_start()
734 dev_dbg(hsotg->dev, "%s: %s: buf=%p length=%d\n", __func__, in dwc2_hsotg_handle_unaligned_buf_start()
740 dev_err(hsotg->dev, in dwc2_hsotg_handle_unaligned_buf_start()
754 static void dwc2_hsotg_handle_unaligned_buf_complete(struct dwc2_hsotg *hsotg, in dwc2_hsotg_handle_unaligned_buf_complete() argument
758 if (!using_dma(hsotg) || !hs_req->saved_req_buf) in dwc2_hsotg_handle_unaligned_buf_complete()
761 dev_dbg(hsotg->dev, "%s: %s: status=%d actual-length=%d\n", __func__, in dwc2_hsotg_handle_unaligned_buf_complete()
856 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_complete_oursetup() local
858 dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); in dwc2_hsotg_complete_oursetup()
871 static struct dwc2_hsotg_ep *ep_from_windex(struct dwc2_hsotg *hsotg, in ep_from_windex() argument
881 if (idx > hsotg->num_of_eps) in ep_from_windex()
884 ep = index_to_ep(hsotg, idx, dir); in ep_from_windex()
898 int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode) in dwc2_hsotg_set_test_mode() argument
900 int dctl = dwc2_readl(hsotg->regs + DCTL); in dwc2_hsotg_set_test_mode()
914 dwc2_writel(dctl, hsotg->regs + DCTL); in dwc2_hsotg_set_test_mode()
928 static int dwc2_hsotg_send_reply(struct dwc2_hsotg *hsotg, in dwc2_hsotg_send_reply() argument
936 dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length); in dwc2_hsotg_send_reply()
939 hsotg->ep0_reply = req; in dwc2_hsotg_send_reply()
941 dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__); in dwc2_hsotg_send_reply()
945 req->buf = hsotg->ep0_buff; in dwc2_hsotg_send_reply()
959 dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__); in dwc2_hsotg_send_reply()
971 static int dwc2_hsotg_process_req_status(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_req_status() argument
974 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_req_status()
979 dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__); in dwc2_hsotg_process_req_status()
982 dev_warn(hsotg->dev, "%s: direction out?\n", __func__); in dwc2_hsotg_process_req_status()
998 ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); in dwc2_hsotg_process_req_status()
1012 ret = dwc2_hsotg_send_reply(hsotg, ep0, &reply, 2); in dwc2_hsotg_process_req_status()
1014 dev_err(hsotg->dev, "%s: failed to send reply\n", __func__); in dwc2_hsotg_process_req_status()
1042 static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_req_feature() argument
1045 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_req_feature()
1056 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", in dwc2_hsotg_process_req_feature()
1072 hsotg->test_mode = wIndex >> 8; in dwc2_hsotg_process_req_feature()
1073 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_req_feature()
1075 dev_err(hsotg->dev, in dwc2_hsotg_process_req_feature()
1086 ep = ep_from_windex(hsotg, wIndex); in dwc2_hsotg_process_req_feature()
1088 dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n", in dwc2_hsotg_process_req_feature()
1099 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_req_feature()
1101 dev_err(hsotg->dev, in dwc2_hsotg_process_req_feature()
1121 spin_unlock(&hsotg->lock); in dwc2_hsotg_process_req_feature()
1124 spin_lock(&hsotg->lock); in dwc2_hsotg_process_req_feature()
1133 dwc2_hsotg_start_req(hsotg, ep, in dwc2_hsotg_process_req_feature()
1151 static void dwc2_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg);
1159 static void dwc2_hsotg_stall_ep0(struct dwc2_hsotg *hsotg) in dwc2_hsotg_stall_ep0() argument
1161 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_stall_ep0()
1165 dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); in dwc2_hsotg_stall_ep0()
1173 ctrl = dwc2_readl(hsotg->regs + reg); in dwc2_hsotg_stall_ep0()
1176 dwc2_writel(ctrl, hsotg->regs + reg); in dwc2_hsotg_stall_ep0()
1178 dev_dbg(hsotg->dev, in dwc2_hsotg_stall_ep0()
1180 ctrl, reg, dwc2_readl(hsotg->regs + reg)); in dwc2_hsotg_stall_ep0()
1186 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_stall_ep0()
1198 static void dwc2_hsotg_process_control(struct dwc2_hsotg *hsotg, in dwc2_hsotg_process_control() argument
1201 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; in dwc2_hsotg_process_control()
1205 dev_dbg(hsotg->dev, in dwc2_hsotg_process_control()
1212 hsotg->ep0_state = DWC2_EP0_STATUS_IN; in dwc2_hsotg_process_control()
1215 hsotg->ep0_state = DWC2_EP0_DATA_IN; in dwc2_hsotg_process_control()
1218 hsotg->ep0_state = DWC2_EP0_DATA_OUT; in dwc2_hsotg_process_control()
1224 hsotg->connected = 1; in dwc2_hsotg_process_control()
1225 dcfg = dwc2_readl(hsotg->regs + DCFG); in dwc2_hsotg_process_control()
1229 dwc2_writel(dcfg, hsotg->regs + DCFG); in dwc2_hsotg_process_control()
1231 dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); in dwc2_hsotg_process_control()
1233 ret = dwc2_hsotg_send_reply(hsotg, ep0, NULL, 0); in dwc2_hsotg_process_control()
1237 ret = dwc2_hsotg_process_req_status(hsotg, ctrl); in dwc2_hsotg_process_control()
1242 ret = dwc2_hsotg_process_req_feature(hsotg, ctrl); in dwc2_hsotg_process_control()
1249 if (ret == 0 && hsotg->driver) { in dwc2_hsotg_process_control()
1250 spin_unlock(&hsotg->lock); in dwc2_hsotg_process_control()
1251 ret = hsotg->driver->setup(&hsotg->gadget, ctrl); in dwc2_hsotg_process_control()
1252 spin_lock(&hsotg->lock); in dwc2_hsotg_process_control()
1254 dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); in dwc2_hsotg_process_control()
1263 dwc2_hsotg_stall_ep0(hsotg); in dwc2_hsotg_process_control()
1278 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_complete_setup() local
1281 dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); in dwc2_hsotg_complete_setup()
1285 spin_lock(&hsotg->lock); in dwc2_hsotg_complete_setup()
1287 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_complete_setup()
1289 dwc2_hsotg_process_control(hsotg, req->buf); in dwc2_hsotg_complete_setup()
1290 spin_unlock(&hsotg->lock); in dwc2_hsotg_complete_setup()
1300 static void dwc2_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg) in dwc2_hsotg_enqueue_setup() argument
1302 struct usb_request *req = hsotg->ctrl_req; in dwc2_hsotg_enqueue_setup()
1306 dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__); in dwc2_hsotg_enqueue_setup()
1310 req->buf = hsotg->ctrl_buff; in dwc2_hsotg_enqueue_setup()
1314 dev_dbg(hsotg->dev, "%s already queued???\n", __func__); in dwc2_hsotg_enqueue_setup()
1318 hsotg->eps_out[0]->dir_in = 0; in dwc2_hsotg_enqueue_setup()
1319 hsotg->eps_out[0]->send_zlp = 0; in dwc2_hsotg_enqueue_setup()
1320 hsotg->ep0_state = DWC2_EP0_SETUP; in dwc2_hsotg_enqueue_setup()
1322 ret = dwc2_hsotg_ep_queue(&hsotg->eps_out[0]->ep, req, GFP_ATOMIC); in dwc2_hsotg_enqueue_setup()
1324 dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); in dwc2_hsotg_enqueue_setup()
1332 static void dwc2_hsotg_program_zlp(struct dwc2_hsotg *hsotg, in dwc2_hsotg_program_zlp() argument
1341 dev_dbg(hsotg->dev, "Sending zero-length packet on ep%d\n", in dwc2_hsotg_program_zlp()
1344 dev_dbg(hsotg->dev, "Receiving zero-length packet on ep%d\n", in dwc2_hsotg_program_zlp()
1348 DXEPTSIZ_XFERSIZE(0), hsotg->regs + in dwc2_hsotg_program_zlp()
1351 ctrl = dwc2_readl(hsotg->regs + epctl_reg); in dwc2_hsotg_program_zlp()
1355 dwc2_writel(ctrl, hsotg->regs + epctl_reg); in dwc2_hsotg_program_zlp()
1371 static void dwc2_hsotg_complete_request(struct dwc2_hsotg *hsotg, in dwc2_hsotg_complete_request() argument
1379 dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); in dwc2_hsotg_complete_request()
1383 dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", in dwc2_hsotg_complete_request()
1394 if (using_dma(hsotg)) in dwc2_hsotg_complete_request()
1395 dwc2_hsotg_unmap_dma(hsotg, hs_ep, hs_req); in dwc2_hsotg_complete_request()
1397 dwc2_hsotg_handle_unaligned_buf_complete(hsotg, hs_ep, hs_req); in dwc2_hsotg_complete_request()
1408 spin_unlock(&hsotg->lock); in dwc2_hsotg_complete_request()
1410 spin_lock(&hsotg->lock); in dwc2_hsotg_complete_request()
1423 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, false); in dwc2_hsotg_complete_request()
1438 static void dwc2_hsotg_rx_data(struct dwc2_hsotg *hsotg, int ep_idx, int size) in dwc2_hsotg_rx_data() argument
1440 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[ep_idx]; in dwc2_hsotg_rx_data()
1442 void __iomem *fifo = hsotg->regs + EPFIFO(ep_idx); in dwc2_hsotg_rx_data()
1449 u32 epctl = dwc2_readl(hsotg->regs + DOEPCTL(ep_idx)); in dwc2_hsotg_rx_data()
1452 dev_dbg(hsotg->dev, in dwc2_hsotg_rx_data()
1467 dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", in dwc2_hsotg_rx_data()
1503 static void dwc2_hsotg_ep0_zlp(struct dwc2_hsotg *hsotg, bool dir_in) in dwc2_hsotg_ep0_zlp() argument
1506 hsotg->eps_out[0]->dir_in = dir_in; in dwc2_hsotg_ep0_zlp()
1507 hsotg->ep0_state = dir_in ? DWC2_EP0_STATUS_IN : DWC2_EP0_STATUS_OUT; in dwc2_hsotg_ep0_zlp()
1509 dwc2_hsotg_program_zlp(hsotg, hsotg->eps_out[0]); in dwc2_hsotg_ep0_zlp()
1512 static void dwc2_hsotg_change_ep_iso_parity(struct dwc2_hsotg *hsotg, in dwc2_hsotg_change_ep_iso_parity() argument
1517 ctrl = dwc2_readl(hsotg->regs + epctl_reg); in dwc2_hsotg_change_ep_iso_parity()
1522 dwc2_writel(ctrl, hsotg->regs + epctl_reg); in dwc2_hsotg_change_ep_iso_parity()
1534 static void dwc2_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, int epnum) in dwc2_hsotg_handle_outdone() argument
1536 u32 epsize = dwc2_readl(hsotg->regs + DOEPTSIZ(epnum)); in dwc2_hsotg_handle_outdone()
1537 struct dwc2_hsotg_ep *hs_ep = hsotg->eps_out[epnum]; in dwc2_hsotg_handle_outdone()
1544 dev_dbg(hsotg->dev, "%s: no request active\n", __func__); in dwc2_hsotg_handle_outdone()
1548 if (epnum == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_OUT) { in dwc2_hsotg_handle_outdone()
1549 dev_dbg(hsotg->dev, "zlp packet received\n"); in dwc2_hsotg_handle_outdone()
1550 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_handle_outdone()
1551 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_handle_outdone()
1555 if (using_dma(hsotg)) { in dwc2_hsotg_handle_outdone()
1575 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, true); in dwc2_hsotg_handle_outdone()
1580 dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", in dwc2_hsotg_handle_outdone()
1589 if (epnum == 0 && hsotg->ep0_state == DWC2_EP0_DATA_OUT) { in dwc2_hsotg_handle_outdone()
1591 dwc2_hsotg_ep0_zlp(hsotg, true); in dwc2_hsotg_handle_outdone()
1599 if (!using_dma(hsotg)) { in dwc2_hsotg_handle_outdone()
1602 dwc2_hsotg_change_ep_iso_parity(hsotg, DOEPCTL(epnum)); in dwc2_hsotg_handle_outdone()
1605 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, result); in dwc2_hsotg_handle_outdone()
1614 static u32 dwc2_hsotg_read_frameno(struct dwc2_hsotg *hsotg) in dwc2_hsotg_read_frameno() argument
1618 dsts = dwc2_readl(hsotg->regs + DSTS); in dwc2_hsotg_read_frameno()
1641 static void dwc2_hsotg_handle_rx(struct dwc2_hsotg *hsotg) in dwc2_hsotg_handle_rx() argument
1643 u32 grxstsr = dwc2_readl(hsotg->regs + GRXSTSP); in dwc2_hsotg_handle_rx()
1646 WARN_ON(using_dma(hsotg)); in dwc2_hsotg_handle_rx()
1654 dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", in dwc2_hsotg_handle_rx()
1659 dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); in dwc2_hsotg_handle_rx()
1663 dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", in dwc2_hsotg_handle_rx()
1664 dwc2_hsotg_read_frameno(hsotg)); in dwc2_hsotg_handle_rx()
1666 if (!using_dma(hsotg)) in dwc2_hsotg_handle_rx()
1667 dwc2_hsotg_handle_outdone(hsotg, epnum); in dwc2_hsotg_handle_rx()
1671 dev_dbg(hsotg->dev, in dwc2_hsotg_handle_rx()
1673 dwc2_hsotg_read_frameno(hsotg), in dwc2_hsotg_handle_rx()
1674 dwc2_readl(hsotg->regs + DOEPCTL(0))); in dwc2_hsotg_handle_rx()
1680 if (hsotg->ep0_state == DWC2_EP0_SETUP) in dwc2_hsotg_handle_rx()
1681 dwc2_hsotg_handle_outdone(hsotg, epnum); in dwc2_hsotg_handle_rx()
1685 dwc2_hsotg_rx_data(hsotg, epnum, size); in dwc2_hsotg_handle_rx()
1689 dev_dbg(hsotg->dev, in dwc2_hsotg_handle_rx()
1691 dwc2_hsotg_read_frameno(hsotg), in dwc2_hsotg_handle_rx()
1692 dwc2_readl(hsotg->regs + DOEPCTL(0))); in dwc2_hsotg_handle_rx()
1694 WARN_ON(hsotg->ep0_state != DWC2_EP0_SETUP); in dwc2_hsotg_handle_rx()
1696 dwc2_hsotg_rx_data(hsotg, epnum, size); in dwc2_hsotg_handle_rx()
1700 dev_warn(hsotg->dev, "%s: unknown status %08x\n", in dwc2_hsotg_handle_rx()
1703 dwc2_hsotg_dump(hsotg); in dwc2_hsotg_handle_rx()
1739 static void dwc2_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg, in dwc2_hsotg_set_ep_maxpacket() argument
1743 void __iomem *regs = hsotg->regs; in dwc2_hsotg_set_ep_maxpacket()
1748 hs_ep = index_to_ep(hsotg, ep, dir_in); in dwc2_hsotg_set_ep_maxpacket()
1785 dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); in dwc2_hsotg_set_ep_maxpacket()
1793 static void dwc2_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx) in dwc2_hsotg_txfifo_flush() argument
1799 hsotg->regs + GRSTCTL); in dwc2_hsotg_txfifo_flush()
1805 val = dwc2_readl(hsotg->regs + GRSTCTL); in dwc2_hsotg_txfifo_flush()
1811 dev_err(hsotg->dev, in dwc2_hsotg_txfifo_flush()
1829 static int dwc2_hsotg_trytx(struct dwc2_hsotg *hsotg, in dwc2_hsotg_trytx() argument
1840 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, in dwc2_hsotg_trytx()
1846 dev_dbg(hsotg->dev, "trying to write more for ep%d\n", in dwc2_hsotg_trytx()
1848 return dwc2_hsotg_write_fifo(hsotg, hs_ep, hs_req); in dwc2_hsotg_trytx()
1862 static void dwc2_hsotg_complete_in(struct dwc2_hsotg *hsotg, in dwc2_hsotg_complete_in() argument
1866 u32 epsize = dwc2_readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); in dwc2_hsotg_complete_in()
1870 dev_dbg(hsotg->dev, "XferCompl but no req\n"); in dwc2_hsotg_complete_in()
1875 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_IN) { in dwc2_hsotg_complete_in()
1876 dev_dbg(hsotg->dev, "zlp packet sent\n"); in dwc2_hsotg_complete_in()
1877 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_complete_in()
1878 if (hsotg->test_mode) { in dwc2_hsotg_complete_in()
1881 ret = dwc2_hsotg_set_test_mode(hsotg, hsotg->test_mode); in dwc2_hsotg_complete_in()
1883 dev_dbg(hsotg->dev, "Invalid Test #%d\n", in dwc2_hsotg_complete_in()
1884 hsotg->test_mode); in dwc2_hsotg_complete_in()
1885 dwc2_hsotg_stall_ep0(hsotg); in dwc2_hsotg_complete_in()
1889 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_complete_in()
1909 dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n", in dwc2_hsotg_complete_in()
1913 dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", in dwc2_hsotg_complete_in()
1917 dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); in dwc2_hsotg_complete_in()
1918 dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, true); in dwc2_hsotg_complete_in()
1924 dwc2_hsotg_program_zlp(hsotg, hs_ep); in dwc2_hsotg_complete_in()
1930 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_DATA_IN) { in dwc2_hsotg_complete_in()
1932 dwc2_hsotg_ep0_zlp(hsotg, false); in dwc2_hsotg_complete_in()
1936 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in dwc2_hsotg_complete_in()
1947 static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, in dwc2_hsotg_epint() argument
1950 struct dwc2_hsotg_ep *hs_ep = index_to_ep(hsotg, idx, dir_in); in dwc2_hsotg_epint()
1957 ints = dwc2_readl(hsotg->regs + epint_reg); in dwc2_hsotg_epint()
1958 ctrl = dwc2_readl(hsotg->regs + epctl_reg); in dwc2_hsotg_epint()
1961 dwc2_writel(ints, hsotg->regs + epint_reg); in dwc2_hsotg_epint()
1964 dev_err(hsotg->dev, "%s:Interrupt for unconfigured ep%d(%s)\n", in dwc2_hsotg_epint()
1969 dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", in dwc2_hsotg_epint()
1979 dwc2_hsotg_change_ep_iso_parity(hsotg, epctl_reg); in dwc2_hsotg_epint()
1981 dev_dbg(hsotg->dev, in dwc2_hsotg_epint()
1983 __func__, dwc2_readl(hsotg->regs + epctl_reg), in dwc2_hsotg_epint()
1984 dwc2_readl(hsotg->regs + epsiz_reg)); in dwc2_hsotg_epint()
1991 dwc2_hsotg_complete_in(hsotg, hs_ep); in dwc2_hsotg_epint()
1994 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_epint()
1995 } else if (using_dma(hsotg)) { in dwc2_hsotg_epint()
2001 dwc2_hsotg_handle_outdone(hsotg, idx); in dwc2_hsotg_epint()
2006 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); in dwc2_hsotg_epint()
2009 int epctl = dwc2_readl(hsotg->regs + epctl_reg); in dwc2_hsotg_epint()
2011 dwc2_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); in dwc2_hsotg_epint()
2015 int dctl = dwc2_readl(hsotg->regs + DCTL); in dwc2_hsotg_epint()
2018 dwc2_writel(dctl, hsotg->regs + DCTL); in dwc2_hsotg_epint()
2024 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); in dwc2_hsotg_epint()
2027 dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); in dwc2_hsotg_epint()
2029 if (using_dma(hsotg) && idx == 0) { in dwc2_hsotg_epint()
2040 dwc2_hsotg_handle_outdone(hsotg, 0); in dwc2_hsotg_epint()
2045 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); in dwc2_hsotg_epint()
2050 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", in dwc2_hsotg_epint()
2056 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", in dwc2_hsotg_epint()
2061 if (hsotg->dedicated_fifos && in dwc2_hsotg_epint()
2063 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", in dwc2_hsotg_epint()
2065 if (!using_dma(hsotg)) in dwc2_hsotg_epint()
2066 dwc2_hsotg_trytx(hsotg, hs_ep); in dwc2_hsotg_epint()
2078 static void dwc2_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) in dwc2_hsotg_irq_enumdone() argument
2080 u32 dsts = dwc2_readl(hsotg->regs + DSTS); in dwc2_hsotg_irq_enumdone()
2089 dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); in dwc2_hsotg_irq_enumdone()
2101 hsotg->gadget.speed = USB_SPEED_FULL; in dwc2_hsotg_irq_enumdone()
2107 hsotg->gadget.speed = USB_SPEED_HIGH; in dwc2_hsotg_irq_enumdone()
2113 hsotg->gadget.speed = USB_SPEED_LOW; in dwc2_hsotg_irq_enumdone()
2121 dev_info(hsotg->dev, "new device is %s\n", in dwc2_hsotg_irq_enumdone()
2122 usb_speed_string(hsotg->gadget.speed)); in dwc2_hsotg_irq_enumdone()
2132 dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 1); in dwc2_hsotg_irq_enumdone()
2133 dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0); in dwc2_hsotg_irq_enumdone()
2134 for (i = 1; i < hsotg->num_of_eps; i++) { in dwc2_hsotg_irq_enumdone()
2135 if (hsotg->eps_in[i]) in dwc2_hsotg_irq_enumdone()
2136 dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, 1); in dwc2_hsotg_irq_enumdone()
2137 if (hsotg->eps_out[i]) in dwc2_hsotg_irq_enumdone()
2138 dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, 0); in dwc2_hsotg_irq_enumdone()
2144 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_irq_enumdone()
2146 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_irq_enumdone()
2147 dwc2_readl(hsotg->regs + DIEPCTL0), in dwc2_hsotg_irq_enumdone()
2148 dwc2_readl(hsotg->regs + DOEPCTL0)); in dwc2_hsotg_irq_enumdone()
2160 static void kill_all_requests(struct dwc2_hsotg *hsotg, in kill_all_requests() argument
2170 dwc2_hsotg_complete_request(hsotg, ep, req, in kill_all_requests()
2173 if (!hsotg->dedicated_fifos) in kill_all_requests()
2175 size = (dwc2_readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4; in kill_all_requests()
2177 dwc2_hsotg_txfifo_flush(hsotg, ep->fifo_index); in kill_all_requests()
2188 void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_disconnect() argument
2192 if (!hsotg->connected) in dwc2_hsotg_disconnect()
2195 hsotg->connected = 0; in dwc2_hsotg_disconnect()
2196 hsotg->test_mode = 0; in dwc2_hsotg_disconnect()
2198 for (ep = 0; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_disconnect()
2199 if (hsotg->eps_in[ep]) in dwc2_hsotg_disconnect()
2200 kill_all_requests(hsotg, hsotg->eps_in[ep], in dwc2_hsotg_disconnect()
2202 if (hsotg->eps_out[ep]) in dwc2_hsotg_disconnect()
2203 kill_all_requests(hsotg, hsotg->eps_out[ep], in dwc2_hsotg_disconnect()
2207 call_gadget(hsotg, disconnect); in dwc2_hsotg_disconnect()
2208 hsotg->lx_state = DWC2_L3; in dwc2_hsotg_disconnect()
2216 static void dwc2_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic) in dwc2_hsotg_irq_fifoempty() argument
2222 for (epno = 0; epno < hsotg->num_of_eps; epno++) { in dwc2_hsotg_irq_fifoempty()
2223 ep = index_to_ep(hsotg, epno, 1); in dwc2_hsotg_irq_fifoempty()
2235 ret = dwc2_hsotg_trytx(hsotg, ep); in dwc2_hsotg_irq_fifoempty()
2252 static int dwc2_hsotg_corereset(struct dwc2_hsotg *hsotg) in dwc2_hsotg_corereset() argument
2257 dev_dbg(hsotg->dev, "resetting core\n"); in dwc2_hsotg_corereset()
2260 dwc2_writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); in dwc2_hsotg_corereset()
2264 grstctl = dwc2_readl(hsotg->regs + GRSTCTL); in dwc2_hsotg_corereset()
2268 dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); in dwc2_hsotg_corereset()
2275 u32 grstctl = dwc2_readl(hsotg->regs + GRSTCTL); in dwc2_hsotg_corereset()
2278 dev_info(hsotg->dev, in dwc2_hsotg_corereset()
2290 dev_dbg(hsotg->dev, "reset successful\n"); in dwc2_hsotg_corereset()
2300 void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, in dwc2_hsotg_core_init_disconnected() argument
2307 kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); in dwc2_hsotg_core_init_disconnected()
2310 if (dwc2_hsotg_corereset(hsotg)) in dwc2_hsotg_core_init_disconnected()
2319 val = (hsotg->phyif == GUSBCFG_PHYIF8) ? 9 : 5; in dwc2_hsotg_core_init_disconnected()
2320 dwc2_writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | in dwc2_hsotg_core_init_disconnected()
2321 (val << GUSBCFG_USBTRDTIM_SHIFT), hsotg->regs + GUSBCFG); in dwc2_hsotg_core_init_disconnected()
2323 dwc2_hsotg_init_fifo(hsotg); in dwc2_hsotg_core_init_disconnected()
2326 __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_init_disconnected()
2328 dwc2_writel(DCFG_EPMISCNT(1) | DCFG_DEVSPD_HS, hsotg->regs + DCFG); in dwc2_hsotg_core_init_disconnected()
2331 dwc2_writel(0xffffffff, hsotg->regs + GOTGINT); in dwc2_hsotg_core_init_disconnected()
2334 dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); in dwc2_hsotg_core_init_disconnected()
2342 if (hsotg->core_params->external_id_pin_ctl <= 0) in dwc2_hsotg_core_init_disconnected()
2345 dwc2_writel(intmsk, hsotg->regs + GINTMSK); in dwc2_hsotg_core_init_disconnected()
2347 if (using_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
2350 hsotg->regs + GAHBCFG); in dwc2_hsotg_core_init_disconnected()
2352 dwc2_writel(((hsotg->dedicated_fifos) ? in dwc2_hsotg_core_init_disconnected()
2355 GAHBCFG_GLBL_INTR_EN, hsotg->regs + GAHBCFG); in dwc2_hsotg_core_init_disconnected()
2363 dwc2_writel(((hsotg->dedicated_fifos && !using_dma(hsotg)) ? in dwc2_hsotg_core_init_disconnected()
2368 hsotg->regs + DIEPMSK); in dwc2_hsotg_core_init_disconnected()
2374 dwc2_writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | in dwc2_hsotg_core_init_disconnected()
2378 hsotg->regs + DOEPMSK); in dwc2_hsotg_core_init_disconnected()
2380 dwc2_writel(0, hsotg->regs + DAINTMSK); in dwc2_hsotg_core_init_disconnected()
2382 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_core_init_disconnected()
2383 dwc2_readl(hsotg->regs + DIEPCTL0), in dwc2_hsotg_core_init_disconnected()
2384 dwc2_readl(hsotg->regs + DOEPCTL0)); in dwc2_hsotg_core_init_disconnected()
2387 dwc2_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); in dwc2_hsotg_core_init_disconnected()
2394 if (!using_dma(hsotg)) in dwc2_hsotg_core_init_disconnected()
2395 dwc2_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); in dwc2_hsotg_core_init_disconnected()
2398 dwc2_hsotg_ctrl_epint(hsotg, 0, 0, 1); in dwc2_hsotg_core_init_disconnected()
2399 dwc2_hsotg_ctrl_epint(hsotg, 0, 1, 1); in dwc2_hsotg_core_init_disconnected()
2402 __orr32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); in dwc2_hsotg_core_init_disconnected()
2404 __bic32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); in dwc2_hsotg_core_init_disconnected()
2407 dev_dbg(hsotg->dev, "DCTL=0x%08x\n", dwc2_readl(hsotg->regs + DCTL)); in dwc2_hsotg_core_init_disconnected()
2416 DXEPTSIZ_XFERSIZE(8), hsotg->regs + DOEPTSIZ0); in dwc2_hsotg_core_init_disconnected()
2418 dwc2_writel(dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in dwc2_hsotg_core_init_disconnected()
2421 hsotg->regs + DOEPCTL0); in dwc2_hsotg_core_init_disconnected()
2424 dwc2_writel(dwc2_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in dwc2_hsotg_core_init_disconnected()
2425 DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); in dwc2_hsotg_core_init_disconnected()
2427 dwc2_hsotg_enqueue_setup(hsotg); in dwc2_hsotg_core_init_disconnected()
2429 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in dwc2_hsotg_core_init_disconnected()
2430 dwc2_readl(hsotg->regs + DIEPCTL0), in dwc2_hsotg_core_init_disconnected()
2431 dwc2_readl(hsotg->regs + DOEPCTL0)); in dwc2_hsotg_core_init_disconnected()
2437 __orr32(hsotg->regs + DCTL, val); in dwc2_hsotg_core_init_disconnected()
2442 hsotg->lx_state = DWC2_L0; in dwc2_hsotg_core_init_disconnected()
2445 static void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_core_disconnect() argument
2448 __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_disconnect()
2451 void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) in dwc2_hsotg_core_connect() argument
2454 __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); in dwc2_hsotg_core_connect()
2464 struct dwc2_hsotg *hsotg = pw; in dwc2_hsotg_irq() local
2469 spin_lock(&hsotg->lock); in dwc2_hsotg_irq()
2471 gintsts = dwc2_readl(hsotg->regs + GINTSTS); in dwc2_hsotg_irq()
2472 gintmsk = dwc2_readl(hsotg->regs + GINTMSK); in dwc2_hsotg_irq()
2474 dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", in dwc2_hsotg_irq()
2480 dev_dbg(hsotg->dev, "%s: USBRstDet\n", __func__); in dwc2_hsotg_irq()
2482 dwc2_writel(GINTSTS_RESETDET, hsotg->regs + GINTSTS); in dwc2_hsotg_irq()
2485 if (hsotg->lx_state == DWC2_L2) { in dwc2_hsotg_irq()
2486 dwc2_exit_hibernation(hsotg, true); in dwc2_hsotg_irq()
2487 hsotg->lx_state = DWC2_L0; in dwc2_hsotg_irq()
2493 u32 usb_status = dwc2_readl(hsotg->regs + GOTGCTL); in dwc2_hsotg_irq()
2494 u32 connected = hsotg->connected; in dwc2_hsotg_irq()
2496 dev_dbg(hsotg->dev, "%s: USBRst\n", __func__); in dwc2_hsotg_irq()
2497 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", in dwc2_hsotg_irq()
2498 dwc2_readl(hsotg->regs + GNPTXSTS)); in dwc2_hsotg_irq()
2500 dwc2_writel(GINTSTS_USBRST, hsotg->regs + GINTSTS); in dwc2_hsotg_irq()
2503 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_irq()
2506 dwc2_hsotg_core_init_disconnected(hsotg, true); in dwc2_hsotg_irq()
2510 dwc2_writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); in dwc2_hsotg_irq()
2512 dwc2_hsotg_irq_enumdone(hsotg); in dwc2_hsotg_irq()
2516 u32 daint = dwc2_readl(hsotg->regs + DAINT); in dwc2_hsotg_irq()
2517 u32 daintmsk = dwc2_readl(hsotg->regs + DAINTMSK); in dwc2_hsotg_irq()
2525 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); in dwc2_hsotg_irq()
2527 for (ep = 0; ep < hsotg->num_of_eps && daint_out; in dwc2_hsotg_irq()
2530 dwc2_hsotg_epint(hsotg, ep, 0); in dwc2_hsotg_irq()
2533 for (ep = 0; ep < hsotg->num_of_eps && daint_in; in dwc2_hsotg_irq()
2536 dwc2_hsotg_epint(hsotg, ep, 1); in dwc2_hsotg_irq()
2543 dev_dbg(hsotg->dev, "NPTxFEmp\n"); in dwc2_hsotg_irq()
2551 dwc2_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); in dwc2_hsotg_irq()
2552 dwc2_hsotg_irq_fifoempty(hsotg, false); in dwc2_hsotg_irq()
2556 dev_dbg(hsotg->dev, "PTxFEmp\n"); in dwc2_hsotg_irq()
2560 dwc2_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); in dwc2_hsotg_irq()
2561 dwc2_hsotg_irq_fifoempty(hsotg, true); in dwc2_hsotg_irq()
2571 dwc2_hsotg_handle_rx(hsotg); in dwc2_hsotg_irq()
2575 dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); in dwc2_hsotg_irq()
2576 dwc2_writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); in dwc2_hsotg_irq()
2586 dev_info(hsotg->dev, "GOUTNakEff triggered\n"); in dwc2_hsotg_irq()
2588 dwc2_writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); in dwc2_hsotg_irq()
2590 dwc2_hsotg_dump(hsotg); in dwc2_hsotg_irq()
2594 dev_info(hsotg->dev, "GINNakEff triggered\n"); in dwc2_hsotg_irq()
2596 dwc2_writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); in dwc2_hsotg_irq()
2598 dwc2_hsotg_dump(hsotg); in dwc2_hsotg_irq()
2605 dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n", __func__); in dwc2_hsotg_irq()
2606 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_irq()
2607 hs_ep = hsotg->eps_in[idx]; in dwc2_hsotg_irq()
2613 dwc2_hsotg_change_ep_iso_parity(hsotg, epctl_reg); in dwc2_hsotg_irq()
2615 dwc2_writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS); in dwc2_hsotg_irq()
2622 dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__); in dwc2_hsotg_irq()
2623 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_irq()
2624 hs_ep = hsotg->eps_out[idx]; in dwc2_hsotg_irq()
2630 dwc2_hsotg_change_ep_iso_parity(hsotg, epctl_reg); in dwc2_hsotg_irq()
2632 dwc2_writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS); in dwc2_hsotg_irq()
2643 spin_unlock(&hsotg->lock); in dwc2_hsotg_irq()
2659 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_enable() local
2669 dev_dbg(hsotg->dev, in dwc2_hsotg_ep_enable()
2679 dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__); in dwc2_hsotg_ep_enable()
2688 epctrl = dwc2_readl(hsotg->regs + epctrl_reg); in dwc2_hsotg_ep_enable()
2690 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", in dwc2_hsotg_ep_enable()
2693 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_ep_enable()
2714 dwc2_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps, dir_in); in dwc2_hsotg_ep_enable()
2724 dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); in dwc2_hsotg_ep_enable()
2756 hsotg->fifo_map &= ~(1 << hs_ep->fifo_index); in dwc2_hsotg_ep_enable()
2766 if (dir_in && hsotg->dedicated_fifos && !hs_ep->fifo_index) { in dwc2_hsotg_ep_enable()
2770 for (i = 1; i < hsotg->num_of_eps; ++i) { in dwc2_hsotg_ep_enable()
2771 if (hsotg->fifo_map & (1<<i)) in dwc2_hsotg_ep_enable()
2773 val = dwc2_readl(hsotg->regs + DPTXFSIZN(i)); in dwc2_hsotg_ep_enable()
2784 dev_err(hsotg->dev, in dwc2_hsotg_ep_enable()
2789 hsotg->fifo_map |= 1 << fifo_index; in dwc2_hsotg_ep_enable()
2799 dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", in dwc2_hsotg_ep_enable()
2802 dwc2_writel(epctrl, hsotg->regs + epctrl_reg); in dwc2_hsotg_ep_enable()
2803 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", in dwc2_hsotg_ep_enable()
2804 __func__, dwc2_readl(hsotg->regs + epctrl_reg)); in dwc2_hsotg_ep_enable()
2807 dwc2_hsotg_ctrl_epint(hsotg, index, dir_in, 1); in dwc2_hsotg_ep_enable()
2810 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_ep_enable()
2821 struct dwc2_hsotg *hsotg = hs_ep->parent; in dwc2_hsotg_ep_disable() local
2828 dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); in dwc2_hsotg_ep_disable()
2830 if (ep == &hsotg->eps_out[0]->ep) { in dwc2_hsotg_ep_disable()
2831 dev_err(hsotg->dev, "%s: called for ep0\n", __func__); in dwc2_hsotg_ep_disable()
2837 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_ep_disable()
2839 hsotg->fifo_map &= ~(1<<hs_ep->fifo_index); in dwc2_hsotg_ep_disable()
2843 ctrl = dwc2_readl(hsotg->regs + epctrl_reg); in dwc2_hsotg_ep_disable()
2848 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in dwc2_hsotg_ep_disable()
2849 dwc2_writel(ctrl, hsotg->regs + epctrl_reg); in dwc2_hsotg_ep_disable()
2852 dwc2_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); in dwc2_hsotg_ep_disable()
2855 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN); in dwc2_hsotg_ep_disable()
2857 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_ep_disable()
2892 static void dwc2_hsotg_ep_stop_xfr(struct dwc2_hsotg *hsotg, in dwc2_hsotg_ep_stop_xfr() argument
2903 dev_dbg(hsotg->dev, "%s: stopping transfer on %s\n", __func__, in dwc2_hsotg_ep_stop_xfr()
2906 __orr32(hsotg->regs + epctrl_reg, DXEPCTL_SNAK); in dwc2_hsotg_ep_stop_xfr()
2908 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, in dwc2_hsotg_ep_stop_xfr()
2910 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
2914 dwc2_writel(GINTSTS_GINNAKEFF, hsotg->regs + GINTSTS); in dwc2_hsotg_ep_stop_xfr()
2916 __orr32(hsotg->regs + DCTL, DCTL_SGNPINNAK); in dwc2_hsotg_ep_stop_xfr()
2919 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, in dwc2_hsotg_ep_stop_xfr()
2921 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
2926 __orr32(hsotg->regs + epctrl_reg, DXEPCTL_EPDIS | DXEPCTL_SNAK); in dwc2_hsotg_ep_stop_xfr()
2929 if (dwc2_hsotg_wait_bit_set(hsotg, epint_reg, DXEPINT_EPDISBLD, 100)) in dwc2_hsotg_ep_stop_xfr()
2930 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
2934 if (hsotg->dedicated_fifos) { in dwc2_hsotg_ep_stop_xfr()
2936 GRSTCTL_TXFFLSH, hsotg->regs + GRSTCTL); in dwc2_hsotg_ep_stop_xfr()
2938 if (dwc2_hsotg_wait_bit_set(hsotg, GRSTCTL, in dwc2_hsotg_ep_stop_xfr()
2940 dev_warn(hsotg->dev, in dwc2_hsotg_ep_stop_xfr()
2947 __bic32(hsotg->regs + DCTL, DCTL_SGNPINNAK); in dwc2_hsotg_ep_stop_xfr()
3079 static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg) in dwc2_hsotg_init() argument
3086 hsotg->regs + DIEPMSK); in dwc2_hsotg_init()
3090 hsotg->regs + DOEPMSK); in dwc2_hsotg_init()
3092 dwc2_writel(0, hsotg->regs + DAINTMSK); in dwc2_hsotg_init()
3095 __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); in dwc2_hsotg_init()
3099 dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", in dwc2_hsotg_init()
3100 dwc2_readl(hsotg->regs + GRXFSIZ), in dwc2_hsotg_init()
3101 dwc2_readl(hsotg->regs + GNPTXFSIZ)); in dwc2_hsotg_init()
3103 dwc2_hsotg_init_fifo(hsotg); in dwc2_hsotg_init()
3106 trdtim = (hsotg->phyif == GUSBCFG_PHYIF8) ? 9 : 5; in dwc2_hsotg_init()
3107 dwc2_writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | in dwc2_hsotg_init()
3109 hsotg->regs + GUSBCFG); in dwc2_hsotg_init()
3111 if (using_dma(hsotg)) in dwc2_hsotg_init()
3112 __orr32(hsotg->regs + GAHBCFG, GAHBCFG_DMA_EN); in dwc2_hsotg_init()
3126 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_udc_start() local
3130 if (!hsotg) { in dwc2_hsotg_udc_start()
3136 dev_err(hsotg->dev, "%s: no driver\n", __func__); in dwc2_hsotg_udc_start()
3141 dev_err(hsotg->dev, "%s: bad speed\n", __func__); in dwc2_hsotg_udc_start()
3144 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); in dwc2_hsotg_udc_start()
3148 WARN_ON(hsotg->driver); in dwc2_hsotg_udc_start()
3151 hsotg->driver = driver; in dwc2_hsotg_udc_start()
3152 hsotg->gadget.dev.of_node = hsotg->dev->of_node; in dwc2_hsotg_udc_start()
3153 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_udc_start()
3155 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { in dwc2_hsotg_udc_start()
3156 ret = dwc2_lowlevel_hw_enable(hsotg); in dwc2_hsotg_udc_start()
3161 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_udc_start()
3162 otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget); in dwc2_hsotg_udc_start()
3164 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_udc_start()
3165 dwc2_hsotg_init(hsotg); in dwc2_hsotg_udc_start()
3166 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_udc_start()
3167 hsotg->enabled = 0; in dwc2_hsotg_udc_start()
3168 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_udc_start()
3170 dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); in dwc2_hsotg_udc_start()
3175 hsotg->driver = NULL; in dwc2_hsotg_udc_start()
3188 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_udc_stop() local
3192 if (!hsotg) in dwc2_hsotg_udc_stop()
3196 for (ep = 1; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_udc_stop()
3197 if (hsotg->eps_in[ep]) in dwc2_hsotg_udc_stop()
3198 dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_udc_stop()
3199 if (hsotg->eps_out[ep]) in dwc2_hsotg_udc_stop()
3200 dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_udc_stop()
3203 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_udc_stop()
3205 hsotg->driver = NULL; in dwc2_hsotg_udc_stop()
3206 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_udc_stop()
3207 hsotg->enabled = 0; in dwc2_hsotg_udc_stop()
3209 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_udc_stop()
3211 if (!IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_udc_stop()
3212 otg_set_peripheral(hsotg->uphy->otg, NULL); in dwc2_hsotg_udc_stop()
3214 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_hsotg_udc_stop()
3215 dwc2_lowlevel_hw_disable(hsotg); in dwc2_hsotg_udc_stop()
3240 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_pullup() local
3243 dev_dbg(hsotg->dev, "%s: is_on: %d op_state: %d\n", __func__, is_on, in dwc2_hsotg_pullup()
3244 hsotg->op_state); in dwc2_hsotg_pullup()
3247 if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) { in dwc2_hsotg_pullup()
3248 hsotg->enabled = is_on; in dwc2_hsotg_pullup()
3252 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_pullup()
3254 hsotg->enabled = 1; in dwc2_hsotg_pullup()
3255 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_pullup()
3256 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_pullup()
3258 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_pullup()
3259 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_pullup()
3260 hsotg->enabled = 0; in dwc2_hsotg_pullup()
3263 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_pullup()
3264 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_pullup()
3271 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_vbus_session() local
3274 dev_dbg(hsotg->dev, "%s: is_active: %d\n", __func__, is_active); in dwc2_hsotg_vbus_session()
3275 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_vbus_session()
3281 if (hsotg->lx_state == DWC2_L2) in dwc2_hsotg_vbus_session()
3282 dwc2_exit_hibernation(hsotg, false); in dwc2_hsotg_vbus_session()
3285 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_hsotg_vbus_session()
3287 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_vbus_session()
3288 if (hsotg->enabled) in dwc2_hsotg_vbus_session()
3289 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_vbus_session()
3291 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_vbus_session()
3292 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_vbus_session()
3295 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_vbus_session()
3308 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in dwc2_hsotg_vbus_draw() local
3310 if (IS_ERR_OR_NULL(hsotg->uphy)) in dwc2_hsotg_vbus_draw()
3312 return usb_phy_set_power(hsotg->uphy, mA); in dwc2_hsotg_vbus_draw()
3334 static void dwc2_hsotg_initep(struct dwc2_hsotg *hsotg, in dwc2_hsotg_initep() argument
3358 list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); in dwc2_hsotg_initep()
3360 hs_ep->parent = hsotg; in dwc2_hsotg_initep()
3383 if (using_dma(hsotg)) { in dwc2_hsotg_initep()
3386 dwc2_writel(next, hsotg->regs + DIEPCTL(epnum)); in dwc2_hsotg_initep()
3388 dwc2_writel(next, hsotg->regs + DOEPCTL(epnum)); in dwc2_hsotg_initep()
3398 static int dwc2_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) in dwc2_hsotg_hw_cfg() argument
3406 cfg = dwc2_readl(hsotg->regs + GHWCFG2); in dwc2_hsotg_hw_cfg()
3407 hsotg->num_of_eps = (cfg >> GHWCFG2_NUM_DEV_EP_SHIFT) & 0xF; in dwc2_hsotg_hw_cfg()
3409 hsotg->num_of_eps++; in dwc2_hsotg_hw_cfg()
3411 hsotg->eps_in[0] = devm_kzalloc(hsotg->dev, sizeof(struct dwc2_hsotg_ep), in dwc2_hsotg_hw_cfg()
3413 if (!hsotg->eps_in[0]) in dwc2_hsotg_hw_cfg()
3416 hsotg->eps_out[0] = hsotg->eps_in[0]; in dwc2_hsotg_hw_cfg()
3418 cfg = dwc2_readl(hsotg->regs + GHWCFG1); in dwc2_hsotg_hw_cfg()
3419 for (i = 1, cfg >>= 2; i < hsotg->num_of_eps; i++, cfg >>= 2) { in dwc2_hsotg_hw_cfg()
3423 hsotg->eps_in[i] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
3425 if (!hsotg->eps_in[i]) in dwc2_hsotg_hw_cfg()
3430 hsotg->eps_out[i] = devm_kzalloc(hsotg->dev, in dwc2_hsotg_hw_cfg()
3432 if (!hsotg->eps_out[i]) in dwc2_hsotg_hw_cfg()
3437 cfg = dwc2_readl(hsotg->regs + GHWCFG3); in dwc2_hsotg_hw_cfg()
3438 hsotg->fifo_mem = (cfg >> GHWCFG3_DFIFO_DEPTH_SHIFT); in dwc2_hsotg_hw_cfg()
3440 cfg = dwc2_readl(hsotg->regs + GHWCFG4); in dwc2_hsotg_hw_cfg()
3441 hsotg->dedicated_fifos = (cfg >> GHWCFG4_DED_FIFO_SHIFT) & 1; in dwc2_hsotg_hw_cfg()
3443 dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", in dwc2_hsotg_hw_cfg()
3444 hsotg->num_of_eps, in dwc2_hsotg_hw_cfg()
3445 hsotg->dedicated_fifos ? "dedicated" : "shared", in dwc2_hsotg_hw_cfg()
3446 hsotg->fifo_mem); in dwc2_hsotg_hw_cfg()
3454 static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg) in dwc2_hsotg_dump() argument
3457 struct device *dev = hsotg->dev; in dwc2_hsotg_dump()
3458 void __iomem *regs = hsotg->regs; in dwc2_hsotg_dump()
3474 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_dump()
3481 for (idx = 0; idx < hsotg->num_of_eps; idx++) { in dwc2_hsotg_dump()
3503 static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg) in dwc2_hsotg_of_probe() argument
3505 struct device_node *np = hsotg->dev->of_node; in dwc2_hsotg_of_probe()
3510 hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma"); in dwc2_hsotg_of_probe()
3523 &hsotg->g_tx_fifo_sz[1], len)) in dwc2_hsotg_of_probe()
3532 hsotg->g_tx_fifo_sz[i] = 0; in dwc2_hsotg_of_probe()
3537 of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz); in dwc2_hsotg_of_probe()
3541 &hsotg->g_np_g_tx_fifo_sz); in dwc2_hsotg_of_probe()
3544 static inline void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg) { } in dwc2_hsotg_of_probe() argument
3552 int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) in dwc2_gadget_init() argument
3554 struct device *dev = hsotg->dev; in dwc2_gadget_init()
3561 hsotg->g_rx_fifo_sz = 2048; in dwc2_gadget_init()
3562 hsotg->g_np_g_tx_fifo_sz = 1024; in dwc2_gadget_init()
3563 memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo)); in dwc2_gadget_init()
3565 dwc2_hsotg_of_probe(hsotg); in dwc2_gadget_init()
3568 hsotg->g_np_g_tx_fifo_sz); in dwc2_gadget_init()
3569 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz); in dwc2_gadget_init()
3572 hsotg->g_tx_fifo_sz[i]); in dwc2_gadget_init()
3574 hsotg->gadget.max_speed = USB_SPEED_HIGH; in dwc2_gadget_init()
3575 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops; in dwc2_gadget_init()
3576 hsotg->gadget.name = dev_name(dev); in dwc2_gadget_init()
3577 if (hsotg->dr_mode == USB_DR_MODE_OTG) in dwc2_gadget_init()
3578 hsotg->gadget.is_otg = 1; in dwc2_gadget_init()
3579 else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) in dwc2_gadget_init()
3580 hsotg->op_state = OTG_STATE_B_PERIPHERAL; in dwc2_gadget_init()
3586 __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEHOSTMODE); in dwc2_gadget_init()
3587 __orr32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); in dwc2_gadget_init()
3595 dwc2_hsotg_corereset(hsotg); in dwc2_gadget_init()
3596 ret = dwc2_hsotg_hw_cfg(hsotg); in dwc2_gadget_init()
3598 dev_err(hsotg->dev, "Hardware configuration failed: %d\n", ret); in dwc2_gadget_init()
3602 dwc2_hsotg_init(hsotg); in dwc2_gadget_init()
3605 __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); in dwc2_gadget_init()
3607 hsotg->ctrl_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
3609 if (!hsotg->ctrl_buff) { in dwc2_gadget_init()
3614 hsotg->ep0_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
3616 if (!hsotg->ep0_buff) { in dwc2_gadget_init()
3621 ret = devm_request_irq(hsotg->dev, irq, dwc2_hsotg_irq, IRQF_SHARED, in dwc2_gadget_init()
3622 dev_name(hsotg->dev), hsotg); in dwc2_gadget_init()
3630 if (hsotg->num_of_eps == 0) { in dwc2_gadget_init()
3637 INIT_LIST_HEAD(&hsotg->gadget.ep_list); in dwc2_gadget_init()
3638 hsotg->gadget.ep0 = &hsotg->eps_out[0]->ep; in dwc2_gadget_init()
3642 hsotg->ctrl_req = dwc2_hsotg_ep_alloc_request(&hsotg->eps_out[0]->ep, in dwc2_gadget_init()
3644 if (!hsotg->ctrl_req) { in dwc2_gadget_init()
3650 for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) { in dwc2_gadget_init()
3651 if (hsotg->eps_in[epnum]) in dwc2_gadget_init()
3652 dwc2_hsotg_initep(hsotg, hsotg->eps_in[epnum], in dwc2_gadget_init()
3654 if (hsotg->eps_out[epnum]) in dwc2_gadget_init()
3655 dwc2_hsotg_initep(hsotg, hsotg->eps_out[epnum], in dwc2_gadget_init()
3659 ret = usb_add_gadget_udc(dev, &hsotg->gadget); in dwc2_gadget_init()
3663 dwc2_hsotg_dump(hsotg); in dwc2_gadget_init()
3672 int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg) in dwc2_hsotg_remove() argument
3674 usb_del_gadget_udc(&hsotg->gadget); in dwc2_hsotg_remove()
3679 int dwc2_hsotg_suspend(struct dwc2_hsotg *hsotg) in dwc2_hsotg_suspend() argument
3683 if (hsotg->lx_state != DWC2_L0) in dwc2_hsotg_suspend()
3686 if (hsotg->driver) { in dwc2_hsotg_suspend()
3689 dev_info(hsotg->dev, "suspending usb gadget %s\n", in dwc2_hsotg_suspend()
3690 hsotg->driver->driver.name); in dwc2_hsotg_suspend()
3692 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_suspend()
3693 if (hsotg->enabled) in dwc2_hsotg_suspend()
3694 dwc2_hsotg_core_disconnect(hsotg); in dwc2_hsotg_suspend()
3695 dwc2_hsotg_disconnect(hsotg); in dwc2_hsotg_suspend()
3696 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in dwc2_hsotg_suspend()
3697 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_suspend()
3699 for (ep = 0; ep < hsotg->num_of_eps; ep++) { in dwc2_hsotg_suspend()
3700 if (hsotg->eps_in[ep]) in dwc2_hsotg_suspend()
3701 dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); in dwc2_hsotg_suspend()
3702 if (hsotg->eps_out[ep]) in dwc2_hsotg_suspend()
3703 dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); in dwc2_hsotg_suspend()
3710 int dwc2_hsotg_resume(struct dwc2_hsotg *hsotg) in dwc2_hsotg_resume() argument
3714 if (hsotg->lx_state == DWC2_L2) in dwc2_hsotg_resume()
3717 if (hsotg->driver) { in dwc2_hsotg_resume()
3718 dev_info(hsotg->dev, "resuming usb gadget %s\n", in dwc2_hsotg_resume()
3719 hsotg->driver->driver.name); in dwc2_hsotg_resume()
3721 spin_lock_irqsave(&hsotg->lock, flags); in dwc2_hsotg_resume()
3722 dwc2_hsotg_core_init_disconnected(hsotg, false); in dwc2_hsotg_resume()
3723 if (hsotg->enabled) in dwc2_hsotg_resume()
3724 dwc2_hsotg_core_connect(hsotg); in dwc2_hsotg_resume()
3725 spin_unlock_irqrestore(&hsotg->lock, flags); in dwc2_hsotg_resume()