Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] USB: more omap_udc updates (dma and omap1710)

More omap_udc updates:

* OMAP 1710 updates
- new UDC bit for clearing endpoint toggle, affecting CLEAR_HALT
- new OTG bits affecting wakeup
* Fix the bug Vladimir noted, that IN-DMA transfer code path kicks in
for under 1024 bytes (not "up to 1024 bytes")
* Handle transceiver setup more intelligently
- use transceiver whenever one's available; this can be handy
for GPIO based, loopback, or transceiverless configs
- cleanup correctly after the "unrecognized HMC" case
* DMA performance tweaks
- allow burst/pack for memory access
- use 16 bit DMA access most of the time on TIPB
* Add workarounds for some DMA errata (not observed "in the wild"):
- DMA CSAC/CDAC reads returning zero
- RX/TX DMA config registers bit 12 always reads as zero (TI patch)
* More "sparse" warnings removed, notably "changing" the SETUP packet
to return data in USB byteorder (an API change, null effect on OMAP
except for these warnings).

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

David Brownell and committed by
Greg Kroah-Hartman
65111084 907cba35

+125 -41
+113 -40
drivers/usb/gadget/omap_udc.c
··· 166 166 maxp = le16_to_cpu (desc->wMaxPacketSize); 167 167 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 168 168 && maxp != ep->maxpacket) 169 - || desc->wMaxPacketSize > ep->maxpacket 169 + || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket 170 170 || !desc->wMaxPacketSize) { 171 171 DBG("%s, bad %s maxpacket\n", __FUNCTION__, _ep->name); 172 172 return -ERANGE; ··· 213 213 ep->has_dma = 0; 214 214 ep->lch = -1; 215 215 use_ep(ep, UDC_EP_SEL); 216 - UDC_CTRL_REG = UDC_RESET_EP; 216 + UDC_CTRL_REG = udc->clr_halt; 217 217 ep->ackwait = 0; 218 218 deselect_ep(); 219 219 ··· 537 537 538 538 /*-------------------------------------------------------------------------*/ 539 539 540 + static inline dma_addr_t dma_csac(unsigned lch) 541 + { 542 + dma_addr_t csac; 543 + 544 + /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is 545 + * read before the DMA controller finished disabling the channel. 546 + */ 547 + csac = omap_readw(OMAP_DMA_CSAC(lch)); 548 + if (csac == 0) 549 + csac = omap_readw(OMAP_DMA_CSAC(lch)); 550 + return csac; 551 + } 552 + 553 + static inline dma_addr_t dma_cdac(unsigned lch) 554 + { 555 + dma_addr_t cdac; 556 + 557 + /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is 558 + * read before the DMA controller finished disabling the channel. 559 + */ 560 + cdac = omap_readw(OMAP_DMA_CDAC(lch)); 561 + if (cdac == 0) 562 + cdac = omap_readw(OMAP_DMA_CDAC(lch)); 563 + return cdac; 564 + } 565 + 540 566 static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) 541 567 { 542 568 dma_addr_t end; ··· 573 547 if (cpu_is_omap15xx()) 574 548 return 0; 575 549 576 - end = omap_readw(OMAP_DMA_CSAC(ep->lch)); 550 + end = dma_csac(ep->lch); 577 551 if (end == ep->dma_counter) 578 552 return 0; 579 553 ··· 584 558 } 585 559 586 560 #define DMA_DEST_LAST(x) (cpu_is_omap15xx() \ 587 - ? OMAP_DMA_CSAC(x) /* really: CPC */ \ 588 - : OMAP_DMA_CDAC(x)) 561 + ? omap_readw(OMAP_DMA_CSAC(x)) /* really: CPC */ \ 562 + : dma_cdac(x)) 589 563 590 564 static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) 591 565 { 592 566 dma_addr_t end; 593 567 594 - end = omap_readw(DMA_DEST_LAST(ep->lch)); 568 + end = DMA_DEST_LAST(ep->lch); 595 569 if (end == ep->dma_counter) 596 570 return 0; 597 571 ··· 618 592 : OMAP_DMA_SYNC_ELEMENT; 619 593 620 594 /* measure length in either bytes or packets */ 621 - if ((cpu_is_omap16xx() && length <= (UDC_TXN_TSC + 1)) 595 + if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) 622 596 || (cpu_is_omap15xx() && length < ep->maxpacket)) { 623 597 txdma_ctrl = UDC_TXN_EOT | length; 624 598 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, ··· 627 601 length = min(length / ep->maxpacket, 628 602 (unsigned) UDC_TXN_TSC + 1); 629 603 txdma_ctrl = length; 630 - omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 631 - ep->ep.maxpacket, length, sync_mode); 604 + omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 605 + ep->ep.maxpacket >> 1, length, sync_mode); 632 606 length *= ep->maxpacket; 633 607 } 634 608 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, 635 609 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 636 610 637 611 omap_start_dma(ep->lch); 638 - ep->dma_counter = omap_readw(OMAP_DMA_CSAC(ep->lch)); 612 + ep->dma_counter = dma_csac(ep->lch); 639 613 UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel); 640 614 UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl; 641 615 req->dma_bytes = length; ··· 675 649 packets = (req->req.length - req->req.actual) / ep->ep.maxpacket; 676 650 packets = min(packets, (unsigned)UDC_RXN_TC + 1); 677 651 req->dma_bytes = packets * ep->ep.maxpacket; 678 - omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, 679 - ep->ep.maxpacket, packets, 652 + omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, 653 + ep->ep.maxpacket >> 1, packets, 680 654 OMAP_DMA_SYNC_ELEMENT); 681 655 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, 682 656 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual); 683 - ep->dma_counter = omap_readw(DMA_DEST_LAST(ep->lch)); 657 + ep->dma_counter = DMA_DEST_LAST(ep->lch); 684 658 685 659 UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1); 686 660 UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel); ··· 788 762 reg = UDC_TXDMA_CFG_REG; 789 763 else 790 764 reg = UDC_RXDMA_CFG_REG; 791 - reg |= 1 << 12; /* "pulse" activated */ 765 + reg |= UDC_DMA_REQ; /* "pulse" activated */ 792 766 793 767 ep->dma_channel = 0; 794 768 ep->lch = -1; ··· 812 786 ep->ep.name, dma_error, ep, &ep->lch); 813 787 if (status == 0) { 814 788 UDC_TXDMA_CFG_REG = reg; 789 + /* EMIFF */ 790 + omap_set_dma_src_burst_mode(ep->lch, 791 + OMAP_DMA_DATA_BURST_4); 792 + omap_set_dma_src_data_pack(ep->lch, 1); 793 + /* TIPB */ 815 794 omap_set_dma_dest_params(ep->lch, 816 795 OMAP_DMA_PORT_TIPB, 817 796 OMAP_DMA_AMODE_CONSTANT, ··· 827 796 ep->ep.name, dma_error, ep, &ep->lch); 828 797 if (status == 0) { 829 798 UDC_RXDMA_CFG_REG = reg; 799 + /* TIPB */ 830 800 omap_set_dma_src_params(ep->lch, 831 801 OMAP_DMA_PORT_TIPB, 832 802 OMAP_DMA_AMODE_CONSTANT, 833 803 (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG)); 804 + /* EMIFF */ 805 + omap_set_dma_dest_burst_mode(ep->lch, 806 + OMAP_DMA_DATA_BURST_4); 807 + omap_set_dma_dest_data_pack(ep->lch, 1); 834 808 } 835 809 } 836 810 if (status) ··· 900 864 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', 901 865 ep->dma_channel - 1, req); 902 866 867 + /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before 868 + * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them. 869 + */ 870 + 903 871 /* wait till current packet DMA finishes, and fifo empties */ 904 872 if (ep->bEndpointAddress & USB_DIR_IN) { 905 - UDC_TXDMA_CFG_REG &= ~mask; 873 + UDC_TXDMA_CFG_REG = (UDC_TXDMA_CFG_REG & ~mask) | UDC_DMA_REQ; 906 874 907 875 if (req) { 908 876 finish_in_dma(ep, req, -ECONNRESET); ··· 919 879 while (UDC_TXDMA_CFG_REG & mask) 920 880 udelay(10); 921 881 } else { 922 - UDC_RXDMA_CFG_REG &= ~mask; 882 + UDC_RXDMA_CFG_REG = (UDC_RXDMA_CFG_REG & ~mask) | UDC_DMA_REQ; 923 883 924 884 /* dma empties the fifo */ 925 885 while (UDC_RXDMA_CFG_REG & mask) ··· 1180 1140 dma_channel_claim(ep, channel); 1181 1141 } else { 1182 1142 use_ep(ep, 0); 1183 - UDC_CTRL_REG = UDC_RESET_EP; 1143 + UDC_CTRL_REG = ep->udc->clr_halt; 1184 1144 ep->ackwait = 0; 1185 1145 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1186 1146 UDC_CTRL_REG = UDC_SET_FIFO_EN; ··· 1554 1514 UDC_EP_NUM_REG = 0; 1555 1515 } while (UDC_IRQ_SRC_REG & UDC_SETUP); 1556 1516 1517 + #define w_value le16_to_cpup (&u.r.wValue) 1518 + #define w_index le16_to_cpup (&u.r.wIndex) 1519 + #define w_length le16_to_cpup (&u.r.wLength) 1520 + 1557 1521 /* Delegate almost all control requests to the gadget driver, 1558 1522 * except for a handful of ch9 status/feature requests that 1559 1523 * hardware doesn't autodecode _and_ the gadget API hides. ··· 1572 1528 /* udc needs to know when ep != 0 is valid */ 1573 1529 if (u.r.bRequestType != USB_RECIP_DEVICE) 1574 1530 goto delegate; 1575 - if (u.r.wLength != 0) 1531 + if (w_length != 0) 1576 1532 goto do_stall; 1577 1533 udc->ep0_set_config = 1; 1578 - udc->ep0_reset_config = (u.r.wValue == 0); 1579 - VDBG("set config %d\n", u.r.wValue); 1534 + udc->ep0_reset_config = (w_value == 0); 1535 + VDBG("set config %d\n", w_value); 1580 1536 1581 1537 /* update udc NOW since gadget driver may start 1582 1538 * queueing requests immediately; clear config ··· 1592 1548 /* clear endpoint halt */ 1593 1549 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1594 1550 goto delegate; 1595 - if (u.r.wValue != USB_ENDPOINT_HALT 1596 - || u.r.wLength != 0) 1551 + if (w_value != USB_ENDPOINT_HALT 1552 + || w_length != 0) 1597 1553 goto do_stall; 1598 - ep = &udc->ep[u.r.wIndex & 0xf]; 1554 + ep = &udc->ep[w_index & 0xf]; 1599 1555 if (ep != ep0) { 1600 - if (u.r.wIndex & USB_DIR_IN) 1556 + if (w_index & USB_DIR_IN) 1601 1557 ep += 16; 1602 1558 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1603 1559 || !ep->desc) 1604 1560 goto do_stall; 1605 1561 use_ep(ep, 0); 1606 - UDC_CTRL_REG = UDC_RESET_EP; 1562 + UDC_CTRL_REG = udc->clr_halt; 1607 1563 ep->ackwait = 0; 1608 1564 if (!(ep->bEndpointAddress & USB_DIR_IN)) { 1609 1565 UDC_CTRL_REG = UDC_SET_FIFO_EN; ··· 1621 1577 /* set endpoint halt */ 1622 1578 if (u.r.bRequestType != USB_RECIP_ENDPOINT) 1623 1579 goto delegate; 1624 - if (u.r.wValue != USB_ENDPOINT_HALT 1625 - || u.r.wLength != 0) 1580 + if (w_value != USB_ENDPOINT_HALT 1581 + || w_length != 0) 1626 1582 goto do_stall; 1627 - ep = &udc->ep[u.r.wIndex & 0xf]; 1628 - if (u.r.wIndex & USB_DIR_IN) 1583 + ep = &udc->ep[w_index & 0xf]; 1584 + if (w_index & USB_DIR_IN) 1629 1585 ep += 16; 1630 1586 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 1631 1587 || ep == ep0 || !ep->desc) ··· 1663 1619 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1664 1620 UDC_EP_NUM_REG = UDC_EP_DIR; 1665 1621 status = 0; 1666 - VDBG("GET_STATUS, interface %d\n", u.r.wIndex); 1622 + VDBG("GET_STATUS, interface %d\n", w_index); 1667 1623 /* next, status stage */ 1668 1624 break; 1669 1625 default: 1670 1626 delegate: 1671 1627 /* activate the ep0out fifo right away */ 1672 - if (!udc->ep0_in && u.r.wLength) { 1628 + if (!udc->ep0_in && w_length) { 1673 1629 UDC_EP_NUM_REG = 0; 1674 1630 UDC_CTRL_REG = UDC_SET_FIFO_EN; 1675 1631 } ··· 1680 1636 */ 1681 1637 VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n", 1682 1638 u.r.bRequestType, u.r.bRequest, 1683 - u.r.wValue, u.r.wIndex, u.r.wLength); 1639 + w_value, w_index, w_length); 1640 + 1641 + #undef w_value 1642 + #undef w_index 1643 + #undef w_length 1684 1644 1685 1645 /* The gadget driver may return an error here, 1686 1646 * causing an immediate protocol stall. ··· 2229 2181 2230 2182 tmp = OTG_REV_REG; 2231 2183 trans = USB_TRANSCEIVER_CTRL_REG; 2232 - seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %03x\n", 2184 + seq_printf(s, "\nOTG rev %d.%d, transceiver_ctrl %05x\n", 2233 2185 tmp >> 4, tmp & 0xf, trans); 2234 2186 tmp = OTG_SYSCON_1_REG; 2235 2187 seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," 2236 2188 FOURBITS "\n", tmp, 2237 2189 trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), 2238 2190 trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R), 2239 - (USB0_TRX_MODE(tmp) == 0) 2191 + (USB0_TRX_MODE(tmp) == 0 && !cpu_is_omap1710()) 2240 2192 ? "internal" 2241 2193 : trx_mode(USB0_TRX_MODE(tmp), 1), 2242 2194 (tmp & OTG_IDLE_EN) ? " !otg" : "", ··· 2466 2418 /* Before this controller can enumerate, we need to pick an endpoint 2467 2419 * configuration, or "fifo_mode" That involves allocating 2KB of packet 2468 2420 * buffer space among the endpoints we'll be operating. 2421 + * 2422 + * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when 2423 + * UDC_SYSCON_1_REG.CFG_LOCK is set can now work. We won't use that 2424 + * capability yet though. 2469 2425 */ 2470 2426 static unsigned __init 2471 2427 omap_ep_setup(char *name, u8 addr, u8 type, ··· 2742 2690 FUNC_MUX_CTRL_0_REG = tmp; 2743 2691 } 2744 2692 } else { 2693 + /* The transceiver may package some GPIO logic or handle 2694 + * loopback and/or transceiverless setup; if we find one, 2695 + * use it. Except for OTG, we don't _need_ to talk to one; 2696 + * but not having one probably means no VBUS detection. 2697 + */ 2698 + xceiv = otg_get_transceiver(); 2699 + if (xceiv) 2700 + type = xceiv->label; 2701 + else if (config->otg) { 2702 + DBG("OTG requires external transceiver!\n"); 2703 + goto cleanup0; 2704 + } 2705 + 2745 2706 hmc = HMC_1610; 2746 2707 switch (hmc) { 2747 2708 case 0: /* POWERUP DEFAULT == 0 */ ··· 2771 2706 case 16: 2772 2707 case 19: 2773 2708 case 25: 2774 - xceiv = otg_get_transceiver(); 2775 2709 if (!xceiv) { 2776 2710 DBG("external transceiver not registered!\n"); 2777 - if (config->otg) 2778 - goto cleanup0; 2779 2711 type = "unknown"; 2780 - } else 2781 - type = xceiv->label; 2712 + } 2782 2713 break; 2783 2714 case 21: /* internal loopback */ 2784 2715 type = "loopback"; 2785 2716 break; 2786 2717 case 14: /* transceiverless */ 2718 + if (cpu_is_omap1710()) 2719 + goto bad_on_1710; 2720 + /* FALL THROUGH */ 2721 + case 13: 2722 + case 15: 2787 2723 type = "no"; 2788 2724 break; 2789 2725 2790 2726 default: 2727 + bad_on_1710: 2791 2728 ERR("unrecognized UDC HMC mode %d\n", hmc); 2792 - return -ENODEV; 2729 + goto cleanup0; 2793 2730 } 2794 2731 } 2795 2732 INFO("hmc mode %d, %s transceiver\n", hmc, type); ··· 2807 2740 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) 2808 2741 udc->gadget.is_otg = (config->otg != 0); 2809 2742 #endif 2743 + 2744 + /* starting with omap1710 es2.0, clear toggle is a separate bit */ 2745 + if (UDC_REV_REG >= 0x61) 2746 + udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE; 2747 + else 2748 + udc->clr_halt = UDC_RESET_EP; 2810 2749 2811 2750 /* USB general purpose IRQ: ep0, state changes, dma, etc */ 2812 2751 status = request_irq(odev->resource[1].start, omap_udc_irq,
+3 -1
drivers/usb/gadget/omap_udc.h
··· 20 20 #define UDC_CTRL_REG UDC_REG(0x0C) /* Endpoint control */ 21 21 # define UDC_CLR_HALT (1 << 7) 22 22 # define UDC_SET_HALT (1 << 6) 23 + # define UDC_CLRDATA_TOGGLE (1 << 3) 23 24 # define UDC_SET_FIFO_EN (1 << 2) 24 25 # define UDC_CLR_EP (1 << 1) 25 26 # define UDC_RESET_EP (1 << 0) ··· 100 99 101 100 /* DMA configuration registers: up to three channels in each direction. */ 102 101 #define UDC_RXDMA_CFG_REG UDC_REG(0x40) /* 3 eps for RX DMA */ 102 + # define UDC_DMA_REQ (1 << 12) 103 103 #define UDC_TXDMA_CFG_REG UDC_REG(0x44) /* 3 eps for TX DMA */ 104 104 #define UDC_DATA_DMA_REG UDC_REG(0x48) /* rx/tx fifo addr */ 105 105 ··· 164 162 spinlock_t lock; 165 163 struct omap_ep ep[32]; 166 164 u16 devstat; 165 + u16 clr_halt; 167 166 struct otg_transceiver *transceiver; 168 167 struct list_head iso; 169 168 unsigned softconnect:1; ··· 174 171 unsigned ep0_set_config:1; 175 172 unsigned ep0_reset_config:1; 176 173 unsigned ep0_setup:1; 177 - 178 174 struct completion *done; 179 175 }; 180 176
+9
include/asm-arm/arch-omap/usb.h
··· 47 47 # define HMC_TLLATTACH (1 << 6) 48 48 # define OTG_HMC(w) (((w)>>0)&0x3f) 49 49 #define OTG_CTRL_REG OTG_REG32(0x0c) 50 + # define OTG_USB2_EN (1 << 29) 51 + # define OTG_USB2_DP (1 << 28) 52 + # define OTG_USB2_DM (1 << 27) 53 + # define OTG_USB1_EN (1 << 26) 54 + # define OTG_USB1_DP (1 << 25) 55 + # define OTG_USB1_DM (1 << 24) 56 + # define OTG_USB0_EN (1 << 23) 57 + # define OTG_USB0_DP (1 << 22) 58 + # define OTG_USB0_DM (1 << 21) 50 59 # define OTG_ASESSVLD (1 << 20) 51 60 # define OTG_BSESSEND (1 << 19) 52 61 # define OTG_BSESSVLD (1 << 18)