| .. | .. |
|---|
| 11 | 11 | #include <linux/usb/composite.h> |
|---|
| 12 | 12 | |
|---|
| 13 | 13 | #include "mtu3.h" |
|---|
| 14 | +#include "mtu3_debug.h" |
|---|
| 15 | +#include "mtu3_trace.h" |
|---|
| 14 | 16 | |
|---|
| 15 | 17 | /* ep0 is always mtu3->in_eps[0] */ |
|---|
| 16 | 18 | #define next_ep0_request(mtu) next_request((mtu)->ep0) |
|---|
| .. | .. |
|---|
| 151 | 153 | set ? "SEND" : "CLEAR", decode_ep0_state(mtu)); |
|---|
| 152 | 154 | } |
|---|
| 153 | 155 | |
|---|
| 156 | +static void ep0_do_status_stage(struct mtu3 *mtu) |
|---|
| 157 | +{ |
|---|
| 158 | + void __iomem *mbase = mtu->mac_base; |
|---|
| 159 | + u32 value; |
|---|
| 160 | + |
|---|
| 161 | + value = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS; |
|---|
| 162 | + mtu3_writel(mbase, U3D_EP0CSR, value | EP0_SETUPPKTRDY | EP0_DATAEND); |
|---|
| 163 | +} |
|---|
| 164 | + |
|---|
| 154 | 165 | static int ep0_queue(struct mtu3_ep *mep0, struct mtu3_request *mreq); |
|---|
| 155 | 166 | |
|---|
| 156 | 167 | static void ep0_dummy_complete(struct usb_ep *ep, struct usb_request *req) |
|---|
| .. | .. |
|---|
| 267 | 278 | u32 value; |
|---|
| 268 | 279 | |
|---|
| 269 | 280 | switch (le16_to_cpu(setup->wIndex) >> 8) { |
|---|
| 270 | | - case TEST_J: |
|---|
| 271 | | - dev_dbg(mtu->dev, "TEST_J\n"); |
|---|
| 281 | + case USB_TEST_J: |
|---|
| 282 | + dev_dbg(mtu->dev, "USB_TEST_J\n"); |
|---|
| 272 | 283 | mtu->test_mode_nr = TEST_J_MODE; |
|---|
| 273 | 284 | break; |
|---|
| 274 | | - case TEST_K: |
|---|
| 275 | | - dev_dbg(mtu->dev, "TEST_K\n"); |
|---|
| 285 | + case USB_TEST_K: |
|---|
| 286 | + dev_dbg(mtu->dev, "USB_TEST_K\n"); |
|---|
| 276 | 287 | mtu->test_mode_nr = TEST_K_MODE; |
|---|
| 277 | 288 | break; |
|---|
| 278 | | - case TEST_SE0_NAK: |
|---|
| 279 | | - dev_dbg(mtu->dev, "TEST_SE0_NAK\n"); |
|---|
| 289 | + case USB_TEST_SE0_NAK: |
|---|
| 290 | + dev_dbg(mtu->dev, "USB_TEST_SE0_NAK\n"); |
|---|
| 280 | 291 | mtu->test_mode_nr = TEST_SE0_NAK_MODE; |
|---|
| 281 | 292 | break; |
|---|
| 282 | | - case TEST_PACKET: |
|---|
| 283 | | - dev_dbg(mtu->dev, "TEST_PACKET\n"); |
|---|
| 293 | + case USB_TEST_PACKET: |
|---|
| 294 | + dev_dbg(mtu->dev, "USB_TEST_PACKET\n"); |
|---|
| 284 | 295 | mtu->test_mode_nr = TEST_PACKET_MODE; |
|---|
| 285 | 296 | break; |
|---|
| 286 | 297 | default: |
|---|
| .. | .. |
|---|
| 295 | 306 | ep0_load_test_packet(mtu); |
|---|
| 296 | 307 | |
|---|
| 297 | 308 | /* send status before entering test mode. */ |
|---|
| 298 | | - value = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS; |
|---|
| 299 | | - mtu3_writel(mbase, U3D_EP0CSR, value | EP0_SETUPPKTRDY | EP0_DATAEND); |
|---|
| 309 | + ep0_do_status_stage(mtu); |
|---|
| 300 | 310 | |
|---|
| 301 | 311 | /* wait for ACK status sent by host */ |
|---|
| 302 | 312 | readl_poll_timeout_atomic(mbase + U3D_EP0CSR, value, |
|---|
| .. | .. |
|---|
| 407 | 417 | |
|---|
| 408 | 418 | handled = 1; |
|---|
| 409 | 419 | /* ignore request if endpoint is wedged */ |
|---|
| 410 | | - if (mep->wedged) |
|---|
| 420 | + if (mep->flags & MTU3_EP_WEDGE) |
|---|
| 411 | 421 | break; |
|---|
| 412 | 422 | |
|---|
| 413 | 423 | mtu3_ep_stall_set(mep, set); |
|---|
| .. | .. |
|---|
| 630 | 640 | { |
|---|
| 631 | 641 | struct usb_ctrlrequest setup; |
|---|
| 632 | 642 | struct mtu3_request *mreq; |
|---|
| 633 | | - void __iomem *mbase = mtu->mac_base; |
|---|
| 634 | 643 | int handled = 0; |
|---|
| 635 | 644 | |
|---|
| 636 | 645 | ep0_read_setup(mtu, &setup); |
|---|
| 646 | + trace_mtu3_handle_setup(&setup); |
|---|
| 637 | 647 | |
|---|
| 638 | 648 | if ((setup.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) |
|---|
| 639 | 649 | handled = handle_standard_request(mtu, &setup); |
|---|
| .. | .. |
|---|
| 661 | 671 | if (mtu->test_mode) { |
|---|
| 662 | 672 | ; /* nothing to do */ |
|---|
| 663 | 673 | } else if (handled == USB_GADGET_DELAYED_STATUS) { |
|---|
| 664 | | - /* handle the delay STATUS phase till receive ep_queue on ep0 */ |
|---|
| 665 | | - mtu->delayed_status = true; |
|---|
| 674 | + |
|---|
| 675 | + mreq = next_ep0_request(mtu); |
|---|
| 676 | + if (mreq) { |
|---|
| 677 | + /* already asked us to continue delayed status */ |
|---|
| 678 | + ep0_do_status_stage(mtu); |
|---|
| 679 | + ep0_req_giveback(mtu, &mreq->request); |
|---|
| 680 | + } else { |
|---|
| 681 | + /* do delayed STATUS stage till receive ep0_queue */ |
|---|
| 682 | + mtu->delayed_status = true; |
|---|
| 683 | + } |
|---|
| 666 | 684 | } else if (le16_to_cpu(setup.wLength) == 0) { /* no data stage */ |
|---|
| 667 | 685 | |
|---|
| 668 | | - mtu3_writel(mbase, U3D_EP0CSR, |
|---|
| 669 | | - (mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS) |
|---|
| 670 | | - | EP0_SETUPPKTRDY | EP0_DATAEND); |
|---|
| 671 | | - |
|---|
| 686 | + ep0_do_status_stage(mtu); |
|---|
| 672 | 687 | /* complete zlp request directly */ |
|---|
| 673 | 688 | mreq = next_ep0_request(mtu); |
|---|
| 674 | 689 | if (mreq && !mreq->request.length) |
|---|
| .. | .. |
|---|
| 692 | 707 | mtu3_writel(mbase, U3D_EPISR, int_status); /* W1C */ |
|---|
| 693 | 708 | |
|---|
| 694 | 709 | /* only handle ep0's */ |
|---|
| 695 | | - if (!(int_status & EP0ISR)) |
|---|
| 710 | + if (!(int_status & (EP0ISR | SETUPENDISR))) |
|---|
| 696 | 711 | return IRQ_NONE; |
|---|
| 712 | + |
|---|
| 713 | + /* abort current SETUP, and process new one */ |
|---|
| 714 | + if (int_status & SETUPENDISR) |
|---|
| 715 | + mtu->ep0_state = MU3D_EP0_STATE_SETUP; |
|---|
| 697 | 716 | |
|---|
| 698 | 717 | csr = mtu3_readl(mbase, U3D_EP0CSR); |
|---|
| 699 | 718 | |
|---|
| .. | .. |
|---|
| 706 | 725 | ret = IRQ_HANDLED; |
|---|
| 707 | 726 | } |
|---|
| 708 | 727 | dev_dbg(mtu->dev, "ep0_state: %s\n", decode_ep0_state(mtu)); |
|---|
| 728 | + mtu3_dbg_trace(mtu->dev, "ep0_state %s", decode_ep0_state(mtu)); |
|---|
| 709 | 729 | |
|---|
| 710 | 730 | switch (mtu->ep0_state) { |
|---|
| 711 | 731 | case MU3D_EP0_STATE_TX: |
|---|
| .. | .. |
|---|
| 794 | 814 | } |
|---|
| 795 | 815 | |
|---|
| 796 | 816 | if (mtu->delayed_status) { |
|---|
| 797 | | - u32 csr; |
|---|
| 798 | 817 | |
|---|
| 799 | 818 | mtu->delayed_status = false; |
|---|
| 800 | | - csr = mtu3_readl(mtu->mac_base, U3D_EP0CSR) & EP0_W1C_BITS; |
|---|
| 801 | | - csr |= EP0_SETUPPKTRDY | EP0_DATAEND; |
|---|
| 802 | | - mtu3_writel(mtu->mac_base, U3D_EP0CSR, csr); |
|---|
| 819 | + ep0_do_status_stage(mtu); |
|---|
| 803 | 820 | /* needn't giveback the request for handling delay STATUS */ |
|---|
| 804 | 821 | return 0; |
|---|
| 805 | 822 | } |
|---|