History

Merge tag 'usb-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB updates from Greg KH: "Here is the big USB driver update for 3.17-rc1. Loads of gadget driver changes in here, including some big file movements to make things easier to manage over time. There's also the usual xhci and uas driver updates, and a handful of other changes in here. The changelog has the full details. All of these have been in linux-next for a while" * tag 'usb-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (211 commits) USB: devio: fix issue with log flooding uas: Log a warning when we cannot use uas because the hcd lacks streams uas: Only complain about missing sg if all other checks succeed xhci: Add missing checks for xhci_alloc_command failure xhci: Rename Asrock P67 pci product-id to EJ168 xhci: Blacklist using streams on the Etron EJ168 controller uas: Limit qdepth to 32 when connected over usb-2 uwb/whci: use correct structure type name in sizeof usb-core bInterval quirk USB: serial: ftdi_sio: Add support for new Xsens devices USB: serial: ftdi_sio: Annotate the current Xsens PID assignments usb: chipidea: debug: fix sparse non static symbol warnings usb: ci_hdrc_imx doc: fsl,usbphy is required usb: ci_hdrc_imx: Return -EINVAL for missing USB PHY usb: core: allow zero packet flag for interrupt urbs usb: lvstest: Fix sparse warnings generated by kbuild test bot USB: core: hcd-pci: free IRQ before disabling PCI device when shutting down phy: miphy365x: Represent each PHY channel as a DT subnode phy: miphy365x: Provide support for the MiPHY356x Generic PHY phy: miphy365x: Add Device Tree bindings for the MiPHY365x ...

Linus Torvalds committed 12 years ago

Commit ae9b4752 parents 79eb238 d310d05267 files · +11203 −5803Browse files

Unified · Split

267 files
  1. Documentation/ABI/stable/sysfs-bus-usb +7 −7
  2. Documentation/ABI/testing/sysfs-bus-usb-lvstest +47 −0
  3. Documentation/DocBook/gadget.tmpl +5 −5
  4. Documentation/devicetree/bindings/phy/berlin-sata-phy.txt +34 −0
  5. Documentation/devicetree/bindings/phy/hix5hd2-phy.txt +22 −0
  6. Documentation/devicetree/bindings/phy/phy-bindings.txt +4 −0
  7. Documentation/devicetree/bindings/phy/phy-miphy365x.txt +76 −0
  8. Documentation/devicetree/bindings/phy/qcom-apq8064-sata-phy.txt +24 −0
  9. Documentation/devicetree/bindings/phy/qcom-ipq806x-sata-phy.txt +23 −0
  10. Documentation/devicetree/bindings/phy/samsung-phy.txt +2 −0
  11. Documentation/devicetree/bindings/phy/ti-phy.txt +16 −7
  12. Documentation/devicetree/bindings/usb/ci-hdrc-imx.txt +1 −1
  13. Documentation/devicetree/bindings/usb/nvidia,tegra20-usb-phy.txt +8 −0
  14. Documentation/devicetree/bindings/usb/usb-xhci.txt +2 −1
  15. Documentation/phy.txt +6 −4
  16. Documentation/usb/hotplug.txt +4 −4
  17. Documentation/usb/power-management.txt +243 −2
  18. arch/arm/boot/dts/tegra114.dtsi +5 −0
  19. arch/arm/boot/dts/tegra124.dtsi +7 −0
  20. arch/arm/boot/dts/tegra20.dtsi +7 −0
  21. arch/arm/boot/dts/tegra30.dtsi +7 −0
  22. drivers/phy/Kconfig +53 −25
  23. drivers/phy/Makefile +5 −0
  24. drivers/phy/phy-bcm-kona-usb2.c +1 −1
  25. drivers/phy/phy-berlin-sata.c +284 −0
  26. drivers/phy/phy-core.c +49 −7
  27. drivers/phy/phy-exynos-dp-video.c +3 −4
  28. drivers/phy/phy-exynos-mipi-video.c +3 −4
  29. drivers/phy/phy-exynos4x12-usb2.c +88 −37
  30. drivers/phy/phy-exynos5-usbdrd.c +5 −4
  31. drivers/phy/phy-exynos5250-sata.c +1 −1
  32. drivers/phy/phy-exynos5250-usb2.c +0 −2
  33. drivers/phy/phy-hix5hd2-sata.c +192 −0
  34. drivers/phy/phy-miphy365x.c +636 −0
  35. drivers/phy/phy-mvebu-sata.c +1 −1
  36. drivers/phy/phy-omap-control.c +51 −1
  37. drivers/phy/phy-omap-usb2.c +1 −1
  38. drivers/phy/phy-qcom-apq8064-sata.c +289 −0
  39. drivers/phy/phy-qcom-ipq806x-sata.c +211 −0
  40. drivers/phy/phy-samsung-usb2.c +8 −1
  41. drivers/phy/phy-samsung-usb2.h +4 −1
  42. drivers/phy/phy-sun4i-usb.c +3 −4
  43. drivers/phy/phy-ti-pipe3.c +85 −22
  44. drivers/phy/phy-twl4030-usb.c +1 −1
  45. drivers/phy/phy-xgene.c +1 −1
  46. drivers/usb/chipidea/ci_hdrc_imx.c +3 −0
  47. drivers/usb/chipidea/debug.c +2 −2
  48. drivers/usb/class/usbtmc.c +1 −1
  49. drivers/usb/core/config.c +11 −0
  50. drivers/usb/core/devio.c +1 −1
  51. drivers/usb/core/driver.c +4 −3
  52. drivers/usb/core/hcd-pci.c +2 −0
  53. drivers/usb/core/hcd.c +0 −4
  54. drivers/usb/core/hub.c +78 −16
  55. drivers/usb/core/hub.h +2 −0
  56. drivers/usb/core/port.c +12 −9
  57. drivers/usb/core/quirks.c +7 −0
  58. drivers/usb/core/urb.c +1 −0
  59. drivers/usb/core/usb.c +1 −0
  60. drivers/usb/dwc2/gadget.c +4 −8
  61. drivers/usb/dwc3/Kconfig +7 −0
  62. drivers/usb/dwc3/core.c +32 −19
  63. drivers/usb/dwc3/core.h +13 −0
  64. drivers/usb/dwc3/dwc3-omap.c +86 −86
  65. drivers/usb/dwc3/gadget.c +3 −4
  66. drivers/usb/dwc3/host.c +14 −0
  67. drivers/usb/gadget/Kconfig +2 −822
  68. drivers/usb/gadget/Makefile +4 −97
  69. drivers/usb/gadget/composite.c +1 −0
  70. drivers/usb/gadget/configfs.c +1 −3
  71. drivers/usb/gadget/function/Makefile +34 −0
  72. drivers/usb/gadget/function/f_acm.c +0 −0
  73. drivers/usb/gadget/function/f_ecm.c +0 −0
  74. drivers/usb/gadget/function/f_eem.c +10 −12
  75. drivers/usb/gadget/function/f_fs.c +339 −13
  76. drivers/usb/gadget/function/f_hid.c +0 −0
  77. drivers/usb/gadget/function/f_loopback.c +0 −0
  78. drivers/usb/gadget/function/f_mass_storage.c +0 −0
  79. drivers/usb/gadget/function/f_mass_storage.h +0 −0
  80. drivers/usb/gadget/function/f_midi.c +0 −0
  81. drivers/usb/gadget/function/f_ncm.c +332 −148
  82. drivers/usb/gadget/function/f_obex.c +0 −0
  83. drivers/usb/gadget/function/f_phonet.c +0 −0
  84. drivers/usb/gadget/function/f_rndis.c +4 −0
  85. drivers/usb/gadget/function/f_serial.c +0 −0
  86. drivers/usb/gadget/function/f_sourcesink.c +0 −0
  87. drivers/usb/gadget/function/f_subset.c +0 −0
  88. drivers/usb/gadget/function/f_uac1.c +0 −0
  89. drivers/usb/gadget/function/f_uac2.c +22 −2
  90. drivers/usb/gadget/function/f_uvc.c +0 −0
  91. drivers/usb/gadget/function/f_uvc.h +0 −0
  92. drivers/usb/gadget/function/g_zero.h +0 −0
  93. drivers/usb/gadget/function/ndis.h +0 −0
  94. drivers/usb/gadget/function/rndis.c +0 −0
  95. drivers/usb/gadget/function/rndis.h +0 −0
  96. drivers/usb/gadget/function/storage_common.c +0 −0
  97. drivers/usb/gadget/function/storage_common.h +0 −0
  98. drivers/usb/gadget/function/u_ecm.h +0 −0
  99. drivers/usb/gadget/function/u_eem.h +0 −0
  100. drivers/usb/gadget/function/u_ether.c +13 −6
  101. drivers/usb/gadget/function/u_ether.h +2 −0
  102. drivers/usb/gadget/function/u_ether_configfs.h +0 −0
  103. drivers/usb/gadget/function/u_fs.h +7 −0
  104. drivers/usb/gadget/function/u_gether.h +0 −0
  105. drivers/usb/gadget/function/u_ncm.h +0 −0
  106. drivers/usb/gadget/function/u_phonet.h +0 −0
  107. drivers/usb/gadget/function/u_rndis.h +0 −0
  108. drivers/usb/gadget/function/u_serial.c +0 −0
  109. drivers/usb/gadget/function/u_serial.h +0 −0
  110. drivers/usb/gadget/function/u_uac1.c +0 −0
  111. drivers/usb/gadget/function/u_uac1.h +0 −0
  112. drivers/usb/gadget/function/uvc.h +0 −0
  113. drivers/usb/gadget/function/uvc_queue.c +0 −0
  114. drivers/usb/gadget/function/uvc_queue.h +0 −0
  115. drivers/usb/gadget/function/uvc_v4l2.c +0 −0
  116. drivers/usb/gadget/function/uvc_video.c +0 −0
  117. drivers/usb/gadget/legacy/Kconfig +475 −0
  118. drivers/usb/gadget/legacy/Makefile +44 −0
  119. drivers/usb/gadget/legacy/acm_ms.c +2 −12
  120. drivers/usb/gadget/legacy/audio.c +1 −11
  121. drivers/usb/gadget/legacy/cdc2.c +2 −12
  122. drivers/usb/gadget/legacy/dbgp.c +0 −0
  123. drivers/usb/gadget/legacy/ether.c +2 −12
  124. drivers/usb/gadget/legacy/g_ffs.c +1 −1
  125. drivers/usb/gadget/legacy/gmidi.c +1 −12
  126. drivers/usb/gadget/legacy/hid.c +0 −0
  127. drivers/usb/gadget/legacy/inode.c +0 −0
  128. drivers/usb/gadget/legacy/mass_storage.c +0 −0
  129. drivers/usb/gadget/legacy/multi.c +1 −12
  130. drivers/usb/gadget/legacy/ncm.c +2 −12
  131. drivers/usb/gadget/legacy/nokia.c +1 −11
  132. drivers/usb/gadget/legacy/printer.c +0 −0
  133. drivers/usb/gadget/legacy/serial.c +0 −0
  134. drivers/usb/gadget/legacy/tcm_usb_gadget.c +0 −0
  135. drivers/usb/gadget/legacy/tcm_usb_gadget.h +0 −0
  136. drivers/usb/gadget/legacy/webcam.c +1 −14
  137. drivers/usb/gadget/legacy/zero.c +2 −12
  138. drivers/usb/gadget/net2280.c +0 −2905
  139. drivers/usb/gadget/net2280.h +0 −308
  140. drivers/usb/gadget/u_os_desc.h +46 −13
  141. drivers/usb/gadget/udc/Kconfig +385 −0
  142. drivers/usb/gadget/udc/Makefile +31 −0
  143. drivers/usb/gadget/udc/amd5536udc.c +0 −0
  144. drivers/usb/gadget/udc/amd5536udc.h +0 −0
  145. drivers/usb/gadget/udc/at91_udc.c +0 −0
  146. drivers/usb/gadget/udc/at91_udc.h +0 −0
  147. drivers/usb/gadget/udc/atmel_usba_udc.c +1 −1
  148. drivers/usb/gadget/udc/atmel_usba_udc.h +0 −0
  149. drivers/usb/gadget/udc/bcm63xx_udc.c +0 −0
  150. drivers/usb/gadget/udc/dummy_hcd.c +0 −0
  151. drivers/usb/gadget/udc/fotg210-udc.c +0 −0
  152. drivers/usb/gadget/udc/fotg210.h +0 −0
  153. drivers/usb/gadget/udc/fsl_mxc_udc.c +2 −0
  154. drivers/usb/gadget/udc/fsl_qe_udc.c +7 −12
  155. drivers/usb/gadget/udc/fsl_qe_udc.h +0 −0
  156. drivers/usb/gadget/udc/fsl_udc_core.c +11 −8
  157. drivers/usb/gadget/udc/fsl_usb2_udc.h +3 −0
  158. drivers/usb/gadget/udc/fusb300_udc.c +1 −3
  159. drivers/usb/gadget/udc/fusb300_udc.h +0 −0
  160. drivers/usb/gadget/udc/gadget_chips.h +0 −0
  161. drivers/usb/gadget/udc/goku_udc.c +0 −0
  162. drivers/usb/gadget/udc/goku_udc.h +0 −0
  163. drivers/usb/gadget/udc/gr_udc.c +1 −1
  164. drivers/usb/gadget/udc/gr_udc.h +0 −0
  165. drivers/usb/gadget/udc/lpc32xx_udc.c +3 −4
  166. drivers/usb/gadget/udc/m66592-udc.c +1 −3
  167. drivers/usb/gadget/udc/m66592-udc.h +0 −0
  168. drivers/usb/gadget/udc/mv_u3d.h +0 −0
  169. drivers/usb/gadget/udc/mv_u3d_core.c +0 −0
  170. drivers/usb/gadget/udc/mv_udc.h +0 −0
  171. drivers/usb/gadget/udc/mv_udc_core.c +2 −2
  172. drivers/usb/gadget/udc/net2272.c +1 −1
  173. drivers/usb/gadget/udc/net2272.h +0 −0
  174. drivers/usb/gadget/udc/net2280.c +3827 −0
  175. drivers/usb/gadget/udc/net2280.h +403 −0
  176. drivers/usb/gadget/udc/omap_udc.c +1 −4
  177. drivers/usb/gadget/udc/omap_udc.h +0 −0
  178. drivers/usb/gadget/udc/pch_udc.c +0 −0
  179. drivers/usb/gadget/udc/pxa25x_udc.c +23 −52
  180. drivers/usb/gadget/udc/pxa25x_udc.h +0 −0
  181. drivers/usb/gadget/udc/pxa27x_udc.c +6 −0
  182. drivers/usb/gadget/udc/pxa27x_udc.h +0 −0
  183. drivers/usb/gadget/udc/r8a66597-udc.c +28 −64
  184. drivers/usb/gadget/udc/r8a66597-udc.h +0 −0
  185. drivers/usb/gadget/udc/s3c-hsudc.c +0 −0
  186. drivers/usb/gadget/udc/s3c2410_udc.c +4 −4
  187. drivers/usb/gadget/udc/s3c2410_udc.h +0 −0
  188. drivers/usb/gadget/udc/udc-core.c +0 −0
  189. drivers/usb/host/Kconfig +8 −0
  190. drivers/usb/host/Makefile +3 −0
  191. drivers/usb/host/ehci-exynos.c +1 −1
  192. drivers/usb/host/ehci-mem.c +1 −1
  193. drivers/usb/host/ehci-msm.c +1 −1
  194. drivers/usb/host/ehci-pci.c +25 −0
  195. drivers/usb/host/ehci-spear.c +1 −1
  196. drivers/usb/host/ehci-tegra.c +62 −5
  197. drivers/usb/host/fhci-dbg.c +2 −6
  198. drivers/usb/host/fotg210-hcd.c +9 −39
  199. drivers/usb/host/max3421-hcd.c +22 −26
  200. drivers/usb/host/ohci-dbg.c +5 −4
  201. drivers/usb/host/ohci-exynos.c +1 −1
  202. drivers/usb/host/ohci-hcd.c +211 −170
  203. drivers/usb/host/ohci-hub.c +7 −4
  204. drivers/usb/host/ohci-mem.c +1 −0
  205. drivers/usb/host/ohci-q.c +163 −99
  206. drivers/usb/host/ohci-spear.c +1 −1
  207. drivers/usb/host/ohci.h +17 −6
  208. drivers/usb/host/oxu210hp-hcd.c +9 −39
  209. drivers/usb/host/uhci-grlib.c +9 −22
  210. drivers/usb/host/uhci-hcd.c +1 −1
  211. drivers/usb/host/uhci-platform.c +5 −17
  212. drivers/usb/host/xhci-pci.c +5 −3
  213. drivers/usb/host/xhci-plat.c +32 −20
  214. drivers/usb/host/xhci-rcar.c +148 −0
  215. drivers/usb/host/xhci-rcar.h +27 −0
  216. drivers/usb/host/xhci-ring.c +4 −0
  217. drivers/usb/host/xhci.c +90 −70
  218. drivers/usb/host/xhci.h +2 −0
  219. drivers/usb/misc/Kconfig +7 −0
  220. drivers/usb/misc/Makefile +1 −0
  221. drivers/usb/misc/lvstest.c +460 −0
  222. drivers/usb/misc/usb3503.c +34 −3
  223. drivers/usb/musb/blackfin.c +8 −12
  224. drivers/usb/musb/davinci.c +6 −14
  225. drivers/usb/musb/jz4740.c +3 −0
  226. drivers/usb/musb/musb_core.c +21 −20
  227. drivers/usb/musb/musb_core.h +7 −5
  228. drivers/usb/musb/musb_cppi41.c +13 −57
  229. drivers/usb/musb/musb_dma.h +1 −0
  230. drivers/usb/musb/musb_dsps.c +97 −7
  231. drivers/usb/musb/musb_host.c +10 −9
  232. drivers/usb/musb/musb_regs.h +7 −0
  233. drivers/usb/musb/tusb6010.c +5 −11
  234. drivers/usb/musb/ux500.c +10 −18
  235. drivers/usb/phy/phy-am335x.c +3 −9
  236. drivers/usb/phy/phy-gpio-vbus-usb.c +13 −32
  237. drivers/usb/phy/phy-msm-usb.c +6 −6
  238. drivers/usb/phy/phy-tegra-usb.c +4 −7
  239. drivers/usb/renesas_usbhs/Makefile +1 −1
  240. drivers/usb/renesas_usbhs/common.c +61 −5
  241. drivers/usb/renesas_usbhs/common.h +2 −0
  242. drivers/usb/renesas_usbhs/mod_gadget.c +2 −0
  243. drivers/usb/renesas_usbhs/pipe.c +11 −0
  244. drivers/usb/renesas_usbhs/pipe.h +1 −0
  245. drivers/usb/renesas_usbhs/rcar2.c +77 −0
  246. drivers/usb/renesas_usbhs/rcar2.h +4 −0
  247. drivers/usb/serial/cp210x.c +0 −3
  248. drivers/usb/serial/ftdi_sio.c +25 −59
  249. drivers/usb/serial/ftdi_sio_ids.h +8 −5
  250. drivers/usb/serial/kl5kusb105.c +0 −30
  251. drivers/usb/serial/mos7840.c +1 −4
  252. drivers/usb/storage/uas-detect.h +19 −21
  253. drivers/usb/storage/uas.c +1 −1
  254. drivers/uwb/whci.c +1 −1
  255. include/dt-bindings/phy/phy-miphy365x.h +14 −0
  256. include/linux/phy/omap_control_phy.h +10 −0
  257. include/linux/phy/phy.h +12 −5
  258. include/linux/usb/composite.h +15 −0
  259. include/linux/usb/quirks.h +11 −0
  260. include/linux/usb/renesas_usbhs.h +6 −0
  261. include/linux/usb/usb338x.h +199 −0
  262. include/linux/usb/xhci_pdriver.h +27 −0
  263. include/uapi/linux/usb/functionfs.h +80 −2
  264. tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c +35 −4
  265. tools/usb/ffs-aio-example/multibuff/host_app/test.c +27 −0
  266. tools/usb/ffs-aio-example/simple/device_app/aio_simple.c +35 −4
  267. tools/usb/ffs-aio-example/simple/host_app/test.c +27 −0
Documentation/ABI/stable/sysfs-bus-usb+7−7
@@ -3,13 +3,13 @@ Date: May 2007 · 2 unmodified lines
33 KernelVersion: 2.6.23
44 Contact: Alan Stern <stern@rowland.harvard.edu>
55 Description:
6− If CONFIG_USB_PERSIST is set, then each USB device directory
7− will contain a file named power/persist. The file holds a
8− boolean value (0 or 1) indicating whether or not the
9− "USB-Persist" facility is enabled for the device. Since the
10− facility is inherently dangerous, it is disabled by default
11− for all devices except hubs. For more information, see
12− Documentation/usb/persist.txt.
6+ USB device directories can contain a file named power/persist.
7+ The file holds a boolean value (0 or 1) indicating whether or
8+ not the "USB-Persist" facility is enabled for the device. For
9+ hubs this facility is always enabled and their device
10+ directories will not contain this file.
11+
12+ For more information, see Documentation/usb/persist.txt.
1313
1414 What: /sys/bus/usb/devices/.../power/autosuspend
1515 Date: March 2007
Documentation/ABI/testing/sysfs-bus-usb-lvstest+47−0
@@ -0,0 +1,47 @@
1+Link Layer Validation Device is a standard device for testing of Super
2+Speed Link Layer tests. These nodes are available in sysfs only when lvs
3+driver is bound with root hub device.
4+
5+What: /sys/bus/usb/devices/.../get_dev_desc
6+Date: March 2014
7+Contact: Pratyush Anand <pratyush.anand@st.com>
8+Description:
9+ Write to this node to issue "Get Device Descriptor"
10+ for Link Layer Validation device. It is needed for TD.7.06.
11+
12+What: /sys/bus/usb/devices/.../u1_timeout
13+Date: March 2014
14+Contact: Pratyush Anand <pratyush.anand@st.com>
15+Description:
16+ Set "U1 timeout" for the downstream port where Link Layer
17+ Validation device is connected. Timeout value must be between 0
18+ and 127. It is needed for TD.7.18, TD.7.19, TD.7.20 and TD.7.21.
19+
20+What: /sys/bus/usb/devices/.../u2_timeout
21+Date: March 2014
22+Contact: Pratyush Anand <pratyush.anand@st.com>
23+Description:
24+ Set "U2 timeout" for the downstream port where Link Layer
25+ Validation device is connected. Timeout value must be between 0
26+ and 127. It is needed for TD.7.18, TD.7.19, TD.7.20 and TD.7.21.
27+
28+What: /sys/bus/usb/devices/.../hot_reset
29+Date: March 2014
30+Contact: Pratyush Anand <pratyush.anand@st.com>
31+Description:
32+ Write to this node to issue "Reset" for Link Layer Validation
33+ device. It is needed for TD.7.29, TD.7.31, TD.7.34 and TD.7.35.
34+
35+What: /sys/bus/usb/devices/.../u3_entry
36+Date: March 2014
37+Contact: Pratyush Anand <pratyush.anand@st.com>
38+Description:
39+ Write to this node to issue "U3 entry" for Link Layer
40+ Validation device. It is needed for TD.7.35 and TD.7.36.
41+
42+What: /sys/bus/usb/devices/.../u3_exit
43+Date: March 2014
44+Contact: Pratyush Anand <pratyush.anand@st.com>
45+Description:
46+ Write to this node to issue "U3 exit" for Link Layer
47+ Validation device. It is needed for TD.7.36.
Documentation/DocBook/gadget.tmpl+5−5
@@ -556,11 +556,11 @@ been converted to this framework. · 555 unmodified lines
556556 Near-term plans include converting all of them, except for "gadgetfs".
557557 </para>
558558
559−!Edrivers/usb/gadget/f_acm.c
560−!Edrivers/usb/gadget/f_ecm.c
561−!Edrivers/usb/gadget/f_subset.c
562−!Edrivers/usb/gadget/f_obex.c
563−!Edrivers/usb/gadget/f_serial.c
559+!Edrivers/usb/gadget/function/f_acm.c
560+!Edrivers/usb/gadget/function/f_ecm.c
561+!Edrivers/usb/gadget/function/f_subset.c
562+!Edrivers/usb/gadget/function/f_obex.c
563+!Edrivers/usb/gadget/function/f_serial.c
564564
565565 </sect1>
566566
Documentation/devicetree/bindings/phy/berlin-sata-phy.txt+34−0
@@ -0,0 +1,34 @@
1+Berlin SATA PHY
2+---------------
3+
4+Required properties:
5+- compatible: should be "marvell,berlin2q-sata-phy"
6+- address-cells: should be 1
7+- size-cells: should be 0
8+- phy-cells: from the generic PHY bindings, must be 1
9+- reg: address and length of the register
10+- clocks: reference to the clock entry
11+
12+Sub-nodes:
13+Each PHY should be represented as a sub-node.
14+
15+Sub-nodes required properties:
16+- reg: the PHY number
17+
18+Example:
19+ sata_phy: phy@f7e900a0 {
20+ compatible = "marvell,berlin2q-sata-phy";
21+ reg = <0xf7e900a0 0x200>;
22+ clocks = <&chip CLKID_SATA>;
23+ #address-cells = <1>;
24+ #size-cells = <0>;
25+ #phy-cells = <1>;
26+
27+ sata-phy@0 {
28+ reg = <0>;
29+ };
30+
31+ sata-phy@1 {
32+ reg = <1>;
33+ };
34+ };
Documentation/devicetree/bindings/phy/hix5hd2-phy.txt+22−0
@@ -0,0 +1,22 @@
1+Hisilicon hix5hd2 SATA PHY
2+-----------------------
3+
4+Required properties:
5+- compatible: should be "hisilicon,hix5hd2-sata-phy"
6+- reg: offset and length of the PHY registers
7+- #phy-cells: must be 0
8+Refer to phy/phy-bindings.txt for the generic PHY binding properties
9+
10+Optional Properties:
11+- hisilicon,peripheral-syscon: phandle of syscon used to control peripheral.
12+- hisilicon,power-reg: offset and bit number within peripheral-syscon,
13+ register of controlling sata power supply.
14+
15+Example:
16+ sata_phy: phy@f9900000 {
17+ compatible = "hisilicon,hix5hd2-sata-phy";
18+ reg = <0xf9900000 0x10000>;
19+ #phy-cells = <0>;
20+ hisilicon,peripheral-syscon = <&peripheral_ctrl>;
21+ hisilicon,power-reg = <0x8 10>;
22+ };
Documentation/devicetree/bindings/phy/phy-bindings.txt+4−0
@@ -10,6 +10,10 @@ Required Properties: · 9 unmodified lines
1010 provider can use the values in cells to find the appropriate
1111 PHY.
1212
13+Optional Properties:
14+phy-supply: Phandle to a regulator that provides power to the PHY. This
15+ regulator will be managed during the PHY power on/off sequence.
16+
1317 For example:
1418
1519 phys: phy {
Documentation/devicetree/bindings/phy/phy-miphy365x.txt+76−0
@@ -0,0 +1,76 @@
1+STMicroelectronics STi MIPHY365x PHY binding
2+============================================
3+
4+This binding describes a miphy device that is used to control PHY hardware
5+for SATA and PCIe.
6+
7+Required properties (controller (parent) node):
8+- compatible : Should be "st,miphy365x-phy"
9+- st,syscfg : Should be a phandle of the system configuration register group
10+ which contain the SATA, PCIe mode setting bits
11+
12+Required nodes : A sub-node is required for each channel the controller
13+ provides. Address range information including the usual
14+ 'reg' and 'reg-names' properties are used inside these
15+ nodes to describe the controller's topology. These nodes
16+ are translated by the driver's .xlate() function.
17+
18+Required properties (port (child) node):
19+- #phy-cells : Should be 1 (See second example)
20+ Cell after port phandle is device type from:
21+ - MIPHY_TYPE_SATA
22+ - MIPHY_TYPE_PCI
23+- reg : Address and length of register sets for each device in
24+ "reg-names"
25+- reg-names : The names of the register addresses corresponding to the
26+ registers filled in "reg":
27+ - sata: For SATA devices
28+ - pcie: For PCIe devices
29+ - syscfg: To specify the syscfg based config register
30+
31+Optional properties (port (child) node):
32+- st,sata-gen : Generation of locally attached SATA IP. Expected values
33+ are {1,2,3). If not supplied generation 1 hardware will
34+ be expected
35+- st,pcie-tx-pol-inv : Bool property to invert the polarity PCIe Tx (Txn/Txp)
36+- st,sata-tx-pol-inv : Bool property to invert the polarity SATA Tx (Txn/Txp)
37+
38+Example:
39+
40+ miphy365x_phy: miphy365x@fe382000 {
41+ compatible = "st,miphy365x-phy";
42+ st,syscfg = <&syscfg_rear>;
43+ #address-cells = <1>;
44+ #size-cells = <1>;
45+ ranges;
46+
47+ phy_port0: port@fe382000 {
48+ reg = <0xfe382000 0x100>, <0xfe394000 0x100>, <0x824 0x4>;
49+ reg-names = "sata", "pcie", "syscfg";
50+ #phy-cells = <1>;
51+ st,sata-gen = <3>;
52+ };
53+
54+ phy_port1: port@fe38a000 {
55+ reg = <0xfe38a000 0x100>, <0xfe804000 0x100>, <0x828 0x4>;;
56+ reg-names = "sata", "pcie", "syscfg";
57+ #phy-cells = <1>;
58+ st,pcie-tx-pol-inv;
59+ };
60+ };
61+
62+Specifying phy control of devices
63+=================================
64+
65+Device nodes should specify the configuration required in their "phys"
66+property, containing a phandle to the phy port node and a device type.
67+
68+Example:
69+
70+#include <dt-bindings/phy/phy-miphy365x.h>
71+
72+ sata0: sata@fe380000 {
73+ ...
74+ phys = <&phy_port0 MIPHY_TYPE_SATA>;
75+ ...
76+ };
Documentation/devicetree/bindings/phy/qcom-apq8064-sata-phy.txt+24−0
@@ -0,0 +1,24 @@
1+Qualcomm APQ8064 SATA PHY Controller
2+------------------------------------
3+
4+SATA PHY nodes are defined to describe on-chip SATA Physical layer controllers.
5+Each SATA PHY controller should have its own node.
6+
7+Required properties:
8+- compatible: compatible list, contains "qcom,apq8064-sata-phy".
9+- reg: offset and length of the SATA PHY register set;
10+- #phy-cells: must be zero
11+- clocks: a list of phandles and clock-specifier pairs, one for each entry in
12+ clock-names.
13+- clock-names: must be "cfg" for phy config clock.
14+
15+Example:
16+ sata_phy: sata-phy@1b400000 {
17+ compatible = "qcom,apq8064-sata-phy";
18+ reg = <0x1b400000 0x200>;
19+
20+ clocks = <&gcc SATA_PHY_CFG_CLK>;
21+ clock-names = "cfg";
22+
23+ #phy-cells = <0>;
24+ };
Documentation/devicetree/bindings/phy/qcom-ipq806x-sata-phy.txt+23−0
@@ -0,0 +1,23 @@
1+Qualcomm IPQ806x SATA PHY Controller
2+------------------------------------
3+
4+SATA PHY nodes are defined to describe on-chip SATA Physical layer controllers.
5+Each SATA PHY controller should have its own node.
6+
7+Required properties:
8+- compatible: compatible list, contains "qcom,ipq806x-sata-phy"
9+- reg: offset and length of the SATA PHY register set;
10+- #phy-cells: must be zero
11+- clocks: must be exactly one entry
12+- clock-names: must be "cfg"
13+
14+Example:
15+ sata_phy: sata-phy@1b400000 {
16+ compatible = "qcom,ipq806x-sata-phy";
17+ reg = <0x1b400000 0x200>;
18+
19+ clocks = <&gcc SATA_PHY_CFG_CLK>;
20+ clock-names = "cfg";
21+
22+ #phy-cells = <0>;
23+ };
Documentation/devicetree/bindings/phy/samsung-phy.txt+2−0
@@ -26,6 +26,7 @@ Samsung S5P/EXYNOS SoC series USB PHY · 25 unmodified lines
2626
2727 Required properties:
2828 - compatible : should be one of the listed compatibles:
29+ - "samsung,exynos3250-usb2-phy"
2930 - "samsung,exynos4210-usb2-phy"
3031 - "samsung,exynos4x12-usb2-phy"
3132 - "samsung,exynos5250-usb2-phy"
@@ -46,6 +47,7 @@ and Exynos 4212) it is as follows: · 14 unmodified lines
4647 1 - USB host ("host"),
4748 2 - HSIC0 ("hsic0"),
4849 3 - HSIC1 ("hsic1"),
50+Exynos3250 has only USB device phy available as phy 0.
4951
5052 Exynos 4210 and Exynos 4212 use mode switching and require that mode switch
5153 register is supplied.
Documentation/devicetree/bindings/phy/ti-phy.txt+16−7
@@ -9,15 +9,17 @@ Required properties: · 8 unmodified lines
99 e.g. USB2_PHY on OMAP5.
1010 "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power control
1111 e.g. USB3 PHY and SATA PHY on OMAP5.
12+ "ti,control-phy-pcie" - for pcie to support external clock for pcie and to
13+ set PCS delay value.
14+ e.g. PCIE PHY in DRA7x
1215 "ti,control-phy-usb2-dra7" - if it has power down register like USB2 PHY on
1316 DRA7 platform.
1417 "ti,control-phy-usb2-am437" - if it has power down register like USB2 PHY on
1518 AM437 platform.
16− - reg : Address and length of the register set for the device. It contains
17− the address of "otghs_control" for control-phy-otghs or "power" register
18− for other types.
19− - reg-names: should be "otghs_control" control-phy-otghs and "power" for
20− other types.
19+ - reg : register ranges as listed in the reg-names property
20+ - reg-names: "otghs_control" for control-phy-otghs
21+ "power", "pcie_pcs" and "control_sma" for control-phy-pcie
22+ "power" for all other types
2123
2224 omap_control_usb: omap-control-usb@4a002300 {
2325 compatible = "ti,control-phy-otghs";
@@ -56,8 +58,8 @@ usb2phy@4a0ad080 { · 32 unmodified lines
5658 TI PIPE3 PHY
5759
5860 Required properties:
59− - compatible: Should be "ti,phy-usb3" or "ti,phy-pipe3-sata".
60− "ti,omap-usb3" is deprecated.
61+ - compatible: Should be "ti,phy-usb3", "ti,phy-pipe3-sata" or
62+ "ti,phy-pipe3-pcie. "ti,omap-usb3" is deprecated.
6163 - reg : Address and length of the register set for the device.
6264 - reg-names: The names of the register addresses corresponding to the registers
6365 filled in "reg".
@@ -69,10 +71,17 @@ Required properties: · 5 unmodified lines
6971 * "wkupclk" - wakeup clock.
7072 * "sysclk" - system clock.
7173 * "refclk" - reference clock.
74+ * "dpll_ref" - external dpll ref clk
75+ * "dpll_ref_m2" - external dpll ref clk
76+ * "phy-div" - divider for apll
77+ * "div-clk" - apll clock
7278
7379 Optional properties:
7480 - ctrl-module : phandle of the control module used by PHY driver to power on
7581 the PHY.
82+ - id: If there are multiple instance of the same type, in order to
83+ differentiate between each instance "id" can be used (e.g., multi-lane PCIe
84+ PHY). If "id" is not provided, it is set to default value of '1'.
7685
7786 This is usually a subnode of ocp2scp to which it is connected.
7887
Documentation/devicetree/bindings/usb/ci-hdrc-imx.txt+1−1
@@ -4,6 +4,7 @@ Required properties: · 3 unmodified lines
44 - compatible: Should be "fsl,imx27-usb"
55 - reg: Should contain registers location and length
66 - interrupts: Should contain controller interrupt
7+- fsl,usbphy: phandle of usb phy that connects to the port
78
89 Recommended properies:
910 - phy_type: the type of the phy connected to the core. Should be one
@@ -12,7 +13,6 @@ Recommended properies: · 2 unmodified lines
1213 - dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
1314
1415 Optional properties:
15−- fsl,usbphy: phandler of usb phy that connects to the only one port
1616 - fsl,usbmisc: phandler of non-core register device, with one argument
1717 that indicate usb controller index
1818 - vbus-supply: regulator for vbus
Documentation/devicetree/bindings/usb/nvidia,tegra20-usb-phy.txt+8−0
@@ -20,6 +20,12 @@ Required properties : · 19 unmodified lines
2020 Present if phy_type == utmi.
2121 - ulpi-link: The clock Tegra provides to the ULPI PHY (cdev2).
2222 Present if phy_type == ulpi, and ULPI link mode is in use.
23+ - resets : Must contain an entry for each entry in reset-names.
24+ See ../reset/reset.txt for details.
25+ - reset-names : Must include the following entries:
26+ - usb: The PHY's own reset signal.
27+ - utmi-pads: The reset of the PHY containing the chip-wide UTMI pad control
28+ registers. Required even if phy_type == ulpi.
2329
2430 Required properties for phy_type == ulpi:
2531 - nvidia,phy-reset-gpio : The GPIO used to reset the PHY.
@@ -56,6 +62,8 @@ Optional properties: · 30 unmodified lines
5662 host means this is a host controller
5763 peripheral means it is device controller
5864 otg means it can operate as either ("on the go")
65+ - nvidia,has-utmi-pad-registers : boolean indicates whether this controller
66+ contains the UTMI pad control registers common to all USB controllers.
5967
6068 VBUS control (required for dr_mode == otg, optional for dr_mode == host):
6169 - vbus-supply: regulator for VBUS
Documentation/devicetree/bindings/usb/usb-xhci.txt+2−1
@@ -9,8 +9,9 @@ Required properties: · 8 unmodified lines
99 register set for the device.
1010 - interrupts: one XHCI interrupt should be described here.
1111
12−Optional property:
12+Optional properties:
1313 - clocks: reference to a clock
14+ - usb3-lpm-capable: determines if platform is USB3 LPM capable
1415
1516 Example:
1617 usb@f0931000 {
Documentation/phy.txt+6−4
@@ -53,10 +53,12 @@ unregister the PHY. · 52 unmodified lines
5353 The PHY driver should create the PHY in order for other peripheral controllers
5454 to make use of it. The PHY framework provides 2 APIs to create the PHY.
5555
56−struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
57− struct phy_init_data *init_data);
58−struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops,
59− struct phy_init_data *init_data);
56+struct phy *phy_create(struct device *dev, struct device_node *node,
57+ const struct phy_ops *ops,
58+ struct phy_init_data *init_data);
59+struct phy *devm_phy_create(struct device *dev, struct device_node *node,
60+ const struct phy_ops *ops,
61+ struct phy_init_data *init_data);
6062
6163 The PHY drivers can use one of the above 2 APIs to create the PHY by passing
6264 the device pointer, phy ops and init_data.
Documentation/usb/hotplug.txt+4−4
@@ -105,13 +105,13 @@ macros such as these, and use driver_info to store more information. · 104 unmodified lines
105105 A short example, for a driver that supports several specific USB devices
106106 and their quirks, might have a MODULE_DEVICE_TABLE like this:
107107
108− static const struct usb_device_id mydriver_id_table = {
108+ static const struct usb_device_id mydriver_id_table[] = {
109109 { USB_DEVICE (0x9999, 0xaaaa), driver_info: QUIRK_X },
110110 { USB_DEVICE (0xbbbb, 0x8888), driver_info: QUIRK_Y|QUIRK_Z },
111111 ...
112112 { } /* end with an all-zeroes entry */
113− }
114− MODULE_DEVICE_TABLE (usb, mydriver_id_table);
113+ };
114+ MODULE_DEVICE_TABLE(usb, mydriver_id_table);
115115
116116 Most USB device drivers should pass these tables to the USB subsystem as
117117 well as to the module management subsystem. Not all, though: some driver
@@ -134,7 +134,7 @@ something like this: · 16 unmodified lines
134134 if exposing any operations through usbdevfs:
135135 .ioctl = my_ioctl,
136136 */
137− }
137+ };
138138
139139 When the USB subsystem knows about a driver's device ID table, it's used when
140140 choosing drivers to probe(). The thread doing new device processing checks
Documentation/usb/power-management.txt+243−2
@@ -2,8 +2,27 @@ · 1 unmodified line
22
33 Alan Stern <stern@rowland.harvard.edu>
44
5− October 28, 2010
6−
5+ Last-updated: February 2014
6+
7+
8+ Contents:
9+ ---------
10+ * What is Power Management?
11+ * What is Remote Wakeup?
12+ * When is a USB device idle?
13+ * Forms of dynamic PM
14+ * The user interface for dynamic PM
15+ * Changing the default idle-delay time
16+ * Warnings
17+ * The driver interface for Power Management
18+ * The driver interface for autosuspend and autoresume
19+ * Other parts of the driver interface
20+ * Mutual exclusion
21+ * Interaction between dynamic PM and system PM
22+ * xHCI hardware link PM
23+ * USB Port Power Control
24+ * User Interface for Port Power Control
25+ * Suggested Userspace Port Power Policy
726
827
928 What is Power Management?
@@ -516,3 +535,225 @@ relevant attribute files is usb2_hardware_lpm. · 506 unmodified lines
516535 driver will enable hardware LPM for the device. You
517536 can write y/Y/1 or n/N/0 to the file to enable/disable
518537 USB2 hardware LPM manually. This is for test purpose mainly.
538+
539+
540+ USB Port Power Control
541+ ----------------------
542+
543+In addition to suspending endpoint devices and enabling hardware
544+controlled link power management, the USB subsystem also has the
545+capability to disable power to ports under some conditions. Power is
546+controlled through Set/ClearPortFeature(PORT_POWER) requests to a hub.
547+In the case of a root or platform-internal hub the host controller
548+driver translates PORT_POWER requests into platform firmware (ACPI)
549+method calls to set the port power state. For more background see the
550+Linux Plumbers Conference 2012 slides [1] and video [2]:
551+
552+Upon receiving a ClearPortFeature(PORT_POWER) request a USB port is
553+logically off, and may trigger the actual loss of VBUS to the port [3].
554+VBUS may be maintained in the case where a hub gangs multiple ports into
555+a shared power well causing power to remain until all ports in the gang
556+are turned off. VBUS may also be maintained by hub ports configured for
557+a charging application. In any event a logically off port will lose
558+connection with its device, not respond to hotplug events, and not
559+respond to remote wakeup events*.
560+
561+WARNING: turning off a port may result in the inability to hot add a device.
562+Please see "User Interface for Port Power Control" for details.
563+
564+As far as the effect on the device itself it is similar to what a device
565+goes through during system suspend, i.e. the power session is lost. Any
566+USB device or driver that misbehaves with system suspend will be
567+similarly affected by a port power cycle event. For this reason the
568+implementation shares the same device recovery path (and honors the same
569+quirks) as the system resume path for the hub.
570+
571+[1]: http://dl.dropbox.com/u/96820575/sarah-sharp-lpt-port-power-off2-mini.pdf
572+[2]: http://linuxplumbers.ubicast.tv/videos/usb-port-power-off-kerneluserspace-api/
573+[3]: USB 3.1 Section 10.12
574+* wakeup note: if a device is configured to send wakeup events the port
575+ power control implementation will block poweroff attempts on that
576+ port.
577+
578+
579+ User Interface for Port Power Control
580+ -------------------------------------
581+
582+The port power control mechanism uses the PM runtime system. Poweroff is
583+requested by clearing the power/pm_qos_no_power_off flag of the port device
584+(defaults to 1). If the port is disconnected it will immediately receive a
585+ClearPortFeature(PORT_POWER) request. Otherwise, it will honor the pm runtime
586+rules and require the attached child device and all descendants to be suspended.
587+This mechanism is dependent on the hub advertising port power switching in its
588+hub descriptor (wHubCharacteristics logical power switching mode field).
589+
590+Note, some interface devices/drivers do not support autosuspend. Userspace may
591+need to unbind the interface drivers before the usb_device will suspend. An
592+unbound interface device is suspended by default. When unbinding, be careful
593+to unbind interface drivers, not the driver of the parent usb device. Also,
594+leave hub interface drivers bound. If the driver for the usb device (not
595+interface) is unbound the kernel is no longer able to resume the device. If a
596+hub interface driver is unbound, control of its child ports is lost and all
597+attached child-devices will disconnect. A good rule of thumb is that if the
598+'driver/module' link for a device points to /sys/module/usbcore then unbinding
599+it will interfere with port power control.
600+
601+Example of the relevant files for port power control. Note, in this example
602+these files are relative to a usb hub device (prefix).
603+
604+ prefix=/sys/devices/pci0000:00/0000:00:14.0/usb3/3-1
605+
606+ attached child device +
607+ hub port device + |
608+ hub interface device + | |
609+ v v v
610+ $prefix/3-1:1.0/3-1-port1/device
611+
612+ $prefix/3-1:1.0/3-1-port1/power/pm_qos_no_power_off
613+ $prefix/3-1:1.0/3-1-port1/device/power/control
614+ $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf0>/driver/unbind
615+ $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intf1>/driver/unbind
616+ ...
617+ $prefix/3-1:1.0/3-1-port1/device/3-1.1:<intfN>/driver/unbind
618+
619+In addition to these files some ports may have a 'peer' link to a port on
620+another hub. The expectation is that all superspeed ports have a
621+hi-speed peer.
622+
623+$prefix/3-1:1.0/3-1-port1/peer -> ../../../../usb2/2-1/2-1:1.0/2-1-port1
624+../../../../usb2/2-1/2-1:1.0/2-1-port1/peer -> ../../../../usb3/3-1/3-1:1.0/3-1-port1
625+
626+Distinct from 'companion ports', or 'ehci/xhci shared switchover ports'
627+peer ports are simply the hi-speed and superspeed interface pins that
628+are combined into a single usb3 connector. Peer ports share the same
629+ancestor XHCI device.
630+
631+While a superspeed port is powered off a device may downgrade its
632+connection and attempt to connect to the hi-speed pins. The
633+implementation takes steps to prevent this:
634+
635+1/ Port suspend is sequenced to guarantee that hi-speed ports are powered-off
636+ before their superspeed peer is permitted to power-off. The implication is
637+ that the setting pm_qos_no_power_off to zero on a superspeed port may not cause
638+ the port to power-off until its highspeed peer has gone to its runtime suspend
639+ state. Userspace must take care to order the suspensions if it wants to
640+ guarantee that a superspeed port will power-off.
641+
642+2/ Port resume is sequenced to force a superspeed port to power-on prior to its
643+ highspeed peer.
644+
645+3/ Port resume always triggers an attached child device to resume. After a
646+ power session is lost the device may have been removed, or need reset.
647+ Resuming the child device when the parent port regains power resolves those
648+ states and clamps the maximum port power cycle frequency at the rate the child
649+ device can suspend (autosuspend-delay) and resume (reset-resume latency).
650+
651+Sysfs files relevant for port power control:
652+ <hubdev-portX>/power/pm_qos_no_power_off:
653+ This writable flag controls the state of an idle port.
654+ Once all children and descendants have suspended the
655+ port may suspend/poweroff provided that
656+ pm_qos_no_power_off is '0'. If pm_qos_no_power_off is
657+ '1' the port will remain active/powered regardless of
658+ the stats of descendants. Defaults to 1.
659+
660+ <hubdev-portX>/power/runtime_status:
661+ This file reflects whether the port is 'active' (power is on)
662+ or 'suspended' (logically off). There is no indication to
663+ userspace whether VBUS is still supplied.
664+
665+ <hubdev-portX>/connect_type:
666+ An advisory read-only flag to userspace indicating the
667+ location and connection type of the port. It returns
668+ one of four values 'hotplug', 'hardwired', 'not used',
669+ and 'unknown'. All values, besides unknown, are set by
670+ platform firmware.
671+
672+ "hotplug" indicates an externally connectable/visible
673+ port on the platform. Typically userspace would choose
674+ to keep such a port powered to handle new device
675+ connection events.
676+
677+ "hardwired" refers to a port that is not visible but
678+ connectable. Examples are internal ports for USB
679+ bluetooth that can be disconnected via an external
680+ switch or a port with a hardwired USB camera. It is
681+ expected to be safe to allow these ports to suspend
682+ provided pm_qos_no_power_off is coordinated with any
683+ switch that gates connections. Userspace must arrange
684+ for the device to be connected prior to the port
685+ powering off, or to activate the port prior to enabling
686+ connection via a switch.
687+
688+ "not used" refers to an internal port that is expected
689+ to never have a device connected to it. These may be
690+ empty internal ports, or ports that are not physically
691+ exposed on a platform. Considered safe to be
692+ powered-off at all times.
693+
694+ "unknown" means platform firmware does not provide
695+ information for this port. Most commonly refers to
696+ external hub ports which should be considered 'hotplug'
697+ for policy decisions.
698+
699+ NOTE1: since we are relying on the BIOS to get this ACPI
700+ information correct, the USB port descriptions may be
701+ missing or wrong.
702+
703+ NOTE2: Take care in clearing pm_qos_no_power_off. Once
704+ power is off this port will
705+ not respond to new connect events.
706+
707+ Once a child device is attached additional constraints are
708+ applied before the port is allowed to poweroff.
709+
710+ <child>/power/control:
711+ Must be 'auto', and the port will not
712+ power down until <child>/power/runtime_status
713+ reflects the 'suspended' state. Default
714+ value is controlled by child device driver.
715+
716+ <child>/power/persist:
717+ This defaults to '1' for most devices and indicates if
718+ kernel can persist the device's configuration across a
719+ power session loss (suspend / port-power event). When
720+ this value is '0' (quirky devices), port poweroff is
721+ disabled.
722+
723+ <child>/driver/unbind:
724+ Wakeup capable devices will block port poweroff. At
725+ this time the only mechanism to clear the usb-internal
726+ wakeup-capability for an interface device is to unbind
727+ its driver.
728+
729+Summary of poweroff pre-requisite settings relative to a port device:
730+
731+ echo 0 > power/pm_qos_no_power_off
732+ echo 0 > peer/power/pm_qos_no_power_off # if it exists
733+ echo auto > power/control # this is the default value
734+ echo auto > <child>/power/control
735+ echo 1 > <child>/power/persist # this is the default value
736+
737+ Suggested Userspace Port Power Policy
738+ -------------------------------------
739+
740+As noted above userspace needs to be careful and deliberate about what
741+ports are enabled for poweroff.
742+
743+The default configuration is that all ports start with
744+power/pm_qos_no_power_off set to '1' causing ports to always remain
745+active.
746+
747+Given confidence in the platform firmware's description of the ports
748+(ACPI _PLD record for a port populates 'connect_type') userspace can
749+clear pm_qos_no_power_off for all 'not used' ports. The same can be
750+done for 'hardwired' ports provided poweroff is coordinated with any
751+connection switch for the port.
752+
753+A more aggressive userspace policy is to enable USB port power off for
754+all ports (set <hubdev-portX>/power/pm_qos_no_power_off to '0') when
755+some external factor indicates the user has stopped interacting with the
756+system. For example, a distro may want to enable power off all USB
757+ports when the screen blanks, and re-power them when the screen becomes
758+active. Smart phones and tablets may want to power off USB ports when
759+the user pushes the power button.
arch/arm/boot/dts/tegra114.dtsi+5−0
@@ -657,6 +657,8 @@ · 656 unmodified lines
657657 <&tegra_car TEGRA114_CLK_PLL_U>,
658658 <&tegra_car TEGRA114_CLK_USBD>;
659659 clock-names = "reg", "pll_u", "utmi-pads";
660+ resets = <&tegra_car 22>, <&tegra_car 22>;
661+ reset-names = "usb", "utmi-pads";
660662 nvidia,hssync-start-delay = <0>;
661663 nvidia,idle-wait-delay = <17>;
662664 nvidia,elastic-limit = <16>;
@@ -667,6 +669,7 @@ · 4 unmodified lines
667669 nvidia,hssquelch-level = <2>;
668670 nvidia,hsdiscon-level = <5>;
669671 nvidia,xcvr-hsslew = <12>;
672+ nvidia,has-utmi-pad-registers;
670673 status = "disabled";
671674 };
672675
@@ -690,6 +693,8 @@ · 17 unmodified lines
690693 <&tegra_car TEGRA114_CLK_PLL_U>,
691694 <&tegra_car TEGRA114_CLK_USBD>;
692695 clock-names = "reg", "pll_u", "utmi-pads";
696+ resets = <&tegra_car 59>, <&tegra_car 22>;
697+ reset-names = "usb", "utmi-pads";
693698 nvidia,hssync-start-delay = <0>;
694699 nvidia,idle-wait-delay = <17>;
695700 nvidia,elastic-limit = <16>;
arch/arm/boot/dts/tegra124.dtsi+7−0
@@ -613,6 +613,8 @@ · 612 unmodified lines
613613 <&tegra_car TEGRA124_CLK_PLL_U>,
614614 <&tegra_car TEGRA124_CLK_USBD>;
615615 clock-names = "reg", "pll_u", "utmi-pads";
616+ resets = <&tegra_car 59>, <&tegra_car 22>;
617+ reset-names = "usb", "utmi-pads";
616618 nvidia,hssync-start-delay = <0>;
617619 nvidia,idle-wait-delay = <17>;
618620 nvidia,elastic-limit = <16>;
@@ -647,6 +649,8 @@ · 28 unmodified lines
647649 <&tegra_car TEGRA124_CLK_PLL_U>,
648650 <&tegra_car TEGRA124_CLK_USBD>;
649651 clock-names = "reg", "pll_u", "utmi-pads";
652+ resets = <&tegra_car 22>, <&tegra_car 22>;
653+ reset-names = "usb", "utmi-pads";
650654 nvidia,hssync-start-delay = <0>;
651655 nvidia,idle-wait-delay = <17>;
652656 nvidia,elastic-limit = <16>;
@@ -657,6 +661,7 @@ · 4 unmodified lines
657661 nvidia,hssquelch-level = <2>;
658662 nvidia,hsdiscon-level = <5>;
659663 nvidia,xcvr-hsslew = <12>;
664+ nvidia,has-utmi-pad-registers;
660665 status = "disabled";
661666 };
662667
@@ -681,6 +686,8 @@ · 18 unmodified lines
681686 <&tegra_car TEGRA124_CLK_PLL_U>,
682687 <&tegra_car TEGRA124_CLK_USBD>;
683688 clock-names = "reg", "pll_u", "utmi-pads";
689+ resets = <&tegra_car 58>, <&tegra_car 22>;
690+ reset-names = "usb", "utmi-pads";
684691 nvidia,hssync-start-delay = <0>;
685692 nvidia,idle-wait-delay = <17>;
686693 nvidia,elastic-limit = <16>;
arch/arm/boot/dts/tegra20.dtsi+7−0
@@ -630,6 +630,8 @@ · 629 unmodified lines
630630 <&tegra_car TEGRA20_CLK_CLK_M>,
631631 <&tegra_car TEGRA20_CLK_USBD>;
632632 clock-names = "reg", "pll_u", "timer", "utmi-pads";
633+ resets = <&tegra_car 22>, <&tegra_car 22>;
634+ reset-names = "usb", "utmi-pads";
633635 nvidia,has-legacy-mode;
634636 nvidia,hssync-start-delay = <9>;
635637 nvidia,idle-wait-delay = <17>;
@@ -638,6 +640,7 @@ · 2 unmodified lines
638640 nvidia,xcvr-setup = <9>;
639641 nvidia,xcvr-lsfslew = <1>;
640642 nvidia,xcvr-lsrslew = <1>;
643+ nvidia,has-utmi-pad-registers;
641644 status = "disabled";
642645 };
643646
@@ -661,6 +664,8 @@ · 17 unmodified lines
661664 <&tegra_car TEGRA20_CLK_PLL_U>,
662665 <&tegra_car TEGRA20_CLK_CDEV2>;
663666 clock-names = "reg", "pll_u", "ulpi-link";
667+ resets = <&tegra_car 58>, <&tegra_car 22>;
668+ reset-names = "usb", "utmi-pads";
664669 status = "disabled";
665670 };
666671
@@ -685,6 +690,8 @@ · 18 unmodified lines
685690 <&tegra_car TEGRA20_CLK_CLK_M>,
686691 <&tegra_car TEGRA20_CLK_USBD>;
687692 clock-names = "reg", "pll_u", "timer", "utmi-pads";
693+ resets = <&tegra_car 59>, <&tegra_car 22>;
694+ reset-names = "usb", "utmi-pads";
688695 nvidia,hssync-start-delay = <9>;
689696 nvidia,idle-wait-delay = <17>;
690697 nvidia,elastic-limit = <16>;
arch/arm/boot/dts/tegra30.dtsi+7−0
@@ -775,6 +775,8 @@ · 774 unmodified lines
775775 <&tegra_car TEGRA30_CLK_PLL_U>,
776776 <&tegra_car TEGRA30_CLK_USBD>;
777777 clock-names = "reg", "pll_u", "utmi-pads";
778+ resets = <&tegra_car 22>, <&tegra_car 22>;
779+ reset-names = "usb", "utmi-pads";
778780 nvidia,hssync-start-delay = <9>;
779781 nvidia,idle-wait-delay = <17>;
780782 nvidia,elastic-limit = <16>;
@@ -786,6 +788,7 @@ · 5 unmodified lines
786788 nvidia,xcvr-hsslew = <32>;
787789 nvidia,hssquelch-level = <2>;
788790 nvidia,hsdiscon-level = <5>;
791+ nvidia,has-utmi-pad-registers;
789792 status = "disabled";
790793 };
791794
@@ -809,6 +812,8 @@ · 17 unmodified lines
809812 <&tegra_car TEGRA30_CLK_PLL_U>,
810813 <&tegra_car TEGRA30_CLK_USBD>;
811814 clock-names = "reg", "pll_u", "utmi-pads";
815+ resets = <&tegra_car 58>, <&tegra_car 22>;
816+ reset-names = "usb", "utmi-pads";
812817 nvidia,hssync-start-delay = <9>;
813818 nvidia,idle-wait-delay = <17>;
814819 nvidia,elastic-limit = <16>;
@@ -843,6 +848,8 @@ · 28 unmodified lines
843848 <&tegra_car TEGRA30_CLK_PLL_U>,
844849 <&tegra_car TEGRA30_CLK_USBD>;
845850 clock-names = "reg", "pll_u", "utmi-pads";
851+ resets = <&tegra_car 59>, <&tegra_car 22>;
852+ reset-names = "usb", "utmi-pads";
846853 nvidia,hssync-start-delay = <0>;
847854 nvidia,idle-wait-delay = <17>;
848855 nvidia,elastic-limit = <16>;
drivers/phy/Kconfig+53−25
@@ -15,6 +15,13 @@ config GENERIC_PHY · 14 unmodified lines
1515 phy users can obtain reference to the PHY. All the users of this
1616 framework should select this config.
1717
18+config PHY_BERLIN_SATA
19+ tristate "Marvell Berlin SATA PHY driver"
20+ depends on ARCH_BERLIN && HAS_IOMEM && OF
21+ select GENERIC_PHY
22+ help
23+ Enable this to support the SATA PHY on Marvell Berlin SoCs.
24+
1825 config PHY_EXYNOS_MIPI_VIDEO
1926 tristate "S5P/EXYNOS SoC series MIPI CSI-2/DSI PHY driver"
2027 depends on HAS_IOMEM
@@ -27,10 +34,20 @@ config PHY_EXYNOS_MIPI_VIDEO · 6 unmodified lines
2734
2835 config PHY_MVEBU_SATA
2936 def_bool y
30− depends on ARCH_KIRKWOOD || ARCH_DOVE || MACH_DOVE || MACH_KIRKWOOD
37+ depends on ARCH_DOVE || MACH_DOVE || MACH_KIRKWOOD
3138 depends on OF
3239 select GENERIC_PHY
3340
41+config PHY_MIPHY365X
42+ tristate "STMicroelectronics MIPHY365X PHY driver for STiH41x series"
43+ depends on ARCH_STI
44+ depends on GENERIC_PHY
45+ depends on HAS_IOMEM
46+ depends on OF
47+ help
48+ Enable this to support the miphy transceiver (for SATA/PCIE)
49+ that is part of STMicroelectronics STiH41x SoC series.
50+
3451 config OMAP_CONTROL_PHY
3552 tristate "OMAP CONTROL PHY Driver"
3653 depends on ARCH_OMAP2PLUS || COMPILE_TEST
@@ -109,6 +126,14 @@ config PHY_EXYNOS5250_SATA · 72 unmodified lines
109126 SATA 3.0 Gb/s, SATA 6.0 Gb/s speeds. It supports one SATA host
110127 port to accept one SATA device.
111128
129+config PHY_HIX5HD2_SATA
130+ tristate "HIX5HD2 SATA PHY Driver"
131+ depends on ARCH_HIX5HD2 && OF && HAS_IOMEM
132+ select GENERIC_PHY
133+ select MFD_SYSCON
134+ help
135+ Support for SATA PHY on Hisilicon hix5hd2 Soc.
136+
112137 config PHY_SUN4I_USB
113138 tristate "Allwinner sunxi SoC USB PHY driver"
114139 depends on ARCH_SUNXI && HAS_IOMEM && OF
@@ -124,50 +149,39 @@ config PHY_SUN4I_USB · 9 unmodified lines
124149 config PHY_SAMSUNG_USB2
125150 tristate "Samsung USB 2.0 PHY driver"
126151 depends on HAS_IOMEM
152+ depends on USB_EHCI_EXYNOS || USB_OHCI_EXYNOS || USB_DWC2
127153 select GENERIC_PHY
128154 select MFD_SYSCON
155+ default ARCH_EXYNOS
129156 help
130157 Enable this to support the Samsung USB 2.0 PHY driver for Samsung
131− SoCs. This driver provides the interface for USB 2.0 PHY. Support for
132− particular SoCs has to be enabled in addition to this driver. Number
133− and type of supported phys depends on the SoC.
158+ SoCs. This driver provides the interface for USB 2.0 PHY. Support
159+ for particular PHYs will be enabled based on the SoC type in addition
160+ to this driver.
134161
135162 config PHY_EXYNOS4210_USB2
136− bool "Support for Exynos 4210"
163+ bool
137164 depends on PHY_SAMSUNG_USB2
138− depends on CPU_EXYNOS4210
139− help
140− Enable USB PHY support for Exynos 4210. This option requires that
141− Samsung USB 2.0 PHY driver is enabled and means that support for this
142− particular SoC is compiled in the driver. In case of Exynos 4210 four
143− phys are available - device, host, HSIC0 and HSIC1.
165+ default CPU_EXYNOS4210
144166
145167 config PHY_EXYNOS4X12_USB2
146− bool "Support for Exynos 4x12"
168+ bool
147169 depends on PHY_SAMSUNG_USB2
148− depends on (SOC_EXYNOS4212 || SOC_EXYNOS4412)
149− help
150− Enable USB PHY support for Exynos 4x12. This option requires that
151− Samsung USB 2.0 PHY driver is enabled and means that support for this
152− particular SoC is compiled in the driver. In case of Exynos 4x12 four
153− phys are available - device, host, HSIC0 and HSIC1.
170+ default SOC_EXYNOS3250 || SOC_EXYNOS4212 || SOC_EXYNOS4412
154171
155172 config PHY_EXYNOS5250_USB2
156− bool "Support for Exynos 5250"
173+ bool
157174 depends on PHY_SAMSUNG_USB2
158− depends on SOC_EXYNOS5250
159− help
160− Enable USB PHY support for Exynos 5250. This option requires that
161− Samsung USB 2.0 PHY driver is enabled and means that support for this
162− particular SoC is compiled in the driver. In case of Exynos 5250 four
163− phys are available - device, host, HSIC0 and HSIC.
175+ default SOC_EXYNOS5250 || SOC_EXYNOS5420
164176
165177 config PHY_EXYNOS5_USBDRD
166178 tristate "Exynos5 SoC series USB DRD PHY driver"
167179 depends on ARCH_EXYNOS5 && OF
168180 depends on HAS_IOMEM
181+ depends on USB_DWC3_EXYNOS
169182 select GENERIC_PHY
170183 select MFD_SYSCON
184+ default y
171185 help
172186 Enable USB DRD PHY support for Exynos 5 SoC series.
173187 This driver provides PHY interface for USB 3.0 DRD controller
@@ -180,4 +194,18 @@ config PHY_XGENE · 6 unmodified lines
180194 help
181195 This option enables support for APM X-Gene SoC multi-purpose PHY.
182196
197+config PHY_QCOM_APQ8064_SATA
198+ tristate "Qualcomm APQ8064 SATA SerDes/PHY driver"
199+ depends on ARCH_QCOM
200+ depends on HAS_IOMEM
201+ depends on OF
202+ select GENERIC_PHY
203+
204+config PHY_QCOM_IPQ806X_SATA
205+ tristate "Qualcomm IPQ806x SATA SerDes/PHY driver"
206+ depends on ARCH_QCOM
207+ depends on HAS_IOMEM
208+ depends on OF
209+ select GENERIC_PHY
210+
183211 endmenu
drivers/phy/Makefile+5−0
@@ -3,15 +3,18 @@ · 2 unmodified lines
33 #
44
55 obj-$(CONFIG_GENERIC_PHY) += phy-core.o
6+obj-$(CONFIG_PHY_BERLIN_SATA) += phy-berlin-sata.o
67 obj-$(CONFIG_BCM_KONA_USB2_PHY) += phy-bcm-kona-usb2.o
78 obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o
89 obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o
910 obj-$(CONFIG_PHY_MVEBU_SATA) += phy-mvebu-sata.o
11+obj-$(CONFIG_PHY_MIPHY365X) += phy-miphy365x.o
1012 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
1113 obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
1214 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
1315 obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
1416 obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o
17+obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
1518 obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o
1619 obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o
1720 phy-exynos-usb2-y += phy-samsung-usb2.o
@@ -20,3 +23,5 @@ phy-exynos-usb2-$(CONFIG_PHY_EXYNOS4X12_USB2) += phy-exynos4x12-usb2.o · 2 unmodified lines
2023 phy-exynos-usb2-$(CONFIG_PHY_EXYNOS5250_USB2) += phy-exynos5250-usb2.o
2124 obj-$(CONFIG_PHY_EXYNOS5_USBDRD) += phy-exynos5-usbdrd.o
2225 obj-$(CONFIG_PHY_XGENE) += phy-xgene.o
26+obj-$(CONFIG_PHY_QCOM_APQ8064_SATA) += phy-qcom-apq8064-sata.o
27+obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o
drivers/phy/phy-bcm-kona-usb2.c+1−1
@@ -117,7 +117,7 @@ static int bcm_kona_usb2_probe(struct platform_device *pdev) · 116 unmodified lines
117117
118118 platform_set_drvdata(pdev, phy);
119119
120− gphy = devm_phy_create(dev, &ops, NULL);
120+ gphy = devm_phy_create(dev, NULL, &ops, NULL);
121121 if (IS_ERR(gphy))
122122 return PTR_ERR(gphy);
123123
drivers/phy/phy-berlin-sata.c+284−0
@@ -0,0 +1,284 @@
1+/*
2+ * Marvell Berlin SATA PHY driver
3+ *
4+ * Copyright (C) 2014 Marvell Technology Group Ltd.
5+ *
6+ * Antoine Ténart <antoine.tenart@free-electrons.com>
7+ *
8+ * This file is licensed under the terms of the GNU General Public
9+ * License version 2. This program is licensed "as is" without any
10+ * warranty of any kind, whether express or implied.
11+ */
12+
13+#include <linux/clk.h>
14+#include <linux/module.h>
15+#include <linux/phy/phy.h>
16+#include <linux/io.h>
17+#include <linux/platform_device.h>
18+
19+#define HOST_VSA_ADDR 0x0
20+#define HOST_VSA_DATA 0x4
21+#define PORT_SCR_CTL 0x2c
22+#define PORT_VSR_ADDR 0x78
23+#define PORT_VSR_DATA 0x7c
24+
25+#define CONTROL_REGISTER 0x0
26+#define MBUS_SIZE_CONTROL 0x4
27+
28+#define POWER_DOWN_PHY0 BIT(6)
29+#define POWER_DOWN_PHY1 BIT(14)
30+#define MBUS_WRITE_REQUEST_SIZE_128 (BIT(2) << 16)
31+#define MBUS_READ_REQUEST_SIZE_128 (BIT(2) << 19)
32+
33+#define PHY_BASE 0x200
34+
35+/* register 0x01 */
36+#define REF_FREF_SEL_25 BIT(0)
37+#define PHY_MODE_SATA (0x0 << 5)
38+
39+/* register 0x02 */
40+#define USE_MAX_PLL_RATE BIT(12)
41+
42+/* register 0x23 */
43+#define DATA_BIT_WIDTH_10 (0x0 << 10)
44+#define DATA_BIT_WIDTH_20 (0x1 << 10)
45+#define DATA_BIT_WIDTH_40 (0x2 << 10)
46+
47+/* register 0x25 */
48+#define PHY_GEN_MAX_1_5 (0x0 << 10)
49+#define PHY_GEN_MAX_3_0 (0x1 << 10)
50+#define PHY_GEN_MAX_6_0 (0x2 << 10)
51+
52+struct phy_berlin_desc {
53+ struct phy *phy;
54+ u32 power_bit;
55+ unsigned index;
56+};
57+
58+struct phy_berlin_priv {
59+ void __iomem *base;
60+ spinlock_t lock;
61+ struct clk *clk;
62+ struct phy_berlin_desc **phys;
63+ unsigned nphys;
64+};
65+
66+static inline void phy_berlin_sata_reg_setbits(void __iomem *ctrl_reg, u32 reg,
67+ u32 mask, u32 val)
68+{
69+ u32 regval;
70+
71+ /* select register */
72+ writel(PHY_BASE + reg, ctrl_reg + PORT_VSR_ADDR);
73+
74+ /* set bits */
75+ regval = readl(ctrl_reg + PORT_VSR_DATA);
76+ regval &= ~mask;
77+ regval |= val;
78+ writel(regval, ctrl_reg + PORT_VSR_DATA);
79+}
80+
81+static int phy_berlin_sata_power_on(struct phy *phy)
82+{
83+ struct phy_berlin_desc *desc = phy_get_drvdata(phy);
84+ struct phy_berlin_priv *priv = dev_get_drvdata(phy->dev.parent);
85+ void __iomem *ctrl_reg = priv->base + 0x60 + (desc->index * 0x80);
86+ int ret = 0;
87+ u32 regval;
88+
89+ clk_prepare_enable(priv->clk);
90+
91+ spin_lock(&priv->lock);
92+
93+ /* Power on PHY */
94+ writel(CONTROL_REGISTER, priv->base + HOST_VSA_ADDR);
95+ regval = readl(priv->base + HOST_VSA_DATA);
96+ regval &= ~desc->power_bit;
97+ writel(regval, priv->base + HOST_VSA_DATA);
98+
99+ /* Configure MBus */
100+ writel(MBUS_SIZE_CONTROL, priv->base + HOST_VSA_ADDR);
101+ regval = readl(priv->base + HOST_VSA_DATA);
102+ regval |= MBUS_WRITE_REQUEST_SIZE_128 | MBUS_READ_REQUEST_SIZE_128;
103+ writel(regval, priv->base + HOST_VSA_DATA);
104+
105+ /* set PHY mode and ref freq to 25 MHz */
106+ phy_berlin_sata_reg_setbits(ctrl_reg, 0x1, 0xff,
107+ REF_FREF_SEL_25 | PHY_MODE_SATA);
108+
109+ /* set PHY up to 6 Gbps */
110+ phy_berlin_sata_reg_setbits(ctrl_reg, 0x25, 0xc00, PHY_GEN_MAX_6_0);
111+
112+ /* set 40 bits width */
113+ phy_berlin_sata_reg_setbits(ctrl_reg, 0x23, 0xc00, DATA_BIT_WIDTH_40);
114+
115+ /* use max pll rate */
116+ phy_berlin_sata_reg_setbits(ctrl_reg, 0x2, 0x0, USE_MAX_PLL_RATE);
117+
118+ /* set Gen3 controller speed */
119+ regval = readl(ctrl_reg + PORT_SCR_CTL);
120+ regval &= ~GENMASK(7, 4);
121+ regval |= 0x30;
122+ writel(regval, ctrl_reg + PORT_SCR_CTL);
123+
124+ spin_unlock(&priv->lock);
125+
126+ clk_disable_unprepare(priv->clk);
127+
128+ return ret;
129+}
130+
131+static int phy_berlin_sata_power_off(struct phy *phy)
132+{
133+ struct phy_berlin_desc *desc = phy_get_drvdata(phy);
134+ struct phy_berlin_priv *priv = dev_get_drvdata(phy->dev.parent);
135+ u32 regval;
136+
137+ clk_prepare_enable(priv->clk);
138+
139+ spin_lock(&priv->lock);
140+
141+ /* Power down PHY */
142+ writel(CONTROL_REGISTER, priv->base + HOST_VSA_ADDR);
143+ regval = readl(priv->base + HOST_VSA_DATA);
144+ regval |= desc->power_bit;
145+ writel(regval, priv->base + HOST_VSA_DATA);
146+
147+ spin_unlock(&priv->lock);
148+
149+ clk_disable_unprepare(priv->clk);
150+
151+ return 0;
152+}
153+
154+static struct phy *phy_berlin_sata_phy_xlate(struct device *dev,
155+ struct of_phandle_args *args)
156+{
157+ struct phy_berlin_priv *priv = dev_get_drvdata(dev);
158+ int i;
159+
160+ if (WARN_ON(args->args[0] >= priv->nphys))
161+ return ERR_PTR(-ENODEV);
162+
163+ for (i = 0; i < priv->nphys; i++) {
164+ if (priv->phys[i]->index == args->args[0])
165+ break;
166+ }
167+
168+ if (i == priv->nphys)
169+ return ERR_PTR(-ENODEV);
170+
171+ return priv->phys[i]->phy;
172+}
173+
174+static struct phy_ops phy_berlin_sata_ops = {
175+ .power_on = phy_berlin_sata_power_on,
176+ .power_off = phy_berlin_sata_power_off,
177+ .owner = THIS_MODULE,
178+};
179+
180+static u32 phy_berlin_power_down_bits[] = {
181+ POWER_DOWN_PHY0,
182+ POWER_DOWN_PHY1,
183+};
184+
185+static int phy_berlin_sata_probe(struct platform_device *pdev)
186+{
187+ struct device *dev = &pdev->dev;
188+ struct device_node *child;
189+ struct phy *phy;
190+ struct phy_provider *phy_provider;
191+ struct phy_berlin_priv *priv;
192+ struct resource *res;
193+ int i = 0;
194+ u32 phy_id;
195+
196+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
197+ if (!priv)
198+ return -ENOMEM;
199+
200+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
201+ if (!res)
202+ return -EINVAL;
203+
204+ priv->base = devm_ioremap(dev, res->start, resource_size(res));
205+ if (!priv->base)
206+ return -ENOMEM;
207+
208+ priv->clk = devm_clk_get(dev, NULL);
209+ if (IS_ERR(priv->clk))
210+ return PTR_ERR(priv->clk);
211+
212+ priv->nphys = of_get_child_count(dev->of_node);
213+ if (priv->nphys == 0)
214+ return -ENODEV;
215+
216+ priv->phys = devm_kzalloc(dev, priv->nphys * sizeof(*priv->phys),
217+ GFP_KERNEL);
218+ if (!priv->phys)
219+ return -ENOMEM;
220+
221+ dev_set_drvdata(dev, priv);
222+ spin_lock_init(&priv->lock);
223+
224+ for_each_available_child_of_node(dev->of_node, child) {
225+ struct phy_berlin_desc *phy_desc;
226+
227+ if (of_property_read_u32(child, "reg", &phy_id)) {
228+ dev_err(dev, "missing reg property in node %s\n",
229+ child->name);
230+ return -EINVAL;
231+ }
232+
233+ if (phy_id >= ARRAY_SIZE(phy_berlin_power_down_bits)) {
234+ dev_err(dev, "invalid reg in node %s\n", child->name);
235+ return -EINVAL;
236+ }
237+
238+ phy_desc = devm_kzalloc(dev, sizeof(*phy_desc), GFP_KERNEL);
239+ if (!phy_desc)
240+ return -ENOMEM;
241+
242+ phy = devm_phy_create(dev, NULL, &phy_berlin_sata_ops, NULL);
243+ if (IS_ERR(phy)) {
244+ dev_err(dev, "failed to create PHY %d\n", phy_id);
245+ return PTR_ERR(phy);
246+ }
247+
248+ phy_desc->phy = phy;
249+ phy_desc->power_bit = phy_berlin_power_down_bits[phy_id];
250+ phy_desc->index = phy_id;
251+ phy_set_drvdata(phy, phy_desc);
252+
253+ priv->phys[i++] = phy_desc;
254+
255+ /* Make sure the PHY is off */
256+ phy_berlin_sata_power_off(phy);
257+ }
258+
259+ phy_provider =
260+ devm_of_phy_provider_register(dev, phy_berlin_sata_phy_xlate);
261+ if (IS_ERR(phy_provider))
262+ return PTR_ERR(phy_provider);
263+
264+ return 0;
265+}
266+
267+static const struct of_device_id phy_berlin_sata_of_match[] = {
268+ { .compatible = "marvell,berlin2q-sata-phy" },
269+ { },
270+};
271+
272+static struct platform_driver phy_berlin_sata_driver = {
273+ .probe = phy_berlin_sata_probe,
274+ .driver = {
275+ .name = "phy-berlin-sata",
276+ .owner = THIS_MODULE,
277+ .of_match_table = phy_berlin_sata_of_match,
278+ },
279+};
280+module_platform_driver(phy_berlin_sata_driver);
281+
282+MODULE_DESCRIPTION("Marvell Berlin SATA PHY driver");
283+MODULE_AUTHOR("Antoine Ténart <antoine.tenart@free-electrons.com>");
284+MODULE_LICENSE("GPL v2");
drivers/phy/phy-core.c+49−7
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <linux/phy/phy.h>
2222 #include <linux/idr.h>
2323 #include <linux/pm_runtime.h>
24+#include <linux/regulator/consumer.h>
2425
2526 static struct class *phy_class;
2627 static DEFINE_MUTEX(phy_provider_mutex);
@@ -86,10 +87,15 @@ static struct phy *phy_lookup(struct device *device, const char *port) · 59 unmodified lines
8687 static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
8788 {
8889 struct phy_provider *phy_provider;
90+ struct device_node *child;
8991
9092 list_for_each_entry(phy_provider, &phy_provider_list, list) {
9193 if (phy_provider->dev->of_node == node)
9294 return phy_provider;
95+
96+ for_each_child_of_node(phy_provider->dev->of_node, child)
97+ if (child == node)
98+ return phy_provider;
9399 }
94100
95101 return ERR_PTR(-EPROBE_DEFER);
@@ -226,6 +232,12 @@ int phy_power_on(struct phy *phy) · 130 unmodified lines
226232 if (!phy)
227233 return 0;
228234
235+ if (phy->pwr) {
236+ ret = regulator_enable(phy->pwr);
237+ if (ret)
238+ return ret;
239+ }
240+
229241 ret = phy_pm_runtime_get_sync(phy);
230242 if (ret < 0 && ret != -ENOTSUPP)
231243 return ret;
@@ -247,6 +259,8 @@ int phy_power_on(struct phy *phy) · 15 unmodified lines
247259 out:
248260 mutex_unlock(&phy->mutex);
249261 phy_pm_runtime_put_sync(phy);
262+ if (phy->pwr)
263+ regulator_disable(phy->pwr);
250264
251265 return ret;
252266 }
@@ -272,6 +286,9 @@ int phy_power_off(struct phy *phy) · 19 unmodified lines
272286 mutex_unlock(&phy->mutex);
273287 phy_pm_runtime_put(phy);
274288
289+ if (phy->pwr)
290+ regulator_disable(phy->pwr);
291+
275292 return 0;
276293 }
277294 EXPORT_SYMBOL_GPL(phy_power_off);
@@ -398,13 +415,20 @@ struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args · 120 unmodified lines
398415 struct phy *phy;
399416 struct class_dev_iter iter;
400417 struct device_node *node = dev->of_node;
418+ struct device_node *child;
401419
402420 class_dev_iter_init(&iter, phy_class, NULL, NULL);
403421 while ((dev = class_dev_iter_next(&iter))) {
404422 phy = to_phy(dev);
405− if (node != phy->dev.of_node)
423+ if (node != phy->dev.of_node) {
424+ for_each_child_of_node(node, child) {
425+ if (child == phy->dev.of_node)
426+ goto phy_found;
427+ }
406428 continue;
429+ }
407430
431+phy_found:
408432 class_dev_iter_exit(&iter);
409433 return phy;
410434 }
@@ -562,13 +586,15 @@ EXPORT_SYMBOL_GPL(devm_of_phy_get); · 151 unmodified lines
562586 /**
563587 * phy_create() - create a new phy
564588 * @dev: device that is creating the new phy
589+ * @node: device node of the phy
565590 * @ops: function pointers for performing phy operations
566591 * @init_data: contains the list of PHY consumers or NULL
567592 *
568593 * Called to create a phy using phy framework.
569594 */
570−struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
571− struct phy_init_data *init_data)
595+struct phy *phy_create(struct device *dev, struct device_node *node,
596+ const struct phy_ops *ops,
597+ struct phy_init_data *init_data)
572598 {
573599 int ret;
574600 int id;
@@ -588,12 +614,22 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops, · 13 unmodified lines
588614 goto free_phy;
589615 }
590616
617+ /* phy-supply */
618+ phy->pwr = regulator_get_optional(dev, "phy");
619+ if (IS_ERR(phy->pwr)) {
620+ if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) {
621+ ret = -EPROBE_DEFER;
622+ goto free_ida;
623+ }
624+ phy->pwr = NULL;
625+ }
626+
591627 device_initialize(&phy->dev);
592628 mutex_init(&phy->mutex);
593629
594630 phy->dev.class = phy_class;
595631 phy->dev.parent = dev;
596− phy->dev.of_node = dev->of_node;
632+ phy->dev.of_node = node ?: dev->of_node;
597633 phy->id = id;
598634 phy->ops = ops;
599635 phy->init_data = init_data;
@@ -617,6 +653,9 @@ put_dev: · 17 unmodified lines
617653 put_device(&phy->dev); /* calls phy_release() which frees resources */
618654 return ERR_PTR(ret);
619655
656+free_ida:
657+ ida_simple_remove(&phy_ida, phy->id);
658+
620659 free_phy:
621660 kfree(phy);
622661 return ERR_PTR(ret);
@@ -626,6 +665,7 @@ EXPORT_SYMBOL_GPL(phy_create); · 3 unmodified lines
626665 /**
627666 * devm_phy_create() - create a new phy
628667 * @dev: device that is creating the new phy
668+ * @node: device node of the phy
629669 * @ops: function pointers for performing phy operations
630670 * @init_data: contains the list of PHY consumers or NULL
631671 *
@@ -634,8 +674,9 @@ EXPORT_SYMBOL_GPL(phy_create); · 2 unmodified lines
634674 * On driver detach, release function is invoked on the devres data,
635675 * then, devres data is freed.
636676 */
637−struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops,
638− struct phy_init_data *init_data)
677+struct phy *devm_phy_create(struct device *dev, struct device_node *node,
678+ const struct phy_ops *ops,
679+ struct phy_init_data *init_data)
639680 {
640681 struct phy **ptr, *phy;
641682
@@ -643,7 +684,7 @@ struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops, · 1 unmodified line
643684 if (!ptr)
644685 return ERR_PTR(-ENOMEM);
645686
646− phy = phy_create(dev, ops, init_data);
687+ phy = phy_create(dev, node, ops, init_data);
647688 if (!IS_ERR(phy)) {
648689 *ptr = phy;
649690 devres_add(dev, ptr);
@@ -800,6 +841,7 @@ static void phy_release(struct device *dev) · 150 unmodified lines
800841
801842 phy = to_phy(dev);
802843 dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
844+ regulator_put(phy->pwr);
803845 ida_simple_remove(&phy_ida, phy->id);
804846 kfree(phy);
805847 }
drivers/phy/phy-exynos-dp-video.c+3−4
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 * published by the Free Software Foundation.
1010 */
1111
12+#include <linux/err.h>
1213 #include <linux/io.h>
1314 #include <linux/kernel.h>
1415 #include <linux/module.h>
@@ -76,7 +77,7 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev) · 61 unmodified lines
7677 if (IS_ERR(state->regs))
7778 return PTR_ERR(state->regs);
7879
79− phy = devm_phy_create(dev, &exynos_dp_video_phy_ops, NULL);
80+ phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops, NULL);
8081 if (IS_ERR(phy)) {
8182 dev_err(dev, "failed to create Display Port PHY\n");
8283 return PTR_ERR(phy);
@@ -84,10 +85,8 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev) · 1 unmodified line
8485 phy_set_drvdata(phy, state);
8586
8687 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
87− if (IS_ERR(phy_provider))
88− return PTR_ERR(phy_provider);
8988
90− return 0;
89+ return PTR_ERR_OR_ZERO(phy_provider);
9190 }
9291
9392 static const struct of_device_id exynos_dp_video_phy_of_match[] = {
drivers/phy/phy-exynos-mipi-video.c+3−4
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 * published by the Free Software Foundation.
1010 */
1111
12+#include <linux/err.h>
1213 #include <linux/io.h>
1314 #include <linux/kernel.h>
1415 #include <linux/module.h>
@@ -135,7 +136,7 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev) · 120 unmodified lines
135136 spin_lock_init(&state->slock);
136137
137138 for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) {
138− struct phy *phy = devm_phy_create(dev,
139+ struct phy *phy = devm_phy_create(dev, NULL,
139140 &exynos_mipi_video_phy_ops, NULL);
140141 if (IS_ERR(phy)) {
141142 dev_err(dev, "failed to create PHY %d\n", i);
@@ -149,10 +150,8 @@ static int exynos_mipi_video_phy_probe(struct platform_device *pdev) · 7 unmodified lines
149150
150151 phy_provider = devm_of_phy_provider_register(dev,
151152 exynos_mipi_video_phy_xlate);
152− if (IS_ERR(phy_provider))
153− return PTR_ERR(phy_provider);
154153
155− return 0;
154+ return PTR_ERR_OR_ZERO(phy_provider);
156155 }
157156
158157 static const struct of_device_id exynos_mipi_video_phy_of_match[] = {
drivers/phy/phy-exynos4x12-usb2.c+88−37
@@ -67,6 +67,8 @@ · 66 unmodified lines
6767 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_24MHZ (0x5 << 0)
6868 #define EXYNOS_4x12_UPHYCLK_PHYFSEL_50MHZ (0x7 << 0)
6969
70+#define EXYNOS_3250_UPHYCLK_REFCLKSEL (0x2 << 8)
71+
7072 #define EXYNOS_4x12_UPHYCLK_PHY0_ID_PULLUP BIT(3)
7173 #define EXYNOS_4x12_UPHYCLK_PHY0_COMMON_ON BIT(4)
7274 #define EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON BIT(7)
@@ -86,13 +88,23 @@ · 13 unmodified lines
8688 #define EXYNOS_4x12_URSTCON_OTG_HLINK BIT(1)
8789 #define EXYNOS_4x12_URSTCON_OTG_PHYLINK BIT(2)
8890 #define EXYNOS_4x12_URSTCON_HOST_PHY BIT(3)
91+/* The following bit defines are presented in the
92+ * order taken from the Exynos4412 reference manual.
93+ *
94+ * During experiments with the hardware and debugging
95+ * it was determined that the hardware behaves contrary
96+ * to the manual.
97+ *
98+ * The following bit values were chaned accordingly to the
99+ * results of real hardware experiments.
100+ */
89101 #define EXYNOS_4x12_URSTCON_PHY1 BIT(4)
90−#define EXYNOS_4x12_URSTCON_HSIC0 BIT(5)
91−#define EXYNOS_4x12_URSTCON_HSIC1 BIT(6)
102+#define EXYNOS_4x12_URSTCON_HSIC0 BIT(6)
103+#define EXYNOS_4x12_URSTCON_HSIC1 BIT(5)
92104 #define EXYNOS_4x12_URSTCON_HOST_LINK_ALL BIT(7)
93−#define EXYNOS_4x12_URSTCON_HOST_LINK_P0 BIT(8)
105+#define EXYNOS_4x12_URSTCON_HOST_LINK_P0 BIT(10)
94106 #define EXYNOS_4x12_URSTCON_HOST_LINK_P1 BIT(9)
95−#define EXYNOS_4x12_URSTCON_HOST_LINK_P2 BIT(10)
107+#define EXYNOS_4x12_URSTCON_HOST_LINK_P2 BIT(8)
96108
97109 /* Isolation, configured in the power management unit */
98110 #define EXYNOS_4x12_USB_ISOL_OFFSET 0x704
@@ -187,7 +199,12 @@ static void exynos4x12_setup_clk(struct samsung_usb2_phy_instance *inst) · 88 unmodified lines
187199
188200 clk = readl(drv->reg_phy + EXYNOS_4x12_UPHYCLK);
189201 clk &= ~EXYNOS_4x12_UPHYCLK_PHYFSEL_MASK;
202+
203+ if (drv->cfg->has_refclk_sel)
204+ clk = EXYNOS_3250_UPHYCLK_REFCLKSEL;
205+
190206 clk |= drv->ref_reg_val << EXYNOS_4x12_UPHYCLK_PHYFSEL_OFFSET;
207+ clk |= EXYNOS_4x12_UPHYCLK_PHY1_COMMON_ON;
191208 writel(clk, drv->reg_phy + EXYNOS_4x12_UPHYCLK);
192209 }
193210
@@ -198,27 +215,22 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on) · 4 unmodified lines
198215 u32 phypwr = 0;
199216 u32 rst;
200217 u32 pwr;
201− u32 mode = 0;
202− u32 switch_mode = 0;
203218
204219 switch (inst->cfg->id) {
205220 case EXYNOS4x12_DEVICE:
206221 phypwr = EXYNOS_4x12_UPHYPWR_PHY0;
207222 rstbits = EXYNOS_4x12_URSTCON_PHY0;
208− mode = EXYNOS_4x12_MODE_SWITCH_DEVICE;
209− switch_mode = 1;
210223 break;
211224 case EXYNOS4x12_HOST:
212225 phypwr = EXYNOS_4x12_UPHYPWR_PHY1;
213− rstbits = EXYNOS_4x12_URSTCON_HOST_PHY;
214− mode = EXYNOS_4x12_MODE_SWITCH_HOST;
215− switch_mode = 1;
226+ rstbits = EXYNOS_4x12_URSTCON_HOST_PHY |
227+ EXYNOS_4x12_URSTCON_PHY1 |
228+ EXYNOS_4x12_URSTCON_HOST_LINK_P0;
216229 break;
217230 case EXYNOS4x12_HSIC0:
218231 phypwr = EXYNOS_4x12_UPHYPWR_HSIC0;
219− rstbits = EXYNOS_4x12_URSTCON_HSIC1 |
220− EXYNOS_4x12_URSTCON_HOST_LINK_P0 |
221− EXYNOS_4x12_URSTCON_HOST_PHY;
232+ rstbits = EXYNOS_4x12_URSTCON_HSIC0 |
233+ EXYNOS_4x12_URSTCON_HOST_LINK_P1;
222234 break;
223235 case EXYNOS4x12_HSIC1:
224236 phypwr = EXYNOS_4x12_UPHYPWR_HSIC1;
@@ -228,11 +240,6 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on) · 3 unmodified lines
228240 };
229241
230242 if (on) {
231− if (switch_mode)
232− regmap_update_bits(drv->reg_sys,
233− EXYNOS_4x12_MODE_SWITCH_OFFSET,
234− EXYNOS_4x12_MODE_SWITCH_MASK, mode);
235−
236243 pwr = readl(drv->reg_phy + EXYNOS_4x12_UPHYPWR);
237244 pwr &= ~phypwr;
238245 writel(pwr, drv->reg_phy + EXYNOS_4x12_UPHYPWR);
@@ -253,41 +260,78 @@ static void exynos4x12_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on) · 14 unmodified lines
253260 }
254261 }
255262
256−static int exynos4x12_power_on(struct samsung_usb2_phy_instance *inst)
263+static void exynos4x12_power_on_int(struct samsung_usb2_phy_instance *inst)
257264 {
258− struct samsung_usb2_phy_driver *drv = inst->drv;
265+ if (inst->int_cnt++ > 0)
266+ return;
259267
260− inst->enabled = 1;
261268 exynos4x12_setup_clk(inst);
262− exynos4x12_phy_pwr(inst, 1);
263269 exynos4x12_isol(inst, 0);
270+ exynos4x12_phy_pwr(inst, 1);
271+}
272+
273+static int exynos4x12_power_on(struct samsung_usb2_phy_instance *inst)
274+{
275+ struct samsung_usb2_phy_driver *drv = inst->drv;
276+
277+ if (inst->ext_cnt++ > 0)
278+ return 0;
264279
265− /* Power on the device, as it is necessary for HSIC to work */
266− if (inst->cfg->id == EXYNOS4x12_HSIC0) {
267− struct samsung_usb2_phy_instance *device =
268− &drv->instances[EXYNOS4x12_DEVICE];
269− exynos4x12_phy_pwr(device, 1);
270− exynos4x12_isol(device, 0);
280+ if (inst->cfg->id == EXYNOS4x12_HOST) {
281+ regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET,
282+ EXYNOS_4x12_MODE_SWITCH_MASK,
283+ EXYNOS_4x12_MODE_SWITCH_HOST);
284+ exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_DEVICE]);
271285 }
272286
287+ if (inst->cfg->id == EXYNOS4x12_DEVICE && drv->cfg->has_mode_switch)
288+ regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET,
289+ EXYNOS_4x12_MODE_SWITCH_MASK,
290+ EXYNOS_4x12_MODE_SWITCH_DEVICE);
291+
292+ if (inst->cfg->id == EXYNOS4x12_HSIC0 ||
293+ inst->cfg->id == EXYNOS4x12_HSIC1) {
294+ exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_DEVICE]);
295+ exynos4x12_power_on_int(&drv->instances[EXYNOS4x12_HOST]);
296+ }
297+
298+ exynos4x12_power_on_int(inst);
299+
273300 return 0;
274301 }
275302
276−static int exynos4x12_power_off(struct samsung_usb2_phy_instance *inst)
303+static void exynos4x12_power_off_int(struct samsung_usb2_phy_instance *inst)
277304 {
278− struct samsung_usb2_phy_driver *drv = inst->drv;
279− struct samsung_usb2_phy_instance *device =
280− &drv->instances[EXYNOS4x12_DEVICE];
305+ if (inst->int_cnt-- > 1)
306+ return;
281307
282− inst->enabled = 0;
283308 exynos4x12_isol(inst, 1);
284309 exynos4x12_phy_pwr(inst, 0);
310+}
311+
312+static int exynos4x12_power_off(struct samsung_usb2_phy_instance *inst)
313+{
314+ struct samsung_usb2_phy_driver *drv = inst->drv;
315+
316+ if (inst->ext_cnt-- > 1)
317+ return 0;
318+
319+ if (inst->cfg->id == EXYNOS4x12_DEVICE && drv->cfg->has_mode_switch)
320+ regmap_update_bits(drv->reg_sys, EXYNOS_4x12_MODE_SWITCH_OFFSET,
321+ EXYNOS_4x12_MODE_SWITCH_MASK,
322+ EXYNOS_4x12_MODE_SWITCH_HOST);
323+
324+ if (inst->cfg->id == EXYNOS4x12_HOST)
325+ exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_DEVICE]);
285326
286− if (inst->cfg->id == EXYNOS4x12_HSIC0 && !device->enabled) {
287− exynos4x12_isol(device, 1);
288− exynos4x12_phy_pwr(device, 0);
327+ if (inst->cfg->id == EXYNOS4x12_HSIC0 ||
328+ inst->cfg->id == EXYNOS4x12_HSIC1) {
329+ exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_DEVICE]);
330+ exynos4x12_power_off_int(&drv->instances[EXYNOS4x12_HOST]);
289331 }
290332
333+ exynos4x12_power_off_int(inst);
334+
291335 return 0;
292336 }
293337
@@ -320,6 +364,13 @@ static const struct samsung_usb2_common_phy exynos4x12_phys[] = { · 26 unmodified lines
320364 {},
321365 };
322366
367+const struct samsung_usb2_phy_config exynos3250_usb2_phy_config = {
368+ .has_refclk_sel = 1,
369+ .num_phys = 1,
370+ .phys = exynos4x12_phys,
371+ .rate_to_clk = exynos4x12_rate_to_clk,
372+};
373+
323374 const struct samsung_usb2_phy_config exynos4x12_usb2_phy_config = {
324375 .has_mode_switch = 1,
325376 .num_phys = EXYNOS4x12_NUM_PHYS,
drivers/phy/phy-exynos5-usbdrd.c+5−4
@@ -506,7 +506,7 @@ static struct phy_ops exynos5_usbdrd_phy_ops = { · 505 unmodified lines
506506 .owner = THIS_MODULE,
507507 };
508508
509−const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = {
509+static const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = {
510510 {
511511 .id = EXYNOS5_DRDPHY_UTMI,
512512 .phy_isol = exynos5_usbdrd_phy_isol,
@@ -521,13 +521,13 @@ const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = { · 8 unmodified lines
521521 },
522522 };
523523
524−const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
524+static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
525525 .phy_cfg = phy_cfg_exynos5,
526526 .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
527527 .pmu_offset_usbdrd1_phy = EXYNOS5420_USBDRD1_PHY_CONTROL,
528528 };
529529
530−const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
530+static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
531531 .phy_cfg = phy_cfg_exynos5,
532532 .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
533533 };
@@ -635,7 +635,8 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev) · 101 unmodified lines
635635 dev_vdbg(dev, "Creating usbdrd_phy phy\n");
636636
637637 for (i = 0; i < EXYNOS5_DRDPHYS_NUM; i++) {
638− struct phy *phy = devm_phy_create(dev, &exynos5_usbdrd_phy_ops,
638+ struct phy *phy = devm_phy_create(dev, NULL,
639+ &exynos5_usbdrd_phy_ops,
639640 NULL);
640641 if (IS_ERR(phy)) {
641642 dev_err(dev, "Failed to create usbdrd_phy phy\n");
drivers/phy/phy-exynos5250-sata.c+1−1
@@ -210,7 +210,7 @@ static int exynos_sata_phy_probe(struct platform_device *pdev) · 209 unmodified lines
210210 return ret;
211211 }
212212
213− sata_phy->phy = devm_phy_create(dev, &exynos_sata_phy_ops, NULL);
213+ sata_phy->phy = devm_phy_create(dev, NULL, &exynos_sata_phy_ops, NULL);
214214 if (IS_ERR(sata_phy->phy)) {
215215 clk_disable_unprepare(sata_phy->phyclk);
216216 dev_err(dev, "failed to create PHY\n");
drivers/phy/phy-exynos5250-usb2.c+0−2
@@ -318,7 +318,6 @@ static int exynos5250_power_on(struct samsung_usb2_phy_instance *inst) · 317 unmodified lines
318318
319319 break;
320320 }
321− inst->enabled = 1;
322321 exynos5250_isol(inst, 0);
323322
324323 return 0;
@@ -331,7 +330,6 @@ static int exynos5250_power_off(struct samsung_usb2_phy_instance *inst) · 6 unmodified lines
331330 u32 otg;
332331 u32 hsic;
333332
334− inst->enabled = 0;
335333 exynos5250_isol(inst, 1);
336334
337335 switch (inst->cfg->id) {
drivers/phy/phy-hix5hd2-sata.c+192−0
@@ -0,0 +1,192 @@
1+/*
2+ * Copyright (c) 2014 Linaro Ltd.
3+ * Copyright (c) 2014 Hisilicon Limited.
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2 of the License, or
8+ * (at your option) any later version.
9+ */
10+
11+#include <linux/delay.h>
12+#include <linux/io.h>
13+#include <linux/mfd/syscon.h>
14+#include <linux/module.h>
15+#include <linux/phy/phy.h>
16+#include <linux/platform_device.h>
17+#include <linux/regmap.h>
18+
19+#define SATA_PHY0_CTLL 0xa0
20+#define MPLL_MULTIPLIER_SHIFT 1
21+#define MPLL_MULTIPLIER_MASK 0xfe
22+#define MPLL_MULTIPLIER_50M 0x3c
23+#define MPLL_MULTIPLIER_100M 0x1e
24+#define PHY_RESET BIT(0)
25+#define REF_SSP_EN BIT(9)
26+#define SSC_EN BIT(10)
27+#define REF_USE_PAD BIT(23)
28+
29+#define SATA_PORT_PHYCTL 0x174
30+#define SPEED_MODE_MASK 0x6f0000
31+#define HALF_RATE_SHIFT 16
32+#define PHY_CONFIG_SHIFT 18
33+#define GEN2_EN_SHIFT 21
34+#define SPEED_CTRL BIT(20)
35+
36+#define SATA_PORT_PHYCTL1 0x148
37+#define AMPLITUDE_MASK 0x3ffffe
38+#define AMPLITUDE_GEN3 0x68
39+#define AMPLITUDE_GEN3_SHIFT 15
40+#define AMPLITUDE_GEN2 0x56
41+#define AMPLITUDE_GEN2_SHIFT 8
42+#define AMPLITUDE_GEN1 0x56
43+#define AMPLITUDE_GEN1_SHIFT 1
44+
45+#define SATA_PORT_PHYCTL2 0x14c
46+#define PREEMPH_MASK 0x3ffff
47+#define PREEMPH_GEN3 0x20
48+#define PREEMPH_GEN3_SHIFT 12
49+#define PREEMPH_GEN2 0x15
50+#define PREEMPH_GEN2_SHIFT 6
51+#define PREEMPH_GEN1 0x5
52+#define PREEMPH_GEN1_SHIFT 0
53+
54+struct hix5hd2_priv {
55+ void __iomem *base;
56+ struct regmap *peri_ctrl;
57+};
58+
59+enum phy_speed_mode {
60+ SPEED_MODE_GEN1 = 0,
61+ SPEED_MODE_GEN2 = 1,
62+ SPEED_MODE_GEN3 = 2,
63+};
64+
65+static int hix5hd2_sata_phy_init(struct phy *phy)
66+{
67+ struct hix5hd2_priv *priv = phy_get_drvdata(phy);
68+ u32 val, data[2];
69+ int ret;
70+
71+ if (priv->peri_ctrl) {
72+ ret = of_property_read_u32_array(phy->dev.of_node,
73+ "hisilicon,power-reg",
74+ &data[0], 2);
75+ if (ret) {
76+ dev_err(&phy->dev, "Fail read hisilicon,power-reg\n");
77+ return ret;
78+ }
79+
80+ regmap_update_bits(priv->peri_ctrl, data[0],
81+ BIT(data[1]), BIT(data[1]));
82+ }
83+
84+ /* reset phy */
85+ val = readl_relaxed(priv->base + SATA_PHY0_CTLL);
86+ val &= ~(MPLL_MULTIPLIER_MASK | REF_USE_PAD);
87+ val |= MPLL_MULTIPLIER_50M << MPLL_MULTIPLIER_SHIFT |
88+ REF_SSP_EN | PHY_RESET;
89+ writel_relaxed(val, priv->base + SATA_PHY0_CTLL);
90+ msleep(20);
91+ val &= ~PHY_RESET;
92+ writel_relaxed(val, priv->base + SATA_PHY0_CTLL);
93+
94+ val = readl_relaxed(priv->base + SATA_PORT_PHYCTL1);
95+ val &= ~AMPLITUDE_MASK;
96+ val |= AMPLITUDE_GEN3 << AMPLITUDE_GEN3_SHIFT |
97+ AMPLITUDE_GEN2 << AMPLITUDE_GEN2_SHIFT |
98+ AMPLITUDE_GEN1 << AMPLITUDE_GEN1_SHIFT;
99+ writel_relaxed(val, priv->base + SATA_PORT_PHYCTL1);
100+
101+ val = readl_relaxed(priv->base + SATA_PORT_PHYCTL2);
102+ val &= ~PREEMPH_MASK;
103+ val |= PREEMPH_GEN3 << PREEMPH_GEN3_SHIFT |
104+ PREEMPH_GEN2 << PREEMPH_GEN2_SHIFT |
105+ PREEMPH_GEN1 << PREEMPH_GEN1_SHIFT;
106+ writel_relaxed(val, priv->base + SATA_PORT_PHYCTL2);
107+
108+ /* ensure PHYCTRL setting takes effect */
109+ val = readl_relaxed(priv->base + SATA_PORT_PHYCTL);
110+ val &= ~SPEED_MODE_MASK;
111+ val |= SPEED_MODE_GEN1 << HALF_RATE_SHIFT |
112+ SPEED_MODE_GEN1 << PHY_CONFIG_SHIFT |
113+ SPEED_MODE_GEN1 << GEN2_EN_SHIFT | SPEED_CTRL;
114+ writel_relaxed(val, priv->base + SATA_PORT_PHYCTL);
115+
116+ msleep(20);
117+ val &= ~SPEED_MODE_MASK;
118+ val |= SPEED_MODE_GEN3 << HALF_RATE_SHIFT |
119+ SPEED_MODE_GEN3 << PHY_CONFIG_SHIFT |
120+ SPEED_MODE_GEN3 << GEN2_EN_SHIFT | SPEED_CTRL;
121+ writel_relaxed(val, priv->base + SATA_PORT_PHYCTL);
122+
123+ val &= ~(SPEED_MODE_MASK | SPEED_CTRL);
124+ val |= SPEED_MODE_GEN2 << HALF_RATE_SHIFT |
125+ SPEED_MODE_GEN2 << PHY_CONFIG_SHIFT |
126+ SPEED_MODE_GEN2 << GEN2_EN_SHIFT;
127+ writel_relaxed(val, priv->base + SATA_PORT_PHYCTL);
128+
129+ return 0;
130+}
131+
132+static struct phy_ops hix5hd2_sata_phy_ops = {
133+ .init = hix5hd2_sata_phy_init,
134+ .owner = THIS_MODULE,
135+};
136+
137+static int hix5hd2_sata_phy_probe(struct platform_device *pdev)
138+{
139+ struct phy_provider *phy_provider;
140+ struct device *dev = &pdev->dev;
141+ struct resource *res;
142+ struct phy *phy;
143+ struct hix5hd2_priv *priv;
144+
145+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
146+ if (!priv)
147+ return -ENOMEM;
148+
149+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
150+ priv->base = devm_ioremap(dev, res->start, resource_size(res));
151+ if (!priv->base)
152+ return -ENOMEM;
153+
154+ priv->peri_ctrl = syscon_regmap_lookup_by_phandle(dev->of_node,
155+ "hisilicon,peripheral-syscon");
156+ if (IS_ERR(priv->peri_ctrl))
157+ priv->peri_ctrl = NULL;
158+
159+ phy = devm_phy_create(dev, NULL, &hix5hd2_sata_phy_ops, NULL);
160+ if (IS_ERR(phy)) {
161+ dev_err(dev, "failed to create PHY\n");
162+ return PTR_ERR(phy);
163+ }
164+
165+ phy_set_drvdata(phy, priv);
166+ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
167+ if (IS_ERR(phy_provider))
168+ return PTR_ERR(phy_provider);
169+
170+ return 0;
171+}
172+
173+static const struct of_device_id hix5hd2_sata_phy_of_match[] = {
174+ {.compatible = "hisilicon,hix5hd2-sata-phy",},
175+ { },
176+};
177+MODULE_DEVICE_TABLE(of, hix5hd2_sata_phy_of_match);
178+
179+static struct platform_driver hix5hd2_sata_phy_driver = {
180+ .probe = hix5hd2_sata_phy_probe,
181+ .driver = {
182+ .name = "hix5hd2-sata-phy",
183+ .owner = THIS_MODULE,
184+ .of_match_table = hix5hd2_sata_phy_of_match,
185+ }
186+};
187+module_platform_driver(hix5hd2_sata_phy_driver);
188+
189+MODULE_AUTHOR("Jiancheng Xue <xuejiancheng@huawei.com>");
190+MODULE_DESCRIPTION("HISILICON HIX5HD2 SATA PHY driver");
191+MODULE_ALIAS("platform:hix5hd2-sata-phy");
192+MODULE_LICENSE("GPL v2");
drivers/phy/phy-miphy365x.c+636−0
@@ -0,0 +1,636 @@
1+/*
2+ * Copyright (C) 2014 STMicroelectronics – All Rights Reserved
3+ *
4+ * STMicroelectronics PHY driver MiPHY365 (for SoC STiH416).
5+ *
6+ * Authors: Alexandre Torgue <alexandre.torgue@st.com>
7+ * Lee Jones <lee.jones@linaro.org>
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 version 2, as
11+ * published by the Free Software Foundation.
12+ *
13+ */
14+
15+#include <linux/platform_device.h>
16+#include <linux/io.h>
17+#include <linux/kernel.h>
18+#include <linux/module.h>
19+#include <linux/of.h>
20+#include <linux/of_platform.h>
21+#include <linux/of_address.h>
22+#include <linux/clk.h>
23+#include <linux/phy/phy.h>
24+#include <linux/delay.h>
25+#include <linux/mfd/syscon.h>
26+#include <linux/regmap.h>
27+
28+#include <dt-bindings/phy/phy-miphy365x.h>
29+
30+#define HFC_TIMEOUT 100
31+
32+#define SYSCFG_SELECT_SATA_MASK BIT(1)
33+#define SYSCFG_SELECT_SATA_POS 1
34+
35+/* MiPHY365x register definitions */
36+#define RESET_REG 0x00
37+#define RST_PLL BIT(1)
38+#define RST_PLL_CAL BIT(2)
39+#define RST_RX BIT(4)
40+#define RST_MACRO BIT(7)
41+
42+#define STATUS_REG 0x01
43+#define IDLL_RDY BIT(0)
44+#define PLL_RDY BIT(1)
45+#define DES_BIT_LOCK BIT(2)
46+#define DES_SYMBOL_LOCK BIT(3)
47+
48+#define CTRL_REG 0x02
49+#define TERM_EN BIT(0)
50+#define PCI_EN BIT(2)
51+#define DES_BIT_LOCK_EN BIT(3)
52+#define TX_POL BIT(5)
53+
54+#define INT_CTRL_REG 0x03
55+
56+#define BOUNDARY1_REG 0x10
57+#define SPDSEL_SEL BIT(0)
58+
59+#define BOUNDARY3_REG 0x12
60+#define TX_SPDSEL_GEN1_VAL 0
61+#define TX_SPDSEL_GEN2_VAL 0x01
62+#define TX_SPDSEL_GEN3_VAL 0x02
63+#define RX_SPDSEL_GEN1_VAL 0
64+#define RX_SPDSEL_GEN2_VAL (0x01 << 3)
65+#define RX_SPDSEL_GEN3_VAL (0x02 << 3)
66+
67+#define PCIE_REG 0x16
68+
69+#define BUF_SEL_REG 0x20
70+#define CONF_GEN_SEL_GEN3 0x02
71+#define CONF_GEN_SEL_GEN2 0x01
72+#define PD_VDDTFILTER BIT(4)
73+
74+#define TXBUF1_REG 0x21
75+#define SWING_VAL 0x04
76+#define SWING_VAL_GEN1 0x03
77+#define PREEMPH_VAL (0x3 << 5)
78+
79+#define TXBUF2_REG 0x22
80+#define TXSLEW_VAL 0x2
81+#define TXSLEW_VAL_GEN1 0x4
82+
83+#define RXBUF_OFFSET_CTRL_REG 0x23
84+
85+#define RXBUF_REG 0x25
86+#define SDTHRES_VAL 0x01
87+#define EQ_ON3 (0x03 << 4)
88+#define EQ_ON1 (0x01 << 4)
89+
90+#define COMP_CTRL1_REG 0x40
91+#define START_COMSR BIT(0)
92+#define START_COMZC BIT(1)
93+#define COMSR_DONE BIT(2)
94+#define COMZC_DONE BIT(3)
95+#define COMP_AUTO_LOAD BIT(4)
96+
97+#define COMP_CTRL2_REG 0x41
98+#define COMP_2MHZ_RAT_GEN1 0x1e
99+#define COMP_2MHZ_RAT 0xf
100+
101+#define COMP_CTRL3_REG 0x42
102+#define COMSR_COMP_REF 0x33
103+
104+#define COMP_IDLL_REG 0x47
105+#define COMZC_IDLL 0x2a
106+
107+#define PLL_CTRL1_REG 0x50
108+#define PLL_START_CAL BIT(0)
109+#define BUF_EN BIT(2)
110+#define SYNCHRO_TX BIT(3)
111+#define SSC_EN BIT(6)
112+#define CONFIG_PLL BIT(7)
113+
114+#define PLL_CTRL2_REG 0x51
115+#define BYPASS_PLL_CAL BIT(1)
116+
117+#define PLL_RAT_REG 0x52
118+
119+#define PLL_SSC_STEP_MSB_REG 0x56
120+#define PLL_SSC_STEP_MSB_VAL 0x03
121+
122+#define PLL_SSC_STEP_LSB_REG 0x57
123+#define PLL_SSC_STEP_LSB_VAL 0x63
124+
125+#define PLL_SSC_PER_MSB_REG 0x58
126+#define PLL_SSC_PER_MSB_VAL 0
127+
128+#define PLL_SSC_PER_LSB_REG 0x59
129+#define PLL_SSC_PER_LSB_VAL 0xf1
130+
131+#define IDLL_TEST_REG 0x72
132+#define START_CLK_HF BIT(6)
133+
134+#define DES_BITLOCK_REG 0x86
135+#define BIT_LOCK_LEVEL 0x01
136+#define BIT_LOCK_CNT_512 (0x03 << 5)
137+
138+struct miphy365x_phy {
139+ struct phy *phy;
140+ void __iomem *base;
141+ bool pcie_tx_pol_inv;
142+ bool sata_tx_pol_inv;
143+ u32 sata_gen;
144+ u64 ctrlreg;
145+ u8 type;
146+};
147+
148+struct miphy365x_dev {
149+ struct device *dev;
150+ struct regmap *regmap;
151+ struct mutex miphy_mutex;
152+ struct miphy365x_phy **phys;
153+};
154+
155+/*
156+ * These values are represented in Device tree. They are considered to be ABI
157+ * and although they can be extended any existing values must not change.
158+ */
159+enum miphy_sata_gen {
160+ SATA_GEN1 = 1,
161+ SATA_GEN2,
162+ SATA_GEN3
163+};
164+
165+static u8 rx_tx_spd[] = {
166+ TX_SPDSEL_GEN1_VAL | RX_SPDSEL_GEN1_VAL,
167+ TX_SPDSEL_GEN2_VAL | RX_SPDSEL_GEN2_VAL,
168+ TX_SPDSEL_GEN3_VAL | RX_SPDSEL_GEN3_VAL
169+};
170+
171+/*
172+ * This function selects the system configuration,
173+ * either two SATA, one SATA and one PCIe, or two PCIe lanes.
174+ */
175+static int miphy365x_set_path(struct miphy365x_phy *miphy_phy,
176+ struct miphy365x_dev *miphy_dev)
177+{
178+ bool sata = (miphy_phy->type == MIPHY_TYPE_SATA);
179+
180+ return regmap_update_bits(miphy_dev->regmap,
181+ (unsigned int)miphy_phy->ctrlreg,
182+ SYSCFG_SELECT_SATA_MASK,
183+ sata << SYSCFG_SELECT_SATA_POS);
184+}
185+
186+static int miphy365x_init_pcie_port(struct miphy365x_phy *miphy_phy,
187+ struct miphy365x_dev *miphy_dev)
188+{
189+ u8 val;
190+
191+ if (miphy_phy->pcie_tx_pol_inv) {
192+ /* Invert Tx polarity and clear pci_txdetect_pol bit */
193+ val = TERM_EN | PCI_EN | DES_BIT_LOCK_EN | TX_POL;
194+ writeb_relaxed(val, miphy_phy->base + CTRL_REG);
195+ writeb_relaxed(0x00, miphy_phy->base + PCIE_REG);
196+ }
197+
198+ return 0;
199+}
200+
201+static inline int miphy365x_hfc_not_rdy(struct miphy365x_phy *miphy_phy,
202+ struct miphy365x_dev *miphy_dev)
203+{
204+ unsigned long timeout = jiffies + msecs_to_jiffies(HFC_TIMEOUT);
205+ u8 mask = IDLL_RDY | PLL_RDY;
206+ u8 regval;
207+
208+ do {
209+ regval = readb_relaxed(miphy_phy->base + STATUS_REG);
210+ if (!(regval & mask))
211+ return 0;
212+
213+ usleep_range(2000, 2500);
214+ } while (time_before(jiffies, timeout));
215+
216+ dev_err(miphy_dev->dev, "HFC ready timeout!\n");
217+ return -EBUSY;
218+}
219+
220+static inline int miphy365x_rdy(struct miphy365x_phy *miphy_phy,
221+ struct miphy365x_dev *miphy_dev)
222+{
223+ unsigned long timeout = jiffies + msecs_to_jiffies(HFC_TIMEOUT);
224+ u8 mask = IDLL_RDY | PLL_RDY;
225+ u8 regval;
226+
227+ do {
228+ regval = readb_relaxed(miphy_phy->base + STATUS_REG);
229+ if ((regval & mask) == mask)
230+ return 0;
231+
232+ usleep_range(2000, 2500);
233+ } while (time_before(jiffies, timeout));
234+
235+ dev_err(miphy_dev->dev, "PHY not ready timeout!\n");
236+ return -EBUSY;
237+}
238+
239+static inline void miphy365x_set_comp(struct miphy365x_phy *miphy_phy,
240+ struct miphy365x_dev *miphy_dev)
241+{
242+ u8 val, mask;
243+
244+ if (miphy_phy->sata_gen == SATA_GEN1)
245+ writeb_relaxed(COMP_2MHZ_RAT_GEN1,
246+ miphy_phy->base + COMP_CTRL2_REG);
247+ else
248+ writeb_relaxed(COMP_2MHZ_RAT,
249+ miphy_phy->base + COMP_CTRL2_REG);
250+
251+ if (miphy_phy->sata_gen != SATA_GEN3) {
252+ writeb_relaxed(COMSR_COMP_REF,
253+ miphy_phy->base + COMP_CTRL3_REG);
254+ /*
255+ * Force VCO current to value defined by address 0x5A
256+ * and disable PCIe100Mref bit
257+ * Enable auto load compensation for pll_i_bias
258+ */
259+ writeb_relaxed(BYPASS_PLL_CAL, miphy_phy->base + PLL_CTRL2_REG);
260+ writeb_relaxed(COMZC_IDLL, miphy_phy->base + COMP_IDLL_REG);
261+ }
262+
263+ /*
264+ * Force restart compensation and enable auto load
265+ * for Comzc_Tx, Comzc_Rx and Comsr on macro
266+ */
267+ val = START_COMSR | START_COMZC | COMP_AUTO_LOAD;
268+ writeb_relaxed(val, miphy_phy->base + COMP_CTRL1_REG);
269+
270+ mask = COMSR_DONE | COMZC_DONE;
271+ while ((readb_relaxed(miphy_phy->base + COMP_CTRL1_REG) & mask) != mask)
272+ cpu_relax();
273+}
274+
275+static inline void miphy365x_set_ssc(struct miphy365x_phy *miphy_phy,
276+ struct miphy365x_dev *miphy_dev)
277+{
278+ u8 val;
279+
280+ /*
281+ * SSC Settings. SSC will be enabled through Link
282+ * SSC Ampl. = 0.4%
283+ * SSC Freq = 31KHz
284+ */
285+ writeb_relaxed(PLL_SSC_STEP_MSB_VAL,
286+ miphy_phy->base + PLL_SSC_STEP_MSB_REG);
287+ writeb_relaxed(PLL_SSC_STEP_LSB_VAL,
288+ miphy_phy->base + PLL_SSC_STEP_LSB_REG);
289+ writeb_relaxed(PLL_SSC_PER_MSB_VAL,
290+ miphy_phy->base + PLL_SSC_PER_MSB_REG);
291+ writeb_relaxed(PLL_SSC_PER_LSB_VAL,
292+ miphy_phy->base + PLL_SSC_PER_LSB_REG);
293+
294+ /* SSC Settings complete */
295+ if (miphy_phy->sata_gen == SATA_GEN1) {
296+ val = PLL_START_CAL | BUF_EN | SYNCHRO_TX | CONFIG_PLL;
297+ writeb_relaxed(val, miphy_phy->base + PLL_CTRL1_REG);
298+ } else {
299+ val = SSC_EN | PLL_START_CAL | BUF_EN | SYNCHRO_TX | CONFIG_PLL;
300+ writeb_relaxed(val, miphy_phy->base + PLL_CTRL1_REG);
301+ }
302+}
303+
304+static int miphy365x_init_sata_port(struct miphy365x_phy *miphy_phy,
305+ struct miphy365x_dev *miphy_dev)
306+{
307+ int ret;
308+ u8 val;
309+
310+ /*
311+ * Force PHY macro reset, PLL calibration reset, PLL reset
312+ * and assert Deserializer Reset
313+ */
314+ val = RST_PLL | RST_PLL_CAL | RST_RX | RST_MACRO;
315+ writeb_relaxed(val, miphy_phy->base + RESET_REG);
316+
317+ if (miphy_phy->sata_tx_pol_inv)
318+ writeb_relaxed(TX_POL, miphy_phy->base + CTRL_REG);
319+
320+ /*
321+ * Force macro1 to use rx_lspd, tx_lspd
322+ * Force Rx_Clock on first I-DLL phase
323+ * Force Des in HP mode on macro, rx_lspd, tx_lspd for Gen2/3
324+ */
325+ writeb_relaxed(SPDSEL_SEL, miphy_phy->base + BOUNDARY1_REG);
326+ writeb_relaxed(START_CLK_HF, miphy_phy->base + IDLL_TEST_REG);
327+ val = rx_tx_spd[miphy_phy->sata_gen];
328+ writeb_relaxed(val, miphy_phy->base + BOUNDARY3_REG);
329+
330+ /* Wait for HFC_READY = 0 */
331+ ret = miphy365x_hfc_not_rdy(miphy_phy, miphy_dev);
332+ if (ret)
333+ return ret;
334+
335+ /* Compensation Recalibration */
336+ miphy365x_set_comp(miphy_phy, miphy_dev);
337+
338+ switch (miphy_phy->sata_gen) {
339+ case SATA_GEN3:
340+ /*
341+ * TX Swing target 550-600mv peak to peak diff
342+ * Tx Slew target 90-110ps rising/falling time
343+ * Rx Eq ON3, Sigdet threshold SDTH1
344+ */
345+ val = PD_VDDTFILTER | CONF_GEN_SEL_GEN3;
346+ writeb_relaxed(val, miphy_phy->base + BUF_SEL_REG);
347+ val = SWING_VAL | PREEMPH_VAL;
348+ writeb_relaxed(val, miphy_phy->base + TXBUF1_REG);
349+ writeb_relaxed(TXSLEW_VAL, miphy_phy->base + TXBUF2_REG);
350+ writeb_relaxed(0x00, miphy_phy->base + RXBUF_OFFSET_CTRL_REG);
351+ val = SDTHRES_VAL | EQ_ON3;
352+ writeb_relaxed(val, miphy_phy->base + RXBUF_REG);
353+ break;
354+ case SATA_GEN2:
355+ /*
356+ * conf gen sel=0x1 to program Gen2 banked registers
357+ * VDDT filter ON
358+ * Tx Swing target 550-600mV peak-to-peak diff
359+ * Tx Slew target 90-110 ps rising/falling time
360+ * RX Equalization ON1, Sigdet threshold SDTH1
361+ */
362+ writeb_relaxed(CONF_GEN_SEL_GEN2,
363+ miphy_phy->base + BUF_SEL_REG);
364+ writeb_relaxed(SWING_VAL, miphy_phy->base + TXBUF1_REG);
365+ writeb_relaxed(TXSLEW_VAL, miphy_phy->base + TXBUF2_REG);
366+ val = SDTHRES_VAL | EQ_ON1;
367+ writeb_relaxed(val, miphy_phy->base + RXBUF_REG);
368+ break;
369+ case SATA_GEN1:
370+ /*
371+ * conf gen sel = 00b to program Gen1 banked registers
372+ * VDDT filter ON
373+ * Tx Swing target 500-550mV peak-to-peak diff
374+ * Tx Slew target120-140 ps rising/falling time
375+ */
376+ writeb_relaxed(PD_VDDTFILTER, miphy_phy->base + BUF_SEL_REG);
377+ writeb_relaxed(SWING_VAL_GEN1, miphy_phy->base + TXBUF1_REG);
378+ writeb_relaxed(TXSLEW_VAL_GEN1, miphy_phy->base + TXBUF2_REG);
379+ break;
380+ default:
381+ break;
382+ }
383+
384+ /* Force Macro1 in partial mode & release pll cal reset */
385+ writeb_relaxed(RST_RX, miphy_phy->base + RESET_REG);
386+ usleep_range(100, 150);
387+
388+ miphy365x_set_ssc(miphy_phy, miphy_dev);
389+
390+ /* Wait for phy_ready */
391+ ret = miphy365x_rdy(miphy_phy, miphy_dev);
392+ if (ret)
393+ return ret;
394+
395+ /*
396+ * Enable macro1 to use rx_lspd & tx_lspd
397+ * Release Rx_Clock on first I-DLL phase on macro1
398+ * Assert deserializer reset
399+ * des_bit_lock_en is set
400+ * bit lock detection strength
401+ * Deassert deserializer reset
402+ */
403+ writeb_relaxed(0x00, miphy_phy->base + BOUNDARY1_REG);
404+ writeb_relaxed(0x00, miphy_phy->base + IDLL_TEST_REG);
405+ writeb_relaxed(RST_RX, miphy_phy->base + RESET_REG);
406+ val = miphy_phy->sata_tx_pol_inv ?
407+ (TX_POL | DES_BIT_LOCK_EN) : DES_BIT_LOCK_EN;
408+ writeb_relaxed(val, miphy_phy->base + CTRL_REG);
409+
410+ val = BIT_LOCK_CNT_512 | BIT_LOCK_LEVEL;
411+ writeb_relaxed(val, miphy_phy->base + DES_BITLOCK_REG);
412+ writeb_relaxed(0x00, miphy_phy->base + RESET_REG);
413+
414+ return 0;
415+}
416+
417+static int miphy365x_init(struct phy *phy)
418+{
419+ struct miphy365x_phy *miphy_phy = phy_get_drvdata(phy);
420+ struct miphy365x_dev *miphy_dev = dev_get_drvdata(phy->dev.parent);
421+ int ret = 0;
422+
423+ mutex_lock(&miphy_dev->miphy_mutex);
424+
425+ ret = miphy365x_set_path(miphy_phy, miphy_dev);
426+ if (ret) {
427+ mutex_unlock(&miphy_dev->miphy_mutex);
428+ return ret;
429+ }
430+
431+ /* Initialise Miphy for PCIe or SATA */
432+ if (miphy_phy->type == MIPHY_TYPE_PCIE)
433+ ret = miphy365x_init_pcie_port(miphy_phy, miphy_dev);
434+ else
435+ ret = miphy365x_init_sata_port(miphy_phy, miphy_dev);
436+
437+ mutex_unlock(&miphy_dev->miphy_mutex);
438+
439+ return ret;
440+}
441+
442+int miphy365x_get_addr(struct device *dev, struct miphy365x_phy *miphy_phy,
443+ int index)
444+{
445+ struct device_node *phynode = miphy_phy->phy->dev.of_node;
446+ const char *name;
447+ const __be32 *taddr;
448+ int type = miphy_phy->type;
449+ int ret;
450+
451+ ret = of_property_read_string_index(phynode, "reg-names", index, &name);
452+ if (ret) {
453+ dev_err(dev, "no reg-names property not found\n");
454+ return ret;
455+ }
456+
457+ if (!strncmp(name, "syscfg", 6)) {
458+ taddr = of_get_address(phynode, index, NULL, NULL);
459+ if (!taddr) {
460+ dev_err(dev, "failed to fetch syscfg address\n");
461+ return -EINVAL;
462+ }
463+
464+ miphy_phy->ctrlreg = of_translate_address(phynode, taddr);
465+ if (miphy_phy->ctrlreg == OF_BAD_ADDR) {
466+ dev_err(dev, "failed to translate syscfg address\n");
467+ return -EINVAL;
468+ }
469+
470+ return 0;
471+ }
472+
473+ if (!((!strncmp(name, "sata", 4) && type == MIPHY_TYPE_SATA) ||
474+ (!strncmp(name, "pcie", 4) && type == MIPHY_TYPE_PCIE)))
475+ return 0;
476+
477+ miphy_phy->base = of_iomap(phynode, index);
478+ if (!miphy_phy->base) {
479+ dev_err(dev, "Failed to map %s\n", phynode->full_name);
480+ return -EINVAL;
481+ }
482+
483+ return 0;
484+}
485+
486+static struct phy *miphy365x_xlate(struct device *dev,
487+ struct of_phandle_args *args)
488+{
489+ struct miphy365x_dev *miphy_dev = dev_get_drvdata(dev);
490+ struct miphy365x_phy *miphy_phy = NULL;
491+ struct device_node *phynode = args->np;
492+ int ret, index;
493+
494+ if (!of_device_is_available(phynode)) {
495+ dev_warn(dev, "Requested PHY is disabled\n");
496+ return ERR_PTR(-ENODEV);
497+ }
498+
499+ if (args->args_count != 1) {
500+ dev_err(dev, "Invalid number of cells in 'phy' property\n");
501+ return ERR_PTR(-EINVAL);
502+ }
503+
504+ for (index = 0; index < of_get_child_count(dev->of_node); index++)
505+ if (phynode == miphy_dev->phys[index]->phy->dev.of_node) {
506+ miphy_phy = miphy_dev->phys[index];
507+ break;
508+ }
509+
510+ if (!miphy_phy) {
511+ dev_err(dev, "Failed to find appropriate phy\n");
512+ return ERR_PTR(-EINVAL);
513+ }
514+
515+ miphy_phy->type = args->args[0];
516+
517+ if (!(miphy_phy->type == MIPHY_TYPE_SATA ||
518+ miphy_phy->type == MIPHY_TYPE_PCIE)) {
519+ dev_err(dev, "Unsupported device type: %d\n", miphy_phy->type);
520+ return ERR_PTR(-EINVAL);
521+ }
522+
523+ /* Each port handles SATA and PCIE - third entry is always sysconf. */
524+ for (index = 0; index < 3; index++) {
525+ ret = miphy365x_get_addr(dev, miphy_phy, index);
526+ if (ret < 0)
527+ return ERR_PTR(ret);
528+ }
529+
530+ return miphy_phy->phy;
531+}
532+
533+static struct phy_ops miphy365x_ops = {
534+ .init = miphy365x_init,
535+ .owner = THIS_MODULE,
536+};
537+
538+static int miphy365x_of_probe(struct device_node *phynode,
539+ struct miphy365x_phy *miphy_phy)
540+{
541+ of_property_read_u32(phynode, "st,sata-gen", &miphy_phy->sata_gen);
542+ if (!miphy_phy->sata_gen)
543+ miphy_phy->sata_gen = SATA_GEN1;
544+
545+ miphy_phy->pcie_tx_pol_inv =
546+ of_property_read_bool(phynode, "st,pcie-tx-pol-inv");
547+
548+ miphy_phy->sata_tx_pol_inv =
549+ of_property_read_bool(phynode, "st,sata-tx-pol-inv");
550+
551+ return 0;
552+}
553+
554+static int miphy365x_probe(struct platform_device *pdev)
555+{
556+ struct device_node *child, *np = pdev->dev.of_node;
557+ struct miphy365x_dev *miphy_dev;
558+ struct phy_provider *provider;
559+ struct phy *phy;
560+ int chancount, port = 0;
561+ int ret;
562+
563+ miphy_dev = devm_kzalloc(&pdev->dev, sizeof(*miphy_dev), GFP_KERNEL);
564+ if (!miphy_dev)
565+ return -ENOMEM;
566+
567+ chancount = of_get_child_count(np);
568+ miphy_dev->phys = devm_kzalloc(&pdev->dev, sizeof(phy) * chancount,
569+ GFP_KERNEL);
570+ if (!miphy_dev->phys)
571+ return -ENOMEM;
572+
573+ miphy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
574+ if (IS_ERR(miphy_dev->regmap)) {
575+ dev_err(miphy_dev->dev, "No syscfg phandle specified\n");
576+ return PTR_ERR(miphy_dev->regmap);
577+ }
578+
579+ miphy_dev->dev = &pdev->dev;
580+
581+ dev_set_drvdata(&pdev->dev, miphy_dev);
582+
583+ mutex_init(&miphy_dev->miphy_mutex);
584+
585+ for_each_child_of_node(np, child) {
586+ struct miphy365x_phy *miphy_phy;
587+
588+ miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy),
589+ GFP_KERNEL);
590+ if (!miphy_phy)
591+ return -ENOMEM;
592+
593+ miphy_dev->phys[port] = miphy_phy;
594+
595+ phy = devm_phy_create(&pdev->dev, child, &miphy365x_ops, NULL);
596+ if (IS_ERR(phy)) {
597+ dev_err(&pdev->dev, "failed to create PHY\n");
598+ return PTR_ERR(phy);
599+ }
600+
601+ miphy_dev->phys[port]->phy = phy;
602+
603+ ret = miphy365x_of_probe(child, miphy_phy);
604+ if (ret)
605+ return ret;
606+
607+ phy_set_drvdata(phy, miphy_dev->phys[port]);
608+ port++;
609+ }
610+
611+ provider = devm_of_phy_provider_register(&pdev->dev, miphy365x_xlate);
612+ if (IS_ERR(provider))
613+ return PTR_ERR(provider);
614+
615+ return 0;
616+}
617+
618+static const struct of_device_id miphy365x_of_match[] = {
619+ { .compatible = "st,miphy365x-phy", },
620+ { },
621+};
622+MODULE_DEVICE_TABLE(of, miphy365x_of_match);
623+
624+static struct platform_driver miphy365x_driver = {
625+ .probe = miphy365x_probe,
626+ .driver = {
627+ .name = "miphy365x-phy",
628+ .owner = THIS_MODULE,
629+ .of_match_table = miphy365x_of_match,
630+ }
631+};
632+module_platform_driver(miphy365x_driver);
633+
634+MODULE_AUTHOR("Alexandre Torgue <alexandre.torgue@st.com>");
635+MODULE_DESCRIPTION("STMicroelectronics miphy365x driver");
636+MODULE_LICENSE("GPL v2");
drivers/phy/phy-mvebu-sata.c+1−1
@@ -99,7 +99,7 @@ static int phy_mvebu_sata_probe(struct platform_device *pdev) · 98 unmodified lines
9999 if (IS_ERR(priv->clk))
100100 return PTR_ERR(priv->clk);
101101
102− phy = devm_phy_create(&pdev->dev, &phy_mvebu_sata_ops, NULL);
102+ phy = devm_phy_create(&pdev->dev, NULL, &phy_mvebu_sata_ops, NULL);
103103 if (IS_ERR(phy))
104104 return PTR_ERR(phy);
105105
drivers/phy/phy-omap-control.c+51−1
@@ -26,6 +26,41 @@ · 25 unmodified lines
2626 #include <linux/clk.h>
2727 #include <linux/phy/omap_control_phy.h>
2828
29+/**
30+ * omap_control_pcie_pcs - set the PCS delay count
31+ * @dev: the control module device
32+ * @id: index of the pcie PHY (should be 1 or 2)
33+ * @delay: 8 bit delay value
34+ */
35+void omap_control_pcie_pcs(struct device *dev, u8 id, u8 delay)
36+{
37+ u32 val;
38+ struct omap_control_phy *control_phy;
39+
40+ if (IS_ERR(dev) || !dev) {
41+ pr_err("%s: invalid device\n", __func__);
42+ return;
43+ }
44+
45+ control_phy = dev_get_drvdata(dev);
46+ if (!control_phy) {
47+ dev_err(dev, "%s: invalid control phy device\n", __func__);
48+ return;
49+ }
50+
51+ if (control_phy->type != OMAP_CTRL_TYPE_PCIE) {
52+ dev_err(dev, "%s: unsupported operation\n", __func__);
53+ return;
54+ }
55+
56+ val = readl(control_phy->pcie_pcs);
57+ val &= ~(OMAP_CTRL_PCIE_PCS_MASK <<
58+ (id * OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT));
59+ val |= delay << (id * OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT);
60+ writel(val, control_phy->pcie_pcs);
61+}
62+EXPORT_SYMBOL_GPL(omap_control_pcie_pcs);
63+
2964 /**
3065 * omap_control_phy_power - power on/off the phy using control module reg
3166 * @dev: the control module device
@@ -61,6 +96,7 @@ void omap_control_phy_power(struct device *dev, int on) · 29 unmodified lines
6196 val |= OMAP_CTRL_DEV_PHY_PD;
6297 break;
6398
99+ case OMAP_CTRL_TYPE_PCIE:
64100 case OMAP_CTRL_TYPE_PIPE3:
65101 rate = clk_get_rate(control_phy->sys_clk);
66102 rate = rate/1000000;
@@ -211,6 +247,7 @@ EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); · 144 unmodified lines
211247 static const enum omap_control_phy_type otghs_data = OMAP_CTRL_TYPE_OTGHS;
212248 static const enum omap_control_phy_type usb2_data = OMAP_CTRL_TYPE_USB2;
213249 static const enum omap_control_phy_type pipe3_data = OMAP_CTRL_TYPE_PIPE3;
250+static const enum omap_control_phy_type pcie_data = OMAP_CTRL_TYPE_PCIE;
214251 static const enum omap_control_phy_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2;
215252 static const enum omap_control_phy_type am437usb2_data = OMAP_CTRL_TYPE_AM437USB2;
216253
@@ -227,6 +264,10 @@ static const struct of_device_id omap_control_phy_id_table[] = { · 10 unmodified lines
227264 .compatible = "ti,control-phy-pipe3",
228265 .data = &pipe3_data,
229266 },
267+ {
268+ .compatible = "ti,control-phy-pcie",
269+ .data = &pcie_data,
270+ },
230271 {
231272 .compatible = "ti,control-phy-usb2-dra7",
232273 .data = &dra7usb2_data,
@@ -279,7 +320,8 @@ static int omap_control_phy_probe(struct platform_device *pdev) · 46 unmodified lines
279320 }
280321 }
281322
282− if (control_phy->type == OMAP_CTRL_TYPE_PIPE3) {
323+ if (control_phy->type == OMAP_CTRL_TYPE_PIPE3 ||
324+ control_phy->type == OMAP_CTRL_TYPE_PCIE) {
283325 control_phy->sys_clk = devm_clk_get(control_phy->dev,
284326 "sys_clkin");
285327 if (IS_ERR(control_phy->sys_clk)) {
@@ -288,6 +330,14 @@ static int omap_control_phy_probe(struct platform_device *pdev) · 2 unmodified lines
288330 }
289331 }
290332
333+ if (control_phy->type == OMAP_CTRL_TYPE_PCIE) {
334+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
335+ "pcie_pcs");
336+ control_phy->pcie_pcs = devm_ioremap_resource(&pdev->dev, res);
337+ if (IS_ERR(control_phy->pcie_pcs))
338+ return PTR_ERR(control_phy->pcie_pcs);
339+ }
340+
291341 dev_set_drvdata(control_phy->dev, control_phy);
292342
293343 return 0;
drivers/phy/phy-omap-usb2.c+1−1
@@ -263,7 +263,7 @@ static int omap_usb2_probe(struct platform_device *pdev) · 262 unmodified lines
263263
264264 platform_set_drvdata(pdev, phy);
265265
266− generic_phy = devm_phy_create(phy->dev, &ops, NULL);
266+ generic_phy = devm_phy_create(phy->dev, NULL, &ops, NULL);
267267 if (IS_ERR(generic_phy))
268268 return PTR_ERR(generic_phy);
269269
drivers/phy/phy-qcom-apq8064-sata.c+289−0
@@ -0,0 +1,289 @@
1+/*
2+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.
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/io.h>
15+#include <linux/kernel.h>
16+#include <linux/module.h>
17+#include <linux/of.h>
18+#include <linux/time.h>
19+#include <linux/delay.h>
20+#include <linux/clk.h>
21+#include <linux/slab.h>
22+#include <linux/platform_device.h>
23+#include <linux/phy/phy.h>
24+
25+/* PHY registers */
26+#define UNIPHY_PLL_REFCLK_CFG 0x000
27+#define UNIPHY_PLL_PWRGEN_CFG 0x014
28+#define UNIPHY_PLL_GLB_CFG 0x020
29+#define UNIPHY_PLL_SDM_CFG0 0x038
30+#define UNIPHY_PLL_SDM_CFG1 0x03C
31+#define UNIPHY_PLL_SDM_CFG2 0x040
32+#define UNIPHY_PLL_SDM_CFG3 0x044
33+#define UNIPHY_PLL_SDM_CFG4 0x048
34+#define UNIPHY_PLL_SSC_CFG0 0x04C
35+#define UNIPHY_PLL_SSC_CFG1 0x050
36+#define UNIPHY_PLL_SSC_CFG2 0x054
37+#define UNIPHY_PLL_SSC_CFG3 0x058
38+#define UNIPHY_PLL_LKDET_CFG0 0x05C
39+#define UNIPHY_PLL_LKDET_CFG1 0x060
40+#define UNIPHY_PLL_LKDET_CFG2 0x064
41+#define UNIPHY_PLL_CAL_CFG0 0x06C
42+#define UNIPHY_PLL_CAL_CFG8 0x08C
43+#define UNIPHY_PLL_CAL_CFG9 0x090
44+#define UNIPHY_PLL_CAL_CFG10 0x094
45+#define UNIPHY_PLL_CAL_CFG11 0x098
46+#define UNIPHY_PLL_STATUS 0x0C0
47+
48+#define SATA_PHY_SER_CTRL 0x100
49+#define SATA_PHY_TX_DRIV_CTRL0 0x104
50+#define SATA_PHY_TX_DRIV_CTRL1 0x108
51+#define SATA_PHY_TX_IMCAL0 0x11C
52+#define SATA_PHY_TX_IMCAL2 0x124
53+#define SATA_PHY_RX_IMCAL0 0x128
54+#define SATA_PHY_EQUAL 0x13C
55+#define SATA_PHY_OOB_TERM 0x144
56+#define SATA_PHY_CDR_CTRL0 0x148
57+#define SATA_PHY_CDR_CTRL1 0x14C
58+#define SATA_PHY_CDR_CTRL2 0x150
59+#define SATA_PHY_CDR_CTRL3 0x154
60+#define SATA_PHY_PI_CTRL0 0x168
61+#define SATA_PHY_POW_DWN_CTRL0 0x180
62+#define SATA_PHY_POW_DWN_CTRL1 0x184
63+#define SATA_PHY_TX_DATA_CTRL 0x188
64+#define SATA_PHY_ALIGNP 0x1A4
65+#define SATA_PHY_TX_IMCAL_STAT 0x1E4
66+#define SATA_PHY_RX_IMCAL_STAT 0x1E8
67+
68+#define UNIPHY_PLL_LOCK BIT(0)
69+#define SATA_PHY_TX_CAL BIT(0)
70+#define SATA_PHY_RX_CAL BIT(0)
71+
72+/* default timeout set to 1 sec */
73+#define TIMEOUT_MS 10000
74+#define DELAY_INTERVAL_US 100
75+
76+struct qcom_apq8064_sata_phy {
77+ void __iomem *mmio;
78+ struct clk *cfg_clk;
79+ struct device *dev;
80+};
81+
82+/* Helper function to do poll and timeout */
83+static int read_poll_timeout(void __iomem *addr, u32 mask)
84+{
85+ unsigned long timeout = jiffies + msecs_to_jiffies(TIMEOUT_MS);
86+
87+ do {
88+ if (readl_relaxed(addr) & mask)
89+ return 0;
90+
91+ usleep_range(DELAY_INTERVAL_US, DELAY_INTERVAL_US + 50);
92+ } while (!time_after(jiffies, timeout));
93+
94+ return (readl_relaxed(addr) & mask) ? 0 : -ETIMEDOUT;
95+}
96+
97+static int qcom_apq8064_sata_phy_init(struct phy *generic_phy)
98+{
99+ struct qcom_apq8064_sata_phy *phy = phy_get_drvdata(generic_phy);
100+ void __iomem *base = phy->mmio;
101+ int ret = 0;
102+
103+ /* SATA phy initialization */
104+ writel_relaxed(0x01, base + SATA_PHY_SER_CTRL);
105+ writel_relaxed(0xB1, base + SATA_PHY_POW_DWN_CTRL0);
106+ /* Make sure the power down happens before power up */
107+ mb();
108+ usleep_range(10, 60);
109+
110+ writel_relaxed(0x01, base + SATA_PHY_POW_DWN_CTRL0);
111+ writel_relaxed(0x3E, base + SATA_PHY_POW_DWN_CTRL1);
112+ writel_relaxed(0x01, base + SATA_PHY_RX_IMCAL0);
113+ writel_relaxed(0x01, base + SATA_PHY_TX_IMCAL0);
114+ writel_relaxed(0x02, base + SATA_PHY_TX_IMCAL2);
115+
116+ /* Write UNIPHYPLL registers to configure PLL */
117+ writel_relaxed(0x04, base + UNIPHY_PLL_REFCLK_CFG);
118+ writel_relaxed(0x00, base + UNIPHY_PLL_PWRGEN_CFG);
119+
120+ writel_relaxed(0x0A, base + UNIPHY_PLL_CAL_CFG0);
121+ writel_relaxed(0xF3, base + UNIPHY_PLL_CAL_CFG8);
122+ writel_relaxed(0x01, base + UNIPHY_PLL_CAL_CFG9);
123+ writel_relaxed(0xED, base + UNIPHY_PLL_CAL_CFG10);
124+ writel_relaxed(0x02, base + UNIPHY_PLL_CAL_CFG11);
125+
126+ writel_relaxed(0x36, base + UNIPHY_PLL_SDM_CFG0);
127+ writel_relaxed(0x0D, base + UNIPHY_PLL_SDM_CFG1);
128+ writel_relaxed(0xA3, base + UNIPHY_PLL_SDM_CFG2);
129+ writel_relaxed(0xF0, base + UNIPHY_PLL_SDM_CFG3);
130+ writel_relaxed(0x00, base + UNIPHY_PLL_SDM_CFG4);
131+
132+ writel_relaxed(0x19, base + UNIPHY_PLL_SSC_CFG0);
133+ writel_relaxed(0xE1, base + UNIPHY_PLL_SSC_CFG1);
134+ writel_relaxed(0x00, base + UNIPHY_PLL_SSC_CFG2);
135+ writel_relaxed(0x11, base + UNIPHY_PLL_SSC_CFG3);
136+
137+ writel_relaxed(0x04, base + UNIPHY_PLL_LKDET_CFG0);
138+ writel_relaxed(0xFF, base + UNIPHY_PLL_LKDET_CFG1);
139+
140+ writel_relaxed(0x02, base + UNIPHY_PLL_GLB_CFG);
141+ /* make sure global config LDO power down happens before power up */
142+ mb();
143+
144+ writel_relaxed(0x03, base + UNIPHY_PLL_GLB_CFG);
145+ writel_relaxed(0x05, base + UNIPHY_PLL_LKDET_CFG2);
146+
147+ /* PLL Lock wait */
148+ ret = read_poll_timeout(base + UNIPHY_PLL_STATUS, UNIPHY_PLL_LOCK);
149+ if (ret) {
150+ dev_err(phy->dev, "poll timeout UNIPHY_PLL_STATUS\n");
151+ return ret;
152+ }
153+
154+ /* TX Calibration */
155+ ret = read_poll_timeout(base + SATA_PHY_TX_IMCAL_STAT, SATA_PHY_TX_CAL);
156+ if (ret) {
157+ dev_err(phy->dev, "poll timeout SATA_PHY_TX_IMCAL_STAT\n");
158+ return ret;
159+ }
160+
161+ /* RX Calibration */
162+ ret = read_poll_timeout(base + SATA_PHY_RX_IMCAL_STAT, SATA_PHY_RX_CAL);
163+ if (ret) {
164+ dev_err(phy->dev, "poll timeout SATA_PHY_RX_IMCAL_STAT\n");
165+ return ret;
166+ }
167+
168+ /* SATA phy calibrated succesfully, power up to functional mode */
169+ writel_relaxed(0x3E, base + SATA_PHY_POW_DWN_CTRL1);
170+ writel_relaxed(0x01, base + SATA_PHY_RX_IMCAL0);
171+ writel_relaxed(0x01, base + SATA_PHY_TX_IMCAL0);
172+
173+ writel_relaxed(0x00, base + SATA_PHY_POW_DWN_CTRL1);
174+ writel_relaxed(0x59, base + SATA_PHY_CDR_CTRL0);
175+ writel_relaxed(0x04, base + SATA_PHY_CDR_CTRL1);
176+ writel_relaxed(0x00, base + SATA_PHY_CDR_CTRL2);
177+ writel_relaxed(0x00, base + SATA_PHY_PI_CTRL0);
178+ writel_relaxed(0x00, base + SATA_PHY_CDR_CTRL3);
179+ writel_relaxed(0x01, base + SATA_PHY_POW_DWN_CTRL0);
180+
181+ writel_relaxed(0x11, base + SATA_PHY_TX_DATA_CTRL);
182+ writel_relaxed(0x43, base + SATA_PHY_ALIGNP);
183+ writel_relaxed(0x04, base + SATA_PHY_OOB_TERM);
184+
185+ writel_relaxed(0x01, base + SATA_PHY_EQUAL);
186+ writel_relaxed(0x09, base + SATA_PHY_TX_DRIV_CTRL0);
187+ writel_relaxed(0x09, base + SATA_PHY_TX_DRIV_CTRL1);
188+
189+ return 0;
190+}
191+
192+static int qcom_apq8064_sata_phy_exit(struct phy *generic_phy)
193+{
194+ struct qcom_apq8064_sata_phy *phy = phy_get_drvdata(generic_phy);
195+ void __iomem *base = phy->mmio;
196+
197+ /* Power down PHY */
198+ writel_relaxed(0xF8, base + SATA_PHY_POW_DWN_CTRL0);
199+ writel_relaxed(0xFE, base + SATA_PHY_POW_DWN_CTRL1);
200+
201+ /* Power down PLL block */
202+ writel_relaxed(0x00, base + UNIPHY_PLL_GLB_CFG);
203+
204+ return 0;
205+}
206+
207+static struct phy_ops qcom_apq8064_sata_phy_ops = {
208+ .init = qcom_apq8064_sata_phy_init,
209+ .exit = qcom_apq8064_sata_phy_exit,
210+ .owner = THIS_MODULE,
211+};
212+
213+static int qcom_apq8064_sata_phy_probe(struct platform_device *pdev)
214+{
215+ struct qcom_apq8064_sata_phy *phy;
216+ struct device *dev = &pdev->dev;
217+ struct resource *res;
218+ struct phy_provider *phy_provider;
219+ struct phy *generic_phy;
220+ int ret;
221+
222+ phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
223+ if (!phy)
224+ return -ENOMEM;
225+
226+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
227+ phy->mmio = devm_ioremap_resource(dev, res);
228+ if (IS_ERR(phy->mmio))
229+ return PTR_ERR(phy->mmio);
230+
231+ generic_phy = devm_phy_create(dev, NULL, &qcom_apq8064_sata_phy_ops,
232+ NULL);
233+ if (IS_ERR(generic_phy)) {
234+ dev_err(dev, "%s: failed to create phy\n", __func__);
235+ return PTR_ERR(generic_phy);
236+ }
237+
238+ phy->dev = dev;
239+ phy_set_drvdata(generic_phy, phy);
240+ platform_set_drvdata(pdev, phy);
241+
242+ phy->cfg_clk = devm_clk_get(dev, "cfg");
243+ if (IS_ERR(phy->cfg_clk)) {
244+ dev_err(dev, "Failed to get sata cfg clock\n");
245+ return PTR_ERR(phy->cfg_clk);
246+ }
247+
248+ ret = clk_prepare_enable(phy->cfg_clk);
249+ if (ret)
250+ return ret;
251+
252+ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
253+ if (IS_ERR(phy_provider)) {
254+ clk_disable_unprepare(phy->cfg_clk);
255+ dev_err(dev, "%s: failed to register phy\n", __func__);
256+ return PTR_ERR(phy_provider);
257+ }
258+
259+ return 0;
260+}
261+
262+static int qcom_apq8064_sata_phy_remove(struct platform_device *pdev)
263+{
264+ struct qcom_apq8064_sata_phy *phy = platform_get_drvdata(pdev);
265+
266+ clk_disable_unprepare(phy->cfg_clk);
267+
268+ return 0;
269+}
270+
271+static const struct of_device_id qcom_apq8064_sata_phy_of_match[] = {
272+ { .compatible = "qcom,apq8064-sata-phy" },
273+ { },
274+};
275+MODULE_DEVICE_TABLE(of, qcom_apq8064_sata_phy_of_match);
276+
277+static struct platform_driver qcom_apq8064_sata_phy_driver = {
278+ .probe = qcom_apq8064_sata_phy_probe,
279+ .remove = qcom_apq8064_sata_phy_remove,
280+ .driver = {
281+ .name = "qcom-apq8064-sata-phy",
282+ .owner = THIS_MODULE,
283+ .of_match_table = qcom_apq8064_sata_phy_of_match,
284+ }
285+};
286+module_platform_driver(qcom_apq8064_sata_phy_driver);
287+
288+MODULE_DESCRIPTION("QCOM apq8064 SATA PHY driver");
289+MODULE_LICENSE("GPL v2");
drivers/phy/phy-qcom-ipq806x-sata.c+211−0
@@ -0,0 +1,211 @@
1+/*
2+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.
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/io.h>
15+#include <linux/kernel.h>
16+#include <linux/module.h>
17+#include <linux/of.h>
18+#include <linux/of_address.h>
19+#include <linux/time.h>
20+#include <linux/delay.h>
21+#include <linux/clk.h>
22+#include <linux/slab.h>
23+#include <linux/platform_device.h>
24+#include <linux/phy/phy.h>
25+
26+struct qcom_ipq806x_sata_phy {
27+ void __iomem *mmio;
28+ struct clk *cfg_clk;
29+ struct device *dev;
30+};
31+
32+#define __set(v, a, b) (((v) << (b)) & GENMASK(a, b))
33+
34+#define SATA_PHY_P0_PARAM0 0x200
35+#define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3(x) __set(x, 17, 12)
36+#define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3_MASK GENMASK(17, 12)
37+#define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN2(x) __set(x, 11, 6)
38+#define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN2_MASK GENMASK(11, 6)
39+#define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN1(x) __set(x, 5, 0)
40+#define SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN1_MASK GENMASK(5, 0)
41+
42+#define SATA_PHY_P0_PARAM1 0x204
43+#define SATA_PHY_P0_PARAM1_RESERVED_BITS31_21(x) __set(x, 31, 21)
44+#define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3(x) __set(x, 20, 14)
45+#define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3_MASK GENMASK(20, 14)
46+#define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2(x) __set(x, 13, 7)
47+#define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2_MASK GENMASK(13, 7)
48+#define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1(x) __set(x, 6, 0)
49+#define SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1_MASK GENMASK(6, 0)
50+
51+#define SATA_PHY_P0_PARAM2 0x208
52+#define SATA_PHY_P0_PARAM2_RX_EQ(x) __set(x, 20, 18)
53+#define SATA_PHY_P0_PARAM2_RX_EQ_MASK GENMASK(20, 18)
54+
55+#define SATA_PHY_P0_PARAM3 0x20C
56+#define SATA_PHY_SSC_EN 0x8
57+#define SATA_PHY_P0_PARAM4 0x210
58+#define SATA_PHY_REF_SSP_EN 0x2
59+#define SATA_PHY_RESET 0x1
60+
61+static int qcom_ipq806x_sata_phy_init(struct phy *generic_phy)
62+{
63+ struct qcom_ipq806x_sata_phy *phy = phy_get_drvdata(generic_phy);
64+ u32 reg;
65+
66+ /* Setting SSC_EN to 1 */
67+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM3);
68+ reg = reg | SATA_PHY_SSC_EN;
69+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM3);
70+
71+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM0) &
72+ ~(SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3_MASK |
73+ SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN2_MASK |
74+ SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN1_MASK);
75+ reg |= SATA_PHY_P0_PARAM0_P0_TX_PREEMPH_GEN3(0xf);
76+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM0);
77+
78+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM1) &
79+ ~(SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3_MASK |
80+ SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2_MASK |
81+ SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1_MASK);
82+ reg |= SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN3(0x55) |
83+ SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN2(0x55) |
84+ SATA_PHY_P0_PARAM1_P0_TX_AMPLITUDE_GEN1(0x55);
85+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM1);
86+
87+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM2) &
88+ ~SATA_PHY_P0_PARAM2_RX_EQ_MASK;
89+ reg |= SATA_PHY_P0_PARAM2_RX_EQ(0x3);
90+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM2);
91+
92+ /* Setting PHY_RESET to 1 */
93+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4);
94+ reg = reg | SATA_PHY_RESET;
95+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4);
96+
97+ /* Setting REF_SSP_EN to 1 */
98+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4);
99+ reg = reg | SATA_PHY_REF_SSP_EN | SATA_PHY_RESET;
100+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4);
101+
102+ /* make sure all changes complete before we let the PHY out of reset */
103+ mb();
104+
105+ /* sleep for max. 50us more to combine processor wakeups */
106+ usleep_range(20, 20 + 50);
107+
108+ /* Clearing PHY_RESET to 0 */
109+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4);
110+ reg = reg & ~SATA_PHY_RESET;
111+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4);
112+
113+ return 0;
114+}
115+
116+static int qcom_ipq806x_sata_phy_exit(struct phy *generic_phy)
117+{
118+ struct qcom_ipq806x_sata_phy *phy = phy_get_drvdata(generic_phy);
119+ u32 reg;
120+
121+ /* Setting PHY_RESET to 1 */
122+ reg = readl_relaxed(phy->mmio + SATA_PHY_P0_PARAM4);
123+ reg = reg | SATA_PHY_RESET;
124+ writel_relaxed(reg, phy->mmio + SATA_PHY_P0_PARAM4);
125+
126+ return 0;
127+}
128+
129+static struct phy_ops qcom_ipq806x_sata_phy_ops = {
130+ .init = qcom_ipq806x_sata_phy_init,
131+ .exit = qcom_ipq806x_sata_phy_exit,
132+ .owner = THIS_MODULE,
133+};
134+
135+static int qcom_ipq806x_sata_phy_probe(struct platform_device *pdev)
136+{
137+ struct qcom_ipq806x_sata_phy *phy;
138+ struct device *dev = &pdev->dev;
139+ struct resource *res;
140+ struct phy_provider *phy_provider;
141+ struct phy *generic_phy;
142+ int ret;
143+
144+ phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
145+ if (!phy)
146+ return -ENOMEM;
147+
148+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
149+ phy->mmio = devm_ioremap_resource(dev, res);
150+ if (IS_ERR(phy->mmio))
151+ return PTR_ERR(phy->mmio);
152+
153+ generic_phy = devm_phy_create(dev, NULL, &qcom_ipq806x_sata_phy_ops,
154+ NULL);
155+ if (IS_ERR(generic_phy)) {
156+ dev_err(dev, "%s: failed to create phy\n", __func__);
157+ return PTR_ERR(generic_phy);
158+ }
159+
160+ phy->dev = dev;
161+ phy_set_drvdata(generic_phy, phy);
162+ platform_set_drvdata(pdev, phy);
163+
164+ phy->cfg_clk = devm_clk_get(dev, "cfg");
165+ if (IS_ERR(phy->cfg_clk)) {
166+ dev_err(dev, "Failed to get sata cfg clock\n");
167+ return PTR_ERR(phy->cfg_clk);
168+ }
169+
170+ ret = clk_prepare_enable(phy->cfg_clk);
171+ if (ret)
172+ return ret;
173+
174+ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
175+ if (IS_ERR(phy_provider)) {
176+ clk_disable_unprepare(phy->cfg_clk);
177+ dev_err(dev, "%s: failed to register phy\n", __func__);
178+ return PTR_ERR(phy_provider);
179+ }
180+
181+ return 0;
182+}
183+
184+static int qcom_ipq806x_sata_phy_remove(struct platform_device *pdev)
185+{
186+ struct qcom_ipq806x_sata_phy *phy = platform_get_drvdata(pdev);
187+
188+ clk_disable_unprepare(phy->cfg_clk);
189+
190+ return 0;
191+}
192+
193+static const struct of_device_id qcom_ipq806x_sata_phy_of_match[] = {
194+ { .compatible = "qcom,ipq806x-sata-phy" },
195+ { },
196+};
197+MODULE_DEVICE_TABLE(of, qcom_ipq806x_sata_phy_of_match);
198+
199+static struct platform_driver qcom_ipq806x_sata_phy_driver = {
200+ .probe = qcom_ipq806x_sata_phy_probe,
201+ .remove = qcom_ipq806x_sata_phy_remove,
202+ .driver = {
203+ .name = "qcom-ipq806x-sata-phy",
204+ .owner = THIS_MODULE,
205+ .of_match_table = qcom_ipq806x_sata_phy_of_match,
206+ }
207+};
208+module_platform_driver(qcom_ipq806x_sata_phy_driver);
209+
210+MODULE_DESCRIPTION("QCOM IPQ806x SATA PHY driver");
211+MODULE_LICENSE("GPL v2");
drivers/phy/phy-samsung-usb2.c+8−1
@@ -87,6 +87,12 @@ static struct phy *samsung_usb2_phy_xlate(struct device *dev, · 86 unmodified lines
8787 }
8888
8989 static const struct of_device_id samsung_usb2_phy_of_match[] = {
90+#ifdef CONFIG_PHY_EXYNOS4X12_USB2
91+ {
92+ .compatible = "samsung,exynos3250-usb2-phy",
93+ .data = &exynos3250_usb2_phy_config,
94+ },
95+#endif
9096 #ifdef CONFIG_PHY_EXYNOS4210_USB2
9197 {
9298 .compatible = "samsung,exynos4210-usb2-phy",
@@ -190,7 +196,8 @@ static int samsung_usb2_phy_probe(struct platform_device *pdev) · 97 unmodified lines
190196 struct samsung_usb2_phy_instance *p = &drv->instances[i];
191197
192198 dev_dbg(dev, "Creating phy \"%s\"\n", label);
193− p->phy = devm_phy_create(dev, &samsung_usb2_phy_ops, NULL);
199+ p->phy = devm_phy_create(dev, NULL, &samsung_usb2_phy_ops,
200+ NULL);
194201 if (IS_ERR(p->phy)) {
195202 dev_err(drv->dev, "Failed to create usb2_phy \"%s\"\n",
196203 label);
drivers/phy/phy-samsung-usb2.h+4−1
@@ -29,7 +29,8 @@ struct samsung_usb2_phy_instance { · 28 unmodified lines
2929 const struct samsung_usb2_common_phy *cfg;
3030 struct phy *phy;
3131 struct samsung_usb2_phy_driver *drv;
32− bool enabled;
32+ int int_cnt;
33+ int ext_cnt;
3334 };
3435
3536 struct samsung_usb2_phy_driver {
@@ -59,8 +60,10 @@ struct samsung_usb2_phy_config { · 23 unmodified lines
5960 int (*rate_to_clk)(unsigned long, u32 *);
6061 unsigned int num_phys;
6162 bool has_mode_switch;
63+ bool has_refclk_sel;
6264 };
6365
66+extern const struct samsung_usb2_phy_config exynos3250_usb2_phy_config;
6467 extern const struct samsung_usb2_phy_config exynos4210_usb2_phy_config;
6568 extern const struct samsung_usb2_phy_config exynos4x12_usb2_phy_config;
6669 extern const struct samsung_usb2_phy_config exynos5250_usb2_phy_config;
drivers/phy/phy-sun4i-usb.c+3−4
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 */
2323
2424 #include <linux/clk.h>
25+#include <linux/err.h>
2526 #include <linux/io.h>
2627 #include <linux/kernel.h>
2728 #include <linux/module.h>
@@ -294,7 +295,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev) · 266 unmodified lines
294295 return PTR_ERR(phy->pmu);
295296 }
296297
297− phy->phy = devm_phy_create(dev, &sun4i_usb_phy_ops, NULL);
298+ phy->phy = devm_phy_create(dev, NULL, &sun4i_usb_phy_ops, NULL);
298299 if (IS_ERR(phy->phy)) {
299300 dev_err(dev, "failed to create PHY %d\n", i);
300301 return PTR_ERR(phy->phy);
@@ -306,10 +307,8 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev) · 5 unmodified lines
306307
307308 dev_set_drvdata(dev, data);
308309 phy_provider = devm_of_phy_provider_register(dev, sun4i_usb_phy_xlate);
309− if (IS_ERR(phy_provider))
310− return PTR_ERR(phy_provider);
311310
312− return 0;
311+ return PTR_ERR_OR_ZERO(phy_provider);
313312 }
314313
315314 static const struct of_device_id sun4i_usb_phy_of_match[] = {
drivers/phy/phy-ti-pipe3.c+85−22
@@ -80,7 +80,9 @@ struct ti_pipe3 { · 79 unmodified lines
8080 struct clk *wkupclk;
8181 struct clk *sys_clk;
8282 struct clk *refclk;
83+ struct clk *div_clk;
8384 struct pipe3_dpll_map *dpll_map;
85+ u8 id;
8486 };
8587
8688 static struct pipe3_dpll_map dpll_map_usb[] = {
@@ -215,6 +217,11 @@ static int ti_pipe3_init(struct phy *x) · 128 unmodified lines
215217 u32 val;
216218 int ret = 0;
217219
220+ if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-pcie")) {
221+ omap_control_pcie_pcs(phy->control_dev, phy->id, 0xF1);
222+ return 0;
223+ }
224+
218225 /* Bring it out of IDLE if it is IDLE */
219226 val = ti_pipe3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
220227 if (val & PLL_IDLE) {
@@ -238,8 +245,11 @@ static int ti_pipe3_exit(struct phy *x) · 17 unmodified lines
238245 u32 val;
239246 unsigned long timeout;
240247
241− /* SATA DPLL can't be powered down due to Errata i783 */
242− if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-sata"))
248+ /* SATA DPLL can't be powered down due to Errata i783 and PCIe
249+ * does not have internal DPLL
250+ */
251+ if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-sata") ||
252+ of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-pcie"))
243253 return 0;
244254
245255 /* Put DPLL in IDLE mode */
@@ -286,32 +296,41 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 40 unmodified lines
286296 struct device_node *control_node;
287297 struct platform_device *control_pdev;
288298 const struct of_device_id *match;
289−
290− match = of_match_device(of_match_ptr(ti_pipe3_id_table), &pdev->dev);
291− if (!match)
292− return -EINVAL;
299+ struct clk *clk;
293300
294301 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
295302 if (!phy) {
296303 dev_err(&pdev->dev, "unable to alloc mem for TI PIPE3 PHY\n");
297304 return -ENOMEM;
298305 }
306+ phy->dev = &pdev->dev;
299307
300− phy->dpll_map = (struct pipe3_dpll_map *)match->data;
301− if (!phy->dpll_map) {
302− dev_err(&pdev->dev, "no DPLL data\n");
303− return -EINVAL;
304− }
308+ if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie")) {
309+ match = of_match_device(of_match_ptr(ti_pipe3_id_table),
310+ &pdev->dev);
311+ if (!match)
312+ return -EINVAL;
305313
306− res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pll_ctrl");
307− phy->pll_ctrl_base = devm_ioremap_resource(&pdev->dev, res);
308− if (IS_ERR(phy->pll_ctrl_base))
309− return PTR_ERR(phy->pll_ctrl_base);
314+ phy->dpll_map = (struct pipe3_dpll_map *)match->data;
315+ if (!phy->dpll_map) {
316+ dev_err(&pdev->dev, "no DPLL data\n");
317+ return -EINVAL;
318+ }
310319
311− phy->dev = &pdev->dev;
320+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
321+ "pll_ctrl");
322+ phy->pll_ctrl_base = devm_ioremap_resource(&pdev->dev, res);
323+ if (IS_ERR(phy->pll_ctrl_base))
324+ return PTR_ERR(phy->pll_ctrl_base);
312325
313− if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) {
326+ phy->sys_clk = devm_clk_get(phy->dev, "sysclk");
327+ if (IS_ERR(phy->sys_clk)) {
328+ dev_err(&pdev->dev, "unable to get sysclk\n");
329+ return -EINVAL;
330+ }
331+ }
314332
333+ if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) {
315334 phy->wkupclk = devm_clk_get(phy->dev, "wkupclk");
316335 if (IS_ERR(phy->wkupclk)) {
317336 dev_err(&pdev->dev, "unable to get wkupclk\n");
@@ -328,10 +347,38 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 10 unmodified lines
328347 phy->refclk = ERR_PTR(-ENODEV);
329348 }
330349
331− phy->sys_clk = devm_clk_get(phy->dev, "sysclk");
332− if (IS_ERR(phy->sys_clk)) {
333− dev_err(&pdev->dev, "unable to get sysclk\n");
334− return -EINVAL;
350+ if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) {
351+ if (of_property_read_u8(node, "id", &phy->id) < 0)
352+ phy->id = 1;
353+
354+ clk = devm_clk_get(phy->dev, "dpll_ref");
355+ if (IS_ERR(clk)) {
356+ dev_err(&pdev->dev, "unable to get dpll ref clk\n");
357+ return PTR_ERR(clk);
358+ }
359+ clk_set_rate(clk, 1500000000);
360+
361+ clk = devm_clk_get(phy->dev, "dpll_ref_m2");
362+ if (IS_ERR(clk)) {
363+ dev_err(&pdev->dev, "unable to get dpll ref m2 clk\n");
364+ return PTR_ERR(clk);
365+ }
366+ clk_set_rate(clk, 100000000);
367+
368+ clk = devm_clk_get(phy->dev, "phy-div");
369+ if (IS_ERR(clk)) {
370+ dev_err(&pdev->dev, "unable to get phy-div clk\n");
371+ return PTR_ERR(clk);
372+ }
373+ clk_set_rate(clk, 100000000);
374+
375+ phy->div_clk = devm_clk_get(phy->dev, "div-clk");
376+ if (IS_ERR(phy->div_clk)) {
377+ dev_err(&pdev->dev, "unable to get div-clk\n");
378+ return PTR_ERR(phy->div_clk);
379+ }
380+ } else {
381+ phy->div_clk = ERR_PTR(-ENODEV);
335382 }
336383
337384 control_node = of_parse_phandle(node, "ctrl-module", 0);
@@ -353,7 +400,7 @@ static int ti_pipe3_probe(struct platform_device *pdev) · 15 unmodified lines
353400 platform_set_drvdata(pdev, phy);
354401 pm_runtime_enable(phy->dev);
355402
356− generic_phy = devm_phy_create(phy->dev, &ops, NULL);
403+ generic_phy = devm_phy_create(phy->dev, NULL, &ops, NULL);
357404 if (IS_ERR(generic_phy))
358405 return PTR_ERR(generic_phy);
359406
@@ -387,6 +434,8 @@ static int ti_pipe3_runtime_suspend(struct device *dev) · 27 unmodified lines
387434 clk_disable_unprepare(phy->wkupclk);
388435 if (!IS_ERR(phy->refclk))
389436 clk_disable_unprepare(phy->refclk);
437+ if (!IS_ERR(phy->div_clk))
438+ clk_disable_unprepare(phy->div_clk);
390439
391440 return 0;
392441 }
@@ -412,8 +461,19 @@ static int ti_pipe3_runtime_resume(struct device *dev) · 19 unmodified lines
412461 }
413462 }
414463
464+ if (!IS_ERR(phy->div_clk)) {
465+ ret = clk_prepare_enable(phy->div_clk);
466+ if (ret) {
467+ dev_err(phy->dev, "Failed to enable div_clk %d\n", ret);
468+ goto err3;
469+ }
470+ }
415471 return 0;
416472
473+err3:
474+ if (!IS_ERR(phy->wkupclk))
475+ clk_disable_unprepare(phy->wkupclk);
476+
417477 err2:
418478 if (!IS_ERR(phy->refclk))
419479 clk_disable_unprepare(phy->refclk);
@@ -446,6 +506,9 @@ static const struct of_device_id ti_pipe3_id_table[] = { · 26 unmodified lines
446506 .compatible = "ti,phy-pipe3-sata",
447507 .data = dpll_map_sata,
448508 },
509+ {
510+ .compatible = "ti,phy-pipe3-pcie",
511+ },
449512 {}
450513 };
451514 MODULE_DEVICE_TABLE(of, ti_pipe3_id_table);
drivers/phy/phy-twl4030-usb.c+1−1
@@ -695,7 +695,7 @@ static int twl4030_usb_probe(struct platform_device *pdev) · 694 unmodified lines
695695 otg->set_host = twl4030_set_host;
696696 otg->set_peripheral = twl4030_set_peripheral;
697697
698− phy = devm_phy_create(twl->dev, &ops, init_data);
698+ phy = devm_phy_create(twl->dev, NULL, &ops, init_data);
699699 if (IS_ERR(phy)) {
700700 dev_dbg(&pdev->dev, "Failed to create PHY\n");
701701 return PTR_ERR(phy);
drivers/phy/phy-xgene.c+1−1
@@ -1707,7 +1707,7 @@ static int xgene_phy_probe(struct platform_device *pdev) · 1706 unmodified lines
17071707 ctx->dev = &pdev->dev;
17081708 platform_set_drvdata(pdev, ctx);
17091709
1710− ctx->phy = devm_phy_create(ctx->dev, &xgene_phy_ops, NULL);
1710+ ctx->phy = devm_phy_create(ctx->dev, NULL, &xgene_phy_ops, NULL);
17111711 if (IS_ERR(ctx->phy)) {
17121712 dev_dbg(&pdev->dev, "Failed to create PHY\n");
17131713 rc = PTR_ERR(ctx->phy);
drivers/usb/chipidea/ci_hdrc_imx.c+3−0
@@ -133,6 +133,9 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) · 132 unmodified lines
133133 data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
134134 if (IS_ERR(data->phy)) {
135135 ret = PTR_ERR(data->phy);
136+ /* Return -EINVAL if no usbphy is available */
137+ if (ret == -ENODEV)
138+ ret = -EINVAL;
136139 goto err_clk;
137140 }
138141
drivers/usb/chipidea/debug.c+2−2
@@ -208,7 +208,7 @@ static const struct file_operations ci_requests_fops = { · 207 unmodified lines
208208 .release = single_release,
209209 };
210210
211−int ci_otg_show(struct seq_file *s, void *unused)
211+static int ci_otg_show(struct seq_file *s, void *unused)
212212 {
213213 struct ci_hdrc *ci = s->private;
214214 struct otg_fsm *fsm;
@@ -331,7 +331,7 @@ static const struct file_operations ci_role_fops = { · 116 unmodified lines
331331 .release = single_release,
332332 };
333333
334−int ci_registers_show(struct seq_file *s, void *unused)
334+static int ci_registers_show(struct seq_file *s, void *unused)
335335 {
336336 struct ci_hdrc *ci = s->private;
337337 u32 tmp_reg;
drivers/usb/class/usbtmc.c+1−1
@@ -715,7 +715,7 @@ static int usbtmc_ioctl_clear(struct usbtmc_device_data *data) · 714 unmodified lines
715715 u8 *buffer;
716716 int rv;
717717 int n;
718− int actual;
718+ int actual = 0;
719719 int max_size;
720720
721721 dev = &data->intf->dev;
drivers/usb/core/config.c+11−0
@@ -199,6 +199,17 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, · 198 unmodified lines
199199 if (n == 0)
200200 n = 9; /* 32 ms = 2^(9-1) uframes */
201201 j = 16;
202+
203+ /*
204+ * Adjust bInterval for quirked devices.
205+ * This quirk fixes bIntervals reported in
206+ * linear microframes.
207+ */
208+ if (to_usb_device(ddev)->quirks &
209+ USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL) {
210+ n = clamp(fls(d->bInterval), i, j);
211+ i = j = n;
212+ }
202213 break;
203214 default: /* USB_SPEED_FULL or _LOW */
204215 /* For low-speed, 10 ms is the official minimum.
drivers/usb/core/devio.c+1−1
@@ -1509,7 +1509,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb · 1508 unmodified lines
15091509 u = (is_in ? URB_DIR_IN : URB_DIR_OUT);
15101510 if (uurb->flags & USBDEVFS_URB_ISO_ASAP)
15111511 u |= URB_ISO_ASAP;
1512− if (uurb->flags & USBDEVFS_URB_SHORT_NOT_OK)
1512+ if (uurb->flags & USBDEVFS_URB_SHORT_NOT_OK && is_in)
15131513 u |= URB_SHORT_NOT_OK;
15141514 if (uurb->flags & USBDEVFS_URB_NO_FSBR)
15151515 u |= URB_NO_FSBR;
drivers/usb/core/driver.c+4−3
@@ -417,10 +417,11 @@ static int usb_unbind_interface(struct device *dev) · 416 unmodified lines
417417 */
418418 lpm_disable_error = usb_unlocked_disable_lpm(udev);
419419
420− /* Terminate all URBs for this interface unless the driver
421− * supports "soft" unbinding.
420+ /*
421+ * Terminate all URBs for this interface unless the driver
422+ * supports "soft" unbinding and the device is still present.
422423 */
423− if (!driver->soft_unbind)
424+ if (!driver->soft_unbind || udev->state == USB_STATE_NOTATTACHED)
424425 usb_disable_interface(udev, intf, false);
425426
426427 driver->disconnect(intf);
drivers/usb/core/hcd-pci.c+2−0
@@ -380,6 +380,8 @@ void usb_hcd_pci_shutdown(struct pci_dev *dev) · 379 unmodified lines
380380 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) &&
381381 hcd->driver->shutdown) {
382382 hcd->driver->shutdown(hcd);
383+ if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0)
384+ free_irq(hcd->irq, hcd);
383385 pci_disable_device(dev);
384386 }
385387 }
drivers/usb/core/hcd.c+0−4
@@ -855,8 +855,6 @@ static ssize_t authorized_default_show(struct device *dev, · 854 unmodified lines
855855 struct usb_bus *usb_bus = rh_usb_dev->bus;
856856 struct usb_hcd *usb_hcd;
857857
858− if (usb_bus == NULL) /* FIXME: not sure if this case is possible */
859− return -ENODEV;
860858 usb_hcd = bus_to_hcd(usb_bus);
861859 return snprintf(buf, PAGE_SIZE, "%u\n", usb_hcd->authorized_default);
862860 }
@@ -871,8 +869,6 @@ static ssize_t authorized_default_store(struct device *dev, · 8 unmodified lines
871869 struct usb_bus *usb_bus = rh_usb_dev->bus;
872870 struct usb_hcd *usb_hcd;
873871
874− if (usb_bus == NULL) /* FIXME: not sure if this case is possible */
875− return -ENODEV;
876872 usb_hcd = bus_to_hcd(usb_bus);
877873 result = sscanf(buf, "%u\n", &val);
878874 if (result == 1) {
drivers/usb/core/hub.c+78−16
@@ -2606,13 +2606,20 @@ static int hub_port_reset(struct usb_hub *hub, int port1, · 2605 unmodified lines
26062606 /* Is a USB 3.0 port in the Inactive or Compliance Mode state?
26072607 * Port worm reset is required to recover
26082608 */
2609−static bool hub_port_warm_reset_required(struct usb_hub *hub, u16 portstatus)
2609+static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
2610+ u16 portstatus)
26102611 {
2611− return hub_is_superspeed(hub->hdev) &&
2612− (((portstatus & USB_PORT_STAT_LINK_STATE) ==
2613− USB_SS_PORT_LS_SS_INACTIVE) ||
2614− ((portstatus & USB_PORT_STAT_LINK_STATE) ==
2615− USB_SS_PORT_LS_COMP_MOD)) ;
2612+ u16 link_state;
2613+
2614+ if (!hub_is_superspeed(hub->hdev))
2615+ return false;
2616+
2617+ if (test_bit(port1, hub->warm_reset_bits))
2618+ return true;
2619+
2620+ link_state = portstatus & USB_PORT_STAT_LINK_STATE;
2621+ return link_state == USB_SS_PORT_LS_SS_INACTIVE
2622+ || link_state == USB_SS_PORT_LS_COMP_MOD;
26162623 }
26172624
26182625 static int hub_port_wait_reset(struct usb_hub *hub, int port1,
@@ -2649,7 +2656,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, · 30 unmodified lines
26492656 if ((portstatus & USB_PORT_STAT_RESET))
26502657 return -EBUSY;
26512658
2652− if (hub_port_warm_reset_required(hub, portstatus))
2659+ if (hub_port_warm_reset_required(hub, port1, portstatus))
26532660 return -ENOTCONN;
26542661
26552662 /* Device went away? */
@@ -2749,9 +2756,10 @@ static int hub_port_reset(struct usb_hub *hub, int port1, · 93 unmodified lines
27492756 if (status < 0)
27502757 goto done;
27512758
2752− if (hub_port_warm_reset_required(hub, portstatus))
2759+ if (hub_port_warm_reset_required(hub, port1, portstatus))
27532760 warm = true;
27542761 }
2762+ clear_bit(port1, hub->warm_reset_bits);
27552763
27562764 /* Reset the port */
27572765 for (i = 0; i < PORT_RESET_TRIES; i++) {
@@ -2788,7 +2796,8 @@ static int hub_port_reset(struct usb_hub *hub, int port1, · 30 unmodified lines
27882796 &portstatus, &portchange) < 0)
27892797 goto done;
27902798
2791− if (!hub_port_warm_reset_required(hub, portstatus))
2799+ if (!hub_port_warm_reset_required(hub, port1,
2800+ portstatus))
27922801 goto done;
27932802
27942803 /*
@@ -2875,8 +2884,13 @@ static int check_port_resume_type(struct usb_device *udev, · 80 unmodified lines
28752884 {
28762885 struct usb_port *port_dev = hub->ports[port1 - 1];
28772886
2887+ /* Is a warm reset needed to recover the connection? */
2888+ if (status == 0 && udev->reset_resume
2889+ && hub_port_warm_reset_required(hub, port1, portstatus)) {
2890+ /* pass */;
2891+ }
28782892 /* Is the device still present? */
2879− if (status || port_is_suspended(hub, portstatus) ||
2893+ else if (status || port_is_suspended(hub, portstatus) ||
28802894 !port_is_power_on(hub, portstatus) ||
28812895 !(portstatus & USB_PORT_STAT_CONNECTION)) {
28822896 if (status >= 0)
@@ -3263,6 +3277,43 @@ static int finish_port_resume(struct usb_device *udev) · 380 unmodified lines
32633277 return status;
32643278 }
32653279
3280+/*
3281+ * There are some SS USB devices which take longer time for link training.
3282+ * XHCI specs 4.19.4 says that when Link training is successful, port
3283+ * sets CSC bit to 1. So if SW reads port status before successful link
3284+ * training, then it will not find device to be present.
3285+ * USB Analyzer log with such buggy devices show that in some cases
3286+ * device switch on the RX termination after long delay of host enabling
3287+ * the VBUS. In few other cases it has been seen that device fails to
3288+ * negotiate link training in first attempt. It has been
3289+ * reported till now that few devices take as long as 2000 ms to train
3290+ * the link after host enabling its VBUS and termination. Following
3291+ * routine implements a 2000 ms timeout for link training. If in a case
3292+ * link trains before timeout, loop will exit earlier.
3293+ *
3294+ * FIXME: If a device was connected before suspend, but was removed
3295+ * while system was asleep, then the loop in the following routine will
3296+ * only exit at timeout.
3297+ *
3298+ * This routine should only be called when persist is enabled for a SS
3299+ * device.
3300+ */
3301+static int wait_for_ss_port_enable(struct usb_device *udev,
3302+ struct usb_hub *hub, int *port1,
3303+ u16 *portchange, u16 *portstatus)
3304+{
3305+ int status = 0, delay_ms = 0;
3306+
3307+ while (delay_ms < 2000) {
3308+ if (status || *portstatus & USB_PORT_STAT_CONNECTION)
3309+ break;
3310+ msleep(20);
3311+ delay_ms += 20;
3312+ status = hub_port_status(hub, *port1, portstatus, portchange);
3313+ }
3314+ return status;
3315+}
3316+
32663317 /*
32673318 * usb_port_resume - re-activate a suspended usb device's upstream port
32683319 * @udev: device to re-activate, not a root hub
@@ -3359,6 +3410,10 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) · 90 unmodified lines
33593410 }
33603411 }
33613412
3413+ if (udev->persist_enabled && hub_is_superspeed(hub->hdev))
3414+ status = wait_for_ss_port_enable(udev, hub, &port1, &portchange,
3415+ &portstatus);
3416+
33623417 status = check_port_resume_type(udev,
33633418 hub, port1, status, portchange, portstatus);
33643419 if (status == 0)
@@ -3879,7 +3934,8 @@ int usb_disable_lpm(struct usb_device *udev) · 514 unmodified lines
38793934
38803935 if (!udev || !udev->parent ||
38813936 udev->speed != USB_SPEED_SUPER ||
3882− !udev->lpm_capable)
3937+ !udev->lpm_capable ||
3938+ udev->state < USB_STATE_DEFAULT)
38833939 return 0;
38843940
38853941 hcd = bus_to_hcd(udev->bus);
@@ -3935,7 +3991,8 @@ void usb_enable_lpm(struct usb_device *udev) · 49 unmodified lines
39353991
39363992 if (!udev || !udev->parent ||
39373993 udev->speed != USB_SPEED_SUPER ||
3938− !udev->lpm_capable)
3994+ !udev->lpm_capable ||
3995+ udev->state < USB_STATE_DEFAULT)
39393996 return;
39403997
39413998 udev->lpm_disable_count--;
@@ -4550,6 +4607,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, · 608 unmodified lines
45504607 struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
45514608 struct usb_port *port_dev = hub->ports[port1 - 1];
45524609 struct usb_device *udev = port_dev->child;
4610+ static int unreliable_port = -1;
45534611
45544612 /* Disconnect any existing devices under this port */
45554613 if (udev) {
@@ -4570,10 +4628,14 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, · 14 unmodified lines
45704628 USB_PORT_STAT_C_ENABLE)) {
45714629 status = hub_port_debounce_be_stable(hub, port1);
45724630 if (status < 0) {
4573− if (status != -ENODEV && printk_ratelimit())
4574− dev_err(&port_dev->dev,
4575− "connect-debounce failed\n");
4631+ if (status != -ENODEV &&
4632+ port1 != unreliable_port &&
4633+ printk_ratelimit())
4634+ dev_err(&udev->dev, "connect-debounce failed, port %d disabled\n",
4635+ port1);
4636+
45764637 portstatus &= ~USB_PORT_STAT_CONNECTION;
4638+ unreliable_port = port1;
45774639 } else {
45784640 portstatus = status;
45794641 }
@@ -4889,7 +4951,7 @@ static void port_event(struct usb_hub *hub, int port1) · 309 unmodified lines
48894951 * Warm reset a USB3 protocol port if it's in
48904952 * SS.Inactive state.
48914953 */
4892− if (hub_port_warm_reset_required(hub, portstatus)) {
4954+ if (hub_port_warm_reset_required(hub, port1, portstatus)) {
48934955 dev_dbg(&port_dev->dev, "do warm reset\n");
48944956 if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION)
48954957 || udev->state == USB_STATE_NOTATTACHED) {
drivers/usb/core/hub.h+2−0
@@ -52,6 +52,8 @@ struct usb_hub { · 51 unmodified lines
5252 unsigned long power_bits[1]; /* ports that are powered */
5353 unsigned long child_usage_bits[1]; /* ports powered on for
5454 children */
55+ unsigned long warm_reset_bits[1]; /* ports requesting warm
56+ reset recovery */
5557 #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
5658 #error event_bits[] is too short!
5759 #endif
drivers/usb/core/port.c+12−9
@@ -103,16 +103,19 @@ static int usb_port_runtime_resume(struct device *dev) · 102 unmodified lines
103103 msleep(hub_power_on_good_delay(hub));
104104 if (udev && !retval) {
105105 /*
106− * Attempt to wait for usb hub port to be reconnected in order
107− * to make the resume procedure successful. The device may have
108− * disconnected while the port was powered off, so ignore the
109− * return status.
106+ * Our preference is to simply wait for the port to reconnect,
107+ * as that is the lowest latency method to restart the port.
108+ * However, there are cases where toggling port power results in
109+ * the host port and the device port getting out of sync causing
110+ * a link training live lock. Upon timeout, flag the port as
111+ * needing warm reset recovery (to be performed later by
112+ * usb_port_resume() as requested via usb_wakeup_notification())
110113 */
111− retval = hub_port_debounce_be_connected(hub, port1);
112− if (retval < 0)
113− dev_dbg(&port_dev->dev, "can't get reconnection after setting port power on, status %d\n",
114− retval);
115− retval = 0;
114+ if (hub_port_debounce_be_connected(hub, port1) < 0) {
115+ dev_dbg(&port_dev->dev, "reconnect timeout\n");
116+ if (hub_is_superspeed(hdev))
117+ set_bit(port1, hub->warm_reset_bits);
118+ }
116119
117120 /* Force the child awake to revalidate after the power loss. */
118121 if (!test_and_set_bit(port1, hub->child_usage_bits)) {
drivers/usb/core/quirks.c+7−0
@@ -145,6 +145,10 @@ static const struct usb_device_id usb_quirk_list[] = { · 144 unmodified lines
145145 /* SKYMEDI USB_DRIVE */
146146 { USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME },
147147
148+ /* Razer - Razer Blade Keyboard */
149+ { USB_DEVICE(0x1532, 0x0116), .driver_info =
150+ USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL },
151+
148152 /* BUILDWIN Photo Frame */
149153 { USB_DEVICE(0x1908, 0x1315), .driver_info =
150154 USB_QUIRK_HONOR_BNUMINTERFACES },
@@ -152,6 +156,9 @@ static const struct usb_device_id usb_quirk_list[] = { · 1 unmodified line
152156 /* INTEL VALUE SSD */
153157 { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME },
154158
159+ /* USB3503 */
160+ { USB_DEVICE(0x0424, 0x3503), .driver_info = USB_QUIRK_RESET_RESUME },
161+
155162 { } /* terminating entry must be last */
156163 };
157164
drivers/usb/core/urb.c+1−0
@@ -454,6 +454,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) · 453 unmodified lines
454454 URB_FREE_BUFFER);
455455 switch (xfertype) {
456456 case USB_ENDPOINT_XFER_BULK:
457+ case USB_ENDPOINT_XFER_INT:
457458 if (is_out)
458459 allowed |= URB_ZERO_PACKET;
459460 /* FALLTHROUGH */
drivers/usb/core/usb.c+1−0
@@ -501,6 +501,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, · 500 unmodified lines
501501 }
502502 return dev;
503503 }
504+EXPORT_SYMBOL_GPL(usb_alloc_dev);
504505
505506 /**
506507 * usb_get_dev - increments the reference count of the usb device structure
drivers/usb/dwc2/gadget.c+4−8
@@ -1,6 +1,4 @@
11 /**
2− * linux/drivers/usb/gadget/s3c-hsotg.c
3− *
42 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
53 * http://www.samsung.com
64 *
@@ -1022,7 +1020,8 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg); · 1015 unmodified lines
10221020 *
10231021 * Set stall for ep0 as response for setup request.
10241022 */
1025−static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) {
1023+static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg)
1024+{
10261025 struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
10271026 u32 reg;
10281027 u32 ctrl;
@@ -1994,7 +1993,7 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, · 965 unmodified lines
19941993 s3c_hsotg_complete_request(hsotg, ep, req,
19951994 result);
19961995 }
1997− if(hsotg->dedicated_fifos)
1996+ if (hsotg->dedicated_fifos)
19981997 if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072)
19991998 s3c_hsotg_txfifo_flush(hsotg, ep->index);
20001999 }
@@ -3390,10 +3389,8 @@ static int s3c_hsotg_probe(struct platform_device *pdev) · 1389 unmodified lines
33903389 int i;
33913390
33923391 hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL);
3393− if (!hsotg) {
3394− dev_err(dev, "cannot get memory\n");
3392+ if (!hsotg)
33953393 return -ENOMEM;
3396− }
33973394
33983395 /*
33993396 * Attempt to find a generic PHY, then look for an old style
@@ -3512,7 +3509,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev) · 112 unmodified lines
35123509 eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep),
35133510 GFP_KERNEL);
35143511 if (!eps) {
3515− dev_err(dev, "cannot get memory\n");
35163512 ret = -ENOMEM;
35173513 goto err_supplies;
35183514 }
drivers/usb/dwc3/Kconfig+7−0
@@ -93,4 +93,11 @@ config USB_DWC3_VERBOSE · 92 unmodified lines
9393 help
9494 Say Y here to enable verbose debugging messages on DWC3 Driver.
9595
96+config DWC3_HOST_USB3_LPM_ENABLE
97+ bool "Enable USB3 LPM Capability"
98+ depends on USB_DWC3_HOST=y || USB_DWC3_DUAL_ROLE=y
99+ default n
100+ help
101+ Select this when you want to enable USB3 LPM with dwc3 xhci host.
102+
96103 endif
drivers/usb/dwc3/core.c+32−19
@@ -386,6 +386,13 @@ static int dwc3_core_init(struct dwc3 *dwc) · 385 unmodified lines
386386 }
387387 dwc->revision = reg;
388388
389+ /* Handle USB2.0-only core configuration */
390+ if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
391+ DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
392+ if (dwc->maximum_speed == USB_SPEED_SUPER)
393+ dwc->maximum_speed = USB_SPEED_HIGH;
394+ }
395+
389396 /* issue device SoftReset too */
390397 timeout = jiffies + msecs_to_jiffies(500);
391398 dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
@@ -656,6 +663,31 @@ static int dwc3_probe(struct platform_device *pdev) · 264 unmodified lines
656663 return -ENODEV;
657664 }
658665
666+ dwc->xhci_resources[0].start = res->start;
667+ dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
668+ DWC3_XHCI_REGS_END;
669+ dwc->xhci_resources[0].flags = res->flags;
670+ dwc->xhci_resources[0].name = res->name;
671+
672+ res->start += DWC3_GLOBALS_REGS_START;
673+
674+ /*
675+ * Request memory region but exclude xHCI regs,
676+ * since it will be requested by the xhci-plat driver.
677+ */
678+ regs = devm_ioremap_resource(dev, res);
679+ if (IS_ERR(regs))
680+ return PTR_ERR(regs);
681+
682+ dwc->regs = regs;
683+ dwc->regs_size = resource_size(res);
684+ /*
685+ * restore res->start back to its original value so that,
686+ * in case the probe is deferred, we don't end up getting error in
687+ * request the memory region the next time probe is called.
688+ */
689+ res->start -= DWC3_GLOBALS_REGS_START;
690+
659691 if (node) {
660692 dwc->maximum_speed = of_usb_get_maximum_speed(node);
661693
@@ -676,28 +708,9 @@ static int dwc3_probe(struct platform_device *pdev) · 14 unmodified lines
676708 if (ret)
677709 return ret;
678710
679− dwc->xhci_resources[0].start = res->start;
680− dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
681− DWC3_XHCI_REGS_END;
682− dwc->xhci_resources[0].flags = res->flags;
683− dwc->xhci_resources[0].name = res->name;
684−
685− res->start += DWC3_GLOBALS_REGS_START;
686−
687− /*
688− * Request memory region but exclude xHCI regs,
689− * since it will be requested by the xhci-plat driver.
690− */
691− regs = devm_ioremap_resource(dev, res);
692− if (IS_ERR(regs))
693− return PTR_ERR(regs);
694−
695711 spin_lock_init(&dwc->lock);
696712 platform_set_drvdata(pdev, dwc);
697713
698− dwc->regs = regs;
699− dwc->regs_size = resource_size(res);
700−
701714 dev->dma_mask = dev->parent->dma_mask;
702715 dev->dma_parms = dev->parent->dma_parms;
703716 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
drivers/usb/dwc3/core.h+13−0
@@ -191,6 +191,19 @@ · 190 unmodified lines
191191 #define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24)
192192 #define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3)
193193
194+/* Global HWPARAMS3 Register */
195+#define DWC3_GHWPARAMS3_SSPHY_IFC(n) ((n) & 3)
196+#define DWC3_GHWPARAMS3_SSPHY_IFC_DIS 0
197+#define DWC3_GHWPARAMS3_SSPHY_IFC_ENA 1
198+#define DWC3_GHWPARAMS3_HSPHY_IFC(n) (((n) & (3 << 2)) >> 2)
199+#define DWC3_GHWPARAMS3_HSPHY_IFC_DIS 0
200+#define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI 1
201+#define DWC3_GHWPARAMS3_HSPHY_IFC_ULPI 2
202+#define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI 3
203+#define DWC3_GHWPARAMS3_FSPHY_IFC(n) (((n) & (3 << 4)) >> 4)
204+#define DWC3_GHWPARAMS3_FSPHY_IFC_DIS 0
205+#define DWC3_GHWPARAMS3_FSPHY_IFC_ENA 1
206+
194207 /* Global HWPARAMS4 Register */
195208 #define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13)
196209 #define DWC3_MAX_HIBER_SCRATCHBUFS 15
drivers/usb/dwc3/dwc3-omap.c+86−86
@@ -77,10 +77,6 @@ · 76 unmodified lines
7777 #define USBOTGSS_DEV_EBC_EN 0x0110
7878 #define USBOTGSS_DEBUG_OFFSET 0x0600
7979
80−/* REVISION REGISTER */
81−#define USBOTGSS_REVISION_XMAJOR(reg) ((reg >> 8) & 0x7)
82−#define USBOTGSS_REVISION_XMAJOR1 1
83−#define USBOTGSS_REVISION_XMAJOR2 2
8480 /* SYSCONFIG REGISTER */
8581 #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16)
8682
@@ -129,7 +125,6 @@ struct dwc3_omap { · 42 unmodified lines
129125 u32 irq_eoi_offset;
130126 u32 debug_offset;
131127 u32 irq0_offset;
132− u32 revision;
133128
134129 u32 dma_status:1;
135130
@@ -383,6 +378,87 @@ static int dwc3_omap_vbus_notifier(struct notifier_block *nb, · 247 unmodified lines
383378 return NOTIFY_DONE;
384379 }
385380
381+static void dwc3_omap_map_offset(struct dwc3_omap *omap)
382+{
383+ struct device_node *node = omap->dev->of_node;
384+
385+ /*
386+ * Differentiate between OMAP5 and AM437x.
387+ *
388+ * For OMAP5(ES2.0) and AM437x wrapper revision is same, even
389+ * though there are changes in wrapper register offsets.
390+ *
391+ * Using dt compatible to differentiate AM437x.
392+ */
393+ if (of_device_is_compatible(node, "ti,am437x-dwc3")) {
394+ omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
395+ omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
396+ omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
397+ omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
398+ omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
399+ }
400+}
401+
402+static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
403+{
404+ u32 reg;
405+ struct device_node *node = omap->dev->of_node;
406+ int utmi_mode = 0;
407+
408+ reg = dwc3_omap_read_utmi_status(omap);
409+
410+ of_property_read_u32(node, "utmi-mode", &utmi_mode);
411+
412+ switch (utmi_mode) {
413+ case DWC3_OMAP_UTMI_MODE_SW:
414+ reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
415+ break;
416+ case DWC3_OMAP_UTMI_MODE_HW:
417+ reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
418+ break;
419+ default:
420+ dev_dbg(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode);
421+ }
422+
423+ dwc3_omap_write_utmi_status(omap, reg);
424+}
425+
426+static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
427+{
428+ u32 ret;
429+ struct device_node *node = omap->dev->of_node;
430+ struct extcon_dev *edev;
431+
432+ if (of_property_read_bool(node, "extcon")) {
433+ edev = extcon_get_edev_by_phandle(omap->dev, 0);
434+ if (IS_ERR(edev)) {
435+ dev_vdbg(omap->dev, "couldn't get extcon device\n");
436+ return -EPROBE_DEFER;
437+ }
438+
439+ omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
440+ ret = extcon_register_interest(&omap->extcon_vbus_dev,
441+ edev->name, "USB",
442+ &omap->vbus_nb);
443+ if (ret < 0)
444+ dev_vdbg(omap->dev, "failed to register notifier for USB\n");
445+
446+ omap->id_nb.notifier_call = dwc3_omap_id_notifier;
447+ ret = extcon_register_interest(&omap->extcon_id_dev,
448+ edev->name, "USB-HOST",
449+ &omap->id_nb);
450+ if (ret < 0)
451+ dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n");
452+
453+ if (extcon_get_cable_state(edev, "USB") == true)
454+ dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
455+ if (extcon_get_cable_state(edev, "USB-HOST") == true)
456+ dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
457+ }
458+
459+ return 0;
460+}
461+
386462 static int dwc3_omap_probe(struct platform_device *pdev)
387463 {
388464 struct device_node *node = pdev->dev.of_node;
@@ -390,15 +466,11 @@ static int dwc3_omap_probe(struct platform_device *pdev) · 1 unmodified line
390466 struct dwc3_omap *omap;
391467 struct resource *res;
392468 struct device *dev = &pdev->dev;
393− struct extcon_dev *edev;
394469 struct regulator *vbus_reg = NULL;
395470
396471 int ret;
397472 int irq;
398473
399− int utmi_mode = 0;
400− int x_major;
401−
402474 u32 reg;
403475
404476 void __iomem *base;
@@ -448,58 +520,8 @@ static int dwc3_omap_probe(struct platform_device *pdev) · 43 unmodified lines
448520 goto err0;
449521 }
450522
451− reg = dwc3_omap_readl(omap->base, USBOTGSS_REVISION);
452− omap->revision = reg;
453− x_major = USBOTGSS_REVISION_XMAJOR(reg);
454−
455− /* Differentiate between OMAP5 and AM437x */
456− switch (x_major) {
457− case USBOTGSS_REVISION_XMAJOR1:
458− case USBOTGSS_REVISION_XMAJOR2:
459− omap->irq_eoi_offset = 0;
460− omap->irq0_offset = 0;
461− omap->irqmisc_offset = 0;
462− omap->utmi_otg_offset = 0;
463− omap->debug_offset = 0;
464− break;
465− default:
466− /* Default to the latest revision */
467− omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
468− omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
469− omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
470− omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
471− omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
472− break;
473− }
474−
475− /* For OMAP5(ES2.0) and AM437x x_major is 2 even though there are
476− * changes in wrapper registers, Using dt compatible for aegis
477− */
478−
479− if (of_device_is_compatible(node, "ti,am437x-dwc3")) {
480− omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
481− omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
482− omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
483− omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
484− omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
485− }
486−
487− reg = dwc3_omap_read_utmi_status(omap);
488−
489− of_property_read_u32(node, "utmi-mode", &utmi_mode);
490−
491− switch (utmi_mode) {
492− case DWC3_OMAP_UTMI_MODE_SW:
493− reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
494− break;
495− case DWC3_OMAP_UTMI_MODE_HW:
496− reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
497− break;
498− default:
499− dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode);
500− }
501−
502− dwc3_omap_write_utmi_status(omap, reg);
523+ dwc3_omap_map_offset(omap);
524+ dwc3_omap_set_utmi_mode(omap);
503525
504526 /* check the DMA Status */
505527 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
@@ -515,31 +537,9 @@ static int dwc3_omap_probe(struct platform_device *pdev) · 9 unmodified lines
515537
516538 dwc3_omap_enable_irqs(omap);
517539
518− if (of_property_read_bool(node, "extcon")) {
519− edev = extcon_get_edev_by_phandle(dev, 0);
520− if (IS_ERR(edev)) {
521− dev_vdbg(dev, "couldn't get extcon device\n");
522− ret = -EPROBE_DEFER;
523− goto err2;
524− }
525−
526− omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
527− ret = extcon_register_interest(&omap->extcon_vbus_dev,
528− edev->name, "USB", &omap->vbus_nb);
529− if (ret < 0)
530− dev_vdbg(dev, "failed to register notifier for USB\n");
531− omap->id_nb.notifier_call = dwc3_omap_id_notifier;
532− ret = extcon_register_interest(&omap->extcon_id_dev, edev->name,
533− "USB-HOST", &omap->id_nb);
534− if (ret < 0)
535− dev_vdbg(dev,
536− "failed to register notifier for USB-HOST\n");
537−
538− if (extcon_get_cable_state(edev, "USB") == true)
539− dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
540− if (extcon_get_cable_state(edev, "USB-HOST") == true)
541− dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
542− }
540+ ret = dwc3_omap_extcon_register(omap);
541+ if (ret < 0)
542+ goto err2;
543543
544544 ret = of_platform_populate(node, NULL, NULL, dev);
545545 if (ret) {
drivers/usb/dwc3/gadget.c+3−4
@@ -1971,8 +1971,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, · 1970 unmodified lines
19711971 }
19721972
19731973 static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc,
1974− struct dwc3_ep *dep, const struct dwc3_event_depevt *event,
1975− int start_new)
1974+ struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
19761975 {
19771976 unsigned status = 0;
19781977 int clean_busy;
@@ -2039,7 +2038,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, · 60 unmodified lines
20392038 return;
20402039 }
20412040
2042− dwc3_endpoint_transfer_complete(dwc, dep, event, 1);
2041+ dwc3_endpoint_transfer_complete(dwc, dep, event);
20432042 break;
20442043 case DWC3_DEPEVT_XFERINPROGRESS:
20452044 if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
@@ -2048,7 +2047,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, · 2 unmodified lines
20482047 return;
20492048 }
20502049
2051− dwc3_endpoint_transfer_complete(dwc, dep, event, 0);
2050+ dwc3_endpoint_transfer_complete(dwc, dep, event);
20522051 break;
20532052 case DWC3_DEPEVT_XFERNOTREADY:
20542053 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
drivers/usb/dwc3/host.c+14−0
@@ -16,12 +16,14 @@ · 15 unmodified lines
1616 */
1717
1818 #include <linux/platform_device.h>
19+#include <linux/usb/xhci_pdriver.h>
1920
2021 #include "core.h"
2122
2223 int dwc3_host_init(struct dwc3 *dwc)
2324 {
2425 struct platform_device *xhci;
26+ struct usb_xhci_pdata pdata;
2527 int ret;
2628
2729 xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
@@ -46,6 +48,18 @@ int dwc3_host_init(struct dwc3 *dwc) · 18 unmodified lines
4648 goto err1;
4749 }
4850
51+ memset(&pdata, 0, sizeof(pdata));
52+
53+#ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE
54+ pdata.usb3_lpm_capable = 1;
55+#endif
56+
57+ ret = platform_device_add_data(xhci, &pdata, sizeof(pdata));
58+ if (ret) {
59+ dev_err(dwc->dev, "couldn't add platform data to xHCI device\n");
60+ goto err1;
61+ }
62+
4963 ret = platform_device_add(xhci);
5064 if (ret) {
5165 dev_err(dwc->dev, "failed to register xHCI device\n");
drivers/usb/gadget/Kconfig+2−822
@@ -127,368 +127,7 @@ config USB_GADGET_STORAGE_NUM_BUFFERS · 126 unmodified lines
127127 a module parameter as well.
128128 If unsure, say 2.
129129
130−#
131−# USB Peripheral Controller Support
132−#
133−# The order here is alphabetical, except that integrated controllers go
134−# before discrete ones so they will be the initial/default value:
135−# - integrated/SOC controllers first
136−# - licensed IP used in both SOC and discrete versions
137−# - discrete ones (including all PCI-only controllers)
138−# - debug/dummy gadget+hcd is last.
139−#
140−menu "USB Peripheral Controller"
141−
142−#
143−# Integrated controllers
144−#
145−
146−config USB_AT91
147− tristate "Atmel AT91 USB Device Port"
148− depends on ARCH_AT91
149− help
150− Many Atmel AT91 processors (such as the AT91RM2000) have a
151− full speed USB Device Port with support for five configurable
152− endpoints (plus endpoint zero).
153−
154− Say "y" to link the driver statically, or "m" to build a
155− dynamically linked module called "at91_udc" and force all
156− gadget drivers to also be dynamically linked.
157−
158−config USB_LPC32XX
159− tristate "LPC32XX USB Peripheral Controller"
160− depends on ARCH_LPC32XX && I2C
161− select USB_ISP1301
162− help
163− This option selects the USB device controller in the LPC32xx SoC.
164−
165− Say "y" to link the driver statically, or "m" to build a
166− dynamically linked module called "lpc32xx_udc" and force all
167− gadget drivers to also be dynamically linked.
168−
169−config USB_ATMEL_USBA
170− tristate "Atmel USBA"
171− depends on AVR32 || ARCH_AT91
172− help
173− USBA is the integrated high-speed USB Device controller on
174− the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
175−
176−config USB_BCM63XX_UDC
177− tristate "Broadcom BCM63xx Peripheral Controller"
178− depends on BCM63XX
179− help
180− Many Broadcom BCM63xx chipsets (such as the BCM6328) have a
181− high speed USB Device Port with support for four fixed endpoints
182− (plus endpoint zero).
183−
184− Say "y" to link the driver statically, or "m" to build a
185− dynamically linked module called "bcm63xx_udc".
186−
187−config USB_FSL_USB2
188− tristate "Freescale Highspeed USB DR Peripheral Controller"
189− depends on FSL_SOC || ARCH_MXC
190− select USB_FSL_MPH_DR_OF if OF
191− help
192− Some of Freescale PowerPC and i.MX processors have a High Speed
193− Dual-Role(DR) USB controller, which supports device mode.
194−
195− The number of programmable endpoints is different through
196− SOC revisions.
197−
198− Say "y" to link the driver statically, or "m" to build a
199− dynamically linked module called "fsl_usb2_udc" and force
200− all gadget drivers to also be dynamically linked.
201−
202−config USB_FUSB300
203− tristate "Faraday FUSB300 USB Peripheral Controller"
204− depends on !PHYS_ADDR_T_64BIT && HAS_DMA
205− help
206− Faraday usb device controller FUSB300 driver
207−
208−config USB_FOTG210_UDC
209− depends on HAS_DMA
210− tristate "Faraday FOTG210 USB Peripheral Controller"
211− help
212− Faraday USB2.0 OTG controller which can be configured as
213− high speed or full speed USB device. This driver supppors
214− Bulk Transfer so far.
215−
216− Say "y" to link the driver statically, or "m" to build a
217− dynamically linked module called "fotg210_udc".
218−
219−config USB_GR_UDC
220− tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver"
221− depends on HAS_DMA
222− help
223− Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB
224− VHDL IP core library.
225−
226−config USB_OMAP
227− tristate "OMAP USB Device Controller"
228− depends on ARCH_OMAP1
229− depends on ISP1301_OMAP || !(MACH_OMAP_H2 || MACH_OMAP_H3)
230− help
231− Many Texas Instruments OMAP processors have flexible full
232− speed USB device controllers, with support for up to 30
233− endpoints (plus endpoint zero). This driver supports the
234− controller in the OMAP 1611, and should work with controllers
235− in other OMAP processors too, given minor tweaks.
236−
237− Say "y" to link the driver statically, or "m" to build a
238− dynamically linked module called "omap_udc" and force all
239− gadget drivers to also be dynamically linked.
240−
241−config USB_PXA25X
242− tristate "PXA 25x or IXP 4xx"
243− depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
244− help
245− Intel's PXA 25x series XScale ARM-5TE processors include
246− an integrated full speed USB 1.1 device controller. The
247− controller in the IXP 4xx series is register-compatible.
248−
249− It has fifteen fixed-function endpoints, as well as endpoint
250− zero (for control transfers).
251−
252− Say "y" to link the driver statically, or "m" to build a
253− dynamically linked module called "pxa25x_udc" and force all
254− gadget drivers to also be dynamically linked.
255−
256−# if there's only one gadget driver, using only two bulk endpoints,
257−# don't waste memory for the other endpoints
258−config USB_PXA25X_SMALL
259− depends on USB_PXA25X
260− bool
261− default n if USB_ETH_RNDIS
262− default y if USB_ZERO
263− default y if USB_ETH
264− default y if USB_G_SERIAL
265−
266−config USB_R8A66597
267− tristate "Renesas R8A66597 USB Peripheral Controller"
268− depends on HAS_DMA
269− help
270− R8A66597 is a discrete USB host and peripheral controller chip that
271− supports both full and high speed USB 2.0 data transfers.
272− It has nine configurable endpoints, and endpoint zero.
273−
274− Say "y" to link the driver statically, or "m" to build a
275− dynamically linked module called "r8a66597_udc" and force all
276− gadget drivers to also be dynamically linked.
277−
278−config USB_RENESAS_USBHS_UDC
279− tristate 'Renesas USBHS controller'
280− depends on USB_RENESAS_USBHS
281− help
282− Renesas USBHS is a discrete USB host and peripheral controller chip
283− that supports both full and high speed USB 2.0 data transfers.
284− It has nine or more configurable endpoints, and endpoint zero.
285−
286− Say "y" to link the driver statically, or "m" to build a
287− dynamically linked module called "renesas_usbhs" and force all
288− gadget drivers to also be dynamically linked.
289−
290−config USB_PXA27X
291− tristate "PXA 27x"
292− help
293− Intel's PXA 27x series XScale ARM v5TE processors include
294− an integrated full speed USB 1.1 device controller.
295−
296− It has up to 23 endpoints, as well as endpoint zero (for
297− control transfers).
298−
299− Say "y" to link the driver statically, or "m" to build a
300− dynamically linked module called "pxa27x_udc" and force all
301− gadget drivers to also be dynamically linked.
302−
303−config USB_S3C2410
304− tristate "S3C2410 USB Device Controller"
305− depends on ARCH_S3C24XX
306− help
307− Samsung's S3C2410 is an ARM-4 processor with an integrated
308− full speed USB 1.1 device controller. It has 4 configurable
309− endpoints, as well as endpoint zero (for control transfers).
310−
311− This driver has been tested on the S3C2410, S3C2412, and
312− S3C2440 processors.
313−
314−config USB_S3C2410_DEBUG
315− boolean "S3C2410 udc debug messages"
316− depends on USB_S3C2410
317−
318−config USB_S3C_HSUDC
319− tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller"
320− depends on ARCH_S3C24XX
321− help
322− Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC
323− integrated with dual speed USB 2.0 device controller. It has
324− 8 endpoints, as well as endpoint zero.
325−
326− This driver has been tested on S3C2416 and S3C2450 processors.
327−
328−config USB_MV_UDC
329− tristate "Marvell USB2.0 Device Controller"
330− depends on HAS_DMA
331− help
332− Marvell Socs (including PXA and MMP series) include a high speed
333− USB2.0 OTG controller, which can be configured as high speed or
334− full speed USB peripheral.
335−
336−config USB_MV_U3D
337− depends on HAS_DMA
338− tristate "MARVELL PXA2128 USB 3.0 controller"
339− help
340− MARVELL PXA2128 Processor series include a super speed USB3.0 device
341− controller, which support super speed USB peripheral.
342−
343−#
344−# Controllers available in both integrated and discrete versions
345−#
346−
347−config USB_M66592
348− tristate "Renesas M66592 USB Peripheral Controller"
349− help
350− M66592 is a discrete USB peripheral controller chip that
351− supports both full and high speed USB 2.0 data transfers.
352− It has seven configurable endpoints, and endpoint zero.
353−
354− Say "y" to link the driver statically, or "m" to build a
355− dynamically linked module called "m66592_udc" and force all
356− gadget drivers to also be dynamically linked.
357−
358−#
359−# Controllers available only in discrete form (and all PCI controllers)
360−#
361−
362−config USB_AMD5536UDC
363− tristate "AMD5536 UDC"
364− depends on PCI
365− help
366− The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
367− It is a USB Highspeed DMA capable USB device controller. Beside ep0
368− it provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
369− The UDC port supports OTG operation, and may be used as a host port
370− if it's not being used to implement peripheral or OTG roles.
371−
372− Say "y" to link the driver statically, or "m" to build a
373− dynamically linked module called "amd5536udc" and force all
374− gadget drivers to also be dynamically linked.
375−
376−config USB_FSL_QE
377− tristate "Freescale QE/CPM USB Device Controller"
378− depends on FSL_SOC && (QUICC_ENGINE || CPM)
379− help
380− Some of Freescale PowerPC processors have a Full Speed
381− QE/CPM2 USB controller, which support device mode with 4
382− programmable endpoints. This driver supports the
383− controller in the MPC8360 and MPC8272, and should work with
384− controllers having QE or CPM2, given minor tweaks.
385−
386− Set CONFIG_USB_GADGET to "m" to build this driver as a
387− dynamically linked module called "fsl_qe_udc".
388−
389−config USB_NET2272
390− tristate "PLX NET2272"
391− help
392− PLX NET2272 is a USB peripheral controller which supports
393− both full and high speed USB 2.0 data transfers.
394−
395− It has three configurable endpoints, as well as endpoint zero
396− (for control transfer).
397− Say "y" to link the driver statically, or "m" to build a
398− dynamically linked module called "net2272" and force all
399− gadget drivers to also be dynamically linked.
400−
401−config USB_NET2272_DMA
402− boolean "Support external DMA controller"
403− depends on USB_NET2272 && HAS_DMA
404− help
405− The NET2272 part can optionally support an external DMA
406− controller, but your board has to have support in the
407− driver itself.
408−
409− If unsure, say "N" here. The driver works fine in PIO mode.
410−
411−config USB_NET2280
412− tristate "NetChip 228x"
413− depends on PCI
414− help
415− NetChip 2280 / 2282 is a PCI based USB peripheral controller which
416− supports both full and high speed USB 2.0 data transfers.
417−
418− It has six configurable endpoints, as well as endpoint zero
419− (for control transfers) and several endpoints with dedicated
420− functions.
421−
422− Say "y" to link the driver statically, or "m" to build a
423− dynamically linked module called "net2280" and force all
424− gadget drivers to also be dynamically linked.
425−
426−config USB_GOKU
427− tristate "Toshiba TC86C001 'Goku-S'"
428− depends on PCI
429− help
430− The Toshiba TC86C001 is a PCI device which includes controllers
431− for full speed USB devices, IDE, I2C, SIO, plus a USB host (OHCI).
432−
433− The device controller has three configurable (bulk or interrupt)
434− endpoints, plus endpoint zero (for control transfers).
435−
436− Say "y" to link the driver statically, or "m" to build a
437− dynamically linked module called "goku_udc" and to force all
438− gadget drivers to also be dynamically linked.
439−
440−config USB_EG20T
441− tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC"
442− depends on PCI
443− help
444− This is a USB device driver for EG20T PCH.
445− EG20T PCH is the platform controller hub that is used in Intel's
446− general embedded platform. EG20T PCH has USB device interface.
447− Using this interface, it is able to access system devices connected
448− to USB device.
449− This driver enables USB device function.
450− USB device is a USB peripheral controller which
451− supports both full and high speed USB 2.0 data transfers.
452− This driver supports both control transfer and bulk transfer modes.
453− This driver dose not support interrupt transfer or isochronous
454− transfer modes.
455−
456− This driver also can be used for LAPIS Semiconductor's ML7213 which is
457− for IVI(In-Vehicle Infotainment) use.
458− ML7831 is for general purpose use.
459− ML7213/ML7831 is companion chip for Intel Atom E6xx series.
460− ML7213/ML7831 is completely compatible for Intel EG20T PCH.
461−
462−#
463−# LAST -- dummy/emulated controller
464−#
465−
466−config USB_DUMMY_HCD
467− tristate "Dummy HCD (DEVELOPMENT)"
468− depends on USB=y || (USB=m && USB_GADGET=m)
469− help
470− This host controller driver emulates USB, looping all data transfer
471− requests back to a USB "gadget driver" in the same host. The host
472− side is the master; the gadget side is the slave. Gadget drivers
473− can be high, full, or low speed; and they have access to endpoints
474− like those from NET2280, PXA2xx, or SA1100 hardware.
475−
476− This may help in some stages of creating a driver to embed in a
477− Linux device, since it lets you debug several parts of the gadget
478− driver without its hardware or drivers being involved.
479−
480− Since such a gadget side driver needs to interoperate with a host
481− side Linux-USB device driver, this may help to debug both sides
482− of a USB protocol stack.
483−
484− Say "y" to link the driver statically, or "m" to build a
485− dynamically linked module called "dummy_hcd" and force all
486− gadget drivers to also be dynamically linked.
487−
488−# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears
489−# first and will be selected by default.
490−
491−endmenu
130+source "drivers/usb/gadget/udc/Kconfig"
492131
493132 #
494133 # USB Gadget Drivers
@@ -714,466 +353,7 @@ config USB_CONFIGFS_F_FS · 219 unmodified lines
714353 implemented in kernel space (for instance Ethernet, serial or
715354 mass storage) and other are implemented in user space.
716355
717−config USB_ZERO
718− tristate "Gadget Zero (DEVELOPMENT)"
719− select USB_LIBCOMPOSITE
720− select USB_F_SS_LB
721− help
722− Gadget Zero is a two-configuration device. It either sinks and
723− sources bulk data; or it loops back a configurable number of
724− transfers. It also implements control requests, for "chapter 9"
725− conformance. The driver needs only two bulk-capable endpoints, so
726− it can work on top of most device-side usb controllers. It's
727− useful for testing, and is also a working example showing how
728− USB "gadget drivers" can be written.
729−
730− Make this be the first driver you try using on top of any new
731− USB peripheral controller driver. Then you can use host-side
732− test software, like the "usbtest" driver, to put your hardware
733− and its driver through a basic set of functional tests.
734−
735− Gadget Zero also works with the host-side "usb-skeleton" driver,
736− and with many kinds of host-side test software. You may need
737− to tweak product and vendor IDs before host software knows about
738− this device, and arrange to select an appropriate configuration.
739−
740− Say "y" to link the driver statically, or "m" to build a
741− dynamically linked module called "g_zero".
742−
743−config USB_ZERO_HNPTEST
744− boolean "HNP Test Device"
745− depends on USB_ZERO && USB_OTG
746− help
747− You can configure this device to enumerate using the device
748− identifiers of the USB-OTG test device. That means that when
749− this gadget connects to another OTG device, with this one using
750− the "B-Peripheral" role, that device will use HNP to let this
751− one serve as the USB host instead (in the "B-Host" role).
752−
753−config USB_AUDIO
754− tristate "Audio Gadget"
755− depends on SND
756− select USB_LIBCOMPOSITE
757− select SND_PCM
758− help
759− This Gadget Audio driver is compatible with USB Audio Class
760− specification 2.0. It implements 1 AudioControl interface,
761− 1 AudioStreaming Interface each for USB-OUT and USB-IN.
762− Number of channels, sample rate and sample size can be
763− specified as module parameters.
764− This driver doesn't expect any real Audio codec to be present
765− on the device - the audio streams are simply sinked to and
766− sourced from a virtual ALSA sound card created. The user-space
767− application may choose to do whatever it wants with the data
768− received from the USB Host and choose to provide whatever it
769− wants as audio data to the USB Host.
770−
771− Say "y" to link the driver statically, or "m" to build a
772− dynamically linked module called "g_audio".
773−
774−config GADGET_UAC1
775− bool "UAC 1.0 (Legacy)"
776− depends on USB_AUDIO
777− help
778− If you instead want older UAC Spec-1.0 driver that also has audio
779− paths hardwired to the Audio codec chip on-board and doesn't work
780− without one.
781−
782−config USB_ETH
783− tristate "Ethernet Gadget (with CDC Ethernet support)"
784− depends on NET
785− select USB_LIBCOMPOSITE
786− select USB_U_ETHER
787− select USB_F_ECM
788− select USB_F_SUBSET
789− select CRC32
790− help
791− This driver implements Ethernet style communication, in one of
792− several ways:
793−
794− - The "Communication Device Class" (CDC) Ethernet Control Model.
795− That protocol is often avoided with pure Ethernet adapters, in
796− favor of simpler vendor-specific hardware, but is widely
797− supported by firmware for smart network devices.
798−
799− - On hardware can't implement that protocol, a simple CDC subset
800− is used, placing fewer demands on USB.
801−
802− - CDC Ethernet Emulation Model (EEM) is a newer standard that has
803− a simpler interface that can be used by more USB hardware.
804−
805− RNDIS support is an additional option, more demanding than than
806− subset.
807−
808− Within the USB device, this gadget driver exposes a network device
809− "usbX", where X depends on what other networking devices you have.
810− Treat it like a two-node Ethernet link: host, and gadget.
811−
812− The Linux-USB host-side "usbnet" driver interoperates with this
813− driver, so that deep I/O queues can be supported. On 2.4 kernels,
814− use "CDCEther" instead, if you're using the CDC option. That CDC
815− mode should also interoperate with standard CDC Ethernet class
816− drivers on other host operating systems.
817−
818− Say "y" to link the driver statically, or "m" to build a
819− dynamically linked module called "g_ether".
820−
821−config USB_ETH_RNDIS
822− bool "RNDIS support"
823− depends on USB_ETH
824− select USB_LIBCOMPOSITE
825− select USB_F_RNDIS
826− default y
827− help
828− Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
829− and Microsoft provides redistributable binary RNDIS drivers for
830− older versions of Windows.
831−
832− If you say "y" here, the Ethernet gadget driver will try to provide
833− a second device configuration, supporting RNDIS to talk to such
834− Microsoft USB hosts.
835−
836− To make MS-Windows work with this, use Documentation/usb/linux.inf
837− as the "driver info file". For versions of MS-Windows older than
838− XP, you'll need to download drivers from Microsoft's website; a URL
839− is given in comments found in that info file.
840−
841−config USB_ETH_EEM
842− bool "Ethernet Emulation Model (EEM) support"
843− depends on USB_ETH
844− select USB_LIBCOMPOSITE
845− select USB_F_EEM
846− default n
847− help
848− CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM
849− and therefore can be supported by more hardware. Technically ECM and
850− EEM are designed for different applications. The ECM model extends
851− the network interface to the target (e.g. a USB cable modem), and the
852− EEM model is for mobile devices to communicate with hosts using
853− ethernet over USB. For Linux gadgets, however, the interface with
854− the host is the same (a usbX device), so the differences are minimal.
855−
856− If you say "y" here, the Ethernet gadget driver will use the EEM
857− protocol rather than ECM. If unsure, say "n".
858−
859−config USB_G_NCM
860− tristate "Network Control Model (NCM) support"
861− depends on NET
862− select USB_LIBCOMPOSITE
863− select USB_U_ETHER
864− select USB_F_NCM
865− select CRC32
866− help
867− This driver implements USB CDC NCM subclass standard. NCM is
868− an advanced protocol for Ethernet encapsulation, allows grouping
869− of several ethernet frames into one USB transfer and different
870− alignment possibilities.
871−
872− Say "y" to link the driver statically, or "m" to build a
873− dynamically linked module called "g_ncm".
874−
875−config USB_GADGETFS
876− tristate "Gadget Filesystem"
877− help
878− This driver provides a filesystem based API that lets user mode
879− programs implement a single-configuration USB device, including
880− endpoint I/O and control requests that don't relate to enumeration.
881− All endpoints, transfer speeds, and transfer types supported by
882− the hardware are available, through read() and write() calls.
883−
884− Say "y" to link the driver statically, or "m" to build a
885− dynamically linked module called "gadgetfs".
886−
887−config USB_FUNCTIONFS
888− tristate "Function Filesystem"
889− select USB_LIBCOMPOSITE
890− select USB_F_FS
891− select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS)
892− help
893− The Function Filesystem (FunctionFS) lets one create USB
894− composite functions in user space in the same way GadgetFS
895− lets one create USB gadgets in user space. This allows creation
896− of composite gadgets such that some of the functions are
897− implemented in kernel space (for instance Ethernet, serial or
898− mass storage) and other are implemented in user space.
899−
900− If you say "y" or "m" here you will be able what kind of
901− configurations the gadget will provide.
902−
903− Say "y" to link the driver statically, or "m" to build
904− a dynamically linked module called "g_ffs".
905−
906−config USB_FUNCTIONFS_ETH
907− bool "Include configuration with CDC ECM (Ethernet)"
908− depends on USB_FUNCTIONFS && NET
909− select USB_U_ETHER
910− select USB_F_ECM
911− select USB_F_SUBSET
912− help
913− Include a configuration with CDC ECM function (Ethernet) and the
914− Function Filesystem.
915−
916−config USB_FUNCTIONFS_RNDIS
917− bool "Include configuration with RNDIS (Ethernet)"
918− depends on USB_FUNCTIONFS && NET
919− select USB_U_ETHER
920− select USB_F_RNDIS
921− help
922− Include a configuration with RNDIS function (Ethernet) and the Filesystem.
923−
924−config USB_FUNCTIONFS_GENERIC
925− bool "Include 'pure' configuration"
926− depends on USB_FUNCTIONFS
927− help
928− Include a configuration with the Function Filesystem alone with
929− no Ethernet interface.
930−
931−config USB_MASS_STORAGE
932− tristate "Mass Storage Gadget"
933− depends on BLOCK
934− select USB_LIBCOMPOSITE
935− select USB_F_MASS_STORAGE
936− help
937− The Mass Storage Gadget acts as a USB Mass Storage disk drive.
938− As its storage repository it can use a regular file or a block
939− device (in much the same way as the "loop" device driver),
940− specified as a module parameter or sysfs option.
941−
942− This driver is a replacement for now removed File-backed
943− Storage Gadget (g_file_storage).
944−
945− Say "y" to link the driver statically, or "m" to build
946− a dynamically linked module called "g_mass_storage".
947−
948−config USB_GADGET_TARGET
949− tristate "USB Gadget Target Fabric Module"
950− depends on TARGET_CORE
951− select USB_LIBCOMPOSITE
952− help
953− This fabric is an USB gadget. Two USB protocols are supported that is
954− BBB or BOT (Bulk Only Transport) and UAS (USB Attached SCSI). BOT is
955− advertised on alternative interface 0 (primary) and UAS is on
956− alternative interface 1. Both protocols can work on USB2.0 and USB3.0.
957− UAS utilizes the USB 3.0 feature called streams support.
958−
959−config USB_G_SERIAL
960− tristate "Serial Gadget (with CDC ACM and CDC OBEX support)"
961− depends on TTY
962− select USB_U_SERIAL
963− select USB_F_ACM
964− select USB_F_SERIAL
965− select USB_F_OBEX
966− select USB_LIBCOMPOSITE
967− help
968− The Serial Gadget talks to the Linux-USB generic serial driver.
969− This driver supports a CDC-ACM module option, which can be used
970− to interoperate with MS-Windows hosts or with the Linux-USB
971− "cdc-acm" driver.
972−
973− This driver also supports a CDC-OBEX option. You will need a
974− user space OBEX server talking to /dev/ttyGS*, since the kernel
975− itself doesn't implement the OBEX protocol.
976−
977− Say "y" to link the driver statically, or "m" to build a
978− dynamically linked module called "g_serial".
979−
980− For more information, see Documentation/usb/gadget_serial.txt
981− which includes instructions and a "driver info file" needed to
982− make MS-Windows work with CDC ACM.
983−
984−config USB_MIDI_GADGET
985− tristate "MIDI Gadget"
986− depends on SND
987− select USB_LIBCOMPOSITE
988− select SND_RAWMIDI
989− help
990− The MIDI Gadget acts as a USB Audio device, with one MIDI
991− input and one MIDI output. These MIDI jacks appear as
992− a sound "card" in the ALSA sound system. Other MIDI
993− connections can then be made on the gadget system, using
994− ALSA's aconnect utility etc.
995−
996− Say "y" to link the driver statically, or "m" to build a
997− dynamically linked module called "g_midi".
998−
999−config USB_G_PRINTER
1000− tristate "Printer Gadget"
1001− select USB_LIBCOMPOSITE
1002− help
1003− The Printer Gadget channels data between the USB host and a
1004− userspace program driving the print engine. The user space
1005− program reads and writes the device file /dev/g_printer to
1006− receive or send printer data. It can use ioctl calls to
1007− the device file to get or set printer status.
1008−
1009− Say "y" to link the driver statically, or "m" to build a
1010− dynamically linked module called "g_printer".
1011−
1012− For more information, see Documentation/usb/gadget_printer.txt
1013− which includes sample code for accessing the device file.
1014−
1015−if TTY
1016−
1017−config USB_CDC_COMPOSITE
1018− tristate "CDC Composite Device (Ethernet and ACM)"
1019− depends on NET
1020− select USB_LIBCOMPOSITE
1021− select USB_U_SERIAL
1022− select USB_U_ETHER
1023− select USB_F_ACM
1024− select USB_F_ECM
1025− help
1026− This driver provides two functions in one configuration:
1027− a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link.
1028−
1029− This driver requires four bulk and two interrupt endpoints,
1030− plus the ability to handle altsettings. Not all peripheral
1031− controllers are that capable.
1032−
1033− Say "y" to link the driver statically, or "m" to build a
1034− dynamically linked module.
1035−
1036−config USB_G_NOKIA
1037− tristate "Nokia composite gadget"
1038− depends on PHONET
1039− select USB_LIBCOMPOSITE
1040− select USB_U_SERIAL
1041− select USB_U_ETHER
1042− select USB_F_ACM
1043− select USB_F_OBEX
1044− select USB_F_PHONET
1045− select USB_F_ECM
1046− help
1047− The Nokia composite gadget provides support for acm, obex
1048− and phonet in only one composite gadget driver.
1049−
1050− It's only really useful for N900 hardware. If you're building
1051− a kernel for N900, say Y or M here. If unsure, say N.
1052−
1053−config USB_G_ACM_MS
1054− tristate "CDC Composite Device (ACM and mass storage)"
1055− depends on BLOCK
1056− select USB_LIBCOMPOSITE
1057− select USB_U_SERIAL
1058− select USB_F_ACM
1059− select USB_F_MASS_STORAGE
1060− help
1061− This driver provides two functions in one configuration:
1062− a mass storage, and a CDC ACM (serial port) link.
1063−
1064− Say "y" to link the driver statically, or "m" to build a
1065− dynamically linked module called "g_acm_ms".
1066−
1067−config USB_G_MULTI
1068− tristate "Multifunction Composite Gadget"
1069− depends on BLOCK && NET
1070− select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
1071− select USB_LIBCOMPOSITE
1072− select USB_U_SERIAL
1073− select USB_U_ETHER
1074− select USB_F_ACM
1075− select USB_F_MASS_STORAGE
1076− help
1077− The Multifunction Composite Gadget provides Ethernet (RNDIS
1078− and/or CDC Ethernet), mass storage and ACM serial link
1079− interfaces.
1080−
1081− You will be asked to choose which of the two configurations is
1082− to be available in the gadget. At least one configuration must
1083− be chosen to make the gadget usable. Selecting more than one
1084− configuration will prevent Windows from automatically detecting
1085− the gadget as a composite gadget, so an INF file will be needed to
1086− use the gadget.
1087−
1088− Say "y" to link the driver statically, or "m" to build a
1089− dynamically linked module called "g_multi".
1090−
1091−config USB_G_MULTI_RNDIS
1092− bool "RNDIS + CDC Serial + Storage configuration"
1093− depends on USB_G_MULTI
1094− select USB_F_RNDIS
1095− default y
1096− help
1097− This option enables a configuration with RNDIS, CDC Serial and
1098− Mass Storage functions available in the Multifunction Composite
1099− Gadget. This is the configuration dedicated for Windows since RNDIS
1100− is Microsoft's protocol.
1101−
1102− If unsure, say "y".
1103−
1104−config USB_G_MULTI_CDC
1105− bool "CDC Ethernet + CDC Serial + Storage configuration"
1106− depends on USB_G_MULTI
1107− default n
1108− select USB_F_ECM
1109− help
1110− This option enables a configuration with CDC Ethernet (ECM), CDC
1111− Serial and Mass Storage functions available in the Multifunction
1112− Composite Gadget.
1113−
1114− If unsure, say "y".
1115−
1116−endif # TTY
1117−
1118−config USB_G_HID
1119− tristate "HID Gadget"
1120− select USB_LIBCOMPOSITE
1121− help
1122− The HID gadget driver provides generic emulation of USB
1123− Human Interface Devices (HID).
1124−
1125− For more information, see Documentation/usb/gadget_hid.txt which
1126− includes sample code for accessing the device files.
1127−
1128− Say "y" to link the driver statically, or "m" to build a
1129− dynamically linked module called "g_hid".
1130−
1131−# Standalone / single function gadgets
1132−config USB_G_DBGP
1133− tristate "EHCI Debug Device Gadget"
1134− depends on TTY
1135− select USB_LIBCOMPOSITE
1136− help
1137− This gadget emulates an EHCI Debug device. This is useful when you want
1138− to interact with an EHCI Debug Port.
1139−
1140− Say "y" to link the driver statically, or "m" to build a
1141− dynamically linked module called "g_dbgp".
1142−
1143−if USB_G_DBGP
1144−choice
1145− prompt "EHCI Debug Device mode"
1146− default USB_G_DBGP_SERIAL
1147−
1148−config USB_G_DBGP_PRINTK
1149− depends on USB_G_DBGP
1150− bool "printk"
1151− help
1152− Directly printk() received data. No interaction.
1153−
1154−config USB_G_DBGP_SERIAL
1155− depends on USB_G_DBGP
1156− select USB_U_SERIAL
1157− bool "serial"
1158− help
1159− Userland can interact using /dev/ttyGSxxx.
1160−endchoice
1161−endif
1162−
1163−# put drivers that need isochronous transfer support (for audio
1164−# or video class gadget drivers), or specific hardware, here.
1165−config USB_G_WEBCAM
1166− tristate "USB Webcam Gadget"
1167− depends on VIDEO_DEV
1168− select USB_LIBCOMPOSITE
1169− select VIDEOBUF2_VMALLOC
1170− help
1171− The Webcam Gadget acts as a composite USB Audio and Video Class
1172− device. It provides a userspace API to process UVC control requests
1173− and stream video data to the host.
1174−
1175− Say "y" to link the driver statically, or "m" to build a
1176− dynamically linked module called "g_webcam".
356+source "drivers/usb/gadget/legacy/Kconfig"
1177357
1178358 endchoice
1179359
drivers/usb/gadget/Makefile+4−97
@@ -1,105 +1,12 @@
11 #
22 # USB peripheral controller drivers
33 #
4−ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5−ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG
4+subdir-ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5+subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG
6+ccflags-y += -I$(PWD)/drivers/usb/gadget/udc
67
7−obj-$(CONFIG_USB_GADGET) += udc-core.o
88 obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
99 libcomposite-y := usbstring.o config.o epautoconf.o
1010 libcomposite-y += composite.o functions.o configfs.o u_f.o
11−obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
12−obj-$(CONFIG_USB_NET2272) += net2272.o
13−obj-$(CONFIG_USB_NET2280) += net2280.o
14−obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o
15−obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o
16−obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o
17−obj-$(CONFIG_USB_GOKU) += goku_udc.o
18−obj-$(CONFIG_USB_OMAP) += omap_udc.o
19−obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
20−obj-$(CONFIG_USB_AT91) += at91_udc.o
21−obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
22−obj-$(CONFIG_USB_BCM63XX_UDC) += bcm63xx_udc.o
23−obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
24−fsl_usb2_udc-y := fsl_udc_core.o
25−fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o
26−obj-$(CONFIG_USB_M66592) += m66592-udc.o
27−obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o
28−obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o
29−obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o
30−obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o
31−obj-$(CONFIG_USB_EG20T) += pch_udc.o
32−obj-$(CONFIG_USB_MV_UDC) += mv_udc.o
33−mv_udc-y := mv_udc_core.o
34−obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
35−obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
36−obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
37−obj-$(CONFIG_USB_GR_UDC) += gr_udc.o
3811
39−# USB Functions
40−usb_f_acm-y := f_acm.o
41−obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o
42−usb_f_ss_lb-y := f_loopback.o f_sourcesink.o
43−obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o
44−obj-$(CONFIG_USB_U_SERIAL) += u_serial.o
45−usb_f_serial-y := f_serial.o
46−obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o
47−usb_f_obex-y := f_obex.o
48−obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o
49−obj-$(CONFIG_USB_U_ETHER) += u_ether.o
50−usb_f_ncm-y := f_ncm.o
51−obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o
52−usb_f_ecm-y := f_ecm.o
53−obj-$(CONFIG_USB_F_ECM) += usb_f_ecm.o
54−usb_f_phonet-y := f_phonet.o
55−obj-$(CONFIG_USB_F_PHONET) += usb_f_phonet.o
56−usb_f_eem-y := f_eem.o
57−obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o
58−usb_f_ecm_subset-y := f_subset.o
59−obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o
60−usb_f_rndis-y := f_rndis.o rndis.o
61−obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o
62−usb_f_mass_storage-y := f_mass_storage.o storage_common.o
63−obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
64−usb_f_fs-y := f_fs.o
65−obj-$(CONFIG_USB_F_FS) += usb_f_fs.o
66−
67−#
68−# USB gadget drivers
69−#
70−g_zero-y := zero.o
71−g_audio-y := audio.o
72−g_ether-y := ether.o
73−g_serial-y := serial.o
74−g_midi-y := gmidi.o
75−gadgetfs-y := inode.o
76−g_mass_storage-y := mass_storage.o
77−g_printer-y := printer.o
78−g_cdc-y := cdc2.o
79−g_multi-y := multi.o
80−g_hid-y := hid.o
81−g_dbgp-y := dbgp.o
82−g_nokia-y := nokia.o
83−g_webcam-y := webcam.o
84−g_ncm-y := ncm.o
85−g_acm_ms-y := acm_ms.o
86−g_tcm_usb_gadget-y := tcm_usb_gadget.o
87−
88−obj-$(CONFIG_USB_ZERO) += g_zero.o
89−obj-$(CONFIG_USB_AUDIO) += g_audio.o
90−obj-$(CONFIG_USB_ETH) += g_ether.o
91−obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
92−obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o
93−obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o
94−obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
95−obj-$(CONFIG_USB_G_PRINTER) += g_printer.o
96−obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
97−obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o
98−obj-$(CONFIG_USB_G_HID) += g_hid.o
99−obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o
100−obj-$(CONFIG_USB_G_MULTI) += g_multi.o
101−obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o
102−obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
103−obj-$(CONFIG_USB_G_NCM) += g_ncm.o
104−obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o
105−obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o
12+obj-$(CONFIG_USB_GADGET) += udc/ function/ legacy/
drivers/usb/gadget/composite.c+1−0
@@ -1956,6 +1956,7 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev) · 1955 unmodified lines
19561956 }
19571957 if (cdev->req) {
19581958 kfree(cdev->req->buf);
1959+ usb_ep_dequeue(cdev->gadget->ep0, cdev->req);
19591960 usb_ep_free_request(cdev->gadget->ep0, cdev->req);
19601961 }
19611962 cdev->next_string_id = 0;
drivers/usb/gadget/configfs.c+1−3
@@ -1021,12 +1021,10 @@ static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop, · 1020 unmodified lines
10211021
10221022 if (page[len - 1] == '\n' || page[len - 1] == '\0')
10231023 --len;
1024− new_data = kzalloc(len, GFP_KERNEL);
1024+ new_data = kmemdup(page, len, GFP_KERNEL);
10251025 if (!new_data)
10261026 return -ENOMEM;
10271027
1028− memcpy(new_data, page, len);
1029−
10301028 if (desc->opts_mutex)
10311029 mutex_lock(desc->opts_mutex);
10321030 kfree(ext_prop->data);
drivers/usb/gadget/function/Makefile+34−0
@@ -0,0 +1,34 @@
1+#
2+# USB peripheral controller drivers
3+#
4+
5+ccflags-y := -I$(PWD)/drivers/usb/gadget/
6+ccflags-y += -I$(PWD)/drivers/usb/gadget/udc/
7+
8+# USB Functions
9+usb_f_acm-y := f_acm.o
10+obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o
11+usb_f_ss_lb-y := f_loopback.o f_sourcesink.o
12+obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o
13+obj-$(CONFIG_USB_U_SERIAL) += u_serial.o
14+usb_f_serial-y := f_serial.o
15+obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o
16+usb_f_obex-y := f_obex.o
17+obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o
18+obj-$(CONFIG_USB_U_ETHER) += u_ether.o
19+usb_f_ncm-y := f_ncm.o
20+obj-$(CONFIG_USB_F_NCM) += usb_f_ncm.o
21+usb_f_ecm-y := f_ecm.o
22+obj-$(CONFIG_USB_F_ECM) += usb_f_ecm.o
23+usb_f_phonet-y := f_phonet.o
24+obj-$(CONFIG_USB_F_PHONET) += usb_f_phonet.o
25+usb_f_eem-y := f_eem.o
26+obj-$(CONFIG_USB_F_EEM) += usb_f_eem.o
27+usb_f_ecm_subset-y := f_subset.o
28+obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o
29+usb_f_rndis-y := f_rndis.o rndis.o
30+obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o
31+usb_f_mass_storage-y := f_mass_storage.o storage_common.o
32+obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
33+usb_f_fs-y := f_fs.o
34+obj-$(CONFIG_USB_F_FS) += usb_f_fs.o
drivers/usb/gadget/function/f_acm.crenamed from drivers/usb/gadget/f_acm.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_ecm.crenamed from drivers/usb/gadget/f_ecm.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_eem.crenamed from drivers/usb/gadget/f_eem.c+10−12
@@ -355,20 +355,18 @@ static struct sk_buff *eem_wrap(struct gether *port, struct sk_buff *skb) · 354 unmodified lines
355355 int padlen = 0;
356356 u16 len = skb->len;
357357
358− if (!skb_cloned(skb)) {
359− int headroom = skb_headroom(skb);
360− int tailroom = skb_tailroom(skb);
358+ int headroom = skb_headroom(skb);
359+ int tailroom = skb_tailroom(skb);
361360
362− /* When (len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) is 0,
363− * stick two bytes of zero-length EEM packet on the end.
364− */
365− if (((len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) == 0)
366− padlen += 2;
361+ /* When (len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) is 0,
362+ * stick two bytes of zero-length EEM packet on the end.
363+ */
364+ if (((len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) == 0)
365+ padlen += 2;
367366
368− if ((tailroom >= (ETH_FCS_LEN + padlen)) &&
369− (headroom >= EEM_HLEN))
370− goto done;
371− }
367+ if ((tailroom >= (ETH_FCS_LEN + padlen)) &&
368+ (headroom >= EEM_HLEN) && !skb_cloned(skb))
369+ goto done;
372370
373371 skb2 = skb_copy_expand(skb, EEM_HLEN, ETH_FCS_LEN + padlen, GFP_ATOMIC);
374372 dev_kfree_skb_any(skb);
drivers/usb/gadget/function/f_fs.crenamed from drivers/usb/gadget/f_fs.c+339−13
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434
3535 #include "u_fs.h"
3636 #include "u_f.h"
37+#include "u_os_desc.h"
3738 #include "configfs.h"
3839
3940 #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */
@@ -1646,13 +1647,22 @@ enum ffs_entity_type { · 1606 unmodified lines
16461647 FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT
16471648 };
16481649
1650+enum ffs_os_desc_type {
1651+ FFS_OS_DESC, FFS_OS_DESC_EXT_COMPAT, FFS_OS_DESC_EXT_PROP
1652+};
1653+
16491654 typedef int (*ffs_entity_callback)(enum ffs_entity_type entity,
16501655 u8 *valuep,
16511656 struct usb_descriptor_header *desc,
16521657 void *priv);
16531658
1654−static int __must_check ffs_do_desc(char *data, unsigned len,
1655− ffs_entity_callback entity, void *priv)
1659+typedef int (*ffs_os_desc_callback)(enum ffs_os_desc_type entity,
1660+ struct usb_os_desc_header *h, void *data,
1661+ unsigned len, void *priv);
1662+
1663+static int __must_check ffs_do_single_desc(char *data, unsigned len,
1664+ ffs_entity_callback entity,
1665+ void *priv)
16561666 {
16571667 struct usb_descriptor_header *_ds = (void *)data;
16581668 u8 length;
@@ -1804,7 +1814,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, · 145 unmodified lines
18041814 if (!data)
18051815 return _len - len;
18061816
1807− ret = ffs_do_desc(data, len, entity, priv);
1817+ ret = ffs_do_single_desc(data, len, entity, priv);
18081818 if (unlikely(ret < 0)) {
18091819 pr_debug("%s returns %d\n", __func__, ret);
18101820 return ret;
@@ -1857,11 +1867,191 @@ static int __ffs_data_do_entity(enum ffs_entity_type type, · 46 unmodified lines
18571867 return 0;
18581868 }
18591869
1870+static int __ffs_do_os_desc_header(enum ffs_os_desc_type *next_type,
1871+ struct usb_os_desc_header *desc)
1872+{
1873+ u16 bcd_version = le16_to_cpu(desc->bcdVersion);
1874+ u16 w_index = le16_to_cpu(desc->wIndex);
1875+
1876+ if (bcd_version != 1) {
1877+ pr_vdebug("unsupported os descriptors version: %d",
1878+ bcd_version);
1879+ return -EINVAL;
1880+ }
1881+ switch (w_index) {
1882+ case 0x4:
1883+ *next_type = FFS_OS_DESC_EXT_COMPAT;
1884+ break;
1885+ case 0x5:
1886+ *next_type = FFS_OS_DESC_EXT_PROP;
1887+ break;
1888+ default:
1889+ pr_vdebug("unsupported os descriptor type: %d", w_index);
1890+ return -EINVAL;
1891+ }
1892+
1893+ return sizeof(*desc);
1894+}
1895+
1896+/*
1897+ * Process all extended compatibility/extended property descriptors
1898+ * of a feature descriptor
1899+ */
1900+static int __must_check ffs_do_single_os_desc(char *data, unsigned len,
1901+ enum ffs_os_desc_type type,
1902+ u16 feature_count,
1903+ ffs_os_desc_callback entity,
1904+ void *priv,
1905+ struct usb_os_desc_header *h)
1906+{
1907+ int ret;
1908+ const unsigned _len = len;
1909+
1910+ ENTER();
1911+
1912+ /* loop over all ext compat/ext prop descriptors */
1913+ while (feature_count--) {
1914+ ret = entity(type, h, data, len, priv);
1915+ if (unlikely(ret < 0)) {
1916+ pr_debug("bad OS descriptor, type: %d\n", type);
1917+ return ret;
1918+ }
1919+ data += ret;
1920+ len -= ret;
1921+ }
1922+ return _len - len;
1923+}
1924+
1925+/* Process a number of complete Feature Descriptors (Ext Compat or Ext Prop) */
1926+static int __must_check ffs_do_os_descs(unsigned count,
1927+ char *data, unsigned len,
1928+ ffs_os_desc_callback entity, void *priv)
1929+{
1930+ const unsigned _len = len;
1931+ unsigned long num = 0;
1932+
1933+ ENTER();
1934+
1935+ for (num = 0; num < count; ++num) {
1936+ int ret;
1937+ enum ffs_os_desc_type type;
1938+ u16 feature_count;
1939+ struct usb_os_desc_header *desc = (void *)data;
1940+
1941+ if (len < sizeof(*desc))
1942+ return -EINVAL;
1943+
1944+ /*
1945+ * Record "descriptor" entity.
1946+ * Process dwLength, bcdVersion, wIndex, get b/wCount.
1947+ * Move the data pointer to the beginning of extended
1948+ * compatibilities proper or extended properties proper
1949+ * portions of the data
1950+ */
1951+ if (le32_to_cpu(desc->dwLength) > len)
1952+ return -EINVAL;
1953+
1954+ ret = __ffs_do_os_desc_header(&type, desc);
1955+ if (unlikely(ret < 0)) {
1956+ pr_debug("entity OS_DESCRIPTOR(%02lx); ret = %d\n",
1957+ num, ret);
1958+ return ret;
1959+ }
1960+ /*
1961+ * 16-bit hex "?? 00" Little Endian looks like 8-bit hex "??"
1962+ */
1963+ feature_count = le16_to_cpu(desc->wCount);
1964+ if (type == FFS_OS_DESC_EXT_COMPAT &&
1965+ (feature_count > 255 || desc->Reserved))
1966+ return -EINVAL;
1967+ len -= ret;
1968+ data += ret;
1969+
1970+ /*
1971+ * Process all function/property descriptors
1972+ * of this Feature Descriptor
1973+ */
1974+ ret = ffs_do_single_os_desc(data, len, type,
1975+ feature_count, entity, priv, desc);
1976+ if (unlikely(ret < 0)) {
1977+ pr_debug("%s returns %d\n", __func__, ret);
1978+ return ret;
1979+ }
1980+
1981+ len -= ret;
1982+ data += ret;
1983+ }
1984+ return _len - len;
1985+}
1986+
1987+/**
1988+ * Validate contents of the buffer from userspace related to OS descriptors.
1989+ */
1990+static int __ffs_data_do_os_desc(enum ffs_os_desc_type type,
1991+ struct usb_os_desc_header *h, void *data,
1992+ unsigned len, void *priv)
1993+{
1994+ struct ffs_data *ffs = priv;
1995+ u8 length;
1996+
1997+ ENTER();
1998+
1999+ switch (type) {
2000+ case FFS_OS_DESC_EXT_COMPAT: {
2001+ struct usb_ext_compat_desc *d = data;
2002+ int i;
2003+
2004+ if (len < sizeof(*d) ||
2005+ d->bFirstInterfaceNumber >= ffs->interfaces_count ||
2006+ d->Reserved1)
2007+ return -EINVAL;
2008+ for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i)
2009+ if (d->Reserved2[i])
2010+ return -EINVAL;
2011+
2012+ length = sizeof(struct usb_ext_compat_desc);
2013+ }
2014+ break;
2015+ case FFS_OS_DESC_EXT_PROP: {
2016+ struct usb_ext_prop_desc *d = data;
2017+ u32 type, pdl;
2018+ u16 pnl;
2019+
2020+ if (len < sizeof(*d) || h->interface >= ffs->interfaces_count)
2021+ return -EINVAL;
2022+ length = le32_to_cpu(d->dwSize);
2023+ type = le32_to_cpu(d->dwPropertyDataType);
2024+ if (type < USB_EXT_PROP_UNICODE ||
2025+ type > USB_EXT_PROP_UNICODE_MULTI) {
2026+ pr_vdebug("unsupported os descriptor property type: %d",
2027+ type);
2028+ return -EINVAL;
2029+ }
2030+ pnl = le16_to_cpu(d->wPropertyNameLength);
2031+ pdl = le32_to_cpu(*(u32 *)((u8 *)data + 10 + pnl));
2032+ if (length != 14 + pnl + pdl) {
2033+ pr_vdebug("invalid os descriptor length: %d pnl:%d pdl:%d (descriptor %d)\n",
2034+ length, pnl, pdl, type);
2035+ return -EINVAL;
2036+ }
2037+ ++ffs->ms_os_descs_ext_prop_count;
2038+ /* property name reported to the host as "WCHAR"s */
2039+ ffs->ms_os_descs_ext_prop_name_len += pnl * 2;
2040+ ffs->ms_os_descs_ext_prop_data_len += pdl;
2041+ }
2042+ break;
2043+ default:
2044+ pr_vdebug("unknown descriptor: %d\n", type);
2045+ return -EINVAL;
2046+ }
2047+ return length;
2048+}
2049+
18602050 static int __ffs_data_got_descs(struct ffs_data *ffs,
18612051 char *const _data, size_t len)
18622052 {
18632053 char *data = _data, *raw_descs;
1864− unsigned counts[3], flags;
2054+ unsigned os_descs_count = 0, counts[3], flags;
18652055 int ret = -EINVAL, i;
18662056
18672057 ENTER();
@@ -1879,7 +2069,8 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 11 unmodified lines
18792069 flags = get_unaligned_le32(data + 8);
18802070 if (flags & ~(FUNCTIONFS_HAS_FS_DESC |
18812071 FUNCTIONFS_HAS_HS_DESC |
1882− FUNCTIONFS_HAS_SS_DESC)) {
2072+ FUNCTIONFS_HAS_SS_DESC |
2073+ FUNCTIONFS_HAS_MS_OS_DESC)) {
18832074 ret = -ENOSYS;
18842075 goto error;
18852076 }
@@ -1902,6 +2093,11 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 16 unmodified lines
19022093 len -= 4;
19032094 }
19042095 }
2096+ if (flags & (1 << i)) {
2097+ os_descs_count = get_unaligned_le32(data);
2098+ data += 4;
2099+ len -= 4;
2100+ };
19052101
19062102 /* Read descriptors */
19072103 raw_descs = data;
@@ -1915,6 +2111,14 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 7 unmodified lines
19152111 data += ret;
19162112 len -= ret;
19172113 }
2114+ if (os_descs_count) {
2115+ ret = ffs_do_os_descs(os_descs_count, data, len,
2116+ __ffs_data_do_os_desc, ffs);
2117+ if (ret < 0)
2118+ goto error;
2119+ data += ret;
2120+ len -= ret;
2121+ }
19182122
19192123 if (raw_descs == data || len) {
19202124 ret = -EINVAL;
@@ -1927,6 +2131,7 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, · 6 unmodified lines
19272131 ffs->fs_descs_count = counts[0];
19282132 ffs->hs_descs_count = counts[1];
19292133 ffs->ss_descs_count = counts[2];
2134+ ffs->ms_os_descs_count = os_descs_count;
19302135
19312136 return 0;
19322137
@@ -2268,6 +2473,85 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, · 335 unmodified lines
22682473 return 0;
22692474 }
22702475
2476+static int __ffs_func_bind_do_os_desc(enum ffs_os_desc_type type,
2477+ struct usb_os_desc_header *h, void *data,
2478+ unsigned len, void *priv)
2479+{
2480+ struct ffs_function *func = priv;
2481+ u8 length = 0;
2482+
2483+ switch (type) {
2484+ case FFS_OS_DESC_EXT_COMPAT: {
2485+ struct usb_ext_compat_desc *desc = data;
2486+ struct usb_os_desc_table *t;
2487+
2488+ t = &func->function.os_desc_table[desc->bFirstInterfaceNumber];
2489+ t->if_id = func->interfaces_nums[desc->bFirstInterfaceNumber];
2490+ memcpy(t->os_desc->ext_compat_id, &desc->CompatibleID,
2491+ ARRAY_SIZE(desc->CompatibleID) +
2492+ ARRAY_SIZE(desc->SubCompatibleID));
2493+ length = sizeof(*desc);
2494+ }
2495+ break;
2496+ case FFS_OS_DESC_EXT_PROP: {
2497+ struct usb_ext_prop_desc *desc = data;
2498+ struct usb_os_desc_table *t;
2499+ struct usb_os_desc_ext_prop *ext_prop;
2500+ char *ext_prop_name;
2501+ char *ext_prop_data;
2502+
2503+ t = &func->function.os_desc_table[h->interface];
2504+ t->if_id = func->interfaces_nums[h->interface];
2505+
2506+ ext_prop = func->ffs->ms_os_descs_ext_prop_avail;
2507+ func->ffs->ms_os_descs_ext_prop_avail += sizeof(*ext_prop);
2508+
2509+ ext_prop->type = le32_to_cpu(desc->dwPropertyDataType);
2510+ ext_prop->name_len = le16_to_cpu(desc->wPropertyNameLength);
2511+ ext_prop->data_len = le32_to_cpu(*(u32 *)
2512+ usb_ext_prop_data_len_ptr(data, ext_prop->name_len));
2513+ length = ext_prop->name_len + ext_prop->data_len + 14;
2514+
2515+ ext_prop_name = func->ffs->ms_os_descs_ext_prop_name_avail;
2516+ func->ffs->ms_os_descs_ext_prop_name_avail +=
2517+ ext_prop->name_len;
2518+
2519+ ext_prop_data = func->ffs->ms_os_descs_ext_prop_data_avail;
2520+ func->ffs->ms_os_descs_ext_prop_data_avail +=
2521+ ext_prop->data_len;
2522+ memcpy(ext_prop_data,
2523+ usb_ext_prop_data_ptr(data, ext_prop->name_len),
2524+ ext_prop->data_len);
2525+ /* unicode data reported to the host as "WCHAR"s */
2526+ switch (ext_prop->type) {
2527+ case USB_EXT_PROP_UNICODE:
2528+ case USB_EXT_PROP_UNICODE_ENV:
2529+ case USB_EXT_PROP_UNICODE_LINK:
2530+ case USB_EXT_PROP_UNICODE_MULTI:
2531+ ext_prop->data_len *= 2;
2532+ break;
2533+ }
2534+ ext_prop->data = ext_prop_data;
2535+
2536+ memcpy(ext_prop_name, usb_ext_prop_name_ptr(data),
2537+ ext_prop->name_len);
2538+ /* property name reported to the host as "WCHAR"s */
2539+ ext_prop->name_len *= 2;
2540+ ext_prop->name = ext_prop_name;
2541+
2542+ t->os_desc->ext_prop_len +=
2543+ ext_prop->name_len + ext_prop->data_len + 14;
2544+ ++t->os_desc->ext_prop_count;
2545+ list_add_tail(&ext_prop->entry, &t->os_desc->ext_prop);
2546+ }
2547+ break;
2548+ default:
2549+ pr_vdebug("unknown descriptor: %d\n", type);
2550+ }
2551+
2552+ return length;
2553+}
2554+
22712555 static inline struct f_fs_opts *ffs_do_functionfs_bind(struct usb_function *f,
22722556 struct usb_configuration *c)
22732557 {
@@ -2329,7 +2613,7 @@ static int _ffs_func_bind(struct usb_configuration *c, · 55 unmodified lines
23292613 const int super = gadget_is_superspeed(func->gadget) &&
23302614 func->ffs->ss_descs_count;
23312615
2332− int fs_len, hs_len, ret;
2616+ int fs_len, hs_len, ss_len, ret, i;
23332617
23342618 /* Make it a single chunk, less management later on */
23352619 vla_group(d);
@@ -2341,6 +2625,18 @@ static int _ffs_func_bind(struct usb_configuration *c, · 5 unmodified lines
23412625 vla_item_with_sz(d, struct usb_descriptor_header *, ss_descs,
23422626 super ? ffs->ss_descs_count + 1 : 0);
23432627 vla_item_with_sz(d, short, inums, ffs->interfaces_count);
2628+ vla_item_with_sz(d, struct usb_os_desc_table, os_desc_table,
2629+ c->cdev->use_os_string ? ffs->interfaces_count : 0);
2630+ vla_item_with_sz(d, char[16], ext_compat,
2631+ c->cdev->use_os_string ? ffs->interfaces_count : 0);
2632+ vla_item_with_sz(d, struct usb_os_desc, os_desc,
2633+ c->cdev->use_os_string ? ffs->interfaces_count : 0);
2634+ vla_item_with_sz(d, struct usb_os_desc_ext_prop, ext_prop,
2635+ ffs->ms_os_descs_ext_prop_count);
2636+ vla_item_with_sz(d, char, ext_prop_name,
2637+ ffs->ms_os_descs_ext_prop_name_len);
2638+ vla_item_with_sz(d, char, ext_prop_data,
2639+ ffs->ms_os_descs_ext_prop_data_len);
23442640 vla_item_with_sz(d, char, raw_descs, ffs->raw_descs_length);
23452641 char *vlabuf;
23462642
@@ -2351,12 +2647,16 @@ static int _ffs_func_bind(struct usb_configuration *c, · 4 unmodified lines
23512647 return -ENOTSUPP;
23522648
23532649 /* Allocate a single chunk, less management later on */
2354− vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL);
2650+ vlabuf = kzalloc(vla_group_size(d), GFP_KERNEL);
23552651 if (unlikely(!vlabuf))
23562652 return -ENOMEM;
23572653
2358− /* Zero */
2359− memset(vla_ptr(vlabuf, d, eps), 0, d_eps__sz);
2654+ ffs->ms_os_descs_ext_prop_avail = vla_ptr(vlabuf, d, ext_prop);
2655+ ffs->ms_os_descs_ext_prop_name_avail =
2656+ vla_ptr(vlabuf, d, ext_prop_name);
2657+ ffs->ms_os_descs_ext_prop_data_avail =
2658+ vla_ptr(vlabuf, d, ext_prop_data);
2659+
23602660 /* Copy descriptors */
23612661 memcpy(vla_ptr(vlabuf, d, raw_descs), ffs->raw_descs,
23622662 ffs->raw_descs_length);
@@ -2410,12 +2710,16 @@ static int _ffs_func_bind(struct usb_configuration *c, · 47 unmodified lines
24102710
24112711 if (likely(super)) {
24122712 func->function.ss_descriptors = vla_ptr(vlabuf, d, ss_descs);
2413− ret = ffs_do_descs(ffs->ss_descs_count,
2713+ ss_len = ffs_do_descs(ffs->ss_descs_count,
24142714 vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len,
24152715 d_raw_descs__sz - fs_len - hs_len,
24162716 __ffs_func_bind_do_descs, func);
2417− if (unlikely(ret < 0))
2717+ if (unlikely(ss_len < 0)) {
2718+ ret = ss_len;
24182719 goto error;
2720+ }
2721+ } else {
2722+ ss_len = 0;
24192723 }
24202724
24212725 /*
@@ -2431,6 +2735,28 @@ static int _ffs_func_bind(struct usb_configuration *c, · 9 unmodified lines
24312735 if (unlikely(ret < 0))
24322736 goto error;
24332737
2738+ func->function.os_desc_table = vla_ptr(vlabuf, d, os_desc_table);
2739+ if (c->cdev->use_os_string)
2740+ for (i = 0; i < ffs->interfaces_count; ++i) {
2741+ struct usb_os_desc *desc;
2742+
2743+ desc = func->function.os_desc_table[i].os_desc =
2744+ vla_ptr(vlabuf, d, os_desc) +
2745+ i * sizeof(struct usb_os_desc);
2746+ desc->ext_compat_id =
2747+ vla_ptr(vlabuf, d, ext_compat) + i * 16;
2748+ INIT_LIST_HEAD(&desc->ext_prop);
2749+ }
2750+ ret = ffs_do_os_descs(ffs->ms_os_descs_count,
2751+ vla_ptr(vlabuf, d, raw_descs) +
2752+ fs_len + hs_len + ss_len,
2753+ d_raw_descs__sz - fs_len - hs_len - ss_len,
2754+ __ffs_func_bind_do_os_desc, func);
2755+ if (unlikely(ret < 0))
2756+ goto error;
2757+ func->function.os_desc_n =
2758+ c->cdev->use_os_string ? ffs->interfaces_count : 0;
2759+
24342760 /* And we're done */
24352761 ffs_event_add(ffs, FUNCTIONFS_BIND);
24362762 return 0;
@@ -2901,12 +3227,12 @@ static void *ffs_acquire_dev(const char *dev_name) · 464 unmodified lines
29013227
29023228 ffs_dev = _ffs_find_dev(dev_name);
29033229 if (!ffs_dev)
2904− ffs_dev = ERR_PTR(-ENODEV);
3230+ ffs_dev = ERR_PTR(-ENOENT);
29053231 else if (ffs_dev->mounted)
29063232 ffs_dev = ERR_PTR(-EBUSY);
29073233 else if (ffs_dev->ffs_acquire_dev_callback &&
29083234 ffs_dev->ffs_acquire_dev_callback(ffs_dev))
2909− ffs_dev = ERR_PTR(-ENODEV);
3235+ ffs_dev = ERR_PTR(-ENOENT);
29103236 else
29113237 ffs_dev->mounted = true;
29123238
drivers/usb/gadget/function/f_hid.crenamed from drivers/usb/gadget/f_hid.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_loopback.crenamed from drivers/usb/gadget/f_loopback.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_mass_storage.crenamed from drivers/usb/gadget/f_mass_storage.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_mass_storage.hrenamed from drivers/usb/gadget/f_mass_storage.h+0−0

File renamed without changes.

drivers/usb/gadget/function/f_midi.crenamed from drivers/usb/gadget/f_midi.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_ncm.crenamed from drivers/usb/gadget/f_ncm.c+332−148
@@ -68,6 +68,18 @@ struct f_ncm { · 67 unmodified lines
6868 * callback and ethernet open/close
6969 */
7070 spinlock_t lock;
71+
72+ struct net_device *netdev;
73+
74+ /* For multi-frame NDP TX */
75+ struct sk_buff *skb_tx_data;
76+ struct sk_buff *skb_tx_ndp;
77+ u16 ndp_dgram_count;
78+ bool timer_force_tx;
79+ struct tasklet_struct tx_tasklet;
80+ struct hrtimer task_timer;
81+
82+ bool timer_stopping;
7183 };
7284
7385 static inline struct f_ncm *func_to_ncm(struct usb_function *f)
@@ -92,15 +104,20 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g) · 18 unmodified lines
92104 * If the host can group frames, allow it to do that, 16K is selected,
93105 * because it's used by default by the current linux host driver
94106 */
95−#define NTB_DEFAULT_IN_SIZE USB_CDC_NCM_NTB_MIN_IN_SIZE
107+#define NTB_DEFAULT_IN_SIZE 16384
96108 #define NTB_OUT_SIZE 16384
97109
98−/*
99− * skbs of size less than that will not be aligned
100− * to NCM's dwNtbInMaxSize to save bus bandwidth
110+/* Allocation for storing the NDP, 32 should suffice for a
111+ * 16k packet. This allows a maximum of 32 * 507 Byte packets to
112+ * be transmitted in a single 16kB skb, though when sending full size
113+ * packets this limit will be plenty.
114+ * Smaller packets are not likely to be trying to maximize the
115+ * throughput and will be mstly sending smaller infrequent frames.
101116 */
117+#define TX_MAX_NUM_DPE 32
102118
103−#define MAX_TX_NONFIXED (512 * 3)
119+/* Delay for the transmit to wait before sending an unfilled NTB frame. */
120+#define TX_TIMEOUT_NSECS 300000
104121
105122 #define FORMATS_SUPPORTED (USB_CDC_NCM_NTB16_SUPPORTED | \
106123 USB_CDC_NCM_NTB32_SUPPORTED)
@@ -355,14 +372,15 @@ struct ndp_parser_opts { · 248 unmodified lines
355372 u32 ndp_sign;
356373 unsigned nth_size;
357374 unsigned ndp_size;
375+ unsigned dpe_size;
358376 unsigned ndplen_align;
359377 /* sizes in u16 units */
360378 unsigned dgram_item_len; /* index or length */
361379 unsigned block_length;
362− unsigned fp_index;
380+ unsigned ndp_index;
363381 unsigned reserved1;
364382 unsigned reserved2;
365− unsigned next_fp_index;
383+ unsigned next_ndp_index;
366384 };
367385
368386 #define INIT_NDP16_OPTS { \
@@ -370,13 +388,14 @@ struct ndp_parser_opts { · 1 unmodified line
370388 .ndp_sign = USB_CDC_NCM_NDP16_NOCRC_SIGN, \
371389 .nth_size = sizeof(struct usb_cdc_ncm_nth16), \
372390 .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \
391+ .dpe_size = sizeof(struct usb_cdc_ncm_dpe16), \
373392 .ndplen_align = 4, \
374393 .dgram_item_len = 1, \
375394 .block_length = 1, \
376− .fp_index = 1, \
395+ .ndp_index = 1, \
377396 .reserved1 = 0, \
378397 .reserved2 = 0, \
379− .next_fp_index = 1, \
398+ .next_ndp_index = 1, \
380399 }
381400
382401
@@ -385,13 +404,14 @@ struct ndp_parser_opts { · 2 unmodified lines
385404 .ndp_sign = USB_CDC_NCM_NDP32_NOCRC_SIGN, \
386405 .nth_size = sizeof(struct usb_cdc_ncm_nth32), \
387406 .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \
407+ .dpe_size = sizeof(struct usb_cdc_ncm_dpe32), \
388408 .ndplen_align = 8, \
389409 .dgram_item_len = 2, \
390410 .block_length = 2, \
391− .fp_index = 2, \
411+ .ndp_index = 2, \
392412 .reserved1 = 1, \
393413 .reserved2 = 2, \
394− .next_fp_index = 2, \
414+ .next_ndp_index = 2, \
395415 }
396416
397417 static const struct ndp_parser_opts ndp16_opts = INIT_NDP16_OPTS;
@@ -803,6 +823,8 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) · 405 unmodified lines
803823
804824 if (ncm->port.in_ep->driver_data) {
805825 DBG(cdev, "reset ncm\n");
826+ ncm->timer_stopping = true;
827+ ncm->netdev = NULL;
806828 gether_disconnect(&ncm->port);
807829 ncm_reset_values(ncm);
808830 }
@@ -839,6 +861,8 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) · 30 unmodified lines
839861 net = gether_connect(&ncm->port);
840862 if (IS_ERR(net))
841863 return PTR_ERR(net);
864+ ncm->netdev = net;
865+ ncm->timer_stopping = false;
842866 }
843867
844868 spin_lock(&ncm->lock);
@@ -865,95 +889,232 @@ static int ncm_get_alt(struct usb_function *f, unsigned intf) · 20 unmodified lines
865889 return ncm->port.in_ep->driver_data ? 1 : 0;
866890 }
867891
892+static struct sk_buff *package_for_tx(struct f_ncm *ncm)
893+{
894+ __le16 *ntb_iter;
895+ struct sk_buff *skb2 = NULL;
896+ unsigned ndp_pad;
897+ unsigned ndp_index;
898+ unsigned new_len;
899+
900+ const struct ndp_parser_opts *opts = ncm->parser_opts;
901+ const int ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
902+ const int dgram_idx_len = 2 * 2 * opts->dgram_item_len;
903+
904+ /* Stop the timer */
905+ hrtimer_try_to_cancel(&ncm->task_timer);
906+
907+ ndp_pad = ALIGN(ncm->skb_tx_data->len, ndp_align) -
908+ ncm->skb_tx_data->len;
909+ ndp_index = ncm->skb_tx_data->len + ndp_pad;
910+ new_len = ndp_index + dgram_idx_len + ncm->skb_tx_ndp->len;
911+
912+ /* Set the final BlockLength and wNdpIndex */
913+ ntb_iter = (void *) ncm->skb_tx_data->data;
914+ /* Increment pointer to BlockLength */
915+ ntb_iter += 2 + 1 + 1;
916+ put_ncm(&ntb_iter, opts->block_length, new_len);
917+ put_ncm(&ntb_iter, opts->ndp_index, ndp_index);
918+
919+ /* Set the final NDP wLength */
920+ new_len = opts->ndp_size +
921+ (ncm->ndp_dgram_count * dgram_idx_len);
922+ ncm->ndp_dgram_count = 0;
923+ /* Increment from start to wLength */
924+ ntb_iter = (void *) ncm->skb_tx_ndp->data;
925+ ntb_iter += 2;
926+ put_unaligned_le16(new_len, ntb_iter);
927+
928+ /* Merge the skbs */
929+ swap(skb2, ncm->skb_tx_data);
930+ if (ncm->skb_tx_data) {
931+ dev_kfree_skb_any(ncm->skb_tx_data);
932+ ncm->skb_tx_data = NULL;
933+ }
934+
935+ /* Insert NDP alignment. */
936+ ntb_iter = (void *) skb_put(skb2, ndp_pad);
937+ memset(ntb_iter, 0, ndp_pad);
938+
939+ /* Copy NTB across. */
940+ ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len);
941+ memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len);
942+ dev_kfree_skb_any(ncm->skb_tx_ndp);
943+ ncm->skb_tx_ndp = NULL;
944+
945+ /* Insert zero'd datagram. */
946+ ntb_iter = (void *) skb_put(skb2, dgram_idx_len);
947+ memset(ntb_iter, 0, dgram_idx_len);
948+
949+ return skb2;
950+}
951+
868952 static struct sk_buff *ncm_wrap_ntb(struct gether *port,
869953 struct sk_buff *skb)
870954 {
871955 struct f_ncm *ncm = func_to_ncm(&port->func);
872− struct sk_buff *skb2;
956+ struct sk_buff *skb2 = NULL;
873957 int ncb_len = 0;
874− __le16 *tmp;
875− int div;
876− int rem;
877− int pad;
878− int ndp_align;
879− int ndp_pad;
958+ __le16 *ntb_data;
959+ __le16 *ntb_ndp;
960+ int dgram_pad;
961+
880962 unsigned max_size = ncm->port.fixed_in_len;
881963 const struct ndp_parser_opts *opts = ncm->parser_opts;
882− unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
883−
884− div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
885− rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder);
886− ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
964+ const int ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
965+ const int div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
966+ const int rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder);
967+ const int dgram_idx_len = 2 * 2 * opts->dgram_item_len;
887968
888− ncb_len += opts->nth_size;
889− ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len;
890− ncb_len += ndp_pad;
891− ncb_len += opts->ndp_size;
892− ncb_len += 2 * 2 * opts->dgram_item_len; /* Datagram entry */
893− ncb_len += 2 * 2 * opts->dgram_item_len; /* Zero datagram entry */
894− pad = ALIGN(ncb_len, div) + rem - ncb_len;
895− ncb_len += pad;
896−
897− if (ncb_len + skb->len + crc_len > max_size) {
898− dev_kfree_skb_any(skb);
969+ if (!skb && !ncm->skb_tx_data)
899970 return NULL;
900− }
901971
902− skb2 = skb_copy_expand(skb, ncb_len,
903− max_size - skb->len - ncb_len - crc_len,
904− GFP_ATOMIC);
905− dev_kfree_skb_any(skb);
906− if (!skb2)
907− return NULL;
972+ if (skb) {
973+ /* Add the CRC if required up front */
974+ if (ncm->is_crc) {
975+ uint32_t crc;
976+ __le16 *crc_pos;
977+
978+ crc = ~crc32_le(~0,
979+ skb->data,
980+ skb->len);
981+ crc_pos = (void *) skb_put(skb, sizeof(uint32_t));
982+ put_unaligned_le32(crc, crc_pos);
983+ }
908984
909− skb = skb2;
985+ /* If the new skb is too big for the current NCM NTB then
986+ * set the current stored skb to be sent now and clear it
987+ * ready for new data.
988+ * NOTE: Assume maximum align for speed of calculation.
989+ */
990+ if (ncm->skb_tx_data
991+ && (ncm->ndp_dgram_count >= TX_MAX_NUM_DPE
992+ || (ncm->skb_tx_data->len +
993+ div + rem + skb->len +
994+ ncm->skb_tx_ndp->len + ndp_align + (2 * dgram_idx_len))
995+ > max_size)) {
996+ skb2 = package_for_tx(ncm);
997+ if (!skb2)
998+ goto err;
999+ }
9101000
911− tmp = (void *) skb_push(skb, ncb_len);
912− memset(tmp, 0, ncb_len);
1001+ if (!ncm->skb_tx_data) {
1002+ ncb_len = opts->nth_size;
1003+ dgram_pad = ALIGN(ncb_len, div) + rem - ncb_len;
1004+ ncb_len += dgram_pad;
9131005
914− put_unaligned_le32(opts->nth_sign, tmp); /* dwSignature */
915− tmp += 2;
916− /* wHeaderLength */
917− put_unaligned_le16(opts->nth_size, tmp++);
918− tmp++; /* skip wSequence */
919− put_ncm(&tmp, opts->block_length, skb->len); /* (d)wBlockLength */
920− /* (d)wFpIndex */
921− /* the first pointer is right after the NTH + align */
922− put_ncm(&tmp, opts->fp_index, opts->nth_size + ndp_pad);
1006+ /* Create a new skb for the NTH and datagrams. */
1007+ ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC);
1008+ if (!ncm->skb_tx_data)
1009+ goto err;
9231010
924− tmp = (void *)tmp + ndp_pad;
1011+ ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len);
1012+ memset(ntb_data, 0, ncb_len);
1013+ /* dwSignature */
1014+ put_unaligned_le32(opts->nth_sign, ntb_data);
1015+ ntb_data += 2;
1016+ /* wHeaderLength */
1017+ put_unaligned_le16(opts->nth_size, ntb_data++);
1018+
1019+ /* Allocate an skb for storing the NDP,
1020+ * TX_MAX_NUM_DPE should easily suffice for a
1021+ * 16k packet.
1022+ */
1023+ ncm->skb_tx_ndp = alloc_skb((int)(opts->ndp_size
1024+ + opts->dpe_size
1025+ * TX_MAX_NUM_DPE),
1026+ GFP_ATOMIC);
1027+ if (!ncm->skb_tx_ndp)
1028+ goto err;
1029+ ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp,
1030+ opts->ndp_size);
1031+ memset(ntb_ndp, 0, ncb_len);
1032+ /* dwSignature */
1033+ put_unaligned_le32(ncm->ndp_sign, ntb_ndp);
1034+ ntb_ndp += 2;
9251035
926− /* NDP */
927− put_unaligned_le32(ncm->ndp_sign, tmp); /* dwSignature */
928− tmp += 2;
929− /* wLength */
930− put_unaligned_le16(ncb_len - opts->nth_size - pad, tmp++);
1036+ /* There is always a zeroed entry */
1037+ ncm->ndp_dgram_count = 1;
9311038
932− tmp += opts->reserved1;
933− tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */
934− tmp += opts->reserved2;
1039+ /* Note: we skip opts->next_ndp_index */
1040+ }
9351041
936− if (ncm->is_crc) {
937− uint32_t crc;
1042+ /* Delay the timer. */
1043+ hrtimer_start(&ncm->task_timer,
1044+ ktime_set(0, TX_TIMEOUT_NSECS),
1045+ HRTIMER_MODE_REL);
1046+
1047+ /* Add the datagram position entries */
1048+ ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp, dgram_idx_len);
1049+ memset(ntb_ndp, 0, dgram_idx_len);
1050+
1051+ ncb_len = ncm->skb_tx_data->len;
1052+ dgram_pad = ALIGN(ncb_len, div) + rem - ncb_len;
1053+ ncb_len += dgram_pad;
1054+
1055+ /* (d)wDatagramIndex */
1056+ put_ncm(&ntb_ndp, opts->dgram_item_len, ncb_len);
1057+ /* (d)wDatagramLength */
1058+ put_ncm(&ntb_ndp, opts->dgram_item_len, skb->len);
1059+ ncm->ndp_dgram_count++;
1060+
1061+ /* Add the new data to the skb */
1062+ ntb_data = (void *) skb_put(ncm->skb_tx_data, dgram_pad);
1063+ memset(ntb_data, 0, dgram_pad);
1064+ ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len);
1065+ memcpy(ntb_data, skb->data, skb->len);
1066+ dev_kfree_skb_any(skb);
1067+ skb = NULL;
9381068
939− crc = ~crc32_le(~0,
940− skb->data + ncb_len,
941− skb->len - ncb_len);
942− put_unaligned_le32(crc, skb->data + skb->len);
943− skb_put(skb, crc_len);
1069+ } else if (ncm->skb_tx_data && ncm->timer_force_tx) {
1070+ /* If the tx was requested because of a timeout then send */
1071+ skb2 = package_for_tx(ncm);
1072+ if (!skb2)
1073+ goto err;
9441074 }
9451075
946− /* (d)wDatagramIndex[0] */
947− put_ncm(&tmp, opts->dgram_item_len, ncb_len);
948− /* (d)wDatagramLength[0] */
949− put_ncm(&tmp, opts->dgram_item_len, skb->len - ncb_len);
950− /* (d)wDatagramIndex[1] and (d)wDatagramLength[1] already zeroed */
1076+ return skb2;
9511077
952− if (skb->len > MAX_TX_NONFIXED)
953− memset(skb_put(skb, max_size - skb->len),
954− 0, max_size - skb->len);
1078+err:
1079+ ncm->netdev->stats.tx_dropped++;
1080+
1081+ if (skb)
1082+ dev_kfree_skb_any(skb);
1083+ if (ncm->skb_tx_data)
1084+ dev_kfree_skb_any(ncm->skb_tx_data);
1085+ if (ncm->skb_tx_ndp)
1086+ dev_kfree_skb_any(ncm->skb_tx_ndp);
9551087
956− return skb;
1088+ return NULL;
1089+}
1090+
1091+/*
1092+ * This transmits the NTB if there are frames waiting.
1093+ */
1094+static void ncm_tx_tasklet(unsigned long data)
1095+{
1096+ struct f_ncm *ncm = (void *)data;
1097+
1098+ if (ncm->timer_stopping)
1099+ return;
1100+
1101+ /* Only send if data is available. */
1102+ if (ncm->skb_tx_data) {
1103+ ncm->timer_force_tx = true;
1104+ ncm->netdev->netdev_ops->ndo_start_xmit(NULL, ncm->netdev);
1105+ ncm->timer_force_tx = false;
1106+ }
1107+}
1108+
1109+/*
1110+ * The transmit should only be run if no skb data has been sent
1111+ * for a certain duration.
1112+ */
1113+static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
1114+{
1115+ struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer);
1116+ tasklet_schedule(&ncm->tx_tasklet);
1117+ return HRTIMER_NORESTART;
9571118 }
9581119
9591120 static int ncm_unwrap_ntb(struct gether *port,
@@ -963,6 +1124,7 @@ static int ncm_unwrap_ntb(struct gether *port, · 3 unmodified lines
9631124 struct f_ncm *ncm = func_to_ncm(&port->func);
9641125 __le16 *tmp = (void *) skb->data;
9651126 unsigned index, index2;
1127+ int ndp_index;
9661128 unsigned dg_len, dg_len2;
9671129 unsigned ndp_len;
9681130 struct sk_buff *skb2;
@@ -995,91 +1157,101 @@ static int ncm_unwrap_ntb(struct gether *port, · 26 unmodified lines
9951157 goto err;
9961158 }
9971159
998− index = get_ncm(&tmp, opts->fp_index);
999− /* NCM 3.2 */
1000− if (((index % 4) != 0) && (index < opts->nth_size)) {
1001− INFO(port->func.config->cdev, "Bad index: %x\n",
1002− index);
1003− goto err;
1004− }
1005−
1006− /* walk through NDP */
1007− tmp = ((void *)skb->data) + index;
1008− if (get_unaligned_le32(tmp) != ncm->ndp_sign) {
1009− INFO(port->func.config->cdev, "Wrong NDP SIGN\n");
1010− goto err;
1011− }
1012− tmp += 2;
1013−
1014− ndp_len = get_unaligned_le16(tmp++);
1015− /*
1016− * NCM 3.3.1
1017− * entry is 2 items
1018− * item size is 16/32 bits, opts->dgram_item_len * 2 bytes
1019− * minimal: struct usb_cdc_ncm_ndpX + normal entry + zero entry
1020− */
1021− if ((ndp_len < opts->ndp_size + 2 * 2 * (opts->dgram_item_len * 2))
1022− || (ndp_len % opts->ndplen_align != 0)) {
1023− INFO(port->func.config->cdev, "Bad NDP length: %x\n", ndp_len);
1024− goto err;
1025− }
1026− tmp += opts->reserved1;
1027− tmp += opts->next_fp_index; /* skip reserved (d)wNextFpIndex */
1028− tmp += opts->reserved2;
1029−
1030− ndp_len -= opts->ndp_size;
1031− index2 = get_ncm(&tmp, opts->dgram_item_len);
1032− dg_len2 = get_ncm(&tmp, opts->dgram_item_len);
1033− dgram_counter = 0;
1160+ ndp_index = get_ncm(&tmp, opts->ndp_index);
10341161
1162+ /* Run through all the NDP's in the NTB */
10351163 do {
1036− index = index2;
1037− dg_len = dg_len2;
1038− if (dg_len < 14 + crc_len) { /* ethernet header + crc */
1039− INFO(port->func.config->cdev, "Bad dgram length: %x\n",
1040− dg_len);
1164+ /* NCM 3.2 */
1165+ if (((ndp_index % 4) != 0) &&
1166+ (ndp_index < opts->nth_size)) {
1167+ INFO(port->func.config->cdev, "Bad index: %#X\n",
1168+ ndp_index);
10411169 goto err;
10421170 }
1043− if (ncm->is_crc) {
1044− uint32_t crc, crc2;
1045−
1046− crc = get_unaligned_le32(skb->data +
1047− index + dg_len - crc_len);
1048− crc2 = ~crc32_le(~0,
1049− skb->data + index,
1050− dg_len - crc_len);
1051− if (crc != crc2) {
1052− INFO(port->func.config->cdev, "Bad CRC\n");
1053− goto err;
1054− }
1171+
1172+ /* walk through NDP */
1173+ tmp = (void *)(skb->data + ndp_index);
1174+ if (get_unaligned_le32(tmp) != ncm->ndp_sign) {
1175+ INFO(port->func.config->cdev, "Wrong NDP SIGN\n");
1176+ goto err;
10551177 }
1178+ tmp += 2;
10561179
1180+ ndp_len = get_unaligned_le16(tmp++);
1181+ /*
1182+ * NCM 3.3.1
1183+ * entry is 2 items
1184+ * item size is 16/32 bits, opts->dgram_item_len * 2 bytes
1185+ * minimal: struct usb_cdc_ncm_ndpX + normal entry + zero entry
1186+ * Each entry is a dgram index and a dgram length.
1187+ */
1188+ if ((ndp_len < opts->ndp_size
1189+ + 2 * 2 * (opts->dgram_item_len * 2))
1190+ || (ndp_len % opts->ndplen_align != 0)) {
1191+ INFO(port->func.config->cdev, "Bad NDP length: %#X\n",
1192+ ndp_len);
1193+ goto err;
1194+ }
1195+ tmp += opts->reserved1;
1196+ /* Check for another NDP (d)wNextNdpIndex */
1197+ ndp_index = get_ncm(&tmp, opts->next_ndp_index);
1198+ tmp += opts->reserved2;
1199+
1200+ ndp_len -= opts->ndp_size;
10571201 index2 = get_ncm(&tmp, opts->dgram_item_len);
10581202 dg_len2 = get_ncm(&tmp, opts->dgram_item_len);
1203+ dgram_counter = 0;
1204+
1205+ do {
1206+ index = index2;
1207+ dg_len = dg_len2;
1208+ if (dg_len < 14 + crc_len) { /* ethernet hdr + crc */
1209+ INFO(port->func.config->cdev,
1210+ "Bad dgram length: %#X\n", dg_len);
1211+ goto err;
1212+ }
1213+ if (ncm->is_crc) {
1214+ uint32_t crc, crc2;
1215+
1216+ crc = get_unaligned_le32(skb->data +
1217+ index + dg_len -
1218+ crc_len);
1219+ crc2 = ~crc32_le(~0,
1220+ skb->data + index,
1221+ dg_len - crc_len);
1222+ if (crc != crc2) {
1223+ INFO(port->func.config->cdev,
1224+ "Bad CRC\n");
1225+ goto err;
1226+ }
1227+ }
1228+
1229+ index2 = get_ncm(&tmp, opts->dgram_item_len);
1230+ dg_len2 = get_ncm(&tmp, opts->dgram_item_len);
10591231
1060− if (index2 == 0 || dg_len2 == 0) {
1061− skb2 = skb;
1062− } else {
1063− skb2 = skb_clone(skb, GFP_ATOMIC);
1232+ /*
1233+ * Copy the data into a new skb.
1234+ * This ensures the truesize is correct
1235+ */
1236+ skb2 = netdev_alloc_skb_ip_align(ncm->netdev,
1237+ dg_len - crc_len);
10641238 if (skb2 == NULL)
10651239 goto err;
1066− }
1240+ memcpy(skb_put(skb2, dg_len - crc_len),
1241+ skb->data + index, dg_len - crc_len);
10671242
1068− if (!skb_pull(skb2, index)) {
1069− ret = -EOVERFLOW;
1070− goto err;
1071− }
1243+ skb_queue_tail(list, skb2);
10721244
1073− skb_trim(skb2, dg_len - crc_len);
1074− skb_queue_tail(list, skb2);
1245+ ndp_len -= 2 * (opts->dgram_item_len * 2);
10751246
1076− ndp_len -= 2 * (opts->dgram_item_len * 2);
1247+ dgram_counter++;
10771248
1078− dgram_counter++;
1249+ if (index2 == 0 || dg_len2 == 0)
1250+ break;
1251+ } while (ndp_len > 2 * (opts->dgram_item_len * 2));
1252+ } while (ndp_index);
10791253
1080− if (index2 == 0 || dg_len2 == 0)
1081− break;
1082− } while (ndp_len > 2 * (opts->dgram_item_len * 2)); /* zero entry */
1254+ dev_kfree_skb_any(skb);
10831255
10841256 VDBG(port->func.config->cdev,
10851257 "Parsed NTB with %d frames\n", dgram_counter);
@@ -1097,8 +1269,11 @@ static void ncm_disable(struct usb_function *f) · 11 unmodified lines
10971269
10981270 DBG(cdev, "ncm deactivated\n");
10991271
1100− if (ncm->port.in_ep->driver_data)
1272+ if (ncm->port.in_ep->driver_data) {
1273+ ncm->timer_stopping = true;
1274+ ncm->netdev = NULL;
11011275 gether_disconnect(&ncm->port);
1276+ }
11021277
11031278 if (ncm->notify->driver_data) {
11041279 usb_ep_disable(ncm->notify);
@@ -1267,6 +1442,10 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f) · 162 unmodified lines
12671442 ncm->port.open = ncm_open;
12681443 ncm->port.close = ncm_close;
12691444
1445+ tasklet_init(&ncm->tx_tasklet, ncm_tx_tasklet, (unsigned long) ncm);
1446+ hrtimer_init(&ncm->task_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1447+ ncm->task_timer.function = ncm_tx_timeout;
1448+
12701449 DBG(cdev, "CDC Network: %s speed IN/%s OUT/%s NOTIFY/%s\n",
12711450 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
12721451 ncm->port.in_ep->name, ncm->port.out_ep->name,
@@ -1380,6 +1559,10 @@ static void ncm_unbind(struct usb_configuration *c, struct usb_function *f) · 107 unmodified lines
13801559
13811560 DBG(c->cdev, "ncm unbind\n");
13821561
1562+ hrtimer_cancel(&ncm->task_timer);
1563+ tasklet_kill(&ncm->tx_tasklet);
1564+
1565+ ncm_string_defs[0].id = 0;
13831566 usb_free_all_descriptors(f);
13841567
13851568 kfree(ncm->notify_req->buf);
@@ -1416,6 +1599,7 @@ static struct usb_function *ncm_alloc(struct usb_function_instance *fi) · 30 unmodified lines
14161599 ncm->port.ioport = netdev_priv(opts->net);
14171600 mutex_unlock(&opts->lock);
14181601 ncm->port.is_fixed = true;
1602+ ncm->port.supports_multi_frame = true;
14191603
14201604 ncm->port.func.name = "cdc_network";
14211605 /* descriptors are per-instance copies */
drivers/usb/gadget/function/f_obex.crenamed from drivers/usb/gadget/f_obex.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_phonet.crenamed from drivers/usb/gadget/f_phonet.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_rndis.crenamed from drivers/usb/gadget/f_rndis.c+4−0
@@ -727,6 +727,10 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) · 726 unmodified lines
727727 rndis_control_intf.bInterfaceNumber = status;
728728 rndis_union_desc.bMasterInterface0 = status;
729729
730+ if (cdev->use_os_string)
731+ f->os_desc_table[0].if_id =
732+ rndis_iad_descriptor.bFirstInterface;
733+
730734 status = usb_interface_id(c, f);
731735 if (status < 0)
732736 goto fail;
drivers/usb/gadget/function/f_serial.crenamed from drivers/usb/gadget/f_serial.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_sourcesink.crenamed from drivers/usb/gadget/f_sourcesink.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_subset.crenamed from drivers/usb/gadget/f_subset.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_uac1.crenamed from drivers/usb/gadget/f_uac1.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_uac2.crenamed from drivers/usb/gadget/f_uac2.c+22−2
@@ -348,14 +348,34 @@ static int uac2_pcm_open(struct snd_pcm_substream *substream) · 347 unmodified lines
348348 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
349349 spin_lock_init(&uac2->p_prm.lock);
350350 runtime->hw.rate_min = p_srate;
351− runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; /* ! p_ssize ! */
351+ switch (p_ssize) {
352+ case 3:
353+ runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE;
354+ break;
355+ case 4:
356+ runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
357+ break;
358+ default:
359+ runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
360+ break;
361+ }
352362 runtime->hw.channels_min = num_channels(p_chmask);
353363 runtime->hw.period_bytes_min = 2 * uac2->p_prm.max_psize
354364 / runtime->hw.periods_min;
355365 } else {
356366 spin_lock_init(&uac2->c_prm.lock);
357367 runtime->hw.rate_min = c_srate;
358− runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; /* ! c_ssize ! */
368+ switch (c_ssize) {
369+ case 3:
370+ runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE;
371+ break;
372+ case 4:
373+ runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
374+ break;
375+ default:
376+ runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
377+ break;
378+ }
359379 runtime->hw.channels_min = num_channels(c_chmask);
360380 runtime->hw.period_bytes_min = 2 * uac2->c_prm.max_psize
361381 / runtime->hw.periods_min;
drivers/usb/gadget/function/f_uvc.crenamed from drivers/usb/gadget/f_uvc.c+0−0

File renamed without changes.

drivers/usb/gadget/function/f_uvc.hrenamed from drivers/usb/gadget/f_uvc.h+0−0

File renamed without changes.

drivers/usb/gadget/function/g_zero.hrenamed from drivers/usb/gadget/g_zero.h+0−0

File renamed without changes.

drivers/usb/gadget/function/ndis.hrenamed from drivers/usb/gadget/ndis.h+0−0

File renamed without changes.

drivers/usb/gadget/function/rndis.crenamed from drivers/usb/gadget/rndis.c+0−0

File renamed without changes.

drivers/usb/gadget/function/rndis.hrenamed from drivers/usb/gadget/rndis.h+0−0

File renamed without changes.

drivers/usb/gadget/function/storage_common.crenamed from drivers/usb/gadget/storage_common.c+0−0

File renamed without changes.

drivers/usb/gadget/function/storage_common.hrenamed from drivers/usb/gadget/storage_common.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_ecm.hrenamed from drivers/usb/gadget/u_ecm.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_eem.hrenamed from drivers/usb/gadget/u_eem.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_ether.crenamed from drivers/usb/gadget/u_ether.c+13−6
@@ -483,7 +483,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 482 unmodified lines
483483 struct net_device *net)
484484 {
485485 struct eth_dev *dev = netdev_priv(net);
486− int length = skb->len;
486+ int length = 0;
487487 int retval;
488488 struct usb_request *req = NULL;
489489 unsigned long flags;
@@ -500,13 +500,13 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 10 unmodified lines
500500 }
501501 spin_unlock_irqrestore(&dev->lock, flags);
502502
503− if (!in) {
503+ if (skb && !in) {
504504 dev_kfree_skb_any(skb);
505505 return NETDEV_TX_OK;
506506 }
507507
508508 /* apply outgoing CDC or RNDIS filters */
509− if (!is_promisc(cdc_filter)) {
509+ if (skb && !is_promisc(cdc_filter)) {
510510 u8 *dest = skb->data;
511511
512512 if (is_multicast_ether_addr(dest)) {
@@ -557,11 +557,17 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 44 unmodified lines
557557 if (dev->port_usb)
558558 skb = dev->wrap(dev->port_usb, skb);
559559 spin_unlock_irqrestore(&dev->lock, flags);
560− if (!skb)
560+ if (!skb) {
561+ /* Multi frame CDC protocols may store the frame for
562+ * later which is not a dropped frame.
563+ */
564+ if (dev->port_usb->supports_multi_frame)
565+ goto multiframe;
561566 goto drop;
562−
563− length = skb->len;
567+ }
564568 }
569+
570+ length = skb->len;
565571 req->buf = skb->data;
566572 req->context = skb;
567573 req->complete = tx_complete;
@@ -604,6 +610,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb, · 36 unmodified lines
604610 dev_kfree_skb_any(skb);
605611 drop:
606612 dev->net->stats.tx_dropped++;
613+multiframe:
607614 spin_lock_irqsave(&dev->req_lock, flags);
608615 if (list_empty(&dev->tx_reqs))
609616 netif_start_queue(net);
drivers/usb/gadget/function/u_ether.hrenamed from drivers/usb/gadget/u_ether.h+2−0
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include <linux/if_ether.h>
1919 #include <linux/usb/composite.h>
2020 #include <linux/usb/cdc.h>
21+#include <linux/netdevice.h>
2122
2223 #include "gadget_chips.h"
2324
@@ -74,6 +75,7 @@ struct gether { · 50 unmodified lines
7475 bool is_fixed;
7576 u32 fixed_out_len;
7677 u32 fixed_in_len;
78+ bool supports_multi_frame;
7779 struct sk_buff *(*wrap)(struct gether *port,
7880 struct sk_buff *skb);
7981 int (*unwrap)(struct gether *port,
drivers/usb/gadget/function/u_ether_configfs.hrenamed from drivers/usb/gadget/u_ether_configfs.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_fs.hrenamed from drivers/usb/gadget/u_fs.h+7−0
@@ -216,6 +216,13 @@ struct ffs_data { · 215 unmodified lines
216216 unsigned fs_descs_count;
217217 unsigned hs_descs_count;
218218 unsigned ss_descs_count;
219+ unsigned ms_os_descs_count;
220+ unsigned ms_os_descs_ext_prop_count;
221+ unsigned ms_os_descs_ext_prop_name_len;
222+ unsigned ms_os_descs_ext_prop_data_len;
223+ void *ms_os_descs_ext_prop_avail;
224+ void *ms_os_descs_ext_prop_name_avail;
225+ void *ms_os_descs_ext_prop_data_avail;
219226
220227 unsigned short strings_count;
221228 unsigned short interfaces_count;
drivers/usb/gadget/function/u_gether.hrenamed from drivers/usb/gadget/u_gether.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_ncm.hrenamed from drivers/usb/gadget/u_ncm.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_phonet.hrenamed from drivers/usb/gadget/u_phonet.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_rndis.hrenamed from drivers/usb/gadget/u_rndis.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_serial.crenamed from drivers/usb/gadget/u_serial.c+0−0

File renamed without changes.

drivers/usb/gadget/function/u_serial.hrenamed from drivers/usb/gadget/u_serial.h+0−0

File renamed without changes.

drivers/usb/gadget/function/u_uac1.crenamed from drivers/usb/gadget/u_uac1.c+0−0

File renamed without changes.

drivers/usb/gadget/function/u_uac1.hrenamed from drivers/usb/gadget/u_uac1.h+0−0

File renamed without changes.

drivers/usb/gadget/function/uvc.hrenamed from drivers/usb/gadget/uvc.h+0−0

File renamed without changes.

drivers/usb/gadget/function/uvc_queue.crenamed from drivers/usb/gadget/uvc_queue.c+0−0

File renamed without changes.

drivers/usb/gadget/function/uvc_queue.hrenamed from drivers/usb/gadget/uvc_queue.h+0−0

File renamed without changes.

drivers/usb/gadget/function/uvc_v4l2.crenamed from drivers/usb/gadget/uvc_v4l2.c+0−0

File renamed without changes.

drivers/usb/gadget/function/uvc_video.crenamed from drivers/usb/gadget/uvc_video.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/Kconfig+475−0
@@ -0,0 +1,475 @@
1+#
2+# USB Gadget support on a system involves
3+# (a) a peripheral controller, and
4+# (b) the gadget driver using it.
5+#
6+# NOTE: Gadget support ** DOES NOT ** depend on host-side CONFIG_USB !!
7+#
8+# - Host systems (like PCs) need CONFIG_USB (with "A" jacks).
9+# - Peripherals (like PDAs) need CONFIG_USB_GADGET (with "B" jacks).
10+# - Some systems have both kinds of controllers.
11+#
12+# With help from a special transceiver and a "Mini-AB" jack, systems with
13+# both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG).
14+#
15+
16+config USB_ZERO
17+ tristate "Gadget Zero (DEVELOPMENT)"
18+ select USB_LIBCOMPOSITE
19+ select USB_F_SS_LB
20+ help
21+ Gadget Zero is a two-configuration device. It either sinks and
22+ sources bulk data; or it loops back a configurable number of
23+ transfers. It also implements control requests, for "chapter 9"
24+ conformance. The driver needs only two bulk-capable endpoints, so
25+ it can work on top of most device-side usb controllers. It's
26+ useful for testing, and is also a working example showing how
27+ USB "gadget drivers" can be written.
28+
29+ Make this be the first driver you try using on top of any new
30+ USB peripheral controller driver. Then you can use host-side
31+ test software, like the "usbtest" driver, to put your hardware
32+ and its driver through a basic set of functional tests.
33+
34+ Gadget Zero also works with the host-side "usb-skeleton" driver,
35+ and with many kinds of host-side test software. You may need
36+ to tweak product and vendor IDs before host software knows about
37+ this device, and arrange to select an appropriate configuration.
38+
39+ Say "y" to link the driver statically, or "m" to build a
40+ dynamically linked module called "g_zero".
41+
42+config USB_ZERO_HNPTEST
43+ boolean "HNP Test Device"
44+ depends on USB_ZERO && USB_OTG
45+ help
46+ You can configure this device to enumerate using the device
47+ identifiers of the USB-OTG test device. That means that when
48+ this gadget connects to another OTG device, with this one using
49+ the "B-Peripheral" role, that device will use HNP to let this
50+ one serve as the USB host instead (in the "B-Host" role).
51+
52+config USB_AUDIO
53+ tristate "Audio Gadget"
54+ depends on SND
55+ select USB_LIBCOMPOSITE
56+ select SND_PCM
57+ help
58+ This Gadget Audio driver is compatible with USB Audio Class
59+ specification 2.0. It implements 1 AudioControl interface,
60+ 1 AudioStreaming Interface each for USB-OUT and USB-IN.
61+ Number of channels, sample rate and sample size can be
62+ specified as module parameters.
63+ This driver doesn't expect any real Audio codec to be present
64+ on the device - the audio streams are simply sinked to and
65+ sourced from a virtual ALSA sound card created. The user-space
66+ application may choose to do whatever it wants with the data
67+ received from the USB Host and choose to provide whatever it
68+ wants as audio data to the USB Host.
69+
70+ Say "y" to link the driver statically, or "m" to build a
71+ dynamically linked module called "g_audio".
72+
73+config GADGET_UAC1
74+ bool "UAC 1.0 (Legacy)"
75+ depends on USB_AUDIO
76+ help
77+ If you instead want older UAC Spec-1.0 driver that also has audio
78+ paths hardwired to the Audio codec chip on-board and doesn't work
79+ without one.
80+
81+config USB_ETH
82+ tristate "Ethernet Gadget (with CDC Ethernet support)"
83+ depends on NET
84+ select USB_LIBCOMPOSITE
85+ select USB_U_ETHER
86+ select USB_F_ECM
87+ select USB_F_SUBSET
88+ select CRC32
89+ help
90+ This driver implements Ethernet style communication, in one of
91+ several ways:
92+
93+ - The "Communication Device Class" (CDC) Ethernet Control Model.
94+ That protocol is often avoided with pure Ethernet adapters, in
95+ favor of simpler vendor-specific hardware, but is widely
96+ supported by firmware for smart network devices.
97+
98+ - On hardware can't implement that protocol, a simple CDC subset
99+ is used, placing fewer demands on USB.
100+
101+ - CDC Ethernet Emulation Model (EEM) is a newer standard that has
102+ a simpler interface that can be used by more USB hardware.
103+
104+ RNDIS support is an additional option, more demanding than than
105+ subset.
106+
107+ Within the USB device, this gadget driver exposes a network device
108+ "usbX", where X depends on what other networking devices you have.
109+ Treat it like a two-node Ethernet link: host, and gadget.
110+
111+ The Linux-USB host-side "usbnet" driver interoperates with this
112+ driver, so that deep I/O queues can be supported. On 2.4 kernels,
113+ use "CDCEther" instead, if you're using the CDC option. That CDC
114+ mode should also interoperate with standard CDC Ethernet class
115+ drivers on other host operating systems.
116+
117+ Say "y" to link the driver statically, or "m" to build a
118+ dynamically linked module called "g_ether".
119+
120+config USB_ETH_RNDIS
121+ bool "RNDIS support"
122+ depends on USB_ETH
123+ select USB_LIBCOMPOSITE
124+ select USB_F_RNDIS
125+ default y
126+ help
127+ Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
128+ and Microsoft provides redistributable binary RNDIS drivers for
129+ older versions of Windows.
130+
131+ If you say "y" here, the Ethernet gadget driver will try to provide
132+ a second device configuration, supporting RNDIS to talk to such
133+ Microsoft USB hosts.
134+
135+ To make MS-Windows work with this, use Documentation/usb/linux.inf
136+ as the "driver info file". For versions of MS-Windows older than
137+ XP, you'll need to download drivers from Microsoft's website; a URL
138+ is given in comments found in that info file.
139+
140+config USB_ETH_EEM
141+ bool "Ethernet Emulation Model (EEM) support"
142+ depends on USB_ETH
143+ select USB_LIBCOMPOSITE
144+ select USB_F_EEM
145+ default n
146+ help
147+ CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM
148+ and therefore can be supported by more hardware. Technically ECM and
149+ EEM are designed for different applications. The ECM model extends
150+ the network interface to the target (e.g. a USB cable modem), and the
151+ EEM model is for mobile devices to communicate with hosts using
152+ ethernet over USB. For Linux gadgets, however, the interface with
153+ the host is the same (a usbX device), so the differences are minimal.
154+
155+ If you say "y" here, the Ethernet gadget driver will use the EEM
156+ protocol rather than ECM. If unsure, say "n".
157+
158+config USB_G_NCM
159+ tristate "Network Control Model (NCM) support"
160+ depends on NET
161+ select USB_LIBCOMPOSITE
162+ select USB_U_ETHER
163+ select USB_F_NCM
164+ select CRC32
165+ help
166+ This driver implements USB CDC NCM subclass standard. NCM is
167+ an advanced protocol for Ethernet encapsulation, allows grouping
168+ of several ethernet frames into one USB transfer and different
169+ alignment possibilities.
170+
171+ Say "y" to link the driver statically, or "m" to build a
172+ dynamically linked module called "g_ncm".
173+
174+config USB_GADGETFS
175+ tristate "Gadget Filesystem"
176+ help
177+ This driver provides a filesystem based API that lets user mode
178+ programs implement a single-configuration USB device, including
179+ endpoint I/O and control requests that don't relate to enumeration.
180+ All endpoints, transfer speeds, and transfer types supported by
181+ the hardware are available, through read() and write() calls.
182+
183+ Say "y" to link the driver statically, or "m" to build a
184+ dynamically linked module called "gadgetfs".
185+
186+config USB_FUNCTIONFS
187+ tristate "Function Filesystem"
188+ select USB_LIBCOMPOSITE
189+ select USB_F_FS
190+ select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS)
191+ help
192+ The Function Filesystem (FunctionFS) lets one create USB
193+ composite functions in user space in the same way GadgetFS
194+ lets one create USB gadgets in user space. This allows creation
195+ of composite gadgets such that some of the functions are
196+ implemented in kernel space (for instance Ethernet, serial or
197+ mass storage) and other are implemented in user space.
198+
199+ If you say "y" or "m" here you will be able what kind of
200+ configurations the gadget will provide.
201+
202+ Say "y" to link the driver statically, or "m" to build
203+ a dynamically linked module called "g_ffs".
204+
205+config USB_FUNCTIONFS_ETH
206+ bool "Include configuration with CDC ECM (Ethernet)"
207+ depends on USB_FUNCTIONFS && NET
208+ select USB_U_ETHER
209+ select USB_F_ECM
210+ select USB_F_SUBSET
211+ help
212+ Include a configuration with CDC ECM function (Ethernet) and the
213+ Function Filesystem.
214+
215+config USB_FUNCTIONFS_RNDIS
216+ bool "Include configuration with RNDIS (Ethernet)"
217+ depends on USB_FUNCTIONFS && NET
218+ select USB_U_ETHER
219+ select USB_F_RNDIS
220+ help
221+ Include a configuration with RNDIS function (Ethernet) and the Filesystem.
222+
223+config USB_FUNCTIONFS_GENERIC
224+ bool "Include 'pure' configuration"
225+ depends on USB_FUNCTIONFS
226+ help
227+ Include a configuration with the Function Filesystem alone with
228+ no Ethernet interface.
229+
230+config USB_MASS_STORAGE
231+ tristate "Mass Storage Gadget"
232+ depends on BLOCK
233+ select USB_LIBCOMPOSITE
234+ select USB_F_MASS_STORAGE
235+ help
236+ The Mass Storage Gadget acts as a USB Mass Storage disk drive.
237+ As its storage repository it can use a regular file or a block
238+ device (in much the same way as the "loop" device driver),
239+ specified as a module parameter or sysfs option.
240+
241+ This driver is a replacement for now removed File-backed
242+ Storage Gadget (g_file_storage).
243+
244+ Say "y" to link the driver statically, or "m" to build
245+ a dynamically linked module called "g_mass_storage".
246+
247+config USB_GADGET_TARGET
248+ tristate "USB Gadget Target Fabric Module"
249+ depends on TARGET_CORE
250+ select USB_LIBCOMPOSITE
251+ help
252+ This fabric is an USB gadget. Two USB protocols are supported that is
253+ BBB or BOT (Bulk Only Transport) and UAS (USB Attached SCSI). BOT is
254+ advertised on alternative interface 0 (primary) and UAS is on
255+ alternative interface 1. Both protocols can work on USB2.0 and USB3.0.
256+ UAS utilizes the USB 3.0 feature called streams support.
257+
258+config USB_G_SERIAL
259+ tristate "Serial Gadget (with CDC ACM and CDC OBEX support)"
260+ depends on TTY
261+ select USB_U_SERIAL
262+ select USB_F_ACM
263+ select USB_F_SERIAL
264+ select USB_F_OBEX
265+ select USB_LIBCOMPOSITE
266+ help
267+ The Serial Gadget talks to the Linux-USB generic serial driver.
268+ This driver supports a CDC-ACM module option, which can be used
269+ to interoperate with MS-Windows hosts or with the Linux-USB
270+ "cdc-acm" driver.
271+
272+ This driver also supports a CDC-OBEX option. You will need a
273+ user space OBEX server talking to /dev/ttyGS*, since the kernel
274+ itself doesn't implement the OBEX protocol.
275+
276+ Say "y" to link the driver statically, or "m" to build a
277+ dynamically linked module called "g_serial".
278+
279+ For more information, see Documentation/usb/gadget_serial.txt
280+ which includes instructions and a "driver info file" needed to
281+ make MS-Windows work with CDC ACM.
282+
283+config USB_MIDI_GADGET
284+ tristate "MIDI Gadget"
285+ depends on SND
286+ select USB_LIBCOMPOSITE
287+ select SND_RAWMIDI
288+ help
289+ The MIDI Gadget acts as a USB Audio device, with one MIDI
290+ input and one MIDI output. These MIDI jacks appear as
291+ a sound "card" in the ALSA sound system. Other MIDI
292+ connections can then be made on the gadget system, using
293+ ALSA's aconnect utility etc.
294+
295+ Say "y" to link the driver statically, or "m" to build a
296+ dynamically linked module called "g_midi".
297+
298+config USB_G_PRINTER
299+ tristate "Printer Gadget"
300+ select USB_LIBCOMPOSITE
301+ help
302+ The Printer Gadget channels data between the USB host and a
303+ userspace program driving the print engine. The user space
304+ program reads and writes the device file /dev/g_printer to
305+ receive or send printer data. It can use ioctl calls to
306+ the device file to get or set printer status.
307+
308+ Say "y" to link the driver statically, or "m" to build a
309+ dynamically linked module called "g_printer".
310+
311+ For more information, see Documentation/usb/gadget_printer.txt
312+ which includes sample code for accessing the device file.
313+
314+if TTY
315+
316+config USB_CDC_COMPOSITE
317+ tristate "CDC Composite Device (Ethernet and ACM)"
318+ depends on NET
319+ select USB_LIBCOMPOSITE
320+ select USB_U_SERIAL
321+ select USB_U_ETHER
322+ select USB_F_ACM
323+ select USB_F_ECM
324+ help
325+ This driver provides two functions in one configuration:
326+ a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link.
327+
328+ This driver requires four bulk and two interrupt endpoints,
329+ plus the ability to handle altsettings. Not all peripheral
330+ controllers are that capable.
331+
332+ Say "y" to link the driver statically, or "m" to build a
333+ dynamically linked module.
334+
335+config USB_G_NOKIA
336+ tristate "Nokia composite gadget"
337+ depends on PHONET
338+ select USB_LIBCOMPOSITE
339+ select USB_U_SERIAL
340+ select USB_U_ETHER
341+ select USB_F_ACM
342+ select USB_F_OBEX
343+ select USB_F_PHONET
344+ select USB_F_ECM
345+ help
346+ The Nokia composite gadget provides support for acm, obex
347+ and phonet in only one composite gadget driver.
348+
349+ It's only really useful for N900 hardware. If you're building
350+ a kernel for N900, say Y or M here. If unsure, say N.
351+
352+config USB_G_ACM_MS
353+ tristate "CDC Composite Device (ACM and mass storage)"
354+ depends on BLOCK
355+ select USB_LIBCOMPOSITE
356+ select USB_U_SERIAL
357+ select USB_F_ACM
358+ select USB_F_MASS_STORAGE
359+ help
360+ This driver provides two functions in one configuration:
361+ a mass storage, and a CDC ACM (serial port) link.
362+
363+ Say "y" to link the driver statically, or "m" to build a
364+ dynamically linked module called "g_acm_ms".
365+
366+config USB_G_MULTI
367+ tristate "Multifunction Composite Gadget"
368+ depends on BLOCK && NET
369+ select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
370+ select USB_LIBCOMPOSITE
371+ select USB_U_SERIAL
372+ select USB_U_ETHER
373+ select USB_F_ACM
374+ select USB_F_MASS_STORAGE
375+ help
376+ The Multifunction Composite Gadget provides Ethernet (RNDIS
377+ and/or CDC Ethernet), mass storage and ACM serial link
378+ interfaces.
379+
380+ You will be asked to choose which of the two configurations is
381+ to be available in the gadget. At least one configuration must
382+ be chosen to make the gadget usable. Selecting more than one
383+ configuration will prevent Windows from automatically detecting
384+ the gadget as a composite gadget, so an INF file will be needed to
385+ use the gadget.
386+
387+ Say "y" to link the driver statically, or "m" to build a
388+ dynamically linked module called "g_multi".
389+
390+config USB_G_MULTI_RNDIS
391+ bool "RNDIS + CDC Serial + Storage configuration"
392+ depends on USB_G_MULTI
393+ select USB_F_RNDIS
394+ default y
395+ help
396+ This option enables a configuration with RNDIS, CDC Serial and
397+ Mass Storage functions available in the Multifunction Composite
398+ Gadget. This is the configuration dedicated for Windows since RNDIS
399+ is Microsoft's protocol.
400+
401+ If unsure, say "y".
402+
403+config USB_G_MULTI_CDC
404+ bool "CDC Ethernet + CDC Serial + Storage configuration"
405+ depends on USB_G_MULTI
406+ default n
407+ select USB_F_ECM
408+ help
409+ This option enables a configuration with CDC Ethernet (ECM), CDC
410+ Serial and Mass Storage functions available in the Multifunction
411+ Composite Gadget.
412+
413+ If unsure, say "y".
414+
415+endif # TTY
416+
417+config USB_G_HID
418+ tristate "HID Gadget"
419+ select USB_LIBCOMPOSITE
420+ help
421+ The HID gadget driver provides generic emulation of USB
422+ Human Interface Devices (HID).
423+
424+ For more information, see Documentation/usb/gadget_hid.txt which
425+ includes sample code for accessing the device files.
426+
427+ Say "y" to link the driver statically, or "m" to build a
428+ dynamically linked module called "g_hid".
429+
430+# Standalone / single function gadgets
431+config USB_G_DBGP
432+ tristate "EHCI Debug Device Gadget"
433+ depends on TTY
434+ select USB_LIBCOMPOSITE
435+ help
436+ This gadget emulates an EHCI Debug device. This is useful when you want
437+ to interact with an EHCI Debug Port.
438+
439+ Say "y" to link the driver statically, or "m" to build a
440+ dynamically linked module called "g_dbgp".
441+
442+if USB_G_DBGP
443+choice
444+ prompt "EHCI Debug Device mode"
445+ default USB_G_DBGP_SERIAL
446+
447+config USB_G_DBGP_PRINTK
448+ depends on USB_G_DBGP
449+ bool "printk"
450+ help
451+ Directly printk() received data. No interaction.
452+
453+config USB_G_DBGP_SERIAL
454+ depends on USB_G_DBGP
455+ select USB_U_SERIAL
456+ bool "serial"
457+ help
458+ Userland can interact using /dev/ttyGSxxx.
459+endchoice
460+endif
461+
462+# put drivers that need isochronous transfer support (for audio
463+# or video class gadget drivers), or specific hardware, here.
464+config USB_G_WEBCAM
465+ tristate "USB Webcam Gadget"
466+ depends on VIDEO_DEV
467+ select USB_LIBCOMPOSITE
468+ select VIDEOBUF2_VMALLOC
469+ help
470+ The Webcam Gadget acts as a composite USB Audio and Video Class
471+ device. It provides a userspace API to process UVC control requests
472+ and stream video data to the host.
473+
474+ Say "y" to link the driver statically, or "m" to build a
475+ dynamically linked module called "g_webcam".
drivers/usb/gadget/legacy/Makefile+44−0
@@ -0,0 +1,44 @@
1+#
2+# USB gadget drivers
3+#
4+
5+ccflags-y := -I$(PWD)/drivers/usb/gadget/
6+ccflags-y += -I$(PWD)/drivers/usb/gadget/udc/
7+ccflags-y += -I$(PWD)/drivers/usb/gadget/function/
8+
9+g_zero-y := zero.o
10+g_audio-y := audio.o
11+g_ether-y := ether.o
12+g_serial-y := serial.o
13+g_midi-y := gmidi.o
14+gadgetfs-y := inode.o
15+g_mass_storage-y := mass_storage.o
16+g_printer-y := printer.o
17+g_cdc-y := cdc2.o
18+g_multi-y := multi.o
19+g_hid-y := hid.o
20+g_dbgp-y := dbgp.o
21+g_nokia-y := nokia.o
22+g_webcam-y := webcam.o
23+g_ncm-y := ncm.o
24+g_acm_ms-y := acm_ms.o
25+g_tcm_usb_gadget-y := tcm_usb_gadget.o
26+
27+obj-$(CONFIG_USB_ZERO) += g_zero.o
28+obj-$(CONFIG_USB_AUDIO) += g_audio.o
29+obj-$(CONFIG_USB_ETH) += g_ether.o
30+obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
31+obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o
32+obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o
33+obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
34+obj-$(CONFIG_USB_G_PRINTER) += g_printer.o
35+obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
36+obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o
37+obj-$(CONFIG_USB_G_HID) += g_hid.o
38+obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o
39+obj-$(CONFIG_USB_G_MULTI) += g_multi.o
40+obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o
41+obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
42+obj-$(CONFIG_USB_G_NCM) += g_ncm.o
43+obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o
44+obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o
drivers/usb/gadget/legacy/acm_ms.crenamed from drivers/usb/gadget/acm_ms.c+2−12
@@ -267,18 +267,8 @@ static __refdata struct usb_composite_driver acm_ms_driver = { · 266 unmodified lines
267267 .unbind = __exit_p(acm_ms_unbind),
268268 };
269269
270+module_usb_composite_driver(acm_ms_driver);
271+
270272 MODULE_DESCRIPTION(DRIVER_DESC);
271273 MODULE_AUTHOR("Klaus Schwarzkopf <schwarzkopf@sensortherm.de>");
272274 MODULE_LICENSE("GPL v2");
273−
274−static int __init init(void)
275−{
276− return usb_composite_probe(&acm_ms_driver);
277−}
278−module_init(init);
279−
280−static void __exit cleanup(void)
281−{
282− usb_composite_unregister(&acm_ms_driver);
283−}
284−module_exit(cleanup);
drivers/usb/gadget/legacy/audio.crenamed from drivers/usb/gadget/audio.c+1−11
@@ -172,17 +172,7 @@ static __refdata struct usb_composite_driver audio_driver = { · 171 unmodified lines
172172 .unbind = __exit_p(audio_unbind),
173173 };
174174
175−static int __init init(void)
176−{
177− return usb_composite_probe(&audio_driver);
178−}
179−module_init(init);
180−
181−static void __exit cleanup(void)
182−{
183− usb_composite_unregister(&audio_driver);
184−}
185−module_exit(cleanup);
175+module_usb_composite_driver(audio_driver);
186176
187177 MODULE_DESCRIPTION(DRIVER_DESC);
188178 MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>");
drivers/usb/gadget/legacy/cdc2.crenamed from drivers/usb/gadget/cdc2.c+2−12
@@ -231,18 +231,8 @@ static __refdata struct usb_composite_driver cdc_driver = { · 230 unmodified lines
231231 .unbind = __exit_p(cdc_unbind),
232232 };
233233
234+module_usb_composite_driver(cdc_driver);
235+
234236 MODULE_DESCRIPTION(DRIVER_DESC);
235237 MODULE_AUTHOR("David Brownell");
236238 MODULE_LICENSE("GPL");
237−
238−static int __init init(void)
239−{
240− return usb_composite_probe(&cdc_driver);
241−}
242−module_init(init);
243−
244−static void __exit cleanup(void)
245−{
246− usb_composite_unregister(&cdc_driver);
247−}
248−module_exit(cleanup);
drivers/usb/gadget/legacy/dbgp.crenamed from drivers/usb/gadget/dbgp.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/ether.crenamed from drivers/usb/gadget/ether.c+2−12
@@ -475,18 +475,8 @@ static __refdata struct usb_composite_driver eth_driver = { · 474 unmodified lines
475475 .unbind = __exit_p(eth_unbind),
476476 };
477477
478+module_usb_composite_driver(eth_driver);
479+
478480 MODULE_DESCRIPTION(PREFIX DRIVER_DESC);
479481 MODULE_AUTHOR("David Brownell, Benedikt Spanger");
480482 MODULE_LICENSE("GPL");
481−
482−static int __init init(void)
483−{
484− return usb_composite_probe(&eth_driver);
485−}
486−module_init(init);
487−
488−static void __exit cleanup(void)
489−{
490− usb_composite_unregister(&eth_driver);
491−}
492−module_exit(cleanup);
drivers/usb/gadget/legacy/g_ffs.crenamed from drivers/usb/gadget/g_ffs.c+1−1
@@ -276,7 +276,7 @@ module_exit(gfs_exit); · 275 unmodified lines
276276 static void *functionfs_acquire_dev(struct ffs_dev *dev)
277277 {
278278 if (!try_module_get(THIS_MODULE))
279− return ERR_PTR(-ENODEV);
279+ return ERR_PTR(-ENOENT);
280280
281281 return 0;
282282 }
drivers/usb/gadget/legacy/gmidi.crenamed from drivers/usb/gadget/gmidi.c+1−12
@@ -163,15 +163,4 @@ static __refdata struct usb_composite_driver midi_driver = { · 162 unmodified lines
163163 .unbind = __exit_p(midi_unbind),
164164 };
165165
166−static int __init midi_init(void)
167−{
168− return usb_composite_probe(&midi_driver);
169−}
170−module_init(midi_init);
171−
172−static void __exit midi_cleanup(void)
173−{
174− usb_composite_unregister(&midi_driver);
175−}
176−module_exit(midi_cleanup);
177−
166+module_usb_composite_driver(midi_driver);
drivers/usb/gadget/legacy/hid.crenamed from drivers/usb/gadget/hid.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/inode.crenamed from drivers/usb/gadget/inode.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/mass_storage.crenamed from drivers/usb/gadget/mass_storage.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/multi.crenamed from drivers/usb/gadget/multi.c+1−12
@@ -507,15 +507,4 @@ static __refdata struct usb_composite_driver multi_driver = { · 506 unmodified lines
507507 .needs_serial = 1,
508508 };
509509
510−
511−static int __init multi_init(void)
512−{
513− return usb_composite_probe(&multi_driver);
514−}
515−module_init(multi_init);
516−
517−static void __exit multi_exit(void)
518−{
519− usb_composite_unregister(&multi_driver);
520−}
521−module_exit(multi_exit);
510+module_usb_composite_driver(multi_driver);
drivers/usb/gadget/legacy/ncm.crenamed from drivers/usb/gadget/ncm.c+2−12
@@ -204,18 +204,8 @@ static __refdata struct usb_composite_driver ncm_driver = { · 203 unmodified lines
204204 .unbind = __exit_p(gncm_unbind),
205205 };
206206
207+module_usb_composite_driver(ncm_driver);
208+
207209 MODULE_DESCRIPTION(DRIVER_DESC);
208210 MODULE_AUTHOR("Yauheni Kaliuta");
209211 MODULE_LICENSE("GPL");
210−
211−static int __init init(void)
212−{
213− return usb_composite_probe(&ncm_driver);
214−}
215−module_init(init);
216−
217−static void __exit cleanup(void)
218−{
219− usb_composite_unregister(&ncm_driver);
220−}
221−module_exit(cleanup);
drivers/usb/gadget/legacy/nokia.crenamed from drivers/usb/gadget/nokia.c+1−11
@@ -347,14 +347,4 @@ static __refdata struct usb_composite_driver nokia_driver = { · 346 unmodified lines
347347 .unbind = __exit_p(nokia_unbind),
348348 };
349349
350−static int __init nokia_init(void)
351−{
352− return usb_composite_probe(&nokia_driver);
353−}
354−module_init(nokia_init);
355−
356−static void __exit nokia_cleanup(void)
357−{
358− usb_composite_unregister(&nokia_driver);
359−}
360−module_exit(nokia_cleanup);
350+module_usb_composite_driver(nokia_driver);
drivers/usb/gadget/legacy/printer.crenamed from drivers/usb/gadget/printer.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/serial.crenamed from drivers/usb/gadget/serial.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/tcm_usb_gadget.crenamed from drivers/usb/gadget/tcm_usb_gadget.c+0−0

File renamed without changes.

drivers/usb/gadget/legacy/tcm_usb_gadget.hrenamed from drivers/usb/gadget/tcm_usb_gadget.h+0−0

File renamed without changes.

drivers/usb/gadget/legacy/webcam.crenamed from drivers/usb/gadget/webcam.c+1−14
@@ -390,20 +390,7 @@ static __refdata struct usb_composite_driver webcam_driver = { · 389 unmodified lines
390390 .unbind = webcam_unbind,
391391 };
392392
393−static int __init
394−webcam_init(void)
395−{
396− return usb_composite_probe(&webcam_driver);
397−}
398−
399−static void __exit
400−webcam_cleanup(void)
401−{
402− usb_composite_unregister(&webcam_driver);
403−}
404−
405−module_init(webcam_init);
406−module_exit(webcam_cleanup);
393+module_usb_composite_driver(webcam_driver);
407394
408395 MODULE_AUTHOR("Laurent Pinchart");
409396 MODULE_DESCRIPTION("Webcam Video Gadget");
drivers/usb/gadget/legacy/zero.crenamed from drivers/usb/gadget/zero.c+2−12
@@ -411,17 +411,7 @@ static __refdata struct usb_composite_driver zero_driver = { · 410 unmodified lines
411411 .resume = zero_resume,
412412 };
413413
414+module_usb_composite_driver(zero_driver);
415+
414416 MODULE_AUTHOR("David Brownell");
415417 MODULE_LICENSE("GPL");
416−
417−static int __init init(void)
418−{
419− return usb_composite_probe(&zero_driver);
420−}
421−module_init(init);
422−
423−static void __exit cleanup(void)
424−{
425− usb_composite_unregister(&zero_driver);
426−}
427−module_exit(cleanup);
drivers/usb/gadget/net2280.c+0−2905
@@ -1,2905 +0,0 @@
1−/*
2− * Driver for the PLX NET2280 USB device controller.
3− * Specs and errata are available from <http://www.plxtech.com>.
4− *
5− * PLX Technology Inc. (formerly NetChip Technology) supported the
6− * development of this driver.
7− *
8− *
9− * CODE STATUS HIGHLIGHTS
10− *
11− * This driver should work well with most "gadget" drivers, including
12− * the Mass Storage, Serial, and Ethernet/RNDIS gadget drivers
13− * as well as Gadget Zero and Gadgetfs.
14− *
15− * DMA is enabled by default. Drivers using transfer queues might use
16− * DMA chaining to remove IRQ latencies between transfers. (Except when
17− * short OUT transfers happen.) Drivers can use the req->no_interrupt
18− * hint to completely eliminate some IRQs, if a later IRQ is guaranteed
19− * and DMA chaining is enabled.
20− *
21− * Note that almost all the errata workarounds here are only needed for
22− * rev1 chips. Rev1a silicon (0110) fixes almost all of them.
23− */
24−
25−/*
26− * Copyright (C) 2003 David Brownell
27− * Copyright (C) 2003-2005 PLX Technology, Inc.
28− *
29− * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
30− * with 2282 chip
31− *
32− * This program is free software; you can redistribute it and/or modify
33− * it under the terms of the GNU General Public License as published by
34− * the Free Software Foundation; either version 2 of the License, or
35− * (at your option) any later version.
36− */
37−
38−#undef DEBUG /* messages on error and most fault paths */
39−#undef VERBOSE /* extra debug messages (success too) */
40−
41−#include <linux/module.h>
42−#include <linux/pci.h>
43−#include <linux/dma-mapping.h>
44−#include <linux/kernel.h>
45−#include <linux/delay.h>
46−#include <linux/ioport.h>
47−#include <linux/slab.h>
48−#include <linux/errno.h>
49−#include <linux/init.h>
50−#include <linux/timer.h>
51−#include <linux/list.h>
52−#include <linux/interrupt.h>
53−#include <linux/moduleparam.h>
54−#include <linux/device.h>
55−#include <linux/usb/ch9.h>
56−#include <linux/usb/gadget.h>
57−#include <linux/prefetch.h>
58−
59−#include <asm/byteorder.h>
60−#include <asm/io.h>
61−#include <asm/irq.h>
62−#include <asm/unaligned.h>
63−
64−
65−#define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
66−#define DRIVER_VERSION "2005 Sept 27"
67−
68−#define EP_DONTUSE 13 /* nonzero */
69−
70−#define USE_RDK_LEDS /* GPIO pins control three LEDs */
71−
72−
73−static const char driver_name [] = "net2280";
74−static const char driver_desc [] = DRIVER_DESC;
75−
76−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",
81−};
82−
83−/* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO)
84− * use_dma_chaining -- dma descriptor queueing gives even more irq reduction
85− *
86− * The net2280 DMA engines are not tightly integrated with their FIFOs;
87− * not all cases are (yet) handled well in this driver or the silicon.
88− * Some gadget drivers work better with the dma support here than others.
89− * These two parameters let you use PIO or more aggressive DMA.
90− */
91−static bool use_dma = 1;
92−static bool use_dma_chaining = 0;
93−
94−/* "modprobe net2280 use_dma=n" etc */
95−module_param (use_dma, bool, S_IRUGO);
96−module_param (use_dma_chaining, bool, S_IRUGO);
97−
98−
99−/* mode 0 == ep-{a,b,c,d} 1K fifo each
100− * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
101− * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
102− */
103−static ushort fifo_mode = 0;
104−
105−/* "modprobe net2280 fifo_mode=1" etc */
106−module_param (fifo_mode, ushort, 0644);
107−
108−/* enable_suspend -- When enabled, the driver will respond to
109− * USB suspend requests by powering down the NET2280. Otherwise,
110− * USB suspend requests will be ignored. This is acceptable for
111− * self-powered devices
112− */
113−static bool enable_suspend = 0;
114−
115−/* "modprobe net2280 enable_suspend=1" etc */
116−module_param (enable_suspend, bool, S_IRUGO);
117−
118−/* force full-speed operation */
119−static bool full_speed;
120−module_param(full_speed, bool, 0444);
121−MODULE_PARM_DESC(full_speed, "force full-speed mode -- for testing only!");
122−
123−#define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
124−
125−#if defined(CONFIG_USB_GADGET_DEBUG_FILES) || defined (DEBUG)
126−static char *type_string (u8 bmAttributes)
127−{
128− switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
129− case USB_ENDPOINT_XFER_BULK: return "bulk";
130− case USB_ENDPOINT_XFER_ISOC: return "iso";
131− case USB_ENDPOINT_XFER_INT: return "intr";
132− }
133− return "control";
134−}
135−#endif
136−
137−#include "net2280.h"
138−
139−#define valid_bit cpu_to_le32 (1 << VALID_BIT)
140−#define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
141−
142−/*-------------------------------------------------------------------------*/
143−
144−static int
145−net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
146−{
147− struct net2280 *dev;
148− struct net2280_ep *ep;
149− u32 max, tmp;
150− unsigned long flags;
151−
152− ep = container_of (_ep, struct net2280_ep, ep);
153− if (!_ep || !desc || ep->desc || _ep->name == ep0name
154− || desc->bDescriptorType != USB_DT_ENDPOINT)
155− return -EINVAL;
156− dev = ep->dev;
157− if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
158− return -ESHUTDOWN;
159−
160− /* erratum 0119 workaround ties up an endpoint number */
161− if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE)
162− return -EDOM;
163−
164− /* sanity check ep-e/ep-f since their fifos are small */
165− max = usb_endpoint_maxp (desc) & 0x1fff;
166− if (ep->num > 4 && max > 64)
167− return -ERANGE;
168−
169− spin_lock_irqsave (&dev->lock, flags);
170− _ep->maxpacket = max & 0x7ff;
171− ep->desc = desc;
172−
173− /* ep_reset() has already been called */
174− ep->stopped = 0;
175− ep->wedged = 0;
176− ep->out_overflow = 0;
177−
178− /* set speed-dependent max packet; may kick in high bandwidth */
179− set_idx_reg (dev->regs, REG_EP_MAXPKT (dev, ep->num), max);
180−
181− /* FIFO lines can't go to different packets. PIO is ok, so
182− * use it instead of troublesome (non-bulk) multi-packet DMA.
183− */
184− if (ep->dma && (max % 4) != 0 && use_dma_chaining) {
185− DEBUG (ep->dev, "%s, no dma for maxpacket %d\n",
186− ep->ep.name, ep->ep.maxpacket);
187− ep->dma = NULL;
188− }
189−
190− /* set type, direction, address; reset fifo counters */
191− writel ((1 << FIFO_FLUSH), &ep->regs->ep_stat);
192− tmp = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
193− if (tmp == USB_ENDPOINT_XFER_INT) {
194− /* erratum 0105 workaround prevents hs NYET */
195− if (dev->chiprev == 0100
196− && dev->gadget.speed == USB_SPEED_HIGH
197− && !(desc->bEndpointAddress & USB_DIR_IN))
198− writel ((1 << CLEAR_NAK_OUT_PACKETS_MODE),
199− &ep->regs->ep_rsp);
200− } else if (tmp == USB_ENDPOINT_XFER_BULK) {
201− /* catch some particularly blatant driver bugs */
202− if ((dev->gadget.speed == USB_SPEED_HIGH
203− && max != 512)
204− || (dev->gadget.speed == USB_SPEED_FULL
205− && max > 64)) {
206− spin_unlock_irqrestore (&dev->lock, flags);
207− return -ERANGE;
208− }
209− }
210− ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC) ? 1 : 0;
211− tmp <<= ENDPOINT_TYPE;
212− tmp |= desc->bEndpointAddress;
213− tmp |= (4 << ENDPOINT_BYTE_COUNT); /* default full fifo lines */
214− tmp |= 1 << ENDPOINT_ENABLE;
215− wmb ();
216−
217− /* for OUT transfers, block the rx fifo until a read is posted */
218− ep->is_in = (tmp & USB_DIR_IN) != 0;
219− if (!ep->is_in)
220− writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
221− else if (dev->pdev->device != 0x2280) {
222− /* Added for 2282, Don't use nak packets on an in endpoint,
223− * this was ignored on 2280
224− */
225− writel ((1 << CLEAR_NAK_OUT_PACKETS)
226− | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
227− }
228−
229− writel (tmp, &ep->regs->ep_cfg);
230−
231− /* enable irqs */
232− if (!ep->dma) { /* pio, per-packet */
233− tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0);
234− writel (tmp, &dev->regs->pciirqenb0);
235−
236− tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE)
237− | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE);
238− if (dev->pdev->device == 0x2280)
239− tmp |= readl (&ep->regs->ep_irqenb);
240− writel (tmp, &ep->regs->ep_irqenb);
241− } else { /* dma, per-request */
242− tmp = (1 << (8 + ep->num)); /* completion */
243− tmp |= readl (&dev->regs->pciirqenb1);
244− writel (tmp, &dev->regs->pciirqenb1);
245−
246− /* for short OUT transfers, dma completions can't
247− * advance the queue; do it pio-style, by hand.
248− * NOTE erratum 0112 workaround #2
249− */
250− if ((desc->bEndpointAddress & USB_DIR_IN) == 0) {
251− tmp = (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE);
252− writel (tmp, &ep->regs->ep_irqenb);
253−
254− tmp = (1 << ep->num) | readl (&dev->regs->pciirqenb0);
255− writel (tmp, &dev->regs->pciirqenb0);
256− }
257− }
258−
259− tmp = desc->bEndpointAddress;
260− DEBUG (dev, "enabled %s (ep%d%s-%s) %s max %04x\n",
261− _ep->name, tmp & 0x0f, DIR_STRING (tmp),
262− type_string (desc->bmAttributes),
263− ep->dma ? "dma" : "pio", max);
264−
265− /* pci writes may still be posted */
266− spin_unlock_irqrestore (&dev->lock, flags);
267− return 0;
268−}
269−
270−static int handshake (u32 __iomem *ptr, u32 mask, u32 done, int usec)
271−{
272− u32 result;
273−
274− do {
275− result = readl (ptr);
276− if (result == ~(u32)0) /* "device unplugged" */
277− return -ENODEV;
278− result &= mask;
279− if (result == done)
280− return 0;
281− udelay (1);
282− usec--;
283− } while (usec > 0);
284− return -ETIMEDOUT;
285−}
286−
287−static const struct usb_ep_ops net2280_ep_ops;
288−
289−static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)
290−{
291− u32 tmp;
292−
293− ep->desc = NULL;
294− INIT_LIST_HEAD (&ep->queue);
295−
296− usb_ep_set_maxpacket_limit(&ep->ep, ~0);
297− ep->ep.ops = &net2280_ep_ops;
298−
299− /* disable the dma, irqs, endpoint... */
300− if (ep->dma) {
301− writel (0, &ep->dma->dmactl);
302− writel ( (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT)
303− | (1 << DMA_TRANSACTION_DONE_INTERRUPT)
304− | (1 << DMA_ABORT)
305− , &ep->dma->dmastat);
306−
307− tmp = readl (&regs->pciirqenb0);
308− tmp &= ~(1 << ep->num);
309− writel (tmp, &regs->pciirqenb0);
310− } else {
311− tmp = readl (&regs->pciirqenb1);
312− tmp &= ~(1 << (8 + ep->num)); /* completion */
313− writel (tmp, &regs->pciirqenb1);
314− }
315− writel (0, &ep->regs->ep_irqenb);
316−
317− /* init to our chosen defaults, notably so that we NAK OUT
318− * packets until the driver queues a read (+note erratum 0112)
319− */
320− if (!ep->is_in || ep->dev->pdev->device == 0x2280) {
321− tmp = (1 << SET_NAK_OUT_PACKETS_MODE)
322− | (1 << SET_NAK_OUT_PACKETS)
323− | (1 << CLEAR_EP_HIDE_STATUS_PHASE)
324− | (1 << CLEAR_INTERRUPT_MODE);
325− } else {
326− /* added for 2282 */
327− tmp = (1 << CLEAR_NAK_OUT_PACKETS_MODE)
328− | (1 << CLEAR_NAK_OUT_PACKETS)
329− | (1 << CLEAR_EP_HIDE_STATUS_PHASE)
330− | (1 << CLEAR_INTERRUPT_MODE);
331− }
332−
333− if (ep->num != 0) {
334− tmp |= (1 << CLEAR_ENDPOINT_TOGGLE)
335− | (1 << CLEAR_ENDPOINT_HALT);
336− }
337− writel (tmp, &ep->regs->ep_rsp);
338−
339− /* scrub most status bits, and flush any fifo state */
340− if (ep->dev->pdev->device == 0x2280)
341− tmp = (1 << FIFO_OVERFLOW)
342− | (1 << FIFO_UNDERFLOW);
343− else
344− tmp = 0;
345−
346− writel (tmp | (1 << TIMEOUT)
347− | (1 << USB_STALL_SENT)
348− | (1 << USB_IN_NAK_SENT)
349− | (1 << USB_IN_ACK_RCVD)
350− | (1 << USB_OUT_PING_NAK_SENT)
351− | (1 << USB_OUT_ACK_SENT)
352− | (1 << FIFO_FLUSH)
353− | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT)
354− | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)
355− | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
356− | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
357− | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
358− | (1 << DATA_IN_TOKEN_INTERRUPT)
359− , &ep->regs->ep_stat);
360−
361− /* fifo size is handled separately */
362−}
363−
364−static void nuke (struct net2280_ep *);
365−
366−static int net2280_disable (struct usb_ep *_ep)
367−{
368− struct net2280_ep *ep;
369− unsigned long flags;
370−
371− ep = container_of (_ep, struct net2280_ep, ep);
372− if (!_ep || !ep->desc || _ep->name == ep0name)
373− return -EINVAL;
374−
375− spin_lock_irqsave (&ep->dev->lock, flags);
376− nuke (ep);
377− ep_reset (ep->dev->regs, ep);
378−
379− VDEBUG (ep->dev, "disabled %s %s\n",
380− ep->dma ? "dma" : "pio", _ep->name);
381−
382− /* synch memory views with the device */
383− (void) readl (&ep->regs->ep_cfg);
384−
385− if (use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4)
386− ep->dma = &ep->dev->dma [ep->num - 1];
387−
388− spin_unlock_irqrestore (&ep->dev->lock, flags);
389− return 0;
390−}
391−
392−/*-------------------------------------------------------------------------*/
393−
394−static struct usb_request *
395−net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
396−{
397− struct net2280_ep *ep;
398− struct net2280_request *req;
399−
400− if (!_ep)
401− return NULL;
402− ep = container_of (_ep, struct net2280_ep, ep);
403−
404− req = kzalloc(sizeof(*req), gfp_flags);
405− if (!req)
406− return NULL;
407−
408− INIT_LIST_HEAD (&req->queue);
409−
410− /* this dma descriptor may be swapped with the previous dummy */
411− if (ep->dma) {
412− struct net2280_dma *td;
413−
414− td = pci_pool_alloc (ep->dev->requests, gfp_flags,
415− &req->td_dma);
416− if (!td) {
417− kfree (req);
418− return NULL;
419− }
420− td->dmacount = 0; /* not VALID */
421− td->dmadesc = td->dmaaddr;
422− req->td = td;
423− }
424− return &req->req;
425−}
426−
427−static void
428−net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
429−{
430− struct net2280_ep *ep;
431− struct net2280_request *req;
432−
433− ep = container_of (_ep, struct net2280_ep, ep);
434− if (!_ep || !_req)
435− return;
436−
437− req = container_of (_req, struct net2280_request, req);
438− WARN_ON (!list_empty (&req->queue));
439− if (req->td)
440− pci_pool_free (ep->dev->requests, req->td, req->td_dma);
441− kfree (req);
442−}
443−
444−/*-------------------------------------------------------------------------*/
445−
446−/* load a packet into the fifo we use for usb IN transfers.
447− * works for all endpoints.
448− *
449− * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
450− * at a time, but this code is simpler because it knows it only writes
451− * one packet. ep-a..ep-d should use dma instead.
452− */
453−static void
454−write_fifo (struct net2280_ep *ep, struct usb_request *req)
455−{
456− struct net2280_ep_regs __iomem *regs = ep->regs;
457− u8 *buf;
458− u32 tmp;
459− unsigned count, total;
460−
461− /* INVARIANT: fifo is currently empty. (testable) */
462−
463− if (req) {
464− buf = req->buf + req->actual;
465− prefetch (buf);
466− total = req->length - req->actual;
467− } else {
468− total = 0;
469− buf = NULL;
470− }
471−
472− /* write just one packet at a time */
473− count = ep->ep.maxpacket;
474− if (count > total) /* min() cannot be used on a bitfield */
475− count = total;
476−
477− VDEBUG (ep->dev, "write %s fifo (IN) %d bytes%s req %p\n",
478− ep->ep.name, count,
479− (count != ep->ep.maxpacket) ? " (short)" : "",
480− req);
481− while (count >= 4) {
482− /* NOTE be careful if you try to align these. fifo lines
483− * should normally be full (4 bytes) and successive partial
484− * lines are ok only in certain cases.
485− */
486− tmp = get_unaligned ((u32 *)buf);
487− cpu_to_le32s (&tmp);
488− writel (tmp, &regs->ep_data);
489− buf += 4;
490− count -= 4;
491− }
492−
493− /* last fifo entry is "short" unless we wrote a full packet.
494− * also explicitly validate last word in (periodic) transfers
495− * when maxpacket is not a multiple of 4 bytes.
496− */
497− if (count || total < ep->ep.maxpacket) {
498− tmp = count ? get_unaligned ((u32 *)buf) : count;
499− cpu_to_le32s (&tmp);
500− set_fifo_bytecount (ep, count & 0x03);
501− writel (tmp, &regs->ep_data);
502− }
503−
504− /* pci writes may still be posted */
505−}
506−
507−/* work around erratum 0106: PCI and USB race over the OUT fifo.
508− * caller guarantees chiprev 0100, out endpoint is NAKing, and
509− * there's no real data in the fifo.
510− *
511− * NOTE: also used in cases where that erratum doesn't apply:
512− * where the host wrote "too much" data to us.
513− */
514−static void out_flush (struct net2280_ep *ep)
515−{
516− u32 __iomem *statp;
517− u32 tmp;
518−
519− ASSERT_OUT_NAKING (ep);
520−
521− statp = &ep->regs->ep_stat;
522− writel ( (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
523− | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
524− , statp);
525− writel ((1 << FIFO_FLUSH), statp);
526− mb ();
527− tmp = readl (statp);
528− if (tmp & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
529− /* high speed did bulk NYET; fifo isn't filling */
530− && ep->dev->gadget.speed == USB_SPEED_FULL) {
531− unsigned usec;
532−
533− usec = 50; /* 64 byte bulk/interrupt */
534− handshake (statp, (1 << USB_OUT_PING_NAK_SENT),
535− (1 << USB_OUT_PING_NAK_SENT), usec);
536− /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
537− }
538−}
539−
540−/* unload packet(s) from the fifo we use for usb OUT transfers.
541− * returns true iff the request completed, because of short packet
542− * or the request buffer having filled with full packets.
543− *
544− * for ep-a..ep-d this will read multiple packets out when they
545− * have been accepted.
546− */
547−static int
548−read_fifo (struct net2280_ep *ep, struct net2280_request *req)
549−{
550− struct net2280_ep_regs __iomem *regs = ep->regs;
551− u8 *buf = req->req.buf + req->req.actual;
552− unsigned count, tmp, is_short;
553− unsigned cleanup = 0, prevent = 0;
554−
555− /* erratum 0106 ... packets coming in during fifo reads might
556− * be incompletely rejected. not all cases have workarounds.
557− */
558− if (ep->dev->chiprev == 0x0100
559− && ep->dev->gadget.speed == USB_SPEED_FULL) {
560− udelay (1);
561− tmp = readl (&ep->regs->ep_stat);
562− if ((tmp & (1 << NAK_OUT_PACKETS)))
563− cleanup = 1;
564− else if ((tmp & (1 << FIFO_FULL))) {
565− start_out_naking (ep);
566− prevent = 1;
567− }
568− /* else: hope we don't see the problem */
569− }
570−
571− /* never overflow the rx buffer. the fifo reads packets until
572− * it sees a short one; we might not be ready for them all.
573− */
574− prefetchw (buf);
575− count = readl (&regs->ep_avail);
576− if (unlikely (count == 0)) {
577− udelay (1);
578− tmp = readl (&ep->regs->ep_stat);
579− count = readl (&regs->ep_avail);
580− /* handled that data already? */
581− if (count == 0 && (tmp & (1 << NAK_OUT_PACKETS)) == 0)
582− return 0;
583− }
584−
585− tmp = req->req.length - req->req.actual;
586− if (count > tmp) {
587− /* as with DMA, data overflow gets flushed */
588− if ((tmp % ep->ep.maxpacket) != 0) {
589− ERROR (ep->dev,
590− "%s out fifo %d bytes, expected %d\n",
591− ep->ep.name, count, tmp);
592− req->req.status = -EOVERFLOW;
593− cleanup = 1;
594− /* NAK_OUT_PACKETS will be set, so flushing is safe;
595− * the next read will start with the next packet
596− */
597− } /* else it's a ZLP, no worries */
598− count = tmp;
599− }
600− req->req.actual += count;
601−
602− is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0);
603−
604− VDEBUG (ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
605− ep->ep.name, count, is_short ? " (short)" : "",
606− cleanup ? " flush" : "", prevent ? " nak" : "",
607− req, req->req.actual, req->req.length);
608−
609− while (count >= 4) {
610− tmp = readl (&regs->ep_data);
611− cpu_to_le32s (&tmp);
612− put_unaligned (tmp, (u32 *)buf);
613− buf += 4;
614− count -= 4;
615− }
616− if (count) {
617− tmp = readl (&regs->ep_data);
618− /* LE conversion is implicit here: */
619− do {
620− *buf++ = (u8) tmp;
621− tmp >>= 8;
622− } while (--count);
623− }
624− if (cleanup)
625− out_flush (ep);
626− if (prevent) {
627− writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
628− (void) readl (&ep->regs->ep_rsp);
629− }
630−
631− return is_short || ((req->req.actual == req->req.length)
632− && !req->req.zero);
633−}
634−
635−/* fill out dma descriptor to match a given request */
636−static void
637−fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid)
638−{
639− struct net2280_dma *td = req->td;
640− u32 dmacount = req->req.length;
641−
642− /* don't let DMA continue after a short OUT packet,
643− * so overruns can't affect the next transfer.
644− * in case of overruns on max-size packets, we can't
645− * stop the fifo from filling but we can flush it.
646− */
647− if (ep->is_in)
648− dmacount |= (1 << DMA_DIRECTION);
649− if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0)
650− || ep->dev->pdev->device != 0x2280)
651− dmacount |= (1 << END_OF_CHAIN);
652−
653− req->valid = valid;
654− if (valid)
655− dmacount |= (1 << VALID_BIT);
656− if (likely(!req->req.no_interrupt || !use_dma_chaining))
657− dmacount |= (1 << DMA_DONE_INTERRUPT_ENABLE);
658−
659− /* td->dmadesc = previously set by caller */
660− td->dmaaddr = cpu_to_le32 (req->req.dma);
661−
662− /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
663− wmb ();
664− td->dmacount = cpu_to_le32(dmacount);
665−}
666−
667−static const u32 dmactl_default =
668− (1 << DMA_SCATTER_GATHER_DONE_INTERRUPT)
669− | (1 << DMA_CLEAR_COUNT_ENABLE)
670− /* erratum 0116 workaround part 1 (use POLLING) */
671− | (POLL_100_USEC << DESCRIPTOR_POLLING_RATE)
672− | (1 << DMA_VALID_BIT_POLLING_ENABLE)
673− | (1 << DMA_VALID_BIT_ENABLE)
674− | (1 << DMA_SCATTER_GATHER_ENABLE)
675− /* erratum 0116 workaround part 2 (no AUTOSTART) */
676− | (1 << DMA_ENABLE);
677−
678−static inline void spin_stop_dma (struct net2280_dma_regs __iomem *dma)
679−{
680− handshake (&dma->dmactl, (1 << DMA_ENABLE), 0, 50);
681−}
682−
683−static inline void stop_dma (struct net2280_dma_regs __iomem *dma)
684−{
685− writel (readl (&dma->dmactl) & ~(1 << DMA_ENABLE), &dma->dmactl);
686− spin_stop_dma (dma);
687−}
688−
689−static void start_queue (struct net2280_ep *ep, u32 dmactl, u32 td_dma)
690−{
691− struct net2280_dma_regs __iomem *dma = ep->dma;
692− unsigned int tmp = (1 << VALID_BIT) | (ep->is_in << DMA_DIRECTION);
693−
694− if (ep->dev->pdev->device != 0x2280)
695− tmp |= (1 << END_OF_CHAIN);
696−
697− writel (tmp, &dma->dmacount);
698− writel (readl (&dma->dmastat), &dma->dmastat);
699−
700− writel (td_dma, &dma->dmadesc);
701− writel (dmactl, &dma->dmactl);
702−
703− /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
704− (void) readl (&ep->dev->pci->pcimstctl);
705−
706− writel ((1 << DMA_START), &dma->dmastat);
707−
708− if (!ep->is_in)
709− stop_out_naking (ep);
710−}
711−
712−static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
713−{
714− u32 tmp;
715− struct net2280_dma_regs __iomem *dma = ep->dma;
716−
717− /* FIXME can't use DMA for ZLPs */
718−
719− /* on this path we "know" there's no dma active (yet) */
720− WARN_ON (readl (&dma->dmactl) & (1 << DMA_ENABLE));
721− writel (0, &ep->dma->dmactl);
722−
723− /* previous OUT packet might have been short */
724− if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat))
725− & (1 << NAK_OUT_PACKETS)) != 0) {
726− writel ((1 << SHORT_PACKET_TRANSFERRED_INTERRUPT),
727− &ep->regs->ep_stat);
728−
729− tmp = readl (&ep->regs->ep_avail);
730− if (tmp) {
731− writel (readl (&dma->dmastat), &dma->dmastat);
732−
733− /* transfer all/some fifo data */
734− writel (req->req.dma, &dma->dmaaddr);
735− tmp = min (tmp, req->req.length);
736−
737− /* dma irq, faking scatterlist status */
738− req->td->dmacount = cpu_to_le32 (req->req.length - tmp);
739− writel ((1 << DMA_DONE_INTERRUPT_ENABLE)
740− | tmp, &dma->dmacount);
741− req->td->dmadesc = 0;
742− req->valid = 1;
743−
744− writel ((1 << DMA_ENABLE), &dma->dmactl);
745− writel ((1 << DMA_START), &dma->dmastat);
746− return;
747− }
748− }
749−
750− tmp = dmactl_default;
751−
752− /* force packet boundaries between dma requests, but prevent the
753− * controller from automagically writing a last "short" packet
754− * (zero length) unless the driver explicitly said to do that.
755− */
756− if (ep->is_in) {
757− if (likely ((req->req.length % ep->ep.maxpacket) != 0
758− || req->req.zero)) {
759− tmp |= (1 << DMA_FIFO_VALIDATE);
760− ep->in_fifo_validate = 1;
761− } else
762− ep->in_fifo_validate = 0;
763− }
764−
765− /* init req->td, pointing to the current dummy */
766− req->td->dmadesc = cpu_to_le32 (ep->td_dma);
767− fill_dma_desc (ep, req, 1);
768−
769− if (!use_dma_chaining)
770− req->td->dmacount |= cpu_to_le32 (1 << END_OF_CHAIN);
771−
772− start_queue (ep, tmp, req->td_dma);
773−}
774−
775−static inline void
776−queue_dma (struct net2280_ep *ep, struct net2280_request *req, int valid)
777−{
778− struct net2280_dma *end;
779− dma_addr_t tmp;
780−
781− /* swap new dummy for old, link; fill and maybe activate */
782− end = ep->dummy;
783− ep->dummy = req->td;
784− req->td = end;
785−
786− tmp = ep->td_dma;
787− ep->td_dma = req->td_dma;
788− req->td_dma = tmp;
789−
790− end->dmadesc = cpu_to_le32 (ep->td_dma);
791−
792− fill_dma_desc (ep, req, valid);
793−}
794−
795−static void
796−done (struct net2280_ep *ep, struct net2280_request *req, int status)
797−{
798− struct net2280 *dev;
799− unsigned stopped = ep->stopped;
800−
801− list_del_init (&req->queue);
802−
803− if (req->req.status == -EINPROGRESS)
804− req->req.status = status;
805− else
806− status = req->req.status;
807−
808− dev = ep->dev;
809− if (ep->dma)
810− usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in);
811−
812− if (status && status != -ESHUTDOWN)
813− VDEBUG (dev, "complete %s req %p stat %d len %u/%u\n",
814− ep->ep.name, &req->req, status,
815− req->req.actual, req->req.length);
816−
817− /* don't modify queue heads during completion callback */
818− ep->stopped = 1;
819− spin_unlock (&dev->lock);
820− req->req.complete (&ep->ep, &req->req);
821− spin_lock (&dev->lock);
822− ep->stopped = stopped;
823−}
824−
825−/*-------------------------------------------------------------------------*/
826−
827−static int
828−net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
829−{
830− struct net2280_request *req;
831− struct net2280_ep *ep;
832− struct net2280 *dev;
833− unsigned long flags;
834−
835− /* we always require a cpu-view buffer, so that we can
836− * always use pio (as fallback or whatever).
837− */
838− req = container_of (_req, struct net2280_request, req);
839− if (!_req || !_req->complete || !_req->buf
840− || !list_empty (&req->queue))
841− return -EINVAL;
842− if (_req->length > (~0 & DMA_BYTE_COUNT_MASK))
843− return -EDOM;
844− ep = container_of (_ep, struct net2280_ep, ep);
845− if (!_ep || (!ep->desc && ep->num != 0))
846− return -EINVAL;
847− dev = ep->dev;
848− if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
849− return -ESHUTDOWN;
850−
851− /* FIXME implement PIO fallback for ZLPs with DMA */
852− if (ep->dma && _req->length == 0)
853− return -EOPNOTSUPP;
854−
855− /* set up dma mapping in case the caller didn't */
856− if (ep->dma) {
857− int ret;
858−
859− ret = usb_gadget_map_request(&dev->gadget, _req,
860− ep->is_in);
861− if (ret)
862− return ret;
863− }
864−
865−#if 0
866− VDEBUG (dev, "%s queue req %p, len %d buf %p\n",
867− _ep->name, _req, _req->length, _req->buf);
868−#endif
869−
870− spin_lock_irqsave (&dev->lock, flags);
871−
872− _req->status = -EINPROGRESS;
873− _req->actual = 0;
874−
875− /* kickstart this i/o queue? */
876− if (list_empty (&ep->queue) && !ep->stopped) {
877− /* use DMA if the endpoint supports it, else pio */
878− if (ep->dma)
879− start_dma (ep, req);
880− else {
881− /* maybe there's no control data, just status ack */
882− if (ep->num == 0 && _req->length == 0) {
883− allow_status (ep);
884− done (ep, req, 0);
885− VDEBUG (dev, "%s status ack\n", ep->ep.name);
886− goto done;
887− }
888−
889− /* PIO ... stuff the fifo, or unblock it. */
890− if (ep->is_in)
891− write_fifo (ep, _req);
892− else if (list_empty (&ep->queue)) {
893− u32 s;
894−
895− /* OUT FIFO might have packet(s) buffered */
896− s = readl (&ep->regs->ep_stat);
897− if ((s & (1 << FIFO_EMPTY)) == 0) {
898− /* note: _req->short_not_ok is
899− * ignored here since PIO _always_
900− * stops queue advance here, and
901− * _req->status doesn't change for
902− * short reads (only _req->actual)
903− */
904− if (read_fifo (ep, req)) {
905− done (ep, req, 0);
906− if (ep->num == 0)
907− allow_status (ep);
908− /* don't queue it */
909− req = NULL;
910− } else
911− s = readl (&ep->regs->ep_stat);
912− }
913−
914− /* don't NAK, let the fifo fill */
915− if (req && (s & (1 << NAK_OUT_PACKETS)))
916− writel ((1 << CLEAR_NAK_OUT_PACKETS),
917− &ep->regs->ep_rsp);
918− }
919− }
920−
921− } else if (ep->dma) {
922− int valid = 1;
923−
924− if (ep->is_in) {
925− int expect;
926−
927− /* preventing magic zlps is per-engine state, not
928− * per-transfer; irq logic must recover hiccups.
929− */
930− expect = likely (req->req.zero
931− || (req->req.length % ep->ep.maxpacket) != 0);
932− if (expect != ep->in_fifo_validate)
933− valid = 0;
934− }
935− queue_dma (ep, req, valid);
936−
937− } /* else the irq handler advances the queue. */
938−
939− ep->responded = 1;
940− if (req)
941− list_add_tail (&req->queue, &ep->queue);
942−done:
943− spin_unlock_irqrestore (&dev->lock, flags);
944−
945− /* pci writes may still be posted */
946− return 0;
947−}
948−
949−static inline void
950−dma_done (
951− struct net2280_ep *ep,
952− struct net2280_request *req,
953− u32 dmacount,
954− int status
955−)
956−{
957− req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount);
958− done (ep, req, status);
959−}
960−
961−static void restart_dma (struct net2280_ep *ep);
962−
963−static void scan_dma_completions (struct net2280_ep *ep)
964−{
965− /* only look at descriptors that were "naturally" retired,
966− * so fifo and list head state won't matter
967− */
968− while (!list_empty (&ep->queue)) {
969− struct net2280_request *req;
970− u32 tmp;
971−
972− req = list_entry (ep->queue.next,
973− struct net2280_request, queue);
974− if (!req->valid)
975− break;
976− rmb ();
977− tmp = le32_to_cpup (&req->td->dmacount);
978− if ((tmp & (1 << VALID_BIT)) != 0)
979− break;
980−
981− /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
982− * cases where DMA must be aborted; this code handles
983− * all non-abort DMA completions.
984− */
985− if (unlikely (req->td->dmadesc == 0)) {
986− /* paranoia */
987− tmp = readl (&ep->dma->dmacount);
988− if (tmp & DMA_BYTE_COUNT_MASK)
989− break;
990− /* single transfer mode */
991− dma_done (ep, req, tmp, 0);
992− break;
993− } else if (!ep->is_in
994− && (req->req.length % ep->ep.maxpacket) != 0) {
995− tmp = readl (&ep->regs->ep_stat);
996−
997− /* AVOID TROUBLE HERE by not issuing short reads from
998− * your gadget driver. That helps avoids errata 0121,
999− * 0122, and 0124; not all cases trigger the warning.
1000− */
1001− if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
1002− WARNING (ep->dev, "%s lost packet sync!\n",
1003− ep->ep.name);
1004− req->req.status = -EOVERFLOW;
1005− } else if ((tmp = readl (&ep->regs->ep_avail)) != 0) {
1006− /* fifo gets flushed later */
1007− ep->out_overflow = 1;
1008− DEBUG (ep->dev, "%s dma, discard %d len %d\n",
1009− ep->ep.name, tmp,
1010− req->req.length);
1011− req->req.status = -EOVERFLOW;
1012− }
1013− }
1014− dma_done (ep, req, tmp, 0);
1015− }
1016−}
1017−
1018−static void restart_dma (struct net2280_ep *ep)
1019−{
1020− struct net2280_request *req;
1021− u32 dmactl = dmactl_default;
1022−
1023− if (ep->stopped)
1024− return;
1025− req = list_entry (ep->queue.next, struct net2280_request, queue);
1026−
1027− if (!use_dma_chaining) {
1028− start_dma (ep, req);
1029− return;
1030− }
1031−
1032− /* the 2280 will be processing the queue unless queue hiccups after
1033− * the previous transfer:
1034− * IN: wanted automagic zlp, head doesn't (or vice versa)
1035− * DMA_FIFO_VALIDATE doesn't init from dma descriptors.
1036− * OUT: was "usb-short", we must restart.
1037− */
1038− if (ep->is_in && !req->valid) {
1039− struct net2280_request *entry, *prev = NULL;
1040− int reqmode, done = 0;
1041−
1042− DEBUG (ep->dev, "%s dma hiccup td %p\n", ep->ep.name, req->td);
1043− ep->in_fifo_validate = likely (req->req.zero
1044− || (req->req.length % ep->ep.maxpacket) != 0);
1045− if (ep->in_fifo_validate)
1046− dmactl |= (1 << DMA_FIFO_VALIDATE);
1047− list_for_each_entry (entry, &ep->queue, queue) {
1048− __le32 dmacount;
1049−
1050− if (entry == req)
1051− continue;
1052− dmacount = entry->td->dmacount;
1053− if (!done) {
1054− reqmode = likely (entry->req.zero
1055− || (entry->req.length
1056− % ep->ep.maxpacket) != 0);
1057− if (reqmode == ep->in_fifo_validate) {
1058− entry->valid = 1;
1059− dmacount |= valid_bit;
1060− entry->td->dmacount = dmacount;
1061− prev = entry;
1062− continue;
1063− } else {
1064− /* force a hiccup */
1065− prev->td->dmacount |= dma_done_ie;
1066− done = 1;
1067− }
1068− }
1069−
1070− /* walk the rest of the queue so unlinks behave */
1071− entry->valid = 0;
1072− dmacount &= ~valid_bit;
1073− entry->td->dmacount = dmacount;
1074− prev = entry;
1075− }
1076− }
1077−
1078− writel (0, &ep->dma->dmactl);
1079− start_queue (ep, dmactl, req->td_dma);
1080−}
1081−
1082−static void abort_dma (struct net2280_ep *ep)
1083−{
1084− /* abort the current transfer */
1085− if (likely (!list_empty (&ep->queue))) {
1086− /* FIXME work around errata 0121, 0122, 0124 */
1087− writel ((1 << DMA_ABORT), &ep->dma->dmastat);
1088− spin_stop_dma (ep->dma);
1089− } else
1090− stop_dma (ep->dma);
1091− scan_dma_completions (ep);
1092−}
1093−
1094−/* dequeue ALL requests */
1095−static void nuke (struct net2280_ep *ep)
1096−{
1097− struct net2280_request *req;
1098−
1099− /* called with spinlock held */
1100− ep->stopped = 1;
1101− if (ep->dma)
1102− abort_dma (ep);
1103− while (!list_empty (&ep->queue)) {
1104− req = list_entry (ep->queue.next,
1105− struct net2280_request,
1106− queue);
1107− done (ep, req, -ESHUTDOWN);
1108− }
1109−}
1110−
1111−/* dequeue JUST ONE request */
1112−static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req)
1113−{
1114− struct net2280_ep *ep;
1115− struct net2280_request *req;
1116− unsigned long flags;
1117− u32 dmactl;
1118− int stopped;
1119−
1120− ep = container_of (_ep, struct net2280_ep, ep);
1121− if (!_ep || (!ep->desc && ep->num != 0) || !_req)
1122− return -EINVAL;
1123−
1124− spin_lock_irqsave (&ep->dev->lock, flags);
1125− stopped = ep->stopped;
1126−
1127− /* quiesce dma while we patch the queue */
1128− dmactl = 0;
1129− ep->stopped = 1;
1130− if (ep->dma) {
1131− dmactl = readl (&ep->dma->dmactl);
1132− /* WARNING erratum 0127 may kick in ... */
1133− stop_dma (ep->dma);
1134− scan_dma_completions (ep);
1135− }
1136−
1137− /* make sure it's still queued on this endpoint */
1138− list_for_each_entry (req, &ep->queue, queue) {
1139− if (&req->req == _req)
1140− break;
1141− }
1142− if (&req->req != _req) {
1143− spin_unlock_irqrestore (&ep->dev->lock, flags);
1144− return -EINVAL;
1145− }
1146−
1147− /* queue head may be partially complete. */
1148− if (ep->queue.next == &req->queue) {
1149− if (ep->dma) {
1150− DEBUG (ep->dev, "unlink (%s) dma\n", _ep->name);
1151− _req->status = -ECONNRESET;
1152− abort_dma (ep);
1153− if (likely (ep->queue.next == &req->queue)) {
1154− // NOTE: misreports single-transfer mode
1155− req->td->dmacount = 0; /* invalidate */
1156− dma_done (ep, req,
1157− readl (&ep->dma->dmacount),
1158− -ECONNRESET);
1159− }
1160− } else {
1161− DEBUG (ep->dev, "unlink (%s) pio\n", _ep->name);
1162− done (ep, req, -ECONNRESET);
1163− }
1164− req = NULL;
1165−
1166− /* patch up hardware chaining data */
1167− } else if (ep->dma && use_dma_chaining) {
1168− if (req->queue.prev == ep->queue.next) {
1169− writel (le32_to_cpu (req->td->dmadesc),
1170− &ep->dma->dmadesc);
1171− if (req->td->dmacount & dma_done_ie)
1172− writel (readl (&ep->dma->dmacount)
1173− | le32_to_cpu(dma_done_ie),
1174− &ep->dma->dmacount);
1175− } else {
1176− struct net2280_request *prev;
1177−
1178− prev = list_entry (req->queue.prev,
1179− struct net2280_request, queue);
1180− prev->td->dmadesc = req->td->dmadesc;
1181− if (req->td->dmacount & dma_done_ie)
1182− prev->td->dmacount |= dma_done_ie;
1183− }
1184− }
1185−
1186− if (req)
1187− done (ep, req, -ECONNRESET);
1188− ep->stopped = stopped;
1189−
1190− if (ep->dma) {
1191− /* turn off dma on inactive queues */
1192− if (list_empty (&ep->queue))
1193− stop_dma (ep->dma);
1194− else if (!ep->stopped) {
1195− /* resume current request, or start new one */
1196− if (req)
1197− writel (dmactl, &ep->dma->dmactl);
1198− else
1199− start_dma (ep, list_entry (ep->queue.next,
1200− struct net2280_request, queue));
1201− }
1202− }
1203−
1204− spin_unlock_irqrestore (&ep->dev->lock, flags);
1205− return 0;
1206−}
1207−
1208−/*-------------------------------------------------------------------------*/
1209−
1210−static int net2280_fifo_status (struct usb_ep *_ep);
1211−
1212−static int
1213−net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
1214−{
1215− struct net2280_ep *ep;
1216− unsigned long flags;
1217− int retval = 0;
1218−
1219− ep = container_of (_ep, struct net2280_ep, ep);
1220− if (!_ep || (!ep->desc && ep->num != 0))
1221− return -EINVAL;
1222− if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1223− return -ESHUTDOWN;
1224− if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03)
1225− == USB_ENDPOINT_XFER_ISOC)
1226− return -EINVAL;
1227−
1228− spin_lock_irqsave (&ep->dev->lock, flags);
1229− if (!list_empty (&ep->queue))
1230− retval = -EAGAIN;
1231− else if (ep->is_in && value && net2280_fifo_status (_ep) != 0)
1232− retval = -EAGAIN;
1233− else {
1234− VDEBUG (ep->dev, "%s %s %s\n", _ep->name,
1235− value ? "set" : "clear",
1236− wedged ? "wedge" : "halt");
1237− /* set/clear, then synch memory views with the device */
1238− if (value) {
1239− if (ep->num == 0)
1240− ep->dev->protocol_stall = 1;
1241− else
1242− set_halt (ep);
1243− if (wedged)
1244− ep->wedged = 1;
1245− } else {
1246− clear_halt (ep);
1247− ep->wedged = 0;
1248− }
1249− (void) readl (&ep->regs->ep_rsp);
1250− }
1251− spin_unlock_irqrestore (&ep->dev->lock, flags);
1252−
1253− return retval;
1254−}
1255−
1256−static int
1257−net2280_set_halt(struct usb_ep *_ep, int value)
1258−{
1259− return net2280_set_halt_and_wedge(_ep, value, 0);
1260−}
1261−
1262−static int
1263−net2280_set_wedge(struct usb_ep *_ep)
1264−{
1265− if (!_ep || _ep->name == ep0name)
1266− return -EINVAL;
1267− return net2280_set_halt_and_wedge(_ep, 1, 1);
1268−}
1269−
1270−static int
1271−net2280_fifo_status (struct usb_ep *_ep)
1272−{
1273− struct net2280_ep *ep;
1274− u32 avail;
1275−
1276− ep = container_of (_ep, struct net2280_ep, ep);
1277− if (!_ep || (!ep->desc && ep->num != 0))
1278− return -ENODEV;
1279− if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1280− return -ESHUTDOWN;
1281−
1282− avail = readl (&ep->regs->ep_avail) & ((1 << 12) - 1);
1283− if (avail > ep->fifo_size)
1284− return -EOVERFLOW;
1285− if (ep->is_in)
1286− avail = ep->fifo_size - avail;
1287− return avail;
1288−}
1289−
1290−static void
1291−net2280_fifo_flush (struct usb_ep *_ep)
1292−{
1293− struct net2280_ep *ep;
1294−
1295− ep = container_of (_ep, struct net2280_ep, ep);
1296− if (!_ep || (!ep->desc && ep->num != 0))
1297− return;
1298− if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1299− return;
1300−
1301− writel ((1 << FIFO_FLUSH), &ep->regs->ep_stat);
1302− (void) readl (&ep->regs->ep_rsp);
1303−}
1304−
1305−static const struct usb_ep_ops net2280_ep_ops = {
1306− .enable = net2280_enable,
1307− .disable = net2280_disable,
1308−
1309− .alloc_request = net2280_alloc_request,
1310− .free_request = net2280_free_request,
1311−
1312− .queue = net2280_queue,
1313− .dequeue = net2280_dequeue,
1314−
1315− .set_halt = net2280_set_halt,
1316− .set_wedge = net2280_set_wedge,
1317− .fifo_status = net2280_fifo_status,
1318− .fifo_flush = net2280_fifo_flush,
1319−};
1320−
1321−/*-------------------------------------------------------------------------*/
1322−
1323−static int net2280_get_frame (struct usb_gadget *_gadget)
1324−{
1325− struct net2280 *dev;
1326− unsigned long flags;
1327− u16 retval;
1328−
1329− if (!_gadget)
1330− return -ENODEV;
1331− dev = container_of (_gadget, struct net2280, gadget);
1332− spin_lock_irqsave (&dev->lock, flags);
1333− retval = get_idx_reg (dev->regs, REG_FRAME) & 0x03ff;
1334− spin_unlock_irqrestore (&dev->lock, flags);
1335− return retval;
1336−}
1337−
1338−static int net2280_wakeup (struct usb_gadget *_gadget)
1339−{
1340− struct net2280 *dev;
1341− u32 tmp;
1342− unsigned long flags;
1343−
1344− if (!_gadget)
1345− return 0;
1346− dev = container_of (_gadget, struct net2280, gadget);
1347−
1348− spin_lock_irqsave (&dev->lock, flags);
1349− tmp = readl (&dev->usb->usbctl);
1350− if (tmp & (1 << DEVICE_REMOTE_WAKEUP_ENABLE))
1351− writel (1 << GENERATE_RESUME, &dev->usb->usbstat);
1352− spin_unlock_irqrestore (&dev->lock, flags);
1353−
1354− /* pci writes may still be posted */
1355− return 0;
1356−}
1357−
1358−static int net2280_set_selfpowered (struct usb_gadget *_gadget, int value)
1359−{
1360− struct net2280 *dev;
1361− u32 tmp;
1362− unsigned long flags;
1363−
1364− if (!_gadget)
1365− return 0;
1366− dev = container_of (_gadget, struct net2280, gadget);
1367−
1368− spin_lock_irqsave (&dev->lock, flags);
1369− tmp = readl (&dev->usb->usbctl);
1370− if (value)
1371− tmp |= (1 << SELF_POWERED_STATUS);
1372− else
1373− tmp &= ~(1 << SELF_POWERED_STATUS);
1374− writel (tmp, &dev->usb->usbctl);
1375− spin_unlock_irqrestore (&dev->lock, flags);
1376−
1377− return 0;
1378−}
1379−
1380−static int net2280_pullup(struct usb_gadget *_gadget, int is_on)
1381−{
1382− struct net2280 *dev;
1383− u32 tmp;
1384− unsigned long flags;
1385−
1386− if (!_gadget)
1387− return -ENODEV;
1388− dev = container_of (_gadget, struct net2280, gadget);
1389−
1390− spin_lock_irqsave (&dev->lock, flags);
1391− tmp = readl (&dev->usb->usbctl);
1392− dev->softconnect = (is_on != 0);
1393− if (is_on)
1394− tmp |= (1 << USB_DETECT_ENABLE);
1395− else
1396− tmp &= ~(1 << USB_DETECT_ENABLE);
1397− writel (tmp, &dev->usb->usbctl);
1398− spin_unlock_irqrestore (&dev->lock, flags);
1399−
1400− return 0;
1401−}
1402−
1403−static int net2280_start(struct usb_gadget *_gadget,
1404− struct usb_gadget_driver *driver);
1405−static int net2280_stop(struct usb_gadget *_gadget,
1406− struct usb_gadget_driver *driver);
1407−
1408−static const struct usb_gadget_ops net2280_ops = {
1409− .get_frame = net2280_get_frame,
1410− .wakeup = net2280_wakeup,
1411− .set_selfpowered = net2280_set_selfpowered,
1412− .pullup = net2280_pullup,
1413− .udc_start = net2280_start,
1414− .udc_stop = net2280_stop,
1415−};
1416−
1417−/*-------------------------------------------------------------------------*/
1418−
1419−#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1420−
1421−/* FIXME move these into procfs, and use seq_file.
1422− * Sysfs _still_ doesn't behave for arbitrarily sized files,
1423− * and also doesn't help products using this with 2.4 kernels.
1424− */
1425−
1426−/* "function" sysfs attribute */
1427−static ssize_t function_show(struct device *_dev, struct device_attribute *attr,
1428− char *buf)
1429−{
1430− struct net2280 *dev = dev_get_drvdata (_dev);
1431−
1432− if (!dev->driver
1433− || !dev->driver->function
1434− || strlen (dev->driver->function) > PAGE_SIZE)
1435− return 0;
1436− return scnprintf (buf, PAGE_SIZE, "%s\n", dev->driver->function);
1437−}
1438−static DEVICE_ATTR_RO(function);
1439−
1440−static ssize_t registers_show(struct device *_dev,
1441− struct device_attribute *attr, char *buf)
1442−{
1443− struct net2280 *dev;
1444− char *next;
1445− unsigned size, t;
1446− unsigned long flags;
1447− int i;
1448− u32 t1, t2;
1449− const char *s;
1450−
1451− dev = dev_get_drvdata (_dev);
1452− next = buf;
1453− size = PAGE_SIZE;
1454− spin_lock_irqsave (&dev->lock, flags);
1455−
1456− if (dev->driver)
1457− s = dev->driver->driver.name;
1458− else
1459− s = "(none)";
1460−
1461− /* Main Control Registers */
1462− t = scnprintf (next, size, "%s version " DRIVER_VERSION
1463− ", chiprev %04x, dma %s\n\n"
1464− "devinit %03x fifoctl %08x gadget '%s'\n"
1465− "pci irqenb0 %02x irqenb1 %08x "
1466− "irqstat0 %04x irqstat1 %08x\n",
1467− driver_name, dev->chiprev,
1468− use_dma
1469− ? (use_dma_chaining ? "chaining" : "enabled")
1470− : "disabled",
1471− readl (&dev->regs->devinit),
1472− readl (&dev->regs->fifoctl),
1473− s,
1474− readl (&dev->regs->pciirqenb0),
1475− readl (&dev->regs->pciirqenb1),
1476− readl (&dev->regs->irqstat0),
1477− readl (&dev->regs->irqstat1));
1478− size -= t;
1479− next += t;
1480−
1481− /* USB Control Registers */
1482− t1 = readl (&dev->usb->usbctl);
1483− t2 = readl (&dev->usb->usbstat);
1484− if (t1 & (1 << VBUS_PIN)) {
1485− if (t2 & (1 << HIGH_SPEED))
1486− s = "high speed";
1487− else if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1488− s = "powered";
1489− else
1490− s = "full speed";
1491− /* full speed bit (6) not working?? */
1492− } else
1493− s = "not attached";
1494− t = scnprintf (next, size,
1495− "stdrsp %08x usbctl %08x usbstat %08x "
1496− "addr 0x%02x (%s)\n",
1497− readl (&dev->usb->stdrsp), t1, t2,
1498− readl (&dev->usb->ouraddr), s);
1499− size -= t;
1500− next += t;
1501−
1502− /* PCI Master Control Registers */
1503−
1504− /* DMA Control Registers */
1505−
1506− /* Configurable EP Control Registers */
1507− for (i = 0; i < 7; i++) {
1508− struct net2280_ep *ep;
1509−
1510− ep = &dev->ep [i];
1511− if (i && !ep->desc)
1512− continue;
1513−
1514− t1 = readl (&ep->regs->ep_cfg);
1515− t2 = readl (&ep->regs->ep_rsp) & 0xff;
1516− t = scnprintf (next, size,
1517− "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
1518− "irqenb %02x\n",
1519− ep->ep.name, t1, t2,
1520− (t2 & (1 << CLEAR_NAK_OUT_PACKETS))
1521− ? "NAK " : "",
1522− (t2 & (1 << CLEAR_EP_HIDE_STATUS_PHASE))
1523− ? "hide " : "",
1524− (t2 & (1 << CLEAR_EP_FORCE_CRC_ERROR))
1525− ? "CRC " : "",
1526− (t2 & (1 << CLEAR_INTERRUPT_MODE))
1527− ? "interrupt " : "",
1528− (t2 & (1<<CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE))
1529− ? "status " : "",
1530− (t2 & (1 << CLEAR_NAK_OUT_PACKETS_MODE))
1531− ? "NAKmode " : "",
1532− (t2 & (1 << CLEAR_ENDPOINT_TOGGLE))
1533− ? "DATA1 " : "DATA0 ",
1534− (t2 & (1 << CLEAR_ENDPOINT_HALT))
1535− ? "HALT " : "",
1536− readl (&ep->regs->ep_irqenb));
1537− size -= t;
1538− next += t;
1539−
1540− t = scnprintf (next, size,
1541− "\tstat %08x avail %04x "
1542− "(ep%d%s-%s)%s\n",
1543− readl (&ep->regs->ep_stat),
1544− readl (&ep->regs->ep_avail),
1545− t1 & 0x0f, DIR_STRING (t1),
1546− type_string (t1 >> 8),
1547− ep->stopped ? "*" : "");
1548− size -= t;
1549− next += t;
1550−
1551− if (!ep->dma)
1552− continue;
1553−
1554− t = scnprintf (next, size,
1555− " dma\tctl %08x stat %08x count %08x\n"
1556− "\taddr %08x desc %08x\n",
1557− readl (&ep->dma->dmactl),
1558− readl (&ep->dma->dmastat),
1559− readl (&ep->dma->dmacount),
1560− readl (&ep->dma->dmaaddr),
1561− readl (&ep->dma->dmadesc));
1562− size -= t;
1563− next += t;
1564−
1565− }
1566−
1567− /* Indexed Registers */
1568− // none yet
1569−
1570− /* Statistics */
1571− t = scnprintf (next, size, "\nirqs: ");
1572− size -= t;
1573− next += t;
1574− for (i = 0; i < 7; i++) {
1575− struct net2280_ep *ep;
1576−
1577− ep = &dev->ep [i];
1578− if (i && !ep->irqs)
1579− continue;
1580− t = scnprintf (next, size, " %s/%lu", ep->ep.name, ep->irqs);
1581− size -= t;
1582− next += t;
1583−
1584− }
1585− t = scnprintf (next, size, "\n");
1586− size -= t;
1587− next += t;
1588−
1589− spin_unlock_irqrestore (&dev->lock, flags);
1590−
1591− return PAGE_SIZE - size;
1592−}
1593−static DEVICE_ATTR_RO(registers);
1594−
1595−static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
1596− char *buf)
1597−{
1598− struct net2280 *dev;
1599− char *next;
1600− unsigned size;
1601− unsigned long flags;
1602− int i;
1603−
1604− dev = dev_get_drvdata (_dev);
1605− next = buf;
1606− size = PAGE_SIZE;
1607− spin_lock_irqsave (&dev->lock, flags);
1608−
1609− for (i = 0; i < 7; i++) {
1610− struct net2280_ep *ep = &dev->ep [i];
1611− struct net2280_request *req;
1612− int t;
1613−
1614− if (i != 0) {
1615− const struct usb_endpoint_descriptor *d;
1616−
1617− d = ep->desc;
1618− if (!d)
1619− continue;
1620− t = d->bEndpointAddress;
1621− t = scnprintf (next, size,
1622− "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
1623− ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK,
1624− (t & USB_DIR_IN) ? "in" : "out",
1625− ({ char *val;
1626− switch (d->bmAttributes & 0x03) {
1627− case USB_ENDPOINT_XFER_BULK:
1628− val = "bulk"; break;
1629− case USB_ENDPOINT_XFER_INT:
1630− val = "intr"; break;
1631− default:
1632− val = "iso"; break;
1633− } val; }),
1634− usb_endpoint_maxp (d) & 0x1fff,
1635− ep->dma ? "dma" : "pio", ep->fifo_size
1636− );
1637− } else /* ep0 should only have one transfer queued */
1638− t = scnprintf (next, size, "ep0 max 64 pio %s\n",
1639− ep->is_in ? "in" : "out");
1640− if (t <= 0 || t > size)
1641− goto done;
1642− size -= t;
1643− next += t;
1644−
1645− if (list_empty (&ep->queue)) {
1646− t = scnprintf (next, size, "\t(nothing queued)\n");
1647− if (t <= 0 || t > size)
1648− goto done;
1649− size -= t;
1650− next += t;
1651− continue;
1652− }
1653− list_for_each_entry (req, &ep->queue, queue) {
1654− if (ep->dma && req->td_dma == readl (&ep->dma->dmadesc))
1655− t = scnprintf (next, size,
1656− "\treq %p len %d/%d "
1657− "buf %p (dmacount %08x)\n",
1658− &req->req, req->req.actual,
1659− req->req.length, req->req.buf,
1660− readl (&ep->dma->dmacount));
1661− else
1662− t = scnprintf (next, size,
1663− "\treq %p len %d/%d buf %p\n",
1664− &req->req, req->req.actual,
1665− req->req.length, req->req.buf);
1666− if (t <= 0 || t > size)
1667− goto done;
1668− size -= t;
1669− next += t;
1670−
1671− if (ep->dma) {
1672− struct net2280_dma *td;
1673−
1674− td = req->td;
1675− t = scnprintf (next, size, "\t td %08x "
1676− " count %08x buf %08x desc %08x\n",
1677− (u32) req->td_dma,
1678− le32_to_cpu (td->dmacount),
1679− le32_to_cpu (td->dmaaddr),
1680− le32_to_cpu (td->dmadesc));
1681− if (t <= 0 || t > size)
1682− goto done;
1683− size -= t;
1684− next += t;
1685− }
1686− }
1687− }
1688−
1689−done:
1690− spin_unlock_irqrestore (&dev->lock, flags);
1691− return PAGE_SIZE - size;
1692−}
1693−static DEVICE_ATTR_RO(queues);
1694−
1695−
1696−#else
1697−
1698−#define device_create_file(a,b) (0)
1699−#define device_remove_file(a,b) do { } while (0)
1700−
1701−#endif
1702−
1703−/*-------------------------------------------------------------------------*/
1704−
1705−/* another driver-specific mode might be a request type doing dma
1706− * to/from another device fifo instead of to/from memory.
1707− */
1708−
1709−static void set_fifo_mode (struct net2280 *dev, int mode)
1710−{
1711− /* keeping high bits preserves BAR2 */
1712− writel ((0xffff << PCI_BASE2_RANGE) | mode, &dev->regs->fifoctl);
1713−
1714− /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */
1715− INIT_LIST_HEAD (&dev->gadget.ep_list);
1716− list_add_tail (&dev->ep [1].ep.ep_list, &dev->gadget.ep_list);
1717− list_add_tail (&dev->ep [2].ep.ep_list, &dev->gadget.ep_list);
1718− switch (mode) {
1719− case 0:
1720− list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list);
1721− list_add_tail (&dev->ep [4].ep.ep_list, &dev->gadget.ep_list);
1722− dev->ep [1].fifo_size = dev->ep [2].fifo_size = 1024;
1723− break;
1724− case 1:
1725− dev->ep [1].fifo_size = dev->ep [2].fifo_size = 2048;
1726− break;
1727− case 2:
1728− list_add_tail (&dev->ep [3].ep.ep_list, &dev->gadget.ep_list);
1729− dev->ep [1].fifo_size = 2048;
1730− dev->ep [2].fifo_size = 1024;
1731− break;
1732− }
1733− /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */
1734− list_add_tail (&dev->ep [5].ep.ep_list, &dev->gadget.ep_list);
1735− list_add_tail (&dev->ep [6].ep.ep_list, &dev->gadget.ep_list);
1736−}
1737−
1738−/* keeping it simple:
1739− * - one bus driver, initted first;
1740− * - one function driver, initted second
1741− *
1742− * most of the work to support multiple net2280 controllers would
1743− * be to associate this gadget driver (yes?) with all of them, or
1744− * perhaps to bind specific drivers to specific devices.
1745− */
1746−
1747−static void usb_reset (struct net2280 *dev)
1748−{
1749− u32 tmp;
1750−
1751− dev->gadget.speed = USB_SPEED_UNKNOWN;
1752− (void) readl (&dev->usb->usbctl);
1753−
1754− net2280_led_init (dev);
1755−
1756− /* disable automatic responses, and irqs */
1757− writel (0, &dev->usb->stdrsp);
1758− writel (0, &dev->regs->pciirqenb0);
1759− writel (0, &dev->regs->pciirqenb1);
1760−
1761− /* clear old dma and irq state */
1762− for (tmp = 0; tmp < 4; tmp++) {
1763− struct net2280_ep *ep = &dev->ep [tmp + 1];
1764−
1765− if (ep->dma)
1766− abort_dma (ep);
1767− }
1768− writel (~0, &dev->regs->irqstat0),
1769− writel (~(1 << SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1),
1770−
1771− /* reset, and enable pci */
1772− tmp = readl (&dev->regs->devinit)
1773− | (1 << PCI_ENABLE)
1774− | (1 << FIFO_SOFT_RESET)
1775− | (1 << USB_SOFT_RESET)
1776− | (1 << M8051_RESET);
1777− writel (tmp, &dev->regs->devinit);
1778−
1779− /* standard fifo and endpoint allocations */
1780− set_fifo_mode (dev, (fifo_mode <= 2) ? fifo_mode : 0);
1781−}
1782−
1783−static void usb_reinit (struct net2280 *dev)
1784−{
1785− u32 tmp;
1786− int init_dma;
1787−
1788− /* use_dma changes are ignored till next device re-init */
1789− init_dma = use_dma;
1790−
1791− /* basic endpoint init */
1792− for (tmp = 0; tmp < 7; tmp++) {
1793− struct net2280_ep *ep = &dev->ep [tmp];
1794−
1795− ep->ep.name = ep_name [tmp];
1796− ep->dev = dev;
1797− ep->num = tmp;
1798−
1799− if (tmp > 0 && tmp <= 4) {
1800− ep->fifo_size = 1024;
1801− if (init_dma)
1802− ep->dma = &dev->dma [tmp - 1];
1803− } else
1804− ep->fifo_size = 64;
1805− ep->regs = &dev->epregs [tmp];
1806− ep_reset (dev->regs, ep);
1807− }
1808− usb_ep_set_maxpacket_limit(&dev->ep [0].ep, 64);
1809− usb_ep_set_maxpacket_limit(&dev->ep [5].ep, 64);
1810− usb_ep_set_maxpacket_limit(&dev->ep [6].ep, 64);
1811−
1812− dev->gadget.ep0 = &dev->ep [0].ep;
1813− dev->ep [0].stopped = 0;
1814− INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
1815−
1816− /* we want to prevent lowlevel/insecure access from the USB host,
1817− * but erratum 0119 means this enable bit is ignored
1818− */
1819− for (tmp = 0; tmp < 5; tmp++)
1820− writel (EP_DONTUSE, &dev->dep [tmp].dep_cfg);
1821−}
1822−
1823−static void ep0_start (struct net2280 *dev)
1824−{
1825− writel ( (1 << CLEAR_EP_HIDE_STATUS_PHASE)
1826− | (1 << CLEAR_NAK_OUT_PACKETS)
1827− | (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
1828− , &dev->epregs [0].ep_rsp);
1829−
1830− /*
1831− * hardware optionally handles a bunch of standard requests
1832− * that the API hides from drivers anyway. have it do so.
1833− * endpoint status/features are handled in software, to
1834− * help pass tests for some dubious behavior.
1835− */
1836− writel ( (1 << SET_TEST_MODE)
1837− | (1 << SET_ADDRESS)
1838− | (1 << DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP)
1839− | (1 << GET_DEVICE_STATUS)
1840− | (1 << GET_INTERFACE_STATUS)
1841− , &dev->usb->stdrsp);
1842− writel ( (1 << USB_ROOT_PORT_WAKEUP_ENABLE)
1843− | (1 << SELF_POWERED_USB_DEVICE)
1844− | (1 << REMOTE_WAKEUP_SUPPORT)
1845− | (dev->softconnect << USB_DETECT_ENABLE)
1846− | (1 << SELF_POWERED_STATUS)
1847− , &dev->usb->usbctl);
1848−
1849− /* enable irqs so we can see ep0 and general operation */
1850− writel ( (1 << SETUP_PACKET_INTERRUPT_ENABLE)
1851− | (1 << ENDPOINT_0_INTERRUPT_ENABLE)
1852− , &dev->regs->pciirqenb0);
1853− writel ( (1 << PCI_INTERRUPT_ENABLE)
1854− | (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE)
1855− | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE)
1856− | (1 << PCI_RETRY_ABORT_INTERRUPT_ENABLE)
1857− | (1 << VBUS_INTERRUPT_ENABLE)
1858− | (1 << ROOT_PORT_RESET_INTERRUPT_ENABLE)
1859− | (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE)
1860− , &dev->regs->pciirqenb1);
1861−
1862− /* don't leave any writes posted */
1863− (void) readl (&dev->usb->usbctl);
1864−}
1865−
1866−/* when a driver is successfully registered, it will receive
1867− * control requests including set_configuration(), which enables
1868− * non-control requests. then usb traffic follows until a
1869− * disconnect is reported. then a host may connect again, or
1870− * the driver might get unbound.
1871− */
1872−static int net2280_start(struct usb_gadget *_gadget,
1873− struct usb_gadget_driver *driver)
1874−{
1875− struct net2280 *dev;
1876− int retval;
1877− unsigned i;
1878−
1879− /* insist on high speed support from the driver, since
1880− * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
1881− * "must not be used in normal operation"
1882− */
1883− if (!driver || driver->max_speed < USB_SPEED_HIGH
1884− || !driver->setup)
1885− return -EINVAL;
1886−
1887− dev = container_of (_gadget, struct net2280, gadget);
1888−
1889− for (i = 0; i < 7; i++)
1890− dev->ep [i].irqs = 0;
1891−
1892− /* hook up the driver ... */
1893− dev->softconnect = 1;
1894− driver->driver.bus = NULL;
1895− dev->driver = driver;
1896−
1897− retval = device_create_file (&dev->pdev->dev, &dev_attr_function);
1898− if (retval) goto err_unbind;
1899− retval = device_create_file (&dev->pdev->dev, &dev_attr_queues);
1900− if (retval) goto err_func;
1901−
1902− /* Enable force-full-speed testing mode, if desired */
1903− if (full_speed)
1904− writel(1 << FORCE_FULL_SPEED_MODE, &dev->usb->xcvrdiag);
1905−
1906− /* ... then enable host detection and ep0; and we're ready
1907− * for set_configuration as well as eventual disconnect.
1908− */
1909− net2280_led_active (dev, 1);
1910− ep0_start (dev);
1911−
1912− DEBUG (dev, "%s ready, usbctl %08x stdrsp %08x\n",
1913− driver->driver.name,
1914− readl (&dev->usb->usbctl),
1915− readl (&dev->usb->stdrsp));
1916−
1917− /* pci writes may still be posted */
1918− return 0;
1919−
1920−err_func:
1921− device_remove_file (&dev->pdev->dev, &dev_attr_function);
1922−err_unbind:
1923− dev->driver = NULL;
1924− return retval;
1925−}
1926−
1927−static void
1928−stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
1929−{
1930− int i;
1931−
1932− /* don't disconnect if it's not connected */
1933− if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1934− driver = NULL;
1935−
1936− /* stop hardware; prevent new request submissions;
1937− * and kill any outstanding requests.
1938− */
1939− usb_reset (dev);
1940− for (i = 0; i < 7; i++)
1941− nuke (&dev->ep [i]);
1942−
1943− /* report disconnect; the driver is already quiesced */
1944− if (driver) {
1945− spin_unlock(&dev->lock);
1946− driver->disconnect(&dev->gadget);
1947− spin_lock(&dev->lock);
1948− }
1949−
1950− usb_reinit (dev);
1951−}
1952−
1953−static int net2280_stop(struct usb_gadget *_gadget,
1954− struct usb_gadget_driver *driver)
1955−{
1956− struct net2280 *dev;
1957− unsigned long flags;
1958−
1959− dev = container_of (_gadget, struct net2280, gadget);
1960−
1961− spin_lock_irqsave (&dev->lock, flags);
1962− stop_activity (dev, driver);
1963− spin_unlock_irqrestore (&dev->lock, flags);
1964−
1965− dev->driver = NULL;
1966−
1967− net2280_led_active (dev, 0);
1968−
1969− /* Disable full-speed test mode */
1970− writel(0, &dev->usb->xcvrdiag);
1971−
1972− device_remove_file (&dev->pdev->dev, &dev_attr_function);
1973− device_remove_file (&dev->pdev->dev, &dev_attr_queues);
1974−
1975− DEBUG(dev, "unregistered driver '%s'\n",
1976− driver ? driver->driver.name : "");
1977−
1978− return 0;
1979−}
1980−
1981−/*-------------------------------------------------------------------------*/
1982−
1983−/* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
1984− * also works for dma-capable endpoints, in pio mode or just
1985− * to manually advance the queue after short OUT transfers.
1986− */
1987−static void handle_ep_small (struct net2280_ep *ep)
1988−{
1989− struct net2280_request *req;
1990− u32 t;
1991− /* 0 error, 1 mid-data, 2 done */
1992− int mode = 1;
1993−
1994− if (!list_empty (&ep->queue))
1995− req = list_entry (ep->queue.next,
1996− struct net2280_request, queue);
1997− else
1998− req = NULL;
1999−
2000− /* ack all, and handle what we care about */
2001− t = readl (&ep->regs->ep_stat);
2002− ep->irqs++;
2003−#if 0
2004− VDEBUG (ep->dev, "%s ack ep_stat %08x, req %p\n",
2005− ep->ep.name, t, req ? &req->req : 0);
2006−#endif
2007− if (!ep->is_in || ep->dev->pdev->device == 0x2280)
2008− writel (t & ~(1 << NAK_OUT_PACKETS), &ep->regs->ep_stat);
2009− else
2010− /* Added for 2282 */
2011− writel (t, &ep->regs->ep_stat);
2012−
2013− /* for ep0, monitor token irqs to catch data stage length errors
2014− * and to synchronize on status.
2015− *
2016− * also, to defer reporting of protocol stalls ... here's where
2017− * data or status first appears, handling stalls here should never
2018− * cause trouble on the host side..
2019− *
2020− * control requests could be slightly faster without token synch for
2021− * status, but status can jam up that way.
2022− */
2023− if (unlikely (ep->num == 0)) {
2024− if (ep->is_in) {
2025− /* status; stop NAKing */
2026− if (t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT)) {
2027− if (ep->dev->protocol_stall) {
2028− ep->stopped = 1;
2029− set_halt (ep);
2030− }
2031− if (!req)
2032− allow_status (ep);
2033− mode = 2;
2034− /* reply to extra IN data tokens with a zlp */
2035− } else if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) {
2036− if (ep->dev->protocol_stall) {
2037− ep->stopped = 1;
2038− set_halt (ep);
2039− mode = 2;
2040− } else if (ep->responded &&
2041− !req && !ep->stopped)
2042− write_fifo (ep, NULL);
2043− }
2044− } else {
2045− /* status; stop NAKing */
2046− if (t & (1 << DATA_IN_TOKEN_INTERRUPT)) {
2047− if (ep->dev->protocol_stall) {
2048− ep->stopped = 1;
2049− set_halt (ep);
2050− }
2051− mode = 2;
2052− /* an extra OUT token is an error */
2053− } else if (((t & (1 << DATA_OUT_PING_TOKEN_INTERRUPT))
2054− && req
2055− && req->req.actual == req->req.length)
2056− || (ep->responded && !req)) {
2057− ep->dev->protocol_stall = 1;
2058− set_halt (ep);
2059− ep->stopped = 1;
2060− if (req)
2061− done (ep, req, -EOVERFLOW);
2062− req = NULL;
2063− }
2064− }
2065− }
2066−
2067− if (unlikely (!req))
2068− return;
2069−
2070− /* manual DMA queue advance after short OUT */
2071− if (likely (ep->dma)) {
2072− if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
2073− u32 count;
2074− int stopped = ep->stopped;
2075−
2076− /* TRANSFERRED works around OUT_DONE erratum 0112.
2077− * we expect (N <= maxpacket) bytes; host wrote M.
2078− * iff (M < N) we won't ever see a DMA interrupt.
2079− */
2080− ep->stopped = 1;
2081− for (count = 0; ; t = readl (&ep->regs->ep_stat)) {
2082−
2083− /* any preceding dma transfers must finish.
2084− * dma handles (M >= N), may empty the queue
2085− */
2086− scan_dma_completions (ep);
2087− if (unlikely (list_empty (&ep->queue)
2088− || ep->out_overflow)) {
2089− req = NULL;
2090− break;
2091− }
2092− req = list_entry (ep->queue.next,
2093− struct net2280_request, queue);
2094−
2095− /* here either (M < N), a "real" short rx;
2096− * or (M == N) and the queue didn't empty
2097− */
2098− if (likely (t & (1 << FIFO_EMPTY))) {
2099− count = readl (&ep->dma->dmacount);
2100− count &= DMA_BYTE_COUNT_MASK;
2101− if (readl (&ep->dma->dmadesc)
2102− != req->td_dma)
2103− req = NULL;
2104− break;
2105− }
2106− udelay(1);
2107− }
2108−
2109− /* stop DMA, leave ep NAKing */
2110− writel ((1 << DMA_ABORT), &ep->dma->dmastat);
2111− spin_stop_dma (ep->dma);
2112−
2113− if (likely (req)) {
2114− req->td->dmacount = 0;
2115− t = readl (&ep->regs->ep_avail);
2116− dma_done (ep, req, count,
2117− (ep->out_overflow || t)
2118− ? -EOVERFLOW : 0);
2119− }
2120−
2121− /* also flush to prevent erratum 0106 trouble */
2122− if (unlikely (ep->out_overflow
2123− || (ep->dev->chiprev == 0x0100
2124− && ep->dev->gadget.speed
2125− == USB_SPEED_FULL))) {
2126− out_flush (ep);
2127− ep->out_overflow = 0;
2128− }
2129−
2130− /* (re)start dma if needed, stop NAKing */
2131− ep->stopped = stopped;
2132− if (!list_empty (&ep->queue))
2133− restart_dma (ep);
2134− } else
2135− DEBUG (ep->dev, "%s dma ep_stat %08x ??\n",
2136− ep->ep.name, t);
2137− return;
2138−
2139− /* data packet(s) received (in the fifo, OUT) */
2140− } else if (t & (1 << DATA_PACKET_RECEIVED_INTERRUPT)) {
2141− if (read_fifo (ep, req) && ep->num != 0)
2142− mode = 2;
2143−
2144− /* data packet(s) transmitted (IN) */
2145− } else if (t & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)) {
2146− unsigned len;
2147−
2148− len = req->req.length - req->req.actual;
2149− if (len > ep->ep.maxpacket)
2150− len = ep->ep.maxpacket;
2151− req->req.actual += len;
2152−
2153− /* if we wrote it all, we're usually done */
2154− if (req->req.actual == req->req.length) {
2155− if (ep->num == 0) {
2156− /* send zlps until the status stage */
2157− } else if (!req->req.zero || len != ep->ep.maxpacket)
2158− mode = 2;
2159− }
2160−
2161− /* there was nothing to do ... */
2162− } else if (mode == 1)
2163− return;
2164−
2165− /* done */
2166− if (mode == 2) {
2167− /* stream endpoints often resubmit/unlink in completion */
2168− done (ep, req, 0);
2169−
2170− /* maybe advance queue to next request */
2171− if (ep->num == 0) {
2172− /* NOTE: net2280 could let gadget driver start the
2173− * status stage later. since not all controllers let
2174− * them control that, the api doesn't (yet) allow it.
2175− */
2176− if (!ep->stopped)
2177− allow_status (ep);
2178− req = NULL;
2179− } else {
2180− if (!list_empty (&ep->queue) && !ep->stopped)
2181− req = list_entry (ep->queue.next,
2182− struct net2280_request, queue);
2183− else
2184− req = NULL;
2185− if (req && !ep->is_in)
2186− stop_out_naking (ep);
2187− }
2188− }
2189−
2190− /* is there a buffer for the next packet?
2191− * for best streaming performance, make sure there is one.
2192− */
2193− if (req && !ep->stopped) {
2194−
2195− /* load IN fifo with next packet (may be zlp) */
2196− if (t & (1 << DATA_PACKET_TRANSMITTED_INTERRUPT))
2197− write_fifo (ep, &req->req);
2198− }
2199−}
2200−
2201−static struct net2280_ep *
2202−get_ep_by_addr (struct net2280 *dev, u16 wIndex)
2203−{
2204− struct net2280_ep *ep;
2205−
2206− if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
2207− return &dev->ep [0];
2208− list_for_each_entry (ep, &dev->gadget.ep_list, ep.ep_list) {
2209− u8 bEndpointAddress;
2210−
2211− if (!ep->desc)
2212− continue;
2213− bEndpointAddress = ep->desc->bEndpointAddress;
2214− if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
2215− continue;
2216− if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f))
2217− return ep;
2218− }
2219− return NULL;
2220−}
2221−
2222−static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2223−{
2224− struct net2280_ep *ep;
2225− u32 num, scratch;
2226−
2227− /* most of these don't need individual acks */
2228− stat &= ~(1 << INTA_ASSERTED);
2229− if (!stat)
2230− return;
2231− // DEBUG (dev, "irqstat0 %04x\n", stat);
2232−
2233− /* starting a control request? */
2234− if (unlikely (stat & (1 << SETUP_PACKET_INTERRUPT))) {
2235− union {
2236− u32 raw [2];
2237− struct usb_ctrlrequest r;
2238− } u;
2239− int tmp;
2240− struct net2280_request *req;
2241−
2242− if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
2243− if (readl (&dev->usb->usbstat) & (1 << HIGH_SPEED))
2244− dev->gadget.speed = USB_SPEED_HIGH;
2245− else
2246− dev->gadget.speed = USB_SPEED_FULL;
2247− net2280_led_speed (dev, dev->gadget.speed);
2248− DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed));
2249− }
2250−
2251− ep = &dev->ep [0];
2252− ep->irqs++;
2253−
2254− /* make sure any leftover request state is cleared */
2255− stat &= ~(1 << ENDPOINT_0_INTERRUPT);
2256− while (!list_empty (&ep->queue)) {
2257− req = list_entry (ep->queue.next,
2258− struct net2280_request, queue);
2259− done (ep, req, (req->req.actual == req->req.length)
2260− ? 0 : -EPROTO);
2261− }
2262− ep->stopped = 0;
2263− dev->protocol_stall = 0;
2264−
2265− if (ep->dev->pdev->device == 0x2280)
2266− tmp = (1 << FIFO_OVERFLOW)
2267− | (1 << FIFO_UNDERFLOW);
2268− else
2269− tmp = 0;
2270−
2271− writel (tmp | (1 << TIMEOUT)
2272− | (1 << USB_STALL_SENT)
2273− | (1 << USB_IN_NAK_SENT)
2274− | (1 << USB_IN_ACK_RCVD)
2275− | (1 << USB_OUT_PING_NAK_SENT)
2276− | (1 << USB_OUT_ACK_SENT)
2277− | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT)
2278− | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)
2279− | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
2280− | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
2281− | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
2282− | (1 << DATA_IN_TOKEN_INTERRUPT)
2283− , &ep->regs->ep_stat);
2284− u.raw [0] = readl (&dev->usb->setup0123);
2285− u.raw [1] = readl (&dev->usb->setup4567);
2286−
2287− cpu_to_le32s (&u.raw [0]);
2288− cpu_to_le32s (&u.raw [1]);
2289−
2290− tmp = 0;
2291−
2292−#define w_value le16_to_cpu(u.r.wValue)
2293−#define w_index le16_to_cpu(u.r.wIndex)
2294−#define w_length le16_to_cpu(u.r.wLength)
2295−
2296− /* ack the irq */
2297− writel (1 << SETUP_PACKET_INTERRUPT, &dev->regs->irqstat0);
2298− stat ^= (1 << SETUP_PACKET_INTERRUPT);
2299−
2300− /* watch control traffic at the token level, and force
2301− * synchronization before letting the status stage happen.
2302− * FIXME ignore tokens we'll NAK, until driver responds.
2303− * that'll mean a lot less irqs for some drivers.
2304− */
2305− ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0;
2306− if (ep->is_in) {
2307− scratch = (1 << DATA_PACKET_TRANSMITTED_INTERRUPT)
2308− | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
2309− | (1 << DATA_IN_TOKEN_INTERRUPT);
2310− stop_out_naking (ep);
2311− } else
2312− scratch = (1 << DATA_PACKET_RECEIVED_INTERRUPT)
2313− | (1 << DATA_OUT_PING_TOKEN_INTERRUPT)
2314− | (1 << DATA_IN_TOKEN_INTERRUPT);
2315− writel (scratch, &dev->epregs [0].ep_irqenb);
2316−
2317− /* we made the hardware handle most lowlevel requests;
2318− * everything else goes uplevel to the gadget code.
2319− */
2320− ep->responded = 1;
2321− switch (u.r.bRequest) {
2322− case USB_REQ_GET_STATUS: {
2323− struct net2280_ep *e;
2324− __le32 status;
2325−
2326− /* hw handles device and interface status */
2327− if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
2328− goto delegate;
2329− if ((e = get_ep_by_addr (dev, w_index)) == NULL
2330− || w_length > 2)
2331− goto do_stall;
2332−
2333− if (readl (&e->regs->ep_rsp)
2334− & (1 << SET_ENDPOINT_HALT))
2335− status = cpu_to_le32 (1);
2336− else
2337− status = cpu_to_le32 (0);
2338−
2339− /* don't bother with a request object! */
2340− writel (0, &dev->epregs [0].ep_irqenb);
2341− set_fifo_bytecount (ep, w_length);
2342− writel ((__force u32)status, &dev->epregs [0].ep_data);
2343− allow_status (ep);
2344− VDEBUG (dev, "%s stat %02x\n", ep->ep.name, status);
2345− goto next_endpoints;
2346− }
2347− break;
2348− case USB_REQ_CLEAR_FEATURE: {
2349− struct net2280_ep *e;
2350−
2351− /* hw handles device features */
2352− if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2353− goto delegate;
2354− if (w_value != USB_ENDPOINT_HALT
2355− || w_length != 0)
2356− goto do_stall;
2357− if ((e = get_ep_by_addr (dev, w_index)) == NULL)
2358− goto do_stall;
2359− if (e->wedged) {
2360− VDEBUG(dev, "%s wedged, halt not cleared\n",
2361− ep->ep.name);
2362− } else {
2363− VDEBUG(dev, "%s clear halt\n", ep->ep.name);
2364− clear_halt(e);
2365− }
2366− allow_status (ep);
2367− goto next_endpoints;
2368− }
2369− break;
2370− case USB_REQ_SET_FEATURE: {
2371− struct net2280_ep *e;
2372−
2373− /* hw handles device features */
2374− if (u.r.bRequestType != USB_RECIP_ENDPOINT)
2375− goto delegate;
2376− if (w_value != USB_ENDPOINT_HALT
2377− || w_length != 0)
2378− goto do_stall;
2379− if ((e = get_ep_by_addr (dev, w_index)) == NULL)
2380− goto do_stall;
2381− if (e->ep.name == ep0name)
2382− goto do_stall;
2383− set_halt (e);
2384− allow_status (ep);
2385− VDEBUG (dev, "%s set halt\n", ep->ep.name);
2386− goto next_endpoints;
2387− }
2388− break;
2389− default:
2390−delegate:
2391− VDEBUG (dev, "setup %02x.%02x v%04x i%04x l%04x "
2392− "ep_cfg %08x\n",
2393− u.r.bRequestType, u.r.bRequest,
2394− w_value, w_index, w_length,
2395− readl (&ep->regs->ep_cfg));
2396− ep->responded = 0;
2397− spin_unlock (&dev->lock);
2398− tmp = dev->driver->setup (&dev->gadget, &u.r);
2399− spin_lock (&dev->lock);
2400− }
2401−
2402− /* stall ep0 on error */
2403− if (tmp < 0) {
2404−do_stall:
2405− VDEBUG (dev, "req %02x.%02x protocol STALL; stat %d\n",
2406− u.r.bRequestType, u.r.bRequest, tmp);
2407− dev->protocol_stall = 1;
2408− }
2409−
2410− /* some in/out token irq should follow; maybe stall then.
2411− * driver must queue a request (even zlp) or halt ep0
2412− * before the host times out.
2413− */
2414− }
2415−
2416−#undef w_value
2417−#undef w_index
2418−#undef w_length
2419−
2420−next_endpoints:
2421− /* endpoint data irq ? */
2422− scratch = stat & 0x7f;
2423− stat &= ~0x7f;
2424− for (num = 0; scratch; num++) {
2425− u32 t;
2426−
2427− /* do this endpoint's FIFO and queue need tending? */
2428− t = 1 << num;
2429− if ((scratch & t) == 0)
2430− continue;
2431− scratch ^= t;
2432−
2433− ep = &dev->ep [num];
2434− handle_ep_small (ep);
2435− }
2436−
2437− if (stat)
2438− DEBUG (dev, "unhandled irqstat0 %08x\n", stat);
2439−}
2440−
2441−#define DMA_INTERRUPTS ( \
2442− (1 << DMA_D_INTERRUPT) \
2443− | (1 << DMA_C_INTERRUPT) \
2444− | (1 << DMA_B_INTERRUPT) \
2445− | (1 << DMA_A_INTERRUPT))
2446−#define PCI_ERROR_INTERRUPTS ( \
2447− (1 << PCI_MASTER_ABORT_RECEIVED_INTERRUPT) \
2448− | (1 << PCI_TARGET_ABORT_RECEIVED_INTERRUPT) \
2449− | (1 << PCI_RETRY_ABORT_INTERRUPT))
2450−
2451−static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2452−{
2453− struct net2280_ep *ep;
2454− u32 tmp, num, mask, scratch;
2455−
2456− /* after disconnect there's nothing else to do! */
2457− tmp = (1 << VBUS_INTERRUPT) | (1 << ROOT_PORT_RESET_INTERRUPT);
2458− mask = (1 << HIGH_SPEED) | (1 << FULL_SPEED);
2459−
2460− /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
2461− * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and
2462− * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
2463− * only indicates a change in the reset state).
2464− */
2465− if (stat & tmp) {
2466− writel (tmp, &dev->regs->irqstat1);
2467− if ((((stat & (1 << ROOT_PORT_RESET_INTERRUPT))
2468− && ((readl (&dev->usb->usbstat) & mask)
2469− == 0))
2470− || ((readl (&dev->usb->usbctl)
2471− & (1 << VBUS_PIN)) == 0)
2472− ) && ( dev->gadget.speed != USB_SPEED_UNKNOWN)) {
2473− DEBUG (dev, "disconnect %s\n",
2474− dev->driver->driver.name);
2475− stop_activity (dev, dev->driver);
2476− ep0_start (dev);
2477− return;
2478− }
2479− stat &= ~tmp;
2480−
2481− /* vBUS can bounce ... one of many reasons to ignore the
2482− * notion of hotplug events on bus connect/disconnect!
2483− */
2484− if (!stat)
2485− return;
2486− }
2487−
2488− /* NOTE: chip stays in PCI D0 state for now, but it could
2489− * enter D1 to save more power
2490− */
2491− tmp = (1 << SUSPEND_REQUEST_CHANGE_INTERRUPT);
2492− if (stat & tmp) {
2493− writel (tmp, &dev->regs->irqstat1);
2494− if (stat & (1 << SUSPEND_REQUEST_INTERRUPT)) {
2495− if (dev->driver->suspend)
2496− dev->driver->suspend (&dev->gadget);
2497− if (!enable_suspend)
2498− stat &= ~(1 << SUSPEND_REQUEST_INTERRUPT);
2499− } else {
2500− if (dev->driver->resume)
2501− dev->driver->resume (&dev->gadget);
2502− /* at high speed, note erratum 0133 */
2503− }
2504− stat &= ~tmp;
2505− }
2506−
2507− /* clear any other status/irqs */
2508− if (stat)
2509− writel (stat, &dev->regs->irqstat1);
2510−
2511− /* some status we can just ignore */
2512− if (dev->pdev->device == 0x2280)
2513− stat &= ~((1 << CONTROL_STATUS_INTERRUPT)
2514− | (1 << SUSPEND_REQUEST_INTERRUPT)
2515− | (1 << RESUME_INTERRUPT)
2516− | (1 << SOF_INTERRUPT));
2517− else
2518− stat &= ~((1 << CONTROL_STATUS_INTERRUPT)
2519− | (1 << RESUME_INTERRUPT)
2520− | (1 << SOF_DOWN_INTERRUPT)
2521− | (1 << SOF_INTERRUPT));
2522−
2523− if (!stat)
2524− return;
2525− // DEBUG (dev, "irqstat1 %08x\n", stat);
2526−
2527− /* DMA status, for ep-{a,b,c,d} */
2528− scratch = stat & DMA_INTERRUPTS;
2529− stat &= ~DMA_INTERRUPTS;
2530− scratch >>= 9;
2531− for (num = 0; scratch; num++) {
2532− struct net2280_dma_regs __iomem *dma;
2533−
2534− tmp = 1 << num;
2535− if ((tmp & scratch) == 0)
2536− continue;
2537− scratch ^= tmp;
2538−
2539− ep = &dev->ep [num + 1];
2540− dma = ep->dma;
2541−
2542− if (!dma)
2543− continue;
2544−
2545− /* clear ep's dma status */
2546− tmp = readl (&dma->dmastat);
2547− writel (tmp, &dma->dmastat);
2548−
2549− /* chaining should stop on abort, short OUT from fifo,
2550− * or (stat0 codepath) short OUT transfer.
2551− */
2552− if (!use_dma_chaining) {
2553− if ((tmp & (1 << DMA_TRANSACTION_DONE_INTERRUPT))
2554− == 0) {
2555− DEBUG (ep->dev, "%s no xact done? %08x\n",
2556− ep->ep.name, tmp);
2557− continue;
2558− }
2559− stop_dma (ep->dma);
2560− }
2561−
2562− /* OUT transfers terminate when the data from the
2563− * host is in our memory. Process whatever's done.
2564− * On this path, we know transfer's last packet wasn't
2565− * less than req->length. NAK_OUT_PACKETS may be set,
2566− * or the FIFO may already be holding new packets.
2567− *
2568− * IN transfers can linger in the FIFO for a very
2569− * long time ... we ignore that for now, accounting
2570− * precisely (like PIO does) needs per-packet irqs
2571− */
2572− scan_dma_completions (ep);
2573−
2574− /* disable dma on inactive queues; else maybe restart */
2575− if (list_empty (&ep->queue)) {
2576− if (use_dma_chaining)
2577− stop_dma (ep->dma);
2578− } else {
2579− tmp = readl (&dma->dmactl);
2580− if (!use_dma_chaining
2581− || (tmp & (1 << DMA_ENABLE)) == 0)
2582− restart_dma (ep);
2583− else if (ep->is_in && use_dma_chaining) {
2584− struct net2280_request *req;
2585− __le32 dmacount;
2586−
2587− /* the descriptor at the head of the chain
2588− * may still have VALID_BIT clear; that's
2589− * used to trigger changing DMA_FIFO_VALIDATE
2590− * (affects automagic zlp writes).
2591− */
2592− req = list_entry (ep->queue.next,
2593− struct net2280_request, queue);
2594− dmacount = req->td->dmacount;
2595− dmacount &= cpu_to_le32 (
2596− (1 << VALID_BIT)
2597− | DMA_BYTE_COUNT_MASK);
2598− if (dmacount && (dmacount & valid_bit) == 0)
2599− restart_dma (ep);
2600− }
2601− }
2602− ep->irqs++;
2603− }
2604−
2605− /* NOTE: there are other PCI errors we might usefully notice.
2606− * if they appear very often, here's where to try recovering.
2607− */
2608− if (stat & PCI_ERROR_INTERRUPTS) {
2609− ERROR (dev, "pci dma error; stat %08x\n", stat);
2610− stat &= ~PCI_ERROR_INTERRUPTS;
2611− /* these are fatal errors, but "maybe" they won't
2612− * happen again ...
2613− */
2614− stop_activity (dev, dev->driver);
2615− ep0_start (dev);
2616− stat = 0;
2617− }
2618−
2619− if (stat)
2620− DEBUG (dev, "unhandled irqstat1 %08x\n", stat);
2621−}
2622−
2623−static irqreturn_t net2280_irq (int irq, void *_dev)
2624−{
2625− struct net2280 *dev = _dev;
2626−
2627− /* shared interrupt, not ours */
2628− if (!(readl(&dev->regs->irqstat0) & (1 << INTA_ASSERTED)))
2629− return IRQ_NONE;
2630−
2631− spin_lock (&dev->lock);
2632−
2633− /* handle disconnect, dma, and more */
2634− handle_stat1_irqs (dev, readl (&dev->regs->irqstat1));
2635−
2636− /* control requests and PIO */
2637− handle_stat0_irqs (dev, readl (&dev->regs->irqstat0));
2638−
2639− spin_unlock (&dev->lock);
2640−
2641− return IRQ_HANDLED;
2642−}
2643−
2644−/*-------------------------------------------------------------------------*/
2645−
2646−static void gadget_release (struct device *_dev)
2647−{
2648− struct net2280 *dev = dev_get_drvdata (_dev);
2649−
2650− kfree (dev);
2651−}
2652−
2653−/* tear down the binding between this driver and the pci device */
2654−
2655−static void net2280_remove (struct pci_dev *pdev)
2656−{
2657− struct net2280 *dev = pci_get_drvdata (pdev);
2658−
2659− usb_del_gadget_udc(&dev->gadget);
2660−
2661− BUG_ON(dev->driver);
2662−
2663− /* then clean up the resources we allocated during probe() */
2664− net2280_led_shutdown (dev);
2665− if (dev->requests) {
2666− int i;
2667− for (i = 1; i < 5; i++) {
2668− if (!dev->ep [i].dummy)
2669− continue;
2670− pci_pool_free (dev->requests, dev->ep [i].dummy,
2671− dev->ep [i].td_dma);
2672− }
2673− pci_pool_destroy (dev->requests);
2674− }
2675− if (dev->got_irq)
2676− free_irq (pdev->irq, dev);
2677− if (dev->regs)
2678− iounmap (dev->regs);
2679− if (dev->region)
2680− release_mem_region (pci_resource_start (pdev, 0),
2681− pci_resource_len (pdev, 0));
2682− if (dev->enabled)
2683− pci_disable_device (pdev);
2684− device_remove_file (&pdev->dev, &dev_attr_registers);
2685−
2686− INFO (dev, "unbind\n");
2687−}
2688−
2689−/* wrap this driver around the specified device, but
2690− * don't respond over USB until a gadget driver binds to us.
2691− */
2692−
2693−static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2694−{
2695− struct net2280 *dev;
2696− unsigned long resource, len;
2697− void __iomem *base = NULL;
2698− int retval, i;
2699−
2700− /* alloc, and start init */
2701− dev = kzalloc (sizeof *dev, GFP_KERNEL);
2702− if (dev == NULL){
2703− retval = -ENOMEM;
2704− goto done;
2705− }
2706−
2707− pci_set_drvdata (pdev, dev);
2708− spin_lock_init (&dev->lock);
2709− dev->pdev = pdev;
2710− dev->gadget.ops = &net2280_ops;
2711− dev->gadget.max_speed = USB_SPEED_HIGH;
2712−
2713− /* the "gadget" abstracts/virtualizes the controller */
2714− dev->gadget.name = driver_name;
2715−
2716− /* now all the pci goodies ... */
2717− if (pci_enable_device (pdev) < 0) {
2718− retval = -ENODEV;
2719− goto done;
2720− }
2721− dev->enabled = 1;
2722−
2723− /* BAR 0 holds all the registers
2724− * BAR 1 is 8051 memory; unused here (note erratum 0103)
2725− * BAR 2 is fifo memory; unused here
2726− */
2727− resource = pci_resource_start (pdev, 0);
2728− len = pci_resource_len (pdev, 0);
2729− if (!request_mem_region (resource, len, driver_name)) {
2730− DEBUG (dev, "controller already in use\n");
2731− retval = -EBUSY;
2732− goto done;
2733− }
2734− dev->region = 1;
2735−
2736− /* FIXME provide firmware download interface to put
2737− * 8051 code into the chip, e.g. to turn on PCI PM.
2738− */
2739−
2740− base = ioremap_nocache (resource, len);
2741− if (base == NULL) {
2742− DEBUG (dev, "can't map memory\n");
2743− retval = -EFAULT;
2744− goto done;
2745− }
2746− dev->regs = (struct net2280_regs __iomem *) base;
2747− dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080);
2748− dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100);
2749− dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180);
2750− dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
2751− dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
2752−
2753− /* put into initial config, link up all endpoints */
2754− writel (0, &dev->usb->usbctl);
2755− usb_reset (dev);
2756− usb_reinit (dev);
2757−
2758− /* irq setup after old hardware is cleaned up */
2759− if (!pdev->irq) {
2760− ERROR (dev, "No IRQ. Check PCI setup!\n");
2761− retval = -ENODEV;
2762− goto done;
2763− }
2764−
2765− if (request_irq (pdev->irq, net2280_irq, IRQF_SHARED, driver_name, dev)
2766− != 0) {
2767− ERROR (dev, "request interrupt %d failed\n", pdev->irq);
2768− retval = -EBUSY;
2769− goto done;
2770− }
2771− dev->got_irq = 1;
2772−
2773− /* DMA setup */
2774− /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
2775− dev->requests = pci_pool_create ("requests", pdev,
2776− sizeof (struct net2280_dma),
2777− 0 /* no alignment requirements */,
2778− 0 /* or page-crossing issues */);
2779− if (!dev->requests) {
2780− DEBUG (dev, "can't get request pool\n");
2781− retval = -ENOMEM;
2782− goto done;
2783− }
2784− for (i = 1; i < 5; i++) {
2785− struct net2280_dma *td;
2786−
2787− td = pci_pool_alloc (dev->requests, GFP_KERNEL,
2788− &dev->ep [i].td_dma);
2789− if (!td) {
2790− DEBUG (dev, "can't get dummy %d\n", i);
2791− retval = -ENOMEM;
2792− goto done;
2793− }
2794− td->dmacount = 0; /* not VALID */
2795− td->dmadesc = td->dmaaddr;
2796− dev->ep [i].dummy = td;
2797− }
2798−
2799− /* enable lower-overhead pci memory bursts during DMA */
2800− writel ( (1 << DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE)
2801− // 256 write retries may not be enough...
2802− // | (1 << PCI_RETRY_ABORT_ENABLE)
2803− | (1 << DMA_READ_MULTIPLE_ENABLE)
2804− | (1 << DMA_READ_LINE_ENABLE)
2805− , &dev->pci->pcimstctl);
2806− /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
2807− pci_set_master (pdev);
2808− pci_try_set_mwi (pdev);
2809−
2810− /* ... also flushes any posted pci writes */
2811− dev->chiprev = get_idx_reg (dev->regs, REG_CHIPREV) & 0xffff;
2812−
2813− /* done */
2814− INFO (dev, "%s\n", driver_desc);
2815− INFO (dev, "irq %d, pci mem %p, chip rev %04x\n",
2816− pdev->irq, base, dev->chiprev);
2817− INFO (dev, "version: " DRIVER_VERSION "; dma %s\n",
2818− use_dma
2819− ? (use_dma_chaining ? "chaining" : "enabled")
2820− : "disabled");
2821− retval = device_create_file (&pdev->dev, &dev_attr_registers);
2822− if (retval) goto done;
2823−
2824− retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
2825− gadget_release);
2826− if (retval)
2827− goto done;
2828− return 0;
2829−
2830−done:
2831− if (dev)
2832− net2280_remove (pdev);
2833− return retval;
2834−}
2835−
2836−/* make sure the board is quiescent; otherwise it will continue
2837− * generating IRQs across the upcoming reboot.
2838− */
2839−
2840−static void net2280_shutdown (struct pci_dev *pdev)
2841−{
2842− struct net2280 *dev = pci_get_drvdata (pdev);
2843−
2844− /* disable IRQs */
2845− writel (0, &dev->regs->pciirqenb0);
2846− writel (0, &dev->regs->pciirqenb1);
2847−
2848− /* disable the pullup so the host will think we're gone */
2849− writel (0, &dev->usb->usbctl);
2850−
2851− /* Disable full-speed test mode */
2852− writel(0, &dev->usb->xcvrdiag);
2853−}
2854−
2855−
2856−/*-------------------------------------------------------------------------*/
2857−
2858−static const struct pci_device_id pci_ids [] = { {
2859− .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
2860− .class_mask = ~0,
2861− .vendor = 0x17cc,
2862− .device = 0x2280,
2863− .subvendor = PCI_ANY_ID,
2864− .subdevice = PCI_ANY_ID,
2865−}, {
2866− .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
2867− .class_mask = ~0,
2868− .vendor = 0x17cc,
2869− .device = 0x2282,
2870− .subvendor = PCI_ANY_ID,
2871− .subdevice = PCI_ANY_ID,
2872−
2873−}, { /* end: all zeroes */ }
2874−};
2875−MODULE_DEVICE_TABLE (pci, pci_ids);
2876−
2877−/* pci driver glue; this is a "new style" PCI driver module */
2878−static struct pci_driver net2280_pci_driver = {
2879− .name = (char *) driver_name,
2880− .id_table = pci_ids,
2881−
2882− .probe = net2280_probe,
2883− .remove = net2280_remove,
2884− .shutdown = net2280_shutdown,
2885−
2886− /* FIXME add power management support */
2887−};
2888−
2889−MODULE_DESCRIPTION (DRIVER_DESC);
2890−MODULE_AUTHOR ("David Brownell");
2891−MODULE_LICENSE ("GPL");
2892−
2893−static int __init init (void)
2894−{
2895− if (!use_dma)
2896− use_dma_chaining = 0;
2897− return pci_register_driver (&net2280_pci_driver);
2898−}
2899−module_init (init);
2900−
2901−static void __exit cleanup (void)
2902−{
2903− pci_unregister_driver (&net2280_pci_driver);
2904−}
2905−module_exit (cleanup);
drivers/usb/gadget/net2280.h+0−308
@@ -1,308 +0,0 @@
1−/*
2− * NetChip 2280 high/full speed USB device controller.
3− * Unlike many such controllers, this one talks PCI.
4− */
5−
6−/*
7− * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
8− * Copyright (C) 2003 David Brownell
9− *
10− * This program is free software; you can redistribute it and/or modify
11− * it under the terms of the GNU General Public License as published by
12− * the Free Software Foundation; either version 2 of the License, or
13− * (at your option) any later version.
14− */
15−
16−#include <linux/usb/net2280.h>
17−
18−/*-------------------------------------------------------------------------*/
19−
20−#ifdef __KERNEL__
21−
22−/* indexed registers [11.10] are accessed indirectly
23− * caller must own the device lock.
24− */
25−
26−static inline u32
27−get_idx_reg (struct net2280_regs __iomem *regs, u32 index)
28−{
29− writel (index, &regs->idxaddr);
30− /* NOTE: synchs device/cpu memory views */
31− return readl (&regs->idxdata);
32−}
33−
34−static inline void
35−set_idx_reg (struct net2280_regs __iomem *regs, u32 index, u32 value)
36−{
37− writel (index, &regs->idxaddr);
38− writel (value, &regs->idxdata);
39− /* posted, may not be visible yet */
40−}
41−
42−#endif /* __KERNEL__ */
43−
44−
45−#define REG_DIAG 0x0
46−#define RETRY_COUNTER 16
47−#define FORCE_PCI_SERR 11
48−#define FORCE_PCI_INTERRUPT 10
49−#define FORCE_USB_INTERRUPT 9
50−#define FORCE_CPU_INTERRUPT 8
51−#define ILLEGAL_BYTE_ENABLES 5
52−#define FAST_TIMES 4
53−#define FORCE_RECEIVE_ERROR 2
54−#define FORCE_TRANSMIT_CRC_ERROR 0
55−#define REG_FRAME 0x02 /* from last sof */
56−#define REG_CHIPREV 0x03 /* in bcd */
57−#define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
58−
59−#define CHIPREV_1 0x0100
60−#define CHIPREV_1A 0x0110
61−
62−#ifdef __KERNEL__
63−
64−/* ep a-f highspeed and fullspeed maxpacket, addresses
65− * computed from ep->num
66− */
67−#define REG_EP_MAXPKT(dev,num) (((num) + 1) * 0x10 + \
68− (((dev)->gadget.speed == USB_SPEED_HIGH) ? 0 : 1))
69−
70−/*-------------------------------------------------------------------------*/
71−
72−/* [8.3] for scatter/gather i/o
73− * use struct net2280_dma_regs bitfields
74− */
75−struct net2280_dma {
76− __le32 dmacount;
77− __le32 dmaaddr; /* the buffer */
78− __le32 dmadesc; /* next dma descriptor */
79− __le32 _reserved;
80−} __attribute__ ((aligned (16)));
81−
82−/*-------------------------------------------------------------------------*/
83−
84−/* DRIVER DATA STRUCTURES and UTILITIES */
85−
86−struct net2280_ep {
87− struct usb_ep ep;
88− struct net2280_ep_regs __iomem *regs;
89− struct net2280_dma_regs __iomem *dma;
90− struct net2280_dma *dummy;
91− dma_addr_t td_dma; /* of dummy */
92− struct net2280 *dev;
93− unsigned long irqs;
94−
95− /* analogous to a host-side qh */
96− struct list_head queue;
97− const struct usb_endpoint_descriptor *desc;
98− unsigned num : 8,
99− fifo_size : 12,
100− in_fifo_validate : 1,
101− out_overflow : 1,
102− stopped : 1,
103− wedged : 1,
104− is_in : 1,
105− is_iso : 1,
106− responded : 1;
107−};
108−
109−static inline void allow_status (struct net2280_ep *ep)
110−{
111− /* ep0 only */
112− writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
113− | (1 << CLEAR_NAK_OUT_PACKETS)
114− | (1 << CLEAR_NAK_OUT_PACKETS_MODE)
115− , &ep->regs->ep_rsp);
116− ep->stopped = 1;
117−}
118−
119−/* count (<= 4) bytes in the next fifo write will be valid */
120−static inline void set_fifo_bytecount (struct net2280_ep *ep, unsigned count)
121−{
122− writeb (count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
123−}
124−
125−struct net2280_request {
126− struct usb_request req;
127− struct net2280_dma *td;
128− dma_addr_t td_dma;
129− struct list_head queue;
130− unsigned mapped : 1,
131− valid : 1;
132−};
133−
134−struct net2280 {
135− /* each pci device provides one gadget, several endpoints */
136− struct usb_gadget gadget;
137− spinlock_t lock;
138− struct net2280_ep ep [7];
139− struct usb_gadget_driver *driver;
140− unsigned enabled : 1,
141− protocol_stall : 1,
142− softconnect : 1,
143− got_irq : 1,
144− region : 1;
145− u16 chiprev;
146−
147− /* pci state used to access those endpoints */
148− struct pci_dev *pdev;
149− struct net2280_regs __iomem *regs;
150− struct net2280_usb_regs __iomem *usb;
151− struct net2280_pci_regs __iomem *pci;
152− struct net2280_dma_regs __iomem *dma;
153− struct net2280_dep_regs __iomem *dep;
154− struct net2280_ep_regs __iomem *epregs;
155−
156− struct pci_pool *requests;
157− // statistics...
158−};
159−
160−static inline void set_halt (struct net2280_ep *ep)
161−{
162− /* ep0 and bulk/intr endpoints */
163− writel ( (1 << CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE)
164− /* set NAK_OUT for erratum 0114 */
165− | ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS)
166− | (1 << SET_ENDPOINT_HALT)
167− , &ep->regs->ep_rsp);
168−}
169−
170−static inline void clear_halt (struct net2280_ep *ep)
171−{
172− /* ep0 and bulk/intr endpoints */
173− writel ( (1 << CLEAR_ENDPOINT_HALT)
174− | (1 << CLEAR_ENDPOINT_TOGGLE)
175− /* unless the gadget driver left a short packet in the
176− * fifo, this reverses the erratum 0114 workaround.
177− */
178− | ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS)
179− , &ep->regs->ep_rsp);
180−}
181−
182−#ifdef USE_RDK_LEDS
183−
184−static inline void net2280_led_init (struct net2280 *dev)
185−{
186− /* LED3 (green) is on during USB activity. note erratum 0113. */
187− writel ((1 << GPIO3_LED_SELECT)
188− | (1 << GPIO3_OUTPUT_ENABLE)
189− | (1 << GPIO2_OUTPUT_ENABLE)
190− | (1 << GPIO1_OUTPUT_ENABLE)
191− | (1 << GPIO0_OUTPUT_ENABLE)
192− , &dev->regs->gpioctl);
193−}
194−
195−/* indicate speed with bi-color LED 0/1 */
196−static inline
197−void net2280_led_speed (struct net2280 *dev, enum usb_device_speed speed)
198−{
199− u32 val = readl (&dev->regs->gpioctl);
200− switch (speed) {
201− case USB_SPEED_HIGH: /* green */
202− val &= ~(1 << GPIO0_DATA);
203− val |= (1 << GPIO1_DATA);
204− break;
205− case USB_SPEED_FULL: /* red */
206− val &= ~(1 << GPIO1_DATA);
207− val |= (1 << GPIO0_DATA);
208− break;
209− default: /* (off/black) */
210− val &= ~((1 << GPIO1_DATA) | (1 << GPIO0_DATA));
211− break;
212− }
213− writel (val, &dev->regs->gpioctl);
214−}
215−
216−/* indicate power with LED 2 */
217−static inline void net2280_led_active (struct net2280 *dev, int is_active)
218−{
219− u32 val = readl (&dev->regs->gpioctl);
220−
221− // FIXME this LED never seems to turn on.
222− if (is_active)
223− val |= GPIO2_DATA;
224− else
225− val &= ~GPIO2_DATA;
226− writel (val, &dev->regs->gpioctl);
227−}
228−static inline void net2280_led_shutdown (struct net2280 *dev)
229−{
230− /* turn off all four GPIO*_DATA bits */
231− writel (readl (&dev->regs->gpioctl) & ~0x0f,
232− &dev->regs->gpioctl);
233−}
234−
235−#else
236−
237−#define net2280_led_init(dev) do { } while (0)
238−#define net2280_led_speed(dev, speed) do { } while (0)
239−#define net2280_led_shutdown(dev) do { } while (0)
240−
241−#endif
242−
243−/*-------------------------------------------------------------------------*/
244−
245−#define xprintk(dev,level,fmt,args...) \
246− printk(level "%s %s: " fmt , driver_name , \
247− pci_name(dev->pdev) , ## args)
248−
249−#ifdef DEBUG
250−#undef DEBUG
251−#define DEBUG(dev,fmt,args...) \
252− xprintk(dev , KERN_DEBUG , fmt , ## args)
253−#else
254−#define DEBUG(dev,fmt,args...) \
255− do { } while (0)
256−#endif /* DEBUG */
257−
258−#ifdef VERBOSE
259−#define VDEBUG DEBUG
260−#else
261−#define VDEBUG(dev,fmt,args...) \
262− do { } while (0)
263−#endif /* VERBOSE */
264−
265−#define ERROR(dev,fmt,args...) \
266− xprintk(dev , KERN_ERR , fmt , ## args)
267−#define WARNING(dev,fmt,args...) \
268− xprintk(dev , KERN_WARNING , fmt , ## args)
269−#define INFO(dev,fmt,args...) \
270− xprintk(dev , KERN_INFO , fmt , ## args)
271−
272−/*-------------------------------------------------------------------------*/
273−
274−static inline void start_out_naking (struct net2280_ep *ep)
275−{
276− /* NOTE: hardware races lurk here, and PING protocol issues */
277− writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
278− /* synch with device */
279− readl (&ep->regs->ep_rsp);
280−}
281−
282−#ifdef DEBUG
283−static inline void assert_out_naking (struct net2280_ep *ep, const char *where)
284−{
285− u32 tmp = readl (&ep->regs->ep_stat);
286−
287− if ((tmp & (1 << NAK_OUT_PACKETS)) == 0) {
288− DEBUG (ep->dev, "%s %s %08x !NAK\n",
289− ep->ep.name, where, tmp);
290− writel ((1 << SET_NAK_OUT_PACKETS),
291− &ep->regs->ep_rsp);
292− }
293−}
294−#define ASSERT_OUT_NAKING(ep) assert_out_naking(ep,__func__)
295−#else
296−#define ASSERT_OUT_NAKING(ep) do {} while (0)
297−#endif
298−
299−static inline void stop_out_naking (struct net2280_ep *ep)
300−{
301− u32 tmp;
302−
303− tmp = readl (&ep->regs->ep_stat);
304− if ((tmp & (1 << NAK_OUT_PACKETS)) != 0)
305− writel ((1 << CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
306−}
307−
308−#endif /* __KERNEL__ */
drivers/usb/gadget/u_os_desc.h+46−13
@@ -35,27 +35,63 @@ · 34 unmodified lines
3535 #define USB_EXT_PROP_UNICODE_LINK 6
3636 #define USB_EXT_PROP_UNICODE_MULTI 7
3737
38+static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset)
39+{
40+ return buf + offset;
41+}
42+
43+static inline u8 *usb_ext_prop_size_ptr(u8 *buf)
44+{
45+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE);
46+}
47+
48+static inline u8 *usb_ext_prop_type_ptr(u8 *buf)
49+{
50+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE);
51+}
52+
53+static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf)
54+{
55+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH);
56+}
57+
58+static inline u8 *usb_ext_prop_name_ptr(u8 *buf)
59+{
60+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME);
61+}
62+
63+static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off)
64+{
65+ return __usb_ext_prop_ptr(buf,
66+ USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off);
67+}
68+
69+static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off)
70+{
71+ return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off);
72+}
73+
3874 static inline void usb_ext_prop_put_size(u8 *buf, int dw_size)
3975 {
40− put_unaligned_le32(dw_size, &buf[USB_EXT_PROP_DW_SIZE]);
76+ put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf));
4177 }
4278
4379 static inline void usb_ext_prop_put_type(u8 *buf, int type)
4480 {
45− put_unaligned_le32(type, &buf[USB_EXT_PROP_DW_PROPERTY_DATA_TYPE]);
81+ put_unaligned_le32(type, usb_ext_prop_type_ptr(buf));
4682 }
4783
4884 static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl)
4985 {
5086 int result;
5187
52− put_unaligned_le16(pnl, &buf[USB_EXT_PROP_W_PROPERTY_NAME_LENGTH]);
88+ put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf));
5389 result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN,
54− (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_NAME], pnl - 2);
90+ (wchar_t *) usb_ext_prop_name_ptr(buf), pnl - 2);
5591 if (result < 0)
5692 return result;
5793
58− put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl]);
94+ put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]);
5995
6096 return pnl;
6197 }
@@ -63,26 +99,23 @@ static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) · 1 unmodified line
6399 static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data,
64100 int data_len)
65101 {
66− put_unaligned_le32(data_len,
67− &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]);
68− memcpy(&buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], data, data_len);
102+ put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
103+ memcpy(usb_ext_prop_data_ptr(buf, pnl), data, data_len);
69104 }
70105
71106 static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string,
72107 int data_len)
73108 {
74109 int result;
75− put_unaligned_le32(data_len,
76− &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]);
77−
110+ put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
78111 result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN,
79− (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl],
112+ (wchar_t *) usb_ext_prop_data_ptr(buf, pnl),
80113 data_len - 2);
81114 if (result < 0)
82115 return result;
83116
84117 put_unaligned_le16(0,
85− &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len]);
118+ &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]);
86119
87120 return data_len;
88121 }
drivers/usb/gadget/udc/Kconfig+385−0
@@ -0,0 +1,385 @@
1+#
2+# USB Gadget support on a system involves
3+# (a) a peripheral controller, and
4+# (b) the gadget driver using it.
5+#
6+# NOTE: Gadget support ** DOES NOT ** depend on host-side CONFIG_USB !!
7+#
8+# - Host systems (like PCs) need CONFIG_USB (with "A" jacks).
9+# - Peripherals (like PDAs) need CONFIG_USB_GADGET (with "B" jacks).
10+# - Some systems have both kinds of controllers.
11+#
12+# With help from a special transceiver and a "Mini-AB" jack, systems with
13+# both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG).
14+#
15+
16+#
17+# USB Peripheral Controller Support
18+#
19+# The order here is alphabetical, except that integrated controllers go
20+# before discrete ones so they will be the initial/default value:
21+# - integrated/SOC controllers first
22+# - licensed IP used in both SOC and discrete versions
23+# - discrete ones (including all PCI-only controllers)
24+# - debug/dummy gadget+hcd is last.
25+#
26+menu "USB Peripheral Controller"
27+
28+#
29+# Integrated controllers
30+#
31+
32+config USB_AT91
33+ tristate "Atmel AT91 USB Device Port"
34+ depends on ARCH_AT91
35+ help
36+ Many Atmel AT91 processors (such as the AT91RM2000) have a
37+ full speed USB Device Port with support for five configurable
38+ endpoints (plus endpoint zero).
39+
40+ Say "y" to link the driver statically, or "m" to build a
41+ dynamically linked module called "at91_udc" and force all
42+ gadget drivers to also be dynamically linked.
43+
44+config USB_LPC32XX
45+ tristate "LPC32XX USB Peripheral Controller"
46+ depends on ARCH_LPC32XX && I2C
47+ select USB_ISP1301
48+ help
49+ This option selects the USB device controller in the LPC32xx SoC.
50+
51+ Say "y" to link the driver statically, or "m" to build a
52+ dynamically linked module called "lpc32xx_udc" and force all
53+ gadget drivers to also be dynamically linked.
54+
55+config USB_ATMEL_USBA
56+ tristate "Atmel USBA"
57+ depends on AVR32 || ARCH_AT91
58+ help
59+ USBA is the integrated high-speed USB Device controller on
60+ the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
61+
62+config USB_BCM63XX_UDC
63+ tristate "Broadcom BCM63xx Peripheral Controller"
64+ depends on BCM63XX
65+ help
66+ Many Broadcom BCM63xx chipsets (such as the BCM6328) have a
67+ high speed USB Device Port with support for four fixed endpoints
68+ (plus endpoint zero).
69+
70+ Say "y" to link the driver statically, or "m" to build a
71+ dynamically linked module called "bcm63xx_udc".
72+
73+config USB_FSL_USB2
74+ tristate "Freescale Highspeed USB DR Peripheral Controller"
75+ depends on FSL_SOC || ARCH_MXC
76+ select USB_FSL_MPH_DR_OF if OF
77+ help
78+ Some of Freescale PowerPC and i.MX processors have a High Speed
79+ Dual-Role(DR) USB controller, which supports device mode.
80+
81+ The number of programmable endpoints is different through
82+ SOC revisions.
83+
84+ Say "y" to link the driver statically, or "m" to build a
85+ dynamically linked module called "fsl_usb2_udc" and force
86+ all gadget drivers to also be dynamically linked.
87+
88+config USB_FUSB300
89+ tristate "Faraday FUSB300 USB Peripheral Controller"
90+ depends on !PHYS_ADDR_T_64BIT && HAS_DMA
91+ help
92+ Faraday usb device controller FUSB300 driver
93+
94+config USB_FOTG210_UDC
95+ depends on HAS_DMA
96+ tristate "Faraday FOTG210 USB Peripheral Controller"
97+ help
98+ Faraday USB2.0 OTG controller which can be configured as
99+ high speed or full speed USB device. This driver supppors
100+ Bulk Transfer so far.
101+
102+ Say "y" to link the driver statically, or "m" to build a
103+ dynamically linked module called "fotg210_udc".
104+
105+config USB_GR_UDC
106+ tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver"
107+ depends on HAS_DMA
108+ help
109+ Select this to support Aeroflex Gaisler GRUSBDC cores from the GRLIB
110+ VHDL IP core library.
111+
112+config USB_OMAP
113+ tristate "OMAP USB Device Controller"
114+ depends on ARCH_OMAP1
115+ depends on ISP1301_OMAP || !(MACH_OMAP_H2 || MACH_OMAP_H3)
116+ help
117+ Many Texas Instruments OMAP processors have flexible full
118+ speed USB device controllers, with support for up to 30
119+ endpoints (plus endpoint zero). This driver supports the
120+ controller in the OMAP 1611, and should work with controllers
121+ in other OMAP processors too, given minor tweaks.
122+
123+ Say "y" to link the driver statically, or "m" to build a
124+ dynamically linked module called "omap_udc" and force all
125+ gadget drivers to also be dynamically linked.
126+
127+config USB_PXA25X
128+ tristate "PXA 25x or IXP 4xx"
129+ depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
130+ help
131+ Intel's PXA 25x series XScale ARM-5TE processors include
132+ an integrated full speed USB 1.1 device controller. The
133+ controller in the IXP 4xx series is register-compatible.
134+
135+ It has fifteen fixed-function endpoints, as well as endpoint
136+ zero (for control transfers).
137+
138+ Say "y" to link the driver statically, or "m" to build a
139+ dynamically linked module called "pxa25x_udc" and force all
140+ gadget drivers to also be dynamically linked.
141+
142+# if there's only one gadget driver, using only two bulk endpoints,
143+# don't waste memory for the other endpoints
144+config USB_PXA25X_SMALL
145+ depends on USB_PXA25X
146+ bool
147+ default n if USB_ETH_RNDIS
148+ default y if USB_ZERO
149+ default y if USB_ETH
150+ default y if USB_G_SERIAL
151+
152+config USB_R8A66597
153+ tristate "Renesas R8A66597 USB Peripheral Controller"
154+ depends on HAS_DMA
155+ help
156+ R8A66597 is a discrete USB host and peripheral controller chip that
157+ supports both full and high speed USB 2.0 data transfers.
158+ It has nine configurable endpoints, and endpoint zero.
159+
160+ Say "y" to link the driver statically, or "m" to build a
161+ dynamically linked module called "r8a66597_udc" and force all
162+ gadget drivers to also be dynamically linked.
163+
164+config USB_RENESAS_USBHS_UDC
165+ tristate 'Renesas USBHS controller'
166+ depends on USB_RENESAS_USBHS
167+ help
168+ Renesas USBHS is a discrete USB host and peripheral controller chip
169+ that supports both full and high speed USB 2.0 data transfers.
170+ It has nine or more configurable endpoints, and endpoint zero.
171+
172+ Say "y" to link the driver statically, or "m" to build a
173+ dynamically linked module called "renesas_usbhs" and force all
174+ gadget drivers to also be dynamically linked.
175+
176+config USB_PXA27X
177+ tristate "PXA 27x"
178+ help
179+ Intel's PXA 27x series XScale ARM v5TE processors include
180+ an integrated full speed USB 1.1 device controller.
181+
182+ It has up to 23 endpoints, as well as endpoint zero (for
183+ control transfers).
184+
185+ Say "y" to link the driver statically, or "m" to build a
186+ dynamically linked module called "pxa27x_udc" and force all
187+ gadget drivers to also be dynamically linked.
188+
189+config USB_S3C2410
190+ tristate "S3C2410 USB Device Controller"
191+ depends on ARCH_S3C24XX
192+ help
193+ Samsung's S3C2410 is an ARM-4 processor with an integrated
194+ full speed USB 1.1 device controller. It has 4 configurable
195+ endpoints, as well as endpoint zero (for control transfers).
196+
197+ This driver has been tested on the S3C2410, S3C2412, and
198+ S3C2440 processors.
199+
200+config USB_S3C2410_DEBUG
201+ boolean "S3C2410 udc debug messages"
202+ depends on USB_S3C2410
203+
204+config USB_S3C_HSUDC
205+ tristate "S3C2416, S3C2443 and S3C2450 USB Device Controller"
206+ depends on ARCH_S3C24XX
207+ help
208+ Samsung's S3C2416, S3C2443 and S3C2450 is an ARM9 based SoC
209+ integrated with dual speed USB 2.0 device controller. It has
210+ 8 endpoints, as well as endpoint zero.
211+
212+ This driver has been tested on S3C2416 and S3C2450 processors.
213+
214+config USB_MV_UDC
215+ tristate "Marvell USB2.0 Device Controller"
216+ depends on HAS_DMA
217+ help
218+ Marvell Socs (including PXA and MMP series) include a high speed
219+ USB2.0 OTG controller, which can be configured as high speed or
220+ full speed USB peripheral.
221+
222+config USB_MV_U3D
223+ depends on HAS_DMA
224+ tristate "MARVELL PXA2128 USB 3.0 controller"
225+ help
226+ MARVELL PXA2128 Processor series include a super speed USB3.0 device
227+ controller, which support super speed USB peripheral.
228+
229+#
230+# Controllers available in both integrated and discrete versions
231+#
232+
233+config USB_M66592
234+ tristate "Renesas M66592 USB Peripheral Controller"
235+ help
236+ M66592 is a discrete USB peripheral controller chip that
237+ supports both full and high speed USB 2.0 data transfers.
238+ It has seven configurable endpoints, and endpoint zero.
239+
240+ Say "y" to link the driver statically, or "m" to build a
241+ dynamically linked module called "m66592_udc" and force all
242+ gadget drivers to also be dynamically linked.
243+
244+#
245+# Controllers available only in discrete form (and all PCI controllers)
246+#
247+
248+config USB_AMD5536UDC
249+ tristate "AMD5536 UDC"
250+ depends on PCI
251+ help
252+ The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
253+ It is a USB Highspeed DMA capable USB device controller. Beside ep0
254+ it provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
255+ The UDC port supports OTG operation, and may be used as a host port
256+ if it's not being used to implement peripheral or OTG roles.
257+
258+ Say "y" to link the driver statically, or "m" to build a
259+ dynamically linked module called "amd5536udc" and force all
260+ gadget drivers to also be dynamically linked.
261+
262+config USB_FSL_QE
263+ tristate "Freescale QE/CPM USB Device Controller"
264+ depends on FSL_SOC && (QUICC_ENGINE || CPM)
265+ help
266+ Some of Freescale PowerPC processors have a Full Speed
267+ QE/CPM2 USB controller, which support device mode with 4
268+ programmable endpoints. This driver supports the
269+ controller in the MPC8360 and MPC8272, and should work with
270+ controllers having QE or CPM2, given minor tweaks.
271+
272+ Set CONFIG_USB_GADGET to "m" to build this driver as a
273+ dynamically linked module called "fsl_qe_udc".
274+
275+config USB_NET2272
276+ tristate "PLX NET2272"
277+ help
278+ PLX NET2272 is a USB peripheral controller which supports
279+ both full and high speed USB 2.0 data transfers.
280+
281+ It has three configurable endpoints, as well as endpoint zero
282+ (for control transfer).
283+ Say "y" to link the driver statically, or "m" to build a
284+ dynamically linked module called "net2272" and force all
285+ gadget drivers to also be dynamically linked.
286+
287+config USB_NET2272_DMA
288+ boolean "Support external DMA controller"
289+ depends on USB_NET2272 && HAS_DMA
290+ help
291+ The NET2272 part can optionally support an external DMA
292+ controller, but your board has to have support in the
293+ driver itself.
294+
295+ If unsure, say "N" here. The driver works fine in PIO mode.
296+
297+config USB_NET2280
298+ tristate "NetChip 228x / PLX USB338x"
299+ depends on PCI
300+ help
301+ NetChip 2280 / 2282 is a PCI based USB peripheral controller which
302+ supports both full and high speed USB 2.0 data transfers.
303+
304+ It has six configurable endpoints, as well as endpoint zero
305+ (for control transfers) and several endpoints with dedicated
306+ functions.
307+
308+ PLX 3380 / 3382 is a PCIe based USB peripheral controller which
309+ supports full, high speed USB 2.0 and super speed USB 3.0
310+ data transfers.
311+
312+ It has eight configurable endpoints, as well as endpoint zero
313+ (for control transfers) and several endpoints with dedicated
314+ functions.
315+
316+ Say "y" to link the driver statically, or "m" to build a
317+ dynamically linked module called "net2280" and force all
318+ gadget drivers to also be dynamically linked.
319+
320+config USB_GOKU
321+ tristate "Toshiba TC86C001 'Goku-S'"
322+ depends on PCI
323+ help
324+ The Toshiba TC86C001 is a PCI device which includes controllers
325+ for full speed USB devices, IDE, I2C, SIO, plus a USB host (OHCI).
326+
327+ The device controller has three configurable (bulk or interrupt)
328+ endpoints, plus endpoint zero (for control transfers).
329+
330+ Say "y" to link the driver statically, or "m" to build a
331+ dynamically linked module called "goku_udc" and to force all
332+ gadget drivers to also be dynamically linked.
333+
334+config USB_EG20T
335+ tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC"
336+ depends on PCI
337+ help
338+ This is a USB device driver for EG20T PCH.
339+ EG20T PCH is the platform controller hub that is used in Intel's
340+ general embedded platform. EG20T PCH has USB device interface.
341+ Using this interface, it is able to access system devices connected
342+ to USB device.
343+ This driver enables USB device function.
344+ USB device is a USB peripheral controller which
345+ supports both full and high speed USB 2.0 data transfers.
346+ This driver supports both control transfer and bulk transfer modes.
347+ This driver dose not support interrupt transfer or isochronous
348+ transfer modes.
349+
350+ This driver also can be used for LAPIS Semiconductor's ML7213 which is
351+ for IVI(In-Vehicle Infotainment) use.
352+ ML7831 is for general purpose use.
353+ ML7213/ML7831 is companion chip for Intel Atom E6xx series.
354+ ML7213/ML7831 is completely compatible for Intel EG20T PCH.
355+
356+#
357+# LAST -- dummy/emulated controller
358+#
359+
360+config USB_DUMMY_HCD
361+ tristate "Dummy HCD (DEVELOPMENT)"
362+ depends on USB=y || (USB=m && USB_GADGET=m)
363+ help
364+ This host controller driver emulates USB, looping all data transfer
365+ requests back to a USB "gadget driver" in the same host. The host
366+ side is the master; the gadget side is the slave. Gadget drivers
367+ can be high, full, or low speed; and they have access to endpoints
368+ like those from NET2280, PXA2xx, or SA1100 hardware.
369+
370+ This may help in some stages of creating a driver to embed in a
371+ Linux device, since it lets you debug several parts of the gadget
372+ driver without its hardware or drivers being involved.
373+
374+ Since such a gadget side driver needs to interoperate with a host
375+ side Linux-USB device driver, this may help to debug both sides
376+ of a USB protocol stack.
377+
378+ Say "y" to link the driver statically, or "m" to build a
379+ dynamically linked module called "dummy_hcd" and force all
380+ gadget drivers to also be dynamically linked.
381+
382+# NOTE: Please keep dummy_hcd LAST so that "real hardware" appears
383+# first and will be selected by default.
384+
385+endmenu
drivers/usb/gadget/udc/Makefile+31−0
@@ -0,0 +1,31 @@
1+#
2+# USB peripheral controller drivers
3+#
4+obj-$(CONFIG_USB_GADGET) += udc-core.o
5+obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
6+obj-$(CONFIG_USB_NET2272) += net2272.o
7+obj-$(CONFIG_USB_NET2280) += net2280.o
8+obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o
9+obj-$(CONFIG_USB_PXA25X) += pxa25x_udc.o
10+obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o
11+obj-$(CONFIG_USB_GOKU) += goku_udc.o
12+obj-$(CONFIG_USB_OMAP) += omap_udc.o
13+obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
14+obj-$(CONFIG_USB_AT91) += at91_udc.o
15+obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
16+obj-$(CONFIG_USB_BCM63XX_UDC) += bcm63xx_udc.o
17+obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
18+fsl_usb2_udc-y := fsl_udc_core.o
19+fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o
20+obj-$(CONFIG_USB_M66592) += m66592-udc.o
21+obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o
22+obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o
23+obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o
24+obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o
25+obj-$(CONFIG_USB_EG20T) += pch_udc.o
26+obj-$(CONFIG_USB_MV_UDC) += mv_udc.o
27+mv_udc-y := mv_udc_core.o
28+obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
29+obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
30+obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
31+obj-$(CONFIG_USB_GR_UDC) += gr_udc.o
drivers/usb/gadget/udc/amd5536udc.crenamed from drivers/usb/gadget/amd5536udc.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/amd5536udc.hrenamed from drivers/usb/gadget/amd5536udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/at91_udc.crenamed from drivers/usb/gadget/at91_udc.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/at91_udc.hrenamed from drivers/usb/gadget/at91_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/atmel_usba_udc.crenamed from drivers/usb/gadget/atmel_usba_udc.c+1−1
@@ -1979,7 +1979,7 @@ static struct usba_ep * usba_udc_pdata(struct platform_device *pdev, · 1978 unmodified lines
19791979 return eps;
19801980 }
19811981
1982−static int __init usba_udc_probe(struct platform_device *pdev)
1982+static int usba_udc_probe(struct platform_device *pdev)
19831983 {
19841984 struct resource *regs, *fifo;
19851985 struct clk *pclk, *hclk;
drivers/usb/gadget/udc/atmel_usba_udc.hrenamed from drivers/usb/gadget/atmel_usba_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/bcm63xx_udc.crenamed from drivers/usb/gadget/bcm63xx_udc.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/dummy_hcd.crenamed from drivers/usb/gadget/dummy_hcd.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/fotg210-udc.crenamed from drivers/usb/gadget/fotg210-udc.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/fotg210.hrenamed from drivers/usb/gadget/fotg210.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/fsl_mxc_udc.crenamed from drivers/usb/gadget/fsl_mxc_udc.c+2−0
@@ -18,6 +18,8 @@ · 17 unmodified lines
1818 #include <linux/platform_device.h>
1919 #include <linux/io.h>
2020
21+#include "fsl_usb2_udc.h"
22+
2123 static struct clk *mxc_ahb_clk;
2224 static struct clk *mxc_per_clk;
2325 static struct clk *mxc_ipg_clk;
drivers/usb/gadget/udc/fsl_qe_udc.crenamed from drivers/usb/gadget/fsl_qe_udc.c+7−12
@@ -2539,7 +2539,7 @@ static int qe_udc_probe(struct platform_device *ofdev) · 2538 unmodified lines
25392539 goto err2;
25402540
25412541 /* create a buf for ZLP send, need to remain zeroed */
2542− udc->nullbuf = kzalloc(256, GFP_KERNEL);
2542+ udc->nullbuf = devm_kzalloc(&ofdev->dev, 256, GFP_KERNEL);
25432543 if (udc->nullbuf == NULL) {
25442544 dev_err(udc->dev, "cannot alloc nullbuf\n");
25452545 ret = -ENOMEM;
@@ -2547,10 +2547,10 @@ static int qe_udc_probe(struct platform_device *ofdev) · 1 unmodified line
25472547 }
25482548
25492549 /* buffer for data of get_status request */
2550− udc->statusbuf = kzalloc(2, GFP_KERNEL);
2550+ udc->statusbuf = devm_kzalloc(&ofdev->dev, 2, GFP_KERNEL);
25512551 if (udc->statusbuf == NULL) {
25522552 ret = -ENOMEM;
2553− goto err4;
2553+ goto err3;
25542554 }
25552555
25562556 udc->nullp = virt_to_phys((void *)udc->nullbuf);
@@ -2581,13 +2581,13 @@ static int qe_udc_probe(struct platform_device *ofdev) · 24 unmodified lines
25812581 if (ret) {
25822582 dev_err(udc->dev, "cannot request irq %d err %d\n",
25832583 udc->usb_irq, ret);
2584− goto err5;
2584+ goto err4;
25852585 }
25862586
25872587 ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget,
25882588 qe_udc_release);
25892589 if (ret)
2590− goto err6;
2590+ goto err5;
25912591
25922592 platform_set_drvdata(ofdev, udc);
25932593 dev_info(udc->dev,
@@ -2595,9 +2595,9 @@ static int qe_udc_probe(struct platform_device *ofdev) · 1 unmodified line
25952595 (udc->soc_type == PORT_QE) ? "QE" : "CPM");
25962596 return 0;
25972597
2598−err6:
2599− free_irq(udc->usb_irq, udc);
26002598 err5:
2599+ free_irq(udc->usb_irq, udc);
2600+err4:
26012601 irq_dispose_mapping(udc->usb_irq);
26022602 err_noirq:
26032603 if (udc->nullmap) {
@@ -2610,9 +2610,6 @@ err_noirq: · 6 unmodified lines
26102610 udc->nullp, 256,
26112611 DMA_TO_DEVICE);
26122612 }
2613− kfree(udc->statusbuf);
2614−err4:
2615− kfree(udc->nullbuf);
26162613 err3:
26172614 ep = &udc->eps[0];
26182615 cpm_muram_free(cpm_muram_offset(ep->rxbase));
@@ -2660,8 +2657,6 @@ static int qe_udc_remove(struct platform_device *ofdev) · 41 unmodified lines
26602657 udc->nullp, 256,
26612658 DMA_TO_DEVICE);
26622659 }
2663− kfree(udc->statusbuf);
2664− kfree(udc->nullbuf);
26652660
26662661 ep = &udc->eps[0];
26672662 cpm_muram_free(cpm_muram_offset(ep->rxbase));
drivers/usb/gadget/udc/fsl_qe_udc.hrenamed from drivers/usb/gadget/fsl_qe_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/fsl_udc_core.crenamed from drivers/usb/gadget/fsl_udc_core.c+11−8
@@ -59,9 +59,9 @@ · 58 unmodified lines
5959 static const char driver_name[] = "fsl-usb2-udc";
6060 static const char driver_desc[] = DRIVER_DESC;
6161
62−static struct usb_dr_device *dr_regs;
62+static struct usb_dr_device __iomem *dr_regs;
6363
64−static struct usb_sys_interface *usb_sys_regs;
64+static struct usb_sys_interface __iomem *usb_sys_regs;
6565
6666 /* it is initialized in probe() */
6767 static struct fsl_udc *udc_controller = NULL;
@@ -159,6 +159,8 @@ static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata) {} · 91 unmodified lines
159159 * request is still in progress.
160160 *--------------------------------------------------------------*/
161161 static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
162+__releases(ep->udc->lock)
163+__acquires(ep->udc->lock)
162164 {
163165 struct fsl_udc *udc = NULL;
164166 unsigned char stopped = ep->stopped;
@@ -1392,6 +1394,8 @@ stall: · 1227 unmodified lines
13921394
13931395 static void setup_received_irq(struct fsl_udc *udc,
13941396 struct usb_ctrlrequest *setup)
1397+__releases(udc->lock)
1398+__acquires(udc->lock)
13951399 {
13961400 u16 wValue = le16_to_cpu(setup->wValue);
13971401 u16 wIndex = le16_to_cpu(setup->wIndex);
@@ -1957,8 +1961,7 @@ static int fsl_udc_start(struct usb_gadget *g, · 559 unmodified lines
19571961 &udc_controller->gadget);
19581962 if (retval < 0) {
19591963 ERR("can't bind to transceiver\n");
1960− driver->unbind(&udc_controller->gadget);
1961− udc_controller->driver = 0;
1964+ udc_controller->driver = NULL;
19621965 return retval;
19631966 }
19641967 }
@@ -2246,7 +2249,7 @@ static void fsl_udc_release(struct device *dev) · 281 unmodified lines
22462249 * init resource for globle controller
22472250 * Return the udc handle on success or NULL on failure
22482251 ------------------------------------------------------------------*/
2249−static int __init struct_udc_setup(struct fsl_udc *udc,
2252+static int struct_udc_setup(struct fsl_udc *udc,
22502253 struct platform_device *pdev)
22512254 {
22522255 struct fsl_usb2_platform_data *pdata;
@@ -2298,7 +2301,7 @@ static int __init struct_udc_setup(struct fsl_udc *udc, · 45 unmodified lines
22982301 * ep0out is not used so do nothing here
22992302 * ep0in should be taken care
23002303 *--------------------------------------------------------------*/
2301−static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index,
2304+static int struct_ep_setup(struct fsl_udc *udc, unsigned char index,
23022305 char *name, int link)
23032306 {
23042307 struct fsl_ep *ep = &udc->eps[index];
@@ -2331,7 +2334,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index, · 26 unmodified lines
23312334 * all intialization operations implemented here except enabling usb_intr reg
23322335 * board setup should have been done in the platform code
23332336 */
2334−static int __init fsl_udc_probe(struct platform_device *pdev)
2337+static int fsl_udc_probe(struct platform_device *pdev)
23352338 {
23362339 struct fsl_usb2_platform_data *pdata;
23372340 struct resource *res;
@@ -2380,7 +2383,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev) · 42 unmodified lines
23802383 goto err_release_mem_region;
23812384 }
23822385
2383− pdata->regs = (void *)dr_regs;
2386+ pdata->regs = (void __iomem *)dr_regs;
23842387
23852388 /*
23862389 * do platform specific init: check the clock, grab/config pins, etc.
drivers/usb/gadget/udc/fsl_usb2_udc.hrenamed from drivers/usb/gadget/fsl_usb2_udc.h+3−0
@@ -12,6 +12,9 @@ · 11 unmodified lines
1212 #ifndef __FSL_USB2_UDC_H
1313 #define __FSL_USB2_UDC_H
1414
15+#include <linux/usb/ch9.h>
16+#include <linux/usb/gadget.h>
17+
1518 /* ### define USB registers here
1619 */
1720 #define USB_MAX_CTRL_PAYLOAD 64
drivers/usb/gadget/udc/fusb300_udc.crenamed from drivers/usb/gadget/fusb300_udc.c+1−3
@@ -1325,8 +1325,6 @@ static int fusb300_udc_stop(struct usb_gadget *g, · 1324 unmodified lines
13251325 {
13261326 struct fusb300 *fusb300 = to_fusb300(g);
13271327
1328− driver->unbind(&fusb300->gadget);
1329−
13301328 init_controller(fusb300);
13311329 fusb300->driver = NULL;
13321330
@@ -1359,7 +1357,7 @@ static int __exit fusb300_remove(struct platform_device *pdev) · 26 unmodified lines
13591357 return 0;
13601358 }
13611359
1362−static int __init fusb300_probe(struct platform_device *pdev)
1360+static int fusb300_probe(struct platform_device *pdev)
13631361 {
13641362 struct resource *res, *ires, *ires1;
13651363 void __iomem *reg = NULL;
drivers/usb/gadget/udc/fusb300_udc.hrenamed from drivers/usb/gadget/fusb300_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/gadget_chips.hrenamed from drivers/usb/gadget/gadget_chips.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/goku_udc.crenamed from drivers/usb/gadget/goku_udc.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/goku_udc.hrenamed from drivers/usb/gadget/goku_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/gr_udc.crenamed from drivers/usb/gadget/gr_udc.c+1−1
@@ -2213,7 +2213,7 @@ out: · 2212 unmodified lines
22132213 return retval;
22142214 }
22152215
2216−static struct of_device_id gr_match[] = {
2216+static const struct of_device_id gr_match[] = {
22172217 {.name = "GAISLER_USBDC"},
22182218 {.name = "01_021"},
22192219 {},
drivers/usb/gadget/udc/gr_udc.hrenamed from drivers/usb/gadget/gr_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/lpc32xx_udc.crenamed from drivers/usb/gadget/lpc32xx_udc.c+3−4
@@ -3036,7 +3036,7 @@ struct lpc32xx_usbd_cfg lpc32xx_usbddata = { · 3035 unmodified lines
30363036
30373037 static u64 lpc32xx_usbd_dmamask = ~(u32) 0x7F;
30383038
3039−static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3039+static int lpc32xx_udc_probe(struct platform_device *pdev)
30403040 {
30413041 struct device *dev = &pdev->dev;
30423042 struct lpc32xx_udc *udc;
@@ -3045,11 +3045,10 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev) · 2 unmodified lines
30453045 dma_addr_t dma_handle;
30463046 struct device_node *isp1301_node;
30473047
3048− udc = kzalloc(sizeof(*udc), GFP_KERNEL);
3048+ udc = kmemdup(&controller_template, sizeof(*udc), GFP_KERNEL);
30493049 if (!udc)
30503050 return -ENOMEM;
30513051
3052− memcpy(udc, &controller_template, sizeof(*udc));
30533052 for (i = 0; i <= 15; i++)
30543053 udc->ep[i].udc = udc;
30553054 udc->gadget.ep0 = &udc->ep[0].ep;
@@ -3397,7 +3396,7 @@ static int lpc32xx_udc_resume(struct platform_device *pdev) · 341 unmodified lines
33973396 #endif
33983397
33993398 #ifdef CONFIG_OF
3400−static struct of_device_id lpc32xx_udc_of_match[] = {
3399+static const struct of_device_id lpc32xx_udc_of_match[] = {
34013400 { .compatible = "nxp,lpc3220-udc", },
34023401 { },
34033402 };
drivers/usb/gadget/udc/m66592-udc.crenamed from drivers/usb/gadget/m66592-udc.c+1−3
@@ -1492,8 +1492,6 @@ static int m66592_udc_stop(struct usb_gadget *g, · 1491 unmodified lines
14921492
14931493 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
14941494
1495− driver->unbind(&m66592->gadget);
1496−
14971495 init_controller(m66592);
14981496 disable_controller(m66592);
14991497
@@ -1553,7 +1551,7 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) · 53 unmodified lines
15531551 {
15541552 }
15551553
1556−static int __init m66592_probe(struct platform_device *pdev)
1554+static int m66592_probe(struct platform_device *pdev)
15571555 {
15581556 struct resource *res, *ires;
15591557 void __iomem *reg = NULL;
drivers/usb/gadget/udc/m66592-udc.hrenamed from drivers/usb/gadget/m66592-udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/mv_u3d.hrenamed from drivers/usb/gadget/mv_u3d.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/mv_u3d_core.crenamed from drivers/usb/gadget/mv_u3d_core.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/mv_udc.hrenamed from drivers/usb/gadget/mv_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/mv_udc_core.crenamed from drivers/usb/gadget/mv_udc_core.c+2−2
@@ -332,7 +332,7 @@ static int queue_dtd(struct mv_ep *ep, struct mv_req *req) · 331 unmodified lines
332332 /* clear active and halt bit, in case set from a previous error */
333333 dqh->size_ioc_int_sts &= ~(DTD_STATUS_ACTIVE | DTD_STATUS_HALTED);
334334
335− /* Ensure that updates to the QH will occure before priming. */
335+ /* Ensure that updates to the QH will occur before priming. */
336336 wmb();
337337
338338 /* Prime the Endpoint */
@@ -1656,7 +1656,7 @@ static void handle_setup_packet(struct mv_udc *udc, u8 ep_num, · 1317 unmodified lines
16561656 dev_dbg(&udc->dev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n",
16571657 setup->bRequestType, setup->bRequest,
16581658 setup->wValue, setup->wIndex, setup->wLength);
1659− /* We process some stardard setup requests here */
1659+ /* We process some standard setup requests here */
16601660 if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
16611661 switch (setup->bRequest) {
16621662 case USB_REQ_GET_STATUS:
drivers/usb/gadget/udc/net2272.crenamed from drivers/usb/gadget/net2272.c+1−1
@@ -1453,7 +1453,7 @@ static int net2272_start(struct usb_gadget *_gadget, · 1452 unmodified lines
14531453 struct net2272 *dev;
14541454 unsigned i;
14551455
1456− if (!driver || !driver->unbind || !driver->setup ||
1456+ if (!driver || !driver->setup ||
14571457 driver->max_speed != USB_SPEED_HIGH)
14581458 return -EINVAL;
14591459
drivers/usb/gadget/udc/net2272.hrenamed from drivers/usb/gadget/net2272.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/net2280.c+3827−0
@@ -0,0 +1,3827 @@
1+/*
2+ * Driver for the PLX NET2280 USB device controller.
3+ * Specs and errata are available from <http://www.plxtech.com>.
4+ *
5+ * PLX Technology Inc. (formerly NetChip Technology) supported the
6+ * development of this driver.
7+ *
8+ *
9+ * CODE STATUS HIGHLIGHTS
10+ *
11+ * This driver should work well with most "gadget" drivers, including
12+ * the Mass Storage, Serial, and Ethernet/RNDIS gadget drivers
13+ * as well as Gadget Zero and Gadgetfs.
14+ *
15+ * DMA is enabled by default. Drivers using transfer queues might use
16+ * DMA chaining to remove IRQ latencies between transfers. (Except when
17+ * short OUT transfers happen.) Drivers can use the req->no_interrupt
18+ * hint to completely eliminate some IRQs, if a later IRQ is guaranteed
19+ * and DMA chaining is enabled.
20+ *
21+ * MSI is enabled by default. The legacy IRQ is used if MSI couldn't
22+ * be enabled.
23+ *
24+ * Note that almost all the errata workarounds here are only needed for
25+ * rev1 chips. Rev1a silicon (0110) fixes almost all of them.
26+ */
27+
28+/*
29+ * Copyright (C) 2003 David Brownell
30+ * Copyright (C) 2003-2005 PLX Technology, Inc.
31+ * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
32+ *
33+ * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility
34+ * with 2282 chip
35+ *
36+ * Modified Ricardo Ribalda Qtechnology AS to provide compatibility
37+ * with usb 338x chip. Based on PLX driver
38+ *
39+ * This program is free software; you can redistribute it and/or modify
40+ * it under the terms of the GNU General Public License as published by
41+ * the Free Software Foundation; either version 2 of the License, or
42+ * (at your option) any later version.
43+ */
44+
45+#include <linux/module.h>
46+#include <linux/pci.h>
47+#include <linux/dma-mapping.h>
48+#include <linux/kernel.h>
49+#include <linux/delay.h>
50+#include <linux/ioport.h>
51+#include <linux/slab.h>
52+#include <linux/errno.h>
53+#include <linux/init.h>
54+#include <linux/timer.h>
55+#include <linux/list.h>
56+#include <linux/interrupt.h>
57+#include <linux/moduleparam.h>
58+#include <linux/device.h>
59+#include <linux/usb/ch9.h>
60+#include <linux/usb/gadget.h>
61+#include <linux/prefetch.h>
62+#include <linux/io.h>
63+
64+#include <asm/byteorder.h>
65+#include <asm/irq.h>
66+#include <asm/unaligned.h>
67+
68+#define DRIVER_DESC "PLX NET228x/USB338x USB Peripheral Controller"
69+#define DRIVER_VERSION "2005 Sept 27/v3.0"
70+
71+#define EP_DONTUSE 13 /* nonzero */
72+
73+#define USE_RDK_LEDS /* GPIO pins control three LEDs */
74+
75+
76+static const char driver_name[] = "net2280";
77+static const char driver_desc[] = DRIVER_DESC;
78+
79+static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };
80+static const char ep0name[] = "ep0";
81+static const char *const ep_name[] = {
82+ ep0name,
83+ "ep-a", "ep-b", "ep-c", "ep-d",
84+ "ep-e", "ep-f", "ep-g", "ep-h",
85+};
86+
87+/* use_dma -- general goodness, fewer interrupts, less cpu load (vs PIO)
88+ * use_dma_chaining -- dma descriptor queueing gives even more irq reduction
89+ *
90+ * The net2280 DMA engines are not tightly integrated with their FIFOs;
91+ * not all cases are (yet) handled well in this driver or the silicon.
92+ * Some gadget drivers work better with the dma support here than others.
93+ * These two parameters let you use PIO or more aggressive DMA.
94+ */
95+static bool use_dma = true;
96+static bool use_dma_chaining;
97+static bool use_msi = true;
98+
99+/* "modprobe net2280 use_dma=n" etc */
100+module_param(use_dma, bool, 0444);
101+module_param(use_dma_chaining, bool, 0444);
102+module_param(use_msi, bool, 0444);
103+
104+/* mode 0 == ep-{a,b,c,d} 1K fifo each
105+ * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
106+ * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
107+ */
108+static ushort fifo_mode;
109+
110+/* "modprobe net2280 fifo_mode=1" etc */
111+module_param(fifo_mode, ushort, 0644);
112+
113+/* enable_suspend -- When enabled, the driver will respond to
114+ * USB suspend requests by powering down the NET2280. Otherwise,
115+ * USB suspend requests will be ignored. This is acceptable for
116+ * self-powered devices
117+ */
118+static bool enable_suspend;
119+
120+/* "modprobe net2280 enable_suspend=1" etc */
121+module_param(enable_suspend, bool, 0444);
122+
123+/* force full-speed operation */
124+static bool full_speed;
125+module_param(full_speed, bool, 0444);
126+MODULE_PARM_DESC(full_speed, "force full-speed mode -- for testing only!");
127+
128+#define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
129+
130+static char *type_string(u8 bmAttributes)
131+{
132+ switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
133+ case USB_ENDPOINT_XFER_BULK: return "bulk";
134+ case USB_ENDPOINT_XFER_ISOC: return "iso";
135+ case USB_ENDPOINT_XFER_INT: return "intr";
136+ }
137+ return "control";
138+}
139+
140+#include "net2280.h"
141+
142+#define valid_bit cpu_to_le32(BIT(VALID_BIT))
143+#define dma_done_ie cpu_to_le32(BIT(DMA_DONE_INTERRUPT_ENABLE))
144+
145+/*-------------------------------------------------------------------------*/
146+static inline void enable_pciirqenb(struct net2280_ep *ep)
147+{
148+ u32 tmp = readl(&ep->dev->regs->pciirqenb0);
149+
150+ if (ep->dev->quirks & PLX_LEGACY)
151+ tmp |= BIT(ep->num);
152+ else
153+ tmp |= BIT(ep_bit[ep->num]);
154+ writel(tmp, &ep->dev->regs->pciirqenb0);
155+
156+ return;
157+}
158+
159+static int
160+net2280_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
161+{
162+ struct net2280 *dev;
163+ struct net2280_ep *ep;
164+ u32 max, tmp;
165+ unsigned long flags;
166+ static const u32 ep_key[9] = { 1, 0, 1, 0, 1, 1, 0, 1, 0 };
167+
168+ ep = container_of(_ep, struct net2280_ep, ep);
169+ if (!_ep || !desc || ep->desc || _ep->name == ep0name ||
170+ desc->bDescriptorType != USB_DT_ENDPOINT)
171+ return -EINVAL;
172+ dev = ep->dev;
173+ if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
174+ return -ESHUTDOWN;
175+
176+ /* erratum 0119 workaround ties up an endpoint number */
177+ if ((desc->bEndpointAddress & 0x0f) == EP_DONTUSE)
178+ return -EDOM;
179+
180+ if (dev->quirks & PLX_SUPERSPEED) {
181+ if ((desc->bEndpointAddress & 0x0f) >= 0x0c)
182+ return -EDOM;
183+ ep->is_in = !!usb_endpoint_dir_in(desc);
184+ if (dev->enhanced_mode && ep->is_in && ep_key[ep->num])
185+ return -EINVAL;
186+ }
187+
188+ /* sanity check ep-e/ep-f since their fifos are small */
189+ max = usb_endpoint_maxp(desc) & 0x1fff;
190+ if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY))
191+ return -ERANGE;
192+
193+ spin_lock_irqsave(&dev->lock, flags);
194+ _ep->maxpacket = max & 0x7ff;
195+ ep->desc = desc;
196+
197+ /* ep_reset() has already been called */
198+ ep->stopped = 0;
199+ ep->wedged = 0;
200+ ep->out_overflow = 0;
201+
202+ /* set speed-dependent max packet; may kick in high bandwidth */
203+ set_max_speed(ep, max);
204+
205+ /* FIFO lines can't go to different packets. PIO is ok, so
206+ * use it instead of troublesome (non-bulk) multi-packet DMA.
207+ */
208+ if (ep->dma && (max % 4) != 0 && use_dma_chaining) {
209+ ep_dbg(ep->dev, "%s, no dma for maxpacket %d\n",
210+ ep->ep.name, ep->ep.maxpacket);
211+ ep->dma = NULL;
212+ }
213+
214+ /* set type, direction, address; reset fifo counters */
215+ writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
216+ tmp = (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
217+ if (tmp == USB_ENDPOINT_XFER_INT) {
218+ /* erratum 0105 workaround prevents hs NYET */
219+ if (dev->chiprev == 0100 &&
220+ dev->gadget.speed == USB_SPEED_HIGH &&
221+ !(desc->bEndpointAddress & USB_DIR_IN))
222+ writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE),
223+ &ep->regs->ep_rsp);
224+ } else if (tmp == USB_ENDPOINT_XFER_BULK) {
225+ /* catch some particularly blatant driver bugs */
226+ if ((dev->gadget.speed == USB_SPEED_SUPER && max != 1024) ||
227+ (dev->gadget.speed == USB_SPEED_HIGH && max != 512) ||
228+ (dev->gadget.speed == USB_SPEED_FULL && max > 64)) {
229+ spin_unlock_irqrestore(&dev->lock, flags);
230+ return -ERANGE;
231+ }
232+ }
233+ ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC);
234+ /* Enable this endpoint */
235+ if (dev->quirks & PLX_LEGACY) {
236+ tmp <<= ENDPOINT_TYPE;
237+ tmp |= desc->bEndpointAddress;
238+ /* default full fifo lines */
239+ tmp |= (4 << ENDPOINT_BYTE_COUNT);
240+ tmp |= BIT(ENDPOINT_ENABLE);
241+ ep->is_in = (tmp & USB_DIR_IN) != 0;
242+ } else {
243+ /* In Legacy mode, only OUT endpoints are used */
244+ if (dev->enhanced_mode && ep->is_in) {
245+ tmp <<= IN_ENDPOINT_TYPE;
246+ tmp |= BIT(IN_ENDPOINT_ENABLE);
247+ /* Not applicable to Legacy */
248+ tmp |= BIT(ENDPOINT_DIRECTION);
249+ } else {
250+ tmp <<= OUT_ENDPOINT_TYPE;
251+ tmp |= BIT(OUT_ENDPOINT_ENABLE);
252+ tmp |= (ep->is_in << ENDPOINT_DIRECTION);
253+ }
254+
255+ tmp |= usb_endpoint_num(desc);
256+ tmp |= (ep->ep.maxburst << MAX_BURST_SIZE);
257+ }
258+
259+ /* Make sure all the registers are written before ep_rsp*/
260+ wmb();
261+
262+ /* for OUT transfers, block the rx fifo until a read is posted */
263+ if (!ep->is_in)
264+ writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
265+ else if (!(dev->quirks & PLX_2280)) {
266+ /* Added for 2282, Don't use nak packets on an in endpoint,
267+ * this was ignored on 2280
268+ */
269+ writel(BIT(CLEAR_NAK_OUT_PACKETS) |
270+ BIT(CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
271+ }
272+
273+ writel(tmp, &ep->cfg->ep_cfg);
274+
275+ /* enable irqs */
276+ if (!ep->dma) { /* pio, per-packet */
277+ enable_pciirqenb(ep);
278+
279+ tmp = BIT(DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) |
280+ BIT(DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE);
281+ if (dev->quirks & PLX_2280)
282+ tmp |= readl(&ep->regs->ep_irqenb);
283+ writel(tmp, &ep->regs->ep_irqenb);
284+ } else { /* dma, per-request */
285+ tmp = BIT((8 + ep->num)); /* completion */
286+ tmp |= readl(&dev->regs->pciirqenb1);
287+ writel(tmp, &dev->regs->pciirqenb1);
288+
289+ /* for short OUT transfers, dma completions can't
290+ * advance the queue; do it pio-style, by hand.
291+ * NOTE erratum 0112 workaround #2
292+ */
293+ if ((desc->bEndpointAddress & USB_DIR_IN) == 0) {
294+ tmp = BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE);
295+ writel(tmp, &ep->regs->ep_irqenb);
296+
297+ enable_pciirqenb(ep);
298+ }
299+ }
300+
301+ tmp = desc->bEndpointAddress;
302+ ep_dbg(dev, "enabled %s (ep%d%s-%s) %s max %04x\n",
303+ _ep->name, tmp & 0x0f, DIR_STRING(tmp),
304+ type_string(desc->bmAttributes),
305+ ep->dma ? "dma" : "pio", max);
306+
307+ /* pci writes may still be posted */
308+ spin_unlock_irqrestore(&dev->lock, flags);
309+ return 0;
310+}
311+
312+static int handshake(u32 __iomem *ptr, u32 mask, u32 done, int usec)
313+{
314+ u32 result;
315+
316+ do {
317+ result = readl(ptr);
318+ if (result == ~(u32)0) /* "device unplugged" */
319+ return -ENODEV;
320+ result &= mask;
321+ if (result == done)
322+ return 0;
323+ udelay(1);
324+ usec--;
325+ } while (usec > 0);
326+ return -ETIMEDOUT;
327+}
328+
329+static const struct usb_ep_ops net2280_ep_ops;
330+
331+static void ep_reset_228x(struct net2280_regs __iomem *regs,
332+ struct net2280_ep *ep)
333+{
334+ u32 tmp;
335+
336+ ep->desc = NULL;
337+ INIT_LIST_HEAD(&ep->queue);
338+
339+ usb_ep_set_maxpacket_limit(&ep->ep, ~0);
340+ ep->ep.ops = &net2280_ep_ops;
341+
342+ /* disable the dma, irqs, endpoint... */
343+ if (ep->dma) {
344+ writel(0, &ep->dma->dmactl);
345+ writel(BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
346+ BIT(DMA_TRANSACTION_DONE_INTERRUPT) |
347+ BIT(DMA_ABORT),
348+ &ep->dma->dmastat);
349+
350+ tmp = readl(&regs->pciirqenb0);
351+ tmp &= ~BIT(ep->num);
352+ writel(tmp, &regs->pciirqenb0);
353+ } else {
354+ tmp = readl(&regs->pciirqenb1);
355+ tmp &= ~BIT((8 + ep->num)); /* completion */
356+ writel(tmp, &regs->pciirqenb1);
357+ }
358+ writel(0, &ep->regs->ep_irqenb);
359+
360+ /* init to our chosen defaults, notably so that we NAK OUT
361+ * packets until the driver queues a read (+note erratum 0112)
362+ */
363+ if (!ep->is_in || (ep->dev->quirks & PLX_2280)) {
364+ tmp = BIT(SET_NAK_OUT_PACKETS_MODE) |
365+ BIT(SET_NAK_OUT_PACKETS) |
366+ BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
367+ BIT(CLEAR_INTERRUPT_MODE);
368+ } else {
369+ /* added for 2282 */
370+ tmp = BIT(CLEAR_NAK_OUT_PACKETS_MODE) |
371+ BIT(CLEAR_NAK_OUT_PACKETS) |
372+ BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
373+ BIT(CLEAR_INTERRUPT_MODE);
374+ }
375+
376+ if (ep->num != 0) {
377+ tmp |= BIT(CLEAR_ENDPOINT_TOGGLE) |
378+ BIT(CLEAR_ENDPOINT_HALT);
379+ }
380+ writel(tmp, &ep->regs->ep_rsp);
381+
382+ /* scrub most status bits, and flush any fifo state */
383+ if (ep->dev->quirks & PLX_2280)
384+ tmp = BIT(FIFO_OVERFLOW) |
385+ BIT(FIFO_UNDERFLOW);
386+ else
387+ tmp = 0;
388+
389+ writel(tmp | BIT(TIMEOUT) |
390+ BIT(USB_STALL_SENT) |
391+ BIT(USB_IN_NAK_SENT) |
392+ BIT(USB_IN_ACK_RCVD) |
393+ BIT(USB_OUT_PING_NAK_SENT) |
394+ BIT(USB_OUT_ACK_SENT) |
395+ BIT(FIFO_FLUSH) |
396+ BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
397+ BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
398+ BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
399+ BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
400+ BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
401+ BIT(DATA_IN_TOKEN_INTERRUPT),
402+ &ep->regs->ep_stat);
403+
404+ /* fifo size is handled separately */
405+}
406+
407+static void ep_reset_338x(struct net2280_regs __iomem *regs,
408+ struct net2280_ep *ep)
409+{
410+ u32 tmp, dmastat;
411+
412+ ep->desc = NULL;
413+ INIT_LIST_HEAD(&ep->queue);
414+
415+ usb_ep_set_maxpacket_limit(&ep->ep, ~0);
416+ ep->ep.ops = &net2280_ep_ops;
417+
418+ /* disable the dma, irqs, endpoint... */
419+ if (ep->dma) {
420+ writel(0, &ep->dma->dmactl);
421+ writel(BIT(DMA_ABORT_DONE_INTERRUPT) |
422+ BIT(DMA_PAUSE_DONE_INTERRUPT) |
423+ BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
424+ BIT(DMA_TRANSACTION_DONE_INTERRUPT),
425+ /* | BIT(DMA_ABORT), */
426+ &ep->dma->dmastat);
427+
428+ dmastat = readl(&ep->dma->dmastat);
429+ if (dmastat == 0x5002) {
430+ ep_warn(ep->dev, "The dmastat return = %x!!\n",
431+ dmastat);
432+ writel(0x5a, &ep->dma->dmastat);
433+ }
434+
435+ tmp = readl(&regs->pciirqenb0);
436+ tmp &= ~BIT(ep_bit[ep->num]);
437+ writel(tmp, &regs->pciirqenb0);
438+ } else {
439+ if (ep->num < 5) {
440+ tmp = readl(&regs->pciirqenb1);
441+ tmp &= ~BIT((8 + ep->num)); /* completion */
442+ writel(tmp, &regs->pciirqenb1);
443+ }
444+ }
445+ writel(0, &ep->regs->ep_irqenb);
446+
447+ writel(BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
448+ BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
449+ BIT(FIFO_OVERFLOW) |
450+ BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
451+ BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
452+ BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
453+ BIT(DATA_IN_TOKEN_INTERRUPT), &ep->regs->ep_stat);
454+}
455+
456+static void nuke(struct net2280_ep *);
457+
458+static int net2280_disable(struct usb_ep *_ep)
459+{
460+ struct net2280_ep *ep;
461+ unsigned long flags;
462+
463+ ep = container_of(_ep, struct net2280_ep, ep);
464+ if (!_ep || !ep->desc || _ep->name == ep0name)
465+ return -EINVAL;
466+
467+ spin_lock_irqsave(&ep->dev->lock, flags);
468+ nuke(ep);
469+
470+ if (ep->dev->quirks & PLX_SUPERSPEED)
471+ ep_reset_338x(ep->dev->regs, ep);
472+ else
473+ ep_reset_228x(ep->dev->regs, ep);
474+
475+ ep_vdbg(ep->dev, "disabled %s %s\n",
476+ ep->dma ? "dma" : "pio", _ep->name);
477+
478+ /* synch memory views with the device */
479+ (void)readl(&ep->cfg->ep_cfg);
480+
481+ if (use_dma && !ep->dma && ep->num >= 1 && ep->num <= 4)
482+ ep->dma = &ep->dev->dma[ep->num - 1];
483+
484+ spin_unlock_irqrestore(&ep->dev->lock, flags);
485+ return 0;
486+}
487+
488+/*-------------------------------------------------------------------------*/
489+
490+static struct usb_request
491+*net2280_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
492+{
493+ struct net2280_ep *ep;
494+ struct net2280_request *req;
495+
496+ if (!_ep)
497+ return NULL;
498+ ep = container_of(_ep, struct net2280_ep, ep);
499+
500+ req = kzalloc(sizeof(*req), gfp_flags);
501+ if (!req)
502+ return NULL;
503+
504+ INIT_LIST_HEAD(&req->queue);
505+
506+ /* this dma descriptor may be swapped with the previous dummy */
507+ if (ep->dma) {
508+ struct net2280_dma *td;
509+
510+ td = pci_pool_alloc(ep->dev->requests, gfp_flags,
511+ &req->td_dma);
512+ if (!td) {
513+ kfree(req);
514+ return NULL;
515+ }
516+ td->dmacount = 0; /* not VALID */
517+ td->dmadesc = td->dmaaddr;
518+ req->td = td;
519+ }
520+ return &req->req;
521+}
522+
523+static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req)
524+{
525+ struct net2280_ep *ep;
526+ struct net2280_request *req;
527+
528+ ep = container_of(_ep, struct net2280_ep, ep);
529+ if (!_ep || !_req)
530+ return;
531+
532+ req = container_of(_req, struct net2280_request, req);
533+ WARN_ON(!list_empty(&req->queue));
534+ if (req->td)
535+ pci_pool_free(ep->dev->requests, req->td, req->td_dma);
536+ kfree(req);
537+}
538+
539+/*-------------------------------------------------------------------------*/
540+
541+/* load a packet into the fifo we use for usb IN transfers.
542+ * works for all endpoints.
543+ *
544+ * NOTE: pio with ep-a..ep-d could stuff multiple packets into the fifo
545+ * at a time, but this code is simpler because it knows it only writes
546+ * one packet. ep-a..ep-d should use dma instead.
547+ */
548+static void write_fifo(struct net2280_ep *ep, struct usb_request *req)
549+{
550+ struct net2280_ep_regs __iomem *regs = ep->regs;
551+ u8 *buf;
552+ u32 tmp;
553+ unsigned count, total;
554+
555+ /* INVARIANT: fifo is currently empty. (testable) */
556+
557+ if (req) {
558+ buf = req->buf + req->actual;
559+ prefetch(buf);
560+ total = req->length - req->actual;
561+ } else {
562+ total = 0;
563+ buf = NULL;
564+ }
565+
566+ /* write just one packet at a time */
567+ count = ep->ep.maxpacket;
568+ if (count > total) /* min() cannot be used on a bitfield */
569+ count = total;
570+
571+ ep_vdbg(ep->dev, "write %s fifo (IN) %d bytes%s req %p\n",
572+ ep->ep.name, count,
573+ (count != ep->ep.maxpacket) ? " (short)" : "",
574+ req);
575+ while (count >= 4) {
576+ /* NOTE be careful if you try to align these. fifo lines
577+ * should normally be full (4 bytes) and successive partial
578+ * lines are ok only in certain cases.
579+ */
580+ tmp = get_unaligned((u32 *)buf);
581+ cpu_to_le32s(&tmp);
582+ writel(tmp, &regs->ep_data);
583+ buf += 4;
584+ count -= 4;
585+ }
586+
587+ /* last fifo entry is "short" unless we wrote a full packet.
588+ * also explicitly validate last word in (periodic) transfers
589+ * when maxpacket is not a multiple of 4 bytes.
590+ */
591+ if (count || total < ep->ep.maxpacket) {
592+ tmp = count ? get_unaligned((u32 *)buf) : count;
593+ cpu_to_le32s(&tmp);
594+ set_fifo_bytecount(ep, count & 0x03);
595+ writel(tmp, &regs->ep_data);
596+ }
597+
598+ /* pci writes may still be posted */
599+}
600+
601+/* work around erratum 0106: PCI and USB race over the OUT fifo.
602+ * caller guarantees chiprev 0100, out endpoint is NAKing, and
603+ * there's no real data in the fifo.
604+ *
605+ * NOTE: also used in cases where that erratum doesn't apply:
606+ * where the host wrote "too much" data to us.
607+ */
608+static void out_flush(struct net2280_ep *ep)
609+{
610+ u32 __iomem *statp;
611+ u32 tmp;
612+
613+ ASSERT_OUT_NAKING(ep);
614+
615+ statp = &ep->regs->ep_stat;
616+ writel(BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
617+ BIT(DATA_PACKET_RECEIVED_INTERRUPT),
618+ statp);
619+ writel(BIT(FIFO_FLUSH), statp);
620+ /* Make sure that stap is written */
621+ mb();
622+ tmp = readl(statp);
623+ if (tmp & BIT(DATA_OUT_PING_TOKEN_INTERRUPT) &&
624+ /* high speed did bulk NYET; fifo isn't filling */
625+ ep->dev->gadget.speed == USB_SPEED_FULL) {
626+ unsigned usec;
627+
628+ usec = 50; /* 64 byte bulk/interrupt */
629+ handshake(statp, BIT(USB_OUT_PING_NAK_SENT),
630+ BIT(USB_OUT_PING_NAK_SENT), usec);
631+ /* NAK done; now CLEAR_NAK_OUT_PACKETS is safe */
632+ }
633+}
634+
635+/* unload packet(s) from the fifo we use for usb OUT transfers.
636+ * returns true iff the request completed, because of short packet
637+ * or the request buffer having filled with full packets.
638+ *
639+ * for ep-a..ep-d this will read multiple packets out when they
640+ * have been accepted.
641+ */
642+static int read_fifo(struct net2280_ep *ep, struct net2280_request *req)
643+{
644+ struct net2280_ep_regs __iomem *regs = ep->regs;
645+ u8 *buf = req->req.buf + req->req.actual;
646+ unsigned count, tmp, is_short;
647+ unsigned cleanup = 0, prevent = 0;
648+
649+ /* erratum 0106 ... packets coming in during fifo reads might
650+ * be incompletely rejected. not all cases have workarounds.
651+ */
652+ if (ep->dev->chiprev == 0x0100 &&
653+ ep->dev->gadget.speed == USB_SPEED_FULL) {
654+ udelay(1);
655+ tmp = readl(&ep->regs->ep_stat);
656+ if ((tmp & BIT(NAK_OUT_PACKETS)))
657+ cleanup = 1;
658+ else if ((tmp & BIT(FIFO_FULL))) {
659+ start_out_naking(ep);
660+ prevent = 1;
661+ }
662+ /* else: hope we don't see the problem */
663+ }
664+
665+ /* never overflow the rx buffer. the fifo reads packets until
666+ * it sees a short one; we might not be ready for them all.
667+ */
668+ prefetchw(buf);
669+ count = readl(&regs->ep_avail);
670+ if (unlikely(count == 0)) {
671+ udelay(1);
672+ tmp = readl(&ep->regs->ep_stat);
673+ count = readl(&regs->ep_avail);
674+ /* handled that data already? */
675+ if (count == 0 && (tmp & BIT(NAK_OUT_PACKETS)) == 0)
676+ return 0;
677+ }
678+
679+ tmp = req->req.length - req->req.actual;
680+ if (count > tmp) {
681+ /* as with DMA, data overflow gets flushed */
682+ if ((tmp % ep->ep.maxpacket) != 0) {
683+ ep_err(ep->dev,
684+ "%s out fifo %d bytes, expected %d\n",
685+ ep->ep.name, count, tmp);
686+ req->req.status = -EOVERFLOW;
687+ cleanup = 1;
688+ /* NAK_OUT_PACKETS will be set, so flushing is safe;
689+ * the next read will start with the next packet
690+ */
691+ } /* else it's a ZLP, no worries */
692+ count = tmp;
693+ }
694+ req->req.actual += count;
695+
696+ is_short = (count == 0) || ((count % ep->ep.maxpacket) != 0);
697+
698+ ep_vdbg(ep->dev, "read %s fifo (OUT) %d bytes%s%s%s req %p %d/%d\n",
699+ ep->ep.name, count, is_short ? " (short)" : "",
700+ cleanup ? " flush" : "", prevent ? " nak" : "",
701+ req, req->req.actual, req->req.length);
702+
703+ while (count >= 4) {
704+ tmp = readl(&regs->ep_data);
705+ cpu_to_le32s(&tmp);
706+ put_unaligned(tmp, (u32 *)buf);
707+ buf += 4;
708+ count -= 4;
709+ }
710+ if (count) {
711+ tmp = readl(&regs->ep_data);
712+ /* LE conversion is implicit here: */
713+ do {
714+ *buf++ = (u8) tmp;
715+ tmp >>= 8;
716+ } while (--count);
717+ }
718+ if (cleanup)
719+ out_flush(ep);
720+ if (prevent) {
721+ writel(BIT(CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
722+ (void) readl(&ep->regs->ep_rsp);
723+ }
724+
725+ return is_short || ((req->req.actual == req->req.length) &&
726+ !req->req.zero);
727+}
728+
729+/* fill out dma descriptor to match a given request */
730+static void fill_dma_desc(struct net2280_ep *ep,
731+ struct net2280_request *req, int valid)
732+{
733+ struct net2280_dma *td = req->td;
734+ u32 dmacount = req->req.length;
735+
736+ /* don't let DMA continue after a short OUT packet,
737+ * so overruns can't affect the next transfer.
738+ * in case of overruns on max-size packets, we can't
739+ * stop the fifo from filling but we can flush it.
740+ */
741+ if (ep->is_in)
742+ dmacount |= BIT(DMA_DIRECTION);
743+ if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) ||
744+ !(ep->dev->quirks & PLX_2280))
745+ dmacount |= BIT(END_OF_CHAIN);
746+
747+ req->valid = valid;
748+ if (valid)
749+ dmacount |= BIT(VALID_BIT);
750+ if (likely(!req->req.no_interrupt || !use_dma_chaining))
751+ dmacount |= BIT(DMA_DONE_INTERRUPT_ENABLE);
752+
753+ /* td->dmadesc = previously set by caller */
754+ td->dmaaddr = cpu_to_le32 (req->req.dma);
755+
756+ /* 2280 may be polling VALID_BIT through ep->dma->dmadesc */
757+ wmb();
758+ td->dmacount = cpu_to_le32(dmacount);
759+}
760+
761+static const u32 dmactl_default =
762+ BIT(DMA_SCATTER_GATHER_DONE_INTERRUPT) |
763+ BIT(DMA_CLEAR_COUNT_ENABLE) |
764+ /* erratum 0116 workaround part 1 (use POLLING) */
765+ (POLL_100_USEC << DESCRIPTOR_POLLING_RATE) |
766+ BIT(DMA_VALID_BIT_POLLING_ENABLE) |
767+ BIT(DMA_VALID_BIT_ENABLE) |
768+ BIT(DMA_SCATTER_GATHER_ENABLE) |
769+ /* erratum 0116 workaround part 2 (no AUTOSTART) */
770+ BIT(DMA_ENABLE);
771+
772+static inline void spin_stop_dma(struct net2280_dma_regs __iomem *dma)
773+{
774+ handshake(&dma->dmactl, BIT(DMA_ENABLE), 0, 50);
775+}
776+
777+static inline void stop_dma(struct net2280_dma_regs __iomem *dma)
778+{
779+ writel(readl(&dma->dmactl) & ~BIT(DMA_ENABLE), &dma->dmactl);
780+ spin_stop_dma(dma);
781+}
782+
783+static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma)
784+{
785+ struct net2280_dma_regs __iomem *dma = ep->dma;
786+ unsigned int tmp = BIT(VALID_BIT) | (ep->is_in << DMA_DIRECTION);
787+
788+ if (!(ep->dev->quirks & PLX_2280))
789+ tmp |= BIT(END_OF_CHAIN);
790+
791+ writel(tmp, &dma->dmacount);
792+ writel(readl(&dma->dmastat), &dma->dmastat);
793+
794+ writel(td_dma, &dma->dmadesc);
795+ if (ep->dev->quirks & PLX_SUPERSPEED)
796+ dmactl |= BIT(DMA_REQUEST_OUTSTANDING);
797+ writel(dmactl, &dma->dmactl);
798+
799+ /* erratum 0116 workaround part 3: pci arbiter away from net2280 */
800+ (void) readl(&ep->dev->pci->pcimstctl);
801+
802+ writel(BIT(DMA_START), &dma->dmastat);
803+
804+ if (!ep->is_in)
805+ stop_out_naking(ep);
806+}
807+
808+static void start_dma(struct net2280_ep *ep, struct net2280_request *req)
809+{
810+ u32 tmp;
811+ struct net2280_dma_regs __iomem *dma = ep->dma;
812+
813+ /* FIXME can't use DMA for ZLPs */
814+
815+ /* on this path we "know" there's no dma active (yet) */
816+ WARN_ON(readl(&dma->dmactl) & BIT(DMA_ENABLE));
817+ writel(0, &ep->dma->dmactl);
818+
819+ /* previous OUT packet might have been short */
820+ if (!ep->is_in && (readl(&ep->regs->ep_stat) &
821+ BIT(NAK_OUT_PACKETS))) {
822+ writel(BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT),
823+ &ep->regs->ep_stat);
824+
825+ tmp = readl(&ep->regs->ep_avail);
826+ if (tmp) {
827+ writel(readl(&dma->dmastat), &dma->dmastat);
828+
829+ /* transfer all/some fifo data */
830+ writel(req->req.dma, &dma->dmaaddr);
831+ tmp = min(tmp, req->req.length);
832+
833+ /* dma irq, faking scatterlist status */
834+ req->td->dmacount = cpu_to_le32(req->req.length - tmp);
835+ writel(BIT(DMA_DONE_INTERRUPT_ENABLE) | tmp,
836+ &dma->dmacount);
837+ req->td->dmadesc = 0;
838+ req->valid = 1;
839+
840+ writel(BIT(DMA_ENABLE), &dma->dmactl);
841+ writel(BIT(DMA_START), &dma->dmastat);
842+ return;
843+ }
844+ }
845+
846+ tmp = dmactl_default;
847+
848+ /* force packet boundaries between dma requests, but prevent the
849+ * controller from automagically writing a last "short" packet
850+ * (zero length) unless the driver explicitly said to do that.
851+ */
852+ if (ep->is_in) {
853+ if (likely((req->req.length % ep->ep.maxpacket) ||
854+ req->req.zero)){
855+ tmp |= BIT(DMA_FIFO_VALIDATE);
856+ ep->in_fifo_validate = 1;
857+ } else
858+ ep->in_fifo_validate = 0;
859+ }
860+
861+ /* init req->td, pointing to the current dummy */
862+ req->td->dmadesc = cpu_to_le32 (ep->td_dma);
863+ fill_dma_desc(ep, req, 1);
864+
865+ if (!use_dma_chaining)
866+ req->td->dmacount |= cpu_to_le32(BIT(END_OF_CHAIN));
867+
868+ start_queue(ep, tmp, req->td_dma);
869+}
870+
871+static inline void resume_dma(struct net2280_ep *ep)
872+{
873+ writel(readl(&ep->dma->dmactl) | BIT(DMA_ENABLE), &ep->dma->dmactl);
874+
875+ ep->dma_started = true;
876+}
877+
878+static inline void ep_stop_dma(struct net2280_ep *ep)
879+{
880+ writel(readl(&ep->dma->dmactl) & ~BIT(DMA_ENABLE), &ep->dma->dmactl);
881+ spin_stop_dma(ep->dma);
882+
883+ ep->dma_started = false;
884+}
885+
886+static inline void
887+queue_dma(struct net2280_ep *ep, struct net2280_request *req, int valid)
888+{
889+ struct net2280_dma *end;
890+ dma_addr_t tmp;
891+
892+ /* swap new dummy for old, link; fill and maybe activate */
893+ end = ep->dummy;
894+ ep->dummy = req->td;
895+ req->td = end;
896+
897+ tmp = ep->td_dma;
898+ ep->td_dma = req->td_dma;
899+ req->td_dma = tmp;
900+
901+ end->dmadesc = cpu_to_le32 (ep->td_dma);
902+
903+ fill_dma_desc(ep, req, valid);
904+}
905+
906+static void
907+done(struct net2280_ep *ep, struct net2280_request *req, int status)
908+{
909+ struct net2280 *dev;
910+ unsigned stopped = ep->stopped;
911+
912+ list_del_init(&req->queue);
913+
914+ if (req->req.status == -EINPROGRESS)
915+ req->req.status = status;
916+ else
917+ status = req->req.status;
918+
919+ dev = ep->dev;
920+ if (ep->dma)
921+ usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in);
922+
923+ if (status && status != -ESHUTDOWN)
924+ ep_vdbg(dev, "complete %s req %p stat %d len %u/%u\n",
925+ ep->ep.name, &req->req, status,
926+ req->req.actual, req->req.length);
927+
928+ /* don't modify queue heads during completion callback */
929+ ep->stopped = 1;
930+ spin_unlock(&dev->lock);
931+ req->req.complete(&ep->ep, &req->req);
932+ spin_lock(&dev->lock);
933+ ep->stopped = stopped;
934+}
935+
936+/*-------------------------------------------------------------------------*/
937+
938+static int
939+net2280_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
940+{
941+ struct net2280_request *req;
942+ struct net2280_ep *ep;
943+ struct net2280 *dev;
944+ unsigned long flags;
945+
946+ /* we always require a cpu-view buffer, so that we can
947+ * always use pio (as fallback or whatever).
948+ */
949+ req = container_of(_req, struct net2280_request, req);
950+ if (!_req || !_req->complete || !_req->buf ||
951+ !list_empty(&req->queue))
952+ return -EINVAL;
953+ if (_req->length > (~0 & DMA_BYTE_COUNT_MASK))
954+ return -EDOM;
955+ ep = container_of(_ep, struct net2280_ep, ep);
956+ if (!_ep || (!ep->desc && ep->num != 0))
957+ return -EINVAL;
958+ dev = ep->dev;
959+ if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
960+ return -ESHUTDOWN;
961+
962+ /* FIXME implement PIO fallback for ZLPs with DMA */
963+ if (ep->dma && _req->length == 0)
964+ return -EOPNOTSUPP;
965+
966+ /* set up dma mapping in case the caller didn't */
967+ if (ep->dma) {
968+ int ret;
969+
970+ ret = usb_gadget_map_request(&dev->gadget, _req,
971+ ep->is_in);
972+ if (ret)
973+ return ret;
974+ }
975+
976+#if 0
977+ ep_vdbg(dev, "%s queue req %p, len %d buf %p\n",
978+ _ep->name, _req, _req->length, _req->buf);
979+#endif
980+
981+ spin_lock_irqsave(&dev->lock, flags);
982+
983+ _req->status = -EINPROGRESS;
984+ _req->actual = 0;
985+
986+ /* kickstart this i/o queue? */
987+ if (list_empty(&ep->queue) && !ep->stopped) {
988+ /* DMA request while EP halted */
989+ if (ep->dma &&
990+ (readl(&ep->regs->ep_rsp) & BIT(CLEAR_ENDPOINT_HALT)) &&
991+ (dev->quirks & PLX_SUPERSPEED)) {
992+ int valid = 1;
993+ if (ep->is_in) {
994+ int expect;
995+ expect = likely(req->req.zero ||
996+ ((req->req.length %
997+ ep->ep.maxpacket) != 0));
998+ if (expect != ep->in_fifo_validate)
999+ valid = 0;
1000+ }
1001+ queue_dma(ep, req, valid);
1002+ }
1003+ /* use DMA if the endpoint supports it, else pio */
1004+ else if (ep->dma)
1005+ start_dma(ep, req);
1006+ else {
1007+ /* maybe there's no control data, just status ack */
1008+ if (ep->num == 0 && _req->length == 0) {
1009+ allow_status(ep);
1010+ done(ep, req, 0);
1011+ ep_vdbg(dev, "%s status ack\n", ep->ep.name);
1012+ goto done;
1013+ }
1014+
1015+ /* PIO ... stuff the fifo, or unblock it. */
1016+ if (ep->is_in)
1017+ write_fifo(ep, _req);
1018+ else if (list_empty(&ep->queue)) {
1019+ u32 s;
1020+
1021+ /* OUT FIFO might have packet(s) buffered */
1022+ s = readl(&ep->regs->ep_stat);
1023+ if ((s & BIT(FIFO_EMPTY)) == 0) {
1024+ /* note: _req->short_not_ok is
1025+ * ignored here since PIO _always_
1026+ * stops queue advance here, and
1027+ * _req->status doesn't change for
1028+ * short reads (only _req->actual)
1029+ */
1030+ if (read_fifo(ep, req) &&
1031+ ep->num == 0) {
1032+ done(ep, req, 0);
1033+ allow_status(ep);
1034+ /* don't queue it */
1035+ req = NULL;
1036+ } else if (read_fifo(ep, req) &&
1037+ ep->num != 0) {
1038+ done(ep, req, 0);
1039+ req = NULL;
1040+ } else
1041+ s = readl(&ep->regs->ep_stat);
1042+ }
1043+
1044+ /* don't NAK, let the fifo fill */
1045+ if (req && (s & BIT(NAK_OUT_PACKETS)))
1046+ writel(BIT(CLEAR_NAK_OUT_PACKETS),
1047+ &ep->regs->ep_rsp);
1048+ }
1049+ }
1050+
1051+ } else if (ep->dma) {
1052+ int valid = 1;
1053+
1054+ if (ep->is_in) {
1055+ int expect;
1056+
1057+ /* preventing magic zlps is per-engine state, not
1058+ * per-transfer; irq logic must recover hiccups.
1059+ */
1060+ expect = likely(req->req.zero ||
1061+ (req->req.length % ep->ep.maxpacket));
1062+ if (expect != ep->in_fifo_validate)
1063+ valid = 0;
1064+ }
1065+ queue_dma(ep, req, valid);
1066+
1067+ } /* else the irq handler advances the queue. */
1068+
1069+ ep->responded = 1;
1070+ if (req)
1071+ list_add_tail(&req->queue, &ep->queue);
1072+done:
1073+ spin_unlock_irqrestore(&dev->lock, flags);
1074+
1075+ /* pci writes may still be posted */
1076+ return 0;
1077+}
1078+
1079+static inline void
1080+dma_done(struct net2280_ep *ep, struct net2280_request *req, u32 dmacount,
1081+ int status)
1082+{
1083+ req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount);
1084+ done(ep, req, status);
1085+}
1086+
1087+static void restart_dma(struct net2280_ep *ep);
1088+
1089+static void scan_dma_completions(struct net2280_ep *ep)
1090+{
1091+ /* only look at descriptors that were "naturally" retired,
1092+ * so fifo and list head state won't matter
1093+ */
1094+ while (!list_empty(&ep->queue)) {
1095+ struct net2280_request *req;
1096+ u32 tmp;
1097+
1098+ req = list_entry(ep->queue.next,
1099+ struct net2280_request, queue);
1100+ if (!req->valid)
1101+ break;
1102+ rmb();
1103+ tmp = le32_to_cpup(&req->td->dmacount);
1104+ if ((tmp & BIT(VALID_BIT)) != 0)
1105+ break;
1106+
1107+ /* SHORT_PACKET_TRANSFERRED_INTERRUPT handles "usb-short"
1108+ * cases where DMA must be aborted; this code handles
1109+ * all non-abort DMA completions.
1110+ */
1111+ if (unlikely(req->td->dmadesc == 0)) {
1112+ /* paranoia */
1113+ tmp = readl(&ep->dma->dmacount);
1114+ if (tmp & DMA_BYTE_COUNT_MASK)
1115+ break;
1116+ /* single transfer mode */
1117+ dma_done(ep, req, tmp, 0);
1118+ break;
1119+ } else if (!ep->is_in &&
1120+ (req->req.length % ep->ep.maxpacket) != 0) {
1121+ tmp = readl(&ep->regs->ep_stat);
1122+ if (ep->dev->quirks & PLX_SUPERSPEED)
1123+ return dma_done(ep, req, tmp, 0);
1124+
1125+ /* AVOID TROUBLE HERE by not issuing short reads from
1126+ * your gadget driver. That helps avoids errata 0121,
1127+ * 0122, and 0124; not all cases trigger the warning.
1128+ */
1129+ if ((tmp & BIT(NAK_OUT_PACKETS)) == 0) {
1130+ ep_warn(ep->dev, "%s lost packet sync!\n",
1131+ ep->ep.name);
1132+ req->req.status = -EOVERFLOW;
1133+ } else {
1134+ tmp = readl(&ep->regs->ep_avail);
1135+ if (tmp) {
1136+ /* fifo gets flushed later */
1137+ ep->out_overflow = 1;
1138+ ep_dbg(ep->dev,
1139+ "%s dma, discard %d len %d\n",
1140+ ep->ep.name, tmp,
1141+ req->req.length);
1142+ req->req.status = -EOVERFLOW;
1143+ }
1144+ }
1145+ }
1146+ dma_done(ep, req, tmp, 0);
1147+ }
1148+}
1149+
1150+static void restart_dma(struct net2280_ep *ep)
1151+{
1152+ struct net2280_request *req;
1153+ u32 dmactl = dmactl_default;
1154+
1155+ if (ep->stopped)
1156+ return;
1157+ req = list_entry(ep->queue.next, struct net2280_request, queue);
1158+
1159+ if (!use_dma_chaining) {
1160+ start_dma(ep, req);
1161+ return;
1162+ }
1163+
1164+ /* the 2280 will be processing the queue unless queue hiccups after
1165+ * the previous transfer:
1166+ * IN: wanted automagic zlp, head doesn't (or vice versa)
1167+ * DMA_FIFO_VALIDATE doesn't init from dma descriptors.
1168+ * OUT: was "usb-short", we must restart.
1169+ */
1170+ if (ep->is_in && !req->valid) {
1171+ struct net2280_request *entry, *prev = NULL;
1172+ int reqmode, done = 0;
1173+
1174+ ep_dbg(ep->dev, "%s dma hiccup td %p\n", ep->ep.name, req->td);
1175+ ep->in_fifo_validate = likely(req->req.zero ||
1176+ (req->req.length % ep->ep.maxpacket) != 0);
1177+ if (ep->in_fifo_validate)
1178+ dmactl |= BIT(DMA_FIFO_VALIDATE);
1179+ list_for_each_entry(entry, &ep->queue, queue) {
1180+ __le32 dmacount;
1181+
1182+ if (entry == req)
1183+ continue;
1184+ dmacount = entry->td->dmacount;
1185+ if (!done) {
1186+ reqmode = likely(entry->req.zero ||
1187+ (entry->req.length % ep->ep.maxpacket));
1188+ if (reqmode == ep->in_fifo_validate) {
1189+ entry->valid = 1;
1190+ dmacount |= valid_bit;
1191+ entry->td->dmacount = dmacount;
1192+ prev = entry;
1193+ continue;
1194+ } else {
1195+ /* force a hiccup */
1196+ prev->td->dmacount |= dma_done_ie;
1197+ done = 1;
1198+ }
1199+ }
1200+
1201+ /* walk the rest of the queue so unlinks behave */
1202+ entry->valid = 0;
1203+ dmacount &= ~valid_bit;
1204+ entry->td->dmacount = dmacount;
1205+ prev = entry;
1206+ }
1207+ }
1208+
1209+ writel(0, &ep->dma->dmactl);
1210+ start_queue(ep, dmactl, req->td_dma);
1211+}
1212+
1213+static void abort_dma_228x(struct net2280_ep *ep)
1214+{
1215+ /* abort the current transfer */
1216+ if (likely(!list_empty(&ep->queue))) {
1217+ /* FIXME work around errata 0121, 0122, 0124 */
1218+ writel(BIT(DMA_ABORT), &ep->dma->dmastat);
1219+ spin_stop_dma(ep->dma);
1220+ } else
1221+ stop_dma(ep->dma);
1222+ scan_dma_completions(ep);
1223+}
1224+
1225+static void abort_dma_338x(struct net2280_ep *ep)
1226+{
1227+ writel(BIT(DMA_ABORT), &ep->dma->dmastat);
1228+ spin_stop_dma(ep->dma);
1229+}
1230+
1231+static void abort_dma(struct net2280_ep *ep)
1232+{
1233+ if (ep->dev->quirks & PLX_LEGACY)
1234+ return abort_dma_228x(ep);
1235+ return abort_dma_338x(ep);
1236+}
1237+
1238+/* dequeue ALL requests */
1239+static void nuke(struct net2280_ep *ep)
1240+{
1241+ struct net2280_request *req;
1242+
1243+ /* called with spinlock held */
1244+ ep->stopped = 1;
1245+ if (ep->dma)
1246+ abort_dma(ep);
1247+ while (!list_empty(&ep->queue)) {
1248+ req = list_entry(ep->queue.next,
1249+ struct net2280_request,
1250+ queue);
1251+ done(ep, req, -ESHUTDOWN);
1252+ }
1253+}
1254+
1255+/* dequeue JUST ONE request */
1256+static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1257+{
1258+ struct net2280_ep *ep;
1259+ struct net2280_request *req;
1260+ unsigned long flags;
1261+ u32 dmactl;
1262+ int stopped;
1263+
1264+ ep = container_of(_ep, struct net2280_ep, ep);
1265+ if (!_ep || (!ep->desc && ep->num != 0) || !_req)
1266+ return -EINVAL;
1267+
1268+ spin_lock_irqsave(&ep->dev->lock, flags);
1269+ stopped = ep->stopped;
1270+
1271+ /* quiesce dma while we patch the queue */
1272+ dmactl = 0;
1273+ ep->stopped = 1;
1274+ if (ep->dma) {
1275+ dmactl = readl(&ep->dma->dmactl);
1276+ /* WARNING erratum 0127 may kick in ... */
1277+ stop_dma(ep->dma);
1278+ scan_dma_completions(ep);
1279+ }
1280+
1281+ /* make sure it's still queued on this endpoint */
1282+ list_for_each_entry(req, &ep->queue, queue) {
1283+ if (&req->req == _req)
1284+ break;
1285+ }
1286+ if (&req->req != _req) {
1287+ spin_unlock_irqrestore(&ep->dev->lock, flags);
1288+ return -EINVAL;
1289+ }
1290+
1291+ /* queue head may be partially complete. */
1292+ if (ep->queue.next == &req->queue) {
1293+ if (ep->dma) {
1294+ ep_dbg(ep->dev, "unlink (%s) dma\n", _ep->name);
1295+ _req->status = -ECONNRESET;
1296+ abort_dma(ep);
1297+ if (likely(ep->queue.next == &req->queue)) {
1298+ /* NOTE: misreports single-transfer mode*/
1299+ req->td->dmacount = 0; /* invalidate */
1300+ dma_done(ep, req,
1301+ readl(&ep->dma->dmacount),
1302+ -ECONNRESET);
1303+ }
1304+ } else {
1305+ ep_dbg(ep->dev, "unlink (%s) pio\n", _ep->name);
1306+ done(ep, req, -ECONNRESET);
1307+ }
1308+ req = NULL;
1309+
1310+ /* patch up hardware chaining data */
1311+ } else if (ep->dma && use_dma_chaining) {
1312+ if (req->queue.prev == ep->queue.next) {
1313+ writel(le32_to_cpu(req->td->dmadesc),
1314+ &ep->dma->dmadesc);
1315+ if (req->td->dmacount & dma_done_ie)
1316+ writel(readl(&ep->dma->dmacount) |
1317+ le32_to_cpu(dma_done_ie),
1318+ &ep->dma->dmacount);
1319+ } else {
1320+ struct net2280_request *prev;
1321+
1322+ prev = list_entry(req->queue.prev,
1323+ struct net2280_request, queue);
1324+ prev->td->dmadesc = req->td->dmadesc;
1325+ if (req->td->dmacount & dma_done_ie)
1326+ prev->td->dmacount |= dma_done_ie;
1327+ }
1328+ }
1329+
1330+ if (req)
1331+ done(ep, req, -ECONNRESET);
1332+ ep->stopped = stopped;
1333+
1334+ if (ep->dma) {
1335+ /* turn off dma on inactive queues */
1336+ if (list_empty(&ep->queue))
1337+ stop_dma(ep->dma);
1338+ else if (!ep->stopped) {
1339+ /* resume current request, or start new one */
1340+ if (req)
1341+ writel(dmactl, &ep->dma->dmactl);
1342+ else
1343+ start_dma(ep, list_entry(ep->queue.next,
1344+ struct net2280_request, queue));
1345+ }
1346+ }
1347+
1348+ spin_unlock_irqrestore(&ep->dev->lock, flags);
1349+ return 0;
1350+}
1351+
1352+/*-------------------------------------------------------------------------*/
1353+
1354+static int net2280_fifo_status(struct usb_ep *_ep);
1355+
1356+static int
1357+net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
1358+{
1359+ struct net2280_ep *ep;
1360+ unsigned long flags;
1361+ int retval = 0;
1362+
1363+ ep = container_of(_ep, struct net2280_ep, ep);
1364+ if (!_ep || (!ep->desc && ep->num != 0))
1365+ return -EINVAL;
1366+ if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1367+ return -ESHUTDOWN;
1368+ if (ep->desc /* not ep0 */ && (ep->desc->bmAttributes & 0x03)
1369+ == USB_ENDPOINT_XFER_ISOC)
1370+ return -EINVAL;
1371+
1372+ spin_lock_irqsave(&ep->dev->lock, flags);
1373+ if (!list_empty(&ep->queue))
1374+ retval = -EAGAIN;
1375+ else if (ep->is_in && value && net2280_fifo_status(_ep) != 0)
1376+ retval = -EAGAIN;
1377+ else {
1378+ ep_vdbg(ep->dev, "%s %s %s\n", _ep->name,
1379+ value ? "set" : "clear",
1380+ wedged ? "wedge" : "halt");
1381+ /* set/clear, then synch memory views with the device */
1382+ if (value) {
1383+ if (ep->num == 0)
1384+ ep->dev->protocol_stall = 1;
1385+ else
1386+ set_halt(ep);
1387+ if (wedged)
1388+ ep->wedged = 1;
1389+ } else {
1390+ clear_halt(ep);
1391+ if (ep->dev->quirks & PLX_SUPERSPEED &&
1392+ !list_empty(&ep->queue) && ep->td_dma)
1393+ restart_dma(ep);
1394+ ep->wedged = 0;
1395+ }
1396+ (void) readl(&ep->regs->ep_rsp);
1397+ }
1398+ spin_unlock_irqrestore(&ep->dev->lock, flags);
1399+
1400+ return retval;
1401+}
1402+
1403+static int net2280_set_halt(struct usb_ep *_ep, int value)
1404+{
1405+ return net2280_set_halt_and_wedge(_ep, value, 0);
1406+}
1407+
1408+static int net2280_set_wedge(struct usb_ep *_ep)
1409+{
1410+ if (!_ep || _ep->name == ep0name)
1411+ return -EINVAL;
1412+ return net2280_set_halt_and_wedge(_ep, 1, 1);
1413+}
1414+
1415+static int net2280_fifo_status(struct usb_ep *_ep)
1416+{
1417+ struct net2280_ep *ep;
1418+ u32 avail;
1419+
1420+ ep = container_of(_ep, struct net2280_ep, ep);
1421+ if (!_ep || (!ep->desc && ep->num != 0))
1422+ return -ENODEV;
1423+ if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1424+ return -ESHUTDOWN;
1425+
1426+ avail = readl(&ep->regs->ep_avail) & (BIT(12) - 1);
1427+ if (avail > ep->fifo_size)
1428+ return -EOVERFLOW;
1429+ if (ep->is_in)
1430+ avail = ep->fifo_size - avail;
1431+ return avail;
1432+}
1433+
1434+static void net2280_fifo_flush(struct usb_ep *_ep)
1435+{
1436+ struct net2280_ep *ep;
1437+
1438+ ep = container_of(_ep, struct net2280_ep, ep);
1439+ if (!_ep || (!ep->desc && ep->num != 0))
1440+ return;
1441+ if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1442+ return;
1443+
1444+ writel(BIT(FIFO_FLUSH), &ep->regs->ep_stat);
1445+ (void) readl(&ep->regs->ep_rsp);
1446+}
1447+
1448+static const struct usb_ep_ops net2280_ep_ops = {
1449+ .enable = net2280_enable,
1450+ .disable = net2280_disable,
1451+
1452+ .alloc_request = net2280_alloc_request,
1453+ .free_request = net2280_free_request,
1454+
1455+ .queue = net2280_queue,
1456+ .dequeue = net2280_dequeue,
1457+
1458+ .set_halt = net2280_set_halt,
1459+ .set_wedge = net2280_set_wedge,
1460+ .fifo_status = net2280_fifo_status,
1461+ .fifo_flush = net2280_fifo_flush,
1462+};
1463+
1464+/*-------------------------------------------------------------------------*/
1465+
1466+static int net2280_get_frame(struct usb_gadget *_gadget)
1467+{
1468+ struct net2280 *dev;
1469+ unsigned long flags;
1470+ u16 retval;
1471+
1472+ if (!_gadget)
1473+ return -ENODEV;
1474+ dev = container_of(_gadget, struct net2280, gadget);
1475+ spin_lock_irqsave(&dev->lock, flags);
1476+ retval = get_idx_reg(dev->regs, REG_FRAME) & 0x03ff;
1477+ spin_unlock_irqrestore(&dev->lock, flags);
1478+ return retval;
1479+}
1480+
1481+static int net2280_wakeup(struct usb_gadget *_gadget)
1482+{
1483+ struct net2280 *dev;
1484+ u32 tmp;
1485+ unsigned long flags;
1486+
1487+ if (!_gadget)
1488+ return 0;
1489+ dev = container_of(_gadget, struct net2280, gadget);
1490+
1491+ spin_lock_irqsave(&dev->lock, flags);
1492+ tmp = readl(&dev->usb->usbctl);
1493+ if (tmp & BIT(DEVICE_REMOTE_WAKEUP_ENABLE))
1494+ writel(BIT(GENERATE_RESUME), &dev->usb->usbstat);
1495+ spin_unlock_irqrestore(&dev->lock, flags);
1496+
1497+ /* pci writes may still be posted */
1498+ return 0;
1499+}
1500+
1501+static int net2280_set_selfpowered(struct usb_gadget *_gadget, int value)
1502+{
1503+ struct net2280 *dev;
1504+ u32 tmp;
1505+ unsigned long flags;
1506+
1507+ if (!_gadget)
1508+ return 0;
1509+ dev = container_of(_gadget, struct net2280, gadget);
1510+
1511+ spin_lock_irqsave(&dev->lock, flags);
1512+ tmp = readl(&dev->usb->usbctl);
1513+ if (value) {
1514+ tmp |= BIT(SELF_POWERED_STATUS);
1515+ dev->selfpowered = 1;
1516+ } else {
1517+ tmp &= ~BIT(SELF_POWERED_STATUS);
1518+ dev->selfpowered = 0;
1519+ }
1520+ writel(tmp, &dev->usb->usbctl);
1521+ spin_unlock_irqrestore(&dev->lock, flags);
1522+
1523+ return 0;
1524+}
1525+
1526+static int net2280_pullup(struct usb_gadget *_gadget, int is_on)
1527+{
1528+ struct net2280 *dev;
1529+ u32 tmp;
1530+ unsigned long flags;
1531+
1532+ if (!_gadget)
1533+ return -ENODEV;
1534+ dev = container_of(_gadget, struct net2280, gadget);
1535+
1536+ spin_lock_irqsave(&dev->lock, flags);
1537+ tmp = readl(&dev->usb->usbctl);
1538+ dev->softconnect = (is_on != 0);
1539+ if (is_on)
1540+ tmp |= BIT(USB_DETECT_ENABLE);
1541+ else
1542+ tmp &= ~BIT(USB_DETECT_ENABLE);
1543+ writel(tmp, &dev->usb->usbctl);
1544+ spin_unlock_irqrestore(&dev->lock, flags);
1545+
1546+ return 0;
1547+}
1548+
1549+static int net2280_start(struct usb_gadget *_gadget,
1550+ struct usb_gadget_driver *driver);
1551+static int net2280_stop(struct usb_gadget *_gadget,
1552+ struct usb_gadget_driver *driver);
1553+
1554+static const struct usb_gadget_ops net2280_ops = {
1555+ .get_frame = net2280_get_frame,
1556+ .wakeup = net2280_wakeup,
1557+ .set_selfpowered = net2280_set_selfpowered,
1558+ .pullup = net2280_pullup,
1559+ .udc_start = net2280_start,
1560+ .udc_stop = net2280_stop,
1561+};
1562+
1563+/*-------------------------------------------------------------------------*/
1564+
1565+#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1566+
1567+/* FIXME move these into procfs, and use seq_file.
1568+ * Sysfs _still_ doesn't behave for arbitrarily sized files,
1569+ * and also doesn't help products using this with 2.4 kernels.
1570+ */
1571+
1572+/* "function" sysfs attribute */
1573+static ssize_t function_show(struct device *_dev, struct device_attribute *attr,
1574+ char *buf)
1575+{
1576+ struct net2280 *dev = dev_get_drvdata(_dev);
1577+
1578+ if (!dev->driver || !dev->driver->function ||
1579+ strlen(dev->driver->function) > PAGE_SIZE)
1580+ return 0;
1581+ return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->function);
1582+}
1583+static DEVICE_ATTR_RO(function);
1584+
1585+static ssize_t registers_show(struct device *_dev,
1586+ struct device_attribute *attr, char *buf)
1587+{
1588+ struct net2280 *dev;
1589+ char *next;
1590+ unsigned size, t;
1591+ unsigned long flags;
1592+ int i;
1593+ u32 t1, t2;
1594+ const char *s;
1595+
1596+ dev = dev_get_drvdata(_dev);
1597+ next = buf;
1598+ size = PAGE_SIZE;
1599+ spin_lock_irqsave(&dev->lock, flags);
1600+
1601+ if (dev->driver)
1602+ s = dev->driver->driver.name;
1603+ else
1604+ s = "(none)";
1605+
1606+ /* Main Control Registers */
1607+ t = scnprintf(next, size, "%s version " DRIVER_VERSION
1608+ ", chiprev %04x, dma %s\n\n"
1609+ "devinit %03x fifoctl %08x gadget '%s'\n"
1610+ "pci irqenb0 %02x irqenb1 %08x "
1611+ "irqstat0 %04x irqstat1 %08x\n",
1612+ driver_name, dev->chiprev,
1613+ use_dma
1614+ ? (use_dma_chaining ? "chaining" : "enabled")
1615+ : "disabled",
1616+ readl(&dev->regs->devinit),
1617+ readl(&dev->regs->fifoctl),
1618+ s,
1619+ readl(&dev->regs->pciirqenb0),
1620+ readl(&dev->regs->pciirqenb1),
1621+ readl(&dev->regs->irqstat0),
1622+ readl(&dev->regs->irqstat1));
1623+ size -= t;
1624+ next += t;
1625+
1626+ /* USB Control Registers */
1627+ t1 = readl(&dev->usb->usbctl);
1628+ t2 = readl(&dev->usb->usbstat);
1629+ if (t1 & BIT(VBUS_PIN)) {
1630+ if (t2 & BIT(HIGH_SPEED))
1631+ s = "high speed";
1632+ else if (dev->gadget.speed == USB_SPEED_UNKNOWN)
1633+ s = "powered";
1634+ else
1635+ s = "full speed";
1636+ /* full speed bit (6) not working?? */
1637+ } else
1638+ s = "not attached";
1639+ t = scnprintf(next, size,
1640+ "stdrsp %08x usbctl %08x usbstat %08x "
1641+ "addr 0x%02x (%s)\n",
1642+ readl(&dev->usb->stdrsp), t1, t2,
1643+ readl(&dev->usb->ouraddr), s);
1644+ size -= t;
1645+ next += t;
1646+
1647+ /* PCI Master Control Registers */
1648+
1649+ /* DMA Control Registers */
1650+
1651+ /* Configurable EP Control Registers */
1652+ for (i = 0; i < dev->n_ep; i++) {
1653+ struct net2280_ep *ep;
1654+
1655+ ep = &dev->ep[i];
1656+ if (i && !ep->desc)
1657+ continue;
1658+
1659+ t1 = readl(&ep->cfg->ep_cfg);
1660+ t2 = readl(&ep->regs->ep_rsp) & 0xff;
1661+ t = scnprintf(next, size,
1662+ "\n%s\tcfg %05x rsp (%02x) %s%s%s%s%s%s%s%s"
1663+ "irqenb %02x\n",
1664+ ep->ep.name, t1, t2,
1665+ (t2 & BIT(CLEAR_NAK_OUT_PACKETS))
1666+ ? "NAK " : "",
1667+ (t2 & BIT(CLEAR_EP_HIDE_STATUS_PHASE))
1668+ ? "hide " : "",
1669+ (t2 & BIT(CLEAR_EP_FORCE_CRC_ERROR))
1670+ ? "CRC " : "",
1671+ (t2 & BIT(CLEAR_INTERRUPT_MODE))
1672+ ? "interrupt " : "",
1673+ (t2 & BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE))
1674+ ? "status " : "",
1675+ (t2 & BIT(CLEAR_NAK_OUT_PACKETS_MODE))
1676+ ? "NAKmode " : "",
1677+ (t2 & BIT(CLEAR_ENDPOINT_TOGGLE))
1678+ ? "DATA1 " : "DATA0 ",
1679+ (t2 & BIT(CLEAR_ENDPOINT_HALT))
1680+ ? "HALT " : "",
1681+ readl(&ep->regs->ep_irqenb));
1682+ size -= t;
1683+ next += t;
1684+
1685+ t = scnprintf(next, size,
1686+ "\tstat %08x avail %04x "
1687+ "(ep%d%s-%s)%s\n",
1688+ readl(&ep->regs->ep_stat),
1689+ readl(&ep->regs->ep_avail),
1690+ t1 & 0x0f, DIR_STRING(t1),
1691+ type_string(t1 >> 8),
1692+ ep->stopped ? "*" : "");
1693+ size -= t;
1694+ next += t;
1695+
1696+ if (!ep->dma)
1697+ continue;
1698+
1699+ t = scnprintf(next, size,
1700+ " dma\tctl %08x stat %08x count %08x\n"
1701+ "\taddr %08x desc %08x\n",
1702+ readl(&ep->dma->dmactl),
1703+ readl(&ep->dma->dmastat),
1704+ readl(&ep->dma->dmacount),
1705+ readl(&ep->dma->dmaaddr),
1706+ readl(&ep->dma->dmadesc));
1707+ size -= t;
1708+ next += t;
1709+
1710+ }
1711+
1712+ /* Indexed Registers (none yet) */
1713+
1714+ /* Statistics */
1715+ t = scnprintf(next, size, "\nirqs: ");
1716+ size -= t;
1717+ next += t;
1718+ for (i = 0; i < dev->n_ep; i++) {
1719+ struct net2280_ep *ep;
1720+
1721+ ep = &dev->ep[i];
1722+ if (i && !ep->irqs)
1723+ continue;
1724+ t = scnprintf(next, size, " %s/%lu", ep->ep.name, ep->irqs);
1725+ size -= t;
1726+ next += t;
1727+
1728+ }
1729+ t = scnprintf(next, size, "\n");
1730+ size -= t;
1731+ next += t;
1732+
1733+ spin_unlock_irqrestore(&dev->lock, flags);
1734+
1735+ return PAGE_SIZE - size;
1736+}
1737+static DEVICE_ATTR_RO(registers);
1738+
1739+static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
1740+ char *buf)
1741+{
1742+ struct net2280 *dev;
1743+ char *next;
1744+ unsigned size;
1745+ unsigned long flags;
1746+ int i;
1747+
1748+ dev = dev_get_drvdata(_dev);
1749+ next = buf;
1750+ size = PAGE_SIZE;
1751+ spin_lock_irqsave(&dev->lock, flags);
1752+
1753+ for (i = 0; i < dev->n_ep; i++) {
1754+ struct net2280_ep *ep = &dev->ep[i];
1755+ struct net2280_request *req;
1756+ int t;
1757+
1758+ if (i != 0) {
1759+ const struct usb_endpoint_descriptor *d;
1760+
1761+ d = ep->desc;
1762+ if (!d)
1763+ continue;
1764+ t = d->bEndpointAddress;
1765+ t = scnprintf(next, size,
1766+ "\n%s (ep%d%s-%s) max %04x %s fifo %d\n",
1767+ ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK,
1768+ (t & USB_DIR_IN) ? "in" : "out",
1769+ type_string(d->bmAttributes),
1770+ usb_endpoint_maxp(d) & 0x1fff,
1771+ ep->dma ? "dma" : "pio", ep->fifo_size
1772+ );
1773+ } else /* ep0 should only have one transfer queued */
1774+ t = scnprintf(next, size, "ep0 max 64 pio %s\n",
1775+ ep->is_in ? "in" : "out");
1776+ if (t <= 0 || t > size)
1777+ goto done;
1778+ size -= t;
1779+ next += t;
1780+
1781+ if (list_empty(&ep->queue)) {
1782+ t = scnprintf(next, size, "\t(nothing queued)\n");
1783+ if (t <= 0 || t > size)
1784+ goto done;
1785+ size -= t;
1786+ next += t;
1787+ continue;
1788+ }
1789+ list_for_each_entry(req, &ep->queue, queue) {
1790+ if (ep->dma && req->td_dma == readl(&ep->dma->dmadesc))
1791+ t = scnprintf(next, size,
1792+ "\treq %p len %d/%d "
1793+ "buf %p (dmacount %08x)\n",
1794+ &req->req, req->req.actual,
1795+ req->req.length, req->req.buf,
1796+ readl(&ep->dma->dmacount));
1797+ else
1798+ t = scnprintf(next, size,
1799+ "\treq %p len %d/%d buf %p\n",
1800+ &req->req, req->req.actual,
1801+ req->req.length, req->req.buf);
1802+ if (t <= 0 || t > size)
1803+ goto done;
1804+ size -= t;
1805+ next += t;
1806+
1807+ if (ep->dma) {
1808+ struct net2280_dma *td;
1809+
1810+ td = req->td;
1811+ t = scnprintf(next, size, "\t td %08x "
1812+ " count %08x buf %08x desc %08x\n",
1813+ (u32) req->td_dma,
1814+ le32_to_cpu(td->dmacount),
1815+ le32_to_cpu(td->dmaaddr),
1816+ le32_to_cpu(td->dmadesc));
1817+ if (t <= 0 || t > size)
1818+ goto done;
1819+ size -= t;
1820+ next += t;
1821+ }
1822+ }
1823+ }
1824+
1825+done:
1826+ spin_unlock_irqrestore(&dev->lock, flags);
1827+ return PAGE_SIZE - size;
1828+}
1829+static DEVICE_ATTR_RO(queues);
1830+
1831+
1832+#else
1833+
1834+#define device_create_file(a, b) (0)
1835+#define device_remove_file(a, b) do { } while (0)
1836+
1837+#endif
1838+
1839+/*-------------------------------------------------------------------------*/
1840+
1841+/* another driver-specific mode might be a request type doing dma
1842+ * to/from another device fifo instead of to/from memory.
1843+ */
1844+
1845+static void set_fifo_mode(struct net2280 *dev, int mode)
1846+{
1847+ /* keeping high bits preserves BAR2 */
1848+ writel((0xffff << PCI_BASE2_RANGE) | mode, &dev->regs->fifoctl);
1849+
1850+ /* always ep-{a,b,e,f} ... maybe not ep-c or ep-d */
1851+ INIT_LIST_HEAD(&dev->gadget.ep_list);
1852+ list_add_tail(&dev->ep[1].ep.ep_list, &dev->gadget.ep_list);
1853+ list_add_tail(&dev->ep[2].ep.ep_list, &dev->gadget.ep_list);
1854+ switch (mode) {
1855+ case 0:
1856+ list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list);
1857+ list_add_tail(&dev->ep[4].ep.ep_list, &dev->gadget.ep_list);
1858+ dev->ep[1].fifo_size = dev->ep[2].fifo_size = 1024;
1859+ break;
1860+ case 1:
1861+ dev->ep[1].fifo_size = dev->ep[2].fifo_size = 2048;
1862+ break;
1863+ case 2:
1864+ list_add_tail(&dev->ep[3].ep.ep_list, &dev->gadget.ep_list);
1865+ dev->ep[1].fifo_size = 2048;
1866+ dev->ep[2].fifo_size = 1024;
1867+ break;
1868+ }
1869+ /* fifo sizes for ep0, ep-c, ep-d, ep-e, and ep-f never change */
1870+ list_add_tail(&dev->ep[5].ep.ep_list, &dev->gadget.ep_list);
1871+ list_add_tail(&dev->ep[6].ep.ep_list, &dev->gadget.ep_list);
1872+}
1873+
1874+static void defect7374_disable_data_eps(struct net2280 *dev)
1875+{
1876+ /*
1877+ * For Defect 7374, disable data EPs (and more):
1878+ * - This phase undoes the earlier phase of the Defect 7374 workaround,
1879+ * returing ep regs back to normal.
1880+ */
1881+ struct net2280_ep *ep;
1882+ int i;
1883+ unsigned char ep_sel;
1884+ u32 tmp_reg;
1885+
1886+ for (i = 1; i < 5; i++) {
1887+ ep = &dev->ep[i];
1888+ writel(0, &ep->cfg->ep_cfg);
1889+ }
1890+
1891+ /* CSROUT, CSRIN, PCIOUT, PCIIN, STATIN, RCIN */
1892+ for (i = 0; i < 6; i++)
1893+ writel(0, &dev->dep[i].dep_cfg);
1894+
1895+ for (ep_sel = 0; ep_sel <= 21; ep_sel++) {
1896+ /* Select an endpoint for subsequent operations: */
1897+ tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1898+ writel(((tmp_reg & ~0x1f) | ep_sel), &dev->plregs->pl_ep_ctrl);
1899+
1900+ if (ep_sel < 2 || (ep_sel > 9 && ep_sel < 14) ||
1901+ ep_sel == 18 || ep_sel == 20)
1902+ continue;
1903+
1904+ /* Change settings on some selected endpoints */
1905+ tmp_reg = readl(&dev->plregs->pl_ep_cfg_4);
1906+ tmp_reg &= ~BIT(NON_CTRL_IN_TOLERATE_BAD_DIR);
1907+ writel(tmp_reg, &dev->plregs->pl_ep_cfg_4);
1908+ tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1909+ tmp_reg |= BIT(EP_INITIALIZED);
1910+ writel(tmp_reg, &dev->plregs->pl_ep_ctrl);
1911+ }
1912+}
1913+
1914+static void defect7374_enable_data_eps_zero(struct net2280 *dev)
1915+{
1916+ u32 tmp = 0, tmp_reg;
1917+ u32 fsmvalue, scratch;
1918+ int i;
1919+ unsigned char ep_sel;
1920+
1921+ scratch = get_idx_reg(dev->regs, SCRATCH);
1922+ fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD);
1923+ scratch &= ~(0xf << DEFECT7374_FSM_FIELD);
1924+
1925+ /*See if firmware needs to set up for workaround*/
1926+ if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) {
1927+ ep_warn(dev, "Operate Defect 7374 workaround soft this time");
1928+ ep_warn(dev, "It will operate on cold-reboot and SS connect");
1929+
1930+ /*GPEPs:*/
1931+ tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_DIRECTION) |
1932+ (2 << OUT_ENDPOINT_TYPE) | (2 << IN_ENDPOINT_TYPE) |
1933+ ((dev->enhanced_mode) ?
1934+ BIT(OUT_ENDPOINT_ENABLE) : BIT(ENDPOINT_ENABLE)) |
1935+ BIT(IN_ENDPOINT_ENABLE));
1936+
1937+ for (i = 1; i < 5; i++)
1938+ writel(tmp, &dev->ep[i].cfg->ep_cfg);
1939+
1940+ /* CSRIN, PCIIN, STATIN, RCIN*/
1941+ tmp = ((0 << ENDPOINT_NUMBER) | BIT(ENDPOINT_ENABLE));
1942+ writel(tmp, &dev->dep[1].dep_cfg);
1943+ writel(tmp, &dev->dep[3].dep_cfg);
1944+ writel(tmp, &dev->dep[4].dep_cfg);
1945+ writel(tmp, &dev->dep[5].dep_cfg);
1946+
1947+ /*Implemented for development and debug.
1948+ * Can be refined/tuned later.*/
1949+ for (ep_sel = 0; ep_sel <= 21; ep_sel++) {
1950+ /* Select an endpoint for subsequent operations: */
1951+ tmp_reg = readl(&dev->plregs->pl_ep_ctrl);
1952+ writel(((tmp_reg & ~0x1f) | ep_sel),
1953+ &dev->plregs->pl_ep_ctrl);
1954+
1955+ if (ep_sel == 1) {
1956+ tmp =
1957+ (readl(&dev->plregs->pl_ep_ctrl) |
1958+ BIT(CLEAR_ACK_ERROR_CODE) | 0);
1959+ writel(tmp, &dev->plregs->pl_ep_ctrl);
1960+ continue;
1961+ }
1962+
1963+ if (ep_sel == 0 || (ep_sel > 9 && ep_sel < 14) ||
1964+ ep_sel == 18 || ep_sel == 20)
1965+ continue;
1966+
1967+ tmp = (readl(&dev->plregs->pl_ep_cfg_4) |
1968+ BIT(NON_CTRL_IN_TOLERATE_BAD_DIR) | 0);
1969+ writel(tmp, &dev->plregs->pl_ep_cfg_4);
1970+
1971+ tmp = readl(&dev->plregs->pl_ep_ctrl) &
1972+ ~BIT(EP_INITIALIZED);
1973+ writel(tmp, &dev->plregs->pl_ep_ctrl);
1974+
1975+ }
1976+
1977+ /* Set FSM to focus on the first Control Read:
1978+ * - Tip: Connection speed is known upon the first
1979+ * setup request.*/
1980+ scratch |= DEFECT7374_FSM_WAITING_FOR_CONTROL_READ;
1981+ set_idx_reg(dev->regs, SCRATCH, scratch);
1982+
1983+ } else{
1984+ ep_warn(dev, "Defect 7374 workaround soft will NOT operate");
1985+ ep_warn(dev, "It will operate on cold-reboot and SS connect");
1986+ }
1987+}
1988+
1989+/* keeping it simple:
1990+ * - one bus driver, initted first;
1991+ * - one function driver, initted second
1992+ *
1993+ * most of the work to support multiple net2280 controllers would
1994+ * be to associate this gadget driver (yes?) with all of them, or
1995+ * perhaps to bind specific drivers to specific devices.
1996+ */
1997+
1998+static void usb_reset_228x(struct net2280 *dev)
1999+{
2000+ u32 tmp;
2001+
2002+ dev->gadget.speed = USB_SPEED_UNKNOWN;
2003+ (void) readl(&dev->usb->usbctl);
2004+
2005+ net2280_led_init(dev);
2006+
2007+ /* disable automatic responses, and irqs */
2008+ writel(0, &dev->usb->stdrsp);
2009+ writel(0, &dev->regs->pciirqenb0);
2010+ writel(0, &dev->regs->pciirqenb1);
2011+
2012+ /* clear old dma and irq state */
2013+ for (tmp = 0; tmp < 4; tmp++) {
2014+ struct net2280_ep *ep = &dev->ep[tmp + 1];
2015+ if (ep->dma)
2016+ abort_dma(ep);
2017+ }
2018+
2019+ writel(~0, &dev->regs->irqstat0),
2020+ writel(~(u32)BIT(SUSPEND_REQUEST_INTERRUPT), &dev->regs->irqstat1),
2021+
2022+ /* reset, and enable pci */
2023+ tmp = readl(&dev->regs->devinit) |
2024+ BIT(PCI_ENABLE) |
2025+ BIT(FIFO_SOFT_RESET) |
2026+ BIT(USB_SOFT_RESET) |
2027+ BIT(M8051_RESET);
2028+ writel(tmp, &dev->regs->devinit);
2029+
2030+ /* standard fifo and endpoint allocations */
2031+ set_fifo_mode(dev, (fifo_mode <= 2) ? fifo_mode : 0);
2032+}
2033+
2034+static void usb_reset_338x(struct net2280 *dev)
2035+{
2036+ u32 tmp;
2037+ u32 fsmvalue;
2038+
2039+ dev->gadget.speed = USB_SPEED_UNKNOWN;
2040+ (void)readl(&dev->usb->usbctl);
2041+
2042+ net2280_led_init(dev);
2043+
2044+ fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
2045+ (0xf << DEFECT7374_FSM_FIELD);
2046+
2047+ /* See if firmware needs to set up for workaround: */
2048+ if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ) {
2049+ ep_info(dev, "%s: Defect 7374 FsmValue 0x%08x\n", __func__,
2050+ fsmvalue);
2051+ } else {
2052+ /* disable automatic responses, and irqs */
2053+ writel(0, &dev->usb->stdrsp);
2054+ writel(0, &dev->regs->pciirqenb0);
2055+ writel(0, &dev->regs->pciirqenb1);
2056+ }
2057+
2058+ /* clear old dma and irq state */
2059+ for (tmp = 0; tmp < 4; tmp++) {
2060+ struct net2280_ep *ep = &dev->ep[tmp + 1];
2061+
2062+ if (ep->dma)
2063+ abort_dma(ep);
2064+ }
2065+
2066+ writel(~0, &dev->regs->irqstat0), writel(~0, &dev->regs->irqstat1);
2067+
2068+ if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ) {
2069+ /* reset, and enable pci */
2070+ tmp = readl(&dev->regs->devinit) |
2071+ BIT(PCI_ENABLE) |
2072+ BIT(FIFO_SOFT_RESET) |
2073+ BIT(USB_SOFT_RESET) |
2074+ BIT(M8051_RESET);
2075+
2076+ writel(tmp, &dev->regs->devinit);
2077+ }
2078+
2079+ /* always ep-{1,2,3,4} ... maybe not ep-3 or ep-4 */
2080+ INIT_LIST_HEAD(&dev->gadget.ep_list);
2081+
2082+ for (tmp = 1; tmp < dev->n_ep; tmp++)
2083+ list_add_tail(&dev->ep[tmp].ep.ep_list, &dev->gadget.ep_list);
2084+
2085+}
2086+
2087+static void usb_reset(struct net2280 *dev)
2088+{
2089+ if (dev->quirks & PLX_LEGACY)
2090+ return usb_reset_228x(dev);
2091+ return usb_reset_338x(dev);
2092+}
2093+
2094+static void usb_reinit_228x(struct net2280 *dev)
2095+{
2096+ u32 tmp;
2097+ int init_dma;
2098+
2099+ /* use_dma changes are ignored till next device re-init */
2100+ init_dma = use_dma;
2101+
2102+ /* basic endpoint init */
2103+ for (tmp = 0; tmp < 7; tmp++) {
2104+ struct net2280_ep *ep = &dev->ep[tmp];
2105+
2106+ ep->ep.name = ep_name[tmp];
2107+ ep->dev = dev;
2108+ ep->num = tmp;
2109+
2110+ if (tmp > 0 && tmp <= 4) {
2111+ ep->fifo_size = 1024;
2112+ if (init_dma)
2113+ ep->dma = &dev->dma[tmp - 1];
2114+ } else
2115+ ep->fifo_size = 64;
2116+ ep->regs = &dev->epregs[tmp];
2117+ ep->cfg = &dev->epregs[tmp];
2118+ ep_reset_228x(dev->regs, ep);
2119+ }
2120+ usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 64);
2121+ usb_ep_set_maxpacket_limit(&dev->ep[5].ep, 64);
2122+ usb_ep_set_maxpacket_limit(&dev->ep[6].ep, 64);
2123+
2124+ dev->gadget.ep0 = &dev->ep[0].ep;
2125+ dev->ep[0].stopped = 0;
2126+ INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
2127+
2128+ /* we want to prevent lowlevel/insecure access from the USB host,
2129+ * but erratum 0119 means this enable bit is ignored
2130+ */
2131+ for (tmp = 0; tmp < 5; tmp++)
2132+ writel(EP_DONTUSE, &dev->dep[tmp].dep_cfg);
2133+}
2134+
2135+static void usb_reinit_338x(struct net2280 *dev)
2136+{
2137+ int init_dma;
2138+ int i;
2139+ u32 tmp, val;
2140+ u32 fsmvalue;
2141+ static const u32 ne[9] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };
2142+ static const u32 ep_reg_addr[9] = { 0x00, 0xC0, 0x00, 0xC0, 0x00,
2143+ 0x00, 0xC0, 0x00, 0xC0 };
2144+
2145+ /* use_dma changes are ignored till next device re-init */
2146+ init_dma = use_dma;
2147+
2148+ /* basic endpoint init */
2149+ for (i = 0; i < dev->n_ep; i++) {
2150+ struct net2280_ep *ep = &dev->ep[i];
2151+
2152+ ep->ep.name = ep_name[i];
2153+ ep->dev = dev;
2154+ ep->num = i;
2155+
2156+ if (i > 0 && i <= 4 && init_dma)
2157+ ep->dma = &dev->dma[i - 1];
2158+
2159+ if (dev->enhanced_mode) {
2160+ ep->cfg = &dev->epregs[ne[i]];
2161+ ep->regs = (struct net2280_ep_regs __iomem *)
2162+ (((void __iomem *)&dev->epregs[ne[i]]) +
2163+ ep_reg_addr[i]);
2164+ ep->fiforegs = &dev->fiforegs[i];
2165+ } else {
2166+ ep->cfg = &dev->epregs[i];
2167+ ep->regs = &dev->epregs[i];
2168+ ep->fiforegs = &dev->fiforegs[i];
2169+ }
2170+
2171+ ep->fifo_size = (i != 0) ? 2048 : 512;
2172+
2173+ ep_reset_338x(dev->regs, ep);
2174+ }
2175+ usb_ep_set_maxpacket_limit(&dev->ep[0].ep, 512);
2176+
2177+ dev->gadget.ep0 = &dev->ep[0].ep;
2178+ dev->ep[0].stopped = 0;
2179+
2180+ /* Link layer set up */
2181+ fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
2182+ (0xf << DEFECT7374_FSM_FIELD);
2183+
2184+ /* See if driver needs to set up for workaround: */
2185+ if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ)
2186+ ep_info(dev, "%s: Defect 7374 FsmValue %08x\n",
2187+ __func__, fsmvalue);
2188+ else {
2189+ tmp = readl(&dev->usb_ext->usbctl2) &
2190+ ~(BIT(U1_ENABLE) | BIT(U2_ENABLE) | BIT(LTM_ENABLE));
2191+ writel(tmp, &dev->usb_ext->usbctl2);
2192+ }
2193+
2194+ /* Hardware Defect and Workaround */
2195+ val = readl(&dev->ll_lfps_regs->ll_lfps_5);
2196+ val &= ~(0xf << TIMER_LFPS_6US);
2197+ val |= 0x5 << TIMER_LFPS_6US;
2198+ writel(val, &dev->ll_lfps_regs->ll_lfps_5);
2199+
2200+ val = readl(&dev->ll_lfps_regs->ll_lfps_6);
2201+ val &= ~(0xffff << TIMER_LFPS_80US);
2202+ val |= 0x0100 << TIMER_LFPS_80US;
2203+ writel(val, &dev->ll_lfps_regs->ll_lfps_6);
2204+
2205+ /*
2206+ * AA_AB Errata. Issue 4. Workaround for SuperSpeed USB
2207+ * Hot Reset Exit Handshake may Fail in Specific Case using
2208+ * Default Register Settings. Workaround for Enumeration test.
2209+ */
2210+ val = readl(&dev->ll_tsn_regs->ll_tsn_counters_2);
2211+ val &= ~(0x1f << HOT_TX_NORESET_TS2);
2212+ val |= 0x10 << HOT_TX_NORESET_TS2;
2213+ writel(val, &dev->ll_tsn_regs->ll_tsn_counters_2);
2214+
2215+ val = readl(&dev->ll_tsn_regs->ll_tsn_counters_3);
2216+ val &= ~(0x1f << HOT_RX_RESET_TS2);
2217+ val |= 0x3 << HOT_RX_RESET_TS2;
2218+ writel(val, &dev->ll_tsn_regs->ll_tsn_counters_3);
2219+
2220+ /*
2221+ * Set Recovery Idle to Recover bit:
2222+ * - On SS connections, setting Recovery Idle to Recover Fmw improves
2223+ * link robustness with various hosts and hubs.
2224+ * - It is safe to set for all connection speeds; all chip revisions.
2225+ * - R-M-W to leave other bits undisturbed.
2226+ * - Reference PLX TT-7372
2227+ */
2228+ val = readl(&dev->ll_chicken_reg->ll_tsn_chicken_bit);
2229+ val |= BIT(RECOVERY_IDLE_TO_RECOVER_FMW);
2230+ writel(val, &dev->ll_chicken_reg->ll_tsn_chicken_bit);
2231+
2232+ INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
2233+
2234+ /* disable dedicated endpoints */
2235+ writel(0x0D, &dev->dep[0].dep_cfg);
2236+ writel(0x0D, &dev->dep[1].dep_cfg);
2237+ writel(0x0E, &dev->dep[2].dep_cfg);
2238+ writel(0x0E, &dev->dep[3].dep_cfg);
2239+ writel(0x0F, &dev->dep[4].dep_cfg);
2240+ writel(0x0C, &dev->dep[5].dep_cfg);
2241+}
2242+
2243+static void usb_reinit(struct net2280 *dev)
2244+{
2245+ if (dev->quirks & PLX_LEGACY)
2246+ return usb_reinit_228x(dev);
2247+ return usb_reinit_338x(dev);
2248+}
2249+
2250+static void ep0_start_228x(struct net2280 *dev)
2251+{
2252+ writel(BIT(CLEAR_EP_HIDE_STATUS_PHASE) |
2253+ BIT(CLEAR_NAK_OUT_PACKETS) |
2254+ BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE),
2255+ &dev->epregs[0].ep_rsp);
2256+
2257+ /*
2258+ * hardware optionally handles a bunch of standard requests
2259+ * that the API hides from drivers anyway. have it do so.
2260+ * endpoint status/features are handled in software, to
2261+ * help pass tests for some dubious behavior.
2262+ */
2263+ writel(BIT(SET_TEST_MODE) |
2264+ BIT(SET_ADDRESS) |
2265+ BIT(DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP) |
2266+ BIT(GET_DEVICE_STATUS) |
2267+ BIT(GET_INTERFACE_STATUS),
2268+ &dev->usb->stdrsp);
2269+ writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) |
2270+ BIT(SELF_POWERED_USB_DEVICE) |
2271+ BIT(REMOTE_WAKEUP_SUPPORT) |
2272+ (dev->softconnect << USB_DETECT_ENABLE) |
2273+ BIT(SELF_POWERED_STATUS),
2274+ &dev->usb->usbctl);
2275+
2276+ /* enable irqs so we can see ep0 and general operation */
2277+ writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) |
2278+ BIT(ENDPOINT_0_INTERRUPT_ENABLE),
2279+ &dev->regs->pciirqenb0);
2280+ writel(BIT(PCI_INTERRUPT_ENABLE) |
2281+ BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE) |
2282+ BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE) |
2283+ BIT(PCI_RETRY_ABORT_INTERRUPT_ENABLE) |
2284+ BIT(VBUS_INTERRUPT_ENABLE) |
2285+ BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) |
2286+ BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE),
2287+ &dev->regs->pciirqenb1);
2288+
2289+ /* don't leave any writes posted */
2290+ (void) readl(&dev->usb->usbctl);
2291+}
2292+
2293+static void ep0_start_338x(struct net2280 *dev)
2294+{
2295+ u32 fsmvalue;
2296+
2297+ fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
2298+ (0xf << DEFECT7374_FSM_FIELD);
2299+
2300+ if (fsmvalue != DEFECT7374_FSM_SS_CONTROL_READ)
2301+ ep_info(dev, "%s: Defect 7374 FsmValue %08x\n", __func__,
2302+ fsmvalue);
2303+ else
2304+ writel(BIT(CLEAR_NAK_OUT_PACKETS_MODE) |
2305+ BIT(SET_EP_HIDE_STATUS_PHASE),
2306+ &dev->epregs[0].ep_rsp);
2307+
2308+ /*
2309+ * hardware optionally handles a bunch of standard requests
2310+ * that the API hides from drivers anyway. have it do so.
2311+ * endpoint status/features are handled in software, to
2312+ * help pass tests for some dubious behavior.
2313+ */
2314+ writel(BIT(SET_ISOCHRONOUS_DELAY) |
2315+ BIT(SET_SEL) |
2316+ BIT(SET_TEST_MODE) |
2317+ BIT(SET_ADDRESS) |
2318+ BIT(GET_INTERFACE_STATUS) |
2319+ BIT(GET_DEVICE_STATUS),
2320+ &dev->usb->stdrsp);
2321+ dev->wakeup_enable = 1;
2322+ writel(BIT(USB_ROOT_PORT_WAKEUP_ENABLE) |
2323+ (dev->softconnect << USB_DETECT_ENABLE) |
2324+ BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
2325+ &dev->usb->usbctl);
2326+
2327+ /* enable irqs so we can see ep0 and general operation */
2328+ writel(BIT(SETUP_PACKET_INTERRUPT_ENABLE) |
2329+ BIT(ENDPOINT_0_INTERRUPT_ENABLE),
2330+ &dev->regs->pciirqenb0);
2331+ writel(BIT(PCI_INTERRUPT_ENABLE) |
2332+ BIT(ROOT_PORT_RESET_INTERRUPT_ENABLE) |
2333+ BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE) |
2334+ BIT(VBUS_INTERRUPT_ENABLE),
2335+ &dev->regs->pciirqenb1);
2336+
2337+ /* don't leave any writes posted */
2338+ (void)readl(&dev->usb->usbctl);
2339+}
2340+
2341+static void ep0_start(struct net2280 *dev)
2342+{
2343+ if (dev->quirks & PLX_LEGACY)
2344+ return ep0_start_228x(dev);
2345+ return ep0_start_338x(dev);
2346+}
2347+
2348+/* when a driver is successfully registered, it will receive
2349+ * control requests including set_configuration(), which enables
2350+ * non-control requests. then usb traffic follows until a
2351+ * disconnect is reported. then a host may connect again, or
2352+ * the driver might get unbound.
2353+ */
2354+static int net2280_start(struct usb_gadget *_gadget,
2355+ struct usb_gadget_driver *driver)
2356+{
2357+ struct net2280 *dev;
2358+ int retval;
2359+ unsigned i;
2360+
2361+ /* insist on high speed support from the driver, since
2362+ * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
2363+ * "must not be used in normal operation"
2364+ */
2365+ if (!driver || driver->max_speed < USB_SPEED_HIGH ||
2366+ !driver->setup)
2367+ return -EINVAL;
2368+
2369+ dev = container_of(_gadget, struct net2280, gadget);
2370+
2371+ for (i = 0; i < dev->n_ep; i++)
2372+ dev->ep[i].irqs = 0;
2373+
2374+ /* hook up the driver ... */
2375+ dev->softconnect = 1;
2376+ driver->driver.bus = NULL;
2377+ dev->driver = driver;
2378+
2379+ retval = device_create_file(&dev->pdev->dev, &dev_attr_function);
2380+ if (retval)
2381+ goto err_unbind;
2382+ retval = device_create_file(&dev->pdev->dev, &dev_attr_queues);
2383+ if (retval)
2384+ goto err_func;
2385+
2386+ /* Enable force-full-speed testing mode, if desired */
2387+ if (full_speed && (dev->quirks & PLX_LEGACY))
2388+ writel(BIT(FORCE_FULL_SPEED_MODE), &dev->usb->xcvrdiag);
2389+
2390+ /* ... then enable host detection and ep0; and we're ready
2391+ * for set_configuration as well as eventual disconnect.
2392+ */
2393+ net2280_led_active(dev, 1);
2394+
2395+ if (dev->quirks & PLX_SUPERSPEED)
2396+ defect7374_enable_data_eps_zero(dev);
2397+
2398+ ep0_start(dev);
2399+
2400+ ep_dbg(dev, "%s ready, usbctl %08x stdrsp %08x\n",
2401+ driver->driver.name,
2402+ readl(&dev->usb->usbctl),
2403+ readl(&dev->usb->stdrsp));
2404+
2405+ /* pci writes may still be posted */
2406+ return 0;
2407+
2408+err_func:
2409+ device_remove_file(&dev->pdev->dev, &dev_attr_function);
2410+err_unbind:
2411+ dev->driver = NULL;
2412+ return retval;
2413+}
2414+
2415+static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver)
2416+{
2417+ int i;
2418+
2419+ /* don't disconnect if it's not connected */
2420+ if (dev->gadget.speed == USB_SPEED_UNKNOWN)
2421+ driver = NULL;
2422+
2423+ /* stop hardware; prevent new request submissions;
2424+ * and kill any outstanding requests.
2425+ */
2426+ usb_reset(dev);
2427+ for (i = 0; i < dev->n_ep; i++)
2428+ nuke(&dev->ep[i]);
2429+
2430+ /* report disconnect; the driver is already quiesced */
2431+ if (driver) {
2432+ spin_unlock(&dev->lock);
2433+ driver->disconnect(&dev->gadget);
2434+ spin_lock(&dev->lock);
2435+ }
2436+
2437+ usb_reinit(dev);
2438+}
2439+
2440+static int net2280_stop(struct usb_gadget *_gadget,
2441+ struct usb_gadget_driver *driver)
2442+{
2443+ struct net2280 *dev;
2444+ unsigned long flags;
2445+
2446+ dev = container_of(_gadget, struct net2280, gadget);
2447+
2448+ spin_lock_irqsave(&dev->lock, flags);
2449+ stop_activity(dev, driver);
2450+ spin_unlock_irqrestore(&dev->lock, flags);
2451+
2452+ dev->driver = NULL;
2453+
2454+ net2280_led_active(dev, 0);
2455+
2456+ /* Disable full-speed test mode */
2457+ if (dev->quirks & PLX_LEGACY)
2458+ writel(0, &dev->usb->xcvrdiag);
2459+
2460+ device_remove_file(&dev->pdev->dev, &dev_attr_function);
2461+ device_remove_file(&dev->pdev->dev, &dev_attr_queues);
2462+
2463+ ep_dbg(dev, "unregistered driver '%s'\n",
2464+ driver ? driver->driver.name : "");
2465+
2466+ return 0;
2467+}
2468+
2469+/*-------------------------------------------------------------------------*/
2470+
2471+/* handle ep0, ep-e, ep-f with 64 byte packets: packet per irq.
2472+ * also works for dma-capable endpoints, in pio mode or just
2473+ * to manually advance the queue after short OUT transfers.
2474+ */
2475+static void handle_ep_small(struct net2280_ep *ep)
2476+{
2477+ struct net2280_request *req;
2478+ u32 t;
2479+ /* 0 error, 1 mid-data, 2 done */
2480+ int mode = 1;
2481+
2482+ if (!list_empty(&ep->queue))
2483+ req = list_entry(ep->queue.next,
2484+ struct net2280_request, queue);
2485+ else
2486+ req = NULL;
2487+
2488+ /* ack all, and handle what we care about */
2489+ t = readl(&ep->regs->ep_stat);
2490+ ep->irqs++;
2491+#if 0
2492+ ep_vdbg(ep->dev, "%s ack ep_stat %08x, req %p\n",
2493+ ep->ep.name, t, req ? &req->req : 0);
2494+#endif
2495+ if (!ep->is_in || (ep->dev->quirks & PLX_2280))
2496+ writel(t & ~BIT(NAK_OUT_PACKETS), &ep->regs->ep_stat);
2497+ else
2498+ /* Added for 2282 */
2499+ writel(t, &ep->regs->ep_stat);
2500+
2501+ /* for ep0, monitor token irqs to catch data stage length errors
2502+ * and to synchronize on status.
2503+ *
2504+ * also, to defer reporting of protocol stalls ... here's where
2505+ * data or status first appears, handling stalls here should never
2506+ * cause trouble on the host side..
2507+ *
2508+ * control requests could be slightly faster without token synch for
2509+ * status, but status can jam up that way.
2510+ */
2511+ if (unlikely(ep->num == 0)) {
2512+ if (ep->is_in) {
2513+ /* status; stop NAKing */
2514+ if (t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) {
2515+ if (ep->dev->protocol_stall) {
2516+ ep->stopped = 1;
2517+ set_halt(ep);
2518+ }
2519+ if (!req)
2520+ allow_status(ep);
2521+ mode = 2;
2522+ /* reply to extra IN data tokens with a zlp */
2523+ } else if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) {
2524+ if (ep->dev->protocol_stall) {
2525+ ep->stopped = 1;
2526+ set_halt(ep);
2527+ mode = 2;
2528+ } else if (ep->responded &&
2529+ !req && !ep->stopped)
2530+ write_fifo(ep, NULL);
2531+ }
2532+ } else {
2533+ /* status; stop NAKing */
2534+ if (t & BIT(DATA_IN_TOKEN_INTERRUPT)) {
2535+ if (ep->dev->protocol_stall) {
2536+ ep->stopped = 1;
2537+ set_halt(ep);
2538+ }
2539+ mode = 2;
2540+ /* an extra OUT token is an error */
2541+ } else if (((t & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)) &&
2542+ req &&
2543+ req->req.actual == req->req.length) ||
2544+ (ep->responded && !req)) {
2545+ ep->dev->protocol_stall = 1;
2546+ set_halt(ep);
2547+ ep->stopped = 1;
2548+ if (req)
2549+ done(ep, req, -EOVERFLOW);
2550+ req = NULL;
2551+ }
2552+ }
2553+ }
2554+
2555+ if (unlikely(!req))
2556+ return;
2557+
2558+ /* manual DMA queue advance after short OUT */
2559+ if (likely(ep->dma)) {
2560+ if (t & BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
2561+ u32 count;
2562+ int stopped = ep->stopped;
2563+
2564+ /* TRANSFERRED works around OUT_DONE erratum 0112.
2565+ * we expect (N <= maxpacket) bytes; host wrote M.
2566+ * iff (M < N) we won't ever see a DMA interrupt.
2567+ */
2568+ ep->stopped = 1;
2569+ for (count = 0; ; t = readl(&ep->regs->ep_stat)) {
2570+
2571+ /* any preceding dma transfers must finish.
2572+ * dma handles (M >= N), may empty the queue
2573+ */
2574+ scan_dma_completions(ep);
2575+ if (unlikely(list_empty(&ep->queue) ||
2576+ ep->out_overflow)) {
2577+ req = NULL;
2578+ break;
2579+ }
2580+ req = list_entry(ep->queue.next,
2581+ struct net2280_request, queue);
2582+
2583+ /* here either (M < N), a "real" short rx;
2584+ * or (M == N) and the queue didn't empty
2585+ */
2586+ if (likely(t & BIT(FIFO_EMPTY))) {
2587+ count = readl(&ep->dma->dmacount);
2588+ count &= DMA_BYTE_COUNT_MASK;
2589+ if (readl(&ep->dma->dmadesc)
2590+ != req->td_dma)
2591+ req = NULL;
2592+ break;
2593+ }
2594+ udelay(1);
2595+ }
2596+
2597+ /* stop DMA, leave ep NAKing */
2598+ writel(BIT(DMA_ABORT), &ep->dma->dmastat);
2599+ spin_stop_dma(ep->dma);
2600+
2601+ if (likely(req)) {
2602+ req->td->dmacount = 0;
2603+ t = readl(&ep->regs->ep_avail);
2604+ dma_done(ep, req, count,
2605+ (ep->out_overflow || t)
2606+ ? -EOVERFLOW : 0);
2607+ }
2608+
2609+ /* also flush to prevent erratum 0106 trouble */
2610+ if (unlikely(ep->out_overflow ||
2611+ (ep->dev->chiprev == 0x0100 &&
2612+ ep->dev->gadget.speed
2613+ == USB_SPEED_FULL))) {
2614+ out_flush(ep);
2615+ ep->out_overflow = 0;
2616+ }
2617+
2618+ /* (re)start dma if needed, stop NAKing */
2619+ ep->stopped = stopped;
2620+ if (!list_empty(&ep->queue))
2621+ restart_dma(ep);
2622+ } else
2623+ ep_dbg(ep->dev, "%s dma ep_stat %08x ??\n",
2624+ ep->ep.name, t);
2625+ return;
2626+
2627+ /* data packet(s) received (in the fifo, OUT) */
2628+ } else if (t & BIT(DATA_PACKET_RECEIVED_INTERRUPT)) {
2629+ if (read_fifo(ep, req) && ep->num != 0)
2630+ mode = 2;
2631+
2632+ /* data packet(s) transmitted (IN) */
2633+ } else if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT)) {
2634+ unsigned len;
2635+
2636+ len = req->req.length - req->req.actual;
2637+ if (len > ep->ep.maxpacket)
2638+ len = ep->ep.maxpacket;
2639+ req->req.actual += len;
2640+
2641+ /* if we wrote it all, we're usually done */
2642+ /* send zlps until the status stage */
2643+ if ((req->req.actual == req->req.length) &&
2644+ (!req->req.zero || len != ep->ep.maxpacket) && ep->num)
2645+ mode = 2;
2646+
2647+ /* there was nothing to do ... */
2648+ } else if (mode == 1)
2649+ return;
2650+
2651+ /* done */
2652+ if (mode == 2) {
2653+ /* stream endpoints often resubmit/unlink in completion */
2654+ done(ep, req, 0);
2655+
2656+ /* maybe advance queue to next request */
2657+ if (ep->num == 0) {
2658+ /* NOTE: net2280 could let gadget driver start the
2659+ * status stage later. since not all controllers let
2660+ * them control that, the api doesn't (yet) allow it.
2661+ */
2662+ if (!ep->stopped)
2663+ allow_status(ep);
2664+ req = NULL;
2665+ } else {
2666+ if (!list_empty(&ep->queue) && !ep->stopped)
2667+ req = list_entry(ep->queue.next,
2668+ struct net2280_request, queue);
2669+ else
2670+ req = NULL;
2671+ if (req && !ep->is_in)
2672+ stop_out_naking(ep);
2673+ }
2674+ }
2675+
2676+ /* is there a buffer for the next packet?
2677+ * for best streaming performance, make sure there is one.
2678+ */
2679+ if (req && !ep->stopped) {
2680+
2681+ /* load IN fifo with next packet (may be zlp) */
2682+ if (t & BIT(DATA_PACKET_TRANSMITTED_INTERRUPT))
2683+ write_fifo(ep, &req->req);
2684+ }
2685+}
2686+
2687+static struct net2280_ep *get_ep_by_addr(struct net2280 *dev, u16 wIndex)
2688+{
2689+ struct net2280_ep *ep;
2690+
2691+ if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
2692+ return &dev->ep[0];
2693+ list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) {
2694+ u8 bEndpointAddress;
2695+
2696+ if (!ep->desc)
2697+ continue;
2698+ bEndpointAddress = ep->desc->bEndpointAddress;
2699+ if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
2700+ continue;
2701+ if ((wIndex & 0x0f) == (bEndpointAddress & 0x0f))
2702+ return ep;
2703+ }
2704+ return NULL;
2705+}
2706+
2707+static void defect7374_workaround(struct net2280 *dev, struct usb_ctrlrequest r)
2708+{
2709+ u32 scratch, fsmvalue;
2710+ u32 ack_wait_timeout, state;
2711+
2712+ /* Workaround for Defect 7374 (U1/U2 erroneously rejected): */
2713+ scratch = get_idx_reg(dev->regs, SCRATCH);
2714+ fsmvalue = scratch & (0xf << DEFECT7374_FSM_FIELD);
2715+ scratch &= ~(0xf << DEFECT7374_FSM_FIELD);
2716+
2717+ if (!((fsmvalue == DEFECT7374_FSM_WAITING_FOR_CONTROL_READ) &&
2718+ (r.bRequestType & USB_DIR_IN)))
2719+ return;
2720+
2721+ /* This is the first Control Read for this connection: */
2722+ if (!(readl(&dev->usb->usbstat) & BIT(SUPER_SPEED_MODE))) {
2723+ /*
2724+ * Connection is NOT SS:
2725+ * - Connection must be FS or HS.
2726+ * - This FSM state should allow workaround software to
2727+ * run after the next USB connection.
2728+ */
2729+ scratch |= DEFECT7374_FSM_NON_SS_CONTROL_READ;
2730+ goto restore_data_eps;
2731+ }
2732+
2733+ /* Connection is SS: */
2734+ for (ack_wait_timeout = 0;
2735+ ack_wait_timeout < DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS;
2736+ ack_wait_timeout++) {
2737+
2738+ state = readl(&dev->plregs->pl_ep_status_1)
2739+ & (0xff << STATE);
2740+ if ((state >= (ACK_GOOD_NORMAL << STATE)) &&
2741+ (state <= (ACK_GOOD_MORE_ACKS_TO_COME << STATE))) {
2742+ scratch |= DEFECT7374_FSM_SS_CONTROL_READ;
2743+ break;
2744+ }
2745+
2746+ /*
2747+ * We have not yet received host's Data Phase ACK
2748+ * - Wait and try again.
2749+ */
2750+ udelay(DEFECT_7374_PROCESSOR_WAIT_TIME);
2751+
2752+ continue;
2753+ }
2754+
2755+
2756+ if (ack_wait_timeout >= DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS) {
2757+ ep_err(dev, "FAIL: Defect 7374 workaround waited but failed "
2758+ "to detect SS host's data phase ACK.");
2759+ ep_err(dev, "PL_EP_STATUS_1(23:16):.Expected from 0x11 to 0x16"
2760+ "got 0x%2.2x.\n", state >> STATE);
2761+ } else {
2762+ ep_warn(dev, "INFO: Defect 7374 workaround waited about\n"
2763+ "%duSec for Control Read Data Phase ACK\n",
2764+ DEFECT_7374_PROCESSOR_WAIT_TIME * ack_wait_timeout);
2765+ }
2766+
2767+restore_data_eps:
2768+ /*
2769+ * Restore data EPs to their pre-workaround settings (disabled,
2770+ * initialized, and other details).
2771+ */
2772+ defect7374_disable_data_eps(dev);
2773+
2774+ set_idx_reg(dev->regs, SCRATCH, scratch);
2775+
2776+ return;
2777+}
2778+
2779+static void ep_stall(struct net2280_ep *ep, int stall)
2780+{
2781+ struct net2280 *dev = ep->dev;
2782+ u32 val;
2783+ static const u32 ep_pl[9] = { 0, 3, 4, 7, 8, 2, 5, 6, 9 };
2784+
2785+ if (stall) {
2786+ writel(BIT(SET_ENDPOINT_HALT) |
2787+ /* BIT(SET_NAK_PACKETS) | */
2788+ BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE),
2789+ &ep->regs->ep_rsp);
2790+ ep->is_halt = 1;
2791+ } else {
2792+ if (dev->gadget.speed == USB_SPEED_SUPER) {
2793+ /*
2794+ * Workaround for SS SeqNum not cleared via
2795+ * Endpoint Halt (Clear) bit. select endpoint
2796+ */
2797+ val = readl(&dev->plregs->pl_ep_ctrl);
2798+ val = (val & ~0x1f) | ep_pl[ep->num];
2799+ writel(val, &dev->plregs->pl_ep_ctrl);
2800+
2801+ val |= BIT(SEQUENCE_NUMBER_RESET);
2802+ writel(val, &dev->plregs->pl_ep_ctrl);
2803+ }
2804+ val = readl(&ep->regs->ep_rsp);
2805+ val |= BIT(CLEAR_ENDPOINT_HALT) |
2806+ BIT(CLEAR_ENDPOINT_TOGGLE);
2807+ writel(val,
2808+ /* | BIT(CLEAR_NAK_PACKETS),*/
2809+ &ep->regs->ep_rsp);
2810+ ep->is_halt = 0;
2811+ val = readl(&ep->regs->ep_rsp);
2812+ }
2813+}
2814+
2815+static void ep_stdrsp(struct net2280_ep *ep, int value, int wedged)
2816+{
2817+ /* set/clear, then synch memory views with the device */
2818+ if (value) {
2819+ ep->stopped = 1;
2820+ if (ep->num == 0)
2821+ ep->dev->protocol_stall = 1;
2822+ else {
2823+ if (ep->dma)
2824+ ep_stop_dma(ep);
2825+ ep_stall(ep, true);
2826+ }
2827+
2828+ if (wedged)
2829+ ep->wedged = 1;
2830+ } else {
2831+ ep->stopped = 0;
2832+ ep->wedged = 0;
2833+
2834+ ep_stall(ep, false);
2835+
2836+ /* Flush the queue */
2837+ if (!list_empty(&ep->queue)) {
2838+ struct net2280_request *req =
2839+ list_entry(ep->queue.next, struct net2280_request,
2840+ queue);
2841+ if (ep->dma)
2842+ resume_dma(ep);
2843+ else {
2844+ if (ep->is_in)
2845+ write_fifo(ep, &req->req);
2846+ else {
2847+ if (read_fifo(ep, req))
2848+ done(ep, req, 0);
2849+ }
2850+ }
2851+ }
2852+ }
2853+}
2854+
2855+static void handle_stat0_irqs_superspeed(struct net2280 *dev,
2856+ struct net2280_ep *ep, struct usb_ctrlrequest r)
2857+{
2858+ int tmp = 0;
2859+
2860+#define w_value le16_to_cpu(r.wValue)
2861+#define w_index le16_to_cpu(r.wIndex)
2862+#define w_length le16_to_cpu(r.wLength)
2863+
2864+ switch (r.bRequest) {
2865+ struct net2280_ep *e;
2866+ u16 status;
2867+
2868+ case USB_REQ_SET_CONFIGURATION:
2869+ dev->addressed_state = !w_value;
2870+ goto usb3_delegate;
2871+
2872+ case USB_REQ_GET_STATUS:
2873+ switch (r.bRequestType) {
2874+ case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2875+ status = dev->wakeup_enable ? 0x02 : 0x00;
2876+ if (dev->selfpowered)
2877+ status |= BIT(0);
2878+ status |= (dev->u1_enable << 2 | dev->u2_enable << 3 |
2879+ dev->ltm_enable << 4);
2880+ writel(0, &dev->epregs[0].ep_irqenb);
2881+ set_fifo_bytecount(ep, sizeof(status));
2882+ writel((__force u32) status, &dev->epregs[0].ep_data);
2883+ allow_status_338x(ep);
2884+ break;
2885+
2886+ case (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2887+ e = get_ep_by_addr(dev, w_index);
2888+ if (!e)
2889+ goto do_stall3;
2890+ status = readl(&e->regs->ep_rsp) &
2891+ BIT(CLEAR_ENDPOINT_HALT);
2892+ writel(0, &dev->epregs[0].ep_irqenb);
2893+ set_fifo_bytecount(ep, sizeof(status));
2894+ writel((__force u32) status, &dev->epregs[0].ep_data);
2895+ allow_status_338x(ep);
2896+ break;
2897+
2898+ default:
2899+ goto usb3_delegate;
2900+ }
2901+ break;
2902+
2903+ case USB_REQ_CLEAR_FEATURE:
2904+ switch (r.bRequestType) {
2905+ case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2906+ if (!dev->addressed_state) {
2907+ switch (w_value) {
2908+ case USB_DEVICE_U1_ENABLE:
2909+ dev->u1_enable = 0;
2910+ writel(readl(&dev->usb_ext->usbctl2) &
2911+ ~BIT(U1_ENABLE),
2912+ &dev->usb_ext->usbctl2);
2913+ allow_status_338x(ep);
2914+ goto next_endpoints3;
2915+
2916+ case USB_DEVICE_U2_ENABLE:
2917+ dev->u2_enable = 0;
2918+ writel(readl(&dev->usb_ext->usbctl2) &
2919+ ~BIT(U2_ENABLE),
2920+ &dev->usb_ext->usbctl2);
2921+ allow_status_338x(ep);
2922+ goto next_endpoints3;
2923+
2924+ case USB_DEVICE_LTM_ENABLE:
2925+ dev->ltm_enable = 0;
2926+ writel(readl(&dev->usb_ext->usbctl2) &
2927+ ~BIT(LTM_ENABLE),
2928+ &dev->usb_ext->usbctl2);
2929+ allow_status_338x(ep);
2930+ goto next_endpoints3;
2931+
2932+ default:
2933+ break;
2934+ }
2935+ }
2936+ if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
2937+ dev->wakeup_enable = 0;
2938+ writel(readl(&dev->usb->usbctl) &
2939+ ~BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
2940+ &dev->usb->usbctl);
2941+ allow_status_338x(ep);
2942+ break;
2943+ }
2944+ goto usb3_delegate;
2945+
2946+ case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
2947+ e = get_ep_by_addr(dev, w_index);
2948+ if (!e)
2949+ goto do_stall3;
2950+ if (w_value != USB_ENDPOINT_HALT)
2951+ goto do_stall3;
2952+ ep_vdbg(dev, "%s clear halt\n", e->ep.name);
2953+ ep_stall(e, false);
2954+ if (!list_empty(&e->queue) && e->td_dma)
2955+ restart_dma(e);
2956+ allow_status(ep);
2957+ ep->stopped = 1;
2958+ break;
2959+
2960+ default:
2961+ goto usb3_delegate;
2962+ }
2963+ break;
2964+ case USB_REQ_SET_FEATURE:
2965+ switch (r.bRequestType) {
2966+ case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE):
2967+ if (!dev->addressed_state) {
2968+ switch (w_value) {
2969+ case USB_DEVICE_U1_ENABLE:
2970+ dev->u1_enable = 1;
2971+ writel(readl(&dev->usb_ext->usbctl2) |
2972+ BIT(U1_ENABLE),
2973+ &dev->usb_ext->usbctl2);
2974+ allow_status_338x(ep);
2975+ goto next_endpoints3;
2976+
2977+ case USB_DEVICE_U2_ENABLE:
2978+ dev->u2_enable = 1;
2979+ writel(readl(&dev->usb_ext->usbctl2) |
2980+ BIT(U2_ENABLE),
2981+ &dev->usb_ext->usbctl2);
2982+ allow_status_338x(ep);
2983+ goto next_endpoints3;
2984+
2985+ case USB_DEVICE_LTM_ENABLE:
2986+ dev->ltm_enable = 1;
2987+ writel(readl(&dev->usb_ext->usbctl2) |
2988+ BIT(LTM_ENABLE),
2989+ &dev->usb_ext->usbctl2);
2990+ allow_status_338x(ep);
2991+ goto next_endpoints3;
2992+ default:
2993+ break;
2994+ }
2995+ }
2996+
2997+ if (w_value == USB_DEVICE_REMOTE_WAKEUP) {
2998+ dev->wakeup_enable = 1;
2999+ writel(readl(&dev->usb->usbctl) |
3000+ BIT(DEVICE_REMOTE_WAKEUP_ENABLE),
3001+ &dev->usb->usbctl);
3002+ allow_status_338x(ep);
3003+ break;
3004+ }
3005+ goto usb3_delegate;
3006+
3007+ case (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT):
3008+ e = get_ep_by_addr(dev, w_index);
3009+ if (!e || (w_value != USB_ENDPOINT_HALT))
3010+ goto do_stall3;
3011+ ep_stdrsp(e, true, false);
3012+ allow_status_338x(ep);
3013+ break;
3014+
3015+ default:
3016+ goto usb3_delegate;
3017+ }
3018+
3019+ break;
3020+ default:
3021+
3022+usb3_delegate:
3023+ ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x ep_cfg %08x\n",
3024+ r.bRequestType, r.bRequest,
3025+ w_value, w_index, w_length,
3026+ readl(&ep->cfg->ep_cfg));
3027+
3028+ ep->responded = 0;
3029+ spin_unlock(&dev->lock);
3030+ tmp = dev->driver->setup(&dev->gadget, &r);
3031+ spin_lock(&dev->lock);
3032+ }
3033+do_stall3:
3034+ if (tmp < 0) {
3035+ ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n",
3036+ r.bRequestType, r.bRequest, tmp);
3037+ dev->protocol_stall = 1;
3038+ /* TD 9.9 Halt Endpoint test. TD 9.22 Set feature test */
3039+ ep_stall(ep, true);
3040+ }
3041+
3042+next_endpoints3:
3043+
3044+#undef w_value
3045+#undef w_index
3046+#undef w_length
3047+
3048+ return;
3049+}
3050+
3051+static void handle_stat0_irqs(struct net2280 *dev, u32 stat)
3052+{
3053+ struct net2280_ep *ep;
3054+ u32 num, scratch;
3055+
3056+ /* most of these don't need individual acks */
3057+ stat &= ~BIT(INTA_ASSERTED);
3058+ if (!stat)
3059+ return;
3060+ /* ep_dbg(dev, "irqstat0 %04x\n", stat); */
3061+
3062+ /* starting a control request? */
3063+ if (unlikely(stat & BIT(SETUP_PACKET_INTERRUPT))) {
3064+ union {
3065+ u32 raw[2];
3066+ struct usb_ctrlrequest r;
3067+ } u;
3068+ int tmp;
3069+ struct net2280_request *req;
3070+
3071+ if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
3072+ u32 val = readl(&dev->usb->usbstat);
3073+ if (val & BIT(SUPER_SPEED)) {
3074+ dev->gadget.speed = USB_SPEED_SUPER;
3075+ usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3076+ EP0_SS_MAX_PACKET_SIZE);
3077+ } else if (val & BIT(HIGH_SPEED)) {
3078+ dev->gadget.speed = USB_SPEED_HIGH;
3079+ usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3080+ EP0_HS_MAX_PACKET_SIZE);
3081+ } else {
3082+ dev->gadget.speed = USB_SPEED_FULL;
3083+ usb_ep_set_maxpacket_limit(&dev->ep[0].ep,
3084+ EP0_HS_MAX_PACKET_SIZE);
3085+ }
3086+ net2280_led_speed(dev, dev->gadget.speed);
3087+ ep_dbg(dev, "%s\n",
3088+ usb_speed_string(dev->gadget.speed));
3089+ }
3090+
3091+ ep = &dev->ep[0];
3092+ ep->irqs++;
3093+
3094+ /* make sure any leftover request state is cleared */
3095+ stat &= ~BIT(ENDPOINT_0_INTERRUPT);
3096+ while (!list_empty(&ep->queue)) {
3097+ req = list_entry(ep->queue.next,
3098+ struct net2280_request, queue);
3099+ done(ep, req, (req->req.actual == req->req.length)
3100+ ? 0 : -EPROTO);
3101+ }
3102+ ep->stopped = 0;
3103+ dev->protocol_stall = 0;
3104+ if (dev->quirks & PLX_SUPERSPEED)
3105+ ep->is_halt = 0;
3106+ else{
3107+ if (ep->dev->quirks & PLX_2280)
3108+ tmp = BIT(FIFO_OVERFLOW) |
3109+ BIT(FIFO_UNDERFLOW);
3110+ else
3111+ tmp = 0;
3112+
3113+ writel(tmp | BIT(TIMEOUT) |
3114+ BIT(USB_STALL_SENT) |
3115+ BIT(USB_IN_NAK_SENT) |
3116+ BIT(USB_IN_ACK_RCVD) |
3117+ BIT(USB_OUT_PING_NAK_SENT) |
3118+ BIT(USB_OUT_ACK_SENT) |
3119+ BIT(SHORT_PACKET_OUT_DONE_INTERRUPT) |
3120+ BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT) |
3121+ BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
3122+ BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
3123+ BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3124+ BIT(DATA_IN_TOKEN_INTERRUPT),
3125+ &ep->regs->ep_stat);
3126+ }
3127+ u.raw[0] = readl(&dev->usb->setup0123);
3128+ u.raw[1] = readl(&dev->usb->setup4567);
3129+
3130+ cpu_to_le32s(&u.raw[0]);
3131+ cpu_to_le32s(&u.raw[1]);
3132+
3133+ if (dev->quirks & PLX_SUPERSPEED)
3134+ defect7374_workaround(dev, u.r);
3135+
3136+ tmp = 0;
3137+
3138+#define w_value le16_to_cpu(u.r.wValue)
3139+#define w_index le16_to_cpu(u.r.wIndex)
3140+#define w_length le16_to_cpu(u.r.wLength)
3141+
3142+ /* ack the irq */
3143+ writel(BIT(SETUP_PACKET_INTERRUPT), &dev->regs->irqstat0);
3144+ stat ^= BIT(SETUP_PACKET_INTERRUPT);
3145+
3146+ /* watch control traffic at the token level, and force
3147+ * synchronization before letting the status stage happen.
3148+ * FIXME ignore tokens we'll NAK, until driver responds.
3149+ * that'll mean a lot less irqs for some drivers.
3150+ */
3151+ ep->is_in = (u.r.bRequestType & USB_DIR_IN) != 0;
3152+ if (ep->is_in) {
3153+ scratch = BIT(DATA_PACKET_TRANSMITTED_INTERRUPT) |
3154+ BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3155+ BIT(DATA_IN_TOKEN_INTERRUPT);
3156+ stop_out_naking(ep);
3157+ } else
3158+ scratch = BIT(DATA_PACKET_RECEIVED_INTERRUPT) |
3159+ BIT(DATA_OUT_PING_TOKEN_INTERRUPT) |
3160+ BIT(DATA_IN_TOKEN_INTERRUPT);
3161+ writel(scratch, &dev->epregs[0].ep_irqenb);
3162+
3163+ /* we made the hardware handle most lowlevel requests;
3164+ * everything else goes uplevel to the gadget code.
3165+ */
3166+ ep->responded = 1;
3167+
3168+ if (dev->gadget.speed == USB_SPEED_SUPER) {
3169+ handle_stat0_irqs_superspeed(dev, ep, u.r);
3170+ goto next_endpoints;
3171+ }
3172+
3173+ switch (u.r.bRequest) {
3174+ case USB_REQ_GET_STATUS: {
3175+ struct net2280_ep *e;
3176+ __le32 status;
3177+
3178+ /* hw handles device and interface status */
3179+ if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
3180+ goto delegate;
3181+ e = get_ep_by_addr(dev, w_index);
3182+ if (!e || w_length > 2)
3183+ goto do_stall;
3184+
3185+ if (readl(&e->regs->ep_rsp) & BIT(SET_ENDPOINT_HALT))
3186+ status = cpu_to_le32(1);
3187+ else
3188+ status = cpu_to_le32(0);
3189+
3190+ /* don't bother with a request object! */
3191+ writel(0, &dev->epregs[0].ep_irqenb);
3192+ set_fifo_bytecount(ep, w_length);
3193+ writel((__force u32)status, &dev->epregs[0].ep_data);
3194+ allow_status(ep);
3195+ ep_vdbg(dev, "%s stat %02x\n", ep->ep.name, status);
3196+ goto next_endpoints;
3197+ }
3198+ break;
3199+ case USB_REQ_CLEAR_FEATURE: {
3200+ struct net2280_ep *e;
3201+
3202+ /* hw handles device features */
3203+ if (u.r.bRequestType != USB_RECIP_ENDPOINT)
3204+ goto delegate;
3205+ if (w_value != USB_ENDPOINT_HALT || w_length != 0)
3206+ goto do_stall;
3207+ e = get_ep_by_addr(dev, w_index);
3208+ if (!e)
3209+ goto do_stall;
3210+ if (e->wedged) {
3211+ ep_vdbg(dev, "%s wedged, halt not cleared\n",
3212+ ep->ep.name);
3213+ } else {
3214+ ep_vdbg(dev, "%s clear halt\n", e->ep.name);
3215+ clear_halt(e);
3216+ if ((ep->dev->quirks & PLX_SUPERSPEED) &&
3217+ !list_empty(&e->queue) && e->td_dma)
3218+ restart_dma(e);
3219+ }
3220+ allow_status(ep);
3221+ goto next_endpoints;
3222+ }
3223+ break;
3224+ case USB_REQ_SET_FEATURE: {
3225+ struct net2280_ep *e;
3226+
3227+ /* hw handles device features */
3228+ if (u.r.bRequestType != USB_RECIP_ENDPOINT)
3229+ goto delegate;
3230+ if (w_value != USB_ENDPOINT_HALT || w_length != 0)
3231+ goto do_stall;
3232+ e = get_ep_by_addr(dev, w_index);
3233+ if (!e)
3234+ goto do_stall;
3235+ if (e->ep.name == ep0name)
3236+ goto do_stall;
3237+ set_halt(e);
3238+ if ((dev->quirks & PLX_SUPERSPEED) && e->dma)
3239+ abort_dma(e);
3240+ allow_status(ep);
3241+ ep_vdbg(dev, "%s set halt\n", ep->ep.name);
3242+ goto next_endpoints;
3243+ }
3244+ break;
3245+ default:
3246+delegate:
3247+ ep_vdbg(dev, "setup %02x.%02x v%04x i%04x l%04x "
3248+ "ep_cfg %08x\n",
3249+ u.r.bRequestType, u.r.bRequest,
3250+ w_value, w_index, w_length,
3251+ readl(&ep->cfg->ep_cfg));
3252+ ep->responded = 0;
3253+ spin_unlock(&dev->lock);
3254+ tmp = dev->driver->setup(&dev->gadget, &u.r);
3255+ spin_lock(&dev->lock);
3256+ }
3257+
3258+ /* stall ep0 on error */
3259+ if (tmp < 0) {
3260+do_stall:
3261+ ep_vdbg(dev, "req %02x.%02x protocol STALL; stat %d\n",
3262+ u.r.bRequestType, u.r.bRequest, tmp);
3263+ dev->protocol_stall = 1;
3264+ }
3265+
3266+ /* some in/out token irq should follow; maybe stall then.
3267+ * driver must queue a request (even zlp) or halt ep0
3268+ * before the host times out.
3269+ */
3270+ }
3271+
3272+#undef w_value
3273+#undef w_index
3274+#undef w_length
3275+
3276+next_endpoints:
3277+ /* endpoint data irq ? */
3278+ scratch = stat & 0x7f;
3279+ stat &= ~0x7f;
3280+ for (num = 0; scratch; num++) {
3281+ u32 t;
3282+
3283+ /* do this endpoint's FIFO and queue need tending? */
3284+ t = BIT(num);
3285+ if ((scratch & t) == 0)
3286+ continue;
3287+ scratch ^= t;
3288+
3289+ ep = &dev->ep[num];
3290+ handle_ep_small(ep);
3291+ }
3292+
3293+ if (stat)
3294+ ep_dbg(dev, "unhandled irqstat0 %08x\n", stat);
3295+}
3296+
3297+#define DMA_INTERRUPTS (BIT(DMA_D_INTERRUPT) | \
3298+ BIT(DMA_C_INTERRUPT) | \
3299+ BIT(DMA_B_INTERRUPT) | \
3300+ BIT(DMA_A_INTERRUPT))
3301+#define PCI_ERROR_INTERRUPTS ( \
3302+ BIT(PCI_MASTER_ABORT_RECEIVED_INTERRUPT) | \
3303+ BIT(PCI_TARGET_ABORT_RECEIVED_INTERRUPT) | \
3304+ BIT(PCI_RETRY_ABORT_INTERRUPT))
3305+
3306+static void handle_stat1_irqs(struct net2280 *dev, u32 stat)
3307+{
3308+ struct net2280_ep *ep;
3309+ u32 tmp, num, mask, scratch;
3310+
3311+ /* after disconnect there's nothing else to do! */
3312+ tmp = BIT(VBUS_INTERRUPT) | BIT(ROOT_PORT_RESET_INTERRUPT);
3313+ mask = BIT(SUPER_SPEED) | BIT(HIGH_SPEED) | BIT(FULL_SPEED);
3314+
3315+ /* VBUS disconnect is indicated by VBUS_PIN and VBUS_INTERRUPT set.
3316+ * Root Port Reset is indicated by ROOT_PORT_RESET_INTERRUPT set and
3317+ * both HIGH_SPEED and FULL_SPEED clear (as ROOT_PORT_RESET_INTERRUPT
3318+ * only indicates a change in the reset state).
3319+ */
3320+ if (stat & tmp) {
3321+ writel(tmp, &dev->regs->irqstat1);
3322+ if ((((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) &&
3323+ (readl(&dev->usb->usbstat) & mask)) ||
3324+ ((readl(&dev->usb->usbctl) &
3325+ BIT(VBUS_PIN)) == 0)) &&
3326+ (dev->gadget.speed != USB_SPEED_UNKNOWN)) {
3327+ ep_dbg(dev, "disconnect %s\n",
3328+ dev->driver->driver.name);
3329+ stop_activity(dev, dev->driver);
3330+ ep0_start(dev);
3331+ return;
3332+ }
3333+ stat &= ~tmp;
3334+
3335+ /* vBUS can bounce ... one of many reasons to ignore the
3336+ * notion of hotplug events on bus connect/disconnect!
3337+ */
3338+ if (!stat)
3339+ return;
3340+ }
3341+
3342+ /* NOTE: chip stays in PCI D0 state for now, but it could
3343+ * enter D1 to save more power
3344+ */
3345+ tmp = BIT(SUSPEND_REQUEST_CHANGE_INTERRUPT);
3346+ if (stat & tmp) {
3347+ writel(tmp, &dev->regs->irqstat1);
3348+ if (stat & BIT(SUSPEND_REQUEST_INTERRUPT)) {
3349+ if (dev->driver->suspend)
3350+ dev->driver->suspend(&dev->gadget);
3351+ if (!enable_suspend)
3352+ stat &= ~BIT(SUSPEND_REQUEST_INTERRUPT);
3353+ } else {
3354+ if (dev->driver->resume)
3355+ dev->driver->resume(&dev->gadget);
3356+ /* at high speed, note erratum 0133 */
3357+ }
3358+ stat &= ~tmp;
3359+ }
3360+
3361+ /* clear any other status/irqs */
3362+ if (stat)
3363+ writel(stat, &dev->regs->irqstat1);
3364+
3365+ /* some status we can just ignore */
3366+ if (dev->quirks & PLX_2280)
3367+ stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) |
3368+ BIT(SUSPEND_REQUEST_INTERRUPT) |
3369+ BIT(RESUME_INTERRUPT) |
3370+ BIT(SOF_INTERRUPT));
3371+ else
3372+ stat &= ~(BIT(CONTROL_STATUS_INTERRUPT) |
3373+ BIT(RESUME_INTERRUPT) |
3374+ BIT(SOF_DOWN_INTERRUPT) |
3375+ BIT(SOF_INTERRUPT));
3376+
3377+ if (!stat)
3378+ return;
3379+ /* ep_dbg(dev, "irqstat1 %08x\n", stat);*/
3380+
3381+ /* DMA status, for ep-{a,b,c,d} */
3382+ scratch = stat & DMA_INTERRUPTS;
3383+ stat &= ~DMA_INTERRUPTS;
3384+ scratch >>= 9;
3385+ for (num = 0; scratch; num++) {
3386+ struct net2280_dma_regs __iomem *dma;
3387+
3388+ tmp = BIT(num);
3389+ if ((tmp & scratch) == 0)
3390+ continue;
3391+ scratch ^= tmp;
3392+
3393+ ep = &dev->ep[num + 1];
3394+ dma = ep->dma;
3395+
3396+ if (!dma)
3397+ continue;
3398+
3399+ /* clear ep's dma status */
3400+ tmp = readl(&dma->dmastat);
3401+ writel(tmp, &dma->dmastat);
3402+
3403+ /* dma sync*/
3404+ if (dev->quirks & PLX_SUPERSPEED) {
3405+ u32 r_dmacount = readl(&dma->dmacount);
3406+ if (!ep->is_in && (r_dmacount & 0x00FFFFFF) &&
3407+ (tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT)))
3408+ continue;
3409+ }
3410+
3411+ /* chaining should stop on abort, short OUT from fifo,
3412+ * or (stat0 codepath) short OUT transfer.
3413+ */
3414+ if (!use_dma_chaining) {
3415+ if (!(tmp & BIT(DMA_TRANSACTION_DONE_INTERRUPT))) {
3416+ ep_dbg(ep->dev, "%s no xact done? %08x\n",
3417+ ep->ep.name, tmp);
3418+ continue;
3419+ }
3420+ stop_dma(ep->dma);
3421+ }
3422+
3423+ /* OUT transfers terminate when the data from the
3424+ * host is in our memory. Process whatever's done.
3425+ * On this path, we know transfer's last packet wasn't
3426+ * less than req->length. NAK_OUT_PACKETS may be set,
3427+ * or the FIFO may already be holding new packets.
3428+ *
3429+ * IN transfers can linger in the FIFO for a very
3430+ * long time ... we ignore that for now, accounting
3431+ * precisely (like PIO does) needs per-packet irqs
3432+ */
3433+ scan_dma_completions(ep);
3434+
3435+ /* disable dma on inactive queues; else maybe restart */
3436+ if (list_empty(&ep->queue)) {
3437+ if (use_dma_chaining)
3438+ stop_dma(ep->dma);
3439+ } else {
3440+ tmp = readl(&dma->dmactl);
3441+ if (!use_dma_chaining || (tmp & BIT(DMA_ENABLE)) == 0)
3442+ restart_dma(ep);
3443+ else if (ep->is_in && use_dma_chaining) {
3444+ struct net2280_request *req;
3445+ __le32 dmacount;
3446+
3447+ /* the descriptor at the head of the chain
3448+ * may still have VALID_BIT clear; that's
3449+ * used to trigger changing DMA_FIFO_VALIDATE
3450+ * (affects automagic zlp writes).
3451+ */
3452+ req = list_entry(ep->queue.next,
3453+ struct net2280_request, queue);
3454+ dmacount = req->td->dmacount;
3455+ dmacount &= cpu_to_le32(BIT(VALID_BIT) |
3456+ DMA_BYTE_COUNT_MASK);
3457+ if (dmacount && (dmacount & valid_bit) == 0)
3458+ restart_dma(ep);
3459+ }
3460+ }
3461+ ep->irqs++;
3462+ }
3463+
3464+ /* NOTE: there are other PCI errors we might usefully notice.
3465+ * if they appear very often, here's where to try recovering.
3466+ */
3467+ if (stat & PCI_ERROR_INTERRUPTS) {
3468+ ep_err(dev, "pci dma error; stat %08x\n", stat);
3469+ stat &= ~PCI_ERROR_INTERRUPTS;
3470+ /* these are fatal errors, but "maybe" they won't
3471+ * happen again ...
3472+ */
3473+ stop_activity(dev, dev->driver);
3474+ ep0_start(dev);
3475+ stat = 0;
3476+ }
3477+
3478+ if (stat)
3479+ ep_dbg(dev, "unhandled irqstat1 %08x\n", stat);
3480+}
3481+
3482+static irqreturn_t net2280_irq(int irq, void *_dev)
3483+{
3484+ struct net2280 *dev = _dev;
3485+
3486+ /* shared interrupt, not ours */
3487+ if ((dev->quirks & PLX_LEGACY) &&
3488+ (!(readl(&dev->regs->irqstat0) & BIT(INTA_ASSERTED))))
3489+ return IRQ_NONE;
3490+
3491+ spin_lock(&dev->lock);
3492+
3493+ /* handle disconnect, dma, and more */
3494+ handle_stat1_irqs(dev, readl(&dev->regs->irqstat1));
3495+
3496+ /* control requests and PIO */
3497+ handle_stat0_irqs(dev, readl(&dev->regs->irqstat0));
3498+
3499+ if (dev->quirks & PLX_SUPERSPEED) {
3500+ /* re-enable interrupt to trigger any possible new interrupt */
3501+ u32 pciirqenb1 = readl(&dev->regs->pciirqenb1);
3502+ writel(pciirqenb1 & 0x7FFFFFFF, &dev->regs->pciirqenb1);
3503+ writel(pciirqenb1, &dev->regs->pciirqenb1);
3504+ }
3505+
3506+ spin_unlock(&dev->lock);
3507+
3508+ return IRQ_HANDLED;
3509+}
3510+
3511+/*-------------------------------------------------------------------------*/
3512+
3513+static void gadget_release(struct device *_dev)
3514+{
3515+ struct net2280 *dev = dev_get_drvdata(_dev);
3516+
3517+ kfree(dev);
3518+}
3519+
3520+/* tear down the binding between this driver and the pci device */
3521+
3522+static void net2280_remove(struct pci_dev *pdev)
3523+{
3524+ struct net2280 *dev = pci_get_drvdata(pdev);
3525+
3526+ usb_del_gadget_udc(&dev->gadget);
3527+
3528+ BUG_ON(dev->driver);
3529+
3530+ /* then clean up the resources we allocated during probe() */
3531+ net2280_led_shutdown(dev);
3532+ if (dev->requests) {
3533+ int i;
3534+ for (i = 1; i < 5; i++) {
3535+ if (!dev->ep[i].dummy)
3536+ continue;
3537+ pci_pool_free(dev->requests, dev->ep[i].dummy,
3538+ dev->ep[i].td_dma);
3539+ }
3540+ pci_pool_destroy(dev->requests);
3541+ }
3542+ if (dev->got_irq)
3543+ free_irq(pdev->irq, dev);
3544+ if (use_msi && dev->quirks & PLX_SUPERSPEED)
3545+ pci_disable_msi(pdev);
3546+ if (dev->regs)
3547+ iounmap(dev->regs);
3548+ if (dev->region)
3549+ release_mem_region(pci_resource_start(pdev, 0),
3550+ pci_resource_len(pdev, 0));
3551+ if (dev->enabled)
3552+ pci_disable_device(pdev);
3553+ device_remove_file(&pdev->dev, &dev_attr_registers);
3554+
3555+ ep_info(dev, "unbind\n");
3556+}
3557+
3558+/* wrap this driver around the specified device, but
3559+ * don't respond over USB until a gadget driver binds to us.
3560+ */
3561+
3562+static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)
3563+{
3564+ struct net2280 *dev;
3565+ unsigned long resource, len;
3566+ void __iomem *base = NULL;
3567+ int retval, i;
3568+
3569+ if (!use_dma)
3570+ use_dma_chaining = 0;
3571+
3572+ /* alloc, and start init */
3573+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
3574+ if (dev == NULL) {
3575+ retval = -ENOMEM;
3576+ goto done;
3577+ }
3578+
3579+ pci_set_drvdata(pdev, dev);
3580+ spin_lock_init(&dev->lock);
3581+ dev->quirks = id->driver_data;
3582+ dev->pdev = pdev;
3583+ dev->gadget.ops = &net2280_ops;
3584+ dev->gadget.max_speed = (dev->quirks & PLX_SUPERSPEED) ?
3585+ USB_SPEED_SUPER : USB_SPEED_HIGH;
3586+
3587+ /* the "gadget" abstracts/virtualizes the controller */
3588+ dev->gadget.name = driver_name;
3589+
3590+ /* now all the pci goodies ... */
3591+ if (pci_enable_device(pdev) < 0) {
3592+ retval = -ENODEV;
3593+ goto done;
3594+ }
3595+ dev->enabled = 1;
3596+
3597+ /* BAR 0 holds all the registers
3598+ * BAR 1 is 8051 memory; unused here (note erratum 0103)
3599+ * BAR 2 is fifo memory; unused here
3600+ */
3601+ resource = pci_resource_start(pdev, 0);
3602+ len = pci_resource_len(pdev, 0);
3603+ if (!request_mem_region(resource, len, driver_name)) {
3604+ ep_dbg(dev, "controller already in use\n");
3605+ retval = -EBUSY;
3606+ goto done;
3607+ }
3608+ dev->region = 1;
3609+
3610+ /* FIXME provide firmware download interface to put
3611+ * 8051 code into the chip, e.g. to turn on PCI PM.
3612+ */
3613+
3614+ base = ioremap_nocache(resource, len);
3615+ if (base == NULL) {
3616+ ep_dbg(dev, "can't map memory\n");
3617+ retval = -EFAULT;
3618+ goto done;
3619+ }
3620+ dev->regs = (struct net2280_regs __iomem *) base;
3621+ dev->usb = (struct net2280_usb_regs __iomem *) (base + 0x0080);
3622+ dev->pci = (struct net2280_pci_regs __iomem *) (base + 0x0100);
3623+ dev->dma = (struct net2280_dma_regs __iomem *) (base + 0x0180);
3624+ dev->dep = (struct net2280_dep_regs __iomem *) (base + 0x0200);
3625+ dev->epregs = (struct net2280_ep_regs __iomem *) (base + 0x0300);
3626+
3627+ if (dev->quirks & PLX_SUPERSPEED) {
3628+ u32 fsmvalue;
3629+ u32 usbstat;
3630+ dev->usb_ext = (struct usb338x_usb_ext_regs __iomem *)
3631+ (base + 0x00b4);
3632+ dev->fiforegs = (struct usb338x_fifo_regs __iomem *)
3633+ (base + 0x0500);
3634+ dev->llregs = (struct usb338x_ll_regs __iomem *)
3635+ (base + 0x0700);
3636+ dev->ll_lfps_regs = (struct usb338x_ll_lfps_regs __iomem *)
3637+ (base + 0x0748);
3638+ dev->ll_tsn_regs = (struct usb338x_ll_tsn_regs __iomem *)
3639+ (base + 0x077c);
3640+ dev->ll_chicken_reg = (struct usb338x_ll_chi_regs __iomem *)
3641+ (base + 0x079c);
3642+ dev->plregs = (struct usb338x_pl_regs __iomem *)
3643+ (base + 0x0800);
3644+ usbstat = readl(&dev->usb->usbstat);
3645+ dev->enhanced_mode = !!(usbstat & BIT(11));
3646+ dev->n_ep = (dev->enhanced_mode) ? 9 : 5;
3647+ /* put into initial config, link up all endpoints */
3648+ fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
3649+ (0xf << DEFECT7374_FSM_FIELD);
3650+ /* See if firmware needs to set up for workaround: */
3651+ if (fsmvalue == DEFECT7374_FSM_SS_CONTROL_READ)
3652+ writel(0, &dev->usb->usbctl);
3653+ } else{
3654+ dev->enhanced_mode = 0;
3655+ dev->n_ep = 7;
3656+ /* put into initial config, link up all endpoints */
3657+ writel(0, &dev->usb->usbctl);
3658+ }
3659+
3660+ usb_reset(dev);
3661+ usb_reinit(dev);
3662+
3663+ /* irq setup after old hardware is cleaned up */
3664+ if (!pdev->irq) {
3665+ ep_err(dev, "No IRQ. Check PCI setup!\n");
3666+ retval = -ENODEV;
3667+ goto done;
3668+ }
3669+
3670+ if (use_msi && (dev->quirks & PLX_SUPERSPEED))
3671+ if (pci_enable_msi(pdev))
3672+ ep_err(dev, "Failed to enable MSI mode\n");
3673+
3674+ if (request_irq(pdev->irq, net2280_irq, IRQF_SHARED,
3675+ driver_name, dev)) {
3676+ ep_err(dev, "request interrupt %d failed\n", pdev->irq);
3677+ retval = -EBUSY;
3678+ goto done;
3679+ }
3680+ dev->got_irq = 1;
3681+
3682+ /* DMA setup */
3683+ /* NOTE: we know only the 32 LSBs of dma addresses may be nonzero */
3684+ dev->requests = pci_pool_create("requests", pdev,
3685+ sizeof(struct net2280_dma),
3686+ 0 /* no alignment requirements */,
3687+ 0 /* or page-crossing issues */);
3688+ if (!dev->requests) {
3689+ ep_dbg(dev, "can't get request pool\n");
3690+ retval = -ENOMEM;
3691+ goto done;
3692+ }
3693+ for (i = 1; i < 5; i++) {
3694+ struct net2280_dma *td;
3695+
3696+ td = pci_pool_alloc(dev->requests, GFP_KERNEL,
3697+ &dev->ep[i].td_dma);
3698+ if (!td) {
3699+ ep_dbg(dev, "can't get dummy %d\n", i);
3700+ retval = -ENOMEM;
3701+ goto done;
3702+ }
3703+ td->dmacount = 0; /* not VALID */
3704+ td->dmadesc = td->dmaaddr;
3705+ dev->ep[i].dummy = td;
3706+ }
3707+
3708+ /* enable lower-overhead pci memory bursts during DMA */
3709+ if (dev->quirks & PLX_LEGACY)
3710+ writel(BIT(DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE) |
3711+ /*
3712+ * 256 write retries may not be enough...
3713+ BIT(PCI_RETRY_ABORT_ENABLE) |
3714+ */
3715+ BIT(DMA_READ_MULTIPLE_ENABLE) |
3716+ BIT(DMA_READ_LINE_ENABLE),
3717+ &dev->pci->pcimstctl);
3718+ /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
3719+ pci_set_master(pdev);
3720+ pci_try_set_mwi(pdev);
3721+
3722+ /* ... also flushes any posted pci writes */
3723+ dev->chiprev = get_idx_reg(dev->regs, REG_CHIPREV) & 0xffff;
3724+
3725+ /* done */
3726+ ep_info(dev, "%s\n", driver_desc);
3727+ ep_info(dev, "irq %d, pci mem %p, chip rev %04x\n",
3728+ pdev->irq, base, dev->chiprev);
3729+ ep_info(dev, "version: " DRIVER_VERSION "; dma %s %s\n",
3730+ use_dma ? (use_dma_chaining ? "chaining" : "enabled")
3731+ : "disabled",
3732+ dev->enhanced_mode ? "enhanced mode" : "legacy mode");
3733+ retval = device_create_file(&pdev->dev, &dev_attr_registers);
3734+ if (retval)
3735+ goto done;
3736+
3737+ retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
3738+ gadget_release);
3739+ if (retval)
3740+ goto done;
3741+ return 0;
3742+
3743+done:
3744+ if (dev)
3745+ net2280_remove(pdev);
3746+ return retval;
3747+}
3748+
3749+/* make sure the board is quiescent; otherwise it will continue
3750+ * generating IRQs across the upcoming reboot.
3751+ */
3752+
3753+static void net2280_shutdown(struct pci_dev *pdev)
3754+{
3755+ struct net2280 *dev = pci_get_drvdata(pdev);
3756+
3757+ /* disable IRQs */
3758+ writel(0, &dev->regs->pciirqenb0);
3759+ writel(0, &dev->regs->pciirqenb1);
3760+
3761+ /* disable the pullup so the host will think we're gone */
3762+ writel(0, &dev->usb->usbctl);
3763+
3764+ /* Disable full-speed test mode */
3765+ if (dev->quirks & PLX_LEGACY)
3766+ writel(0, &dev->usb->xcvrdiag);
3767+}
3768+
3769+
3770+/*-------------------------------------------------------------------------*/
3771+
3772+static const struct pci_device_id pci_ids[] = { {
3773+ .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3774+ .class_mask = ~0,
3775+ .vendor = PCI_VENDOR_ID_PLX_LEGACY,
3776+ .device = 0x2280,
3777+ .subvendor = PCI_ANY_ID,
3778+ .subdevice = PCI_ANY_ID,
3779+ .driver_data = PLX_LEGACY | PLX_2280,
3780+ }, {
3781+ .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3782+ .class_mask = ~0,
3783+ .vendor = PCI_VENDOR_ID_PLX_LEGACY,
3784+ .device = 0x2282,
3785+ .subvendor = PCI_ANY_ID,
3786+ .subdevice = PCI_ANY_ID,
3787+ .driver_data = PLX_LEGACY,
3788+ },
3789+ {
3790+ .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3791+ .class_mask = ~0,
3792+ .vendor = PCI_VENDOR_ID_PLX,
3793+ .device = 0x3380,
3794+ .subvendor = PCI_ANY_ID,
3795+ .subdevice = PCI_ANY_ID,
3796+ .driver_data = PLX_SUPERSPEED,
3797+ },
3798+ {
3799+ .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
3800+ .class_mask = ~0,
3801+ .vendor = PCI_VENDOR_ID_PLX,
3802+ .device = 0x3382,
3803+ .subvendor = PCI_ANY_ID,
3804+ .subdevice = PCI_ANY_ID,
3805+ .driver_data = PLX_SUPERSPEED,
3806+ },
3807+{ /* end: all zeroes */ }
3808+};
3809+MODULE_DEVICE_TABLE(pci, pci_ids);
3810+
3811+/* pci driver glue; this is a "new style" PCI driver module */
3812+static struct pci_driver net2280_pci_driver = {
3813+ .name = (char *) driver_name,
3814+ .id_table = pci_ids,
3815+
3816+ .probe = net2280_probe,
3817+ .remove = net2280_remove,
3818+ .shutdown = net2280_shutdown,
3819+
3820+ /* FIXME add power management support */
3821+};
3822+
3823+module_pci_driver(net2280_pci_driver);
3824+
3825+MODULE_DESCRIPTION(DRIVER_DESC);
3826+MODULE_AUTHOR("David Brownell");
3827+MODULE_LICENSE("GPL");
drivers/usb/gadget/udc/net2280.h+403−0
@@ -0,0 +1,403 @@
1+/*
2+ * NetChip 2280 high/full speed USB device controller.
3+ * Unlike many such controllers, this one talks PCI.
4+ */
5+
6+/*
7+ * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
8+ * Copyright (C) 2003 David Brownell
9+ * Copyright (C) 2014 Ricardo Ribalda - Qtechnology/AS
10+ *
11+ * This program is free software; you can redistribute it and/or modify
12+ * it under the terms of the GNU General Public License as published by
13+ * the Free Software Foundation; either version 2 of the License, or
14+ * (at your option) any later version.
15+ */
16+
17+#include <linux/usb/net2280.h>
18+#include <linux/usb/usb338x.h>
19+
20+/*-------------------------------------------------------------------------*/
21+
22+#ifdef __KERNEL__
23+
24+/* indexed registers [11.10] are accessed indirectly
25+ * caller must own the device lock.
26+ */
27+
28+static inline u32 get_idx_reg(struct net2280_regs __iomem *regs, u32 index)
29+{
30+ writel(index, &regs->idxaddr);
31+ /* NOTE: synchs device/cpu memory views */
32+ return readl(&regs->idxdata);
33+}
34+
35+static inline void
36+set_idx_reg(struct net2280_regs __iomem *regs, u32 index, u32 value)
37+{
38+ writel(index, &regs->idxaddr);
39+ writel(value, &regs->idxdata);
40+ /* posted, may not be visible yet */
41+}
42+
43+#endif /* __KERNEL__ */
44+
45+#define PCI_VENDOR_ID_PLX_LEGACY 0x17cc
46+
47+#define PLX_LEGACY BIT(0)
48+#define PLX_2280 BIT(1)
49+#define PLX_SUPERSPEED BIT(2)
50+
51+#define REG_DIAG 0x0
52+#define RETRY_COUNTER 16
53+#define FORCE_PCI_SERR 11
54+#define FORCE_PCI_INTERRUPT 10
55+#define FORCE_USB_INTERRUPT 9
56+#define FORCE_CPU_INTERRUPT 8
57+#define ILLEGAL_BYTE_ENABLES 5
58+#define FAST_TIMES 4
59+#define FORCE_RECEIVE_ERROR 2
60+#define FORCE_TRANSMIT_CRC_ERROR 0
61+#define REG_FRAME 0x02 /* from last sof */
62+#define REG_CHIPREV 0x03 /* in bcd */
63+#define REG_HS_NAK_RATE 0x0a /* NAK per N uframes */
64+
65+#define CHIPREV_1 0x0100
66+#define CHIPREV_1A 0x0110
67+
68+/* DEFECT 7374 */
69+#define DEFECT_7374_NUMBEROF_MAX_WAIT_LOOPS 200
70+#define DEFECT_7374_PROCESSOR_WAIT_TIME 10
71+
72+/* ep0 max packet size */
73+#define EP0_SS_MAX_PACKET_SIZE 0x200
74+#define EP0_HS_MAX_PACKET_SIZE 0x40
75+#ifdef __KERNEL__
76+
77+/*-------------------------------------------------------------------------*/
78+
79+/* [8.3] for scatter/gather i/o
80+ * use struct net2280_dma_regs bitfields
81+ */
82+struct net2280_dma {
83+ __le32 dmacount;
84+ __le32 dmaaddr; /* the buffer */
85+ __le32 dmadesc; /* next dma descriptor */
86+ __le32 _reserved;
87+} __aligned(16);
88+
89+/*-------------------------------------------------------------------------*/
90+
91+/* DRIVER DATA STRUCTURES and UTILITIES */
92+
93+struct net2280_ep {
94+ struct usb_ep ep;
95+ struct net2280_ep_regs __iomem *cfg;
96+ struct net2280_ep_regs __iomem *regs;
97+ struct net2280_dma_regs __iomem *dma;
98+ struct net2280_dma *dummy;
99+ struct usb338x_fifo_regs __iomem *fiforegs;
100+ dma_addr_t td_dma; /* of dummy */
101+ struct net2280 *dev;
102+ unsigned long irqs;
103+ unsigned is_halt:1, dma_started:1;
104+
105+ /* analogous to a host-side qh */
106+ struct list_head queue;
107+ const struct usb_endpoint_descriptor *desc;
108+ unsigned num : 8,
109+ fifo_size : 12,
110+ in_fifo_validate : 1,
111+ out_overflow : 1,
112+ stopped : 1,
113+ wedged : 1,
114+ is_in : 1,
115+ is_iso : 1,
116+ responded : 1;
117+};
118+
119+static inline void allow_status(struct net2280_ep *ep)
120+{
121+ /* ep0 only */
122+ writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) |
123+ BIT(CLEAR_NAK_OUT_PACKETS) |
124+ BIT(CLEAR_NAK_OUT_PACKETS_MODE),
125+ &ep->regs->ep_rsp);
126+ ep->stopped = 1;
127+}
128+
129+static void allow_status_338x(struct net2280_ep *ep)
130+{
131+ /*
132+ * Control Status Phase Handshake was set by the chip when the setup
133+ * packet arrived. While set, the chip automatically NAKs the host's
134+ * Status Phase tokens.
135+ */
136+ writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE), &ep->regs->ep_rsp);
137+
138+ ep->stopped = 1;
139+
140+ /* TD 9.9 Halt Endpoint test. TD 9.22 set feature test. */
141+ ep->responded = 0;
142+}
143+
144+struct net2280_request {
145+ struct usb_request req;
146+ struct net2280_dma *td;
147+ dma_addr_t td_dma;
148+ struct list_head queue;
149+ unsigned mapped : 1,
150+ valid : 1;
151+};
152+
153+struct net2280 {
154+ /* each pci device provides one gadget, several endpoints */
155+ struct usb_gadget gadget;
156+ spinlock_t lock;
157+ struct net2280_ep ep[9];
158+ struct usb_gadget_driver *driver;
159+ unsigned enabled : 1,
160+ protocol_stall : 1,
161+ softconnect : 1,
162+ got_irq : 1,
163+ region:1,
164+ u1_enable:1,
165+ u2_enable:1,
166+ ltm_enable:1,
167+ wakeup_enable:1,
168+ selfpowered:1,
169+ addressed_state:1;
170+ u16 chiprev;
171+ int enhanced_mode;
172+ int n_ep;
173+ kernel_ulong_t quirks;
174+
175+
176+ /* pci state used to access those endpoints */
177+ struct pci_dev *pdev;
178+ struct net2280_regs __iomem *regs;
179+ struct net2280_usb_regs __iomem *usb;
180+ struct usb338x_usb_ext_regs __iomem *usb_ext;
181+ struct net2280_pci_regs __iomem *pci;
182+ struct net2280_dma_regs __iomem *dma;
183+ struct net2280_dep_regs __iomem *dep;
184+ struct net2280_ep_regs __iomem *epregs;
185+ struct usb338x_fifo_regs __iomem *fiforegs;
186+ struct usb338x_ll_regs __iomem *llregs;
187+ struct usb338x_ll_lfps_regs __iomem *ll_lfps_regs;
188+ struct usb338x_ll_tsn_regs __iomem *ll_tsn_regs;
189+ struct usb338x_ll_chi_regs __iomem *ll_chicken_reg;
190+ struct usb338x_pl_regs __iomem *plregs;
191+
192+ struct pci_pool *requests;
193+ /* statistics...*/
194+};
195+
196+static inline void set_halt(struct net2280_ep *ep)
197+{
198+ /* ep0 and bulk/intr endpoints */
199+ writel(BIT(CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE) |
200+ /* set NAK_OUT for erratum 0114 */
201+ ((ep->dev->chiprev == CHIPREV_1) << SET_NAK_OUT_PACKETS) |
202+ BIT(SET_ENDPOINT_HALT),
203+ &ep->regs->ep_rsp);
204+}
205+
206+static inline void clear_halt(struct net2280_ep *ep)
207+{
208+ /* ep0 and bulk/intr endpoints */
209+ writel(BIT(CLEAR_ENDPOINT_HALT) |
210+ BIT(CLEAR_ENDPOINT_TOGGLE) |
211+ /*
212+ * unless the gadget driver left a short packet in the
213+ * fifo, this reverses the erratum 0114 workaround.
214+ */
215+ ((ep->dev->chiprev == CHIPREV_1) << CLEAR_NAK_OUT_PACKETS),
216+ &ep->regs->ep_rsp);
217+}
218+
219+/*
220+ * FSM value for Defect 7374 (U1U2 Test) is managed in
221+ * chip's SCRATCH register:
222+ */
223+#define DEFECT7374_FSM_FIELD 28
224+
225+/* Waiting for Control Read:
226+ * - A transition to this state indicates a fresh USB connection,
227+ * before the first Setup Packet. The connection speed is not
228+ * known. Firmware is waiting for the first Control Read.
229+ * - Starting state: This state can be thought of as the FSM's typical
230+ * starting state.
231+ * - Tip: Upon the first SS Control Read the FSM never
232+ * returns to this state.
233+ */
234+#define DEFECT7374_FSM_WAITING_FOR_CONTROL_READ BIT(DEFECT7374_FSM_FIELD)
235+
236+/* Non-SS Control Read:
237+ * - A transition to this state indicates detection of the first HS
238+ * or FS Control Read.
239+ * - Tip: Upon the first SS Control Read the FSM never
240+ * returns to this state.
241+ */
242+#define DEFECT7374_FSM_NON_SS_CONTROL_READ (2 << DEFECT7374_FSM_FIELD)
243+
244+/* SS Control Read:
245+ * - A transition to this state indicates detection of the
246+ * first SS Control Read.
247+ * - This state indicates workaround completion. Workarounds no longer
248+ * need to be applied (as long as the chip remains powered up).
249+ * - Tip: Once in this state the FSM state does not change (until
250+ * the chip's power is lost and restored).
251+ * - This can be thought of as the final state of the FSM;
252+ * the FSM 'locks-up' in this state until the chip loses power.
253+ */
254+#define DEFECT7374_FSM_SS_CONTROL_READ (3 << DEFECT7374_FSM_FIELD)
255+
256+#ifdef USE_RDK_LEDS
257+
258+static inline void net2280_led_init(struct net2280 *dev)
259+{
260+ /* LED3 (green) is on during USB activity. note erratum 0113. */
261+ writel(BIT(GPIO3_LED_SELECT) |
262+ BIT(GPIO3_OUTPUT_ENABLE) |
263+ BIT(GPIO2_OUTPUT_ENABLE) |
264+ BIT(GPIO1_OUTPUT_ENABLE) |
265+ BIT(GPIO0_OUTPUT_ENABLE),
266+ &dev->regs->gpioctl);
267+}
268+
269+/* indicate speed with bi-color LED 0/1 */
270+static inline
271+void net2280_led_speed(struct net2280 *dev, enum usb_device_speed speed)
272+{
273+ u32 val = readl(&dev->regs->gpioctl);
274+ switch (speed) {
275+ case USB_SPEED_SUPER: /* green + red */
276+ val |= BIT(GPIO0_DATA) | BIT(GPIO1_DATA);
277+ break;
278+ case USB_SPEED_HIGH: /* green */
279+ val &= ~BIT(GPIO0_DATA);
280+ val |= BIT(GPIO1_DATA);
281+ break;
282+ case USB_SPEED_FULL: /* red */
283+ val &= ~BIT(GPIO1_DATA);
284+ val |= BIT(GPIO0_DATA);
285+ break;
286+ default: /* (off/black) */
287+ val &= ~(BIT(GPIO1_DATA) | BIT(GPIO0_DATA));
288+ break;
289+ }
290+ writel(val, &dev->regs->gpioctl);
291+}
292+
293+/* indicate power with LED 2 */
294+static inline void net2280_led_active(struct net2280 *dev, int is_active)
295+{
296+ u32 val = readl(&dev->regs->gpioctl);
297+
298+ /* FIXME this LED never seems to turn on.*/
299+ if (is_active)
300+ val |= GPIO2_DATA;
301+ else
302+ val &= ~GPIO2_DATA;
303+ writel(val, &dev->regs->gpioctl);
304+}
305+
306+static inline void net2280_led_shutdown(struct net2280 *dev)
307+{
308+ /* turn off all four GPIO*_DATA bits */
309+ writel(readl(&dev->regs->gpioctl) & ~0x0f,
310+ &dev->regs->gpioctl);
311+}
312+
313+#else
314+
315+#define net2280_led_init(dev) do { } while (0)
316+#define net2280_led_speed(dev, speed) do { } while (0)
317+#define net2280_led_shutdown(dev) do { } while (0)
318+
319+#endif
320+
321+/*-------------------------------------------------------------------------*/
322+
323+#define ep_dbg(ndev, fmt, args...) \
324+ dev_dbg((&((ndev)->pdev->dev)), fmt, ##args)
325+
326+#define ep_vdbg(ndev, fmt, args...) \
327+ dev_vdbg((&((ndev)->pdev->dev)), fmt, ##args)
328+
329+#define ep_info(ndev, fmt, args...) \
330+ dev_info((&((ndev)->pdev->dev)), fmt, ##args)
331+
332+#define ep_warn(ndev, fmt, args...) \
333+ dev_warn((&((ndev)->pdev->dev)), fmt, ##args)
334+
335+#define ep_err(ndev, fmt, args...) \
336+ dev_err((&((ndev)->pdev->dev)), fmt, ##args)
337+
338+/*-------------------------------------------------------------------------*/
339+
340+static inline void set_fifo_bytecount(struct net2280_ep *ep, unsigned count)
341+{
342+ if (ep->dev->pdev->vendor == 0x17cc)
343+ writeb(count, 2 + (u8 __iomem *) &ep->regs->ep_cfg);
344+ else{
345+ u32 tmp = readl(&ep->cfg->ep_cfg) &
346+ (~(0x07 << EP_FIFO_BYTE_COUNT));
347+ writel(tmp | (count << EP_FIFO_BYTE_COUNT), &ep->cfg->ep_cfg);
348+ }
349+}
350+
351+static inline void start_out_naking(struct net2280_ep *ep)
352+{
353+ /* NOTE: hardware races lurk here, and PING protocol issues */
354+ writel(BIT(SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
355+ /* synch with device */
356+ readl(&ep->regs->ep_rsp);
357+}
358+
359+#ifdef DEBUG
360+static inline void assert_out_naking(struct net2280_ep *ep, const char *where)
361+{
362+ u32 tmp = readl(&ep->regs->ep_stat);
363+
364+ if ((tmp & BIT(NAK_OUT_PACKETS)) == 0) {
365+ ep_dbg(ep->dev, "%s %s %08x !NAK\n",
366+ ep->ep.name, where, tmp);
367+ writel(BIT(SET_NAK_OUT_PACKETS),
368+ &ep->regs->ep_rsp);
369+ }
370+}
371+#define ASSERT_OUT_NAKING(ep) assert_out_naking(ep, __func__)
372+#else
373+#define ASSERT_OUT_NAKING(ep) do {} while (0)
374+#endif
375+
376+static inline void stop_out_naking(struct net2280_ep *ep)
377+{
378+ u32 tmp;
379+
380+ tmp = readl(&ep->regs->ep_stat);
381+ if ((tmp & BIT(NAK_OUT_PACKETS)) != 0)
382+ writel(BIT(CLEAR_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
383+}
384+
385+
386+static inline void set_max_speed(struct net2280_ep *ep, u32 max)
387+{
388+ u32 reg;
389+ static const u32 ep_enhanced[9] = { 0x10, 0x60, 0x30, 0x80,
390+ 0x50, 0x20, 0x70, 0x40, 0x90 };
391+
392+ if (ep->dev->enhanced_mode)
393+ reg = ep_enhanced[ep->num];
394+ else{
395+ reg = (ep->num + 1) * 0x10;
396+ if (ep->dev->gadget.speed != USB_SPEED_HIGH)
397+ reg += 1;
398+ }
399+
400+ set_idx_reg(ep->dev->regs, reg, max);
401+}
402+
403+#endif /* __KERNEL__ */
drivers/usb/gadget/udc/omap_udc.crenamed from drivers/usb/gadget/omap_udc.c+1−4
@@ -2079,10 +2079,7 @@ static int omap_udc_start(struct usb_gadget *g, · 2078 unmodified lines
20792079 &udc->gadget);
20802080 if (status < 0) {
20812081 ERR("can't bind to transceiver\n");
2082− if (driver->unbind) {
2083− driver->unbind(&udc->gadget);
2084− udc->driver = NULL;
2085− }
2082+ udc->driver = NULL;
20862083 goto done;
20872084 }
20882085 } else {
drivers/usb/gadget/udc/omap_udc.hrenamed from drivers/usb/gadget/omap_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/pch_udc.crenamed from drivers/usb/gadget/pch_udc.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/pxa25x_udc.crenamed from drivers/usb/gadget/pxa25x_udc.c+23−52
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 /* #define VERBOSE_DEBUG */
1717
1818 #include <linux/device.h>
19+#include <linux/gpio.h>
1920 #include <linux/module.h>
2021 #include <linux/kernel.h>
2122 #include <linux/ioport.h>
@@ -40,7 +41,6 @@ · 18 unmodified lines
4041
4142 #include <asm/byteorder.h>
4243 #include <asm/dma.h>
43−#include <asm/gpio.h>
4444 #include <asm/mach-types.h>
4545 #include <asm/unaligned.h>
4646
@@ -2105,11 +2105,9 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 2058 unmodified lines
21052105 if (irq < 0)
21062106 return -ENODEV;
21072107
2108− dev->clk = clk_get(&pdev->dev, NULL);
2109− if (IS_ERR(dev->clk)) {
2110− retval = PTR_ERR(dev->clk);
2111− goto err_clk;
2112− }
2108+ dev->clk = devm_clk_get(&pdev->dev, NULL);
2109+ if (IS_ERR(dev->clk))
2110+ return PTR_ERR(dev->clk);
21132111
21142112 pr_debug("%s: IRQ %d%s%s\n", driver_name, irq,
21152113 dev->has_cfr ? "" : " (!cfr)",
@@ -2120,15 +2118,16 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 4 unmodified lines
21202118 dev->dev = &pdev->dev;
21212119 dev->mach = dev_get_platdata(&pdev->dev);
21222120
2123− dev->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
2121+ dev->transceiver = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
21242122
21252123 if (gpio_is_valid(dev->mach->gpio_pullup)) {
2126− if ((retval = gpio_request(dev->mach->gpio_pullup,
2127− "pca25x_udc GPIO PULLUP"))) {
2124+ retval = devm_gpio_request(&pdev->dev, dev->mach->gpio_pullup,
2125+ "pca25x_udc GPIO PULLUP");
2126+ if (retval) {
21282127 dev_dbg(&pdev->dev,
21292128 "can't get pullup gpio %d, err: %d\n",
21302129 dev->mach->gpio_pullup, retval);
2131− goto err_gpio_pullup;
2130+ goto err;
21322131 }
21332132 gpio_direction_output(dev->mach->gpio_pullup, 0);
21342133 }
@@ -2146,30 +2145,32 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 11 unmodified lines
21462145 dev->vbus = 0;
21472146
21482147 /* irq setup after old hardware state is cleaned up */
2149− retval = request_irq(irq, pxa25x_udc_irq,
2150− 0, driver_name, dev);
2148+ retval = devm_request_irq(&pdev->dev, irq, pxa25x_udc_irq, 0,
2149+ driver_name, dev);
21512150 if (retval != 0) {
21522151 pr_err("%s: can't get irq %d, err %d\n",
21532152 driver_name, irq, retval);
2154− goto err_irq1;
2153+ goto err;
21552154 }
21562155 dev->got_irq = 1;
21572156
21582157 #ifdef CONFIG_ARCH_LUBBOCK
21592158 if (machine_is_lubbock()) {
2160− retval = request_irq(LUBBOCK_USB_DISC_IRQ, lubbock_vbus_irq,
2161− 0, driver_name, dev);
2159+ retval = devm_request_irq(&pdev->dev, LUBBOCK_USB_DISC_IRQ,
2160+ lubbock_vbus_irq, 0, driver_name,
2161+ dev);
21622162 if (retval != 0) {
21632163 pr_err("%s: can't get irq %i, err %d\n",
21642164 driver_name, LUBBOCK_USB_DISC_IRQ, retval);
2165− goto err_irq_lub;
2165+ goto err;
21662166 }
2167− retval = request_irq(LUBBOCK_USB_IRQ, lubbock_vbus_irq,
2168− 0, driver_name, dev);
2167+ retval = devm_request_irq(&pdev->dev, LUBBOCK_USB_IRQ,
2168+ lubbock_vbus_irq, 0, driver_name,
2169+ dev);
21692170 if (retval != 0) {
21702171 pr_err("%s: can't get irq %i, err %d\n",
21712172 driver_name, LUBBOCK_USB_IRQ, retval);
2172− goto lubbock_fail0;
2173+ goto err;
21732174 }
21742175 } else
21752176 #endif
@@ -2180,22 +2181,9 @@ static int pxa25x_udc_probe(struct platform_device *pdev) · 4 unmodified lines
21802181 return retval;
21812182
21822183 remove_debug_files(dev);
2183−#ifdef CONFIG_ARCH_LUBBOCK
2184−lubbock_fail0:
2185− free_irq(LUBBOCK_USB_DISC_IRQ, dev);
2186− err_irq_lub:
2187− free_irq(irq, dev);
2188−#endif
2189− err_irq1:
2190− if (gpio_is_valid(dev->mach->gpio_pullup))
2191− gpio_free(dev->mach->gpio_pullup);
2192− err_gpio_pullup:
2193− if (!IS_ERR_OR_NULL(dev->transceiver)) {
2194− usb_put_phy(dev->transceiver);
2184+ err:
2185+ if (!IS_ERR_OR_NULL(dev->transceiver))
21952186 dev->transceiver = NULL;
2196− }
2197− clk_put(dev->clk);
2198− err_clk:
21992187 return retval;
22002188 }
22012189
@@ -2217,25 +2205,8 @@ static int pxa25x_udc_remove(struct platform_device *pdev) · 15 unmodified lines
22172205
22182206 remove_debug_files(dev);
22192207
2220− if (dev->got_irq) {
2221− free_irq(platform_get_irq(pdev, 0), dev);
2222− dev->got_irq = 0;
2223− }
2224−#ifdef CONFIG_ARCH_LUBBOCK
2225− if (machine_is_lubbock()) {
2226− free_irq(LUBBOCK_USB_DISC_IRQ, dev);
2227− free_irq(LUBBOCK_USB_IRQ, dev);
2228− }
2229−#endif
2230− if (gpio_is_valid(dev->mach->gpio_pullup))
2231− gpio_free(dev->mach->gpio_pullup);
2232−
2233− clk_put(dev->clk);
2234−
2235− if (!IS_ERR_OR_NULL(dev->transceiver)) {
2236− usb_put_phy(dev->transceiver);
2208+ if (!IS_ERR_OR_NULL(dev->transceiver))
22372209 dev->transceiver = NULL;
2238− }
22392210
22402211 the_controller = NULL;
22412212 return 0;
drivers/usb/gadget/udc/pxa25x_udc.hrenamed from drivers/usb/gadget/pxa25x_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/pxa27x_udc.crenamed from drivers/usb/gadget/pxa27x_udc.c+6−0
@@ -2446,6 +2446,9 @@ static int pxa_udc_probe(struct platform_device *pdev) · 2445 unmodified lines
24462446 retval = PTR_ERR(udc->clk);
24472447 goto err_clk;
24482448 }
2449+ retval = clk_prepare(udc->clk);
2450+ if (retval)
2451+ goto err_clk_prepare;
24492452
24502453 retval = -ENOMEM;
24512454 udc->regs = ioremap(regs->start, resource_size(regs));
@@ -2483,6 +2486,8 @@ err_add_udc: · 31 unmodified lines
24832486 err_irq:
24842487 iounmap(udc->regs);
24852488 err_map:
2489+ clk_unprepare(udc->clk);
2490+err_clk_prepare:
24862491 clk_put(udc->clk);
24872492 udc->clk = NULL;
24882493 err_clk:
@@ -2509,6 +2514,7 @@ static int pxa_udc_remove(struct platform_device *_dev) · 20 unmodified lines
25092514
25102515 udc->transceiver = NULL;
25112516 the_controller = NULL;
2517+ clk_unprepare(udc->clk);
25122518 clk_put(udc->clk);
25132519 iounmap(udc->regs);
25142520
drivers/usb/gadget/udc/pxa27x_udc.hrenamed from drivers/usb/gadget/pxa27x_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/r8a66597-udc.crenamed from drivers/usb/gadget/r8a66597-udc.c+28−64
@@ -1826,18 +1826,12 @@ static int __exit r8a66597_remove(struct platform_device *pdev) · 1825 unmodified lines
18261826
18271827 usb_del_gadget_udc(&r8a66597->gadget);
18281828 del_timer_sync(&r8a66597->timer);
1829− iounmap(r8a66597->reg);
1830− if (r8a66597->pdata->sudmac)
1831− iounmap(r8a66597->sudmac_reg);
1832− free_irq(platform_get_irq(pdev, 0), r8a66597);
18331829 r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
18341830
18351831 if (r8a66597->pdata->on_chip) {
18361832 clk_disable_unprepare(r8a66597->clk);
1837− clk_put(r8a66597->clk);
18381833 }
18391834
1840− kfree(r8a66597);
18411835 return 0;
18421836 }
18431837
@@ -1845,28 +1839,24 @@ static void nop_completion(struct usb_ep *ep, struct usb_request *r) · 1 unmodified line
18451839 {
18461840 }
18471841
1848−static int __init r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597,
1842+static int r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597,
18491843 struct platform_device *pdev)
18501844 {
18511845 struct resource *res;
18521846
18531847 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac");
1854− if (!res) {
1855− dev_err(&pdev->dev, "platform_get_resource error(sudmac).\n");
1856− return -ENODEV;
1857− }
1858−
1859− r8a66597->sudmac_reg = ioremap(res->start, resource_size(res));
1860− if (r8a66597->sudmac_reg == NULL) {
1848+ r8a66597->sudmac_reg = devm_ioremap_resource(&pdev->dev, res);
1849+ if (IS_ERR(r8a66597->sudmac_reg)) {
18611850 dev_err(&pdev->dev, "ioremap error(sudmac).\n");
1862− return -ENOMEM;
1851+ return PTR_ERR(r8a66597->sudmac_reg);
18631852 }
18641853
18651854 return 0;
18661855 }
18671856
1868−static int __init r8a66597_probe(struct platform_device *pdev)
1857+static int r8a66597_probe(struct platform_device *pdev)
18691858 {
1859+ struct device *dev = &pdev->dev;
18701860 char clk_name[8];
18711861 struct resource *res, *ires;
18721862 int irq;
@@ -1877,39 +1867,27 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 4 unmodified lines
18771867 unsigned long irq_trigger;
18781868
18791869 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1880− if (!res) {
1881− ret = -ENODEV;
1882− dev_err(&pdev->dev, "platform_get_resource error.\n");
1883− goto clean_up;
1884− }
1870+ reg = devm_ioremap_resource(&pdev->dev, res);
1871+ if (!reg)
1872+ return -ENODEV;
18851873
18861874 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
18871875 irq = ires->start;
18881876 irq_trigger = ires->flags & IRQF_TRIGGER_MASK;
18891877
18901878 if (irq < 0) {
1891− ret = -ENODEV;
1892− dev_err(&pdev->dev, "platform_get_irq error.\n");
1893− goto clean_up;
1894− }
1895−
1896− reg = ioremap(res->start, resource_size(res));
1897− if (reg == NULL) {
1898− ret = -ENOMEM;
1899− dev_err(&pdev->dev, "ioremap error.\n");
1900− goto clean_up;
1879+ dev_err(dev, "platform_get_irq error.\n");
1880+ return -ENODEV;
19011881 }
19021882
19031883 /* initialize ucd */
1904− r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL);
1905− if (r8a66597 == NULL) {
1906− ret = -ENOMEM;
1907− goto clean_up;
1908− }
1884+ r8a66597 = devm_kzalloc(dev, sizeof(struct r8a66597), GFP_KERNEL);
1885+ if (r8a66597 == NULL)
1886+ return -ENOMEM;
19091887
19101888 spin_lock_init(&r8a66597->lock);
19111889 platform_set_drvdata(pdev, r8a66597);
1912− r8a66597->pdata = dev_get_platdata(&pdev->dev);
1890+ r8a66597->pdata = dev_get_platdata(dev);
19131891 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
19141892
19151893 r8a66597->gadget.ops = &r8a66597_gadget_ops;
@@ -1923,12 +1901,10 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 7 unmodified lines
19231901
19241902 if (r8a66597->pdata->on_chip) {
19251903 snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id);
1926− r8a66597->clk = clk_get(&pdev->dev, clk_name);
1904+ r8a66597->clk = devm_clk_get(dev, clk_name);
19271905 if (IS_ERR(r8a66597->clk)) {
1928− dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
1929− clk_name);
1930− ret = PTR_ERR(r8a66597->clk);
1931− goto clean_up;
1906+ dev_err(dev, "cannot get clock \"%s\"\n", clk_name);
1907+ return PTR_ERR(r8a66597->clk);
19321908 }
19331909 clk_prepare_enable(r8a66597->clk);
19341910 }
@@ -1941,10 +1917,10 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 6 unmodified lines
19411917
19421918 disable_controller(r8a66597); /* make sure controller is disabled */
19431919
1944− ret = request_irq(irq, r8a66597_irq, IRQF_SHARED,
1945− udc_name, r8a66597);
1920+ ret = devm_request_irq(dev, irq, r8a66597_irq, IRQF_SHARED,
1921+ udc_name, r8a66597);
19461922 if (ret < 0) {
1947− dev_err(&pdev->dev, "request_irq error (%d)\n", ret);
1923+ dev_err(dev, "request_irq error (%d)\n", ret);
19481924 goto clean_up2;
19491925 }
19501926
@@ -1978,37 +1954,25 @@ static int __init r8a66597_probe(struct platform_device *pdev) · 27 unmodified lines
19781954 GFP_KERNEL);
19791955 if (r8a66597->ep0_req == NULL) {
19801956 ret = -ENOMEM;
1981− goto clean_up3;
1957+ goto clean_up2;
19821958 }
19831959 r8a66597->ep0_req->complete = nop_completion;
19841960
1985− ret = usb_add_gadget_udc(&pdev->dev, &r8a66597->gadget);
1961+ ret = usb_add_gadget_udc(dev, &r8a66597->gadget);
19861962 if (ret)
19871963 goto err_add_udc;
19881964
1989− dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1965+ dev_info(dev, "version %s\n", DRIVER_VERSION);
19901966 return 0;
19911967
19921968 err_add_udc:
19931969 r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
1994−clean_up3:
1995− free_irq(irq, r8a66597);
19961970 clean_up2:
1997− if (r8a66597->pdata->on_chip) {
1971+ if (r8a66597->pdata->on_chip)
19981972 clk_disable_unprepare(r8a66597->clk);
1999− clk_put(r8a66597->clk);
2000− }
2001−clean_up:
2002− if (r8a66597) {
2003− if (r8a66597->sudmac_reg)
2004− iounmap(r8a66597->sudmac_reg);
2005− if (r8a66597->ep0_req)
2006− r8a66597_free_request(&r8a66597->ep[0].ep,
2007− r8a66597->ep0_req);
2008− kfree(r8a66597);
2009− }
2010− if (reg)
2011− iounmap(reg);
1973+
1974+ if (r8a66597->ep0_req)
1975+ r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
20121976
20131977 return ret;
20141978 }
drivers/usb/gadget/udc/r8a66597-udc.hrenamed from drivers/usb/gadget/r8a66597-udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/s3c-hsudc.crenamed from drivers/usb/gadget/s3c-hsudc.c+0−0

File renamed without changes.

drivers/usb/gadget/udc/s3c2410_udc.crenamed from drivers/usb/gadget/s3c2410_udc.c+4−4
@@ -1788,7 +1788,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) · 1787 unmodified lines
17881788 return PTR_ERR(usb_bus_clock);
17891789 }
17901790
1791− clk_enable(usb_bus_clock);
1791+ clk_prepare_enable(usb_bus_clock);
17921792
17931793 udc_clock = clk_get(NULL, "usb-device");
17941794 if (IS_ERR(udc_clock)) {
@@ -1796,7 +1796,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev) · 1 unmodified line
17961796 return PTR_ERR(udc_clock);
17971797 }
17981798
1799− clk_enable(udc_clock);
1799+ clk_prepare_enable(udc_clock);
18001800
18011801 mdelay(10);
18021802
@@ -1952,13 +1952,13 @@ static int s3c2410_udc_remove(struct platform_device *pdev) · 149 unmodified lines
19521952 release_mem_region(rsrc_start, rsrc_len);
19531953
19541954 if (!IS_ERR(udc_clock) && udc_clock != NULL) {
1955− clk_disable(udc_clock);
1955+ clk_disable_unprepare(udc_clock);
19561956 clk_put(udc_clock);
19571957 udc_clock = NULL;
19581958 }
19591959
19601960 if (!IS_ERR(usb_bus_clock) && usb_bus_clock != NULL) {
1961− clk_disable(usb_bus_clock);
1961+ clk_disable_unprepare(usb_bus_clock);
19621962 clk_put(usb_bus_clock);
19631963 usb_bus_clock = NULL;
19641964 }
drivers/usb/gadget/udc/s3c2410_udc.hrenamed from drivers/usb/gadget/s3c2410_udc.h+0−0

File renamed without changes.

drivers/usb/gadget/udc/udc-core.crenamed from drivers/usb/gadget/udc-core.c+0−0

File renamed without changes.

drivers/usb/host/Kconfig+8−0
@@ -37,6 +37,14 @@ config USB_XHCI_MVEBU · 36 unmodified lines
3737 Say 'Y' to enable the support for the xHCI host controller
3838 found in Marvell Armada 375/38x ARM SOCs.
3939
40+config USB_XHCI_RCAR
41+ tristate "xHCI support for Renesas R-Car SoCs"
42+ select USB_XHCI_PLATFORM
43+ depends on ARCH_SHMOBILE || COMPILE_TEST
44+ ---help---
45+ Say 'Y' to enable the support for the xHCI host controller
46+ found in Renesas R-Car ARM SoCs.
47+
4048 endif # USB_XHCI_HCD
4149
4250 config USB_EHCI_HCD
drivers/usb/host/Makefile+3−0
@@ -22,6 +22,9 @@ ifneq ($(CONFIG_USB_XHCI_PLATFORM), ) · 21 unmodified lines
2222 ifneq ($(CONFIG_USB_XHCI_MVEBU), )
2323 xhci-hcd-y += xhci-mvebu.o
2424 endif
25+ifneq ($(CONFIG_USB_XHCI_RCAR), )
26+ xhci-hcd-y += xhci-rcar.o
27+endif
2528 endif
2629
2730 obj-$(CONFIG_USB_WHCI_HCD) += whci/
drivers/usb/host/ehci-exynos.c+1−1
@@ -88,7 +88,7 @@ static int exynos_ehci_get_phy(struct device *dev, · 87 unmodified lines
8888 return -EINVAL;
8989 }
9090
91− phy = devm_of_phy_get(dev, child, 0);
91+ phy = devm_of_phy_get(dev, child, NULL);
9292 of_node_put(child);
9393 if (IS_ERR(phy)) {
9494 ret = PTR_ERR(phy);
drivers/usb/host/ehci-mem.c+1−1
@@ -209,7 +209,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags) · 208 unmodified lines
209209 ehci->periodic = (__le32 *)
210210 dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller,
211211 ehci->periodic_size * sizeof(__le32),
212− &ehci->periodic_dma, 0);
212+ &ehci->periodic_dma, flags);
213213 if (ehci->periodic == NULL) {
214214 goto fail;
215215 }
drivers/usb/host/ehci-msm.c+1−1
@@ -190,7 +190,7 @@ static const struct dev_pm_ops ehci_msm_dev_pm_ops = { · 189 unmodified lines
190190 .resume = ehci_msm_pm_resume,
191191 };
192192
193−static struct of_device_id msm_ehci_dt_match[] = {
193+static const struct of_device_id msm_ehci_dt_match[] = {
194194 { .compatible = "qcom,ehci-host", },
195195 {}
196196 };
drivers/usb/host/ehci-pci.c+25−0
@@ -35,6 +35,21 @@ static const char hcd_name[] = "ehci-pci"; · 34 unmodified lines
3535 #define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70
3636
3737 /*-------------------------------------------------------------------------*/
38+#define PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC 0x0939
39+static inline bool is_intel_quark_x1000(struct pci_dev *pdev)
40+{
41+ return pdev->vendor == PCI_VENDOR_ID_INTEL &&
42+ pdev->device == PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC;
43+}
44+
45+/*
46+ * 0x84 is the offset of in/out threshold register,
47+ * and it is the same offset as the register of 'hostpc'.
48+ */
49+#define intel_quark_x1000_insnreg01 hostpc
50+
51+/* Maximum usable threshold value is 0x7f dwords for both IN and OUT */
52+#define INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD 0x007f007f
3853
3954 /* called after powerup, by probe or system-pm "wakeup" */
4055 static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
@@ -50,6 +65,16 @@ static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) · 9 unmodified lines
5065 if (!retval)
5166 ehci_dbg(ehci, "MWI active\n");
5267
68+ /* Reset the threshold limit */
69+ if (is_intel_quark_x1000(pdev)) {
70+ /*
71+ * For the Intel QUARK X1000, raise the I/O threshold to the
72+ * maximum usable value in order to improve performance.
73+ */
74+ ehci_writel(ehci, INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD,
75+ ehci->regs->intel_quark_x1000_insnreg01);
76+ }
77+
5378 return 0;
5479 }
5580
drivers/usb/host/ehci-spear.c+1−1
@@ -150,7 +150,7 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev) · 149 unmodified lines
150150 return 0;
151151 }
152152
153−static struct of_device_id spear_ehci_id_table[] = {
153+static const struct of_device_id spear_ehci_id_table[] = {
154154 { .compatible = "st,spear600-ehci", },
155155 { },
156156 };
drivers/usb/host/ehci-tegra.c+62−5
@@ -46,6 +46,7 @@ · 45 unmodified lines
4646 #define DRV_NAME "tegra-ehci"
4747
4848 static struct hc_driver __read_mostly tegra_ehci_hc_driver;
49+static bool usb1_reset_attempted;
4950
5051 struct tegra_ehci_soc_config {
5152 bool has_hostpc;
@@ -60,6 +61,61 @@ struct tegra_ehci_hcd { · 8 unmodified lines
6061 enum tegra_usb_phy_port_speed port_speed;
6162 };
6263
64+/*
65+ * The 1st USB controller contains some UTMI pad registers that are global for
66+ * all the controllers on the chip. Those registers are also cleared when
67+ * reset is asserted to the 1st controller. This means that the 1st controller
68+ * can only be reset when no other controlled has finished probing. So we'll
69+ * reset the 1st controller before doing any other setup on any of the
70+ * controllers, and then never again.
71+ *
72+ * Since this is a PHY issue, the Tegra PHY driver should probably be doing
73+ * the resetting of the USB controllers. But to keep compatibility with old
74+ * device trees that don't have reset phandles in the PHYs, do it here.
75+ * Those old DTs will be vulnerable to total USB breakage if the 1st EHCI
76+ * device isn't the first one to finish probing, so warn them.
77+ */
78+static int tegra_reset_usb_controller(struct platform_device *pdev)
79+{
80+ struct device_node *phy_np;
81+ struct usb_hcd *hcd = platform_get_drvdata(pdev);
82+ struct tegra_ehci_hcd *tegra =
83+ (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv;
84+
85+ phy_np = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0);
86+ if (!phy_np)
87+ return -ENOENT;
88+
89+ if (!usb1_reset_attempted) {
90+ struct reset_control *usb1_reset;
91+
92+ usb1_reset = of_reset_control_get(phy_np, "usb");
93+ if (IS_ERR(usb1_reset)) {
94+ dev_warn(&pdev->dev,
95+ "can't get utmi-pads reset from the PHY\n");
96+ dev_warn(&pdev->dev,
97+ "continuing, but please update your DT\n");
98+ } else {
99+ reset_control_assert(usb1_reset);
100+ udelay(1);
101+ reset_control_deassert(usb1_reset);
102+ }
103+
104+ reset_control_put(usb1_reset);
105+ usb1_reset_attempted = true;
106+ }
107+
108+ if (!of_property_read_bool(phy_np, "nvidia,has-utmi-pad-registers")) {
109+ reset_control_assert(tegra->rst);
110+ udelay(1);
111+ reset_control_deassert(tegra->rst);
112+ }
113+
114+ of_node_put(phy_np);
115+
116+ return 0;
117+}
118+
63119 static int tegra_ehci_internal_port_reset(
64120 struct ehci_hcd *ehci,
65121 u32 __iomem *portsc_reg
@@ -326,7 +382,7 @@ static const struct tegra_ehci_soc_config tegra20_soc_config = { · 260 unmodified lines
326382 .has_hostpc = false,
327383 };
328384
329−static struct of_device_id tegra_ehci_of_match[] = {
385+static const struct of_device_id tegra_ehci_of_match[] = {
330386 { .compatible = "nvidia,tegra30-ehci", .data = &tegra30_soc_config },
331387 { .compatible = "nvidia,tegra20-ehci", .data = &tegra20_soc_config },
332388 { },
@@ -389,9 +445,9 @@ static int tegra_ehci_probe(struct platform_device *pdev) · 56 unmodified lines
389445 if (err)
390446 goto cleanup_hcd_create;
391447
392− reset_control_assert(tegra->rst);
393− udelay(1);
394− reset_control_deassert(tegra->rst);
448+ err = tegra_reset_usb_controller(pdev);
449+ if (err)
450+ goto cleanup_clk_en;
395451
396452 u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
397453 if (IS_ERR(u_phy)) {
@@ -479,10 +535,11 @@ static int tegra_ehci_remove(struct platform_device *pdev) · 81 unmodified lines
479535
480536 usb_phy_shutdown(hcd->phy);
481537 usb_remove_hcd(hcd);
482− usb_put_hcd(hcd);
483538
484539 clk_disable_unprepare(tegra->clk);
485540
541+ usb_put_hcd(hcd);
542+
486543 return 0;
487544 }
488545
drivers/usb/host/fhci-dbg.c+2−6
@@ -129,11 +129,7 @@ void fhci_dfs_destroy(struct fhci_hcd *fhci) · 128 unmodified lines
129129 if (!fhci->dfs_root)
130130 return;
131131
132− if (fhci->dfs_irq_stat)
133− debugfs_remove(fhci->dfs_irq_stat);
134−
135− if (fhci->dfs_regs)
136− debugfs_remove(fhci->dfs_regs);
137−
132+ debugfs_remove(fhci->dfs_irq_stat);
133+ debugfs_remove(fhci->dfs_regs);
138134 debugfs_remove(fhci->dfs_root);
139135 }
drivers/usb/host/fotg210-hcd.c+9−39
@@ -5838,41 +5838,17 @@ static int fotg210_hcd_probe(struct platform_device *pdev) · 5837 unmodified lines
58385838 goto fail_create_hcd;
58395839 }
58405840
5841+ hcd->has_tt = 1;
5842+
58415843 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5842− if (!res) {
5843− dev_err(dev,
5844− "Found HC with no register addr. Check %s setup!\n",
5845− dev_name(dev));
5846− retval = -ENODEV;
5847− goto fail_request_resource;
5844+ hcd->regs = devm_ioremap_resource(&pdev->dev, res);
5845+ if (IS_ERR(hcd->regs)) {
5846+ retval = PTR_ERR(hcd->regs);
5847+ goto failed;
58485848 }
58495849
58505850 hcd->rsrc_start = res->start;
58515851 hcd->rsrc_len = resource_size(res);
5852− hcd->has_tt = 1;
5853−
5854− if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
5855− fotg210_fotg210_hc_driver.description)) {
5856− dev_dbg(dev, "controller already in use\n");
5857− retval = -EBUSY;
5858− goto fail_request_resource;
5859− }
5860−
5861− res = platform_get_resource(pdev, IORESOURCE_IO, 0);
5862− if (!res) {
5863− dev_err(dev,
5864− "Found HC with no register addr. Check %s setup!\n",
5865− dev_name(dev));
5866− retval = -ENODEV;
5867− goto fail_request_resource;
5868− }
5869−
5870− hcd->regs = ioremap_nocache(res->start, resource_size(res));
5871− if (hcd->regs == NULL) {
5872− dev_dbg(dev, "error mapping memory\n");
5873− retval = -EFAULT;
5874− goto fail_ioremap;
5875− }
58765852
58775853 fotg210 = hcd_to_fotg210(hcd);
58785854
@@ -5880,24 +5856,20 @@ static int fotg210_hcd_probe(struct platform_device *pdev) · 1 unmodified line
58805856
58815857 retval = fotg210_setup(hcd);
58825858 if (retval)
5883− goto fail_add_hcd;
5859+ goto failed;
58845860
58855861 fotg210_init(fotg210);
58865862
58875863 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
58885864 if (retval) {
58895865 dev_err(dev, "failed to add hcd with err %d\n", retval);
5890− goto fail_add_hcd;
5866+ goto failed;
58915867 }
58925868 device_wakeup_enable(hcd->self.controller);
58935869
58945870 return retval;
58955871
5896−fail_add_hcd:
5897− iounmap(hcd->regs);
5898−fail_ioremap:
5899− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
5900−fail_request_resource:
5872+failed:
59015873 usb_put_hcd(hcd);
59025874 fail_create_hcd:
59035875 dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval);
@@ -5918,8 +5890,6 @@ static int fotg210_hcd_remove(struct platform_device *pdev) · 14 unmodified lines
59185890 return 0;
59195891
59205892 usb_remove_hcd(hcd);
5921− iounmap(hcd->regs);
5922− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
59235893 usb_put_hcd(hcd);
59245894
59255895 return 0;
drivers/usb/host/max3421-hcd.c+22−26
@@ -102,6 +102,15 @@ enum scheduling_pass { · 101 unmodified lines
102102 SCHED_PASS_DONE
103103 };
104104
105+/* Bit numbers for max3421_hcd->todo: */
106+enum {
107+ ENABLE_IRQ = 0,
108+ RESET_HCD,
109+ RESET_PORT,
110+ CHECK_UNLINK,
111+ IOPIN_UPDATE
112+};
113+
105114 struct max3421_dma_buf {
106115 u8 data[2];
107116 };
@@ -146,11 +155,7 @@ struct max3421_hcd { · 38 unmodified lines
146155 u8 hien;
147156 u8 mode;
148157 u8 iopins[2];
149− unsigned int do_enable_irq:1;
150− unsigned int do_reset_hcd:1;
151− unsigned int do_reset_port:1;
152− unsigned int do_check_unlink:1;
153− unsigned int do_iopin_update:1;
158+ unsigned long todo;
154159 #ifdef DEBUG
155160 unsigned long err_stat[16];
156161 #endif
@@ -1165,10 +1170,8 @@ max3421_irq_handler(int irq, void *dev_id) · 1008 unmodified lines
11651170 if (max3421_hcd->spi_thread &&
11661171 max3421_hcd->spi_thread->state != TASK_RUNNING)
11671172 wake_up_process(max3421_hcd->spi_thread);
1168− if (!max3421_hcd->do_enable_irq) {
1169− max3421_hcd->do_enable_irq = 1;
1173+ if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo))
11701174 disable_irq_nosync(spi->irq);
1171− }
11721175 return IRQ_HANDLED;
11731176 }
11741177
@@ -1423,10 +1426,8 @@ max3421_spi_thread(void *dev_id) · 248 unmodified lines
14231426 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien);
14241427
14251428 set_current_state(TASK_INTERRUPTIBLE);
1426− if (max3421_hcd->do_enable_irq) {
1427− max3421_hcd->do_enable_irq = 0;
1429+ if (test_and_clear_bit(ENABLE_IRQ, &max3421_hcd->todo))
14281430 enable_irq(spi->irq);
1429− }
14301431 schedule();
14311432 __set_current_state(TASK_RUNNING);
14321433 }
@@ -1440,23 +1441,18 @@ max3421_spi_thread(void *dev_id) · 7 unmodified lines
14401441 else if (!max3421_hcd->curr_urb)
14411442 i_worked |= max3421_select_and_start_urb(hcd);
14421443
1443− if (max3421_hcd->do_reset_hcd) {
1444+ if (test_and_clear_bit(RESET_HCD, &max3421_hcd->todo))
14441445 /* reset the HCD: */
1445− max3421_hcd->do_reset_hcd = 0;
14461446 i_worked |= max3421_reset_hcd(hcd);
1447− }
1448− if (max3421_hcd->do_reset_port) {
1447+ if (test_and_clear_bit(RESET_PORT, &max3421_hcd->todo)) {
14491448 /* perform a USB bus reset: */
1450− max3421_hcd->do_reset_port = 0;
14511449 spi_wr8(hcd, MAX3421_REG_HCTL,
14521450 BIT(MAX3421_HCTL_BUSRST_BIT));
14531451 i_worked = 1;
14541452 }
1455− if (max3421_hcd->do_check_unlink) {
1456− max3421_hcd->do_check_unlink = 0;
1453+ if (test_and_clear_bit(CHECK_UNLINK, &max3421_hcd->todo))
14571454 i_worked |= max3421_check_unlink(hcd);
1458− }
1459− if (max3421_hcd->do_iopin_update) {
1455+ if (test_and_clear_bit(IOPIN_UPDATE, &max3421_hcd->todo)) {
14601456 /*
14611457 * IOPINS1/IOPINS2 do not auto-increment, so we can't
14621458 * use spi_wr_buf().
@@ -1469,7 +1465,6 @@ max3421_spi_thread(void *dev_id) · 6 unmodified lines
14691465 spi_wr8(hcd, MAX3421_REG_IOPINS1 + i, val);
14701466 max3421_hcd->iopins[i] = val;
14711467 }
1472− max3421_hcd->do_iopin_update = 0;
14731468 i_worked = 1;
14741469 }
14751470 }
@@ -1485,7 +1480,8 @@ max3421_reset_port(struct usb_hcd *hcd) · 9 unmodified lines
14851480
14861481 max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE |
14871482 USB_PORT_STAT_LOW_SPEED);
1488− max3421_hcd->do_reset_port = 1;
1483+ max3421_hcd->port_status |= USB_PORT_STAT_RESET;
1484+ set_bit(RESET_PORT, &max3421_hcd->todo);
14891485 wake_up_process(max3421_hcd->spi_thread);
14901486 return 0;
14911487 }
@@ -1498,7 +1494,7 @@ max3421_reset(struct usb_hcd *hcd) · 6 unmodified lines
14981494 hcd->self.sg_tablesize = 0;
14991495 hcd->speed = HCD_USB2;
15001496 hcd->self.root_hub->speed = USB_SPEED_FULL;
1501− max3421_hcd->do_reset_hcd = 1;
1497+ set_bit(RESET_HCD, &max3421_hcd->todo);
15021498 wake_up_process(max3421_hcd->spi_thread);
15031499 return 0;
15041500 }
@@ -1551,7 +1547,7 @@ max3421_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) · 46 unmodified lines
15511547 max3421_ep = urb->ep->hcpriv;
15521548 if (!max3421_ep) {
15531549 /* gets freed in max3421_endpoint_disable: */
1554− max3421_ep = kzalloc(sizeof(struct max3421_ep), mem_flags);
1550+ max3421_ep = kzalloc(sizeof(struct max3421_ep), GFP_ATOMIC);
15551551 if (!max3421_ep) {
15561552 retval = -ENOMEM;
15571553 goto out;
@@ -1590,7 +1586,7 @@ max3421_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) · 32 unmodified lines
15901586 */
15911587 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
15921588 if (retval == 0) {
1593− max3421_hcd->do_check_unlink = 1;
1589+ set_bit(CHECK_UNLINK, &max3421_hcd->todo);
15941590 wake_up_process(max3421_hcd->spi_thread);
15951591 }
15961592 spin_unlock_irqrestore(&max3421_hcd->lock, flags);
@@ -1690,7 +1686,7 @@ max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value) · 93 unmodified lines
16901686 max3421_hcd->iopins[idx] |= mask;
16911687 else
16921688 max3421_hcd->iopins[idx] &= ~mask;
1693− max3421_hcd->do_iopin_update = 1;
1689+ set_bit(IOPIN_UPDATE, &max3421_hcd->todo);
16941690 wake_up_process(max3421_hcd->spi_thread);
16951691 }
16961692
drivers/usb/host/ohci-dbg.c+5−4
@@ -236,7 +236,7 @@ ohci_dump_roothub ( · 235 unmodified lines
236236 }
237237 }
238238
239−static void ohci_dump (struct ohci_hcd *controller, int verbose)
239+static void ohci_dump(struct ohci_hcd *controller)
240240 {
241241 ohci_dbg (controller, "OHCI controller state\n");
242242
@@ -464,15 +464,16 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) · 221 unmodified lines
464464 static ssize_t fill_async_buffer(struct debug_buffer *buf)
465465 {
466466 struct ohci_hcd *ohci;
467− size_t temp;
467+ size_t temp, size;
468468 unsigned long flags;
469469
470470 ohci = buf->ohci;
471+ size = PAGE_SIZE;
471472
472473 /* display control and bulk lists together, for simplicity */
473474 spin_lock_irqsave (&ohci->lock, flags);
474− temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail);
475− temp += show_list(ohci, buf->page + temp, buf->count - temp,
475+ temp = show_list(ohci, buf->page, size, ohci->ed_controltail);
476+ temp += show_list(ohci, buf->page + temp, size - temp,
476477 ohci->ed_bulktail);
477478 spin_unlock_irqrestore (&ohci->lock, flags);
478479
drivers/usb/host/ohci-exynos.c+1−1
@@ -87,7 +87,7 @@ static int exynos_ohci_get_phy(struct device *dev, · 86 unmodified lines
8787 return -EINVAL;
8888 }
8989
90− phy = devm_of_phy_get(dev, child, 0);
90+ phy = devm_of_phy_get(dev, child, NULL);
9191 of_node_put(child);
9292 if (IS_ERR(phy)) {
9393 ret = PTR_ERR(phy);
drivers/usb/host/ohci-hcd.c+211−170
@@ -72,12 +72,14 @@ · 71 unmodified lines
7272 static const char hcd_name [] = "ohci_hcd";
7373
7474 #define STATECHANGE_DELAY msecs_to_jiffies(300)
75+#define IO_WATCHDOG_DELAY msecs_to_jiffies(250)
7576
7677 #include "ohci.h"
7778 #include "pci-quirks.h"
7879
79−static void ohci_dump (struct ohci_hcd *ohci, int verbose);
80−static void ohci_stop (struct usb_hcd *hcd);
80+static void ohci_dump(struct ohci_hcd *ohci);
81+static void ohci_stop(struct usb_hcd *hcd);
82+static void io_watchdog_func(unsigned long _ohci);
8183
8284 #include "ohci-hub.c"
8385 #include "ohci-dbg.c"
@@ -109,6 +111,33 @@ MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake"); · 25 unmodified lines
109111
110112 /*-------------------------------------------------------------------------*/
111113
114+static int number_of_tds(struct urb *urb)
115+{
116+ int len, i, num, this_sg_len;
117+ struct scatterlist *sg;
118+
119+ len = urb->transfer_buffer_length;
120+ i = urb->num_mapped_sgs;
121+
122+ if (len > 0 && i > 0) { /* Scatter-gather transfer */
123+ num = 0;
124+ sg = urb->sg;
125+ for (;;) {
126+ this_sg_len = min_t(int, sg_dma_len(sg), len);
127+ num += DIV_ROUND_UP(this_sg_len, 4096);
128+ len -= this_sg_len;
129+ if (--i <= 0 || len <= 0)
130+ break;
131+ sg = sg_next(sg);
132+ }
133+
134+ } else { /* Non-SG transfer */
135+ /* one TD for every 4096 Bytes (could be up to 8K) */
136+ num = DIV_ROUND_UP(len, 4096);
137+ }
138+ return num;
139+}
140+
112141 /*
113142 * queue up an urb for anything except the root hub
114143 */
@@ -142,12 +171,8 @@ static int ohci_urb_enqueue ( · 27 unmodified lines
142171 // case PIPE_INTERRUPT:
143172 // case PIPE_BULK:
144173 default:
145− /* one TD for every 4096 Bytes (can be up to 8K) */
146− size += urb->transfer_buffer_length / 4096;
147− /* ... and for any remaining bytes ... */
148− if ((urb->transfer_buffer_length % 4096) != 0)
149− size++;
150− /* ... and maybe a zero length packet to wrap it up */
174+ size += number_of_tds(urb);
175+ /* maybe a zero-length packet to wrap it up */
151176 if (size == 0)
152177 size++;
153178 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
@@ -202,6 +227,16 @@ static int ohci_urb_enqueue ( · 48 unmodified lines
202227 usb_hcd_unlink_urb_from_ep(hcd, urb);
203228 goto fail;
204229 }
230+
231+ /* Start up the I/O watchdog timer, if it's not running */
232+ if (!timer_pending(&ohci->io_watchdog) &&
233+ list_empty(&ohci->eds_in_use)) {
234+ ohci->prev_frame_no = ohci_frame_no(ohci);
235+ mod_timer(&ohci->io_watchdog,
236+ jiffies + IO_WATCHDOG_DELAY);
237+ }
238+ list_add(&ed->in_use_list, &ohci->eds_in_use);
239+
205240 if (ed->type == PIPE_ISOCHRONOUS) {
206241 u16 frame = ohci_frame_no(ohci);
207242
@@ -277,30 +312,24 @@ static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) · 69 unmodified lines
277312 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
278313 unsigned long flags;
279314 int rc;
315+ urb_priv_t *urb_priv;
280316
281317 spin_lock_irqsave (&ohci->lock, flags);
282318 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
283− if (rc) {
284− ; /* Do nothing */
285− } else if (ohci->rh_state == OHCI_RH_RUNNING) {
286− urb_priv_t *urb_priv;
319+ if (rc == 0) {
287320
288321 /* Unless an IRQ completed the unlink while it was being
289322 * handed to us, flag it for unlink and giveback, and force
290323 * some upcoming INTR_SF to call finish_unlinks()
291324 */
292325 urb_priv = urb->hcpriv;
293− if (urb_priv) {
294− if (urb_priv->ed->state == ED_OPER)
295− start_ed_unlink (ohci, urb_priv->ed);
326+ if (urb_priv->ed->state == ED_OPER)
327+ start_ed_unlink(ohci, urb_priv->ed);
328+
329+ if (ohci->rh_state != OHCI_RH_RUNNING) {
330+ /* With HC dead, we can clean up right away */
331+ ohci_work(ohci);
296332 }
297− } else {
298− /*
299− * with HC dead, we won't respect hc queue pointers
300− * any more ... just clean up every urb's memory.
301− */
302− if (urb->hcpriv)
303− finish_urb(ohci, urb, status);
304333 }
305334 spin_unlock_irqrestore (&ohci->lock, flags);
306335 return rc;
@@ -332,9 +361,7 @@ rescan: · 25 unmodified lines
332361 if (ohci->rh_state != OHCI_RH_RUNNING) {
333362 sanitize:
334363 ed->state = ED_IDLE;
335− if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
336− ohci->eds_scheduled--;
337− finish_unlinks (ohci, 0);
364+ ohci_work(ohci);
338365 }
339366
340367 switch (ed->state) {
@@ -342,11 +369,6 @@ sanitize: · 1 unmodified line
342369 /* major IRQ delivery trouble loses INTR_SF too... */
343370 if (limit-- == 0) {
344371 ohci_warn(ohci, "ED unlink timeout\n");
345− if (quirk_zfmicro(ohci)) {
346− ohci_warn(ohci, "Attempting ZF TD recovery\n");
347− ohci->ed_to_check = ed;
348− ohci->zf_delay = 2;
349− }
350372 goto sanitize;
351373 }
352374 spin_unlock_irqrestore (&ohci->lock, flags);
@@ -406,93 +428,7 @@ ohci_shutdown (struct usb_hcd *hcd) · 53 unmodified lines
406428 udelay(10);
407429
408430 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
409−}
410−
411−static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
412−{
413− return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
414− && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
415− == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
416− && !list_empty(&ed->td_list);
417−}
418−
419−/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
420− * an interrupt TD but neglects to add it to the donelist. On systems with
421− * this chipset, we need to periodically check the state of the queues to look
422− * for such "lost" TDs.
423− */
424−static void unlink_watchdog_func(unsigned long _ohci)
425−{
426− unsigned long flags;
427− unsigned max;
428− unsigned seen_count = 0;
429− unsigned i;
430− struct ed **seen = NULL;
431− struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
432−
433− spin_lock_irqsave(&ohci->lock, flags);
434− max = ohci->eds_scheduled;
435− if (!max)
436− goto done;
437−
438− if (ohci->ed_to_check)
439− goto out;
440−
441− seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
442− if (!seen)
443− goto out;
444−
445− for (i = 0; i < NUM_INTS; i++) {
446− struct ed *ed = ohci->periodic[i];
447−
448− while (ed) {
449− unsigned temp;
450−
451− /* scan this branch of the periodic schedule tree */
452− for (temp = 0; temp < seen_count; temp++) {
453− if (seen[temp] == ed) {
454− /* we've checked it and what's after */
455− ed = NULL;
456− break;
457− }
458− }
459− if (!ed)
460− break;
461− seen[seen_count++] = ed;
462− if (!check_ed(ohci, ed)) {
463− ed = ed->ed_next;
464− continue;
465− }
466−
467− /* HC's TD list is empty, but HCD sees at least one
468− * TD that's not been sent through the donelist.
469− */
470− ohci->ed_to_check = ed;
471− ohci->zf_delay = 2;
472−
473− /* The HC may wait until the next frame to report the
474− * TD as done through the donelist and INTR_WDH. (We
475− * just *assume* it's not a multi-TD interrupt URB;
476− * those could defer the IRQ more than one frame, using
477− * DI...) Check again after the next INTR_SF.
478− */
479− ohci_writel(ohci, OHCI_INTR_SF,
480− &ohci->regs->intrstatus);
481− ohci_writel(ohci, OHCI_INTR_SF,
482− &ohci->regs->intrenable);
483−
484− /* flush those writes */
485− (void) ohci_readl(ohci, &ohci->regs->control);
486−
487− goto out;
488− }
489− }
490−out:
491− kfree(seen);
492− if (ohci->eds_scheduled)
493− mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
494−done:
495− spin_unlock_irqrestore(&ohci->lock, flags);
431+ ohci->rh_state = OHCI_RH_HALTED;
496432 }
497433
498434 /*-------------------------------------------------------------------------*
@@ -506,6 +442,9 @@ static int ohci_init (struct ohci_hcd *ohci) · 7 unmodified lines
506442 int ret;
507443 struct usb_hcd *hcd = ohci_to_hcd(ohci);
508444
445+ /* Accept arbitrarily long scatter-gather lists */
446+ hcd->self.sg_tablesize = ~0;
447+
509448 if (distrust_firmware)
510449 ohci->flags |= OHCI_QUIRK_HUB_POWER;
511450
@@ -558,8 +497,12 @@ static int ohci_init (struct ohci_hcd *ohci) · 46 unmodified lines
558497 if (ohci->hcca)
559498 return 0;
560499
500+ setup_timer(&ohci->io_watchdog, io_watchdog_func,
501+ (unsigned long) ohci);
502+ set_timer_slack(&ohci->io_watchdog, msecs_to_jiffies(20));
503+
561504 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
562− sizeof *ohci->hcca, &ohci->hcca_dma, 0);
505+ sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
563506 if (!ohci->hcca)
564507 return -ENOMEM;
565508
@@ -735,16 +678,7 @@ retry: · 169 unmodified lines
735678 // POTPGT delay is bits 24-31, in 2 ms units.
736679 mdelay ((val >> 23) & 0x1fe);
737680
738− if (quirk_zfmicro(ohci)) {
739− /* Create timer to watch for bad queue state on ZF Micro */
740− setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
741− (unsigned long) ohci);
742−
743− ohci->eds_scheduled = 0;
744− ohci->ed_to_check = NULL;
745− }
746−
747− ohci_dump (ohci, 1);
681+ ohci_dump(ohci);
748682
749683 return 0;
750684 }
@@ -777,6 +711,142 @@ static int ohci_start(struct usb_hcd *hcd) · 26 unmodified lines
777711
778712 /*-------------------------------------------------------------------------*/
779713
714+/*
715+ * Some OHCI controllers are known to lose track of completed TDs. They
716+ * don't add the TDs to the hardware done queue, which means we never see
717+ * them as being completed.
718+ *
719+ * This watchdog routine checks for such problems. Without some way to
720+ * tell when those TDs have completed, we would never take their EDs off
721+ * the unlink list. As a result, URBs could never be dequeued and
722+ * endpoints could never be released.
723+ */
724+static void io_watchdog_func(unsigned long _ohci)
725+{
726+ struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
727+ bool takeback_all_pending = false;
728+ u32 status;
729+ u32 head;
730+ struct ed *ed;
731+ struct td *td, *td_start, *td_next;
732+ unsigned frame_no;
733+ unsigned long flags;
734+
735+ spin_lock_irqsave(&ohci->lock, flags);
736+
737+ /*
738+ * One way to lose track of completed TDs is if the controller
739+ * never writes back the done queue head. If it hasn't been
740+ * written back since the last time this function ran and if it
741+ * was non-empty at that time, something is badly wrong with the
742+ * hardware.
743+ */
744+ status = ohci_readl(ohci, &ohci->regs->intrstatus);
745+ if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) {
746+ if (ohci->prev_donehead) {
747+ ohci_err(ohci, "HcDoneHead not written back; disabled\n");
748+ died:
749+ usb_hc_died(ohci_to_hcd(ohci));
750+ ohci_dump(ohci);
751+ ohci_shutdown(ohci_to_hcd(ohci));
752+ goto done;
753+ } else {
754+ /* No write back because the done queue was empty */
755+ takeback_all_pending = true;
756+ }
757+ }
758+
759+ /* Check every ED which might have pending TDs */
760+ list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) {
761+ if (ed->pending_td) {
762+ if (takeback_all_pending ||
763+ OKAY_TO_TAKEBACK(ohci, ed)) {
764+ unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO);
765+
766+ ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n",
767+ 0x007f & tmp,
768+ (0x000f & (tmp >> 7)) +
769+ ((tmp & ED_IN) >> 5));
770+ add_to_done_list(ohci, ed->pending_td);
771+ }
772+ }
773+
774+ /* Starting from the latest pending TD, */
775+ td = ed->pending_td;
776+
777+ /* or the last TD on the done list, */
778+ if (!td) {
779+ list_for_each_entry(td_next, &ed->td_list, td_list) {
780+ if (!td_next->next_dl_td)
781+ break;
782+ td = td_next;
783+ }
784+ }
785+
786+ /* find the last TD processed by the controller. */
787+ head = hc32_to_cpu(ohci, ACCESS_ONCE(ed->hwHeadP)) & TD_MASK;
788+ td_start = td;
789+ td_next = list_prepare_entry(td, &ed->td_list, td_list);
790+ list_for_each_entry_continue(td_next, &ed->td_list, td_list) {
791+ if (head == (u32) td_next->td_dma)
792+ break;
793+ td = td_next; /* head pointer has passed this TD */
794+ }
795+ if (td != td_start) {
796+ /*
797+ * In case a WDH cycle is in progress, we will wait
798+ * for the next two cycles to complete before assuming
799+ * this TD will never get on the done queue.
800+ */
801+ ed->takeback_wdh_cnt = ohci->wdh_cnt + 2;
802+ ed->pending_td = td;
803+ }
804+ }
805+
806+ ohci_work(ohci);
807+
808+ if (ohci->rh_state == OHCI_RH_RUNNING) {
809+
810+ /*
811+ * Sometimes a controller just stops working. We can tell
812+ * by checking that the frame counter has advanced since
813+ * the last time we ran.
814+ *
815+ * But be careful: Some controllers violate the spec by
816+ * stopping their frame counter when no ports are active.
817+ */
818+ frame_no = ohci_frame_no(ohci);
819+ if (frame_no == ohci->prev_frame_no) {
820+ int active_cnt = 0;
821+ int i;
822+ unsigned tmp;
823+
824+ for (i = 0; i < ohci->num_ports; ++i) {
825+ tmp = roothub_portstatus(ohci, i);
826+ /* Enabled and not suspended? */
827+ if ((tmp & RH_PS_PES) && !(tmp & RH_PS_PSS))
828+ ++active_cnt;
829+ }
830+
831+ if (active_cnt > 0) {
832+ ohci_err(ohci, "frame counter not updating; disabled\n");
833+ goto died;
834+ }
835+ }
836+ if (!list_empty(&ohci->eds_in_use)) {
837+ ohci->prev_frame_no = frame_no;
838+ ohci->prev_wdh_cnt = ohci->wdh_cnt;
839+ ohci->prev_donehead = ohci_readl(ohci,
840+ &ohci->regs->donehead);
841+ mod_timer(&ohci->io_watchdog,
842+ jiffies + IO_WATCHDOG_DELAY);
843+ }
844+ }
845+
846+ done:
847+ spin_unlock_irqrestore(&ohci->lock, flags);
848+}
849+
780850 /* an interrupt happens */
781851
782852 static irqreturn_t ohci_irq (struct usb_hcd *hcd)
@@ -825,7 +895,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) · 42 unmodified lines
825895 usb_hc_died(hcd);
826896 }
827897
828− ohci_dump (ohci, 1);
898+ ohci_dump(ohci);
829899 ohci_usb_reset (ohci);
830900 }
831901
@@ -863,58 +933,30 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) · 31 unmodified lines
863933 usb_hcd_resume_root_hub(hcd);
864934 }
865935
866− if (ints & OHCI_INTR_WDH) {
867− spin_lock (&ohci->lock);
868− dl_done_list (ohci);
869− spin_unlock (&ohci->lock);
870− }
871−
872− if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
873− spin_lock(&ohci->lock);
874− if (ohci->ed_to_check) {
875− struct ed *ed = ohci->ed_to_check;
876−
877− if (check_ed(ohci, ed)) {
878− /* HC thinks the TD list is empty; HCD knows
879− * at least one TD is outstanding
880− */
881− if (--ohci->zf_delay == 0) {
882− struct td *td = list_entry(
883− ed->td_list.next,
884− struct td, td_list);
885− ohci_warn(ohci,
886− "Reclaiming orphan TD %p\n",
887− td);
888− takeback_td(ohci, td);
889− ohci->ed_to_check = NULL;
890− }
891− } else
892− ohci->ed_to_check = NULL;
893− }
894− spin_unlock(&ohci->lock);
895− }
936+ spin_lock(&ohci->lock);
937+ if (ints & OHCI_INTR_WDH)
938+ update_done_list(ohci);
896939
897940 /* could track INTR_SO to reduce available PCI/... bandwidth */
898941
899942 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
900943 * when there's still unlinking to be done (next frame).
901944 */
902− spin_lock (&ohci->lock);
903− if (ohci->ed_rm_list)
904− finish_unlinks (ohci, ohci_frame_no(ohci));
905− if ((ints & OHCI_INTR_SF) != 0
906− && !ohci->ed_rm_list
907− && !ohci->ed_to_check
945+ ohci_work(ohci);
946+ if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
908947 && ohci->rh_state == OHCI_RH_RUNNING)
909948 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
910− spin_unlock (&ohci->lock);
911949
912950 if (ohci->rh_state == OHCI_RH_RUNNING) {
913951 ohci_writel (ohci, ints, &regs->intrstatus);
952+ if (ints & OHCI_INTR_WDH)
953+ ++ohci->wdh_cnt;
954+
914955 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
915956 // flush those writes
916957 (void) ohci_readl (ohci, &ohci->regs->control);
917958 }
959+ spin_unlock(&ohci->lock);
918960
919961 return IRQ_HANDLED;
920962 }
@@ -925,18 +967,17 @@ static void ohci_stop (struct usb_hcd *hcd) · 4 unmodified lines
925967 {
926968 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
927969
928− ohci_dump (ohci, 1);
970+ ohci_dump(ohci);
929971
930972 if (quirk_nec(ohci))
931973 flush_work(&ohci->nec_work);
974+ del_timer_sync(&ohci->io_watchdog);
932975
933976 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
934977 ohci_usb_reset(ohci);
935978 free_irq(hcd->irq, hcd);
936979 hcd->irq = 0;
937980
938− if (quirk_zfmicro(ohci))
939− del_timer(&ohci->unlink_watchdog);
940981 if (quirk_amdiso(ohci))
941982 usb_amd_dev_put();
942983
@@ -993,7 +1034,7 @@ int ohci_restart(struct ohci_hcd *ohci) · 50 unmodified lines
9931034 if (!urb->unlinked)
9941035 urb->unlinked = -ESHUTDOWN;
9951036 }
996− finish_unlinks (ohci, 0);
1037+ ohci_work(ohci);
9971038 spin_unlock_irq(&ohci->lock);
9981039
9991040 /* paranoia, in case that didn't work: */
drivers/usb/host/ohci-hub.c+7−4
@@ -39,8 +39,8 @@ · 38 unmodified lines
3939 #define OHCI_SCHED_ENABLES \
4040 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
4141
42−static void dl_done_list (struct ohci_hcd *);
43−static void finish_unlinks (struct ohci_hcd *, u16);
42+static void update_done_list(struct ohci_hcd *);
43+static void ohci_work(struct ohci_hcd *);
4444
4545 #ifdef CONFIG_PM
4646 static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop)
@@ -87,8 +87,8 @@ __acquires(ohci->lock) · 40 unmodified lines
8787 msleep (8);
8888 spin_lock_irq (&ohci->lock);
8989 }
90− dl_done_list (ohci);
91− finish_unlinks (ohci, ohci_frame_no(ohci));
90+ update_done_list(ohci);
91+ ohci_work(ohci);
9292
9393 /*
9494 * Some controllers don't handle "global" suspend properly if
@@ -309,6 +309,9 @@ static int ohci_bus_suspend (struct usb_hcd *hcd) · 214 unmodified lines
309309 else
310310 rc = ohci_rh_suspend (ohci, 0);
311311 spin_unlock_irq (&ohci->lock);
312+
313+ if (rc == 0)
314+ del_timer_sync(&ohci->io_watchdog);
312315 return rc;
313316 }
314317
drivers/usb/host/ohci-mem.c+1−0
@@ -28,6 +28,7 @@ static void ohci_hcd_init (struct ohci_hcd *ohci) · 27 unmodified lines
2828 ohci->next_statechange = jiffies;
2929 spin_lock_init (&ohci->lock);
3030 INIT_LIST_HEAD (&ohci->pending);
31+ INIT_LIST_HEAD(&ohci->eds_in_use);
3132 }
3233
3334 /*-------------------------------------------------------------------------*/
drivers/usb/host/ohci-q.c+163−99
@@ -187,10 +187,6 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed) · 186 unmodified lines
187187 ed->ed_prev = NULL;
188188 ed->ed_next = NULL;
189189 ed->hwNextED = 0;
190− if (quirk_zfmicro(ohci)
191− && (ed->type == PIPE_INTERRUPT)
192− && !(ohci->eds_scheduled++))
193− mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
194190 wmb ();
195191
196192 /* we care about rm_list when setting CLE/BLE in case the HC was at
@@ -311,8 +307,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed) · 114 unmodified lines
311307 * - ED_OPER: when there's any request queued, the ED gets rescheduled
312308 * immediately. HC should be working on them.
313309 *
314− * - ED_IDLE: when there's no TD queue. there's no reason for the HC
315− * to care about this ED; safe to disable the endpoint.
310+ * - ED_IDLE: when there's no TD queue or the HC isn't running.
316311 *
317312 * When finish_unlinks() runs later, after SOF interrupt, it will often
318313 * complete one or more URB unlinks before making that state change.
@@ -602,6 +597,8 @@ static void td_submit_urb ( · 283 unmodified lines
602597 u32 info = 0;
603598 int is_out = usb_pipeout (urb->pipe);
604599 int periodic = 0;
600+ int i, this_sg_len, n;
601+ struct scatterlist *sg;
605602
606603 /* OHCI handles the bulk/interrupt data toggles itself. We just
607604 * use the device toggle bits for resetting, and rely on the fact
@@ -615,10 +612,24 @@ static void td_submit_urb ( · 7 unmodified lines
615612
616613 list_add (&urb_priv->pending, &ohci->pending);
617614
618− if (data_len)
619− data = urb->transfer_dma;
620− else
621− data = 0;
615+ i = urb->num_mapped_sgs;
616+ if (data_len > 0 && i > 0) {
617+ sg = urb->sg;
618+ data = sg_dma_address(sg);
619+
620+ /*
621+ * urb->transfer_buffer_length may be smaller than the
622+ * size of the scatterlist (or vice versa)
623+ */
624+ this_sg_len = min_t(int, sg_dma_len(sg), data_len);
625+ } else {
626+ sg = NULL;
627+ if (data_len)
628+ data = urb->transfer_dma;
629+ else
630+ data = 0;
631+ this_sg_len = data_len;
632+ }
622633
623634 /* NOTE: TD_CC is set so we can tell which TDs the HC processed by
624635 * using TD_CC_GET, as well as by seeing them on the done list.
@@ -639,17 +650,29 @@ static void td_submit_urb ( · 14 unmodified lines
639650 ? TD_T_TOGGLE | TD_CC | TD_DP_OUT
640651 : TD_T_TOGGLE | TD_CC | TD_DP_IN;
641652 /* TDs _could_ transfer up to 8K each */
642− while (data_len > 4096) {
643− td_fill (ohci, info, data, 4096, urb, cnt);
644− data += 4096;
645− data_len -= 4096;
653+ for (;;) {
654+ n = min(this_sg_len, 4096);
655+
656+ /* maybe avoid ED halt on final TD short read */
657+ if (n >= data_len || (i == 1 && n >= this_sg_len)) {
658+ if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
659+ info |= TD_R;
660+ }
661+ td_fill(ohci, info, data, n, urb, cnt);
662+ this_sg_len -= n;
663+ data_len -= n;
664+ data += n;
646665 cnt++;
666+
667+ if (this_sg_len <= 0) {
668+ if (--i <= 0 || data_len <= 0)
669+ break;
670+ sg = sg_next(sg);
671+ data = sg_dma_address(sg);
672+ this_sg_len = min_t(int, sg_dma_len(sg),
673+ data_len);
674+ }
647675 }
648− /* maybe avoid ED halt on final TD short read */
649− if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
650− info |= TD_R;
651− td_fill (ohci, info, data, data_len, urb, cnt);
652− cnt++;
653676 if ((urb->transfer_flags & URB_ZERO_PACKET)
654677 && cnt < urb_priv->length) {
655678 td_fill (ohci, info, 0, 0, urb, cnt);
@@ -869,13 +892,46 @@ static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc) · 213 unmodified lines
869892 }
870893 }
871894
872−/* replies to the request have to be on a FIFO basis so
873− * we unreverse the hc-reversed done-list
874− */
875−static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
895+/* Add a TD to the done list */
896+static void add_to_done_list(struct ohci_hcd *ohci, struct td *td)
897+{
898+ struct td *td2, *td_prev;
899+ struct ed *ed;
900+
901+ if (td->next_dl_td)
902+ return; /* Already on the list */
903+
904+ /* Add all the TDs going back until we reach one that's on the list */
905+ ed = td->ed;
906+ td2 = td_prev = td;
907+ list_for_each_entry_continue_reverse(td2, &ed->td_list, td_list) {
908+ if (td2->next_dl_td)
909+ break;
910+ td2->next_dl_td = td_prev;
911+ td_prev = td2;
912+ }
913+
914+ if (ohci->dl_end)
915+ ohci->dl_end->next_dl_td = td_prev;
916+ else
917+ ohci->dl_start = td_prev;
918+
919+ /*
920+ * Make td->next_dl_td point to td itself, to mark the fact
921+ * that td is on the done list.
922+ */
923+ ohci->dl_end = td->next_dl_td = td;
924+
925+ /* Did we just add the latest pending TD? */
926+ td2 = ed->pending_td;
927+ if (td2 && td2->next_dl_td)
928+ ed->pending_td = NULL;
929+}
930+
931+/* Get the entries on the hardware done queue and put them on our list */
932+static void update_done_list(struct ohci_hcd *ohci)
876933 {
877934 u32 td_dma;
878− struct td *td_rev = NULL;
879935 struct td *td = NULL;
880936
881937 td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head);
@@ -883,7 +939,7 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci) · 1 unmodified line
883939 wmb();
884940
885941 /* get TD from hc's singly linked list, and
886− * prepend to ours. ed->td_list changes later.
942+ * add to ours. ed->td_list changes later.
887943 */
888944 while (td_dma) {
889945 int cc;
@@ -905,19 +961,17 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci) · 15 unmodified lines
905961 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
906962 ed_halted(ohci, td, cc);
907963
908− td->next_dl_td = td_rev;
909− td_rev = td;
910964 td_dma = hc32_to_cpup (ohci, &td->hwNextTD);
965+ add_to_done_list(ohci, td);
911966 }
912− return td_rev;
913967 }
914968
915969 /*-------------------------------------------------------------------------*/
916970
917971 /* there are some urbs/eds to unlink; called in_irq(), with HCD locked */
918−static void
919−finish_unlinks (struct ohci_hcd *ohci, u16 tick)
972+static void finish_unlinks(struct ohci_hcd *ohci)
920973 {
974+ unsigned tick = ohci_frame_no(ohci);
921975 struct ed *ed, **last;
922976
923977 rescan_all:
@@ -926,41 +980,48 @@ rescan_all: · 2 unmodified lines
926980 int completed, modified;
927981 __hc32 *prev;
928982
983+ /* Is this ED already invisible to the hardware? */
984+ if (ed->state == ED_IDLE)
985+ goto ed_idle;
986+
929987 /* only take off EDs that the HC isn't using, accounting for
930988 * frame counter wraps and EDs with partially retired TDs
931989 */
932− if (likely(ohci->rh_state == OHCI_RH_RUNNING)) {
933− if (tick_before (tick, ed->tick)) {
990+ if (likely(ohci->rh_state == OHCI_RH_RUNNING) &&
991+ tick_before(tick, ed->tick)) {
934992 skip_ed:
935− last = &ed->ed_next;
936− continue;
937− }
993+ last = &ed->ed_next;
994+ continue;
995+ }
996+ if (!list_empty(&ed->td_list)) {
997+ struct td *td;
998+ u32 head;
938999
939− if (!list_empty (&ed->td_list)) {
940− struct td *td;
941− u32 head;
942−
943− td = list_entry (ed->td_list.next, struct td,
944− td_list);
945− head = hc32_to_cpu (ohci, ed->hwHeadP) &
946− TD_MASK;
947−
948− /* INTR_WDH may need to clean up first */
949− if (td->td_dma != head) {
950− if (ed == ohci->ed_to_check)
951− ohci->ed_to_check = NULL;
952− else
953− goto skip_ed;
954− }
955− }
1000+ td = list_first_entry(&ed->td_list, struct td, td_list);
1001+
1002+ /* INTR_WDH may need to clean up first */
1003+ head = hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK;
1004+ if (td->td_dma != head &&
1005+ ohci->rh_state == OHCI_RH_RUNNING)
1006+ goto skip_ed;
1007+
1008+ /* Don't mess up anything already on the done list */
1009+ if (td->next_dl_td)
1010+ goto skip_ed;
9561011 }
9571012
1013+ /* ED's now officially unlinked, hc doesn't see */
1014+ ed->state = ED_IDLE;
1015+ ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H);
1016+ ed->hwNextED = 0;
1017+ wmb();
1018+ ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE);
1019+ed_idle:
1020+
9581021 /* reentrancy: if we drop the schedule lock, someone might
9591022 * have modified this list. normally it's just prepending
9601023 * entries (which we'd ignore), but paranoia won't hurt.
9611024 */
962− *last = ed->ed_next;
963− ed->ed_next = NULL;
9641025 modified = 0;
9651026
9661027 /* unlink urbs as requested, but rescan the list after
@@ -1018,19 +1079,21 @@ rescan_this: · 51 unmodified lines
10181079 if (completed && !list_empty (&ed->td_list))
10191080 goto rescan_this;
10201081
1021− /* ED's now officially unlinked, hc doesn't see */
1022− ed->state = ED_IDLE;
1023− if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
1024− ohci->eds_scheduled--;
1025− ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H);
1026− ed->hwNextED = 0;
1027− wmb ();
1028− ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE);
1029−
1030− /* but if there's work queued, reschedule */
1031− if (!list_empty (&ed->td_list)) {
1032− if (ohci->rh_state == OHCI_RH_RUNNING)
1033− ed_schedule (ohci, ed);
1082+ /*
1083+ * If no TDs are queued, take ED off the ed_rm_list.
1084+ * Otherwise, if the HC is running, reschedule.
1085+ * If not, leave it on the list for further dequeues.
1086+ */
1087+ if (list_empty(&ed->td_list)) {
1088+ *last = ed->ed_next;
1089+ ed->ed_next = NULL;
1090+ list_del(&ed->in_use_list);
1091+ } else if (ohci->rh_state == OHCI_RH_RUNNING) {
1092+ *last = ed->ed_next;
1093+ ed->ed_next = NULL;
1094+ ed_schedule(ohci, ed);
1095+ } else {
1096+ last = &ed->ed_next;
10341097 }
10351098
10361099 if (modified)
@@ -1082,12 +1145,7 @@ rescan_this: · 45 unmodified lines
10821145
10831146 /*-------------------------------------------------------------------------*/
10841147
1085−/*
1086− * Used to take back a TD from the host controller. This would normally be
1087− * called from within dl_done_list, however it may be called directly if the
1088− * HC no longer sees the TD and it has not appeared on the donelist (after
1089− * two frames). This bug has been observed on ZF Micro systems.
1090− */
1148+/* Take back a TD from the host controller */
10911149 static void takeback_td(struct ohci_hcd *ohci, struct td *td)
10921150 {
10931151 struct urb *urb = td->urb;
@@ -1134,37 +1192,43 @@ static void takeback_td(struct ohci_hcd *ohci, struct td *td) · 40 unmodified lines
11341192 *
11351193 * This is the main path for handing urbs back to drivers. The only other
11361194 * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list,
1137− * instead of scanning the (re-reversed) donelist as this does. There's
1138− * an abnormal path too, handling a quirk in some Compaq silicon: URBs
1139− * with TDs that appear to be orphaned are directly reclaimed.
1195+ * instead of scanning the (re-reversed) donelist as this does.
11401196 */
1141−static void
1142−dl_done_list (struct ohci_hcd *ohci)
1197+static void process_done_list(struct ohci_hcd *ohci)
11431198 {
1144− struct td *td = dl_reverse_done_list (ohci);
1199+ struct td *td;
11451200
1146− while (td) {
1147− struct td *td_next = td->next_dl_td;
1148− struct ed *ed = td->ed;
1201+ while (ohci->dl_start) {
1202+ td = ohci->dl_start;
1203+ if (td == ohci->dl_end)
1204+ ohci->dl_start = ohci->dl_end = NULL;
1205+ else
1206+ ohci->dl_start = td->next_dl_td;
11491207
1150− /*
1151− * Some OHCI controllers (NVIDIA for sure, maybe others)
1152− * occasionally forget to add TDs to the done queue. Since
1153− * TDs for a given endpoint are always processed in order,
1154− * if we find a TD on the donelist then all of its
1155− * predecessors must be finished as well.
1156− */
1157− for (;;) {
1158− struct td *td2;
1208+ takeback_td(ohci, td);
1209+ }
1210+}
11591211
1160− td2 = list_first_entry(&ed->td_list, struct td,
1161− td_list);
1162− if (td2 == td)
1163− break;
1164− takeback_td(ohci, td2);
1165− }
1212+/*
1213+ * TD takeback and URB giveback must be single-threaded.
1214+ * This routine takes care of it all.
1215+ */
1216+static void ohci_work(struct ohci_hcd *ohci)
1217+{
1218+ if (ohci->working) {
1219+ ohci->restart_work = 1;
1220+ return;
1221+ }
1222+ ohci->working = 1;
11661223
1167− takeback_td(ohci, td);
1168− td = td_next;
1224+ restart:
1225+ process_done_list(ohci);
1226+ if (ohci->ed_rm_list)
1227+ finish_unlinks(ohci);
1228+
1229+ if (ohci->restart_work) {
1230+ ohci->restart_work = 0;
1231+ goto restart;
11691232 }
1233+ ohci->working = 0;
11701234 }
drivers/usb/host/ohci-spear.c+1−1
@@ -162,7 +162,7 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev) · 161 unmodified lines
162162 }
163163 #endif
164164
165−static struct of_device_id spear_ohci_id_table[] = {
165+static const struct of_device_id spear_ohci_id_table[] = {
166166 { .compatible = "st,spear600-ohci", },
167167 { },
168168 };
drivers/usb/host/ohci.h+17−6
@@ -47,6 +47,7 @@ struct ed { · 46 unmodified lines
4747 struct ed *ed_next; /* on schedule or rm_list */
4848 struct ed *ed_prev; /* for non-interrupt EDs */
4949 struct list_head td_list; /* "shadow list" of our TDs */
50+ struct list_head in_use_list;
5051
5152 /* create --> IDLE --> OPER --> ... --> IDLE --> destroy
5253 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ...
@@ -66,6 +67,13 @@ struct ed { · 13 unmodified lines
6667
6768 /* HC may see EDs on rm_list until next frame (frame_no == tick) */
6869 u16 tick;
70+
71+ /* Detect TDs not added to the done queue */
72+ unsigned takeback_wdh_cnt;
73+ struct td *pending_td;
74+#define OKAY_TO_TAKEBACK(ohci, ed) \
75+ ((int) (ohci->wdh_cnt - ed->takeback_wdh_cnt) >= 0)
76+
6977 } __attribute__ ((aligned(16)));
7078
7179 #define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */
@@ -380,7 +388,9 @@ struct ohci_hcd { · 308 unmodified lines
380388 struct dma_pool *td_cache;
381389 struct dma_pool *ed_cache;
382390 struct td *td_hash [TD_HASH_SIZE];
391+ struct td *dl_start, *dl_end; /* the done list */
383392 struct list_head pending;
393+ struct list_head eds_in_use; /* all EDs with at least 1 TD */
384394
385395 /*
386396 * driver state
@@ -392,6 +402,8 @@ struct ohci_hcd { · 5 unmodified lines
392402 unsigned long next_statechange; /* suspend/resume */
393403 u32 fminterval; /* saved register */
394404 unsigned autostop:1; /* rh auto stopping/stopped */
405+ unsigned working:1;
406+ unsigned restart_work:1;
395407
396408 unsigned long flags; /* for HC bugs */
397409 #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
@@ -409,13 +421,12 @@ struct ohci_hcd { · 11 unmodified lines
409421
410422 // there are also chip quirks/bugs in init logic
411423
412− struct work_struct nec_work; /* Worker for NEC quirk */
424+ unsigned prev_frame_no;
425+ unsigned wdh_cnt, prev_wdh_cnt;
426+ u32 prev_donehead;
427+ struct timer_list io_watchdog;
413428
414− /* Needed for ZF Micro quirk */
415− struct timer_list unlink_watchdog;
416− unsigned eds_scheduled;
417− struct ed *ed_to_check;
418− unsigned zf_delay;
429+ struct work_struct nec_work; /* Worker for NEC quirk */
419430
420431 struct dentry *debug_dir;
421432 struct dentry *debug_async;
drivers/usb/host/oxu210hp-hcd.c+9−39
@@ -3826,49 +3826,36 @@ static int oxu_drv_probe(struct platform_device *pdev) · 3825 unmodified lines
38263826 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq);
38273827
38283828 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3829− if (!res) {
3830− dev_err(&pdev->dev, "no registers address! Check %s setup!\n",
3831− dev_name(&pdev->dev));
3832− return -ENODEV;
3829+ base = devm_ioremap_resource(&pdev->dev, res);
3830+ if (IS_ERR(base)) {
3831+ ret = PTR_ERR(base);
3832+ goto error;
38333833 }
38343834 memstart = res->start;
38353835 memlen = resource_size(res);
3836− dev_dbg(&pdev->dev, "MEM resource %lx-%lx\n", memstart, memlen);
3837− if (!request_mem_region(memstart, memlen,
3838− oxu_hc_driver.description)) {
3839− dev_dbg(&pdev->dev, "memory area already in use\n");
3840− return -EBUSY;
3841− }
38423836
38433837 ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING);
38443838 if (ret) {
38453839 dev_err(&pdev->dev, "error setting irq type\n");
38463840 ret = -EFAULT;
3847− goto error_set_irq_type;
3848− }
3849−
3850− base = ioremap(memstart, memlen);
3851− if (!base) {
3852− dev_dbg(&pdev->dev, "error mapping memory\n");
3853− ret = -EFAULT;
3854− goto error_ioremap;
3841+ goto error;
38553842 }
38563843
38573844 /* Allocate a driver data struct to hold useful info for both
38583845 * SPH & OTG devices
38593846 */
3860− info = kzalloc(sizeof(struct oxu_info), GFP_KERNEL);
3847+ info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL);
38613848 if (!info) {
38623849 dev_dbg(&pdev->dev, "error allocating memory\n");
38633850 ret = -EFAULT;
3864− goto error_alloc;
3851+ goto error;
38653852 }
38663853 platform_set_drvdata(pdev, info);
38673854
38683855 ret = oxu_init(pdev, memstart, memlen, base, irq);
38693856 if (ret < 0) {
38703857 dev_dbg(&pdev->dev, "cannot init USB devices\n");
3871− goto error_init;
3858+ goto error;
38723859 }
38733860
38743861 dev_info(&pdev->dev, "devices enabled and running\n");
@@ -3876,16 +3863,7 @@ static int oxu_drv_probe(struct platform_device *pdev) · 1 unmodified line
38763863
38773864 return 0;
38783865
3879−error_init:
3880− kfree(info);
3881−
3882−error_alloc:
3883− iounmap(base);
3884−
3885−error_set_irq_type:
3886−error_ioremap:
3887− release_mem_region(memstart, memlen);
3888−
3866+error:
38893867 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
38903868 return ret;
38913869 }
@@ -3899,18 +3877,10 @@ static void oxu_remove(struct platform_device *pdev, struct usb_hcd *hcd) · 7 unmodified lines
38993877 static int oxu_drv_remove(struct platform_device *pdev)
39003878 {
39013879 struct oxu_info *info = platform_get_drvdata(pdev);
3902− unsigned long memstart = info->hcd[0]->rsrc_start,
3903− memlen = info->hcd[0]->rsrc_len;
3904− void *base = info->hcd[0]->regs;
39053880
39063881 oxu_remove(pdev, info->hcd[0]);
39073882 oxu_remove(pdev, info->hcd[1]);
39083883
3909− iounmap(base);
3910− release_mem_region(memstart, memlen);
3911−
3912− kfree(info);
3913−
39143884 return 0;
39153885 }
39163886
drivers/usb/host/uhci-grlib.c+9−22
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
1818 */
1919
20+#include <linux/device.h>
2021 #include <linux/of_irq.h>
2122 #include <linux/of_address.h>
2223 #include <linux/of_platform.h>
@@ -113,24 +114,17 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) · 90 unmodified lines
113114 hcd->rsrc_start = res.start;
114115 hcd->rsrc_len = resource_size(&res);
115116
116− if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
117− printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
118− rv = -EBUSY;
119− goto err_rmr;
120− }
121−
122117 irq = irq_of_parse_and_map(dn, 0);
123118 if (irq == NO_IRQ) {
124119 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
125120 rv = -EBUSY;
126− goto err_irq;
121+ goto err_usb;
127122 }
128123
129− hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
130− if (!hcd->regs) {
131− printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
132− rv = -ENOMEM;
133− goto err_ioremap;
124+ hcd->regs = devm_ioremap_resource(&op->dev, &res);
125+ if (IS_ERR(hcd->regs)) {
126+ rv = PTR_ERR(hcd->regs);
127+ goto err_irq;
134128 }
135129
136130 uhci = hcd_to_uhci(hcd);
@@ -139,18 +133,14 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) · 2 unmodified lines
139133
140134 rv = usb_add_hcd(hcd, irq, 0);
141135 if (rv)
142− goto err_uhci;
136+ goto err_irq;
143137
144138 device_wakeup_enable(hcd->self.controller);
145139 return 0;
146140
147−err_uhci:
148− iounmap(hcd->regs);
149−err_ioremap:
150− irq_dispose_mapping(irq);
151141 err_irq:
152− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
153−err_rmr:
142+ irq_dispose_mapping(irq);
143+err_usb:
154144 usb_put_hcd(hcd);
155145
156146 return rv;
@@ -164,10 +154,7 @@ static int uhci_hcd_grlib_remove(struct platform_device *op) · 7 unmodified lines
164154
165155 usb_remove_hcd(hcd);
166156
167− iounmap(hcd->regs);
168157 irq_dispose_mapping(hcd->irq);
169− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
170−
171158 usb_put_hcd(hcd);
172159
173160 return 0;
drivers/usb/host/uhci-hcd.c+1−1
@@ -591,7 +591,7 @@ static int uhci_start(struct usb_hcd *hcd) · 590 unmodified lines
591591
592592 uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
593593 UHCI_NUMFRAMES * sizeof(*uhci->frame),
594− &uhci->frame_dma_handle, 0);
594+ &uhci->frame_dma_handle, GFP_KERNEL);
595595 if (!uhci->frame) {
596596 dev_err(uhci_dev(uhci),
597597 "unable to allocate consistent memory for frame list\n");
drivers/usb/host/uhci-platform.c+5−17
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 */
99
1010 #include <linux/of.h>
11+#include <linux/device.h>
1112 #include <linux/platform_device.h>
1213
1314 static int uhci_platform_init(struct usb_hcd *hcd)
@@ -88,33 +89,22 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev) · 74 unmodified lines
8889 hcd->rsrc_start = res->start;
8990 hcd->rsrc_len = resource_size(res);
9091
91− if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
92− pr_err("%s: request_mem_region failed\n", __func__);
93− ret = -EBUSY;
92+ hcd->regs = devm_ioremap_resource(&pdev->dev, res);
93+ if (IS_ERR(hcd->regs)) {
94+ ret = PTR_ERR(hcd->regs);
9495 goto err_rmr;
9596 }
96−
97− hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
98− if (!hcd->regs) {
99− pr_err("%s: ioremap failed\n", __func__);
100− ret = -ENOMEM;
101− goto err_irq;
102− }
10397 uhci = hcd_to_uhci(hcd);
10498
10599 uhci->regs = hcd->regs;
106100
107101 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
108102 if (ret)
109− goto err_uhci;
103+ goto err_rmr;
110104
111105 device_wakeup_enable(hcd->self.controller);
112106 return 0;
113107
114−err_uhci:
115− iounmap(hcd->regs);
116−err_irq:
117− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
118108 err_rmr:
119109 usb_put_hcd(hcd);
120110
@@ -126,8 +116,6 @@ static int uhci_hcd_platform_remove(struct platform_device *pdev) · 5 unmodified lines
126116 struct usb_hcd *hcd = platform_get_drvdata(pdev);
127117
128118 usb_remove_hcd(hcd);
129− iounmap(hcd->regs);
130− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
131119 usb_put_hcd(hcd);
132120
133121 return 0;
drivers/usb/host/xhci-pci.c+5−3
@@ -33,7 +33,7 @@ · 32 unmodified lines
3333 #define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400
3434
3535 #define PCI_VENDOR_ID_ETRON 0x1b6f
36−#define PCI_DEVICE_ID_ASROCK_P67 0x7023
36+#define PCI_DEVICE_ID_EJ168 0x7023
3737
3838 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
3939 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
@@ -140,9 +140,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) · 100 unmodified lines
140140 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
141141 }
142142 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
143− pdev->device == PCI_DEVICE_ID_ASROCK_P67) {
143+ pdev->device == PCI_DEVICE_ID_EJ168) {
144144 xhci->quirks |= XHCI_RESET_ON_RESUME;
145145 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
146+ xhci->quirks |= XHCI_BROKEN_STREAMS;
146147 }
147148 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
148149 pdev->device == 0x0015)
@@ -230,7 +231,8 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) · 81 unmodified lines
230231 goto put_usb3_hcd;
231232 /* Roothub already marked as USB 3.0 speed */
232233
233− if (HCC_MAX_PSA(xhci->hcc_params) >= 4)
234+ if (!(xhci->quirks & XHCI_BROKEN_STREAMS) &&
235+ HCC_MAX_PSA(xhci->hcc_params) >= 4)
234236 xhci->shared_hcd->can_do_streams = 1;
235237
236238 /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
drivers/usb/host/xhci-plat.c+32−20
@@ -17,9 +17,11 @@ · 16 unmodified lines
1717 #include <linux/of.h>
1818 #include <linux/platform_device.h>
1919 #include <linux/slab.h>
20+#include <linux/usb/xhci_pdriver.h>
2021
2122 #include "xhci.h"
2223 #include "xhci-mvebu.h"
24+#include "xhci-rcar.h"
2325
2426 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
2527 {
@@ -34,11 +36,27 @@ static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) · 8 unmodified lines
3436 /* called during probe() after chip reset completes */
3537 static int xhci_plat_setup(struct usb_hcd *hcd)
3638 {
39+ struct device_node *of_node = hcd->self.controller->of_node;
40+ int ret;
41+
42+ if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
43+ of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) {
44+ ret = xhci_rcar_init_quirk(hcd);
45+ if (ret)
46+ return ret;
47+ }
48+
3749 return xhci_gen_setup(hcd, xhci_plat_quirks);
3850 }
3951
4052 static int xhci_plat_start(struct usb_hcd *hcd)
4153 {
54+ struct device_node *of_node = hcd->self.controller->of_node;
55+
56+ if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
57+ of_device_is_compatible(of_node, "renesas,xhci-r8a7791"))
58+ xhci_rcar_start(hcd);
59+
4260 return xhci_run(hcd);
4361 }
4462
@@ -90,10 +108,15 @@ static const struct hc_driver xhci_plat_xhci_driver = { · 45 unmodified lines
90108 .hub_status_data = xhci_hub_status_data,
91109 .bus_suspend = xhci_bus_suspend,
92110 .bus_resume = xhci_bus_resume,
111+
112+ .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
113+ .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
93114 };
94115
95116 static int xhci_plat_probe(struct platform_device *pdev)
96117 {
118+ struct device_node *node = pdev->dev.of_node;
119+ struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
97120 const struct hc_driver *driver;
98121 struct xhci_hcd *xhci;
99122 struct resource *res;
@@ -140,20 +163,12 @@ static int xhci_plat_probe(struct platform_device *pdev) · 40 unmodified lines
140163 hcd->rsrc_start = res->start;
141164 hcd->rsrc_len = resource_size(res);
142165
143− if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
144− driver->description)) {
145− dev_dbg(&pdev->dev, "controller already in use\n");
146− ret = -EBUSY;
166+ hcd->regs = devm_ioremap_resource(&pdev->dev, res);
167+ if (IS_ERR(hcd->regs)) {
168+ ret = PTR_ERR(hcd->regs);
147169 goto put_hcd;
148170 }
149171
150− hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
151− if (!hcd->regs) {
152− dev_dbg(&pdev->dev, "error mapping memory\n");
153− ret = -EFAULT;
154− goto release_mem_region;
155− }
156−
157172 /*
158173 * Not all platforms have a clk so it is not an error if the
159174 * clock does not exists.
@@ -162,7 +177,7 @@ static int xhci_plat_probe(struct platform_device *pdev) · 2 unmodified lines
162177 if (!IS_ERR(clk)) {
163178 ret = clk_prepare_enable(clk);
164179 if (ret)
165− goto unmap_registers;
180+ goto put_hcd;
166181 }
167182
168183 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
@@ -182,6 +197,9 @@ static int xhci_plat_probe(struct platform_device *pdev) · 13 unmodified lines
182197 goto dealloc_usb2_hcd;
183198 }
184199
200+ if ((node && of_property_read_bool(node, "usb3-lpm-capable")) ||
201+ (pdata && pdata->usb3_lpm_capable))
202+ xhci->quirks |= XHCI_LPM_SUPPORT;
185203 /*
186204 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
187205 * is called by usb_add_hcd().
@@ -207,12 +225,6 @@ disable_clk: · 19 unmodified lines
207225 if (!IS_ERR(clk))
208226 clk_disable_unprepare(clk);
209227
210−unmap_registers:
211− iounmap(hcd->regs);
212−
213−release_mem_region:
214− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
215−
216228 put_hcd:
217229 usb_put_hcd(hcd);
218230
@@ -231,8 +243,6 @@ static int xhci_plat_remove(struct platform_device *dev) · 12 unmodified lines
231243 usb_remove_hcd(hcd);
232244 if (!IS_ERR(clk))
233245 clk_disable_unprepare(clk);
234− iounmap(hcd->regs);
235− release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
236246 usb_put_hcd(hcd);
237247 kfree(xhci);
238248
@@ -270,6 +280,8 @@ static const struct of_device_id usb_xhci_of_match[] = { · 31 unmodified lines
270280 { .compatible = "xhci-platform" },
271281 { .compatible = "marvell,armada-375-xhci"},
272282 { .compatible = "marvell,armada-380-xhci"},
283+ { .compatible = "renesas,xhci-r8a7790"},
284+ { .compatible = "renesas,xhci-r8a7791"},
273285 { },
274286 };
275287 MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
drivers/usb/host/xhci-rcar.c+148−0
@@ -0,0 +1,148 @@
1+/*
2+ * xHCI host controller driver for R-Car SoCs
3+ *
4+ * Copyright (C) 2014 Renesas Electronics Corporation
5+ *
6+ * This program is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU General Public License
8+ * version 2 as published by the Free Software Foundation.
9+ */
10+
11+#include <linux/firmware.h>
12+#include <linux/module.h>
13+#include <linux/platform_device.h>
14+#include <linux/usb/phy.h>
15+
16+#include "xhci.h"
17+#include "xhci-rcar.h"
18+
19+#define FIRMWARE_NAME "r8a779x_usb3_v1.dlmem"
20+MODULE_FIRMWARE(FIRMWARE_NAME);
21+
22+/*** Register Offset ***/
23+#define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */
24+#define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */
25+#define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */
26+
27+#define RCAR_USB3_LCLK 0xa44 /* LCLK Select */
28+#define RCAR_USB3_CONF1 0xa48 /* USB3.0 Configuration1 */
29+#define RCAR_USB3_CONF2 0xa5c /* USB3.0 Configuration2 */
30+#define RCAR_USB3_CONF3 0xaa8 /* USB3.0 Configuration3 */
31+#define RCAR_USB3_RX_POL 0xab0 /* USB3.0 RX Polarity */
32+#define RCAR_USB3_TX_POL 0xab8 /* USB3.0 TX Polarity */
33+
34+/*** Register Settings ***/
35+/* Interrupt Enable */
36+#define RCAR_USB3_INT_XHC_ENA 0x00000001
37+#define RCAR_USB3_INT_PME_ENA 0x00000002
38+#define RCAR_USB3_INT_HSE_ENA 0x00000004
39+#define RCAR_USB3_INT_ENA_VAL (RCAR_USB3_INT_XHC_ENA | \
40+ RCAR_USB3_INT_PME_ENA | RCAR_USB3_INT_HSE_ENA)
41+
42+/* FW Download Control & Status */
43+#define RCAR_USB3_DL_CTRL_ENABLE 0x00000001
44+#define RCAR_USB3_DL_CTRL_FW_SUCCESS 0x00000010
45+#define RCAR_USB3_DL_CTRL_FW_SET_DATA0 0x00000100
46+
47+/* LCLK Select */
48+#define RCAR_USB3_LCLK_ENA_VAL 0x01030001
49+
50+/* USB3.0 Configuration */
51+#define RCAR_USB3_CONF1_VAL 0x00030204
52+#define RCAR_USB3_CONF2_VAL 0x00030300
53+#define RCAR_USB3_CONF3_VAL 0x13802007
54+
55+/* USB3.0 Polarity */
56+#define RCAR_USB3_RX_POL_VAL BIT(21)
57+#define RCAR_USB3_TX_POL_VAL BIT(4)
58+
59+void xhci_rcar_start(struct usb_hcd *hcd)
60+{
61+ u32 temp;
62+
63+ if (hcd->regs != NULL) {
64+ /* Interrupt Enable */
65+ temp = readl(hcd->regs + RCAR_USB3_INT_ENA);
66+ temp |= RCAR_USB3_INT_ENA_VAL;
67+ writel(temp, hcd->regs + RCAR_USB3_INT_ENA);
68+ /* LCLK Select */
69+ writel(RCAR_USB3_LCLK_ENA_VAL, hcd->regs + RCAR_USB3_LCLK);
70+ /* USB3.0 Configuration */
71+ writel(RCAR_USB3_CONF1_VAL, hcd->regs + RCAR_USB3_CONF1);
72+ writel(RCAR_USB3_CONF2_VAL, hcd->regs + RCAR_USB3_CONF2);
73+ writel(RCAR_USB3_CONF3_VAL, hcd->regs + RCAR_USB3_CONF3);
74+ /* USB3.0 Polarity */
75+ writel(RCAR_USB3_RX_POL_VAL, hcd->regs + RCAR_USB3_RX_POL);
76+ writel(RCAR_USB3_TX_POL_VAL, hcd->regs + RCAR_USB3_TX_POL);
77+ }
78+}
79+
80+static int xhci_rcar_download_firmware(struct device *dev, void __iomem *regs)
81+{
82+ const struct firmware *fw;
83+ int retval, index, j, time;
84+ int timeout = 10000;
85+ u32 data, val, temp;
86+
87+ /* request R-Car USB3.0 firmware */
88+ retval = request_firmware(&fw, FIRMWARE_NAME, dev);
89+ if (retval)
90+ return retval;
91+
92+ /* download R-Car USB3.0 firmware */
93+ temp = readl(regs + RCAR_USB3_DL_CTRL);
94+ temp |= RCAR_USB3_DL_CTRL_ENABLE;
95+ writel(temp, regs + RCAR_USB3_DL_CTRL);
96+
97+ for (index = 0; index < fw->size; index += 4) {
98+ /* to avoid reading beyond the end of the buffer */
99+ for (data = 0, j = 3; j >= 0; j--) {
100+ if ((j + index) < fw->size)
101+ data |= fw->data[index + j] << (8 * j);
102+ }
103+ writel(data, regs + RCAR_USB3_FW_DATA0);
104+ temp = readl(regs + RCAR_USB3_DL_CTRL);
105+ temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
106+ writel(temp, regs + RCAR_USB3_DL_CTRL);
107+
108+ for (time = 0; time < timeout; time++) {
109+ val = readl(regs + RCAR_USB3_DL_CTRL);
110+ if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
111+ break;
112+ udelay(1);
113+ }
114+ if (time == timeout) {
115+ retval = -ETIMEDOUT;
116+ break;
117+ }
118+ }
119+
120+ temp = readl(regs + RCAR_USB3_DL_CTRL);
121+ temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
122+ writel(temp, regs + RCAR_USB3_DL_CTRL);
123+
124+ for (time = 0; time < timeout; time++) {
125+ val = readl(regs + RCAR_USB3_DL_CTRL);
126+ if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
127+ retval = 0;
128+ break;
129+ }
130+ udelay(1);
131+ }
132+ if (time == timeout)
133+ retval = -ETIMEDOUT;
134+
135+ release_firmware(fw);
136+
137+ return retval;
138+}
139+
140+/* This function needs to initialize a "phy" of usb before */
141+int xhci_rcar_init_quirk(struct usb_hcd *hcd)
142+{
143+ /* If hcd->regs is NULL, we don't just call the following function */
144+ if (!hcd->regs)
145+ return 0;
146+
147+ return xhci_rcar_download_firmware(hcd->self.controller, hcd->regs);
148+}
drivers/usb/host/xhci-rcar.h+27−0
@@ -0,0 +1,27 @@
1+/*
2+ * drivers/usb/host/xhci-rcar.h
3+ *
4+ * Copyright (C) 2014 Renesas Electronics Corporation
5+ *
6+ * This program is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU General Public License
8+ * version 2 as published by the Free Software Foundation.
9+ */
10+
11+#ifndef _XHCI_RCAR_H
12+#define _XHCI_RCAR_H
13+
14+#if IS_ENABLED(CONFIG_USB_XHCI_RCAR)
15+void xhci_rcar_start(struct usb_hcd *hcd);
16+int xhci_rcar_init_quirk(struct usb_hcd *hcd);
17+#else
18+static inline void xhci_rcar_start(struct usb_hcd *hcd)
19+{
20+}
21+
22+static inline int xhci_rcar_init_quirk(struct usb_hcd *hcd)
23+{
24+ return 0;
25+}
26+#endif
27+#endif /* _XHCI_RCAR_H */
drivers/usb/host/xhci-ring.c+4−0
@@ -1118,6 +1118,10 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, · 1117 unmodified lines
11181118 if (xhci->quirks & XHCI_RESET_EP_QUIRK) {
11191119 struct xhci_command *command;
11201120 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC);
1121+ if (!command) {
1122+ xhci_warn(xhci, "WARN Cannot submit cfg ep: ENOMEM\n");
1123+ return;
1124+ }
11211125 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
11221126 "Queueing configure endpoint command");
11231127 xhci_queue_configure_endpoint(xhci, command,
drivers/usb/host/xhci.c+90−70
@@ -1553,6 +1553,10 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) · 1552 unmodified lines
15531553 */
15541554 if (!(ep->ep_state & EP_HALT_PENDING)) {
15551555 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC);
1556+ if (!command) {
1557+ ret = -ENOMEM;
1558+ goto done;
1559+ }
15561560 ep->ep_state |= EP_HALT_PENDING;
15571561 ep->stop_cmds_pending++;
15581562 ep->stop_cmd_timer.expires = jiffies +
@@ -1586,12 +1590,10 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 27 unmodified lines
15861590 struct xhci_hcd *xhci;
15871591 struct xhci_container_ctx *in_ctx, *out_ctx;
15881592 struct xhci_input_control_ctx *ctrl_ctx;
1589− struct xhci_slot_ctx *slot_ctx;
1590− unsigned int last_ctx;
15911593 unsigned int ep_index;
15921594 struct xhci_ep_ctx *ep_ctx;
15931595 u32 drop_flag;
1594− u32 new_add_flags, new_drop_flags, new_slot_info;
1596+ u32 new_add_flags, new_drop_flags;
15951597 int ret;
15961598
15971599 ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
@@ -1638,24 +1640,13 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 40 unmodified lines
16381640 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag);
16391641 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
16401642
1641− last_ctx = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags));
1642− slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1643− /* Update the last valid endpoint context, if we deleted the last one */
1644− if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) >
1645− LAST_CTX(last_ctx)) {
1646− slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
1647− slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
1648− }
1649− new_slot_info = le32_to_cpu(slot_ctx->dev_info);
1650−
16511643 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
16521644
1653− xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n",
1645+ xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n",
16541646 (unsigned int) ep->desc.bEndpointAddress,
16551647 udev->slot_id,
16561648 (unsigned int) new_drop_flags,
1657− (unsigned int) new_add_flags,
1658− (unsigned int) new_slot_info);
1649+ (unsigned int) new_add_flags);
16591650 return 0;
16601651 }
16611652
@@ -1678,11 +1669,9 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 16 unmodified lines
16781669 struct xhci_hcd *xhci;
16791670 struct xhci_container_ctx *in_ctx, *out_ctx;
16801671 unsigned int ep_index;
1681− struct xhci_slot_ctx *slot_ctx;
16821672 struct xhci_input_control_ctx *ctrl_ctx;
16831673 u32 added_ctxs;
1684− unsigned int last_ctx;
1685− u32 new_add_flags, new_drop_flags, new_slot_info;
1674+ u32 new_add_flags, new_drop_flags;
16861675 struct xhci_virt_device *virt_dev;
16871676 int ret = 0;
16881677
@@ -1697,7 +1686,6 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 8 unmodified lines
16971686 return -ENODEV;
16981687
16991688 added_ctxs = xhci_get_endpoint_flag(&ep->desc);
1700− last_ctx = xhci_last_valid_endpoint(added_ctxs);
17011689 if (added_ctxs == SLOT_FLAG || added_ctxs == EP0_FLAG) {
17021690 /* FIXME when we have to issue an evaluate endpoint command to
17031691 * deal with ep0 max packet size changing once we get the
@@ -1763,24 +1751,14 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, · 59 unmodified lines
17631751 */
17641752 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
17651753
1766− slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1767− /* Update the last valid endpoint context, if we just added one past */
1768− if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) <
1769− LAST_CTX(last_ctx)) {
1770− slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
1771− slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
1772− }
1773− new_slot_info = le32_to_cpu(slot_ctx->dev_info);
1774−
17751754 /* Store the usb_device pointer for later use */
17761755 ep->hcpriv = udev;
17771756
1778− xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n",
1757+ xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n",
17791758 (unsigned int) ep->desc.bEndpointAddress,
17801759 udev->slot_id,
17811760 (unsigned int) new_drop_flags,
1782− (unsigned int) new_add_flags,
1783− (unsigned int) new_slot_info);
1761+ (unsigned int) new_add_flags);
17841762 return 0;
17851763 }
17861764
@@ -1830,15 +1808,15 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, · 43 unmodified lines
18301808 ret = -ETIME;
18311809 break;
18321810 case COMP_ENOMEM:
1833− dev_warn(&udev->dev, "Not enough host controller resources "
1834− "for new device state.\n");
1811+ dev_warn(&udev->dev,
1812+ "Not enough host controller resources for new device state.\n");
18351813 ret = -ENOMEM;
18361814 /* FIXME: can we allocate more resources for the HC? */
18371815 break;
18381816 case COMP_BW_ERR:
18391817 case COMP_2ND_BW_ERR:
1840− dev_warn(&udev->dev, "Not enough bandwidth "
1841− "for new device state.\n");
1818+ dev_warn(&udev->dev,
1819+ "Not enough bandwidth for new device state.\n");
18421820 ret = -ENOSPC;
18431821 /* FIXME: can we go back to the old state? */
18441822 break;
@@ -1850,8 +1828,8 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, · 5 unmodified lines
18501828 ret = -EINVAL;
18511829 break;
18521830 case COMP_DEV_ERR:
1853− dev_warn(&udev->dev, "ERROR: Incompatible device for endpoint "
1854− "configure command.\n");
1831+ dev_warn(&udev->dev,
1832+ "ERROR: Incompatible device for endpoint configure command.\n");
18551833 ret = -ENODEV;
18561834 break;
18571835 case COMP_SUCCESS:
@@ -1860,8 +1838,8 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, · 2 unmodified lines
18601838 ret = 0;
18611839 break;
18621840 default:
1863− xhci_err(xhci, "ERROR: unexpected command completion "
1864− "code 0x%x.\n", *cmd_status);
1841+ xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n",
1842+ *cmd_status);
18651843 ret = -EINVAL;
18661844 break;
18671845 }
@@ -1881,24 +1859,24 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci, · 13 unmodified lines
18811859 ret = -ETIME;
18821860 break;
18831861 case COMP_EINVAL:
1884− dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate "
1885− "context command.\n");
1862+ dev_warn(&udev->dev,
1863+ "WARN: xHCI driver setup invalid evaluate context command.\n");
18861864 ret = -EINVAL;
18871865 break;
18881866 case COMP_EBADSLT:
1889− dev_warn(&udev->dev, "WARN: slot not enabled for"
1890− "evaluate context command.\n");
1867+ dev_warn(&udev->dev,
1868+ "WARN: slot not enabled for evaluate context command.\n");
18911869 ret = -EINVAL;
18921870 break;
18931871 case COMP_CTX_STATE:
1894− dev_warn(&udev->dev, "WARN: invalid context state for "
1895− "evaluate context command.\n");
1872+ dev_warn(&udev->dev,
1873+ "WARN: invalid context state for evaluate context command.\n");
18961874 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1);
18971875 ret = -EINVAL;
18981876 break;
18991877 case COMP_DEV_ERR:
1900− dev_warn(&udev->dev, "ERROR: Incompatible device for evaluate "
1901− "context command.\n");
1878+ dev_warn(&udev->dev,
1879+ "ERROR: Incompatible device for evaluate context command.\n");
19021880 ret = -ENODEV;
19031881 break;
19041882 case COMP_MEL_ERR:
@@ -1912,8 +1890,8 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci, · 7 unmodified lines
19121890 ret = 0;
19131891 break;
19141892 default:
1915− xhci_err(xhci, "ERROR: unexpected command completion "
1916− "code 0x%x.\n", *cmd_status);
1893+ xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n",
1894+ *cmd_status);
19171895 ret = -EINVAL;
19181896 break;
19191897 }
@@ -2750,8 +2728,19 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) · 830 unmodified lines
27502728 ret = 0;
27512729 goto command_cleanup;
27522730 }
2753− xhci_dbg(xhci, "New Input Control Context:\n");
2731+ /* Fix up Context Entries field. Minimum value is EP0 == BIT(1). */
27542732 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
2733+ for (i = 31; i >= 1; i--) {
2734+ __le32 le32 = cpu_to_le32(BIT(i));
2735+
2736+ if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32))
2737+ || (ctrl_ctx->add_flags & le32) || i == 1) {
2738+ slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
2739+ slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i));
2740+ break;
2741+ }
2742+ }
2743+ xhci_dbg(xhci, "New Input Control Context:\n");
27552744 xhci_dbg_ctx(xhci, virt_dev->in_ctx,
27562745 LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info)));
27572746
@@ -3163,7 +3152,8 @@ int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, · 405 unmodified lines
31633152 num_streams);
31643153
31653154 /* MaxPSASize value 0 (2 streams) means streams are not supported */
3166− if (HCC_MAX_PSA(xhci->hcc_params) < 4) {
3155+ if ((xhci->quirks & XHCI_BROKEN_STREAMS) ||
3156+ HCC_MAX_PSA(xhci->hcc_params) < 4) {
31673157 xhci_dbg(xhci, "xHCI controller does not support streams.\n");
31683158 return -ENOSYS;
31693159 }
@@ -4303,8 +4293,7 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev, · 1133 unmodified lines
43034293 return USB3_LPM_DISABLED;
43044294 }
43054295
4306−/* Returns the hub-encoded U1 timeout value.
4307− * The U1 timeout should be the maximum of the following values:
4296+/* The U1 timeout should be the maximum of the following values:
43084297 * - For control endpoints, U1 system exit latency (SEL) * 3
43094298 * - For bulk endpoints, U1 SEL * 5
43104299 * - For interrupt endpoints:
@@ -4312,7 +4301,8 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev, · 1 unmodified line
43124301 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
43134302 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
43144303 */
4315−static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev,
4304+static unsigned long long xhci_calculate_intel_u1_timeout(
4305+ struct usb_device *udev,
43164306 struct usb_endpoint_descriptor *desc)
43174307 {
43184308 unsigned long long timeout_ns;
@@ -4344,11 +4334,28 @@ static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev, · 25 unmodified lines
43444334 return 0;
43454335 }
43464336
4347− /* The U1 timeout is encoded in 1us intervals. */
4348− timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000);
4349− /* Don't return a timeout of zero, because that's USB3_LPM_DISABLED. */
4337+ return timeout_ns;
4338+}
4339+
4340+/* Returns the hub-encoded U1 timeout value. */
4341+static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci,
4342+ struct usb_device *udev,
4343+ struct usb_endpoint_descriptor *desc)
4344+{
4345+ unsigned long long timeout_ns;
4346+
4347+ if (xhci->quirks & XHCI_INTEL_HOST)
4348+ timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc);
4349+ else
4350+ timeout_ns = udev->u1_params.sel;
4351+
4352+ /* The U1 timeout is encoded in 1us intervals.
4353+ * Don't return a timeout of zero, because that's USB3_LPM_DISABLED.
4354+ */
43504355 if (timeout_ns == USB3_LPM_DISABLED)
4351− timeout_ns++;
4356+ timeout_ns = 1;
4357+ else
4358+ timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000);
43524359
43534360 /* If the necessary timeout value is bigger than what we can set in the
43544361 * USB 3.0 hub, we have to disable hub-initiated U1.
@@ -4360,14 +4367,14 @@ static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev, · 5 unmodified lines
43604367 return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1);
43614368 }
43624369
4363−/* Returns the hub-encoded U2 timeout value.
4364− * The U2 timeout should be the maximum of:
4370+/* The U2 timeout should be the maximum of:
43654371 * - 10 ms (to avoid the bandwidth impact on the scheduler)
43664372 * - largest bInterval of any active periodic endpoint (to avoid going
43674373 * into lower power link states between intervals).
43684374 * - the U2 Exit Latency of the device
43694375 */
4370−static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev,
4376+static unsigned long long xhci_calculate_intel_u2_timeout(
4377+ struct usb_device *udev,
43714378 struct usb_endpoint_descriptor *desc)
43724379 {
43734380 unsigned long long timeout_ns;
@@ -4383,6 +4390,21 @@ static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev, · 9 unmodified lines
43834390 if (u2_del_ns > timeout_ns)
43844391 timeout_ns = u2_del_ns;
43854392
4393+ return timeout_ns;
4394+}
4395+
4396+/* Returns the hub-encoded U2 timeout value. */
4397+static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci,
4398+ struct usb_device *udev,
4399+ struct usb_endpoint_descriptor *desc)
4400+{
4401+ unsigned long long timeout_ns;
4402+
4403+ if (xhci->quirks & XHCI_INTEL_HOST)
4404+ timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc);
4405+ else
4406+ timeout_ns = udev->u2_params.sel;
4407+
43864408 /* The U2 timeout is encoded in 256us intervals */
43874409 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000);
43884410 /* If the necessary timeout value is bigger than what we can set in the
@@ -4401,13 +4423,10 @@ static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci, · 12 unmodified lines
44014423 enum usb3_link_state state,
44024424 u16 *timeout)
44034425 {
4404− if (state == USB3_LPM_U1) {
4405− if (xhci->quirks & XHCI_INTEL_HOST)
4406− return xhci_calculate_intel_u1_timeout(udev, desc);
4407− } else {
4408− if (xhci->quirks & XHCI_INTEL_HOST)
4409− return xhci_calculate_intel_u2_timeout(udev, desc);
4410− }
4426+ if (state == USB3_LPM_U1)
4427+ return xhci_calculate_u1_timeout(xhci, udev, desc);
4428+ else if (state == USB3_LPM_U2)
4429+ return xhci_calculate_u2_timeout(xhci, udev, desc);
44114430
44124431 return USB3_LPM_DISABLED;
44134432 }
@@ -4484,7 +4503,8 @@ static int xhci_check_tier_policy(struct xhci_hcd *xhci, · 70 unmodified lines
44844503 {
44854504 if (xhci->quirks & XHCI_INTEL_HOST)
44864505 return xhci_check_intel_tier_policy(udev, state);
4487− return -EINVAL;
4506+ else
4507+ return 0;
44884508 }
44894509
44904510 /* Returns the U1 or U2 timeout that should be enabled.
drivers/usb/host/xhci.h+2−0
@@ -1558,6 +1558,8 @@ struct xhci_hcd { · 1557 unmodified lines
15581558 #define XHCI_PLAT (1 << 16)
15591559 #define XHCI_SLOW_SUSPEND (1 << 17)
15601560 #define XHCI_SPURIOUS_WAKEUP (1 << 18)
1561+/* For controllers with a broken beyond repair streams implementation */
1562+#define XHCI_BROKEN_STREAMS (1 << 19)
15611563 unsigned int num_active_eps;
15621564 unsigned int limit_active_eps;
15631565 /* There are two roothubs to keep track of bus suspend info for */
drivers/usb/misc/Kconfig+7−0
@@ -248,3 +248,10 @@ config USB_HSIC_USB3503 · 247 unmodified lines
248248 select REGMAP_I2C
249249 help
250250 This option enables support for SMSC USB3503 HSIC to USB 2.0 Driver.
251+
252+config USB_LINK_LAYER_TEST
253+ tristate "USB Link Layer Test driver"
254+ help
255+ This driver is for generating specific traffic for Super Speed Link
256+ Layer Test Device. Say Y only when you want to conduct USB Super Speed
257+ Link Layer Test for host controllers.
drivers/usb/misc/Makefile+1−0
@@ -27,3 +27,4 @@ obj-$(CONFIG_USB_YUREX) += yurex.o · 26 unmodified lines
2727 obj-$(CONFIG_USB_HSIC_USB3503) += usb3503.o
2828
2929 obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/
30+obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
drivers/usb/misc/lvstest.c+460−0
@@ -0,0 +1,460 @@
1+/*
2+ * drivers/usb/misc/lvstest.c
3+ *
4+ * Test pattern generation for Link Layer Validation System Tests
5+ *
6+ * Copyright (C) 2014 ST Microelectronics
7+ * Pratyush Anand <pratyush.anand@st.com>
8+ *
9+ * This file is licensed under the terms of the GNU General Public
10+ * License version 2. This program is licensed "as is" without any
11+ * warranty of any kind, whether express or implied.
12+ */
13+
14+#include <linux/init.h>
15+#include <linux/kernel.h>
16+#include <linux/module.h>
17+#include <linux/platform_device.h>
18+#include <linux/slab.h>
19+#include <linux/usb.h>
20+#include <linux/usb/ch11.h>
21+#include <linux/usb/hcd.h>
22+#include <linux/usb/phy.h>
23+
24+struct lvs_rh {
25+ /* root hub interface */
26+ struct usb_interface *intf;
27+ /* if lvs device connected */
28+ bool present;
29+ /* port no at which lvs device is present */
30+ int portnum;
31+ /* urb buffer */
32+ u8 buffer[8];
33+ /* class descriptor */
34+ struct usb_hub_descriptor descriptor;
35+ /* urb for polling interrupt pipe */
36+ struct urb *urb;
37+ /* LVS RH work queue */
38+ struct workqueue_struct *rh_queue;
39+ /* LVH RH work */
40+ struct work_struct rh_work;
41+ /* RH port status */
42+ struct usb_port_status port_status;
43+};
44+
45+static struct usb_device *create_lvs_device(struct usb_interface *intf)
46+{
47+ struct usb_device *udev, *hdev;
48+ struct usb_hcd *hcd;
49+ struct lvs_rh *lvs = usb_get_intfdata(intf);
50+
51+ if (!lvs->present) {
52+ dev_err(&intf->dev, "No LVS device is present\n");
53+ return NULL;
54+ }
55+
56+ hdev = interface_to_usbdev(intf);
57+ hcd = bus_to_hcd(hdev->bus);
58+
59+ udev = usb_alloc_dev(hdev, hdev->bus, lvs->portnum);
60+ if (!udev) {
61+ dev_err(&intf->dev, "Could not allocate lvs udev\n");
62+ return NULL;
63+ }
64+ udev->speed = USB_SPEED_SUPER;
65+ udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512);
66+ usb_set_device_state(udev, USB_STATE_DEFAULT);
67+
68+ if (hcd->driver->enable_device) {
69+ if (hcd->driver->enable_device(hcd, udev) < 0) {
70+ dev_err(&intf->dev, "Failed to enable\n");
71+ usb_put_dev(udev);
72+ return NULL;
73+ }
74+ }
75+
76+ return udev;
77+}
78+
79+static void destroy_lvs_device(struct usb_device *udev)
80+{
81+ struct usb_device *hdev = udev->parent;
82+ struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
83+
84+ if (hcd->driver->free_dev)
85+ hcd->driver->free_dev(hcd, udev);
86+
87+ usb_put_dev(udev);
88+}
89+
90+static int lvs_rh_clear_port_feature(struct usb_device *hdev,
91+ int port1, int feature)
92+{
93+ return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
94+ USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port1,
95+ NULL, 0, 1000);
96+}
97+
98+static int lvs_rh_set_port_feature(struct usb_device *hdev,
99+ int port1, int feature)
100+{
101+ return usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
102+ USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port1,
103+ NULL, 0, 1000);
104+}
105+
106+static ssize_t u3_entry_store(struct device *dev,
107+ struct device_attribute *attr, const char *buf, size_t count)
108+{
109+ struct usb_interface *intf = to_usb_interface(dev);
110+ struct usb_device *hdev = interface_to_usbdev(intf);
111+ struct lvs_rh *lvs = usb_get_intfdata(intf);
112+ struct usb_device *udev;
113+ int ret;
114+
115+ udev = create_lvs_device(intf);
116+ if (!udev) {
117+ dev_err(dev, "failed to create lvs device\n");
118+ return -ENOMEM;
119+ }
120+
121+ ret = lvs_rh_set_port_feature(hdev, lvs->portnum,
122+ USB_PORT_FEAT_SUSPEND);
123+ if (ret < 0)
124+ dev_err(dev, "can't issue U3 entry %d\n", ret);
125+
126+ destroy_lvs_device(udev);
127+
128+ if (ret < 0)
129+ return ret;
130+
131+ return count;
132+}
133+static DEVICE_ATTR_WO(u3_entry);
134+
135+static ssize_t u3_exit_store(struct device *dev,
136+ struct device_attribute *attr, const char *buf, size_t count)
137+{
138+ struct usb_interface *intf = to_usb_interface(dev);
139+ struct usb_device *hdev = interface_to_usbdev(intf);
140+ struct lvs_rh *lvs = usb_get_intfdata(intf);
141+ struct usb_device *udev;
142+ int ret;
143+
144+ udev = create_lvs_device(intf);
145+ if (!udev) {
146+ dev_err(dev, "failed to create lvs device\n");
147+ return -ENOMEM;
148+ }
149+
150+ ret = lvs_rh_clear_port_feature(hdev, lvs->portnum,
151+ USB_PORT_FEAT_SUSPEND);
152+ if (ret < 0)
153+ dev_err(dev, "can't issue U3 exit %d\n", ret);
154+
155+ destroy_lvs_device(udev);
156+
157+ if (ret < 0)
158+ return ret;
159+
160+ return count;
161+}
162+static DEVICE_ATTR_WO(u3_exit);
163+
164+static ssize_t hot_reset_store(struct device *dev,
165+ struct device_attribute *attr, const char *buf, size_t count)
166+{
167+ struct usb_interface *intf = to_usb_interface(dev);
168+ struct usb_device *hdev = interface_to_usbdev(intf);
169+ struct lvs_rh *lvs = usb_get_intfdata(intf);
170+ int ret;
171+
172+ ret = lvs_rh_set_port_feature(hdev, lvs->portnum,
173+ USB_PORT_FEAT_RESET);
174+ if (ret < 0) {
175+ dev_err(dev, "can't issue hot reset %d\n", ret);
176+ return ret;
177+ }
178+
179+ return count;
180+}
181+static DEVICE_ATTR_WO(hot_reset);
182+
183+static ssize_t u2_timeout_store(struct device *dev,
184+ struct device_attribute *attr, const char *buf, size_t count)
185+{
186+ struct usb_interface *intf = to_usb_interface(dev);
187+ struct usb_device *hdev = interface_to_usbdev(intf);
188+ struct lvs_rh *lvs = usb_get_intfdata(intf);
189+ unsigned long val;
190+ int ret;
191+
192+ ret = kstrtoul(buf, 10, &val);
193+ if (ret < 0) {
194+ dev_err(dev, "couldn't parse string %d\n", ret);
195+ return ret;
196+ }
197+
198+ if (val < 0 || val > 127)
199+ return -EINVAL;
200+
201+ ret = lvs_rh_set_port_feature(hdev, lvs->portnum | (val << 8),
202+ USB_PORT_FEAT_U2_TIMEOUT);
203+ if (ret < 0) {
204+ dev_err(dev, "Error %d while setting U2 timeout %ld\n", ret, val);
205+ return ret;
206+ }
207+
208+ return count;
209+}
210+static DEVICE_ATTR_WO(u2_timeout);
211+
212+static ssize_t u1_timeout_store(struct device *dev,
213+ struct device_attribute *attr, const char *buf, size_t count)
214+{
215+ struct usb_interface *intf = to_usb_interface(dev);
216+ struct usb_device *hdev = interface_to_usbdev(intf);
217+ struct lvs_rh *lvs = usb_get_intfdata(intf);
218+ unsigned long val;
219+ int ret;
220+
221+ ret = kstrtoul(buf, 10, &val);
222+ if (ret < 0) {
223+ dev_err(dev, "couldn't parse string %d\n", ret);
224+ return ret;
225+ }
226+
227+ if (val < 0 || val > 127)
228+ return -EINVAL;
229+
230+ ret = lvs_rh_set_port_feature(hdev, lvs->portnum | (val << 8),
231+ USB_PORT_FEAT_U1_TIMEOUT);
232+ if (ret < 0) {
233+ dev_err(dev, "Error %d while setting U1 timeout %ld\n", ret, val);
234+ return ret;
235+ }
236+
237+ return count;
238+}
239+static DEVICE_ATTR_WO(u1_timeout);
240+
241+static ssize_t get_dev_desc_store(struct device *dev,
242+ struct device_attribute *attr, const char *buf, size_t count)
243+{
244+ struct usb_interface *intf = to_usb_interface(dev);
245+ struct usb_device *udev;
246+ struct usb_device_descriptor *descriptor;
247+ int ret;
248+
249+ descriptor = kmalloc(sizeof(*descriptor), GFP_KERNEL);
250+ if (!descriptor) {
251+ dev_err(dev, "failed to allocate descriptor memory\n");
252+ return -ENOMEM;
253+ }
254+
255+ udev = create_lvs_device(intf);
256+ if (!udev) {
257+ dev_err(dev, "failed to create lvs device\n");
258+ ret = -ENOMEM;
259+ goto free_desc;
260+ }
261+
262+ ret = usb_control_msg(udev, (PIPE_CONTROL << 30) | USB_DIR_IN,
263+ USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, USB_DT_DEVICE << 8,
264+ 0, descriptor, sizeof(*descriptor),
265+ USB_CTRL_GET_TIMEOUT);
266+ if (ret < 0)
267+ dev_err(dev, "can't read device descriptor %d\n", ret);
268+
269+ destroy_lvs_device(udev);
270+
271+free_desc:
272+ kfree(descriptor);
273+
274+ if (ret < 0)
275+ return ret;
276+
277+ return count;
278+}
279+static DEVICE_ATTR_WO(get_dev_desc);
280+
281+static struct attribute *lvs_attributes[] = {
282+ &dev_attr_get_dev_desc.attr,
283+ &dev_attr_u1_timeout.attr,
284+ &dev_attr_u2_timeout.attr,
285+ &dev_attr_hot_reset.attr,
286+ &dev_attr_u3_entry.attr,
287+ &dev_attr_u3_exit.attr,
288+ NULL
289+};
290+
291+static const struct attribute_group lvs_attr_group = {
292+ .attrs = lvs_attributes,
293+};
294+
295+static void lvs_rh_work(struct work_struct *work)
296+{
297+ struct lvs_rh *lvs = container_of(work, struct lvs_rh, rh_work);
298+ struct usb_interface *intf = lvs->intf;
299+ struct usb_device *hdev = interface_to_usbdev(intf);
300+ struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
301+ struct usb_hub_descriptor *descriptor = &lvs->descriptor;
302+ struct usb_port_status *port_status = &lvs->port_status;
303+ int i, ret = 0;
304+ u16 portchange;
305+
306+ /* Examine each root port */
307+ for (i = 1; i <= descriptor->bNbrPorts; i++) {
308+ ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
309+ USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, i,
310+ port_status, sizeof(*port_status), 1000);
311+ if (ret < 4)
312+ continue;
313+
314+ portchange = le16_to_cpu(port_status->wPortChange);
315+
316+ if (portchange & USB_PORT_STAT_C_LINK_STATE)
317+ lvs_rh_clear_port_feature(hdev, i,
318+ USB_PORT_FEAT_C_PORT_LINK_STATE);
319+ if (portchange & USB_PORT_STAT_C_ENABLE)
320+ lvs_rh_clear_port_feature(hdev, i,
321+ USB_PORT_FEAT_C_ENABLE);
322+ if (portchange & USB_PORT_STAT_C_RESET)
323+ lvs_rh_clear_port_feature(hdev, i,
324+ USB_PORT_FEAT_C_RESET);
325+ if (portchange & USB_PORT_STAT_C_BH_RESET)
326+ lvs_rh_clear_port_feature(hdev, i,
327+ USB_PORT_FEAT_C_BH_PORT_RESET);
328+ if (portchange & USB_PORT_STAT_C_CONNECTION) {
329+ lvs_rh_clear_port_feature(hdev, i,
330+ USB_PORT_FEAT_C_CONNECTION);
331+
332+ if (le16_to_cpu(port_status->wPortStatus) &
333+ USB_PORT_STAT_CONNECTION) {
334+ lvs->present = true;
335+ lvs->portnum = i;
336+ if (hcd->phy)
337+ usb_phy_notify_connect(hcd->phy,
338+ USB_SPEED_SUPER);
339+ } else {
340+ lvs->present = false;
341+ if (hcd->phy)
342+ usb_phy_notify_disconnect(hcd->phy,
343+ USB_SPEED_SUPER);
344+ }
345+ break;
346+ }
347+ }
348+
349+ ret = usb_submit_urb(lvs->urb, GFP_KERNEL);
350+ if (ret != 0 && ret != -ENODEV && ret != -EPERM)
351+ dev_err(&intf->dev, "urb resubmit error %d\n", ret);
352+}
353+
354+static void lvs_rh_irq(struct urb *urb)
355+{
356+ struct lvs_rh *lvs = urb->context;
357+
358+ queue_work(lvs->rh_queue, &lvs->rh_work);
359+}
360+
361+static int lvs_rh_probe(struct usb_interface *intf,
362+ const struct usb_device_id *id)
363+{
364+ struct usb_device *hdev;
365+ struct usb_host_interface *desc;
366+ struct usb_endpoint_descriptor *endpoint;
367+ struct lvs_rh *lvs;
368+ unsigned int pipe;
369+ int ret, maxp;
370+
371+ hdev = interface_to_usbdev(intf);
372+ desc = intf->cur_altsetting;
373+ endpoint = &desc->endpoint[0].desc;
374+
375+ /* valid only for SS root hub */
376+ if (hdev->descriptor.bDeviceProtocol != USB_HUB_PR_SS || hdev->parent) {
377+ dev_err(&intf->dev, "Bind LVS driver with SS root Hub only\n");
378+ return -EINVAL;
379+ }
380+
381+ lvs = devm_kzalloc(&intf->dev, sizeof(*lvs), GFP_KERNEL);
382+ if (!lvs)
383+ return -ENOMEM;
384+
385+ lvs->intf = intf;
386+ usb_set_intfdata(intf, lvs);
387+
388+ /* how many number of ports this root hub has */
389+ ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
390+ USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB,
391+ USB_DT_SS_HUB << 8, 0, &lvs->descriptor,
392+ USB_DT_SS_HUB_SIZE, USB_CTRL_GET_TIMEOUT);
393+ if (ret < (USB_DT_HUB_NONVAR_SIZE + 2)) {
394+ dev_err(&hdev->dev, "wrong root hub descriptor read %d\n", ret);
395+ return ret;
396+ }
397+
398+ /* submit urb to poll interrupt endpoint */
399+ lvs->urb = usb_alloc_urb(0, GFP_KERNEL);
400+ if (!lvs->urb) {
401+ dev_err(&intf->dev, "couldn't allocate lvs urb\n");
402+ return -ENOMEM;
403+ }
404+
405+ lvs->rh_queue = create_singlethread_workqueue("lvs_rh_queue");
406+ if (!lvs->rh_queue) {
407+ dev_err(&intf->dev, "couldn't create workqueue\n");
408+ ret = -ENOMEM;
409+ goto free_urb;
410+ }
411+
412+ INIT_WORK(&lvs->rh_work, lvs_rh_work);
413+
414+ ret = sysfs_create_group(&intf->dev.kobj, &lvs_attr_group);
415+ if (ret < 0) {
416+ dev_err(&intf->dev, "Failed to create sysfs node %d\n", ret);
417+ goto destroy_queue;
418+ }
419+
420+ pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress);
421+ maxp = usb_maxpacket(hdev, pipe, usb_pipeout(pipe));
422+ usb_fill_int_urb(lvs->urb, hdev, pipe, &lvs->buffer[0], maxp,
423+ lvs_rh_irq, lvs, endpoint->bInterval);
424+
425+ ret = usb_submit_urb(lvs->urb, GFP_KERNEL);
426+ if (ret < 0) {
427+ dev_err(&intf->dev, "couldn't submit lvs urb %d\n", ret);
428+ goto sysfs_remove;
429+ }
430+
431+ return ret;
432+
433+sysfs_remove:
434+ sysfs_remove_group(&intf->dev.kobj, &lvs_attr_group);
435+destroy_queue:
436+ destroy_workqueue(lvs->rh_queue);
437+free_urb:
438+ usb_free_urb(lvs->urb);
439+ return ret;
440+}
441+
442+static void lvs_rh_disconnect(struct usb_interface *intf)
443+{
444+ struct lvs_rh *lvs = usb_get_intfdata(intf);
445+
446+ sysfs_remove_group(&intf->dev.kobj, &lvs_attr_group);
447+ destroy_workqueue(lvs->rh_queue);
448+ usb_free_urb(lvs->urb);
449+}
450+
451+static struct usb_driver lvs_driver = {
452+ .name = "lvs",
453+ .probe = lvs_rh_probe,
454+ .disconnect = lvs_rh_disconnect,
455+};
456+
457+module_usb_driver(lvs_driver);
458+
459+MODULE_DESCRIPTION("Link Layer Validation System Driver");
460+MODULE_LICENSE("GPL");
drivers/usb/misc/usb3503.c+34−3
@@ -149,8 +149,6 @@ static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode) · 148 unmodified lines
149149
150150 case USB3503_MODE_STANDBY:
151151 usb3503_reset(hub, 0);
152−
153− hub->mode = mode;
154152 dev_info(dev, "switched to STANDBY mode\n");
155153 break;
156154
@@ -192,7 +190,8 @@ static int usb3503_probe(struct usb3503 *hub) · 35 unmodified lines
192190
193191 clk = devm_clk_get(dev, "refclk");
194192 if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) {
195− dev_err(dev, "unable to request refclk (%d)\n", err);
193+ dev_err(dev, "unable to request refclk (%ld)\n",
194+ PTR_ERR(clk));
196195 return PTR_ERR(clk);
197196 }
198197
@@ -346,6 +345,37 @@ static int usb3503_platform_probe(struct platform_device *pdev) · 147 unmodified lines
346345 return usb3503_probe(hub);
347346 }
348347
348+#ifdef CONFIG_PM_SLEEP
349+static int usb3503_i2c_suspend(struct device *dev)
350+{
351+ struct i2c_client *client = to_i2c_client(dev);
352+ struct usb3503 *hub = i2c_get_clientdata(client);
353+
354+ usb3503_switch_mode(hub, USB3503_MODE_STANDBY);
355+
356+ if (hub->clk)
357+ clk_disable_unprepare(hub->clk);
358+
359+ return 0;
360+}
361+
362+static int usb3503_i2c_resume(struct device *dev)
363+{
364+ struct i2c_client *client = to_i2c_client(dev);
365+ struct usb3503 *hub = i2c_get_clientdata(client);
366+
367+ if (hub->clk)
368+ clk_prepare_enable(hub->clk);
369+
370+ usb3503_switch_mode(hub, hub->mode);
371+
372+ return 0;
373+}
374+#endif
375+
376+static SIMPLE_DEV_PM_OPS(usb3503_i2c_pm_ops, usb3503_i2c_suspend,
377+ usb3503_i2c_resume);
378+
349379 static const struct i2c_device_id usb3503_id[] = {
350380 { USB3503_I2C_NAME, 0 },
351381 { }
@@ -364,6 +394,7 @@ MODULE_DEVICE_TABLE(of, usb3503_of_match); · 12 unmodified lines
364394 static struct i2c_driver usb3503_i2c_driver = {
365395 .driver = {
366396 .name = USB3503_I2C_NAME,
397+ .pm = &usb3503_i2c_pm_ops,
367398 .of_match_table = of_match_ptr(usb3503_of_match),
368399 },
369400 .probe = usb3503_i2c_probe,
drivers/usb/musb/blackfin.c+8−12
@@ -455,7 +455,7 @@ static int bfin_probe(struct platform_device *pdev) · 454 unmodified lines
455455
456456 int ret = -ENOMEM;
457457
458− glue = kzalloc(sizeof(*glue), GFP_KERNEL);
458+ glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
459459 if (!glue) {
460460 dev_err(&pdev->dev, "failed to allocate glue context\n");
461461 goto err0;
@@ -464,7 +464,7 @@ static int bfin_probe(struct platform_device *pdev) · 2 unmodified lines
464464 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
465465 if (!musb) {
466466 dev_err(&pdev->dev, "failed to allocate musb device\n");
467− goto err1;
467+ goto err0;
468468 }
469469
470470 musb->dev.parent = &pdev->dev;
@@ -478,7 +478,7 @@ static int bfin_probe(struct platform_device *pdev) · 7 unmodified lines
478478
479479 glue->phy = usb_phy_generic_register();
480480 if (IS_ERR(glue->phy))
481− goto err2;
481+ goto err1;
482482 platform_set_drvdata(pdev, glue);
483483
484484 memset(musb_resources, 0x00, sizeof(*musb_resources) *
@@ -498,31 +498,28 @@ static int bfin_probe(struct platform_device *pdev) · 13 unmodified lines
498498 ARRAY_SIZE(musb_resources));
499499 if (ret) {
500500 dev_err(&pdev->dev, "failed to add resources\n");
501− goto err3;
501+ goto err2;
502502 }
503503
504504 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
505505 if (ret) {
506506 dev_err(&pdev->dev, "failed to add platform_data\n");
507− goto err3;
507+ goto err2;
508508 }
509509
510510 ret = platform_device_add(musb);
511511 if (ret) {
512512 dev_err(&pdev->dev, "failed to register musb device\n");
513− goto err3;
513+ goto err2;
514514 }
515515
516516 return 0;
517517
518−err3:
519− usb_phy_generic_unregister(glue->phy);
520−
521518 err2:
522− platform_device_put(musb);
519+ usb_phy_generic_unregister(glue->phy);
523520
524521 err1:
525− kfree(glue);
522+ platform_device_put(musb);
526523
527524 err0:
528525 return ret;
@@ -534,7 +531,6 @@ static int bfin_remove(struct platform_device *pdev) · 5 unmodified lines
534531
535532 platform_device_unregister(glue->musb);
536533 usb_phy_generic_unregister(glue->phy);
537− kfree(glue);
538534
539535 return 0;
540536 }
drivers/usb/musb/davinci.c+6−14
@@ -519,23 +519,23 @@ static int davinci_probe(struct platform_device *pdev) · 518 unmodified lines
519519
520520 int ret = -ENOMEM;
521521
522− glue = kzalloc(sizeof(*glue), GFP_KERNEL);
522+ glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
523523 if (!glue) {
524524 dev_err(&pdev->dev, "failed to allocate glue context\n");
525525 goto err0;
526526 }
527527
528− clk = clk_get(&pdev->dev, "usb");
528+ clk = devm_clk_get(&pdev->dev, "usb");
529529 if (IS_ERR(clk)) {
530530 dev_err(&pdev->dev, "failed to get clock\n");
531531 ret = PTR_ERR(clk);
532− goto err3;
532+ goto err0;
533533 }
534534
535535 ret = clk_enable(clk);
536536 if (ret) {
537537 dev_err(&pdev->dev, "failed to enable clock\n");
538− goto err4;
538+ goto err0;
539539 }
540540
541541 glue->dev = &pdev->dev;
@@ -579,20 +579,14 @@ static int davinci_probe(struct platform_device *pdev) · 37 unmodified lines
579579 if (IS_ERR(musb)) {
580580 ret = PTR_ERR(musb);
581581 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
582− goto err5;
582+ goto err1;
583583 }
584584
585585 return 0;
586586
587−err5:
587+err1:
588588 clk_disable(clk);
589589
590−err4:
591− clk_put(clk);
592−
593−err3:
594− kfree(glue);
595−
596590 err0:
597591 return ret;
598592 }
@@ -604,8 +598,6 @@ static int davinci_remove(struct platform_device *pdev) · 5 unmodified lines
604598 platform_device_unregister(glue->musb);
605599 usb_phy_generic_unregister();
606600 clk_disable(glue->clk);
607− clk_put(glue->clk);
608− kfree(glue);
609601
610602 return 0;
611603 }
drivers/usb/musb/jz4740.c+3−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <linux/kernel.h>
2020 #include <linux/module.h>
2121 #include <linux/platform_device.h>
22+#include <linux/usb/usb_phy_generic.h>
2223
2324 #include "musb_core.h"
2425
@@ -80,6 +81,7 @@ static struct musb_hdrc_platform_data jz4740_musb_platform_data = { · 55 unmodified lines
8081
8182 static int jz4740_musb_init(struct musb *musb)
8283 {
84+ usb_phy_generic_register();
8385 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
8486 if (!musb->xceiv) {
8587 pr_err("HS UDC: no transceiver configured\n");
@@ -182,6 +184,7 @@ static int jz4740_remove(struct platform_device *pdev) · 96 unmodified lines
182184 struct jz4740_glue *glue = platform_get_drvdata(pdev);
183185
184186 platform_device_unregister(glue->musb);
187+ usb_phy_generic_unregister(pdev);
185188 clk_disable_unprepare(glue->clk);
186189
187190 return 0;
drivers/usb/musb/musb_core.c+21−20
@@ -850,7 +850,8 @@ b_host: · 849 unmodified lines
850850
851851 /* handle babble condition */
852852 if (int_usb & MUSB_INTR_BABBLE && is_host_active(musb))
853− schedule_work(&musb->recover_work);
853+ schedule_delayed_work(&musb->recover_work,
854+ msecs_to_jiffies(100));
854855
855856 #if 0
856857 /* REVISIT ... this would be for multiplexing periodic endpoints, or
@@ -1517,7 +1518,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 660 unmodified lines
15171518 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
15181519
15191520 dev_dbg(musb->controller, "** IRQ %s usb%04x tx%04x rx%04x\n",
1520− (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
1521+ is_host_active(musb) ? "host" : "peripheral",
15211522 musb->int_usb, musb->int_tx, musb->int_rx);
15221523
15231524 /* the core can interrupt us for multiple reasons; docs have
@@ -1531,7 +1532,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 7 unmodified lines
15311532
15321533 /* handle endpoint 0 first */
15331534 if (musb->int_tx & 1) {
1534− if (devctl & MUSB_DEVCTL_HM)
1535+ if (is_host_active(musb))
15351536 retval |= musb_h_ep0_irq(musb);
15361537 else
15371538 retval |= musb_g_ep0_irq(musb);
@@ -1545,7 +1546,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 7 unmodified lines
15451546 /* musb_ep_select(musb->mregs, ep_num); */
15461547 /* REVISIT just retval = ep->rx_irq(...) */
15471548 retval = IRQ_HANDLED;
1548− if (devctl & MUSB_DEVCTL_HM)
1549+ if (is_host_active(musb))
15491550 musb_host_rx(musb, ep_num);
15501551 else
15511552 musb_g_rx(musb, ep_num);
@@ -1563,7 +1564,7 @@ irqreturn_t musb_interrupt(struct musb *musb) · 11 unmodified lines
15631564 /* musb_ep_select(musb->mregs, ep_num); */
15641565 /* REVISIT just retval |= ep->tx_irq(...) */
15651566 retval = IRQ_HANDLED;
1566− if (devctl & MUSB_DEVCTL_HM)
1567+ if (is_host_active(musb))
15671568 musb_host_tx(musb, ep_num);
15681569 else
15691570 musb_g_tx(musb, ep_num);
@@ -1585,15 +1586,13 @@ MODULE_PARM_DESC(use_dma, "enable/disable use of DMA"); · 15 unmodified lines
15851586
15861587 void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
15871588 {
1588− u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
1589−
15901589 /* called with controller lock already held */
15911590
15921591 if (!epnum) {
15931592 #ifndef CONFIG_USB_TUSB_OMAP_DMA
15941593 if (!is_cppi_enabled()) {
15951594 /* endpoint 0 */
1596− if (devctl & MUSB_DEVCTL_HM)
1595+ if (is_host_active(musb))
15971596 musb_h_ep0_irq(musb);
15981597 else
15991598 musb_g_ep0_irq(musb);
@@ -1602,13 +1601,13 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit) · 2 unmodified lines
16021601 } else {
16031602 /* endpoints 1..15 */
16041603 if (transmit) {
1605− if (devctl & MUSB_DEVCTL_HM)
1604+ if (is_host_active(musb))
16061605 musb_host_tx(musb, epnum);
16071606 else
16081607 musb_g_tx(musb, epnum);
16091608 } else {
16101609 /* receive */
1611− if (devctl & MUSB_DEVCTL_HM)
1610+ if (is_host_active(musb))
16121611 musb_host_rx(musb, epnum);
16131612 else
16141613 musb_g_rx(musb, epnum);
@@ -1753,20 +1752,22 @@ static void musb_irq_work(struct work_struct *data) · 138 unmodified lines
17531752 /* Recover from babble interrupt conditions */
17541753 static void musb_recover_work(struct work_struct *data)
17551754 {
1756− struct musb *musb = container_of(data, struct musb, recover_work);
1757− int status;
1755+ struct musb *musb = container_of(data, struct musb, recover_work.work);
1756+ int status, ret;
17581757
1759− musb_platform_reset(musb);
1758+ ret = musb_platform_reset(musb);
1759+ if (ret)
1760+ return;
17601761
17611762 usb_phy_vbus_off(musb->xceiv);
1762− udelay(100);
1763+ usleep_range(100, 200);
17631764
17641765 usb_phy_vbus_on(musb->xceiv);
1765− udelay(100);
1766+ usleep_range(100, 200);
17661767
17671768 /*
1768− * When a babble condition occurs, the musb controller removes the
1769− * session bit and the endpoint config is lost.
1769+ * When a babble condition occurs, the musb controller
1770+ * removes the session bit and the endpoint config is lost.
17701771 */
17711772 if (musb->dyn_fifo)
17721773 status = ep_config_from_table(musb);
@@ -1945,7 +1946,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) · 172 unmodified lines
19451946
19461947 /* Init IRQ workqueue before request_irq */
19471948 INIT_WORK(&musb->irq_work, musb_irq_work);
1948− INIT_WORK(&musb->recover_work, musb_recover_work);
1949+ INIT_DELAYED_WORK(&musb->recover_work, musb_recover_work);
19491950 INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset);
19501951 INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume);
19511952
@@ -2041,7 +2042,7 @@ fail4: · 89 unmodified lines
20412042
20422043 fail3:
20432044 cancel_work_sync(&musb->irq_work);
2044− cancel_work_sync(&musb->recover_work);
2045+ cancel_delayed_work_sync(&musb->recover_work);
20452046 cancel_delayed_work_sync(&musb->finish_resume_work);
20462047 cancel_delayed_work_sync(&musb->deassert_reset_work);
20472048 if (musb->dma_controller)
@@ -2107,7 +2108,7 @@ static int musb_remove(struct platform_device *pdev) · 59 unmodified lines
21072108 dma_controller_destroy(musb->dma_controller);
21082109
21092110 cancel_work_sync(&musb->irq_work);
2110− cancel_work_sync(&musb->recover_work);
2111+ cancel_delayed_work_sync(&musb->recover_work);
21112112 cancel_delayed_work_sync(&musb->finish_resume_work);
21122113 cancel_delayed_work_sync(&musb->deassert_reset_work);
21132114 musb_free(musb);
drivers/usb/musb/musb_core.h+7−5
@@ -192,7 +192,7 @@ struct musb_platform_ops { · 191 unmodified lines
192192
193193 int (*set_mode)(struct musb *musb, u8 mode);
194194 void (*try_idle)(struct musb *musb, unsigned long timeout);
195− void (*reset)(struct musb *musb);
195+ int (*reset)(struct musb *musb);
196196
197197 int (*vbus_status)(struct musb *musb);
198198 void (*set_vbus)(struct musb *musb, int on);
@@ -297,7 +297,7 @@ struct musb { · 98 unmodified lines
297297
298298 irqreturn_t (*isr)(int, void *);
299299 struct work_struct irq_work;
300− struct work_struct recover_work;
300+ struct delayed_work recover_work;
301301 struct delayed_work deassert_reset_work;
302302 struct delayed_work finish_resume_work;
303303 u16 hwvers;
@@ -555,10 +555,12 @@ static inline void musb_platform_try_idle(struct musb *musb, · 251 unmodified lines
555555 musb->ops->try_idle(musb, timeout);
556556 }
557557
558−static inline void musb_platform_reset(struct musb *musb)
558+static inline int musb_platform_reset(struct musb *musb)
559559 {
560− if (musb->ops->reset)
561− musb->ops->reset(musb);
560+ if (!musb->ops->reset)
561+ return -EINVAL;
562+
563+ return musb->ops->reset(musb);
562564 }
563565
564566 static inline int musb_platform_get_vbus_status(struct musb *musb)
drivers/usb/musb/musb_cppi41.c+13−57
@@ -39,7 +39,6 @@ struct cppi41_dma_channel { · 38 unmodified lines
3939 u32 transferred;
4040 u32 packet_sz;
4141 struct list_head tx_check;
42− struct work_struct dma_completion;
4342 };
4443
4544 #define MUSB_DMA_NUM_CHANNELS 15
@@ -74,15 +73,18 @@ static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel) · 28 unmodified lines
7473
7574 static void update_rx_toggle(struct cppi41_dma_channel *cppi41_channel)
7675 {
76+ struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep;
77+ struct musb *musb = hw_ep->musb;
7778 u16 csr;
7879 u8 toggle;
7980
8081 if (cppi41_channel->is_tx)
8182 return;
82− if (!is_host_active(cppi41_channel->controller->musb))
83+ if (!is_host_active(musb))
8384 return;
8485
85− csr = musb_readw(cppi41_channel->hw_ep->regs, MUSB_RXCSR);
86+ musb_ep_select(musb->mregs, hw_ep->epnum);
87+ csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
8688 toggle = csr & MUSB_RXCSR_H_DATATOGGLE ? 1 : 0;
8789
8890 /*
@@ -107,24 +109,13 @@ static bool musb_is_tx_fifo_empty(struct musb_hw_ep *hw_ep) · 18 unmodified lines
107109 void __iomem *epio = musb->endpoints[epnum].regs;
108110 u16 csr;
109111
112+ musb_ep_select(musb->mregs, hw_ep->epnum);
110113 csr = musb_readw(epio, MUSB_TXCSR);
111114 if (csr & MUSB_TXCSR_TXPKTRDY)
112115 return false;
113116 return true;
114117 }
115118
116−static bool is_isoc(struct musb_hw_ep *hw_ep, bool in)
117−{
118− if (in && hw_ep->in_qh) {
119− if (hw_ep->in_qh->type == USB_ENDPOINT_XFER_ISOC)
120− return true;
121− } else if (hw_ep->out_qh) {
122− if (hw_ep->out_qh->type == USB_ENDPOINT_XFER_ISOC)
123− return true;
124− }
125− return false;
126−}
127−
128119 static void cppi41_dma_callback(void *private_data);
129120
130121 static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel)
@@ -139,6 +130,7 @@ static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) · 8 unmodified lines
139130 cppi41_channel->channel.actual_len =
140131 cppi41_channel->transferred;
141132 cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE;
133+ cppi41_channel->channel.rx_packet_done = true;
142134 musb_dma_completion(musb, hw_ep->epnum, cppi41_channel->is_tx);
143135 } else {
144136 /* next iteration, reload */
@@ -172,6 +164,7 @@ static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) · 27 unmodified lines
172164 dma_async_issue_pending(dc);
173165
174166 if (!cppi41_channel->is_tx) {
167+ musb_ep_select(musb->mregs, hw_ep->epnum);
175168 csr = musb_readw(epio, MUSB_RXCSR);
176169 csr |= MUSB_RXCSR_H_REQPKT;
177170 musb_writew(epio, MUSB_RXCSR, csr);
@@ -179,32 +172,6 @@ static void cppi41_trans_done(struct cppi41_dma_channel *cppi41_channel) · 1 unmodified line
179172 }
180173 }
181174
182−static void cppi_trans_done_work(struct work_struct *work)
183−{
184− unsigned long flags;
185− struct cppi41_dma_channel *cppi41_channel =
186− container_of(work, struct cppi41_dma_channel, dma_completion);
187− struct cppi41_dma_controller *controller = cppi41_channel->controller;
188− struct musb *musb = controller->musb;
189− struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep;
190− bool empty;
191−
192− if (!cppi41_channel->is_tx && is_isoc(hw_ep, 1)) {
193− spin_lock_irqsave(&musb->lock, flags);
194− cppi41_trans_done(cppi41_channel);
195− spin_unlock_irqrestore(&musb->lock, flags);
196− } else {
197− empty = musb_is_tx_fifo_empty(hw_ep);
198− if (empty) {
199− spin_lock_irqsave(&musb->lock, flags);
200− cppi41_trans_done(cppi41_channel);
201− spin_unlock_irqrestore(&musb->lock, flags);
202− } else {
203− schedule_work(&cppi41_channel->dma_completion);
204− }
205− }
206−}
207−
208175 static enum hrtimer_restart cppi41_recheck_tx_req(struct hrtimer *timer)
209176 {
210177 struct cppi41_dma_controller *controller;
@@ -233,7 +200,7 @@ static enum hrtimer_restart cppi41_recheck_tx_req(struct hrtimer *timer) · 22 unmodified lines
233200 if (!list_empty(&controller->early_tx_list)) {
234201 ret = HRTIMER_RESTART;
235202 hrtimer_forward_now(&controller->early_tx,
236− ktime_set(0, 150 * NSEC_PER_USEC));
203+ ktime_set(0, 50 * NSEC_PER_USEC));
237204 }
238205
239206 spin_unlock_irqrestore(&musb->lock, flags);
@@ -268,14 +235,6 @@ static void cppi41_dma_callback(void *private_data) · 28 unmodified lines
268235 transferred < cppi41_channel->packet_sz)
269236 cppi41_channel->prog_len = 0;
270237
271− if (!cppi41_channel->is_tx) {
272− if (is_isoc(hw_ep, 1))
273− schedule_work(&cppi41_channel->dma_completion);
274− else
275− cppi41_trans_done(cppi41_channel);
276− goto out;
277− }
278−
279238 empty = musb_is_tx_fifo_empty(hw_ep);
280239 if (empty) {
281240 cppi41_trans_done(cppi41_channel);
@@ -312,15 +271,13 @@ static void cppi41_dma_callback(void *private_data) · 30 unmodified lines
312271 goto out;
313272 }
314273 }
315− if (is_isoc(hw_ep, 0)) {
316− schedule_work(&cppi41_channel->dma_completion);
317− goto out;
318− }
319274 list_add_tail(&cppi41_channel->tx_check,
320275 &controller->early_tx_list);
321276 if (!hrtimer_is_queued(&controller->early_tx)) {
277+ unsigned long usecs = cppi41_channel->total_len / 10;
278+
322279 hrtimer_start_range_ns(&controller->early_tx,
323− ktime_set(0, 140 * NSEC_PER_USEC),
280+ ktime_set(0, usecs * NSEC_PER_USEC),
324281 40 * NSEC_PER_USEC,
325282 HRTIMER_MODE_REL);
326283 }
@@ -450,6 +407,7 @@ static bool cppi41_configure_channel(struct dma_channel *channel, · 123 unmodified lines
450407 dma_desc->callback = cppi41_dma_callback;
451408 dma_desc->callback_param = channel;
452409 cppi41_channel->cookie = dma_desc->tx_submit(dma_desc);
410+ cppi41_channel->channel.rx_packet_done = false;
453411
454412 save_rx_toggle(cppi41_channel);
455413 dma_async_issue_pending(dc);
@@ -672,8 +630,6 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) · 216 unmodified lines
672630 cppi41_channel->port_num = port;
673631 cppi41_channel->is_tx = is_tx;
674632 INIT_LIST_HEAD(&cppi41_channel->tx_check);
675− INIT_WORK(&cppi41_channel->dma_completion,
676− cppi_trans_done_work);
677633
678634 musb_dma = &cppi41_channel->channel;
679635 musb_dma->private_data = cppi41_channel;
drivers/usb/musb/musb_dma.h+1−0
@@ -129,6 +129,7 @@ struct dma_channel { · 128 unmodified lines
129129 size_t actual_len;
130130 enum dma_channel_status status;
131131 bool desired_mode;
132+ bool rx_packet_done;
132133 };
133134
134135 /*
drivers/usb/musb/musb_dsps.c+97−7
@@ -56,16 +56,24 @@ static const struct of_device_id musb_dsps_of_match[]; · 55 unmodified lines
5656 * dependent on musb core layer symbols.
5757 */
5858 static inline u8 dsps_readb(const void __iomem *addr, unsigned offset)
59− { return __raw_readb(addr + offset); }
59+{
60+ return __raw_readb(addr + offset);
61+}
6062
6163 static inline u32 dsps_readl(const void __iomem *addr, unsigned offset)
62− { return __raw_readl(addr + offset); }
64+{
65+ return __raw_readl(addr + offset);
66+}
6367
6468 static inline void dsps_writeb(void __iomem *addr, unsigned offset, u8 data)
65− { __raw_writeb(data, addr + offset); }
69+{
70+ __raw_writeb(data, addr + offset);
71+}
6672
6773 static inline void dsps_writel(void __iomem *addr, unsigned offset, u32 data)
68− { __raw_writel(data, addr + offset); }
74+{
75+ __raw_writel(data, addr + offset);
76+}
6977
7078 /**
7179 * DSPS musb wrapper register offset.
@@ -136,6 +144,7 @@ struct dsps_glue { · 64 unmodified lines
136144 const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
137145 struct timer_list timer; /* otg_workaround timer */
138146 unsigned long last_timer; /* last timer data for each instance */
147+ bool sw_babble_enabled;
139148
140149 struct dsps_context context;
141150 struct debugfs_regset32 regset;
@@ -469,6 +478,19 @@ static int dsps_musb_init(struct musb *musb) · 327 unmodified lines
469478 val &= ~(1 << wrp->otg_disable);
470479 dsps_writel(musb->ctrl_base, wrp->phy_utmi, val);
471480
481+ /*
482+ * Check whether the dsps version has babble control enabled.
483+ * In latest silicon revision the babble control logic is enabled.
484+ * If MUSB_BABBLE_CTL returns 0x4 then we have the babble control
485+ * logic enabled.
486+ */
487+ val = dsps_readb(musb->mregs, MUSB_BABBLE_CTL);
488+ if (val == MUSB_BABBLE_RCV_DISABLE) {
489+ glue->sw_babble_enabled = true;
490+ val |= MUSB_BABBLE_SW_SESSION_CTRL;
491+ dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, val);
492+ }
493+
472494 ret = dsps_musb_dbg_init(musb, glue);
473495 if (ret)
474496 return ret;
@@ -535,14 +557,82 @@ static int dsps_musb_set_mode(struct musb *musb, u8 mode) · 60 unmodified lines
535557 return 0;
536558 }
537559
538−static void dsps_musb_reset(struct musb *musb)
560+static bool sw_babble_control(struct musb *musb)
561+{
562+ u8 babble_ctl;
563+ bool session_restart = false;
564+
565+ babble_ctl = dsps_readb(musb->mregs, MUSB_BABBLE_CTL);
566+ dev_dbg(musb->controller, "babble: MUSB_BABBLE_CTL value %x\n",
567+ babble_ctl);
568+ /*
569+ * check line monitor flag to check whether babble is
570+ * due to noise
571+ */
572+ dev_dbg(musb->controller, "STUCK_J is %s\n",
573+ babble_ctl & MUSB_BABBLE_STUCK_J ? "set" : "reset");
574+
575+ if (babble_ctl & MUSB_BABBLE_STUCK_J) {
576+ int timeout = 10;
577+
578+ /*
579+ * babble is due to noise, then set transmit idle (d7 bit)
580+ * to resume normal operation
581+ */
582+ babble_ctl = dsps_readb(musb->mregs, MUSB_BABBLE_CTL);
583+ babble_ctl |= MUSB_BABBLE_FORCE_TXIDLE;
584+ dsps_writeb(musb->mregs, MUSB_BABBLE_CTL, babble_ctl);
585+
586+ /* wait till line monitor flag cleared */
587+ dev_dbg(musb->controller, "Set TXIDLE, wait J to clear\n");
588+ do {
589+ babble_ctl = dsps_readb(musb->mregs, MUSB_BABBLE_CTL);
590+ udelay(1);
591+ } while ((babble_ctl & MUSB_BABBLE_STUCK_J) && timeout--);
592+
593+ /* check whether stuck_at_j bit cleared */
594+ if (babble_ctl & MUSB_BABBLE_STUCK_J) {
595+ /*
596+ * real babble condition has occurred
597+ * restart the controller to start the
598+ * session again
599+ */
600+ dev_dbg(musb->controller, "J not cleared, misc (%x)\n",
601+ babble_ctl);
602+ session_restart = true;
603+ }
604+ } else {
605+ session_restart = true;
606+ }
607+
608+ return session_restart;
609+}
610+
611+static int dsps_musb_reset(struct musb *musb)
539612 {
540613 struct device *dev = musb->controller;
541614 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
542615 const struct dsps_musb_wrapper *wrp = glue->wrp;
616+ int session_restart = 0;
617+
618+ if (glue->sw_babble_enabled)
619+ session_restart = sw_babble_control(musb);
620+ /*
621+ * In case of new silicon version babble condition can be recovered
622+ * without resetting the MUSB. But for older silicon versions, MUSB
623+ * reset is needed
624+ */
625+ if (session_restart || !glue->sw_babble_enabled) {
626+ dev_info(musb->controller, "Restarting MUSB to recover from Babble\n");
627+ dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset));
628+ usleep_range(100, 200);
629+ usb_phy_shutdown(musb->xceiv);
630+ usleep_range(100, 200);
631+ usb_phy_init(musb->xceiv);
632+ session_restart = 1;
633+ }
543634
544− dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset));
545− udelay(100);
635+ return !session_restart;
546636 }
547637
548638 static struct musb_platform_ops dsps_ops = {
drivers/usb/musb/musb_host.c+10−9
@@ -120,7 +120,7 @@ static void musb_h_tx_flush_fifo(struct musb_hw_ep *ep) · 119 unmodified lines
120120 if (csr != lastcsr)
121121 dev_dbg(musb->controller, "Host TX FIFONOTEMPTY csr: %02x\n", csr);
122122 lastcsr = csr;
123− csr |= MUSB_TXCSR_FLUSHFIFO;
123+ csr |= MUSB_TXCSR_FLUSHFIFO | MUSB_TXCSR_TXPKTRDY;
124124 musb_writew(epio, MUSB_TXCSR, csr);
125125 csr = musb_readw(epio, MUSB_TXCSR);
126126 if (WARN(retries-- < 1,
@@ -1295,7 +1295,7 @@ done: · 1168 unmodified lines
12951295 if (status) {
12961296 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
12971297 dma->status = MUSB_DMA_STATUS_CORE_ABORT;
1298− (void) musb->dma_controller->channel_abort(dma);
1298+ musb->dma_controller->channel_abort(dma);
12991299 }
13001300
13011301 /* do the proper sequence to abort the transfer in the
@@ -1640,7 +1640,7 @@ void musb_host_rx(struct musb *musb, u8 epnum) · 338 unmodified lines
16401640 /* clean up dma and collect transfer count */
16411641 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
16421642 dma->status = MUSB_DMA_STATUS_CORE_ABORT;
1643− (void) musb->dma_controller->channel_abort(dma);
1643+ musb->dma_controller->channel_abort(dma);
16441644 xfer_len = dma->actual_len;
16451645 }
16461646 musb_h_flush_rxfifo(hw_ep, MUSB_RXCSR_CLRDATATOG);
@@ -1671,7 +1671,7 @@ void musb_host_rx(struct musb *musb, u8 epnum) · 24 unmodified lines
16711671 */
16721672 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
16731673 dma->status = MUSB_DMA_STATUS_CORE_ABORT;
1674− (void) musb->dma_controller->channel_abort(dma);
1674+ musb->dma_controller->channel_abort(dma);
16751675 xfer_len = dma->actual_len;
16761676 done = true;
16771677 }
@@ -1734,10 +1734,11 @@ void musb_host_rx(struct musb *musb, u8 epnum) · 56 unmodified lines
17341734 }
17351735
17361736 } else {
1737− /* done if urb buffer is full or short packet is recd */
1738− done = (urb->actual_length + xfer_len >=
1739− urb->transfer_buffer_length
1740− || dma->actual_len < qh->maxpacket);
1737+ /* done if urb buffer is full or short packet is recd */
1738+ done = (urb->actual_length + xfer_len >=
1739+ urb->transfer_buffer_length
1740+ || dma->actual_len < qh->maxpacket
1741+ || dma->rx_packet_done);
17411742 }
17421743
17431744 /* send IN token for next packet, without AUTOREQ */
@@ -1957,7 +1958,7 @@ static int musb_schedule( · 213 unmodified lines
19571958 struct musb_qh *qh,
19581959 int is_in)
19591960 {
1960− int idle;
1961+ int idle = 0;
19611962 int best_diff;
19621963 int best_end, epnum;
19631964 struct musb_hw_ep *hw_ep = NULL;
drivers/usb/musb/musb_regs.h+7−0
@@ -72,6 +72,12 @@ · 71 unmodified lines
7272 #define MUSB_DEVCTL_HR 0x02
7373 #define MUSB_DEVCTL_SESSION 0x01
7474
75+/* BABBLE_CTL */
76+#define MUSB_BABBLE_FORCE_TXIDLE 0x80
77+#define MUSB_BABBLE_SW_SESSION_CTRL 0x40
78+#define MUSB_BABBLE_STUCK_J 0x20
79+#define MUSB_BABBLE_RCV_DISABLE 0x04
80+
7581 /* MUSB ULPI VBUSCONTROL */
7682 #define MUSB_ULPI_USE_EXTVBUS 0x01
7783 #define MUSB_ULPI_USE_EXTVBUSIND 0x02
@@ -246,6 +252,7 @@ · 168 unmodified lines
246252 */
247253
248254 #define MUSB_DEVCTL 0x60 /* 8 bit */
255+#define MUSB_BABBLE_CTL 0x61 /* 8 bit */
249256
250257 /* These are always controlled through the INDEX register */
251258 #define MUSB_TXFIFOSZ 0x62 /* 8-bit (see masks) */
drivers/usb/musb/tusb6010.c+5−11
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include <linux/usb.h>
2323 #include <linux/irq.h>
2424 #include <linux/io.h>
25+#include <linux/device.h>
2526 #include <linux/platform_device.h>
2627 #include <linux/dma-mapping.h>
2728 #include <linux/usb/usb_phy_generic.h>
@@ -1160,12 +1161,12 @@ static int tusb_probe(struct platform_device *pdev) · 1132 unmodified lines
11601161 struct platform_device *musb;
11611162 struct tusb6010_glue *glue;
11621163 struct platform_device_info pinfo;
1163− int ret = -ENOMEM;
1164+ int ret;
11641165
1165− glue = kzalloc(sizeof(*glue), GFP_KERNEL);
1166+ glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
11661167 if (!glue) {
11671168 dev_err(&pdev->dev, "failed to allocate glue context\n");
1168− goto err0;
1169+ return -ENOMEM;
11691170 }
11701171
11711172 glue->dev = &pdev->dev;
@@ -1204,16 +1205,10 @@ static int tusb_probe(struct platform_device *pdev) · 32 unmodified lines
12041205 if (IS_ERR(musb)) {
12051206 ret = PTR_ERR(musb);
12061207 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
1207− goto err3;
1208+ return ret;
12081209 }
12091210
12101211 return 0;
1211−
1212−err3:
1213− kfree(glue);
1214−
1215−err0:
1216− return ret;
12171212 }
12181213
12191214 static int tusb_remove(struct platform_device *pdev)
@@ -1222,7 +1217,6 @@ static int tusb_remove(struct platform_device *pdev) · 2 unmodified lines
12221217
12231218 platform_device_unregister(glue->musb);
12241219 usb_phy_generic_unregister(glue->phy);
1225− kfree(glue);
12261220
12271221 return 0;
12281222 }
drivers/usb/musb/ux500.c+10−18
@@ -246,7 +246,7 @@ static int ux500_probe(struct platform_device *pdev) · 245 unmodified lines
246246 }
247247 }
248248
249− glue = kzalloc(sizeof(*glue), GFP_KERNEL);
249+ glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
250250 if (!glue) {
251251 dev_err(&pdev->dev, "failed to allocate glue context\n");
252252 goto err0;
@@ -255,20 +255,20 @@ static int ux500_probe(struct platform_device *pdev) · 2 unmodified lines
255255 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
256256 if (!musb) {
257257 dev_err(&pdev->dev, "failed to allocate musb device\n");
258− goto err1;
258+ goto err0;
259259 }
260260
261− clk = clk_get(&pdev->dev, NULL);
261+ clk = devm_clk_get(&pdev->dev, NULL);
262262 if (IS_ERR(clk)) {
263263 dev_err(&pdev->dev, "failed to get clock\n");
264264 ret = PTR_ERR(clk);
265− goto err3;
265+ goto err1;
266266 }
267267
268268 ret = clk_prepare_enable(clk);
269269 if (ret) {
270270 dev_err(&pdev->dev, "failed to enable clock\n");
271− goto err4;
271+ goto err1;
272272 }
273273
274274 musb->dev.parent = &pdev->dev;
@@ -301,34 +301,28 @@ static int ux500_probe(struct platform_device *pdev) · 26 unmodified lines
301301 ARRAY_SIZE(musb_resources));
302302 if (ret) {
303303 dev_err(&pdev->dev, "failed to add resources\n");
304− goto err5;
304+ goto err2;
305305 }
306306
307307 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
308308 if (ret) {
309309 dev_err(&pdev->dev, "failed to add platform_data\n");
310− goto err5;
310+ goto err2;
311311 }
312312
313313 ret = platform_device_add(musb);
314314 if (ret) {
315315 dev_err(&pdev->dev, "failed to register musb device\n");
316− goto err5;
316+ goto err2;
317317 }
318318
319319 return 0;
320320
321−err5:
321+err2:
322322 clk_disable_unprepare(clk);
323323
324−err4:
325− clk_put(clk);
326−
327−err3:
328− platform_device_put(musb);
329−
330324 err1:
331− kfree(glue);
325+ platform_device_put(musb);
332326
333327 err0:
334328 return ret;
@@ -340,8 +334,6 @@ static int ux500_remove(struct platform_device *pdev) · 5 unmodified lines
340334
341335 platform_device_unregister(glue->musb);
342336 clk_disable_unprepare(glue->clk);
343− clk_put(glue->clk);
344− kfree(glue);
345337
346338 return 0;
347339 }
drivers/usb/phy/phy-am335x.c+3−9
@@ -122,16 +122,10 @@ static int am335x_phy_resume(struct device *dev) · 121 unmodified lines
122122
123123 return 0;
124124 }
125−
126−static const struct dev_pm_ops am335x_pm_ops = {
127− SET_SYSTEM_SLEEP_PM_OPS(am335x_phy_suspend, am335x_phy_resume)
128−};
129−
130−#define DEV_PM_OPS (&am335x_pm_ops)
131−#else
132−#define DEV_PM_OPS NULL
133125 #endif
134126
127+static SIMPLE_DEV_PM_OPS(am335x_pm_ops, am335x_phy_suspend, am335x_phy_resume);
128+
135129 static const struct of_device_id am335x_phy_ids[] = {
136130 { .compatible = "ti,am335x-usb-phy" },
137131 { }
@@ -144,7 +138,7 @@ static struct platform_driver am335x_phy_driver = { · 6 unmodified lines
144138 .driver = {
145139 .name = "am335x-phy-driver",
146140 .owner = THIS_MODULE,
147− .pm = DEV_PM_OPS,
141+ .pm = &am335x_pm_ops,
148142 .of_match_table = am335x_phy_ids,
149143 },
150144 };
drivers/usb/phy/phy-gpio-vbus-usb.c+13−32
@@ -253,11 +253,13 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 252 unmodified lines
253253 return -EINVAL;
254254 gpio = pdata->gpio_vbus;
255255
256− gpio_vbus = kzalloc(sizeof(struct gpio_vbus_data), GFP_KERNEL);
256+ gpio_vbus = devm_kzalloc(&pdev->dev, sizeof(struct gpio_vbus_data),
257+ GFP_KERNEL);
257258 if (!gpio_vbus)
258259 return -ENOMEM;
259260
260− gpio_vbus->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL);
261+ gpio_vbus->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg),
262+ GFP_KERNEL);
261263 if (!gpio_vbus->phy.otg) {
262264 kfree(gpio_vbus);
263265 return -ENOMEM;
@@ -274,11 +276,11 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 10 unmodified lines
274276 gpio_vbus->phy.otg->phy = &gpio_vbus->phy;
275277 gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral;
276278
277− err = gpio_request(gpio, "vbus_detect");
279+ err = devm_gpio_request(&pdev->dev, gpio, "vbus_detect");
278280 if (err) {
279281 dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n",
280282 gpio, err);
281− goto err_gpio;
283+ return err;
282284 }
283285 gpio_direction_input(gpio);
284286
@@ -296,27 +298,27 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 11 unmodified lines
296298 /* if data line pullup is in use, initialize it to "not pulling up" */
297299 gpio = pdata->gpio_pullup;
298300 if (gpio_is_valid(gpio)) {
299− err = gpio_request(gpio, "udc_pullup");
301+ err = devm_gpio_request(&pdev->dev, gpio, "udc_pullup");
300302 if (err) {
301303 dev_err(&pdev->dev,
302304 "can't request pullup gpio %d, err: %d\n",
303305 gpio, err);
304− gpio_free(pdata->gpio_vbus);
305− goto err_gpio;
306+ return err;
306307 }
307308 gpio_direction_output(gpio, pdata->gpio_pullup_inverted);
308309 }
309310
310− err = request_irq(irq, gpio_vbus_irq, irqflags, "vbus_detect", pdev);
311+ err = devm_request_irq(&pdev->dev, irq, gpio_vbus_irq, irqflags,
312+ "vbus_detect", pdev);
311313 if (err) {
312314 dev_err(&pdev->dev, "can't request irq %i, err: %d\n",
313315 irq, err);
314− goto err_irq;
316+ return err;
315317 }
316318
317319 INIT_DELAYED_WORK(&gpio_vbus->work, gpio_vbus_work);
318320
319− gpio_vbus->vbus_draw = regulator_get(&pdev->dev, "vbus_draw");
321+ gpio_vbus->vbus_draw = devm_regulator_get(&pdev->dev, "vbus_draw");
320322 if (IS_ERR(gpio_vbus->vbus_draw)) {
321323 dev_dbg(&pdev->dev, "can't get vbus_draw regulator, err: %ld\n",
322324 PTR_ERR(gpio_vbus->vbus_draw));
@@ -328,44 +330,23 @@ static int gpio_vbus_probe(struct platform_device *pdev) · 5 unmodified lines
328330 if (err) {
329331 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
330332 err);
331− goto err_otg;
333+ return err;
332334 }
333335
334336 device_init_wakeup(&pdev->dev, pdata->wakeup);
335337
336338 return 0;
337−err_otg:
338− regulator_put(gpio_vbus->vbus_draw);
339− free_irq(irq, pdev);
340−err_irq:
341− if (gpio_is_valid(pdata->gpio_pullup))
342− gpio_free(pdata->gpio_pullup);
343− gpio_free(pdata->gpio_vbus);
344−err_gpio:
345− kfree(gpio_vbus->phy.otg);
346− kfree(gpio_vbus);
347− return err;
348339 }
349340
350341 static int gpio_vbus_remove(struct platform_device *pdev)
351342 {
352343 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev);
353− struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev);
354− int gpio = pdata->gpio_vbus;
355344
356345 device_init_wakeup(&pdev->dev, 0);
357346 cancel_delayed_work_sync(&gpio_vbus->work);
358− regulator_put(gpio_vbus->vbus_draw);
359347
360348 usb_remove_phy(&gpio_vbus->phy);
361349
362− free_irq(gpio_vbus->irq, pdev);
363− if (gpio_is_valid(pdata->gpio_pullup))
364− gpio_free(pdata->gpio_pullup);
365− gpio_free(gpio);
366− kfree(gpio_vbus->phy.otg);
367− kfree(gpio_vbus);
368−
369350 return 0;
370351 }
371352
drivers/usb/phy/phy-msm-usb.c+6−6
@@ -279,11 +279,11 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) · 278 unmodified lines
279279
280280 static int msm_otg_phy_clk_reset(struct msm_otg *motg)
281281 {
282− int ret;
282+ int ret = 0;
283283
284− if (motg->pdata->phy_clk_reset)
284+ if (motg->pdata->phy_clk_reset && motg->phy_reset_clk)
285285 ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk);
286− else
286+ else if (motg->phy_rst)
287287 ret = reset_control_reset(motg->phy_rst);
288288
289289 if (ret)
@@ -1429,7 +1429,7 @@ static void msm_otg_debugfs_cleanup(void) · 1139 unmodified lines
14291429 debugfs_remove(msm_otg_dbg_root);
14301430 }
14311431
1432−static struct of_device_id msm_otg_dt_match[] = {
1432+static const struct of_device_id msm_otg_dt_match[] = {
14331433 {
14341434 .compatible = "qcom,usb-otg-ci",
14351435 .data = (void *) CI_45NM_INTEGRATED_PHY
@@ -1466,7 +1466,7 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) · 30 unmodified lines
14661466
14671467 motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy");
14681468 if (IS_ERR(motg->phy_rst))
1469− return PTR_ERR(motg->phy_rst);
1469+ motg->phy_rst = NULL;
14701470
14711471 pdata->mode = of_usb_get_dr_mode(node);
14721472 if (pdata->mode == USB_DR_MODE_UNKNOWN)
@@ -1558,7 +1558,7 @@ static int msm_otg_probe(struct platform_device *pdev) · 85 unmodified lines
15581558 np ? "phy" : "usb_phy_clk");
15591559 if (IS_ERR(motg->phy_reset_clk)) {
15601560 dev_err(&pdev->dev, "failed to get usb_phy_clk\n");
1561− return PTR_ERR(motg->phy_reset_clk);
1561+ motg->phy_reset_clk = NULL;
15621562 }
15631563
15641564 motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk");
drivers/usb/phy/phy-tegra-usb.c+4−7
@@ -33,7 +33,6 @@ · 32 unmodified lines
3333 #include <linux/usb/otg.h>
3434 #include <linux/usb/ulpi.h>
3535 #include <linux/usb/of.h>
36−#include <asm/mach-types.h>
3736 #include <linux/usb/ehci_def.h>
3837 #include <linux/usb/tegra_usb_phy.h>
3938 #include <linux/regulator/consumer.h>
@@ -686,10 +685,8 @@ static int ulpi_phy_power_off(struct tegra_usb_phy *phy) · 646 unmodified lines
686685 return gpio_direction_output(phy->reset_gpio, 0);
687686 }
688687
689−static void tegra_usb_phy_close(struct usb_phy *x)
688+static void tegra_usb_phy_close(struct tegra_usb_phy *phy)
690689 {
691− struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
692−
693690 if (!IS_ERR(phy->vbus))
694691 regulator_disable(phy->vbus);
695692
@@ -965,7 +962,7 @@ static const struct tegra_phy_soc_config tegra30_soc_config = { · 269 unmodified lines
965962 .requires_extra_tuning_parameters = true,
966963 };
967964
968−static struct of_device_id tegra_usb_phy_id_table[] = {
965+static const struct of_device_id tegra_usb_phy_id_table[] = {
969966 { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config },
970967 { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config },
971968 { },
@@ -1061,14 +1058,13 @@ static int tegra_usb_phy_probe(struct platform_device *pdev) · 89 unmodified lines
10611058 if (err < 0)
10621059 return err;
10631060
1064− tegra_phy->u_phy.shutdown = tegra_usb_phy_close;
10651061 tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend;
10661062
10671063 platform_set_drvdata(pdev, tegra_phy);
10681064
10691065 err = usb_add_phy_dev(&tegra_phy->u_phy);
10701066 if (err < 0) {
1071− tegra_usb_phy_close(&tegra_phy->u_phy);
1067+ tegra_usb_phy_close(tegra_phy);
10721068 return err;
10731069 }
10741070
@@ -1080,6 +1076,7 @@ static int tegra_usb_phy_remove(struct platform_device *pdev) · 5 unmodified lines
10801076 struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev);
10811077
10821078 usb_remove_phy(&tegra_phy->u_phy);
1079+ tegra_usb_phy_close(tegra_phy);
10831080
10841081 return 0;
10851082 }
drivers/usb/renesas_usbhs/Makefile+1−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
44
55 obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs.o
66
7−renesas_usbhs-y := common.o mod.o pipe.o fifo.o
7+renesas_usbhs-y := common.o mod.o pipe.o fifo.o rcar2.o
88
99 ifneq ($(CONFIG_USB_RENESAS_USBHS_HCD),)
1010 renesas_usbhs-y += mod_host.o
drivers/usb/renesas_usbhs/common.c+61−5
@@ -15,12 +15,14 @@ · 14 unmodified lines
1515 *
1616 */
1717 #include <linux/err.h>
18+#include <linux/gpio.h>
1819 #include <linux/io.h>
1920 #include <linux/module.h>

111 more lines aren’t shown here.

drivers/usb/renesas_usbhs/common.h+2−0

This diff is large: its 9 lines aren’t shown here.

drivers/usb/renesas_usbhs/mod_gadget.c+2−0

This diff is large: its 11 lines aren’t shown here.

drivers/usb/renesas_usbhs/pipe.c+11−0

This diff is large: its 32 lines aren’t shown here.

drivers/usb/renesas_usbhs/pipe.h+1−0

This diff is large: its 8 lines aren’t shown here.

drivers/usb/renesas_usbhs/rcar2.c+77−0

This diff is large: its 78 lines aren’t shown here.

drivers/usb/renesas_usbhs/rcar2.h+4−0

This diff is large: its 5 lines aren’t shown here.

drivers/usb/serial/cp210x.c+0−3

This diff is large: its 10 lines aren’t shown here.

drivers/usb/serial/ftdi_sio.c+25−59

This diff is large: its 156 lines aren’t shown here.

drivers/usb/serial/ftdi_sio_ids.h+8−5

This diff is large: its 21 lines aren’t shown here.

drivers/usb/serial/kl5kusb105.c+0−30

This diff is large: its 51 lines aren’t shown here.

drivers/usb/serial/mos7840.c+1−4

This diff is large: its 12 lines aren’t shown here.

drivers/usb/storage/uas-detect.h+19−21

This diff is large: its 68 lines aren’t shown here.

drivers/usb/storage/uas.c+1−1

This diff is large: its 9 lines aren’t shown here.

drivers/uwb/whci.c+1−1

This diff is large: its 9 lines aren’t shown here.

include/dt-bindings/phy/phy-miphy365x.h+14−0

This diff is large: its 15 lines aren’t shown here.

include/linux/phy/omap_control_phy.h+10−0

This diff is large: its 45 lines aren’t shown here.

include/linux/phy/phy.h+12−5

This diff is large: its 50 lines aren’t shown here.

include/linux/usb/composite.h+15−0

This diff is large: its 22 lines aren’t shown here.

include/linux/usb/quirks.h+11−0

This diff is large: its 16 lines aren’t shown here.

include/linux/usb/renesas_usbhs.h+6−0

This diff is large: its 20 lines aren’t shown here.

include/linux/usb/usb338x.h+199−0

This diff is large: its 200 lines aren’t shown here.

include/linux/usb/xhci_pdriver.h+27−0

This diff is large: its 28 lines aren’t shown here.

include/uapi/linux/usb/functionfs.h+80−2

This diff is large: its 115 lines aren’t shown here.

tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c+35−4

This diff is large: its 66 lines aren’t shown here.

tools/usb/ffs-aio-example/multibuff/host_app/test.c+27−0

This diff is large: its 31 lines aren’t shown here.

tools/usb/ffs-aio-example/simple/device_app/aio_simple.c+35−4

This diff is large: its 66 lines aren’t shown here.

tools/usb/ffs-aio-example/simple/host_app/test.c+27−0

This diff is large: its 31 lines aren’t shown here.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t