Lines Matching refs:dwc
29 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep);
30 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
49 static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, in dwc3_ep0_start_trans() argument
58 dep = dwc->eps[epnum]; in dwc3_ep0_start_trans()
60 dev_vdbg(dwc->dev, "%s still busy", dep->name); in dwc3_ep0_start_trans()
64 trb = &dwc->ep0_trb[dep->free_slot]; in dwc3_ep0_start_trans()
90 params.param0 = upper_32_bits(dwc->ep0_trb_addr); in dwc3_ep0_start_trans()
91 params.param1 = lower_32_bits(dwc->ep0_trb_addr); in dwc3_ep0_start_trans()
93 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, in dwc3_ep0_start_trans()
96 dev_dbg(dwc->dev, "%s STARTTRANSFER failed", dep->name); in dwc3_ep0_start_trans()
101 dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc, in dwc3_ep0_start_trans()
104 dwc->ep0_next_event = DWC3_EP0_COMPLETE; in dwc3_ep0_start_trans()
112 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep0_queue() local
134 if (dwc->ep0state != EP0_DATA_PHASE) { in __dwc3_gadget_ep0_queue()
135 dev_WARN(dwc->dev, "Unexpected pending request\n"); in __dwc3_gadget_ep0_queue()
139 __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); in __dwc3_gadget_ep0_queue()
151 if (dwc->delayed_status) { in __dwc3_gadget_ep0_queue()
154 direction = !dwc->ep0_expect_in; in __dwc3_gadget_ep0_queue()
155 dwc->delayed_status = false; in __dwc3_gadget_ep0_queue()
156 usb_gadget_set_state(&dwc->gadget, USB_STATE_CONFIGURED); in __dwc3_gadget_ep0_queue()
158 if (dwc->ep0state == EP0_STATUS_PHASE) in __dwc3_gadget_ep0_queue()
159 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); in __dwc3_gadget_ep0_queue()
161 dev_dbg(dwc->dev, "too early for delayed status"); in __dwc3_gadget_ep0_queue()
198 if (dwc->three_stage_setup) { in __dwc3_gadget_ep0_queue()
201 direction = dwc->ep0_expect_in; in __dwc3_gadget_ep0_queue()
202 dwc->ep0state = EP0_DATA_PHASE; in __dwc3_gadget_ep0_queue()
204 __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); in __dwc3_gadget_ep0_queue()
217 struct dwc3 *dwc = dep->dwc; in dwc3_gadget_ep0_queue() local
223 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep0_queue()
225 dev_dbg(dwc->dev, "trying to queue request %p to disabled %s", in dwc3_gadget_ep0_queue()
237 dev_vdbg(dwc->dev, "queueing request %p to %s length %d state '%s'", in dwc3_gadget_ep0_queue()
239 dwc3_ep0_state_string(dwc->ep0state)); in dwc3_gadget_ep0_queue()
244 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep0_queue()
249 static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc) in dwc3_ep0_stall_and_restart() argument
254 dep = dwc->eps[1]; in dwc3_ep0_stall_and_restart()
258 dep = dwc->eps[0]; in dwc3_ep0_stall_and_restart()
261 dwc->delayed_status = false; in dwc3_ep0_stall_and_restart()
270 dwc->ep0state = EP0_SETUP_PHASE; in dwc3_ep0_stall_and_restart()
271 dwc3_ep0_out_start(dwc); in dwc3_ep0_stall_and_restart()
277 struct dwc3 *dwc = dep->dwc; in __dwc3_gadget_ep0_set_halt() local
279 dwc3_ep0_stall_and_restart(dwc); in __dwc3_gadget_ep0_set_halt()
289 spin_lock_irqsave(&dwc->lock, flags); in dwc3_gadget_ep0_set_halt()
291 spin_unlock_irqrestore(&dwc->lock, flags); in dwc3_gadget_ep0_set_halt()
296 void dwc3_ep0_out_start(struct dwc3 *dwc) in dwc3_ep0_out_start() argument
300 ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8, in dwc3_ep0_out_start()
305 static struct dwc3_ep *dwc3_wIndex_to_dep(struct dwc3 *dwc, __le16 wIndex_le) in dwc3_wIndex_to_dep() argument
315 dep = dwc->eps[epnum]; in dwc3_wIndex_to_dep()
328 static int dwc3_ep0_handle_status(struct dwc3 *dwc, in dwc3_ep0_handle_status() argument
343 usb_status |= dwc->is_selfpowered << USB_DEVICE_SELF_POWERED; in dwc3_ep0_handle_status()
345 if (dwc->speed == DWC3_DSTS_SUPERSPEED) { in dwc3_ep0_handle_status()
346 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_status()
363 dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); in dwc3_ep0_handle_status()
374 response_pkt = (__le16 *) dwc->setup_buf; in dwc3_ep0_handle_status()
377 dep = dwc->eps[0]; in dwc3_ep0_handle_status()
378 dwc->ep0_usb_req.dep = dep; in dwc3_ep0_handle_status()
379 dwc->ep0_usb_req.request.length = sizeof(*response_pkt); in dwc3_ep0_handle_status()
380 dwc->ep0_usb_req.request.buf = dwc->setup_buf; in dwc3_ep0_handle_status()
381 dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl; in dwc3_ep0_handle_status()
383 return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); in dwc3_ep0_handle_status()
386 static int dwc3_ep0_handle_feature(struct dwc3 *dwc, in dwc3_ep0_handle_feature() argument
400 state = dwc->gadget.state; in dwc3_ep0_handle_feature()
415 if (dwc->speed != DWC3_DSTS_SUPERSPEED) in dwc3_ep0_handle_feature()
418 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_feature()
423 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_handle_feature()
429 if (dwc->speed != DWC3_DSTS_SUPERSPEED) in dwc3_ep0_handle_feature()
432 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_handle_feature()
437 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_handle_feature()
449 dwc->test_mode_nr = wIndex >> 8; in dwc3_ep0_handle_feature()
450 dwc->test_mode = true; in dwc3_ep0_handle_feature()
475 dep = dwc3_wIndex_to_dep(dwc, wIndex); in dwc3_ep0_handle_feature()
496 static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_address() argument
498 enum usb_device_state state = dwc->gadget.state; in dwc3_ep0_set_address()
504 dev_dbg(dwc->dev, "invalid device address %d", addr); in dwc3_ep0_set_address()
509 dev_dbg(dwc->dev, "trying to set address when configured"); in dwc3_ep0_set_address()
513 reg = dwc3_readl(dwc->regs, DWC3_DCFG); in dwc3_ep0_set_address()
516 dwc3_writel(dwc->regs, DWC3_DCFG, reg); in dwc3_ep0_set_address()
519 usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); in dwc3_ep0_set_address()
521 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); in dwc3_ep0_set_address()
526 static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_delegate_req() argument
530 spin_unlock(&dwc->lock); in dwc3_ep0_delegate_req()
531 ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl); in dwc3_ep0_delegate_req()
532 spin_lock(&dwc->lock); in dwc3_ep0_delegate_req()
536 static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_config() argument
538 enum usb_device_state state = dwc->gadget.state; in dwc3_ep0_set_config()
543 dwc->start_config_issued = false; in dwc3_ep0_set_config()
551 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_set_config()
562 usb_gadget_set_state(&dwc->gadget, in dwc3_ep0_set_config()
569 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_set_config()
571 dwc3_writel(dwc->regs, DWC3_DCTL, reg); in dwc3_ep0_set_config()
573 dwc->resize_fifos = true; in dwc3_ep0_set_config()
574 dev_dbg(dwc->dev, "resize FIFOs flag SET"); in dwc3_ep0_set_config()
579 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_set_config()
581 usb_gadget_set_state(&dwc->gadget, in dwc3_ep0_set_config()
593 struct dwc3 *dwc = dep->dwc; in dwc3_ep0_set_sel_cmpl() local
609 dwc->u1sel = timing.u1sel; in dwc3_ep0_set_sel_cmpl()
610 dwc->u1pel = timing.u1pel; in dwc3_ep0_set_sel_cmpl()
611 dwc->u2sel = le16_to_cpu(timing.u2sel); in dwc3_ep0_set_sel_cmpl()
612 dwc->u2pel = le16_to_cpu(timing.u2pel); in dwc3_ep0_set_sel_cmpl()
614 reg = dwc3_readl(dwc->regs, DWC3_DCTL); in dwc3_ep0_set_sel_cmpl()
616 param = dwc->u2pel; in dwc3_ep0_set_sel_cmpl()
618 param = dwc->u1pel; in dwc3_ep0_set_sel_cmpl()
629 ret = dwc3_send_gadget_generic_command(dwc, in dwc3_ep0_set_sel_cmpl()
634 static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_sel() argument
637 enum usb_device_state state = dwc->gadget.state; in dwc3_ep0_set_sel()
646 dev_err(dwc->dev, "Set SEL should be 6 bytes, got %d\n", in dwc3_ep0_set_sel()
659 dep = dwc->eps[0]; in dwc3_ep0_set_sel()
660 dwc->ep0_usb_req.dep = dep; in dwc3_ep0_set_sel()
661 dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket; in dwc3_ep0_set_sel()
662 dwc->ep0_usb_req.request.buf = dwc->setup_buf; in dwc3_ep0_set_sel()
663 dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl; in dwc3_ep0_set_sel()
665 return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); in dwc3_ep0_set_sel()
668 static int dwc3_ep0_set_isoch_delay(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_set_isoch_delay() argument
685 dwc->isoch_delay = wValue; in dwc3_ep0_set_isoch_delay()
690 static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) in dwc3_ep0_std_request() argument
696 dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS"); in dwc3_ep0_std_request()
697 ret = dwc3_ep0_handle_status(dwc, ctrl); in dwc3_ep0_std_request()
700 dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE"); in dwc3_ep0_std_request()
701 ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); in dwc3_ep0_std_request()
704 dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE"); in dwc3_ep0_std_request()
705 ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); in dwc3_ep0_std_request()
708 dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS"); in dwc3_ep0_std_request()
709 ret = dwc3_ep0_set_address(dwc, ctrl); in dwc3_ep0_std_request()
712 dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION"); in dwc3_ep0_std_request()
713 ret = dwc3_ep0_set_config(dwc, ctrl); in dwc3_ep0_std_request()
716 dev_vdbg(dwc->dev, "USB_REQ_SET_SEL"); in dwc3_ep0_std_request()
717 ret = dwc3_ep0_set_sel(dwc, ctrl); in dwc3_ep0_std_request()
720 dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY"); in dwc3_ep0_std_request()
721 ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); in dwc3_ep0_std_request()
724 dev_vdbg(dwc->dev, "Forwarding to gadget driver"); in dwc3_ep0_std_request()
725 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_std_request()
732 static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, in dwc3_ep0_inspect_setup() argument
735 struct usb_ctrlrequest *ctrl = dwc->ctrl_req; in dwc3_ep0_inspect_setup()
739 if (!dwc->gadget_driver) in dwc3_ep0_inspect_setup()
744 dwc->three_stage_setup = false; in dwc3_ep0_inspect_setup()
745 dwc->ep0_expect_in = false; in dwc3_ep0_inspect_setup()
746 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; in dwc3_ep0_inspect_setup()
748 dwc->three_stage_setup = true; in dwc3_ep0_inspect_setup()
749 dwc->ep0_expect_in = !!(ctrl->bRequestType & USB_DIR_IN); in dwc3_ep0_inspect_setup()
750 dwc->ep0_next_event = DWC3_EP0_NRDY_DATA; in dwc3_ep0_inspect_setup()
754 ret = dwc3_ep0_std_request(dwc, ctrl); in dwc3_ep0_inspect_setup()
756 ret = dwc3_ep0_delegate_req(dwc, ctrl); in dwc3_ep0_inspect_setup()
759 dwc->delayed_status = true; in dwc3_ep0_inspect_setup()
763 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_inspect_setup()
766 static void dwc3_ep0_complete_data(struct dwc3 *dwc, in dwc3_ep0_complete_data() argument
782 ep0 = dwc->eps[0]; in dwc3_ep0_complete_data()
784 dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; in dwc3_ep0_complete_data()
786 trb = dwc->ep0_trb; in dwc3_ep0_complete_data()
796 dev_dbg(dwc->dev, "Setup Pending received"); in dwc3_ep0_complete_data()
811 if (dwc->ep0_bounced) { in dwc3_ep0_complete_data()
833 dwc3_flush_cache((uintptr_t)dwc->ep0_bounce, DWC3_EP0_BOUNCE_SIZE); in dwc3_ep0_complete_data()
834 memcpy(buf, dwc->ep0_bounce, transferred); in dwc3_ep0_complete_data()
844 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_complete_data()
852 dwc->ep0_next_event = DWC3_EP0_COMPLETE; in dwc3_ep0_complete_data()
854 ret = dwc3_ep0_start_trans(dwc, epnum, in dwc3_ep0_complete_data()
855 dwc->ctrl_req_addr, 0, in dwc3_ep0_complete_data()
862 static void dwc3_ep0_complete_status(struct dwc3 *dwc, in dwc3_ep0_complete_status() argument
870 dep = dwc->eps[0]; in dwc3_ep0_complete_status()
871 trb = dwc->ep0_trb; in dwc3_ep0_complete_status()
879 if (dwc->test_mode) { in dwc3_ep0_complete_status()
882 ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); in dwc3_ep0_complete_status()
884 dev_dbg(dwc->dev, "Invalid Test #%d", in dwc3_ep0_complete_status()
885 dwc->test_mode_nr); in dwc3_ep0_complete_status()
886 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_complete_status()
893 dev_dbg(dwc->dev, "Setup Pending received"); in dwc3_ep0_complete_status()
895 dwc->ep0state = EP0_SETUP_PHASE; in dwc3_ep0_complete_status()
896 dwc3_ep0_out_start(dwc); in dwc3_ep0_complete_status()
899 static void dwc3_ep0_xfer_complete(struct dwc3 *dwc, in dwc3_ep0_xfer_complete() argument
902 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; in dwc3_ep0_xfer_complete()
906 dwc->setup_packet_pending = false; in dwc3_ep0_xfer_complete()
908 switch (dwc->ep0state) { in dwc3_ep0_xfer_complete()
910 dev_vdbg(dwc->dev, "Setup Phase"); in dwc3_ep0_xfer_complete()
911 dwc3_ep0_inspect_setup(dwc, event); in dwc3_ep0_xfer_complete()
915 dev_vdbg(dwc->dev, "Data Phase"); in dwc3_ep0_xfer_complete()
916 dwc3_ep0_complete_data(dwc, event); in dwc3_ep0_xfer_complete()
920 dev_vdbg(dwc->dev, "Status Phase"); in dwc3_ep0_xfer_complete()
921 dwc3_ep0_complete_status(dwc, event); in dwc3_ep0_xfer_complete()
924 WARN(true, "UNKNOWN ep0state %d\n", dwc->ep0state); in dwc3_ep0_xfer_complete()
928 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, in __dwc3_ep0_do_control_data() argument
936 ret = dwc3_ep0_start_trans(dwc, dep->number, in __dwc3_ep0_do_control_data()
937 dwc->ctrl_req_addr, 0, in __dwc3_ep0_do_control_data()
944 ret = usb_gadget_map_request(&dwc->gadget, &req->request, in __dwc3_ep0_do_control_data()
947 dev_dbg(dwc->dev, "failed to map request\n"); in __dwc3_ep0_do_control_data()
955 ret = dwc3_ep0_start_trans(dwc, dep->number, in __dwc3_ep0_do_control_data()
964 dwc->ep0_bounced = true; in __dwc3_ep0_do_control_data()
971 ret = dwc3_ep0_start_trans(dwc, dep->number, in __dwc3_ep0_do_control_data()
972 dwc->ep0_bounce_addr, transfer_size, in __dwc3_ep0_do_control_data()
975 ret = usb_gadget_map_request(&dwc->gadget, &req->request, in __dwc3_ep0_do_control_data()
978 dev_dbg(dwc->dev, "failed to map request\n"); in __dwc3_ep0_do_control_data()
982 ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma, in __dwc3_ep0_do_control_data()
992 struct dwc3 *dwc = dep->dwc; in dwc3_ep0_start_control_status() local
995 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3 in dwc3_ep0_start_control_status()
998 return dwc3_ep0_start_trans(dwc, dep->number, in dwc3_ep0_start_control_status()
999 dwc->ctrl_req_addr, 0, type, 0); in dwc3_ep0_start_control_status()
1002 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) in __dwc3_ep0_do_control_status() argument
1004 if (dwc->resize_fifos) { in __dwc3_ep0_do_control_status()
1005 dev_dbg(dwc->dev, "Resizing FIFOs"); in __dwc3_ep0_do_control_status()
1006 dwc3_gadget_resize_tx_fifos(dwc); in __dwc3_ep0_do_control_status()
1007 dwc->resize_fifos = 0; in __dwc3_ep0_do_control_status()
1013 static void dwc3_ep0_do_control_status(struct dwc3 *dwc, in dwc3_ep0_do_control_status() argument
1016 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; in dwc3_ep0_do_control_status()
1018 __dwc3_ep0_do_control_status(dwc, dep); in dwc3_ep0_do_control_status()
1021 static void dwc3_ep0_end_control_data(struct dwc3 *dwc, struct dwc3_ep *dep) in dwc3_ep0_end_control_data() argument
1034 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, ¶ms); in dwc3_ep0_end_control_data()
1039 static void dwc3_ep0_xfernotready(struct dwc3 *dwc, in dwc3_ep0_xfernotready() argument
1042 dwc->setup_packet_pending = true; in dwc3_ep0_xfernotready()
1046 dev_vdbg(dwc->dev, "Control Data"); in dwc3_ep0_xfernotready()
1057 if (dwc->ep0_expect_in != event->endpoint_number) { in dwc3_ep0_xfernotready()
1058 struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; in dwc3_ep0_xfernotready()
1060 dev_vdbg(dwc->dev, "Wrong direction for Data phase"); in dwc3_ep0_xfernotready()
1061 dwc3_ep0_end_control_data(dwc, dep); in dwc3_ep0_xfernotready()
1062 dwc3_ep0_stall_and_restart(dwc); in dwc3_ep0_xfernotready()
1069 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) in dwc3_ep0_xfernotready()
1072 dev_vdbg(dwc->dev, "Control Status"); in dwc3_ep0_xfernotready()
1074 dwc->ep0state = EP0_STATUS_PHASE; in dwc3_ep0_xfernotready()
1076 if (dwc->delayed_status) { in dwc3_ep0_xfernotready()
1078 dev_vdbg(dwc->dev, "Delayed Status"); in dwc3_ep0_xfernotready()
1082 dwc3_ep0_do_control_status(dwc, event); in dwc3_ep0_xfernotready()
1086 void dwc3_ep0_interrupt(struct dwc3 *dwc, in dwc3_ep0_interrupt() argument
1091 dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'", in dwc3_ep0_interrupt()
1094 dwc3_ep0_state_string(dwc->ep0state)); in dwc3_ep0_interrupt()
1098 dwc3_ep0_xfer_complete(dwc, event); in dwc3_ep0_interrupt()
1102 dwc3_ep0_xfernotready(dwc, event); in dwc3_ep0_interrupt()