Lines Matching refs:dwc

33 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep);
34 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
53 static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, in dwc3_ep0_start_trans() argument
62 dep = dwc->eps[epnum]; in dwc3_ep0_start_trans()
64 dev_vdbg(dwc->dev, "%s still busy", dep->name); in dwc3_ep0_start_trans()
68 trb = &dwc->ep0_trb[dep->free_slot]; in dwc3_ep0_start_trans()
94 params.param0 = upper_32_bits(dwc->ep0_trb_addr); in dwc3_ep0_start_trans()
95 params.param1 = lower_32_bits(dwc->ep0_trb_addr); in dwc3_ep0_start_trans()
97 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, in dwc3_ep0_start_trans()
100 dev_dbg(dwc->dev, "%s STARTTRANSFER failed", dep->name); in dwc3_ep0_start_trans()
105 dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc, in dwc3_ep0_start_trans()
108 dwc->ep0_next_event = DWC3_EP0_COMPLETE; in dwc3_ep0_start_trans()
116 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep0_queue() local
138 if (dwc->ep0state != EP0_DATA_PHASE) { in __dwc3_gadget_ep0_queue()
139 dev_WARN(dwc->dev, "Unexpected pending request\n"); in __dwc3_gadget_ep0_queue()
143 __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); in __dwc3_gadget_ep0_queue()
155 if (dwc->delayed_status) { in __dwc3_gadget_ep0_queue()
158 direction = !dwc->ep0_expect_in; in __dwc3_gadget_ep0_queue()
159 dwc->delayed_status = false; in __dwc3_gadget_ep0_queue()
160 usb_gadget_set_state(&dwc->gadget, USB_STATE_CONFIGURED); in __dwc3_gadget_ep0_queue()
162 if (dwc->ep0state == EP0_STATUS_PHASE) in __dwc3_gadget_ep0_queue()
163 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); in __dwc3_gadget_ep0_queue()
165 dev_dbg(dwc->dev, "too early for delayed status"); in __dwc3_gadget_ep0_queue()
202 if (dwc->three_stage_setup) { in __dwc3_gadget_ep0_queue()
205 direction = dwc->ep0_expect_in; in __dwc3_gadget_ep0_queue()
206 dwc->ep0state = EP0_DATA_PHASE; in __dwc3_gadget_ep0_queue()
208 __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); in __dwc3_gadget_ep0_queue()
221 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep0_queue() local
227 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep0_queue()
229 dev_dbg(dwc->dev, "trying to queue request %p to disabled %s", in dwc3_gadget_ep0_queue()
241 dev_vdbg(dwc->dev, "queueing request %p to %s length %d state '%s'", in dwc3_gadget_ep0_queue()
243 dwc3_ep0_state_string(dwc->ep0state)); in dwc3_gadget_ep0_queue()
248 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep0_queue()
253 static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc) in dwc3_ep0_stall_and_restart() argument
258 dep = dwc->eps[1]; in dwc3_ep0_stall_and_restart()
262 dep = dwc->eps[0]; in dwc3_ep0_stall_and_restart()
265 dwc->delayed_status = false; in dwc3_ep0_stall_and_restart()
274 dwc->ep0state = EP0_SETUP_PHASE; in dwc3_ep0_stall_and_restart()
275 dwc3_ep0_out_start(dwc); in dwc3_ep0_stall_and_restart()
281 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep0_set_halt() local
283 dwc3_ep0_stall_and_restart(dwc); in __dwc3_gadget_ep0_set_halt()
293 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep0_set_halt()
295 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep0_set_halt()
300 void dwc3_ep0_out_start(struct dwc3 *dwc) in dwc3_ep0_out_start() argument
304 ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8, in dwc3_ep0_out_start()
309 static struct dwc3_ep *dwc3_wIndex_to_dep(struct dwc3 *dwc, __le16 wIndex_le) in dwc3_wIndex_to_dep() argument
319 dep = dwc->eps[epnum]; in dwc3_wIndex_to_dep()
332 static int dwc3_ep0_handle_status(struct dwc3 *dwc, in dwc3_ep0_handle_status() argument
347 usb_status |= dwc->is_selfpowered << USB_DEVICE_SELF_POWERED; in dwc3_ep0_handle_status()
349 if (dwc->speed == DWC3_DSTS_SUPERSPEED) { in dwc3_ep0_handle_status()
350 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_status()
367 dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); in dwc3_ep0_handle_status()
378 response_pkt = (__le16 *) dwc->setup_buf; in dwc3_ep0_handle_status()
381 dep = dwc->eps[0]; in dwc3_ep0_handle_status()
382 dwc->ep0_usb_req.dep = dep; in dwc3_ep0_handle_status()
383 dwc->ep0_usb_req.request.length = sizeof(*response_pkt); in dwc3_ep0_handle_status()
384 dwc->ep0_usb_req.request.buf = dwc->setup_buf; in dwc3_ep0_handle_status()
385 dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl; in dwc3_ep0_handle_status()
387 return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); in dwc3_ep0_handle_status()
390 static int dwc3_ep0_handle_feature(struct dwc3 *dwc, in dwc3_ep0_handle_feature() argument
404 state = dwc->gadget.state; in dwc3_ep0_handle_feature()
419 if (dwc->speed != DWC3_DSTS_SUPERSPEED) in dwc3_ep0_handle_feature()
422 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_feature()
427 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_handle_feature()
433 if (dwc->speed != DWC3_DSTS_SUPERSPEED) in dwc3_ep0_handle_feature()
436 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_feature()
441 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_handle_feature()
453 dwc->test_mode_nr = wIndex >> 8; in dwc3_ep0_handle_feature()
454 dwc->test_mode = true; in dwc3_ep0_handle_feature()
479 dep = dwc3_wIndex_to_dep(dwc, wIndex); in dwc3_ep0_handle_feature()
500 static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_address() argument
502 enum usb_device_state state = dwc->gadget.state; in dwc3_ep0_set_address()
508 dev_dbg(dwc->dev, "invalid device address %d", addr); in dwc3_ep0_set_address()
513 dev_dbg(dwc->dev, "trying to set address when configured"); in dwc3_ep0_set_address()
517 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_ep0_set_address()
520 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_ep0_set_address()
523 usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); in dwc3_ep0_set_address()
525 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); in dwc3_ep0_set_address()
530 static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_delegate_req() argument
534 spin_unlock(&dwc->lock); in dwc3_ep0_delegate_req()
535 ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl); in dwc3_ep0_delegate_req()
536 spin_lock(&dwc->lock); in dwc3_ep0_delegate_req()
540 static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_config() argument
542 enum usb_device_state state = dwc->gadget.state; in dwc3_ep0_set_config()
547 dwc->start_config_issued = false; in dwc3_ep0_set_config()
555 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_set_config()
566 usb_gadget_set_state(&dwc->gadget, in dwc3_ep0_set_config()
573 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_set_config()
575 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_set_config()
577 dwc->resize_fifos = true; in dwc3_ep0_set_config()
578 dev_dbg(dwc->dev, "resize FIFOs flag SET"); in dwc3_ep0_set_config()
583 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_set_config()
585 usb_gadget_set_state(&dwc->gadget, in dwc3_ep0_set_config()
597 struct dwc3 *dwc = dep->dwc; in dwc3_ep0_set_sel_cmpl() local
613 dwc->u1sel = timing.u1sel; in dwc3_ep0_set_sel_cmpl()
614 dwc->u1pel = timing.u1pel; in dwc3_ep0_set_sel_cmpl()
615 dwc->u2sel = le16_to_cpu(timing.u2sel); in dwc3_ep0_set_sel_cmpl()
616 dwc->u2pel = le16_to_cpu(timing.u2pel); in dwc3_ep0_set_sel_cmpl()
618 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_set_sel_cmpl()
620 param = dwc->u2pel; in dwc3_ep0_set_sel_cmpl()
622 param = dwc->u1pel; in dwc3_ep0_set_sel_cmpl()
633 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_ep0_set_sel_cmpl()
638 static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_sel() argument
641 enum usb_device_state state = dwc->gadget.state; in dwc3_ep0_set_sel()
650 dev_err(dwc->dev, "Set SEL should be 6 bytes, got %d\n", in dwc3_ep0_set_sel()
663 dep = dwc->eps[0]; in dwc3_ep0_set_sel()
664 dwc->ep0_usb_req.dep = dep; in dwc3_ep0_set_sel()
665 dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket; in dwc3_ep0_set_sel()
666 dwc->ep0_usb_req.request.buf = dwc->setup_buf; in dwc3_ep0_set_sel()
667 dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl; in dwc3_ep0_set_sel()
669 return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); in dwc3_ep0_set_sel()
672 static int dwc3_ep0_set_isoch_delay(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_isoch_delay() argument
689 dwc->isoch_delay = wValue; in dwc3_ep0_set_isoch_delay()
694 static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_std_request() argument
700 dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS"); in dwc3_ep0_std_request()
701 ret = dwc3_ep0_handle_status(dwc, ctrl); in dwc3_ep0_std_request()
704 dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE"); in dwc3_ep0_std_request()
705 ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); in dwc3_ep0_std_request()
708 dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE"); in dwc3_ep0_std_request()
709 ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); in dwc3_ep0_std_request()
712 dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS"); in dwc3_ep0_std_request()
713 ret = dwc3_ep0_set_address(dwc, ctrl); in dwc3_ep0_std_request()
716 dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION"); in dwc3_ep0_std_request()
717 ret = dwc3_ep0_set_config(dwc, ctrl); in dwc3_ep0_std_request()
720 dev_vdbg(dwc->dev, "USB_REQ_SET_SEL"); in dwc3_ep0_std_request()
721 ret = dwc3_ep0_set_sel(dwc, ctrl); in dwc3_ep0_std_request()
724 dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY"); in dwc3_ep0_std_request()
725 ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); in dwc3_ep0_std_request()
728 dev_vdbg(dwc->dev, "Forwarding to gadget driver"); in dwc3_ep0_std_request()
729 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_std_request()
736 static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, in dwc3_ep0_inspect_setup() argument
739 struct usb_ctrlrequest *ctrl = dwc->ctrl_req; in dwc3_ep0_inspect_setup()
743 if (!dwc->gadget_driver) in dwc3_ep0_inspect_setup()
748 dwc->three_stage_setup = false; in dwc3_ep0_inspect_setup()
749 dwc->ep0_expect_in = false; in dwc3_ep0_inspect_setup()
750 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; in dwc3_ep0_inspect_setup()
752 dwc->three_stage_setup = true; in dwc3_ep0_inspect_setup()
753 dwc->ep0_expect_in = !!(ctrl->bRequestType & USB_DIR_IN); in dwc3_ep0_inspect_setup()
754 dwc->ep0_next_event = DWC3_EP0_NRDY_DATA; in dwc3_ep0_inspect_setup()
758 ret = dwc3_ep0_std_request(dwc, ctrl); in dwc3_ep0_inspect_setup()
760 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_inspect_setup()
763 dwc->delayed_status = true; in dwc3_ep0_inspect_setup()
767 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_inspect_setup()
770 static void dwc3_ep0_complete_data(struct dwc3 *dwc, in dwc3_ep0_complete_data() argument
786 ep0 = dwc->eps[0]; in dwc3_ep0_complete_data()
788 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; in dwc3_ep0_complete_data()
790 trb = dwc->ep0_trb; in dwc3_ep0_complete_data()
800 dev_dbg(dwc->dev, "Setup Pending received"); in dwc3_ep0_complete_data()
815 if (dwc->ep0_bounced) { in dwc3_ep0_complete_data()
837 dwc3_flush_cache((uintptr_t)dwc->ep0_bounce, DWC3_EP0_BOUNCE_SIZE); in dwc3_ep0_complete_data()
838 memcpy(buf, dwc->ep0_bounce, transferred); in dwc3_ep0_complete_data()
848 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_complete_data()
856 dwc->ep0_next_event = DWC3_EP0_COMPLETE; in dwc3_ep0_complete_data()
858 ret = dwc3_ep0_start_trans(dwc, epnum, in dwc3_ep0_complete_data()
859 dwc->ctrl_req_addr, 0, in dwc3_ep0_complete_data()
866 static void dwc3_ep0_complete_status(struct dwc3 *dwc, in dwc3_ep0_complete_status() argument
874 dep = dwc->eps[0]; in dwc3_ep0_complete_status()
875 trb = dwc->ep0_trb; in dwc3_ep0_complete_status()
883 if (dwc->test_mode) { in dwc3_ep0_complete_status()
886 ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); in dwc3_ep0_complete_status()
888 dev_dbg(dwc->dev, "Invalid Test #%d", in dwc3_ep0_complete_status()
889 dwc->test_mode_nr); in dwc3_ep0_complete_status()
890 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_complete_status()
897 dev_dbg(dwc->dev, "Setup Pending received"); in dwc3_ep0_complete_status()
899 dwc->ep0state = EP0_SETUP_PHASE; in dwc3_ep0_complete_status()
900 dwc3_ep0_out_start(dwc); in dwc3_ep0_complete_status()
903 static void dwc3_ep0_xfer_complete(struct dwc3 *dwc, in dwc3_ep0_xfer_complete() argument
906 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; in dwc3_ep0_xfer_complete()
910 dwc->setup_packet_pending = false; in dwc3_ep0_xfer_complete()
912 switch (dwc->ep0state) { in dwc3_ep0_xfer_complete()
914 dev_vdbg(dwc->dev, "Setup Phase"); in dwc3_ep0_xfer_complete()
915 dwc3_ep0_inspect_setup(dwc, event); in dwc3_ep0_xfer_complete()
919 dev_vdbg(dwc->dev, "Data Phase"); in dwc3_ep0_xfer_complete()
920 dwc3_ep0_complete_data(dwc, event); in dwc3_ep0_xfer_complete()
924 dev_vdbg(dwc->dev, "Status Phase"); in dwc3_ep0_xfer_complete()
925 dwc3_ep0_complete_status(dwc, event); in dwc3_ep0_xfer_complete()
928 WARN(true, "UNKNOWN ep0state %d\n", dwc->ep0state); in dwc3_ep0_xfer_complete()
932 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, in __dwc3_ep0_do_control_data() argument
940 ret = dwc3_ep0_start_trans(dwc, dep->number, in __dwc3_ep0_do_control_data()
941 dwc->ctrl_req_addr, 0, in __dwc3_ep0_do_control_data()
948 ret = usb_gadget_map_request(&dwc->gadget, &req->request, in __dwc3_ep0_do_control_data()
951 dev_dbg(dwc->dev, "failed to map request\n"); in __dwc3_ep0_do_control_data()
959 ret = dwc3_ep0_start_trans(dwc, dep->number, in __dwc3_ep0_do_control_data()
968 dwc->ep0_bounced = true; in __dwc3_ep0_do_control_data()
975 ret = dwc3_ep0_start_trans(dwc, dep->number, in __dwc3_ep0_do_control_data()
976 dwc->ep0_bounce_addr, transfer_size, in __dwc3_ep0_do_control_data()
979 ret = usb_gadget_map_request(&dwc->gadget, &req->request, in __dwc3_ep0_do_control_data()
982 dev_dbg(dwc->dev, "failed to map request\n"); in __dwc3_ep0_do_control_data()
986 ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma, in __dwc3_ep0_do_control_data()
996 struct dwc3 *dwc = dep->dwc; in dwc3_ep0_start_control_status() local
999 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3 in dwc3_ep0_start_control_status()
1002 return dwc3_ep0_start_trans(dwc, dep->number, in dwc3_ep0_start_control_status()
1003 dwc->ctrl_req_addr, 0, type, 0); in dwc3_ep0_start_control_status()
1006 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) in __dwc3_ep0_do_control_status() argument
1008 if (dwc->resize_fifos) { in __dwc3_ep0_do_control_status()
1009 dev_dbg(dwc->dev, "Resizing FIFOs"); in __dwc3_ep0_do_control_status()
1010 dwc3_gadget_resize_tx_fifos(dwc); in __dwc3_ep0_do_control_status()
1011 dwc->resize_fifos = 0; in __dwc3_ep0_do_control_status()
1017 static void dwc3_ep0_do_control_status(struct dwc3 *dwc, in dwc3_ep0_do_control_status() argument
1020 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; in dwc3_ep0_do_control_status()
1022 __dwc3_ep0_do_control_status(dwc, dep); in dwc3_ep0_do_control_status()
1025 static void dwc3_ep0_end_control_data(struct dwc3 *dwc, struct dwc3_ep *dep) in dwc3_ep0_end_control_data() argument
1038 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); in dwc3_ep0_end_control_data()
1043 static void dwc3_ep0_xfernotready(struct dwc3 *dwc, in dwc3_ep0_xfernotready() argument
1046 dwc->setup_packet_pending = true; in dwc3_ep0_xfernotready()
1050 dev_vdbg(dwc->dev, "Control Data"); in dwc3_ep0_xfernotready()
1061 if (dwc->ep0_expect_in != event->endpoint_number) { in dwc3_ep0_xfernotready()
1062 struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; in dwc3_ep0_xfernotready()
1064 dev_vdbg(dwc->dev, "Wrong direction for Data phase"); in dwc3_ep0_xfernotready()
1065 dwc3_ep0_end_control_data(dwc, dep); in dwc3_ep0_xfernotready()
1066 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_xfernotready()
1073 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) in dwc3_ep0_xfernotready()
1076 dev_vdbg(dwc->dev, "Control Status"); in dwc3_ep0_xfernotready()
1078 dwc->ep0state = EP0_STATUS_PHASE; in dwc3_ep0_xfernotready()
1080 if (dwc->delayed_status) { in dwc3_ep0_xfernotready()
1082 dev_vdbg(dwc->dev, "Delayed Status"); in dwc3_ep0_xfernotready()
1086 dwc3_ep0_do_control_status(dwc, event); in dwc3_ep0_xfernotready()
1090 void dwc3_ep0_interrupt(struct dwc3 *dwc, in dwc3_ep0_interrupt() argument
1095 dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'", in dwc3_ep0_interrupt()
1098 dwc3_ep0_state_string(dwc->ep0state)); in dwc3_ep0_interrupt()
1102 dwc3_ep0_xfer_complete(dwc, event); in dwc3_ep0_interrupt()
1106 dwc3_ep0_xfernotready(dwc, event); in dwc3_ep0_interrupt()