Lines Matching full:mtu
18 #define next_ep0_request(mtu) next_request((mtu)->ep0) argument
39 static char *decode_ep0_state(struct mtu3 *mtu) in decode_ep0_state() argument
41 switch (mtu->ep0_state) { in decode_ep0_state()
57 static void ep0_req_giveback(struct mtu3 *mtu, struct usb_request *req) in ep0_req_giveback() argument
59 mtu3_req_complete(mtu->ep0, req, 0); in ep0_req_giveback()
63 forward_to_driver(struct mtu3 *mtu, const struct usb_ctrlrequest *setup) in forward_to_driver() argument
64 __releases(mtu->lock) in forward_to_driver()
65 __acquires(mtu->lock) in forward_to_driver()
69 if (!mtu->gadget_driver || !mtu->async_callbacks) in forward_to_driver()
72 spin_unlock(&mtu->lock); in forward_to_driver()
73 ret = mtu->gadget_driver->setup(&mtu->g, setup); in forward_to_driver()
74 spin_lock(&mtu->lock); in forward_to_driver()
76 dev_dbg(mtu->dev, "%s ret %d\n", __func__, ret); in forward_to_driver()
82 void __iomem *fifo = mep->mtu->mac_base + U3D_FIFO0; in ep0_write_fifo()
85 dev_dbg(mep->mtu->dev, "%s: ep%din, len=%d, buf=%p\n", in ep0_write_fifo()
102 void __iomem *fifo = mep->mtu->mac_base + U3D_FIFO0; in ep0_read_fifo()
106 dev_dbg(mep->mtu->dev, "%s: ep%dout len=%d buf=%p\n", in ep0_read_fifo()
120 static void ep0_load_test_packet(struct mtu3 *mtu) in ep0_load_test_packet() argument
126 ep0_write_fifo(mtu->ep0, mtu3_test_packet, sizeof(mtu3_test_packet)); in ep0_load_test_packet()
137 struct mtu3 *mtu = mep0->mtu; in ep0_stall_set() local
138 void __iomem *mbase = mtu->mac_base; in ep0_stall_set()
147 mtu3_writel(mtu->mac_base, U3D_EP0CSR, csr); in ep0_stall_set()
149 mtu->delayed_status = false; in ep0_stall_set()
150 mtu->ep0_state = MU3D_EP0_STATE_SETUP; in ep0_stall_set()
152 dev_dbg(mtu->dev, "ep0: %s STALL, ep0_state: %s\n", in ep0_stall_set()
153 set ? "SEND" : "CLEAR", decode_ep0_state(mtu)); in ep0_stall_set()
156 static void ep0_do_status_stage(struct mtu3 *mtu) in ep0_do_status_stage() argument
158 void __iomem *mbase = mtu->mac_base; in ep0_do_status_stage()
173 struct mtu3 *mtu; in ep0_set_sel_complete() local
179 mtu = mreq->mtu; in ep0_set_sel_complete()
180 dev_dbg(mtu->dev, "u1sel:%d, u1pel:%d, u2sel:%d, u2pel:%d\n", in ep0_set_sel_complete()
185 static int ep0_set_sel(struct mtu3 *mtu, struct usb_ctrlrequest *setup) in ep0_set_sel() argument
191 dev_err(mtu->dev, "%s wrong wLength:%d\n", in ep0_set_sel()
196 mtu->ep0_req.mep = mtu->ep0; in ep0_set_sel()
197 mtu->ep0_req.request.length = 6; in ep0_set_sel()
198 mtu->ep0_req.request.buf = mtu->setup_buf; in ep0_set_sel()
199 mtu->ep0_req.request.complete = ep0_set_sel_complete; in ep0_set_sel()
200 ret = ep0_queue(mtu->ep0, &mtu->ep0_req); in ep0_set_sel()
206 ep0_get_status(struct mtu3 *mtu, const struct usb_ctrlrequest *setup) in ep0_get_status() argument
216 result[0] = mtu->is_self_powered << USB_DEVICE_SELF_POWERED; in ep0_get_status()
217 result[0] |= mtu->may_wakeup << USB_DEVICE_REMOTE_WAKEUP; in ep0_get_status()
219 if (mtu->g.speed >= USB_SPEED_SUPER) { in ep0_get_status()
220 result[0] |= mtu->u1_enable << USB_DEV_STAT_U1_ENABLED; in ep0_get_status()
221 result[0] |= mtu->u2_enable << USB_DEV_STAT_U2_ENABLED; in ep0_get_status()
224 dev_dbg(mtu->dev, "%s result=%x, U1=%x, U2=%x\n", __func__, in ep0_get_status()
225 result[0], mtu->u1_enable, mtu->u2_enable); in ep0_get_status()
237 if (epnum >= mtu->num_eps) { in ep0_get_status()
244 mep = (is_in ? mtu->in_eps : mtu->out_eps) + epnum; in ep0_get_status()
263 dev_dbg(mtu->dev, "get_status=%x\n", *(u16 *)result); in ep0_get_status()
264 memcpy(mtu->setup_buf, result, sizeof(result)); in ep0_get_status()
265 mtu->ep0_req.mep = mtu->ep0; in ep0_get_status()
266 mtu->ep0_req.request.length = 2; in ep0_get_status()
267 mtu->ep0_req.request.buf = &mtu->setup_buf; in ep0_get_status()
268 mtu->ep0_req.request.complete = ep0_dummy_complete; in ep0_get_status()
269 ret = ep0_queue(mtu->ep0, &mtu->ep0_req); in ep0_get_status()
276 static int handle_test_mode(struct mtu3 *mtu, struct usb_ctrlrequest *setup) in handle_test_mode() argument
278 void __iomem *mbase = mtu->mac_base; in handle_test_mode()
284 dev_dbg(mtu->dev, "USB_TEST_J\n"); in handle_test_mode()
285 mtu->test_mode_nr = TEST_J_MODE; in handle_test_mode()
288 dev_dbg(mtu->dev, "USB_TEST_K\n"); in handle_test_mode()
289 mtu->test_mode_nr = TEST_K_MODE; in handle_test_mode()
292 dev_dbg(mtu->dev, "USB_TEST_SE0_NAK\n"); in handle_test_mode()
293 mtu->test_mode_nr = TEST_SE0_NAK_MODE; in handle_test_mode()
296 dev_dbg(mtu->dev, "USB_TEST_PACKET\n"); in handle_test_mode()
297 mtu->test_mode_nr = TEST_PACKET_MODE; in handle_test_mode()
304 mtu->test_mode = true; in handle_test_mode()
307 if (mtu->test_mode_nr == TEST_PACKET_MODE) in handle_test_mode()
308 ep0_load_test_packet(mtu); in handle_test_mode()
311 ep0_do_status_stage(mtu); in handle_test_mode()
317 mtu3_writel(mbase, U3D_USB2_TEST_MODE, mtu->test_mode_nr); in handle_test_mode()
319 mtu->ep0_state = MU3D_EP0_STATE_SETUP; in handle_test_mode()
325 static int ep0_handle_feature_dev(struct mtu3 *mtu, in ep0_handle_feature_dev() argument
328 void __iomem *mbase = mtu->mac_base; in ep0_handle_feature_dev()
334 mtu->may_wakeup = !!set; in ep0_handle_feature_dev()
338 if (!set || (mtu->g.speed != USB_SPEED_HIGH) || in ep0_handle_feature_dev()
342 handled = handle_test_mode(mtu, setup); in ep0_handle_feature_dev()
345 if (mtu->g.speed < USB_SPEED_SUPER || in ep0_handle_feature_dev()
346 mtu->g.state != USB_STATE_CONFIGURED) in ep0_handle_feature_dev()
356 mtu->u1_enable = !!set; in ep0_handle_feature_dev()
360 if (mtu->g.speed < USB_SPEED_SUPER || in ep0_handle_feature_dev()
361 mtu->g.state != USB_STATE_CONFIGURED) in ep0_handle_feature_dev()
371 mtu->u2_enable = !!set; in ep0_handle_feature_dev()
381 static int ep0_handle_feature(struct mtu3 *mtu, in ep0_handle_feature() argument
396 handled = ep0_handle_feature_dev(mtu, setup, set); in ep0_handle_feature()
401 mtu->g.speed >= USB_SPEED_SUPER) { in ep0_handle_feature()
403 mtu->may_wakeup = !!(index & USB_INTRF_FUNC_SUSPEND_RW); in ep0_handle_feature()
409 if (epnum == 0 || epnum >= mtu->num_eps || in ep0_handle_feature()
414 mep = (is_in ? mtu->in_eps : mtu->out_eps) + epnum; in ep0_handle_feature()
440 static int handle_standard_request(struct mtu3 *mtu, in handle_standard_request() argument
443 void __iomem *mbase = mtu->mac_base; in handle_standard_request()
444 enum usb_device_state state = mtu->g.state; in handle_standard_request()
455 mtu->address = (u8) (value & 0x7f); in handle_standard_request()
456 dev_dbg(mtu->dev, "set address to 0x%x\n", mtu->address); in handle_standard_request()
460 dev_conf |= DEV_ADDR(mtu->address); in handle_standard_request()
463 if (mtu->address) in handle_standard_request()
464 usb_gadget_set_state(&mtu->g, USB_STATE_ADDRESS); in handle_standard_request()
466 usb_gadget_set_state(&mtu->g, USB_STATE_DEFAULT); in handle_standard_request()
472 usb_gadget_set_state(&mtu->g, in handle_standard_request()
480 usb_gadget_set_state(&mtu->g, in handle_standard_request()
486 handled = ep0_handle_feature(mtu, setup, 0); in handle_standard_request()
489 handled = ep0_handle_feature(mtu, setup, 1); in handle_standard_request()
492 handled = ep0_get_status(mtu, setup); in handle_standard_request()
495 handled = ep0_set_sel(mtu, setup); in handle_standard_request()
509 static void ep0_rx_state(struct mtu3 *mtu) in ep0_rx_state() argument
513 void __iomem *mbase = mtu->mac_base; in ep0_rx_state()
518 dev_dbg(mtu->dev, "%s\n", __func__); in ep0_rx_state()
521 mreq = next_ep0_request(mtu); in ep0_rx_state()
535 ep0_read_fifo(mtu->ep0, buf, count); in ep0_rx_state()
539 maxp = mtu->g.ep0->maxpacket; in ep0_rx_state()
541 mtu->ep0_state = MU3D_EP0_STATE_SETUP; in ep0_rx_state()
542 dev_dbg(mtu->dev, "ep0 state: %s\n", in ep0_rx_state()
543 decode_ep0_state(mtu)); in ep0_rx_state()
551 dev_dbg(mtu->dev, "%s: SENDSTALL\n", __func__); in ep0_rx_state()
558 ep0_req_giveback(mtu, req); in ep0_rx_state()
563 static void ep0_tx_state(struct mtu3 *mtu) in ep0_tx_state() argument
565 struct mtu3_request *mreq = next_ep0_request(mtu); in ep0_tx_state()
572 dev_dbg(mtu->dev, "%s\n", __func__); in ep0_tx_state()
577 maxp = mtu->g.ep0->maxpacket; in ep0_tx_state()
584 ep0_write_fifo(mtu->ep0, src, count); in ep0_tx_state()
586 dev_dbg(mtu->dev, "%s act=%d, len=%d, cnt=%d, maxp=%d zero=%d\n", in ep0_tx_state()
593 mtu->ep0_state = MU3D_EP0_STATE_TX_END; in ep0_tx_state()
596 csr = mtu3_readl(mtu->mac_base, U3D_EP0CSR) & EP0_W1C_BITS; in ep0_tx_state()
597 mtu3_writel(mtu->mac_base, U3D_EP0CSR, csr | EP0_TXPKTRDY); in ep0_tx_state()
599 dev_dbg(mtu->dev, "%s ep0csr=0x%x\n", __func__, in ep0_tx_state()
600 mtu3_readl(mtu->mac_base, U3D_EP0CSR)); in ep0_tx_state()
603 static void ep0_read_setup(struct mtu3 *mtu, struct usb_ctrlrequest *setup) in ep0_read_setup() argument
609 csr = mtu3_readl(mtu->mac_base, U3D_EP0CSR) & EP0_W1C_BITS; in ep0_read_setup()
610 count = mtu3_readl(mtu->mac_base, U3D_RXCOUNT0); in ep0_read_setup()
612 ep0_read_fifo(mtu->ep0, (u8 *)setup, count); in ep0_read_setup()
614 dev_dbg(mtu->dev, "SETUP req%02x.%02x v%04x i%04x l%04x\n", in ep0_read_setup()
620 mreq = next_ep0_request(mtu); in ep0_read_setup()
622 ep0_req_giveback(mtu, &mreq->request); in ep0_read_setup()
627 mtu3_writel(mtu->mac_base, U3D_EP0CSR, in ep0_read_setup()
629 mtu->ep0_state = MU3D_EP0_STATE_TX; in ep0_read_setup()
631 mtu3_writel(mtu->mac_base, U3D_EP0CSR, in ep0_read_setup()
633 mtu->ep0_state = MU3D_EP0_STATE_RX; in ep0_read_setup()
637 static int ep0_handle_setup(struct mtu3 *mtu) in ep0_handle_setup() argument
638 __releases(mtu->lock) in ep0_handle_setup()
639 __acquires(mtu->lock) in ep0_handle_setup()
645 ep0_read_setup(mtu, &setup); in ep0_handle_setup()
649 handled = handle_standard_request(mtu, &setup); in ep0_handle_setup()
651 dev_dbg(mtu->dev, "handled %d, ep0_state: %s\n", in ep0_handle_setup()
652 handled, decode_ep0_state(mtu)); in ep0_handle_setup()
659 handled = forward_to_driver(mtu, &setup); in ep0_handle_setup()
662 dev_dbg(mtu->dev, "%s stall (%d)\n", __func__, handled); in ep0_handle_setup()
664 ep0_stall_set(mtu->ep0, true, in ep0_handle_setup()
671 if (mtu->test_mode) { in ep0_handle_setup()
675 mreq = next_ep0_request(mtu); in ep0_handle_setup()
678 ep0_do_status_stage(mtu); in ep0_handle_setup()
679 ep0_req_giveback(mtu, &mreq->request); in ep0_handle_setup()
682 mtu->delayed_status = true; in ep0_handle_setup()
686 ep0_do_status_stage(mtu); in ep0_handle_setup()
688 mreq = next_ep0_request(mtu); in ep0_handle_setup()
690 ep0_req_giveback(mtu, &mreq->request); in ep0_handle_setup()
696 irqreturn_t mtu3_ep0_isr(struct mtu3 *mtu) in mtu3_ep0_isr() argument
698 void __iomem *mbase = mtu->mac_base; in mtu3_ep0_isr()
715 mtu->ep0_state = MU3D_EP0_STATE_SETUP; in mtu3_ep0_isr()
719 dev_dbg(mtu->dev, "%s csr=0x%x\n", __func__, csr); in mtu3_ep0_isr()
723 ep0_stall_set(mtu->ep0, false, 0); in mtu3_ep0_isr()
727 dev_dbg(mtu->dev, "ep0_state: %s\n", decode_ep0_state(mtu)); in mtu3_ep0_isr()
728 mtu3_dbg_trace(mtu->dev, "ep0_state %s", decode_ep0_state(mtu)); in mtu3_ep0_isr()
730 switch (mtu->ep0_state) { in mtu3_ep0_isr()
734 ep0_tx_state(mtu); in mtu3_ep0_isr()
741 ep0_rx_state(mtu); in mtu3_ep0_isr()
749 mreq = next_ep0_request(mtu); in mtu3_ep0_isr()
751 ep0_req_giveback(mtu, &mreq->request); in mtu3_ep0_isr()
753 mtu->ep0_state = MU3D_EP0_STATE_SETUP; in mtu3_ep0_isr()
755 dev_dbg(mtu->dev, "ep0_state: %s\n", decode_ep0_state(mtu)); in mtu3_ep0_isr()
763 dev_err(mtu->dev, "SETUP packet len %d != 8 ?\n", len); in mtu3_ep0_isr()
767 ep0_handle_setup(mtu); in mtu3_ep0_isr()
772 ep0_stall_set(mtu->ep0, true, 0); in mtu3_ep0_isr()
796 struct mtu3 *mtu = mep->mtu; in ep0_queue() local
798 mreq->mtu = mtu; in ep0_queue()
802 dev_dbg(mtu->dev, "%s %s (ep0_state: %s), len#%d\n", __func__, in ep0_queue()
803 mep->name, decode_ep0_state(mtu), mreq->request.length); in ep0_queue()
805 switch (mtu->ep0_state) { in ep0_queue()
811 dev_err(mtu->dev, "%s, error in ep0 state %s\n", __func__, in ep0_queue()
812 decode_ep0_state(mtu)); in ep0_queue()
816 if (mtu->delayed_status) { in ep0_queue()
818 mtu->delayed_status = false; in ep0_queue()
819 ep0_do_status_stage(mtu); in ep0_queue()
830 if (mtu->ep0_state == MU3D_EP0_STATE_TX) in ep0_queue()
831 ep0_tx_state(mtu); in ep0_queue()
841 struct mtu3 *mtu; in mtu3_ep0_queue() local
849 mtu = mep->mtu; in mtu3_ep0_queue()
852 spin_lock_irqsave(&mtu->lock, flags); in mtu3_ep0_queue()
854 spin_unlock_irqrestore(&mtu->lock, flags); in mtu3_ep0_queue()
867 struct mtu3 *mtu; in mtu3_ep0_halt() local
875 mtu = mep->mtu; in mtu3_ep0_halt()
877 dev_dbg(mtu->dev, "%s\n", __func__); in mtu3_ep0_halt()
879 spin_lock_irqsave(&mtu->lock, flags); in mtu3_ep0_halt()
886 switch (mtu->ep0_state) { in mtu3_ep0_halt()
895 ep0_stall_set(mtu->ep0, true, 0); in mtu3_ep0_halt()
898 dev_dbg(mtu->dev, "ep0 can't halt in state %s\n", in mtu3_ep0_halt()
899 decode_ep0_state(mtu)); in mtu3_ep0_halt()
904 spin_unlock_irqrestore(&mtu->lock, flags); in mtu3_ep0_halt()