History

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

Felipe writes: usb: patches for v4.3 merge window New support for Allwinne SoC on the MUSB driver has been added to the list of glue layers. MUSB also got support for building all DMA engines in one binary; this will be great for distros. DWC3 now has no trace of dev_dbg()/dev_vdbg() usage. We will rely solely on tracing to debug DWC3. There was also a fix for memory corruption with EP0 when maxpacket size transfers are > 512 bytes. Robert's EP capabilities flags is making EP selection a lot simpler. UDCs are now required to set these flags up when adding endpoints to the framework. Other than these, we have the usual set of miscelaneous cleanups and minor fixes.

Greg Kroah-Hartman committed 11 years ago

Commit a3fbedf2 parents e6bbe1d 2f3cc24113 files · +3440 −1079Browse files

Unified · Split

113 files
  1. Documentation/ABI/testing/configfs-usb-gadget-loopback +1 −1
  2. Documentation/ABI/testing/configfs-usb-gadget-sourcesink +1 −1
  3. Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt +29 −0
  4. Documentation/devicetree/bindings/usb/generic.txt +15 −0
  5. Documentation/devicetree/bindings/usb/msm-hsusb.txt +4 −0
  6. Documentation/devicetree/bindings/usb/qcom,usb-8x16-phy.txt +76 −0
  7. Documentation/usb/gadget-testing.txt +2 −5
  8. drivers/staging/emxx_udc/emxx_udc.c +44 −32
  9. drivers/usb/chipidea/ci.h +4 −1
  10. drivers/usb/chipidea/core.c +15 −0
  11. drivers/usb/chipidea/debug.c +1 −0
  12. drivers/usb/chipidea/udc.c +20 −1
  13. drivers/usb/common/common.c +56 −0
  14. drivers/usb/dwc2/gadget.c +14 −1
  15. drivers/usb/dwc3/Kconfig +0 −7
  16. drivers/usb/dwc3/Makefile +0 −2
  17. drivers/usb/dwc3/core.c +0 −2
  18. drivers/usb/dwc3/dwc3-exynos.c +1 −1
  19. drivers/usb/dwc3/dwc3-keystone.c +1 −1
  20. drivers/usb/dwc3/dwc3-omap.c +17 −58
  21. drivers/usb/dwc3/dwc3-pci.c +16 −10
  22. drivers/usb/dwc3/dwc3-qcom.c +2 −2
  23. drivers/usb/dwc3/dwc3-st.c +0 −4
  24. drivers/usb/dwc3/ep0.c +66 −26
  25. drivers/usb/dwc3/gadget.c +35 −22
  26. drivers/usb/gadget/composite.c +37 −4
  27. drivers/usb/gadget/config.c +56 −0
  28. drivers/usb/gadget/configfs.c +20 −9
  29. drivers/usb/gadget/epautoconf.c +43 −239
  30. drivers/usb/gadget/function/f_acm.c +0 −1
  31. drivers/usb/gadget/function/f_ecm.c +2 −2
  32. drivers/usb/gadget/function/f_fs.c +7 −1
  33. drivers/usb/gadget/function/f_loopback.c +0 −5
  34. drivers/usb/gadget/function/f_mass_storage.c +71 −93
  35. drivers/usb/gadget/function/f_mass_storage.h +1 −5
  36. drivers/usb/gadget/function/f_midi.c +4 −0
  37. drivers/usb/gadget/function/f_ncm.c +2 −3
  38. drivers/usb/gadget/function/f_obex.c +2 −20
  39. drivers/usb/gadget/function/f_printer.c +4 −3
  40. drivers/usb/gadget/function/f_serial.c +0 −1
  41. drivers/usb/gadget/function/f_sourcesink.c +0 −6
  42. drivers/usb/gadget/function/f_uac2.c +29 −2
  43. drivers/usb/gadget/function/f_uvc.c +1 −6
  44. drivers/usb/gadget/function/storage_common.h +1 −1
  45. drivers/usb/gadget/function/u_ether.h +1 −3
  46. drivers/usb/gadget/function/u_uac1.h +0 −2
  47. drivers/usb/gadget/legacy/Kconfig +2 −0
  48. drivers/usb/gadget/legacy/acm_ms.c +19 −22
  49. drivers/usb/gadget/legacy/audio.c +22 −19
  50. drivers/usb/gadget/legacy/cdc2.c +19 −16
  51. drivers/usb/gadget/legacy/dbgp.c +5 −5
  52. drivers/usb/gadget/legacy/ether.c +20 −16
  53. drivers/usb/gadget/legacy/g_ffs.c +17 −15
  54. drivers/usb/gadget/legacy/gmidi.c +3 −5
  55. drivers/usb/gadget/legacy/hid.c +20 −17
  56. drivers/usb/gadget/legacy/mass_storage.c +19 −22
  57. drivers/usb/gadget/legacy/multi.c +20 −23
  58. drivers/usb/gadget/legacy/ncm.c +19 −15
  59. drivers/usb/gadget/legacy/nokia.c +99 −6
  60. drivers/usb/gadget/legacy/printer.c +30 −21
  61. drivers/usb/gadget/legacy/serial.c +21 −17
  62. drivers/usb/gadget/legacy/zero.c +21 −20
  63. drivers/usb/gadget/udc/amd5536udc.c +78 −10
  64. drivers/usb/gadget/udc/at91_udc.c +30 −9
  65. drivers/usb/gadget/udc/atmel_usba_udc.c +15 −0
  66. drivers/usb/gadget/udc/bcm63xx_udc.c +25 −4
  67. drivers/usb/gadget/udc/bdc/bdc_ep.c +9 −0
  68. drivers/usb/gadget/udc/dummy_hcd.c +80 −15
  69. drivers/usb/gadget/udc/fotg210-udc.c +15 −14
  70. drivers/usb/gadget/udc/fsl_qe_udc.c +11 −0
  71. drivers/usb/gadget/udc/fsl_udc_core.c +13 −0
  72. drivers/usb/gadget/udc/fusb300_udc.c +11 −0
  73. drivers/usb/gadget/udc/gadget_chips.h +0 −55
  74. drivers/usb/gadget/udc/goku_udc.c +38 −0
  75. drivers/usb/gadget/udc/gr_udc.c +11 −0
  76. drivers/usb/gadget/udc/lpc32xx_udc.c +32 −0
  77. drivers/usb/gadget/udc/m66592-udc.c +12 −1
  78. drivers/usb/gadget/udc/mv_u3d_core.c +9 −0
  79. drivers/usb/gadget/udc/mv_udc_core.c +9 −0
  80. drivers/usb/gadget/udc/net2272.c +13 −2
  81. drivers/usb/gadget/udc/net2280.c +83 −12
  82. drivers/usb/gadget/udc/omap_udc.c +22 −0
  83. drivers/usb/gadget/udc/pch_udc.c +31 −21
  84. drivers/usb/gadget/udc/pxa25x_udc.c +30 −0
  85. drivers/usb/gadget/udc/pxa27x_udc.c +2 −1
  86. drivers/usb/gadget/udc/pxa27x_udc.h +25 −15
  87. drivers/usb/gadget/udc/r8a66597-udc.c +10 −0
  88. drivers/usb/gadget/udc/s3c-hsudc.c +15 −0
  89. drivers/usb/gadget/udc/s3c2410_udc.c +10 −0
  90. drivers/usb/gadget/udc/udc-core.c +90 −0
  91. drivers/usb/gadget/udc/udc-xilinx.c +9 −0
  92. drivers/usb/isp1760/isp1760-udc.c +13 −2
  93. drivers/usb/musb/Kconfig +26 −25
  94. drivers/usb/musb/Makefile +1 −0
  95. drivers/usb/musb/musb_cppi41.c +3 −3
  96. drivers/usb/musb/musb_gadget.c +66 −21
  97. drivers/usb/musb/sunxi.c +756 −0
  98. drivers/usb/phy/Kconfig +14 −0
  99. drivers/usb/phy/Makefile +1 −0
  100. drivers/usb/phy/phy-generic.c +4 −2
  101. drivers/usb/phy/phy-msm-usb.c +57 −10
  102. drivers/usb/phy/phy-omap-otg.c +11 −11
  103. drivers/usb/phy/phy-qcom-8x16-usb.c +436 −0
  104. drivers/usb/phy/phy-tahvo.c +13 −14
  105. drivers/usb/renesas_usbhs/common.c +1 −1
  106. drivers/usb/renesas_usbhs/mod_gadget.c +7 −1
  107. include/linux/usb/chipidea.h +1 −0
  108. include/linux/usb/composite.h +2 −0
  109. include/linux/usb/gadget.h +191 −7
  110. include/linux/usb/msm_hsusb.h +8 −1
  111. include/linux/usb/of.h +7 −0
  112. include/linux/usb/otg.h +15 −0
  113. include/uapi/linux/usb/ch9.h +12 −0
Documentation/ABI/testing/configfs-usb-gadget-loopback+1−1
@@ -5,4 +5,4 @@ Description: · 4 unmodified lines
55 The attributes:
66
77 qlen - depth of loopback queue
8− bulk_buflen - buffer length
8+ buflen - buffer length
Documentation/ABI/testing/configfs-usb-gadget-sourcesink+1−1
@@ -9,4 +9,4 @@ Description: · 8 unmodified lines
99 isoc_maxpacket - 0 - 1023 (fs), 0 - 1024 (hs/ss)
1010 isoc_mult - 0..2 (hs/ss only)
1111 isoc_maxburst - 0..15 (ss only)
12− qlen - buffer length
12+ buflen - buffer length
Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt+29−0
@@ -0,0 +1,29 @@
1+Allwinner sun4i A10 musb DRC/OTG controller
2+-------------------------------------------
3+
4+Required properties:
5+ - compatible : "allwinner,sun4i-a10-musb", "allwinner,sun6i-a31-musb"
6+ or "allwinner,sun8i-a33-musb"
7+ - reg : mmio address range of the musb controller
8+ - clocks : clock specifier for the musb controller ahb gate clock
9+ - reset : reset specifier for the ahb reset (A31 and newer only)
10+ - interrupts : interrupt to which the musb controller is connected
11+ - interrupt-names : must be "mc"
12+ - phys : phy specifier for the otg phy
13+ - phy-names : must be "usb"
14+ - dr_mode : Dual-Role mode must be "host" or "otg"
15+ - extcon : extcon specifier for the otg phy
16+
17+Example:
18+
19+ usb_otg: usb@01c13000 {
20+ compatible = "allwinner,sun4i-a10-musb";
21+ reg = <0x01c13000 0x0400>;
22+ clocks = <&ahb_gates 0>;
23+ interrupts = <38>;
24+ interrupt-names = "mc";
25+ phys = <&usbphy 0>;
26+ phy-names = "usb";
27+ extcon = <&usbphy 0>;
28+ status = "disabled";
29+ };
Documentation/devicetree/bindings/usb/generic.txt+15−0
@@ -11,6 +11,19 @@ Optional properties: · 10 unmodified lines
1111 "peripheral" and "otg". In case this attribute isn't
1212 passed via DT, USB DRD controllers should default to
1313 OTG.
14+ - otg-rev: tells usb driver the release number of the OTG and EH supplement
15+ with which the device and its descriptors are compliant,
16+ in binary-coded decimal (i.e. 2.0 is 0200H). This
17+ property is used if any real OTG features(HNP/SRP/ADP)
18+ is enabled, if ADP is required, otg-rev should be
19+ 0x0200 or above.
20+ - hnp-disable: tells OTG controllers we want to disable OTG HNP, normally HNP
21+ is the basic function of real OTG except you want it
22+ to be a srp-capable only B device.
23+ - srp-disable: tells OTG controllers we want to disable OTG SRP, SRP is
24+ optional for OTG device.
25+ - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is
26+ optional for OTG device.
1427
1528 This is an attribute to a USB controller such as:
1629
@@ -21,4 +34,6 @@ dwc3@4a030000 { · 4 unmodified lines
2134 usb-phy = <&usb2_phy>, <&usb3,phy>;
2235 maximum-speed = "super-speed";
2336 dr_mode = "otg";
37+ otg-rev = <0x0200>;
38+ adp-disable;
2439 };
Documentation/devicetree/bindings/usb/msm-hsusb.txt+4−0
@@ -52,6 +52,10 @@ Required properties: · 51 unmodified lines
5252 Optional properties:
5353 - dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
5454
55+- switch-gpio: A phandle + gpio-specifier pair. Some boards are using Dual
56+ SPDT USB Switch, witch is cotrolled by GPIO to de/multiplex
57+ D+/D- USB lines between connectors.
58+
5559 - qcom,phy-init-sequence: PHY configuration sequence values. This is related to Device
5660 Mode Eye Diagram test. Start address at which these values will be
5761 written is ULPI_EXT_VENDOR_SPECIFIC. Value of -1 is reserved as
Documentation/devicetree/bindings/usb/qcom,usb-8x16-phy.txt+76−0
@@ -0,0 +1,76 @@
1+Qualcomm's APQ8016/MSM8916 USB transceiver controller
2+
3+- compatible:
4+ Usage: required
5+ Value type: <string>
6+ Definition: Should contain "qcom,usb-8x16-phy".
7+
8+- reg:
9+ Usage: required
10+ Value type: <prop-encoded-array>
11+ Definition: USB PHY base address and length of the register map
12+
13+- clocks:
14+ Usage: required
15+ Value type: <prop-encoded-array>
16+ Definition: See clock-bindings.txt section "consumers". List of
17+ two clock specifiers for interface and core controller
18+ clocks.
19+
20+- clock-names:
21+ Usage: required
22+ Value type: <string>
23+ Definition: Must contain "iface" and "core" strings.
24+
25+- vddcx-supply:
26+ Usage: required
27+ Value type: <phandle>
28+ Definition: phandle to the regulator VDCCX supply node.
29+
30+- v1p8-supply:
31+ Usage: required
32+ Value type: <phandle>
33+ Definition: phandle to the regulator 1.8V supply node.
34+
35+- v3p3-supply:
36+ Usage: required
37+ Value type: <phandle>
38+ Definition: phandle to the regulator 3.3V supply node.
39+
40+- resets:
41+ Usage: required
42+ Value type: <prop-encoded-array>
43+ Definition: See reset.txt section "consumers". PHY reset specifier.
44+
45+- reset-names:
46+ Usage: required
47+ Value type: <string>
48+ Definition: Must contain "phy" string.
49+
50+- switch-gpio:
51+ Usage: optional
52+ Value type: <prop-encoded-array>
53+ Definition: Some boards are using Dual SPDT USB Switch, witch is
54+ controlled by GPIO to de/multiplex D+/D- USB lines
55+ between connectors.
56+
57+Example:
58+ usb_phy: phy@78d9000 {
59+ compatible = "qcom,usb-8x16-phy";
60+ reg = <0x78d9000 0x400>;
61+
62+ vddcx-supply = <&pm8916_s1_corner>;
63+ v1p8-supply = <&pm8916_l7>;
64+ v3p3-supply = <&pm8916_l13>;
65+
66+ clocks = <&gcc GCC_USB_HS_AHB_CLK>,
67+ <&gcc GCC_USB_HS_SYSTEM_CLK>;
68+ clock-names = "iface", "core";
69+
70+ resets = <&gcc GCC_USB2A_PHY_BCR>;
71+ reset-names = "phy";
72+
73+ // D+/D- lines: 1 - Routed to HUB, 0 - Device connector
74+ switch-gpio = <&pm8916_gpios 4 GPIO_ACTIVE_HIGH>;
75+ };
76+
Documentation/usb/gadget-testing.txt+2−5
@@ -237,9 +237,7 @@ Testing the LOOPBACK function · 236 unmodified lines
237237 -----------------------------
238238
239239 device: run the gadget
240−host: test-usb
241−
242−http://www.linux-usb.org/usbtest/testusb.c
240+host: test-usb (tools/usb/testusb.c)
243241
244242 8. MASS STORAGE function
245243 ========================
@@ -586,9 +584,8 @@ Testing the SOURCESINK function · 340 unmodified lines
586584 -------------------------------
587585
588586 device: run the gadget
589−host: test-usb
587+host: test-usb (tools/usb/testusb.c)
590588
591−http://www.linux-usb.org/usbtest/testusb.c
592589
593590 16. UAC1 function
594591 =================
drivers/staging/emxx_udc/emxx_udc.c+44−32
@@ -3153,36 +3153,46 @@ static const struct usb_gadget_ops nbu2ss_gadget_ops = { · 3152 unmodified lines
31533153 .ioctl = nbu2ss_gad_ioctl,
31543154 };
31553155
3156−static const char g_ep0_name[] = "ep0";
3157−static const char g_ep1_name[] = "ep1-bulk";
3158−static const char g_ep2_name[] = "ep2-bulk";
3159−static const char g_ep3_name[] = "ep3in-int";
3160−static const char g_ep4_name[] = "ep4-iso";
3161−static const char g_ep5_name[] = "ep5-iso";
3162−static const char g_ep6_name[] = "ep6-bulk";
3163−static const char g_ep7_name[] = "ep7-bulk";
3164−static const char g_ep8_name[] = "ep8in-int";
3165−static const char g_ep9_name[] = "ep9-iso";
3166−static const char g_epa_name[] = "epa-iso";
3167−static const char g_epb_name[] = "epb-bulk";
3168−static const char g_epc_name[] = "epc-nulk";
3169−static const char g_epd_name[] = "epdin-int";
3170−
3171−static const char *gp_ep_name[NUM_ENDPOINTS] = {
3172− g_ep0_name,
3173− g_ep1_name,
3174− g_ep2_name,
3175− g_ep3_name,
3176− g_ep4_name,
3177− g_ep5_name,
3178− g_ep6_name,
3179− g_ep7_name,
3180− g_ep8_name,
3181− g_ep9_name,
3182− g_epa_name,
3183− g_epb_name,
3184− g_epc_name,
3185− g_epd_name,
3156+static const struct {
3157+ const char *name;
3158+ const struct usb_ep_caps caps;
3159+} ep_info[NUM_ENDPOINTS] = {
3160+#define EP_INFO(_name, _caps) \
3161+ { \
3162+ .name = _name, \
3163+ .caps = _caps, \
3164+ }
3165+
3166+ EP_INFO("ep0",
3167+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
3168+ EP_INFO("ep1-bulk",
3169+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)),
3170+ EP_INFO("ep2-bulk",
3171+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)),
3172+ EP_INFO("ep3in-int",
3173+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)),
3174+ EP_INFO("ep4-iso",
3175+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)),
3176+ EP_INFO("ep5-iso",
3177+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)),
3178+ EP_INFO("ep6-bulk",
3179+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)),
3180+ EP_INFO("ep7-bulk",
3181+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)),
3182+ EP_INFO("ep8in-int",
3183+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)),
3184+ EP_INFO("ep9-iso",
3185+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)),
3186+ EP_INFO("epa-iso",
3187+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_ALL)),
3188+ EP_INFO("epb-bulk",
3189+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)),
3190+ EP_INFO("epc-bulk",
3191+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_ALL)),
3192+ EP_INFO("epdin-int",
3193+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)),
3194+
3195+#undef EP_INFO
31863196 };
31873197
31883198 /*-------------------------------------------------------------------------*/
@@ -3200,10 +3210,12 @@ static void __init nbu2ss_drv_ep_init(struct nbu2ss_udc *udc) · 11 unmodified lines
32003210 ep->desc = NULL;
32013211
32023212 ep->ep.driver_data = NULL;
3203− ep->ep.name = gp_ep_name[i];
3213+ ep->ep.name = ep_info[i].name;
3214+ ep->ep.caps = ep_info[i].caps;
32043215 ep->ep.ops = &nbu2ss_ep_ops;
32053216
3206− ep->ep.maxpacket = (i == 0 ? EP0_PACKETSIZE : EP_PACKETSIZE);
3217+ usb_ep_set_maxpacket_limit(&ep->ep,
3218+ i == 0 ? EP0_PACKETSIZE : EP_PACKETSIZE);
32073219
32083220 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
32093221 INIT_LIST_HEAD(&ep->queue);
drivers/usb/chipidea/ci.h+4−1
@@ -406,8 +406,11 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, enum ci_hw_regs reg, · 405 unmodified lines
406406 static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci)
407407 {
408408 #ifdef CONFIG_USB_OTG_FSM
409+ struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps;
410+
409411 return ci->is_otg && ci->roles[CI_ROLE_HOST] &&
410− ci->roles[CI_ROLE_GADGET];
412+ ci->roles[CI_ROLE_GADGET] && (otg_caps->srp_support ||
413+ otg_caps->hnp_support || otg_caps->adp_support);
411414 #else
412415 return false;
413416 #endif
drivers/usb/chipidea/core.c+15−0
@@ -560,6 +560,8 @@ static irqreturn_t ci_irq(int irq, void *data) · 559 unmodified lines
560560 static int ci_get_platdata(struct device *dev,
561561 struct ci_hdrc_platform_data *platdata)
562562 {
563+ int ret;
564+
563565 if (!platdata->phy_mode)
564566 platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
565567
@@ -588,6 +590,19 @@ static int ci_get_platdata(struct device *dev, · 22 unmodified lines
588590 of_usb_host_tpl_support(dev->of_node);
589591 }
590592
593+ if (platdata->dr_mode == USB_DR_MODE_OTG) {
594+ /* We can support HNP and SRP of OTG 2.0 */
595+ platdata->ci_otg_caps.otg_rev = 0x0200;
596+ platdata->ci_otg_caps.hnp_support = true;
597+ platdata->ci_otg_caps.srp_support = true;
598+
599+ /* Update otg capabilities by DT properties */
600+ ret = of_usb_update_otg_caps(dev->of_node,
601+ &platdata->ci_otg_caps);
602+ if (ret)
603+ return ret;
604+ }
605+
591606 if (of_usb_get_maximum_speed(dev->of_node) == USB_SPEED_FULL)
592607 platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
593608
drivers/usb/chipidea/debug.c+1−0
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/usb/phy.h>
1111 #include <linux/usb/otg.h>
1212 #include <linux/usb/otg-fsm.h>
13+#include <linux/usb/chipidea.h>
1314
1415 #include "ci.h"
1516 #include "udc.h"
drivers/usb/chipidea/udc.c+20−1
@@ -1624,6 +1624,20 @@ static int init_eps(struct ci_hdrc *ci) · 1623 unmodified lines
16241624
16251625 hwep->ep.name = hwep->name;
16261626 hwep->ep.ops = &usb_ep_ops;
1627+
1628+ if (i == 0) {
1629+ hwep->ep.caps.type_control = true;
1630+ } else {
1631+ hwep->ep.caps.type_iso = true;
1632+ hwep->ep.caps.type_bulk = true;
1633+ hwep->ep.caps.type_int = true;
1634+ }
1635+
1636+ if (j == TX)
1637+ hwep->ep.caps.dir_in = true;
1638+ else
1639+ hwep->ep.caps.dir_out = true;
1640+
16271641 /*
16281642 * for ep0: maxP defined in desc, for other
16291643 * eps, maxP is set by epautoconfig() called
@@ -1827,6 +1841,7 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci) · 197 unmodified lines
18271841 static int udc_start(struct ci_hdrc *ci)
18281842 {
18291843 struct device *dev = ci->dev;
1844+ struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps;
18301845 int retval = 0;
18311846
18321847 spin_lock_init(&ci->lock);
@@ -1834,8 +1849,12 @@ static int udc_start(struct ci_hdrc *ci) · 1 unmodified line
18341849 ci->gadget.ops = &usb_gadget_ops;
18351850 ci->gadget.speed = USB_SPEED_UNKNOWN;
18361851 ci->gadget.max_speed = USB_SPEED_HIGH;
1837− ci->gadget.is_otg = ci->is_otg ? 1 : 0;
18381852 ci->gadget.name = ci->platdata->name;
1853+ ci->gadget.otg_caps = otg_caps;
1854+
1855+ if (ci->is_otg && (otg_caps->hnp_support || otg_caps->srp_support ||
1856+ otg_caps->adp_support))
1857+ ci->gadget.is_otg = 1;
18391858
18401859 INIT_LIST_HEAD(&ci->gadget.ep_list);
18411860
drivers/usb/common/common.c+56−0
@@ -154,6 +154,62 @@ bool of_usb_host_tpl_support(struct device_node *np) · 153 unmodified lines
154154 return false;
155155 }
156156 EXPORT_SYMBOL_GPL(of_usb_host_tpl_support);
157+
158+/**
159+ * of_usb_update_otg_caps - to update usb otg capabilities according to
160+ * the passed properties in DT.
161+ * @np: Pointer to the given device_node
162+ * @otg_caps: Pointer to the target usb_otg_caps to be set
163+ *
164+ * The function updates the otg capabilities
165+ */
166+int of_usb_update_otg_caps(struct device_node *np,
167+ struct usb_otg_caps *otg_caps)
168+{
169+ u32 otg_rev;
170+
171+ if (!otg_caps)
172+ return -EINVAL;
173+
174+ if (!of_property_read_u32(np, "otg-rev", &otg_rev)) {
175+ switch (otg_rev) {
176+ case 0x0100:
177+ case 0x0120:
178+ case 0x0130:
179+ case 0x0200:
180+ /* Choose the lesser one if it's already been set */
181+ if (otg_caps->otg_rev)
182+ otg_caps->otg_rev = min_t(u16, otg_rev,
183+ otg_caps->otg_rev);
184+ else
185+ otg_caps->otg_rev = otg_rev;
186+ break;
187+ default:
188+ pr_err("%s: unsupported otg-rev: 0x%x\n",
189+ np->full_name, otg_rev);
190+ return -EINVAL;
191+ }
192+ } else {
193+ /*
194+ * otg-rev is mandatory for otg properties, if not passed
195+ * we set it to be 0 and assume it's a legacy otg device.
196+ * Non-dt platform can set it afterwards.
197+ */
198+ otg_caps->otg_rev = 0;
199+ }
200+
201+ if (of_find_property(np, "hnp-disable", NULL))
202+ otg_caps->hnp_support = false;
203+ if (of_find_property(np, "srp-disable", NULL))
204+ otg_caps->srp_support = false;
205+ if (of_find_property(np, "adp-disable", NULL) ||
206+ (otg_caps->otg_rev < 0x0200))
207+ otg_caps->adp_support = false;
208+
209+ return 0;
210+}
211+EXPORT_SYMBOL_GPL(of_usb_update_otg_caps);
212+
157213 #endif
158214
159215 MODULE_LICENSE("GPL");
drivers/usb/dwc2/gadget.c+14−1
@@ -2880,7 +2880,7 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) · 2879 unmodified lines
28802880 epctl = readl(hs->regs + epreg);
28812881
28822882 if (value) {
2883− epctl |= DXEPCTL_STALL + DXEPCTL_SNAK;
2883+ epctl |= DXEPCTL_STALL | DXEPCTL_SNAK;
28842884 if (epctl & DXEPCTL_EPENA)
28852885 epctl |= DXEPCTL_EPDIS;
28862886 } else {
@@ -3289,6 +3289,19 @@ static void s3c_hsotg_initep(struct dwc2_hsotg *hsotg, · 402 unmodified lines
32893289 usb_ep_set_maxpacket_limit(&hs_ep->ep, epnum ? 1024 : EP0_MPS_LIMIT);
32903290 hs_ep->ep.ops = &s3c_hsotg_ep_ops;
32913291
3292+ if (epnum == 0) {
3293+ hs_ep->ep.caps.type_control = true;
3294+ } else {
3295+ hs_ep->ep.caps.type_iso = true;
3296+ hs_ep->ep.caps.type_bulk = true;
3297+ hs_ep->ep.caps.type_int = true;
3298+ }
3299+
3300+ if (dir_in)
3301+ hs_ep->ep.caps.dir_in = true;
3302+ else
3303+ hs_ep->ep.caps.dir_out = true;
3304+
32923305 /*
32933306 * if we're using dma, we need to set the next-endpoint pointer
32943307 * to be something valid.
drivers/usb/dwc3/Kconfig+0−7
@@ -104,11 +104,4 @@ config USB_DWC3_QCOM · 103 unmodified lines
104104 Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside,
105105 say 'Y' or 'M' if you have one such device.
106106
107−comment "Debugging features"
108−
109−config USB_DWC3_DEBUG
110− bool "Enable Debugging Messages"
111− help
112− Say Y here to enable debugging messages on DWC3 Driver.
113−
114107 endif
drivers/usb/dwc3/Makefile+0−2
@@ -1,8 +1,6 @@
11 # define_trace.h needs to know how to find our header
22 CFLAGS_trace.o := -I$(src)
33
4−ccflags-$(CONFIG_USB_DWC3_DEBUG) := -DDEBUG
5−
64 obj-$(CONFIG_USB_DWC3) += dwc3.o
75
86 dwc3-y := core.o debug.o trace.o
drivers/usb/dwc3/core.c+0−2
@@ -455,8 +455,6 @@ static int dwc3_phy_setup(struct dwc3 *dwc) · 454 unmodified lines
455455 reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
456456 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
457457 } else {
458− dev_warn(dwc->dev, "HSPHY Interface not defined\n");
459−
460458 /* Relying on default value. */
461459 if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI))
462460 break;
drivers/usb/dwc3/dwc3-exynos.c+1−1
@@ -145,7 +145,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev) · 144 unmodified lines
145145
146146 exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk");
147147 if (IS_ERR(exynos->susp_clk)) {
148− dev_dbg(dev, "no suspend clk specified\n");
148+ dev_info(dev, "no suspend clk specified\n");
149149 exynos->susp_clk = NULL;
150150 }
151151 clk_prepare_enable(exynos->susp_clk);
drivers/usb/dwc3/dwc3-keystone.c+1−1
@@ -115,7 +115,7 @@ static int kdwc3_probe(struct platform_device *pdev) · 114 unmodified lines
115115
116116 error = clk_prepare_enable(kdwc->clk);
117117 if (error < 0) {
118− dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
118+ dev_err(kdwc->dev, "unable to enable usb clock, error %d\n",
119119 error);
120120 return error;
121121 }
drivers/usb/dwc3/dwc3-omap.c+17−58
@@ -128,8 +128,7 @@ struct dwc3_omap { · 127 unmodified lines
128128
129129 u32 dma_status:1;
130130
131− struct extcon_specific_cable_nb extcon_vbus_dev;
132− struct extcon_specific_cable_nb extcon_id_dev;
131+ struct extcon_dev *edev;
133132 struct notifier_block vbus_nb;
134133 struct notifier_block id_nb;
135134
@@ -225,12 +224,10 @@ static void dwc3_omap_set_mailbox(struct dwc3_omap *omap, · 89 unmodified lines
225224
226225 switch (status) {
227226 case OMAP_DWC3_ID_GROUND:
228− dev_dbg(omap->dev, "ID GND\n");
229−
230227 if (omap->vbus_reg) {
231228 ret = regulator_enable(omap->vbus_reg);
232229 if (ret) {
233− dev_dbg(omap->dev, "regulator enable failed\n");
230+ dev_err(omap->dev, "regulator enable failed\n");
234231 return;
235232 }
236233 }
@@ -245,8 +242,6 @@ static void dwc3_omap_set_mailbox(struct dwc3_omap *omap, · 8 unmodified lines
245242 break;
246243
247244 case OMAP_DWC3_VBUS_VALID:
248− dev_dbg(omap->dev, "VBUS Connect\n");
249−
250245 val = dwc3_omap_read_utmi_ctrl(omap);
251246 val &= ~USBOTGSS_UTMI_OTG_CTRL_SESSEND;
252247 val |= USBOTGSS_UTMI_OTG_CTRL_IDDIG
@@ -261,8 +256,6 @@ static void dwc3_omap_set_mailbox(struct dwc3_omap *omap, · 8 unmodified lines
261256 regulator_disable(omap->vbus_reg);
262257
263258 case OMAP_DWC3_VBUS_OFF:
264− dev_dbg(omap->dev, "VBUS Disconnect\n");
265−
266259 val = dwc3_omap_read_utmi_ctrl(omap);
267260 val &= ~(USBOTGSS_UTMI_OTG_CTRL_SESSVALID
268261 | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID
@@ -273,7 +266,7 @@ static void dwc3_omap_set_mailbox(struct dwc3_omap *omap, · 4 unmodified lines
273266 break;
274267
275268 default:
276− dev_dbg(omap->dev, "invalid state\n");
269+ dev_WARN(omap->dev, "invalid state\n");
277270 }
278271 }
279272
@@ -284,37 +277,8 @@ static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) · 4 unmodified lines
284277
285278 reg = dwc3_omap_read_irqmisc_status(omap);
286279
287− if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) {
288− dev_dbg(omap->dev, "DMA Disable was Cleared\n");
280+ if (reg & USBOTGSS_IRQMISC_DMADISABLECLR)
289281 omap->dma_status = false;
290− }
291−
292− if (reg & USBOTGSS_IRQMISC_OEVT)
293− dev_dbg(omap->dev, "OTG Event\n");
294−
295− if (reg & USBOTGSS_IRQMISC_DRVVBUS_RISE)
296− dev_dbg(omap->dev, "DRVVBUS Rise\n");
297−
298− if (reg & USBOTGSS_IRQMISC_CHRGVBUS_RISE)
299− dev_dbg(omap->dev, "CHRGVBUS Rise\n");
300−
301− if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_RISE)
302− dev_dbg(omap->dev, "DISCHRGVBUS Rise\n");
303−
304− if (reg & USBOTGSS_IRQMISC_IDPULLUP_RISE)
305− dev_dbg(omap->dev, "IDPULLUP Rise\n");
306−
307− if (reg & USBOTGSS_IRQMISC_DRVVBUS_FALL)
308− dev_dbg(omap->dev, "DRVVBUS Fall\n");
309−
310− if (reg & USBOTGSS_IRQMISC_CHRGVBUS_FALL)
311− dev_dbg(omap->dev, "CHRGVBUS Fall\n");
312−
313− if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_FALL)
314− dev_dbg(omap->dev, "DISCHRGVBUS Fall\n");
315−
316− if (reg & USBOTGSS_IRQMISC_IDPULLUP_FALL)
317− dev_dbg(omap->dev, "IDPULLUP Fall\n");
318282
319283 dwc3_omap_write_irqmisc_status(omap, reg);
320284
@@ -434,7 +398,7 @@ static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap) · 113 unmodified lines
434398 reg &= ~USBOTGSS_UTMI_OTG_CTRL_SW_MODE;
435399 break;
436400 default:
437− dev_dbg(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode);
401+ dev_WARN(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode);
438402 }
439403
440404 dwc3_omap_write_utmi_ctrl(omap, reg);
@@ -454,23 +418,23 @@ static int dwc3_omap_extcon_register(struct dwc3_omap *omap) · 13 unmodified lines
454418 }
455419
456420 omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
457− ret = extcon_register_interest(&omap->extcon_vbus_dev,
458− edev->name, "USB",
459− &omap->vbus_nb);
421+ ret = extcon_register_notifier(edev, EXTCON_USB,
422+ &omap->vbus_nb);
460423 if (ret < 0)
461424 dev_vdbg(omap->dev, "failed to register notifier for USB\n");
462425
463426 omap->id_nb.notifier_call = dwc3_omap_id_notifier;
464− ret = extcon_register_interest(&omap->extcon_id_dev,
465− edev->name, "USB-HOST",
466− &omap->id_nb);
427+ ret = extcon_register_notifier(edev, EXTCON_USB_HOST,
428+ &omap->id_nb);
467429 if (ret < 0)
468430 dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n");
469431
470− if (extcon_get_cable_state(edev, "USB") == true)
432+ if (extcon_get_cable_state_(edev, EXTCON_USB) == true)
471433 dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
472− if (extcon_get_cable_state(edev, "USB-HOST") == true)
434+ if (extcon_get_cable_state_(edev, EXTCON_USB_HOST) == true)
473435 dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
436+
437+ omap->edev = edev;
474438 }
475439
476440 return 0;
@@ -565,11 +529,8 @@ static int dwc3_omap_probe(struct platform_device *pdev) · 88 unmodified lines
565529 return 0;
566530
567531 err3:
568− if (omap->extcon_vbus_dev.edev)
569− extcon_unregister_interest(&omap->extcon_vbus_dev);
570− if (omap->extcon_id_dev.edev)
571− extcon_unregister_interest(&omap->extcon_id_dev);
572−
532+ extcon_unregister_notifier(omap->edev, EXTCON_USB, &omap->vbus_nb);
533+ extcon_unregister_notifier(omap->edev, EXTCON_USB_HOST, &omap->id_nb);
573534 err2:
574535 dwc3_omap_disable_irqs(omap);
575536
@@ -586,10 +547,8 @@ static int dwc3_omap_remove(struct platform_device *pdev) · 10 unmodified lines
586547 {
587548 struct dwc3_omap *omap = platform_get_drvdata(pdev);
588549
589− if (omap->extcon_vbus_dev.edev)
590− extcon_unregister_interest(&omap->extcon_vbus_dev);
591− if (omap->extcon_id_dev.edev)
592− extcon_unregister_interest(&omap->extcon_id_dev);
550+ extcon_unregister_notifier(omap->edev, EXTCON_USB, &omap->vbus_nb);
551+ extcon_unregister_notifier(omap->edev, EXTCON_USB_HOST, &omap->id_nb);
593552 dwc3_omap_disable_irqs(omap);
594553 of_platform_depopulate(omap->dev);
595554 pm_runtime_put_sync(&pdev->dev);
drivers/usb/dwc3/dwc3-pci.c+16−10
@@ -83,17 +83,23 @@ static int dwc3_pci_quirks(struct pci_dev *pdev) · 82 unmodified lines
8383 acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev),
8484 acpi_dwc3_byt_gpios);
8585
86− /* These GPIOs will turn on the USB2 PHY */
87− gpio = gpiod_get(&pdev->dev, "cs");
88− if (!IS_ERR(gpio)) {
89− gpiod_direction_output(gpio, 0);
90− gpiod_set_value_cansleep(gpio, 1);
91− gpiod_put(gpio);
92− }
86+ /*
87+ * These GPIOs will turn on the USB2 PHY. Note that we have to
88+ * put the gpio descriptors again here because the phy driver
89+ * might want to grab them, too.
90+ */
91+ gpio = gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
92+ if (IS_ERR(gpio))
93+ return PTR_ERR(gpio);
94+
95+ gpiod_set_value_cansleep(gpio, 1);
96+ gpiod_put(gpio);
97+
98+ gpio = gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
99+ if (IS_ERR(gpio))
100+ return PTR_ERR(gpio);
93101
94− gpio = gpiod_get(&pdev->dev, "reset");
95− if (!IS_ERR(gpio)) {
96− gpiod_direction_output(gpio, 0);
102+ if (gpio) {
97103 gpiod_set_value_cansleep(gpio, 1);
98104 gpiod_put(gpio);
99105 usleep_range(10000, 11000);
drivers/usb/dwc3/dwc3-qcom.c+2−2
@@ -48,13 +48,13 @@ static int dwc3_qcom_probe(struct platform_device *pdev) · 47 unmodified lines
4848
4949 qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
5050 if (IS_ERR(qdwc->iface_clk)) {
51− dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
51+ dev_info(qdwc->dev, "failed to get optional iface clock\n");
5252 qdwc->iface_clk = NULL;
5353 }
5454
5555 qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
5656 if (IS_ERR(qdwc->sleep_clk)) {
57− dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");
57+ dev_info(qdwc->dev, "failed to get optional sleep clock\n");
5858 qdwc->sleep_clk = NULL;
5959 }
6060
drivers/usb/dwc3/dwc3-st.c+0−4
@@ -135,8 +135,6 @@ static int st_dwc3_drd_init(struct st_dwc3 *dwc3_data) · 134 unmodified lines
135135 | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
136136
137137 val |= USB3_DEVICE_NOT_HOST;
138−
139− dev_dbg(dwc3_data->dev, "Configuring as Device\n");
140138 break;
141139
142140 case USB_DR_MODE_HOST:
@@ -154,8 +152,6 @@ static int st_dwc3_drd_init(struct st_dwc3 *dwc3_data) · 11 unmodified lines
154152 */
155153
156154 val |= USB3_DELAY_VBUSVALID;
157−
158− dev_dbg(dwc3_data->dev, "Configuring as Host\n");
159155 break;
160156
161157 default:
drivers/usb/dwc3/ep0.c+66−26
@@ -56,7 +56,7 @@ static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state) · 55 unmodified lines
5656 }
5757
5858 static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
59− u32 len, u32 type)
59+ u32 len, u32 type, bool chain)
6060 {
6161 struct dwc3_gadget_ep_cmd_params params;
6262 struct dwc3_trb *trb;
@@ -70,7 +70,10 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, · 7 unmodified lines
7070 return 0;
7171 }
7272
73− trb = dwc->ep0_trb;
73+ trb = &dwc->ep0_trb[dep->free_slot];
74+
75+ if (chain)
76+ dep->free_slot++;
7477
7578 trb->bpl = lower_32_bits(buf_dma);
7679 trb->bph = upper_32_bits(buf_dma);
@@ -78,10 +81,17 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, · 1 unmodified line
7881 trb->ctrl = type;
7982
8083 trb->ctrl |= (DWC3_TRB_CTRL_HWO
81− | DWC3_TRB_CTRL_LST
82− | DWC3_TRB_CTRL_IOC
8384 | DWC3_TRB_CTRL_ISP_IMI);
8485
86+ if (chain)
87+ trb->ctrl |= DWC3_TRB_CTRL_CHN;
88+ else
89+ trb->ctrl |= (DWC3_TRB_CTRL_IOC
90+ | DWC3_TRB_CTRL_LST);
91+
92+ if (chain)
93+ return 0;
94+
8595 memset(&params, 0, sizeof(params));
8696 params.param0 = upper_32_bits(dwc->ep0_trb_addr);
8797 params.param1 = lower_32_bits(dwc->ep0_trb_addr);
@@ -302,7 +312,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc) · 214 unmodified lines
302312 int ret;
303313
304314 ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
305− DWC3_TRBCTL_CONTROL_SETUP);
315+ DWC3_TRBCTL_CONTROL_SETUP, false);
306316 WARN_ON(ret < 0);
307317 }
308318
@@ -783,7 +793,11 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, · 474 unmodified lines
783793 struct usb_request *ur;
784794 struct dwc3_trb *trb;
785795 struct dwc3_ep *ep0;
786− u32 transferred;
796+ unsigned transfer_size = 0;
797+ unsigned maxp;
798+ unsigned remaining_ur_length;
799+ void *buf;
800+ u32 transferred = 0;
787801 u32 status;
788802 u32 length;
789803 u8 epnum;
@@ -812,17 +826,37 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, · 22 unmodified lines
812826 }
813827
814828 ur = &r->request;
829+ buf = ur->buf;
830+ remaining_ur_length = ur->length;
815831
816832 length = trb->size & DWC3_TRB_SIZE_MASK;
817833
834+ maxp = ep0->endpoint.maxpacket;
835+
818836 if (dwc->ep0_bounced) {
819− unsigned transfer_size = ur->length;
820− unsigned maxp = ep0->endpoint.maxpacket;
837+ /*
838+ * Handle the first TRB before handling the bounce buffer if
839+ * the request length is greater than the bounce buffer size
840+ */
841+ if (ur->length > DWC3_EP0_BOUNCE_SIZE) {
842+ transfer_size = ALIGN(ur->length - maxp, maxp);
843+ transferred = transfer_size - length;
844+ buf = (u8 *)buf + transferred;
845+ ur->actual += transferred;
846+ remaining_ur_length -= transferred;
847+
848+ trb++;
849+ length = trb->size & DWC3_TRB_SIZE_MASK;
821850
822− transfer_size += (maxp - (transfer_size % maxp));
823− transferred = min_t(u32, ur->length,
824− transfer_size - length);
825− memcpy(ur->buf, dwc->ep0_bounce, transferred);
851+ ep0->free_slot = 0;
852+ }
853+
854+ transfer_size = roundup((ur->length - transfer_size),
855+ maxp);
856+
857+ transferred = min_t(u32, remaining_ur_length,
858+ transfer_size - length);
859+ memcpy(buf, dwc->ep0_bounce, transferred);
826860 } else {
827861 transferred = ur->length - length;
828862 }
@@ -844,7 +878,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, · 15 unmodified lines
844878
845879 ret = dwc3_ep0_start_trans(dwc, epnum,
846880 dwc->ctrl_req_addr, 0,
847− DWC3_TRBCTL_CONTROL_DATA);
881+ DWC3_TRBCTL_CONTROL_DATA, false);
848882 WARN_ON(ret < 0);
849883 }
850884 }
@@ -928,10 +962,10 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, · 77 unmodified lines
928962 if (req->request.length == 0) {
929963 ret = dwc3_ep0_start_trans(dwc, dep->number,
930964 dwc->ctrl_req_addr, 0,
931− DWC3_TRBCTL_CONTROL_DATA);
965+ DWC3_TRBCTL_CONTROL_DATA, false);
932966 } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket)
933967 && (dep->number == 0)) {
934− u32 transfer_size;
968+ u32 transfer_size = 0;
935969 u32 maxpacket;
936970
937971 ret = usb_gadget_map_request(&dwc->gadget, &req->request,
@@ -941,21 +975,26 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, · 3 unmodified lines
941975 return;
942976 }
943977
944− WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
945−
946978 maxpacket = dep->endpoint.maxpacket;
947− transfer_size = roundup(req->request.length, maxpacket);
979+
980+ if (req->request.length > DWC3_EP0_BOUNCE_SIZE) {
981+ transfer_size = ALIGN(req->request.length - maxpacket,
982+ maxpacket);
983+ ret = dwc3_ep0_start_trans(dwc, dep->number,
984+ req->request.dma,
985+ transfer_size,
986+ DWC3_TRBCTL_CONTROL_DATA,
987+ true);
988+ }
989+
990+ transfer_size = roundup((req->request.length - transfer_size),
991+ maxpacket);
948992
949993 dwc->ep0_bounced = true;
950994
951− /*
952− * REVISIT in case request length is bigger than
953− * DWC3_EP0_BOUNCE_SIZE we will need two chained
954− * TRBs to handle the transfer.
955− */
956995 ret = dwc3_ep0_start_trans(dwc, dep->number,
957996 dwc->ep0_bounce_addr, transfer_size,
958− DWC3_TRBCTL_CONTROL_DATA);
997+ DWC3_TRBCTL_CONTROL_DATA, false);
959998 } else {
960999 ret = usb_gadget_map_request(&dwc->gadget, &req->request,
9611000 dep->number);
@@ -965,7 +1004,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, · 3 unmodified lines
9651004 }
9661005
9671006 ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma,
968− req->request.length, DWC3_TRBCTL_CONTROL_DATA);
1007+ req->request.length, DWC3_TRBCTL_CONTROL_DATA,
1008+ false);
9691009 }
9701010
9711011 WARN_ON(ret < 0);
@@ -980,7 +1020,7 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep *dep) · 8 unmodified lines
9801020 : DWC3_TRBCTL_CONTROL_STATUS2;
9811021
9821022 return dwc3_ep0_start_trans(dwc, dep->number,
983− dwc->ctrl_req_addr, 0, type);
1023+ dwc->ctrl_req_addr, 0, type, false);
9841024 }
9851025
9861026 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
drivers/usb/dwc3/gadget.c+35−22
@@ -547,6 +547,23 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, · 546 unmodified lines
547547 trb_link->ctrl |= DWC3_TRB_CTRL_HWO;
548548 }
549549
550+ switch (usb_endpoint_type(desc)) {
551+ case USB_ENDPOINT_XFER_CONTROL:
552+ strlcat(dep->name, "-control", sizeof(dep->name));
553+ break;
554+ case USB_ENDPOINT_XFER_ISOC:
555+ strlcat(dep->name, "-isoc", sizeof(dep->name));
556+ break;
557+ case USB_ENDPOINT_XFER_BULK:
558+ strlcat(dep->name, "-bulk", sizeof(dep->name));
559+ break;
560+ case USB_ENDPOINT_XFER_INT:
561+ strlcat(dep->name, "-int", sizeof(dep->name));
562+ break;
563+ default:
564+ dev_err(dwc->dev, "invalid endpoint transfer type\n");
565+ }
566+
550567 return 0;
551568 }
552569
@@ -586,6 +603,8 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) · 33 unmodified lines
586603 struct dwc3 *dwc = dep->dwc;
587604 u32 reg;
588605
606+ dwc3_trace(trace_dwc3_gadget, "Disabling %s", dep->name);
607+
589608 dwc3_remove_requests(dwc, dep);
590609
591610 /* make sure HW endpoint isn't stalled */
@@ -602,6 +621,10 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) · 10 unmodified lines
602621 dep->type = 0;
603622 dep->flags = 0;
604623
624+ snprintf(dep->name, sizeof(dep->name), "ep%d%s",
625+ dep->number >> 1,
626+ (dep->number & 1) ? "in" : "out");
627+
605628 return 0;
606629 }
607630
@@ -647,23 +670,6 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep, · 39 unmodified lines
647670 return 0;
648671 }
649672
650− switch (usb_endpoint_type(desc)) {
651− case USB_ENDPOINT_XFER_CONTROL:
652− strlcat(dep->name, "-control", sizeof(dep->name));
653− break;
654− case USB_ENDPOINT_XFER_ISOC:
655− strlcat(dep->name, "-isoc", sizeof(dep->name));
656− break;
657− case USB_ENDPOINT_XFER_BULK:
658− strlcat(dep->name, "-bulk", sizeof(dep->name));
659− break;
660− case USB_ENDPOINT_XFER_INT:
661− strlcat(dep->name, "-int", sizeof(dep->name));
662− break;
663− default:
664− dev_err(dwc->dev, "invalid endpoint transfer type\n");
665− }
666−
667673 spin_lock_irqsave(&dwc->lock, flags);
668674 ret = __dwc3_gadget_ep_enable(dep, desc, ep->comp_desc, false, false);
669675 spin_unlock_irqrestore(&dwc->lock, flags);
@@ -692,10 +698,6 @@ static int dwc3_gadget_ep_disable(struct usb_ep *ep) · 22 unmodified lines
692698 return 0;
693699 }
694700
695− snprintf(dep->name, sizeof(dep->name), "ep%d%s",
696− dep->number >> 1,
697− (dep->number & 1) ? "in" : "out");
698−
699701 spin_lock_irqsave(&dwc->lock, flags);
700702 ret = __dwc3_gadget_ep_disable(dep);
701703 spin_unlock_irqrestore(&dwc->lock, flags);
@@ -1713,6 +1715,17 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc, · 1011 unmodified lines
17131715 return ret;
17141716 }
17151717
1718+ if (epnum == 0 || epnum == 1) {
1719+ dep->endpoint.caps.type_control = true;
1720+ } else {
1721+ dep->endpoint.caps.type_iso = true;
1722+ dep->endpoint.caps.type_bulk = true;
1723+ dep->endpoint.caps.type_int = true;
1724+ }
1725+
1726+ dep->endpoint.caps.dir_in = !!direction;
1727+ dep->endpoint.caps.dir_out = !direction;
1728+
17161729 INIT_LIST_HEAD(&dep->request_list);
17171730 INIT_LIST_HEAD(&dep->req_queued);
17181731 }
@@ -2685,7 +2698,7 @@ int dwc3_gadget_init(struct dwc3 *dwc) · 966 unmodified lines
26852698 goto err0;
26862699 }
26872700
2688− dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
2701+ dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
26892702 &dwc->ep0_trb_addr, GFP_KERNEL);
26902703 if (!dwc->ep0_trb) {
26912704 dev_err(dwc->dev, "failed to allocate ep0 trb\n");
drivers/usb/gadget/composite.c+37−4
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <linux/utsname.h>
2020
2121 #include <linux/usb/composite.h>
22+#include <linux/usb/otg.h>
2223 #include <asm/unaligned.h>
2324
2425 #include "u_os_desc.h"
@@ -209,6 +210,12 @@ int usb_add_function(struct usb_configuration *config, · 184 unmodified lines
209210 function->config = config;
210211 list_add_tail(&function->list, &config->functions);
211212
213+ if (function->bind_deactivated) {
214+ value = usb_function_deactivate(function);
215+ if (value)
216+ goto done;
217+ }
218+
212219 /* REVISIT *require* function->bind? */
213220 if (function->bind) {
214221 value = function->bind(config, function);
@@ -279,7 +286,7 @@ int usb_function_deactivate(struct usb_function *function) · 64 unmodified lines
279286 spin_lock_irqsave(&cdev->lock, flags);
280287
281288 if (cdev->deactivations == 0)
282− status = usb_gadget_disconnect(cdev->gadget);
289+ status = usb_gadget_deactivate(cdev->gadget);
283290 if (status == 0)
284291 cdev->deactivations++;
285292
@@ -311,7 +318,7 @@ int usb_function_activate(struct usb_function *function) · 25 unmodified lines
311318 else {
312319 cdev->deactivations--;
313320 if (cdev->deactivations == 0)
314− status = usb_gadget_connect(cdev->gadget);
321+ status = usb_gadget_activate(cdev->gadget);
315322 }
316323
317324 spin_unlock_irqrestore(&cdev->lock, flags);
@@ -896,7 +903,7 @@ void usb_remove_config(struct usb_composite_dev *cdev, · 578 unmodified lines
896903
897904 /* We support strings in multiple languages ... string descriptor zero
898905 * says which languages are supported. The typical case will be that
899− * only one language (probably English) is used, with I18N handled on
906+ * only one language (probably English) is used, with i18n handled on
900907 * the host side.
901908 */
902909
@@ -949,7 +956,7 @@ static int get_string(struct usb_composite_dev *cdev, · 46 unmodified lines
949956 struct usb_function *f;
950957 int len;
951958
952− /* Yes, not only is USB's I18N support probably more than most
959+ /* Yes, not only is USB's i18n support probably more than most
953960 * folk will ever care about ... also, it's all supported here.
954961 * (Except for UTF8 support for Unicode's "Astral Planes".)
955962 */
@@ -1534,6 +1541,32 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) · 578 unmodified lines
15341541 value = min(w_length, (u16) value);
15351542 }
15361543 break;
1544+ case USB_DT_OTG:
1545+ if (gadget_is_otg(gadget)) {
1546+ struct usb_configuration *config;
1547+ int otg_desc_len = 0;
1548+
1549+ if (cdev->config)
1550+ config = cdev->config;
1551+ else
1552+ config = list_first_entry(
1553+ &cdev->configs,
1554+ struct usb_configuration, list);
1555+ if (!config)
1556+ goto done;
1557+
1558+ if (gadget->otg_caps &&
1559+ (gadget->otg_caps->otg_rev >= 0x0200))
1560+ otg_desc_len += sizeof(
1561+ struct usb_otg20_descriptor);
1562+ else
1563+ otg_desc_len += sizeof(
1564+ struct usb_otg_descriptor);
1565+
1566+ value = min_t(int, w_length, otg_desc_len);
1567+ memcpy(req->buf, config->descriptors[0], value);
1568+ }
1569+ break;
15371570 }
15381571 break;
15391572
drivers/usb/gadget/config.c+56−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 #include <linux/usb/ch9.h>
2121 #include <linux/usb/gadget.h>
2222 #include <linux/usb/composite.h>
23+#include <linux/usb/otg.h>
2324
2425 /**
2526 * usb_descriptor_fillbuf - fill buffer with descriptors
@@ -195,3 +196,58 @@ void usb_free_all_descriptors(struct usb_function *f) · 169 unmodified lines
195196 usb_free_descriptors(f->ss_descriptors);
196197 }
197198 EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
199+
200+struct usb_descriptor_header *usb_otg_descriptor_alloc(
201+ struct usb_gadget *gadget)
202+{
203+ struct usb_descriptor_header *otg_desc;
204+ unsigned length = 0;
205+
206+ if (gadget->otg_caps && (gadget->otg_caps->otg_rev >= 0x0200))
207+ length = sizeof(struct usb_otg20_descriptor);
208+ else
209+ length = sizeof(struct usb_otg_descriptor);
210+
211+ otg_desc = kzalloc(length, GFP_KERNEL);
212+ return otg_desc;
213+}
214+EXPORT_SYMBOL_GPL(usb_otg_descriptor_alloc);
215+
216+int usb_otg_descriptor_init(struct usb_gadget *gadget,
217+ struct usb_descriptor_header *otg_desc)
218+{
219+ struct usb_otg_descriptor *otg1x_desc;
220+ struct usb_otg20_descriptor *otg20_desc;
221+ struct usb_otg_caps *otg_caps = gadget->otg_caps;
222+ u8 otg_attributes = 0;
223+
224+ if (!otg_desc)
225+ return -EINVAL;
226+
227+ if (otg_caps && otg_caps->otg_rev) {
228+ if (otg_caps->hnp_support)
229+ otg_attributes |= USB_OTG_HNP;
230+ if (otg_caps->srp_support)
231+ otg_attributes |= USB_OTG_SRP;
232+ if (otg_caps->adp_support && (otg_caps->otg_rev >= 0x0200))
233+ otg_attributes |= USB_OTG_ADP;
234+ } else {
235+ otg_attributes = USB_OTG_SRP | USB_OTG_HNP;
236+ }
237+
238+ if (otg_caps && (otg_caps->otg_rev >= 0x0200)) {
239+ otg20_desc = (struct usb_otg20_descriptor *)otg_desc;
240+ otg20_desc->bLength = sizeof(struct usb_otg20_descriptor);
241+ otg20_desc->bDescriptorType = USB_DT_OTG;
242+ otg20_desc->bmAttributes = otg_attributes;
243+ otg20_desc->bcdOTG = cpu_to_le16(otg_caps->otg_rev);
244+ } else {
245+ otg1x_desc = (struct usb_otg_descriptor *)otg_desc;
246+ otg1x_desc->bLength = sizeof(struct usb_otg_descriptor);
247+ otg1x_desc->bDescriptorType = USB_DT_OTG;
248+ otg1x_desc->bmAttributes = otg_attributes;
249+ }
250+
251+ return 0;
252+}
253+EXPORT_SYMBOL_GPL(usb_otg_descriptor_init);
drivers/usb/gadget/configfs.c+20−9
@@ -41,6 +41,8 @@ int check_user_usb_string(const char *name, · 40 unmodified lines
4141 #define MAX_NAME_LEN 40
4242 #define MAX_USB_STRING_LANGS 2
4343
44+static const struct usb_descriptor_header *otg_desc[2];
45+
4446 struct gadget_info {
4547 struct config_group group;
4648 struct config_group functions_group;
@@ -55,9 +57,6 @@ struct gadget_info { · 8 unmodified lines
5557 struct list_head available_func;
5658
5759 const char *udc_name;
58−#ifdef CONFIG_USB_OTG
59− struct usb_otg_descriptor otg;
60−#endif
6160 struct usb_composite_driver composite;
6261 struct usb_composite_dev cdev;
6362 bool use_os_desc;
@@ -1376,6 +1375,19 @@ static int configfs_composite_bind(struct usb_gadget *gadget, · 1312 unmodified lines
13761375 memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
13771376 }
13781377
1378+ if (gadget_is_otg(gadget) && !otg_desc[0]) {
1379+ struct usb_descriptor_header *usb_desc;
1380+
1381+ usb_desc = usb_otg_descriptor_alloc(gadget);
1382+ if (!usb_desc) {
1383+ ret = -ENOMEM;
1384+ goto err_comp_cleanup;
1385+ }
1386+ usb_otg_descriptor_init(gadget, usb_desc);
1387+ otg_desc[0] = usb_desc;
1388+ otg_desc[1] = NULL;
1389+ }
1390+
13791391 /* Go through all configs, attach all functions */
13801392 list_for_each_entry(c, &gi->cdev.configs, list) {
13811393 struct config_usb_cfg *cfg;
@@ -1383,6 +1395,9 @@ static int configfs_composite_bind(struct usb_gadget *gadget, · 1 unmodified line
13831395 struct usb_function *tmp;
13841396 struct gadget_config_name *cn;
13851397
1398+ if (gadget_is_otg(gadget))
1399+ c->descriptors = otg_desc;
1400+
13861401 cfg = container_of(c, struct config_usb_cfg, c);
13871402 if (!list_empty(&cfg->string_list)) {
13881403 i = 0;
@@ -1437,6 +1452,8 @@ static void configfs_composite_unbind(struct usb_gadget *gadget) · 48 unmodified lines
14371452 cdev = get_gadget_data(gadget);
14381453 gi = container_of(cdev, struct gadget_info, cdev);
14391454
1455+ kfree(otg_desc[0]);
1456+ otg_desc[0] = NULL;
14401457 purge_configs_funcs(gi);
14411458 composite_dev_cleanup(cdev);
14421459 usb_ep_autoconfig_reset(cdev->gadget);
@@ -1510,12 +1527,6 @@ static struct config_group *gadgets_make( · 67 unmodified lines
15101527 if (!gi->composite.gadget_driver.function)
15111528 goto err;
15121529
1513−#ifdef CONFIG_USB_OTG
1514− gi->otg.bLength = sizeof(struct usb_otg_descriptor);
1515− gi->otg.bDescriptorType = USB_DT_OTG;
1516− gi->otg.bmAttributes = USB_OTG_SRP | USB_OTG_HNP;
1517−#endif
1518−
15191530 config_group_init_type_name(&gi->group, name,
15201531 &gadget_root_type);
15211532 return &gi->group;
drivers/usb/gadget/epautoconf.c+43−239
@@ -20,186 +20,6 @@ · 19 unmodified lines
2020 #include <linux/usb/ch9.h>
2121 #include <linux/usb/gadget.h>
2222
23−#include "gadget_chips.h"
24−
25−/*
26− * This should work with endpoints from controller drivers sharing the
27− * same endpoint naming convention. By example:
28− *
29− * - ep1, ep2, ... address is fixed, not direction or type
30− * - ep1in, ep2out, ... address and direction are fixed, not type
31− * - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction
32− * - ep1in-bulk, ep2out-iso, ... all three are fixed
33− * - ep-* ... no functionality restrictions
34− *
35− * Type suffixes are "-bulk", "-iso", or "-int". Numbers are decimal.
36− * Less common restrictions are implied by gadget_is_*().
37− *
38− * NOTE: each endpoint is unidirectional, as specified by its USB
39− * descriptor; and isn't specific to a configuration or altsetting.
40− */
41−static int
42−ep_matches (
43− struct usb_gadget *gadget,
44− struct usb_ep *ep,
45− struct usb_endpoint_descriptor *desc,
46− struct usb_ss_ep_comp_descriptor *ep_comp
47−)
48−{
49− u8 type;
50− const char *tmp;
51− u16 max;
52−
53− int num_req_streams = 0;
54−
55− /* endpoint already claimed? */
56− if (NULL != ep->driver_data)
57− return 0;
58−
59− /* only support ep0 for portable CONTROL traffic */
60− type = usb_endpoint_type(desc);
61− if (USB_ENDPOINT_XFER_CONTROL == type)
62− return 0;
63−
64− /* some other naming convention */
65− if ('e' != ep->name[0])
66− return 0;
67−
68− /* type-restriction: "-iso", "-bulk", or "-int".
69− * direction-restriction: "in", "out".
70− */
71− if ('-' != ep->name[2]) {
72− tmp = strrchr (ep->name, '-');
73− if (tmp) {
74− switch (type) {
75− case USB_ENDPOINT_XFER_INT:
76− /* bulk endpoints handle interrupt transfers,
77− * except the toggle-quirky iso-synch kind
78− */
79− if ('s' == tmp[2]) // == "-iso"
80− return 0;
81− /* for now, avoid PXA "interrupt-in";
82− * it's documented as never using DATA1.
83− */
84− if (gadget_is_pxa (gadget)
85− && 'i' == tmp [1])
86− return 0;
87− break;
88− case USB_ENDPOINT_XFER_BULK:
89− if ('b' != tmp[1]) // != "-bulk"
90− return 0;
91− break;
92− case USB_ENDPOINT_XFER_ISOC:
93− if ('s' != tmp[2]) // != "-iso"
94− return 0;
95− }
96− } else {
97− tmp = ep->name + strlen (ep->name);
98− }
99−
100− /* direction-restriction: "..in-..", "out-.." */
101− tmp--;
102− if (!isdigit (*tmp)) {
103− if (desc->bEndpointAddress & USB_DIR_IN) {
104− if ('n' != *tmp)
105− return 0;
106− } else {
107− if ('t' != *tmp)
108− return 0;
109− }
110− }
111− }
112−
113− /*
114− * Get the number of required streams from the EP companion
115− * descriptor and see if the EP matches it
116− */
117− if (usb_endpoint_xfer_bulk(desc)) {
118− if (ep_comp && gadget->max_speed >= USB_SPEED_SUPER) {
119− num_req_streams = ep_comp->bmAttributes & 0x1f;
120− if (num_req_streams > ep->max_streams)
121− return 0;
122− }
123−
124− }
125−
126− /*
127− * If the protocol driver hasn't yet decided on wMaxPacketSize
128− * and wants to know the maximum possible, provide the info.
129− */
130− if (desc->wMaxPacketSize == 0)
131− desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket_limit);
132−
133− /* endpoint maxpacket size is an input parameter, except for bulk
134− * where it's an output parameter representing the full speed limit.
135− * the usb spec fixes high speed bulk maxpacket at 512 bytes.
136− */
137− max = 0x7ff & usb_endpoint_maxp(desc);
138− switch (type) {
139− case USB_ENDPOINT_XFER_INT:
140− /* INT: limit 64 bytes full speed, 1024 high/super speed */
141− if (!gadget_is_dualspeed(gadget) && max > 64)
142− return 0;
143− /* FALLTHROUGH */
144−
145− case USB_ENDPOINT_XFER_ISOC:
146− /* ISO: limit 1023 bytes full speed, 1024 high/super speed */
147− if (ep->maxpacket_limit < max)
148− return 0;
149− if (!gadget_is_dualspeed(gadget) && max > 1023)
150− return 0;
151−
152− /* BOTH: "high bandwidth" works only at high speed */
153− if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) {
154− if (!gadget_is_dualspeed(gadget))
155− return 0;
156− /* configure your hardware with enough buffering!! */
157− }
158− break;
159− }
160−
161− /* MATCH!! */
162−
163− /* report address */
164− desc->bEndpointAddress &= USB_DIR_IN;
165− if (isdigit (ep->name [2])) {
166− u8 num = simple_strtoul (&ep->name [2], NULL, 10);
167− desc->bEndpointAddress |= num;
168− } else if (desc->bEndpointAddress & USB_DIR_IN) {
169− if (++gadget->in_epnum > 15)
170− return 0;
171− desc->bEndpointAddress = USB_DIR_IN | gadget->in_epnum;
172− } else {
173− if (++gadget->out_epnum > 15)
174− return 0;
175− desc->bEndpointAddress |= gadget->out_epnum;
176− }
177−
178− /* report (variable) full speed bulk maxpacket */
179− if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) {
180− int size = ep->maxpacket_limit;
181−
182− /* min() doesn't work on bitfields with gcc-3.5 */
183− if (size > 64)
184− size = 64;
185− desc->wMaxPacketSize = cpu_to_le16(size);
186− }
187− ep->address = desc->bEndpointAddress;
188− return 1;
189−}
190−
191−static struct usb_ep *
192−find_ep (struct usb_gadget *gadget, const char *name)
193−{
194− struct usb_ep *ep;
195−
196− list_for_each_entry (ep, &gadget->ep_list, ep_list) {
197− if (0 == strcmp (ep->name, name))
198− return ep;
199− }
200− return NULL;
201−}
202−
20323 /**
20424 * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
20525 * descriptor and ep companion descriptor
@@ -240,7 +60,7 @@ find_ep (struct usb_gadget *gadget, const char *name) · 34 unmodified lines
24060 * updated with the assigned number of streams if it is
24161 * different from the original value. To prevent the endpoint
24262 * from being returned by a later autoconfig call, claim it by
243− * assigning ep->driver_data to some non-null value.
63+ * assigning ep->claimed to true.
24464 *
24565 * On failure, this returns a null endpoint descriptor.
24666 */
@@ -255,74 +75,58 @@ struct usb_ep *usb_ep_autoconfig_ss( · 8 unmodified lines
25575
25676 type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
25777
258− /* First, apply chip-specific "best usage" knowledge.
259− * This might make a good usb_gadget_ops hook ...
260− */
261− if (gadget_is_net2280(gadget)) {
262− char name[8];
263−
264− if (type == USB_ENDPOINT_XFER_INT) {
265− /* ep-e, ep-f are PIO with only 64 byte fifos */
266− ep = find_ep(gadget, "ep-e");
267− if (ep && ep_matches(gadget, ep, desc, ep_comp))
268− goto found_ep;
269− ep = find_ep(gadget, "ep-f");
270− if (ep && ep_matches(gadget, ep, desc, ep_comp))
271− goto found_ep;
272− }
273−
274− /* USB3380: use same address for usb and hardware endpoints */
275− snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
276− usb_endpoint_dir_in(desc) ? "in" : "out");
277− ep = find_ep(gadget, name);
278− if (ep && ep_matches(gadget, ep, desc, ep_comp))
78+ if (gadget->ops->match_ep) {
79+ ep = gadget->ops->match_ep(gadget, desc, ep_comp);
80+ if (ep)
27981 goto found_ep;
280− } else if (gadget_is_goku (gadget)) {
281− if (USB_ENDPOINT_XFER_INT == type) {
282− /* single buffering is enough */
283− ep = find_ep(gadget, "ep3-bulk");
284− if (ep && ep_matches(gadget, ep, desc, ep_comp))
285− goto found_ep;
286− } else if (USB_ENDPOINT_XFER_BULK == type
287− && (USB_DIR_IN & desc->bEndpointAddress)) {
288− /* DMA may be available */
289− ep = find_ep(gadget, "ep2-bulk");
290− if (ep && ep_matches(gadget, ep, desc,
291− ep_comp))
292− goto found_ep;
293− }
294−
295−#ifdef CONFIG_BLACKFIN
296− } else if (gadget_is_musbhdrc(gadget)) {
297− if ((USB_ENDPOINT_XFER_BULK == type) ||
298− (USB_ENDPOINT_XFER_ISOC == type)) {
299− if (USB_DIR_IN & desc->bEndpointAddress)
300− ep = find_ep (gadget, "ep5in");
301− else
302− ep = find_ep (gadget, "ep6out");
303− } else if (USB_ENDPOINT_XFER_INT == type) {
304− if (USB_DIR_IN & desc->bEndpointAddress)
305− ep = find_ep(gadget, "ep1in");
306− else
307− ep = find_ep(gadget, "ep2out");
308− } else
309− ep = NULL;
310− if (ep && ep_matches(gadget, ep, desc, ep_comp))
311− goto found_ep;
312−#endif
31382 }
31483
31584 /* Second, look at endpoints until an unclaimed one looks usable */
31685 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
317− if (ep_matches(gadget, ep, desc, ep_comp))
86+ if (usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
31887 goto found_ep;
31988 }
32089
32190 /* Fail */
32291 return NULL;
32392 found_ep:
93+
94+ /*
95+ * If the protocol driver hasn't yet decided on wMaxPacketSize
96+ * and wants to know the maximum possible, provide the info.
97+ */
98+ if (desc->wMaxPacketSize == 0)
99+ desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket_limit);
100+
101+ /* report address */
102+ desc->bEndpointAddress &= USB_DIR_IN;
103+ if (isdigit(ep->name[2])) {
104+ u8 num = simple_strtoul(&ep->name[2], NULL, 10);
105+ desc->bEndpointAddress |= num;
106+ } else if (desc->bEndpointAddress & USB_DIR_IN) {
107+ if (++gadget->in_epnum > 15)
108+ return NULL;
109+ desc->bEndpointAddress = USB_DIR_IN | gadget->in_epnum;
110+ } else {
111+ if (++gadget->out_epnum > 15)
112+ return NULL;
113+ desc->bEndpointAddress |= gadget->out_epnum;
114+ }
115+
116+ /* report (variable) full speed bulk maxpacket */
117+ if ((type == USB_ENDPOINT_XFER_BULK) && !ep_comp) {
118+ int size = ep->maxpacket_limit;
119+
120+ /* min() doesn't work on bitfields with gcc-3.5 */
121+ if (size > 64)
122+ size = 64;
123+ desc->wMaxPacketSize = cpu_to_le16(size);
124+ }
125+
126+ ep->address = desc->bEndpointAddress;
324127 ep->desc = NULL;
325128 ep->comp_desc = NULL;
129+ ep->claimed = true;
326130 return ep;
327131 }
328132 EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss);
@@ -354,7 +158,7 @@ EXPORT_SYMBOL_GPL(usb_ep_autoconfig_ss); · 25 unmodified lines
354158 * descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value
355159 * is initialized as if the endpoint were used at full speed. To prevent
356160 * the endpoint from being returned by a later autoconfig call, claim it
357− * by assigning ep->driver_data to some non-null value.
161+ * by assigning ep->claimed to true.
358162 *
359163 * On failure, this returns a null endpoint descriptor.
360164 */
@@ -373,7 +177,7 @@ EXPORT_SYMBOL_GPL(usb_ep_autoconfig); · 12 unmodified lines
373177 *
374178 * Use this for devices where one configuration may need to assign
375179 * endpoint resources very differently from the next one. It clears
376− * state such as ep->driver_data and the record of assigned endpoints
180+ * state such as ep->claimed and the record of assigned endpoints
377181 * used by usb_ep_autoconfig().
378182 */
379183 void usb_ep_autoconfig_reset (struct usb_gadget *gadget)
@@ -381,7 +185,7 @@ void usb_ep_autoconfig_reset (struct usb_gadget *gadget) · 1 unmodified line
381185 struct usb_ep *ep;
382186
383187 list_for_each_entry (ep, &gadget->ep_list, ep_list) {
384− ep->driver_data = NULL;
188+ ep->claimed = false;
385189 }
386190 gadget->in_epnum = 0;
387191 gadget->out_epnum = 0;
drivers/usb/gadget/function/f_acm.c+0−1
@@ -21,7 +21,6 @@ · 20 unmodified lines
2121 #include <linux/err.h>
2222
2323 #include "u_serial.h"
24−#include "gadget_chips.h"
2524
2625
2726 /*
drivers/usb/gadget/function/f_ecm.c+2−2
@@ -585,8 +585,8 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) · 584 unmodified lines
585585 /* Enable zlps by default for ECM conformance;
586586 * override for musb_hdrc (avoids txdma ovhead).
587587 */
588− ecm->port.is_zlp_ok = !(gadget_is_musbhdrc(cdev->gadget)
589− );
588+ ecm->port.is_zlp_ok =
589+ gadget_is_zlp_supported(cdev->gadget);
590590 ecm->port.cdc_filter = DEFAULT_FILTER;
591591 DBG(cdev, "activate ecm\n");
592592 net = gether_connect(&ecm->port);
drivers/usb/gadget/function/f_fs.c+7−1
@@ -2897,11 +2897,17 @@ static int ffs_func_bind(struct usb_configuration *c, · 2896 unmodified lines
28972897 struct usb_function *f)
28982898 {
28992899 struct f_fs_opts *ffs_opts = ffs_do_functionfs_bind(f, c);
2900+ struct ffs_function *func = ffs_func_from_usb(f);
2901+ int ret;
29002902
29012903 if (IS_ERR(ffs_opts))
29022904 return PTR_ERR(ffs_opts);
29032905
2904− return _ffs_func_bind(c, f);
2906+ ret = _ffs_func_bind(c, f);
2907+ if (ret && !--ffs_opts->refcnt)
2908+ functionfs_unbind(func->ffs);
2909+
2910+ return ret;
29052911 }
29062912
29072913
drivers/usb/gadget/function/f_loopback.c+0−5
@@ -28,11 +28,6 @@ · 27 unmodified lines
2828 * This takes messages of various sizes written OUT to a device, and loops
2929 * them back so they can be read IN from it. It has been used by certain
3030 * test applications. It supports limited testing of data queueing logic.
31− *
32− *
33− * This is currently packaged as a configuration driver, which can't be
34− * combined with other functions to make composite devices. However, it
35− * can be combined with other independent configurations.
3631 */
3732 struct f_loopback {
3833 struct usb_function function;
drivers/usb/gadget/function/f_mass_storage.c+71−93
@@ -54,7 +54,7 @@ · 53 unmodified lines
5454 * following fields:
5555 *
5656 * nluns Number of LUNs function have (anywhere from 1
57− * to FSG_MAX_LUNS which is 8).
57+ * to FSG_MAX_LUNS).
5858 * luns An array of LUN configuration values. This
5959 * should be filled for each LUN that
6060 * function will include (ie. for "nluns"
@@ -214,12 +214,12 @@ · 153 unmodified lines
214214 #include <linux/string.h>
215215 #include <linux/freezer.h>
216216 #include <linux/module.h>
217+#include <linux/uaccess.h>
217218
218219 #include <linux/usb/ch9.h>
219220 #include <linux/usb/gadget.h>
220221 #include <linux/usb/composite.h>
221222
222−#include "gadget_chips.h"
223223 #include "configfs.h"
224224
225225
@@ -279,9 +279,8 @@ struct fsg_common { · 53 unmodified lines
279279 int cmnd_size;
280280 u8 cmnd[MAX_COMMAND_SIZE];
281281
282− unsigned int nluns;
283282 unsigned int lun;
284− struct fsg_lun **luns;
283+ struct fsg_lun *luns[FSG_MAX_LUNS];
285284 struct fsg_lun *curlun;
286285
287286 unsigned int bulk_out_maxpacket;
@@ -490,6 +489,16 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req) · 202 unmodified lines
490489 spin_unlock(&common->lock);
491490 }
492491
492+static int _fsg_common_get_max_lun(struct fsg_common *common)
493+{
494+ int i = ARRAY_SIZE(common->luns) - 1;
495+
496+ while (i >= 0 && !common->luns[i])
497+ --i;
498+
499+ return i;
500+}
501+
493502 static int fsg_setup(struct usb_function *f,
494503 const struct usb_ctrlrequest *ctrl)
495504 {
@@ -533,7 +542,7 @@ static int fsg_setup(struct usb_function *f, · 37 unmodified lines
533542 w_length != 1)
534543 return -EDOM;
535544 VDBG(fsg, "get max LUN\n");
536− *(u8 *)req->buf = fsg->common->nluns - 1;
545+ *(u8 *)req->buf = _fsg_common_get_max_lun(fsg->common);
537546
538547 /* Respond with data/status */
539548 req->length = min((u16)1, w_length);
@@ -2131,8 +2140,9 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) · 1591 unmodified lines
21312140 }
21322141
21332142 /* Is the CBW meaningful? */
2134− if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
2135− cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
2143+ if (cbw->Lun >= ARRAY_SIZE(common->luns) ||
2144+ cbw->Flags & ~US_BULK_FLAG_IN || cbw->Length <= 0 ||
2145+ cbw->Length > MAX_COMMAND_SIZE) {
21362146 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
21372147 "cmdlen %u\n",
21382148 cbw->Lun, cbw->Flags, cbw->Length);
@@ -2159,7 +2169,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) · 20 unmodified lines
21592169 if (common->data_size == 0)
21602170 common->data_dir = DATA_DIR_NONE;
21612171 common->lun = cbw->Lun;
2162− if (common->lun < common->nluns)
2172+ if (common->lun < ARRAY_SIZE(common->luns))
21632173 common->curlun = common->luns[common->lun];
21642174 else
21652175 common->curlun = NULL;
@@ -2307,7 +2317,7 @@ reset: · 141 unmodified lines
23072317 }
23082318
23092319 common->running = 1;
2310− for (i = 0; i < common->nluns; ++i)
2320+ for (i = 0; i < ARRAY_SIZE(common->luns); ++i)
23112321 if (common->luns[i])
23122322 common->luns[i]->unit_attention_data =
23132323 SS_RESET_OCCURRED;
@@ -2409,7 +2419,7 @@ static void handle_exception(struct fsg_common *common) · 95 unmodified lines
24092419 if (old_state == FSG_STATE_ABORT_BULK_OUT)
24102420 common->state = FSG_STATE_STATUS_PHASE;
24112421 else {
2412− for (i = 0; i < common->nluns; ++i) {
2422+ for (i = 0; i < ARRAY_SIZE(common->luns); ++i) {
24132423 curlun = common->luns[i];
24142424 if (!curlun)
24152425 continue;
@@ -2453,7 +2463,7 @@ static void handle_exception(struct fsg_common *common) · 37 unmodified lines
24532463 * a waste of time. Ditto for the INTERFACE_CHANGE and
24542464 * CONFIG_CHANGE cases.
24552465 */
2456− /* for (i = 0; i < common->nluns; ++i) */
2466+ /* for (i = 0; i < common->ARRAY_SIZE(common->luns); ++i) */
24572467 /* if (common->luns[i]) */
24582468 /* common->luns[i]->unit_attention_data = */
24592469 /* SS_RESET_OCCURRED; */
@@ -2552,12 +2562,11 @@ static int fsg_main_thread(void *common_) · 92 unmodified lines
25522562
25532563 if (!common->ops || !common->ops->thread_exits
25542564 || common->ops->thread_exits(common) < 0) {
2555− struct fsg_lun **curlun_it = common->luns;
2556− unsigned i = common->nluns;
2565+ int i;
25572566
25582567 down_write(&common->filesem);
2559− for (; i--; ++curlun_it) {
2560− struct fsg_lun *curlun = *curlun_it;
2568+ for (i = 0; i < ARRAY_SIZE(common->luns); --i) {
2569+ struct fsg_lun *curlun = common->luns[i];
25612570 if (!curlun || !fsg_lun_is_open(curlun))
25622571 continue;
25632572
@@ -2676,6 +2685,7 @@ static struct fsg_common *fsg_common_setup(struct fsg_common *common) · 112 unmodified lines
26762685 init_completion(&common->thread_notifier);
26772686 init_waitqueue_head(&common->fsg_wait);
26782687 common->state = FSG_STATE_TERMINATED;
2688+ memset(common->luns, 0, sizeof(common->luns));
26792689
26802690 return common;
26812691 }
@@ -2742,9 +2752,9 @@ error_release: · 60 unmodified lines
27422752 }
27432753 EXPORT_SYMBOL_GPL(fsg_common_set_num_buffers);
27442754
2745−void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs)
2755+void fsg_common_remove_lun(struct fsg_lun *lun)
27462756 {
2747− if (sysfs)
2757+ if (device_is_registered(&lun->dev))
27482758 device_unregister(&lun->dev);
27492759 fsg_lun_close(lun);
27502760 kfree(lun);
@@ -2757,48 +2767,16 @@ static void _fsg_common_remove_luns(struct fsg_common *common, int n) · 6 unmodified lines
27572767
27582768 for (i = 0; i < n; ++i)
27592769 if (common->luns[i]) {
2760− fsg_common_remove_lun(common->luns[i], common->sysfs);
2770+ fsg_common_remove_lun(common->luns[i]);
27612771 common->luns[i] = NULL;
27622772 }
27632773 }
2764−EXPORT_SYMBOL_GPL(fsg_common_remove_luns);
27652774
27662775 void fsg_common_remove_luns(struct fsg_common *common)
27672776 {
2768− _fsg_common_remove_luns(common, common->nluns);
2769−}
2770−
2771−void fsg_common_free_luns(struct fsg_common *common)
2772−{
2773− fsg_common_remove_luns(common);
2774− kfree(common->luns);
2775− common->luns = NULL;
2776−}
2777−EXPORT_SYMBOL_GPL(fsg_common_free_luns);
2778−
2779−int fsg_common_set_nluns(struct fsg_common *common, int nluns)
2780−{
2781− struct fsg_lun **curlun;
2782−
2783− /* Find out how many LUNs there should be */
2784− if (nluns < 1 || nluns > FSG_MAX_LUNS) {
2785− pr_err("invalid number of LUNs: %u\n", nluns);
2786− return -EINVAL;
2787− }
2788−
2789− curlun = kcalloc(FSG_MAX_LUNS, sizeof(*curlun), GFP_KERNEL);
2790− if (unlikely(!curlun))
2791− return -ENOMEM;
2792−
2793− if (common->luns)
2794− fsg_common_free_luns(common);
2795−
2796− common->luns = curlun;
2797− common->nluns = nluns;
2798−
2799− return 0;
2777+ _fsg_common_remove_luns(common, ARRAY_SIZE(common->luns));
28002778 }
2801−EXPORT_SYMBOL_GPL(fsg_common_set_nluns);
2779+EXPORT_SYMBOL_GPL(fsg_common_remove_luns);
28022780
28032781 void fsg_common_set_ops(struct fsg_common *common,
28042782 const struct fsg_operations *ops)
@@ -2836,7 +2814,8 @@ int fsg_common_set_cdev(struct fsg_common *common, · 31 unmodified lines
28362814 * halt bulk endpoints correctly. If one of them is present,
28372815 * disable stalls.
28382816 */
2839− common->can_stall = can_stall && !(gadget_is_at91(common->gadget));
2817+ common->can_stall = can_stall &&
2818+ gadget_is_stall_supported(common->gadget);
28402819
28412820 return 0;
28422821 }
@@ -2880,7 +2859,7 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, · 37 unmodified lines
28802859 char *pathbuf, *p;
28812860 int rc = -ENOMEM;
28822861
2883− if (!common->nluns || !common->luns)
2862+ if (id >= ARRAY_SIZE(common->luns))
28842863 return -ENODEV;
28852864
28862865 if (common->luns[id])
@@ -2949,7 +2928,7 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, · 62 unmodified lines
29492928 return 0;
29502929
29512930 error_lun:
2952− if (common->sysfs)
2931+ if (device_is_registered(&lun->dev))
29532932 device_unregister(&lun->dev);
29542933 fsg_lun_close(lun);
29552934 common->luns[id] = NULL;
@@ -2964,14 +2943,16 @@ int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg) · 8 unmodified lines
29642943 char buf[8]; /* enough for 100000000 different numbers, decimal */
29652944 int i, rc;
29662945
2967− for (i = 0; i < common->nluns; ++i) {
2946+ fsg_common_remove_luns(common);
2947+
2948+ for (i = 0; i < cfg->nluns; ++i) {
29682949 snprintf(buf, sizeof(buf), "lun%d", i);
29692950 rc = fsg_common_create_lun(common, &cfg->luns[i], i, buf, NULL);
29702951 if (rc)
29712952 goto fail;
29722953 }
29732954
2974− pr_info("Number of LUNs=%d\n", common->nluns);
2955+ pr_info("Number of LUNs=%d\n", cfg->nluns);
29752956
29762957 return 0;
29772958
@@ -3020,6 +3001,7 @@ EXPORT_SYMBOL_GPL(fsg_common_run_thread); · 42 unmodified lines
30203001 static void fsg_common_release(struct kref *ref)
30213002 {
30223003 struct fsg_common *common = container_of(ref, struct fsg_common, ref);
3004+ int i;
30233005
30243006 /* If the thread isn't already dead, tell it to exit now */
30253007 if (common->state != FSG_STATE_TERMINATED) {
@@ -3027,22 +3009,14 @@ static void fsg_common_release(struct kref *ref) · 1 unmodified line
30273009 wait_for_completion(&common->thread_notifier);
30283010 }
30293011
3030− if (likely(common->luns)) {
3031− struct fsg_lun **lun_it = common->luns;
3032− unsigned i = common->nluns;
3033−
3034− /* In error recovery common->nluns may be zero. */
3035− for (; i; --i, ++lun_it) {
3036− struct fsg_lun *lun = *lun_it;
3037− if (!lun)
3038− continue;
3039− fsg_lun_close(lun);
3040− if (common->sysfs)
3041− device_unregister(&lun->dev);
3042− kfree(lun);
3043− }
3044−
3045− kfree(common->luns);
3012+ for (i = 0; i < ARRAY_SIZE(common->luns); ++i) {
3013+ struct fsg_lun *lun = common->luns[i];
3014+ if (!lun)
3015+ continue;
3016+ fsg_lun_close(lun);
3017+ if (device_is_registered(&lun->dev))
3018+ device_unregister(&lun->dev);
3019+ kfree(lun);
30463020 }
30473021
30483022 _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
@@ -3056,6 +3030,7 @@ static void fsg_common_release(struct kref *ref) · 7 unmodified lines
30563030 static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
30573031 {
30583032 struct fsg_dev *fsg = fsg_from_func(f);
3033+ struct fsg_common *common = fsg->common;
30593034 struct usb_gadget *gadget = c->cdev->gadget;
30603035 int i;
30613036 struct usb_ep *ep;
@@ -3063,6 +3038,13 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · 1 unmodified line
30633038 int ret;
30643039 struct fsg_opts *opts;
30653040
3041+ /* Don't allow to bind if we don't have at least one LUN */
3042+ ret = _fsg_common_get_max_lun(common);
3043+ if (ret < 0) {
3044+ pr_err("There should be at least one LUN.\n");
3045+ return -EINVAL;
3046+ }
3047+
30663048 opts = fsg_opts_from_func_inst(f->fi);
30673049 if (!opts->no_configfs) {
30683050 ret = fsg_common_set_cdev(fsg->common, c->cdev,
@@ -3080,7 +3062,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · 11 unmodified lines
30803062 /* New interface */
30813063 i = usb_interface_id(c, f);
30823064 if (i < 0)
3083− return i;
3065+ goto fail;
30843066 fsg_intf_desc.bInterfaceNumber = i;
30853067 fsg->interface_number = i;
30863068
@@ -3123,7 +3105,14 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · 36 unmodified lines
31233105
31243106 autoconf_fail:
31253107 ERROR(fsg, "unable to autoconfigure all endpoints\n");
3126− return -ENOTSUPP;
3108+ i = -ENOTSUPP;
3109+fail:
3110+ /* terminate the thread */
3111+ if (fsg->common->state != FSG_STATE_TERMINATED) {
3112+ raise_exception(fsg->common, FSG_STATE_EXIT);
3113+ wait_for_completion(&fsg->common->thread_notifier);
3114+ }
3115+ return i;
31273116 }
31283117
31293118 /****************************** ALLOCATE FUNCTION *************************/
@@ -3355,7 +3344,7 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item) · 225 unmodified lines
33553344 unregister_gadget_item(gadget);
33563345 }
33573346
3358− fsg_common_remove_lun(lun_opts->lun, fsg_opts->common->sysfs);
3347+ fsg_common_remove_lun(lun_opts->lun);
33593348 fsg_opts->common->luns[lun_opts->lun_id] = NULL;
33603349 lun_opts->lun_id = 0;
33613350 mutex_unlock(&fsg_opts->lock);
@@ -3509,14 +3498,11 @@ static struct usb_function_instance *fsg_alloc_inst(void) · 147 unmodified lines
35093498 rc = PTR_ERR(opts->common);
35103499 goto release_opts;
35113500 }
3512− rc = fsg_common_set_nluns(opts->common, FSG_MAX_LUNS);
3513− if (rc)
3514− goto release_opts;
35153501
35163502 rc = fsg_common_set_num_buffers(opts->common,
35173503 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS);
35183504 if (rc)
3519− goto release_luns;
3505+ goto release_opts;
35203506
35213507 pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
35223508
@@ -3524,6 +3510,9 @@ static struct usb_function_instance *fsg_alloc_inst(void) · 1 unmodified line
35243510 config.removable = true;
35253511 rc = fsg_common_create_lun(opts->common, &config, 0, "lun.0",
35263512 (const char **)&opts->func_inst.group.cg_item.ci_name);
3513+ if (rc)
3514+ goto release_buffers;
3515+
35273516 opts->lun0.lun = opts->common->luns[0];
35283517 opts->lun0.lun_id = 0;
35293518 config_group_init_type_name(&opts->lun0.group, "lun.0", &fsg_lun_type);
@@ -3534,8 +3523,8 @@ static struct usb_function_instance *fsg_alloc_inst(void) · 4 unmodified lines
35343523
35353524 return &opts->func_inst;
35363525
3537−release_luns:
3538− kfree(opts->common->luns);
3526+release_buffers:
3527+ fsg_common_free_buffers(opts->common);
35393528 release_opts:
35403529 kfree(opts);
35413530 return ERR_PTR(rc);
@@ -3561,23 +3550,12 @@ static struct usb_function *fsg_alloc(struct usb_function_instance *fi) · 19 unmodified lines
35613550 struct fsg_opts *opts = fsg_opts_from_func_inst(fi);
35623551 struct fsg_common *common = opts->common;
35633552 struct fsg_dev *fsg;
3564− unsigned nluns, i;
35653553
35663554 fsg = kzalloc(sizeof(*fsg), GFP_KERNEL);
35673555 if (unlikely(!fsg))
35683556 return ERR_PTR(-ENOMEM);
35693557
35703558 mutex_lock(&opts->lock);
3571− if (!opts->refcnt) {
3572− for (nluns = i = 0; i < FSG_MAX_LUNS; ++i)
3573− if (common->luns[i])
3574− nluns = i + 1;
3575− if (!nluns)
3576− pr_warn("No LUNS defined, continuing anyway\n");
3577− else
3578− common->nluns = nluns;
3579− pr_info("Number of LUNs=%u\n", common->nluns);
3580− }
35813559 opts->refcnt++;
35823560 mutex_unlock(&opts->lock);
35833561
drivers/usb/gadget/function/f_mass_storage.h+1−5
@@ -137,14 +137,10 @@ void fsg_common_free_buffers(struct fsg_common *common); · 136 unmodified lines
137137 int fsg_common_set_cdev(struct fsg_common *common,
138138 struct usb_composite_dev *cdev, bool can_stall);
139139
140−void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs);
140+void fsg_common_remove_lun(struct fsg_lun *lun);
141141
142142 void fsg_common_remove_luns(struct fsg_common *common);
143143
144−void fsg_common_free_luns(struct fsg_common *common);
145−
146−int fsg_common_set_nluns(struct fsg_common *common, int nluns);
147−
148144 void fsg_common_set_ops(struct fsg_common *common,
149145 const struct fsg_operations *ops);
150146
drivers/usb/gadget/function/f_midi.c+4−0
@@ -329,6 +329,10 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) · 328 unmodified lines
329329 unsigned i;
330330 int err;
331331
332+ /* For Control Device interface we do nothing */
333+ if (intf == 0)
334+ return 0;
335+
332336 err = f_midi_start_ep(midi, f, midi->in_ep);
333337 if (err)
334338 return err;
drivers/usb/gadget/function/f_ncm.c+2−3
@@ -853,9 +853,8 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) · 852 unmodified lines
853853 /* Enable zlps by default for NCM conformance;
854854 * override for musb_hdrc (avoids txdma ovhead)
855855 */
856− ncm->port.is_zlp_ok = !(
857− gadget_is_musbhdrc(cdev->gadget)
858− );
856+ ncm->port.is_zlp_ok =
857+ gadget_is_zlp_supported(cdev->gadget);
859858 ncm->port.cdc_filter = DEFAULT_FILTER;
860859 DBG(cdev, "activate ncm\n");
861860 net = gether_connect(&ncm->port);
drivers/usb/gadget/function/f_obex.c+2−20
@@ -20,7 +20,6 @@ · 19 unmodified lines
2020 #include <linux/module.h>
2121
2222 #include "u_serial.h"
23−#include "gadget_chips.h"
2423
2524
2625 /*
@@ -37,7 +36,6 @@ struct f_obex { · 10 unmodified lines
3736 u8 data_id;
3837 u8 cur_alt;
3938 u8 port_num;
40− u8 can_activate;
4139 };
4240
4341 static inline struct f_obex *func_to_obex(struct usb_function *f)
@@ -268,9 +266,6 @@ static void obex_connect(struct gserial *g) · 224 unmodified lines
268266 struct usb_composite_dev *cdev = g->func.config->cdev;
269267 int status;
270268
271− if (!obex->can_activate)
272− return;
273−
274269 status = usb_function_activate(&g->func);
275270 if (status)
276271 dev_dbg(&cdev->gadget->dev,
@@ -284,9 +279,6 @@ static void obex_disconnect(struct gserial *g) · 7 unmodified lines
284279 struct usb_composite_dev *cdev = g->func.config->cdev;
285280 int status;
286281
287− if (!obex->can_activate)
288− return;
289−
290282 status = usb_function_deactivate(&g->func);
291283 if (status)
292284 dev_dbg(&cdev->gadget->dev,
@@ -304,7 +296,7 @@ static inline bool can_support_obex(struct usb_configuration *c) · 11 unmodified lines
304296 *
305297 * Altsettings are mandatory, however...
306298 */
307− if (!gadget_supports_altsettings(c->cdev->gadget))
299+ if (!gadget_is_altset_supported(c->cdev->gadget))
308300 return false;
309301
310302 /* everything else is *probably* fine ... */
@@ -378,17 +370,6 @@ static int obex_bind(struct usb_configuration *c, struct usb_function *f) · 67 unmodified lines
378370 if (status)
379371 goto fail;
380372
381− /* Avoid letting this gadget enumerate until the userspace
382− * OBEX server is active.
383− */
384− status = usb_function_deactivate(f);
385− if (status < 0)
386− WARNING(cdev, "obex ttyGS%d: can't prevent enumeration, %d\n",
387− obex->port_num, status);
388− else
389− obex->can_activate = true;
390−
391−
392373 dev_dbg(&cdev->gadget->dev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n",
393374 obex->port_num,
394375 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
@@ -529,6 +510,7 @@ static struct usb_function *obex_alloc(struct usb_function_instance *fi) · 134 unmodified lines
529510 obex->port.func.get_alt = obex_get_alt;
530511 obex->port.func.disable = obex_disable;
531512 obex->port.func.free_func = obex_free;
513+ obex->port.func.bind_deactivated = true;
532514
533515 return &obex->port.func;
534516 }
drivers/usb/gadget/function/f_printer.c+4−3
@@ -804,6 +804,8 @@ done: · 803 unmodified lines
804804
805805 static void printer_reset_interface(struct printer_dev *dev)
806806 {
807+ unsigned long flags;
808+
807809 if (dev->interface < 0)
808810 return;
809811
@@ -815,9 +817,11 @@ static void printer_reset_interface(struct printer_dev *dev) · 5 unmodified lines
815817 if (dev->out_ep->desc)
816818 usb_ep_disable(dev->out_ep);
817819
820+ spin_lock_irqsave(&dev->lock, flags);
818821 dev->in_ep->desc = NULL;
819822 dev->out_ep->desc = NULL;
820823 dev->interface = -1;
824+ spin_unlock_irqrestore(&dev->lock, flags);
821825 }
822826
823827 /* Change our operational Interface. */
@@ -1131,13 +1135,10 @@ static int printer_func_set_alt(struct usb_function *f, · 307 unmodified lines
11311135 static void printer_func_disable(struct usb_function *f)
11321136 {
11331137 struct printer_dev *dev = func_to_printer(f);
1134− unsigned long flags;
11351138
11361139 DBG(dev, "%s\n", __func__);
11371140
1138− spin_lock_irqsave(&dev->lock, flags);
11391141 printer_reset_interface(dev);
1140− spin_unlock_irqrestore(&dev->lock, flags);
11411142 }
11421143
11431144 static inline struct f_printer_opts
drivers/usb/gadget/function/f_serial.c+0−1
@@ -16,7 +16,6 @@ · 15 unmodified lines
1616 #include <linux/device.h>
1717
1818 #include "u_serial.h"
19−#include "gadget_chips.h"
2019
2120
2221 /*
drivers/usb/gadget/function/f_sourcesink.c+0−6
@@ -20,7 +20,6 @@ · 19 unmodified lines
2020 #include <linux/err.h>
2121
2222 #include "g_zero.h"
23−#include "gadget_chips.h"
2423 #include "u_f.h"
2524
2625 /*
@@ -42,11 +41,6 @@ · 15 unmodified lines
4241 * queues are relatively independent, will receive a range of packet sizes,
4342 * and can often be made to run out completely. Those issues are important
4443 * when stress testing peripheral controller drivers.
45− *
46− *
47− * This is currently packaged as a configuration driver, which can't be
48− * combined with other functions to make composite devices. However, it
49− * can be combined with other independent configurations.
5044 */
5145 struct f_sourcesink {
5246 struct usb_function function;
drivers/usb/gadget/function/f_uac2.c+29−2
@@ -975,6 +975,29 @@ free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep) · 974 unmodified lines
975975 "%s:%d Error!\n", __func__, __LINE__);
976976 }
977977
978+static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
979+ struct usb_endpoint_descriptor *ep_desc,
980+ unsigned int factor, bool is_playback)
981+{
982+ int chmask, srate, ssize;
983+ u16 max_packet_size;
984+
985+ if (is_playback) {
986+ chmask = uac2_opts->p_chmask;
987+ srate = uac2_opts->p_srate;
988+ ssize = uac2_opts->p_ssize;
989+ } else {
990+ chmask = uac2_opts->c_chmask;
991+ srate = uac2_opts->c_srate;
992+ ssize = uac2_opts->c_ssize;
993+ }
994+
995+ max_packet_size = num_channels(chmask) * ssize *
996+ DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1)));
997+ ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_packet_size,
998+ le16_to_cpu(ep_desc->wMaxPacketSize)));
999+}
1000+
9781001 static int
9791002 afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
9801003 {
@@ -1070,10 +1093,14 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) · 89 unmodified lines
10701093 uac2->p_prm.uac2 = uac2;
10711094 uac2->c_prm.uac2 = uac2;
10721095
1096+ /* Calculate wMaxPacketSize according to audio bandwidth */
1097+ set_ep_max_packet_size(uac2_opts, &fs_epin_desc, 1000, true);
1098+ set_ep_max_packet_size(uac2_opts, &fs_epout_desc, 1000, false);
1099+ set_ep_max_packet_size(uac2_opts, &hs_epin_desc, 8000, true);
1100+ set_ep_max_packet_size(uac2_opts, &hs_epout_desc, 8000, false);
1101+
10731102 hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
1074− hs_epout_desc.wMaxPacketSize = fs_epout_desc.wMaxPacketSize;
10751103 hs_epin_desc.bEndpointAddress = fs_epin_desc.bEndpointAddress;
1076− hs_epin_desc.wMaxPacketSize = fs_epin_desc.wMaxPacketSize;
10771104
10781105 ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, NULL);
10791106 if (ret)
drivers/usb/gadget/function/f_uvc.c+1−6
@@ -733,12 +733,6 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) · 732 unmodified lines
733733 uvc->control_req->complete = uvc_function_ep0_complete;
734734 uvc->control_req->context = uvc;
735735
736− /* Avoid letting this gadget enumerate until the userspace server is
737− * active.
738− */
739− if ((ret = usb_function_deactivate(f)) < 0)
740− goto error;
741−
742736 if (v4l2_device_register(&cdev->gadget->dev, &uvc->v4l2_dev)) {
743737 printk(KERN_INFO "v4l2_device_register failed\n");
744738 goto error;
@@ -949,6 +943,7 @@ static struct usb_function *uvc_alloc(struct usb_function_instance *fi) · 204 unmodified lines
949943 uvc->func.disable = uvc_function_disable;
950944 uvc->func.setup = uvc_function_setup;
951945 uvc->func.free_func = uvc_free;
946+ uvc->func.bind_deactivated = true;
952947
953948 return &uvc->func;
954949 }
drivers/usb/gadget/function/storage_common.h+1−1
@@ -123,7 +123,7 @@ static inline bool fsg_lun_is_open(struct fsg_lun *curlun) · 122 unmodified lines
123123 #define FSG_BUFLEN ((u32)16384)
124124
125125 /* Maximal number of LUNs supported in mass storage function */
126−#define FSG_MAX_LUNS 8
126+#define FSG_MAX_LUNS 16
127127
128128 enum fsg_buffer_state {
129129 BUF_STATE_EMPTY = 0,
drivers/usb/gadget/function/u_ether.h+1−3
@@ -20,8 +20,6 @@ · 19 unmodified lines
2020 #include <linux/usb/cdc.h>
2121 #include <linux/netdevice.h>
2222
23−#include "gadget_chips.h"
24−
2523 #define QMULT_DEFAULT 5
2624
2725 /*
@@ -259,7 +257,7 @@ void gether_disconnect(struct gether *); · 231 unmodified lines
259257 /* Some controllers can't support CDC Ethernet (ECM) ... */
260258 static inline bool can_support_ecm(struct usb_gadget *gadget)
261259 {
262− if (!gadget_supports_altsettings(gadget))
260+ if (!gadget_is_altset_supported(gadget))
263261 return false;
264262
265263 /* Everything else is *presumably* fine ... but this is a bit
drivers/usb/gadget/function/u_uac1.h+0−2
@@ -21,8 +21,6 @@ · 20 unmodified lines
2121 #include <sound/pcm.h>
2222 #include <sound/pcm_params.h>
2323
24−#include "gadget_chips.h"
25−
2624 #define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p"
2725 #define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c"
2826 #define FILE_CONTROL "/dev/snd/controlC0"
drivers/usb/gadget/legacy/Kconfig+2−0
@@ -339,6 +339,7 @@ config USB_CDC_COMPOSITE · 338 unmodified lines
339339 config USB_G_NOKIA
340340 tristate "Nokia composite gadget"
341341 depends on PHONET
342+ depends on BLOCK
342343 select USB_LIBCOMPOSITE
343344 select USB_U_SERIAL
344345 select USB_U_ETHER
@@ -346,6 +347,7 @@ config USB_G_NOKIA · 1 unmodified line
346347 select USB_F_OBEX
347348 select USB_F_PHONET
348349 select USB_F_ECM
350+ select USB_F_MASS_STORAGE
349351 help
350352 The Nokia composite gadget provides support for acm, obex
351353 and phonet in only one composite gadget driver.
drivers/usb/gadget/legacy/acm_ms.c+19−22
@@ -58,21 +58,7 @@ static struct usb_device_descriptor device_desc = { · 57 unmodified lines
5858 /*.bNumConfigurations = DYNAMIC*/
5959 };
6060
61−static struct usb_otg_descriptor otg_descriptor = {
62− .bLength = sizeof otg_descriptor,
63− .bDescriptorType = USB_DT_OTG,
64−
65− /*
66− * REVISIT SRP-only hardware is possible, although
67− * it would not be called "OTG" ...
68− */
69− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
70−};
71−
72−static const struct usb_descriptor_header *otg_desc[] = {
73− (struct usb_descriptor_header *) &otg_descriptor,
74− NULL,
75−};
61+static const struct usb_descriptor_header *otg_desc[2];
7662
7763 /* string IDs are assigned dynamically */
7864 static struct usb_string strings_dev[] = {
@@ -200,10 +186,6 @@ static int acm_ms_bind(struct usb_composite_dev *cdev) · 121 unmodified lines
200186 if (status)
201187 goto fail;
202188
203− status = fsg_common_set_nluns(opts->common, config.nluns);
204− if (status)
205− goto fail_set_nluns;
206−
207189 status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
208190 if (status)
209191 goto fail_set_cdev;
@@ -225,10 +207,21 @@ static int acm_ms_bind(struct usb_composite_dev *cdev) · 15 unmodified lines
225207 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
226208 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
227209
210+ if (gadget_is_otg(gadget) && !otg_desc[0]) {
211+ struct usb_descriptor_header *usb_desc;
212+
213+ usb_desc = usb_otg_descriptor_alloc(gadget);
214+ if (!usb_desc)
215+ goto fail_string_ids;
216+ usb_otg_descriptor_init(gadget, usb_desc);
217+ otg_desc[0] = usb_desc;
218+ otg_desc[1] = NULL;
219+ }
220+
228221 /* register our configuration */
229222 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
230223 if (status < 0)
231− goto fail_string_ids;
224+ goto fail_otg_desc;
232225
233226 usb_composite_overwrite_options(cdev, &coverwrite);
234227 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
@@ -236,11 +229,12 @@ static int acm_ms_bind(struct usb_composite_dev *cdev) · 1 unmodified line
236229 return 0;
237230
238231 /* error recovery */
232+fail_otg_desc:
233+ kfree(otg_desc[0]);
234+ otg_desc[0] = NULL;
239235 fail_string_ids:
240236 fsg_common_remove_luns(opts->common);
241237 fail_set_cdev:
242− fsg_common_free_luns(opts->common);
243−fail_set_nluns:
244238 fsg_common_free_buffers(opts->common);
245239 fail:
246240 usb_put_function_instance(fi_msg);
@@ -255,6 +249,9 @@ static int acm_ms_unbind(struct usb_composite_dev *cdev) · 8 unmodified lines
255249 usb_put_function_instance(fi_msg);
256250 usb_put_function(f_acm);
257251 usb_put_function_instance(f_acm_inst);
252+ kfree(otg_desc[0]);
253+ otg_desc[0] = NULL;
254+
258255 return 0;
259256 }
260257
drivers/usb/gadget/legacy/audio.c+22−19
@@ -15,7 +15,6 @@ · 14 unmodified lines
1515 #include <linux/module.h>
1616 #include <linux/usb/composite.h>
1717
18−#include "gadget_chips.h"
1918 #define DRIVER_DESC "Linux USB Audio Gadget"
2019 #define DRIVER_VERSION "Feb 2, 2012"
2120
@@ -124,7 +123,7 @@ static struct usb_device_descriptor device_desc = { · 102 unmodified lines
124123 .bLength = sizeof device_desc,
125124 .bDescriptorType = USB_DT_DEVICE,
126125
127− .bcdUSB = __constant_cpu_to_le16(0x200),
126+ .bcdUSB = cpu_to_le16(0x200),
128127
129128 #ifdef CONFIG_GADGET_UAC1
130129 .bDeviceClass = USB_CLASS_PER_INTERFACE,
@@ -141,8 +140,8 @@ static struct usb_device_descriptor device_desc = { · 10 unmodified lines
141140 * we support. (As does bNumConfigurations.) These values can
142141 * also be overridden by module parameters.
143142 */
144− .idVendor = __constant_cpu_to_le16(AUDIO_VENDOR_NUM),
145− .idProduct = __constant_cpu_to_le16(AUDIO_PRODUCT_NUM),
143+ .idVendor = cpu_to_le16(AUDIO_VENDOR_NUM),
144+ .idProduct = cpu_to_le16(AUDIO_PRODUCT_NUM),
146145 /* .bcdDevice = f(hardware) */
147146 /* .iManufacturer = DYNAMIC */
148147 /* .iProduct = DYNAMIC */
@@ -150,20 +149,7 @@ static struct usb_device_descriptor device_desc = { · 1 unmodified line
150149 .bNumConfigurations = 1,
151150 };
152151
153−static struct usb_otg_descriptor otg_descriptor = {
154− .bLength = sizeof otg_descriptor,
155− .bDescriptorType = USB_DT_OTG,
156−
157− /* REVISIT SRP-only hardware is possible, although
158− * it would not be called "OTG" ...
159− */
160− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
161−};
162−
163−static const struct usb_descriptor_header *otg_desc[] = {
164− (struct usb_descriptor_header *) &otg_descriptor,
165− NULL,
166−};
152+static const struct usb_descriptor_header *otg_desc[2];
167153
168154 /*-------------------------------------------------------------------------*/
169155
@@ -259,14 +245,28 @@ static int audio_bind(struct usb_composite_dev *cdev) · 89 unmodified lines
259245 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
260246 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
261247
248+ if (gadget_is_otg(cdev->gadget) && !otg_desc[0]) {
249+ struct usb_descriptor_header *usb_desc;
250+
251+ usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
252+ if (!usb_desc)
253+ goto fail;
254+ usb_otg_descriptor_init(cdev->gadget, usb_desc);
255+ otg_desc[0] = usb_desc;
256+ otg_desc[1] = NULL;
257+ }
258+
262259 status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
263260 if (status < 0)
264− goto fail;
261+ goto fail_otg_desc;
265262 usb_composite_overwrite_options(cdev, &coverwrite);
266263
267264 INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION);
268265 return 0;
269266
267+fail_otg_desc:
268+ kfree(otg_desc[0]);
269+ otg_desc[0] = NULL;
270270 fail:
271271 #ifndef CONFIG_GADGET_UAC1
272272 usb_put_function_instance(fi_uac2);
@@ -289,6 +289,9 @@ static int audio_unbind(struct usb_composite_dev *cdev) · 16 unmodified lines
289289 if (!IS_ERR_OR_NULL(fi_uac2))
290290 usb_put_function_instance(fi_uac2);
291291 #endif
292+ kfree(otg_desc[0]);
293+ otg_desc[0] = NULL;
294+
292295 return 0;
293296 }
294297
drivers/usb/gadget/legacy/cdc2.c+19−16
@@ -60,21 +60,7 @@ static struct usb_device_descriptor device_desc = { · 59 unmodified lines
6060 .bNumConfigurations = 1,
6161 };
6262
63−static struct usb_otg_descriptor otg_descriptor = {
64− .bLength = sizeof otg_descriptor,
65− .bDescriptorType = USB_DT_OTG,
66−
67− /* REVISIT SRP-only hardware is possible, although
68− * it would not be called "OTG" ...
69− */
70− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
71−};
72−
73−static const struct usb_descriptor_header *otg_desc[] = {
74− (struct usb_descriptor_header *) &otg_descriptor,
75− NULL,
76−};
77−
63+static const struct usb_descriptor_header *otg_desc[2];
7864
7965 /* string IDs are assigned dynamically */
8066 static struct usb_string strings_dev[] = {
@@ -193,10 +179,21 @@ static int cdc_bind(struct usb_composite_dev *cdev) · 112 unmodified lines
193179 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
194180 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
195181
182+ if (gadget_is_otg(gadget) && !otg_desc[0]) {
183+ struct usb_descriptor_header *usb_desc;
184+
185+ usb_desc = usb_otg_descriptor_alloc(gadget);
186+ if (!usb_desc)
187+ goto fail1;
188+ usb_otg_descriptor_init(gadget, usb_desc);
189+ otg_desc[0] = usb_desc;
190+ otg_desc[1] = NULL;
191+ }
192+
196193 /* register our configuration */
197194 status = usb_add_config(cdev, &cdc_config_driver, cdc_do_config);
198195 if (status < 0)
199− goto fail1;
196+ goto fail2;
200197
201198 usb_composite_overwrite_options(cdev, &coverwrite);
202199 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
@@ -204,6 +201,9 @@ static int cdc_bind(struct usb_composite_dev *cdev) · 1 unmodified line
204201
205202 return 0;
206203
204+fail2:
205+ kfree(otg_desc[0]);
206+ otg_desc[0] = NULL;
207207 fail1:
208208 usb_put_function_instance(fi_serial);
209209 fail:
@@ -219,6 +219,9 @@ static int cdc_unbind(struct usb_composite_dev *cdev) · 9 unmodified lines
219219 usb_put_function(f_ecm);
220220 if (!IS_ERR_OR_NULL(fi_ecm))
221221 usb_put_function_instance(fi_ecm);
222+ kfree(otg_desc[0]);
223+ otg_desc[0] = NULL;
224+
222225 return 0;
223226 }
224227
drivers/usb/gadget/legacy/dbgp.c+5−5
@@ -35,10 +35,10 @@ static struct dbgp { · 34 unmodified lines
3535 static struct usb_device_descriptor device_desc = {
3636 .bLength = sizeof device_desc,
3737 .bDescriptorType = USB_DT_DEVICE,
38− .bcdUSB = __constant_cpu_to_le16(0x0200),
38+ .bcdUSB = cpu_to_le16(0x0200),
3939 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
40− .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_ID),
41− .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_ID),
40+ .idVendor = cpu_to_le16(DRIVER_VENDOR_ID),
41+ .idProduct = cpu_to_le16(DRIVER_PRODUCT_ID),
4242 .bNumConfigurations = 1,
4343 };
4444
@@ -251,7 +251,7 @@ static int dbgp_configure_endpoints(struct usb_gadget *gadget) · 206 unmodified lines
251251
252252 dbgp.i_ep->driver_data = gadget;
253253 i_desc.wMaxPacketSize =
254− __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
254+ cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
255255
256256 dbgp.o_ep = usb_ep_autoconfig(gadget, &o_desc);
257257 if (!dbgp.o_ep) {
@@ -262,7 +262,7 @@ static int dbgp_configure_endpoints(struct usb_gadget *gadget) · 4 unmodified lines
262262
263263 dbgp.o_ep->driver_data = gadget;
264264 o_desc.wMaxPacketSize =
265− __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
265+ cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
266266
267267 dbg_desc.bDebugInEndpoint = i_desc.bEndpointAddress;
268268 dbg_desc.bDebugOutEndpoint = o_desc.bEndpointAddress;
drivers/usb/gadget/legacy/ether.c+20−16
@@ -171,20 +171,7 @@ static struct usb_device_descriptor device_desc = { · 170 unmodified lines
171171 .bNumConfigurations = 1,
172172 };
173173
174−static struct usb_otg_descriptor otg_descriptor = {
175− .bLength = sizeof otg_descriptor,
176− .bDescriptorType = USB_DT_OTG,
177−
178− /* REVISIT SRP-only hardware is possible, although
179− * it would not be called "OTG" ...
180− */
181− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
182−};
183−
184−static const struct usb_descriptor_header *otg_desc[] = {
185− (struct usb_descriptor_header *) &otg_descriptor,
186− NULL,
187−};
174+static const struct usb_descriptor_header *otg_desc[2];
188175
189176 static struct usb_string strings_dev[] = {
190177 [USB_GADGET_MANUFACTURER_IDX].s = "",
@@ -416,17 +403,28 @@ static int eth_bind(struct usb_composite_dev *cdev) · 225 unmodified lines
416403 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
417404 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
418405
406+ if (gadget_is_otg(gadget) && !otg_desc[0]) {
407+ struct usb_descriptor_header *usb_desc;
408+
409+ usb_desc = usb_otg_descriptor_alloc(gadget);
410+ if (!usb_desc)
411+ goto fail1;
412+ usb_otg_descriptor_init(gadget, usb_desc);
413+ otg_desc[0] = usb_desc;
414+ otg_desc[1] = NULL;
415+ }
416+
419417 /* register our configuration(s); RNDIS first, if it's used */
420418 if (has_rndis()) {
421419 status = usb_add_config(cdev, &rndis_config_driver,
422420 rndis_do_config);
423421 if (status < 0)
424− goto fail1;
422+ goto fail2;
425423 }
426424
427425 status = usb_add_config(cdev, &eth_config_driver, eth_do_config);
428426 if (status < 0)
429− goto fail1;
427+ goto fail2;
430428
431429 usb_composite_overwrite_options(cdev, &coverwrite);
432430 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
@@ -434,6 +432,9 @@ static int eth_bind(struct usb_composite_dev *cdev) · 1 unmodified line
434432
435433 return 0;
436434
435+fail2:
436+ kfree(otg_desc[0]);
437+ otg_desc[0] = NULL;
437438 fail1:
438439 if (has_rndis())
439440 usb_put_function_instance(fi_rndis);
@@ -463,6 +464,9 @@ static int eth_unbind(struct usb_composite_dev *cdev) · 23 unmodified lines
463464 usb_put_function(f_geth);
464465 usb_put_function_instance(fi_geth);
465466 }
467+ kfree(otg_desc[0]);
468+ otg_desc[0] = NULL;
469+
466470 return 0;
467471 }
468472
drivers/usb/gadget/legacy/g_ffs.c+17−15
@@ -88,21 +88,7 @@ MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol"); · 87 unmodified lines
8888 module_param_array_named(functions, func_names, charp, &func_num, 0);
8989 MODULE_PARM_DESC(functions, "USB Functions list");
9090
91−static const struct usb_descriptor_header *gfs_otg_desc[] = {
92− (const struct usb_descriptor_header *)
93− &(const struct usb_otg_descriptor) {
94− .bLength = sizeof(struct usb_otg_descriptor),
95− .bDescriptorType = USB_DT_OTG,
96−
97− /*
98− * REVISIT SRP-only hardware is possible, although
99− * it would not be called "OTG" ...
100− */
101− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
102− },
103−
104− NULL
105−};
91+static const struct usb_descriptor_header *gfs_otg_desc[2];
10692
10793 /* String IDs are assigned dynamically */
10894 static struct usb_string gfs_strings[] = {
@@ -412,6 +398,17 @@ static int gfs_bind(struct usb_composite_dev *cdev) · 303 unmodified lines
412398 goto error_rndis;
413399 gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id;
414400
401+ if (gadget_is_otg(cdev->gadget) && !gfs_otg_desc[0]) {
402+ struct usb_descriptor_header *usb_desc;
403+
404+ usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
405+ if (!usb_desc)
406+ goto error_rndis;
407+ usb_otg_descriptor_init(cdev->gadget, usb_desc);
408+ gfs_otg_desc[0] = usb_desc;
409+ gfs_otg_desc[1] = NULL;
410+ }
411+
415412 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) {
416413 struct gfs_configuration *c = gfs_configurations + i;
417414 int sid = USB_GADGET_FIRST_AVAIL_IDX + i;
@@ -432,6 +429,8 @@ static int gfs_bind(struct usb_composite_dev *cdev) · 14 unmodified lines
432429
433430 /* TODO */
434431 error_unbind:
432+ kfree(gfs_otg_desc[0]);
433+ gfs_otg_desc[0] = NULL;
435434 error_rndis:
436435 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS
437436 usb_put_function_instance(fi_rndis);
@@ -473,6 +472,9 @@ static int gfs_unbind(struct usb_composite_dev *cdev) · 35 unmodified lines
473472 for (i = 0; i < N_CONF * func_num; ++i)
474473 usb_put_function(*(f_ffs[0] + i));
475474
475+ kfree(gfs_otg_desc[0]);
476+ gfs_otg_desc[0] = NULL;
477+
476478 return 0;
477479 }
478480
drivers/usb/gadget/legacy/gmidi.c+3−5
@@ -35,8 +35,6 @@ · 34 unmodified lines
3535 #include <linux/usb/audio.h>
3636 #include <linux/usb/midi.h>
3737
38−#include "gadget_chips.h"
39−
4038 #include "u_midi.h"
4139
4240 /*-------------------------------------------------------------------------*/
@@ -88,10 +86,10 @@ MODULE_PARM_DESC(out_ports, "Number of MIDI output ports"); · 45 unmodified lines
8886 static struct usb_device_descriptor device_desc = {
8987 .bLength = USB_DT_DEVICE_SIZE,
9088 .bDescriptorType = USB_DT_DEVICE,
91− .bcdUSB = __constant_cpu_to_le16(0x0200),
89+ .bcdUSB = cpu_to_le16(0x0200),
9290 .bDeviceClass = USB_CLASS_PER_INTERFACE,
93− .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
94− .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
91+ .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
92+ .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
9593 /* .iManufacturer = DYNAMIC */
9694 /* .iProduct = DYNAMIC */
9795 .bNumConfigurations = 1,
drivers/usb/gadget/legacy/hid.c+20−17
@@ -19,7 +19,6 @@ · 18 unmodified lines
1919 #include <linux/usb/composite.h>
2020 #include <linux/usb/g_hid.h>
2121
22−#include "gadget_chips.h"
2322 #define DRIVER_DESC "HID Gadget"
2423 #define DRIVER_VERSION "2010/03/16"
2524
@@ -68,21 +67,7 @@ static struct usb_device_descriptor device_desc = { · 42 unmodified lines
6867 .bNumConfigurations = 1,
6968 };
7069
71−static struct usb_otg_descriptor otg_descriptor = {
72− .bLength = sizeof otg_descriptor,
73− .bDescriptorType = USB_DT_OTG,
74−
75− /* REVISIT SRP-only hardware is possible, although
76− * it would not be called "OTG" ...
77− */
78− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
79−};
80−
81−static const struct usb_descriptor_header *otg_desc[] = {
82− (struct usb_descriptor_header *) &otg_descriptor,
83− NULL,
84−};
85−
70+static const struct usb_descriptor_header *otg_desc[2];
8671
8772 /* string IDs are assigned dynamically */
8873 static struct usb_string strings_dev[] = {
@@ -186,16 +171,30 @@ static int hid_bind(struct usb_composite_dev *cdev) · 97 unmodified lines
186171 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
187172 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
188173
174+ if (gadget_is_otg(gadget) && !otg_desc[0]) {
175+ struct usb_descriptor_header *usb_desc;
176+
177+ usb_desc = usb_otg_descriptor_alloc(gadget);
178+ if (!usb_desc)
179+ goto put;
180+ usb_otg_descriptor_init(gadget, usb_desc);
181+ otg_desc[0] = usb_desc;
182+ otg_desc[1] = NULL;
183+ }
184+
189185 /* register our configuration */
190186 status = usb_add_config(cdev, &config_driver, do_config);
191187 if (status < 0)
192− goto put;
188+ goto free_otg_desc;
193189
194190 usb_composite_overwrite_options(cdev, &coverwrite);
195191 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
196192
197193 return 0;
198194
195+free_otg_desc:
196+ kfree(otg_desc[0]);
197+ otg_desc[0] = NULL;
199198 put:
200199 list_for_each_entry(m, &hidg_func_list, node) {
201200 if (m == n)
@@ -213,6 +212,10 @@ static int hid_unbind(struct usb_composite_dev *cdev) · 11 unmodified lines
213212 usb_put_function(n->f);
214213 usb_put_function_instance(n->fi);
215214 }
215+
216+ kfree(otg_desc[0]);
217+ otg_desc[0] = NULL;
218+
216219 return 0;
217220 }
218221
drivers/usb/gadget/legacy/mass_storage.c+19−22
@@ -64,21 +64,7 @@ static struct usb_device_descriptor msg_device_desc = { · 63 unmodified lines
6464 .bNumConfigurations = 1,
6565 };
6666
67−static struct usb_otg_descriptor otg_descriptor = {
68− .bLength = sizeof otg_descriptor,
69− .bDescriptorType = USB_DT_OTG,
70−
71− /*
72− * REVISIT SRP-only hardware is possible, although
73− * it would not be called "OTG" ...
74− */
75− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
76−};
77−
78−static const struct usb_descriptor_header *otg_desc[] = {
79− (struct usb_descriptor_header *) &otg_descriptor,
80− NULL,
81−};
67+static const struct usb_descriptor_header *otg_desc[2];
8268
8369 static struct usb_string strings_dev[] = {
8470 [USB_GADGET_MANUFACTURER_IDX].s = "",
@@ -191,10 +177,6 @@ static int msg_bind(struct usb_composite_dev *cdev) · 106 unmodified lines
191177 if (status)
192178 goto fail;
193179
194− status = fsg_common_set_nluns(opts->common, config.nluns);
195− if (status)
196− goto fail_set_nluns;
197−
198180 fsg_common_set_ops(opts->common, &ops);
199181
200182 status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
@@ -214,9 +196,20 @@ static int msg_bind(struct usb_composite_dev *cdev) · 13 unmodified lines
214196 goto fail_string_ids;
215197 msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
216198
199+ if (gadget_is_otg(cdev->gadget) && !otg_desc[0]) {
200+ struct usb_descriptor_header *usb_desc;
201+
202+ usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
203+ if (!usb_desc)
204+ goto fail_string_ids;
205+ usb_otg_descriptor_init(cdev->gadget, usb_desc);
206+ otg_desc[0] = usb_desc;
207+ otg_desc[1] = NULL;
208+ }
209+
217210 status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
218211 if (status < 0)
219− goto fail_string_ids;
212+ goto fail_otg_desc;
220213
221214 usb_composite_overwrite_options(cdev, &coverwrite);
222215 dev_info(&cdev->gadget->dev,
@@ -224,11 +217,12 @@ static int msg_bind(struct usb_composite_dev *cdev) · 1 unmodified line
224217 set_bit(0, &msg_registered);
225218 return 0;
226219
220+fail_otg_desc:
221+ kfree(otg_desc[0]);
222+ otg_desc[0] = NULL;
227223 fail_string_ids:
228224 fsg_common_remove_luns(opts->common);
229225 fail_set_cdev:
230− fsg_common_free_luns(opts->common);
231−fail_set_nluns:
232226 fsg_common_free_buffers(opts->common);
233227 fail:
234228 usb_put_function_instance(fi_msg);
@@ -243,6 +237,9 @@ static int msg_unbind(struct usb_composite_dev *cdev) · 8 unmodified lines
243237 if (!IS_ERR(fi_msg))
244238 usb_put_function_instance(fi_msg);
245239
240+ kfree(otg_desc[0]);
241+ otg_desc[0] = NULL;
242+
246243 return 0;
247244 }
248245
drivers/usb/gadget/legacy/multi.c+20−23
@@ -78,21 +78,7 @@ static struct usb_device_descriptor device_desc = { · 77 unmodified lines
7878 .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM),
7979 };
8080
81−
82−static const struct usb_descriptor_header *otg_desc[] = {
83− (struct usb_descriptor_header *) &(struct usb_otg_descriptor){
84− .bLength = sizeof(struct usb_otg_descriptor),
85− .bDescriptorType = USB_DT_OTG,
86−
87− /*
88− * REVISIT SRP-only hardware is possible, although
89− * it would not be called "OTG" ...
90− */
91− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
92− },
93− NULL,
94−};
95−
81+static const struct usb_descriptor_header *otg_desc[2];
9682
9783 enum {
9884 MULTI_STRING_RNDIS_CONFIG_IDX = USB_GADGET_FIRST_AVAIL_IDX,
@@ -407,10 +393,6 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) · 308 unmodified lines
407393 if (status)
408394 goto fail2;
409395
410− status = fsg_common_set_nluns(fsg_opts->common, config.nluns);
411− if (status)
412− goto fail_set_nluns;
413−
414396 status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall);
415397 if (status)
416398 goto fail_set_cdev;
@@ -429,14 +411,25 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) · 12 unmodified lines
429411 goto fail_string_ids;
430412 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
431413
414+ if (gadget_is_otg(gadget) && !otg_desc[0]) {
415+ struct usb_descriptor_header *usb_desc;
416+
417+ usb_desc = usb_otg_descriptor_alloc(gadget);
418+ if (!usb_desc)
419+ goto fail_string_ids;
420+ usb_otg_descriptor_init(gadget, usb_desc);
421+ otg_desc[0] = usb_desc;
422+ otg_desc[1] = NULL;
423+ }
424+
432425 /* register configurations */
433426 status = rndis_config_register(cdev);
434427 if (unlikely(status < 0))
435− goto fail_string_ids;
428+ goto fail_otg_desc;
436429
437430 status = cdc_config_register(cdev);
438431 if (unlikely(status < 0))
439− goto fail_string_ids;
432+ goto fail_otg_desc;
440433 usb_composite_overwrite_options(cdev, &coverwrite);
441434
442435 /* we're done */
@@ -445,11 +438,12 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) · 2 unmodified lines
445438
446439
447440 /* error recovery */
441+fail_otg_desc:
442+ kfree(otg_desc[0]);
443+ otg_desc[0] = NULL;
448444 fail_string_ids:
449445 fsg_common_remove_luns(fsg_opts->common);
450446 fail_set_cdev:
451− fsg_common_free_luns(fsg_opts->common);
452−fail_set_nluns:
453447 fsg_common_free_buffers(fsg_opts->common);
454448 fail2:
455449 usb_put_function_instance(fi_msg);
@@ -490,6 +484,9 @@ static int multi_unbind(struct usb_composite_dev *cdev) · 34 unmodified lines
490484 usb_put_function(f_ecm);
491485 usb_put_function_instance(fi_ecm);
492486 #endif
487+ kfree(otg_desc[0]);
488+ otg_desc[0] = NULL;
489+
493490 return 0;
494491 }
495492
drivers/usb/gadget/legacy/ncm.c+19−15
@@ -69,20 +69,7 @@ static struct usb_device_descriptor device_desc = { · 68 unmodified lines
6969 .bNumConfigurations = 1,
7070 };
7171
72−static struct usb_otg_descriptor otg_descriptor = {
73− .bLength = sizeof otg_descriptor,
74− .bDescriptorType = USB_DT_OTG,
75−
76− /* REVISIT SRP-only hardware is possible, although
77− * it would not be called "OTG" ...
78− */
79− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
80−};
81−
82−static const struct usb_descriptor_header *otg_desc[] = {
83− (struct usb_descriptor_header *) &otg_descriptor,
84− NULL,
85−};
72+static const struct usb_descriptor_header *otg_desc[2];
8673
8774 /* string IDs are assigned dynamically */
8875 static struct usb_string strings_dev[] = {
@@ -171,16 +158,30 @@ static int gncm_bind(struct usb_composite_dev *cdev) · 82 unmodified lines
171158 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
172159 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
173160
161+ if (gadget_is_otg(gadget) && !otg_desc[0]) {
162+ struct usb_descriptor_header *usb_desc;
163+
164+ usb_desc = usb_otg_descriptor_alloc(gadget);
165+ if (!usb_desc)
166+ goto fail;
167+ usb_otg_descriptor_init(gadget, usb_desc);
168+ otg_desc[0] = usb_desc;
169+ otg_desc[1] = NULL;
170+ }
171+
174172 status = usb_add_config(cdev, &ncm_config_driver,
175173 ncm_do_config);
176174 if (status < 0)
177− goto fail;
175+ goto fail1;
178176
179177 usb_composite_overwrite_options(cdev, &coverwrite);
180178 dev_info(&gadget->dev, "%s\n", DRIVER_DESC);
181179
182180 return 0;
183181
182+fail1:
183+ kfree(otg_desc[0]);
184+ otg_desc[0] = NULL;
184185 fail:
185186 usb_put_function_instance(f_ncm_inst);
186187 return status;
@@ -192,6 +193,9 @@ static int gncm_unbind(struct usb_composite_dev *cdev) · 5 unmodified lines
192193 usb_put_function(f_ncm);
193194 if (!IS_ERR_OR_NULL(f_ncm_inst))
194195 usb_put_function_instance(f_ncm_inst);
196+ kfree(otg_desc[0]);
197+ otg_desc[0] = NULL;
198+
195199 return 0;
196200 }
197201
drivers/usb/gadget/legacy/nokia.c+99−6
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323 #include "u_ether.h"
2424 #include "u_phonet.h"
2525 #include "u_ecm.h"
26−#include "gadget_chips.h"
26+#include "f_mass_storage.h"
2727
2828 /* Defines */
2929
@@ -34,6 +34,29 @@ USB_GADGET_COMPOSITE_OPTIONS(); · 4 unmodified lines
3434
3535 USB_ETHERNET_MODULE_PARAMETERS();
3636
37+static struct fsg_module_parameters fsg_mod_data = {
38+ .stall = 0,
39+ .luns = 2,
40+ .removable_count = 2,
41+ .removable = { 1, 1, },
42+};
43+
44+#ifdef CONFIG_USB_GADGET_DEBUG_FILES
45+
46+static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
47+
48+#else
49+
50+/*
51+ * Number of buffers we will use.
52+ * 2 is usually enough for good buffering pipeline
53+ */
54+#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
55+
56+#endif /* CONFIG_USB_DEBUG */
57+
58+FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
59+
3760 #define NOKIA_VENDOR_ID 0x0421 /* Nokia */
3861 #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
3962
@@ -66,10 +89,10 @@ static struct usb_gadget_strings *dev_strings[] = { · 26 unmodified lines
6689 static struct usb_device_descriptor device_desc = {
6790 .bLength = USB_DT_DEVICE_SIZE,
6891 .bDescriptorType = USB_DT_DEVICE,
69− .bcdUSB = __constant_cpu_to_le16(0x0200),
92+ .bcdUSB = cpu_to_le16(0x0200),
7093 .bDeviceClass = USB_CLASS_COMM,
71− .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID),
72− .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID),
94+ .idVendor = cpu_to_le16(NOKIA_VENDOR_ID),
95+ .idProduct = cpu_to_le16(NOKIA_PRODUCT_ID),
7396 .bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM),
7497 /* .iManufacturer = DYNAMIC */
7598 /* .iProduct = DYNAMIC */
@@ -94,6 +117,8 @@ static struct usb_function *f_obex1_cfg2; · 18 unmodified lines
94117 static struct usb_function *f_obex2_cfg2;
95118 static struct usb_function *f_phonet_cfg1;
96119 static struct usb_function *f_phonet_cfg2;
120+static struct usb_function *f_msg_cfg1;
121+static struct usb_function *f_msg_cfg2;
97122
98123
99124 static struct usb_configuration nokia_config_500ma_driver = {
@@ -117,6 +142,7 @@ static struct usb_function_instance *fi_ecm; · 17 unmodified lines
117142 static struct usb_function_instance *fi_obex1;
118143 static struct usb_function_instance *fi_obex2;
119144 static struct usb_function_instance *fi_phonet;
145+static struct usb_function_instance *fi_msg;
120146
121147 static int nokia_bind_config(struct usb_configuration *c)
122148 {
@@ -125,6 +151,8 @@ static int nokia_bind_config(struct usb_configuration *c) · 2 unmodified lines
125151 struct usb_function *f_obex1 = NULL;
126152 struct usb_function *f_ecm;
127153 struct usb_function *f_obex2 = NULL;
154+ struct usb_function *f_msg;
155+ struct fsg_opts *fsg_opts;
128156 int status = 0;
129157 int obex1_stat = -1;
130158 int obex2_stat = -1;
@@ -160,6 +188,12 @@ static int nokia_bind_config(struct usb_configuration *c) · 29 unmodified lines
160188 goto err_get_ecm;
161189 }
162190
191+ f_msg = usb_get_function(fi_msg);
192+ if (IS_ERR(f_msg)) {
193+ status = PTR_ERR(f_msg);
194+ goto err_get_msg;
195+ }
196+
163197 if (!IS_ERR_OR_NULL(f_phonet)) {
164198 phonet_stat = usb_add_function(c, f_phonet);
165199 if (phonet_stat)
@@ -187,21 +221,36 @@ static int nokia_bind_config(struct usb_configuration *c) · 21 unmodified lines
187221 pr_debug("could not bind ecm config %d\n", status);
188222 goto err_ecm;
189223 }
224+
225+ fsg_opts = fsg_opts_from_func_inst(fi_msg);
226+
227+ status = fsg_common_run_thread(fsg_opts->common);
228+ if (status)
229+ goto err_msg;
230+
231+ status = usb_add_function(c, f_msg);
232+ if (status)
233+ goto err_msg;
234+
190235 if (c == &nokia_config_500ma_driver) {
191236 f_acm_cfg1 = f_acm;
192237 f_ecm_cfg1 = f_ecm;
193238 f_phonet_cfg1 = f_phonet;
194239 f_obex1_cfg1 = f_obex1;
195240 f_obex2_cfg1 = f_obex2;
241+ f_msg_cfg1 = f_msg;
196242 } else {
197243 f_acm_cfg2 = f_acm;
198244 f_ecm_cfg2 = f_ecm;
199245 f_phonet_cfg2 = f_phonet;
200246 f_obex1_cfg2 = f_obex1;
201247 f_obex2_cfg2 = f_obex2;
248+ f_msg_cfg2 = f_msg;
202249 }
203250
204251 return status;
252+err_msg:
253+ usb_remove_function(c, f_ecm);
205254 err_ecm:
206255 usb_remove_function(c, f_acm);
207256 err_conf:
@@ -211,6 +260,8 @@ err_conf: · 3 unmodified lines
211260 usb_remove_function(c, f_obex1);
212261 if (!phonet_stat)
213262 usb_remove_function(c, f_phonet);
263+ usb_put_function(f_msg);
264+err_get_msg:
214265 usb_put_function(f_ecm);
215266 err_get_ecm:
216267 usb_put_function(f_acm);
@@ -227,6 +278,8 @@ err_get_acm: · 10 unmodified lines
227278 static int nokia_bind(struct usb_composite_dev *cdev)
228279 {
229280 struct usb_gadget *gadget = cdev->gadget;
281+ struct fsg_opts *fsg_opts;
282+ struct fsg_config fsg_config;
230283 int status;
231284
232285 status = usb_string_ids_tab(cdev, strings_dev);
@@ -238,7 +291,7 @@ static int nokia_bind(struct usb_composite_dev *cdev) · 5 unmodified lines
238291 nokia_config_500ma_driver.iConfiguration = status;
239292 nokia_config_100ma_driver.iConfiguration = status;
240293
241− if (!gadget_supports_altsettings(gadget)) {
294+ if (!gadget_is_altset_supported(gadget)) {
242295 status = -ENODEV;
243296 goto err_usb;
244297 }
@@ -267,11 +320,42 @@ static int nokia_bind(struct usb_composite_dev *cdev) · 22 unmodified lines
267320 goto err_acm_inst;
268321 }
269322
323+ fi_msg = usb_get_function_instance("mass_storage");
324+ if (IS_ERR(fi_msg)) {
325+ status = PTR_ERR(fi_msg);
326+ goto err_ecm_inst;
327+ }
328+
329+ /* set up mass storage function */
330+ fsg_config_from_params(&fsg_config, &fsg_mod_data, fsg_num_buffers);
331+ fsg_config.vendor_name = "Nokia";
332+ fsg_config.product_name = "N900";
333+
334+ fsg_opts = fsg_opts_from_func_inst(fi_msg);
335+ fsg_opts->no_configfs = true;
336+
337+ status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers);
338+ if (status)
339+ goto err_msg_inst;
340+
341+ status = fsg_common_set_cdev(fsg_opts->common, cdev, fsg_config.can_stall);
342+ if (status)
343+ goto err_msg_buf;
344+
345+ fsg_common_set_sysfs(fsg_opts->common, true);
346+
347+ status = fsg_common_create_luns(fsg_opts->common, &fsg_config);
348+ if (status)
349+ goto err_msg_buf;
350+
351+ fsg_common_set_inquiry_string(fsg_opts->common, fsg_config.vendor_name,
352+ fsg_config.product_name);
353+
270354 /* finally register the configuration */
271355 status = usb_add_config(cdev, &nokia_config_500ma_driver,
272356 nokia_bind_config);
273357 if (status < 0)
274− goto err_ecm_inst;
358+ goto err_msg_luns;
275359
276360 status = usb_add_config(cdev, &nokia_config_100ma_driver,
277361 nokia_bind_config);
@@ -292,6 +376,12 @@ err_put_cfg1: · 14 unmodified lines
292376 if (!IS_ERR_OR_NULL(f_phonet_cfg1))
293377 usb_put_function(f_phonet_cfg1);
294378 usb_put_function(f_ecm_cfg1);
379+err_msg_luns:
380+ fsg_common_remove_luns(fsg_opts->common);
381+err_msg_buf:
382+ fsg_common_free_buffers(fsg_opts->common);
383+err_msg_inst:
384+ usb_put_function_instance(fi_msg);
295385 err_ecm_inst:
296386 usb_put_function_instance(fi_ecm);
297387 err_acm_inst:
@@ -325,7 +415,10 @@ static int nokia_unbind(struct usb_composite_dev *cdev) · 27 unmodified lines
325415 usb_put_function(f_acm_cfg2);
326416 usb_put_function(f_ecm_cfg1);
327417 usb_put_function(f_ecm_cfg2);
418+ usb_put_function(f_msg_cfg1);
419+ usb_put_function(f_msg_cfg2);
328420
421+ usb_put_function_instance(fi_msg);
329422 usb_put_function_instance(fi_ecm);
330423 if (!IS_ERR(fi_obex2))
331424 usb_put_function_instance(fi_obex2);
drivers/usb/gadget/legacy/printer.c+30−21
@@ -19,8 +19,6 @@ · 18 unmodified lines
1919 #include <linux/usb/gadget.h>
2020 #include <linux/usb/g_printer.h>
2121
22−#include "gadget_chips.h"
23−
2422 USB_GADGET_COMPOSITE_OPTIONS();
2523
2624 #define DRIVER_DESC "Printer Gadget"
@@ -82,16 +80,7 @@ static struct usb_device_descriptor device_desc = { · 55 unmodified lines
8280 .bNumConfigurations = 1
8381 };
8482
85−static struct usb_otg_descriptor otg_descriptor = {
86− .bLength = sizeof otg_descriptor,
87− .bDescriptorType = USB_DT_OTG,
88− .bmAttributes = USB_OTG_SRP,
89−};
90−
91−static const struct usb_descriptor_header *otg_desc[] = {
92− (struct usb_descriptor_header *) &otg_descriptor,
93− NULL,
94−};
83+static const struct usb_descriptor_header *otg_desc[2];
9584
9685 /*-------------------------------------------------------------------------*/
9786
@@ -136,7 +125,6 @@ static int printer_do_config(struct usb_configuration *c) · 38 unmodified lines
136125 usb_gadget_set_selfpowered(gadget);
137126
138127 if (gadget_is_otg(gadget)) {
139− otg_descriptor.bmAttributes |= USB_OTG_HNP;
140128 printer_cfg_driver.descriptors = otg_desc;
141129 printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
142130 }
@@ -174,21 +162,39 @@ static int printer_bind(struct usb_composite_dev *cdev) · 31 unmodified lines
174162 opts->q_len = QLEN;
175163
176164 ret = usb_string_ids_tab(cdev, strings);
177− if (ret < 0) {
178− usb_put_function_instance(fi_printer);
179− return ret;
180− }
165+ if (ret < 0)
166+ goto fail_put_func_inst;
167+
181168 device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id;
182169 device_desc.iProduct = strings[USB_GADGET_PRODUCT_IDX].id;
183170 device_desc.iSerialNumber = strings[USB_GADGET_SERIAL_IDX].id;
184171
185− ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config);
186− if (ret) {
187− usb_put_function_instance(fi_printer);
188− return ret;
172+ if (gadget_is_otg(cdev->gadget) && !otg_desc[0]) {
173+ struct usb_descriptor_header *usb_desc;
174+
175+ usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
176+ if (!usb_desc) {
177+ ret = -ENOMEM;
178+ goto fail_put_func_inst;
179+ }
180+ usb_otg_descriptor_init(cdev->gadget, usb_desc);
181+ otg_desc[0] = usb_desc;
182+ otg_desc[1] = NULL;
189183 }
184+
185+ ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config);
186+ if (ret)
187+ goto fail_free_otg_desc;
188+
190189 usb_composite_overwrite_options(cdev, &coverwrite);
191190 return ret;
191+
192+fail_free_otg_desc:
193+ kfree(otg_desc[0]);
194+ otg_desc[0] = NULL;
195+fail_put_func_inst:
196+ usb_put_function_instance(fi_printer);
197+ return ret;
192198 }
193199
194200 static int printer_unbind(struct usb_composite_dev *cdev)
@@ -196,6 +202,9 @@ static int printer_unbind(struct usb_composite_dev *cdev) · 1 unmodified line
196202 usb_put_function(f_printer);
197203 usb_put_function_instance(fi_printer);
198204
205+ kfree(otg_desc[0]);
206+ otg_desc[0] = NULL;
207+
199208 return 0;
200209 }
201210
drivers/usb/gadget/legacy/serial.c+21−17
@@ -17,7 +17,6 @@ · 16 unmodified lines
1717 #include <linux/tty_flip.h>
1818
1919 #include "u_serial.h"
20−#include "gadget_chips.h"
2120
2221
2322 /* Defines */
@@ -79,20 +78,7 @@ static struct usb_device_descriptor device_desc = { · 55 unmodified lines
7978 .bNumConfigurations = 1,
8079 };
8180
82−static struct usb_otg_descriptor otg_descriptor = {
83− .bLength = sizeof otg_descriptor,
84− .bDescriptorType = USB_DT_OTG,
85−
86− /* REVISIT SRP-only hardware is possible, although
87− * it would not be called "OTG" ...
88− */
89− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
90−};
91−
92−static const struct usb_descriptor_header *otg_desc[] = {
93− (struct usb_descriptor_header *) &otg_descriptor,
94− NULL,
95−};
81+static const struct usb_descriptor_header *otg_desc[2];
9682
9783 /*-------------------------------------------------------------------------*/
9884
@@ -191,6 +177,18 @@ static int gs_bind(struct usb_composite_dev *cdev) · 92 unmodified lines
191177 serial_config_driver.iConfiguration = status;
192178
193179 if (gadget_is_otg(cdev->gadget)) {
180+ if (!otg_desc[0]) {
181+ struct usb_descriptor_header *usb_desc;
182+
183+ usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
184+ if (!usb_desc) {
185+ status = -ENOMEM;
186+ goto fail;
187+ }
188+ usb_otg_descriptor_init(cdev->gadget, usb_desc);
189+ otg_desc[0] = usb_desc;
190+ otg_desc[1] = NULL;
191+ }
194192 serial_config_driver.descriptors = otg_desc;
195193 serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
196194 }
@@ -208,13 +206,15 @@ static int gs_bind(struct usb_composite_dev *cdev) · 11 unmodified lines
208206 "gser");
209207 }
210208 if (status < 0)
211− goto fail;
209+ goto fail1;
212210
213211 usb_composite_overwrite_options(cdev, &coverwrite);
214212 INFO(cdev, "%s\n", GS_VERSION_NAME);
215213
216214 return 0;
217−
215+fail1:
216+ kfree(otg_desc[0]);
217+ otg_desc[0] = NULL;
218218 fail:
219219 return status;
220220 }
@@ -227,6 +227,10 @@ static int gs_unbind(struct usb_composite_dev *cdev) · 6 unmodified lines
227227 usb_put_function(f_serial[i]);
228228 usb_put_function_instance(fi_serial[i]);
229229 }
230+
231+ kfree(otg_desc[0]);
232+ otg_desc[0] = NULL;
233+
230234 return 0;
231235 }
232236
drivers/usb/gadget/legacy/zero.c+21−20
@@ -121,24 +121,7 @@ static struct usb_device_descriptor device_desc = { · 120 unmodified lines
121121 .bNumConfigurations = 2,
122122 };
123123
124−#ifdef CONFIG_USB_OTG
125−static struct usb_otg_descriptor otg_descriptor = {
126− .bLength = sizeof otg_descriptor,
127− .bDescriptorType = USB_DT_OTG,
128−
129− /* REVISIT SRP-only hardware is possible, although
130− * it would not be called "OTG" ...
131− */
132− .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
133−};
134−
135−static const struct usb_descriptor_header *otg_desc[] = {
136− (struct usb_descriptor_header *) &otg_descriptor,
137− NULL,
138−};
139−#else
140−#define otg_desc NULL
141−#endif
124+static const struct usb_descriptor_header *otg_desc[2];
142125
143126 /* string IDs are assigned dynamically */
144127 /* default serial number takes at least two packets */
@@ -341,6 +324,18 @@ static int zero_bind(struct usb_composite_dev *cdev) · 196 unmodified lines
341324
342325 /* support OTG systems */
343326 if (gadget_is_otg(cdev->gadget)) {
327+ if (!otg_desc[0]) {
328+ struct usb_descriptor_header *usb_desc;
329+
330+ usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
331+ if (!usb_desc) {
332+ status = -ENOMEM;
333+ goto err_conf_flb;
334+ }
335+ usb_otg_descriptor_init(cdev->gadget, usb_desc);
336+ otg_desc[0] = usb_desc;
337+ otg_desc[1] = NULL;
338+ }
344339 sourcesink_driver.descriptors = otg_desc;
345340 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
346341 loopback_driver.descriptors = otg_desc;
@@ -359,12 +354,12 @@ static int zero_bind(struct usb_composite_dev *cdev) · 12 unmodified lines
359354 }
360355 status = usb_add_function(&sourcesink_driver, func_ss);
361356 if (status)
362− goto err_conf_flb;
357+ goto err_free_otg_desc;
363358
364359 usb_ep_autoconfig_reset(cdev->gadget);
365360 status = usb_add_function(&loopback_driver, func_lb);
366361 if (status)
367− goto err_conf_flb;
362+ goto err_free_otg_desc;
368363
369364 usb_ep_autoconfig_reset(cdev->gadget);
370365 usb_composite_overwrite_options(cdev, &coverwrite);
@@ -373,6 +368,9 @@ static int zero_bind(struct usb_composite_dev *cdev) · 2 unmodified lines
373368
374369 return 0;
375370
371+err_free_otg_desc:
372+ kfree(otg_desc[0]);
373+ otg_desc[0] = NULL;
376374 err_conf_flb:
377375 usb_put_function(func_lb);
378376 func_lb = NULL;
@@ -397,6 +395,9 @@ static int zero_unbind(struct usb_composite_dev *cdev) · 18 unmodified lines
397395 if (!IS_ERR_OR_NULL(func_lb))
398396 usb_put_function(func_lb);
399397 usb_put_function_instance(func_inst_lb);
398+ kfree(otg_desc[0]);
399+ otg_desc[0] = NULL;
400+
400401 return 0;
401402 }
402403
drivers/usb/gadget/udc/amd5536udc.c+78−10
@@ -138,15 +138,82 @@ static DECLARE_TASKLET(disconnect_tasklet, udc_tasklet_disconnect, · 137 unmodified lines
138138
139139 /* endpoint names used for print */
140140 static const char ep0_string[] = "ep0in";
141−static const char *const ep_string[] = {
142− ep0_string,
143− "ep1in-int", "ep2in-bulk", "ep3in-bulk", "ep4in-bulk", "ep5in-bulk",
144− "ep6in-bulk", "ep7in-bulk", "ep8in-bulk", "ep9in-bulk", "ep10in-bulk",
145− "ep11in-bulk", "ep12in-bulk", "ep13in-bulk", "ep14in-bulk",
146− "ep15in-bulk", "ep0out", "ep1out-bulk", "ep2out-bulk", "ep3out-bulk",
147− "ep4out-bulk", "ep5out-bulk", "ep6out-bulk", "ep7out-bulk",
148− "ep8out-bulk", "ep9out-bulk", "ep10out-bulk", "ep11out-bulk",
149− "ep12out-bulk", "ep13out-bulk", "ep14out-bulk", "ep15out-bulk"
141+static const struct {
142+ const char *name;
143+ const struct usb_ep_caps caps;
144+} ep_info[] = {
145+#define EP_INFO(_name, _caps) \
146+ { \
147+ .name = _name, \
148+ .caps = _caps, \
149+ }
150+
151+ EP_INFO(ep0_string,
152+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_IN)),
153+ EP_INFO("ep1in-int",
154+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
155+ EP_INFO("ep2in-bulk",
156+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
157+ EP_INFO("ep3in-bulk",
158+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
159+ EP_INFO("ep4in-bulk",
160+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
161+ EP_INFO("ep5in-bulk",
162+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
163+ EP_INFO("ep6in-bulk",
164+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
165+ EP_INFO("ep7in-bulk",
166+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
167+ EP_INFO("ep8in-bulk",
168+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
169+ EP_INFO("ep9in-bulk",
170+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
171+ EP_INFO("ep10in-bulk",
172+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
173+ EP_INFO("ep11in-bulk",
174+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
175+ EP_INFO("ep12in-bulk",
176+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
177+ EP_INFO("ep13in-bulk",
178+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
179+ EP_INFO("ep14in-bulk",
180+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
181+ EP_INFO("ep15in-bulk",
182+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
183+ EP_INFO("ep0out",
184+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_OUT)),
185+ EP_INFO("ep1out-bulk",
186+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
187+ EP_INFO("ep2out-bulk",
188+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
189+ EP_INFO("ep3out-bulk",
190+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
191+ EP_INFO("ep4out-bulk",
192+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
193+ EP_INFO("ep5out-bulk",
194+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
195+ EP_INFO("ep6out-bulk",
196+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
197+ EP_INFO("ep7out-bulk",
198+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
199+ EP_INFO("ep8out-bulk",
200+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
201+ EP_INFO("ep9out-bulk",
202+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
203+ EP_INFO("ep10out-bulk",
204+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
205+ EP_INFO("ep11out-bulk",
206+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
207+ EP_INFO("ep12out-bulk",
208+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
209+ EP_INFO("ep13out-bulk",
210+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
211+ EP_INFO("ep14out-bulk",
212+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
213+ EP_INFO("ep15out-bulk",
214+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
215+
216+#undef EP_INFO
150217 };
151218
152219 /* DMA usage flag */
@@ -1517,7 +1584,8 @@ static void udc_setup_endpoints(struct udc *dev) · 1364 unmodified lines
15171584 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) {
15181585 ep = &dev->ep[tmp];
15191586 ep->dev = dev;
1520− ep->ep.name = ep_string[tmp];
1587+ ep->ep.name = ep_info[tmp].name;
1588+ ep->ep.caps = ep_info[tmp].caps;
15211589 ep->num = tmp;
15221590 /* txfifo size is calculated at enable time */
15231591 ep->txfifo = dev->txfifo;
drivers/usb/gadget/udc/at91_udc.c+30−9
@@ -59,15 +59,34 @@ · 58 unmodified lines
5959 #define DRIVER_VERSION "3 May 2006"
6060
6161 static const char driver_name [] = "at91_udc";
62−static const char * const ep_names[] = {
63− "ep0",
64− "ep1",
65− "ep2",
66− "ep3-int",
67− "ep4",
68− "ep5",
62+
63+static const struct {
64+ const char *name;
65+ const struct usb_ep_caps caps;
66+} ep_info[] = {
67+#define EP_INFO(_name, _caps) \
68+ { \
69+ .name = _name, \
70+ .caps = _caps, \
71+ }
72+
73+ EP_INFO("ep0",
74+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
75+ EP_INFO("ep1",
76+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
77+ EP_INFO("ep2",
78+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
79+ EP_INFO("ep3-int",
80+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_ALL)),
81+ EP_INFO("ep4",
82+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
83+ EP_INFO("ep5",
84+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
85+
86+#undef EP_INFO
6987 };
70−#define ep0name ep_names[0]
88+
89+#define ep0name ep_info[0].name
7190
7291 #define VBUS_POLL_TIMEOUT msecs_to_jiffies(1000)
7392
@@ -825,6 +844,7 @@ static void udc_reinit(struct at91_udc *udc) · 751 unmodified lines
825844
826845 INIT_LIST_HEAD(&udc->gadget.ep_list);
827846 INIT_LIST_HEAD(&udc->gadget.ep0->ep_list);
847+ udc->gadget.quirk_stall_not_supp = 1;
828848
829849 for (i = 0; i < NUM_ENDPOINTS; i++) {
830850 struct at91_ep *ep = &udc->ep[i];
@@ -1830,7 +1850,8 @@ static int at91udc_probe(struct platform_device *pdev) · 999 unmodified lines
18301850
18311851 for (i = 0; i < NUM_ENDPOINTS; i++) {
18321852 ep = &udc->ep[i];
1833− ep->ep.name = ep_names[i];
1853+ ep->ep.name = ep_info[i].name;
1854+ ep->ep.caps = ep_info[i].caps;
18341855 ep->ep.ops = &at91_ep_ops;
18351856 ep->udc = udc;
18361857 ep->int_mask = BIT(i);
drivers/usb/gadget/udc/atmel_usba_udc.c+15−0
@@ -1989,6 +1989,10 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, · 1988 unmodified lines
19891989 ep->can_isoc = of_property_read_bool(pp, "atmel,can-isoc");
19901990
19911991 ret = of_property_read_string(pp, "name", &name);
1992+ if (ret) {
1993+ dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret);
1994+ goto err;
1995+ }
19921996 ep->ep.name = name;
19931997
19941998 ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
@@ -2063,6 +2067,17 @@ static struct usba_ep * usba_udc_pdata(struct platform_device *pdev, · 68 unmodified lines
20632067 ep->can_dma = pdata->ep[i].can_dma;
20642068 ep->can_isoc = pdata->ep[i].can_isoc;
20652069
2070+ if (i == 0) {
2071+ ep->ep.caps.type_control = true;
2072+ } else {
2073+ ep->ep.caps.type_iso = ep->can_isoc;
2074+ ep->ep.caps.type_bulk = true;
2075+ ep->ep.caps.type_int = true;
2076+ }
2077+
2078+ ep->ep.caps.dir_in = true;
2079+ ep->ep.caps.dir_out = true;
2080+
20662081 if (i)
20672082 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
20682083 }
drivers/usb/gadget/udc/bcm63xx_udc.c+25−4
@@ -44,9 +44,29 @@ · 43 unmodified lines
4444 #define DRV_MODULE_NAME "bcm63xx_udc"
4545
4646 static const char bcm63xx_ep0name[] = "ep0";
47−static const char *const bcm63xx_ep_name[] = {
48− bcm63xx_ep0name,
49− "ep1in-bulk", "ep2out-bulk", "ep3in-int", "ep4out-int",
47+
48+static const struct {
49+ const char *name;
50+ const struct usb_ep_caps caps;
51+} bcm63xx_ep_info[] = {
52+#define EP_INFO(_name, _caps) \
53+ { \
54+ .name = _name, \
55+ .caps = _caps, \
56+ }
57+
58+ EP_INFO(bcm63xx_ep0name,
59+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
60+ EP_INFO("ep1in-bulk",
61+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
62+ EP_INFO("ep2out-bulk",
63+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
64+ EP_INFO("ep3in-int",
65+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)),
66+ EP_INFO("ep4out-int",
67+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_OUT)),
68+
69+#undef EP_INFO
5070 };
5171
5272 static bool use_fullspeed;
@@ -943,7 +963,8 @@ static int bcm63xx_init_udc_hw(struct bcm63xx_udc *udc) · 890 unmodified lines
943963 for (i = 0; i < BCM63XX_NUM_EP; i++) {
944964 struct bcm63xx_ep *bep = &udc->bep[i];
945965
946− bep->ep.name = bcm63xx_ep_name[i];
966+ bep->ep.name = bcm63xx_ep_info[i].name;
967+ bep->ep.caps = bcm63xx_ep_info[i].caps;
947968 bep->ep_num = i;
948969 bep->ep.ops = &bcm63xx_udc_ep_ops;
949970 list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list);
drivers/usb/gadget/udc/bdc/bdc_ep.c+9−0
@@ -1952,12 +1952,18 @@ static int init_ep(struct bdc *bdc, u32 epnum, u32 dir) · 1951 unmodified lines
19521952 ep->bdc = bdc;
19531953 ep->dir = dir;
19541954
1955+ if (dir)
1956+ ep->usb_ep.caps.dir_in = true;
1957+ else
1958+ ep->usb_ep.caps.dir_out = true;
1959+
19551960 /* ep->ep_num is the index inside bdc_ep */
19561961 if (epnum == 1) {
19571962 ep->ep_num = 1;
19581963 bdc->bdc_ep_array[ep->ep_num] = ep;
19591964 snprintf(ep->name, sizeof(ep->name), "ep%d", epnum - 1);
19601965 usb_ep_set_maxpacket_limit(&ep->usb_ep, EP0_MAX_PKT_SIZE);
1966+ ep->usb_ep.caps.type_control = true;
19611967 ep->comp_desc = NULL;
19621968 bdc->gadget.ep0 = &ep->usb_ep;
19631969 } else {
@@ -1971,6 +1977,9 @@ static int init_ep(struct bdc *bdc, u32 epnum, u32 dir) · 7 unmodified lines
19711977 dir & 1 ? "in" : "out");
19721978
19731979 usb_ep_set_maxpacket_limit(&ep->usb_ep, 1024);
1980+ ep->usb_ep.caps.type_iso = true;
1981+ ep->usb_ep.caps.type_bulk = true;
1982+ ep->usb_ep.caps.type_int = true;
19741983 ep->usb_ep.max_streams = 0;
19751984 list_add_tail(&ep->usb_ep.ep_list, &bdc->gadget.ep_list);
19761985 }
drivers/usb/gadget/udc/dummy_hcd.c+80−15
@@ -127,23 +127,87 @@ static inline struct dummy_request *usb_request_to_dummy_request · 126 unmodified lines
127127
128128 static const char ep0name[] = "ep0";
129129
130−static const char *const ep_name[] = {
131− ep0name, /* everyone has ep0 */
130+static const struct {
131+ const char *name;
132+ const struct usb_ep_caps caps;
133+} ep_info[] = {
134+#define EP_INFO(_name, _caps) \
135+ { \
136+ .name = _name, \
137+ .caps = _caps, \
138+ }
132139
140+ /* everyone has ep0 */
141+ EP_INFO(ep0name,
142+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
133143 /* act like a pxa250: fifteen fixed function endpoints */
134− "ep1in-bulk", "ep2out-bulk", "ep3in-iso", "ep4out-iso", "ep5in-int",
135− "ep6in-bulk", "ep7out-bulk", "ep8in-iso", "ep9out-iso", "ep10in-int",
136− "ep11in-bulk", "ep12out-bulk", "ep13in-iso", "ep14out-iso",
137− "ep15in-int",
138−
144+ EP_INFO("ep1in-bulk",
145+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
146+ EP_INFO("ep2out-bulk",
147+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
148+ EP_INFO("ep3in-iso",
149+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_IN)),
150+ EP_INFO("ep4out-iso",
151+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_OUT)),
152+ EP_INFO("ep5in-int",
153+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)),
154+ EP_INFO("ep6in-bulk",
155+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
156+ EP_INFO("ep7out-bulk",
157+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
158+ EP_INFO("ep8in-iso",
159+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_IN)),
160+ EP_INFO("ep9out-iso",
161+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_OUT)),
162+ EP_INFO("ep10in-int",
163+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)),
164+ EP_INFO("ep11in-bulk",
165+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
166+ EP_INFO("ep12out-bulk",
167+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
168+ EP_INFO("ep13in-iso",
169+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_IN)),
170+ EP_INFO("ep14out-iso",
171+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO, USB_EP_CAPS_DIR_OUT)),
172+ EP_INFO("ep15in-int",
173+ USB_EP_CAPS(USB_EP_CAPS_TYPE_INT, USB_EP_CAPS_DIR_IN)),
139174 /* or like sa1100: two fixed function endpoints */
140− "ep1out-bulk", "ep2in-bulk",
141−
175+ EP_INFO("ep1out-bulk",
176+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_OUT)),
177+ EP_INFO("ep2in-bulk",
178+ USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK, USB_EP_CAPS_DIR_IN)),
142179 /* and now some generic EPs so we have enough in multi config */
143− "ep3out", "ep4in", "ep5out", "ep6out", "ep7in", "ep8out", "ep9in",
144− "ep10out", "ep11out", "ep12in", "ep13out", "ep14in", "ep15out",
180+ EP_INFO("ep3out",
181+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
182+ EP_INFO("ep4in",
183+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
184+ EP_INFO("ep5out",
185+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
186+ EP_INFO("ep6out",
187+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
188+ EP_INFO("ep7in",
189+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
190+ EP_INFO("ep8out",
191+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
192+ EP_INFO("ep9in",
193+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
194+ EP_INFO("ep10out",
195+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
196+ EP_INFO("ep11out",
197+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
198+ EP_INFO("ep12in",
199+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
200+ EP_INFO("ep13out",
201+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
202+ EP_INFO("ep14in",
203+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
204+ EP_INFO("ep15out",
205+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
206+
207+#undef EP_INFO
145208 };
146−#define DUMMY_ENDPOINTS ARRAY_SIZE(ep_name)
209+
210+#define DUMMY_ENDPOINTS ARRAY_SIZE(ep_info)
147211
148212 /*-------------------------------------------------------------------------*/
149213
@@ -938,9 +1002,10 @@ static void init_dummy_udc_hw(struct dummy *dum) · 788 unmodified lines
9381002 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
9391003 struct dummy_ep *ep = &dum->ep[i];
9401004
941− if (!ep_name[i])
1005+ if (!ep_info[i].name)
9421006 break;
943− ep->ep.name = ep_name[i];
1007+ ep->ep.name = ep_info[i].name;
1008+ ep->ep.caps = ep_info[i].caps;
9441009 ep->ep.ops = &dummy_ep_ops;
9451010 list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list);
9461011 ep->halted = ep->wedged = ep->already_seen =
@@ -1684,7 +1749,7 @@ static void dummy_timer(unsigned long _dum_hcd) · 737 unmodified lines
16841749 }
16851750
16861751 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
1687− if (!ep_name[i])
1752+ if (!ep_info[i].name)
16881753 break;
16891754 dum->ep[i].already_seen = 0;
16901755 }
drivers/usb/gadget/udc/fotg210-udc.c+15−14
@@ -384,25 +384,15 @@ static void fotg210_ep0_queue(struct fotg210_ep *ep, · 383 unmodified lines
384384 return;
385385 }
386386 if (ep->dir_in) { /* if IN */
387− if (req->req.length) {
388− fotg210_start_dma(ep, req);
389− } else {
390− pr_err("%s : req->req.length = 0x%x\n",
391− __func__, req->req.length);
392− }
387+ fotg210_start_dma(ep, req);
393388 if ((req->req.length == req->req.actual) ||
394389 (req->req.actual < ep->ep.maxpacket))
395390 fotg210_done(ep, req, 0);
396391 } else { /* OUT */
397− if (!req->req.length) {
398− fotg210_done(ep, req, 0);
399− } else {
400− u32 value = ioread32(ep->fotg210->reg +
401− FOTG210_DMISGR0);
392+ u32 value = ioread32(ep->fotg210->reg + FOTG210_DMISGR0);
402393
403− value &= ~DMISGR0_MCX_OUT_INT;
404− iowrite32(value, ep->fotg210->reg + FOTG210_DMISGR0);
405− }
394+ value &= ~DMISGR0_MCX_OUT_INT;
395+ iowrite32(value, ep->fotg210->reg + FOTG210_DMISGR0);
406396 }
407397 }
408398
@@ -1153,6 +1143,17 @@ static int fotg210_udc_probe(struct platform_device *pdev) · 744 unmodified lines
11531143 ep->ep.name = fotg210_ep_name[i];
11541144 ep->ep.ops = &fotg210_ep_ops;
11551145 usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0);
1146+
1147+ if (i == 0) {
1148+ ep->ep.caps.type_control = true;
1149+ } else {
1150+ ep->ep.caps.type_iso = true;
1151+ ep->ep.caps.type_bulk = true;
1152+ ep->ep.caps.type_int = true;
1153+ }
1154+
1155+ ep->ep.caps.dir_in = true;
1156+ ep->ep.caps.dir_out = true;
11561157 }
11571158 usb_ep_set_maxpacket_limit(&fotg210->ep[0]->ep, 0x40);
11581159 fotg210->gadget.ep0 = &fotg210->ep[0]->ep;
drivers/usb/gadget/udc/fsl_qe_udc.c+11−0
@@ -2417,6 +2417,17 @@ static int qe_ep_config(struct qe_udc *udc, unsigned char pipe_num) · 2416 unmodified lines
24172417 strcpy(ep->name, ep_name[pipe_num]);
24182418 ep->ep.name = ep_name[pipe_num];
24192419
2420+ if (pipe_num == 0) {
2421+ ep->ep.caps.type_control = true;
2422+ } else {
2423+ ep->ep.caps.type_iso = true;
2424+ ep->ep.caps.type_bulk = true;
2425+ ep->ep.caps.type_int = true;
2426+ }
2427+
2428+ ep->ep.caps.dir_in = true;
2429+ ep->ep.caps.dir_out = true;
2430+
24202431 ep->ep.ops = &qe_ep_ops;
24212432 ep->stopped = 1;
24222433 usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0);
drivers/usb/gadget/udc/fsl_udc_core.c+13−0
@@ -2313,6 +2313,19 @@ static int struct_ep_setup(struct fsl_udc *udc, unsigned char index, · 2312 unmodified lines
23132313 ep->ep.ops = &fsl_ep_ops;
23142314 ep->stopped = 0;
23152315
2316+ if (index == 0) {
2317+ ep->ep.caps.type_control = true;
2318+ } else {
2319+ ep->ep.caps.type_iso = true;
2320+ ep->ep.caps.type_bulk = true;
2321+ ep->ep.caps.type_int = true;
2322+ }
2323+
2324+ if (index & 1)
2325+ ep->ep.caps.dir_in = true;
2326+ else
2327+ ep->ep.caps.dir_out = true;
2328+
23162329 /* for ep0: maxP defined in desc
23172330 * for other eps, maxP is set by epautoconfig() called by gadget layer
23182331 */
drivers/usb/gadget/udc/fusb300_udc.c+11−0
@@ -1450,6 +1450,17 @@ static int fusb300_probe(struct platform_device *pdev) · 1449 unmodified lines
14501450 ep->ep.name = fusb300_ep_name[i];
14511451 ep->ep.ops = &fusb300_ep_ops;
14521452 usb_ep_set_maxpacket_limit(&ep->ep, HS_BULK_MAX_PACKET_SIZE);
1453+
1454+ if (i == 0) {
1455+ ep->ep.caps.type_control = true;
1456+ } else {
1457+ ep->ep.caps.type_iso = true;
1458+ ep->ep.caps.type_bulk = true;
1459+ ep->ep.caps.type_int = true;
1460+ }
1461+
1462+ ep->ep.caps.dir_in = true;
1463+ ep->ep.caps.dir_out = true;
14531464 }
14541465 usb_ep_set_maxpacket_limit(&fusb300->ep[0]->ep, HS_CTL_MAX_PACKET_SIZE);
14551466 fusb300->ep[0]->epnum = 0;
drivers/usb/gadget/udc/gadget_chips.h+0−55
@@ -1,55 +0,0 @@
1−/*
2− * USB device controllers have lots of quirks. Use these macros in
3− * gadget drivers or other code that needs to deal with them, and which
4− * autoconfigures instead of using early binding to the hardware.
5− *
6− * This SHOULD eventually work like the ARM mach_is_*() stuff, driven by
7− * some config file that gets updated as new hardware is supported.
8− * (And avoiding all runtime comparisons in typical one-choice configs!)
9− *
10− * NOTE: some of these controller drivers may not be available yet.
11− * Some are available on 2.4 kernels; several are available, but not
12− * yet pushed in the 2.6 mainline tree.
13− */
14−
15−#ifndef __GADGET_CHIPS_H
16−#define __GADGET_CHIPS_H
17−
18−#include <linux/usb/gadget.h>
19−
20−/*
21− * NOTICE: the entries below are alphabetical and should be kept
22− * that way.
23− *
24− * Always be sure to add new entries to the correct position or
25− * accept the bashing later.
26− *
27− * If you have forgotten the alphabetical order let VIM/EMACS
28− * do that for you.
29− */
30−#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name))
31−#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name))
32−#define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name))
33−#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name))
34−#define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name))
35−#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name))
36−
37−/**
38− * gadget_supports_altsettings - return true if altsettings work
39− * @gadget: the gadget in question
40− */
41−static inline bool gadget_supports_altsettings(struct usb_gadget *gadget)
42−{
43− /* PXA 21x/25x/26x has no altsettings at all */
44− if (gadget_is_pxa(gadget))
45− return false;
46−
47− /* PXA 27x and 3xx have *broken* altsetting support */
48− if (gadget_is_pxa27x(gadget))
49− return false;
50−
51− /* Everything else is *presumably* fine ... */
52− return true;
53−}
54−
55−#endif /* __GADGET_CHIPS_H */
drivers/usb/gadget/udc/goku_udc.c+38−0
@@ -990,6 +990,35 @@ static int goku_get_frame(struct usb_gadget *_gadget) · 989 unmodified lines
990990 return -EOPNOTSUPP;
991991 }
992992
993+static struct usb_ep *goku_match_ep(struct usb_gadget *g,
994+ struct usb_endpoint_descriptor *desc,
995+ struct usb_ss_ep_comp_descriptor *ep_comp)
996+{
997+ struct goku_udc *dev = to_goku_udc(g);
998+ struct usb_ep *ep;
999+
1000+ switch (usb_endpoint_type(desc)) {
1001+ case USB_ENDPOINT_XFER_INT:
1002+ /* single buffering is enough */
1003+ ep = &dev->ep[3].ep;
1004+ if (usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
1005+ return ep;
1006+ break;
1007+ case USB_ENDPOINT_XFER_BULK:
1008+ if (usb_endpoint_dir_in(desc)) {
1009+ /* DMA may be available */
1010+ ep = &dev->ep[2].ep;
1011+ if (usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
1012+ return ep;
1013+ }
1014+ break;
1015+ default:
1016+ /* nothing */ ;
1017+ }
1018+
1019+ return NULL;
1020+}
1021+
9931022 static int goku_udc_start(struct usb_gadget *g,
9941023 struct usb_gadget_driver *driver);
9951024 static int goku_udc_stop(struct usb_gadget *g);
@@ -998,6 +1027,7 @@ static const struct usb_gadget_ops goku_ops = { · 2 unmodified lines
9981027 .get_frame = goku_get_frame,
9991028 .udc_start = goku_udc_start,
10001029 .udc_stop = goku_udc_stop,
1030+ .match_ep = goku_match_ep,
10011031 // no remote wakeup
10021032 // not selfpowered
10031033 };
@@ -1257,6 +1287,14 @@ static void udc_reinit (struct goku_udc *dev) · 253 unmodified lines
12571287 INIT_LIST_HEAD (&ep->queue);
12581288
12591289 ep_reset(NULL, ep);
1290+
1291+ if (i == 0)
1292+ ep->ep.caps.type_control = true;
1293+ else
1294+ ep->ep.caps.type_bulk = true;
1295+
1296+ ep->ep.caps.dir_in = true;
1297+ ep->ep.caps.dir_out = true;
12601298 }
12611299
12621300 dev->ep[0].reg_mode = NULL;
drivers/usb/gadget/udc/gr_udc.c+11−0
@@ -2018,12 +2018,23 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit) · 2017 unmodified lines
20182018
20192019 usb_ep_set_maxpacket_limit(&ep->ep, MAX_CTRL_PL_SIZE);
20202020 ep->bytes_per_buffer = MAX_CTRL_PL_SIZE;
2021+
2022+ ep->ep.caps.type_control = true;
20212023 } else {
20222024 usb_ep_set_maxpacket_limit(&ep->ep, (u16)maxplimit);
20232025 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
2026+
2027+ ep->ep.caps.type_iso = true;
2028+ ep->ep.caps.type_bulk = true;
2029+ ep->ep.caps.type_int = true;
20242030 }
20252031 list_add_tail(&ep->ep_list, &dev->ep_list);
20262032
2033+ if (is_in)
2034+ ep->ep.caps.dir_in = true;
2035+ else
2036+ ep->ep.caps.dir_out = true;
2037+
20272038 ep->tailbuf = dma_alloc_coherent(dev->dev, ep->ep.maxpacket_limit,
20282039 &ep->tailbuf_paddr, GFP_ATOMIC);
20292040 if (!ep->tailbuf)
drivers/usb/gadget/udc/lpc32xx_udc.c+32−0
@@ -2575,6 +2575,8 @@ static const struct lpc32xx_udc controller_template = { · 2574 unmodified lines
25752575 .ep = {
25762576 .name = "ep0",
25772577 .ops = &lpc32xx_ep_ops,
2578+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL,
2579+ USB_EP_CAPS_DIR_ALL),
25782580 },
25792581 .maxpacket = 64,
25802582 .hwep_num_base = 0,
@@ -2586,6 +2588,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
25862588 .ep = {
25872589 .name = "ep1-int",
25882590 .ops = &lpc32xx_ep_ops,
2591+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_INT,
2592+ USB_EP_CAPS_DIR_ALL),
25892593 },
25902594 .maxpacket = 64,
25912595 .hwep_num_base = 2,
@@ -2597,6 +2601,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
25972601 .ep = {
25982602 .name = "ep2-bulk",
25992603 .ops = &lpc32xx_ep_ops,
2604+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
2605+ USB_EP_CAPS_DIR_ALL),
26002606 },
26012607 .maxpacket = 64,
26022608 .hwep_num_base = 4,
@@ -2608,6 +2614,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26082614 .ep = {
26092615 .name = "ep3-iso",
26102616 .ops = &lpc32xx_ep_ops,
2617+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
2618+ USB_EP_CAPS_DIR_ALL),
26112619 },
26122620 .maxpacket = 1023,
26132621 .hwep_num_base = 6,
@@ -2619,6 +2627,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26192627 .ep = {
26202628 .name = "ep4-int",
26212629 .ops = &lpc32xx_ep_ops,
2630+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_INT,
2631+ USB_EP_CAPS_DIR_ALL),
26222632 },
26232633 .maxpacket = 64,
26242634 .hwep_num_base = 8,
@@ -2630,6 +2640,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26302640 .ep = {
26312641 .name = "ep5-bulk",
26322642 .ops = &lpc32xx_ep_ops,
2643+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
2644+ USB_EP_CAPS_DIR_ALL),
26332645 },
26342646 .maxpacket = 64,
26352647 .hwep_num_base = 10,
@@ -2641,6 +2653,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26412653 .ep = {
26422654 .name = "ep6-iso",
26432655 .ops = &lpc32xx_ep_ops,
2656+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
2657+ USB_EP_CAPS_DIR_ALL),
26442658 },
26452659 .maxpacket = 1023,
26462660 .hwep_num_base = 12,
@@ -2652,6 +2666,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26522666 .ep = {
26532667 .name = "ep7-int",
26542668 .ops = &lpc32xx_ep_ops,
2669+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_INT,
2670+ USB_EP_CAPS_DIR_ALL),
26552671 },
26562672 .maxpacket = 64,
26572673 .hwep_num_base = 14,
@@ -2663,6 +2679,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26632679 .ep = {
26642680 .name = "ep8-bulk",
26652681 .ops = &lpc32xx_ep_ops,
2682+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
2683+ USB_EP_CAPS_DIR_ALL),
26662684 },
26672685 .maxpacket = 64,
26682686 .hwep_num_base = 16,
@@ -2674,6 +2692,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26742692 .ep = {
26752693 .name = "ep9-iso",
26762694 .ops = &lpc32xx_ep_ops,
2695+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
2696+ USB_EP_CAPS_DIR_ALL),
26772697 },
26782698 .maxpacket = 1023,
26792699 .hwep_num_base = 18,
@@ -2685,6 +2705,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26852705 .ep = {
26862706 .name = "ep10-int",
26872707 .ops = &lpc32xx_ep_ops,
2708+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_INT,
2709+ USB_EP_CAPS_DIR_ALL),
26882710 },
26892711 .maxpacket = 64,
26902712 .hwep_num_base = 20,
@@ -2696,6 +2718,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
26962718 .ep = {
26972719 .name = "ep11-bulk",
26982720 .ops = &lpc32xx_ep_ops,
2721+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
2722+ USB_EP_CAPS_DIR_ALL),
26992723 },
27002724 .maxpacket = 64,
27012725 .hwep_num_base = 22,
@@ -2707,6 +2731,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
27072731 .ep = {
27082732 .name = "ep12-iso",
27092733 .ops = &lpc32xx_ep_ops,
2734+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
2735+ USB_EP_CAPS_DIR_ALL),
27102736 },
27112737 .maxpacket = 1023,
27122738 .hwep_num_base = 24,
@@ -2718,6 +2744,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
27182744 .ep = {
27192745 .name = "ep13-int",
27202746 .ops = &lpc32xx_ep_ops,
2747+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_INT,
2748+ USB_EP_CAPS_DIR_ALL),
27212749 },
27222750 .maxpacket = 64,
27232751 .hwep_num_base = 26,
@@ -2729,6 +2757,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
27292757 .ep = {
27302758 .name = "ep14-bulk",
27312759 .ops = &lpc32xx_ep_ops,
2760+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
2761+ USB_EP_CAPS_DIR_ALL),
27322762 },
27332763 .maxpacket = 64,
27342764 .hwep_num_base = 28,
@@ -2740,6 +2770,8 @@ static const struct lpc32xx_udc controller_template = { · 5 unmodified lines
27402770 .ep = {
27412771 .name = "ep15-bulk",
27422772 .ops = &lpc32xx_ep_ops,
2773+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
2774+ USB_EP_CAPS_DIR_ALL),
27432775 },
27442776 .maxpacket = 1023,
27452777 .hwep_num_base = 30,
drivers/usb/gadget/udc/m66592-udc.c+12−1
@@ -1052,7 +1052,7 @@ static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) · 1051 unmodified lines
10521052 tmp = m66592_read(m66592, M66592_INTSTS0) &
10531053 M66592_CTSQ;
10541054 udelay(1);
1055− } while (tmp != M66592_CS_IDST || timeout-- > 0);
1055+ } while (tmp != M66592_CS_IDST && timeout-- > 0);
10561056
10571057 if (tmp == M66592_CS_IDST)
10581058 m66592_bset(m66592,
@@ -1644,6 +1644,17 @@ static int m66592_probe(struct platform_device *pdev) · 585 unmodified lines
16441644 ep->ep.name = m66592_ep_name[i];
16451645 ep->ep.ops = &m66592_ep_ops;
16461646 usb_ep_set_maxpacket_limit(&ep->ep, 512);
1647+
1648+ if (i == 0) {
1649+ ep->ep.caps.type_control = true;
1650+ } else {
1651+ ep->ep.caps.type_iso = true;
1652+ ep->ep.caps.type_bulk = true;
1653+ ep->ep.caps.type_int = true;
1654+ }
1655+
1656+ ep->ep.caps.dir_in = true;
1657+ ep->ep.caps.dir_out = true;
16471658 }
16481659 usb_ep_set_maxpacket_limit(&m66592->ep[0].ep, 64);
16491660 m66592->ep[0].pipenum = 0;
drivers/usb/gadget/udc/mv_u3d_core.c+9−0
@@ -1324,6 +1324,9 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d) · 1323 unmodified lines
13241324 ep->ep.ops = &mv_u3d_ep_ops;
13251325 ep->wedge = 0;
13261326 usb_ep_set_maxpacket_limit(&ep->ep, MV_U3D_EP0_MAX_PKT_SIZE);
1327+ ep->ep.caps.type_control = true;
1328+ ep->ep.caps.dir_in = true;
1329+ ep->ep.caps.dir_out = true;
13271330 ep->ep_num = 0;
13281331 ep->ep.desc = &mv_u3d_ep0_desc;
13291332 INIT_LIST_HEAD(&ep->queue);
@@ -1339,14 +1342,20 @@ static int mv_u3d_eps_init(struct mv_u3d *u3d) · 9 unmodified lines
13391342 if (i & 1) {
13401343 snprintf(name, sizeof(name), "ep%din", i >> 1);
13411344 ep->direction = MV_U3D_EP_DIR_IN;
1345+ ep->ep.caps.dir_in = true;
13421346 } else {
13431347 snprintf(name, sizeof(name), "ep%dout", i >> 1);
13441348 ep->direction = MV_U3D_EP_DIR_OUT;
1349+ ep->ep.caps.dir_out = true;
13451350 }
13461351 ep->u3d = u3d;
13471352 strncpy(ep->name, name, sizeof(ep->name));
13481353 ep->ep.name = ep->name;
13491354
1355+ ep->ep.caps.type_iso = true;
1356+ ep->ep.caps.type_bulk = true;
1357+ ep->ep.caps.type_int = true;
1358+
13501359 ep->ep.ops = &mv_u3d_ep_ops;
13511360 usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0);
13521361 ep->ep_num = i / 2;
drivers/usb/gadget/udc/mv_udc_core.c+9−0
@@ -1257,6 +1257,9 @@ static int eps_init(struct mv_udc *udc) · 1256 unmodified lines
12571257 ep->wedge = 0;
12581258 ep->stopped = 0;
12591259 usb_ep_set_maxpacket_limit(&ep->ep, EP0_MAX_PKT_SIZE);
1260+ ep->ep.caps.type_control = true;
1261+ ep->ep.caps.dir_in = true;
1262+ ep->ep.caps.dir_out = true;
12601263 ep->ep_num = 0;
12611264 ep->ep.desc = &mv_ep0_desc;
12621265 INIT_LIST_HEAD(&ep->queue);
@@ -1269,14 +1272,20 @@ static int eps_init(struct mv_udc *udc) · 6 unmodified lines
12691272 if (i % 2) {
12701273 snprintf(name, sizeof(name), "ep%din", i / 2);
12711274 ep->direction = EP_DIR_IN;
1275+ ep->ep.caps.dir_in = true;
12721276 } else {
12731277 snprintf(name, sizeof(name), "ep%dout", i / 2);
12741278 ep->direction = EP_DIR_OUT;
1279+ ep->ep.caps.dir_out = true;
12751280 }
12761281 ep->udc = udc;
12771282 strncpy(ep->name, name, sizeof(ep->name));
12781283 ep->ep.name = ep->name;
12791284
1285+ ep->ep.caps.type_iso = true;
1286+ ep->ep.caps.type_bulk = true;
1287+ ep->ep.caps.type_int = true;
1288+
12801289 ep->ep.ops = &mv_ep_ops;
12811290 ep->stopped = 0;
12821291 usb_ep_set_maxpacket_limit(&ep->ep, (unsigned short) ~0);
drivers/usb/gadget/udc/net2272.c+13−2
@@ -1404,6 +1404,17 @@ net2272_usb_reinit(struct net2272 *dev) · 1403 unmodified lines
14041404 else
14051405 ep->fifo_size = 64;
14061406 net2272_ep_reset(ep);
1407+
1408+ if (i == 0) {
1409+ ep->ep.caps.type_control = true;
1410+ } else {
1411+ ep->ep.caps.type_iso = true;
1412+ ep->ep.caps.type_bulk = true;
1413+ ep->ep.caps.type_int = true;
1414+ }
1415+
1416+ ep->ep.caps.dir_in = true;
1417+ ep->ep.caps.dir_out = true;
14071418 }
14081419 usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64);
14091420
@@ -1826,9 +1837,9 @@ net2272_handle_stat0_irqs(struct net2272 *dev, u8 stat) · 416 unmodified lines
18261837 if (!e || u.r.wLength > 2)
18271838 goto do_stall;
18281839 if (net2272_ep_read(e, EP_RSPSET) & (1 << ENDPOINT_HALT))
1829− status = __constant_cpu_to_le16(1);
1840+ status = cpu_to_le16(1);
18301841 else
1831− status = __constant_cpu_to_le16(0);
1842+ status = cpu_to_le16(0);
18321843
18331844 /* don't bother with a request object! */
18341845 net2272_ep_write(&dev->ep[0], EP_IRQENB, 0);
drivers/usb/gadget/udc/net2280.c+83−12
@@ -74,19 +74,58 @@ static const char driver_desc[] = DRIVER_DESC; · 73 unmodified lines
7474
7575 static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };
7676 static const char ep0name[] = "ep0";
77−static const char *const ep_name[] = {
78− ep0name,
79− "ep-a", "ep-b", "ep-c", "ep-d",
80− "ep-e", "ep-f", "ep-g", "ep-h",
81−};
8277
83−/* Endpoint names for usb3380 advance mode */
84−static const char *const ep_name_adv[] = {
85− ep0name,
86− "ep1in", "ep2out", "ep3in", "ep4out",
87− "ep1out", "ep2in", "ep3out", "ep4in",
78+#define EP_INFO(_name, _caps) \
79+ { \
80+ .name = _name, \
81+ .caps = _caps, \
82+ }
83+
84+static const struct {
85+ const char *name;
86+ const struct usb_ep_caps caps;
87+} ep_info_dft[] = { /* Default endpoint configuration */
88+ EP_INFO(ep0name,
89+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
90+ EP_INFO("ep-a",
91+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
92+ EP_INFO("ep-b",
93+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
94+ EP_INFO("ep-c",
95+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
96+ EP_INFO("ep-d",
97+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
98+ EP_INFO("ep-e",
99+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
100+ EP_INFO("ep-f",
101+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
102+ EP_INFO("ep-g",
103+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
104+ EP_INFO("ep-h",
105+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_ALL)),
106+}, ep_info_adv[] = { /* Endpoints for usb3380 advance mode */
107+ EP_INFO(ep0name,
108+ USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)),
109+ EP_INFO("ep1in",
110+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
111+ EP_INFO("ep2out",
112+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
113+ EP_INFO("ep3in",
114+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
115+ EP_INFO("ep4out",
116+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
117+ EP_INFO("ep1out",
118+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
119+ EP_INFO("ep2in",
120+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
121+ EP_INFO("ep3out",
122+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_OUT)),
123+ EP_INFO("ep4in",
124+ USB_EP_CAPS(USB_EP_CAPS_TYPE_ALL, USB_EP_CAPS_DIR_IN)),
88125 };
89126
127+#undef EP_INFO
128+
90129 /* mode 0 == ep-{a,b,c,d} 1K fifo each
91130 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
92131 * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
@@ -1511,6 +1550,33 @@ static int net2280_pullup(struct usb_gadget *_gadget, int is_on) · 1418 unmodified lines
15111550 return 0;
15121551 }
15131552
1553+static struct usb_ep *net2280_match_ep(struct usb_gadget *_gadget,
1554+ struct usb_endpoint_descriptor *desc,
1555+ struct usb_ss_ep_comp_descriptor *ep_comp)
1556+{
1557+ char name[8];
1558+ struct usb_ep *ep;
1559+
1560+ if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT) {
1561+ /* ep-e, ep-f are PIO with only 64 byte fifos */
1562+ ep = gadget_find_ep_by_name(_gadget, "ep-e");
1563+ if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1564+ return ep;
1565+ ep = gadget_find_ep_by_name(_gadget, "ep-f");
1566+ if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1567+ return ep;
1568+ }
1569+
1570+ /* USB3380: use same address for usb and hardware endpoints */
1571+ snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
1572+ usb_endpoint_dir_in(desc) ? "in" : "out");
1573+ ep = gadget_find_ep_by_name(_gadget, name);
1574+ if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
1575+ return ep;
1576+
1577+ return NULL;
1578+}
1579+
15141580 static int net2280_start(struct usb_gadget *_gadget,
15151581 struct usb_gadget_driver *driver);
15161582 static int net2280_stop(struct usb_gadget *_gadget);
@@ -1522,6 +1588,7 @@ static const struct usb_gadget_ops net2280_ops = { · 5 unmodified lines
15221588 .pullup = net2280_pullup,
15231589 .udc_start = net2280_start,
15241590 .udc_stop = net2280_stop,
1591+ .match_ep = net2280_match_ep,
15251592 };
15261593
15271594 /*-------------------------------------------------------------------------*/
@@ -2055,7 +2122,8 @@ static void usb_reinit_228x(struct net2280 *dev) · 527 unmodified lines
20552122 for (tmp = 0; tmp < 7; tmp++) {
20562123 struct net2280_ep *ep = &dev->ep[tmp];
20572124
2058− ep->ep.name = ep_name[tmp];
2125+ ep->ep.name = ep_info_dft[tmp].name;
2126+ ep->ep.caps = ep_info_dft[tmp].caps;
20592127 ep->dev = dev;
20602128 ep->num = tmp;
20612129
@@ -2095,7 +2163,10 @@ static void usb_reinit_338x(struct net2280 *dev) · 33 unmodified lines
20952163 for (i = 0; i < dev->n_ep; i++) {
20962164 struct net2280_ep *ep = &dev->ep[i];
20972165
2098− ep->ep.name = dev->enhanced_mode ? ep_name_adv[i] : ep_name[i];
2166+ ep->ep.name = dev->enhanced_mode ? ep_info_adv[i].name :
2167+ ep_info_dft[i].name;
2168+ ep->ep.caps = dev->enhanced_mode ? ep_info_adv[i].caps :
2169+ ep_info_dft[i].caps;
20992170 ep->dev = dev;
21002171 ep->num = i;
21012172
drivers/usb/gadget/udc/omap_udc.c+22−0
@@ -2579,6 +2579,28 @@ omap_ep_setup(char *name, u8 addr, u8 type, · 2578 unmodified lines
25792579 ep->double_buf = dbuf;
25802580 ep->udc = udc;
25812581
2582+ switch (type) {
2583+ case USB_ENDPOINT_XFER_CONTROL:
2584+ ep->ep.caps.type_control = true;
2585+ ep->ep.caps.dir_in = true;
2586+ ep->ep.caps.dir_out = true;
2587+ break;
2588+ case USB_ENDPOINT_XFER_ISOC:
2589+ ep->ep.caps.type_iso = true;
2590+ break;
2591+ case USB_ENDPOINT_XFER_BULK:
2592+ ep->ep.caps.type_bulk = true;
2593+ break;
2594+ case USB_ENDPOINT_XFER_INT:
2595+ ep->ep.caps.type_int = true;
2596+ break;
2597+ };
2598+
2599+ if (addr & USB_DIR_IN)
2600+ ep->ep.caps.dir_in = true;
2601+ else
2602+ ep->ep.caps.dir_out = true;
2603+
25822604 ep->ep.name = ep->name;
25832605 ep->ep.ops = &omap_ep_ops;
25842606 ep->maxpacket = maxp;
drivers/usb/gadget/udc/pch_udc.c+31−21
@@ -620,9 +620,9 @@ static inline void pch_udc_vbus_session(struct pch_udc_dev *dev, · 619 unmodified lines
620620 dev->vbus_session = 1;
621621 } else {
622622 if (dev->driver && dev->driver->disconnect) {
623− spin_unlock(&dev->lock);
624− dev->driver->disconnect(&dev->gadget);
625623 spin_lock(&dev->lock);
624+ dev->driver->disconnect(&dev->gadget);
625+ spin_unlock(&dev->lock);
626626 }
627627 pch_udc_set_disconnect(dev);
628628 dev->vbus_session = 0;
@@ -1191,9 +1191,9 @@ static int pch_udc_pcd_pullup(struct usb_gadget *gadget, int is_on) · 562 unmodified lines
11911191 pch_udc_reconnect(dev);
11921192 } else {
11931193 if (dev->driver && dev->driver->disconnect) {
1194− spin_unlock(&dev->lock);
1195− dev->driver->disconnect(&dev->gadget);
11961194 spin_lock(&dev->lock);
1195+ dev->driver->disconnect(&dev->gadget);
1196+ spin_unlock(&dev->lock);
11971197 }
11981198 pch_udc_set_disconnect(dev);
11991199 }
@@ -1488,11 +1488,11 @@ static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, · 288 unmodified lines
14881488 req->dma_mapped = 0;
14891489 }
14901490 ep->halted = 1;
1491− spin_unlock(&dev->lock);
1491+ spin_lock(&dev->lock);
14921492 if (!ep->in)
14931493 pch_udc_ep_clear_rrdy(ep);
14941494 usb_gadget_giveback_request(&ep->ep, &req->req);
1495− spin_lock(&dev->lock);
1495+ spin_unlock(&dev->lock);
14961496 ep->halted = halted;
14971497 }
14981498
@@ -1793,7 +1793,7 @@ static struct usb_request *pch_udc_alloc_request(struct usb_ep *usbep, · 294 unmodified lines
17931793 }
17941794 /* prevent from using desc. - set HOST BUSY */
17951795 dma_desc->status |= PCH_UDC_BS_HST_BSY;
1796− dma_desc->dataptr = __constant_cpu_to_le32(DMA_ADDR_INVALID);
1796+ dma_desc->dataptr = cpu_to_le32(DMA_ADDR_INVALID);
17971797 req->td_data = dma_desc;
17981798 req->td_data_last = dma_desc;
17991799 req->chain_len = 1;
@@ -2414,7 +2414,7 @@ static void pch_udc_svc_control_out(struct pch_udc_dev *dev) · 614 unmodified lines
24142414 dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IDX].ep;
24152415 else /* OUT */
24162416 dev->gadget.ep0 = &ep->ep;
2417− spin_unlock(&dev->lock);
2417+ spin_lock(&dev->lock);
24182418 /* If Mass storage Reset */
24192419 if ((dev->setup_data.bRequestType == 0x21) &&
24202420 (dev->setup_data.bRequest == 0xFF))
@@ -2422,7 +2422,7 @@ static void pch_udc_svc_control_out(struct pch_udc_dev *dev) · 1 unmodified line
24222422 /* call gadget with setup data received */
24232423 setup_supported = dev->driver->setup(&dev->gadget,
24242424 &dev->setup_data);
2425− spin_lock(&dev->lock);
2425+ spin_unlock(&dev->lock);
24262426
24272427 if (dev->setup_data.bRequestType & USB_DIR_IN) {
24282428 ep->td_data->status = (ep->td_data->status &
@@ -2594,9 +2594,9 @@ static void pch_udc_svc_ur_interrupt(struct pch_udc_dev *dev) · 165 unmodified lines
25942594 empty_req_queue(ep);
25952595 }
25962596 if (dev->driver) {
2597− spin_unlock(&dev->lock);
2598− usb_gadget_udc_reset(&dev->gadget, dev->driver);
25992597 spin_lock(&dev->lock);
2598+ usb_gadget_udc_reset(&dev->gadget, dev->driver);
2599+ spin_unlock(&dev->lock);
26002600 }
26012601 }
26022602
@@ -2675,9 +2675,9 @@ static void pch_udc_svc_intf_interrupt(struct pch_udc_dev *dev) · 72 unmodified lines
26752675 dev->ep[i].halted = 0;
26762676 }
26772677 dev->stall = 0;
2678− spin_unlock(&dev->lock);
2679− ret = dev->driver->setup(&dev->gadget, &dev->setup_data);
26802678 spin_lock(&dev->lock);
2679+ ret = dev->driver->setup(&dev->gadget, &dev->setup_data);
2680+ spin_unlock(&dev->lock);
26812681 }
26822682
26832683 /**
@@ -2712,9 +2712,9 @@ static void pch_udc_svc_cfg_interrupt(struct pch_udc_dev *dev) · 28 unmodified lines
27122712 dev->stall = 0;
27132713
27142714 /* call gadget zero with setup data received */
2715− spin_unlock(&dev->lock);
2716− ret = dev->driver->setup(&dev->gadget, &dev->setup_data);
27172715 spin_lock(&dev->lock);
2716+ ret = dev->driver->setup(&dev->gadget, &dev->setup_data);
2717+ spin_unlock(&dev->lock);
27182718 }
27192719
27202720 /**
@@ -2747,18 +2747,18 @@ static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr) · 26 unmodified lines
27472747 if (dev_intr & UDC_DEVINT_US) {
27482748 if (dev->driver
27492749 && dev->driver->suspend) {
2750− spin_unlock(&dev->lock);
2751− dev->driver->suspend(&dev->gadget);
27522750 spin_lock(&dev->lock);
2751+ dev->driver->suspend(&dev->gadget);
2752+ spin_unlock(&dev->lock);
27532753 }
27542754
27552755 vbus = pch_vbus_gpio_get_value(dev);
27562756 if ((dev->vbus_session == 0)
27572757 && (vbus != 1)) {
27582758 if (dev->driver && dev->driver->disconnect) {
2759− spin_unlock(&dev->lock);
2760− dev->driver->disconnect(&dev->gadget);
27612759 spin_lock(&dev->lock);
2760+ dev->driver->disconnect(&dev->gadget);
2761+ spin_unlock(&dev->lock);
27622762 }
27632763 pch_udc_reconnect(dev);
27642764 } else if ((dev->vbus_session == 0)
@@ -2895,11 +2895,21 @@ static void pch_udc_pcd_reinit(struct pch_udc_dev *dev) · 130 unmodified lines
28952895 ep->in = ~i & 1;
28962896 ep->ep.name = ep_string[i];
28972897 ep->ep.ops = &pch_udc_ep_ops;
2898− if (ep->in)
2898+ if (ep->in) {
28992899 ep->offset_addr = ep->num * UDC_EP_REG_SHIFT;
2900− else
2900+ ep->ep.caps.dir_in = true;
2901+ } else {
29012902 ep->offset_addr = (UDC_EPINT_OUT_SHIFT + ep->num) *
29022903 UDC_EP_REG_SHIFT;
2904+ ep->ep.caps.dir_out = true;
2905+ }
2906+ if (i == UDC_EP0IN_IDX || i == UDC_EP0OUT_IDX) {
2907+ ep->ep.caps.type_control = true;
2908+ } else {
2909+ ep->ep.caps.type_iso = true;
2910+ ep->ep.caps.type_bulk = true;
2911+ ep->ep.caps.type_int = true;
2912+ }
29032913 /* need to set ep->ep.maxpacket and set Default Configuration?*/
29042914 usb_ep_set_maxpacket_limit(&ep->ep, UDC_BULK_MAX_PKT_SIZE);
29052915 list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list);
drivers/usb/gadget/udc/pxa25x_udc.c+30−0
@@ -1176,6 +1176,7 @@ static void udc_reinit(struct pxa25x_udc *dev) · 1175 unmodified lines
11761176 INIT_LIST_HEAD (&dev->gadget.ep_list);
11771177 INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
11781178 dev->ep0state = EP0_IDLE;
1179+ dev->gadget.quirk_altset_not_supp = 1;
11791180
11801181 /* basic endpoint records init */
11811182 for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
@@ -1821,6 +1822,8 @@ static struct pxa25x_udc memory = { · 639 unmodified lines
18211822 .name = ep0name,
18221823 .ops = &pxa25x_ep_ops,
18231824 .maxpacket = EP0_FIFO_SIZE,
1825+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL,
1826+ USB_EP_CAPS_DIR_ALL),
18241827 },
18251828 .dev = &memory,
18261829 .reg_udccs = &UDCCS0,
@@ -1833,6 +1836,8 @@ static struct pxa25x_udc memory = { · 6 unmodified lines
18331836 .name = "ep1in-bulk",
18341837 .ops = &pxa25x_ep_ops,
18351838 .maxpacket = BULK_FIFO_SIZE,
1839+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1840+ USB_EP_CAPS_DIR_IN),
18361841 },
18371842 .dev = &memory,
18381843 .fifo_size = BULK_FIFO_SIZE,
@@ -1846,6 +1851,8 @@ static struct pxa25x_udc memory = { · 7 unmodified lines
18461851 .name = "ep2out-bulk",
18471852 .ops = &pxa25x_ep_ops,
18481853 .maxpacket = BULK_FIFO_SIZE,
1854+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1855+ USB_EP_CAPS_DIR_OUT),
18491856 },
18501857 .dev = &memory,
18511858 .fifo_size = BULK_FIFO_SIZE,
@@ -1861,6 +1868,8 @@ static struct pxa25x_udc memory = { · 9 unmodified lines
18611868 .name = "ep3in-iso",
18621869 .ops = &pxa25x_ep_ops,
18631870 .maxpacket = ISO_FIFO_SIZE,
1871+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
1872+ USB_EP_CAPS_DIR_IN),
18641873 },
18651874 .dev = &memory,
18661875 .fifo_size = ISO_FIFO_SIZE,
@@ -1874,6 +1883,8 @@ static struct pxa25x_udc memory = { · 7 unmodified lines
18741883 .name = "ep4out-iso",
18751884 .ops = &pxa25x_ep_ops,
18761885 .maxpacket = ISO_FIFO_SIZE,
1886+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
1887+ USB_EP_CAPS_DIR_OUT),
18771888 },
18781889 .dev = &memory,
18791890 .fifo_size = ISO_FIFO_SIZE,
@@ -1888,6 +1899,7 @@ static struct pxa25x_udc memory = { · 8 unmodified lines
18881899 .name = "ep5in-int",
18891900 .ops = &pxa25x_ep_ops,
18901901 .maxpacket = INT_FIFO_SIZE,
1902+ .caps = USB_EP_CAPS(0, 0),
18911903 },
18921904 .dev = &memory,
18931905 .fifo_size = INT_FIFO_SIZE,
@@ -1903,6 +1915,8 @@ static struct pxa25x_udc memory = { · 9 unmodified lines
19031915 .name = "ep6in-bulk",
19041916 .ops = &pxa25x_ep_ops,
19051917 .maxpacket = BULK_FIFO_SIZE,
1918+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1919+ USB_EP_CAPS_DIR_IN),
19061920 },
19071921 .dev = &memory,
19081922 .fifo_size = BULK_FIFO_SIZE,
@@ -1916,6 +1930,8 @@ static struct pxa25x_udc memory = { · 7 unmodified lines
19161930 .name = "ep7out-bulk",
19171931 .ops = &pxa25x_ep_ops,
19181932 .maxpacket = BULK_FIFO_SIZE,
1933+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1934+ USB_EP_CAPS_DIR_OUT),
19191935 },
19201936 .dev = &memory,
19211937 .fifo_size = BULK_FIFO_SIZE,
@@ -1930,6 +1946,8 @@ static struct pxa25x_udc memory = { · 8 unmodified lines
19301946 .name = "ep8in-iso",
19311947 .ops = &pxa25x_ep_ops,
19321948 .maxpacket = ISO_FIFO_SIZE,
1949+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
1950+ USB_EP_CAPS_DIR_IN),
19331951 },
19341952 .dev = &memory,
19351953 .fifo_size = ISO_FIFO_SIZE,
@@ -1943,6 +1961,8 @@ static struct pxa25x_udc memory = { · 7 unmodified lines
19431961 .name = "ep9out-iso",
19441962 .ops = &pxa25x_ep_ops,
19451963 .maxpacket = ISO_FIFO_SIZE,
1964+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
1965+ USB_EP_CAPS_DIR_OUT),
19461966 },
19471967 .dev = &memory,
19481968 .fifo_size = ISO_FIFO_SIZE,
@@ -1957,6 +1977,7 @@ static struct pxa25x_udc memory = { · 8 unmodified lines
19571977 .name = "ep10in-int",
19581978 .ops = &pxa25x_ep_ops,
19591979 .maxpacket = INT_FIFO_SIZE,
1980+ .caps = USB_EP_CAPS(0, 0),
19601981 },
19611982 .dev = &memory,
19621983 .fifo_size = INT_FIFO_SIZE,
@@ -1972,6 +1993,8 @@ static struct pxa25x_udc memory = { · 9 unmodified lines
19721993 .name = "ep11in-bulk",
19731994 .ops = &pxa25x_ep_ops,
19741995 .maxpacket = BULK_FIFO_SIZE,
1996+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1997+ USB_EP_CAPS_DIR_IN),
19751998 },
19761999 .dev = &memory,
19772000 .fifo_size = BULK_FIFO_SIZE,
@@ -1985,6 +2008,8 @@ static struct pxa25x_udc memory = { · 7 unmodified lines
19852008 .name = "ep12out-bulk",
19862009 .ops = &pxa25x_ep_ops,
19872010 .maxpacket = BULK_FIFO_SIZE,
2011+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
2012+ USB_EP_CAPS_DIR_OUT),
19882013 },
19892014 .dev = &memory,
19902015 .fifo_size = BULK_FIFO_SIZE,
@@ -1999,6 +2024,8 @@ static struct pxa25x_udc memory = { · 8 unmodified lines
19992024 .name = "ep13in-iso",
20002025 .ops = &pxa25x_ep_ops,
20012026 .maxpacket = ISO_FIFO_SIZE,
2027+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
2028+ USB_EP_CAPS_DIR_IN),
20022029 },
20032030 .dev = &memory,
20042031 .fifo_size = ISO_FIFO_SIZE,
@@ -2012,6 +2039,8 @@ static struct pxa25x_udc memory = { · 7 unmodified lines
20122039 .name = "ep14out-iso",
20132040 .ops = &pxa25x_ep_ops,
20142041 .maxpacket = ISO_FIFO_SIZE,
2042+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_ISO,
2043+ USB_EP_CAPS_DIR_OUT),
20152044 },
20162045 .dev = &memory,
20172046 .fifo_size = ISO_FIFO_SIZE,
@@ -2026,6 +2055,7 @@ static struct pxa25x_udc memory = { · 8 unmodified lines
20262055 .name = "ep15in-int",
20272056 .ops = &pxa25x_ep_ops,
20282057 .maxpacket = INT_FIFO_SIZE,
2058+ .caps = USB_EP_CAPS(0, 0),
20292059 },
20302060 .dev = &memory,
20312061 .fifo_size = INT_FIFO_SIZE,
drivers/usb/gadget/udc/pxa27x_udc.c+2−1
@@ -1710,6 +1710,7 @@ static void udc_init_data(struct pxa_udc *dev) · 1709 unmodified lines
17101710 INIT_LIST_HEAD(&dev->gadget.ep_list);
17111711 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
17121712 dev->udc_usb_ep[0].pxa_ep = &dev->pxa_ep[0];
1713+ dev->gadget.quirk_altset_not_supp = 1;
17131714 ep0_idle(dev);
17141715
17151716 /* PXA endpoints init */
@@ -2422,7 +2423,7 @@ static int pxa_udc_probe(struct platform_device *pdev) · 706 unmodified lines
24222423 }
24232424 udc->udc_command = mach->udc_command;
24242425 } else {
2425− udc->gpiod = devm_gpiod_get(&pdev->dev, NULL);
2426+ udc->gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_ASIS);
24262427 }
24272428
24282429 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/usb/gadget/udc/pxa27x_udc.h+25−15
@@ -234,25 +234,35 @@ · 233 unmodified lines
234234 /*
235235 * Endpoint definition helpers
236236 */
237−#define USB_EP_DEF(addr, bname, dir, type, maxpkt) \
238−{ .usb_ep = { .name = bname, .ops = &pxa_ep_ops, .maxpacket = maxpkt, }, \
237+#define USB_EP_DEF(addr, bname, dir, type, maxpkt, ctype, cdir) \
238+{ .usb_ep = { .name = bname, .ops = &pxa_ep_ops, .maxpacket = maxpkt, \
239+ .caps = USB_EP_CAPS(ctype, cdir), }, \
239240 .desc = { .bEndpointAddress = addr | (dir ? USB_DIR_IN : 0), \
240− .bmAttributes = type, \
241+ .bmAttributes = USB_ENDPOINT_XFER_ ## type, \
241242 .wMaxPacketSize = maxpkt, }, \
242243 .dev = &memory \
243244 }
244−#define USB_EP_BULK(addr, bname, dir) \
245− USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_BULK, BULK_FIFO_SIZE)
246−#define USB_EP_ISO(addr, bname, dir) \
247− USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_ISOC, ISO_FIFO_SIZE)
248−#define USB_EP_INT(addr, bname, dir) \
249− USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_INT, INT_FIFO_SIZE)
250−#define USB_EP_IN_BULK(n) USB_EP_BULK(n, "ep" #n "in-bulk", 1)
251−#define USB_EP_OUT_BULK(n) USB_EP_BULK(n, "ep" #n "out-bulk", 0)
252−#define USB_EP_IN_ISO(n) USB_EP_ISO(n, "ep" #n "in-iso", 1)
253−#define USB_EP_OUT_ISO(n) USB_EP_ISO(n, "ep" #n "out-iso", 0)
254−#define USB_EP_IN_INT(n) USB_EP_INT(n, "ep" #n "in-int", 1)
255−#define USB_EP_CTRL USB_EP_DEF(0, "ep0", 0, 0, EP0_FIFO_SIZE)
245+#define USB_EP_BULK(addr, bname, dir, cdir) \
246+ USB_EP_DEF(addr, bname, dir, BULK, BULK_FIFO_SIZE, \
247+ USB_EP_CAPS_TYPE_BULK, cdir)
248+#define USB_EP_ISO(addr, bname, dir, cdir) \
249+ USB_EP_DEF(addr, bname, dir, ISOC, ISO_FIFO_SIZE, \
250+ USB_EP_CAPS_TYPE_ISO, cdir)
251+#define USB_EP_INT(addr, bname, dir, cdir) \
252+ USB_EP_DEF(addr, bname, dir, INT, INT_FIFO_SIZE, \
253+ USB_EP_CAPS_TYPE_INT, cdir)
254+#define USB_EP_IN_BULK(n) USB_EP_BULK(n, "ep" #n "in-bulk", 1, \
255+ USB_EP_CAPS_DIR_IN)
256+#define USB_EP_OUT_BULK(n) USB_EP_BULK(n, "ep" #n "out-bulk", 0, \
257+ USB_EP_CAPS_DIR_OUT)
258+#define USB_EP_IN_ISO(n) USB_EP_ISO(n, "ep" #n "in-iso", 1, \
259+ USB_EP_CAPS_DIR_IN)
260+#define USB_EP_OUT_ISO(n) USB_EP_ISO(n, "ep" #n "out-iso", 0, \
261+ USB_EP_CAPS_DIR_OUT)
262+#define USB_EP_IN_INT(n) USB_EP_INT(n, "ep" #n "in-int", 1, \
263+ USB_EP_CAPS_DIR_IN)
264+#define USB_EP_CTRL USB_EP_DEF(0, "ep0", 0, CONTROL, EP0_FIFO_SIZE, \
265+ USB_EP_CAPS_TYPE_CONTROL, USB_EP_CAPS_DIR_ALL)
256266
257267 #define PXA_EP_DEF(_idx, _addr, dir, _type, maxpkt, _config, iface, altset) \
258268 { \
drivers/usb/gadget/udc/r8a66597-udc.c+10−0
@@ -1935,6 +1935,16 @@ static int r8a66597_probe(struct platform_device *pdev) · 1934 unmodified lines
19351935 ep->ep.name = r8a66597_ep_name[i];
19361936 ep->ep.ops = &r8a66597_ep_ops;
19371937 usb_ep_set_maxpacket_limit(&ep->ep, 512);
1938+
1939+ if (i == 0) {
1940+ ep->ep.caps.type_control = true;
1941+ } else {
1942+ ep->ep.caps.type_iso = true;
1943+ ep->ep.caps.type_bulk = true;
1944+ ep->ep.caps.type_int = true;
1945+ }
1946+ ep->ep.caps.dir_in = true;
1947+ ep->ep.caps.dir_out = true;
19381948 }
19391949 usb_ep_set_maxpacket_limit(&r8a66597->ep[0].ep, 64);
19401950 r8a66597->ep[0].pipenum = 0;
drivers/usb/gadget/udc/s3c-hsudc.c+15−0
@@ -1005,6 +1005,21 @@ static void s3c_hsudc_initep(struct s3c_hsudc *hsudc, · 1004 unmodified lines
10051005 hsep->stopped = 0;
10061006 hsep->wedge = 0;
10071007
1008+ if (epnum == 0) {
1009+ hsep->ep.caps.type_control = true;
1010+ hsep->ep.caps.dir_in = true;
1011+ hsep->ep.caps.dir_out = true;
1012+ } else {
1013+ hsep->ep.caps.type_iso = true;
1014+ hsep->ep.caps.type_bulk = true;
1015+ hsep->ep.caps.type_int = true;
1016+ }
1017+
1018+ if (epnum & 1)
1019+ hsep->ep.caps.dir_in = true;
1020+ else
1021+ hsep->ep.caps.dir_out = true;
1022+
10081023 set_index(hsudc, epnum);
10091024 writel(hsep->ep.maxpacket, hsudc->regs + S3C_MPR);
10101025 }
drivers/usb/gadget/udc/s3c2410_udc.c+10−0
@@ -1691,6 +1691,8 @@ static struct s3c2410_udc memory = { · 1690 unmodified lines
16911691 .name = ep0name,
16921692 .ops = &s3c2410_ep_ops,
16931693 .maxpacket = EP0_FIFO_SIZE,
1694+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_CONTROL,
1695+ USB_EP_CAPS_DIR_ALL),
16941696 },
16951697 .dev = &memory,
16961698 },
@@ -1702,6 +1704,8 @@ static struct s3c2410_udc memory = { · 5 unmodified lines
17021704 .name = "ep1-bulk",
17031705 .ops = &s3c2410_ep_ops,
17041706 .maxpacket = EP_FIFO_SIZE,
1707+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1708+ USB_EP_CAPS_DIR_ALL),
17051709 },
17061710 .dev = &memory,
17071711 .fifo_size = EP_FIFO_SIZE,
@@ -1714,6 +1718,8 @@ static struct s3c2410_udc memory = { · 6 unmodified lines
17141718 .name = "ep2-bulk",
17151719 .ops = &s3c2410_ep_ops,
17161720 .maxpacket = EP_FIFO_SIZE,
1721+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1722+ USB_EP_CAPS_DIR_ALL),
17171723 },
17181724 .dev = &memory,
17191725 .fifo_size = EP_FIFO_SIZE,
@@ -1726,6 +1732,8 @@ static struct s3c2410_udc memory = { · 6 unmodified lines
17261732 .name = "ep3-bulk",
17271733 .ops = &s3c2410_ep_ops,
17281734 .maxpacket = EP_FIFO_SIZE,
1735+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1736+ USB_EP_CAPS_DIR_ALL),
17291737 },
17301738 .dev = &memory,
17311739 .fifo_size = EP_FIFO_SIZE,
@@ -1738,6 +1746,8 @@ static struct s3c2410_udc memory = { · 6 unmodified lines
17381746 .name = "ep4-bulk",
17391747 .ops = &s3c2410_ep_ops,
17401748 .maxpacket = EP_FIFO_SIZE,
1749+ .caps = USB_EP_CAPS(USB_EP_CAPS_TYPE_BULK,
1750+ USB_EP_CAPS_DIR_ALL),
17411751 },
17421752 .dev = &memory,
17431753 .fifo_size = EP_FIFO_SIZE,
drivers/usb/gadget/udc/udc-core.c+90−0
@@ -131,6 +131,96 @@ EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); · 130 unmodified lines
131131
132132 /* ------------------------------------------------------------------------- */
133133
134+/**
135+ * gadget_find_ep_by_name - returns ep whose name is the same as sting passed
136+ * in second parameter or NULL if searched endpoint not found
137+ * @g: controller to check for quirk
138+ * @name: name of searched endpoint
139+ */
140+struct usb_ep *gadget_find_ep_by_name(struct usb_gadget *g, const char *name)
141+{
142+ struct usb_ep *ep;
143+
144+ gadget_for_each_ep(ep, g) {
145+ if (!strcmp(ep->name, name))
146+ return ep;
147+ }
148+
149+ return NULL;
150+}
151+EXPORT_SYMBOL_GPL(gadget_find_ep_by_name);
152+
153+/* ------------------------------------------------------------------------- */
154+
155+int usb_gadget_ep_match_desc(struct usb_gadget *gadget,
156+ struct usb_ep *ep, struct usb_endpoint_descriptor *desc,
157+ struct usb_ss_ep_comp_descriptor *ep_comp)
158+{
159+ u8 type;
160+ u16 max;
161+ int num_req_streams = 0;
162+
163+ /* endpoint already claimed? */
164+ if (ep->claimed)
165+ return 0;
166+
167+ type = usb_endpoint_type(desc);
168+ max = 0x7ff & usb_endpoint_maxp(desc);
169+
170+ if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in)
171+ return 0;
172+ if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out)
173+ return 0;
174+
175+ if (max > ep->maxpacket_limit)
176+ return 0;
177+
178+ /* "high bandwidth" works only at high speed */
179+ if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11))
180+ return 0;
181+
182+ switch (type) {
183+ case USB_ENDPOINT_XFER_CONTROL:
184+ /* only support ep0 for portable CONTROL traffic */
185+ return 0;
186+ case USB_ENDPOINT_XFER_ISOC:
187+ if (!ep->caps.type_iso)
188+ return 0;
189+ /* ISO: limit 1023 bytes full speed, 1024 high/super speed */
190+ if (!gadget_is_dualspeed(gadget) && max > 1023)
191+ return 0;
192+ break;
193+ case USB_ENDPOINT_XFER_BULK:
194+ if (!ep->caps.type_bulk)
195+ return 0;
196+ if (ep_comp && gadget_is_superspeed(gadget)) {
197+ /* Get the number of required streams from the
198+ * EP companion descriptor and see if the EP
199+ * matches it
200+ */
201+ num_req_streams = ep_comp->bmAttributes & 0x1f;
202+ if (num_req_streams > ep->max_streams)
203+ return 0;
204+ }
205+ break;
206+ case USB_ENDPOINT_XFER_INT:
207+ /* Bulk endpoints handle interrupt transfers,
208+ * except the toggle-quirky iso-synch kind
209+ */
210+ if (!ep->caps.type_int && !ep->caps.type_bulk)
211+ return 0;
212+ /* INT: limit 64 bytes full speed, 1024 high/super speed */
213+ if (!gadget_is_dualspeed(gadget) && max > 64)
214+ return 0;
215+ break;
216+ }
217+
218+ return 1;
219+}
220+EXPORT_SYMBOL_GPL(usb_gadget_ep_match_desc);
221+
222+/* ------------------------------------------------------------------------- */
223+
134224 static void usb_gadget_state_work(struct work_struct *work)
135225 {
136226 struct usb_gadget *gadget = work_to_gadget(work);
drivers/usb/gadget/udc/udc-xilinx.c+9−0
@@ -1317,12 +1317,21 @@ static void xudc_eps_init(struct xusb_udc *udc) · 1316 unmodified lines
13171317 snprintf(ep->name, EPNAME_SIZE, "ep%d", ep_number);
13181318 ep->ep_usb.name = ep->name;
13191319 ep->ep_usb.ops = &xusb_ep_ops;
1320+
1321+ ep->ep_usb.caps.type_iso = true;
1322+ ep->ep_usb.caps.type_bulk = true;
1323+ ep->ep_usb.caps.type_int = true;
13201324 } else {
13211325 ep->ep_usb.name = ep0name;
13221326 usb_ep_set_maxpacket_limit(&ep->ep_usb, EP0_MAX_PACKET);
13231327 ep->ep_usb.ops = &xusb_ep0_ops;
1328+
1329+ ep->ep_usb.caps.type_control = true;
13241330 }
13251331
1332+ ep->ep_usb.caps.dir_in = true;
1333+ ep->ep_usb.caps.dir_out = true;
1334+
13261335 ep->udc = udc;
13271336 ep->epnumber = ep_number;
13281337 ep->desc = NULL;
drivers/usb/isp1760/isp1760-udc.c+13−2
@@ -1382,14 +1382,25 @@ static void isp1760_udc_init_eps(struct isp1760_udc *udc) · 1381 unmodified lines
13821382 * This fits in the 8kB FIFO without double-buffering.
13831383 */
13841384 if (ep_num == 0) {
1385− ep->ep.maxpacket = 64;
1385+ usb_ep_set_maxpacket_limit(&ep->ep, 64);
1386+ ep->ep.caps.type_control = true;
1387+ ep->ep.caps.dir_in = true;
1388+ ep->ep.caps.dir_out = true;
13861389 ep->maxpacket = 64;
13871390 udc->gadget.ep0 = &ep->ep;
13881391 } else {
1389− ep->ep.maxpacket = 512;
1392+ usb_ep_set_maxpacket_limit(&ep->ep, 512);
1393+ ep->ep.caps.type_iso = true;
1394+ ep->ep.caps.type_bulk = true;
1395+ ep->ep.caps.type_int = true;
13901396 ep->maxpacket = 0;
13911397 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
13921398 }
1399+
1400+ if (is_in)
1401+ ep->ep.caps.dir_in = true;
1402+ else
1403+ ep->ep.caps.dir_out = true;
13931404 }
13941405 }
13951406
drivers/usb/musb/Kconfig+26−25
@@ -5,7 +5,7 @@ · 4 unmodified lines
55
66 # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
77 config USB_MUSB_HDRC
8− tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
8+ tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
99 depends on (USB || USB_GADGET)
1010 help
1111 Say Y here if your system has a dual role high speed USB
@@ -20,6 +20,8 @@ config USB_MUSB_HDRC · 8 unmodified lines
2020 Analog Devices parts using this IP include Blackfin BF54x,
2121 BF525 and BF527.
2222
23+ Allwinner SoCs using this IP include A10, A13, A20, ...
24+
2325 If you do not know what this is, please say N.
2426
2527 To compile this driver as a module, choose M here; the
@@ -60,6 +62,15 @@ endchoice · 34 unmodified lines
6062
6163 comment "Platform Glue Layer"
6264
65+config USB_MUSB_SUNXI
66+ tristate "Allwinner (sunxi)"
67+ depends on ARCH_SUNXI
68+ depends on NOP_USB_XCEIV
69+ depends on PHY_SUN4I_USB
70+ depends on EXTCON
71+ depends on GENERIC_PHY
72+ select SUNXI_SRAM
73+
6374 config USB_MUSB_DAVINCI
6475 tristate "DaVinci"
6576 depends on ARCH_DAVINCI_DMx
@@ -113,19 +124,20 @@ config USB_MUSB_JZ4740 · 47 unmodified lines
113124 config USB_MUSB_AM335X_CHILD
114125 tristate
115126
116−choice
117− prompt 'MUSB DMA mode'
118− default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM || USB_MUSB_JZ4740
119− default USB_UX500_DMA if USB_MUSB_UX500
120− default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
121− default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI
122− default USB_TUSB_OMAP_DMA if USB_MUSB_TUSB6010
123− default MUSB_PIO_ONLY if USB_MUSB_TUSB6010 || USB_MUSB_DA8XX || USB_MUSB_AM35X \
124− || USB_MUSB_DSPS
127+comment "MUSB DMA mode"
128+
129+config MUSB_PIO_ONLY
130+ bool 'Disable DMA (always use PIO)'
125131 help
126− Unfortunately, only one option can be enabled here. Ideally one
127− should be able to build all these drivers into one kernel to
128− allow using DMA on multiplatform kernels.
132+ All data is copied between memory and FIFO by the CPU.
133+ DMA controllers are ignored.
134+
135+ Do not choose this unless DMA support for your SOC or board
136+ is unavailable (or unstable). When DMA is enabled at compile time,
137+ you can still disable it at run time using the "use_dma=n" module
138+ parameter.
139+
140+if !MUSB_PIO_ONLY
129141
130142 config USB_UX500_DMA
131143 bool 'ST Ericsson Ux500'
@@ -157,17 +169,6 @@ config USB_TUSB_OMAP_DMA · 25 unmodified lines
157169 help
158170 Enable DMA transfers on TUSB 6010 when OMAP DMA is available.
159171
160−config MUSB_PIO_ONLY
161− bool 'Disable DMA (always use PIO)'
162− help
163− All data is copied between memory and FIFO by the CPU.
164− DMA controllers are ignored.
165−
166− Do not choose this unless DMA support for your SOC or board
167− is unavailable (or unstable). When DMA is enabled at compile time,
168− you can still disable it at run time using the "use_dma=n" module
169− parameter.
170−
171−endchoice
172+endif # !MUSB_PIO_ONLY
172173
173174 endif # USB_MUSB_HDRC
drivers/usb/musb/Makefile+1−0
@@ -20,6 +20,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o · 19 unmodified lines
2020 obj-$(CONFIG_USB_MUSB_BLACKFIN) += blackfin.o
2121 obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
2222 obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o
23+obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o
2324
2425
2526 obj-$(CONFIG_USB_MUSB_AM335X_CHILD) += musb_am335x.o
drivers/usb/musb/musb_cppi41.c+3−3
@@ -614,7 +614,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) · 613 unmodified lines
614614 {
615615 struct musb *musb = controller->musb;
616616 struct device *dev = musb->controller;
617− struct device_node *np = dev->of_node;
617+ struct device_node *np = dev->parent->of_node;
618618 struct cppi41_dma_channel *cppi41_channel;
619619 int count;
620620 int i;
@@ -664,7 +664,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) · 43 unmodified lines
664664 musb_dma->status = MUSB_DMA_STATUS_FREE;
665665 musb_dma->max_len = SZ_4M;
666666
667− dc = dma_request_slave_channel(dev, str);
667+ dc = dma_request_slave_channel(dev->parent, str);
668668 if (!dc) {
669669 dev_err(dev, "Failed to request %s.\n", str);
670670 ret = -EPROBE_DEFER;
@@ -695,7 +695,7 @@ cppi41_dma_controller_create(struct musb *musb, void __iomem *base) · 24 unmodified lines
695695 struct cppi41_dma_controller *controller;
696696 int ret = 0;
697697
698− if (!musb->controller->of_node) {
698+ if (!musb->controller->parent->of_node) {
699699 dev_err(musb->controller, "Need DT for the DMA engine.\n");
700700 return NULL;
701701 }
drivers/usb/musb/musb_gadget.c+66−21
@@ -313,8 +313,7 @@ static void txstate(struct musb *musb, struct musb_request *req) · 312 unmodified lines
313313
314314 /* MUSB_TXCSR_P_ISO is still set correctly */
315315
316−#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA)
317− {
316+ if (musb_dma_inventra(musb) || musb_dma_ux500(musb)) {
318317 if (request_size < musb_ep->packet_sz)
319318 musb_ep->dma->desired_mode = 0;
320319 else
@@ -365,7 +364,6 @@ static void txstate(struct musb *musb, struct musb_request *req) · 44 unmodified lines
365364 }
366365 }
367366
368−#endif
369367 if (is_cppi_enabled(musb)) {
370368 /* program endpoint CSR first, then setup DMA */
371369 csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY);
@@ -641,8 +639,10 @@ static void rxstate(struct musb *musb, struct musb_request *req) · 269 unmodified lines
641639 use_mode_1 = 0;
642640
643641 if (request->actual < request->length) {
644−#ifdef CONFIG_USB_INVENTRA_DMA
645− if (is_buffer_mapped(req)) {
642+ if (!is_buffer_mapped(req))
643+ goto buffer_aint_mapped;
644+
645+ if (musb_dma_inventra(musb)) {
646646 struct dma_controller *c;
647647 struct dma_channel *channel;
648648 int use_dma = 0;
@@ -716,8 +716,8 @@ static void rxstate(struct musb *musb, struct musb_request *req) · 67 unmodified lines
716716 if (use_dma)
717717 return;
718718 }
719−#elif defined(CONFIG_USB_UX500_DMA)
720− if ((is_buffer_mapped(req)) &&
719+
720+ if ((musb_dma_ux500(musb)) &&
721721 (request->actual < request->length)) {
722722
723723 struct dma_controller *c;
@@ -765,7 +765,6 @@ static void rxstate(struct musb *musb, struct musb_request *req) · 41 unmodified lines
765765
766766 return;
767767 }
768−#endif /* Mentor's DMA */
769768
770769 len = request->length - request->actual;
771770 dev_dbg(musb->controller, "%s OUT/RX pio fifo %d/%d, maxpacket %d\n",
@@ -775,8 +774,7 @@ static void rxstate(struct musb *musb, struct musb_request *req) · 3 unmodified lines
775774
776775 fifo_count = min_t(unsigned, len, fifo_count);
777776
778−#ifdef CONFIG_USB_TUSB_OMAP_DMA
779− if (tusb_dma_omap(musb) && is_buffer_mapped(req)) {
777+ if (tusb_dma_omap(musb)) {
780778 struct dma_controller *c = musb->dma_controller;
781779 struct dma_channel *channel = musb_ep->dma;
782780 u32 dma_addr = request->dma + request->actual;
@@ -790,23 +788,22 @@ static void rxstate(struct musb *musb, struct musb_request *req) · 7 unmodified lines
790788 if (ret)
791789 return;
792790 }
793−#endif
791+
794792 /*
795793 * Unmap the dma buffer back to cpu if dma channel
796794 * programming fails. This buffer is mapped if the
797795 * channel allocation is successful
798796 */
799− if (is_buffer_mapped(req)) {
800− unmap_dma_buffer(req, musb);
801−
802− /*
803− * Clear DMAENAB and AUTOCLEAR for the
804− * PIO mode transfer
805− */
806− csr &= ~(MUSB_RXCSR_DMAENAB | MUSB_RXCSR_AUTOCLEAR);
807− musb_writew(epio, MUSB_RXCSR, csr);
808− }
797+ unmap_dma_buffer(req, musb);
809798
799+ /*
800+ * Clear DMAENAB and AUTOCLEAR for the
801+ * PIO mode transfer
802+ */
803+ csr &= ~(MUSB_RXCSR_DMAENAB | MUSB_RXCSR_AUTOCLEAR);
804+ musb_writew(epio, MUSB_RXCSR, csr);
805+
806+buffer_aint_mapped:
810807 musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *)
811808 (request->buf + request->actual));
812809 request->actual += fifo_count;
@@ -1684,6 +1681,40 @@ static int musb_gadget_pullup(struct usb_gadget *gadget, int is_on) · 871 unmodified lines
16841681 return 0;
16851682 }
16861683
1684+#ifdef CONFIG_BLACKFIN
1685+static struct usb_ep *musb_match_ep(struct usb_gadget *g,
1686+ struct usb_endpoint_descriptor *desc,
1687+ struct usb_ss_ep_comp_descriptor *ep_comp)
1688+{
1689+ struct usb_ep *ep = NULL;
1690+
1691+ switch (usb_endpoint_type(desc)) {
1692+ case USB_ENDPOINT_XFER_ISOC:
1693+ case USB_ENDPOINT_XFER_BULK:
1694+ if (usb_endpoint_dir_in(desc))
1695+ ep = gadget_find_ep_by_name(g, "ep5in");
1696+ else
1697+ ep = gadget_find_ep_by_name(g, "ep6out");
1698+ break;
1699+ case USB_ENDPOINT_XFER_INT:
1700+ if (usb_endpoint_dir_in(desc))
1701+ ep = gadget_find_ep_by_name(g, "ep1in");
1702+ else
1703+ ep = gadget_find_ep_by_name(g, "ep2out");
1704+ break;
1705+ default:
1706+ break;
1707+ }
1708+
1709+ if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
1710+ return ep;
1711+
1712+ return NULL;
1713+}
1714+#else
1715+#define musb_match_ep NULL
1716+#endif
1717+
16871718 static int musb_gadget_start(struct usb_gadget *g,
16881719 struct usb_gadget_driver *driver);
16891720 static int musb_gadget_stop(struct usb_gadget *g);
@@ -1697,6 +1728,7 @@ static const struct usb_gadget_ops musb_gadget_operations = { · 7 unmodified lines
16971728 .pullup = musb_gadget_pullup,
16981729 .udc_start = musb_gadget_start,
16991730 .udc_stop = musb_gadget_stop,
1731+ .match_ep = musb_match_ep,
17001732 };
17011733
17021734 /* ----------------------------------------------------------------------- */
@@ -1729,6 +1761,7 @@ init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) · 26 unmodified lines
17291761 INIT_LIST_HEAD(&ep->end_point.ep_list);
17301762 if (!epnum) {
17311763 usb_ep_set_maxpacket_limit(&ep->end_point, 64);
1764+ ep->end_point.caps.type_control = true;
17321765 ep->end_point.ops = &musb_g_ep0_ops;
17331766 musb->g.ep0 = &ep->end_point;
17341767 } else {
@@ -1736,9 +1769,20 @@ init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) · 1 unmodified line
17361769 usb_ep_set_maxpacket_limit(&ep->end_point, hw_ep->max_packet_sz_tx);
17371770 else
17381771 usb_ep_set_maxpacket_limit(&ep->end_point, hw_ep->max_packet_sz_rx);
1772+ ep->end_point.caps.type_iso = true;
1773+ ep->end_point.caps.type_bulk = true;
1774+ ep->end_point.caps.type_int = true;
17391775 ep->end_point.ops = &musb_ep_ops;
17401776 list_add_tail(&ep->end_point.ep_list, &musb->g.ep_list);
17411777 }
1778+
1779+ if (!epnum || hw_ep->is_shared_fifo) {
1780+ ep->end_point.caps.dir_in = true;
1781+ ep->end_point.caps.dir_out = true;
1782+ } else if (is_in)
1783+ ep->end_point.caps.dir_in = true;
1784+ else
1785+ ep->end_point.caps.dir_out = true;
17421786 }
17431787
17441788 /*
@@ -2075,6 +2119,7 @@ __acquires(musb->lock) · 330 unmodified lines
20752119 musb->g.b_hnp_enable = 0;
20762120 musb->g.a_alt_hnp_support = 0;
20772121 musb->g.a_hnp_support = 0;
2122+ musb->g.quirk_zlp_not_supp = 1;
20782123
20792124 /* Normal reset, as B-Device;
20802125 * or else after HNP, as A-Device
drivers/usb/musb/sunxi.c+756−0
@@ -0,0 +1,756 @@
1+/*
2+ * Allwinner sun4i MUSB Glue Layer
3+ *
4+ * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
5+ *
6+ * Based on code from
7+ * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
8+ *
9+ * This program is free software; you can redistribute it and/or modify
10+ * it under the terms of the GNU General Public License as published by
11+ * the Free Software Foundation; either version 2 of the License, or
12+ * (at your option) any later version.
13+ *
14+ * This program is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ * GNU General Public License for more details.
18+ */
19+
20+#include <linux/clk.h>
21+#include <linux/err.h>
22+#include <linux/extcon.h>
23+#include <linux/io.h>
24+#include <linux/kernel.h>
25+#include <linux/module.h>
26+#include <linux/of.h>
27+#include <linux/phy/phy-sun4i-usb.h>
28+#include <linux/platform_device.h>
29+#include <linux/reset.h>
30+#include <linux/soc/sunxi/sunxi_sram.h>
31+#include <linux/usb/musb.h>
32+#include <linux/usb/of.h>
33+#include <linux/usb/usb_phy_generic.h>
34+#include <linux/workqueue.h>
35+#include "musb_core.h"
36+
37+/*
38+ * Register offsets, note sunxi musb has a different layout then most
39+ * musb implementations, we translate the layout in musb_readb & friends.
40+ */
41+#define SUNXI_MUSB_POWER 0x0040
42+#define SUNXI_MUSB_DEVCTL 0x0041
43+#define SUNXI_MUSB_INDEX 0x0042
44+#define SUNXI_MUSB_VEND0 0x0043
45+#define SUNXI_MUSB_INTRTX 0x0044
46+#define SUNXI_MUSB_INTRRX 0x0046
47+#define SUNXI_MUSB_INTRTXE 0x0048
48+#define SUNXI_MUSB_INTRRXE 0x004a
49+#define SUNXI_MUSB_INTRUSB 0x004c
50+#define SUNXI_MUSB_INTRUSBE 0x0050
51+#define SUNXI_MUSB_FRAME 0x0054
52+#define SUNXI_MUSB_TXFIFOSZ 0x0090
53+#define SUNXI_MUSB_TXFIFOADD 0x0092
54+#define SUNXI_MUSB_RXFIFOSZ 0x0094
55+#define SUNXI_MUSB_RXFIFOADD 0x0096
56+#define SUNXI_MUSB_FADDR 0x0098
57+#define SUNXI_MUSB_TXFUNCADDR 0x0098
58+#define SUNXI_MUSB_TXHUBADDR 0x009a
59+#define SUNXI_MUSB_TXHUBPORT 0x009b
60+#define SUNXI_MUSB_RXFUNCADDR 0x009c
61+#define SUNXI_MUSB_RXHUBADDR 0x009e
62+#define SUNXI_MUSB_RXHUBPORT 0x009f
63+#define SUNXI_MUSB_CONFIGDATA 0x00c0
64+
65+/* VEND0 bits */
66+#define SUNXI_MUSB_VEND0_PIO_MODE 0
67+
68+/* flags */
69+#define SUNXI_MUSB_FL_ENABLED 0
70+#define SUNXI_MUSB_FL_HOSTMODE 1
71+#define SUNXI_MUSB_FL_HOSTMODE_PEND 2
72+#define SUNXI_MUSB_FL_VBUS_ON 3
73+#define SUNXI_MUSB_FL_PHY_ON 4
74+#define SUNXI_MUSB_FL_HAS_SRAM 5
75+#define SUNXI_MUSB_FL_HAS_RESET 6
76+#define SUNXI_MUSB_FL_NO_CONFIGDATA 7
77+
78+/* Our read/write methods need access and do not get passed in a musb ref :| */
79+static struct musb *sunxi_musb;
80+
81+struct sunxi_glue {
82+ struct device *dev;
83+ struct platform_device *musb;
84+ struct clk *clk;
85+ struct reset_control *rst;
86+ struct phy *phy;
87+ struct platform_device *usb_phy;
88+ struct usb_phy *xceiv;
89+ unsigned long flags;
90+ struct work_struct work;
91+ struct extcon_dev *extcon;
92+ struct notifier_block host_nb;
93+};
94+
95+/* phy_power_on / off may sleep, so we use a workqueue */
96+static void sunxi_musb_work(struct work_struct *work)
97+{
98+ struct sunxi_glue *glue = container_of(work, struct sunxi_glue, work);
99+ bool vbus_on, phy_on;
100+
101+ if (!test_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
102+ return;
103+
104+ if (test_and_clear_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags)) {
105+ struct musb *musb = platform_get_drvdata(glue->musb);
106+ unsigned long flags;
107+ u8 devctl;
108+
109+ spin_lock_irqsave(&musb->lock, flags);
110+
111+ devctl = readb(musb->mregs + SUNXI_MUSB_DEVCTL);
112+ if (test_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags)) {
113+ set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
114+ musb->xceiv->otg->default_a = 1;
115+ musb->xceiv->otg->state = OTG_STATE_A_IDLE;
116+ MUSB_HST_MODE(musb);
117+ devctl |= MUSB_DEVCTL_SESSION;
118+ } else {
119+ clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
120+ musb->xceiv->otg->default_a = 0;
121+ musb->xceiv->otg->state = OTG_STATE_B_IDLE;
122+ MUSB_DEV_MODE(musb);
123+ devctl &= ~MUSB_DEVCTL_SESSION;
124+ }
125+ writeb(devctl, musb->mregs + SUNXI_MUSB_DEVCTL);
126+
127+ spin_unlock_irqrestore(&musb->lock, flags);
128+ }
129+
130+ vbus_on = test_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
131+ phy_on = test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
132+
133+ if (phy_on != vbus_on) {
134+ if (vbus_on) {
135+ phy_power_on(glue->phy);
136+ set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
137+ } else {
138+ phy_power_off(glue->phy);
139+ clear_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
140+ }
141+ }
142+}
143+
144+static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
145+{
146+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
147+
148+ if (is_on)
149+ set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
150+ else
151+ clear_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
152+
153+ schedule_work(&glue->work);
154+}
155+
156+static void sunxi_musb_pre_root_reset_end(struct musb *musb)
157+{
158+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
159+
160+ sun4i_usb_phy_set_squelch_detect(glue->phy, false);
161+}
162+
163+static void sunxi_musb_post_root_reset_end(struct musb *musb)
164+{
165+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
166+
167+ sun4i_usb_phy_set_squelch_detect(glue->phy, true);
168+}
169+
170+static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
171+{
172+ struct musb *musb = __hci;
173+ unsigned long flags;
174+
175+ spin_lock_irqsave(&musb->lock, flags);
176+
177+ musb->int_usb = readb(musb->mregs + SUNXI_MUSB_INTRUSB);
178+ if (musb->int_usb)
179+ writeb(musb->int_usb, musb->mregs + SUNXI_MUSB_INTRUSB);
180+
181+ /*
182+ * sunxi musb often signals babble on low / full speed device
183+ * disconnect, without ever raising MUSB_INTR_DISCONNECT, since
184+ * normally babble never happens treat it as disconnect.
185+ */
186+ if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {
187+ musb->int_usb &= ~MUSB_INTR_BABBLE;
188+ musb->int_usb |= MUSB_INTR_DISCONNECT;
189+ }
190+
191+ if ((musb->int_usb & MUSB_INTR_RESET) && !is_host_active(musb)) {
192+ /* ep0 FADDR must be 0 when (re)entering peripheral mode */
193+ musb_ep_select(musb->mregs, 0);
194+ musb_writeb(musb->mregs, MUSB_FADDR, 0);
195+ }
196+
197+ musb->int_tx = readw(musb->mregs + SUNXI_MUSB_INTRTX);
198+ if (musb->int_tx)
199+ writew(musb->int_tx, musb->mregs + SUNXI_MUSB_INTRTX);
200+
201+ musb->int_rx = readw(musb->mregs + SUNXI_MUSB_INTRRX);
202+ if (musb->int_rx)
203+ writew(musb->int_rx, musb->mregs + SUNXI_MUSB_INTRRX);
204+
205+ musb_interrupt(musb);
206+
207+ spin_unlock_irqrestore(&musb->lock, flags);
208+
209+ return IRQ_HANDLED;
210+}
211+
212+static int sunxi_musb_host_notifier(struct notifier_block *nb,
213+ unsigned long event, void *ptr)
214+{
215+ struct sunxi_glue *glue = container_of(nb, struct sunxi_glue, host_nb);
216+
217+ if (event)
218+ set_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
219+ else
220+ clear_bit(SUNXI_MUSB_FL_HOSTMODE, &glue->flags);
221+
222+ set_bit(SUNXI_MUSB_FL_HOSTMODE_PEND, &glue->flags);
223+ schedule_work(&glue->work);
224+
225+ return NOTIFY_DONE;
226+}
227+
228+static int sunxi_musb_init(struct musb *musb)
229+{
230+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
231+ int ret;
232+
233+ sunxi_musb = musb;
234+ musb->phy = glue->phy;
235+ musb->xceiv = glue->xceiv;
236+
237+ if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags)) {
238+ ret = sunxi_sram_claim(musb->controller->parent);
239+ if (ret)
240+ return ret;
241+ }
242+
243+ ret = clk_prepare_enable(glue->clk);
244+ if (ret)
245+ goto error_sram_release;
246+
247+ if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
248+ ret = reset_control_deassert(glue->rst);
249+ if (ret)
250+ goto error_clk_disable;
251+ }
252+
253+ writeb(SUNXI_MUSB_VEND0_PIO_MODE, musb->mregs + SUNXI_MUSB_VEND0);
254+
255+ /* Register notifier before calling phy_init() */
256+ if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) {
257+ ret = extcon_register_notifier(glue->extcon, EXTCON_USB_HOST,
258+ &glue->host_nb);
259+ if (ret)
260+ goto error_reset_assert;
261+ }
262+
263+ ret = phy_init(glue->phy);
264+ if (ret)
265+ goto error_unregister_notifier;
266+
267+ if (musb->port_mode == MUSB_PORT_MODE_HOST) {
268+ ret = phy_power_on(glue->phy);
269+ if (ret)
270+ goto error_phy_exit;
271+ set_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
272+ /* Stop musb work from turning vbus off again */
273+ set_bit(SUNXI_MUSB_FL_VBUS_ON, &glue->flags);
274+ }
275+
276+ musb->isr = sunxi_musb_interrupt;
277+
278+ /* Stop the musb-core from doing runtime pm (not supported on sunxi) */
279+ pm_runtime_get(musb->controller);
280+
281+ return 0;
282+
283+error_phy_exit:
284+ phy_exit(glue->phy);
285+error_unregister_notifier:
286+ if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
287+ extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST,
288+ &glue->host_nb);
289+error_reset_assert:
290+ if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags))
291+ reset_control_assert(glue->rst);
292+error_clk_disable:
293+ clk_disable_unprepare(glue->clk);
294+error_sram_release:
295+ if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags))
296+ sunxi_sram_release(musb->controller->parent);
297+ return ret;
298+}
299+
300+static int sunxi_musb_exit(struct musb *musb)
301+{
302+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
303+
304+ pm_runtime_put(musb->controller);
305+
306+ cancel_work_sync(&glue->work);
307+ if (test_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags))
308+ phy_power_off(glue->phy);
309+
310+ phy_exit(glue->phy);
311+
312+ if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
313+ extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST,
314+ &glue->host_nb);
315+
316+ if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags))
317+ reset_control_assert(glue->rst);
318+
319+ clk_disable_unprepare(glue->clk);
320+ if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags))
321+ sunxi_sram_release(musb->controller->parent);
322+
323+ return 0;
324+}
325+
326+static void sunxi_musb_enable(struct musb *musb)
327+{
328+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
329+
330+ /* musb_core does not call us in a balanced manner */
331+ if (test_and_set_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags))
332+ return;
333+
334+ schedule_work(&glue->work);
335+}
336+
337+static void sunxi_musb_disable(struct musb *musb)
338+{
339+ struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
340+
341+ clear_bit(SUNXI_MUSB_FL_ENABLED, &glue->flags);
342+}
343+
344+/*
345+ * sunxi musb register layout
346+ * 0x00 - 0x17 fifo regs, 1 long per fifo
347+ * 0x40 - 0x57 generic control regs (power - frame)
348+ * 0x80 - 0x8f ep control regs (addressed through hw_ep->regs, indexed)
349+ * 0x90 - 0x97 fifo control regs (indexed)
350+ * 0x98 - 0x9f multipoint / busctl regs (indexed)
351+ * 0xc0 configdata reg
352+ */
353+
354+static u32 sunxi_musb_fifo_offset(u8 epnum)
355+{
356+ return (epnum * 4);
357+}
358+
359+static u32 sunxi_musb_ep_offset(u8 epnum, u16 offset)
360+{
361+ WARN_ONCE(offset != 0,
362+ "sunxi_musb_ep_offset called with non 0 offset\n");
363+
364+ return 0x80; /* indexed, so ignore epnum */
365+}
366+
367+static u32 sunxi_musb_busctl_offset(u8 epnum, u16 offset)
368+{
369+ return SUNXI_MUSB_TXFUNCADDR + offset;
370+}
371+
372+static u8 sunxi_musb_readb(const void __iomem *addr, unsigned offset)
373+{
374+ struct sunxi_glue *glue;
375+
376+ if (addr == sunxi_musb->mregs) {
377+ /* generic control or fifo control reg access */
378+ switch (offset) {
379+ case MUSB_FADDR:
380+ return readb(addr + SUNXI_MUSB_FADDR);
381+ case MUSB_POWER:
382+ return readb(addr + SUNXI_MUSB_POWER);
383+ case MUSB_INTRUSB:
384+ return readb(addr + SUNXI_MUSB_INTRUSB);
385+ case MUSB_INTRUSBE:
386+ return readb(addr + SUNXI_MUSB_INTRUSBE);
387+ case MUSB_INDEX:
388+ return readb(addr + SUNXI_MUSB_INDEX);
389+ case MUSB_TESTMODE:
390+ return 0; /* No testmode on sunxi */
391+ case MUSB_DEVCTL:
392+ return readb(addr + SUNXI_MUSB_DEVCTL);
393+ case MUSB_TXFIFOSZ:
394+ return readb(addr + SUNXI_MUSB_TXFIFOSZ);
395+ case MUSB_RXFIFOSZ:
396+ return readb(addr + SUNXI_MUSB_RXFIFOSZ);
397+ case MUSB_CONFIGDATA + 0x10: /* See musb_read_configdata() */
398+ glue = dev_get_drvdata(sunxi_musb->controller->parent);
399+ /* A33 saves a reg, and we get to hardcode this */
400+ if (test_bit(SUNXI_MUSB_FL_NO_CONFIGDATA,
401+ &glue->flags))
402+ return 0xde;
403+
404+ return readb(addr + SUNXI_MUSB_CONFIGDATA);
405+ /* Offset for these is fixed by sunxi_musb_busctl_offset() */
406+ case SUNXI_MUSB_TXFUNCADDR:
407+ case SUNXI_MUSB_TXHUBADDR:
408+ case SUNXI_MUSB_TXHUBPORT:
409+ case SUNXI_MUSB_RXFUNCADDR:
410+ case SUNXI_MUSB_RXHUBADDR:
411+ case SUNXI_MUSB_RXHUBPORT:
412+ /* multipoint / busctl reg access */
413+ return readb(addr + offset);
414+ default:
415+ dev_err(sunxi_musb->controller->parent,
416+ "Error unknown readb offset %u\n", offset);
417+ return 0;
418+ }
419+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
420+ /* ep control reg access */
421+ /* sunxi has a 2 byte hole before the txtype register */
422+ if (offset >= MUSB_TXTYPE)
423+ offset += 2;
424+ return readb(addr + offset);
425+ }
426+
427+ dev_err(sunxi_musb->controller->parent,
428+ "Error unknown readb at 0x%x bytes offset\n",
429+ (int)(addr - sunxi_musb->mregs));
430+ return 0;
431+}
432+
433+static void sunxi_musb_writeb(void __iomem *addr, unsigned offset, u8 data)
434+{
435+ if (addr == sunxi_musb->mregs) {
436+ /* generic control or fifo control reg access */
437+ switch (offset) {
438+ case MUSB_FADDR:
439+ return writeb(data, addr + SUNXI_MUSB_FADDR);
440+ case MUSB_POWER:
441+ return writeb(data, addr + SUNXI_MUSB_POWER);
442+ case MUSB_INTRUSB:
443+ return writeb(data, addr + SUNXI_MUSB_INTRUSB);
444+ case MUSB_INTRUSBE:
445+ return writeb(data, addr + SUNXI_MUSB_INTRUSBE);
446+ case MUSB_INDEX:
447+ return writeb(data, addr + SUNXI_MUSB_INDEX);
448+ case MUSB_TESTMODE:
449+ if (data)
450+ dev_warn(sunxi_musb->controller->parent,
451+ "sunxi-musb does not have testmode\n");
452+ return;
453+ case MUSB_DEVCTL:
454+ return writeb(data, addr + SUNXI_MUSB_DEVCTL);
455+ case MUSB_TXFIFOSZ:
456+ return writeb(data, addr + SUNXI_MUSB_TXFIFOSZ);
457+ case MUSB_RXFIFOSZ:
458+ return writeb(data, addr + SUNXI_MUSB_RXFIFOSZ);
459+ /* Offset for these is fixed by sunxi_musb_busctl_offset() */
460+ case SUNXI_MUSB_TXFUNCADDR:
461+ case SUNXI_MUSB_TXHUBADDR:
462+ case SUNXI_MUSB_TXHUBPORT:
463+ case SUNXI_MUSB_RXFUNCADDR:
464+ case SUNXI_MUSB_RXHUBADDR:
465+ case SUNXI_MUSB_RXHUBPORT:
466+ /* multipoint / busctl reg access */
467+ return writeb(data, addr + offset);
468+ default:
469+ dev_err(sunxi_musb->controller->parent,
470+ "Error unknown writeb offset %u\n", offset);
471+ return;
472+ }
473+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
474+ /* ep control reg access */
475+ if (offset >= MUSB_TXTYPE)
476+ offset += 2;
477+ return writeb(data, addr + offset);
478+ }
479+
480+ dev_err(sunxi_musb->controller->parent,
481+ "Error unknown writeb at 0x%x bytes offset\n",
482+ (int)(addr - sunxi_musb->mregs));
483+}
484+
485+static u16 sunxi_musb_readw(const void __iomem *addr, unsigned offset)
486+{
487+ if (addr == sunxi_musb->mregs) {
488+ /* generic control or fifo control reg access */
489+ switch (offset) {
490+ case MUSB_INTRTX:
491+ return readw(addr + SUNXI_MUSB_INTRTX);
492+ case MUSB_INTRRX:
493+ return readw(addr + SUNXI_MUSB_INTRRX);
494+ case MUSB_INTRTXE:
495+ return readw(addr + SUNXI_MUSB_INTRTXE);
496+ case MUSB_INTRRXE:
497+ return readw(addr + SUNXI_MUSB_INTRRXE);
498+ case MUSB_FRAME:
499+ return readw(addr + SUNXI_MUSB_FRAME);
500+ case MUSB_TXFIFOADD:
501+ return readw(addr + SUNXI_MUSB_TXFIFOADD);
502+ case MUSB_RXFIFOADD:
503+ return readw(addr + SUNXI_MUSB_RXFIFOADD);
504+ case MUSB_HWVERS:
505+ return 0; /* sunxi musb version is not known */
506+ default:
507+ dev_err(sunxi_musb->controller->parent,
508+ "Error unknown readw offset %u\n", offset);
509+ return 0;
510+ }
511+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
512+ /* ep control reg access */
513+ return readw(addr + offset);
514+ }
515+
516+ dev_err(sunxi_musb->controller->parent,
517+ "Error unknown readw at 0x%x bytes offset\n",
518+ (int)(addr - sunxi_musb->mregs));
519+ return 0;
520+}
521+
522+static void sunxi_musb_writew(void __iomem *addr, unsigned offset, u16 data)
523+{
524+ if (addr == sunxi_musb->mregs) {
525+ /* generic control or fifo control reg access */
526+ switch (offset) {
527+ case MUSB_INTRTX:
528+ return writew(data, addr + SUNXI_MUSB_INTRTX);
529+ case MUSB_INTRRX:
530+ return writew(data, addr + SUNXI_MUSB_INTRRX);
531+ case MUSB_INTRTXE:
532+ return writew(data, addr + SUNXI_MUSB_INTRTXE);
533+ case MUSB_INTRRXE:
534+ return writew(data, addr + SUNXI_MUSB_INTRRXE);
535+ case MUSB_FRAME:
536+ return writew(data, addr + SUNXI_MUSB_FRAME);
537+ case MUSB_TXFIFOADD:
538+ return writew(data, addr + SUNXI_MUSB_TXFIFOADD);
539+ case MUSB_RXFIFOADD:
540+ return writew(data, addr + SUNXI_MUSB_RXFIFOADD);
541+ default:
542+ dev_err(sunxi_musb->controller->parent,
543+ "Error unknown writew offset %u\n", offset);
544+ return;
545+ }
546+ } else if (addr == (sunxi_musb->mregs + 0x80)) {
547+ /* ep control reg access */
548+ return writew(data, addr + offset);
549+ }
550+
551+ dev_err(sunxi_musb->controller->parent,
552+ "Error unknown writew at 0x%x bytes offset\n",
553+ (int)(addr - sunxi_musb->mregs));
554+}
555+
556+static const struct musb_platform_ops sunxi_musb_ops = {
557+ .quirks = MUSB_INDEXED_EP,
558+ .init = sunxi_musb_init,
559+ .exit = sunxi_musb_exit,
560+ .enable = sunxi_musb_enable,
561+ .disable = sunxi_musb_disable,
562+ .fifo_offset = sunxi_musb_fifo_offset,
563+ .ep_offset = sunxi_musb_ep_offset,
564+ .busctl_offset = sunxi_musb_busctl_offset,
565+ .readb = sunxi_musb_readb,
566+ .writeb = sunxi_musb_writeb,
567+ .readw = sunxi_musb_readw,
568+ .writew = sunxi_musb_writew,
569+ .set_vbus = sunxi_musb_set_vbus,
570+ .pre_root_reset_end = sunxi_musb_pre_root_reset_end,
571+ .post_root_reset_end = sunxi_musb_post_root_reset_end,
572+};
573+
574+/* Allwinner OTG supports up to 5 endpoints */
575+#define SUNXI_MUSB_MAX_EP_NUM 6
576+#define SUNXI_MUSB_RAM_BITS 11
577+
578+static struct musb_fifo_cfg sunxi_musb_mode_cfg[] = {
579+ MUSB_EP_FIFO_SINGLE(1, FIFO_TX, 512),
580+ MUSB_EP_FIFO_SINGLE(1, FIFO_RX, 512),
581+ MUSB_EP_FIFO_SINGLE(2, FIFO_TX, 512),
582+ MUSB_EP_FIFO_SINGLE(2, FIFO_RX, 512),
583+ MUSB_EP_FIFO_SINGLE(3, FIFO_TX, 512),
584+ MUSB_EP_FIFO_SINGLE(3, FIFO_RX, 512),
585+ MUSB_EP_FIFO_SINGLE(4, FIFO_TX, 512),
586+ MUSB_EP_FIFO_SINGLE(4, FIFO_RX, 512),
587+ MUSB_EP_FIFO_SINGLE(5, FIFO_TX, 512),
588+ MUSB_EP_FIFO_SINGLE(5, FIFO_RX, 512),
589+};
590+
591+static struct musb_hdrc_config sunxi_musb_hdrc_config = {
592+ .fifo_cfg = sunxi_musb_mode_cfg,
593+ .fifo_cfg_size = ARRAY_SIZE(sunxi_musb_mode_cfg),
594+ .multipoint = true,
595+ .dyn_fifo = true,
596+ .soft_con = true,
597+ .num_eps = SUNXI_MUSB_MAX_EP_NUM,
598+ .ram_bits = SUNXI_MUSB_RAM_BITS,
599+ .dma = 0,
600+};
601+
602+static int sunxi_musb_probe(struct platform_device *pdev)
603+{
604+ struct musb_hdrc_platform_data pdata;
605+ struct platform_device_info pinfo;
606+ struct sunxi_glue *glue;
607+ struct device_node *np = pdev->dev.of_node;
608+ int ret;
609+
610+ if (!np) {
611+ dev_err(&pdev->dev, "Error no device tree node found\n");
612+ return -EINVAL;
613+ }
614+
615+ glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
616+ if (!glue)
617+ return -ENOMEM;
618+
619+ memset(&pdata, 0, sizeof(pdata));
620+ switch (of_usb_get_dr_mode(np)) {
621+#if defined CONFIG_USB_MUSB_DUAL_ROLE || defined CONFIG_USB_MUSB_HOST
622+ case USB_DR_MODE_HOST:
623+ pdata.mode = MUSB_PORT_MODE_HOST;
624+ break;
625+#endif
626+#ifdef CONFIG_USB_MUSB_DUAL_ROLE
627+ case USB_DR_MODE_OTG:
628+ glue->extcon = extcon_get_edev_by_phandle(&pdev->dev, 0);
629+ if (IS_ERR(glue->extcon)) {
630+ if (PTR_ERR(glue->extcon) == -EPROBE_DEFER)
631+ return -EPROBE_DEFER;
632+ dev_err(&pdev->dev, "Invalid or missing extcon\n");
633+ return PTR_ERR(glue->extcon);
634+ }
635+ pdata.mode = MUSB_PORT_MODE_DUAL_ROLE;
636+ break;
637+#endif
638+ default:
639+ dev_err(&pdev->dev, "Invalid or missing 'dr_mode' property\n");
640+ return -EINVAL;
641+ }
642+ pdata.platform_ops = &sunxi_musb_ops;
643+ pdata.config = &sunxi_musb_hdrc_config;
644+
645+ glue->dev = &pdev->dev;
646+ INIT_WORK(&glue->work, sunxi_musb_work);
647+ glue->host_nb.notifier_call = sunxi_musb_host_notifier;
648+
649+ if (of_device_is_compatible(np, "allwinner,sun4i-a10-musb"))
650+ set_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags);
651+
652+ if (of_device_is_compatible(np, "allwinner,sun6i-a31-musb"))
653+ set_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags);
654+
655+ if (of_device_is_compatible(np, "allwinner,sun8i-a33-musb")) {
656+ set_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags);
657+ set_bit(SUNXI_MUSB_FL_NO_CONFIGDATA, &glue->flags);
658+ }
659+
660+ glue->clk = devm_clk_get(&pdev->dev, NULL);
661+ if (IS_ERR(glue->clk)) {
662+ dev_err(&pdev->dev, "Error getting clock: %ld\n",
663+ PTR_ERR(glue->clk));
664+ return PTR_ERR(glue->clk);
665+ }
666+
667+ if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
668+ glue->rst = devm_reset_control_get(&pdev->dev, NULL);
669+ if (IS_ERR(glue->rst)) {
670+ if (PTR_ERR(glue->rst) == -EPROBE_DEFER)
671+ return -EPROBE_DEFER;
672+ dev_err(&pdev->dev, "Error getting reset %ld\n",
673+ PTR_ERR(glue->rst));
674+ return PTR_ERR(glue->rst);
675+ }
676+ }
677+
678+ glue->phy = devm_phy_get(&pdev->dev, "usb");
679+ if (IS_ERR(glue->phy)) {
680+ if (PTR_ERR(glue->phy) == -EPROBE_DEFER)
681+ return -EPROBE_DEFER;
682+ dev_err(&pdev->dev, "Error getting phy %ld\n",
683+ PTR_ERR(glue->phy));
684+ return PTR_ERR(glue->phy);
685+ }
686+
687+ glue->usb_phy = usb_phy_generic_register();
688+ if (IS_ERR(glue->usb_phy)) {
689+ dev_err(&pdev->dev, "Error registering usb-phy %ld\n",
690+ PTR_ERR(glue->usb_phy));
691+ return PTR_ERR(glue->usb_phy);
692+ }
693+
694+ glue->xceiv = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
695+ if (IS_ERR(glue->xceiv)) {
696+ ret = PTR_ERR(glue->xceiv);
697+ dev_err(&pdev->dev, "Error getting usb-phy %d\n", ret);
698+ goto err_unregister_usb_phy;
699+ }
700+
701+ platform_set_drvdata(pdev, glue);
702+
703+ memset(&pinfo, 0, sizeof(pinfo));
704+ pinfo.name = "musb-hdrc";
705+ pinfo.id = PLATFORM_DEVID_AUTO;
706+ pinfo.parent = &pdev->dev;
707+ pinfo.res = pdev->resource;
708+ pinfo.num_res = pdev->num_resources;
709+ pinfo.data = &pdata;
710+ pinfo.size_data = sizeof(pdata);
711+
712+ glue->musb = platform_device_register_full(&pinfo);
713+ if (IS_ERR(glue->musb)) {
714+ ret = PTR_ERR(glue->musb);
715+ dev_err(&pdev->dev, "Error registering musb dev: %d\n", ret);
716+ goto err_unregister_usb_phy;
717+ }
718+
719+ return 0;
720+
721+err_unregister_usb_phy:
722+ usb_phy_generic_unregister(glue->usb_phy);
723+ return ret;
724+}
725+
726+static int sunxi_musb_remove(struct platform_device *pdev)
727+{
728+ struct sunxi_glue *glue = platform_get_drvdata(pdev);
729+ struct platform_device *usb_phy = glue->usb_phy;
730+
731+ platform_device_unregister(glue->musb); /* Frees glue ! */
732+ usb_phy_generic_unregister(usb_phy);
733+
734+ return 0;
735+}
736+
737+static const struct of_device_id sunxi_musb_match[] = {
738+ { .compatible = "allwinner,sun4i-a10-musb", },
739+ { .compatible = "allwinner,sun6i-a31-musb", },
740+ { .compatible = "allwinner,sun8i-a33-musb", },
741+ {}
742+};
743+
744+static struct platform_driver sunxi_musb_driver = {
745+ .probe = sunxi_musb_probe,
746+ .remove = sunxi_musb_remove,
747+ .driver = {
748+ .name = "musb-sunxi",
749+ .of_match_table = sunxi_musb_match,
750+ },
751+};
752+module_platform_driver(sunxi_musb_driver);
753+
754+MODULE_DESCRIPTION("Allwinner sunxi MUSB Glue Layer");
755+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
756+MODULE_LICENSE("GPL v2");
drivers/usb/phy/Kconfig+14−0
@@ -152,6 +152,20 @@ config USB_MSM_OTG · 151 unmodified lines
152152 This driver is not supported on boards like trout which
153153 has an external PHY.
154154
155+config USB_QCOM_8X16_PHY
156+ tristate "Qualcomm APQ8016/MSM8916 on-chip USB PHY controller support"
157+ depends on ARCH_QCOM || COMPILE_TEST
158+ depends on RESET_CONTROLLER
159+ select USB_PHY
160+ select USB_ULPI_VIEWPORT
161+ help
162+ Enable this to support the USB transceiver on Qualcomm 8x16 chipsets.
163+ It handles PHY initialization, clock management, power management,
164+ and workarounds required after resetting the hardware.
165+
166+ To compile this driver as a module, choose M here: the
167+ module will be called phy-qcom-8x16-usb.
168+
155169 config USB_MV_OTG
156170 tristate "Marvell USB OTG support"
157171 depends on USB_EHCI_MV && USB_MV_UDC && PM
drivers/usb/phy/Makefile+1−0
@@ -20,6 +20,7 @@ obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o · 19 unmodified lines
2020 obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o
2121 obj-$(CONFIG_USB_ISP1301) += phy-isp1301.o
2222 obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
23+obj-$(CONFIG_USB_QCOM_8X16_PHY) += phy-qcom-8x16-usb.o
2324 obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o
2425 obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o
2526 obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
drivers/usb/phy/phy-generic.c+4−2
@@ -218,11 +218,13 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, · 217 unmodified lines
218218 clk_rate = 0;
219219
220220 needs_vcc = of_property_read_bool(node, "vcc-supply");
221− nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset");
221+ nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
222+ GPIOD_ASIS);
222223 err = PTR_ERR_OR_ZERO(nop->gpiod_reset);
223224 if (!err) {
224225 nop->gpiod_vbus = devm_gpiod_get_optional(dev,
225− "vbus-detect");
226+ "vbus-detect",
227+ GPIOD_ASIS);
226228 err = PTR_ERR_OR_ZERO(nop->gpiod_vbus);
227229 }
228230 } else if (pdata) {
drivers/usb/phy/phy-msm-usb.c+57−10
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818
1919 #include <linux/module.h>
2020 #include <linux/device.h>
21+#include <linux/gpio/consumer.h>
2122 #include <linux/platform_device.h>
2223 #include <linux/clk.h>
2324 #include <linux/slab.h>
@@ -32,6 +33,7 @@ · 8 unmodified lines
3233 #include <linux/pm_runtime.h>
3334 #include <linux/of.h>
3435 #include <linux/of_device.h>
36+#include <linux/reboot.h>
3537 #include <linux/reset.h>
3638
3739 #include <linux/usb.h>
@@ -1471,6 +1473,14 @@ static int msm_otg_vbus_notifier(struct notifier_block *nb, unsigned long event, · 1433 unmodified lines
14711473 else
14721474 clear_bit(B_SESS_VLD, &motg->inputs);
14731475
1476+ if (test_bit(B_SESS_VLD, &motg->inputs)) {
1477+ /* Switch D+/D- lines to Device connector */
1478+ gpiod_set_value_cansleep(motg->switch_gpio, 0);
1479+ } else {
1480+ /* Switch D+/D- lines to Hub */
1481+ gpiod_set_value_cansleep(motg->switch_gpio, 1);
1482+ }
1483+
14741484 schedule_work(&motg->sm_work);
14751485
14761486 return NOTIFY_DONE;
@@ -1546,6 +1556,11 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) · 69 unmodified lines
15461556
15471557 motg->manual_pullup = of_property_read_bool(node, "qcom,manual-pullup");
15481558
1559+ motg->switch_gpio = devm_gpiod_get_optional(&pdev->dev, "switch",
1560+ GPIOD_OUT_LOW);
1561+ if (IS_ERR(motg->switch_gpio))
1562+ return PTR_ERR(motg->switch_gpio);
1563+
15491564 ext_id = ERR_PTR(-ENODEV);
15501565 ext_vbus = ERR_PTR(-ENODEV);
15511566 if (of_property_read_bool(node, "extcon")) {
@@ -1561,15 +1576,16 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) · 9 unmodified lines
15611576 }
15621577
15631578 if (!IS_ERR(ext_vbus)) {
1579+ motg->vbus.extcon = ext_vbus;
15641580 motg->vbus.nb.notifier_call = msm_otg_vbus_notifier;
1565− ret = extcon_register_interest(&motg->vbus.conn, ext_vbus->name,
1566− "USB", &motg->vbus.nb);
1581+ ret = extcon_register_notifier(ext_vbus, EXTCON_USB,
1582+ &motg->vbus.nb);
15671583 if (ret < 0) {
15681584 dev_err(&pdev->dev, "register VBUS notifier failed\n");
15691585 return ret;
15701586 }
15711587
1572− ret = extcon_get_cable_state(ext_vbus, "USB");
1588+ ret = extcon_get_cable_state_(ext_vbus, EXTCON_USB);
15731589 if (ret)
15741590 set_bit(B_SESS_VLD, &motg->inputs);
15751591 else
@@ -1577,15 +1593,16 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) · 1 unmodified line
15771593 }
15781594
15791595 if (!IS_ERR(ext_id)) {
1596+ motg->id.extcon = ext_id;
15801597 motg->id.nb.notifier_call = msm_otg_id_notifier;
1581− ret = extcon_register_interest(&motg->id.conn, ext_id->name,
1582− "USB-HOST", &motg->id.nb);
1598+ ret = extcon_register_notifier(ext_id, EXTCON_USB_HOST,
1599+ &motg->id.nb);
15831600 if (ret < 0) {
15841601 dev_err(&pdev->dev, "register ID notifier failed\n");
15851602 return ret;
15861603 }
15871604
1588− ret = extcon_get_cable_state(ext_id, "USB-HOST");
1605+ ret = extcon_get_cable_state_(ext_id, EXTCON_USB_HOST);
15891606 if (ret)
15901607 clear_bit(ID, &motg->inputs);
15911608 else
@@ -1615,6 +1632,19 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) · 23 unmodified lines
16151632 return 0;
16161633 }
16171634
1635+static int msm_otg_reboot_notify(struct notifier_block *this,
1636+ unsigned long code, void *unused)
1637+{
1638+ struct msm_otg *motg = container_of(this, struct msm_otg, reboot);
1639+
1640+ /*
1641+ * Ensure that D+/D- lines are routed to uB connector, so
1642+ * we could load bootloader/kernel at next reboot
1643+ */
1644+ gpiod_set_value_cansleep(motg->switch_gpio, 0);
1645+ return NOTIFY_DONE;
1646+}
1647+
16181648 static int msm_otg_probe(struct platform_device *pdev)
16191649 {
16201650 struct regulator_bulk_data regs[3];
@@ -1779,6 +1809,17 @@ static int msm_otg_probe(struct platform_device *pdev) · 158 unmodified lines
17791809 dev_dbg(&pdev->dev, "Can not create mode change file\n");
17801810 }
17811811
1812+ if (test_bit(B_SESS_VLD, &motg->inputs)) {
1813+ /* Switch D+/D- lines to Device connector */
1814+ gpiod_set_value_cansleep(motg->switch_gpio, 0);
1815+ } else {
1816+ /* Switch D+/D- lines to Hub */
1817+ gpiod_set_value_cansleep(motg->switch_gpio, 1);
1818+ }
1819+
1820+ motg->reboot.notifier_call = msm_otg_reboot_notify;
1821+ register_reboot_notifier(&motg->reboot);
1822+
17821823 pm_runtime_set_active(&pdev->dev);
17831824 pm_runtime_enable(&pdev->dev);
17841825
@@ -1805,10 +1846,16 @@ static int msm_otg_remove(struct platform_device *pdev) · 20 unmodified lines
18051846 if (phy->otg->host || phy->otg->gadget)
18061847 return -EBUSY;
18071848
1808− if (motg->id.conn.edev)
1809− extcon_unregister_interest(&motg->id.conn);
1810− if (motg->vbus.conn.edev)
1811− extcon_unregister_interest(&motg->vbus.conn);
1849+ unregister_reboot_notifier(&motg->reboot);
1850+
1851+ /*
1852+ * Ensure that D+/D- lines are routed to uB connector, so
1853+ * we could load bootloader/kernel at next reboot
1854+ */
1855+ gpiod_set_value_cansleep(motg->switch_gpio, 0);
1856+
1857+ extcon_unregister_notifier(motg->id.extcon, EXTCON_USB_HOST, &motg->id.nb);
1858+ extcon_unregister_notifier(motg->vbus.extcon, EXTCON_USB, &motg->vbus.nb);
18121859
18131860 msm_otg_debugfs_cleanup();
18141861 cancel_delayed_work_sync(&motg->chg_work);
drivers/usb/phy/phy-omap-otg.c+11−11
@@ -30,8 +30,7 @@ struct otg_device { · 29 unmodified lines
3030 void __iomem *base;
3131 bool id;
3232 bool vbus;
33− struct extcon_specific_cable_nb vbus_dev;
34− struct extcon_specific_cable_nb id_dev;
33+ struct extcon_dev *extcon;
3534 struct notifier_block vbus_nb;
3635 struct notifier_block id_nb;
3736 };
@@ -106,6 +105,7 @@ static int omap_otg_probe(struct platform_device *pdev) · 68 unmodified lines
106105 extcon = extcon_get_extcon_dev(config->extcon);
107106 if (!extcon)
108107 return -EPROBE_DEFER;
108+ otg_dev->extcon = extcon;
109109
110110 otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL);
111111 if (!otg_dev)
@@ -118,20 +118,19 @@ static int omap_otg_probe(struct platform_device *pdev) · 6 unmodified lines
118118 otg_dev->id_nb.notifier_call = omap_otg_id_notifier;
119119 otg_dev->vbus_nb.notifier_call = omap_otg_vbus_notifier;
120120
121− ret = extcon_register_interest(&otg_dev->id_dev, config->extcon,
122− "USB-HOST", &otg_dev->id_nb);
121+ ret = extcon_register_notifier(extcon, EXTCON_USB_HOST, &otg_dev->id_nb);
123122 if (ret)
124123 return ret;
125124
126− ret = extcon_register_interest(&otg_dev->vbus_dev, config->extcon,
127− "USB", &otg_dev->vbus_nb);
125+ ret = extcon_register_notifier(extcon, EXTCON_USB, &otg_dev->vbus_nb);
128126 if (ret) {
129− extcon_unregister_interest(&otg_dev->id_dev);
127+ extcon_unregister_notifier(extcon, EXTCON_USB_HOST,
128+ &otg_dev->id_nb);
130129 return ret;
131130 }
132131
133− otg_dev->id = extcon_get_cable_state(extcon, "USB-HOST");
134− otg_dev->vbus = extcon_get_cable_state(extcon, "USB");
132+ otg_dev->id = extcon_get_cable_state_(extcon, EXTCON_USB_HOST);
133+ otg_dev->vbus = extcon_get_cable_state_(extcon, EXTCON_USB);
135134 omap_otg_set_mode(otg_dev);
136135
137136 rev = readl(otg_dev->base);
@@ -147,9 +146,10 @@ static int omap_otg_probe(struct platform_device *pdev) · 9 unmodified lines
147146 static int omap_otg_remove(struct platform_device *pdev)
148147 {
149148 struct otg_device *otg_dev = platform_get_drvdata(pdev);
149+ struct extcon_dev *edev = otg_dev->extcon;
150150
151− extcon_unregister_interest(&otg_dev->id_dev);
152− extcon_unregister_interest(&otg_dev->vbus_dev);
151+ extcon_unregister_notifier(edev, EXTCON_USB_HOST,&otg_dev->id_nb);
152+ extcon_unregister_notifier(edev, EXTCON_USB, &otg_dev->vbus_nb);
153153
154154 return 0;
155155 }
drivers/usb/phy/phy-qcom-8x16-usb.c+436−0
@@ -0,0 +1,436 @@
1+/*
2+ * Copyright (c) 2015, Linaro Limited
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License version 2 and
6+ * only version 2 as published by the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ */
13+
14+#include <linux/clk.h>
15+#include <linux/delay.h>
16+#include <linux/device.h>
17+#include <linux/err.h>
18+#include <linux/extcon.h>
19+#include <linux/gpio/consumer.h>
20+#include <linux/io.h>
21+#include <linux/module.h>
22+#include <linux/of.h>
23+#include <linux/platform_device.h>
24+#include <linux/reboot.h>
25+#include <linux/regulator/consumer.h>
26+#include <linux/reset.h>
27+#include <linux/slab.h>
28+#include <linux/usb.h>
29+#include <linux/usb/ulpi.h>
30+
31+#define HSPHY_AHBBURST 0x0090
32+#define HSPHY_AHBMODE 0x0098
33+#define HSPHY_GENCONFIG 0x009c
34+#define HSPHY_GENCONFIG_2 0x00a0
35+
36+#define HSPHY_USBCMD 0x0140
37+#define HSPHY_ULPI_VIEWPORT 0x0170
38+#define HSPHY_CTRL 0x0240
39+
40+#define HSPHY_TXFIFO_IDLE_FORCE_DIS BIT(4)
41+#define HSPHY_SESS_VLD_CTRL_EN BIT(7)
42+#define HSPHY_POR_ASSERT BIT(0)
43+#define HSPHY_RETEN BIT(1)
44+
45+#define HSPHY_SESS_VLD_CTRL BIT(25)
46+
47+#define ULPI_PWR_CLK_MNG_REG 0x88
48+#define ULPI_PWR_OTG_COMP_DISABLE BIT(0)
49+
50+#define ULPI_MISC_A 0x96
51+#define ULPI_MISC_A_VBUSVLDEXTSEL BIT(1)
52+#define ULPI_MISC_A_VBUSVLDEXT BIT(0)
53+
54+#define HSPHY_3P3_MIN 3050000 /* uV */
55+#define HSPHY_3P3_MAX 3300000 /* uV */
56+
57+#define HSPHY_1P8_MIN 1800000 /* uV */
58+#define HSPHY_1P8_MAX 1800000 /* uV */
59+
60+#define HSPHY_VDD_MIN 5
61+#define HSPHY_VDD_MAX 7
62+
63+struct phy_8x16 {
64+ struct usb_phy phy;
65+ void __iomem *regs;
66+ struct clk *core_clk;
67+ struct clk *iface_clk;
68+ struct regulator *v3p3;
69+ struct regulator *v1p8;
70+ struct regulator *vdd;
71+
72+ struct reset_control *phy_reset;
73+
74+ struct extcon_specific_cable_nb vbus_cable;
75+ struct notifier_block vbus_notify;
76+
77+ struct gpio_desc *switch_gpio;
78+ struct notifier_block reboot_notify;
79+};
80+
81+static int phy_8x16_regulators_enable(struct phy_8x16 *qphy)
82+{
83+ int ret;
84+
85+ ret = regulator_set_voltage(qphy->vdd, HSPHY_VDD_MIN, HSPHY_VDD_MAX);
86+ if (ret)
87+ return ret;
88+
89+ ret = regulator_enable(qphy->vdd);
90+ if (ret)
91+ return ret;
92+
93+ ret = regulator_set_voltage(qphy->v3p3, HSPHY_3P3_MIN, HSPHY_3P3_MAX);
94+ if (ret)
95+ goto off_vdd;
96+
97+ ret = regulator_enable(qphy->v3p3);
98+ if (ret)
99+ goto off_vdd;
100+
101+ ret = regulator_set_voltage(qphy->v1p8, HSPHY_1P8_MIN, HSPHY_1P8_MAX);
102+ if (ret)
103+ goto off_3p3;
104+
105+ ret = regulator_enable(qphy->v1p8);
106+ if (ret)
107+ goto off_3p3;
108+
109+ return 0;
110+
111+off_3p3:
112+ regulator_disable(qphy->v3p3);
113+off_vdd:
114+ regulator_disable(qphy->vdd);
115+
116+ return ret;
117+}
118+
119+static void phy_8x16_regulators_disable(struct phy_8x16 *qphy)
120+{
121+ regulator_disable(qphy->v1p8);
122+ regulator_disable(qphy->v3p3);
123+ regulator_disable(qphy->vdd);
124+}
125+
126+static int phy_8x16_notify_connect(struct usb_phy *phy,
127+ enum usb_device_speed speed)
128+{
129+ struct phy_8x16 *qphy = container_of(phy, struct phy_8x16, phy);
130+ u32 val;
131+
132+ val = ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT;
133+ usb_phy_io_write(&qphy->phy, val, ULPI_SET(ULPI_MISC_A));
134+
135+ val = readl(qphy->regs + HSPHY_USBCMD);
136+ val |= HSPHY_SESS_VLD_CTRL;
137+ writel(val, qphy->regs + HSPHY_USBCMD);
138+
139+ return 0;
140+}
141+
142+static int phy_8x16_notify_disconnect(struct usb_phy *phy,
143+ enum usb_device_speed speed)
144+{
145+ struct phy_8x16 *qphy = container_of(phy, struct phy_8x16, phy);
146+ u32 val;
147+
148+ val = ULPI_MISC_A_VBUSVLDEXT | ULPI_MISC_A_VBUSVLDEXTSEL;
149+ usb_phy_io_write(&qphy->phy, val, ULPI_CLR(ULPI_MISC_A));
150+
151+ val = readl(qphy->regs + HSPHY_USBCMD);
152+ val &= ~HSPHY_SESS_VLD_CTRL;
153+ writel(val, qphy->regs + HSPHY_USBCMD);
154+
155+ return 0;
156+}
157+
158+static int phy_8x16_vbus_on(struct phy_8x16 *qphy)
159+{
160+ phy_8x16_notify_connect(&qphy->phy, USB_SPEED_UNKNOWN);
161+
162+ /* Switch D+/D- lines to Device connector */
163+ gpiod_set_value_cansleep(qphy->switch_gpio, 0);
164+
165+ return 0;
166+}
167+
168+static int phy_8x16_vbus_off(struct phy_8x16 *qphy)
169+{
170+ phy_8x16_notify_disconnect(&qphy->phy, USB_SPEED_UNKNOWN);
171+
172+ /* Switch D+/D- lines to USB HUB */
173+ gpiod_set_value_cansleep(qphy->switch_gpio, 1);
174+
175+ return 0;
176+}
177+
178+static int phy_8x16_vbus_notify(struct notifier_block *nb, unsigned long event,
179+ void *ptr)
180+{
181+ struct phy_8x16 *qphy = container_of(nb, struct phy_8x16, vbus_notify);
182+
183+ if (event)
184+ phy_8x16_vbus_on(qphy);
185+ else
186+ phy_8x16_vbus_off(qphy);
187+
188+ return NOTIFY_DONE;
189+}
190+
191+static int phy_8x16_init(struct usb_phy *phy)
192+{
193+ struct phy_8x16 *qphy = container_of(phy, struct phy_8x16, phy);
194+ u32 val, init[] = {0x44, 0x6B, 0x24, 0x13};
195+ u32 addr = ULPI_EXT_VENDOR_SPECIFIC;
196+ int idx, state;
197+
198+ for (idx = 0; idx < ARRAY_SIZE(init); idx++)
199+ usb_phy_io_write(phy, init[idx], addr + idx);
200+
201+ reset_control_reset(qphy->phy_reset);
202+
203+ /* Assert USB HSPHY_POR */
204+ val = readl(qphy->regs + HSPHY_CTRL);
205+ val |= HSPHY_POR_ASSERT;
206+ writel(val, qphy->regs + HSPHY_CTRL);
207+
208+ /*
209+ * wait for minimum 10 microseconds as suggested in HPG.
210+ * Use a slightly larger value since the exact value didn't
211+ * work 100% of the time.
212+ */
213+ usleep_range(12, 15);
214+
215+ /* Deassert USB HSPHY_POR */
216+ val = readl(qphy->regs + HSPHY_CTRL);
217+ val &= ~HSPHY_POR_ASSERT;
218+ writel(val, qphy->regs + HSPHY_CTRL);
219+
220+ usleep_range(10, 15);
221+
222+ writel(0x00, qphy->regs + HSPHY_AHBBURST);
223+ writel(0x08, qphy->regs + HSPHY_AHBMODE);
224+
225+ /* workaround for rx buffer collision issue */
226+ val = readl(qphy->regs + HSPHY_GENCONFIG);
227+ val &= ~HSPHY_TXFIFO_IDLE_FORCE_DIS;
228+ writel(val, qphy->regs + HSPHY_GENCONFIG);
229+
230+ val = readl(qphy->regs + HSPHY_GENCONFIG_2);
231+ val |= HSPHY_SESS_VLD_CTRL_EN;
232+ writel(val, qphy->regs + HSPHY_GENCONFIG_2);
233+
234+ val = ULPI_PWR_OTG_COMP_DISABLE;
235+ usb_phy_io_write(phy, val, ULPI_SET(ULPI_PWR_CLK_MNG_REG));
236+
237+ state = extcon_get_cable_state(qphy->vbus_cable.edev, "USB");
238+ if (state)
239+ phy_8x16_vbus_on(qphy);
240+ else
241+ phy_8x16_vbus_off(qphy);
242+
243+ val = usb_phy_io_read(&qphy->phy, ULPI_FUNC_CTRL);
244+ val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
245+ val |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
246+ usb_phy_io_write(&qphy->phy, val, ULPI_FUNC_CTRL);
247+
248+ return 0;
249+}
250+
251+static void phy_8x16_shutdown(struct usb_phy *phy)
252+{
253+ u32 val;
254+
255+ /* Put the controller in non-driving mode */
256+ val = usb_phy_io_read(phy, ULPI_FUNC_CTRL);
257+ val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
258+ val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
259+ usb_phy_io_write(phy, val, ULPI_FUNC_CTRL);
260+}
261+
262+static int phy_8x16_read_devicetree(struct phy_8x16 *qphy)
263+{
264+ struct regulator_bulk_data regs[3];
265+ struct device *dev = qphy->phy.dev;
266+ int ret;
267+
268+ qphy->core_clk = devm_clk_get(dev, "core");
269+ if (IS_ERR(qphy->core_clk))
270+ return PTR_ERR(qphy->core_clk);
271+
272+ qphy->iface_clk = devm_clk_get(dev, "iface");
273+ if (IS_ERR(qphy->iface_clk))
274+ return PTR_ERR(qphy->iface_clk);
275+
276+ regs[0].supply = "v3p3";
277+ regs[1].supply = "v1p8";
278+ regs[2].supply = "vddcx";
279+
280+ ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(regs), regs);
281+ if (ret)
282+ return ret;
283+
284+ qphy->v3p3 = regs[0].consumer;
285+ qphy->v1p8 = regs[1].consumer;
286+ qphy->vdd = regs[2].consumer;
287+
288+ qphy->phy_reset = devm_reset_control_get(dev, "phy");
289+ if (IS_ERR(qphy->phy_reset))
290+ return PTR_ERR(qphy->phy_reset);
291+
292+ qphy->switch_gpio = devm_gpiod_get_optional(dev, "switch",
293+ GPIOD_OUT_LOW);
294+ if (IS_ERR(qphy->switch_gpio))
295+ return PTR_ERR(qphy->switch_gpio);
296+
297+ return 0;
298+}
299+
300+static int phy_8x16_reboot_notify(struct notifier_block *this,
301+ unsigned long code, void *unused)
302+{
303+ struct phy_8x16 *qphy;
304+
305+ qphy = container_of(this, struct phy_8x16, reboot_notify);
306+
307+ /*
308+ * Ensure that D+/D- lines are routed to uB connector, so
309+ * we could load bootloader/kernel at next reboot_notify
310+ */
311+ gpiod_set_value_cansleep(qphy->switch_gpio, 0);
312+ return NOTIFY_DONE;
313+}
314+
315+static int phy_8x16_probe(struct platform_device *pdev)
316+{
317+ struct extcon_dev *edev;
318+ struct phy_8x16 *qphy;
319+ struct resource *res;
320+ struct usb_phy *phy;
321+ int ret;
322+
323+ qphy = devm_kzalloc(&pdev->dev, sizeof(*qphy), GFP_KERNEL);
324+ if (!qphy)
325+ return -ENOMEM;
326+
327+ platform_set_drvdata(pdev, qphy);
328+
329+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
330+ if (!res)
331+ return -EINVAL;
332+
333+ qphy->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
334+ if (!qphy->regs)
335+ return -ENOMEM;
336+
337+ phy = &qphy->phy;
338+ phy->dev = &pdev->dev;
339+ phy->label = dev_name(&pdev->dev);
340+ phy->init = phy_8x16_init;
341+ phy->shutdown = phy_8x16_shutdown;
342+ phy->notify_connect = phy_8x16_notify_connect;
343+ phy->notify_disconnect = phy_8x16_notify_disconnect;
344+ phy->io_priv = qphy->regs + HSPHY_ULPI_VIEWPORT;
345+ phy->io_ops = &ulpi_viewport_access_ops;
346+ phy->type = USB_PHY_TYPE_USB2;
347+
348+ ret = phy_8x16_read_devicetree(qphy);
349+ if (ret < 0)
350+ return ret;
351+
352+ edev = extcon_get_edev_by_phandle(phy->dev, 0);
353+ if (IS_ERR(edev))
354+ return PTR_ERR(edev);
355+
356+ ret = clk_set_rate(qphy->core_clk, INT_MAX);
357+ if (ret < 0)
358+ dev_dbg(phy->dev, "Can't boost core clock\n");
359+
360+ ret = clk_prepare_enable(qphy->core_clk);
361+ if (ret < 0)
362+ return ret;
363+
364+ ret = clk_prepare_enable(qphy->iface_clk);
365+ if (ret < 0)
366+ goto off_core;
367+
368+ ret = phy_8x16_regulators_enable(qphy);
369+ if (0 && ret)
370+ goto off_clks;
371+
372+ qphy->vbus_notify.notifier_call = phy_8x16_vbus_notify;
373+ ret = extcon_register_interest(&qphy->vbus_cable, edev->name,
374+ "USB", &qphy->vbus_notify);
375+ if (ret < 0)
376+ goto off_power;
377+
378+ ret = usb_add_phy_dev(&qphy->phy);
379+ if (ret)
380+ goto off_extcon;
381+
382+ qphy->reboot_notify.notifier_call = phy_8x16_reboot_notify;
383+ register_reboot_notifier(&qphy->reboot_notify);
384+
385+ return 0;
386+
387+off_extcon:
388+ extcon_unregister_interest(&qphy->vbus_cable);
389+off_power:
390+ phy_8x16_regulators_disable(qphy);
391+off_clks:
392+ clk_disable_unprepare(qphy->iface_clk);
393+off_core:
394+ clk_disable_unprepare(qphy->core_clk);
395+ return ret;
396+}
397+
398+static int phy_8x16_remove(struct platform_device *pdev)
399+{
400+ struct phy_8x16 *qphy = platform_get_drvdata(pdev);
401+
402+ unregister_reboot_notifier(&qphy->reboot_notify);
403+ extcon_unregister_interest(&qphy->vbus_cable);
404+
405+ /*
406+ * Ensure that D+/D- lines are routed to uB connector, so
407+ * we could load bootloader/kernel at next reboot_notify
408+ */
409+ gpiod_set_value_cansleep(qphy->switch_gpio, 0);
410+
411+ usb_remove_phy(&qphy->phy);
412+
413+ clk_disable_unprepare(qphy->iface_clk);
414+ clk_disable_unprepare(qphy->core_clk);
415+ phy_8x16_regulators_disable(qphy);
416+ return 0;
417+}
418+
419+static const struct of_device_id phy_8x16_dt_match[] = {
420+ { .compatible = "qcom,usb-8x16-phy" },
421+ { }
422+};
423+MODULE_DEVICE_TABLE(of, phy_8x16_dt_match);
424+
425+static struct platform_driver phy_8x16_driver = {
426+ .probe = phy_8x16_probe,
427+ .remove = phy_8x16_remove,
428+ .driver = {
429+ .name = "phy-qcom-8x16-usb",
430+ .of_match_table = phy_8x16_dt_match,
431+ },
432+};
433+module_platform_driver(phy_8x16_driver);
434+
435+MODULE_LICENSE("GPL v2");
436+MODULE_DESCRIPTION("Qualcomm APQ8016/MSM8916 chipsets USB transceiver driver");
drivers/usb/phy/phy-tahvo.c+13−14
@@ -57,7 +57,7 @@ struct tahvo_usb { · 56 unmodified lines
5757 struct clk *ick;
5858 int irq;
5959 int tahvo_mode;
60− struct extcon_dev extcon;
60+ struct extcon_dev *extcon;
6161 };
6262
6363 static const unsigned int tahvo_cable[] = {
@@ -121,7 +121,7 @@ static void check_vbus_state(struct tahvo_usb *tu) · 57 unmodified lines
121121 prev_state = tu->vbus_state;
122122 tu->vbus_state = reg & TAHVO_STAT_VBUS;
123123 if (prev_state != tu->vbus_state) {
124− extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
124+ extcon_set_cable_state_(tu->extcon, EXTCON_USB, tu->vbus_state);
125125 sysfs_notify(&tu->pt_dev->dev.kobj, NULL, "vbus_state");
126126 }
127127 }
@@ -130,7 +130,7 @@ static void tahvo_usb_become_host(struct tahvo_usb *tu) · 2 unmodified lines
130130 {
131131 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
132132
133− extcon_set_cable_state(&tu->extcon, "USB-HOST", true);
133+ extcon_set_cable_state_(tu->extcon, EXTCON_USB_HOST, true);
134134
135135 /* Power up the transceiver in USB host mode */
136136 retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
@@ -149,7 +149,7 @@ static void tahvo_usb_become_peripheral(struct tahvo_usb *tu) · 12 unmodified lines
149149 {
150150 struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
151151
152− extcon_set_cable_state(&tu->extcon, "USB-HOST", false);
152+ extcon_set_cable_state_(tu->extcon, EXTCON_USB_HOST, false);
153153
154154 /* Power up transceiver and set it in USB peripheral mode */
155155 retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT |
@@ -365,11 +365,13 @@ static int tahvo_usb_probe(struct platform_device *pdev) · 209 unmodified lines
365365 */
366366 tu->vbus_state = retu_read(rdev, TAHVO_REG_IDSR) & TAHVO_STAT_VBUS;
367367
368− tu->extcon.name = DRIVER_NAME;
369− tu->extcon.supported_cable = tahvo_cable;
370− tu->extcon.dev.parent = &pdev->dev;
368+ tu->extcon = devm_extcon_dev_allocate(&pdev->dev, tahvo_cable);
369+ if (IS_ERR(tu->extcon)) {
370+ dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
371+ return -ENOMEM;
372+ }
371373
372− ret = extcon_dev_register(&tu->extcon);
374+ ret = devm_extcon_dev_register(&pdev->dev, tu->extcon);
373375 if (ret) {
374376 dev_err(&pdev->dev, "could not register extcon device: %d\n",
375377 ret);
@@ -377,9 +379,9 @@ static int tahvo_usb_probe(struct platform_device *pdev) · 1 unmodified line
377379 }
378380
379381 /* Set the initial cable state. */
380− extcon_set_cable_state(&tu->extcon, "USB-HOST",
382+ extcon_set_cable_state_(tu->extcon, EXTCON_USB_HOST,
381383 tu->tahvo_mode == TAHVO_MODE_HOST);
382− extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
384+ extcon_set_cable_state_(tu->extcon, EXTCON_USB, tu->vbus_state);
383385
384386 /* Create OTG interface */
385387 tahvo_usb_power_off(tu);
@@ -396,7 +398,7 @@ static int tahvo_usb_probe(struct platform_device *pdev) · 10 unmodified lines
396398 if (ret < 0) {
397399 dev_err(&pdev->dev, "cannot register USB transceiver: %d\n",
398400 ret);
399− goto err_extcon_unreg;
401+ goto err_disable_clk;
400402 }
401403
402404 dev_set_drvdata(&pdev->dev, tu);
@@ -424,8 +426,6 @@ err_free_irq: · 21 unmodified lines
424426 free_irq(tu->irq, tu);
425427 err_remove_phy:
426428 usb_remove_phy(&tu->phy);
427−err_extcon_unreg:
428− extcon_dev_unregister(&tu->extcon);
429429 err_disable_clk:
430430 if (!IS_ERR(tu->ick))
431431 clk_disable(tu->ick);
@@ -440,7 +440,6 @@ static int tahvo_usb_remove(struct platform_device *pdev) · 8 unmodified lines
440440 sysfs_remove_group(&pdev->dev.kobj, &tahvo_attr_group);
441441 free_irq(tu->irq, tu);
442442 usb_remove_phy(&tu->phy);
443− extcon_dev_unregister(&tu->extcon);
444443 if (!IS_ERR(tu->ick))
445444 clk_disable(tu->ick);
446445
drivers/usb/renesas_usbhs/common.c+1−1
@@ -388,7 +388,7 @@ static void usbhsc_hotplug(struct usbhs_priv *priv) · 387 unmodified lines
388388
389389 if (enable && !mod) {
390390 if (priv->edev) {
391− cable = extcon_get_cable_state(priv->edev, "USB-HOST");
391+ cable = extcon_get_cable_state_(priv->edev, EXTCON_USB_HOST);
392392 if ((cable > 0 && id != USBHS_HOST) ||
393393 (!cable && id != USBHS_GADGET)) {
394394 dev_info(&pdev->dev,
drivers/usb/renesas_usbhs/mod_gadget.c+7−1
@@ -52,7 +52,7 @@ struct usbhsg_gpriv { · 51 unmodified lines
5252
5353 struct usb_gadget_driver *driver;
5454 struct usb_phy *transceiver;
55− bool vbus_active;
55+ bool vbus_active;
5656
5757 u32 status;
5858 #define USBHSG_STATUS_STARTED (1 << 0)
@@ -1103,12 +1103,18 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv) · 1044 unmodified lines
11031103 if (usbhsg_is_dcp(uep)) {
11041104 gpriv->gadget.ep0 = &uep->ep;
11051105 usb_ep_set_maxpacket_limit(&uep->ep, 64);
1106+ uep->ep.caps.type_control = true;
11061107 }
11071108 /* init normal pipe */
11081109 else {
11091110 usb_ep_set_maxpacket_limit(&uep->ep, 512);
1111+ uep->ep.caps.type_iso = true;
1112+ uep->ep.caps.type_bulk = true;
1113+ uep->ep.caps.type_int = true;
11101114 list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list);
11111115 }
1116+ uep->ep.caps.dir_in = true;
1117+ uep->ep.caps.dir_out = true;
11121118 }
11131119
11141120 ret = usb_add_gadget_udc(dev, &gpriv->gadget);
include/linux/usb/chipidea.h+1−0
@@ -34,6 +34,7 @@ struct ci_hdrc_platform_data { · 33 unmodified lines
3434 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
3535 void (*notify_event) (struct ci_hdrc *ci, unsigned event);
3636 struct regulator *reg_vbus;
37+ struct usb_otg_caps ci_otg_caps;
3738 bool tpl_support;
3839 };
3940
include/linux/usb/composite.h+2−0
@@ -228,6 +228,8 @@ struct usb_function { · 227 unmodified lines
228228 struct list_head list;
229229 DECLARE_BITMAP(endpoints, 32);
230230 const struct usb_function_instance *fi;
231+
232+ unsigned int bind_deactivated:1;
231233 };
232234
233235 int usb_add_function(struct usb_configuration *, struct usb_function *);
include/linux/usb/gadget.h+191−7
@@ -140,11 +140,50 @@ struct usb_ep_ops { · 139 unmodified lines
140140 void (*fifo_flush) (struct usb_ep *ep);
141141 };
142142
143+/**
144+ * struct usb_ep_caps - endpoint capabilities description
145+ * @type_control:Endpoint supports control type (reserved for ep0).
146+ * @type_iso:Endpoint supports isochronous transfers.
147+ * @type_bulk:Endpoint supports bulk transfers.
148+ * @type_int:Endpoint supports interrupt transfers.
149+ * @dir_in:Endpoint supports IN direction.
150+ * @dir_out:Endpoint supports OUT direction.
151+ */
152+struct usb_ep_caps {
153+ unsigned type_control:1;
154+ unsigned type_iso:1;
155+ unsigned type_bulk:1;
156+ unsigned type_int:1;
157+ unsigned dir_in:1;
158+ unsigned dir_out:1;
159+};
160+
161+#define USB_EP_CAPS_TYPE_CONTROL 0x01
162+#define USB_EP_CAPS_TYPE_ISO 0x02
163+#define USB_EP_CAPS_TYPE_BULK 0x04
164+#define USB_EP_CAPS_TYPE_INT 0x08
165+#define USB_EP_CAPS_TYPE_ALL \
166+ (USB_EP_CAPS_TYPE_ISO | USB_EP_CAPS_TYPE_BULK | USB_EP_CAPS_TYPE_INT)
167+#define USB_EP_CAPS_DIR_IN 0x01
168+#define USB_EP_CAPS_DIR_OUT 0x02
169+#define USB_EP_CAPS_DIR_ALL (USB_EP_CAPS_DIR_IN | USB_EP_CAPS_DIR_OUT)
170+
171+#define USB_EP_CAPS(_type, _dir) \
172+ { \
173+ .type_control = !!(_type & USB_EP_CAPS_TYPE_CONTROL), \
174+ .type_iso = !!(_type & USB_EP_CAPS_TYPE_ISO), \
175+ .type_bulk = !!(_type & USB_EP_CAPS_TYPE_BULK), \
176+ .type_int = !!(_type & USB_EP_CAPS_TYPE_INT), \
177+ .dir_in = !!(_dir & USB_EP_CAPS_DIR_IN), \
178+ .dir_out = !!(_dir & USB_EP_CAPS_DIR_OUT), \
179+ }
180+
143181 /**
144182 * struct usb_ep - device side representation of USB endpoint
145183 * @name:identifier for the endpoint, such as "ep-a" or "ep9in-bulk"
146184 * @ops: Function pointers used to access hardware-specific operations.
147185 * @ep_list:the gadget's ep_list holds all of its endpoints
186+ * @caps:The structure describing types and directions supported by endoint.
148187 * @maxpacket:The maximum packet size used on this endpoint. The initial
149188 * value can sometimes be reduced (hardware allowing), according to
150189 * the endpoint descriptor used to configure the endpoint.
@@ -167,12 +206,15 @@ struct usb_ep_ops { · 16 unmodified lines
167206 * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list,
168207 * and is accessed only in response to a driver setup() callback.
169208 */
209+
170210 struct usb_ep {
171211 void *driver_data;
172212
173213 const char *name;
174214 const struct usb_ep_ops *ops;
175215 struct list_head ep_list;
216+ struct usb_ep_caps caps;
217+ bool claimed;
176218 unsigned maxpacket:16;
177219 unsigned maxpacket_limit:16;
178220 unsigned max_streams:16;
@@ -492,6 +534,9 @@ struct usb_gadget_ops { · 313 unmodified lines
492534 int (*udc_start)(struct usb_gadget *,
493535 struct usb_gadget_driver *);
494536 int (*udc_stop)(struct usb_gadget *);
537+ struct usb_ep *(*match_ep)(struct usb_gadget *,
538+ struct usb_endpoint_descriptor *,
539+ struct usb_ss_ep_comp_descriptor *);
495540 };
496541
497542 /**
@@ -511,6 +556,7 @@ struct usb_gadget_ops { · 13 unmodified lines
511556 * @dev: Driver model state for this abstract device.
512557 * @out_epnum: last used out ep number
513558 * @in_epnum: last used in ep number
559+ * @otg_caps: OTG capabilities of this gadget.
514560 * @sg_supported: true if we can handle scatter-gather
515561 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
516562 * gadget driver must provide a USB OTG descriptor.
@@ -526,6 +572,9 @@ struct usb_gadget_ops { · 9 unmodified lines
526572 * @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to
527573 * MaxPacketSize.
528574 * @is_selfpowered: if the gadget is self-powered.
575+ * @deactivated: True if gadget is deactivated - in deactivated state it cannot
576+ * be connected.
577+ * @connected: True if gadget is connected.
529578 *
530579 * Gadgets have a mostly-portable "gadget driver" implementing device
531580 * functions, handling all usb configurations and interfaces. Gadget
@@ -559,6 +608,7 @@ struct usb_gadget { · 27 unmodified lines
559608 struct device dev;
560609 unsigned out_epnum;
561610 unsigned in_epnum;
611+ struct usb_otg_caps *otg_caps;
562612
563613 unsigned sg_supported:1;
564614 unsigned is_otg:1;
@@ -567,7 +617,12 @@ struct usb_gadget { · 2 unmodified lines
567617 unsigned a_hnp_support:1;
568618 unsigned a_alt_hnp_support:1;
569619 unsigned quirk_ep_out_aligned_size:1;
620+ unsigned quirk_altset_not_supp:1;
621+ unsigned quirk_stall_not_supp:1;
622+ unsigned quirk_zlp_not_supp:1;
570623 unsigned is_selfpowered:1;
624+ unsigned deactivated:1;
625+ unsigned connected:1;
571626 };
572627 #define work_to_gadget(w) (container_of((w), struct usb_gadget, work))
573628
@@ -584,7 +639,6 @@ static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev) · 10 unmodified lines
584639 #define gadget_for_each_ep(tmp, gadget) \
585640 list_for_each_entry(tmp, &(gadget)->ep_list, ep_list)
586641
587−
588642 /**
589643 * usb_ep_align_maybe - returns @len aligned to ep's maxpacketsize if gadget
590644 * requires quirk_ep_out_aligned_size, otherwise reguens len.
@@ -602,6 +656,34 @@ usb_ep_align_maybe(struct usb_gadget *g, struct usb_ep *ep, size_t len) · 11 unmodified lines
602656 round_up(len, (size_t)ep->desc->wMaxPacketSize);
603657 }
604658
659+/**
660+ * gadget_is_altset_supported - return true iff the hardware supports
661+ * altsettings
662+ * @g: controller to check for quirk
663+ */
664+static inline int gadget_is_altset_supported(struct usb_gadget *g)
665+{
666+ return !g->quirk_altset_not_supp;
667+}
668+
669+/**
670+ * gadget_is_stall_supported - return true iff the hardware supports stalling
671+ * @g: controller to check for quirk
672+ */
673+static inline int gadget_is_stall_supported(struct usb_gadget *g)
674+{
675+ return !g->quirk_stall_not_supp;
676+}
677+
678+/**
679+ * gadget_is_zlp_supported - return true iff the hardware supports zlp
680+ * @g: controller to check for quirk
681+ */
682+static inline int gadget_is_zlp_supported(struct usb_gadget *g)
683+{
684+ return !g->quirk_zlp_not_supp;
685+}
686+
605687 /**
606688 * gadget_is_dualspeed - return true iff the hardware handles high speed
607689 * @g: controller that might support both high and full speeds
@@ -771,9 +853,24 @@ static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) · 163 unmodified lines
771853 */
772854 static inline int usb_gadget_connect(struct usb_gadget *gadget)
773855 {
856+ int ret;
857+
774858 if (!gadget->ops->pullup)
775859 return -EOPNOTSUPP;
776− return gadget->ops->pullup(gadget, 1);
860+
861+ if (gadget->deactivated) {
862+ /*
863+ * If gadget is deactivated we only save new state.
864+ * Gadget will be connected automatically after activation.
865+ */
866+ gadget->connected = true;
867+ return 0;
868+ }
869+
870+ ret = gadget->ops->pullup(gadget, 1);
871+ if (!ret)
872+ gadget->connected = 1;
873+ return ret;
777874 }
778875
779876 /**
@@ -784,20 +881,88 @@ static inline int usb_gadget_connect(struct usb_gadget *gadget) · 4 unmodified lines
784881 * as a disconnect (when a VBUS session is active). Not all systems
785882 * support software pullup controls.
786883 *
884+ * Returns zero on success, else negative errno.
885+ */
886+static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
887+{
888+ int ret;
889+
890+ if (!gadget->ops->pullup)
891+ return -EOPNOTSUPP;
892+
893+ if (gadget->deactivated) {
894+ /*
895+ * If gadget is deactivated we only save new state.
896+ * Gadget will stay disconnected after activation.
897+ */
898+ gadget->connected = false;
899+ return 0;
900+ }
901+
902+ ret = gadget->ops->pullup(gadget, 0);
903+ if (!ret)
904+ gadget->connected = 0;
905+ return ret;
906+}
907+
908+/**
909+ * usb_gadget_deactivate - deactivate function which is not ready to work
910+ * @gadget: the peripheral being deactivated
911+ *
787912 * This routine may be used during the gadget driver bind() call to prevent
788913 * the peripheral from ever being visible to the USB host, unless later
789− * usb_gadget_connect() is called. For example, user mode components may
914+ * usb_gadget_activate() is called. For example, user mode components may
790915 * need to be activated before the system can talk to hosts.
791916 *
792917 * Returns zero on success, else negative errno.
793918 */
794−static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
919+static inline int usb_gadget_deactivate(struct usb_gadget *gadget)
795920 {
796− if (!gadget->ops->pullup)
797− return -EOPNOTSUPP;
798− return gadget->ops->pullup(gadget, 0);
921+ int ret;
922+
923+ if (gadget->deactivated)
924+ return 0;
925+
926+ if (gadget->connected) {
927+ ret = usb_gadget_disconnect(gadget);
928+ if (ret)
929+ return ret;
930+ /*
931+ * If gadget was being connected before deactivation, we want
932+ * to reconnect it in usb_gadget_activate().
933+ */
934+ gadget->connected = true;
935+ }
936+ gadget->deactivated = true;
937+
938+ return 0;
799939 }
800940
941+/**
942+ * usb_gadget_activate - activate function which is not ready to work
943+ * @gadget: the peripheral being activated
944+ *
945+ * This routine activates gadget which was previously deactivated with
946+ * usb_gadget_deactivate() call. It calls usb_gadget_connect() if needed.
947+ *
948+ * Returns zero on success, else negative errno.
949+ */
950+static inline int usb_gadget_activate(struct usb_gadget *gadget)
951+{
952+ if (!gadget->deactivated)
953+ return 0;
954+
955+ gadget->deactivated = false;
956+
957+ /*
958+ * If gadget has been connected before deactivation, or became connected
959+ * while it was being deactivated, we call usb_gadget_connect().
960+ */
961+ if (gadget->connected)
962+ return usb_gadget_connect(gadget);
963+
964+ return 0;
965+}
801966
802967 /*-------------------------------------------------------------------------*/
803968
@@ -1002,6 +1167,10 @@ int usb_assign_descriptors(struct usb_function *f, · 198 unmodified lines
10021167 struct usb_descriptor_header **ss);
10031168 void usb_free_all_descriptors(struct usb_function *f);
10041169
1170+struct usb_descriptor_header *usb_otg_descriptor_alloc(
1171+ struct usb_gadget *gadget);
1172+int usb_otg_descriptor_init(struct usb_gadget *gadget,
1173+ struct usb_descriptor_header *otg_desc);
10051174 /*-------------------------------------------------------------------------*/
10061175
10071176 /* utility to simplify map/unmap of usb_requests to/from DMA */
@@ -1034,6 +1203,21 @@ extern void usb_gadget_giveback_request(struct usb_ep *ep, · 26 unmodified lines
10341203
10351204 /*-------------------------------------------------------------------------*/
10361205
1206+/* utility to find endpoint by name */
1207+
1208+extern struct usb_ep *gadget_find_ep_by_name(struct usb_gadget *g,
1209+ const char *name);
1210+
1211+/*-------------------------------------------------------------------------*/
1212+
1213+/* utility to check if endpoint caps match descriptor needs */
1214+
1215+extern int usb_gadget_ep_match_desc(struct usb_gadget *gadget,
1216+ struct usb_ep *ep, struct usb_endpoint_descriptor *desc,
1217+ struct usb_ss_ep_comp_descriptor *ep_comp);
1218+
1219+/*-------------------------------------------------------------------------*/
1220+
10371221 /* utility to update vbus status for udc core, it may be scheduled */
10381222 extern void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status);
10391223
include/linux/usb/msm_hsusb.h+8−1
@@ -128,7 +128,7 @@ struct msm_otg_platform_data { · 127 unmodified lines
128128 */
129129 struct msm_usb_cable {
130130 struct notifier_block nb;
131− struct extcon_specific_cable_nb conn;
131+ struct extcon_dev *extcon;
132132 };
133133
134134 /**
@@ -155,6 +155,10 @@ struct msm_usb_cable { · 20 unmodified lines
155155 * starting controller using usbcmd run/stop bit.
156156 * @vbus: VBUS signal state trakining, using extcon framework
157157 * @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
158162 */
159163 struct msm_otg {
160164 struct usb_phy phy;
@@ -188,6 +192,9 @@ struct msm_otg { · 27 unmodified lines
188192
189193 struct msm_usb_cable vbus;
190194 struct msm_usb_cable id;
195+
196+ struct gpio_desc *switch_gpio;
197+ struct notifier_block reboot;
191198 };
192199
193200 #endif
include/linux/usb/of.h+7−0
@@ -15,6 +15,8 @@ · 14 unmodified lines
1515 enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
1616 enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
1717 bool of_usb_host_tpl_support(struct device_node *np);
18+int of_usb_update_otg_caps(struct device_node *np,
19+ struct usb_otg_caps *otg_caps);
1820 #else
1921 static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
2022 {
@@ -30,6 +32,11 @@ static inline bool of_usb_host_tpl_support(struct device_node *np) · 9 unmodified lines
3032 {
3133 return false;
3234 }
35+static inline int of_usb_update_otg_caps(struct device_node *np,
36+ struct usb_otg_caps *otg_caps)
37+{
38+ return 0;
39+}
3340 #endif
3441
3542 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)
include/linux/usb/otg.h+15−0
@@ -41,6 +41,21 @@ struct usb_otg { · 40 unmodified lines
4141
4242 };
4343
44+/**
45+ * struct usb_otg_caps - describes the otg capabilities of the device
46+ * @otg_rev: The OTG revision number the device is compliant with, it's
47+ * in binary-coded decimal (i.e. 2.0 is 0200H).
48+ * @hnp_support: Indicates if the device supports HNP.
49+ * @srp_support: Indicates if the device supports SRP.
50+ * @adp_support: Indicates if the device supports ADP.
51+ */
52+struct usb_otg_caps {
53+ u16 otg_rev;
54+ bool hnp_support;
55+ bool srp_support;
56+ bool adp_support;
57+};
58+
4459 extern const char *usb_otg_state_string(enum usb_otg_state state);
4560
4661 /* Context: can sleep */
include/uapi/linux/usb/ch9.h+12−0
@@ -674,9 +674,21 @@ struct usb_otg_descriptor { · 673 unmodified lines
674674 __u8 bmAttributes; /* support for HNP, SRP, etc */
675675 } __attribute__ ((packed));
676676
677+/* USB_DT_OTG (from OTG 2.0 supplement) */
678+struct usb_otg20_descriptor {
679+ __u8 bLength;
680+ __u8 bDescriptorType;
681+
682+ __u8 bmAttributes; /* support for HNP, SRP and ADP, etc */
683+ __le16 bcdOTG; /* OTG and EH supplement release number
684+ * in binary-coded decimal(i.e. 2.0 is 0200H)
685+ */
686+} __attribute__ ((packed));
687+
677688 /* from usb_otg_descriptor.bmAttributes */
678689 #define USB_OTG_SRP (1 << 0)
679690 #define USB_OTG_HNP (1 << 1) /* swap host/device roles */
691+#define USB_OTG_ADP (1 << 2) /* support ADP */
680692
681693 /*-------------------------------------------------------------------------*/
682694