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

Merge tag 'usb-for-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

Felipe writes:

usb: patches for v4.8 merge window

Here's the big pull request for Peripheral stack and
all related drivers.

This time around with 109 non-merge commits mostly
concentrated on drivers/usb/gadget/udc (41.5%) and
drivers/usb/dwc3 (28.1%).

There's a big rework on dwc3's transfer handling
which gave us almost 3x faster USB3 speeds with Mass
Storage on a particular test scenario I measured. We
are also removing platform_data from dwc3 after
converting all users to built-in properties instead.

For the Gadget API, we're just adding tracepoints to
aid debugging activities.

Other than these, there's the usual set of spelling
fixes, minor bug fixes and sparse warnings cleanups.

+4040 -2795
+1
drivers/phy/Kconfig
··· 176 176 tristate "TWL4030 USB Transceiver Driver" 177 177 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS 178 178 depends on USB_SUPPORT 179 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't 'y' 179 180 select GENERIC_PHY 180 181 select USB_PHY 181 182 help
+1
drivers/power/Kconfig
··· 309 309 config CHARGER_ISP1704 310 310 tristate "ISP1704 USB Charger Detection" 311 311 depends on USB_PHY 312 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 312 313 help 313 314 Say Y to enable support for USB Charger Detection with 314 315 ISP1707/ISP1704 USB transceivers.
+20 -6
drivers/usb/common/common.c
··· 131 131 * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device 132 132 * which is associated with the given phy device_node 133 133 * @np: Pointer to the given phy device_node 134 + * @arg0: phandle args[0] for phy's with #phy-cells >= 1, or -1 for 135 + * phys which do not have phy-cells 134 136 * 135 137 * In dts a usb controller associates with phy devices. The function gets 136 138 * the string from property 'dr_mode' of the controller associated with the 137 139 * given phy device node, and returns the correspondig enum usb_dr_mode. 138 140 */ 139 - enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np) 141 + enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0) 140 142 { 141 143 struct device_node *controller = NULL; 142 - struct device_node *phy; 144 + struct of_phandle_args args; 143 145 const char *dr_mode; 144 146 int index; 145 147 int err; ··· 150 148 controller = of_find_node_with_property(controller, "phys"); 151 149 index = 0; 152 150 do { 153 - phy = of_parse_phandle(controller, "phys", index); 154 - of_node_put(phy); 155 - if (phy == phy_np) 151 + if (arg0 == -1) { 152 + args.np = of_parse_phandle(controller, "phys", 153 + index); 154 + args.args_count = 0; 155 + } else { 156 + err = of_parse_phandle_with_args(controller, 157 + "phys", "#phy-cells", 158 + index, &args); 159 + if (err) 160 + break; 161 + } 162 + 163 + of_node_put(args.np); 164 + if (args.np == np && (args.args_count == 0 || 165 + args.args[0] == arg0)) 156 166 goto finish; 157 167 index++; 158 - } while (phy); 168 + } while (args.np); 159 169 } while (controller); 160 170 161 171 finish:
+1
drivers/usb/dwc2/Kconfig
··· 55 55 config USB_DWC2_PCI 56 56 tristate "DWC2 PCI" 57 57 depends on PCI 58 + depends on USB_GADGET || !USB_GADGET 58 59 default n 59 60 select NOP_USB_XCEIV 60 61 help
+6 -2
drivers/usb/dwc2/core.h
··· 166 166 * means that it is sending data to the Host. 167 167 * @index: The index for the endpoint registers. 168 168 * @mc: Multi Count - number of transactions per microframe 169 - * @interval - Interval for periodic endpoints 169 + * @interval - Interval for periodic endpoints, in frames or microframes. 170 170 * @name: The name array passed to the USB core. 171 171 * @halted: Set if the endpoint has been halted. 172 172 * @periodic: Set if this is a periodic ep, such as Interrupt ··· 177 177 * @fifo_load: The amount of data loaded into the FIFO (periodic IN) 178 178 * @last_load: The offset of data for the last start of request. 179 179 * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN 180 + * @target_frame: Targeted frame num to setup next ISOC transfer 181 + * @frame_overrun: Indicates SOF number overrun in DSTS 180 182 * 181 183 * This is the driver's state for each registered enpoint, allowing it 182 184 * to keep track of transactions that need doing. Each endpoint has a ··· 215 213 unsigned int periodic:1; 216 214 unsigned int isochronous:1; 217 215 unsigned int send_zlp:1; 218 - unsigned int has_correct_parity:1; 216 + unsigned int target_frame; 217 + #define TARGET_FRAME_INITIAL 0xFFFFFFFF 218 + bool frame_overrun; 219 219 220 220 char name[10]; 221 221 };
+450 -124
drivers/usb/dwc2/gadget.c
··· 97 97 } 98 98 99 99 /** 100 + * dwc2_gadget_incr_frame_num - Increments the targeted frame number. 101 + * @hs_ep: The endpoint 102 + * @increment: The value to increment by 103 + * 104 + * This function will also check if the frame number overruns DSTS_SOFFN_LIMIT. 105 + * If an overrun occurs it will wrap the value and set the frame_overrun flag. 106 + */ 107 + static inline void dwc2_gadget_incr_frame_num(struct dwc2_hsotg_ep *hs_ep) 108 + { 109 + hs_ep->target_frame += hs_ep->interval; 110 + if (hs_ep->target_frame > DSTS_SOFFN_LIMIT) { 111 + hs_ep->frame_overrun = 1; 112 + hs_ep->target_frame &= DSTS_SOFFN_LIMIT; 113 + } else { 114 + hs_ep->frame_overrun = 0; 115 + } 116 + } 117 + 118 + /** 100 119 * dwc2_hsotg_en_gsint - enable one or more of the general interrupt 101 120 * @hsotg: The device state 102 121 * @ints: A bitmask of the interrupts to enable ··· 523 504 } 524 505 525 506 /** 507 + * dwc2_hsotg_read_frameno - read current frame number 508 + * @hsotg: The device instance 509 + * 510 + * Return the current frame number 511 + */ 512 + static u32 dwc2_hsotg_read_frameno(struct dwc2_hsotg *hsotg) 513 + { 514 + u32 dsts; 515 + 516 + dsts = dwc2_readl(hsotg->regs + DSTS); 517 + dsts &= DSTS_SOFFN_MASK; 518 + dsts >>= DSTS_SOFFN_SHIFT; 519 + 520 + return dsts; 521 + } 522 + 523 + /** 526 524 * dwc2_hsotg_start_req - start a USB request from an endpoint's queue 527 525 * @hsotg: The controller state. 528 526 * @hs_ep: The endpoint to process a request for ··· 667 631 __func__, &ureq->dma, dma_reg); 668 632 } 669 633 634 + if (hs_ep->isochronous && hs_ep->interval == 1) { 635 + hs_ep->target_frame = dwc2_hsotg_read_frameno(hsotg); 636 + dwc2_gadget_incr_frame_num(hs_ep); 637 + 638 + if (hs_ep->target_frame & 0x1) 639 + ctrl |= DXEPCTL_SETODDFR; 640 + else 641 + ctrl |= DXEPCTL_SETEVENFR; 642 + } 643 + 670 644 ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ 671 - ctrl |= DXEPCTL_USBACTEP; 672 645 673 646 dev_dbg(hsotg->dev, "ep0 state:%d\n", hsotg->ep0_state); 674 647 ··· 702 657 703 658 dwc2_hsotg_write_fifo(hsotg, hs_ep, hs_req); 704 659 } 705 - 706 - /* 707 - * clear the INTknTXFEmpMsk when we start request, more as a aide 708 - * to debugging to see what is going on. 709 - */ 710 - if (dir_in) 711 - dwc2_writel(DIEPMSK_INTKNTXFEMPMSK, 712 - hsotg->regs + DIEPINT(index)); 713 660 714 661 /* 715 662 * Note, trying to clear the NAK here causes problems with transmit ··· 810 773 hs_req->saved_req_buf = NULL; 811 774 } 812 775 776 + /** 777 + * dwc2_gadget_target_frame_elapsed - Checks target frame 778 + * @hs_ep: The driver endpoint to check 779 + * 780 + * Returns 1 if targeted frame elapsed. If returned 1 then we need to drop 781 + * corresponding transfer. 782 + */ 783 + static bool dwc2_gadget_target_frame_elapsed(struct dwc2_hsotg_ep *hs_ep) 784 + { 785 + struct dwc2_hsotg *hsotg = hs_ep->parent; 786 + u32 target_frame = hs_ep->target_frame; 787 + u32 current_frame = dwc2_hsotg_read_frameno(hsotg); 788 + bool frame_overrun = hs_ep->frame_overrun; 789 + 790 + if (!frame_overrun && current_frame >= target_frame) 791 + return true; 792 + 793 + if (frame_overrun && current_frame >= target_frame && 794 + ((current_frame - target_frame) < DSTS_SOFFN_LIMIT / 2)) 795 + return true; 796 + 797 + return false; 798 + } 799 + 813 800 static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req, 814 801 gfp_t gfp_flags) 815 802 { ··· 873 812 first = list_empty(&hs_ep->queue); 874 813 list_add_tail(&hs_req->queue, &hs_ep->queue); 875 814 876 - if (first) 877 - dwc2_hsotg_start_req(hs, hs_ep, hs_req, false); 815 + if (first) { 816 + if (!hs_ep->isochronous) { 817 + dwc2_hsotg_start_req(hs, hs_ep, hs_req, false); 818 + return 0; 819 + } 878 820 821 + while (dwc2_gadget_target_frame_elapsed(hs_ep)) 822 + dwc2_gadget_incr_frame_num(hs_ep); 823 + 824 + if (hs_ep->target_frame != TARGET_FRAME_INITIAL) 825 + dwc2_hsotg_start_req(hs, hs_ep, hs_req, false); 826 + } 879 827 return 0; 880 828 } 881 829 ··· 1105 1035 } 1106 1036 1107 1037 /** 1038 + * dwc2_gadget_start_next_request - Starts next request from ep queue 1039 + * @hs_ep: Endpoint structure 1040 + * 1041 + * If queue is empty and EP is ISOC-OUT - unmasks OUTTKNEPDIS which is masked 1042 + * in its handler. Hence we need to unmask it here to be able to do 1043 + * resynchronization. 1044 + */ 1045 + static void dwc2_gadget_start_next_request(struct dwc2_hsotg_ep *hs_ep) 1046 + { 1047 + u32 mask; 1048 + struct dwc2_hsotg *hsotg = hs_ep->parent; 1049 + int dir_in = hs_ep->dir_in; 1050 + struct dwc2_hsotg_req *hs_req; 1051 + u32 epmsk_reg = dir_in ? DIEPMSK : DOEPMSK; 1052 + 1053 + if (!list_empty(&hs_ep->queue)) { 1054 + hs_req = get_ep_head(hs_ep); 1055 + dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, false); 1056 + return; 1057 + } 1058 + if (!hs_ep->isochronous) 1059 + return; 1060 + 1061 + if (dir_in) { 1062 + dev_dbg(hsotg->dev, "%s: No more ISOC-IN requests\n", 1063 + __func__); 1064 + } else { 1065 + dev_dbg(hsotg->dev, "%s: No more ISOC-OUT requests\n", 1066 + __func__); 1067 + mask = dwc2_readl(hsotg->regs + epmsk_reg); 1068 + mask |= DOEPMSK_OUTTKNEPDISMSK; 1069 + dwc2_writel(mask, hsotg->regs + epmsk_reg); 1070 + } 1071 + } 1072 + 1073 + /** 1108 1074 * dwc2_hsotg_process_req_feature - process request {SET,CLEAR}_FEATURE 1109 1075 * @hsotg: The device state 1110 1076 * @ctrl: USB control request ··· 1150 1044 { 1151 1045 struct dwc2_hsotg_ep *ep0 = hsotg->eps_out[0]; 1152 1046 struct dwc2_hsotg_req *hs_req; 1153 - bool restart; 1154 1047 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); 1155 1048 struct dwc2_hsotg_ep *ep; 1156 1049 int ret; ··· 1232 1127 1233 1128 /* If we have pending request, then start it */ 1234 1129 if (!ep->req) { 1235 - restart = !list_empty(&ep->queue); 1236 - if (restart) { 1237 - hs_req = get_ep_head(ep); 1238 - dwc2_hsotg_start_req(hsotg, ep, 1239 - hs_req, false); 1240 - } 1130 + dwc2_gadget_start_next_request(ep); 1241 1131 } 1242 1132 } 1243 1133 ··· 1473 1373 struct dwc2_hsotg_req *hs_req, 1474 1374 int result) 1475 1375 { 1476 - bool restart; 1477 1376 1478 1377 if (!hs_req) { 1479 1378 dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__); ··· 1516 1417 */ 1517 1418 1518 1419 if (!hs_ep->req && result >= 0) { 1519 - restart = !list_empty(&hs_ep->queue); 1520 - if (restart) { 1521 - hs_req = get_ep_head(hs_ep); 1522 - dwc2_hsotg_start_req(hsotg, hs_ep, hs_req, false); 1523 - } 1420 + dwc2_gadget_start_next_request(hs_ep); 1524 1421 } 1525 1422 } 1526 1423 ··· 1692 1597 * adjust the ISOC parity here. 1693 1598 */ 1694 1599 if (!using_dma(hsotg)) { 1695 - hs_ep->has_correct_parity = 1; 1696 1600 if (hs_ep->isochronous && hs_ep->interval == 1) 1697 1601 dwc2_hsotg_change_ep_iso_parity(hsotg, DOEPCTL(epnum)); 1602 + else if (hs_ep->isochronous && hs_ep->interval > 1) 1603 + dwc2_gadget_incr_frame_num(hs_ep); 1698 1604 } 1699 1605 1700 1606 dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, result); 1701 - } 1702 - 1703 - /** 1704 - * dwc2_hsotg_read_frameno - read current frame number 1705 - * @hsotg: The device instance 1706 - * 1707 - * Return the current frame number 1708 - */ 1709 - static u32 dwc2_hsotg_read_frameno(struct dwc2_hsotg *hsotg) 1710 - { 1711 - u32 dsts; 1712 - 1713 - dsts = dwc2_readl(hsotg->regs + DSTS); 1714 - dsts &= DSTS_SOFFN_MASK; 1715 - dsts >>= DSTS_SOFFN_SHIFT; 1716 - 1717 - return dsts; 1718 1607 } 1719 1608 1720 1609 /** ··· 2016 1937 } 2017 1938 2018 1939 /** 1940 + * dwc2_gadget_read_ep_interrupts - reads interrupts for given ep 1941 + * @hsotg: The device state. 1942 + * @idx: Index of ep. 1943 + * @dir_in: Endpoint direction 1-in 0-out. 1944 + * 1945 + * Reads for endpoint with given index and direction, by masking 1946 + * epint_reg with coresponding mask. 1947 + */ 1948 + static u32 dwc2_gadget_read_ep_interrupts(struct dwc2_hsotg *hsotg, 1949 + unsigned int idx, int dir_in) 1950 + { 1951 + u32 epmsk_reg = dir_in ? DIEPMSK : DOEPMSK; 1952 + u32 epint_reg = dir_in ? DIEPINT(idx) : DOEPINT(idx); 1953 + u32 ints; 1954 + u32 mask; 1955 + u32 diepempmsk; 1956 + 1957 + mask = dwc2_readl(hsotg->regs + epmsk_reg); 1958 + diepempmsk = dwc2_readl(hsotg->regs + DIEPEMPMSK); 1959 + mask |= ((diepempmsk >> idx) & 0x1) ? DIEPMSK_TXFIFOEMPTY : 0; 1960 + mask |= DXEPINT_SETUP_RCVD; 1961 + 1962 + ints = dwc2_readl(hsotg->regs + epint_reg); 1963 + ints &= mask; 1964 + return ints; 1965 + } 1966 + 1967 + /** 1968 + * dwc2_gadget_handle_ep_disabled - handle DXEPINT_EPDISBLD 1969 + * @hs_ep: The endpoint on which interrupt is asserted. 1970 + * 1971 + * This interrupt indicates that the endpoint has been disabled per the 1972 + * application's request. 1973 + * 1974 + * For IN endpoints flushes txfifo, in case of BULK clears DCTL_CGNPINNAK, 1975 + * in case of ISOC completes current request. 1976 + * 1977 + * For ISOC-OUT endpoints completes expired requests. If there is remaining 1978 + * request starts it. 1979 + */ 1980 + static void dwc2_gadget_handle_ep_disabled(struct dwc2_hsotg_ep *hs_ep) 1981 + { 1982 + struct dwc2_hsotg *hsotg = hs_ep->parent; 1983 + struct dwc2_hsotg_req *hs_req; 1984 + unsigned char idx = hs_ep->index; 1985 + int dir_in = hs_ep->dir_in; 1986 + u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); 1987 + int dctl = dwc2_readl(hsotg->regs + DCTL); 1988 + 1989 + dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); 1990 + 1991 + if (dir_in) { 1992 + int epctl = dwc2_readl(hsotg->regs + epctl_reg); 1993 + 1994 + dwc2_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); 1995 + 1996 + if (hs_ep->isochronous) { 1997 + dwc2_hsotg_complete_in(hsotg, hs_ep); 1998 + return; 1999 + } 2000 + 2001 + if ((epctl & DXEPCTL_STALL) && (epctl & DXEPCTL_EPTYPE_BULK)) { 2002 + int dctl = dwc2_readl(hsotg->regs + DCTL); 2003 + 2004 + dctl |= DCTL_CGNPINNAK; 2005 + dwc2_writel(dctl, hsotg->regs + DCTL); 2006 + } 2007 + return; 2008 + } 2009 + 2010 + if (dctl & DCTL_GOUTNAKSTS) { 2011 + dctl |= DCTL_CGOUTNAK; 2012 + dwc2_writel(dctl, hsotg->regs + DCTL); 2013 + } 2014 + 2015 + if (!hs_ep->isochronous) 2016 + return; 2017 + 2018 + if (list_empty(&hs_ep->queue)) { 2019 + dev_dbg(hsotg->dev, "%s: complete_ep 0x%p, ep->queue empty!\n", 2020 + __func__, hs_ep); 2021 + return; 2022 + } 2023 + 2024 + do { 2025 + hs_req = get_ep_head(hs_ep); 2026 + if (hs_req) 2027 + dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 2028 + -ENODATA); 2029 + dwc2_gadget_incr_frame_num(hs_ep); 2030 + } while (dwc2_gadget_target_frame_elapsed(hs_ep)); 2031 + 2032 + dwc2_gadget_start_next_request(hs_ep); 2033 + } 2034 + 2035 + /** 2036 + * dwc2_gadget_handle_out_token_ep_disabled - handle DXEPINT_OUTTKNEPDIS 2037 + * @hs_ep: The endpoint on which interrupt is asserted. 2038 + * 2039 + * This is starting point for ISOC-OUT transfer, synchronization done with 2040 + * first out token received from host while corresponding EP is disabled. 2041 + * 2042 + * Device does not know initial frame in which out token will come. For this 2043 + * HW generates OUTTKNEPDIS - out token is received while EP is disabled. Upon 2044 + * getting this interrupt SW starts calculation for next transfer frame. 2045 + */ 2046 + static void dwc2_gadget_handle_out_token_ep_disabled(struct dwc2_hsotg_ep *ep) 2047 + { 2048 + struct dwc2_hsotg *hsotg = ep->parent; 2049 + int dir_in = ep->dir_in; 2050 + u32 doepmsk; 2051 + 2052 + if (dir_in || !ep->isochronous) 2053 + return; 2054 + 2055 + dwc2_hsotg_complete_request(hsotg, ep, get_ep_head(ep), -ENODATA); 2056 + 2057 + if (ep->interval > 1 && 2058 + ep->target_frame == TARGET_FRAME_INITIAL) { 2059 + u32 dsts; 2060 + u32 ctrl; 2061 + 2062 + dsts = dwc2_readl(hsotg->regs + DSTS); 2063 + ep->target_frame = dwc2_hsotg_read_frameno(hsotg); 2064 + dwc2_gadget_incr_frame_num(ep); 2065 + 2066 + ctrl = dwc2_readl(hsotg->regs + DOEPCTL(ep->index)); 2067 + if (ep->target_frame & 0x1) 2068 + ctrl |= DXEPCTL_SETODDFR; 2069 + else 2070 + ctrl |= DXEPCTL_SETEVENFR; 2071 + 2072 + dwc2_writel(ctrl, hsotg->regs + DOEPCTL(ep->index)); 2073 + } 2074 + 2075 + dwc2_gadget_start_next_request(ep); 2076 + doepmsk = dwc2_readl(hsotg->regs + DOEPMSK); 2077 + doepmsk &= ~DOEPMSK_OUTTKNEPDISMSK; 2078 + dwc2_writel(doepmsk, hsotg->regs + DOEPMSK); 2079 + } 2080 + 2081 + /** 2082 + * dwc2_gadget_handle_nak - handle NAK interrupt 2083 + * @hs_ep: The endpoint on which interrupt is asserted. 2084 + * 2085 + * This is starting point for ISOC-IN transfer, synchronization done with 2086 + * first IN token received from host while corresponding EP is disabled. 2087 + * 2088 + * Device does not know when first one token will arrive from host. On first 2089 + * token arrival HW generates 2 interrupts: 'in token received while FIFO empty' 2090 + * and 'NAK'. NAK interrupt for ISOC-IN means that token has arrived and ZLP was 2091 + * sent in response to that as there was no data in FIFO. SW is basing on this 2092 + * interrupt to obtain frame in which token has come and then based on the 2093 + * interval calculates next frame for transfer. 2094 + */ 2095 + static void dwc2_gadget_handle_nak(struct dwc2_hsotg_ep *hs_ep) 2096 + { 2097 + struct dwc2_hsotg *hsotg = hs_ep->parent; 2098 + int dir_in = hs_ep->dir_in; 2099 + 2100 + if (!dir_in || !hs_ep->isochronous) 2101 + return; 2102 + 2103 + if (hs_ep->target_frame == TARGET_FRAME_INITIAL) { 2104 + hs_ep->target_frame = dwc2_hsotg_read_frameno(hsotg); 2105 + if (hs_ep->interval > 1) { 2106 + u32 ctrl = dwc2_readl(hsotg->regs + 2107 + DIEPCTL(hs_ep->index)); 2108 + if (hs_ep->target_frame & 0x1) 2109 + ctrl |= DXEPCTL_SETODDFR; 2110 + else 2111 + ctrl |= DXEPCTL_SETEVENFR; 2112 + 2113 + dwc2_writel(ctrl, hsotg->regs + DIEPCTL(hs_ep->index)); 2114 + } 2115 + 2116 + dwc2_hsotg_complete_request(hsotg, hs_ep, 2117 + get_ep_head(hs_ep), 0); 2118 + } 2119 + 2120 + dwc2_gadget_incr_frame_num(hs_ep); 2121 + } 2122 + 2123 + /** 2019 2124 * dwc2_hsotg_epint - handle an in/out endpoint interrupt 2020 2125 * @hsotg: The driver state 2021 2126 * @idx: The index for the endpoint (0..15) ··· 2217 1954 u32 ints; 2218 1955 u32 ctrl; 2219 1956 2220 - ints = dwc2_readl(hsotg->regs + epint_reg); 1957 + ints = dwc2_gadget_read_ep_interrupts(hsotg, idx, dir_in); 2221 1958 ctrl = dwc2_readl(hsotg->regs + epctl_reg); 2222 1959 2223 1960 /* Clear endpoint interrupts */ ··· 2236 1973 if (idx == 0 && (ints & (DXEPINT_SETUP | DXEPINT_SETUP_RCVD))) 2237 1974 ints &= ~DXEPINT_XFERCOMPL; 2238 1975 2239 - if (ints & DXEPINT_XFERCOMPL) { 2240 - hs_ep->has_correct_parity = 1; 2241 - if (hs_ep->isochronous && hs_ep->interval == 1) 2242 - dwc2_hsotg_change_ep_iso_parity(hsotg, epctl_reg); 1976 + if (ints & DXEPINT_STSPHSERCVD) 1977 + dev_dbg(hsotg->dev, "%s: StsPhseRcvd asserted\n", __func__); 2243 1978 1979 + if (ints & DXEPINT_XFERCOMPL) { 2244 1980 dev_dbg(hsotg->dev, 2245 1981 "%s: XferCompl: DxEPCTL=0x%08x, DXEPTSIZ=%08x\n", 2246 1982 __func__, dwc2_readl(hsotg->regs + epctl_reg), ··· 2250 1988 * at completing IN requests here 2251 1989 */ 2252 1990 if (dir_in) { 1991 + if (hs_ep->isochronous && hs_ep->interval > 1) 1992 + dwc2_gadget_incr_frame_num(hs_ep); 1993 + 2253 1994 dwc2_hsotg_complete_in(hsotg, hs_ep); 1995 + if (ints & DXEPINT_NAKINTRPT) 1996 + ints &= ~DXEPINT_NAKINTRPT; 2254 1997 2255 1998 if (idx == 0 && !hs_ep->req) 2256 1999 dwc2_hsotg_enqueue_setup(hsotg); ··· 2264 1997 * We're using DMA, we need to fire an OutDone here 2265 1998 * as we ignore the RXFIFO. 2266 1999 */ 2000 + if (hs_ep->isochronous && hs_ep->interval > 1) 2001 + dwc2_gadget_incr_frame_num(hs_ep); 2267 2002 2268 2003 dwc2_hsotg_handle_outdone(hsotg, idx); 2269 2004 } 2270 2005 } 2271 2006 2272 - if (ints & DXEPINT_EPDISBLD) { 2273 - dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); 2007 + if (ints & DXEPINT_EPDISBLD) 2008 + dwc2_gadget_handle_ep_disabled(hs_ep); 2274 2009 2275 - if (dir_in) { 2276 - int epctl = dwc2_readl(hsotg->regs + epctl_reg); 2010 + if (ints & DXEPINT_OUTTKNEPDIS) 2011 + dwc2_gadget_handle_out_token_ep_disabled(hs_ep); 2277 2012 2278 - dwc2_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); 2279 - 2280 - if ((epctl & DXEPCTL_STALL) && 2281 - (epctl & DXEPCTL_EPTYPE_BULK)) { 2282 - int dctl = dwc2_readl(hsotg->regs + DCTL); 2283 - 2284 - dctl |= DCTL_CGNPINNAK; 2285 - dwc2_writel(dctl, hsotg->regs + DCTL); 2286 - } 2287 - } 2288 - } 2013 + if (ints & DXEPINT_NAKINTRPT) 2014 + dwc2_gadget_handle_nak(hs_ep); 2289 2015 2290 2016 if (ints & DXEPINT_AHBERR) 2291 2017 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); ··· 2306 2046 2307 2047 if (dir_in && !hs_ep->isochronous) { 2308 2048 /* not sure if this is important, but we'll clear it anyway */ 2309 - if (ints & DIEPMSK_INTKNTXFEMPMSK) { 2049 + if (ints & DXEPINT_INTKNTXFEMP) { 2310 2050 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", 2311 2051 __func__, idx); 2312 2052 } 2313 2053 2314 2054 /* this probably means something bad is happening */ 2315 - if (ints & DIEPMSK_INTKNEPMISMSK) { 2055 + if (ints & DXEPINT_INTKNEPMIS) { 2316 2056 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", 2317 2057 __func__, idx); 2318 2058 } 2319 2059 2320 2060 /* FIFO has space or is empty (see GAHBCFG) */ 2321 2061 if (hsotg->dedicated_fifos && 2322 - ints & DIEPMSK_TXFIFOEMPTY) { 2062 + ints & DXEPINT_TXFEMP) { 2323 2063 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", 2324 2064 __func__, idx); 2325 2065 if (!using_dma(hsotg)) ··· 2582 2322 dwc2_writel(((hsotg->dedicated_fifos && !using_dma(hsotg)) ? 2583 2323 DIEPMSK_TXFIFOEMPTY | DIEPMSK_INTKNTXFEMPMSK : 0) | 2584 2324 DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK | 2585 - DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | 2586 - DIEPMSK_INTKNEPMISMSK, 2325 + DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK, 2587 2326 hsotg->regs + DIEPMSK); 2588 2327 2589 2328 /* 2590 2329 * don't need XferCompl, we get that from RXFIFO in slave mode. In 2591 2330 * DMA mode we may need this. 2592 2331 */ 2593 - dwc2_writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | 2594 - DIEPMSK_TIMEOUTMSK) : 0) | 2332 + dwc2_writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK) : 0) | 2595 2333 DOEPMSK_EPDISBLDMSK | DOEPMSK_AHBERRMSK | 2596 - DOEPMSK_SETUPMSK, 2334 + DOEPMSK_SETUPMSK | DOEPMSK_STSPHSERCVDMSK, 2597 2335 hsotg->regs + DOEPMSK); 2598 2336 2599 2337 dwc2_writel(0, hsotg->regs + DAINTMSK); ··· 2669 2411 { 2670 2412 /* remove the soft-disconnect and let's go */ 2671 2413 __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); 2414 + } 2415 + 2416 + /** 2417 + * dwc2_gadget_handle_incomplete_isoc_in - handle incomplete ISO IN Interrupt. 2418 + * @hsotg: The device state: 2419 + * 2420 + * This interrupt indicates one of the following conditions occurred while 2421 + * transmitting an ISOC transaction. 2422 + * - Corrupted IN Token for ISOC EP. 2423 + * - Packet not complete in FIFO. 2424 + * 2425 + * The following actions will be taken: 2426 + * - Determine the EP 2427 + * - Disable EP; when 'Endpoint Disabled' interrupt is received Flush FIFO 2428 + */ 2429 + static void dwc2_gadget_handle_incomplete_isoc_in(struct dwc2_hsotg *hsotg) 2430 + { 2431 + struct dwc2_hsotg_ep *hs_ep; 2432 + u32 epctrl; 2433 + u32 idx; 2434 + 2435 + dev_dbg(hsotg->dev, "Incomplete isoc in interrupt received:\n"); 2436 + 2437 + for (idx = 1; idx <= hsotg->num_of_eps; idx++) { 2438 + hs_ep = hsotg->eps_in[idx]; 2439 + epctrl = dwc2_readl(hsotg->regs + DIEPCTL(idx)); 2440 + if ((epctrl & DXEPCTL_EPENA) && hs_ep->isochronous && 2441 + dwc2_gadget_target_frame_elapsed(hs_ep)) { 2442 + epctrl |= DXEPCTL_SNAK; 2443 + epctrl |= DXEPCTL_EPDIS; 2444 + dwc2_writel(epctrl, hsotg->regs + DIEPCTL(idx)); 2445 + } 2446 + } 2447 + 2448 + /* Clear interrupt */ 2449 + dwc2_writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS); 2450 + } 2451 + 2452 + /** 2453 + * dwc2_gadget_handle_incomplete_isoc_out - handle incomplete ISO OUT Interrupt 2454 + * @hsotg: The device state: 2455 + * 2456 + * This interrupt indicates one of the following conditions occurred while 2457 + * transmitting an ISOC transaction. 2458 + * - Corrupted OUT Token for ISOC EP. 2459 + * - Packet not complete in FIFO. 2460 + * 2461 + * The following actions will be taken: 2462 + * - Determine the EP 2463 + * - Set DCTL_SGOUTNAK and unmask GOUTNAKEFF if target frame elapsed. 2464 + */ 2465 + static void dwc2_gadget_handle_incomplete_isoc_out(struct dwc2_hsotg *hsotg) 2466 + { 2467 + u32 gintsts; 2468 + u32 gintmsk; 2469 + u32 epctrl; 2470 + struct dwc2_hsotg_ep *hs_ep; 2471 + int idx; 2472 + 2473 + dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__); 2474 + 2475 + for (idx = 1; idx <= hsotg->num_of_eps; idx++) { 2476 + hs_ep = hsotg->eps_out[idx]; 2477 + epctrl = dwc2_readl(hsotg->regs + DOEPCTL(idx)); 2478 + if ((epctrl & DXEPCTL_EPENA) && hs_ep->isochronous && 2479 + dwc2_gadget_target_frame_elapsed(hs_ep)) { 2480 + /* Unmask GOUTNAKEFF interrupt */ 2481 + gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 2482 + gintmsk |= GINTSTS_GOUTNAKEFF; 2483 + dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 2484 + 2485 + gintsts = dwc2_readl(hsotg->regs + GINTSTS); 2486 + if (!(gintsts & GINTSTS_GOUTNAKEFF)) 2487 + __orr32(hsotg->regs + DCTL, DCTL_SGOUTNAK); 2488 + } 2489 + } 2490 + 2491 + /* Clear interrupt */ 2492 + dwc2_writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS); 2672 2493 } 2673 2494 2674 2495 /** ··· 2882 2545 */ 2883 2546 2884 2547 if (gintsts & GINTSTS_GOUTNAKEFF) { 2885 - dev_info(hsotg->dev, "GOUTNakEff triggered\n"); 2548 + u8 idx; 2549 + u32 epctrl; 2550 + u32 gintmsk; 2551 + struct dwc2_hsotg_ep *hs_ep; 2886 2552 2887 - __orr32(hsotg->regs + DCTL, DCTL_CGOUTNAK); 2553 + /* Mask this interrupt */ 2554 + gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 2555 + gintmsk &= ~GINTSTS_GOUTNAKEFF; 2556 + dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 2888 2557 2889 - dwc2_hsotg_dump(hsotg); 2558 + dev_dbg(hsotg->dev, "GOUTNakEff triggered\n"); 2559 + for (idx = 1; idx <= hsotg->num_of_eps; idx++) { 2560 + hs_ep = hsotg->eps_out[idx]; 2561 + epctrl = dwc2_readl(hsotg->regs + DOEPCTL(idx)); 2562 + 2563 + if ((epctrl & DXEPCTL_EPENA) && hs_ep->isochronous) { 2564 + epctrl |= DXEPCTL_SNAK; 2565 + epctrl |= DXEPCTL_EPDIS; 2566 + dwc2_writel(epctrl, hsotg->regs + DOEPCTL(idx)); 2567 + } 2568 + } 2569 + 2570 + /* This interrupt bit is cleared in DXEPINT_EPDISBLD handler */ 2890 2571 } 2891 2572 2892 2573 if (gintsts & GINTSTS_GINNAKEFF) { ··· 2915 2560 dwc2_hsotg_dump(hsotg); 2916 2561 } 2917 2562 2918 - if (gintsts & GINTSTS_INCOMPL_SOIN) { 2919 - u32 idx, epctl_reg; 2920 - struct dwc2_hsotg_ep *hs_ep; 2563 + if (gintsts & GINTSTS_INCOMPL_SOIN) 2564 + dwc2_gadget_handle_incomplete_isoc_in(hsotg); 2921 2565 2922 - dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOIN\n", __func__); 2923 - for (idx = 1; idx < hsotg->num_of_eps; idx++) { 2924 - hs_ep = hsotg->eps_in[idx]; 2925 - 2926 - if (!hs_ep->isochronous || hs_ep->has_correct_parity) 2927 - continue; 2928 - 2929 - epctl_reg = DIEPCTL(idx); 2930 - dwc2_hsotg_change_ep_iso_parity(hsotg, epctl_reg); 2931 - } 2932 - dwc2_writel(GINTSTS_INCOMPL_SOIN, hsotg->regs + GINTSTS); 2933 - } 2934 - 2935 - if (gintsts & GINTSTS_INCOMPL_SOOUT) { 2936 - u32 idx, epctl_reg; 2937 - struct dwc2_hsotg_ep *hs_ep; 2938 - 2939 - dev_dbg(hsotg->dev, "%s: GINTSTS_INCOMPL_SOOUT\n", __func__); 2940 - for (idx = 1; idx < hsotg->num_of_eps; idx++) { 2941 - hs_ep = hsotg->eps_out[idx]; 2942 - 2943 - if (!hs_ep->isochronous || hs_ep->has_correct_parity) 2944 - continue; 2945 - 2946 - epctl_reg = DOEPCTL(idx); 2947 - dwc2_hsotg_change_ep_iso_parity(hsotg, epctl_reg); 2948 - } 2949 - dwc2_writel(GINTSTS_INCOMPL_SOOUT, hsotg->regs + GINTSTS); 2950 - } 2566 + if (gintsts & GINTSTS_INCOMPL_SOOUT) 2567 + dwc2_gadget_handle_incomplete_isoc_out(hsotg); 2951 2568 2952 2569 /* 2953 2570 * if we've had fifo events, we should try and go around the ··· 2951 2624 u32 epctrl_reg; 2952 2625 u32 epctrl; 2953 2626 u32 mps; 2627 + u32 mask; 2954 2628 unsigned int dir_in; 2955 2629 unsigned int i, val, size; 2956 2630 int ret = 0; ··· 2994 2666 */ 2995 2667 epctrl |= DXEPCTL_USBACTEP; 2996 2668 2997 - /* 2998 - * set the NAK status on the endpoint, otherwise we might try and 2999 - * do something with data that we've yet got a request to process 3000 - * since the RXFIFO will take data for an endpoint even if the 3001 - * size register hasn't been set. 3002 - */ 3003 - 3004 - epctrl |= DXEPCTL_SNAK; 3005 - 3006 2669 /* update the endpoint state */ 3007 2670 dwc2_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps, dir_in); 3008 2671 ··· 3002 2683 hs_ep->periodic = 0; 3003 2684 hs_ep->halted = 0; 3004 2685 hs_ep->interval = desc->bInterval; 3005 - hs_ep->has_correct_parity = 0; 3006 - 3007 - if (hs_ep->interval > 1 && hs_ep->mc > 1) 3008 - dev_err(hsotg->dev, "MC > 1 when interval is not 1\n"); 3009 2686 3010 2687 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 3011 2688 case USB_ENDPOINT_XFER_ISOC: 3012 2689 epctrl |= DXEPCTL_EPTYPE_ISO; 3013 2690 epctrl |= DXEPCTL_SETEVENFR; 3014 2691 hs_ep->isochronous = 1; 3015 - if (dir_in) 2692 + hs_ep->interval = 1 << (desc->bInterval - 1); 2693 + hs_ep->target_frame = TARGET_FRAME_INITIAL; 2694 + if (dir_in) { 3016 2695 hs_ep->periodic = 1; 2696 + mask = dwc2_readl(hsotg->regs + DIEPMSK); 2697 + mask |= DIEPMSK_NAKMSK; 2698 + dwc2_writel(mask, hsotg->regs + DIEPMSK); 2699 + } else { 2700 + mask = dwc2_readl(hsotg->regs + DOEPMSK); 2701 + mask |= DOEPMSK_OUTTKNEPDISMSK; 2702 + dwc2_writel(mask, hsotg->regs + DOEPMSK); 2703 + } 3017 2704 break; 3018 2705 3019 2706 case USB_ENDPOINT_XFER_BULK: ··· 3029 2704 case USB_ENDPOINT_XFER_INT: 3030 2705 if (dir_in) 3031 2706 hs_ep->periodic = 1; 2707 + 2708 + if (hsotg->gadget.speed == USB_SPEED_HIGH) 2709 + hs_ep->interval = 1 << (desc->bInterval - 1); 3032 2710 3033 2711 epctrl |= DXEPCTL_EPTYPE_INTERRUPT; 3034 2712 break; ··· 3086 2758 } 3087 2759 3088 2760 /* for non control endpoints, set PID to D0 */ 3089 - if (index) 2761 + if (index && !hs_ep->isochronous) 3090 2762 epctrl |= DXEPCTL_SETD0PID; 3091 2763 3092 2764 dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", ··· 3203 2875 dev_warn(hsotg->dev, 3204 2876 "%s: timeout DIEPINT.NAKEFF\n", __func__); 3205 2877 } else { 3206 - /* Clear any pending nak effect interrupt */ 3207 - dwc2_writel(GINTSTS_GOUTNAKEFF, hsotg->regs + GINTSTS); 3208 - 3209 - __orr32(hsotg->regs + DCTL, DCTL_SGOUTNAK); 2878 + if (!(dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_GOUTNAKEFF)) 2879 + __orr32(hsotg->regs + DCTL, DCTL_SGOUTNAK); 3210 2880 3211 2881 /* Wait for global nak to take effect */ 3212 2882 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS,
+2 -1
drivers/usb/dwc2/hcd_queue.c
··· 367 367 * @fmt: The format for printf. 368 368 * @...: The args for printf. 369 369 */ 370 - static void cat_printf(char **buf, size_t *size, const char *fmt, ...) 370 + static __printf(3, 4) 371 + void cat_printf(char **buf, size_t *size, const char *fmt, ...) 371 372 { 372 373 va_list args; 373 374 int i;
+14
drivers/usb/dwc2/hw.h
··· 459 459 #define DSTS_SUSPSTS (1 << 0) 460 460 461 461 #define DIEPMSK HSOTG_REG(0x810) 462 + #define DIEPMSK_NAKMSK (1 << 13) 463 + #define DIEPMSK_BNAININTRMSK (1 << 9) 464 + #define DIEPMSK_TXFIFOUNDRNMSK (1 << 8) 462 465 #define DIEPMSK_TXFIFOEMPTY (1 << 7) 463 466 #define DIEPMSK_INEPNAKEFFMSK (1 << 6) 464 467 #define DIEPMSK_INTKNEPMISMSK (1 << 5) ··· 473 470 474 471 #define DOEPMSK HSOTG_REG(0x814) 475 472 #define DOEPMSK_BACK2BACKSETUP (1 << 6) 473 + #define DOEPMSK_STSPHSERCVDMSK (1 << 5) 476 474 #define DOEPMSK_OUTTKNEPDISMSK (1 << 4) 477 475 #define DOEPMSK_SETUPMSK (1 << 3) 478 476 #define DOEPMSK_AHBERRMSK (1 << 2) ··· 490 486 #define DTKNQR2 HSOTG_REG(0x824) 491 487 #define DTKNQR3 HSOTG_REG(0x830) 492 488 #define DTKNQR4 HSOTG_REG(0x834) 489 + #define DIEPEMPMSK HSOTG_REG(0x834) 493 490 494 491 #define DVBUSDIS HSOTG_REG(0x828) 495 492 #define DVBUSPULSE HSOTG_REG(0x82C) ··· 549 544 #define DIEPINT(_a) HSOTG_REG(0x908 + ((_a) * 0x20)) 550 545 #define DOEPINT(_a) HSOTG_REG(0xB08 + ((_a) * 0x20)) 551 546 #define DXEPINT_SETUP_RCVD (1 << 15) 547 + #define DXEPINT_NYETINTRPT (1 << 14) 548 + #define DXEPINT_NAKINTRPT (1 << 13) 549 + #define DXEPINT_BBLEERRINTRPT (1 << 12) 550 + #define DXEPINT_PKTDRPSTS (1 << 11) 551 + #define DXEPINT_BNAINTR (1 << 9) 552 + #define DXEPINT_TXFIFOUNDRN (1 << 8) 553 + #define DXEPINT_OUTPKTERR (1 << 8) 554 + #define DXEPINT_TXFEMP (1 << 7) 552 555 #define DXEPINT_INEPNAKEFF (1 << 6) 553 556 #define DXEPINT_BACK2BACKSETUP (1 << 6) 554 557 #define DXEPINT_INTKNEPMIS (1 << 5) 558 + #define DXEPINT_STSPHSERCVD (1 << 5) 555 559 #define DXEPINT_INTKNTXFEMP (1 << 4) 556 560 #define DXEPINT_OUTTKNEPDIS (1 << 4) 557 561 #define DXEPINT_TIMEOUT (1 << 3)
+237 -197
drivers/usb/dwc3/core.c
··· 41 41 #include <linux/usb/of.h> 42 42 #include <linux/usb/otg.h> 43 43 44 - #include "platform_data.h" 45 44 #include "core.h" 46 45 #include "gadget.h" 47 46 #include "io.h" 48 47 49 48 #include "debug.h" 50 49 51 - /* -------------------------------------------------------------------------- */ 50 + #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */ 52 51 53 52 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) 54 53 { ··· 148 149 /* 149 150 * dwc3_frame_length_adjustment - Adjusts frame length if required 150 151 * @dwc3: Pointer to our controller context structure 151 - * @fladj: Value of GFLADJ_30MHZ to adjust frame length 152 152 */ 153 - static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) 153 + static void dwc3_frame_length_adjustment(struct dwc3 *dwc) 154 154 { 155 155 u32 reg; 156 156 u32 dft; ··· 157 159 if (dwc->revision < DWC3_REVISION_250A) 158 160 return; 159 161 160 - if (fladj == 0) 162 + if (dwc->fladj == 0) 161 163 return; 162 164 163 165 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); 164 166 dft = reg & DWC3_GFLADJ_30MHZ_MASK; 165 - if (!dev_WARN_ONCE(dwc->dev, dft == fladj, 167 + if (!dev_WARN_ONCE(dwc->dev, dft == dwc->fladj, 166 168 "request value same as default, ignoring\n")) { 167 169 reg &= ~DWC3_GFLADJ_30MHZ_MASK; 168 - reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | fladj; 170 + reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; 169 171 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); 170 172 } 171 173 } ··· 505 507 return 0; 506 508 } 507 509 510 + static void dwc3_core_exit(struct dwc3 *dwc) 511 + { 512 + dwc3_event_buffers_cleanup(dwc); 513 + 514 + usb_phy_shutdown(dwc->usb2_phy); 515 + usb_phy_shutdown(dwc->usb3_phy); 516 + phy_exit(dwc->usb2_generic_phy); 517 + phy_exit(dwc->usb3_generic_phy); 518 + 519 + usb_phy_set_suspend(dwc->usb2_phy, 1); 520 + usb_phy_set_suspend(dwc->usb3_phy, 1); 521 + phy_power_off(dwc->usb2_generic_phy); 522 + phy_power_off(dwc->usb3_generic_phy); 523 + } 524 + 508 525 /** 509 526 * dwc3_core_init - Low-level initialization of DWC3 Core 510 527 * @dwc: Pointer to our controller context structure ··· 566 553 goto err0; 567 554 568 555 ret = dwc3_core_soft_reset(dwc); 556 + if (ret) 557 + goto err0; 558 + 559 + ret = dwc3_phy_setup(dwc); 569 560 if (ret) 570 561 goto err0; 571 562 ··· 639 622 if (dwc->revision < DWC3_REVISION_190A) 640 623 reg |= DWC3_GCTL_U2RSTECN; 641 624 642 - dwc3_core_num_eps(dwc); 643 - 644 625 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 645 626 646 - ret = dwc3_alloc_scratch_buffers(dwc); 647 - if (ret) 648 - goto err1; 627 + dwc3_core_num_eps(dwc); 649 628 650 629 ret = dwc3_setup_scratch_buffers(dwc); 651 630 if (ret) 631 + goto err1; 632 + 633 + /* Adjust Frame Length */ 634 + dwc3_frame_length_adjustment(dwc); 635 + 636 + usb_phy_set_suspend(dwc->usb2_phy, 0); 637 + usb_phy_set_suspend(dwc->usb3_phy, 0); 638 + ret = phy_power_on(dwc->usb2_generic_phy); 639 + if (ret < 0) 652 640 goto err2; 641 + 642 + ret = phy_power_on(dwc->usb3_generic_phy); 643 + if (ret < 0) 644 + goto err3; 645 + 646 + ret = dwc3_event_buffers_setup(dwc); 647 + if (ret) { 648 + dev_err(dwc->dev, "failed to setup event buffers\n"); 649 + goto err4; 650 + } 653 651 654 652 return 0; 655 653 654 + err4: 655 + phy_power_off(dwc->usb2_generic_phy); 656 + 657 + err3: 658 + phy_power_off(dwc->usb3_generic_phy); 659 + 656 660 err2: 657 - dwc3_free_scratch_buffers(dwc); 661 + usb_phy_set_suspend(dwc->usb2_phy, 1); 662 + usb_phy_set_suspend(dwc->usb3_phy, 1); 663 + dwc3_core_exit(dwc); 658 664 659 665 err1: 660 666 usb_phy_shutdown(dwc->usb2_phy); ··· 687 647 688 648 err0: 689 649 return ret; 690 - } 691 - 692 - static void dwc3_core_exit(struct dwc3 *dwc) 693 - { 694 - dwc3_free_scratch_buffers(dwc); 695 - usb_phy_shutdown(dwc->usb2_phy); 696 - usb_phy_shutdown(dwc->usb3_phy); 697 - phy_exit(dwc->usb2_generic_phy); 698 - phy_exit(dwc->usb3_generic_phy); 699 650 } 700 651 701 652 static int dwc3_core_get_phy(struct dwc3 *dwc) ··· 766 735 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); 767 736 ret = dwc3_gadget_init(dwc); 768 737 if (ret) { 769 - dev_err(dev, "failed to initialize gadget\n"); 738 + if (ret != -EPROBE_DEFER) 739 + dev_err(dev, "failed to initialize gadget\n"); 770 740 return ret; 771 741 } 772 742 break; ··· 775 743 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); 776 744 ret = dwc3_host_init(dwc); 777 745 if (ret) { 778 - dev_err(dev, "failed to initialize host\n"); 746 + if (ret != -EPROBE_DEFER) 747 + dev_err(dev, "failed to initialize host\n"); 779 748 return ret; 780 749 } 781 750 break; ··· 784 751 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); 785 752 ret = dwc3_host_init(dwc); 786 753 if (ret) { 787 - dev_err(dev, "failed to initialize host\n"); 754 + if (ret != -EPROBE_DEFER) 755 + dev_err(dev, "failed to initialize host\n"); 788 756 return ret; 789 757 } 790 758 791 759 ret = dwc3_gadget_init(dwc); 792 760 if (ret) { 793 - dev_err(dev, "failed to initialize gadget\n"); 761 + if (ret != -EPROBE_DEFER) 762 + dev_err(dev, "failed to initialize gadget\n"); 794 763 return ret; 795 764 } 796 765 break; ··· 828 793 static int dwc3_probe(struct platform_device *pdev) 829 794 { 830 795 struct device *dev = &pdev->dev; 831 - struct dwc3_platform_data *pdata = dev_get_platdata(dev); 832 796 struct resource *res; 833 797 struct dwc3 *dwc; 834 798 u8 lpm_nyet_threshold; 835 799 u8 tx_de_emphasis; 836 800 u8 hird_threshold; 837 - u32 fladj = 0; 838 801 839 802 int ret; 840 803 ··· 846 813 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 847 814 dwc->mem = mem; 848 815 dwc->dev = dev; 849 - 850 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 851 - if (!res) { 852 - dev_err(dev, "missing IRQ\n"); 853 - return -ENODEV; 854 - } 855 - dwc->xhci_resources[1].start = res->start; 856 - dwc->xhci_resources[1].end = res->end; 857 - dwc->xhci_resources[1].flags = res->flags; 858 - dwc->xhci_resources[1].name = res->name; 859 816 860 817 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 861 818 if (!res) { ··· 932 909 device_property_read_string(dev, "snps,hsphy_interface", 933 910 &dwc->hsphy_interface); 934 911 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment", 935 - &fladj); 936 - 937 - if (pdata) { 938 - dwc->maximum_speed = pdata->maximum_speed; 939 - dwc->has_lpm_erratum = pdata->has_lpm_erratum; 940 - if (pdata->lpm_nyet_threshold) 941 - lpm_nyet_threshold = pdata->lpm_nyet_threshold; 942 - dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend; 943 - if (pdata->hird_threshold) 944 - hird_threshold = pdata->hird_threshold; 945 - 946 - dwc->usb3_lpm_capable = pdata->usb3_lpm_capable; 947 - dwc->dr_mode = pdata->dr_mode; 948 - 949 - dwc->disable_scramble_quirk = pdata->disable_scramble_quirk; 950 - dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk; 951 - dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk; 952 - dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk; 953 - dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk; 954 - dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk; 955 - dwc->lfps_filter_quirk = pdata->lfps_filter_quirk; 956 - dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk; 957 - dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk; 958 - dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk; 959 - dwc->dis_enblslpm_quirk = pdata->dis_enblslpm_quirk; 960 - dwc->dis_rxdet_inp3_quirk = pdata->dis_rxdet_inp3_quirk; 961 - 962 - dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk; 963 - if (pdata->tx_de_emphasis) 964 - tx_de_emphasis = pdata->tx_de_emphasis; 965 - 966 - dwc->hsphy_interface = pdata->hsphy_interface; 967 - fladj = pdata->fladj_value; 968 - } 912 + &dwc->fladj); 969 913 970 914 dwc->lpm_nyet_threshold = lpm_nyet_threshold; 971 915 dwc->tx_de_emphasis = tx_de_emphasis; ··· 942 952 943 953 platform_set_drvdata(pdev, dwc); 944 954 dwc3_cache_hwparams(dwc); 945 - 946 - ret = dwc3_phy_setup(dwc); 947 - if (ret) 948 - goto err0; 949 955 950 956 ret = dwc3_core_get_phy(dwc); 951 957 if (ret) ··· 955 969 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); 956 970 } 957 971 972 + pm_runtime_set_active(dev); 973 + pm_runtime_use_autosuspend(dev); 974 + pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY); 958 975 pm_runtime_enable(dev); 959 - pm_runtime_get_sync(dev); 976 + ret = pm_runtime_get_sync(dev); 977 + if (ret < 0) 978 + goto err1; 979 + 960 980 pm_runtime_forbid(dev); 961 981 962 982 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); 963 983 if (ret) { 964 984 dev_err(dwc->dev, "failed to allocate event buffers\n"); 965 985 ret = -ENOMEM; 966 - goto err1; 986 + goto err2; 967 987 } 968 988 969 - if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) 989 + if (IS_ENABLED(CONFIG_USB_DWC3_HOST) && 990 + (dwc->dr_mode == USB_DR_MODE_OTG || 991 + dwc->dr_mode == USB_DR_MODE_UNKNOWN)) 970 992 dwc->dr_mode = USB_DR_MODE_HOST; 971 - else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) 993 + else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET) && 994 + (dwc->dr_mode == USB_DR_MODE_OTG || 995 + dwc->dr_mode == USB_DR_MODE_UNKNOWN)) 972 996 dwc->dr_mode = USB_DR_MODE_PERIPHERAL; 973 997 974 998 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) 975 999 dwc->dr_mode = USB_DR_MODE_OTG; 976 1000 1001 + ret = dwc3_alloc_scratch_buffers(dwc); 1002 + if (ret) 1003 + goto err3; 1004 + 977 1005 ret = dwc3_core_init(dwc); 978 1006 if (ret) { 979 1007 dev_err(dev, "failed to initialize core\n"); 980 - goto err1; 1008 + goto err4; 981 1009 } 982 1010 983 1011 /* Check the maximum_speed parameter */ ··· 1021 1021 break; 1022 1022 } 1023 1023 1024 - /* Adjust Frame Length */ 1025 - dwc3_frame_length_adjustment(dwc, fladj); 1026 - 1027 - usb_phy_set_suspend(dwc->usb2_phy, 0); 1028 - usb_phy_set_suspend(dwc->usb3_phy, 0); 1029 - ret = phy_power_on(dwc->usb2_generic_phy); 1030 - if (ret < 0) 1031 - goto err2; 1032 - 1033 - ret = phy_power_on(dwc->usb3_generic_phy); 1034 - if (ret < 0) 1035 - goto err3; 1036 - 1037 - ret = dwc3_event_buffers_setup(dwc); 1038 - if (ret) { 1039 - dev_err(dwc->dev, "failed to setup event buffers\n"); 1040 - goto err4; 1041 - } 1042 - 1043 1024 ret = dwc3_core_init_mode(dwc); 1044 1025 if (ret) 1045 1026 goto err5; 1046 1027 1047 1028 dwc3_debugfs_init(dwc); 1048 - pm_runtime_allow(dev); 1029 + pm_runtime_put(dev); 1049 1030 1050 1031 return 0; 1051 1032 ··· 1034 1053 dwc3_event_buffers_cleanup(dwc); 1035 1054 1036 1055 err4: 1037 - phy_power_off(dwc->usb3_generic_phy); 1056 + dwc3_free_scratch_buffers(dwc); 1038 1057 1039 1058 err3: 1040 - phy_power_off(dwc->usb2_generic_phy); 1041 - 1042 - err2: 1043 - usb_phy_set_suspend(dwc->usb2_phy, 1); 1044 - usb_phy_set_suspend(dwc->usb3_phy, 1); 1045 - dwc3_core_exit(dwc); 1046 - 1047 - err1: 1048 1059 dwc3_free_event_buffers(dwc); 1049 1060 dwc3_ulpi_exit(dwc); 1061 + 1062 + err2: 1063 + pm_runtime_allow(&pdev->dev); 1064 + 1065 + err1: 1066 + pm_runtime_put_sync(&pdev->dev); 1067 + pm_runtime_disable(&pdev->dev); 1050 1068 1051 1069 err0: 1052 1070 /* ··· 1063 1083 struct dwc3 *dwc = platform_get_drvdata(pdev); 1064 1084 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1065 1085 1086 + pm_runtime_get_sync(&pdev->dev); 1066 1087 /* 1067 1088 * restore res->start back to its original value so that, in case the 1068 1089 * probe is deferred, we don't end up getting error in request the ··· 1073 1092 1074 1093 dwc3_debugfs_exit(dwc); 1075 1094 dwc3_core_exit_mode(dwc); 1076 - dwc3_event_buffers_cleanup(dwc); 1077 - dwc3_free_event_buffers(dwc); 1078 - 1079 - usb_phy_set_suspend(dwc->usb2_phy, 1); 1080 - usb_phy_set_suspend(dwc->usb3_phy, 1); 1081 - phy_power_off(dwc->usb2_generic_phy); 1082 - phy_power_off(dwc->usb3_generic_phy); 1083 1095 1084 1096 dwc3_core_exit(dwc); 1085 1097 dwc3_ulpi_exit(dwc); 1086 1098 1087 1099 pm_runtime_put_sync(&pdev->dev); 1100 + pm_runtime_allow(&pdev->dev); 1088 1101 pm_runtime_disable(&pdev->dev); 1102 + 1103 + dwc3_free_event_buffers(dwc); 1104 + dwc3_free_scratch_buffers(dwc); 1089 1105 1090 1106 return 0; 1091 1107 } 1108 + 1109 + #ifdef CONFIG_PM 1110 + static int dwc3_suspend_common(struct dwc3 *dwc) 1111 + { 1112 + unsigned long flags; 1113 + 1114 + switch (dwc->dr_mode) { 1115 + case USB_DR_MODE_PERIPHERAL: 1116 + case USB_DR_MODE_OTG: 1117 + spin_lock_irqsave(&dwc->lock, flags); 1118 + dwc3_gadget_suspend(dwc); 1119 + spin_unlock_irqrestore(&dwc->lock, flags); 1120 + break; 1121 + case USB_DR_MODE_HOST: 1122 + default: 1123 + /* do nothing */ 1124 + break; 1125 + } 1126 + 1127 + dwc3_core_exit(dwc); 1128 + 1129 + return 0; 1130 + } 1131 + 1132 + static int dwc3_resume_common(struct dwc3 *dwc) 1133 + { 1134 + unsigned long flags; 1135 + int ret; 1136 + 1137 + ret = dwc3_core_init(dwc); 1138 + if (ret) 1139 + return ret; 1140 + 1141 + switch (dwc->dr_mode) { 1142 + case USB_DR_MODE_PERIPHERAL: 1143 + case USB_DR_MODE_OTG: 1144 + spin_lock_irqsave(&dwc->lock, flags); 1145 + dwc3_gadget_resume(dwc); 1146 + spin_unlock_irqrestore(&dwc->lock, flags); 1147 + /* FALLTHROUGH */ 1148 + case USB_DR_MODE_HOST: 1149 + default: 1150 + /* do nothing */ 1151 + break; 1152 + } 1153 + 1154 + return 0; 1155 + } 1156 + 1157 + static int dwc3_runtime_checks(struct dwc3 *dwc) 1158 + { 1159 + switch (dwc->dr_mode) { 1160 + case USB_DR_MODE_PERIPHERAL: 1161 + case USB_DR_MODE_OTG: 1162 + if (dwc->connected) 1163 + return -EBUSY; 1164 + break; 1165 + case USB_DR_MODE_HOST: 1166 + default: 1167 + /* do nothing */ 1168 + break; 1169 + } 1170 + 1171 + return 0; 1172 + } 1173 + 1174 + static int dwc3_runtime_suspend(struct device *dev) 1175 + { 1176 + struct dwc3 *dwc = dev_get_drvdata(dev); 1177 + int ret; 1178 + 1179 + if (dwc3_runtime_checks(dwc)) 1180 + return -EBUSY; 1181 + 1182 + ret = dwc3_suspend_common(dwc); 1183 + if (ret) 1184 + return ret; 1185 + 1186 + device_init_wakeup(dev, true); 1187 + 1188 + return 0; 1189 + } 1190 + 1191 + static int dwc3_runtime_resume(struct device *dev) 1192 + { 1193 + struct dwc3 *dwc = dev_get_drvdata(dev); 1194 + int ret; 1195 + 1196 + device_init_wakeup(dev, false); 1197 + 1198 + ret = dwc3_resume_common(dwc); 1199 + if (ret) 1200 + return ret; 1201 + 1202 + switch (dwc->dr_mode) { 1203 + case USB_DR_MODE_PERIPHERAL: 1204 + case USB_DR_MODE_OTG: 1205 + dwc3_gadget_process_pending_events(dwc); 1206 + break; 1207 + case USB_DR_MODE_HOST: 1208 + default: 1209 + /* do nothing */ 1210 + break; 1211 + } 1212 + 1213 + pm_runtime_mark_last_busy(dev); 1214 + 1215 + return 0; 1216 + } 1217 + 1218 + static int dwc3_runtime_idle(struct device *dev) 1219 + { 1220 + struct dwc3 *dwc = dev_get_drvdata(dev); 1221 + 1222 + switch (dwc->dr_mode) { 1223 + case USB_DR_MODE_PERIPHERAL: 1224 + case USB_DR_MODE_OTG: 1225 + if (dwc3_runtime_checks(dwc)) 1226 + return -EBUSY; 1227 + break; 1228 + case USB_DR_MODE_HOST: 1229 + default: 1230 + /* do nothing */ 1231 + break; 1232 + } 1233 + 1234 + pm_runtime_mark_last_busy(dev); 1235 + pm_runtime_autosuspend(dev); 1236 + 1237 + return 0; 1238 + } 1239 + #endif /* CONFIG_PM */ 1092 1240 1093 1241 #ifdef CONFIG_PM_SLEEP 1094 1242 static int dwc3_suspend(struct device *dev) 1095 1243 { 1096 1244 struct dwc3 *dwc = dev_get_drvdata(dev); 1097 - unsigned long flags; 1245 + int ret; 1098 1246 1099 - spin_lock_irqsave(&dwc->lock, flags); 1100 - 1101 - switch (dwc->dr_mode) { 1102 - case USB_DR_MODE_PERIPHERAL: 1103 - case USB_DR_MODE_OTG: 1104 - dwc3_gadget_suspend(dwc); 1105 - /* FALLTHROUGH */ 1106 - case USB_DR_MODE_HOST: 1107 - default: 1108 - dwc3_event_buffers_cleanup(dwc); 1109 - break; 1110 - } 1111 - 1112 - dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL); 1113 - spin_unlock_irqrestore(&dwc->lock, flags); 1114 - 1115 - usb_phy_shutdown(dwc->usb3_phy); 1116 - usb_phy_shutdown(dwc->usb2_phy); 1117 - phy_exit(dwc->usb2_generic_phy); 1118 - phy_exit(dwc->usb3_generic_phy); 1119 - 1120 - usb_phy_set_suspend(dwc->usb2_phy, 1); 1121 - usb_phy_set_suspend(dwc->usb3_phy, 1); 1122 - WARN_ON(phy_power_off(dwc->usb2_generic_phy) < 0); 1123 - WARN_ON(phy_power_off(dwc->usb3_generic_phy) < 0); 1247 + ret = dwc3_suspend_common(dwc); 1248 + if (ret) 1249 + return ret; 1124 1250 1125 1251 pinctrl_pm_select_sleep_state(dev); 1126 1252 ··· 1237 1149 static int dwc3_resume(struct device *dev) 1238 1150 { 1239 1151 struct dwc3 *dwc = dev_get_drvdata(dev); 1240 - unsigned long flags; 1241 1152 int ret; 1242 1153 1243 1154 pinctrl_pm_select_default_state(dev); 1244 1155 1245 - usb_phy_set_suspend(dwc->usb2_phy, 0); 1246 - usb_phy_set_suspend(dwc->usb3_phy, 0); 1247 - ret = phy_power_on(dwc->usb2_generic_phy); 1248 - if (ret < 0) 1156 + ret = dwc3_resume_common(dwc); 1157 + if (ret) 1249 1158 return ret; 1250 - 1251 - ret = phy_power_on(dwc->usb3_generic_phy); 1252 - if (ret < 0) 1253 - goto err_usb2phy_power; 1254 - 1255 - usb_phy_init(dwc->usb3_phy); 1256 - usb_phy_init(dwc->usb2_phy); 1257 - ret = phy_init(dwc->usb2_generic_phy); 1258 - if (ret < 0) 1259 - goto err_usb3phy_power; 1260 - 1261 - ret = phy_init(dwc->usb3_generic_phy); 1262 - if (ret < 0) 1263 - goto err_usb2phy_init; 1264 - 1265 - spin_lock_irqsave(&dwc->lock, flags); 1266 - 1267 - dwc3_event_buffers_setup(dwc); 1268 - dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl); 1269 - 1270 - switch (dwc->dr_mode) { 1271 - case USB_DR_MODE_PERIPHERAL: 1272 - case USB_DR_MODE_OTG: 1273 - dwc3_gadget_resume(dwc); 1274 - /* FALLTHROUGH */ 1275 - case USB_DR_MODE_HOST: 1276 - default: 1277 - /* do nothing */ 1278 - break; 1279 - } 1280 - 1281 - spin_unlock_irqrestore(&dwc->lock, flags); 1282 1159 1283 1160 pm_runtime_disable(dev); 1284 1161 pm_runtime_set_active(dev); 1285 1162 pm_runtime_enable(dev); 1286 1163 1287 1164 return 0; 1288 - 1289 - err_usb2phy_init: 1290 - phy_exit(dwc->usb2_generic_phy); 1291 - 1292 - err_usb3phy_power: 1293 - phy_power_off(dwc->usb3_generic_phy); 1294 - 1295 - err_usb2phy_power: 1296 - phy_power_off(dwc->usb2_generic_phy); 1297 - 1298 - return ret; 1299 1165 } 1166 + #endif /* CONFIG_PM_SLEEP */ 1300 1167 1301 1168 static const struct dev_pm_ops dwc3_dev_pm_ops = { 1302 1169 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) 1170 + SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume, 1171 + dwc3_runtime_idle) 1303 1172 }; 1304 - 1305 - #define DWC3_PM_OPS &(dwc3_dev_pm_ops) 1306 - #else 1307 - #define DWC3_PM_OPS NULL 1308 - #endif 1309 1173 1310 1174 #ifdef CONFIG_OF 1311 1175 static const struct of_device_id of_dwc3_match[] = { ··· 1290 1250 .name = "dwc3", 1291 1251 .of_match_table = of_match_ptr(of_dwc3_match), 1292 1252 .acpi_match_table = ACPI_PTR(dwc3_acpi_match), 1293 - .pm = DWC3_PM_OPS, 1253 + .pm = &dwc3_dev_pm_ops, 1294 1254 }, 1295 1255 }; 1296 1256
+46 -13
drivers/usb/dwc3/core.h
··· 86 86 #define DWC3_GCTL 0xc110 87 87 #define DWC3_GEVTEN 0xc114 88 88 #define DWC3_GSTS 0xc118 89 + #define DWC3_GUCTL1 0xc11c 89 90 #define DWC3_GSNPSID 0xc120 90 91 #define DWC3_GGPIO 0xc124 91 92 #define DWC3_GUID 0xc128 ··· 139 138 #define DWC3_DGCMDPAR 0xc710 140 139 #define DWC3_DGCMD 0xc714 141 140 #define DWC3_DALEPENA 0xc720 142 - #define DWC3_DEPCMDPAR2(n) (0xc800 + (n * 0x10)) 143 - #define DWC3_DEPCMDPAR1(n) (0xc804 + (n * 0x10)) 144 - #define DWC3_DEPCMDPAR0(n) (0xc808 + (n * 0x10)) 145 - #define DWC3_DEPCMD(n) (0xc80c + (n * 0x10)) 141 + 142 + #define DWC3_DEP_BASE(n) (0xc800 + (n * 0x10)) 143 + #define DWC3_DEPCMDPAR2 0x00 144 + #define DWC3_DEPCMDPAR1 0x04 145 + #define DWC3_DEPCMDPAR0 0x08 146 + #define DWC3_DEPCMD 0x0c 146 147 147 148 /* OTG Registers */ 148 149 #define DWC3_OCFG 0xcc00 ··· 234 231 #define DWC3_GEVNTSIZ_INTMASK (1 << 31) 235 232 #define DWC3_GEVNTSIZ_SIZE(n) ((n) & 0xffff) 236 233 234 + /* Global HWPARAMS0 Register */ 235 + #define DWC3_GHWPARAMS0_USB3_MODE(n) ((n) & 0x3) 236 + #define DWC3_GHWPARAMS0_MBUS_TYPE(n) (((n) >> 3) & 0x7) 237 + #define DWC3_GHWPARAMS0_SBUS_TYPE(n) (((n) >> 6) & 0x3) 238 + #define DWC3_GHWPARAMS0_MDWIDTH(n) (((n) >> 8) & 0xff) 239 + #define DWC3_GHWPARAMS0_SDWIDTH(n) (((n) >> 16) & 0xff) 240 + #define DWC3_GHWPARAMS0_AWIDTH(n) (((n) >> 24) & 0xff) 241 + 237 242 /* Global HWPARAMS1 Register */ 238 243 #define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24) 239 244 #define DWC3_GHWPARAMS1_EN_PWROPT_NO 0 ··· 270 259 271 260 /* Global HWPARAMS6 Register */ 272 261 #define DWC3_GHWPARAMS6_EN_FPGA (1 << 7) 262 + 263 + /* Global HWPARAMS7 Register */ 264 + #define DWC3_GHWPARAMS7_RAM1_DEPTH(n) ((n) & 0xffff) 265 + #define DWC3_GHWPARAMS7_RAM2_DEPTH(n) (((n) >> 16) & 0xffff) 273 266 274 267 /* Global Frame Length Adjustment Register */ 275 268 #define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7) ··· 483 468 * @endpoint: usb endpoint 484 469 * @pending_list: list of pending requests for this endpoint 485 470 * @started_list: list of started requests on this endpoint 471 + * @lock: spinlock for endpoint request queue traversal 472 + * @regs: pointer to first endpoint register 486 473 * @trb_pool: array of transaction buffers 487 474 * @trb_pool_dma: dma address of @trb_pool 488 475 * @trb_enqueue: enqueue 'pointer' into TRB array ··· 497 480 * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK 498 481 * @resource_index: Resource transfer index 499 482 * @interval: the interval on which the ISOC transfer is started 483 + * @allocated_requests: number of requests allocated 484 + * @queued_requests: number of requests queued for transfer 500 485 * @name: a human readable name e.g. ep1out-bulk 501 486 * @direction: true for TX, false for RX 502 487 * @stream_capable: true when streams are enabled ··· 507 488 struct usb_ep endpoint; 508 489 struct list_head pending_list; 509 490 struct list_head started_list; 491 + 492 + spinlock_t lock; 493 + void __iomem *regs; 510 494 511 495 struct dwc3_trb *trb_pool; 512 496 dma_addr_t trb_pool_dma; ··· 543 521 u8 number; 544 522 u8 type; 545 523 u8 resource_index; 524 + u32 allocated_requests; 525 + u32 queued_requests; 546 526 u32 interval; 547 527 548 528 char name[20]; ··· 736 712 * @gadget_driver: pointer to the gadget driver 737 713 * @regs: base address for our registers 738 714 * @regs_size: address space size 715 + * @fladj: frame length adjustment 716 + * @irq_gadget: peripheral controller's IRQ number 739 717 * @nr_scratch: number of scratch buffers 740 718 * @u1u2: only used on revisions <1.83a for workaround 741 719 * @maximum_speed: maximum speed requested (mainly for testing purposes) ··· 770 744 * @lpm_nyet_threshold: LPM NYET response threshold 771 745 * @hird_threshold: HIRD threshold 772 746 * @hsphy_interface: "utmi" or "ulpi" 747 + * @connected: true when we're connected to a host, false otherwise 773 748 * @delayed_status: true when gadget driver asks for delayed status 774 749 * @ep0_bounced: true when we used bounce buffer 775 750 * @ep0_expect_in: true when we expect a DATA IN transfer ··· 781 754 * 0 - utmi_sleep_n 782 755 * 1 - utmi_l1_suspend_n 783 756 * @is_fpga: true when we are using the FPGA board 757 + * @pending_events: true when we have pending IRQs to be handled 784 758 * @pullups_connected: true when Run/Stop bit is set 785 759 * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround 786 760 * @start_config_issued: true when StartConfig command has been issued ··· 846 818 847 819 enum usb_dr_mode dr_mode; 848 820 849 - /* used for suspend/resume */ 850 - u32 dcfg; 851 - u32 gctl; 852 - 821 + u32 fladj; 822 + u32 irq_gadget; 853 823 u32 nr_scratch; 854 824 u32 u1u2; 855 825 u32 maximum_speed; ··· 886 860 * just so dwc31 revisions are always larger than dwc3. 887 861 */ 888 862 #define DWC3_REVISION_IS_DWC31 0x80000000 889 - #define DWC3_USB31_REVISION_110A (0x3131302a | DWC3_REVISION_IS_USB31) 863 + #define DWC3_USB31_REVISION_110A (0x3131302a | DWC3_REVISION_IS_DWC31) 890 864 891 865 enum dwc3_ep0_next ep0_next_event; 892 866 enum dwc3_ep0_state ep0state; ··· 916 890 917 891 const char *hsphy_interface; 918 892 893 + unsigned connected:1; 919 894 unsigned delayed_status:1; 920 895 unsigned ep0_bounced:1; 921 896 unsigned ep0_expect_in:1; ··· 924 897 unsigned has_lpm_erratum:1; 925 898 unsigned is_utmi_l1_suspend:1; 926 899 unsigned is_fpga:1; 900 + unsigned pending_events:1; 927 901 unsigned pullups_connected:1; 928 902 unsigned setup_packet_pending:1; 929 903 unsigned three_stage_setup:1; ··· 1122 1094 int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode); 1123 1095 int dwc3_gadget_get_link_state(struct dwc3 *dwc); 1124 1096 int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); 1125 - int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 1126 - unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); 1097 + int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, 1098 + struct dwc3_gadget_ep_cmd_params *params); 1127 1099 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param); 1128 1100 #else 1129 1101 static inline int dwc3_gadget_init(struct dwc3 *dwc) ··· 1138 1110 enum dwc3_link_state state) 1139 1111 { return 0; } 1140 1112 1141 - static inline int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 1142 - unsigned cmd, struct dwc3_gadget_ep_cmd_params *params) 1113 + static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, 1114 + struct dwc3_gadget_ep_cmd_params *params) 1143 1115 { return 0; } 1144 1116 static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc, 1145 1117 int cmd, u32 param) ··· 1150 1122 #if !IS_ENABLED(CONFIG_USB_DWC3_HOST) 1151 1123 int dwc3_gadget_suspend(struct dwc3 *dwc); 1152 1124 int dwc3_gadget_resume(struct dwc3 *dwc); 1125 + void dwc3_gadget_process_pending_events(struct dwc3 *dwc); 1153 1126 #else 1154 1127 static inline int dwc3_gadget_suspend(struct dwc3 *dwc) 1155 1128 { ··· 1160 1131 static inline int dwc3_gadget_resume(struct dwc3 *dwc) 1161 1132 { 1162 1133 return 0; 1134 + } 1135 + 1136 + static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc) 1137 + { 1163 1138 } 1164 1139 #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */ 1165 1140
+118 -22
drivers/usb/dwc3/debug.h
··· 128 128 * dwc3_gadget_event_string - returns event name 129 129 * @event: the event code 130 130 */ 131 - static inline const char *dwc3_gadget_event_string(u8 event) 131 + static inline const char * 132 + dwc3_gadget_event_string(const struct dwc3_event_devt *event) 132 133 { 133 - switch (event) { 134 + static char str[256]; 135 + enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK; 136 + 137 + switch (event->type) { 134 138 case DWC3_DEVICE_EVENT_DISCONNECT: 135 - return "Disconnect"; 139 + sprintf(str, "Disconnect: [%s]", 140 + dwc3_gadget_link_string(state)); 141 + break; 136 142 case DWC3_DEVICE_EVENT_RESET: 137 - return "Reset"; 143 + sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state)); 144 + break; 138 145 case DWC3_DEVICE_EVENT_CONNECT_DONE: 139 - return "Connection Done"; 146 + sprintf(str, "Connection Done [%s]", 147 + dwc3_gadget_link_string(state)); 148 + break; 140 149 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: 141 - return "Link Status Change"; 150 + sprintf(str, "Link Change [%s]", 151 + dwc3_gadget_link_string(state)); 152 + break; 142 153 case DWC3_DEVICE_EVENT_WAKEUP: 143 - return "WakeUp"; 154 + sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state)); 155 + break; 144 156 case DWC3_DEVICE_EVENT_EOPF: 145 - return "End-Of-Frame"; 157 + sprintf(str, "End-Of-Frame [%s]", 158 + dwc3_gadget_link_string(state)); 159 + break; 146 160 case DWC3_DEVICE_EVENT_SOF: 147 - return "Start-Of-Frame"; 161 + sprintf(str, "Start-Of-Frame [%s]", 162 + dwc3_gadget_link_string(state)); 163 + break; 148 164 case DWC3_DEVICE_EVENT_ERRATIC_ERROR: 149 - return "Erratic Error"; 165 + sprintf(str, "Erratic Error [%s]", 166 + dwc3_gadget_link_string(state)); 167 + break; 150 168 case DWC3_DEVICE_EVENT_CMD_CMPL: 151 - return "Command Complete"; 169 + sprintf(str, "Command Complete [%s]", 170 + dwc3_gadget_link_string(state)); 171 + break; 152 172 case DWC3_DEVICE_EVENT_OVERFLOW: 153 - return "Overflow"; 173 + sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state)); 174 + break; 175 + default: 176 + sprintf(str, "UNKNOWN"); 154 177 } 155 178 156 - return "UNKNOWN"; 179 + return str; 157 180 } 158 181 159 182 /** 160 183 * dwc3_ep_event_string - returns event name 161 184 * @event: then event code 162 185 */ 163 - static inline const char *dwc3_ep_event_string(u8 event) 186 + static inline const char * 187 + dwc3_ep_event_string(const struct dwc3_event_depevt *event) 164 188 { 165 - switch (event) { 189 + u8 epnum = event->endpoint_number; 190 + static char str[256]; 191 + int status; 192 + int ret; 193 + 194 + ret = sprintf(str, "ep%d%s: ", epnum >> 1, 195 + (epnum & 1) ? "in" : "in"); 196 + if (ret < 0) 197 + return "UNKNOWN"; 198 + 199 + switch (event->endpoint_event) { 166 200 case DWC3_DEPEVT_XFERCOMPLETE: 167 - return "Transfer Complete"; 201 + strcat(str, "Transfer Complete"); 202 + break; 168 203 case DWC3_DEPEVT_XFERINPROGRESS: 169 - return "Transfer In-Progress"; 204 + strcat(str, "Transfer In-Progress"); 205 + break; 170 206 case DWC3_DEPEVT_XFERNOTREADY: 171 - return "Transfer Not Ready"; 207 + strcat(str, "Transfer Not Ready"); 208 + status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE; 209 + strcat(str, status ? " (Active)" : " (Not Active)"); 210 + break; 172 211 case DWC3_DEPEVT_RXTXFIFOEVT: 173 - return "FIFO"; 212 + strcat(str, "FIFO"); 213 + break; 174 214 case DWC3_DEPEVT_STREAMEVT: 175 - return "Stream"; 215 + status = event->status; 216 + 217 + switch (status) { 218 + case DEPEVT_STREAMEVT_FOUND: 219 + sprintf(str + ret, " Stream %d Found", 220 + event->parameters); 221 + break; 222 + case DEPEVT_STREAMEVT_NOTFOUND: 223 + default: 224 + strcat(str, " Stream Not Found"); 225 + break; 226 + } 227 + 228 + break; 176 229 case DWC3_DEPEVT_EPCMDCMPLT: 177 - return "Endpoint Command Complete"; 230 + strcat(str, "Endpoint Command Complete"); 231 + break; 232 + default: 233 + sprintf(str, "UNKNOWN"); 178 234 } 179 235 180 - return "UNKNOWN"; 236 + return str; 181 237 } 182 238 183 239 /** ··· 265 209 return "Command Complete"; 266 210 case DWC3_DEVICE_EVENT_OVERFLOW: 267 211 return "Overflow"; 212 + default: 213 + return "UNKNOWN"; 214 + } 215 + } 216 + 217 + static inline const char *dwc3_decode_event(u32 event) 218 + { 219 + const union dwc3_event evt = (union dwc3_event) event; 220 + 221 + if (evt.type.is_devspec) 222 + return dwc3_gadget_event_string(&evt.devt); 223 + else 224 + return dwc3_ep_event_string(&evt.depevt); 225 + } 226 + 227 + static inline const char *dwc3_ep_cmd_status_string(int status) 228 + { 229 + switch (status) { 230 + case -ETIMEDOUT: 231 + return "Timed Out"; 232 + case 0: 233 + return "Successful"; 234 + case DEPEVT_TRANSFER_NO_RESOURCE: 235 + return "No Resource"; 236 + case DEPEVT_TRANSFER_BUS_EXPIRY: 237 + return "Bus Expiry"; 238 + default: 239 + return "UNKNOWN"; 240 + } 241 + } 242 + 243 + static inline const char *dwc3_gadget_generic_cmd_status_string(int status) 244 + { 245 + switch (status) { 246 + case -ETIMEDOUT: 247 + return "Timed Out"; 248 + case 0: 249 + return "Successful"; 250 + case 1: 251 + return "Error"; 268 252 default: 269 253 return "UNKNOWN"; 270 254 }
+58 -133
drivers/usb/dwc3/debugfs.c
··· 36 36 #define dump_register(nm) \ 37 37 { \ 38 38 .name = __stringify(nm), \ 39 - .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \ 39 + .offset = DWC3_ ##nm, \ 40 40 } 41 + 42 + #define dump_ep_register_set(n) \ 43 + { \ 44 + .name = "DEPCMDPAR2("__stringify(n)")", \ 45 + .offset = DWC3_DEP_BASE(n) + \ 46 + DWC3_DEPCMDPAR2, \ 47 + }, \ 48 + { \ 49 + .name = "DEPCMDPAR1("__stringify(n)")", \ 50 + .offset = DWC3_DEP_BASE(n) + \ 51 + DWC3_DEPCMDPAR1, \ 52 + }, \ 53 + { \ 54 + .name = "DEPCMDPAR0("__stringify(n)")", \ 55 + .offset = DWC3_DEP_BASE(n) + \ 56 + DWC3_DEPCMDPAR0, \ 57 + }, \ 58 + { \ 59 + .name = "DEPCMD("__stringify(n)")", \ 60 + .offset = DWC3_DEP_BASE(n) + \ 61 + DWC3_DEPCMD, \ 62 + } 63 + 41 64 42 65 static const struct debugfs_reg32 dwc3_regs[] = { 43 66 dump_register(GSBUSCFG0), ··· 70 47 dump_register(GCTL), 71 48 dump_register(GEVTEN), 72 49 dump_register(GSTS), 50 + dump_register(GUCTL1), 73 51 dump_register(GSNPSID), 74 52 dump_register(GGPIO), 75 53 dump_register(GUID), ··· 242 218 dump_register(DGCMD), 243 219 dump_register(DALEPENA), 244 220 245 - dump_register(DEPCMDPAR2(0)), 246 - dump_register(DEPCMDPAR2(1)), 247 - dump_register(DEPCMDPAR2(2)), 248 - dump_register(DEPCMDPAR2(3)), 249 - dump_register(DEPCMDPAR2(4)), 250 - dump_register(DEPCMDPAR2(5)), 251 - dump_register(DEPCMDPAR2(6)), 252 - dump_register(DEPCMDPAR2(7)), 253 - dump_register(DEPCMDPAR2(8)), 254 - dump_register(DEPCMDPAR2(9)), 255 - dump_register(DEPCMDPAR2(10)), 256 - dump_register(DEPCMDPAR2(11)), 257 - dump_register(DEPCMDPAR2(12)), 258 - dump_register(DEPCMDPAR2(13)), 259 - dump_register(DEPCMDPAR2(14)), 260 - dump_register(DEPCMDPAR2(15)), 261 - dump_register(DEPCMDPAR2(16)), 262 - dump_register(DEPCMDPAR2(17)), 263 - dump_register(DEPCMDPAR2(18)), 264 - dump_register(DEPCMDPAR2(19)), 265 - dump_register(DEPCMDPAR2(20)), 266 - dump_register(DEPCMDPAR2(21)), 267 - dump_register(DEPCMDPAR2(22)), 268 - dump_register(DEPCMDPAR2(23)), 269 - dump_register(DEPCMDPAR2(24)), 270 - dump_register(DEPCMDPAR2(25)), 271 - dump_register(DEPCMDPAR2(26)), 272 - dump_register(DEPCMDPAR2(27)), 273 - dump_register(DEPCMDPAR2(28)), 274 - dump_register(DEPCMDPAR2(29)), 275 - dump_register(DEPCMDPAR2(30)), 276 - dump_register(DEPCMDPAR2(31)), 277 - 278 - dump_register(DEPCMDPAR1(0)), 279 - dump_register(DEPCMDPAR1(1)), 280 - dump_register(DEPCMDPAR1(2)), 281 - dump_register(DEPCMDPAR1(3)), 282 - dump_register(DEPCMDPAR1(4)), 283 - dump_register(DEPCMDPAR1(5)), 284 - dump_register(DEPCMDPAR1(6)), 285 - dump_register(DEPCMDPAR1(7)), 286 - dump_register(DEPCMDPAR1(8)), 287 - dump_register(DEPCMDPAR1(9)), 288 - dump_register(DEPCMDPAR1(10)), 289 - dump_register(DEPCMDPAR1(11)), 290 - dump_register(DEPCMDPAR1(12)), 291 - dump_register(DEPCMDPAR1(13)), 292 - dump_register(DEPCMDPAR1(14)), 293 - dump_register(DEPCMDPAR1(15)), 294 - dump_register(DEPCMDPAR1(16)), 295 - dump_register(DEPCMDPAR1(17)), 296 - dump_register(DEPCMDPAR1(18)), 297 - dump_register(DEPCMDPAR1(19)), 298 - dump_register(DEPCMDPAR1(20)), 299 - dump_register(DEPCMDPAR1(21)), 300 - dump_register(DEPCMDPAR1(22)), 301 - dump_register(DEPCMDPAR1(23)), 302 - dump_register(DEPCMDPAR1(24)), 303 - dump_register(DEPCMDPAR1(25)), 304 - dump_register(DEPCMDPAR1(26)), 305 - dump_register(DEPCMDPAR1(27)), 306 - dump_register(DEPCMDPAR1(28)), 307 - dump_register(DEPCMDPAR1(29)), 308 - dump_register(DEPCMDPAR1(30)), 309 - dump_register(DEPCMDPAR1(31)), 310 - 311 - dump_register(DEPCMDPAR0(0)), 312 - dump_register(DEPCMDPAR0(1)), 313 - dump_register(DEPCMDPAR0(2)), 314 - dump_register(DEPCMDPAR0(3)), 315 - dump_register(DEPCMDPAR0(4)), 316 - dump_register(DEPCMDPAR0(5)), 317 - dump_register(DEPCMDPAR0(6)), 318 - dump_register(DEPCMDPAR0(7)), 319 - dump_register(DEPCMDPAR0(8)), 320 - dump_register(DEPCMDPAR0(9)), 321 - dump_register(DEPCMDPAR0(10)), 322 - dump_register(DEPCMDPAR0(11)), 323 - dump_register(DEPCMDPAR0(12)), 324 - dump_register(DEPCMDPAR0(13)), 325 - dump_register(DEPCMDPAR0(14)), 326 - dump_register(DEPCMDPAR0(15)), 327 - dump_register(DEPCMDPAR0(16)), 328 - dump_register(DEPCMDPAR0(17)), 329 - dump_register(DEPCMDPAR0(18)), 330 - dump_register(DEPCMDPAR0(19)), 331 - dump_register(DEPCMDPAR0(20)), 332 - dump_register(DEPCMDPAR0(21)), 333 - dump_register(DEPCMDPAR0(22)), 334 - dump_register(DEPCMDPAR0(23)), 335 - dump_register(DEPCMDPAR0(24)), 336 - dump_register(DEPCMDPAR0(25)), 337 - dump_register(DEPCMDPAR0(26)), 338 - dump_register(DEPCMDPAR0(27)), 339 - dump_register(DEPCMDPAR0(28)), 340 - dump_register(DEPCMDPAR0(29)), 341 - dump_register(DEPCMDPAR0(30)), 342 - dump_register(DEPCMDPAR0(31)), 343 - 344 - dump_register(DEPCMD(0)), 345 - dump_register(DEPCMD(1)), 346 - dump_register(DEPCMD(2)), 347 - dump_register(DEPCMD(3)), 348 - dump_register(DEPCMD(4)), 349 - dump_register(DEPCMD(5)), 350 - dump_register(DEPCMD(6)), 351 - dump_register(DEPCMD(7)), 352 - dump_register(DEPCMD(8)), 353 - dump_register(DEPCMD(9)), 354 - dump_register(DEPCMD(10)), 355 - dump_register(DEPCMD(11)), 356 - dump_register(DEPCMD(12)), 357 - dump_register(DEPCMD(13)), 358 - dump_register(DEPCMD(14)), 359 - dump_register(DEPCMD(15)), 360 - dump_register(DEPCMD(16)), 361 - dump_register(DEPCMD(17)), 362 - dump_register(DEPCMD(18)), 363 - dump_register(DEPCMD(19)), 364 - dump_register(DEPCMD(20)), 365 - dump_register(DEPCMD(21)), 366 - dump_register(DEPCMD(22)), 367 - dump_register(DEPCMD(23)), 368 - dump_register(DEPCMD(24)), 369 - dump_register(DEPCMD(25)), 370 - dump_register(DEPCMD(26)), 371 - dump_register(DEPCMD(27)), 372 - dump_register(DEPCMD(28)), 373 - dump_register(DEPCMD(29)), 374 - dump_register(DEPCMD(30)), 375 - dump_register(DEPCMD(31)), 221 + dump_ep_register_set(0), 222 + dump_ep_register_set(1), 223 + dump_ep_register_set(2), 224 + dump_ep_register_set(3), 225 + dump_ep_register_set(4), 226 + dump_ep_register_set(5), 227 + dump_ep_register_set(6), 228 + dump_ep_register_set(7), 229 + dump_ep_register_set(8), 230 + dump_ep_register_set(9), 231 + dump_ep_register_set(10), 232 + dump_ep_register_set(11), 233 + dump_ep_register_set(12), 234 + dump_ep_register_set(13), 235 + dump_ep_register_set(14), 236 + dump_ep_register_set(15), 237 + dump_ep_register_set(16), 238 + dump_ep_register_set(17), 239 + dump_ep_register_set(18), 240 + dump_ep_register_set(19), 241 + dump_ep_register_set(20), 242 + dump_ep_register_set(21), 243 + dump_ep_register_set(22), 244 + dump_ep_register_set(23), 245 + dump_ep_register_set(24), 246 + dump_ep_register_set(25), 247 + dump_ep_register_set(26), 248 + dump_ep_register_set(27), 249 + dump_ep_register_set(28), 250 + dump_ep_register_set(29), 251 + dump_ep_register_set(30), 252 + dump_ep_register_set(31), 376 253 377 254 dump_register(OCFG), 378 255 dump_register(OCTL), ··· 864 939 865 940 dwc->regset->regs = dwc3_regs; 866 941 dwc->regset->nregs = ARRAY_SIZE(dwc3_regs); 867 - dwc->regset->base = dwc->regs; 942 + dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; 868 943 869 944 file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset); 870 945 if (!file)
+34 -19
drivers/usb/dwc3/dwc3-omap.c
··· 165 165 166 166 static u32 dwc3_omap_read_irq0_status(struct dwc3_omap *omap) 167 167 { 168 - return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0 - 168 + return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_RAW_0 - 169 169 omap->irq0_offset); 170 170 } 171 171 ··· 178 178 179 179 static u32 dwc3_omap_read_irqmisc_status(struct dwc3_omap *omap) 180 180 { 181 - return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_MISC + 181 + return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_RAW_MISC + 182 182 omap->irqmisc_offset); 183 183 } 184 184 ··· 231 231 } 232 232 233 233 val = dwc3_omap_read_utmi_ctrl(omap); 234 - val &= ~(USBOTGSS_UTMI_OTG_CTRL_IDDIG 235 - | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID 236 - | USBOTGSS_UTMI_OTG_CTRL_SESSEND); 237 - val |= USBOTGSS_UTMI_OTG_CTRL_SESSVALID 238 - | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT; 234 + val &= ~USBOTGSS_UTMI_OTG_CTRL_IDDIG; 239 235 dwc3_omap_write_utmi_ctrl(omap, val); 240 236 break; 241 237 242 238 case OMAP_DWC3_VBUS_VALID: 243 239 val = dwc3_omap_read_utmi_ctrl(omap); 244 240 val &= ~USBOTGSS_UTMI_OTG_CTRL_SESSEND; 245 - val |= USBOTGSS_UTMI_OTG_CTRL_IDDIG 246 - | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID 247 - | USBOTGSS_UTMI_OTG_CTRL_SESSVALID 248 - | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT; 241 + val |= USBOTGSS_UTMI_OTG_CTRL_VBUSVALID 242 + | USBOTGSS_UTMI_OTG_CTRL_SESSVALID; 249 243 dwc3_omap_write_utmi_ctrl(omap, val); 250 244 break; 251 245 252 246 case OMAP_DWC3_ID_FLOAT: 253 247 if (omap->vbus_reg) 254 248 regulator_disable(omap->vbus_reg); 249 + val = dwc3_omap_read_utmi_ctrl(omap); 250 + val |= USBOTGSS_UTMI_OTG_CTRL_IDDIG; 251 + dwc3_omap_write_utmi_ctrl(omap, val); 255 252 256 253 case OMAP_DWC3_VBUS_OFF: 257 254 val = dwc3_omap_read_utmi_ctrl(omap); 258 255 val &= ~(USBOTGSS_UTMI_OTG_CTRL_SESSVALID 259 - | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID 260 - | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT); 261 - val |= USBOTGSS_UTMI_OTG_CTRL_SESSEND 262 - | USBOTGSS_UTMI_OTG_CTRL_IDDIG; 256 + | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID); 257 + val |= USBOTGSS_UTMI_OTG_CTRL_SESSEND; 263 258 dwc3_omap_write_utmi_ctrl(omap, val); 264 259 break; 265 260 ··· 263 268 } 264 269 } 265 270 271 + static void dwc3_omap_enable_irqs(struct dwc3_omap *omap); 272 + static void dwc3_omap_disable_irqs(struct dwc3_omap *omap); 273 + 266 274 static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) 275 + { 276 + struct dwc3_omap *omap = _omap; 277 + 278 + if (dwc3_omap_read_irqmisc_status(omap) || 279 + dwc3_omap_read_irq0_status(omap)) { 280 + /* mask irqs */ 281 + dwc3_omap_disable_irqs(omap); 282 + return IRQ_WAKE_THREAD; 283 + } 284 + 285 + return IRQ_NONE; 286 + } 287 + 288 + static irqreturn_t dwc3_omap_interrupt_thread(int irq, void *_omap) 267 289 { 268 290 struct dwc3_omap *omap = _omap; 269 291 u32 reg; 270 292 293 + /* clear irq status flags */ 271 294 reg = dwc3_omap_read_irqmisc_status(omap); 272 - 273 295 dwc3_omap_write_irqmisc_status(omap, reg); 274 296 275 297 reg = dwc3_omap_read_irq0_status(omap); 276 - 277 298 dwc3_omap_write_irq0_status(omap, reg); 299 + 300 + /* unmask irqs */ 301 + dwc3_omap_enable_irqs(omap); 278 302 279 303 return IRQ_HANDLED; 280 304 } ··· 511 497 /* check the DMA Status */ 512 498 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); 513 499 514 - ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, 515 - "dwc3-omap", omap); 500 + ret = devm_request_threaded_irq(dev, omap->irq, dwc3_omap_interrupt, 501 + dwc3_omap_interrupt_thread, IRQF_SHARED, 502 + "dwc3-omap", omap); 516 503 if (ret) { 517 504 dev_err(dev, "failed to request IRQ #%d --> %d\n", 518 505 omap->irq, ret);
+101 -56
drivers/usb/dwc3/dwc3-pci.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/slab.h> 22 22 #include <linux/pci.h> 23 + #include <linux/pm_runtime.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/gpio/consumer.h> 25 26 #include <linux/acpi.h> 26 - 27 - #include "platform_data.h" 27 + #include <linux/delay.h> 28 28 29 29 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 30 30 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce ··· 51 51 { 52 52 if (pdev->vendor == PCI_VENDOR_ID_AMD && 53 53 pdev->device == PCI_DEVICE_ID_AMD_NL_USB) { 54 - struct dwc3_platform_data pdata; 54 + struct property_entry properties[] = { 55 + PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 56 + PROPERTY_ENTRY_U8("snps,lpm-nyet-threshold", 0xf), 57 + PROPERTY_ENTRY_BOOL("snps,u2exit_lfps_quirk"), 58 + PROPERTY_ENTRY_BOOL("snps,u2ss_inp3_quirk"), 59 + PROPERTY_ENTRY_BOOL("snps,req_p1p2p3_quirk"), 60 + PROPERTY_ENTRY_BOOL("snps,del_p1p2p3_quirk"), 61 + PROPERTY_ENTRY_BOOL("snps,del_phy_power_chg_quirk"), 62 + PROPERTY_ENTRY_BOOL("snps,lfps_filter_quirk"), 63 + PROPERTY_ENTRY_BOOL("snps,rx_detect_poll_quirk"), 64 + PROPERTY_ENTRY_BOOL("snps,tx_de_emphasis_quirk"), 65 + PROPERTY_ENTRY_U8("snps,tx_de_emphasis", 1), 66 + /* 67 + * FIXME these quirks should be removed when AMD NL 68 + * tapes out 69 + */ 70 + PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"), 71 + PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"), 72 + PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), 73 + { }, 74 + }; 55 75 56 - memset(&pdata, 0, sizeof(pdata)); 57 - 58 - pdata.has_lpm_erratum = true; 59 - pdata.lpm_nyet_threshold = 0xf; 60 - 61 - pdata.u2exit_lfps_quirk = true; 62 - pdata.u2ss_inp3_quirk = true; 63 - pdata.req_p1p2p3_quirk = true; 64 - pdata.del_p1p2p3_quirk = true; 65 - pdata.del_phy_power_chg_quirk = true; 66 - pdata.lfps_filter_quirk = true; 67 - pdata.rx_detect_poll_quirk = true; 68 - 69 - pdata.tx_de_emphasis_quirk = true; 70 - pdata.tx_de_emphasis = 1; 71 - 72 - /* 73 - * FIXME these quirks should be removed when AMD NL 74 - * taps out 75 - */ 76 - pdata.disable_scramble_quirk = true; 77 - pdata.dis_u3_susphy_quirk = true; 78 - pdata.dis_u2_susphy_quirk = true; 79 - 80 - return platform_device_add_data(dwc3, &pdata, sizeof(pdata)); 76 + return platform_device_add_properties(dwc3, properties); 81 77 } 82 78 83 - if (pdev->vendor == PCI_VENDOR_ID_INTEL && 84 - pdev->device == PCI_DEVICE_ID_INTEL_BYT) { 85 - struct gpio_desc *gpio; 79 + if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 80 + int ret; 86 81 87 - acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev), 88 - acpi_dwc3_byt_gpios); 82 + struct property_entry properties[] = { 83 + PROPERTY_ENTRY_STRING("dr-mode", "peripheral"), 84 + { } 85 + }; 89 86 90 - /* 91 - * These GPIOs will turn on the USB2 PHY. Note that we have to 92 - * put the gpio descriptors again here because the phy driver 93 - * might want to grab them, too. 94 - */ 95 - gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW); 96 - if (IS_ERR(gpio)) 97 - return PTR_ERR(gpio); 87 + ret = platform_device_add_properties(dwc3, properties); 88 + if (ret < 0) 89 + return ret; 98 90 99 - gpiod_set_value_cansleep(gpio, 1); 100 - gpiod_put(gpio); 91 + if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) { 92 + struct gpio_desc *gpio; 101 93 102 - gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); 103 - if (IS_ERR(gpio)) 104 - return PTR_ERR(gpio); 94 + acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev), 95 + acpi_dwc3_byt_gpios); 105 96 106 - if (gpio) { 97 + /* 98 + * These GPIOs will turn on the USB2 PHY. Note that we have to 99 + * put the gpio descriptors again here because the phy driver 100 + * might want to grab them, too. 101 + */ 102 + gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW); 103 + if (IS_ERR(gpio)) 104 + return PTR_ERR(gpio); 105 + 107 106 gpiod_set_value_cansleep(gpio, 1); 108 107 gpiod_put(gpio); 109 - usleep_range(10000, 11000); 108 + 109 + gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); 110 + if (IS_ERR(gpio)) 111 + return PTR_ERR(gpio); 112 + 113 + if (gpio) { 114 + gpiod_set_value_cansleep(gpio, 1); 115 + gpiod_put(gpio); 116 + usleep_range(10000, 11000); 117 + } 110 118 } 111 119 } 112 120 ··· 122 114 (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 || 123 115 pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI || 124 116 pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) { 117 + struct property_entry properties[] = { 118 + PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 119 + PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 120 + PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 121 + { }, 122 + }; 125 123 126 - struct dwc3_platform_data pdata; 127 - 128 - memset(&pdata, 0, sizeof(pdata)); 129 - pdata.usb3_lpm_capable = true; 130 - pdata.has_lpm_erratum = true; 131 - pdata.dis_enblslpm_quirk = true; 132 - 133 - return platform_device_add_data(dwc3, &pdata, sizeof(pdata)); 124 + return platform_device_add_properties(dwc3, properties); 134 125 } 135 126 136 127 return 0; ··· 187 180 goto err; 188 181 } 189 182 183 + device_init_wakeup(dev, true); 184 + device_set_run_wake(dev, true); 190 185 pci_set_drvdata(pci, dwc3); 186 + pm_runtime_put(dev); 187 + 191 188 return 0; 192 189 err: 193 190 platform_device_put(dwc3); ··· 200 189 201 190 static void dwc3_pci_remove(struct pci_dev *pci) 202 191 { 192 + device_init_wakeup(&pci->dev, false); 193 + pm_runtime_get(&pci->dev); 203 194 acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pci->dev)); 204 195 platform_device_unregister(pci_get_drvdata(pci)); 205 196 } ··· 232 219 }; 233 220 MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 234 221 222 + #ifdef CONFIG_PM 223 + static int dwc3_pci_runtime_suspend(struct device *dev) 224 + { 225 + if (device_run_wake(dev)) 226 + return 0; 227 + 228 + return -EBUSY; 229 + } 230 + 231 + static int dwc3_pci_pm_dummy(struct device *dev) 232 + { 233 + /* 234 + * There's nothing to do here. No, seriously. Everything is either taken 235 + * care either by PCI subsystem or dwc3/core.c, so we have nothing 236 + * missing here. 237 + * 238 + * So you'd think we didn't need this at all, but PCI subsystem will 239 + * bail out if we don't have a valid callback :-s 240 + */ 241 + return 0; 242 + } 243 + #endif /* CONFIG_PM */ 244 + 245 + static struct dev_pm_ops dwc3_pci_dev_pm_ops = { 246 + SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_pm_dummy, dwc3_pci_pm_dummy) 247 + SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_pm_dummy, 248 + NULL) 249 + }; 250 + 235 251 static struct pci_driver dwc3_pci_driver = { 236 252 .name = "dwc3-pci", 237 253 .id_table = dwc3_pci_id_table, 238 254 .probe = dwc3_pci_probe, 239 255 .remove = dwc3_pci_remove, 256 + .driver = { 257 + .pm = &dwc3_pci_dev_pm_ops, 258 + } 240 259 }; 241 260 242 261 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
+10 -16
drivers/usb/dwc3/ep0.c
··· 98 98 99 99 trace_dwc3_prepare_trb(dep, trb); 100 100 101 - ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 102 - DWC3_DEPCMD_STARTTRANSFER, &params); 101 + ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_STARTTRANSFER, &params); 103 102 if (ret < 0) { 104 103 dwc3_trace(trace_dwc3_ep0, "%s STARTTRANSFER failed", 105 104 dep->name); ··· 106 107 } 107 108 108 109 dep->flags |= DWC3_EP_BUSY; 109 - dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc, 110 - dep->number); 111 - 110 + dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep); 112 111 dwc->ep0_next_event = DWC3_EP0_COMPLETE; 113 112 114 113 return 0; ··· 496 499 case USB_RECIP_ENDPOINT: 497 500 switch (wValue) { 498 501 case USB_ENDPOINT_HALT: 499 - dep = dwc3_wIndex_to_dep(dwc, wIndex); 502 + dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); 500 503 if (!dep) 501 504 return -EINVAL; 502 505 if (set == 0 && (dep->flags & DWC3_EP_WEDGE)) ··· 619 622 struct timing { 620 623 u8 u1sel; 621 624 u8 u1pel; 622 - u16 u2sel; 623 - u16 u2pel; 625 + __le16 u2sel; 626 + __le16 u2pel; 624 627 } __packed timing; 625 628 626 629 int ret; ··· 977 980 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 978 981 dep->number); 979 982 if (ret) { 980 - dwc3_trace(trace_dwc3_ep0, "failed to map request\n"); 983 + dwc3_trace(trace_dwc3_ep0, "failed to map request"); 981 984 return; 982 985 } 983 986 ··· 1005 1008 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 1006 1009 dep->number); 1007 1010 if (ret) { 1008 - dwc3_trace(trace_dwc3_ep0, "failed to map request\n"); 1011 + dwc3_trace(trace_dwc3_ep0, "failed to map request"); 1009 1012 return; 1010 1013 } 1011 1014 ··· 1055 1058 cmd |= DWC3_DEPCMD_CMDIOC; 1056 1059 cmd |= DWC3_DEPCMD_PARAM(dep->resource_index); 1057 1060 memset(&params, 0, sizeof(params)); 1058 - ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 1061 + ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 1059 1062 WARN_ON_ONCE(ret); 1060 1063 dep->resource_index = 0; 1061 1064 } ··· 1109 1112 void dwc3_ep0_interrupt(struct dwc3 *dwc, 1110 1113 const struct dwc3_event_depevt *event) 1111 1114 { 1112 - u8 epnum = event->endpoint_number; 1113 - 1114 - dwc3_trace(trace_dwc3_ep0, "%s while ep%d%s in state '%s'", 1115 - dwc3_ep_event_string(event->endpoint_event), 1116 - epnum >> 1, (epnum & 1) ? "in" : "out", 1115 + dwc3_trace(trace_dwc3_ep0, "%s: state '%s'", 1116 + dwc3_ep_event_string(event), 1117 1117 dwc3_ep0_state_string(dwc->ep0state)); 1118 1118 1119 1119 switch (event->endpoint_event) {
+504 -373
drivers/usb/dwc3/gadget.c
··· 145 145 return -ETIMEDOUT; 146 146 } 147 147 148 + /** 149 + * dwc3_ep_inc_trb() - Increment a TRB index. 150 + * @index - Pointer to the TRB index to increment. 151 + * 152 + * The index should never point to the link TRB. After incrementing, 153 + * if it is point to the link TRB, wrap around to the beginning. The 154 + * link TRB is always at the last TRB entry. 155 + */ 156 + static void dwc3_ep_inc_trb(u8 *index) 157 + { 158 + (*index)++; 159 + if (*index == (DWC3_TRB_NUM - 1)) 160 + *index = 0; 161 + } 162 + 148 163 static void dwc3_ep_inc_enq(struct dwc3_ep *dep) 149 164 { 150 - dep->trb_enqueue++; 151 - dep->trb_enqueue %= DWC3_TRB_NUM; 165 + dwc3_ep_inc_trb(&dep->trb_enqueue); 152 166 } 153 167 154 168 static void dwc3_ep_inc_deq(struct dwc3_ep *dep) 155 169 { 156 - dep->trb_dequeue++; 157 - dep->trb_dequeue %= DWC3_TRB_NUM; 158 - } 159 - 160 - static int dwc3_ep_is_last_trb(unsigned int index) 161 - { 162 - return index == DWC3_TRB_NUM - 1; 170 + dwc3_ep_inc_trb(&dep->trb_dequeue); 163 171 } 164 172 165 173 void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, ··· 180 172 i = 0; 181 173 do { 182 174 dwc3_ep_inc_deq(dep); 183 - /* 184 - * Skip LINK TRB. We can't use req->trb and check for 185 - * DWC3_TRBCTL_LINK_TRB because it points the TRB we 186 - * just completed (not the LINK TRB). 187 - */ 188 - if (dwc3_ep_is_last_trb(dep->trb_dequeue)) 189 - dwc3_ep_inc_deq(dep); 190 175 } while(++i < req->request.num_mapped_sgs); 191 176 req->started = false; 192 177 } ··· 200 199 spin_unlock(&dwc->lock); 201 200 usb_gadget_giveback_request(&dep->endpoint, &req->request); 202 201 spin_lock(&dwc->lock); 202 + 203 + if (dep->number > 1) 204 + pm_runtime_put(dwc->dev); 203 205 } 204 206 205 207 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param) 206 208 { 207 209 u32 timeout = 500; 210 + int status = 0; 211 + int ret = 0; 208 212 u32 reg; 209 - 210 - trace_dwc3_gadget_generic_cmd(cmd, param); 211 213 212 214 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); 213 215 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); ··· 218 214 do { 219 215 reg = dwc3_readl(dwc->regs, DWC3_DGCMD); 220 216 if (!(reg & DWC3_DGCMD_CMDACT)) { 221 - dwc3_trace(trace_dwc3_gadget, 222 - "Command Complete --> %d", 223 - DWC3_DGCMD_STATUS(reg)); 224 - if (DWC3_DGCMD_STATUS(reg)) 225 - return -EINVAL; 226 - return 0; 217 + status = DWC3_DGCMD_STATUS(reg); 218 + if (status) 219 + ret = -EINVAL; 220 + break; 227 221 } 222 + } while (timeout--); 228 223 229 - /* 230 - * We can't sleep here, because it's also called from 231 - * interrupt context. 232 - */ 233 - timeout--; 234 - if (!timeout) { 235 - dwc3_trace(trace_dwc3_gadget, 236 - "Command Timed Out"); 237 - return -ETIMEDOUT; 238 - } 239 - udelay(1); 240 - } while (1); 224 + if (!timeout) { 225 + ret = -ETIMEDOUT; 226 + status = -ETIMEDOUT; 227 + } 228 + 229 + trace_dwc3_gadget_generic_cmd(cmd, param, status); 230 + 231 + return ret; 241 232 } 242 233 243 234 static int __dwc3_gadget_wakeup(struct dwc3 *dwc); 244 235 245 - int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 246 - unsigned cmd, struct dwc3_gadget_ep_cmd_params *params) 236 + int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, 237 + struct dwc3_gadget_ep_cmd_params *params) 247 238 { 248 - struct dwc3_ep *dep = dwc->eps[ep]; 239 + struct dwc3 *dwc = dep->dwc; 249 240 u32 timeout = 500; 250 241 u32 reg; 251 242 243 + int cmd_status = 0; 252 244 int susphy = false; 253 245 int ret = -EINVAL; 254 - 255 - trace_dwc3_gadget_ep_cmd(dep, cmd, params); 256 246 257 247 /* 258 248 * Synopsys Databook 2.60a states, on section 6.3.2.5.[1-8], that if ··· 256 258 * We will also set SUSPHY bit to what it was before returning as stated 257 259 * by the same section on Synopsys databook. 258 260 */ 259 - reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 260 - if (unlikely(reg & DWC3_GUSB2PHYCFG_SUSPHY)) { 261 - susphy = true; 262 - reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; 263 - dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 261 + if (dwc->gadget.speed <= USB_SPEED_HIGH) { 262 + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 263 + if (unlikely(reg & DWC3_GUSB2PHYCFG_SUSPHY)) { 264 + susphy = true; 265 + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; 266 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 267 + } 264 268 } 265 269 266 270 if (cmd == DWC3_DEPCMD_STARTTRANSFER) { ··· 279 279 } 280 280 } 281 281 282 - dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); 283 - dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1); 284 - dwc3_writel(dwc->regs, DWC3_DEPCMDPAR2(ep), params->param2); 282 + dwc3_writel(dep->regs, DWC3_DEPCMDPAR0, params->param0); 283 + dwc3_writel(dep->regs, DWC3_DEPCMDPAR1, params->param1); 284 + dwc3_writel(dep->regs, DWC3_DEPCMDPAR2, params->param2); 285 285 286 - dwc3_writel(dwc->regs, DWC3_DEPCMD(ep), cmd | DWC3_DEPCMD_CMDACT); 286 + dwc3_writel(dep->regs, DWC3_DEPCMD, cmd | DWC3_DEPCMD_CMDACT); 287 287 do { 288 - reg = dwc3_readl(dwc->regs, DWC3_DEPCMD(ep)); 288 + reg = dwc3_readl(dep->regs, DWC3_DEPCMD); 289 289 if (!(reg & DWC3_DEPCMD_CMDACT)) { 290 - int cmd_status = DWC3_DEPCMD_STATUS(reg); 291 - 292 - dwc3_trace(trace_dwc3_gadget, 293 - "Command Complete --> %d", 294 - cmd_status); 290 + cmd_status = DWC3_DEPCMD_STATUS(reg); 295 291 296 292 switch (cmd_status) { 297 293 case 0: 298 294 ret = 0; 299 295 break; 300 296 case DEPEVT_TRANSFER_NO_RESOURCE: 301 - dwc3_trace(trace_dwc3_gadget, "%s: no resource available"); 302 297 ret = -EINVAL; 303 298 break; 304 299 case DEPEVT_TRANSFER_BUS_EXPIRY: ··· 308 313 * give a hint to the gadget driver that this is 309 314 * the case by returning -EAGAIN. 310 315 */ 311 - dwc3_trace(trace_dwc3_gadget, "%s: bus expiry"); 312 316 ret = -EAGAIN; 313 317 break; 314 318 default: ··· 316 322 317 323 break; 318 324 } 325 + } while (--timeout); 319 326 320 - /* 321 - * We can't sleep here, because it is also called from 322 - * interrupt context. 323 - */ 324 - timeout--; 325 - if (!timeout) { 326 - dwc3_trace(trace_dwc3_gadget, 327 - "Command Timed Out"); 328 - ret = -ETIMEDOUT; 329 - break; 330 - } 327 + if (timeout == 0) { 328 + ret = -ETIMEDOUT; 329 + cmd_status = -ETIMEDOUT; 330 + } 331 331 332 - udelay(1); 333 - } while (1); 332 + trace_dwc3_gadget_ep_cmd(dep, cmd, params, cmd_status); 334 333 335 334 if (unlikely(susphy)) { 336 335 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); ··· 353 366 354 367 memset(&params, 0, sizeof(params)); 355 368 356 - return dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 369 + return dwc3_send_gadget_ep_cmd(dep, cmd, &params); 357 370 } 358 371 359 372 static dma_addr_t dwc3_trb_dma_offset(struct dwc3_ep *dep, ··· 441 454 memset(&params, 0x00, sizeof(params)); 442 455 cmd = DWC3_DEPCMD_DEPSTARTCFG; 443 456 444 - ret = dwc3_send_gadget_ep_cmd(dwc, 0, cmd, &params); 457 + ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 445 458 if (ret) 446 459 return ret; 447 460 ··· 462 475 static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep, 463 476 const struct usb_endpoint_descriptor *desc, 464 477 const struct usb_ss_ep_comp_descriptor *comp_desc, 465 - bool ignore, bool restore) 478 + bool modify, bool restore) 466 479 { 467 480 struct dwc3_gadget_ep_cmd_params params; 481 + 482 + if (dev_WARN_ONCE(dwc->dev, modify && restore, 483 + "Can't modify and restore\n")) 484 + return -EINVAL; 468 485 469 486 memset(&params, 0x00, sizeof(params)); 470 487 ··· 478 487 /* Burst size is only needed in SuperSpeed mode */ 479 488 if (dwc->gadget.speed >= USB_SPEED_SUPER) { 480 489 u32 burst = dep->endpoint.maxburst; 481 - u32 nump; 482 - u32 reg; 483 - 484 - /* update NumP */ 485 - reg = dwc3_readl(dwc->regs, DWC3_DCFG); 486 - nump = DWC3_DCFG_NUMP(reg); 487 - nump = max(nump, burst); 488 - reg &= ~DWC3_DCFG_NUMP_MASK; 489 - reg |= nump << DWC3_DCFG_NUMP_SHIFT; 490 - dwc3_writel(dwc->regs, DWC3_DCFG, reg); 491 - 492 490 params.param0 |= DWC3_DEPCFG_BURST_SIZE(burst - 1); 493 491 } 494 492 495 - if (ignore) 496 - params.param0 |= DWC3_DEPCFG_IGN_SEQ_NUM; 497 - 498 - if (restore) { 493 + if (modify) { 494 + params.param0 |= DWC3_DEPCFG_ACTION_MODIFY; 495 + } else if (restore) { 499 496 params.param0 |= DWC3_DEPCFG_ACTION_RESTORE; 500 497 params.param2 |= dep->saved_state; 498 + } else { 499 + params.param0 |= DWC3_DEPCFG_ACTION_INIT; 501 500 } 502 501 503 - params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN 504 - | DWC3_DEPCFG_XFER_NOT_READY_EN; 502 + params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN; 503 + 504 + if (dep->number <= 1 || usb_endpoint_xfer_isoc(desc)) 505 + params.param1 |= DWC3_DEPCFG_XFER_NOT_READY_EN; 505 506 506 507 if (usb_ss_max_streams(comp_desc) && usb_endpoint_xfer_bulk(desc)) { 507 508 params.param1 |= DWC3_DEPCFG_STREAM_CAPABLE ··· 524 541 dep->interval = 1 << (desc->bInterval - 1); 525 542 } 526 543 527 - return dwc3_send_gadget_ep_cmd(dwc, dep->number, 528 - DWC3_DEPCMD_SETEPCONFIG, &params); 544 + return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, &params); 529 545 } 530 546 531 547 static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, struct dwc3_ep *dep) ··· 535 553 536 554 params.param0 = DWC3_DEPXFERCFG_NUM_XFER_RES(1); 537 555 538 - return dwc3_send_gadget_ep_cmd(dwc, dep->number, 539 - DWC3_DEPCMD_SETTRANSFRESOURCE, &params); 556 + return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETTRANSFRESOURCE, 557 + &params); 540 558 } 541 559 542 560 /** ··· 549 567 static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, 550 568 const struct usb_endpoint_descriptor *desc, 551 569 const struct usb_ss_ep_comp_descriptor *comp_desc, 552 - bool ignore, bool restore) 570 + bool modify, bool restore) 553 571 { 554 572 struct dwc3 *dwc = dep->dwc; 555 573 u32 reg; ··· 563 581 return ret; 564 582 } 565 583 566 - ret = dwc3_gadget_set_ep_config(dwc, dep, desc, comp_desc, ignore, 584 + ret = dwc3_gadget_set_ep_config(dwc, dep, desc, comp_desc, modify, 567 585 restore); 568 586 if (ret) 569 587 return ret; ··· 582 600 dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); 583 601 584 602 if (usb_endpoint_xfer_control(desc)) 585 - goto out; 603 + return 0; 604 + 605 + /* Initialize the TRB ring */ 606 + dep->trb_dequeue = 0; 607 + dep->trb_enqueue = 0; 608 + memset(dep->trb_pool, 0, 609 + sizeof(struct dwc3_trb) * DWC3_TRB_NUM); 586 610 587 611 /* Link TRB. The HWO bit is never reset */ 588 612 trb_st_hw = &dep->trb_pool[0]; 589 613 590 614 trb_link = &dep->trb_pool[DWC3_TRB_NUM - 1]; 591 - memset(trb_link, 0, sizeof(*trb_link)); 592 - 593 615 trb_link->bpl = lower_32_bits(dwc3_trb_dma_offset(dep, trb_st_hw)); 594 616 trb_link->bph = upper_32_bits(dwc3_trb_dma_offset(dep, trb_st_hw)); 595 617 trb_link->ctrl |= DWC3_TRBCTL_LINK_TRB; 596 618 trb_link->ctrl |= DWC3_TRB_CTRL_HWO; 597 - } 598 - 599 - out: 600 - switch (usb_endpoint_type(desc)) { 601 - case USB_ENDPOINT_XFER_CONTROL: 602 - /* don't change name */ 603 - break; 604 - case USB_ENDPOINT_XFER_ISOC: 605 - strlcat(dep->name, "-isoc", sizeof(dep->name)); 606 - break; 607 - case USB_ENDPOINT_XFER_BULK: 608 - strlcat(dep->name, "-bulk", sizeof(dep->name)); 609 - break; 610 - case USB_ENDPOINT_XFER_INT: 611 - strlcat(dep->name, "-int", sizeof(dep->name)); 612 - break; 613 - default: 614 - dev_err(dwc->dev, "invalid endpoint transfer type\n"); 615 619 } 616 620 617 621 return 0; ··· 608 640 { 609 641 struct dwc3_request *req; 610 642 611 - if (!list_empty(&dep->started_list)) { 612 - dwc3_stop_active_transfer(dwc, dep->number, true); 643 + dwc3_stop_active_transfer(dwc, dep->number, true); 613 644 614 - /* - giveback all requests to gadget driver */ 615 - while (!list_empty(&dep->started_list)) { 616 - req = next_request(&dep->started_list); 645 + /* - giveback all requests to gadget driver */ 646 + while (!list_empty(&dep->started_list)) { 647 + req = next_request(&dep->started_list); 617 648 618 - dwc3_gadget_giveback(dep, req, -ESHUTDOWN); 619 - } 649 + dwc3_gadget_giveback(dep, req, -ESHUTDOWN); 620 650 } 621 651 622 652 while (!list_empty(&dep->pending_list)) { ··· 654 688 dep->comp_desc = NULL; 655 689 dep->type = 0; 656 690 dep->flags = 0; 657 - 658 - snprintf(dep->name, sizeof(dep->name), "ep%d%s", 659 - dep->number >> 1, 660 - (dep->number & 1) ? "in" : "out"); 661 691 662 692 return 0; 663 693 } ··· 746 784 req->epnum = dep->number; 747 785 req->dep = dep; 748 786 787 + dep->allocated_requests++; 788 + 749 789 trace_dwc3_alloc_request(req); 750 790 751 791 return &req->request; ··· 757 793 struct usb_request *request) 758 794 { 759 795 struct dwc3_request *req = to_dwc3_request(request); 796 + struct dwc3_ep *dep = to_dwc3_ep(ep); 760 797 798 + dep->allocated_requests--; 761 799 trace_dwc3_free_request(req); 762 800 kfree(req); 763 801 } ··· 791 825 } 792 826 793 827 dwc3_ep_inc_enq(dep); 794 - /* Skip the LINK-TRB */ 795 - if (dwc3_ep_is_last_trb(dep->trb_enqueue)) 796 - dwc3_ep_inc_enq(dep); 797 828 798 829 trb->size = DWC3_TRB_SIZE_LENGTH(length); 799 830 trb->bpl = lower_32_bits(dma); ··· 840 877 841 878 trb->ctrl |= DWC3_TRB_CTRL_HWO; 842 879 880 + dep->queued_requests++; 881 + 843 882 trace_dwc3_prepare_trb(dep, trb); 883 + } 884 + 885 + /** 886 + * dwc3_ep_prev_trb() - Returns the previous TRB in the ring 887 + * @dep: The endpoint with the TRB ring 888 + * @index: The index of the current TRB in the ring 889 + * 890 + * Returns the TRB prior to the one pointed to by the index. If the 891 + * index is 0, we will wrap backwards, skip the link TRB, and return 892 + * the one just before that. 893 + */ 894 + static struct dwc3_trb *dwc3_ep_prev_trb(struct dwc3_ep *dep, u8 index) 895 + { 896 + if (!index) 897 + index = DWC3_TRB_NUM - 2; 898 + else 899 + index = dep->trb_enqueue - 1; 900 + 901 + return &dep->trb_pool[index]; 902 + } 903 + 904 + static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep) 905 + { 906 + struct dwc3_trb *tmp; 907 + u8 trbs_left; 908 + 909 + /* 910 + * If enqueue & dequeue are equal than it is either full or empty. 911 + * 912 + * One way to know for sure is if the TRB right before us has HWO bit 913 + * set or not. If it has, then we're definitely full and can't fit any 914 + * more transfers in our ring. 915 + */ 916 + if (dep->trb_enqueue == dep->trb_dequeue) { 917 + tmp = dwc3_ep_prev_trb(dep, dep->trb_enqueue); 918 + if (tmp->ctrl & DWC3_TRB_CTRL_HWO) 919 + return 0; 920 + 921 + return DWC3_TRB_NUM - 1; 922 + } 923 + 924 + trbs_left = dep->trb_dequeue - dep->trb_enqueue; 925 + trbs_left &= (DWC3_TRB_NUM - 1); 926 + 927 + if (dep->trb_dequeue < dep->trb_enqueue) 928 + trbs_left--; 929 + 930 + return trbs_left; 931 + } 932 + 933 + static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, 934 + struct dwc3_request *req, unsigned int trbs_left, 935 + unsigned int more_coming) 936 + { 937 + struct usb_request *request = &req->request; 938 + struct scatterlist *sg = request->sg; 939 + struct scatterlist *s; 940 + unsigned int last = false; 941 + unsigned int length; 942 + dma_addr_t dma; 943 + int i; 944 + 945 + for_each_sg(sg, s, request->num_mapped_sgs, i) { 946 + unsigned chain = true; 947 + 948 + length = sg_dma_len(s); 949 + dma = sg_dma_address(s); 950 + 951 + if (sg_is_last(s)) { 952 + if (usb_endpoint_xfer_int(dep->endpoint.desc) || 953 + !more_coming) 954 + last = true; 955 + 956 + chain = false; 957 + } 958 + 959 + if (!trbs_left--) 960 + last = true; 961 + 962 + if (last) 963 + chain = false; 964 + 965 + dwc3_prepare_one_trb(dep, req, dma, length, 966 + last, chain, i); 967 + 968 + if (last) 969 + break; 970 + } 971 + } 972 + 973 + static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, 974 + struct dwc3_request *req, unsigned int trbs_left, 975 + unsigned int more_coming) 976 + { 977 + unsigned int last = false; 978 + unsigned int length; 979 + dma_addr_t dma; 980 + 981 + dma = req->request.dma; 982 + length = req->request.length; 983 + 984 + if (!trbs_left) 985 + last = true; 986 + 987 + /* Is this the last request? */ 988 + if (usb_endpoint_xfer_int(dep->endpoint.desc) || !more_coming) 989 + last = true; 990 + 991 + dwc3_prepare_one_trb(dep, req, dma, length, 992 + last, false, 0); 844 993 } 845 994 846 995 /* 847 996 * dwc3_prepare_trbs - setup TRBs from requests 848 997 * @dep: endpoint for which requests are being prepared 849 - * @starting: true if the endpoint is idle and no requests are queued. 850 998 * 851 999 * The function goes through the requests list and sets up TRBs for the 852 1000 * transfers. The function returns once there are no more TRBs available or 853 1001 * it runs out of requests. 854 1002 */ 855 - static void dwc3_prepare_trbs(struct dwc3_ep *dep, bool starting) 1003 + static void dwc3_prepare_trbs(struct dwc3_ep *dep) 856 1004 { 857 1005 struct dwc3_request *req, *n; 1006 + unsigned int more_coming; 858 1007 u32 trbs_left; 859 - unsigned int last_one = 0; 860 1008 861 1009 BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM); 862 1010 863 - trbs_left = dep->trb_dequeue - dep->trb_enqueue; 864 - 865 - /* 866 - * If enqueue & dequeue are equal than it is either full or empty. If we 867 - * are starting to process requests then we are empty. Otherwise we are 868 - * full and don't do anything 869 - */ 870 - if (!trbs_left) { 871 - if (!starting) 872 - return; 873 - 874 - trbs_left = DWC3_TRB_NUM; 875 - } 876 - 877 - /* The last TRB is a link TRB, not used for xfer */ 878 - if (trbs_left <= 1) 1011 + trbs_left = dwc3_calc_trbs_left(dep); 1012 + if (!trbs_left) 879 1013 return; 880 1014 1015 + more_coming = dep->allocated_requests - dep->queued_requests; 1016 + 881 1017 list_for_each_entry_safe(req, n, &dep->pending_list, list) { 882 - unsigned length; 883 - dma_addr_t dma; 884 - last_one = false; 1018 + if (req->request.num_mapped_sgs > 0) 1019 + dwc3_prepare_one_trb_sg(dep, req, trbs_left--, 1020 + more_coming); 1021 + else 1022 + dwc3_prepare_one_trb_linear(dep, req, trbs_left--, 1023 + more_coming); 885 1024 886 - if (req->request.num_mapped_sgs > 0) { 887 - struct usb_request *request = &req->request; 888 - struct scatterlist *sg = request->sg; 889 - struct scatterlist *s; 890 - int i; 891 - 892 - for_each_sg(sg, s, request->num_mapped_sgs, i) { 893 - unsigned chain = true; 894 - 895 - length = sg_dma_len(s); 896 - dma = sg_dma_address(s); 897 - 898 - if (i == (request->num_mapped_sgs - 1) || 899 - sg_is_last(s)) { 900 - if (list_empty(&dep->pending_list)) 901 - last_one = true; 902 - chain = false; 903 - } 904 - 905 - trbs_left--; 906 - if (!trbs_left) 907 - last_one = true; 908 - 909 - if (last_one) 910 - chain = false; 911 - 912 - dwc3_prepare_one_trb(dep, req, dma, length, 913 - last_one, chain, i); 914 - 915 - if (last_one) 916 - break; 917 - } 918 - 919 - if (last_one) 920 - break; 921 - } else { 922 - dma = req->request.dma; 923 - length = req->request.length; 924 - trbs_left--; 925 - 926 - if (!trbs_left) 927 - last_one = 1; 928 - 929 - /* Is this the last request? */ 930 - if (list_is_last(&req->list, &dep->pending_list)) 931 - last_one = 1; 932 - 933 - dwc3_prepare_one_trb(dep, req, dma, length, 934 - last_one, false, 0); 935 - 936 - if (last_one) 937 - break; 938 - } 1025 + if (!trbs_left) 1026 + return; 939 1027 } 940 1028 } 941 1029 942 - static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param, 943 - int start_new) 1030 + static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param) 944 1031 { 945 1032 struct dwc3_gadget_ep_cmd_params params; 946 1033 struct dwc3_request *req; 947 1034 struct dwc3 *dwc = dep->dwc; 1035 + int starting; 948 1036 int ret; 949 1037 u32 cmd; 950 1038 951 - if (start_new && (dep->flags & DWC3_EP_BUSY)) { 952 - dwc3_trace(trace_dwc3_gadget, "%s: endpoint busy", dep->name); 953 - return -EBUSY; 954 - } 1039 + starting = !(dep->flags & DWC3_EP_BUSY); 955 1040 956 - /* 957 - * If we are getting here after a short-out-packet we don't enqueue any 958 - * new requests as we try to set the IOC bit only on the last request. 959 - */ 960 - if (start_new) { 961 - if (list_empty(&dep->started_list)) 962 - dwc3_prepare_trbs(dep, start_new); 963 - 964 - /* req points to the first request which will be sent */ 965 - req = next_request(&dep->started_list); 966 - } else { 967 - dwc3_prepare_trbs(dep, start_new); 968 - 969 - /* 970 - * req points to the first request where HWO changed from 0 to 1 971 - */ 972 - req = next_request(&dep->started_list); 973 - } 1041 + dwc3_prepare_trbs(dep); 1042 + req = next_request(&dep->started_list); 974 1043 if (!req) { 975 1044 dep->flags |= DWC3_EP_PENDING_REQUEST; 976 1045 return 0; ··· 1010 1015 1011 1016 memset(&params, 0, sizeof(params)); 1012 1017 1013 - if (start_new) { 1018 + if (starting) { 1014 1019 params.param0 = upper_32_bits(req->trb_dma); 1015 1020 params.param1 = lower_32_bits(req->trb_dma); 1016 - cmd = DWC3_DEPCMD_STARTTRANSFER; 1021 + cmd = DWC3_DEPCMD_STARTTRANSFER | 1022 + DWC3_DEPCMD_PARAM(cmd_param); 1017 1023 } else { 1018 - cmd = DWC3_DEPCMD_UPDATETRANSFER; 1024 + cmd = DWC3_DEPCMD_UPDATETRANSFER | 1025 + DWC3_DEPCMD_PARAM(dep->resource_index); 1019 1026 } 1020 1027 1021 - cmd |= DWC3_DEPCMD_PARAM(cmd_param); 1022 - ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 1028 + ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 1023 1029 if (ret < 0) { 1024 1030 /* 1025 1031 * FIXME we need to iterate over the list of requests ··· 1035 1039 1036 1040 dep->flags |= DWC3_EP_BUSY; 1037 1041 1038 - if (start_new) { 1039 - dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc, 1040 - dep->number); 1042 + if (starting) { 1043 + dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep); 1041 1044 WARN_ON_ONCE(!dep->resource_index); 1042 1045 } 1043 1046 ··· 1059 1064 /* 4 micro frames in the future */ 1060 1065 uf = cur_uf + dep->interval * 4; 1061 1066 1062 - __dwc3_gadget_kick_transfer(dep, uf, 1); 1067 + __dwc3_gadget_kick_transfer(dep, uf); 1063 1068 } 1064 1069 1065 1070 static void dwc3_gadget_start_isoc(struct dwc3 *dwc, ··· 1080 1085 1081 1086 if (!dep->endpoint.desc) { 1082 1087 dwc3_trace(trace_dwc3_gadget, 1083 - "trying to queue request %p to disabled %s\n", 1088 + "trying to queue request %p to disabled %s", 1084 1089 &req->request, dep->endpoint.name); 1085 1090 return -ESHUTDOWN; 1086 1091 } 1087 1092 1088 1093 if (WARN(req->dep != dep, "request %p belongs to '%s'\n", 1089 1094 &req->request, req->dep->name)) { 1090 - dwc3_trace(trace_dwc3_gadget, "request %p belongs to '%s'\n", 1095 + dwc3_trace(trace_dwc3_gadget, "request %p belongs to '%s'", 1091 1096 &req->request, req->dep->name); 1092 1097 return -EINVAL; 1093 1098 } 1099 + 1100 + pm_runtime_get(dwc->dev); 1094 1101 1095 1102 req->request.actual = 0; 1096 1103 req->request.status = -EINPROGRESS; ··· 1128 1131 * little bit faster. 1129 1132 */ 1130 1133 if (!usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1131 - !usb_endpoint_xfer_int(dep->endpoint.desc) && 1132 - !(dep->flags & DWC3_EP_BUSY)) { 1133 - ret = __dwc3_gadget_kick_transfer(dep, 0, true); 1134 + !usb_endpoint_xfer_int(dep->endpoint.desc)) { 1135 + ret = __dwc3_gadget_kick_transfer(dep, 0); 1134 1136 goto out; 1135 1137 } 1136 1138 ··· 1159 1163 return 0; 1160 1164 } 1161 1165 1162 - ret = __dwc3_gadget_kick_transfer(dep, 0, true); 1166 + ret = __dwc3_gadget_kick_transfer(dep, 0); 1163 1167 if (!ret) 1164 1168 dep->flags &= ~DWC3_EP_PENDING_REQUEST; 1165 1169 ··· 1175 1179 (dep->flags & DWC3_EP_BUSY) && 1176 1180 !(dep->flags & DWC3_EP_MISSED_ISOC)) { 1177 1181 WARN_ON_ONCE(!dep->resource_index); 1178 - ret = __dwc3_gadget_kick_transfer(dep, dep->resource_index, 1179 - false); 1182 + ret = __dwc3_gadget_kick_transfer(dep, dep->resource_index); 1180 1183 goto out; 1181 1184 } 1182 1185 ··· 1185 1190 * handled. 1186 1191 */ 1187 1192 if (dep->stream_capable) 1188 - ret = __dwc3_gadget_kick_transfer(dep, 0, true); 1193 + ret = __dwc3_gadget_kick_transfer(dep, 0); 1189 1194 1190 1195 out: 1191 1196 if (ret && ret != -EBUSY) 1192 1197 dwc3_trace(trace_dwc3_gadget, 1193 - "%s: failed to kick transfers\n", 1198 + "%s: failed to kick transfers", 1194 1199 dep->name); 1195 1200 if (ret == -EBUSY) 1196 1201 ret = 0; ··· 1210 1215 struct usb_request *request; 1211 1216 struct usb_ep *ep = &dep->endpoint; 1212 1217 1213 - dwc3_trace(trace_dwc3_gadget, "queueing ZLP\n"); 1218 + dwc3_trace(trace_dwc3_gadget, "queueing ZLP"); 1214 1219 request = dwc3_gadget_ep_alloc_request(ep, GFP_ATOMIC); 1215 1220 if (!request) 1216 1221 return -ENOMEM; ··· 1314 1319 memset(&params, 0x00, sizeof(params)); 1315 1320 1316 1321 if (value) { 1317 - if (!protocol && ((dep->direction && dep->flags & DWC3_EP_BUSY) || 1318 - (!list_empty(&dep->started_list) || 1319 - !list_empty(&dep->pending_list)))) { 1322 + struct dwc3_trb *trb; 1323 + 1324 + unsigned transfer_in_flight; 1325 + unsigned started; 1326 + 1327 + if (dep->number > 1) 1328 + trb = dwc3_ep_prev_trb(dep, dep->trb_enqueue); 1329 + else 1330 + trb = &dwc->ep0_trb[dep->trb_enqueue]; 1331 + 1332 + transfer_in_flight = trb->ctrl & DWC3_TRB_CTRL_HWO; 1333 + started = !list_empty(&dep->started_list); 1334 + 1335 + if (!protocol && ((dep->direction && transfer_in_flight) || 1336 + (!dep->direction && started))) { 1320 1337 dwc3_trace(trace_dwc3_gadget, 1321 1338 "%s: pending request, cannot halt", 1322 1339 dep->name); 1323 1340 return -EAGAIN; 1324 1341 } 1325 1342 1326 - ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 1327 - DWC3_DEPCMD_SETSTALL, &params); 1343 + ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETSTALL, 1344 + &params); 1328 1345 if (ret) 1329 1346 dev_err(dwc->dev, "failed to set STALL on %s\n", 1330 1347 dep->name); 1331 1348 else 1332 1349 dep->flags |= DWC3_EP_STALL; 1333 1350 } else { 1351 + 1334 1352 ret = dwc3_send_clear_stall_ep_cmd(dep); 1335 1353 if (ret) 1336 1354 dev_err(dwc->dev, "failed to clear STALL on %s\n", ··· 1452 1444 speed = reg & DWC3_DSTS_CONNECTSPD; 1453 1445 if ((speed == DWC3_DSTS_SUPERSPEED) || 1454 1446 (speed == DWC3_DSTS_SUPERSPEED_PLUS)) { 1455 - dwc3_trace(trace_dwc3_gadget, "no wakeup on SuperSpeed\n"); 1456 - return -EINVAL; 1447 + dwc3_trace(trace_dwc3_gadget, "no wakeup on SuperSpeed"); 1448 + return 0; 1457 1449 } 1458 1450 1459 1451 link_state = DWC3_DSTS_USBLNKST(reg); ··· 1464 1456 break; 1465 1457 default: 1466 1458 dwc3_trace(trace_dwc3_gadget, 1467 - "can't wakeup from '%s'\n", 1459 + "can't wakeup from '%s'", 1468 1460 dwc3_gadget_link_string(link_state)); 1469 1461 return -EINVAL; 1470 1462 } ··· 1533 1525 u32 reg; 1534 1526 u32 timeout = 500; 1535 1527 1528 + if (pm_runtime_suspended(dwc->dev)) 1529 + return 0; 1530 + 1536 1531 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1537 1532 if (is_on) { 1538 1533 if (dwc->revision <= DWC3_REVISION_187A) { ··· 1564 1553 1565 1554 do { 1566 1555 reg = dwc3_readl(dwc->regs, DWC3_DSTS); 1567 - if (is_on) { 1568 - if (!(reg & DWC3_DSTS_DEVCTRLHLT)) 1569 - break; 1570 - } else { 1571 - if (reg & DWC3_DSTS_DEVCTRLHLT) 1572 - break; 1573 - } 1574 - timeout--; 1575 - if (!timeout) 1576 - return -ETIMEDOUT; 1577 - udelay(1); 1578 - } while (1); 1556 + reg &= DWC3_DSTS_DEVCTRLHLT; 1557 + } while (--timeout && !(!is_on ^ !reg)); 1558 + 1559 + if (!timeout) 1560 + return -ETIMEDOUT; 1579 1561 1580 1562 dwc3_trace(trace_dwc3_gadget, "gadget %s data soft-%s", 1581 1563 dwc->gadget_driver ··· 1620 1616 static irqreturn_t dwc3_interrupt(int irq, void *_dwc); 1621 1617 static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc); 1622 1618 1623 - static int dwc3_gadget_start(struct usb_gadget *g, 1624 - struct usb_gadget_driver *driver) 1619 + /** 1620 + * dwc3_gadget_setup_nump - Calculate and initialize NUMP field of DCFG 1621 + * dwc: pointer to our context structure 1622 + * 1623 + * The following looks like complex but it's actually very simple. In order to 1624 + * calculate the number of packets we can burst at once on OUT transfers, we're 1625 + * gonna use RxFIFO size. 1626 + * 1627 + * To calculate RxFIFO size we need two numbers: 1628 + * MDWIDTH = size, in bits, of the internal memory bus 1629 + * RAM2_DEPTH = depth, in MDWIDTH, of internal RAM2 (where RxFIFO sits) 1630 + * 1631 + * Given these two numbers, the formula is simple: 1632 + * 1633 + * RxFIFO Size = (RAM2_DEPTH * MDWIDTH / 8) - 24 - 16; 1634 + * 1635 + * 24 bytes is for 3x SETUP packets 1636 + * 16 bytes is a clock domain crossing tolerance 1637 + * 1638 + * Given RxFIFO Size, NUMP = RxFIFOSize / 1024; 1639 + */ 1640 + static void dwc3_gadget_setup_nump(struct dwc3 *dwc) 1625 1641 { 1626 - struct dwc3 *dwc = gadget_to_dwc(g); 1642 + u32 ram2_depth; 1643 + u32 mdwidth; 1644 + u32 nump; 1645 + u32 reg; 1646 + 1647 + ram2_depth = DWC3_GHWPARAMS7_RAM2_DEPTH(dwc->hwparams.hwparams7); 1648 + mdwidth = DWC3_GHWPARAMS0_MDWIDTH(dwc->hwparams.hwparams0); 1649 + 1650 + nump = ((ram2_depth * mdwidth / 8) - 24 - 16) / 1024; 1651 + nump = min_t(u32, nump, 16); 1652 + 1653 + /* update NumP */ 1654 + reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1655 + reg &= ~DWC3_DCFG_NUMP_MASK; 1656 + reg |= nump << DWC3_DCFG_NUMP_SHIFT; 1657 + dwc3_writel(dwc->regs, DWC3_DCFG, reg); 1658 + } 1659 + 1660 + static int __dwc3_gadget_start(struct dwc3 *dwc) 1661 + { 1627 1662 struct dwc3_ep *dep; 1628 - unsigned long flags; 1629 1663 int ret = 0; 1630 - int irq; 1631 1664 u32 reg; 1632 - 1633 - irq = platform_get_irq(to_platform_device(dwc->dev), 0); 1634 - ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt, 1635 - IRQF_SHARED, "dwc3", dwc->ev_buf); 1636 - if (ret) { 1637 - dev_err(dwc->dev, "failed to request irq #%d --> %d\n", 1638 - irq, ret); 1639 - goto err0; 1640 - } 1641 - 1642 - spin_lock_irqsave(&dwc->lock, flags); 1643 - 1644 - if (dwc->gadget_driver) { 1645 - dev_err(dwc->dev, "%s is already bound to %s\n", 1646 - dwc->gadget.name, 1647 - dwc->gadget_driver->driver.name); 1648 - ret = -EBUSY; 1649 - goto err1; 1650 - } 1651 - 1652 - dwc->gadget_driver = driver; 1653 1665 1654 1666 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1655 1667 reg &= ~(DWC3_DCFG_SPEED_MASK); ··· 1688 1668 } else { 1689 1669 switch (dwc->maximum_speed) { 1690 1670 case USB_SPEED_LOW: 1691 - reg |= DWC3_DSTS_LOWSPEED; 1671 + reg |= DWC3_DCFG_LOWSPEED; 1692 1672 break; 1693 1673 case USB_SPEED_FULL: 1694 - reg |= DWC3_DSTS_FULLSPEED1; 1674 + reg |= DWC3_DCFG_FULLSPEED1; 1695 1675 break; 1696 1676 case USB_SPEED_HIGH: 1697 - reg |= DWC3_DSTS_HIGHSPEED; 1677 + reg |= DWC3_DCFG_HIGHSPEED; 1698 1678 break; 1699 1679 case USB_SPEED_SUPER_PLUS: 1700 - reg |= DWC3_DSTS_SUPERSPEED_PLUS; 1680 + reg |= DWC3_DCFG_SUPERSPEED_PLUS; 1701 1681 break; 1702 1682 default: 1703 1683 dev_err(dwc->dev, "invalid dwc->maximum_speed (%d)\n", ··· 1721 1701 reg &= ~DWC3_GRXTHRCFG_PKTCNTSEL; 1722 1702 dwc3_writel(dwc->regs, DWC3_GRXTHRCFG, reg); 1723 1703 1704 + dwc3_gadget_setup_nump(dwc); 1705 + 1724 1706 /* Start with SuperSpeed Default */ 1725 1707 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 1726 1708 ··· 1731 1709 false); 1732 1710 if (ret) { 1733 1711 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1734 - goto err2; 1712 + goto err0; 1735 1713 } 1736 1714 1737 1715 dep = dwc->eps[1]; ··· 1739 1717 false); 1740 1718 if (ret) { 1741 1719 dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1742 - goto err3; 1720 + goto err1; 1743 1721 } 1744 1722 1745 1723 /* begin to receive SETUP packets */ ··· 1748 1726 1749 1727 dwc3_gadget_enable_irq(dwc); 1750 1728 1729 + return 0; 1730 + 1731 + err1: 1732 + __dwc3_gadget_ep_disable(dwc->eps[0]); 1733 + 1734 + err0: 1735 + return ret; 1736 + } 1737 + 1738 + static int dwc3_gadget_start(struct usb_gadget *g, 1739 + struct usb_gadget_driver *driver) 1740 + { 1741 + struct dwc3 *dwc = gadget_to_dwc(g); 1742 + unsigned long flags; 1743 + int ret = 0; 1744 + int irq; 1745 + 1746 + irq = dwc->irq_gadget; 1747 + ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt, 1748 + IRQF_SHARED, "dwc3", dwc->ev_buf); 1749 + if (ret) { 1750 + dev_err(dwc->dev, "failed to request irq #%d --> %d\n", 1751 + irq, ret); 1752 + goto err0; 1753 + } 1754 + 1755 + spin_lock_irqsave(&dwc->lock, flags); 1756 + if (dwc->gadget_driver) { 1757 + dev_err(dwc->dev, "%s is already bound to %s\n", 1758 + dwc->gadget.name, 1759 + dwc->gadget_driver->driver.name); 1760 + ret = -EBUSY; 1761 + goto err1; 1762 + } 1763 + 1764 + dwc->gadget_driver = driver; 1765 + 1766 + if (pm_runtime_active(dwc->dev)) 1767 + __dwc3_gadget_start(dwc); 1768 + 1751 1769 spin_unlock_irqrestore(&dwc->lock, flags); 1752 1770 1753 1771 return 0; 1754 1772 1755 - err3: 1756 - __dwc3_gadget_ep_disable(dwc->eps[0]); 1757 - 1758 - err2: 1759 - dwc->gadget_driver = NULL; 1760 - 1761 1773 err1: 1762 1774 spin_unlock_irqrestore(&dwc->lock, flags); 1763 - 1764 - free_irq(irq, dwc->ev_buf); 1775 + free_irq(irq, dwc); 1765 1776 1766 1777 err0: 1767 1778 return ret; 1779 + } 1780 + 1781 + static void __dwc3_gadget_stop(struct dwc3 *dwc) 1782 + { 1783 + if (pm_runtime_suspended(dwc->dev)) 1784 + return; 1785 + 1786 + dwc3_gadget_disable_irq(dwc); 1787 + __dwc3_gadget_ep_disable(dwc->eps[0]); 1788 + __dwc3_gadget_ep_disable(dwc->eps[1]); 1768 1789 } 1769 1790 1770 1791 static int dwc3_gadget_stop(struct usb_gadget *g) 1771 1792 { 1772 1793 struct dwc3 *dwc = gadget_to_dwc(g); 1773 1794 unsigned long flags; 1774 - int irq; 1775 1795 1776 1796 spin_lock_irqsave(&dwc->lock, flags); 1777 - 1778 - dwc3_gadget_disable_irq(dwc); 1779 - __dwc3_gadget_ep_disable(dwc->eps[0]); 1780 - __dwc3_gadget_ep_disable(dwc->eps[1]); 1781 - 1797 + __dwc3_gadget_stop(dwc); 1782 1798 dwc->gadget_driver = NULL; 1783 - 1784 1799 spin_unlock_irqrestore(&dwc->lock, flags); 1785 1800 1786 - irq = platform_get_irq(to_platform_device(dwc->dev), 0); 1787 - free_irq(irq, dwc->ev_buf); 1801 + free_irq(dwc->irq_gadget, dwc->ev_buf); 1788 1802 1789 1803 return 0; 1790 1804 } ··· 1843 1785 u8 i; 1844 1786 1845 1787 for (i = 0; i < num; i++) { 1846 - u8 epnum = (i << 1) | (!!direction); 1788 + u8 epnum = (i << 1) | (direction ? 1 : 0); 1847 1789 1848 1790 dep = kzalloc(sizeof(*dep), GFP_KERNEL); 1849 1791 if (!dep) ··· 1852 1794 dep->dwc = dwc; 1853 1795 dep->number = epnum; 1854 1796 dep->direction = !!direction; 1797 + dep->regs = dwc->regs + DWC3_DEP_BASE(epnum); 1855 1798 dwc->eps[epnum] = dep; 1856 1799 1857 1800 snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, 1858 1801 (epnum & 1) ? "in" : "out"); 1859 1802 1860 1803 dep->endpoint.name = dep->name; 1804 + spin_lock_init(&dep->lock); 1861 1805 1862 1806 dwc3_trace(trace_dwc3_gadget, "initializing %s", dep->name); 1863 1807 ··· 1961 1901 unsigned int s_pkt = 0; 1962 1902 unsigned int trb_status; 1963 1903 1904 + dep->queued_requests--; 1964 1905 trace_dwc3_complete_trb(dep, trb); 1965 1906 1966 1907 if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) ··· 1982 1921 trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size); 1983 1922 if (trb_status == DWC3_TRBSTS_MISSED_ISOC) { 1984 1923 dwc3_trace(trace_dwc3_gadget, 1985 - "%s: incomplete IN transfer\n", 1924 + "%s: incomplete IN transfer", 1986 1925 dep->name); 1987 1926 /* 1988 1927 * If missed isoc occurred and there is ··· 2067 2006 break; 2068 2007 } while (1); 2069 2008 2009 + /* 2010 + * Our endpoint might get disabled by another thread during 2011 + * dwc3_gadget_giveback(). If that happens, we're just gonna return 1 2012 + * early on so DWC3_EP_BUSY flag gets cleared 2013 + */ 2014 + if (!dep->endpoint.desc) 2015 + return 1; 2016 + 2070 2017 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 2071 2018 list_empty(&dep->started_list)) { 2072 2019 if (list_empty(&dep->pending_list)) { ··· 2092 2023 return 1; 2093 2024 } 2094 2025 2026 + if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) 2027 + if ((event->status & DEPEVT_STATUS_IOC) && 2028 + (trb->ctrl & DWC3_TRB_CTRL_IOC)) 2029 + return 0; 2095 2030 return 1; 2096 2031 } 2097 2032 ··· 2112 2039 status = -ECONNRESET; 2113 2040 2114 2041 clean_busy = dwc3_cleanup_done_reqs(dwc, dep, event, status); 2115 - if (clean_busy && (is_xfer_complete || 2042 + if (clean_busy && (!dep->endpoint.desc || is_xfer_complete || 2116 2043 usb_endpoint_xfer_isoc(dep->endpoint.desc))) 2117 2044 dep->flags &= ~DWC3_EP_BUSY; 2118 2045 ··· 2141 2068 dwc->u1u2 = 0; 2142 2069 } 2143 2070 2071 + /* 2072 + * Our endpoint might get disabled by another thread during 2073 + * dwc3_gadget_giveback(). If that happens, we're just gonna return 1 2074 + * early on so DWC3_EP_BUSY flag gets cleared 2075 + */ 2076 + if (!dep->endpoint.desc) 2077 + return; 2078 + 2144 2079 if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 2145 2080 int ret; 2146 2081 2147 - ret = __dwc3_gadget_kick_transfer(dep, 0, is_xfer_complete); 2082 + ret = __dwc3_gadget_kick_transfer(dep, 0); 2148 2083 if (!ret || ret == -EBUSY) 2149 2084 return; 2150 2085 } ··· 2180 2099 2181 2100 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 2182 2101 dwc3_trace(trace_dwc3_gadget, 2183 - "%s is an Isochronous endpoint\n", 2102 + "%s is an Isochronous endpoint", 2184 2103 dep->name); 2185 2104 return; 2186 2105 } ··· 2203 2122 dep->name, active ? "Transfer Active" 2204 2123 : "Transfer Not Active"); 2205 2124 2206 - ret = __dwc3_gadget_kick_transfer(dep, 0, !active); 2125 + ret = __dwc3_gadget_kick_transfer(dep, 0); 2207 2126 if (!ret || ret == -EBUSY) 2208 2127 return; 2209 2128 2210 2129 dwc3_trace(trace_dwc3_gadget, 2211 - "%s: failed to kick transfers\n", 2130 + "%s: failed to kick transfers", 2212 2131 dep->name); 2213 2132 } 2214 2133 ··· 2231 2150 /* FALLTHROUGH */ 2232 2151 default: 2233 2152 dwc3_trace(trace_dwc3_gadget, 2234 - "unable to find suitable stream\n"); 2153 + "unable to find suitable stream"); 2235 2154 } 2236 2155 break; 2237 2156 case DWC3_DEPEVT_RXTXFIFOEVT: 2238 - dwc3_trace(trace_dwc3_gadget, "%s FIFO Overrun\n", dep->name); 2157 + dwc3_trace(trace_dwc3_gadget, "%s FIFO Overrun", dep->name); 2239 2158 break; 2240 2159 case DWC3_DEPEVT_EPCMDCMPLT: 2241 2160 dwc3_trace(trace_dwc3_gadget, "Endpoint Command Complete"); ··· 2318 2237 cmd |= DWC3_DEPCMD_CMDIOC; 2319 2238 cmd |= DWC3_DEPCMD_PARAM(dep->resource_index); 2320 2239 memset(&params, 0, sizeof(params)); 2321 - ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 2240 + ret = dwc3_send_gadget_ep_cmd(dep, cmd, &params); 2322 2241 WARN_ON_ONCE(ret); 2323 2242 dep->resource_index = 0; 2324 2243 dep->flags &= ~DWC3_EP_BUSY; ··· 2381 2300 dwc->gadget.speed = USB_SPEED_UNKNOWN; 2382 2301 dwc->setup_packet_pending = false; 2383 2302 usb_gadget_set_state(&dwc->gadget, USB_STATE_NOTATTACHED); 2303 + 2304 + dwc->connected = false; 2384 2305 } 2385 2306 2386 2307 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) 2387 2308 { 2388 2309 u32 reg; 2310 + 2311 + dwc->connected = true; 2389 2312 2390 2313 /* 2391 2314 * WORKAROUND: DWC3 revisions <1.88a have an issue which ··· 2478 2393 dwc3_update_ram_clk_sel(dwc, speed); 2479 2394 2480 2395 switch (speed) { 2481 - case DWC3_DCFG_SUPERSPEED_PLUS: 2396 + case DWC3_DSTS_SUPERSPEED_PLUS: 2482 2397 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 2483 2398 dwc->gadget.ep0->maxpacket = 512; 2484 2399 dwc->gadget.speed = USB_SPEED_SUPER_PLUS; 2485 2400 break; 2486 - case DWC3_DCFG_SUPERSPEED: 2401 + case DWC3_DSTS_SUPERSPEED: 2487 2402 /* 2488 2403 * WORKAROUND: DWC3 revisions <1.90a have an issue which 2489 2404 * would cause a missing USB3 Reset event. ··· 2504 2419 dwc->gadget.ep0->maxpacket = 512; 2505 2420 dwc->gadget.speed = USB_SPEED_SUPER; 2506 2421 break; 2507 - case DWC3_DCFG_HIGHSPEED: 2422 + case DWC3_DSTS_HIGHSPEED: 2508 2423 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 2509 2424 dwc->gadget.ep0->maxpacket = 64; 2510 2425 dwc->gadget.speed = USB_SPEED_HIGH; 2511 2426 break; 2512 - case DWC3_DCFG_FULLSPEED2: 2513 - case DWC3_DCFG_FULLSPEED1: 2427 + case DWC3_DSTS_FULLSPEED2: 2428 + case DWC3_DSTS_FULLSPEED1: 2514 2429 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 2515 2430 dwc->gadget.ep0->maxpacket = 64; 2516 2431 dwc->gadget.speed = USB_SPEED_FULL; 2517 2432 break; 2518 - case DWC3_DCFG_LOWSPEED: 2433 + case DWC3_DSTS_LOWSPEED: 2519 2434 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(8); 2520 2435 dwc->gadget.ep0->maxpacket = 8; 2521 2436 dwc->gadget.speed = USB_SPEED_LOW; ··· 2525 2440 /* Enable USB2 LPM Capability */ 2526 2441 2527 2442 if ((dwc->revision > DWC3_REVISION_194A) && 2528 - (speed != DWC3_DCFG_SUPERSPEED) && 2529 - (speed != DWC3_DCFG_SUPERSPEED_PLUS)) { 2443 + (speed != DWC3_DSTS_SUPERSPEED) && 2444 + (speed != DWC3_DSTS_SUPERSPEED_PLUS)) { 2530 2445 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 2531 2446 reg |= DWC3_DCFG_LPM_CAP; 2532 2447 dwc3_writel(dwc->regs, DWC3_DCFG, reg); ··· 2695 2610 dwc->link_state = next; 2696 2611 } 2697 2612 2613 + static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, 2614 + unsigned int evtinfo) 2615 + { 2616 + enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK; 2617 + 2618 + if (dwc->link_state != next && next == DWC3_LINK_STATE_U3) 2619 + dwc3_suspend_gadget(dwc); 2620 + 2621 + dwc->link_state = next; 2622 + } 2623 + 2698 2624 static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc, 2699 2625 unsigned int evtinfo) 2700 2626 { ··· 2757 2661 dwc3_gadget_linksts_change_interrupt(dwc, event->event_info); 2758 2662 break; 2759 2663 case DWC3_DEVICE_EVENT_EOPF: 2760 - dwc3_trace(trace_dwc3_gadget, "End of Periodic Frame"); 2664 + /* It changed to be suspend event for version 2.30a and above */ 2665 + if (dwc->revision < DWC3_REVISION_230A) { 2666 + dwc3_trace(trace_dwc3_gadget, "End of Periodic Frame"); 2667 + } else { 2668 + dwc3_trace(trace_dwc3_gadget, "U3/L1-L2 Suspend Event"); 2669 + 2670 + /* 2671 + * Ignore suspend event until the gadget enters into 2672 + * USB_STATE_CONFIGURED state. 2673 + */ 2674 + if (dwc->gadget.state >= USB_STATE_CONFIGURED) 2675 + dwc3_gadget_suspend_interrupt(dwc, 2676 + event->event_info); 2677 + } 2761 2678 break; 2762 2679 case DWC3_DEVICE_EVENT_SOF: 2763 2680 dwc3_trace(trace_dwc3_gadget, "Start of Periodic Frame"); ··· 2876 2767 u32 count; 2877 2768 u32 reg; 2878 2769 2770 + if (pm_runtime_suspended(dwc->dev)) { 2771 + pm_runtime_get(dwc->dev); 2772 + disable_irq_nosync(dwc->irq_gadget); 2773 + dwc->pending_events = true; 2774 + return IRQ_HANDLED; 2775 + } 2776 + 2879 2777 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); 2880 2778 count &= DWC3_GEVNTCOUNT_MASK; 2881 2779 if (!count) ··· 2914 2798 */ 2915 2799 int dwc3_gadget_init(struct dwc3 *dwc) 2916 2800 { 2917 - int ret; 2801 + int ret, irq; 2802 + struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); 2803 + 2804 + irq = platform_get_irq_byname(dwc3_pdev, "peripheral"); 2805 + if (irq == -EPROBE_DEFER) 2806 + return irq; 2807 + 2808 + if (irq <= 0) { 2809 + irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3"); 2810 + if (irq == -EPROBE_DEFER) 2811 + return irq; 2812 + 2813 + if (irq <= 0) { 2814 + irq = platform_get_irq(dwc3_pdev, 0); 2815 + if (irq <= 0) { 2816 + if (irq != -EPROBE_DEFER) { 2817 + dev_err(dwc->dev, 2818 + "missing peripheral IRQ\n"); 2819 + } 2820 + if (!irq) 2821 + irq = -EINVAL; 2822 + return irq; 2823 + } 2824 + } 2825 + } 2826 + 2827 + dwc->irq_gadget = irq; 2918 2828 2919 2829 dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2920 2830 &dwc->ctrl_req_addr, GFP_KERNEL); ··· 3003 2861 */ 3004 2862 if (dwc->revision < DWC3_REVISION_220A) 3005 2863 dwc3_trace(trace_dwc3_gadget, 3006 - "Changing max_speed on rev %08x\n", 2864 + "Changing max_speed on rev %08x", 3007 2865 dwc->revision); 3008 2866 3009 2867 dwc->gadget.max_speed = dwc->maximum_speed; ··· 3077 2935 3078 2936 int dwc3_gadget_suspend(struct dwc3 *dwc) 3079 2937 { 2938 + int ret; 2939 + 3080 2940 if (!dwc->gadget_driver) 3081 2941 return 0; 3082 2942 3083 - if (dwc->pullups_connected) { 3084 - dwc3_gadget_disable_irq(dwc); 3085 - dwc3_gadget_run_stop(dwc, true, true); 3086 - } 2943 + ret = dwc3_gadget_run_stop(dwc, false, false); 2944 + if (ret < 0) 2945 + return ret; 3087 2946 3088 - __dwc3_gadget_ep_disable(dwc->eps[0]); 3089 - __dwc3_gadget_ep_disable(dwc->eps[1]); 3090 - 3091 - dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG); 2947 + dwc3_disconnect_gadget(dwc); 2948 + __dwc3_gadget_stop(dwc); 3092 2949 3093 2950 return 0; 3094 2951 } 3095 2952 3096 2953 int dwc3_gadget_resume(struct dwc3 *dwc) 3097 2954 { 3098 - struct dwc3_ep *dep; 3099 2955 int ret; 3100 2956 3101 2957 if (!dwc->gadget_driver) 3102 2958 return 0; 3103 2959 3104 - /* Start with SuperSpeed Default */ 3105 - dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 3106 - 3107 - dep = dwc->eps[0]; 3108 - ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false, 3109 - false); 3110 - if (ret) 2960 + ret = __dwc3_gadget_start(dwc); 2961 + if (ret < 0) 3111 2962 goto err0; 3112 2963 3113 - dep = dwc->eps[1]; 3114 - ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false, 3115 - false); 3116 - if (ret) 2964 + ret = dwc3_gadget_run_stop(dwc, true, false); 2965 + if (ret < 0) 3117 2966 goto err1; 3118 - 3119 - /* begin to receive SETUP packets */ 3120 - dwc->ep0state = EP0_SETUP_PHASE; 3121 - dwc3_ep0_out_start(dwc); 3122 - 3123 - dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg); 3124 - 3125 - if (dwc->pullups_connected) { 3126 - dwc3_gadget_enable_irq(dwc); 3127 - dwc3_gadget_run_stop(dwc, true, false); 3128 - } 3129 2967 3130 2968 return 0; 3131 2969 3132 2970 err1: 3133 - __dwc3_gadget_ep_disable(dwc->eps[0]); 2971 + __dwc3_gadget_stop(dwc); 3134 2972 3135 2973 err0: 3136 2974 return ret; 2975 + } 2976 + 2977 + void dwc3_gadget_process_pending_events(struct dwc3 *dwc) 2978 + { 2979 + if (dwc->pending_events) { 2980 + dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf); 2981 + dwc->pending_events = false; 2982 + enable_irq(dwc->irq_gadget); 2983 + } 3137 2984 }
+2 -2
drivers/usb/dwc3/gadget.h
··· 95 95 * 96 96 * Caller should take care of locking 97 97 */ 98 - static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number) 98 + static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3_ep *dep) 99 99 { 100 100 u32 res_id; 101 101 102 - res_id = dwc3_readl(dwc->regs, DWC3_DEPCMD(number)); 102 + res_id = dwc3_readl(dep->regs, DWC3_DEPCMD); 103 103 104 104 return DWC3_DEPCMD_GET_RSC_IDX(res_id); 105 105 }
+2 -5
drivers/usb/dwc3/io.h
··· 26 26 27 27 static inline u32 dwc3_readl(void __iomem *base, u32 offset) 28 28 { 29 - u32 offs = offset - DWC3_GLOBALS_REGS_START; 30 29 u32 value; 31 30 32 31 /* ··· 33 34 * space, see dwc3_probe in core.c. 34 35 * However, the offsets are given starting from xHCI address space. 35 36 */ 36 - value = readl(base + offs); 37 + value = readl(base + offset - DWC3_GLOBALS_REGS_START); 37 38 38 39 /* 39 40 * When tracing we want to make it easy to find the correct address on ··· 48 49 49 50 static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) 50 51 { 51 - u32 offs = offset - DWC3_GLOBALS_REGS_START; 52 - 53 52 /* 54 53 * We requested the mem region starting from the Globals address 55 54 * space, see dwc3_probe in core.c. 56 55 * However, the offsets are given starting from xHCI address space. 57 56 */ 58 - writel(value, base + offs); 57 + writel(value, base + offset - DWC3_GLOBALS_REGS_START); 59 58 60 59 /* 61 60 * When tracing we want to make it easy to find the correct address on
-53
drivers/usb/dwc3/platform_data.h
··· 1 - /** 2 - * platform_data.h - USB DWC3 Platform Data Support 3 - * 4 - * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com 5 - * Author: Felipe Balbi <balbi@ti.com> 6 - * 7 - * This program is free software: you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License version 2 of 9 - * the License as published by the Free Software Foundation. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 - */ 19 - 20 - #include <linux/usb/ch9.h> 21 - #include <linux/usb/otg.h> 22 - 23 - struct dwc3_platform_data { 24 - enum usb_device_speed maximum_speed; 25 - enum usb_dr_mode dr_mode; 26 - bool usb3_lpm_capable; 27 - 28 - unsigned is_utmi_l1_suspend:1; 29 - u8 hird_threshold; 30 - 31 - u8 lpm_nyet_threshold; 32 - 33 - unsigned disable_scramble_quirk:1; 34 - unsigned has_lpm_erratum:1; 35 - unsigned u2exit_lfps_quirk:1; 36 - unsigned u2ss_inp3_quirk:1; 37 - unsigned req_p1p2p3_quirk:1; 38 - unsigned del_p1p2p3_quirk:1; 39 - unsigned del_phy_power_chg_quirk:1; 40 - unsigned lfps_filter_quirk:1; 41 - unsigned rx_detect_poll_quirk:1; 42 - unsigned dis_u3_susphy_quirk:1; 43 - unsigned dis_u2_susphy_quirk:1; 44 - unsigned dis_enblslpm_quirk:1; 45 - unsigned dis_rxdet_inp3_quirk:1; 46 - 47 - unsigned tx_de_emphasis_quirk:1; 48 - unsigned tx_de_emphasis:2; 49 - 50 - u32 fladj_value; 51 - 52 - const char *hsphy_interface; 53 - };
+72 -24
drivers/usb/dwc3/trace.h
··· 71 71 TP_fast_assign( 72 72 __entry->event = event; 73 73 ), 74 - TP_printk("event %08x", __entry->event) 74 + TP_printk("event (%08x): %s", __entry->event, 75 + dwc3_decode_event(__entry->event)) 75 76 ); 76 77 77 78 DEFINE_EVENT(dwc3_log_event, dwc3_event, ··· 86 85 TP_STRUCT__entry( 87 86 __field(__u8, bRequestType) 88 87 __field(__u8, bRequest) 89 - __field(__le16, wValue) 90 - __field(__le16, wIndex) 91 - __field(__le16, wLength) 88 + __field(__u16, wValue) 89 + __field(__u16, wIndex) 90 + __field(__u16, wLength) 92 91 ), 93 92 TP_fast_assign( 94 93 __entry->bRequestType = ctrl->bRequestType; 95 94 __entry->bRequest = ctrl->bRequest; 96 - __entry->wValue = ctrl->wValue; 97 - __entry->wIndex = ctrl->wIndex; 98 - __entry->wLength = ctrl->wLength; 95 + __entry->wValue = le16_to_cpu(ctrl->wValue); 96 + __entry->wIndex = le16_to_cpu(ctrl->wIndex); 97 + __entry->wLength = le16_to_cpu(ctrl->wLength); 99 98 ), 100 99 TP_printk("bRequestType %02x bRequest %02x wValue %04x wIndex %04x wLength %d", 101 100 __entry->bRequestType, __entry->bRequest, 102 - le16_to_cpu(__entry->wValue), le16_to_cpu(__entry->wIndex), 103 - le16_to_cpu(__entry->wLength) 101 + __entry->wValue, __entry->wIndex, 102 + __entry->wLength 104 103 ) 105 104 ); 106 105 ··· 167 166 ); 168 167 169 168 DECLARE_EVENT_CLASS(dwc3_log_generic_cmd, 170 - TP_PROTO(unsigned int cmd, u32 param), 171 - TP_ARGS(cmd, param), 169 + TP_PROTO(unsigned int cmd, u32 param, int status), 170 + TP_ARGS(cmd, param, status), 172 171 TP_STRUCT__entry( 173 172 __field(unsigned int, cmd) 174 173 __field(u32, param) 174 + __field(int, status) 175 175 ), 176 176 TP_fast_assign( 177 177 __entry->cmd = cmd; 178 178 __entry->param = param; 179 + __entry->status = status; 179 180 ), 180 - TP_printk("cmd '%s' [%d] param %08x", 181 + TP_printk("cmd '%s' [%d] param %08x --> status: %s", 181 182 dwc3_gadget_generic_cmd_string(__entry->cmd), 182 - __entry->cmd, __entry->param 183 + __entry->cmd, __entry->param, 184 + dwc3_gadget_generic_cmd_status_string(__entry->status) 183 185 ) 184 186 ); 185 187 186 188 DEFINE_EVENT(dwc3_log_generic_cmd, dwc3_gadget_generic_cmd, 187 - TP_PROTO(unsigned int cmd, u32 param), 188 - TP_ARGS(cmd, param) 189 + TP_PROTO(unsigned int cmd, u32 param, int status), 190 + TP_ARGS(cmd, param, status) 189 191 ); 190 192 191 193 DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd, 192 194 TP_PROTO(struct dwc3_ep *dep, unsigned int cmd, 193 - struct dwc3_gadget_ep_cmd_params *params), 194 - TP_ARGS(dep, cmd, params), 195 + struct dwc3_gadget_ep_cmd_params *params, int cmd_status), 196 + TP_ARGS(dep, cmd, params, cmd_status), 195 197 TP_STRUCT__entry( 196 198 __dynamic_array(char, name, DWC3_MSG_MAX) 197 199 __field(unsigned int, cmd) 198 200 __field(u32, param0) 199 201 __field(u32, param1) 200 202 __field(u32, param2) 203 + __field(int, cmd_status) 201 204 ), 202 205 TP_fast_assign( 203 206 snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name); ··· 209 204 __entry->param0 = params->param0; 210 205 __entry->param1 = params->param1; 211 206 __entry->param2 = params->param2; 207 + __entry->cmd_status = cmd_status; 212 208 ), 213 - TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x", 209 + TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x --> status: %s", 214 210 __get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd), 215 211 __entry->cmd, __entry->param0, 216 - __entry->param1, __entry->param2 212 + __entry->param1, __entry->param2, 213 + dwc3_ep_cmd_status_string(__entry->cmd_status) 217 214 ) 218 215 ); 219 216 220 217 DEFINE_EVENT(dwc3_log_gadget_ep_cmd, dwc3_gadget_ep_cmd, 221 218 TP_PROTO(struct dwc3_ep *dep, unsigned int cmd, 222 - struct dwc3_gadget_ep_cmd_params *params), 223 - TP_ARGS(dep, cmd, params) 219 + struct dwc3_gadget_ep_cmd_params *params, int cmd_status), 220 + TP_ARGS(dep, cmd, params, cmd_status) 224 221 ); 225 222 226 223 DECLARE_EVENT_CLASS(dwc3_log_trb, ··· 231 224 TP_STRUCT__entry( 232 225 __dynamic_array(char, name, DWC3_MSG_MAX) 233 226 __field(struct dwc3_trb *, trb) 227 + __field(u32, allocated) 228 + __field(u32, queued) 234 229 __field(u32, bpl) 235 230 __field(u32, bph) 236 231 __field(u32, size) ··· 241 232 TP_fast_assign( 242 233 snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name); 243 234 __entry->trb = trb; 235 + __entry->allocated = dep->allocated_requests; 236 + __entry->queued = dep->queued_requests; 244 237 __entry->bpl = trb->bpl; 245 238 __entry->bph = trb->bph; 246 239 __entry->size = trb->size; 247 240 __entry->ctrl = trb->ctrl; 248 241 ), 249 - TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x", 250 - __get_str(name), __entry->trb, __entry->bph, __entry->bpl, 251 - __entry->size, __entry->ctrl 242 + TP_printk("%s: %d/%d trb %p buf %08x%08x size %d ctrl %08x (%c%c%c%c:%c%c:%s)", 243 + __get_str(name), __entry->queued, __entry->allocated, 244 + __entry->trb, __entry->bph, __entry->bpl, 245 + __entry->size, __entry->ctrl, 246 + __entry->ctrl & DWC3_TRB_CTRL_HWO ? 'H' : 'h', 247 + __entry->ctrl & DWC3_TRB_CTRL_LST ? 'L' : 'l', 248 + __entry->ctrl & DWC3_TRB_CTRL_CHN ? 'C' : 'c', 249 + __entry->ctrl & DWC3_TRB_CTRL_CSP ? 'S' : 's', 250 + __entry->ctrl & DWC3_TRB_CTRL_ISP_IMI ? 'S' : 's', 251 + __entry->ctrl & DWC3_TRB_CTRL_IOC ? 'C' : 'c', 252 + ({char *s; 253 + switch (__entry->ctrl & 0x3f0) { 254 + case DWC3_TRBCTL_NORMAL: 255 + s = "normal"; 256 + break; 257 + case DWC3_TRBCTL_CONTROL_SETUP: 258 + s = "setup"; 259 + break; 260 + case DWC3_TRBCTL_CONTROL_STATUS2: 261 + s = "status2"; 262 + break; 263 + case DWC3_TRBCTL_CONTROL_STATUS3: 264 + s = "status3"; 265 + break; 266 + case DWC3_TRBCTL_CONTROL_DATA: 267 + s = "data"; 268 + break; 269 + case DWC3_TRBCTL_ISOCHRONOUS_FIRST: 270 + s = "isoc-first"; 271 + break; 272 + case DWC3_TRBCTL_ISOCHRONOUS: 273 + s = "isoc"; 274 + break; 275 + case DWC3_TRBCTL_LINK_TRB: 276 + s = "link"; 277 + break; 278 + default: 279 + s = "UNKNOWN"; 280 + break; 281 + } s; }) 252 282 ) 253 283 ); 254 284
+1 -1
drivers/usb/gadget/Kconfig
··· 114 114 115 115 config USB_GADGET_STORAGE_NUM_BUFFERS 116 116 int "Number of storage pipeline buffers" 117 - range 2 32 117 + range 2 256 118 118 default 2 119 119 help 120 120 Usually 2 buffers are enough to establish a good buffering
+1 -1
drivers/usb/gadget/config.c
··· 93 93 *cp = *config; 94 94 95 95 /* then interface/endpoint/class/vendor/... */ 96 - len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf, 96 + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8 *)buf, 97 97 length - USB_DT_CONFIG_SIZE, desc); 98 98 if (len < 0) 99 99 return len;
+156 -36
drivers/usb/gadget/function/f_fs.c
··· 130 130 131 131 struct dentry *dentry; 132 132 133 + /* 134 + * Buffer for holding data from partial reads which may happen since 135 + * we’re rounding user read requests to a multiple of a max packet size. 136 + */ 137 + struct ffs_buffer *read_buffer; /* P: epfile->mutex */ 138 + 133 139 char name[5]; 134 140 135 141 unsigned char in; /* P: ffs->eps_lock */ 136 142 unsigned char isoc; /* P: ffs->eps_lock */ 137 143 138 144 unsigned char _pad; 145 + }; 146 + 147 + struct ffs_buffer { 148 + size_t length; 149 + char *data; 150 + char storage[]; 139 151 }; 140 152 141 153 /* ffs_io_data structure ***************************************************/ ··· 652 640 } 653 641 } 654 642 643 + static ssize_t ffs_copy_to_iter(void *data, int data_len, struct iov_iter *iter) 644 + { 645 + ssize_t ret = copy_to_iter(data, data_len, iter); 646 + if (likely(ret == data_len)) 647 + return ret; 648 + 649 + if (unlikely(iov_iter_count(iter))) 650 + return -EFAULT; 651 + 652 + /* 653 + * Dear user space developer! 654 + * 655 + * TL;DR: To stop getting below error message in your kernel log, change 656 + * user space code using functionfs to align read buffers to a max 657 + * packet size. 658 + * 659 + * Some UDCs (e.g. dwc3) require request sizes to be a multiple of a max 660 + * packet size. When unaligned buffer is passed to functionfs, it 661 + * internally uses a larger, aligned buffer so that such UDCs are happy. 662 + * 663 + * Unfortunately, this means that host may send more data than was 664 + * requested in read(2) system call. f_fs doesn’t know what to do with 665 + * that excess data so it simply drops it. 666 + * 667 + * Was the buffer aligned in the first place, no such problem would 668 + * happen. 669 + * 670 + * Data may be dropped only in AIO reads. Synchronous reads are handled 671 + * by splitting a request into multiple parts. This splitting may still 672 + * be a problem though so it’s likely best to align the buffer 673 + * regardless of it being AIO or not.. 674 + * 675 + * This only affects OUT endpoints, i.e. reading data with a read(2), 676 + * aio_read(2) etc. system calls. Writing data to an IN endpoint is not 677 + * affected. 678 + */ 679 + pr_err("functionfs read size %d > requested size %zd, dropping excess data. " 680 + "Align read buffer size to max packet size to avoid the problem.\n", 681 + data_len, ret); 682 + 683 + return ret; 684 + } 685 + 655 686 static void ffs_user_copy_worker(struct work_struct *work) 656 687 { 657 688 struct ffs_io_data *io_data = container_of(work, struct ffs_io_data, ··· 705 650 706 651 if (io_data->read && ret > 0) { 707 652 use_mm(io_data->mm); 708 - ret = copy_to_iter(io_data->buf, ret, &io_data->data); 709 - if (ret != io_data->req->actual && iov_iter_count(&io_data->data)) 710 - ret = -EFAULT; 653 + ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data); 711 654 unuse_mm(io_data->mm); 712 655 } 713 656 ··· 731 678 732 679 INIT_WORK(&io_data->work, ffs_user_copy_worker); 733 680 schedule_work(&io_data->work); 681 + } 682 + 683 + /* Assumes epfile->mutex is held. */ 684 + static ssize_t __ffs_epfile_read_buffered(struct ffs_epfile *epfile, 685 + struct iov_iter *iter) 686 + { 687 + struct ffs_buffer *buf = epfile->read_buffer; 688 + ssize_t ret; 689 + if (!buf) 690 + return 0; 691 + 692 + ret = copy_to_iter(buf->data, buf->length, iter); 693 + if (buf->length == ret) { 694 + kfree(buf); 695 + epfile->read_buffer = NULL; 696 + } else if (unlikely(iov_iter_count(iter))) { 697 + ret = -EFAULT; 698 + } else { 699 + buf->length -= ret; 700 + buf->data += ret; 701 + } 702 + return ret; 703 + } 704 + 705 + /* Assumes epfile->mutex is held. */ 706 + static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile, 707 + void *data, int data_len, 708 + struct iov_iter *iter) 709 + { 710 + struct ffs_buffer *buf; 711 + 712 + ssize_t ret = copy_to_iter(data, data_len, iter); 713 + if (likely(data_len == ret)) 714 + return ret; 715 + 716 + if (unlikely(iov_iter_count(iter))) 717 + return -EFAULT; 718 + 719 + /* See ffs_copy_to_iter for more context. */ 720 + pr_warn("functionfs read size %d > requested size %zd, splitting request into multiple reads.", 721 + data_len, ret); 722 + 723 + data_len -= ret; 724 + buf = kmalloc(sizeof(*buf) + data_len, GFP_KERNEL); 725 + if (!buf) 726 + return -ENOMEM; 727 + buf->length = data_len; 728 + buf->data = buf->storage; 729 + memcpy(buf->storage, data + ret, data_len); 730 + epfile->read_buffer = buf; 731 + 732 + return ret; 734 733 } 735 734 736 735 static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data) ··· 814 709 if (halt && epfile->isoc) 815 710 return -EINVAL; 816 711 712 + /* We will be using request and read_buffer */ 713 + ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); 714 + if (unlikely(ret)) 715 + goto error; 716 + 817 717 /* Allocate & copy */ 818 718 if (!halt) { 719 + struct usb_gadget *gadget; 720 + 721 + /* 722 + * Do we have buffered data from previous partial read? Check 723 + * that for synchronous case only because we do not have 724 + * facility to ‘wake up’ a pending asynchronous read and push 725 + * buffered data to it which we would need to make things behave 726 + * consistently. 727 + */ 728 + if (!io_data->aio && io_data->read) { 729 + ret = __ffs_epfile_read_buffered(epfile, &io_data->data); 730 + if (ret) 731 + goto error_mutex; 732 + } 733 + 819 734 /* 820 735 * if we _do_ wait above, the epfile->ffs->gadget might be NULL 821 736 * before the waiting completes, so do not assign to 'gadget' 822 737 * earlier 823 738 */ 824 - struct usb_gadget *gadget = epfile->ffs->gadget; 825 - size_t copied; 739 + gadget = epfile->ffs->gadget; 826 740 827 741 spin_lock_irq(&epfile->ffs->eps_lock); 828 742 /* In the meantime, endpoint got disabled or changed. */ 829 743 if (epfile->ep != ep) { 830 - spin_unlock_irq(&epfile->ffs->eps_lock); 831 - return -ESHUTDOWN; 744 + ret = -ESHUTDOWN; 745 + goto error_lock; 832 746 } 833 747 data_len = iov_iter_count(&io_data->data); 834 748 /* ··· 859 735 spin_unlock_irq(&epfile->ffs->eps_lock); 860 736 861 737 data = kmalloc(data_len, GFP_KERNEL); 862 - if (unlikely(!data)) 863 - return -ENOMEM; 864 - if (!io_data->read) { 865 - copied = copy_from_iter(data, data_len, &io_data->data); 866 - if (copied != data_len) { 867 - ret = -EFAULT; 868 - goto error; 869 - } 738 + if (unlikely(!data)) { 739 + ret = -ENOMEM; 740 + goto error_mutex; 741 + } 742 + if (!io_data->read && 743 + copy_from_iter(data, data_len, &io_data->data) != data_len) { 744 + ret = -EFAULT; 745 + goto error_mutex; 870 746 } 871 747 } 872 - 873 - /* We will be using request */ 874 - ret = ffs_mutex_lock(&epfile->mutex, file->f_flags & O_NONBLOCK); 875 - if (unlikely(ret)) 876 - goto error; 877 748 878 749 spin_lock_irq(&epfile->ffs->eps_lock); 879 750 ··· 922 803 interrupted = ep->status < 0; 923 804 } 924 805 925 - /* 926 - * XXX We may end up silently droping data here. Since data_len 927 - * (i.e. req->length) may be bigger than len (after being 928 - * rounded up to maxpacketsize), we may end up with more data 929 - * then user space has space for. 930 - */ 931 - ret = interrupted ? -EINTR : ep->status; 932 - if (io_data->read && ret > 0) { 933 - ret = copy_to_iter(data, ret, &io_data->data); 934 - if (!ret) 935 - ret = -EFAULT; 936 - } 806 + if (interrupted) 807 + ret = -EINTR; 808 + else if (io_data->read && ep->status > 0) 809 + ret = __ffs_epfile_read_data(epfile, data, ep->status, 810 + &io_data->data); 811 + else 812 + ret = ep->status; 937 813 goto error_mutex; 938 814 } else if (!(req = usb_ep_alloc_request(ep->ep, GFP_KERNEL))) { 939 815 ret = -ENOMEM; ··· 1094 980 1095 981 ENTER(); 1096 982 983 + kfree(epfile->read_buffer); 984 + epfile->read_buffer = NULL; 1097 985 ffs_data_closed(epfile->ffs); 1098 986 1099 987 return 0; ··· 1721 1605 unsigned count = func->ffs->eps_count; 1722 1606 unsigned long flags; 1723 1607 1724 - spin_lock_irqsave(&func->ffs->eps_lock, flags); 1725 1608 do { 1609 + if (epfile) 1610 + mutex_lock(&epfile->mutex); 1611 + spin_lock_irqsave(&func->ffs->eps_lock, flags); 1726 1612 /* pending requests get nuked */ 1727 1613 if (likely(ep->ep)) 1728 1614 usb_ep_disable(ep->ep); 1729 1615 ++ep; 1616 + spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 1730 1617 1731 1618 if (epfile) { 1732 1619 epfile->ep = NULL; 1620 + kfree(epfile->read_buffer); 1621 + epfile->read_buffer = NULL; 1622 + mutex_unlock(&epfile->mutex); 1733 1623 ++epfile; 1734 1624 } 1735 1625 } while (--count); 1736 - spin_unlock_irqrestore(&func->ffs->eps_lock, flags); 1737 1626 } 1738 1627 1739 1628 static int ffs_func_eps_enable(struct ffs_function *func) ··· 2348 2227 { 2349 2228 u32 str_count, needed_count, lang_count; 2350 2229 struct usb_gadget_strings **stringtabs, *t; 2351 - struct usb_string *strings, *s; 2352 2230 const char *data = _data; 2231 + struct usb_string *s; 2353 2232 2354 2233 ENTER(); 2355 2234 ··· 2407 2286 stringtabs = vla_ptr(vlabuf, d, stringtabs); 2408 2287 t = vla_ptr(vlabuf, d, stringtab); 2409 2288 s = vla_ptr(vlabuf, d, strings); 2410 - strings = s; 2411 2289 } 2412 2290 2413 2291 /* For each language */
+1 -21
drivers/usb/gadget/function/f_mass_storage.c
··· 2655 2655 } 2656 2656 EXPORT_SYMBOL_GPL(fsg_common_put); 2657 2657 2658 - /* check if fsg_num_buffers is within a valid range */ 2659 - static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers) 2660 - { 2661 - #define FSG_MAX_NUM_BUFFERS 32 2662 - 2663 - if (fsg_num_buffers >= 2 && fsg_num_buffers <= FSG_MAX_NUM_BUFFERS) 2664 - return 0; 2665 - pr_err("fsg_num_buffers %u is out of range (%d to %d)\n", 2666 - fsg_num_buffers, 2, FSG_MAX_NUM_BUFFERS); 2667 - return -EINVAL; 2668 - } 2669 - 2670 2658 static struct fsg_common *fsg_common_setup(struct fsg_common *common) 2671 2659 { 2672 2660 if (!common) { ··· 2697 2709 int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n) 2698 2710 { 2699 2711 struct fsg_buffhd *bh, *buffhds; 2700 - int i, rc; 2701 - 2702 - rc = fsg_num_buffers_validate(n); 2703 - if (rc != 0) 2704 - return rc; 2712 + int i; 2705 2713 2706 2714 buffhds = kcalloc(n, sizeof(*buffhds), GFP_KERNEL); 2707 2715 if (!buffhds) ··· 3382 3398 goto end; 3383 3399 } 3384 3400 ret = kstrtou8(page, 0, &num); 3385 - if (ret) 3386 - goto end; 3387 - 3388 - ret = fsg_num_buffers_validate(num); 3389 3401 if (ret) 3390 3402 goto end; 3391 3403
+1 -2
drivers/usb/gadget/function/u_serial.c
··· 907 907 { 908 908 struct gs_port *port = tty->driver_data; 909 909 unsigned long flags; 910 - int status; 911 910 912 911 pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n", 913 912 port->port_num, tty, count); ··· 916 917 count = gs_buf_put(&port->port_write_buf, buf, count); 917 918 /* treat count == 0 as flush_chars() */ 918 919 if (port->port_usb) 919 - status = gs_start_tx(port); 920 + gs_start_tx(port); 920 921 spin_unlock_irqrestore(&port->port_lock, flags); 921 922 922 923 return count;
+6 -9
drivers/usb/gadget/legacy/g_ffs.c
··· 265 265 { 266 266 if (!try_module_get(THIS_MODULE)) 267 267 return ERR_PTR(-ENOENT); 268 - 268 + 269 269 return NULL; 270 270 } 271 271 ··· 275 275 } 276 276 277 277 /* 278 - * The caller of this function takes ffs_lock 278 + * The caller of this function takes ffs_lock 279 279 */ 280 280 static int functionfs_ready_callback(struct ffs_data *ffs) 281 281 { ··· 294 294 ++missing_funcs; 295 295 gfs_registered = false; 296 296 } 297 - 297 + 298 298 return ret; 299 299 } 300 300 301 301 /* 302 - * The caller of this function takes ffs_lock 302 + * The caller of this function takes ffs_lock 303 303 */ 304 304 static void functionfs_closed_callback(struct ffs_data *ffs) 305 305 { ··· 347 347 348 348 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 349 349 { 350 - struct f_rndis_opts *rndis_opts; 351 - 352 350 fi_rndis = usb_get_function_instance("rndis"); 353 351 if (IS_ERR(fi_rndis)) { 354 352 ret = PTR_ERR(fi_rndis); 355 353 goto error; 356 354 } 357 - rndis_opts = container_of(fi_rndis, struct f_rndis_opts, 358 - func_inst); 359 355 #ifndef CONFIG_USB_FUNCTIONFS_ETH 360 - net = rndis_opts->net; 356 + net = container_of(fi_rndis, struct f_rndis_opts, 357 + func_inst)->net; 361 358 #endif 362 359 } 363 360 #endif
+3 -1
drivers/usb/gadget/udc/Kconfig
··· 312 312 If unsure, say "N" here. The driver works fine in PIO mode. 313 313 314 314 config USB_NET2280 315 - tristate "NetChip 228x / PLX USB338x" 315 + tristate "NetChip NET228x / PLX USB3x8x" 316 316 depends on PCI 317 317 help 318 318 NetChip 2280 / 2282 is a PCI based USB peripheral controller which ··· 321 321 It has six configurable endpoints, as well as endpoint zero 322 322 (for control transfers) and several endpoints with dedicated 323 323 functions. 324 + 325 + PLX 2380 is a PCIe version of the PLX 2380. 324 326 325 327 PLX 3380 / 3382 is a PCIe based USB peripheral controller which 326 328 supports full, high speed USB 2.0 and super speed USB 3.0
+5
drivers/usb/gadget/udc/Makefile
··· 1 + # define_trace.h needs to know how to find our header 2 + CFLAGS_trace.o := -I$(src) 3 + 4 + udc-core-y := core.o trace.o 5 + 1 6 # 2 7 # USB peripheral controller drivers 3 8 #
+1 -8
drivers/usb/gadget/udc/amd5536udc.c
··· 2340 2340 struct udc_ep *ep; 2341 2341 struct udc_request *req; 2342 2342 struct udc_data_dma *td; 2343 - unsigned dma_done; 2344 2343 unsigned len; 2345 2344 2346 2345 ep = &dev->ep[ep_ix]; ··· 2384 2385 */ 2385 2386 if (use_dma_ppb_du) { 2386 2387 td = udc_get_last_dma_desc(req); 2387 - if (td) { 2388 - dma_done = 2389 - AMD_GETBITS(td->status, 2390 - UDC_DMA_IN_STS_BS); 2391 - /* don't care DMA done */ 2388 + if (td) 2392 2389 req->req.actual = req->req.length; 2393 - } 2394 2390 } else { 2395 2391 /* assume all bytes transferred */ 2396 2392 req->req.actual = req->req.length; ··· 3411 3417 MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION); 3412 3418 MODULE_AUTHOR("Thomas Dahlmann"); 3413 3419 MODULE_LICENSE("GPL"); 3414 -
+2
drivers/usb/gadget/udc/atmel_usba_udc.c
··· 1920 1920 1921 1921 udc->errata = match->data; 1922 1922 udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9g45-pmc"); 1923 + if (IS_ERR(udc->pmc)) 1924 + udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9x5-pmc"); 1923 1925 if (udc->errata && IS_ERR(udc->pmc)) 1924 1926 return ERR_CAST(udc->pmc); 1925 1927
-3
drivers/usb/gadget/udc/bdc/bdc_cmd.c
··· 57 57 u32 param0, u32 param1, u32 param2) 58 58 { 59 59 u32 temp, cmd_status; 60 - int reset_bdc = 0; 61 60 int ret; 62 61 63 62 temp = bdc_readl(bdc->regs, BDC_CMDSC); ··· 93 94 94 95 case BDC_CMDS_INTL: 95 96 dev_err(bdc->dev, "BDC Internal error\n"); 96 - reset_bdc = 1; 97 97 ret = -ECONNRESET; 98 98 break; 99 99 ··· 100 102 dev_err(bdc->dev, 101 103 "command timedout waited for %dusec\n", 102 104 BDC_CMD_TIMEOUT); 103 - reset_bdc = 1; 104 105 ret = -ECONNRESET; 105 106 break; 106 107 default:
+1 -5
drivers/usb/gadget/udc/bdc/bdc_ep.c
··· 81 81 continue; 82 82 } 83 83 if (!bd_table->start_bd) { 84 - dev_dbg(bdc->dev, "bd dma pool not allocted\n"); 84 + dev_dbg(bdc->dev, "bd dma pool not allocated\n"); 85 85 continue; 86 86 } 87 87 ··· 702 702 /* Queue data stage */ 703 703 static int ep0_queue_data_stage(struct bdc *bdc) 704 704 { 705 - struct usb_request *ep0_usb_req; 706 705 struct bdc_ep *ep; 707 706 708 707 dev_dbg(bdc->dev, "%s\n", __func__); 709 - ep0_usb_req = &bdc->ep0_req.usb_req; 710 708 ep = bdc->bdc_ep_array[1]; 711 709 bdc->ep0_req.ep = ep; 712 710 bdc->ep0_req.usb_req.complete = NULL; ··· 1391 1393 { 1392 1394 struct bdc_ep *ep; 1393 1395 u16 wLength; 1394 - u16 wValue; 1395 1396 1396 1397 dev_dbg(bdc->dev, "%s\n", __func__); 1397 - wValue = le16_to_cpu(setup_pkt->wValue); 1398 1398 wLength = le16_to_cpu(setup_pkt->wLength); 1399 1399 if (unlikely(wLength != 6)) { 1400 1400 dev_err(bdc->dev, "%s Wrong wLength:%d\n", __func__, wLength);
+1523
drivers/usb/gadget/udc/core.c
··· 1 + /** 2 + * udc.c - Core UDC Framework 3 + * 4 + * Copyright (C) 2010 Texas Instruments 5 + * Author: Felipe Balbi <balbi@ti.com> 6 + * 7 + * This program is free software: you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 of 9 + * the License as published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <linux/kernel.h> 21 + #include <linux/module.h> 22 + #include <linux/device.h> 23 + #include <linux/list.h> 24 + #include <linux/err.h> 25 + #include <linux/dma-mapping.h> 26 + #include <linux/workqueue.h> 27 + 28 + #include <linux/usb/ch9.h> 29 + #include <linux/usb/gadget.h> 30 + #include <linux/usb.h> 31 + 32 + #include "trace.h" 33 + 34 + /** 35 + * struct usb_udc - describes one usb device controller 36 + * @driver - the gadget driver pointer. For use by the class code 37 + * @dev - the child device to the actual controller 38 + * @gadget - the gadget. For use by the class code 39 + * @list - for use by the udc class driver 40 + * @vbus - for udcs who care about vbus status, this value is real vbus status; 41 + * for udcs who do not care about vbus status, this value is always true 42 + * 43 + * This represents the internal data structure which is used by the UDC-class 44 + * to hold information about udc driver and gadget together. 45 + */ 46 + struct usb_udc { 47 + struct usb_gadget_driver *driver; 48 + struct usb_gadget *gadget; 49 + struct device dev; 50 + struct list_head list; 51 + bool vbus; 52 + }; 53 + 54 + static struct class *udc_class; 55 + static LIST_HEAD(udc_list); 56 + static LIST_HEAD(gadget_driver_pending_list); 57 + static DEFINE_MUTEX(udc_lock); 58 + 59 + static int udc_bind_to_driver(struct usb_udc *udc, 60 + struct usb_gadget_driver *driver); 61 + 62 + /* ------------------------------------------------------------------------- */ 63 + 64 + /** 65 + * usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint 66 + * @ep:the endpoint being configured 67 + * @maxpacket_limit:value of maximum packet size limit 68 + * 69 + * This function should be used only in UDC drivers to initialize endpoint 70 + * (usually in probe function). 71 + */ 72 + void usb_ep_set_maxpacket_limit(struct usb_ep *ep, 73 + unsigned maxpacket_limit) 74 + { 75 + ep->maxpacket_limit = maxpacket_limit; 76 + ep->maxpacket = maxpacket_limit; 77 + 78 + trace_usb_ep_set_maxpacket_limit(ep, 0); 79 + } 80 + EXPORT_SYMBOL_GPL(usb_ep_set_maxpacket_limit); 81 + 82 + /** 83 + * usb_ep_enable - configure endpoint, making it usable 84 + * @ep:the endpoint being configured. may not be the endpoint named "ep0". 85 + * drivers discover endpoints through the ep_list of a usb_gadget. 86 + * 87 + * When configurations are set, or when interface settings change, the driver 88 + * will enable or disable the relevant endpoints. while it is enabled, an 89 + * endpoint may be used for i/o until the driver receives a disconnect() from 90 + * the host or until the endpoint is disabled. 91 + * 92 + * the ep0 implementation (which calls this routine) must ensure that the 93 + * hardware capabilities of each endpoint match the descriptor provided 94 + * for it. for example, an endpoint named "ep2in-bulk" would be usable 95 + * for interrupt transfers as well as bulk, but it likely couldn't be used 96 + * for iso transfers or for endpoint 14. some endpoints are fully 97 + * configurable, with more generic names like "ep-a". (remember that for 98 + * USB, "in" means "towards the USB master".) 99 + * 100 + * returns zero, or a negative error code. 101 + */ 102 + int usb_ep_enable(struct usb_ep *ep) 103 + { 104 + int ret = 0; 105 + 106 + if (ep->enabled) 107 + goto out; 108 + 109 + ret = ep->ops->enable(ep, ep->desc); 110 + if (ret) { 111 + ret = ret; 112 + goto out; 113 + } 114 + 115 + ep->enabled = true; 116 + 117 + out: 118 + trace_usb_ep_enable(ep, ret); 119 + 120 + return ret; 121 + } 122 + EXPORT_SYMBOL_GPL(usb_ep_enable); 123 + 124 + /** 125 + * usb_ep_disable - endpoint is no longer usable 126 + * @ep:the endpoint being unconfigured. may not be the endpoint named "ep0". 127 + * 128 + * no other task may be using this endpoint when this is called. 129 + * any pending and uncompleted requests will complete with status 130 + * indicating disconnect (-ESHUTDOWN) before this call returns. 131 + * gadget drivers must call usb_ep_enable() again before queueing 132 + * requests to the endpoint. 133 + * 134 + * returns zero, or a negative error code. 135 + */ 136 + int usb_ep_disable(struct usb_ep *ep) 137 + { 138 + int ret = 0; 139 + 140 + if (!ep->enabled) 141 + goto out; 142 + 143 + ret = ep->ops->disable(ep); 144 + if (ret) { 145 + ret = ret; 146 + goto out; 147 + } 148 + 149 + ep->enabled = false; 150 + 151 + out: 152 + trace_usb_ep_disable(ep, ret); 153 + 154 + return ret; 155 + } 156 + EXPORT_SYMBOL_GPL(usb_ep_disable); 157 + 158 + /** 159 + * usb_ep_alloc_request - allocate a request object to use with this endpoint 160 + * @ep:the endpoint to be used with with the request 161 + * @gfp_flags:GFP_* flags to use 162 + * 163 + * Request objects must be allocated with this call, since they normally 164 + * need controller-specific setup and may even need endpoint-specific 165 + * resources such as allocation of DMA descriptors. 166 + * Requests may be submitted with usb_ep_queue(), and receive a single 167 + * completion callback. Free requests with usb_ep_free_request(), when 168 + * they are no longer needed. 169 + * 170 + * Returns the request, or null if one could not be allocated. 171 + */ 172 + struct usb_request *usb_ep_alloc_request(struct usb_ep *ep, 173 + gfp_t gfp_flags) 174 + { 175 + struct usb_request *req = NULL; 176 + 177 + req = ep->ops->alloc_request(ep, gfp_flags); 178 + 179 + trace_usb_ep_alloc_request(ep, req, req ? 0 : -ENOMEM); 180 + 181 + return req; 182 + } 183 + EXPORT_SYMBOL_GPL(usb_ep_alloc_request); 184 + 185 + /** 186 + * usb_ep_free_request - frees a request object 187 + * @ep:the endpoint associated with the request 188 + * @req:the request being freed 189 + * 190 + * Reverses the effect of usb_ep_alloc_request(). 191 + * Caller guarantees the request is not queued, and that it will 192 + * no longer be requeued (or otherwise used). 193 + */ 194 + void usb_ep_free_request(struct usb_ep *ep, 195 + struct usb_request *req) 196 + { 197 + ep->ops->free_request(ep, req); 198 + trace_usb_ep_free_request(ep, req, 0); 199 + } 200 + EXPORT_SYMBOL_GPL(usb_ep_free_request); 201 + 202 + /** 203 + * usb_ep_queue - queues (submits) an I/O request to an endpoint. 204 + * @ep:the endpoint associated with the request 205 + * @req:the request being submitted 206 + * @gfp_flags: GFP_* flags to use in case the lower level driver couldn't 207 + * pre-allocate all necessary memory with the request. 208 + * 209 + * This tells the device controller to perform the specified request through 210 + * that endpoint (reading or writing a buffer). When the request completes, 211 + * including being canceled by usb_ep_dequeue(), the request's completion 212 + * routine is called to return the request to the driver. Any endpoint 213 + * (except control endpoints like ep0) may have more than one transfer 214 + * request queued; they complete in FIFO order. Once a gadget driver 215 + * submits a request, that request may not be examined or modified until it 216 + * is given back to that driver through the completion callback. 217 + * 218 + * Each request is turned into one or more packets. The controller driver 219 + * never merges adjacent requests into the same packet. OUT transfers 220 + * will sometimes use data that's already buffered in the hardware. 221 + * Drivers can rely on the fact that the first byte of the request's buffer 222 + * always corresponds to the first byte of some USB packet, for both 223 + * IN and OUT transfers. 224 + * 225 + * Bulk endpoints can queue any amount of data; the transfer is packetized 226 + * automatically. The last packet will be short if the request doesn't fill it 227 + * out completely. Zero length packets (ZLPs) should be avoided in portable 228 + * protocols since not all usb hardware can successfully handle zero length 229 + * packets. (ZLPs may be explicitly written, and may be implicitly written if 230 + * the request 'zero' flag is set.) Bulk endpoints may also be used 231 + * for interrupt transfers; but the reverse is not true, and some endpoints 232 + * won't support every interrupt transfer. (Such as 768 byte packets.) 233 + * 234 + * Interrupt-only endpoints are less functional than bulk endpoints, for 235 + * example by not supporting queueing or not handling buffers that are 236 + * larger than the endpoint's maxpacket size. They may also treat data 237 + * toggle differently. 238 + * 239 + * Control endpoints ... after getting a setup() callback, the driver queues 240 + * one response (even if it would be zero length). That enables the 241 + * status ack, after transferring data as specified in the response. Setup 242 + * functions may return negative error codes to generate protocol stalls. 243 + * (Note that some USB device controllers disallow protocol stall responses 244 + * in some cases.) When control responses are deferred (the response is 245 + * written after the setup callback returns), then usb_ep_set_halt() may be 246 + * used on ep0 to trigger protocol stalls. Depending on the controller, 247 + * it may not be possible to trigger a status-stage protocol stall when the 248 + * data stage is over, that is, from within the response's completion 249 + * routine. 250 + * 251 + * For periodic endpoints, like interrupt or isochronous ones, the usb host 252 + * arranges to poll once per interval, and the gadget driver usually will 253 + * have queued some data to transfer at that time. 254 + * 255 + * Returns zero, or a negative error code. Endpoints that are not enabled 256 + * report errors; errors will also be 257 + * reported when the usb peripheral is disconnected. 258 + */ 259 + int usb_ep_queue(struct usb_ep *ep, 260 + struct usb_request *req, gfp_t gfp_flags) 261 + { 262 + int ret = 0; 263 + 264 + if (WARN_ON_ONCE(!ep->enabled && ep->address)) { 265 + ret = -ESHUTDOWN; 266 + goto out; 267 + } 268 + 269 + ret = ep->ops->queue(ep, req, gfp_flags); 270 + 271 + out: 272 + trace_usb_ep_queue(ep, req, ret); 273 + 274 + return ret; 275 + } 276 + EXPORT_SYMBOL_GPL(usb_ep_queue); 277 + 278 + /** 279 + * usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint 280 + * @ep:the endpoint associated with the request 281 + * @req:the request being canceled 282 + * 283 + * If the request is still active on the endpoint, it is dequeued and its 284 + * completion routine is called (with status -ECONNRESET); else a negative 285 + * error code is returned. This is guaranteed to happen before the call to 286 + * usb_ep_dequeue() returns. 287 + * 288 + * Note that some hardware can't clear out write fifos (to unlink the request 289 + * at the head of the queue) except as part of disconnecting from usb. Such 290 + * restrictions prevent drivers from supporting configuration changes, 291 + * even to configuration zero (a "chapter 9" requirement). 292 + */ 293 + int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req) 294 + { 295 + int ret; 296 + 297 + ret = ep->ops->dequeue(ep, req); 298 + trace_usb_ep_dequeue(ep, req, ret); 299 + 300 + return ret; 301 + } 302 + EXPORT_SYMBOL_GPL(usb_ep_dequeue); 303 + 304 + /** 305 + * usb_ep_set_halt - sets the endpoint halt feature. 306 + * @ep: the non-isochronous endpoint being stalled 307 + * 308 + * Use this to stall an endpoint, perhaps as an error report. 309 + * Except for control endpoints, 310 + * the endpoint stays halted (will not stream any data) until the host 311 + * clears this feature; drivers may need to empty the endpoint's request 312 + * queue first, to make sure no inappropriate transfers happen. 313 + * 314 + * Note that while an endpoint CLEAR_FEATURE will be invisible to the 315 + * gadget driver, a SET_INTERFACE will not be. To reset endpoints for the 316 + * current altsetting, see usb_ep_clear_halt(). When switching altsettings, 317 + * it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints. 318 + * 319 + * Returns zero, or a negative error code. On success, this call sets 320 + * underlying hardware state that blocks data transfers. 321 + * Attempts to halt IN endpoints will fail (returning -EAGAIN) if any 322 + * transfer requests are still queued, or if the controller hardware 323 + * (usually a FIFO) still holds bytes that the host hasn't collected. 324 + */ 325 + int usb_ep_set_halt(struct usb_ep *ep) 326 + { 327 + int ret; 328 + 329 + ret = ep->ops->set_halt(ep, 1); 330 + trace_usb_ep_set_halt(ep, ret); 331 + 332 + return ret; 333 + } 334 + EXPORT_SYMBOL_GPL(usb_ep_set_halt); 335 + 336 + /** 337 + * usb_ep_clear_halt - clears endpoint halt, and resets toggle 338 + * @ep:the bulk or interrupt endpoint being reset 339 + * 340 + * Use this when responding to the standard usb "set interface" request, 341 + * for endpoints that aren't reconfigured, after clearing any other state 342 + * in the endpoint's i/o queue. 343 + * 344 + * Returns zero, or a negative error code. On success, this call clears 345 + * the underlying hardware state reflecting endpoint halt and data toggle. 346 + * Note that some hardware can't support this request (like pxa2xx_udc), 347 + * and accordingly can't correctly implement interface altsettings. 348 + */ 349 + int usb_ep_clear_halt(struct usb_ep *ep) 350 + { 351 + int ret; 352 + 353 + ret = ep->ops->set_halt(ep, 0); 354 + trace_usb_ep_clear_halt(ep, ret); 355 + 356 + return ret; 357 + } 358 + EXPORT_SYMBOL_GPL(usb_ep_clear_halt); 359 + 360 + /** 361 + * usb_ep_set_wedge - sets the halt feature and ignores clear requests 362 + * @ep: the endpoint being wedged 363 + * 364 + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT) 365 + * requests. If the gadget driver clears the halt status, it will 366 + * automatically unwedge the endpoint. 367 + * 368 + * Returns zero on success, else negative errno. 369 + */ 370 + int usb_ep_set_wedge(struct usb_ep *ep) 371 + { 372 + int ret; 373 + 374 + if (ep->ops->set_wedge) 375 + ret = ep->ops->set_wedge(ep); 376 + else 377 + ret = ep->ops->set_halt(ep, 1); 378 + 379 + trace_usb_ep_set_wedge(ep, ret); 380 + 381 + return ret; 382 + } 383 + EXPORT_SYMBOL_GPL(usb_ep_set_wedge); 384 + 385 + /** 386 + * usb_ep_fifo_status - returns number of bytes in fifo, or error 387 + * @ep: the endpoint whose fifo status is being checked. 388 + * 389 + * FIFO endpoints may have "unclaimed data" in them in certain cases, 390 + * such as after aborted transfers. Hosts may not have collected all 391 + * the IN data written by the gadget driver (and reported by a request 392 + * completion). The gadget driver may not have collected all the data 393 + * written OUT to it by the host. Drivers that need precise handling for 394 + * fault reporting or recovery may need to use this call. 395 + * 396 + * This returns the number of such bytes in the fifo, or a negative 397 + * errno if the endpoint doesn't use a FIFO or doesn't support such 398 + * precise handling. 399 + */ 400 + int usb_ep_fifo_status(struct usb_ep *ep) 401 + { 402 + int ret; 403 + 404 + if (ep->ops->fifo_status) 405 + ret = ep->ops->fifo_status(ep); 406 + else 407 + ret = -EOPNOTSUPP; 408 + 409 + trace_usb_ep_fifo_status(ep, ret); 410 + 411 + return ret; 412 + } 413 + EXPORT_SYMBOL_GPL(usb_ep_fifo_status); 414 + 415 + /** 416 + * usb_ep_fifo_flush - flushes contents of a fifo 417 + * @ep: the endpoint whose fifo is being flushed. 418 + * 419 + * This call may be used to flush the "unclaimed data" that may exist in 420 + * an endpoint fifo after abnormal transaction terminations. The call 421 + * must never be used except when endpoint is not being used for any 422 + * protocol translation. 423 + */ 424 + void usb_ep_fifo_flush(struct usb_ep *ep) 425 + { 426 + if (ep->ops->fifo_flush) 427 + ep->ops->fifo_flush(ep); 428 + 429 + trace_usb_ep_fifo_flush(ep, 0); 430 + } 431 + EXPORT_SYMBOL_GPL(usb_ep_fifo_flush); 432 + 433 + /* ------------------------------------------------------------------------- */ 434 + 435 + /** 436 + * usb_gadget_frame_number - returns the current frame number 437 + * @gadget: controller that reports the frame number 438 + * 439 + * Returns the usb frame number, normally eleven bits from a SOF packet, 440 + * or negative errno if this device doesn't support this capability. 441 + */ 442 + int usb_gadget_frame_number(struct usb_gadget *gadget) 443 + { 444 + int ret; 445 + 446 + ret = gadget->ops->get_frame(gadget); 447 + 448 + trace_usb_gadget_frame_number(gadget, ret); 449 + 450 + return ret; 451 + } 452 + EXPORT_SYMBOL_GPL(usb_gadget_frame_number); 453 + 454 + /** 455 + * usb_gadget_wakeup - tries to wake up the host connected to this gadget 456 + * @gadget: controller used to wake up the host 457 + * 458 + * Returns zero on success, else negative error code if the hardware 459 + * doesn't support such attempts, or its support has not been enabled 460 + * by the usb host. Drivers must return device descriptors that report 461 + * their ability to support this, or hosts won't enable it. 462 + * 463 + * This may also try to use SRP to wake the host and start enumeration, 464 + * even if OTG isn't otherwise in use. OTG devices may also start 465 + * remote wakeup even when hosts don't explicitly enable it. 466 + */ 467 + int usb_gadget_wakeup(struct usb_gadget *gadget) 468 + { 469 + int ret = 0; 470 + 471 + if (!gadget->ops->wakeup) { 472 + ret = -EOPNOTSUPP; 473 + goto out; 474 + } 475 + 476 + ret = gadget->ops->wakeup(gadget); 477 + 478 + out: 479 + trace_usb_gadget_wakeup(gadget, ret); 480 + 481 + return ret; 482 + } 483 + EXPORT_SYMBOL_GPL(usb_gadget_wakeup); 484 + 485 + /** 486 + * usb_gadget_set_selfpowered - sets the device selfpowered feature. 487 + * @gadget:the device being declared as self-powered 488 + * 489 + * this affects the device status reported by the hardware driver 490 + * to reflect that it now has a local power supply. 491 + * 492 + * returns zero on success, else negative errno. 493 + */ 494 + int usb_gadget_set_selfpowered(struct usb_gadget *gadget) 495 + { 496 + int ret = 0; 497 + 498 + if (!gadget->ops->set_selfpowered) { 499 + ret = -EOPNOTSUPP; 500 + goto out; 501 + } 502 + 503 + ret = gadget->ops->set_selfpowered(gadget, 1); 504 + 505 + out: 506 + trace_usb_gadget_set_selfpowered(gadget, ret); 507 + 508 + return ret; 509 + } 510 + EXPORT_SYMBOL_GPL(usb_gadget_set_selfpowered); 511 + 512 + /** 513 + * usb_gadget_clear_selfpowered - clear the device selfpowered feature. 514 + * @gadget:the device being declared as bus-powered 515 + * 516 + * this affects the device status reported by the hardware driver. 517 + * some hardware may not support bus-powered operation, in which 518 + * case this feature's value can never change. 519 + * 520 + * returns zero on success, else negative errno. 521 + */ 522 + int usb_gadget_clear_selfpowered(struct usb_gadget *gadget) 523 + { 524 + int ret = 0; 525 + 526 + if (!gadget->ops->set_selfpowered) { 527 + ret = -EOPNOTSUPP; 528 + goto out; 529 + } 530 + 531 + ret = gadget->ops->set_selfpowered(gadget, 0); 532 + 533 + out: 534 + trace_usb_gadget_clear_selfpowered(gadget, ret); 535 + 536 + return ret; 537 + } 538 + EXPORT_SYMBOL_GPL(usb_gadget_clear_selfpowered); 539 + 540 + /** 541 + * usb_gadget_vbus_connect - Notify controller that VBUS is powered 542 + * @gadget:The device which now has VBUS power. 543 + * Context: can sleep 544 + * 545 + * This call is used by a driver for an external transceiver (or GPIO) 546 + * that detects a VBUS power session starting. Common responses include 547 + * resuming the controller, activating the D+ (or D-) pullup to let the 548 + * host detect that a USB device is attached, and starting to draw power 549 + * (8mA or possibly more, especially after SET_CONFIGURATION). 550 + * 551 + * Returns zero on success, else negative errno. 552 + */ 553 + int usb_gadget_vbus_connect(struct usb_gadget *gadget) 554 + { 555 + int ret = 0; 556 + 557 + if (!gadget->ops->vbus_session) { 558 + ret = -EOPNOTSUPP; 559 + goto out; 560 + } 561 + 562 + ret = gadget->ops->vbus_session(gadget, 1); 563 + 564 + out: 565 + trace_usb_gadget_vbus_connect(gadget, ret); 566 + 567 + return ret; 568 + } 569 + EXPORT_SYMBOL_GPL(usb_gadget_vbus_connect); 570 + 571 + /** 572 + * usb_gadget_vbus_draw - constrain controller's VBUS power usage 573 + * @gadget:The device whose VBUS usage is being described 574 + * @mA:How much current to draw, in milliAmperes. This should be twice 575 + * the value listed in the configuration descriptor bMaxPower field. 576 + * 577 + * This call is used by gadget drivers during SET_CONFIGURATION calls, 578 + * reporting how much power the device may consume. For example, this 579 + * could affect how quickly batteries are recharged. 580 + * 581 + * Returns zero on success, else negative errno. 582 + */ 583 + int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) 584 + { 585 + int ret = 0; 586 + 587 + if (!gadget->ops->vbus_draw) { 588 + ret = -EOPNOTSUPP; 589 + goto out; 590 + } 591 + 592 + ret = gadget->ops->vbus_draw(gadget, mA); 593 + if (!ret) 594 + gadget->mA = mA; 595 + 596 + out: 597 + trace_usb_gadget_vbus_draw(gadget, ret); 598 + 599 + return ret; 600 + } 601 + EXPORT_SYMBOL_GPL(usb_gadget_vbus_draw); 602 + 603 + /** 604 + * usb_gadget_vbus_disconnect - notify controller about VBUS session end 605 + * @gadget:the device whose VBUS supply is being described 606 + * Context: can sleep 607 + * 608 + * This call is used by a driver for an external transceiver (or GPIO) 609 + * that detects a VBUS power session ending. Common responses include 610 + * reversing everything done in usb_gadget_vbus_connect(). 611 + * 612 + * Returns zero on success, else negative errno. 613 + */ 614 + int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) 615 + { 616 + int ret = 0; 617 + 618 + if (!gadget->ops->vbus_session) { 619 + ret = -EOPNOTSUPP; 620 + goto out; 621 + } 622 + 623 + ret = gadget->ops->vbus_session(gadget, 0); 624 + 625 + out: 626 + trace_usb_gadget_vbus_disconnect(gadget, ret); 627 + 628 + return ret; 629 + } 630 + EXPORT_SYMBOL_GPL(usb_gadget_vbus_disconnect); 631 + 632 + /** 633 + * usb_gadget_connect - software-controlled connect to USB host 634 + * @gadget:the peripheral being connected 635 + * 636 + * Enables the D+ (or potentially D-) pullup. The host will start 637 + * enumerating this gadget when the pullup is active and a VBUS session 638 + * is active (the link is powered). This pullup is always enabled unless 639 + * usb_gadget_disconnect() has been used to disable it. 640 + * 641 + * Returns zero on success, else negative errno. 642 + */ 643 + int usb_gadget_connect(struct usb_gadget *gadget) 644 + { 645 + int ret = 0; 646 + 647 + if (!gadget->ops->pullup) { 648 + ret = -EOPNOTSUPP; 649 + goto out; 650 + } 651 + 652 + if (gadget->deactivated) { 653 + /* 654 + * If gadget is deactivated we only save new state. 655 + * Gadget will be connected automatically after activation. 656 + */ 657 + gadget->connected = true; 658 + goto out; 659 + } 660 + 661 + ret = gadget->ops->pullup(gadget, 1); 662 + if (!ret) 663 + gadget->connected = 1; 664 + 665 + out: 666 + trace_usb_gadget_connect(gadget, ret); 667 + 668 + return ret; 669 + } 670 + EXPORT_SYMBOL_GPL(usb_gadget_connect); 671 + 672 + /** 673 + * usb_gadget_disconnect - software-controlled disconnect from USB host 674 + * @gadget:the peripheral being disconnected 675 + * 676 + * Disables the D+ (or potentially D-) pullup, which the host may see 677 + * as a disconnect (when a VBUS session is active). Not all systems 678 + * support software pullup controls. 679 + * 680 + * Returns zero on success, else negative errno. 681 + */ 682 + int usb_gadget_disconnect(struct usb_gadget *gadget) 683 + { 684 + int ret = 0; 685 + 686 + if (!gadget->ops->pullup) { 687 + ret = -EOPNOTSUPP; 688 + goto out; 689 + } 690 + 691 + if (gadget->deactivated) { 692 + /* 693 + * If gadget is deactivated we only save new state. 694 + * Gadget will stay disconnected after activation. 695 + */ 696 + gadget->connected = false; 697 + goto out; 698 + } 699 + 700 + ret = gadget->ops->pullup(gadget, 0); 701 + if (!ret) 702 + gadget->connected = 0; 703 + 704 + out: 705 + trace_usb_gadget_disconnect(gadget, ret); 706 + 707 + return ret; 708 + } 709 + EXPORT_SYMBOL_GPL(usb_gadget_disconnect); 710 + 711 + /** 712 + * usb_gadget_deactivate - deactivate function which is not ready to work 713 + * @gadget: the peripheral being deactivated 714 + * 715 + * This routine may be used during the gadget driver bind() call to prevent 716 + * the peripheral from ever being visible to the USB host, unless later 717 + * usb_gadget_activate() is called. For example, user mode components may 718 + * need to be activated before the system can talk to hosts. 719 + * 720 + * Returns zero on success, else negative errno. 721 + */ 722 + int usb_gadget_deactivate(struct usb_gadget *gadget) 723 + { 724 + int ret = 0; 725 + 726 + if (gadget->deactivated) 727 + goto out; 728 + 729 + if (gadget->connected) { 730 + ret = usb_gadget_disconnect(gadget); 731 + if (ret) 732 + goto out; 733 + 734 + /* 735 + * If gadget was being connected before deactivation, we want 736 + * to reconnect it in usb_gadget_activate(). 737 + */ 738 + gadget->connected = true; 739 + } 740 + gadget->deactivated = true; 741 + 742 + out: 743 + trace_usb_gadget_deactivate(gadget, ret); 744 + 745 + return ret; 746 + } 747 + EXPORT_SYMBOL_GPL(usb_gadget_deactivate); 748 + 749 + /** 750 + * usb_gadget_activate - activate function which is not ready to work 751 + * @gadget: the peripheral being activated 752 + * 753 + * This routine activates gadget which was previously deactivated with 754 + * usb_gadget_deactivate() call. It calls usb_gadget_connect() if needed. 755 + * 756 + * Returns zero on success, else negative errno. 757 + */ 758 + int usb_gadget_activate(struct usb_gadget *gadget) 759 + { 760 + int ret = 0; 761 + 762 + if (!gadget->deactivated) 763 + goto out; 764 + 765 + gadget->deactivated = false; 766 + 767 + /* 768 + * If gadget has been connected before deactivation, or became connected 769 + * while it was being deactivated, we call usb_gadget_connect(). 770 + */ 771 + if (gadget->connected) 772 + ret = usb_gadget_connect(gadget); 773 + 774 + out: 775 + trace_usb_gadget_activate(gadget, ret); 776 + 777 + return ret; 778 + } 779 + EXPORT_SYMBOL_GPL(usb_gadget_activate); 780 + 781 + /* ------------------------------------------------------------------------- */ 782 + 783 + #ifdef CONFIG_HAS_DMA 784 + 785 + int usb_gadget_map_request_by_dev(struct device *dev, 786 + struct usb_request *req, int is_in) 787 + { 788 + if (req->length == 0) 789 + return 0; 790 + 791 + if (req->num_sgs) { 792 + int mapped; 793 + 794 + mapped = dma_map_sg(dev, req->sg, req->num_sgs, 795 + is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 796 + if (mapped == 0) { 797 + dev_err(dev, "failed to map SGs\n"); 798 + return -EFAULT; 799 + } 800 + 801 + req->num_mapped_sgs = mapped; 802 + } else { 803 + req->dma = dma_map_single(dev, req->buf, req->length, 804 + is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 805 + 806 + if (dma_mapping_error(dev, req->dma)) { 807 + dev_err(dev, "failed to map buffer\n"); 808 + return -EFAULT; 809 + } 810 + } 811 + 812 + return 0; 813 + } 814 + EXPORT_SYMBOL_GPL(usb_gadget_map_request_by_dev); 815 + 816 + int usb_gadget_map_request(struct usb_gadget *gadget, 817 + struct usb_request *req, int is_in) 818 + { 819 + return usb_gadget_map_request_by_dev(gadget->dev.parent, req, is_in); 820 + } 821 + EXPORT_SYMBOL_GPL(usb_gadget_map_request); 822 + 823 + void usb_gadget_unmap_request_by_dev(struct device *dev, 824 + struct usb_request *req, int is_in) 825 + { 826 + if (req->length == 0) 827 + return; 828 + 829 + if (req->num_mapped_sgs) { 830 + dma_unmap_sg(dev, req->sg, req->num_mapped_sgs, 831 + is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 832 + 833 + req->num_mapped_sgs = 0; 834 + } else { 835 + dma_unmap_single(dev, req->dma, req->length, 836 + is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 837 + } 838 + } 839 + EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev); 840 + 841 + void usb_gadget_unmap_request(struct usb_gadget *gadget, 842 + struct usb_request *req, int is_in) 843 + { 844 + usb_gadget_unmap_request_by_dev(gadget->dev.parent, req, is_in); 845 + } 846 + EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); 847 + 848 + #endif /* CONFIG_HAS_DMA */ 849 + 850 + /* ------------------------------------------------------------------------- */ 851 + 852 + /** 853 + * usb_gadget_giveback_request - give the request back to the gadget layer 854 + * Context: in_interrupt() 855 + * 856 + * This is called by device controller drivers in order to return the 857 + * completed request back to the gadget layer. 858 + */ 859 + void usb_gadget_giveback_request(struct usb_ep *ep, 860 + struct usb_request *req) 861 + { 862 + if (likely(req->status == 0)) 863 + usb_led_activity(USB_LED_EVENT_GADGET); 864 + 865 + trace_usb_gadget_giveback_request(ep, req, 0); 866 + 867 + req->complete(ep, req); 868 + } 869 + EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); 870 + 871 + /* ------------------------------------------------------------------------- */ 872 + 873 + /** 874 + * gadget_find_ep_by_name - returns ep whose name is the same as sting passed 875 + * in second parameter or NULL if searched endpoint not found 876 + * @g: controller to check for quirk 877 + * @name: name of searched endpoint 878 + */ 879 + struct usb_ep *gadget_find_ep_by_name(struct usb_gadget *g, const char *name) 880 + { 881 + struct usb_ep *ep; 882 + 883 + gadget_for_each_ep(ep, g) { 884 + if (!strcmp(ep->name, name)) 885 + return ep; 886 + } 887 + 888 + return NULL; 889 + } 890 + EXPORT_SYMBOL_GPL(gadget_find_ep_by_name); 891 + 892 + /* ------------------------------------------------------------------------- */ 893 + 894 + int usb_gadget_ep_match_desc(struct usb_gadget *gadget, 895 + struct usb_ep *ep, struct usb_endpoint_descriptor *desc, 896 + struct usb_ss_ep_comp_descriptor *ep_comp) 897 + { 898 + u8 type; 899 + u16 max; 900 + int num_req_streams = 0; 901 + 902 + /* endpoint already claimed? */ 903 + if (ep->claimed) 904 + return 0; 905 + 906 + type = usb_endpoint_type(desc); 907 + max = 0x7ff & usb_endpoint_maxp(desc); 908 + 909 + if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in) 910 + return 0; 911 + if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out) 912 + return 0; 913 + 914 + if (max > ep->maxpacket_limit) 915 + return 0; 916 + 917 + /* "high bandwidth" works only at high speed */ 918 + if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11)) 919 + return 0; 920 + 921 + switch (type) { 922 + case USB_ENDPOINT_XFER_CONTROL: 923 + /* only support ep0 for portable CONTROL traffic */ 924 + return 0; 925 + case USB_ENDPOINT_XFER_ISOC: 926 + if (!ep->caps.type_iso) 927 + return 0; 928 + /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ 929 + if (!gadget_is_dualspeed(gadget) && max > 1023) 930 + return 0; 931 + break; 932 + case USB_ENDPOINT_XFER_BULK: 933 + if (!ep->caps.type_bulk) 934 + return 0; 935 + if (ep_comp && gadget_is_superspeed(gadget)) { 936 + /* Get the number of required streams from the 937 + * EP companion descriptor and see if the EP 938 + * matches it 939 + */ 940 + num_req_streams = ep_comp->bmAttributes & 0x1f; 941 + if (num_req_streams > ep->max_streams) 942 + return 0; 943 + } 944 + break; 945 + case USB_ENDPOINT_XFER_INT: 946 + /* Bulk endpoints handle interrupt transfers, 947 + * except the toggle-quirky iso-synch kind 948 + */ 949 + if (!ep->caps.type_int && !ep->caps.type_bulk) 950 + return 0; 951 + /* INT: limit 64 bytes full speed, 1024 high/super speed */ 952 + if (!gadget_is_dualspeed(gadget) && max > 64) 953 + return 0; 954 + break; 955 + } 956 + 957 + return 1; 958 + } 959 + EXPORT_SYMBOL_GPL(usb_gadget_ep_match_desc); 960 + 961 + /* ------------------------------------------------------------------------- */ 962 + 963 + static void usb_gadget_state_work(struct work_struct *work) 964 + { 965 + struct usb_gadget *gadget = work_to_gadget(work); 966 + struct usb_udc *udc = gadget->udc; 967 + 968 + if (udc) 969 + sysfs_notify(&udc->dev.kobj, NULL, "state"); 970 + } 971 + 972 + void usb_gadget_set_state(struct usb_gadget *gadget, 973 + enum usb_device_state state) 974 + { 975 + gadget->state = state; 976 + schedule_work(&gadget->work); 977 + } 978 + EXPORT_SYMBOL_GPL(usb_gadget_set_state); 979 + 980 + /* ------------------------------------------------------------------------- */ 981 + 982 + static void usb_udc_connect_control(struct usb_udc *udc) 983 + { 984 + if (udc->vbus) 985 + usb_gadget_connect(udc->gadget); 986 + else 987 + usb_gadget_disconnect(udc->gadget); 988 + } 989 + 990 + /** 991 + * usb_udc_vbus_handler - updates the udc core vbus status, and try to 992 + * connect or disconnect gadget 993 + * @gadget: The gadget which vbus change occurs 994 + * @status: The vbus status 995 + * 996 + * The udc driver calls it when it wants to connect or disconnect gadget 997 + * according to vbus status. 998 + */ 999 + void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) 1000 + { 1001 + struct usb_udc *udc = gadget->udc; 1002 + 1003 + if (udc) { 1004 + udc->vbus = status; 1005 + usb_udc_connect_control(udc); 1006 + } 1007 + } 1008 + EXPORT_SYMBOL_GPL(usb_udc_vbus_handler); 1009 + 1010 + /** 1011 + * usb_gadget_udc_reset - notifies the udc core that bus reset occurs 1012 + * @gadget: The gadget which bus reset occurs 1013 + * @driver: The gadget driver we want to notify 1014 + * 1015 + * If the udc driver has bus reset handler, it needs to call this when the bus 1016 + * reset occurs, it notifies the gadget driver that the bus reset occurs as 1017 + * well as updates gadget state. 1018 + */ 1019 + void usb_gadget_udc_reset(struct usb_gadget *gadget, 1020 + struct usb_gadget_driver *driver) 1021 + { 1022 + driver->reset(gadget); 1023 + usb_gadget_set_state(gadget, USB_STATE_DEFAULT); 1024 + } 1025 + EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); 1026 + 1027 + /** 1028 + * usb_gadget_udc_start - tells usb device controller to start up 1029 + * @udc: The UDC to be started 1030 + * 1031 + * This call is issued by the UDC Class driver when it's about 1032 + * to register a gadget driver to the device controller, before 1033 + * calling gadget driver's bind() method. 1034 + * 1035 + * It allows the controller to be powered off until strictly 1036 + * necessary to have it powered on. 1037 + * 1038 + * Returns zero on success, else negative errno. 1039 + */ 1040 + static inline int usb_gadget_udc_start(struct usb_udc *udc) 1041 + { 1042 + return udc->gadget->ops->udc_start(udc->gadget, udc->driver); 1043 + } 1044 + 1045 + /** 1046 + * usb_gadget_udc_stop - tells usb device controller we don't need it anymore 1047 + * @gadget: The device we want to stop activity 1048 + * @driver: The driver to unbind from @gadget 1049 + * 1050 + * This call is issued by the UDC Class driver after calling 1051 + * gadget driver's unbind() method. 1052 + * 1053 + * The details are implementation specific, but it can go as 1054 + * far as powering off UDC completely and disable its data 1055 + * line pullups. 1056 + */ 1057 + static inline void usb_gadget_udc_stop(struct usb_udc *udc) 1058 + { 1059 + udc->gadget->ops->udc_stop(udc->gadget); 1060 + } 1061 + 1062 + /** 1063 + * usb_udc_release - release the usb_udc struct 1064 + * @dev: the dev member within usb_udc 1065 + * 1066 + * This is called by driver's core in order to free memory once the last 1067 + * reference is released. 1068 + */ 1069 + static void usb_udc_release(struct device *dev) 1070 + { 1071 + struct usb_udc *udc; 1072 + 1073 + udc = container_of(dev, struct usb_udc, dev); 1074 + dev_dbg(dev, "releasing '%s'\n", dev_name(dev)); 1075 + kfree(udc); 1076 + } 1077 + 1078 + static const struct attribute_group *usb_udc_attr_groups[]; 1079 + 1080 + static void usb_udc_nop_release(struct device *dev) 1081 + { 1082 + dev_vdbg(dev, "%s\n", __func__); 1083 + } 1084 + 1085 + /** 1086 + * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list 1087 + * @parent: the parent device to this udc. Usually the controller driver's 1088 + * device. 1089 + * @gadget: the gadget to be added to the list. 1090 + * @release: a gadget release function. 1091 + * 1092 + * Returns zero on success, negative errno otherwise. 1093 + */ 1094 + int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, 1095 + void (*release)(struct device *dev)) 1096 + { 1097 + struct usb_udc *udc; 1098 + struct usb_gadget_driver *driver; 1099 + int ret = -ENOMEM; 1100 + 1101 + udc = kzalloc(sizeof(*udc), GFP_KERNEL); 1102 + if (!udc) 1103 + goto err1; 1104 + 1105 + dev_set_name(&gadget->dev, "gadget"); 1106 + INIT_WORK(&gadget->work, usb_gadget_state_work); 1107 + gadget->dev.parent = parent; 1108 + 1109 + if (release) 1110 + gadget->dev.release = release; 1111 + else 1112 + gadget->dev.release = usb_udc_nop_release; 1113 + 1114 + ret = device_register(&gadget->dev); 1115 + if (ret) 1116 + goto err2; 1117 + 1118 + device_initialize(&udc->dev); 1119 + udc->dev.release = usb_udc_release; 1120 + udc->dev.class = udc_class; 1121 + udc->dev.groups = usb_udc_attr_groups; 1122 + udc->dev.parent = parent; 1123 + ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); 1124 + if (ret) 1125 + goto err3; 1126 + 1127 + udc->gadget = gadget; 1128 + gadget->udc = udc; 1129 + 1130 + mutex_lock(&udc_lock); 1131 + list_add_tail(&udc->list, &udc_list); 1132 + 1133 + ret = device_add(&udc->dev); 1134 + if (ret) 1135 + goto err4; 1136 + 1137 + usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); 1138 + udc->vbus = true; 1139 + 1140 + /* pick up one of pending gadget drivers */ 1141 + list_for_each_entry(driver, &gadget_driver_pending_list, pending) { 1142 + if (!driver->udc_name || strcmp(driver->udc_name, 1143 + dev_name(&udc->dev)) == 0) { 1144 + ret = udc_bind_to_driver(udc, driver); 1145 + if (ret != -EPROBE_DEFER) 1146 + list_del(&driver->pending); 1147 + if (ret) 1148 + goto err4; 1149 + break; 1150 + } 1151 + } 1152 + 1153 + mutex_unlock(&udc_lock); 1154 + 1155 + return 0; 1156 + 1157 + err4: 1158 + list_del(&udc->list); 1159 + mutex_unlock(&udc_lock); 1160 + 1161 + err3: 1162 + put_device(&udc->dev); 1163 + device_del(&gadget->dev); 1164 + 1165 + err2: 1166 + put_device(&gadget->dev); 1167 + kfree(udc); 1168 + 1169 + err1: 1170 + return ret; 1171 + } 1172 + EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); 1173 + 1174 + /** 1175 + * usb_get_gadget_udc_name - get the name of the first UDC controller 1176 + * This functions returns the name of the first UDC controller in the system. 1177 + * Please note that this interface is usefull only for legacy drivers which 1178 + * assume that there is only one UDC controller in the system and they need to 1179 + * get its name before initialization. There is no guarantee that the UDC 1180 + * of the returned name will be still available, when gadget driver registers 1181 + * itself. 1182 + * 1183 + * Returns pointer to string with UDC controller name on success, NULL 1184 + * otherwise. Caller should kfree() returned string. 1185 + */ 1186 + char *usb_get_gadget_udc_name(void) 1187 + { 1188 + struct usb_udc *udc; 1189 + char *name = NULL; 1190 + 1191 + /* For now we take the first available UDC */ 1192 + mutex_lock(&udc_lock); 1193 + list_for_each_entry(udc, &udc_list, list) { 1194 + if (!udc->driver) { 1195 + name = kstrdup(udc->gadget->name, GFP_KERNEL); 1196 + break; 1197 + } 1198 + } 1199 + mutex_unlock(&udc_lock); 1200 + return name; 1201 + } 1202 + EXPORT_SYMBOL_GPL(usb_get_gadget_udc_name); 1203 + 1204 + /** 1205 + * usb_add_gadget_udc - adds a new gadget to the udc class driver list 1206 + * @parent: the parent device to this udc. Usually the controller 1207 + * driver's device. 1208 + * @gadget: the gadget to be added to the list 1209 + * 1210 + * Returns zero on success, negative errno otherwise. 1211 + */ 1212 + int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) 1213 + { 1214 + return usb_add_gadget_udc_release(parent, gadget, NULL); 1215 + } 1216 + EXPORT_SYMBOL_GPL(usb_add_gadget_udc); 1217 + 1218 + static void usb_gadget_remove_driver(struct usb_udc *udc) 1219 + { 1220 + dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", 1221 + udc->driver->function); 1222 + 1223 + kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 1224 + 1225 + usb_gadget_disconnect(udc->gadget); 1226 + udc->driver->disconnect(udc->gadget); 1227 + udc->driver->unbind(udc->gadget); 1228 + usb_gadget_udc_stop(udc); 1229 + 1230 + udc->driver = NULL; 1231 + udc->dev.driver = NULL; 1232 + udc->gadget->dev.driver = NULL; 1233 + } 1234 + 1235 + /** 1236 + * usb_del_gadget_udc - deletes @udc from udc_list 1237 + * @gadget: the gadget to be removed. 1238 + * 1239 + * This, will call usb_gadget_unregister_driver() if 1240 + * the @udc is still busy. 1241 + */ 1242 + void usb_del_gadget_udc(struct usb_gadget *gadget) 1243 + { 1244 + struct usb_udc *udc = gadget->udc; 1245 + 1246 + if (!udc) 1247 + return; 1248 + 1249 + dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); 1250 + 1251 + mutex_lock(&udc_lock); 1252 + list_del(&udc->list); 1253 + 1254 + if (udc->driver) { 1255 + struct usb_gadget_driver *driver = udc->driver; 1256 + 1257 + usb_gadget_remove_driver(udc); 1258 + list_add(&driver->pending, &gadget_driver_pending_list); 1259 + } 1260 + mutex_unlock(&udc_lock); 1261 + 1262 + kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 1263 + flush_work(&gadget->work); 1264 + device_unregister(&udc->dev); 1265 + device_unregister(&gadget->dev); 1266 + } 1267 + EXPORT_SYMBOL_GPL(usb_del_gadget_udc); 1268 + 1269 + /* ------------------------------------------------------------------------- */ 1270 + 1271 + static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver) 1272 + { 1273 + int ret; 1274 + 1275 + dev_dbg(&udc->dev, "registering UDC driver [%s]\n", 1276 + driver->function); 1277 + 1278 + udc->driver = driver; 1279 + udc->dev.driver = &driver->driver; 1280 + udc->gadget->dev.driver = &driver->driver; 1281 + 1282 + ret = driver->bind(udc->gadget, driver); 1283 + if (ret) 1284 + goto err1; 1285 + ret = usb_gadget_udc_start(udc); 1286 + if (ret) { 1287 + driver->unbind(udc->gadget); 1288 + goto err1; 1289 + } 1290 + usb_udc_connect_control(udc); 1291 + 1292 + kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 1293 + return 0; 1294 + err1: 1295 + if (ret != -EISNAM) 1296 + dev_err(&udc->dev, "failed to start %s: %d\n", 1297 + udc->driver->function, ret); 1298 + udc->driver = NULL; 1299 + udc->dev.driver = NULL; 1300 + udc->gadget->dev.driver = NULL; 1301 + return ret; 1302 + } 1303 + 1304 + int usb_gadget_probe_driver(struct usb_gadget_driver *driver) 1305 + { 1306 + struct usb_udc *udc = NULL; 1307 + int ret = -ENODEV; 1308 + 1309 + if (!driver || !driver->bind || !driver->setup) 1310 + return -EINVAL; 1311 + 1312 + mutex_lock(&udc_lock); 1313 + if (driver->udc_name) { 1314 + list_for_each_entry(udc, &udc_list, list) { 1315 + ret = strcmp(driver->udc_name, dev_name(&udc->dev)); 1316 + if (!ret) 1317 + break; 1318 + } 1319 + if (!ret && !udc->driver) 1320 + goto found; 1321 + } else { 1322 + list_for_each_entry(udc, &udc_list, list) { 1323 + /* For now we take the first one */ 1324 + if (!udc->driver) 1325 + goto found; 1326 + } 1327 + } 1328 + 1329 + if (!driver->match_existing_only) { 1330 + list_add_tail(&driver->pending, &gadget_driver_pending_list); 1331 + pr_info("udc-core: couldn't find an available UDC - added [%s] to list of pending drivers\n", 1332 + driver->function); 1333 + ret = 0; 1334 + } 1335 + 1336 + mutex_unlock(&udc_lock); 1337 + return ret; 1338 + found: 1339 + ret = udc_bind_to_driver(udc, driver); 1340 + mutex_unlock(&udc_lock); 1341 + return ret; 1342 + } 1343 + EXPORT_SYMBOL_GPL(usb_gadget_probe_driver); 1344 + 1345 + int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 1346 + { 1347 + struct usb_udc *udc = NULL; 1348 + int ret = -ENODEV; 1349 + 1350 + if (!driver || !driver->unbind) 1351 + return -EINVAL; 1352 + 1353 + mutex_lock(&udc_lock); 1354 + list_for_each_entry(udc, &udc_list, list) 1355 + if (udc->driver == driver) { 1356 + usb_gadget_remove_driver(udc); 1357 + usb_gadget_set_state(udc->gadget, 1358 + USB_STATE_NOTATTACHED); 1359 + ret = 0; 1360 + break; 1361 + } 1362 + 1363 + if (ret) { 1364 + list_del(&driver->pending); 1365 + ret = 0; 1366 + } 1367 + mutex_unlock(&udc_lock); 1368 + return ret; 1369 + } 1370 + EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); 1371 + 1372 + /* ------------------------------------------------------------------------- */ 1373 + 1374 + static ssize_t usb_udc_srp_store(struct device *dev, 1375 + struct device_attribute *attr, const char *buf, size_t n) 1376 + { 1377 + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 1378 + 1379 + if (sysfs_streq(buf, "1")) 1380 + usb_gadget_wakeup(udc->gadget); 1381 + 1382 + return n; 1383 + } 1384 + static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store); 1385 + 1386 + static ssize_t usb_udc_softconn_store(struct device *dev, 1387 + struct device_attribute *attr, const char *buf, size_t n) 1388 + { 1389 + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 1390 + 1391 + if (!udc->driver) { 1392 + dev_err(dev, "soft-connect without a gadget driver\n"); 1393 + return -EOPNOTSUPP; 1394 + } 1395 + 1396 + if (sysfs_streq(buf, "connect")) { 1397 + usb_gadget_udc_start(udc); 1398 + usb_gadget_connect(udc->gadget); 1399 + } else if (sysfs_streq(buf, "disconnect")) { 1400 + usb_gadget_disconnect(udc->gadget); 1401 + udc->driver->disconnect(udc->gadget); 1402 + usb_gadget_udc_stop(udc); 1403 + } else { 1404 + dev_err(dev, "unsupported command '%s'\n", buf); 1405 + return -EINVAL; 1406 + } 1407 + 1408 + return n; 1409 + } 1410 + static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); 1411 + 1412 + static ssize_t state_show(struct device *dev, struct device_attribute *attr, 1413 + char *buf) 1414 + { 1415 + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 1416 + struct usb_gadget *gadget = udc->gadget; 1417 + 1418 + return sprintf(buf, "%s\n", usb_state_string(gadget->state)); 1419 + } 1420 + static DEVICE_ATTR_RO(state); 1421 + 1422 + #define USB_UDC_SPEED_ATTR(name, param) \ 1423 + ssize_t name##_show(struct device *dev, \ 1424 + struct device_attribute *attr, char *buf) \ 1425 + { \ 1426 + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ 1427 + return snprintf(buf, PAGE_SIZE, "%s\n", \ 1428 + usb_speed_string(udc->gadget->param)); \ 1429 + } \ 1430 + static DEVICE_ATTR_RO(name) 1431 + 1432 + static USB_UDC_SPEED_ATTR(current_speed, speed); 1433 + static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); 1434 + 1435 + #define USB_UDC_ATTR(name) \ 1436 + ssize_t name##_show(struct device *dev, \ 1437 + struct device_attribute *attr, char *buf) \ 1438 + { \ 1439 + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ 1440 + struct usb_gadget *gadget = udc->gadget; \ 1441 + \ 1442 + return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ 1443 + } \ 1444 + static DEVICE_ATTR_RO(name) 1445 + 1446 + static USB_UDC_ATTR(is_otg); 1447 + static USB_UDC_ATTR(is_a_peripheral); 1448 + static USB_UDC_ATTR(b_hnp_enable); 1449 + static USB_UDC_ATTR(a_hnp_support); 1450 + static USB_UDC_ATTR(a_alt_hnp_support); 1451 + static USB_UDC_ATTR(is_selfpowered); 1452 + 1453 + static struct attribute *usb_udc_attrs[] = { 1454 + &dev_attr_srp.attr, 1455 + &dev_attr_soft_connect.attr, 1456 + &dev_attr_state.attr, 1457 + &dev_attr_current_speed.attr, 1458 + &dev_attr_maximum_speed.attr, 1459 + 1460 + &dev_attr_is_otg.attr, 1461 + &dev_attr_is_a_peripheral.attr, 1462 + &dev_attr_b_hnp_enable.attr, 1463 + &dev_attr_a_hnp_support.attr, 1464 + &dev_attr_a_alt_hnp_support.attr, 1465 + &dev_attr_is_selfpowered.attr, 1466 + NULL, 1467 + }; 1468 + 1469 + static const struct attribute_group usb_udc_attr_group = { 1470 + .attrs = usb_udc_attrs, 1471 + }; 1472 + 1473 + static const struct attribute_group *usb_udc_attr_groups[] = { 1474 + &usb_udc_attr_group, 1475 + NULL, 1476 + }; 1477 + 1478 + static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env) 1479 + { 1480 + struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 1481 + int ret; 1482 + 1483 + ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); 1484 + if (ret) { 1485 + dev_err(dev, "failed to add uevent USB_UDC_NAME\n"); 1486 + return ret; 1487 + } 1488 + 1489 + if (udc->driver) { 1490 + ret = add_uevent_var(env, "USB_UDC_DRIVER=%s", 1491 + udc->driver->function); 1492 + if (ret) { 1493 + dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); 1494 + return ret; 1495 + } 1496 + } 1497 + 1498 + return 0; 1499 + } 1500 + 1501 + static int __init usb_udc_init(void) 1502 + { 1503 + udc_class = class_create(THIS_MODULE, "udc"); 1504 + if (IS_ERR(udc_class)) { 1505 + pr_err("failed to create udc class --> %ld\n", 1506 + PTR_ERR(udc_class)); 1507 + return PTR_ERR(udc_class); 1508 + } 1509 + 1510 + udc_class->dev_uevent = usb_udc_uevent; 1511 + return 0; 1512 + } 1513 + subsys_initcall(usb_udc_init); 1514 + 1515 + static void __exit usb_udc_exit(void) 1516 + { 1517 + class_destroy(udc_class); 1518 + } 1519 + module_exit(usb_udc_exit); 1520 + 1521 + MODULE_DESCRIPTION("UDC Framework"); 1522 + MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 1523 + MODULE_LICENSE("GPL v2");
-5
drivers/usb/gadget/udc/dummy_hcd.c
··· 647 647 static struct usb_request *dummy_alloc_request(struct usb_ep *_ep, 648 648 gfp_t mem_flags) 649 649 { 650 - struct dummy_ep *ep; 651 650 struct dummy_request *req; 652 651 653 652 if (!_ep) 654 653 return NULL; 655 - ep = usb_ep_to_dummy_ep(_ep); 656 654 657 655 req = kzalloc(sizeof(*req), mem_flags); 658 656 if (!req) ··· 2442 2444 2443 2445 static void dummy_stop(struct usb_hcd *hcd) 2444 2446 { 2445 - struct dummy *dum; 2446 - 2447 - dum = hcd_to_dummy_hcd(hcd)->dum; 2448 2447 device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs); 2449 2448 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n"); 2450 2449 }
+6 -18
drivers/usb/gadget/udc/m66592-udc.c
··· 1199 1199 struct m66592 *m66592 = _m66592; 1200 1200 u16 intsts0; 1201 1201 u16 intenb0; 1202 - u16 brdysts, nrdysts, bempsts; 1203 - u16 brdyenb, nrdyenb, bempenb; 1204 1202 u16 savepipe; 1205 1203 u16 mask0; 1206 1204 ··· 1222 1224 1223 1225 mask0 = intsts0 & intenb0; 1224 1226 if (mask0) { 1225 - brdysts = m66592_read(m66592, M66592_BRDYSTS); 1226 - nrdysts = m66592_read(m66592, M66592_NRDYSTS); 1227 - bempsts = m66592_read(m66592, M66592_BEMPSTS); 1228 - brdyenb = m66592_read(m66592, M66592_BRDYENB); 1229 - nrdyenb = m66592_read(m66592, M66592_NRDYENB); 1230 - bempenb = m66592_read(m66592, M66592_BEMPENB); 1227 + u16 brdysts = m66592_read(m66592, M66592_BRDYSTS); 1228 + u16 bempsts = m66592_read(m66592, M66592_BEMPSTS); 1229 + u16 brdyenb = m66592_read(m66592, M66592_BRDYENB); 1230 + u16 bempenb = m66592_read(m66592, M66592_BEMPENB); 1231 1231 1232 1232 if (mask0 & M66592_VBINT) { 1233 1233 m66592_write(m66592, 0xffff & ~M66592_VBINT, ··· 1404 1408 1405 1409 static int m66592_set_halt(struct usb_ep *_ep, int value) 1406 1410 { 1407 - struct m66592_ep *ep; 1408 - struct m66592_request *req; 1411 + struct m66592_ep *ep = container_of(_ep, struct m66592_ep, ep); 1409 1412 unsigned long flags; 1410 1413 int ret = 0; 1411 - 1412 - ep = container_of(_ep, struct m66592_ep, ep); 1413 - req = list_entry(ep->queue.next, struct m66592_request, queue); 1414 1414 1415 1415 spin_lock_irqsave(&ep->m66592->lock, flags); 1416 1416 if (!list_empty(&ep->queue)) { 1417 1417 ret = -EAGAIN; 1418 - goto out; 1419 - } 1420 - if (value) { 1418 + } else if (value) { 1421 1419 ep->busy = 1; 1422 1420 pipe_stall(ep->m66592, ep->pipenum); 1423 1421 } else { 1424 1422 ep->busy = 0; 1425 1423 pipe_stop(ep->m66592, ep->pipenum); 1426 1424 } 1427 - 1428 - out: 1429 1425 spin_unlock_irqrestore(&ep->m66592->lock, flags); 1430 1426 return ret; 1431 1427 }
+3 -20
drivers/usb/gadget/udc/mv_u3d_core.c
··· 119 119 struct mv_u3d_req *curr_req) 120 120 { 121 121 struct mv_u3d_trb *curr_trb; 122 - dma_addr_t cur_deq_lo; 123 - struct mv_u3d_ep_context *curr_ep_context; 124 - int trb_complete, actual, remaining_length = 0; 122 + int actual, remaining_length = 0; 125 123 int direction, ep_num; 126 124 int retval = 0; 127 125 u32 tmp, status, length; 128 126 129 - curr_ep_context = &u3d->ep_context[index]; 130 127 direction = index % 2; 131 128 ep_num = index / 2; 132 129 133 - trb_complete = 0; 134 130 actual = curr_req->req.length; 135 131 136 132 while (!list_empty(&curr_req->trb_list)) { ··· 139 143 } 140 144 141 145 curr_trb->trb_hw->ctrl.own = 0; 142 - if (direction == MV_U3D_EP_DIR_OUT) { 146 + if (direction == MV_U3D_EP_DIR_OUT) 143 147 tmp = ioread32(&u3d->vuc_regs->rxst[ep_num].statuslo); 144 - cur_deq_lo = 145 - ioread32(&u3d->vuc_regs->rxst[ep_num].curdeqlo); 146 - } else { 148 + else 147 149 tmp = ioread32(&u3d->vuc_regs->txst[ep_num].statuslo); 148 - cur_deq_lo = 149 - ioread32(&u3d->vuc_regs->txst[ep_num].curdeqlo); 150 - } 151 150 152 151 status = tmp >> MV_U3D_XFERSTATUS_COMPLETE_SHIFT; 153 152 length = tmp & MV_U3D_XFERSTATUS_TRB_LENGTH_MASK; ··· 518 527 { 519 528 struct mv_u3d *u3d; 520 529 struct mv_u3d_ep *ep; 521 - struct mv_u3d_ep_context *ep_context; 522 530 u16 max = 0; 523 531 unsigned maxburst = 0; 524 532 u32 epxcr, direction; ··· 537 547 if (!_ep->maxburst) 538 548 _ep->maxburst = 1; 539 549 maxburst = _ep->maxburst; 540 - 541 - /* Get the endpoint context address */ 542 - ep_context = (struct mv_u3d_ep_context *)ep->ep_context; 543 550 544 551 /* Set the max burst size */ 545 552 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { ··· 620 633 { 621 634 struct mv_u3d *u3d; 622 635 struct mv_u3d_ep *ep; 623 - struct mv_u3d_ep_context *ep_context; 624 636 u32 epxcr, direction; 625 637 unsigned long flags; 626 638 ··· 631 645 return -EINVAL; 632 646 633 647 u3d = ep->u3d; 634 - 635 - /* Get the endpoint context address */ 636 - ep_context = ep->ep_context; 637 648 638 649 direction = mv_u3d_ep_dir(ep); 639 650
+2 -7
drivers/usb/gadget/udc/mv_udc_core.c
··· 129 129 { 130 130 struct mv_dtd *curr_dtd; 131 131 struct mv_dqh *curr_dqh; 132 - int td_complete, actual, remaining_length; 132 + int actual, remaining_length; 133 133 int i, direction; 134 134 int retval = 0; 135 135 u32 errors; ··· 139 139 direction = index % 2; 140 140 141 141 curr_dtd = curr_req->head; 142 - td_complete = 0; 143 142 actual = curr_req->req.length; 144 143 145 144 for (i = 0; i < curr_req->dtd_count; i++) { ··· 411 412 unsigned count; 412 413 int is_last, is_first = 1; 413 414 struct mv_dtd *dtd, *last_dtd = NULL; 414 - struct mv_udc *udc; 415 415 dma_addr_t dma; 416 - 417 - udc = req->ep->udc; 418 416 419 417 do { 420 418 dtd = build_dtd(req, &count, &dma, &is_last); ··· 563 567 struct mv_udc *udc; 564 568 struct mv_ep *ep; 565 569 struct mv_dqh *dqh; 566 - u32 bit_pos, epctrlx, direction; 570 + u32 epctrlx, direction; 567 571 unsigned long flags; 568 572 569 573 ep = container_of(_ep, struct mv_ep, ep); ··· 578 582 spin_lock_irqsave(&udc->lock, flags); 579 583 580 584 direction = ep_dir(ep); 581 - bit_pos = 1 << ((direction == EP_DIR_OUT ? 0 : 16) + ep->ep_num); 582 585 583 586 /* Reset the max packet length and the interrupt on Setup */ 584 587 dqh->max_packet_length = 0;
-4
drivers/usb/gadget/udc/net2272.c
··· 329 329 static struct usb_request * 330 330 net2272_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) 331 331 { 332 - struct net2272_ep *ep; 333 332 struct net2272_request *req; 334 333 335 334 if (!_ep) 336 335 return NULL; 337 - ep = container_of(_ep, struct net2272_ep, ep); 338 336 339 337 req = kzalloc(sizeof(*req), gfp_flags); 340 338 if (!req) ··· 346 348 static void 347 349 net2272_free_request(struct usb_ep *_ep, struct usb_request *_req) 348 350 { 349 - struct net2272_ep *ep; 350 351 struct net2272_request *req; 351 352 352 - ep = container_of(_ep, struct net2272_ep, ep); 353 353 if (!_ep || !_req) 354 354 return; 355 355
+30 -21
drivers/usb/gadget/udc/net2280.c
··· 211 211 goto print_err; 212 212 } 213 213 214 - if (dev->quirks & PLX_SUPERSPEED) { 214 + if (dev->quirks & PLX_PCIE) { 215 215 if ((desc->bEndpointAddress & 0x0f) >= 0x0c) { 216 216 ret = -EDOM; 217 217 goto print_err; ··· 245 245 /* set type, direction, address; reset fifo counters */ 246 246 writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat); 247 247 248 - if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) { 248 + if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) { 249 249 tmp = readl(&ep->cfg->ep_cfg); 250 250 /* If USB ep number doesn't match hardware ep number */ 251 251 if ((tmp & 0xf) != usb_endpoint_num(desc)) { ··· 316 316 BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp); 317 317 } 318 318 319 - if (dev->quirks & PLX_SUPERSPEED) 319 + if (dev->quirks & PLX_PCIE) 320 320 ep_clear_seqnum(ep); 321 321 writel(tmp, &ep->cfg->ep_cfg); 322 322 ··· 527 527 spin_lock_irqsave(&ep->dev->lock, flags); 528 528 nuke(ep); 529 529 530 - if (ep->dev->quirks & PLX_SUPERSPEED) 530 + if (ep->dev->quirks & PLX_PCIE) 531 531 ep_reset_338x(ep->dev->regs, ep); 532 532 else 533 533 ep_reset_228x(ep->dev->regs, ep); ··· 862 862 writel(readl(&dma->dmastat), &dma->dmastat); 863 863 864 864 writel(td_dma, &dma->dmadesc); 865 - if (ep->dev->quirks & PLX_SUPERSPEED) 865 + if (ep->dev->quirks & PLX_PCIE) 866 866 dmactl |= BIT(DMA_REQUEST_OUTSTANDING); 867 867 writel(dmactl, &dma->dmactl); 868 868 ··· 1046 1046 1047 1047 /* kickstart this i/o queue? */ 1048 1048 if (list_empty(&ep->queue) && !ep->stopped && 1049 - !((dev->quirks & PLX_SUPERSPEED) && ep->dma && 1049 + !((dev->quirks & PLX_PCIE) && ep->dma && 1050 1050 (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)))) { 1051 1051 1052 1052 /* use DMA if the endpoint supports it, else pio */ ··· 1169 1169 break; 1170 1170 } else if (!ep->is_in && 1171 1171 (req->req.length % ep->ep.maxpacket) && 1172 - !(ep->dev->quirks & PLX_SUPERSPEED)) { 1172 + !(ep->dev->quirks & PLX_PCIE)) { 1173 1173 1174 1174 tmp = readl(&ep->regs->ep_stat); 1175 1175 /* AVOID TROUBLE HERE by not issuing short reads from ··· 1367 1367 ep->wedged = 1; 1368 1368 } else { 1369 1369 clear_halt(ep); 1370 - if (ep->dev->quirks & PLX_SUPERSPEED && 1370 + if (ep->dev->quirks & PLX_PCIE && 1371 1371 !list_empty(&ep->queue) && ep->td_dma) 1372 1372 restart_dma(ep); 1373 1373 ep->wedged = 0; ··· 2394 2394 */ 2395 2395 net2280_led_active(dev, 1); 2396 2396 2397 - if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched) 2397 + if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched) 2398 2398 defect7374_enable_data_eps_zero(dev); 2399 2399 2400 2400 ep0_start(dev); ··· 3063 3063 } 3064 3064 ep->stopped = 0; 3065 3065 dev->protocol_stall = 0; 3066 - if (!(dev->quirks & PLX_SUPERSPEED)) { 3066 + if (!(dev->quirks & PLX_PCIE)) { 3067 3067 if (ep->dev->quirks & PLX_2280) 3068 3068 tmp = BIT(FIFO_OVERFLOW) | 3069 3069 BIT(FIFO_UNDERFLOW); ··· 3090 3090 cpu_to_le32s(&u.raw[0]); 3091 3091 cpu_to_le32s(&u.raw[1]); 3092 3092 3093 - if ((dev->quirks & PLX_SUPERSPEED) && !dev->bug7734_patched) 3093 + if ((dev->quirks & PLX_PCIE) && !dev->bug7734_patched) 3094 3094 defect7374_workaround(dev, u.r); 3095 3095 3096 3096 tmp = 0; ··· 3173 3173 } else { 3174 3174 ep_vdbg(dev, "%s clear halt\n", e->ep.name); 3175 3175 clear_halt(e); 3176 - if ((ep->dev->quirks & PLX_SUPERSPEED) && 3176 + if ((ep->dev->quirks & PLX_PCIE) && 3177 3177 !list_empty(&e->queue) && e->td_dma) 3178 3178 restart_dma(e); 3179 3179 } ··· 3195 3195 if (e->ep.name == ep0name) 3196 3196 goto do_stall; 3197 3197 set_halt(e); 3198 - if ((dev->quirks & PLX_SUPERSPEED) && e->dma) 3198 + if ((dev->quirks & PLX_PCIE) && e->dma) 3199 3199 abort_dma(e); 3200 3200 allow_status(ep); 3201 3201 ep_vdbg(dev, "%s set halt\n", ep->ep.name); ··· 3234 3234 #undef w_length 3235 3235 3236 3236 next_endpoints: 3237 - if ((dev->quirks & PLX_SUPERSPEED) && dev->enhanced_mode) { 3237 + if ((dev->quirks & PLX_PCIE) && dev->enhanced_mode) { 3238 3238 u32 mask = (BIT(ENDPOINT_0_INTERRUPT) | 3239 3239 USB3380_IRQSTAT0_EP_INTR_MASK_IN | 3240 3240 USB3380_IRQSTAT0_EP_INTR_MASK_OUT); ··· 3399 3399 writel(tmp, &dma->dmastat); 3400 3400 3401 3401 /* dma sync*/ 3402 - if (dev->quirks & PLX_SUPERSPEED) { 3402 + if (dev->quirks & PLX_PCIE) { 3403 3403 u32 r_dmacount = readl(&dma->dmacount); 3404 3404 if (!ep->is_in && (r_dmacount & 0x00FFFFFF) && 3405 3405 (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) ··· 3468 3468 /* control requests and PIO */ 3469 3469 handle_stat0_irqs(dev, readl(&dev->regs->irqstat0)); 3470 3470 3471 - if (dev->quirks & PLX_SUPERSPEED) { 3471 + if (dev->quirks & PLX_PCIE) { 3472 3472 /* re-enable interrupt to trigger any possible new interrupt */ 3473 3473 u32 pciirqenb1 = readl(&dev->regs->pciirqenb1); 3474 3474 writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1); ··· 3513 3513 } 3514 3514 if (dev->got_irq) 3515 3515 free_irq(pdev->irq, dev); 3516 - if (dev->quirks & PLX_SUPERSPEED) 3516 + if (dev->quirks & PLX_PCIE) 3517 3517 pci_disable_msi(pdev); 3518 3518 if (dev->regs) 3519 3519 iounmap(dev->regs); ··· 3593 3593 dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200); 3594 3594 dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300); 3595 3595 3596 - if (dev->quirks & PLX_SUPERSPEED) { 3596 + if (dev->quirks & PLX_PCIE) { 3597 3597 u32 fsmvalue; 3598 3598 u32 usbstat; 3599 3599 dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *) ··· 3637 3637 goto done; 3638 3638 } 3639 3639 3640 - if (dev->quirks & PLX_SUPERSPEED) 3640 + if (dev->quirks & PLX_PCIE) 3641 3641 if (pci_enable_msi(pdev)) 3642 3642 ep_err(dev, "Failed to enable MSI mode\n"); 3643 3643 ··· 3755 3755 .class = PCI_CLASS_SERIAL_USB_DEVICE, 3756 3756 .class_mask = ~0, 3757 3757 .vendor = PCI_VENDOR_ID_PLX, 3758 + .device = 0x2380, 3759 + .subvendor = PCI_ANY_ID, 3760 + .subdevice = PCI_ANY_ID, 3761 + .driver_data = PLX_PCIE, 3762 + }, 3763 + { 3764 + .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), 3765 + .class_mask = ~0, 3766 + .vendor = PCI_VENDOR_ID_PLX, 3758 3767 .device = 0x3380, 3759 3768 .subvendor = PCI_ANY_ID, 3760 3769 .subdevice = PCI_ANY_ID, 3761 - .driver_data = PLX_SUPERSPEED, 3770 + .driver_data = PLX_PCIE | PLX_SUPERSPEED, 3762 3771 }, 3763 3772 { 3764 3773 .class = PCI_CLASS_SERIAL_USB_DEVICE, ··· 3776 3767 .device = 0x3382, 3777 3768 .subvendor = PCI_ANY_ID, 3778 3769 .subdevice = PCI_ANY_ID, 3779 - .driver_data = PLX_SUPERSPEED, 3770 + .driver_data = PLX_PCIE | PLX_SUPERSPEED, 3780 3771 }, 3781 3772 { /* end: all zeroes */ } 3782 3773 };
+1
drivers/usb/gadget/udc/net2280.h
··· 47 47 #define PLX_LEGACY BIT(0) 48 48 #define PLX_2280 BIT(1) 49 49 #define PLX_SUPERSPEED BIT(2) 50 + #define PLX_PCIE BIT(3) 50 51 51 52 #define REG_DIAG 0x0 52 53 #define RETRY_COUNTER 16
+15 -21
drivers/usb/gadget/udc/pch_udc.c
··· 1477 1477 req->dma_mapped = 0; 1478 1478 } 1479 1479 ep->halted = 1; 1480 - spin_lock(&dev->lock); 1480 + spin_unlock(&dev->lock); 1481 1481 if (!ep->in) 1482 1482 pch_udc_ep_clear_rrdy(ep); 1483 1483 usb_gadget_giveback_request(&ep->ep, &req->req); 1484 - spin_unlock(&dev->lock); 1484 + spin_lock(&dev->lock); 1485 1485 ep->halted = halted; 1486 1486 } 1487 1487 ··· 1984 1984 if (ep->num == PCH_UDC_EP0) 1985 1985 ep->dev->stall = 1; 1986 1986 pch_udc_ep_set_stall(ep); 1987 - pch_udc_enable_ep_interrupts(ep->dev, 1988 - PCH_UDC_EPINT(ep->in, 1989 - ep->num)); 1987 + pch_udc_enable_ep_interrupts( 1988 + ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); 1990 1989 } else { 1991 1990 pch_udc_ep_clear_stall(ep); 1992 1991 } ··· 2450 2451 */ 2451 2452 static void pch_udc_postsvc_epinters(struct pch_udc_dev *dev, int ep_num) 2452 2453 { 2453 - struct pch_udc_ep *ep; 2454 - struct pch_udc_request *req; 2455 - 2456 - ep = &dev->ep[UDC_EPIN_IDX(ep_num)]; 2457 - if (!list_empty(&ep->queue)) { 2458 - req = list_entry(ep->queue.next, struct pch_udc_request, queue); 2459 - pch_udc_enable_ep_interrupts(ep->dev, 2460 - PCH_UDC_EPINT(ep->in, ep->num)); 2461 - pch_udc_ep_clear_nak(ep); 2462 - } 2454 + struct pch_udc_ep *ep = &dev->ep[UDC_EPIN_IDX(ep_num)]; 2455 + if (list_empty(&ep->queue)) 2456 + return; 2457 + pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); 2458 + pch_udc_ep_clear_nak(ep); 2463 2459 } 2464 2460 2465 2461 /** ··· 2567 2573 empty_req_queue(ep); 2568 2574 } 2569 2575 if (dev->driver) { 2570 - spin_lock(&dev->lock); 2571 - usb_gadget_udc_reset(&dev->gadget, dev->driver); 2572 2576 spin_unlock(&dev->lock); 2577 + usb_gadget_udc_reset(&dev->gadget, dev->driver); 2578 + spin_lock(&dev->lock); 2573 2579 } 2574 2580 } 2575 2581 ··· 2648 2654 dev->ep[i].halted = 0; 2649 2655 } 2650 2656 dev->stall = 0; 2651 - spin_lock(&dev->lock); 2652 - dev->driver->setup(&dev->gadget, &dev->setup_data); 2653 2657 spin_unlock(&dev->lock); 2658 + dev->driver->setup(&dev->gadget, &dev->setup_data); 2659 + spin_lock(&dev->lock); 2654 2660 } 2655 2661 2656 2662 /** ··· 2685 2691 dev->stall = 0; 2686 2692 2687 2693 /* call gadget zero with setup data received */ 2688 - spin_lock(&dev->lock); 2689 - dev->driver->setup(&dev->gadget, &dev->setup_data); 2690 2694 spin_unlock(&dev->lock); 2695 + dev->driver->setup(&dev->gadget, &dev->setup_data); 2696 + spin_lock(&dev->lock); 2691 2697 } 2692 2698 2693 2699 /**
+3 -6
drivers/usb/gadget/udc/pxa27x_udc.c
··· 1825 1825 * Disables all udc endpoints (even control endpoint), report disconnect to 1826 1826 * the gadget user. 1827 1827 */ 1828 - static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver) 1828 + static void stop_activity(struct pxa_udc *udc) 1829 1829 { 1830 1830 int i; 1831 1831 1832 - /* don't disconnect drivers more than once */ 1833 - if (udc->gadget.speed == USB_SPEED_UNKNOWN) 1834 - driver = NULL; 1835 1832 udc->gadget.speed = USB_SPEED_UNKNOWN; 1836 1833 1837 1834 for (i = 0; i < NR_USB_ENDPOINTS; i++) ··· 1845 1848 { 1846 1849 struct pxa_udc *udc = to_pxa(g); 1847 1850 1848 - stop_activity(udc, NULL); 1851 + stop_activity(udc); 1849 1852 udc_disable(udc); 1850 1853 1851 1854 udc->driver = NULL; ··· 2293 2296 2294 2297 if ((udccr & UDCCR_UDA) == 0) { 2295 2298 dev_dbg(udc->dev, "USB reset start\n"); 2296 - stop_activity(udc, udc->driver); 2299 + stop_activity(udc); 2297 2300 } 2298 2301 udc->gadget.speed = USB_SPEED_FULL; 2299 2302 memset(&udc->stats, 0, sizeof udc->stats);
+6 -18
drivers/usb/gadget/udc/r8a66597-udc.c
··· 1464 1464 struct r8a66597 *r8a66597 = _r8a66597; 1465 1465 u16 intsts0; 1466 1466 u16 intenb0; 1467 - u16 brdysts, nrdysts, bempsts; 1468 - u16 brdyenb, nrdyenb, bempenb; 1469 1467 u16 savepipe; 1470 1468 u16 mask0; 1471 1469 ··· 1479 1481 1480 1482 mask0 = intsts0 & intenb0; 1481 1483 if (mask0) { 1482 - brdysts = r8a66597_read(r8a66597, BRDYSTS); 1483 - nrdysts = r8a66597_read(r8a66597, NRDYSTS); 1484 - bempsts = r8a66597_read(r8a66597, BEMPSTS); 1485 - brdyenb = r8a66597_read(r8a66597, BRDYENB); 1486 - nrdyenb = r8a66597_read(r8a66597, NRDYENB); 1487 - bempenb = r8a66597_read(r8a66597, BEMPENB); 1484 + u16 brdysts = r8a66597_read(r8a66597, BRDYSTS); 1485 + u16 bempsts = r8a66597_read(r8a66597, BEMPSTS); 1486 + u16 brdyenb = r8a66597_read(r8a66597, BRDYENB); 1487 + u16 bempenb = r8a66597_read(r8a66597, BEMPENB); 1488 1488 1489 1489 if (mask0 & VBINT) { 1490 1490 r8a66597_write(r8a66597, 0xffff & ~VBINT, ··· 1654 1658 1655 1659 static int r8a66597_set_halt(struct usb_ep *_ep, int value) 1656 1660 { 1657 - struct r8a66597_ep *ep; 1658 - struct r8a66597_request *req; 1661 + struct r8a66597_ep *ep = container_of(_ep, struct r8a66597_ep, ep); 1659 1662 unsigned long flags; 1660 1663 int ret = 0; 1661 - 1662 - ep = container_of(_ep, struct r8a66597_ep, ep); 1663 - req = get_request_from_ep(ep); 1664 1664 1665 1665 spin_lock_irqsave(&ep->r8a66597->lock, flags); 1666 1666 if (!list_empty(&ep->queue)) { 1667 1667 ret = -EAGAIN; 1668 - goto out; 1669 - } 1670 - if (value) { 1668 + } else if (value) { 1671 1669 ep->busy = 1; 1672 1670 pipe_stall(ep->r8a66597, ep->pipenum); 1673 1671 } else { ··· 1669 1679 ep->wedge = 0; 1670 1680 pipe_stop(ep->r8a66597, ep->pipenum); 1671 1681 } 1672 - 1673 - out: 1674 1682 spin_unlock_irqrestore(&ep->r8a66597->lock, flags); 1675 1683 return ret; 1676 1684 }
+18
drivers/usb/gadget/udc/trace.c
··· 1 + /** 2 + * trace.c - USB Gadget Framework Trace Support 3 + * 4 + * Copyright (C) 2016 Intel Corporation 5 + * Author: Felipe Balbi <felipe.balbi@linux.intel.com> 6 + * 7 + * This program is free software: you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 of 9 + * the License as published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #define CREATE_TRACE_POINTS 18 + #include "trace.h"
+298
drivers/usb/gadget/udc/trace.h
··· 1 + /** 2 + * udc.c - Core UDC Framework 3 + * 4 + * Copyright (C) 2016 Intel Corporation 5 + * Author: Felipe Balbi <felipe.balbi@linux.intel.com> 6 + * 7 + * This program is free software: you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 of 9 + * the License as published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #undef TRACE_SYSTEM 21 + #define TRACE_SYSTEM gadget 22 + 23 + #if !defined(__UDC_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) 24 + #define __UDC_TRACE_H 25 + 26 + #include <linux/types.h> 27 + #include <linux/tracepoint.h> 28 + #include <asm/byteorder.h> 29 + #include <linux/usb/gadget.h> 30 + 31 + DECLARE_EVENT_CLASS(udc_log_gadget, 32 + TP_PROTO(struct usb_gadget *g, int ret), 33 + TP_ARGS(g, ret), 34 + TP_STRUCT__entry( 35 + __field(enum usb_device_speed, speed) 36 + __field(enum usb_device_speed, max_speed) 37 + __field(enum usb_device_state, state) 38 + __field(unsigned, mA) 39 + __field(unsigned, sg_supported) 40 + __field(unsigned, is_otg) 41 + __field(unsigned, is_a_peripheral) 42 + __field(unsigned, b_hnp_enable) 43 + __field(unsigned, a_hnp_support) 44 + __field(unsigned, hnp_polling_support) 45 + __field(unsigned, host_request_flag) 46 + __field(unsigned, quirk_ep_out_aligned_size) 47 + __field(unsigned, quirk_altset_not_supp) 48 + __field(unsigned, quirk_stall_not_supp) 49 + __field(unsigned, quirk_zlp_not_supp) 50 + __field(unsigned, is_selfpowered) 51 + __field(unsigned, deactivated) 52 + __field(unsigned, connected) 53 + __field(int, ret) 54 + ), 55 + TP_fast_assign( 56 + __entry->speed = g->speed; 57 + __entry->max_speed = g->max_speed; 58 + __entry->state = g->state; 59 + __entry->mA = g->mA; 60 + __entry->sg_supported = g->sg_supported; 61 + __entry->is_otg = g->is_otg; 62 + __entry->is_a_peripheral = g->is_a_peripheral; 63 + __entry->b_hnp_enable = g->b_hnp_enable; 64 + __entry->a_hnp_support = g->a_hnp_support; 65 + __entry->hnp_polling_support = g->hnp_polling_support; 66 + __entry->host_request_flag = g->host_request_flag; 67 + __entry->quirk_ep_out_aligned_size = g->quirk_ep_out_aligned_size; 68 + __entry->quirk_altset_not_supp = g->quirk_altset_not_supp; 69 + __entry->quirk_stall_not_supp = g->quirk_stall_not_supp; 70 + __entry->quirk_zlp_not_supp = g->quirk_zlp_not_supp; 71 + __entry->is_selfpowered = g->is_selfpowered; 72 + __entry->deactivated = g->deactivated; 73 + __entry->connected = g->connected; 74 + __entry->ret = ret; 75 + ), 76 + TP_printk("speed %d/%d state %d %dmA [%s%s%s%s%s%s%s%s%s%s%s%s%s%s] --> %d", 77 + __entry->speed, __entry->max_speed, __entry->state, __entry->mA, 78 + __entry->sg_supported ? "sg:" : "", 79 + __entry->is_otg ? "OTG:" : "", 80 + __entry->is_a_peripheral ? "a_peripheral:" : "", 81 + __entry->b_hnp_enable ? "b_hnp:" : "", 82 + __entry->a_hnp_support ? "a_hnp:" : "", 83 + __entry->hnp_polling_support ? "hnp_poll:" : "", 84 + __entry->host_request_flag ? "hostreq:" : "", 85 + __entry->quirk_ep_out_aligned_size ? "out_aligned:" : "", 86 + __entry->quirk_altset_not_supp ? "no_altset:" : "", 87 + __entry->quirk_stall_not_supp ? "no_stall:" : "", 88 + __entry->quirk_zlp_not_supp ? "no_zlp" : "", 89 + __entry->is_selfpowered ? "self-powered:" : "bus-powered:", 90 + __entry->deactivated ? "deactivated:" : "activated:", 91 + __entry->connected ? "connected" : "disconnected", 92 + __entry->ret) 93 + ); 94 + 95 + DEFINE_EVENT(udc_log_gadget, usb_gadget_frame_number, 96 + TP_PROTO(struct usb_gadget *g, int ret), 97 + TP_ARGS(g, ret) 98 + ); 99 + 100 + DEFINE_EVENT(udc_log_gadget, usb_gadget_wakeup, 101 + TP_PROTO(struct usb_gadget *g, int ret), 102 + TP_ARGS(g, ret) 103 + ); 104 + 105 + DEFINE_EVENT(udc_log_gadget, usb_gadget_set_selfpowered, 106 + TP_PROTO(struct usb_gadget *g, int ret), 107 + TP_ARGS(g, ret) 108 + ); 109 + 110 + DEFINE_EVENT(udc_log_gadget, usb_gadget_clear_selfpowered, 111 + TP_PROTO(struct usb_gadget *g, int ret), 112 + TP_ARGS(g, ret) 113 + ); 114 + 115 + DEFINE_EVENT(udc_log_gadget, usb_gadget_vbus_connect, 116 + TP_PROTO(struct usb_gadget *g, int ret), 117 + TP_ARGS(g, ret) 118 + ); 119 + 120 + DEFINE_EVENT(udc_log_gadget, usb_gadget_vbus_draw, 121 + TP_PROTO(struct usb_gadget *g, int ret), 122 + TP_ARGS(g, ret) 123 + ); 124 + 125 + DEFINE_EVENT(udc_log_gadget, usb_gadget_vbus_disconnect, 126 + TP_PROTO(struct usb_gadget *g, int ret), 127 + TP_ARGS(g, ret) 128 + ); 129 + 130 + DEFINE_EVENT(udc_log_gadget, usb_gadget_connect, 131 + TP_PROTO(struct usb_gadget *g, int ret), 132 + TP_ARGS(g, ret) 133 + ); 134 + 135 + DEFINE_EVENT(udc_log_gadget, usb_gadget_disconnect, 136 + TP_PROTO(struct usb_gadget *g, int ret), 137 + TP_ARGS(g, ret) 138 + ); 139 + 140 + DEFINE_EVENT(udc_log_gadget, usb_gadget_deactivate, 141 + TP_PROTO(struct usb_gadget *g, int ret), 142 + TP_ARGS(g, ret) 143 + ); 144 + 145 + DEFINE_EVENT(udc_log_gadget, usb_gadget_activate, 146 + TP_PROTO(struct usb_gadget *g, int ret), 147 + TP_ARGS(g, ret) 148 + ); 149 + 150 + DECLARE_EVENT_CLASS(udc_log_ep, 151 + TP_PROTO(struct usb_ep *ep, int ret), 152 + TP_ARGS(ep, ret), 153 + TP_STRUCT__entry( 154 + __dynamic_array(char, name, UDC_TRACE_STR_MAX) 155 + __field(unsigned, maxpacket) 156 + __field(unsigned, maxpacket_limit) 157 + __field(unsigned, max_streams) 158 + __field(unsigned, mult) 159 + __field(unsigned, maxburst) 160 + __field(u8, address) 161 + __field(bool, claimed) 162 + __field(bool, enabled) 163 + __field(int, ret) 164 + ), 165 + TP_fast_assign( 166 + snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name); 167 + __entry->maxpacket = ep->maxpacket; 168 + __entry->maxpacket_limit = ep->maxpacket_limit; 169 + __entry->max_streams = ep->max_streams; 170 + __entry->mult = ep->mult; 171 + __entry->maxburst = ep->maxburst; 172 + __entry->address = ep->address, 173 + __entry->claimed = ep->claimed; 174 + __entry->enabled = ep->enabled; 175 + __entry->ret = ret; 176 + ), 177 + TP_printk("%s: mps %d/%d streams %d mult %d burst %d addr %02x %s%s --> %d", 178 + __get_str(name), __entry->maxpacket, __entry->maxpacket_limit, 179 + __entry->max_streams, __entry->mult, __entry->maxburst, 180 + __entry->address, __entry->claimed ? "claimed:" : "released:", 181 + __entry->enabled ? "enabled" : "disabled", ret) 182 + ); 183 + 184 + DEFINE_EVENT(udc_log_ep, usb_ep_set_maxpacket_limit, 185 + TP_PROTO(struct usb_ep *ep, int ret), 186 + TP_ARGS(ep, ret) 187 + ); 188 + 189 + DEFINE_EVENT(udc_log_ep, usb_ep_enable, 190 + TP_PROTO(struct usb_ep *ep, int ret), 191 + TP_ARGS(ep, ret) 192 + ); 193 + 194 + DEFINE_EVENT(udc_log_ep, usb_ep_disable, 195 + TP_PROTO(struct usb_ep *ep, int ret), 196 + TP_ARGS(ep, ret) 197 + ); 198 + 199 + DEFINE_EVENT(udc_log_ep, usb_ep_set_halt, 200 + TP_PROTO(struct usb_ep *ep, int ret), 201 + TP_ARGS(ep, ret) 202 + ); 203 + 204 + DEFINE_EVENT(udc_log_ep, usb_ep_clear_halt, 205 + TP_PROTO(struct usb_ep *ep, int ret), 206 + TP_ARGS(ep, ret) 207 + ); 208 + 209 + DEFINE_EVENT(udc_log_ep, usb_ep_set_wedge, 210 + TP_PROTO(struct usb_ep *ep, int ret), 211 + TP_ARGS(ep, ret) 212 + ); 213 + 214 + DEFINE_EVENT(udc_log_ep, usb_ep_fifo_status, 215 + TP_PROTO(struct usb_ep *ep, int ret), 216 + TP_ARGS(ep, ret) 217 + ); 218 + 219 + DEFINE_EVENT(udc_log_ep, usb_ep_fifo_flush, 220 + TP_PROTO(struct usb_ep *ep, int ret), 221 + TP_ARGS(ep, ret) 222 + ); 223 + 224 + DECLARE_EVENT_CLASS(udc_log_req, 225 + TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret), 226 + TP_ARGS(ep, req, ret), 227 + TP_STRUCT__entry( 228 + __dynamic_array(char, name, UDC_TRACE_STR_MAX) 229 + __field(unsigned, length) 230 + __field(unsigned, actual) 231 + __field(unsigned, num_sgs) 232 + __field(unsigned, num_mapped_sgs) 233 + __field(unsigned, stream_id) 234 + __field(unsigned, no_interrupt) 235 + __field(unsigned, zero) 236 + __field(unsigned, short_not_ok) 237 + __field(int, status) 238 + __field(int, ret) 239 + ), 240 + TP_fast_assign( 241 + snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name); 242 + __entry->length = req->length; 243 + __entry->actual = req->actual; 244 + __entry->num_sgs = req->num_sgs; 245 + __entry->num_mapped_sgs = req->num_mapped_sgs; 246 + __entry->stream_id = req->stream_id; 247 + __entry->no_interrupt = req->no_interrupt; 248 + __entry->zero = req->zero; 249 + __entry->short_not_ok = req->short_not_ok; 250 + __entry->status = req->status; 251 + __entry->ret = ret; 252 + ), 253 + TP_printk("%s: length %d/%d sgs %d/%d stream %d %s%s%s status %d --> %d", 254 + __get_str(name), __entry->actual, __entry->length, 255 + __entry->num_mapped_sgs, __entry->num_sgs, __entry->stream_id, 256 + __entry->zero ? "Z" : "z", 257 + __entry->short_not_ok ? "S" : "s", 258 + __entry->no_interrupt ? "i" : "I", 259 + __entry->status, __entry->ret 260 + ) 261 + ); 262 + 263 + DEFINE_EVENT(udc_log_req, usb_ep_alloc_request, 264 + TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret), 265 + TP_ARGS(ep, req, ret) 266 + ); 267 + 268 + DEFINE_EVENT(udc_log_req, usb_ep_free_request, 269 + TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret), 270 + TP_ARGS(ep, req, ret) 271 + ); 272 + 273 + DEFINE_EVENT(udc_log_req, usb_ep_queue, 274 + TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret), 275 + TP_ARGS(ep, req, ret) 276 + ); 277 + 278 + DEFINE_EVENT(udc_log_req, usb_ep_dequeue, 279 + TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret), 280 + TP_ARGS(ep, req, ret) 281 + ); 282 + 283 + DEFINE_EVENT(udc_log_req, usb_gadget_giveback_request, 284 + TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret), 285 + TP_ARGS(ep, req, ret) 286 + ); 287 + 288 + #endif /* __UDC_TRACE_H */ 289 + 290 + /* this part has to be here */ 291 + 292 + #undef TRACE_INCLUDE_PATH 293 + #define TRACE_INCLUDE_PATH . 294 + 295 + #undef TRACE_INCLUDE_FILE 296 + #define TRACE_INCLUDE_FILE trace 297 + 298 + #include <trace/define_trace.h>
-800
drivers/usb/gadget/udc/udc-core.c
··· 1 - /** 2 - * udc.c - Core UDC Framework 3 - * 4 - * Copyright (C) 2010 Texas Instruments 5 - * Author: Felipe Balbi <balbi@ti.com> 6 - * 7 - * This program is free software: you can redistribute it and/or modify 8 - * it under the terms of the GNU General Public License version 2 of 9 - * the License as published by the Free Software Foundation. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 - */ 19 - 20 - #include <linux/kernel.h> 21 - #include <linux/module.h> 22 - #include <linux/device.h> 23 - #include <linux/list.h> 24 - #include <linux/err.h> 25 - #include <linux/dma-mapping.h> 26 - #include <linux/workqueue.h> 27 - 28 - #include <linux/usb/ch9.h> 29 - #include <linux/usb/gadget.h> 30 - #include <linux/usb.h> 31 - 32 - /** 33 - * struct usb_udc - describes one usb device controller 34 - * @driver - the gadget driver pointer. For use by the class code 35 - * @dev - the child device to the actual controller 36 - * @gadget - the gadget. For use by the class code 37 - * @list - for use by the udc class driver 38 - * @vbus - for udcs who care about vbus status, this value is real vbus status; 39 - * for udcs who do not care about vbus status, this value is always true 40 - * 41 - * This represents the internal data structure which is used by the UDC-class 42 - * to hold information about udc driver and gadget together. 43 - */ 44 - struct usb_udc { 45 - struct usb_gadget_driver *driver; 46 - struct usb_gadget *gadget; 47 - struct device dev; 48 - struct list_head list; 49 - bool vbus; 50 - }; 51 - 52 - static struct class *udc_class; 53 - static LIST_HEAD(udc_list); 54 - static LIST_HEAD(gadget_driver_pending_list); 55 - static DEFINE_MUTEX(udc_lock); 56 - 57 - static int udc_bind_to_driver(struct usb_udc *udc, 58 - struct usb_gadget_driver *driver); 59 - 60 - /* ------------------------------------------------------------------------- */ 61 - 62 - #ifdef CONFIG_HAS_DMA 63 - 64 - int usb_gadget_map_request_by_dev(struct device *dev, 65 - struct usb_request *req, int is_in) 66 - { 67 - if (req->length == 0) 68 - return 0; 69 - 70 - if (req->num_sgs) { 71 - int mapped; 72 - 73 - mapped = dma_map_sg(dev, req->sg, req->num_sgs, 74 - is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 75 - if (mapped == 0) { 76 - dev_err(dev, "failed to map SGs\n"); 77 - return -EFAULT; 78 - } 79 - 80 - req->num_mapped_sgs = mapped; 81 - } else { 82 - req->dma = dma_map_single(dev, req->buf, req->length, 83 - is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 84 - 85 - if (dma_mapping_error(dev, req->dma)) { 86 - dev_err(dev, "failed to map buffer\n"); 87 - return -EFAULT; 88 - } 89 - } 90 - 91 - return 0; 92 - } 93 - EXPORT_SYMBOL_GPL(usb_gadget_map_request_by_dev); 94 - 95 - int usb_gadget_map_request(struct usb_gadget *gadget, 96 - struct usb_request *req, int is_in) 97 - { 98 - return usb_gadget_map_request_by_dev(gadget->dev.parent, req, is_in); 99 - } 100 - EXPORT_SYMBOL_GPL(usb_gadget_map_request); 101 - 102 - void usb_gadget_unmap_request_by_dev(struct device *dev, 103 - struct usb_request *req, int is_in) 104 - { 105 - if (req->length == 0) 106 - return; 107 - 108 - if (req->num_mapped_sgs) { 109 - dma_unmap_sg(dev, req->sg, req->num_mapped_sgs, 110 - is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 111 - 112 - req->num_mapped_sgs = 0; 113 - } else { 114 - dma_unmap_single(dev, req->dma, req->length, 115 - is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 116 - } 117 - } 118 - EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev); 119 - 120 - void usb_gadget_unmap_request(struct usb_gadget *gadget, 121 - struct usb_request *req, int is_in) 122 - { 123 - usb_gadget_unmap_request_by_dev(gadget->dev.parent, req, is_in); 124 - } 125 - EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); 126 - 127 - #endif /* CONFIG_HAS_DMA */ 128 - 129 - /* ------------------------------------------------------------------------- */ 130 - 131 - /** 132 - * usb_gadget_giveback_request - give the request back to the gadget layer 133 - * Context: in_interrupt() 134 - * 135 - * This is called by device controller drivers in order to return the 136 - * completed request back to the gadget layer. 137 - */ 138 - void usb_gadget_giveback_request(struct usb_ep *ep, 139 - struct usb_request *req) 140 - { 141 - if (likely(req->status == 0)) 142 - usb_led_activity(USB_LED_EVENT_GADGET); 143 - 144 - req->complete(ep, req); 145 - } 146 - EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); 147 - 148 - /* ------------------------------------------------------------------------- */ 149 - 150 - /** 151 - * gadget_find_ep_by_name - returns ep whose name is the same as sting passed 152 - * in second parameter or NULL if searched endpoint not found 153 - * @g: controller to check for quirk 154 - * @name: name of searched endpoint 155 - */ 156 - struct usb_ep *gadget_find_ep_by_name(struct usb_gadget *g, const char *name) 157 - { 158 - struct usb_ep *ep; 159 - 160 - gadget_for_each_ep(ep, g) { 161 - if (!strcmp(ep->name, name)) 162 - return ep; 163 - } 164 - 165 - return NULL; 166 - } 167 - EXPORT_SYMBOL_GPL(gadget_find_ep_by_name); 168 - 169 - /* ------------------------------------------------------------------------- */ 170 - 171 - int usb_gadget_ep_match_desc(struct usb_gadget *gadget, 172 - struct usb_ep *ep, struct usb_endpoint_descriptor *desc, 173 - struct usb_ss_ep_comp_descriptor *ep_comp) 174 - { 175 - u8 type; 176 - u16 max; 177 - int num_req_streams = 0; 178 - 179 - /* endpoint already claimed? */ 180 - if (ep->claimed) 181 - return 0; 182 - 183 - type = usb_endpoint_type(desc); 184 - max = 0x7ff & usb_endpoint_maxp(desc); 185 - 186 - if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in) 187 - return 0; 188 - if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out) 189 - return 0; 190 - 191 - if (max > ep->maxpacket_limit) 192 - return 0; 193 - 194 - /* "high bandwidth" works only at high speed */ 195 - if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11)) 196 - return 0; 197 - 198 - switch (type) { 199 - case USB_ENDPOINT_XFER_CONTROL: 200 - /* only support ep0 for portable CONTROL traffic */ 201 - return 0; 202 - case USB_ENDPOINT_XFER_ISOC: 203 - if (!ep->caps.type_iso) 204 - return 0; 205 - /* ISO: limit 1023 bytes full speed, 1024 high/super speed */ 206 - if (!gadget_is_dualspeed(gadget) && max > 1023) 207 - return 0; 208 - break; 209 - case USB_ENDPOINT_XFER_BULK: 210 - if (!ep->caps.type_bulk) 211 - return 0; 212 - if (ep_comp && gadget_is_superspeed(gadget)) { 213 - /* Get the number of required streams from the 214 - * EP companion descriptor and see if the EP 215 - * matches it 216 - */ 217 - num_req_streams = ep_comp->bmAttributes & 0x1f; 218 - if (num_req_streams > ep->max_streams) 219 - return 0; 220 - } 221 - break; 222 - case USB_ENDPOINT_XFER_INT: 223 - /* Bulk endpoints handle interrupt transfers, 224 - * except the toggle-quirky iso-synch kind 225 - */ 226 - if (!ep->caps.type_int && !ep->caps.type_bulk) 227 - return 0; 228 - /* INT: limit 64 bytes full speed, 1024 high/super speed */ 229 - if (!gadget_is_dualspeed(gadget) && max > 64) 230 - return 0; 231 - break; 232 - } 233 - 234 - return 1; 235 - } 236 - EXPORT_SYMBOL_GPL(usb_gadget_ep_match_desc); 237 - 238 - /* ------------------------------------------------------------------------- */ 239 - 240 - static void usb_gadget_state_work(struct work_struct *work) 241 - { 242 - struct usb_gadget *gadget = work_to_gadget(work); 243 - struct usb_udc *udc = gadget->udc; 244 - 245 - if (udc) 246 - sysfs_notify(&udc->dev.kobj, NULL, "state"); 247 - } 248 - 249 - void usb_gadget_set_state(struct usb_gadget *gadget, 250 - enum usb_device_state state) 251 - { 252 - gadget->state = state; 253 - schedule_work(&gadget->work); 254 - } 255 - EXPORT_SYMBOL_GPL(usb_gadget_set_state); 256 - 257 - /* ------------------------------------------------------------------------- */ 258 - 259 - static void usb_udc_connect_control(struct usb_udc *udc) 260 - { 261 - if (udc->vbus) 262 - usb_gadget_connect(udc->gadget); 263 - else 264 - usb_gadget_disconnect(udc->gadget); 265 - } 266 - 267 - /** 268 - * usb_udc_vbus_handler - updates the udc core vbus status, and try to 269 - * connect or disconnect gadget 270 - * @gadget: The gadget which vbus change occurs 271 - * @status: The vbus status 272 - * 273 - * The udc driver calls it when it wants to connect or disconnect gadget 274 - * according to vbus status. 275 - */ 276 - void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) 277 - { 278 - struct usb_udc *udc = gadget->udc; 279 - 280 - if (udc) { 281 - udc->vbus = status; 282 - usb_udc_connect_control(udc); 283 - } 284 - } 285 - EXPORT_SYMBOL_GPL(usb_udc_vbus_handler); 286 - 287 - /** 288 - * usb_gadget_udc_reset - notifies the udc core that bus reset occurs 289 - * @gadget: The gadget which bus reset occurs 290 - * @driver: The gadget driver we want to notify 291 - * 292 - * If the udc driver has bus reset handler, it needs to call this when the bus 293 - * reset occurs, it notifies the gadget driver that the bus reset occurs as 294 - * well as updates gadget state. 295 - */ 296 - void usb_gadget_udc_reset(struct usb_gadget *gadget, 297 - struct usb_gadget_driver *driver) 298 - { 299 - driver->reset(gadget); 300 - usb_gadget_set_state(gadget, USB_STATE_DEFAULT); 301 - } 302 - EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); 303 - 304 - /** 305 - * usb_gadget_udc_start - tells usb device controller to start up 306 - * @udc: The UDC to be started 307 - * 308 - * This call is issued by the UDC Class driver when it's about 309 - * to register a gadget driver to the device controller, before 310 - * calling gadget driver's bind() method. 311 - * 312 - * It allows the controller to be powered off until strictly 313 - * necessary to have it powered on. 314 - * 315 - * Returns zero on success, else negative errno. 316 - */ 317 - static inline int usb_gadget_udc_start(struct usb_udc *udc) 318 - { 319 - return udc->gadget->ops->udc_start(udc->gadget, udc->driver); 320 - } 321 - 322 - /** 323 - * usb_gadget_udc_stop - tells usb device controller we don't need it anymore 324 - * @gadget: The device we want to stop activity 325 - * @driver: The driver to unbind from @gadget 326 - * 327 - * This call is issued by the UDC Class driver after calling 328 - * gadget driver's unbind() method. 329 - * 330 - * The details are implementation specific, but it can go as 331 - * far as powering off UDC completely and disable its data 332 - * line pullups. 333 - */ 334 - static inline void usb_gadget_udc_stop(struct usb_udc *udc) 335 - { 336 - udc->gadget->ops->udc_stop(udc->gadget); 337 - } 338 - 339 - /** 340 - * usb_udc_release - release the usb_udc struct 341 - * @dev: the dev member within usb_udc 342 - * 343 - * This is called by driver's core in order to free memory once the last 344 - * reference is released. 345 - */ 346 - static void usb_udc_release(struct device *dev) 347 - { 348 - struct usb_udc *udc; 349 - 350 - udc = container_of(dev, struct usb_udc, dev); 351 - dev_dbg(dev, "releasing '%s'\n", dev_name(dev)); 352 - kfree(udc); 353 - } 354 - 355 - static const struct attribute_group *usb_udc_attr_groups[]; 356 - 357 - static void usb_udc_nop_release(struct device *dev) 358 - { 359 - dev_vdbg(dev, "%s\n", __func__); 360 - } 361 - 362 - /** 363 - * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list 364 - * @parent: the parent device to this udc. Usually the controller driver's 365 - * device. 366 - * @gadget: the gadget to be added to the list. 367 - * @release: a gadget release function. 368 - * 369 - * Returns zero on success, negative errno otherwise. 370 - */ 371 - int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, 372 - void (*release)(struct device *dev)) 373 - { 374 - struct usb_udc *udc; 375 - struct usb_gadget_driver *driver; 376 - int ret = -ENOMEM; 377 - 378 - udc = kzalloc(sizeof(*udc), GFP_KERNEL); 379 - if (!udc) 380 - goto err1; 381 - 382 - dev_set_name(&gadget->dev, "gadget"); 383 - INIT_WORK(&gadget->work, usb_gadget_state_work); 384 - gadget->dev.parent = parent; 385 - 386 - if (release) 387 - gadget->dev.release = release; 388 - else 389 - gadget->dev.release = usb_udc_nop_release; 390 - 391 - ret = device_register(&gadget->dev); 392 - if (ret) 393 - goto err2; 394 - 395 - device_initialize(&udc->dev); 396 - udc->dev.release = usb_udc_release; 397 - udc->dev.class = udc_class; 398 - udc->dev.groups = usb_udc_attr_groups; 399 - udc->dev.parent = parent; 400 - ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); 401 - if (ret) 402 - goto err3; 403 - 404 - udc->gadget = gadget; 405 - gadget->udc = udc; 406 - 407 - mutex_lock(&udc_lock); 408 - list_add_tail(&udc->list, &udc_list); 409 - 410 - ret = device_add(&udc->dev); 411 - if (ret) 412 - goto err4; 413 - 414 - usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); 415 - udc->vbus = true; 416 - 417 - /* pick up one of pending gadget drivers */ 418 - list_for_each_entry(driver, &gadget_driver_pending_list, pending) { 419 - if (!driver->udc_name || strcmp(driver->udc_name, 420 - dev_name(&udc->dev)) == 0) { 421 - ret = udc_bind_to_driver(udc, driver); 422 - if (ret != -EPROBE_DEFER) 423 - list_del(&driver->pending); 424 - if (ret) 425 - goto err4; 426 - break; 427 - } 428 - } 429 - 430 - mutex_unlock(&udc_lock); 431 - 432 - return 0; 433 - 434 - err4: 435 - list_del(&udc->list); 436 - mutex_unlock(&udc_lock); 437 - 438 - err3: 439 - put_device(&udc->dev); 440 - device_del(&gadget->dev); 441 - 442 - err2: 443 - put_device(&gadget->dev); 444 - kfree(udc); 445 - 446 - err1: 447 - return ret; 448 - } 449 - EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); 450 - 451 - /** 452 - * usb_get_gadget_udc_name - get the name of the first UDC controller 453 - * This functions returns the name of the first UDC controller in the system. 454 - * Please note that this interface is usefull only for legacy drivers which 455 - * assume that there is only one UDC controller in the system and they need to 456 - * get its name before initialization. There is no guarantee that the UDC 457 - * of the returned name will be still available, when gadget driver registers 458 - * itself. 459 - * 460 - * Returns pointer to string with UDC controller name on success, NULL 461 - * otherwise. Caller should kfree() returned string. 462 - */ 463 - char *usb_get_gadget_udc_name(void) 464 - { 465 - struct usb_udc *udc; 466 - char *name = NULL; 467 - 468 - /* For now we take the first available UDC */ 469 - mutex_lock(&udc_lock); 470 - list_for_each_entry(udc, &udc_list, list) { 471 - if (!udc->driver) { 472 - name = kstrdup(udc->gadget->name, GFP_KERNEL); 473 - break; 474 - } 475 - } 476 - mutex_unlock(&udc_lock); 477 - return name; 478 - } 479 - EXPORT_SYMBOL_GPL(usb_get_gadget_udc_name); 480 - 481 - /** 482 - * usb_add_gadget_udc - adds a new gadget to the udc class driver list 483 - * @parent: the parent device to this udc. Usually the controller 484 - * driver's device. 485 - * @gadget: the gadget to be added to the list 486 - * 487 - * Returns zero on success, negative errno otherwise. 488 - */ 489 - int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) 490 - { 491 - return usb_add_gadget_udc_release(parent, gadget, NULL); 492 - } 493 - EXPORT_SYMBOL_GPL(usb_add_gadget_udc); 494 - 495 - static void usb_gadget_remove_driver(struct usb_udc *udc) 496 - { 497 - dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n", 498 - udc->driver->function); 499 - 500 - kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 501 - 502 - usb_gadget_disconnect(udc->gadget); 503 - udc->driver->disconnect(udc->gadget); 504 - udc->driver->unbind(udc->gadget); 505 - usb_gadget_udc_stop(udc); 506 - 507 - udc->driver = NULL; 508 - udc->dev.driver = NULL; 509 - udc->gadget->dev.driver = NULL; 510 - } 511 - 512 - /** 513 - * usb_del_gadget_udc - deletes @udc from udc_list 514 - * @gadget: the gadget to be removed. 515 - * 516 - * This, will call usb_gadget_unregister_driver() if 517 - * the @udc is still busy. 518 - */ 519 - void usb_del_gadget_udc(struct usb_gadget *gadget) 520 - { 521 - struct usb_udc *udc = gadget->udc; 522 - 523 - if (!udc) 524 - return; 525 - 526 - dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); 527 - 528 - mutex_lock(&udc_lock); 529 - list_del(&udc->list); 530 - 531 - if (udc->driver) { 532 - struct usb_gadget_driver *driver = udc->driver; 533 - 534 - usb_gadget_remove_driver(udc); 535 - list_add(&driver->pending, &gadget_driver_pending_list); 536 - } 537 - mutex_unlock(&udc_lock); 538 - 539 - kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 540 - flush_work(&gadget->work); 541 - device_unregister(&udc->dev); 542 - device_unregister(&gadget->dev); 543 - } 544 - EXPORT_SYMBOL_GPL(usb_del_gadget_udc); 545 - 546 - /* ------------------------------------------------------------------------- */ 547 - 548 - static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver) 549 - { 550 - int ret; 551 - 552 - dev_dbg(&udc->dev, "registering UDC driver [%s]\n", 553 - driver->function); 554 - 555 - udc->driver = driver; 556 - udc->dev.driver = &driver->driver; 557 - udc->gadget->dev.driver = &driver->driver; 558 - 559 - ret = driver->bind(udc->gadget, driver); 560 - if (ret) 561 - goto err1; 562 - ret = usb_gadget_udc_start(udc); 563 - if (ret) { 564 - driver->unbind(udc->gadget); 565 - goto err1; 566 - } 567 - usb_udc_connect_control(udc); 568 - 569 - kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 570 - return 0; 571 - err1: 572 - if (ret != -EISNAM) 573 - dev_err(&udc->dev, "failed to start %s: %d\n", 574 - udc->driver->function, ret); 575 - udc->driver = NULL; 576 - udc->dev.driver = NULL; 577 - udc->gadget->dev.driver = NULL; 578 - return ret; 579 - } 580 - 581 - int usb_gadget_probe_driver(struct usb_gadget_driver *driver) 582 - { 583 - struct usb_udc *udc = NULL; 584 - int ret = -ENODEV; 585 - 586 - if (!driver || !driver->bind || !driver->setup) 587 - return -EINVAL; 588 - 589 - mutex_lock(&udc_lock); 590 - if (driver->udc_name) { 591 - list_for_each_entry(udc, &udc_list, list) { 592 - ret = strcmp(driver->udc_name, dev_name(&udc->dev)); 593 - if (!ret) 594 - break; 595 - } 596 - if (!ret && !udc->driver) 597 - goto found; 598 - } else { 599 - list_for_each_entry(udc, &udc_list, list) { 600 - /* For now we take the first one */ 601 - if (!udc->driver) 602 - goto found; 603 - } 604 - } 605 - 606 - if (!driver->match_existing_only) { 607 - list_add_tail(&driver->pending, &gadget_driver_pending_list); 608 - pr_info("udc-core: couldn't find an available UDC - added [%s] to list of pending drivers\n", 609 - driver->function); 610 - ret = 0; 611 - } 612 - 613 - mutex_unlock(&udc_lock); 614 - return ret; 615 - found: 616 - ret = udc_bind_to_driver(udc, driver); 617 - mutex_unlock(&udc_lock); 618 - return ret; 619 - } 620 - EXPORT_SYMBOL_GPL(usb_gadget_probe_driver); 621 - 622 - int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 623 - { 624 - struct usb_udc *udc = NULL; 625 - int ret = -ENODEV; 626 - 627 - if (!driver || !driver->unbind) 628 - return -EINVAL; 629 - 630 - mutex_lock(&udc_lock); 631 - list_for_each_entry(udc, &udc_list, list) 632 - if (udc->driver == driver) { 633 - usb_gadget_remove_driver(udc); 634 - usb_gadget_set_state(udc->gadget, 635 - USB_STATE_NOTATTACHED); 636 - ret = 0; 637 - break; 638 - } 639 - 640 - if (ret) { 641 - list_del(&driver->pending); 642 - ret = 0; 643 - } 644 - mutex_unlock(&udc_lock); 645 - return ret; 646 - } 647 - EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver); 648 - 649 - /* ------------------------------------------------------------------------- */ 650 - 651 - static ssize_t usb_udc_srp_store(struct device *dev, 652 - struct device_attribute *attr, const char *buf, size_t n) 653 - { 654 - struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 655 - 656 - if (sysfs_streq(buf, "1")) 657 - usb_gadget_wakeup(udc->gadget); 658 - 659 - return n; 660 - } 661 - static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store); 662 - 663 - static ssize_t usb_udc_softconn_store(struct device *dev, 664 - struct device_attribute *attr, const char *buf, size_t n) 665 - { 666 - struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 667 - 668 - if (!udc->driver) { 669 - dev_err(dev, "soft-connect without a gadget driver\n"); 670 - return -EOPNOTSUPP; 671 - } 672 - 673 - if (sysfs_streq(buf, "connect")) { 674 - usb_gadget_udc_start(udc); 675 - usb_gadget_connect(udc->gadget); 676 - } else if (sysfs_streq(buf, "disconnect")) { 677 - usb_gadget_disconnect(udc->gadget); 678 - udc->driver->disconnect(udc->gadget); 679 - usb_gadget_udc_stop(udc); 680 - } else { 681 - dev_err(dev, "unsupported command '%s'\n", buf); 682 - return -EINVAL; 683 - } 684 - 685 - return n; 686 - } 687 - static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); 688 - 689 - static ssize_t state_show(struct device *dev, struct device_attribute *attr, 690 - char *buf) 691 - { 692 - struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 693 - struct usb_gadget *gadget = udc->gadget; 694 - 695 - return sprintf(buf, "%s\n", usb_state_string(gadget->state)); 696 - } 697 - static DEVICE_ATTR_RO(state); 698 - 699 - #define USB_UDC_SPEED_ATTR(name, param) \ 700 - ssize_t name##_show(struct device *dev, \ 701 - struct device_attribute *attr, char *buf) \ 702 - { \ 703 - struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ 704 - return snprintf(buf, PAGE_SIZE, "%s\n", \ 705 - usb_speed_string(udc->gadget->param)); \ 706 - } \ 707 - static DEVICE_ATTR_RO(name) 708 - 709 - static USB_UDC_SPEED_ATTR(current_speed, speed); 710 - static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); 711 - 712 - #define USB_UDC_ATTR(name) \ 713 - ssize_t name##_show(struct device *dev, \ 714 - struct device_attribute *attr, char *buf) \ 715 - { \ 716 - struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \ 717 - struct usb_gadget *gadget = udc->gadget; \ 718 - \ 719 - return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ 720 - } \ 721 - static DEVICE_ATTR_RO(name) 722 - 723 - static USB_UDC_ATTR(is_otg); 724 - static USB_UDC_ATTR(is_a_peripheral); 725 - static USB_UDC_ATTR(b_hnp_enable); 726 - static USB_UDC_ATTR(a_hnp_support); 727 - static USB_UDC_ATTR(a_alt_hnp_support); 728 - static USB_UDC_ATTR(is_selfpowered); 729 - 730 - static struct attribute *usb_udc_attrs[] = { 731 - &dev_attr_srp.attr, 732 - &dev_attr_soft_connect.attr, 733 - &dev_attr_state.attr, 734 - &dev_attr_current_speed.attr, 735 - &dev_attr_maximum_speed.attr, 736 - 737 - &dev_attr_is_otg.attr, 738 - &dev_attr_is_a_peripheral.attr, 739 - &dev_attr_b_hnp_enable.attr, 740 - &dev_attr_a_hnp_support.attr, 741 - &dev_attr_a_alt_hnp_support.attr, 742 - &dev_attr_is_selfpowered.attr, 743 - NULL, 744 - }; 745 - 746 - static const struct attribute_group usb_udc_attr_group = { 747 - .attrs = usb_udc_attrs, 748 - }; 749 - 750 - static const struct attribute_group *usb_udc_attr_groups[] = { 751 - &usb_udc_attr_group, 752 - NULL, 753 - }; 754 - 755 - static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env) 756 - { 757 - struct usb_udc *udc = container_of(dev, struct usb_udc, dev); 758 - int ret; 759 - 760 - ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); 761 - if (ret) { 762 - dev_err(dev, "failed to add uevent USB_UDC_NAME\n"); 763 - return ret; 764 - } 765 - 766 - if (udc->driver) { 767 - ret = add_uevent_var(env, "USB_UDC_DRIVER=%s", 768 - udc->driver->function); 769 - if (ret) { 770 - dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n"); 771 - return ret; 772 - } 773 - } 774 - 775 - return 0; 776 - } 777 - 778 - static int __init usb_udc_init(void) 779 - { 780 - udc_class = class_create(THIS_MODULE, "udc"); 781 - if (IS_ERR(udc_class)) { 782 - pr_err("failed to create udc class --> %ld\n", 783 - PTR_ERR(udc_class)); 784 - return PTR_ERR(udc_class); 785 - } 786 - 787 - udc_class->dev_uevent = usb_udc_uevent; 788 - return 0; 789 - } 790 - subsys_initcall(usb_udc_init); 791 - 792 - static void __exit usb_udc_exit(void) 793 - { 794 - class_destroy(udc_class); 795 - } 796 - module_exit(usb_udc_exit); 797 - 798 - MODULE_DESCRIPTION("UDC Framework"); 799 - MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 800 - MODULE_LICENSE("GPL v2");
-3
drivers/usb/gadget/udc/udc-xilinx.c
··· 2055 2055 struct device_node *np = pdev->dev.of_node; 2056 2056 struct resource *res; 2057 2057 struct xusb_udc *udc; 2058 - struct xusb_ep *ep0; 2059 2058 int irq; 2060 2059 int ret; 2061 2060 u32 ier; ··· 2117 2118 udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); 2118 2119 2119 2120 xudc_eps_init(udc); 2120 - 2121 - ep0 = &udc->ep[0]; 2122 2121 2123 2122 /* Set device address to 0.*/ 2124 2123 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0);
+1 -1
drivers/usb/host/Kconfig
··· 180 180 config USB_EHCI_HCD_OMAP 181 181 tristate "EHCI support for OMAP3 and later chips" 182 182 depends on ARCH_OMAP 183 - select NOP_USB_XCEIV 183 + depends on NOP_USB_XCEIV 184 184 default y 185 185 ---help--- 186 186 Enables support for the on-chip EHCI controller on
+9 -2
drivers/usb/phy/Kconfig
··· 21 21 config FSL_USB2_OTG 22 22 bool "Freescale USB OTG Transceiver Driver" 23 23 depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM && PM 24 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 24 25 select USB_PHY 25 26 help 26 27 Enable this to support Freescale USB OTG transceiver. ··· 30 29 tristate "Philips ISP1301 with OMAP OTG" 31 30 depends on I2C && ARCH_OMAP_OTG 32 31 depends on USB 32 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 33 33 select USB_PHY 34 34 help 35 35 If you say yes here you get support for the Philips ISP1301 ··· 45 43 config KEYSTONE_USB_PHY 46 44 tristate "Keystone USB PHY Driver" 47 45 depends on ARCH_KEYSTONE || COMPILE_TEST 48 - select NOP_USB_XCEIV 46 + depends on NOP_USB_XCEIV 49 47 help 50 48 Enable this to support Keystone USB phy. This driver provides 51 49 interface to interact with USB 2.0 and USB 3.0 PHY that is part ··· 53 51 54 52 config NOP_USB_XCEIV 55 53 tristate "NOP USB Transceiver Driver" 54 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, NOP can't be built-in 56 55 select USB_PHY 57 56 help 58 57 This driver is to be used by all the usb transceiver which are either ··· 66 63 config AM335X_PHY_USB 67 64 tristate "AM335x USB PHY Driver" 68 65 depends on ARM || COMPILE_TEST 66 + depends on NOP_USB_XCEIV 69 67 select USB_PHY 70 68 select AM335X_CONTROL_USB 71 - select NOP_USB_XCEIV 72 69 select USB_COMMON 73 70 help 74 71 This driver provides PHY support for that phy which part for the ··· 95 92 config USB_GPIO_VBUS 96 93 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'" 97 94 depends on GPIOLIB || COMPILE_TEST 95 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 98 96 select USB_PHY 99 97 help 100 98 Provides simple GPIO VBUS sensing for controllers with an ··· 116 112 config TAHVO_USB 117 113 tristate "Tahvo USB transceiver driver" 118 114 depends on MFD_RETU && EXTCON 115 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 119 116 select USB_PHY 120 117 help 121 118 Enable this to support USB transceiver on Tahvo. This is used ··· 145 140 config USB_MSM_OTG 146 141 tristate "Qualcomm on-chip USB OTG controller support" 147 142 depends on (USB || USB_GADGET) && (ARCH_QCOM || COMPILE_TEST) 143 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 148 144 depends on RESET_CONTROLLER 149 145 depends on EXTCON 150 146 select USB_PHY ··· 175 169 config USB_MV_OTG 176 170 tristate "Marvell USB OTG support" 177 171 depends on USB_EHCI_MV && USB_MV_UDC && PM && USB_OTG 172 + depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' 178 173 select USB_PHY 179 174 help 180 175 Say Y here if you want to build Marvell USB OTG transciever
+1 -1
drivers/usb/phy/phy-am335x.c
··· 54 54 return am_phy->id; 55 55 } 56 56 57 - am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node); 57 + am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node, -1); 58 58 59 59 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL); 60 60 if (ret)
+177 -1
drivers/usb/phy/phy-msm-usb.c
··· 18 18 19 19 #include <linux/module.h> 20 20 #include <linux/device.h> 21 + #include <linux/extcon.h> 21 22 #include <linux/gpio/consumer.h> 22 23 #include <linux/platform_device.h> 23 24 #include <linux/clk.h> ··· 36 35 #include <linux/of_device.h> 37 36 #include <linux/reboot.h> 38 37 #include <linux/reset.h> 38 + #include <linux/types.h> 39 + #include <linux/usb/otg.h> 39 40 40 41 #include <linux/usb.h> 41 42 #include <linux/usb/otg.h> ··· 45 42 #include <linux/usb/ulpi.h> 46 43 #include <linux/usb/gadget.h> 47 44 #include <linux/usb/hcd.h> 48 - #include <linux/usb/msm_hsusb.h> 49 45 #include <linux/usb/msm_hsusb_hw.h> 50 46 #include <linux/regulator/consumer.h> 47 + 48 + /** 49 + * OTG control 50 + * 51 + * OTG_NO_CONTROL Id/VBUS notifications not required. Useful in host 52 + * only configuration. 53 + * OTG_PHY_CONTROL Id/VBUS notifications comes form USB PHY. 54 + * OTG_PMIC_CONTROL Id/VBUS notifications comes from PMIC hardware. 55 + * OTG_USER_CONTROL Id/VBUS notifcations comes from User via sysfs. 56 + * 57 + */ 58 + enum otg_control_type { 59 + OTG_NO_CONTROL = 0, 60 + OTG_PHY_CONTROL, 61 + OTG_PMIC_CONTROL, 62 + OTG_USER_CONTROL, 63 + }; 64 + 65 + /** 66 + * PHY used in 67 + * 68 + * INVALID_PHY Unsupported PHY 69 + * CI_45NM_INTEGRATED_PHY Chipidea 45nm integrated PHY 70 + * SNPS_28NM_INTEGRATED_PHY Synopsis 28nm integrated PHY 71 + * 72 + */ 73 + enum msm_usb_phy_type { 74 + INVALID_PHY = 0, 75 + CI_45NM_INTEGRATED_PHY, 76 + SNPS_28NM_INTEGRATED_PHY, 77 + }; 78 + 79 + #define IDEV_CHG_MAX 1500 80 + #define IUNIT 100 81 + 82 + /** 83 + * Different states involved in USB charger detection. 84 + * 85 + * USB_CHG_STATE_UNDEFINED USB charger is not connected or detection 86 + * process is not yet started. 87 + * USB_CHG_STATE_WAIT_FOR_DCD Waiting for Data pins contact. 88 + * USB_CHG_STATE_DCD_DONE Data pin contact is detected. 89 + * USB_CHG_STATE_PRIMARY_DONE Primary detection is completed (Detects 90 + * between SDP and DCP/CDP). 91 + * USB_CHG_STATE_SECONDARY_DONE Secondary detection is completed (Detects 92 + * between DCP and CDP). 93 + * USB_CHG_STATE_DETECTED USB charger type is determined. 94 + * 95 + */ 96 + enum usb_chg_state { 97 + USB_CHG_STATE_UNDEFINED = 0, 98 + USB_CHG_STATE_WAIT_FOR_DCD, 99 + USB_CHG_STATE_DCD_DONE, 100 + USB_CHG_STATE_PRIMARY_DONE, 101 + USB_CHG_STATE_SECONDARY_DONE, 102 + USB_CHG_STATE_DETECTED, 103 + }; 104 + 105 + /** 106 + * USB charger types 107 + * 108 + * USB_INVALID_CHARGER Invalid USB charger. 109 + * USB_SDP_CHARGER Standard downstream port. Refers to a downstream port 110 + * on USB2.0 compliant host/hub. 111 + * USB_DCP_CHARGER Dedicated charger port (AC charger/ Wall charger). 112 + * USB_CDP_CHARGER Charging downstream port. Enumeration can happen and 113 + * IDEV_CHG_MAX can be drawn irrespective of USB state. 114 + * 115 + */ 116 + enum usb_chg_type { 117 + USB_INVALID_CHARGER = 0, 118 + USB_SDP_CHARGER, 119 + USB_DCP_CHARGER, 120 + USB_CDP_CHARGER, 121 + }; 122 + 123 + /** 124 + * struct msm_otg_platform_data - platform device data 125 + * for msm_otg driver. 126 + * @phy_init_seq: PHY configuration sequence values. Value of -1 is reserved as 127 + * "do not overwrite default vaule at this address". 128 + * @phy_init_sz: PHY configuration sequence size. 129 + * @vbus_power: VBUS power on/off routine. 130 + * @power_budget: VBUS power budget in mA (0 will be treated as 500mA). 131 + * @mode: Supported mode (OTG/peripheral/host). 132 + * @otg_control: OTG switch controlled by user/Id pin 133 + */ 134 + struct msm_otg_platform_data { 135 + int *phy_init_seq; 136 + int phy_init_sz; 137 + void (*vbus_power)(bool on); 138 + unsigned power_budget; 139 + enum usb_dr_mode mode; 140 + enum otg_control_type otg_control; 141 + enum msm_usb_phy_type phy_type; 142 + void (*setup_gpio)(enum usb_otg_state state); 143 + }; 144 + 145 + /** 146 + * struct msm_usb_cable - structure for exteternal connector cable 147 + * state tracking 148 + * @nb: hold event notification callback 149 + * @conn: used for notification registration 150 + */ 151 + struct msm_usb_cable { 152 + struct notifier_block nb; 153 + struct extcon_dev *extcon; 154 + }; 155 + 156 + /** 157 + * struct msm_otg: OTG driver data. Shared by HCD and DCD. 158 + * @otg: USB OTG Transceiver structure. 159 + * @pdata: otg device platform data. 160 + * @irq: IRQ number assigned for HSUSB controller. 161 + * @clk: clock struct of usb_hs_clk. 162 + * @pclk: clock struct of usb_hs_pclk. 163 + * @core_clk: clock struct of usb_hs_core_clk. 164 + * @regs: ioremapped register base address. 165 + * @inputs: OTG state machine inputs(Id, SessValid etc). 166 + * @sm_work: OTG state machine work. 167 + * @in_lpm: indicates low power mode (LPM) state. 168 + * @async_int: Async interrupt arrived. 169 + * @cur_power: The amount of mA available from downstream port. 170 + * @chg_work: Charger detection work. 171 + * @chg_state: The state of charger detection process. 172 + * @chg_type: The type of charger attached. 173 + * @dcd_retires: The retry count used to track Data contact 174 + * detection process. 175 + * @manual_pullup: true if VBUS is not routed to USB controller/phy 176 + * and controller driver therefore enables pull-up explicitly before 177 + * starting controller using usbcmd run/stop bit. 178 + * @vbus: VBUS signal state trakining, using extcon framework 179 + * @id: ID signal state trakining, using extcon framework 180 + * @switch_gpio: Descriptor for GPIO used to control external Dual 181 + * SPDT USB Switch. 182 + * @reboot: Used to inform the driver to route USB D+/D- line to Device 183 + * connector 184 + */ 185 + struct msm_otg { 186 + struct usb_phy phy; 187 + struct msm_otg_platform_data *pdata; 188 + int irq; 189 + struct clk *clk; 190 + struct clk *pclk; 191 + struct clk *core_clk; 192 + void __iomem *regs; 193 + #define ID 0 194 + #define B_SESS_VLD 1 195 + unsigned long inputs; 196 + struct work_struct sm_work; 197 + atomic_t in_lpm; 198 + int async_int; 199 + unsigned cur_power; 200 + int phy_number; 201 + struct delayed_work chg_work; 202 + enum usb_chg_state chg_state; 203 + enum usb_chg_type chg_type; 204 + u8 dcd_retries; 205 + struct regulator *v3p3; 206 + struct regulator *v1p8; 207 + struct regulator *vddcx; 208 + 209 + struct reset_control *phy_rst; 210 + struct reset_control *link_rst; 211 + int vdd_levels[3]; 212 + 213 + bool manual_pullup; 214 + 215 + struct msm_usb_cable vbus; 216 + struct msm_usb_cable id; 217 + 218 + struct gpio_desc *switch_gpio; 219 + struct notifier_block reboot; 220 + }; 51 221 52 222 #define MSM_USB_BASE (motg->regs) 53 223 #define DRIVER_NAME "msm_otg"
+1 -1
drivers/usb/phy/phy-omap-otg.c
··· 148 148 struct otg_device *otg_dev = platform_get_drvdata(pdev); 149 149 struct extcon_dev *edev = otg_dev->extcon; 150 150 151 - extcon_unregister_notifier(edev, EXTCON_USB_HOST,&otg_dev->id_nb); 151 + extcon_unregister_notifier(edev, EXTCON_USB_HOST, &otg_dev->id_nb); 152 152 extcon_unregister_notifier(edev, EXTCON_USB, &otg_dev->vbus_nb); 153 153 154 154 return 0;
+1 -1
drivers/usb/renesas_usbhs/common.c
··· 697 697 probe_end_pipe_exit: 698 698 usbhs_pipe_remove(priv); 699 699 700 - dev_info(&pdev->dev, "probe failed\n"); 700 + dev_info(&pdev->dev, "probe failed (%d)\n", ret); 701 701 702 702 return ret; 703 703 }
+14 -4
drivers/usb/renesas_usbhs/fifo.c
··· 810 810 { 811 811 struct usbhs_pkt *pkt = container_of(work, struct usbhs_pkt, work); 812 812 struct usbhs_pipe *pipe = pkt->pipe; 813 - struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe); 813 + struct usbhs_fifo *fifo; 814 814 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 815 815 struct dma_async_tx_descriptor *desc; 816 - struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt); 816 + struct dma_chan *chan; 817 817 struct device *dev = usbhs_priv_to_dev(priv); 818 818 enum dma_transfer_direction dir; 819 + unsigned long flags; 819 820 821 + usbhs_lock(priv, flags); 822 + fifo = usbhs_pipe_to_fifo(pipe); 823 + if (!fifo) 824 + goto xfer_work_end; 825 + 826 + chan = usbhsf_dma_chan_get(fifo, pkt); 820 827 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_DEV_TO_MEM : DMA_MEM_TO_DEV; 821 828 822 829 desc = dmaengine_prep_slave_single(chan, pkt->dma + pkt->actual, 823 830 pkt->trans, dir, 824 831 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 825 832 if (!desc) 826 - return; 833 + goto xfer_work_end; 827 834 828 835 desc->callback = usbhsf_dma_complete; 829 836 desc->callback_param = pipe; ··· 838 831 pkt->cookie = dmaengine_submit(desc); 839 832 if (pkt->cookie < 0) { 840 833 dev_err(dev, "Failed to submit dma descriptor\n"); 841 - return; 834 + goto xfer_work_end; 842 835 } 843 836 844 837 dev_dbg(dev, " %s %d (%d/ %d)\n", ··· 849 842 usbhs_pipe_set_trans_count_if_bulk(pipe, pkt->trans); 850 843 dma_async_issue_pending(chan); 851 844 usbhs_pipe_enable(pipe); 845 + 846 + xfer_work_end: 847 + usbhs_unlock(priv, flags); 852 848 } 853 849 854 850 /*
+8 -1
drivers/usb/renesas_usbhs/mod_gadget.c
··· 585 585 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); 586 586 struct usbhs_pipe *pipe; 587 587 int ret = -EIO; 588 + unsigned long flags; 589 + 590 + usbhs_lock(priv, flags); 588 591 589 592 /* 590 593 * if it already have pipe, ··· 596 593 if (uep->pipe) { 597 594 usbhs_pipe_clear(uep->pipe); 598 595 usbhs_pipe_sequence_data0(uep->pipe); 599 - return 0; 596 + ret = 0; 597 + goto usbhsg_ep_enable_end; 600 598 } 601 599 602 600 pipe = usbhs_pipe_malloc(priv, ··· 624 620 625 621 ret = 0; 626 622 } 623 + 624 + usbhsg_ep_enable_end: 625 + usbhs_unlock(priv, flags); 627 626 628 627 return ret; 629 628 }
+64 -525
include/linux/usb/gadget.h
··· 25 25 #include <linux/workqueue.h> 26 26 #include <linux/usb/ch9.h> 27 27 28 + #define UDC_TRACE_STR_MAX 512 29 + 28 30 struct usb_ep; 29 31 30 32 /** ··· 230 228 231 229 /*-------------------------------------------------------------------------*/ 232 230 233 - /** 234 - * usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint 235 - * @ep:the endpoint being configured 236 - * @maxpacket_limit:value of maximum packet size limit 237 - * 238 - * This function should be used only in UDC drivers to initialize endpoint 239 - * (usually in probe function). 240 - */ 231 + #if IS_ENABLED(CONFIG_USB_GADGET) 232 + void usb_ep_set_maxpacket_limit(struct usb_ep *ep, unsigned maxpacket_limit); 233 + int usb_ep_enable(struct usb_ep *ep); 234 + int usb_ep_disable(struct usb_ep *ep); 235 + struct usb_request *usb_ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags); 236 + void usb_ep_free_request(struct usb_ep *ep, struct usb_request *req); 237 + int usb_ep_queue(struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags); 238 + int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req); 239 + int usb_ep_set_halt(struct usb_ep *ep); 240 + int usb_ep_clear_halt(struct usb_ep *ep); 241 + int usb_ep_set_wedge(struct usb_ep *ep); 242 + int usb_ep_fifo_status(struct usb_ep *ep); 243 + void usb_ep_fifo_flush(struct usb_ep *ep); 244 + #else 241 245 static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, 242 - unsigned maxpacket_limit) 243 - { 244 - ep->maxpacket_limit = maxpacket_limit; 245 - ep->maxpacket = maxpacket_limit; 246 - } 247 - 248 - /** 249 - * usb_ep_enable - configure endpoint, making it usable 250 - * @ep:the endpoint being configured. may not be the endpoint named "ep0". 251 - * drivers discover endpoints through the ep_list of a usb_gadget. 252 - * 253 - * When configurations are set, or when interface settings change, the driver 254 - * will enable or disable the relevant endpoints. while it is enabled, an 255 - * endpoint may be used for i/o until the driver receives a disconnect() from 256 - * the host or until the endpoint is disabled. 257 - * 258 - * the ep0 implementation (which calls this routine) must ensure that the 259 - * hardware capabilities of each endpoint match the descriptor provided 260 - * for it. for example, an endpoint named "ep2in-bulk" would be usable 261 - * for interrupt transfers as well as bulk, but it likely couldn't be used 262 - * for iso transfers or for endpoint 14. some endpoints are fully 263 - * configurable, with more generic names like "ep-a". (remember that for 264 - * USB, "in" means "towards the USB master".) 265 - * 266 - * returns zero, or a negative error code. 267 - */ 246 + unsigned maxpacket_limit) 247 + { } 268 248 static inline int usb_ep_enable(struct usb_ep *ep) 269 - { 270 - int ret; 271 - 272 - if (ep->enabled) 273 - return 0; 274 - 275 - ret = ep->ops->enable(ep, ep->desc); 276 - if (ret) 277 - return ret; 278 - 279 - ep->enabled = true; 280 - 281 - return 0; 282 - } 283 - 284 - /** 285 - * usb_ep_disable - endpoint is no longer usable 286 - * @ep:the endpoint being unconfigured. may not be the endpoint named "ep0". 287 - * 288 - * no other task may be using this endpoint when this is called. 289 - * any pending and uncompleted requests will complete with status 290 - * indicating disconnect (-ESHUTDOWN) before this call returns. 291 - * gadget drivers must call usb_ep_enable() again before queueing 292 - * requests to the endpoint. 293 - * 294 - * returns zero, or a negative error code. 295 - */ 249 + { return 0; } 296 250 static inline int usb_ep_disable(struct usb_ep *ep) 297 - { 298 - int ret; 299 - 300 - if (!ep->enabled) 301 - return 0; 302 - 303 - ret = ep->ops->disable(ep); 304 - if (ret) 305 - return ret; 306 - 307 - ep->enabled = false; 308 - 309 - return 0; 310 - } 311 - 312 - /** 313 - * usb_ep_alloc_request - allocate a request object to use with this endpoint 314 - * @ep:the endpoint to be used with with the request 315 - * @gfp_flags:GFP_* flags to use 316 - * 317 - * Request objects must be allocated with this call, since they normally 318 - * need controller-specific setup and may even need endpoint-specific 319 - * resources such as allocation of DMA descriptors. 320 - * Requests may be submitted with usb_ep_queue(), and receive a single 321 - * completion callback. Free requests with usb_ep_free_request(), when 322 - * they are no longer needed. 323 - * 324 - * Returns the request, or null if one could not be allocated. 325 - */ 251 + { return 0; } 326 252 static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep, 327 - gfp_t gfp_flags) 328 - { 329 - return ep->ops->alloc_request(ep, gfp_flags); 330 - } 331 - 332 - /** 333 - * usb_ep_free_request - frees a request object 334 - * @ep:the endpoint associated with the request 335 - * @req:the request being freed 336 - * 337 - * Reverses the effect of usb_ep_alloc_request(). 338 - * Caller guarantees the request is not queued, and that it will 339 - * no longer be requeued (or otherwise used). 340 - */ 253 + gfp_t gfp_flags) 254 + { return NULL; } 341 255 static inline void usb_ep_free_request(struct usb_ep *ep, 342 - struct usb_request *req) 343 - { 344 - ep->ops->free_request(ep, req); 345 - } 346 - 347 - /** 348 - * usb_ep_queue - queues (submits) an I/O request to an endpoint. 349 - * @ep:the endpoint associated with the request 350 - * @req:the request being submitted 351 - * @gfp_flags: GFP_* flags to use in case the lower level driver couldn't 352 - * pre-allocate all necessary memory with the request. 353 - * 354 - * This tells the device controller to perform the specified request through 355 - * that endpoint (reading or writing a buffer). When the request completes, 356 - * including being canceled by usb_ep_dequeue(), the request's completion 357 - * routine is called to return the request to the driver. Any endpoint 358 - * (except control endpoints like ep0) may have more than one transfer 359 - * request queued; they complete in FIFO order. Once a gadget driver 360 - * submits a request, that request may not be examined or modified until it 361 - * is given back to that driver through the completion callback. 362 - * 363 - * Each request is turned into one or more packets. The controller driver 364 - * never merges adjacent requests into the same packet. OUT transfers 365 - * will sometimes use data that's already buffered in the hardware. 366 - * Drivers can rely on the fact that the first byte of the request's buffer 367 - * always corresponds to the first byte of some USB packet, for both 368 - * IN and OUT transfers. 369 - * 370 - * Bulk endpoints can queue any amount of data; the transfer is packetized 371 - * automatically. The last packet will be short if the request doesn't fill it 372 - * out completely. Zero length packets (ZLPs) should be avoided in portable 373 - * protocols since not all usb hardware can successfully handle zero length 374 - * packets. (ZLPs may be explicitly written, and may be implicitly written if 375 - * the request 'zero' flag is set.) Bulk endpoints may also be used 376 - * for interrupt transfers; but the reverse is not true, and some endpoints 377 - * won't support every interrupt transfer. (Such as 768 byte packets.) 378 - * 379 - * Interrupt-only endpoints are less functional than bulk endpoints, for 380 - * example by not supporting queueing or not handling buffers that are 381 - * larger than the endpoint's maxpacket size. They may also treat data 382 - * toggle differently. 383 - * 384 - * Control endpoints ... after getting a setup() callback, the driver queues 385 - * one response (even if it would be zero length). That enables the 386 - * status ack, after transferring data as specified in the response. Setup 387 - * functions may return negative error codes to generate protocol stalls. 388 - * (Note that some USB device controllers disallow protocol stall responses 389 - * in some cases.) When control responses are deferred (the response is 390 - * written after the setup callback returns), then usb_ep_set_halt() may be 391 - * used on ep0 to trigger protocol stalls. Depending on the controller, 392 - * it may not be possible to trigger a status-stage protocol stall when the 393 - * data stage is over, that is, from within the response's completion 394 - * routine. 395 - * 396 - * For periodic endpoints, like interrupt or isochronous ones, the usb host 397 - * arranges to poll once per interval, and the gadget driver usually will 398 - * have queued some data to transfer at that time. 399 - * 400 - * Returns zero, or a negative error code. Endpoints that are not enabled 401 - * report errors; errors will also be 402 - * reported when the usb peripheral is disconnected. 403 - */ 404 - static inline int usb_ep_queue(struct usb_ep *ep, 405 - struct usb_request *req, gfp_t gfp_flags) 406 - { 407 - if (WARN_ON_ONCE(!ep->enabled && ep->address)) 408 - return -ESHUTDOWN; 409 - 410 - return ep->ops->queue(ep, req, gfp_flags); 411 - } 412 - 413 - /** 414 - * usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint 415 - * @ep:the endpoint associated with the request 416 - * @req:the request being canceled 417 - * 418 - * If the request is still active on the endpoint, it is dequeued and its 419 - * completion routine is called (with status -ECONNRESET); else a negative 420 - * error code is returned. This is guaranteed to happen before the call to 421 - * usb_ep_dequeue() returns. 422 - * 423 - * Note that some hardware can't clear out write fifos (to unlink the request 424 - * at the head of the queue) except as part of disconnecting from usb. Such 425 - * restrictions prevent drivers from supporting configuration changes, 426 - * even to configuration zero (a "chapter 9" requirement). 427 - */ 256 + struct usb_request *req) 257 + { } 258 + static inline int usb_ep_queue(struct usb_ep *ep, struct usb_request *req, 259 + gfp_t gfp_flags) 260 + { return 0; } 428 261 static inline int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req) 429 - { 430 - return ep->ops->dequeue(ep, req); 431 - } 432 - 433 - /** 434 - * usb_ep_set_halt - sets the endpoint halt feature. 435 - * @ep: the non-isochronous endpoint being stalled 436 - * 437 - * Use this to stall an endpoint, perhaps as an error report. 438 - * Except for control endpoints, 439 - * the endpoint stays halted (will not stream any data) until the host 440 - * clears this feature; drivers may need to empty the endpoint's request 441 - * queue first, to make sure no inappropriate transfers happen. 442 - * 443 - * Note that while an endpoint CLEAR_FEATURE will be invisible to the 444 - * gadget driver, a SET_INTERFACE will not be. To reset endpoints for the 445 - * current altsetting, see usb_ep_clear_halt(). When switching altsettings, 446 - * it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints. 447 - * 448 - * Returns zero, or a negative error code. On success, this call sets 449 - * underlying hardware state that blocks data transfers. 450 - * Attempts to halt IN endpoints will fail (returning -EAGAIN) if any 451 - * transfer requests are still queued, or if the controller hardware 452 - * (usually a FIFO) still holds bytes that the host hasn't collected. 453 - */ 262 + { return 0; } 454 263 static inline int usb_ep_set_halt(struct usb_ep *ep) 455 - { 456 - return ep->ops->set_halt(ep, 1); 457 - } 458 - 459 - /** 460 - * usb_ep_clear_halt - clears endpoint halt, and resets toggle 461 - * @ep:the bulk or interrupt endpoint being reset 462 - * 463 - * Use this when responding to the standard usb "set interface" request, 464 - * for endpoints that aren't reconfigured, after clearing any other state 465 - * in the endpoint's i/o queue. 466 - * 467 - * Returns zero, or a negative error code. On success, this call clears 468 - * the underlying hardware state reflecting endpoint halt and data toggle. 469 - * Note that some hardware can't support this request (like pxa2xx_udc), 470 - * and accordingly can't correctly implement interface altsettings. 471 - */ 264 + { return 0; } 472 265 static inline int usb_ep_clear_halt(struct usb_ep *ep) 473 - { 474 - return ep->ops->set_halt(ep, 0); 475 - } 476 - 477 - /** 478 - * usb_ep_set_wedge - sets the halt feature and ignores clear requests 479 - * @ep: the endpoint being wedged 480 - * 481 - * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT) 482 - * requests. If the gadget driver clears the halt status, it will 483 - * automatically unwedge the endpoint. 484 - * 485 - * Returns zero on success, else negative errno. 486 - */ 487 - static inline int 488 - usb_ep_set_wedge(struct usb_ep *ep) 489 - { 490 - if (ep->ops->set_wedge) 491 - return ep->ops->set_wedge(ep); 492 - else 493 - return ep->ops->set_halt(ep, 1); 494 - } 495 - 496 - /** 497 - * usb_ep_fifo_status - returns number of bytes in fifo, or error 498 - * @ep: the endpoint whose fifo status is being checked. 499 - * 500 - * FIFO endpoints may have "unclaimed data" in them in certain cases, 501 - * such as after aborted transfers. Hosts may not have collected all 502 - * the IN data written by the gadget driver (and reported by a request 503 - * completion). The gadget driver may not have collected all the data 504 - * written OUT to it by the host. Drivers that need precise handling for 505 - * fault reporting or recovery may need to use this call. 506 - * 507 - * This returns the number of such bytes in the fifo, or a negative 508 - * errno if the endpoint doesn't use a FIFO or doesn't support such 509 - * precise handling. 510 - */ 266 + { return 0; } 267 + static inline int usb_ep_set_wedge(struct usb_ep *ep) 268 + { return 0; } 511 269 static inline int usb_ep_fifo_status(struct usb_ep *ep) 512 - { 513 - if (ep->ops->fifo_status) 514 - return ep->ops->fifo_status(ep); 515 - else 516 - return -EOPNOTSUPP; 517 - } 518 - 519 - /** 520 - * usb_ep_fifo_flush - flushes contents of a fifo 521 - * @ep: the endpoint whose fifo is being flushed. 522 - * 523 - * This call may be used to flush the "unclaimed data" that may exist in 524 - * an endpoint fifo after abnormal transaction terminations. The call 525 - * must never be used except when endpoint is not being used for any 526 - * protocol translation. 527 - */ 270 + { return 0; } 528 271 static inline void usb_ep_fifo_flush(struct usb_ep *ep) 529 - { 530 - if (ep->ops->fifo_flush) 531 - ep->ops->fifo_flush(ep); 532 - } 533 - 272 + { } 273 + #endif /* USB_GADGET */ 534 274 535 275 /*-------------------------------------------------------------------------*/ 536 276 ··· 326 582 * @dev: Driver model state for this abstract device. 327 583 * @out_epnum: last used out ep number 328 584 * @in_epnum: last used in ep number 585 + * @mA: last set mA value 329 586 * @otg_caps: OTG capabilities of this gadget. 330 587 * @sg_supported: true if we can handle scatter-gather 331 588 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the ··· 383 638 struct device dev; 384 639 unsigned out_epnum; 385 640 unsigned in_epnum; 641 + unsigned mA; 386 642 struct usb_otg_caps *otg_caps; 387 643 388 644 unsigned sg_supported:1; ··· 506 760 #endif 507 761 } 508 762 509 - /** 510 - * usb_gadget_frame_number - returns the current frame number 511 - * @gadget: controller that reports the frame number 512 - * 513 - * Returns the usb frame number, normally eleven bits from a SOF packet, 514 - * or negative errno if this device doesn't support this capability. 515 - */ 763 + /*-------------------------------------------------------------------------*/ 764 + 765 + #if IS_ENABLED(CONFIG_USB_GADGET) 766 + int usb_gadget_frame_number(struct usb_gadget *gadget); 767 + int usb_gadget_wakeup(struct usb_gadget *gadget); 768 + int usb_gadget_set_selfpowered(struct usb_gadget *gadget); 769 + int usb_gadget_clear_selfpowered(struct usb_gadget *gadget); 770 + int usb_gadget_vbus_connect(struct usb_gadget *gadget); 771 + int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA); 772 + int usb_gadget_vbus_disconnect(struct usb_gadget *gadget); 773 + int usb_gadget_connect(struct usb_gadget *gadget); 774 + int usb_gadget_disconnect(struct usb_gadget *gadget); 775 + int usb_gadget_deactivate(struct usb_gadget *gadget); 776 + int usb_gadget_activate(struct usb_gadget *gadget); 777 + #else 516 778 static inline int usb_gadget_frame_number(struct usb_gadget *gadget) 517 - { 518 - return gadget->ops->get_frame(gadget); 519 - } 520 - 521 - /** 522 - * usb_gadget_wakeup - tries to wake up the host connected to this gadget 523 - * @gadget: controller used to wake up the host 524 - * 525 - * Returns zero on success, else negative error code if the hardware 526 - * doesn't support such attempts, or its support has not been enabled 527 - * by the usb host. Drivers must return device descriptors that report 528 - * their ability to support this, or hosts won't enable it. 529 - * 530 - * This may also try to use SRP to wake the host and start enumeration, 531 - * even if OTG isn't otherwise in use. OTG devices may also start 532 - * remote wakeup even when hosts don't explicitly enable it. 533 - */ 779 + { return 0; } 534 780 static inline int usb_gadget_wakeup(struct usb_gadget *gadget) 535 - { 536 - if (!gadget->ops->wakeup) 537 - return -EOPNOTSUPP; 538 - return gadget->ops->wakeup(gadget); 539 - } 540 - 541 - /** 542 - * usb_gadget_set_selfpowered - sets the device selfpowered feature. 543 - * @gadget:the device being declared as self-powered 544 - * 545 - * this affects the device status reported by the hardware driver 546 - * to reflect that it now has a local power supply. 547 - * 548 - * returns zero on success, else negative errno. 549 - */ 781 + { return 0; } 550 782 static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget) 551 - { 552 - if (!gadget->ops->set_selfpowered) 553 - return -EOPNOTSUPP; 554 - return gadget->ops->set_selfpowered(gadget, 1); 555 - } 556 - 557 - /** 558 - * usb_gadget_clear_selfpowered - clear the device selfpowered feature. 559 - * @gadget:the device being declared as bus-powered 560 - * 561 - * this affects the device status reported by the hardware driver. 562 - * some hardware may not support bus-powered operation, in which 563 - * case this feature's value can never change. 564 - * 565 - * returns zero on success, else negative errno. 566 - */ 783 + { return 0; } 567 784 static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget) 568 - { 569 - if (!gadget->ops->set_selfpowered) 570 - return -EOPNOTSUPP; 571 - return gadget->ops->set_selfpowered(gadget, 0); 572 - } 573 - 574 - /** 575 - * usb_gadget_vbus_connect - Notify controller that VBUS is powered 576 - * @gadget:The device which now has VBUS power. 577 - * Context: can sleep 578 - * 579 - * This call is used by a driver for an external transceiver (or GPIO) 580 - * that detects a VBUS power session starting. Common responses include 581 - * resuming the controller, activating the D+ (or D-) pullup to let the 582 - * host detect that a USB device is attached, and starting to draw power 583 - * (8mA or possibly more, especially after SET_CONFIGURATION). 584 - * 585 - * Returns zero on success, else negative errno. 586 - */ 785 + { return 0; } 587 786 static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget) 588 - { 589 - if (!gadget->ops->vbus_session) 590 - return -EOPNOTSUPP; 591 - return gadget->ops->vbus_session(gadget, 1); 592 - } 593 - 594 - /** 595 - * usb_gadget_vbus_draw - constrain controller's VBUS power usage 596 - * @gadget:The device whose VBUS usage is being described 597 - * @mA:How much current to draw, in milliAmperes. This should be twice 598 - * the value listed in the configuration descriptor bMaxPower field. 599 - * 600 - * This call is used by gadget drivers during SET_CONFIGURATION calls, 601 - * reporting how much power the device may consume. For example, this 602 - * could affect how quickly batteries are recharged. 603 - * 604 - * Returns zero on success, else negative errno. 605 - */ 787 + { return 0; } 606 788 static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) 607 - { 608 - if (!gadget->ops->vbus_draw) 609 - return -EOPNOTSUPP; 610 - return gadget->ops->vbus_draw(gadget, mA); 611 - } 612 - 613 - /** 614 - * usb_gadget_vbus_disconnect - notify controller about VBUS session end 615 - * @gadget:the device whose VBUS supply is being described 616 - * Context: can sleep 617 - * 618 - * This call is used by a driver for an external transceiver (or GPIO) 619 - * that detects a VBUS power session ending. Common responses include 620 - * reversing everything done in usb_gadget_vbus_connect(). 621 - * 622 - * Returns zero on success, else negative errno. 623 - */ 789 + { return 0; } 624 790 static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) 625 - { 626 - if (!gadget->ops->vbus_session) 627 - return -EOPNOTSUPP; 628 - return gadget->ops->vbus_session(gadget, 0); 629 - } 630 - 631 - /** 632 - * usb_gadget_connect - software-controlled connect to USB host 633 - * @gadget:the peripheral being connected 634 - * 635 - * Enables the D+ (or potentially D-) pullup. The host will start 636 - * enumerating this gadget when the pullup is active and a VBUS session 637 - * is active (the link is powered). This pullup is always enabled unless 638 - * usb_gadget_disconnect() has been used to disable it. 639 - * 640 - * Returns zero on success, else negative errno. 641 - */ 791 + { return 0; } 642 792 static inline int usb_gadget_connect(struct usb_gadget *gadget) 643 - { 644 - int ret; 645 - 646 - if (!gadget->ops->pullup) 647 - return -EOPNOTSUPP; 648 - 649 - if (gadget->deactivated) { 650 - /* 651 - * If gadget is deactivated we only save new state. 652 - * Gadget will be connected automatically after activation. 653 - */ 654 - gadget->connected = true; 655 - return 0; 656 - } 657 - 658 - ret = gadget->ops->pullup(gadget, 1); 659 - if (!ret) 660 - gadget->connected = 1; 661 - return ret; 662 - } 663 - 664 - /** 665 - * usb_gadget_disconnect - software-controlled disconnect from USB host 666 - * @gadget:the peripheral being disconnected 667 - * 668 - * Disables the D+ (or potentially D-) pullup, which the host may see 669 - * as a disconnect (when a VBUS session is active). Not all systems 670 - * support software pullup controls. 671 - * 672 - * Returns zero on success, else negative errno. 673 - */ 793 + { return 0; } 674 794 static inline int usb_gadget_disconnect(struct usb_gadget *gadget) 675 - { 676 - int ret; 677 - 678 - if (!gadget->ops->pullup) 679 - return -EOPNOTSUPP; 680 - 681 - if (gadget->deactivated) { 682 - /* 683 - * If gadget is deactivated we only save new state. 684 - * Gadget will stay disconnected after activation. 685 - */ 686 - gadget->connected = false; 687 - return 0; 688 - } 689 - 690 - ret = gadget->ops->pullup(gadget, 0); 691 - if (!ret) 692 - gadget->connected = 0; 693 - return ret; 694 - } 695 - 696 - /** 697 - * usb_gadget_deactivate - deactivate function which is not ready to work 698 - * @gadget: the peripheral being deactivated 699 - * 700 - * This routine may be used during the gadget driver bind() call to prevent 701 - * the peripheral from ever being visible to the USB host, unless later 702 - * usb_gadget_activate() is called. For example, user mode components may 703 - * need to be activated before the system can talk to hosts. 704 - * 705 - * Returns zero on success, else negative errno. 706 - */ 795 + { return 0; } 707 796 static inline int usb_gadget_deactivate(struct usb_gadget *gadget) 708 - { 709 - int ret; 710 - 711 - if (gadget->deactivated) 712 - return 0; 713 - 714 - if (gadget->connected) { 715 - ret = usb_gadget_disconnect(gadget); 716 - if (ret) 717 - return ret; 718 - /* 719 - * If gadget was being connected before deactivation, we want 720 - * to reconnect it in usb_gadget_activate(). 721 - */ 722 - gadget->connected = true; 723 - } 724 - gadget->deactivated = true; 725 - 726 - return 0; 727 - } 728 - 729 - /** 730 - * usb_gadget_activate - activate function which is not ready to work 731 - * @gadget: the peripheral being activated 732 - * 733 - * This routine activates gadget which was previously deactivated with 734 - * usb_gadget_deactivate() call. It calls usb_gadget_connect() if needed. 735 - * 736 - * Returns zero on success, else negative errno. 737 - */ 797 + { return 0; } 738 798 static inline int usb_gadget_activate(struct usb_gadget *gadget) 739 - { 740 - if (!gadget->deactivated) 741 - return 0; 742 - 743 - gadget->deactivated = false; 744 - 745 - /* 746 - * If gadget has been connected before deactivation, or became connected 747 - * while it was being deactivated, we call usb_gadget_connect(). 748 - */ 749 - if (gadget->connected) 750 - return usb_gadget_connect(gadget); 751 - 752 - return 0; 753 - } 799 + { return 0; } 800 + #endif /* CONFIG_USB_GADGET */ 754 801 755 802 /*-------------------------------------------------------------------------*/ 756 803
-200
include/linux/usb/msm_hsusb.h
··· 1 - /* linux/include/asm-arm/arch-msm/hsusb.h 2 - * 3 - * Copyright (C) 2008 Google, Inc. 4 - * Author: Brian Swetland <swetland@google.com> 5 - * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. 6 - * 7 - * This software is licensed under the terms of the GNU General Public 8 - * License version 2, as published by the Free Software Foundation, and 9 - * may be copied, distributed, and modified under those terms. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 - * 16 - */ 17 - 18 - #ifndef __ASM_ARCH_MSM_HSUSB_H 19 - #define __ASM_ARCH_MSM_HSUSB_H 20 - 21 - #include <linux/extcon.h> 22 - #include <linux/types.h> 23 - #include <linux/usb/otg.h> 24 - #include <linux/clk.h> 25 - 26 - /** 27 - * OTG control 28 - * 29 - * OTG_NO_CONTROL Id/VBUS notifications not required. Useful in host 30 - * only configuration. 31 - * OTG_PHY_CONTROL Id/VBUS notifications comes form USB PHY. 32 - * OTG_PMIC_CONTROL Id/VBUS notifications comes from PMIC hardware. 33 - * OTG_USER_CONTROL Id/VBUS notifcations comes from User via sysfs. 34 - * 35 - */ 36 - enum otg_control_type { 37 - OTG_NO_CONTROL = 0, 38 - OTG_PHY_CONTROL, 39 - OTG_PMIC_CONTROL, 40 - OTG_USER_CONTROL, 41 - }; 42 - 43 - /** 44 - * PHY used in 45 - * 46 - * INVALID_PHY Unsupported PHY 47 - * CI_45NM_INTEGRATED_PHY Chipidea 45nm integrated PHY 48 - * SNPS_28NM_INTEGRATED_PHY Synopsis 28nm integrated PHY 49 - * 50 - */ 51 - enum msm_usb_phy_type { 52 - INVALID_PHY = 0, 53 - CI_45NM_INTEGRATED_PHY, 54 - SNPS_28NM_INTEGRATED_PHY, 55 - }; 56 - 57 - #define IDEV_CHG_MAX 1500 58 - #define IUNIT 100 59 - 60 - /** 61 - * Different states involved in USB charger detection. 62 - * 63 - * USB_CHG_STATE_UNDEFINED USB charger is not connected or detection 64 - * process is not yet started. 65 - * USB_CHG_STATE_WAIT_FOR_DCD Waiting for Data pins contact. 66 - * USB_CHG_STATE_DCD_DONE Data pin contact is detected. 67 - * USB_CHG_STATE_PRIMARY_DONE Primary detection is completed (Detects 68 - * between SDP and DCP/CDP). 69 - * USB_CHG_STATE_SECONDARY_DONE Secondary detection is completed (Detects 70 - * between DCP and CDP). 71 - * USB_CHG_STATE_DETECTED USB charger type is determined. 72 - * 73 - */ 74 - enum usb_chg_state { 75 - USB_CHG_STATE_UNDEFINED = 0, 76 - USB_CHG_STATE_WAIT_FOR_DCD, 77 - USB_CHG_STATE_DCD_DONE, 78 - USB_CHG_STATE_PRIMARY_DONE, 79 - USB_CHG_STATE_SECONDARY_DONE, 80 - USB_CHG_STATE_DETECTED, 81 - }; 82 - 83 - /** 84 - * USB charger types 85 - * 86 - * USB_INVALID_CHARGER Invalid USB charger. 87 - * USB_SDP_CHARGER Standard downstream port. Refers to a downstream port 88 - * on USB2.0 compliant host/hub. 89 - * USB_DCP_CHARGER Dedicated charger port (AC charger/ Wall charger). 90 - * USB_CDP_CHARGER Charging downstream port. Enumeration can happen and 91 - * IDEV_CHG_MAX can be drawn irrespective of USB state. 92 - * 93 - */ 94 - enum usb_chg_type { 95 - USB_INVALID_CHARGER = 0, 96 - USB_SDP_CHARGER, 97 - USB_DCP_CHARGER, 98 - USB_CDP_CHARGER, 99 - }; 100 - 101 - /** 102 - * struct msm_otg_platform_data - platform device data 103 - * for msm_otg driver. 104 - * @phy_init_seq: PHY configuration sequence values. Value of -1 is reserved as 105 - * "do not overwrite default vaule at this address". 106 - * @phy_init_sz: PHY configuration sequence size. 107 - * @vbus_power: VBUS power on/off routine. 108 - * @power_budget: VBUS power budget in mA (0 will be treated as 500mA). 109 - * @mode: Supported mode (OTG/peripheral/host). 110 - * @otg_control: OTG switch controlled by user/Id pin 111 - */ 112 - struct msm_otg_platform_data { 113 - int *phy_init_seq; 114 - int phy_init_sz; 115 - void (*vbus_power)(bool on); 116 - unsigned power_budget; 117 - enum usb_dr_mode mode; 118 - enum otg_control_type otg_control; 119 - enum msm_usb_phy_type phy_type; 120 - void (*setup_gpio)(enum usb_otg_state state); 121 - }; 122 - 123 - /** 124 - * struct msm_usb_cable - structure for exteternal connector cable 125 - * state tracking 126 - * @nb: hold event notification callback 127 - * @conn: used for notification registration 128 - */ 129 - struct msm_usb_cable { 130 - struct notifier_block nb; 131 - struct extcon_dev *extcon; 132 - }; 133 - 134 - /** 135 - * struct msm_otg: OTG driver data. Shared by HCD and DCD. 136 - * @otg: USB OTG Transceiver structure. 137 - * @pdata: otg device platform data. 138 - * @irq: IRQ number assigned for HSUSB controller. 139 - * @clk: clock struct of usb_hs_clk. 140 - * @pclk: clock struct of usb_hs_pclk. 141 - * @core_clk: clock struct of usb_hs_core_clk. 142 - * @regs: ioremapped register base address. 143 - * @inputs: OTG state machine inputs(Id, SessValid etc). 144 - * @sm_work: OTG state machine work. 145 - * @in_lpm: indicates low power mode (LPM) state. 146 - * @async_int: Async interrupt arrived. 147 - * @cur_power: The amount of mA available from downstream port. 148 - * @chg_work: Charger detection work. 149 - * @chg_state: The state of charger detection process. 150 - * @chg_type: The type of charger attached. 151 - * @dcd_retires: The retry count used to track Data contact 152 - * detection process. 153 - * @manual_pullup: true if VBUS is not routed to USB controller/phy 154 - * and controller driver therefore enables pull-up explicitly before 155 - * starting controller using usbcmd run/stop bit. 156 - * @vbus: VBUS signal state trakining, using extcon framework 157 - * @id: ID signal state trakining, using extcon framework 158 - * @switch_gpio: Descriptor for GPIO used to control external Dual 159 - * SPDT USB Switch. 160 - * @reboot: Used to inform the driver to route USB D+/D- line to Device 161 - * connector 162 - */ 163 - struct msm_otg { 164 - struct usb_phy phy; 165 - struct msm_otg_platform_data *pdata; 166 - int irq; 167 - struct clk *clk; 168 - struct clk *pclk; 169 - struct clk *core_clk; 170 - void __iomem *regs; 171 - #define ID 0 172 - #define B_SESS_VLD 1 173 - unsigned long inputs; 174 - struct work_struct sm_work; 175 - atomic_t in_lpm; 176 - int async_int; 177 - unsigned cur_power; 178 - int phy_number; 179 - struct delayed_work chg_work; 180 - enum usb_chg_state chg_state; 181 - enum usb_chg_type chg_type; 182 - u8 dcd_retries; 183 - struct regulator *v3p3; 184 - struct regulator *v1p8; 185 - struct regulator *vddcx; 186 - 187 - struct reset_control *phy_rst; 188 - struct reset_control *link_rst; 189 - int vdd_levels[3]; 190 - 191 - bool manual_pullup; 192 - 193 - struct msm_usb_cable vbus; 194 - struct msm_usb_cable id; 195 - 196 - struct gpio_desc *switch_gpio; 197 - struct notifier_block reboot; 198 - }; 199 - 200 - #endif
+2 -2
include/linux/usb/of.h
··· 12 12 #include <linux/usb/phy.h> 13 13 14 14 #if IS_ENABLED(CONFIG_OF) 15 - enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np); 15 + enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0); 16 16 bool of_usb_host_tpl_support(struct device_node *np); 17 17 int of_usb_update_otg_caps(struct device_node *np, 18 18 struct usb_otg_caps *otg_caps); ··· 20 20 int portnum); 21 21 #else 22 22 static inline enum usb_dr_mode 23 - of_usb_get_dr_mode_by_phy(struct device_node *phy_np) 23 + of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0) 24 24 { 25 25 return USB_DR_MODE_UNKNOWN; 26 26 }