Lines Matching refs:hsotg
69 static inline struct s3c_hsotg_ep *index_to_ep(struct dwc2_hsotg *hsotg, in index_to_ep() argument
73 return hsotg->eps_in[ep_index]; in index_to_ep()
75 return hsotg->eps_out[ep_index]; in index_to_ep()
79 static void s3c_hsotg_dump(struct dwc2_hsotg *hsotg);
100 static inline bool using_dma(struct dwc2_hsotg *hsotg) in using_dma() argument
102 return hsotg->g_using_dma; in using_dma()
110 static void s3c_hsotg_en_gsint(struct dwc2_hsotg *hsotg, u32 ints) in s3c_hsotg_en_gsint() argument
112 u32 gsintmsk = readl(hsotg->regs + GINTMSK); in s3c_hsotg_en_gsint()
118 dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); in s3c_hsotg_en_gsint()
119 writel(new_gsintmsk, hsotg->regs + GINTMSK); in s3c_hsotg_en_gsint()
128 static void s3c_hsotg_disable_gsint(struct dwc2_hsotg *hsotg, u32 ints) in s3c_hsotg_disable_gsint() argument
130 u32 gsintmsk = readl(hsotg->regs + GINTMSK); in s3c_hsotg_disable_gsint()
136 writel(new_gsintmsk, hsotg->regs + GINTMSK); in s3c_hsotg_disable_gsint()
149 static void s3c_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg, in s3c_hsotg_ctrl_epint() argument
161 daint = readl(hsotg->regs + DAINTMSK); in s3c_hsotg_ctrl_epint()
166 writel(daint, hsotg->regs + DAINTMSK); in s3c_hsotg_ctrl_epint()
174 static void s3c_hsotg_init_fifo(struct dwc2_hsotg *hsotg) in s3c_hsotg_init_fifo() argument
182 WARN_ON(hsotg->fifo_map); in s3c_hsotg_init_fifo()
183 hsotg->fifo_map = 0; in s3c_hsotg_init_fifo()
186 writel(hsotg->g_rx_fifo_sz, hsotg->regs + GRXFSIZ); in s3c_hsotg_init_fifo()
187 writel((hsotg->g_rx_fifo_sz << FIFOSIZE_STARTADDR_SHIFT) | in s3c_hsotg_init_fifo()
188 (hsotg->g_np_g_tx_fifo_sz << FIFOSIZE_DEPTH_SHIFT), in s3c_hsotg_init_fifo()
189 hsotg->regs + GNPTXFSIZ); in s3c_hsotg_init_fifo()
199 addr = hsotg->g_rx_fifo_sz + hsotg->g_np_g_tx_fifo_sz; in s3c_hsotg_init_fifo()
207 if (!hsotg->g_tx_fifo_sz[ep]) in s3c_hsotg_init_fifo()
210 val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT; in s3c_hsotg_init_fifo()
211 WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem, in s3c_hsotg_init_fifo()
213 addr += hsotg->g_tx_fifo_sz[ep]; in s3c_hsotg_init_fifo()
215 writel(val, hsotg->regs + DPTXFSIZN(ep)); in s3c_hsotg_init_fifo()
224 GRSTCTL_RXFFLSH, hsotg->regs + GRSTCTL); in s3c_hsotg_init_fifo()
229 val = readl(hsotg->regs + GRSTCTL); in s3c_hsotg_init_fifo()
235 dev_err(hsotg->dev, in s3c_hsotg_init_fifo()
244 dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout); in s3c_hsotg_init_fifo()
288 static void s3c_hsotg_unmap_dma(struct dwc2_hsotg *hsotg, in s3c_hsotg_unmap_dma() argument
298 usb_gadget_unmap_request(&hsotg->gadget, req, hs_ep->dir_in); in s3c_hsotg_unmap_dma()
317 static int s3c_hsotg_write_fifo(struct dwc2_hsotg *hsotg, in s3c_hsotg_write_fifo() argument
322 u32 gnptxsts = readl(hsotg->regs + GNPTXSTS); in s3c_hsotg_write_fifo()
336 if (periodic && !hsotg->dedicated_fifos) { in s3c_hsotg_write_fifo()
337 u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); in s3c_hsotg_write_fifo()
353 s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in s3c_hsotg_write_fifo()
357 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", in s3c_hsotg_write_fifo()
366 dev_dbg(hsotg->dev, "%s: => can_write1=%d\n", in s3c_hsotg_write_fifo()
370 dev_dbg(hsotg->dev, "%s: => can_write2=%d\n", in s3c_hsotg_write_fifo()
374 s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); in s3c_hsotg_write_fifo()
377 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { in s3c_hsotg_write_fifo()
378 can_write = readl(hsotg->regs + DTXFSTS(hs_ep->index)); in s3c_hsotg_write_fifo()
384 dev_dbg(hsotg->dev, in s3c_hsotg_write_fifo()
388 s3c_hsotg_en_gsint(hsotg, GINTSTS_NPTXFEMP); in s3c_hsotg_write_fifo()
398 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n", in s3c_hsotg_write_fifo()
418 if (!hsotg->dedicated_fifos) in s3c_hsotg_write_fifo()
419 s3c_hsotg_en_gsint(hsotg, in s3c_hsotg_write_fifo()
447 if (!hsotg->dedicated_fifos) in s3c_hsotg_write_fifo()
448 s3c_hsotg_en_gsint(hsotg, in s3c_hsotg_write_fifo()
453 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", in s3c_hsotg_write_fifo()
468 iowrite32_rep(hsotg->regs + EPFIFO(hs_ep->index), data, to_write); in s3c_hsotg_write_fifo()
522 static void s3c_hsotg_start_req(struct dwc2_hsotg *hsotg, in s3c_hsotg_start_req() argument
540 dev_err(hsotg->dev, "%s: active request\n", __func__); in s3c_hsotg_start_req()
544 dev_err(hsotg->dev, in s3c_hsotg_start_req()
554 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", in s3c_hsotg_start_req()
555 __func__, readl(hsotg->regs + epctrl_reg), index, in s3c_hsotg_start_req()
559 ctrl = readl(hsotg->regs + epctrl_reg); in s3c_hsotg_start_req()
562 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); in s3c_hsotg_start_req()
567 dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n", in s3c_hsotg_start_req()
574 dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n", in s3c_hsotg_start_req()
590 dev_err(hsotg->dev, "req length > maxpacket*mc\n"); in s3c_hsotg_start_req()
616 dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", in s3c_hsotg_start_req()
623 writel(epsize, hsotg->regs + epsize_reg); in s3c_hsotg_start_req()
625 if (using_dma(hsotg) && !continuing) { in s3c_hsotg_start_req()
634 writel(ureq->dma, hsotg->regs + dma_reg); in s3c_hsotg_start_req()
636 dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", in s3c_hsotg_start_req()
643 dev_dbg(hsotg->dev, "ep0 state:%d\n", hsotg->ep0_state); in s3c_hsotg_start_req()
646 if (!(index == 0 && hsotg->ep0_state == DWC2_EP0_SETUP)) in s3c_hsotg_start_req()
649 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in s3c_hsotg_start_req()
650 writel(ctrl, hsotg->regs + epctrl_reg); in s3c_hsotg_start_req()
660 if (dir_in && !using_dma(hsotg)) { in s3c_hsotg_start_req()
664 s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); in s3c_hsotg_start_req()
673 hsotg->regs + DIEPINT(index)); in s3c_hsotg_start_req()
681 if (!(readl(hsotg->regs + epctrl_reg) & DXEPCTL_EPENA)) in s3c_hsotg_start_req()
682 dev_dbg(hsotg->dev, in s3c_hsotg_start_req()
684 index, readl(hsotg->regs + epctrl_reg)); in s3c_hsotg_start_req()
686 dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", in s3c_hsotg_start_req()
687 __func__, readl(hsotg->regs + epctrl_reg)); in s3c_hsotg_start_req()
690 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1); in s3c_hsotg_start_req()
705 static int s3c_hsotg_map_dma(struct dwc2_hsotg *hsotg, in s3c_hsotg_map_dma() argument
716 ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in); in s3c_hsotg_map_dma()
723 dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n", in s3c_hsotg_map_dma()
729 static int s3c_hsotg_handle_unaligned_buf_start(struct dwc2_hsotg *hsotg, in s3c_hsotg_handle_unaligned_buf_start() argument
735 if (!using_dma(hsotg) || !((long)req_buf & 3)) in s3c_hsotg_handle_unaligned_buf_start()
740 dev_dbg(hsotg->dev, "%s: %s: buf=%p length=%d\n", __func__, in s3c_hsotg_handle_unaligned_buf_start()
746 dev_err(hsotg->dev, in s3c_hsotg_handle_unaligned_buf_start()
760 static void s3c_hsotg_handle_unaligned_buf_complete(struct dwc2_hsotg *hsotg, in s3c_hsotg_handle_unaligned_buf_complete() argument
764 if (!using_dma(hsotg) || !hs_req->saved_req_buf) in s3c_hsotg_handle_unaligned_buf_complete()
767 dev_dbg(hsotg->dev, "%s: %s: status=%d actual-length=%d\n", __func__, in s3c_hsotg_handle_unaligned_buf_complete()
855 struct dwc2_hsotg *hsotg = hs_ep->parent; in s3c_hsotg_complete_oursetup() local
857 dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req); in s3c_hsotg_complete_oursetup()
870 static struct s3c_hsotg_ep *ep_from_windex(struct dwc2_hsotg *hsotg, in ep_from_windex() argument
880 if (idx > hsotg->num_of_eps) in ep_from_windex()
883 ep = index_to_ep(hsotg, idx, dir); in ep_from_windex()
897 static int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode) in s3c_hsotg_set_test_mode() argument
899 int dctl = readl(hsotg->regs + DCTL); in s3c_hsotg_set_test_mode()
913 writel(dctl, hsotg->regs + DCTL); in s3c_hsotg_set_test_mode()
927 static int s3c_hsotg_send_reply(struct dwc2_hsotg *hsotg, in s3c_hsotg_send_reply() argument
935 dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length); in s3c_hsotg_send_reply()
938 hsotg->ep0_reply = req; in s3c_hsotg_send_reply()
940 dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__); in s3c_hsotg_send_reply()
944 req->buf = hsotg->ep0_buff; in s3c_hsotg_send_reply()
958 dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__); in s3c_hsotg_send_reply()
970 static int s3c_hsotg_process_req_status(struct dwc2_hsotg *hsotg, in s3c_hsotg_process_req_status() argument
973 struct s3c_hsotg_ep *ep0 = hsotg->eps_out[0]; in s3c_hsotg_process_req_status()
978 dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__); in s3c_hsotg_process_req_status()
981 dev_warn(hsotg->dev, "%s: direction out?\n", __func__); in s3c_hsotg_process_req_status()
997 ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex)); in s3c_hsotg_process_req_status()
1011 ret = s3c_hsotg_send_reply(hsotg, ep0, &reply, 2); in s3c_hsotg_process_req_status()
1013 dev_err(hsotg->dev, "%s: failed to send reply\n", __func__); in s3c_hsotg_process_req_status()
1041 static int s3c_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, in s3c_hsotg_process_req_feature() argument
1044 struct s3c_hsotg_ep *ep0 = hsotg->eps_out[0]; in s3c_hsotg_process_req_feature()
1055 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", in s3c_hsotg_process_req_feature()
1071 hsotg->test_mode = wIndex >> 8; in s3c_hsotg_process_req_feature()
1072 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); in s3c_hsotg_process_req_feature()
1074 dev_err(hsotg->dev, in s3c_hsotg_process_req_feature()
1085 ep = ep_from_windex(hsotg, wIndex); in s3c_hsotg_process_req_feature()
1087 dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n", in s3c_hsotg_process_req_feature()
1098 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); in s3c_hsotg_process_req_feature()
1100 dev_err(hsotg->dev, in s3c_hsotg_process_req_feature()
1120 spin_unlock(&hsotg->lock); in s3c_hsotg_process_req_feature()
1123 spin_lock(&hsotg->lock); in s3c_hsotg_process_req_feature()
1132 s3c_hsotg_start_req(hsotg, ep, in s3c_hsotg_process_req_feature()
1150 static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg);
1158 static void s3c_hsotg_stall_ep0(struct dwc2_hsotg *hsotg) in s3c_hsotg_stall_ep0() argument
1160 struct s3c_hsotg_ep *ep0 = hsotg->eps_out[0]; in s3c_hsotg_stall_ep0()
1164 dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); in s3c_hsotg_stall_ep0()
1172 ctrl = readl(hsotg->regs + reg); in s3c_hsotg_stall_ep0()
1175 writel(ctrl, hsotg->regs + reg); in s3c_hsotg_stall_ep0()
1177 dev_dbg(hsotg->dev, in s3c_hsotg_stall_ep0()
1179 ctrl, reg, readl(hsotg->regs + reg)); in s3c_hsotg_stall_ep0()
1185 s3c_hsotg_enqueue_setup(hsotg); in s3c_hsotg_stall_ep0()
1197 static void s3c_hsotg_process_control(struct dwc2_hsotg *hsotg, in s3c_hsotg_process_control() argument
1200 struct s3c_hsotg_ep *ep0 = hsotg->eps_out[0]; in s3c_hsotg_process_control()
1204 dev_dbg(hsotg->dev, "ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n", in s3c_hsotg_process_control()
1210 hsotg->ep0_state = DWC2_EP0_STATUS_IN; in s3c_hsotg_process_control()
1213 hsotg->ep0_state = DWC2_EP0_DATA_IN; in s3c_hsotg_process_control()
1216 hsotg->ep0_state = DWC2_EP0_DATA_OUT; in s3c_hsotg_process_control()
1222 hsotg->connected = 1; in s3c_hsotg_process_control()
1223 dcfg = readl(hsotg->regs + DCFG); in s3c_hsotg_process_control()
1227 writel(dcfg, hsotg->regs + DCFG); in s3c_hsotg_process_control()
1229 dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); in s3c_hsotg_process_control()
1231 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); in s3c_hsotg_process_control()
1235 ret = s3c_hsotg_process_req_status(hsotg, ctrl); in s3c_hsotg_process_control()
1240 ret = s3c_hsotg_process_req_feature(hsotg, ctrl); in s3c_hsotg_process_control()
1247 if (ret == 0 && hsotg->driver) { in s3c_hsotg_process_control()
1248 spin_unlock(&hsotg->lock); in s3c_hsotg_process_control()
1249 ret = hsotg->driver->setup(&hsotg->gadget, ctrl); in s3c_hsotg_process_control()
1250 spin_lock(&hsotg->lock); in s3c_hsotg_process_control()
1252 dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); in s3c_hsotg_process_control()
1261 s3c_hsotg_stall_ep0(hsotg); in s3c_hsotg_process_control()
1276 struct dwc2_hsotg *hsotg = hs_ep->parent; in s3c_hsotg_complete_setup() local
1279 dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status); in s3c_hsotg_complete_setup()
1283 spin_lock(&hsotg->lock); in s3c_hsotg_complete_setup()
1285 s3c_hsotg_enqueue_setup(hsotg); in s3c_hsotg_complete_setup()
1287 s3c_hsotg_process_control(hsotg, req->buf); in s3c_hsotg_complete_setup()
1288 spin_unlock(&hsotg->lock); in s3c_hsotg_complete_setup()
1298 static void s3c_hsotg_enqueue_setup(struct dwc2_hsotg *hsotg) in s3c_hsotg_enqueue_setup() argument
1300 struct usb_request *req = hsotg->ctrl_req; in s3c_hsotg_enqueue_setup()
1304 dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__); in s3c_hsotg_enqueue_setup()
1308 req->buf = hsotg->ctrl_buff; in s3c_hsotg_enqueue_setup()
1312 dev_dbg(hsotg->dev, "%s already queued???\n", __func__); in s3c_hsotg_enqueue_setup()
1316 hsotg->eps_out[0]->dir_in = 0; in s3c_hsotg_enqueue_setup()
1317 hsotg->eps_out[0]->send_zlp = 0; in s3c_hsotg_enqueue_setup()
1318 hsotg->ep0_state = DWC2_EP0_SETUP; in s3c_hsotg_enqueue_setup()
1320 ret = s3c_hsotg_ep_queue(&hsotg->eps_out[0]->ep, req, GFP_ATOMIC); in s3c_hsotg_enqueue_setup()
1322 dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); in s3c_hsotg_enqueue_setup()
1330 static void s3c_hsotg_program_zlp(struct dwc2_hsotg *hsotg, in s3c_hsotg_program_zlp() argument
1339 dev_dbg(hsotg->dev, "Sending zero-length packet on ep%d\n", in s3c_hsotg_program_zlp()
1342 dev_dbg(hsotg->dev, "Receiving zero-length packet on ep%d\n", in s3c_hsotg_program_zlp()
1346 DXEPTSIZ_XFERSIZE(0), hsotg->regs + in s3c_hsotg_program_zlp()
1349 ctrl = readl(hsotg->regs + epctl_reg); in s3c_hsotg_program_zlp()
1353 writel(ctrl, hsotg->regs + epctl_reg); in s3c_hsotg_program_zlp()
1369 static void s3c_hsotg_complete_request(struct dwc2_hsotg *hsotg, in s3c_hsotg_complete_request() argument
1377 dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); in s3c_hsotg_complete_request()
1381 dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", in s3c_hsotg_complete_request()
1392 s3c_hsotg_handle_unaligned_buf_complete(hsotg, hs_ep, hs_req); in s3c_hsotg_complete_request()
1397 if (using_dma(hsotg)) in s3c_hsotg_complete_request()
1398 s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); in s3c_hsotg_complete_request()
1406 spin_unlock(&hsotg->lock); in s3c_hsotg_complete_request()
1408 spin_lock(&hsotg->lock); in s3c_hsotg_complete_request()
1421 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, false); in s3c_hsotg_complete_request()
1436 static void s3c_hsotg_rx_data(struct dwc2_hsotg *hsotg, int ep_idx, int size) in s3c_hsotg_rx_data() argument
1438 struct s3c_hsotg_ep *hs_ep = hsotg->eps_out[ep_idx]; in s3c_hsotg_rx_data()
1440 void __iomem *fifo = hsotg->regs + EPFIFO(ep_idx); in s3c_hsotg_rx_data()
1447 u32 epctl = readl(hsotg->regs + DOEPCTL(ep_idx)); in s3c_hsotg_rx_data()
1450 dev_dbg(hsotg->dev, in s3c_hsotg_rx_data()
1465 dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", in s3c_hsotg_rx_data()
1501 static void s3c_hsotg_ep0_zlp(struct dwc2_hsotg *hsotg, bool dir_in) in s3c_hsotg_ep0_zlp() argument
1504 hsotg->eps_out[0]->dir_in = dir_in; in s3c_hsotg_ep0_zlp()
1505 hsotg->ep0_state = dir_in ? DWC2_EP0_STATUS_IN : DWC2_EP0_STATUS_OUT; in s3c_hsotg_ep0_zlp()
1507 s3c_hsotg_program_zlp(hsotg, hsotg->eps_out[0]); in s3c_hsotg_ep0_zlp()
1519 static void s3c_hsotg_handle_outdone(struct dwc2_hsotg *hsotg, int epnum) in s3c_hsotg_handle_outdone() argument
1521 u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum)); in s3c_hsotg_handle_outdone()
1522 struct s3c_hsotg_ep *hs_ep = hsotg->eps_out[epnum]; in s3c_hsotg_handle_outdone()
1529 dev_dbg(hsotg->dev, "%s: no request active\n", __func__); in s3c_hsotg_handle_outdone()
1533 if (epnum == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_OUT) { in s3c_hsotg_handle_outdone()
1534 dev_dbg(hsotg->dev, "zlp packet received\n"); in s3c_hsotg_handle_outdone()
1535 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in s3c_hsotg_handle_outdone()
1536 s3c_hsotg_enqueue_setup(hsotg); in s3c_hsotg_handle_outdone()
1540 if (using_dma(hsotg)) { in s3c_hsotg_handle_outdone()
1560 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); in s3c_hsotg_handle_outdone()
1565 dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", in s3c_hsotg_handle_outdone()
1574 if (epnum == 0 && hsotg->ep0_state == DWC2_EP0_DATA_OUT) { in s3c_hsotg_handle_outdone()
1576 s3c_hsotg_ep0_zlp(hsotg, true); in s3c_hsotg_handle_outdone()
1580 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result); in s3c_hsotg_handle_outdone()
1589 static u32 s3c_hsotg_read_frameno(struct dwc2_hsotg *hsotg) in s3c_hsotg_read_frameno() argument
1593 dsts = readl(hsotg->regs + DSTS); in s3c_hsotg_read_frameno()
1616 static void s3c_hsotg_handle_rx(struct dwc2_hsotg *hsotg) in s3c_hsotg_handle_rx() argument
1618 u32 grxstsr = readl(hsotg->regs + GRXSTSP); in s3c_hsotg_handle_rx()
1621 WARN_ON(using_dma(hsotg)); in s3c_hsotg_handle_rx()
1629 dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", in s3c_hsotg_handle_rx()
1634 dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); in s3c_hsotg_handle_rx()
1638 dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", in s3c_hsotg_handle_rx()
1639 s3c_hsotg_read_frameno(hsotg)); in s3c_hsotg_handle_rx()
1641 if (!using_dma(hsotg)) in s3c_hsotg_handle_rx()
1642 s3c_hsotg_handle_outdone(hsotg, epnum); in s3c_hsotg_handle_rx()
1646 dev_dbg(hsotg->dev, in s3c_hsotg_handle_rx()
1648 s3c_hsotg_read_frameno(hsotg), in s3c_hsotg_handle_rx()
1649 readl(hsotg->regs + DOEPCTL(0))); in s3c_hsotg_handle_rx()
1655 if (hsotg->ep0_state == DWC2_EP0_SETUP) in s3c_hsotg_handle_rx()
1656 s3c_hsotg_handle_outdone(hsotg, epnum); in s3c_hsotg_handle_rx()
1660 s3c_hsotg_rx_data(hsotg, epnum, size); in s3c_hsotg_handle_rx()
1664 dev_dbg(hsotg->dev, in s3c_hsotg_handle_rx()
1666 s3c_hsotg_read_frameno(hsotg), in s3c_hsotg_handle_rx()
1667 readl(hsotg->regs + DOEPCTL(0))); in s3c_hsotg_handle_rx()
1669 WARN_ON(hsotg->ep0_state != DWC2_EP0_SETUP); in s3c_hsotg_handle_rx()
1671 s3c_hsotg_rx_data(hsotg, epnum, size); in s3c_hsotg_handle_rx()
1675 dev_warn(hsotg->dev, "%s: unknown status %08x\n", in s3c_hsotg_handle_rx()
1678 s3c_hsotg_dump(hsotg); in s3c_hsotg_handle_rx()
1714 static void s3c_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg, in s3c_hsotg_set_ep_maxpacket() argument
1718 void __iomem *regs = hsotg->regs; in s3c_hsotg_set_ep_maxpacket()
1723 hs_ep = index_to_ep(hsotg, ep, dir_in); in s3c_hsotg_set_ep_maxpacket()
1760 dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps); in s3c_hsotg_set_ep_maxpacket()
1768 static void s3c_hsotg_txfifo_flush(struct dwc2_hsotg *hsotg, unsigned int idx) in s3c_hsotg_txfifo_flush() argument
1774 hsotg->regs + GRSTCTL); in s3c_hsotg_txfifo_flush()
1780 val = readl(hsotg->regs + GRSTCTL); in s3c_hsotg_txfifo_flush()
1786 dev_err(hsotg->dev, in s3c_hsotg_txfifo_flush()
1804 static int s3c_hsotg_trytx(struct dwc2_hsotg *hsotg, in s3c_hsotg_trytx() argument
1815 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, in s3c_hsotg_trytx()
1821 dev_dbg(hsotg->dev, "trying to write more for ep%d\n", in s3c_hsotg_trytx()
1823 return s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); in s3c_hsotg_trytx()
1837 static void s3c_hsotg_complete_in(struct dwc2_hsotg *hsotg, in s3c_hsotg_complete_in() argument
1841 u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); in s3c_hsotg_complete_in()
1845 dev_dbg(hsotg->dev, "XferCompl but no req\n"); in s3c_hsotg_complete_in()
1850 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_STATUS_IN) { in s3c_hsotg_complete_in()
1851 dev_dbg(hsotg->dev, "zlp packet sent\n"); in s3c_hsotg_complete_in()
1852 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in s3c_hsotg_complete_in()
1853 if (hsotg->test_mode) { in s3c_hsotg_complete_in()
1856 ret = s3c_hsotg_set_test_mode(hsotg, hsotg->test_mode); in s3c_hsotg_complete_in()
1858 dev_dbg(hsotg->dev, "Invalid Test #%d\n", in s3c_hsotg_complete_in()
1859 hsotg->test_mode); in s3c_hsotg_complete_in()
1860 s3c_hsotg_stall_ep0(hsotg); in s3c_hsotg_complete_in()
1864 s3c_hsotg_enqueue_setup(hsotg); in s3c_hsotg_complete_in()
1884 dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n", in s3c_hsotg_complete_in()
1888 dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", in s3c_hsotg_complete_in()
1892 dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); in s3c_hsotg_complete_in()
1893 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); in s3c_hsotg_complete_in()
1899 s3c_hsotg_program_zlp(hsotg, hs_ep); in s3c_hsotg_complete_in()
1905 if (hs_ep->index == 0 && hsotg->ep0_state == DWC2_EP0_DATA_IN) { in s3c_hsotg_complete_in()
1907 s3c_hsotg_ep0_zlp(hsotg, false); in s3c_hsotg_complete_in()
1911 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0); in s3c_hsotg_complete_in()
1922 static void s3c_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx, in s3c_hsotg_epint() argument
1925 struct s3c_hsotg_ep *hs_ep = index_to_ep(hsotg, idx, dir_in); in s3c_hsotg_epint()
1932 ints = readl(hsotg->regs + epint_reg); in s3c_hsotg_epint()
1933 ctrl = readl(hsotg->regs + epctl_reg); in s3c_hsotg_epint()
1936 writel(ints, hsotg->regs + epint_reg); in s3c_hsotg_epint()
1939 dev_err(hsotg->dev, "%s:Interrupt for unconfigured ep%d(%s)\n", in s3c_hsotg_epint()
1944 dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", in s3c_hsotg_epint()
1957 writel(ctrl, hsotg->regs + epctl_reg); in s3c_hsotg_epint()
1960 dev_dbg(hsotg->dev, in s3c_hsotg_epint()
1962 __func__, readl(hsotg->regs + epctl_reg), in s3c_hsotg_epint()
1963 readl(hsotg->regs + epsiz_reg)); in s3c_hsotg_epint()
1970 s3c_hsotg_complete_in(hsotg, hs_ep); in s3c_hsotg_epint()
1973 s3c_hsotg_enqueue_setup(hsotg); in s3c_hsotg_epint()
1974 } else if (using_dma(hsotg)) { in s3c_hsotg_epint()
1980 s3c_hsotg_handle_outdone(hsotg, idx); in s3c_hsotg_epint()
1985 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); in s3c_hsotg_epint()
1988 int epctl = readl(hsotg->regs + epctl_reg); in s3c_hsotg_epint()
1990 s3c_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); in s3c_hsotg_epint()
1994 int dctl = readl(hsotg->regs + DCTL); in s3c_hsotg_epint()
1997 writel(dctl, hsotg->regs + DCTL); in s3c_hsotg_epint()
2003 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); in s3c_hsotg_epint()
2006 dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); in s3c_hsotg_epint()
2008 if (using_dma(hsotg) && idx == 0) { in s3c_hsotg_epint()
2019 s3c_hsotg_handle_outdone(hsotg, 0); in s3c_hsotg_epint()
2024 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); in s3c_hsotg_epint()
2029 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", in s3c_hsotg_epint()
2035 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", in s3c_hsotg_epint()
2040 if (hsotg->dedicated_fifos && in s3c_hsotg_epint()
2042 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", in s3c_hsotg_epint()
2044 if (!using_dma(hsotg)) in s3c_hsotg_epint()
2045 s3c_hsotg_trytx(hsotg, hs_ep); in s3c_hsotg_epint()
2057 static void s3c_hsotg_irq_enumdone(struct dwc2_hsotg *hsotg) in s3c_hsotg_irq_enumdone() argument
2059 u32 dsts = readl(hsotg->regs + DSTS); in s3c_hsotg_irq_enumdone()
2068 dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); in s3c_hsotg_irq_enumdone()
2080 hsotg->gadget.speed = USB_SPEED_FULL; in s3c_hsotg_irq_enumdone()
2086 hsotg->gadget.speed = USB_SPEED_HIGH; in s3c_hsotg_irq_enumdone()
2092 hsotg->gadget.speed = USB_SPEED_LOW; in s3c_hsotg_irq_enumdone()
2100 dev_info(hsotg->dev, "new device is %s\n", in s3c_hsotg_irq_enumdone()
2101 usb_speed_string(hsotg->gadget.speed)); in s3c_hsotg_irq_enumdone()
2111 s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 1); in s3c_hsotg_irq_enumdone()
2112 s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0); in s3c_hsotg_irq_enumdone()
2113 for (i = 1; i < hsotg->num_of_eps; i++) { in s3c_hsotg_irq_enumdone()
2114 if (hsotg->eps_in[i]) in s3c_hsotg_irq_enumdone()
2115 s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, 1); in s3c_hsotg_irq_enumdone()
2116 if (hsotg->eps_out[i]) in s3c_hsotg_irq_enumdone()
2117 s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, 0); in s3c_hsotg_irq_enumdone()
2123 s3c_hsotg_enqueue_setup(hsotg); in s3c_hsotg_irq_enumdone()
2125 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in s3c_hsotg_irq_enumdone()
2126 readl(hsotg->regs + DIEPCTL0), in s3c_hsotg_irq_enumdone()
2127 readl(hsotg->regs + DOEPCTL0)); in s3c_hsotg_irq_enumdone()
2139 static void kill_all_requests(struct dwc2_hsotg *hsotg, in kill_all_requests() argument
2149 s3c_hsotg_complete_request(hsotg, ep, req, in kill_all_requests()
2152 if (!hsotg->dedicated_fifos) in kill_all_requests()
2154 size = (readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4; in kill_all_requests()
2156 s3c_hsotg_txfifo_flush(hsotg, ep->fifo_index); in kill_all_requests()
2167 void s3c_hsotg_disconnect(struct dwc2_hsotg *hsotg) in s3c_hsotg_disconnect() argument
2171 if (!hsotg->connected) in s3c_hsotg_disconnect()
2174 hsotg->connected = 0; in s3c_hsotg_disconnect()
2175 hsotg->test_mode = 0; in s3c_hsotg_disconnect()
2177 for (ep = 0; ep < hsotg->num_of_eps; ep++) { in s3c_hsotg_disconnect()
2178 if (hsotg->eps_in[ep]) in s3c_hsotg_disconnect()
2179 kill_all_requests(hsotg, hsotg->eps_in[ep], in s3c_hsotg_disconnect()
2181 if (hsotg->eps_out[ep]) in s3c_hsotg_disconnect()
2182 kill_all_requests(hsotg, hsotg->eps_out[ep], in s3c_hsotg_disconnect()
2186 call_gadget(hsotg, disconnect); in s3c_hsotg_disconnect()
2195 static void s3c_hsotg_irq_fifoempty(struct dwc2_hsotg *hsotg, bool periodic) in s3c_hsotg_irq_fifoempty() argument
2201 for (epno = 0; epno < hsotg->num_of_eps; epno++) { in s3c_hsotg_irq_fifoempty()
2202 ep = index_to_ep(hsotg, epno, 1); in s3c_hsotg_irq_fifoempty()
2214 ret = s3c_hsotg_trytx(hsotg, ep); in s3c_hsotg_irq_fifoempty()
2231 static int s3c_hsotg_corereset(struct dwc2_hsotg *hsotg) in s3c_hsotg_corereset() argument
2236 dev_dbg(hsotg->dev, "resetting core\n"); in s3c_hsotg_corereset()
2239 writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); in s3c_hsotg_corereset()
2243 grstctl = readl(hsotg->regs + GRSTCTL); in s3c_hsotg_corereset()
2247 dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); in s3c_hsotg_corereset()
2254 u32 grstctl = readl(hsotg->regs + GRSTCTL); in s3c_hsotg_corereset()
2257 dev_info(hsotg->dev, in s3c_hsotg_corereset()
2269 dev_dbg(hsotg->dev, "reset successful\n"); in s3c_hsotg_corereset()
2279 void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg, in s3c_hsotg_core_init_disconnected() argument
2285 s3c_hsotg_corereset(hsotg); in s3c_hsotg_core_init_disconnected()
2293 val = (hsotg->phyif == GUSBCFG_PHYIF8) ? 9 : 5; in s3c_hsotg_core_init_disconnected()
2294 writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | in s3c_hsotg_core_init_disconnected()
2295 (val << GUSBCFG_USBTRDTIM_SHIFT), hsotg->regs + GUSBCFG); in s3c_hsotg_core_init_disconnected()
2297 s3c_hsotg_init_fifo(hsotg); in s3c_hsotg_core_init_disconnected()
2300 __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); in s3c_hsotg_core_init_disconnected()
2302 writel(DCFG_EPMISCNT(1) | DCFG_DEVSPD_HS, hsotg->regs + DCFG); in s3c_hsotg_core_init_disconnected()
2305 writel(0xffffffff, hsotg->regs + GOTGINT); in s3c_hsotg_core_init_disconnected()
2308 writel(0xffffffff, hsotg->regs + GINTSTS); in s3c_hsotg_core_init_disconnected()
2315 hsotg->regs + GINTMSK); in s3c_hsotg_core_init_disconnected()
2317 if (using_dma(hsotg)) in s3c_hsotg_core_init_disconnected()
2320 hsotg->regs + GAHBCFG); in s3c_hsotg_core_init_disconnected()
2322 writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL | in s3c_hsotg_core_init_disconnected()
2325 hsotg->regs + GAHBCFG); in s3c_hsotg_core_init_disconnected()
2333 writel(((hsotg->dedicated_fifos && !using_dma(hsotg)) ? in s3c_hsotg_core_init_disconnected()
2338 hsotg->regs + DIEPMSK); in s3c_hsotg_core_init_disconnected()
2344 writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | in s3c_hsotg_core_init_disconnected()
2348 hsotg->regs + DOEPMSK); in s3c_hsotg_core_init_disconnected()
2350 writel(0, hsotg->regs + DAINTMSK); in s3c_hsotg_core_init_disconnected()
2352 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in s3c_hsotg_core_init_disconnected()
2353 readl(hsotg->regs + DIEPCTL0), in s3c_hsotg_core_init_disconnected()
2354 readl(hsotg->regs + DOEPCTL0)); in s3c_hsotg_core_init_disconnected()
2357 s3c_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); in s3c_hsotg_core_init_disconnected()
2364 if (!using_dma(hsotg)) in s3c_hsotg_core_init_disconnected()
2365 s3c_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); in s3c_hsotg_core_init_disconnected()
2368 s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); in s3c_hsotg_core_init_disconnected()
2369 s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); in s3c_hsotg_core_init_disconnected()
2372 __orr32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); in s3c_hsotg_core_init_disconnected()
2374 __bic32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); in s3c_hsotg_core_init_disconnected()
2377 dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + DCTL)); in s3c_hsotg_core_init_disconnected()
2386 DXEPTSIZ_XFERSIZE(8), hsotg->regs + DOEPTSIZ0); in s3c_hsotg_core_init_disconnected()
2388 writel(s3c_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in s3c_hsotg_core_init_disconnected()
2391 hsotg->regs + DOEPCTL0); in s3c_hsotg_core_init_disconnected()
2394 writel(s3c_hsotg_ep0_mps(hsotg->eps_out[0]->ep.maxpacket) | in s3c_hsotg_core_init_disconnected()
2395 DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); in s3c_hsotg_core_init_disconnected()
2397 s3c_hsotg_enqueue_setup(hsotg); in s3c_hsotg_core_init_disconnected()
2399 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", in s3c_hsotg_core_init_disconnected()
2400 readl(hsotg->regs + DIEPCTL0), in s3c_hsotg_core_init_disconnected()
2401 readl(hsotg->regs + DOEPCTL0)); in s3c_hsotg_core_init_disconnected()
2407 __orr32(hsotg->regs + DCTL, val); in s3c_hsotg_core_init_disconnected()
2412 hsotg->last_rst = jiffies; in s3c_hsotg_core_init_disconnected()
2415 static void s3c_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) in s3c_hsotg_core_disconnect() argument
2418 __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); in s3c_hsotg_core_disconnect()
2421 void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) in s3c_hsotg_core_connect() argument
2424 __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); in s3c_hsotg_core_connect()
2434 struct dwc2_hsotg *hsotg = pw; in s3c_hsotg_irq() local
2439 spin_lock(&hsotg->lock); in s3c_hsotg_irq()
2441 gintsts = readl(hsotg->regs + GINTSTS); in s3c_hsotg_irq()
2442 gintmsk = readl(hsotg->regs + GINTMSK); in s3c_hsotg_irq()
2444 dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", in s3c_hsotg_irq()
2450 writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); in s3c_hsotg_irq()
2452 s3c_hsotg_irq_enumdone(hsotg); in s3c_hsotg_irq()
2456 u32 daint = readl(hsotg->regs + DAINT); in s3c_hsotg_irq()
2457 u32 daintmsk = readl(hsotg->regs + DAINTMSK); in s3c_hsotg_irq()
2465 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); in s3c_hsotg_irq()
2467 for (ep = 0; ep < hsotg->num_of_eps && daint_out; in s3c_hsotg_irq()
2470 s3c_hsotg_epint(hsotg, ep, 0); in s3c_hsotg_irq()
2473 for (ep = 0; ep < hsotg->num_of_eps && daint_in; in s3c_hsotg_irq()
2476 s3c_hsotg_epint(hsotg, ep, 1); in s3c_hsotg_irq()
2482 u32 usb_status = readl(hsotg->regs + GOTGCTL); in s3c_hsotg_irq()
2484 dev_dbg(hsotg->dev, "%s: USBRst\n", __func__); in s3c_hsotg_irq()
2485 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", in s3c_hsotg_irq()
2486 readl(hsotg->regs + GNPTXSTS)); in s3c_hsotg_irq()
2488 writel(GINTSTS_USBRST, hsotg->regs + GINTSTS); in s3c_hsotg_irq()
2491 s3c_hsotg_disconnect(hsotg); in s3c_hsotg_irq()
2494 if (time_after(jiffies, hsotg->last_rst + in s3c_hsotg_irq()
2497 kill_all_requests(hsotg, hsotg->eps_out[0], in s3c_hsotg_irq()
2500 s3c_hsotg_core_init_disconnected(hsotg, true); in s3c_hsotg_irq()
2508 dev_dbg(hsotg->dev, "NPTxFEmp\n"); in s3c_hsotg_irq()
2516 s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); in s3c_hsotg_irq()
2517 s3c_hsotg_irq_fifoempty(hsotg, false); in s3c_hsotg_irq()
2521 dev_dbg(hsotg->dev, "PTxFEmp\n"); in s3c_hsotg_irq()
2525 s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); in s3c_hsotg_irq()
2526 s3c_hsotg_irq_fifoempty(hsotg, true); in s3c_hsotg_irq()
2536 s3c_hsotg_handle_rx(hsotg); in s3c_hsotg_irq()
2540 dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); in s3c_hsotg_irq()
2541 writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); in s3c_hsotg_irq()
2551 dev_info(hsotg->dev, "GOUTNakEff triggered\n"); in s3c_hsotg_irq()
2553 writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); in s3c_hsotg_irq()
2555 s3c_hsotg_dump(hsotg); in s3c_hsotg_irq()
2559 dev_info(hsotg->dev, "GINNakEff triggered\n"); in s3c_hsotg_irq()
2561 writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); in s3c_hsotg_irq()
2563 s3c_hsotg_dump(hsotg); in s3c_hsotg_irq()
2574 spin_unlock(&hsotg->lock); in s3c_hsotg_irq()
2590 struct dwc2_hsotg *hsotg = hs_ep->parent; in s3c_hsotg_ep_enable() local
2600 dev_dbg(hsotg->dev, in s3c_hsotg_ep_enable()
2610 dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__); in s3c_hsotg_ep_enable()
2619 epctrl = readl(hsotg->regs + epctrl_reg); in s3c_hsotg_ep_enable()
2621 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", in s3c_hsotg_ep_enable()
2624 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_ep_enable()
2645 s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps, dir_in); in s3c_hsotg_ep_enable()
2654 dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); in s3c_hsotg_ep_enable()
2686 hsotg->fifo_map &= ~(1 << hs_ep->fifo_index); in s3c_hsotg_ep_enable()
2696 if (dir_in && hsotg->dedicated_fifos && !hs_ep->fifo_index) { in s3c_hsotg_ep_enable()
2700 for (i = 1; i < hsotg->num_of_eps; ++i) { in s3c_hsotg_ep_enable()
2701 if (hsotg->fifo_map & (1<<i)) in s3c_hsotg_ep_enable()
2703 val = readl(hsotg->regs + DPTXFSIZN(i)); in s3c_hsotg_ep_enable()
2714 dev_err(hsotg->dev, in s3c_hsotg_ep_enable()
2719 hsotg->fifo_map |= 1 << fifo_index; in s3c_hsotg_ep_enable()
2729 dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", in s3c_hsotg_ep_enable()
2732 writel(epctrl, hsotg->regs + epctrl_reg); in s3c_hsotg_ep_enable()
2733 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n", in s3c_hsotg_ep_enable()
2734 __func__, readl(hsotg->regs + epctrl_reg)); in s3c_hsotg_ep_enable()
2737 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); in s3c_hsotg_ep_enable()
2740 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_ep_enable()
2751 struct dwc2_hsotg *hsotg = hs_ep->parent; in s3c_hsotg_ep_disable_force() local
2758 dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); in s3c_hsotg_ep_disable_force()
2760 if (ep == &hsotg->eps_out[0]->ep) { in s3c_hsotg_ep_disable_force()
2761 dev_err(hsotg->dev, "%s: called for ep0\n", __func__); in s3c_hsotg_ep_disable_force()
2767 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_ep_disable_force()
2769 hsotg->fifo_map &= ~(1<<hs_ep->fifo_index); in s3c_hsotg_ep_disable_force()
2773 ctrl = readl(hsotg->regs + epctrl_reg); in s3c_hsotg_ep_disable_force()
2778 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); in s3c_hsotg_ep_disable_force()
2779 writel(ctrl, hsotg->regs + epctrl_reg); in s3c_hsotg_ep_disable_force()
2782 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0); in s3c_hsotg_ep_disable_force()
2785 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN); in s3c_hsotg_ep_disable_force()
2787 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_ep_disable_force()
2939 static void s3c_hsotg_phy_enable(struct dwc2_hsotg *hsotg) in s3c_hsotg_phy_enable() argument
2941 struct platform_device *pdev = to_platform_device(hsotg->dev); in s3c_hsotg_phy_enable()
2943 dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); in s3c_hsotg_phy_enable()
2945 if (hsotg->uphy) in s3c_hsotg_phy_enable()
2946 usb_phy_init(hsotg->uphy); in s3c_hsotg_phy_enable()
2947 else if (hsotg->plat && hsotg->plat->phy_init) in s3c_hsotg_phy_enable()
2948 hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); in s3c_hsotg_phy_enable()
2950 phy_init(hsotg->phy); in s3c_hsotg_phy_enable()
2951 phy_power_on(hsotg->phy); in s3c_hsotg_phy_enable()
2962 static void s3c_hsotg_phy_disable(struct dwc2_hsotg *hsotg) in s3c_hsotg_phy_disable() argument
2964 struct platform_device *pdev = to_platform_device(hsotg->dev); in s3c_hsotg_phy_disable()
2966 if (hsotg->uphy) in s3c_hsotg_phy_disable()
2967 usb_phy_shutdown(hsotg->uphy); in s3c_hsotg_phy_disable()
2968 else if (hsotg->plat && hsotg->plat->phy_exit) in s3c_hsotg_phy_disable()
2969 hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); in s3c_hsotg_phy_disable()
2971 phy_power_off(hsotg->phy); in s3c_hsotg_phy_disable()
2972 phy_exit(hsotg->phy); in s3c_hsotg_phy_disable()
2980 static void s3c_hsotg_init(struct dwc2_hsotg *hsotg) in s3c_hsotg_init() argument
2987 hsotg->regs + DIEPMSK); in s3c_hsotg_init()
2991 hsotg->regs + DOEPMSK); in s3c_hsotg_init()
2993 writel(0, hsotg->regs + DAINTMSK); in s3c_hsotg_init()
2996 __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); in s3c_hsotg_init()
3000 dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", in s3c_hsotg_init()
3001 readl(hsotg->regs + GRXFSIZ), in s3c_hsotg_init()
3002 readl(hsotg->regs + GNPTXFSIZ)); in s3c_hsotg_init()
3004 s3c_hsotg_init_fifo(hsotg); in s3c_hsotg_init()
3007 trdtim = (hsotg->phyif == GUSBCFG_PHYIF8) ? 9 : 5; in s3c_hsotg_init()
3008 writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | in s3c_hsotg_init()
3010 hsotg->regs + GUSBCFG); in s3c_hsotg_init()
3012 if (using_dma(hsotg)) in s3c_hsotg_init()
3013 __orr32(hsotg->regs + GAHBCFG, GAHBCFG_DMA_EN); in s3c_hsotg_init()
3027 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in s3c_hsotg_udc_start() local
3031 if (!hsotg) { in s3c_hsotg_udc_start()
3037 dev_err(hsotg->dev, "%s: no driver\n", __func__); in s3c_hsotg_udc_start()
3042 dev_err(hsotg->dev, "%s: bad speed\n", __func__); in s3c_hsotg_udc_start()
3045 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); in s3c_hsotg_udc_start()
3049 mutex_lock(&hsotg->init_mutex); in s3c_hsotg_udc_start()
3050 WARN_ON(hsotg->driver); in s3c_hsotg_udc_start()
3053 hsotg->driver = driver; in s3c_hsotg_udc_start()
3054 hsotg->gadget.dev.of_node = hsotg->dev->of_node; in s3c_hsotg_udc_start()
3055 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in s3c_hsotg_udc_start()
3057 clk_enable(hsotg->clk); in s3c_hsotg_udc_start()
3059 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), in s3c_hsotg_udc_start()
3060 hsotg->supplies); in s3c_hsotg_udc_start()
3062 dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); in s3c_hsotg_udc_start()
3066 s3c_hsotg_phy_enable(hsotg); in s3c_hsotg_udc_start()
3067 if (!IS_ERR_OR_NULL(hsotg->uphy)) in s3c_hsotg_udc_start()
3068 otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget); in s3c_hsotg_udc_start()
3070 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_udc_start()
3071 s3c_hsotg_init(hsotg); in s3c_hsotg_udc_start()
3072 s3c_hsotg_core_init_disconnected(hsotg, false); in s3c_hsotg_udc_start()
3073 hsotg->enabled = 0; in s3c_hsotg_udc_start()
3074 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_udc_start()
3076 dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); in s3c_hsotg_udc_start()
3078 mutex_unlock(&hsotg->init_mutex); in s3c_hsotg_udc_start()
3083 mutex_unlock(&hsotg->init_mutex); in s3c_hsotg_udc_start()
3084 hsotg->driver = NULL; in s3c_hsotg_udc_start()
3097 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in s3c_hsotg_udc_stop() local
3101 if (!hsotg) in s3c_hsotg_udc_stop()
3104 mutex_lock(&hsotg->init_mutex); in s3c_hsotg_udc_stop()
3107 for (ep = 1; ep < hsotg->num_of_eps; ep++) { in s3c_hsotg_udc_stop()
3108 if (hsotg->eps_in[ep]) in s3c_hsotg_udc_stop()
3109 s3c_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); in s3c_hsotg_udc_stop()
3110 if (hsotg->eps_out[ep]) in s3c_hsotg_udc_stop()
3111 s3c_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); in s3c_hsotg_udc_stop()
3114 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_udc_stop()
3116 hsotg->driver = NULL; in s3c_hsotg_udc_stop()
3117 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in s3c_hsotg_udc_stop()
3118 hsotg->enabled = 0; in s3c_hsotg_udc_stop()
3120 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_udc_stop()
3122 if (!IS_ERR_OR_NULL(hsotg->uphy)) in s3c_hsotg_udc_stop()
3123 otg_set_peripheral(hsotg->uphy->otg, NULL); in s3c_hsotg_udc_stop()
3124 s3c_hsotg_phy_disable(hsotg); in s3c_hsotg_udc_stop()
3126 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); in s3c_hsotg_udc_stop()
3128 clk_disable(hsotg->clk); in s3c_hsotg_udc_stop()
3130 mutex_unlock(&hsotg->init_mutex); in s3c_hsotg_udc_stop()
3155 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in s3c_hsotg_pullup() local
3158 dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); in s3c_hsotg_pullup()
3160 mutex_lock(&hsotg->init_mutex); in s3c_hsotg_pullup()
3161 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_pullup()
3163 clk_enable(hsotg->clk); in s3c_hsotg_pullup()
3164 hsotg->enabled = 1; in s3c_hsotg_pullup()
3165 s3c_hsotg_core_init_disconnected(hsotg, false); in s3c_hsotg_pullup()
3166 s3c_hsotg_core_connect(hsotg); in s3c_hsotg_pullup()
3168 s3c_hsotg_core_disconnect(hsotg); in s3c_hsotg_pullup()
3169 s3c_hsotg_disconnect(hsotg); in s3c_hsotg_pullup()
3170 hsotg->enabled = 0; in s3c_hsotg_pullup()
3171 clk_disable(hsotg->clk); in s3c_hsotg_pullup()
3174 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in s3c_hsotg_pullup()
3175 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_pullup()
3176 mutex_unlock(&hsotg->init_mutex); in s3c_hsotg_pullup()
3183 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in s3c_hsotg_vbus_session() local
3186 dev_dbg(hsotg->dev, "%s: is_active: %d\n", __func__, is_active); in s3c_hsotg_vbus_session()
3187 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_vbus_session()
3191 kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); in s3c_hsotg_vbus_session()
3192 s3c_hsotg_core_init_disconnected(hsotg, false); in s3c_hsotg_vbus_session()
3193 if (hsotg->enabled) in s3c_hsotg_vbus_session()
3194 s3c_hsotg_core_connect(hsotg); in s3c_hsotg_vbus_session()
3196 s3c_hsotg_core_disconnect(hsotg); in s3c_hsotg_vbus_session()
3197 s3c_hsotg_disconnect(hsotg); in s3c_hsotg_vbus_session()
3200 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_vbus_session()
3213 struct dwc2_hsotg *hsotg = to_hsotg(gadget); in s3c_hsotg_vbus_draw() local
3215 if (IS_ERR_OR_NULL(hsotg->uphy)) in s3c_hsotg_vbus_draw()
3217 return usb_phy_set_power(hsotg->uphy, mA); in s3c_hsotg_vbus_draw()
3239 static void s3c_hsotg_initep(struct dwc2_hsotg *hsotg, in s3c_hsotg_initep() argument
3263 list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list); in s3c_hsotg_initep()
3265 hs_ep->parent = hsotg; in s3c_hsotg_initep()
3275 if (using_dma(hsotg)) { in s3c_hsotg_initep()
3278 writel(next, hsotg->regs + DIEPCTL(epnum)); in s3c_hsotg_initep()
3280 writel(next, hsotg->regs + DOEPCTL(epnum)); in s3c_hsotg_initep()
3290 static int s3c_hsotg_hw_cfg(struct dwc2_hsotg *hsotg) in s3c_hsotg_hw_cfg() argument
3298 cfg = readl(hsotg->regs + GHWCFG2); in s3c_hsotg_hw_cfg()
3299 hsotg->num_of_eps = (cfg >> GHWCFG2_NUM_DEV_EP_SHIFT) & 0xF; in s3c_hsotg_hw_cfg()
3301 hsotg->num_of_eps++; in s3c_hsotg_hw_cfg()
3303 hsotg->eps_in[0] = devm_kzalloc(hsotg->dev, sizeof(struct s3c_hsotg_ep), in s3c_hsotg_hw_cfg()
3305 if (!hsotg->eps_in[0]) in s3c_hsotg_hw_cfg()
3308 hsotg->eps_out[0] = hsotg->eps_in[0]; in s3c_hsotg_hw_cfg()
3310 cfg = readl(hsotg->regs + GHWCFG1); in s3c_hsotg_hw_cfg()
3311 for (i = 1, cfg >>= 2; i < hsotg->num_of_eps; i++, cfg >>= 2) { in s3c_hsotg_hw_cfg()
3315 hsotg->eps_in[i] = devm_kzalloc(hsotg->dev, in s3c_hsotg_hw_cfg()
3317 if (!hsotg->eps_in[i]) in s3c_hsotg_hw_cfg()
3322 hsotg->eps_out[i] = devm_kzalloc(hsotg->dev, in s3c_hsotg_hw_cfg()
3324 if (!hsotg->eps_out[i]) in s3c_hsotg_hw_cfg()
3329 cfg = readl(hsotg->regs + GHWCFG3); in s3c_hsotg_hw_cfg()
3330 hsotg->fifo_mem = (cfg >> GHWCFG3_DFIFO_DEPTH_SHIFT); in s3c_hsotg_hw_cfg()
3332 cfg = readl(hsotg->regs + GHWCFG4); in s3c_hsotg_hw_cfg()
3333 hsotg->dedicated_fifos = (cfg >> GHWCFG4_DED_FIFO_SHIFT) & 1; in s3c_hsotg_hw_cfg()
3335 dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", in s3c_hsotg_hw_cfg()
3336 hsotg->num_of_eps, in s3c_hsotg_hw_cfg()
3337 hsotg->dedicated_fifos ? "dedicated" : "shared", in s3c_hsotg_hw_cfg()
3338 hsotg->fifo_mem); in s3c_hsotg_hw_cfg()
3346 static void s3c_hsotg_dump(struct dwc2_hsotg *hsotg) in s3c_hsotg_dump() argument
3349 struct device *dev = hsotg->dev; in s3c_hsotg_dump()
3350 void __iomem *regs = hsotg->regs; in s3c_hsotg_dump()
3366 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in s3c_hsotg_dump()
3373 for (idx = 0; idx < hsotg->num_of_eps; idx++) { in s3c_hsotg_dump()
3405 struct dwc2_hsotg *hsotg = s->private; in testmode_write() local
3426 spin_lock_irqsave(&hsotg->lock, flags); in testmode_write()
3427 s3c_hsotg_set_test_mode(hsotg, testmode); in testmode_write()
3428 spin_unlock_irqrestore(&hsotg->lock, flags); in testmode_write()
3441 struct dwc2_hsotg *hsotg = s->private; in testmode_show() local
3445 spin_lock_irqsave(&hsotg->lock, flags); in testmode_show()
3446 dctl = readl(hsotg->regs + DCTL); in testmode_show()
3449 spin_unlock_irqrestore(&hsotg->lock, flags); in testmode_show()
3502 struct dwc2_hsotg *hsotg = seq->private; in state_show() local
3503 void __iomem *regs = hsotg->regs; in state_show()
3528 for (idx = 0; idx < hsotg->num_of_eps; idx++) { in state_show()
3572 struct dwc2_hsotg *hsotg = seq->private; in fifo_show() local
3573 void __iomem *regs = hsotg->regs; in fifo_show()
3587 for (idx = 1; idx < hsotg->num_of_eps; idx++) { in fifo_show()
3628 struct dwc2_hsotg *hsotg = ep->parent; in ep_show() local
3630 void __iomem *regs = hsotg->regs; in ep_show()
3663 spin_lock_irqsave(&hsotg->lock, flags); in ep_show()
3678 spin_unlock_irqrestore(&hsotg->lock, flags); in ep_show()
3705 static void s3c_hsotg_create_debug(struct dwc2_hsotg *hsotg) in s3c_hsotg_create_debug() argument
3710 root = debugfs_create_dir(dev_name(hsotg->dev), NULL); in s3c_hsotg_create_debug()
3711 hsotg->debug_root = root; in s3c_hsotg_create_debug()
3713 dev_err(hsotg->dev, "cannot create debug root\n"); in s3c_hsotg_create_debug()
3719 hsotg->debug_file = debugfs_create_file("state", S_IRUGO, root, in s3c_hsotg_create_debug()
3720 hsotg, &state_fops); in s3c_hsotg_create_debug()
3722 if (IS_ERR(hsotg->debug_file)) in s3c_hsotg_create_debug()
3723 dev_err(hsotg->dev, "%s: failed to create state\n", __func__); in s3c_hsotg_create_debug()
3725 hsotg->debug_testmode = debugfs_create_file("testmode", in s3c_hsotg_create_debug()
3727 hsotg, &testmode_fops); in s3c_hsotg_create_debug()
3729 if (IS_ERR(hsotg->debug_testmode)) in s3c_hsotg_create_debug()
3730 dev_err(hsotg->dev, "%s: failed to create testmode\n", in s3c_hsotg_create_debug()
3733 hsotg->debug_fifo = debugfs_create_file("fifo", S_IRUGO, root, in s3c_hsotg_create_debug()
3734 hsotg, &fifo_fops); in s3c_hsotg_create_debug()
3736 if (IS_ERR(hsotg->debug_fifo)) in s3c_hsotg_create_debug()
3737 dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__); in s3c_hsotg_create_debug()
3740 for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { in s3c_hsotg_create_debug()
3743 ep = hsotg->eps_out[epidx]; in s3c_hsotg_create_debug()
3749 dev_err(hsotg->dev, "failed to create %s debug file\n", in s3c_hsotg_create_debug()
3754 for (epidx = 1; epidx < hsotg->num_of_eps; epidx++) { in s3c_hsotg_create_debug()
3757 ep = hsotg->eps_in[epidx]; in s3c_hsotg_create_debug()
3763 dev_err(hsotg->dev, "failed to create %s debug file\n", in s3c_hsotg_create_debug()
3775 static void s3c_hsotg_delete_debug(struct dwc2_hsotg *hsotg) in s3c_hsotg_delete_debug() argument
3779 for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { in s3c_hsotg_delete_debug()
3780 if (hsotg->eps_in[epidx]) in s3c_hsotg_delete_debug()
3781 debugfs_remove(hsotg->eps_in[epidx]->debugfs); in s3c_hsotg_delete_debug()
3782 if (hsotg->eps_out[epidx]) in s3c_hsotg_delete_debug()
3783 debugfs_remove(hsotg->eps_out[epidx]->debugfs); in s3c_hsotg_delete_debug()
3786 debugfs_remove(hsotg->debug_file); in s3c_hsotg_delete_debug()
3787 debugfs_remove(hsotg->debug_testmode); in s3c_hsotg_delete_debug()
3788 debugfs_remove(hsotg->debug_fifo); in s3c_hsotg_delete_debug()
3789 debugfs_remove(hsotg->debug_root); in s3c_hsotg_delete_debug()
3793 static void s3c_hsotg_of_probe(struct dwc2_hsotg *hsotg) in s3c_hsotg_of_probe() argument
3795 struct device_node *np = hsotg->dev->of_node; in s3c_hsotg_of_probe()
3800 hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma"); in s3c_hsotg_of_probe()
3813 &hsotg->g_tx_fifo_sz[1], len)) in s3c_hsotg_of_probe()
3822 hsotg->g_tx_fifo_sz[i] = 0; in s3c_hsotg_of_probe()
3827 of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz); in s3c_hsotg_of_probe()
3831 &hsotg->g_np_g_tx_fifo_sz); in s3c_hsotg_of_probe()
3834 static inline void s3c_hsotg_of_probe(struct dwc2_hsotg *hsotg) { } in s3c_hsotg_of_probe() argument
3842 int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) in dwc2_gadget_init() argument
3844 struct device *dev = hsotg->dev; in dwc2_gadget_init()
3852 hsotg->phyif = GUSBCFG_PHYIF16; in dwc2_gadget_init()
3854 s3c_hsotg_of_probe(hsotg); in dwc2_gadget_init()
3857 hsotg->g_rx_fifo_sz = 2048; in dwc2_gadget_init()
3858 hsotg->g_np_g_tx_fifo_sz = 1024; in dwc2_gadget_init()
3859 memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo)); in dwc2_gadget_init()
3861 s3c_hsotg_of_probe(hsotg); in dwc2_gadget_init()
3864 hsotg->g_np_g_tx_fifo_sz); in dwc2_gadget_init()
3865 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz); in dwc2_gadget_init()
3868 hsotg->g_tx_fifo_sz[i]); in dwc2_gadget_init()
3873 if (IS_ERR_OR_NULL(hsotg->phy) && IS_ERR_OR_NULL(hsotg->uphy)) { in dwc2_gadget_init()
3880 hsotg->plat = plat; in dwc2_gadget_init()
3881 } else if (hsotg->phy) { in dwc2_gadget_init()
3886 if (phy_get_bus_width(hsotg->phy) == 8) in dwc2_gadget_init()
3887 hsotg->phyif = GUSBCFG_PHYIF8; in dwc2_gadget_init()
3890 hsotg->clk = devm_clk_get(dev, "otg"); in dwc2_gadget_init()
3891 if (IS_ERR(hsotg->clk)) { in dwc2_gadget_init()
3892 hsotg->clk = NULL; in dwc2_gadget_init()
3896 hsotg->gadget.max_speed = USB_SPEED_HIGH; in dwc2_gadget_init()
3897 hsotg->gadget.ops = &s3c_hsotg_gadget_ops; in dwc2_gadget_init()
3898 hsotg->gadget.name = dev_name(dev); in dwc2_gadget_init()
3902 ret = clk_prepare_enable(hsotg->clk); in dwc2_gadget_init()
3911 for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) in dwc2_gadget_init()
3912 hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; in dwc2_gadget_init()
3914 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), in dwc2_gadget_init()
3915 hsotg->supplies); in dwc2_gadget_init()
3921 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), in dwc2_gadget_init()
3922 hsotg->supplies); in dwc2_gadget_init()
3930 s3c_hsotg_phy_enable(hsotg); in dwc2_gadget_init()
3936 __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEHOSTMODE); in dwc2_gadget_init()
3937 __orr32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); in dwc2_gadget_init()
3945 s3c_hsotg_corereset(hsotg); in dwc2_gadget_init()
3946 ret = s3c_hsotg_hw_cfg(hsotg); in dwc2_gadget_init()
3948 dev_err(hsotg->dev, "Hardware configuration failed: %d\n", ret); in dwc2_gadget_init()
3952 s3c_hsotg_init(hsotg); in dwc2_gadget_init()
3955 __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); in dwc2_gadget_init()
3957 hsotg->ctrl_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
3959 if (!hsotg->ctrl_buff) { in dwc2_gadget_init()
3965 hsotg->ep0_buff = devm_kzalloc(hsotg->dev, in dwc2_gadget_init()
3967 if (!hsotg->ep0_buff) { in dwc2_gadget_init()
3973 ret = devm_request_irq(hsotg->dev, irq, s3c_hsotg_irq, IRQF_SHARED, in dwc2_gadget_init()
3974 dev_name(hsotg->dev), hsotg); in dwc2_gadget_init()
3976 s3c_hsotg_phy_disable(hsotg); in dwc2_gadget_init()
3977 clk_disable_unprepare(hsotg->clk); in dwc2_gadget_init()
3978 regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), in dwc2_gadget_init()
3979 hsotg->supplies); in dwc2_gadget_init()
3986 if (hsotg->num_of_eps == 0) { in dwc2_gadget_init()
3994 INIT_LIST_HEAD(&hsotg->gadget.ep_list); in dwc2_gadget_init()
3995 hsotg->gadget.ep0 = &hsotg->eps_out[0]->ep; in dwc2_gadget_init()
3999 hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps_out[0]->ep, in dwc2_gadget_init()
4001 if (!hsotg->ctrl_req) { in dwc2_gadget_init()
4008 for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) { in dwc2_gadget_init()
4009 if (hsotg->eps_in[epnum]) in dwc2_gadget_init()
4010 s3c_hsotg_initep(hsotg, hsotg->eps_in[epnum], in dwc2_gadget_init()
4012 if (hsotg->eps_out[epnum]) in dwc2_gadget_init()
4013 s3c_hsotg_initep(hsotg, hsotg->eps_out[epnum], in dwc2_gadget_init()
4018 s3c_hsotg_phy_disable(hsotg); in dwc2_gadget_init()
4020 ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), in dwc2_gadget_init()
4021 hsotg->supplies); in dwc2_gadget_init()
4027 ret = usb_add_gadget_udc(dev, &hsotg->gadget); in dwc2_gadget_init()
4031 s3c_hsotg_create_debug(hsotg); in dwc2_gadget_init()
4033 s3c_hsotg_dump(hsotg); in dwc2_gadget_init()
4038 s3c_hsotg_phy_disable(hsotg); in dwc2_gadget_init()
4040 clk_disable_unprepare(hsotg->clk); in dwc2_gadget_init()
4050 int s3c_hsotg_remove(struct dwc2_hsotg *hsotg) in s3c_hsotg_remove() argument
4052 usb_del_gadget_udc(&hsotg->gadget); in s3c_hsotg_remove()
4053 s3c_hsotg_delete_debug(hsotg); in s3c_hsotg_remove()
4054 clk_disable_unprepare(hsotg->clk); in s3c_hsotg_remove()
4060 int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) in s3c_hsotg_suspend() argument
4065 mutex_lock(&hsotg->init_mutex); in s3c_hsotg_suspend()
4067 if (hsotg->driver) { in s3c_hsotg_suspend()
4070 dev_info(hsotg->dev, "suspending usb gadget %s\n", in s3c_hsotg_suspend()
4071 hsotg->driver->driver.name); in s3c_hsotg_suspend()
4073 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_suspend()
4074 if (hsotg->enabled) in s3c_hsotg_suspend()
4075 s3c_hsotg_core_disconnect(hsotg); in s3c_hsotg_suspend()
4076 s3c_hsotg_disconnect(hsotg); in s3c_hsotg_suspend()
4077 hsotg->gadget.speed = USB_SPEED_UNKNOWN; in s3c_hsotg_suspend()
4078 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_suspend()
4080 s3c_hsotg_phy_disable(hsotg); in s3c_hsotg_suspend()
4082 for (ep = 0; ep < hsotg->num_of_eps; ep++) { in s3c_hsotg_suspend()
4083 if (hsotg->eps_in[ep]) in s3c_hsotg_suspend()
4084 s3c_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); in s3c_hsotg_suspend()
4085 if (hsotg->eps_out[ep]) in s3c_hsotg_suspend()
4086 s3c_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); in s3c_hsotg_suspend()
4089 ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), in s3c_hsotg_suspend()
4090 hsotg->supplies); in s3c_hsotg_suspend()
4091 clk_disable(hsotg->clk); in s3c_hsotg_suspend()
4094 mutex_unlock(&hsotg->init_mutex); in s3c_hsotg_suspend()
4100 int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) in s3c_hsotg_resume() argument
4105 mutex_lock(&hsotg->init_mutex); in s3c_hsotg_resume()
4107 if (hsotg->driver) { in s3c_hsotg_resume()
4108 dev_info(hsotg->dev, "resuming usb gadget %s\n", in s3c_hsotg_resume()
4109 hsotg->driver->driver.name); in s3c_hsotg_resume()
4111 clk_enable(hsotg->clk); in s3c_hsotg_resume()
4112 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), in s3c_hsotg_resume()
4113 hsotg->supplies); in s3c_hsotg_resume()
4115 s3c_hsotg_phy_enable(hsotg); in s3c_hsotg_resume()
4117 spin_lock_irqsave(&hsotg->lock, flags); in s3c_hsotg_resume()
4118 s3c_hsotg_core_init_disconnected(hsotg, false); in s3c_hsotg_resume()
4119 if (hsotg->enabled) in s3c_hsotg_resume()
4120 s3c_hsotg_core_connect(hsotg); in s3c_hsotg_resume()
4121 spin_unlock_irqrestore(&hsotg->lock, flags); in s3c_hsotg_resume()
4123 mutex_unlock(&hsotg->init_mutex); in s3c_hsotg_resume()