History

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

Pull USB and Thunderbolt driver updates from Greg KH: "Here is the large set of USB and Thunderbolt driver changes for 6.2-rc1. Overall, thanks to the removal of a driver, more lines were removed than added, a nice change. Highlights include: - removal of the sisusbvga driver that was not used by anyone anymore - minor thunderbolt driver changes and tweaks - chipidea driver updates - usual set of typec driver features and hardware support added - musb minor driver fixes - fotg210 driver fixes, bringing that hardware back from the "dead" - minor dwc3 driver updates - addition, and then removal, of a list.h helper function for many USB and other subsystem drivers, that ended up breaking the build. That will come back for 6.3-rc1, it missed this merge window. - usual xhci updates and enhancements - usb-serial driver updates and support for new devices - other minor USB driver updates All of these have been in linux-next for a while with no reported problems" * tag 'usb-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (153 commits) usb: gadget: uvc: Rename bmInterfaceFlags -> bmInterlaceFlags usb: dwc2: power on/off phy for peripheral mode in dual-role mode usb: dwc2: disable lpm feature on Rockchip SoCs dt-bindings: usb: mtk-xhci: add support for mt7986 usb: dwc3: core: defer probe on ulpi_read_id timeout usb: ulpi: defer ulpi_register on ulpi_read_id timeout usb: misc: onboard_usb_hub: add Genesys Logic GL850G hub support dt-bindings: usb: Add binding for Genesys Logic GL850G hub controller dt-bindings: vendor-prefixes: add Genesys Logic usb: fotg210-udc: fix potential memory leak in fotg210_udc_probe() usb: typec: tipd: Set mode of operation for USB Type-C connector usb: gadget: udc: drop obsolete dependencies on COMPILE_TEST usb: musb: remove extra check in musb_gadget_vbus_draw usb: gadget: uvc: Prevent buffer overflow in setup handler usb: dwc3: qcom: Fix memory leak in dwc3_qcom_interconnect_init usb: typec: wusb3801: fix fwnode refcount leak in wusb3801_probe() usb: storage: Add check for kcalloc USB: sisusbvga: use module_usb_driver() USB: sisusbvga: rename sisusb.c to sisusbvga.c USB: sisusbvga: remove console support ...

Linus Torvalds committed 3 years ago

Commit 58bcac12 parents 84e57d2 81c2524163 files · +2079 −7049Browse files

Unified · Split

163 files
  1. Documentation/ABI/testing/configfs-usb-gadget-uvc +2 −2
  2. Documentation/ABI/testing/sysfs-bus-usb +11 −0
  3. Documentation/devicetree/bindings/phy/fsl,imx8mq-usb-phy.yaml +3 −0
  4. Documentation/devicetree/bindings/usb/dwc2.yaml +3 −0
  5. Documentation/devicetree/bindings/usb/genesys,gl850g.yaml +48 −0
  6. Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml +1 −0
  7. Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml +1 −0
  8. Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +3 −0
  9. Documentation/devicetree/bindings/usb/usb-drd.yaml +1 −0
  10. Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml +5 −0
  11. Documentation/devicetree/bindings/usb/usb251xb.txt +0 −89
  12. Documentation/devicetree/bindings/usb/usb251xb.yaml +271 −0
  13. Documentation/devicetree/bindings/vendor-prefixes.yaml +2 −0
  14. Documentation/driver-api/driver-model/devres.rst +2 −0
  15. MAINTAINERS +7 −1
  16. arch/powerpc/configs/ppc6xx_defconfig +0 −1
  17. arch/sh/configs/landisk_defconfig +0 −1
  18. drivers/extcon/extcon-usbc-tusb320.c +12 −5
  19. drivers/platform/chrome/cros_ec_typec.c +1 −1
  20. drivers/thunderbolt/acpi.c +4 −8
  21. drivers/thunderbolt/switch.c +3 −2
  22. drivers/thunderbolt/tb_regs.h +2 −0
  23. drivers/thunderbolt/usb4.c +25 −8
  24. drivers/thunderbolt/usb4_port.c +3 −0
  25. drivers/thunderbolt/xdomain.c +2 −2
  26. drivers/usb/Kconfig +4 −0
  27. drivers/usb/Makefile +2 −0
  28. drivers/usb/cdns3/cdnsp-pci.c +3 −5
  29. drivers/usb/cdns3/cdnsp-ring.c +32 −10
  30. drivers/usb/chipidea/ci.h +4 −0
  31. drivers/usb/chipidea/ci_hdrc_imx.c +16 −35
  32. drivers/usb/chipidea/ci_hdrc_imx.h +2 −2
  33. drivers/usb/chipidea/core.c +89 −54
  34. drivers/usb/chipidea/host.c +16 −0
  35. drivers/usb/chipidea/otg.c +1 −1
  36. drivers/usb/chipidea/otg.h +1 −0
  37. drivers/usb/chipidea/udc.c +32 −0
  38. drivers/usb/chipidea/usbmisc_imx.c +130 −30
  39. drivers/usb/common/ulpi.c +1 −1
  40. drivers/usb/core/config.c +41 −41
  41. drivers/usb/core/hcd-pci.c +13 −0
  42. drivers/usb/core/hcd.c +5 −1
  43. drivers/usb/core/hub.c +60 −0
  44. drivers/usb/core/hub.h +4 −0
  45. drivers/usb/core/port.c +29 −1
  46. drivers/usb/core/sysfs.c +4 −3
  47. drivers/usb/dwc2/gadget.c +4 −2
  48. drivers/usb/dwc2/params.c +4 −0
  49. drivers/usb/dwc2/platform.c +3 −2
  50. drivers/usb/dwc3/Kconfig +2 −2
  51. drivers/usb/dwc3/core.c +16 −7
  52. drivers/usb/dwc3/dwc3-pci.c +1 −1
  53. drivers/usb/dwc3/dwc3-qcom.c +10 −3
  54. drivers/usb/dwc3/gadget.c +12 −2
  55. drivers/usb/fotg210/Kconfig +38 −0
  56. drivers/usb/fotg210/Makefile +10 −0
  57. drivers/usb/fotg210/fotg210-core.c +166 −0
  58. drivers/usb/fotg210/fotg210-hcd.c +8 −43
  59. drivers/usb/fotg210/fotg210-hcd.h +0 −0
  60. drivers/usb/fotg210/fotg210-udc.c +123 −41
  61. drivers/usb/fotg210/fotg210-udc.h +3 −0
  62. drivers/usb/fotg210/fotg210.h +42 −0
  63. drivers/usb/gadget/configfs.c +2 −1
  64. drivers/usb/gadget/function/f_ecm.c +9 −13
  65. drivers/usb/gadget/function/f_hid.c +33 −27
  66. drivers/usb/gadget/function/f_mass_storage.c +2 −1
  67. drivers/usb/gadget/function/f_printer.c +1 −8
  68. drivers/usb/gadget/function/f_uvc.c +15 −5
  69. drivers/usb/gadget/function/storage_common.c +5 −4
  70. drivers/usb/gadget/function/u_ether.c +0 −4
  71. drivers/usb/gadget/function/u_serial.c +2 −1
  72. drivers/usb/gadget/function/uvc_configfs.c +6 −6
  73. drivers/usb/gadget/legacy/serial.c +2 −1
  74. drivers/usb/gadget/legacy/webcam.c +2 −2
  75. drivers/usb/gadget/udc/Kconfig +2 −13
  76. drivers/usb/gadget/udc/Makefile +0 −1
  77. drivers/usb/gadget/udc/aspeed-vhub/core.c +1 −1
  78. drivers/usb/gadget/udc/aspeed-vhub/epn.c +12 −4
  79. drivers/usb/gadget/udc/at91_udc.c +1 −4
  80. drivers/usb/gadget/udc/core.c +6 −6
  81. drivers/usb/host/Kconfig +1 −12
  82. drivers/usb/host/Makefile +0 −1
  83. drivers/usb/host/ehci-grlib.c +1 −1
  84. drivers/usb/host/ehci-pci.c +4 −3
  85. drivers/usb/host/ehci-ppc-of.c +1 −1
  86. drivers/usb/host/ehci.h +1 −1
  87. drivers/usb/host/fhci-hcd.c +1 −1
  88. drivers/usb/host/ohci-ppc-of.c +1 −1
  89. drivers/usb/host/uhci-grlib.c +1 −1
  90. drivers/usb/host/xhci-hub.c +18 −4
  91. drivers/usb/host/xhci-mtk.c +46 −27
  92. drivers/usb/host/xhci-pci.c +59 −4
  93. drivers/usb/host/xhci-ring.c +23 −19
  94. drivers/usb/host/xhci.h +1 −1
  95. drivers/usb/misc/Kconfig +1 −1
  96. drivers/usb/misc/ftdi-elan.c +0 −4
  97. drivers/usb/misc/onboard_usb_hub.c +2 −0
  98. drivers/usb/misc/onboard_usb_hub.h +5 −0
  99. drivers/usb/misc/sisusbvga/Kconfig +0 −34
  100. drivers/usb/misc/sisusbvga/Makefile +0 −3
  101. drivers/usb/misc/sisusbvga/sisusb.h +0 −21
  102. drivers/usb/misc/sisusbvga/sisusb_con.c +0 −1496
  103. drivers/usb/misc/sisusbvga/sisusb_init.c +0 −955
  104. drivers/usb/misc/sisusbvga/sisusb_init.h +0 −180
  105. drivers/usb/misc/sisusbvga/sisusbvga.c +7 −282
  106. drivers/usb/misc/usb251xb.c +2 −3
  107. drivers/usb/misc/usb3503.c +2 −3
  108. drivers/usb/misc/usb4604.c +2 −3
  109. drivers/usb/musb/Kconfig +0 −18
  110. drivers/usb/musb/Makefile +0 −3
  111. drivers/usb/musb/am35x.c +0 −610
  112. drivers/usb/musb/cppi_dma.c +0 −1547
  113. drivers/usb/musb/davinci.c +0 −606
  114. drivers/usb/musb/davinci.h +0 −103
  115. drivers/usb/musb/jz4740.c +54 −8
  116. drivers/usb/musb/musb_core.c +51 −56
  117. drivers/usb/musb/musb_core.h +24 −0
  118. drivers/usb/musb/musb_debugfs.c +3 −3
  119. drivers/usb/musb/musb_dma.h +3 −10
  120. drivers/usb/musb/musb_gadget.c +34 −27
  121. drivers/usb/musb/musb_host.c +12 −6
  122. drivers/usb/musb/musb_virthub.c +16 −17
  123. drivers/usb/musb/omap2430.c +54 −0
  124. drivers/usb/phy/Kconfig +5 −9
  125. drivers/usb/phy/Makefile +0 −1
  126. drivers/usb/phy/phy-generic.c +9 −9
  127. drivers/usb/phy/phy-gpio-vbus-usb.c +12 −0
  128. drivers/usb/phy/phy-isp1301-omap.c +2 −2
  129. drivers/usb/phy/phy-isp1301.c +2 −3
  130. drivers/usb/phy/phy-jz4770.c +0 −353
  131. drivers/usb/roles/class.c +4 −1
  132. drivers/usb/serial/cp210x.c +17 −4
  133. drivers/usb/serial/f81232.c +7 −5
  134. drivers/usb/serial/f81534.c +7 −5
  135. drivers/usb/serial/option.c +3 −0
  136. drivers/usb/serial/xr_serial.c +0 −2
  137. drivers/usb/storage/alauda.c +2 −0
  138. drivers/usb/typec/anx7411.c +2 −3
  139. drivers/usb/typec/bus.c +1 −1
  140. drivers/usb/typec/class.c +19 −0
  141. drivers/usb/typec/hd3ss3220.c +2 −3
  142. drivers/usb/typec/retimer.c +2 −14
  143. drivers/usb/typec/retimer.h +4 −0
  144. drivers/usb/typec/tcpm/fusb302.c +2 −3
  145. drivers/usb/typec/tcpm/tcpci.c +6 −4
  146. drivers/usb/typec/tcpm/tcpci_maxim.c +2 −2
  147. drivers/usb/typec/tcpm/tcpci_rt1711h.c +2 −3
  148. drivers/usb/typec/tipd/core.c +12 −8
  149. drivers/usb/typec/ucsi/ucsi.c +13 −4
  150. drivers/usb/typec/ucsi/ucsi.h +1 −0
  151. drivers/usb/typec/ucsi/ucsi_ccg.c +2 −3
  152. drivers/usb/typec/ucsi/ucsi_stm32g0.c +2 −2
  153. drivers/usb/typec/wusb3801.c +1 −1
  154. drivers/usb/usb-skeleton.c +0 −1
  155. drivers/usb/usbip/stub_dev.c +3 −1
  156. drivers/usb/usbip/vudc_rx.c +3 −1
  157. drivers/usb/usbip/vudc_sysfs.c +1 −1
  158. include/linux/usb.h +12 −0
  159. include/linux/usb/hcd.h +3 −0
  160. include/linux/usb/typec.h +4 −0
  161. include/uapi/linux/usb/g_uvc.h +3 −0
  162. include/uapi/linux/usb/video.h +2 −2
  163. tools/usb/ffs-aio-example/simple/device_app/aio_simple.c +31 −13
Documentation/ABI/testing/configfs-usb-gadget-uvc+2−2
@@ -197,7 +197,7 @@ Description: Specific MJPEG format descriptors · 196 unmodified lines
197 read-only197 read-only
198 bmaControls this format's data for bmaControls in198 bmaControls this format's data for bmaControls in
199 the streaming header199 the streaming header
200 bmInterfaceFlags specifies interlace information,200 bmInterlaceFlags specifies interlace information,
201 read-only201 read-only
202 bAspectRatioY the X dimension of the picture aspect202 bAspectRatioY the X dimension of the picture aspect
203 ratio, read-only203 ratio, read-only
@@ -253,7 +253,7 @@ Description: Specific uncompressed format descriptors · 49 unmodified lines
253 read-only253 read-only
254 bmaControls this format's data for bmaControls in254 bmaControls this format's data for bmaControls in
255 the streaming header255 the streaming header
256 bmInterfaceFlags specifies interlace information,256 bmInterlaceFlags specifies interlace information,
257 read-only257 read-only
258 bAspectRatioY the X dimension of the picture aspect258 bAspectRatioY the X dimension of the picture aspect
259 ratio, read-only259 ratio, read-only
Documentation/ABI/testing/sysfs-bus-usb+11−0
@@ -264,6 +264,17 @@ Description: · 263 unmodified lines
264 attached to the port will not be detected, initialized,264 attached to the port will not be detected, initialized,
265 or enumerated.265 or enumerated.
266 266
267What: /sys/bus/usb/devices/.../<hub_interface>/port<X>/early_stop
268Date: Sep 2022
269Contact: Ray Chi <raychi@google.com>
270Description:
271 Some USB hosts have some watchdog mechanisms so that the device
272 may enter ramdump if it takes a long time during port initialization.
273 This attribute allows each port just has two attempts so that the
274 port initialization will be failed quickly. In addition, if a port
275 which is marked with early_stop has failed to initialize, it will ignore
276 all future connections until this attribute is clear.
277
267What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout278What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout
268Date: May 2013279Date: May 2013
269Contact: Mathias Nyman <mathias.nyman@linux.intel.com>280Contact: Mathias Nyman <mathias.nyman@linux.intel.com>
Documentation/devicetree/bindings/phy/fsl,imx8mq-usb-phy.yaml+3−0
@@ -28,6 +28,9 @@ properties: · 27 unmodified lines
28 items:28 items:
29 - const: phy29 - const: phy
30 30
31 power-domains:
32 maxItems: 1
33
31 vbus-supply:34 vbus-supply:
32 description:35 description:
33 A phandle to the regulator for USB VBUS.36 A phandle to the regulator for USB VBUS.
Documentation/devicetree/bindings/usb/dwc2.yaml+3−0
@@ -43,7 +43,10 @@ properties: · 42 unmodified lines
43 - const: rockchip,rk3066-usb43 - const: rockchip,rk3066-usb
44 - const: snps,dwc244 - const: snps,dwc2
45 - const: lantiq,arx100-usb45 - const: lantiq,arx100-usb
46 - const: lantiq,ase-usb
47 - const: lantiq,danube-usb
46 - const: lantiq,xrx200-usb48 - const: lantiq,xrx200-usb
49 - const: lantiq,xrx300-usb
47 - items:50 - items:
48 - enum:51 - enum:
49 - amlogic,meson8-usb52 - amlogic,meson8-usb
Documentation/devicetree/bindings/usb/genesys,gl850g.yaml+48−0
@@ -0,0 +1,48 @@
1# SPDX-License-Identifier: GPL-2.0-only or BSD-2-Clause
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/usb/genesys,gl850g.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Genesys Logic GL850G USB 2.0 hub controller
8
9maintainers:
10 - Icenowy Zheng <uwu@icenowy.me>
11
12allOf:
13 - $ref: usb-device.yaml#
14
15properties:
16 compatible:
17 enum:
18 - usb5e3,608
19
20 reg: true
21
22 reset-gpios:
23 description: GPIO controlling the RESET# pin.
24
25 vdd-supply:
26 description:
27 the regulator that provides 3.3V core power to the hub.
28
29required:
30 - compatible
31 - reg
32
33additionalProperties: false
34
35examples:
36 - |
37 #include <dt-bindings/gpio/gpio.h>
38 usb {
39 dr_mode = "host";
40 #address-cells = <1>;
41 #size-cells = <0>;
42
43 hub: hub@1 {
44 compatible = "usb5e3,608";
45 reg = <1>;
46 reset-gpios = <&pio 7 2 GPIO_ACTIVE_LOW>;
47 };
48 };
Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml+1−0
@@ -28,6 +28,7 @@ properties: · 27 unmodified lines
28 - mediatek,mt7622-xhci28 - mediatek,mt7622-xhci
29 - mediatek,mt7623-xhci29 - mediatek,mt7623-xhci
30 - mediatek,mt7629-xhci30 - mediatek,mt7629-xhci
31 - mediatek,mt7986-xhci
31 - mediatek,mt8173-xhci32 - mediatek,mt8173-xhci
32 - mediatek,mt8183-xhci33 - mediatek,mt8183-xhci
33 - mediatek,mt8186-xhci34 - mediatek,mt8186-xhci
Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml+1−0
@@ -24,6 +24,7 @@ properties: · 23 unmodified lines
24 - mediatek,mt2712-mtu324 - mediatek,mt2712-mtu3
25 - mediatek,mt8173-mtu325 - mediatek,mt8173-mtu3
26 - mediatek,mt8183-mtu326 - mediatek,mt8183-mtu3
27 - mediatek,mt8186-mtu3
27 - mediatek,mt8188-mtu328 - mediatek,mt8188-mtu3
28 - mediatek,mt8192-mtu329 - mediatek,mt8192-mtu3
29 - mediatek,mt8195-mtu330 - mediatek,mt8195-mtu3
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml+3−0
@@ -39,6 +39,7 @@ properties: · 38 unmodified lines
39 - qcom,sm8250-dwc339 - qcom,sm8250-dwc3
40 - qcom,sm8350-dwc340 - qcom,sm8350-dwc3
41 - qcom,sm8450-dwc341 - qcom,sm8450-dwc3
42 - qcom,sm8550-dwc3
42 - const: qcom,dwc343 - const: qcom,dwc3
43 44
44 reg:45 reg:
@@ -301,6 +302,7 @@ allOf: · 256 unmodified lines
301 - qcom,sm8150-dwc3302 - qcom,sm8150-dwc3
302 - qcom,sm8250-dwc3303 - qcom,sm8250-dwc3
303 - qcom,sm8450-dwc3304 - qcom,sm8450-dwc3
305 - qcom,sm8550-dwc3
304 then:306 then:
305 properties:307 properties:
306 clocks:308 clocks:
@@ -358,6 +360,7 @@ allOf: · 51 unmodified lines
358 - qcom,sm8250-dwc3360 - qcom,sm8250-dwc3
359 - qcom,sm8350-dwc3361 - qcom,sm8350-dwc3
360 - qcom,sm8450-dwc3362 - qcom,sm8450-dwc3
363 - qcom,sm8550-dwc3
361 then:364 then:
362 properties:365 properties:
363 interrupts:366 interrupts:
Documentation/devicetree/bindings/usb/usb-drd.yaml+1−0
@@ -27,6 +27,7 @@ properties: · 26 unmodified lines
27 should default to OTG.27 should default to OTG.
28 $ref: /schemas/types.yaml#/definitions/string28 $ref: /schemas/types.yaml#/definitions/string
29 enum: [host, peripheral, otg]29 enum: [host, peripheral, otg]
30 default: otg
30 31
31 hnp-disable:32 hnp-disable:
32 description:33 description:
Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml+5−0
@@ -39,6 +39,11 @@ properties: · 38 unmodified lines
39 the VBus line.39 the VBus line.
40 $ref: /schemas/types.yaml#/definitions/phandle40 $ref: /schemas/types.yaml#/definitions/phandle
41 41
42 wakeup-source:
43 description:
44 Specify if the USB phy can detect the remote wakeup signal
45 while the system sleep.
46
42required:47required:
43 - compatible48 - compatible
44 - '#phy-cells'49 - '#phy-cells'
Documentation/devicetree/bindings/usb/usb251xb.txt+0−89
@@ -1,89 +0,0 @@
1Microchip USB 2.0 Hi-Speed Hub Controller
2
3The device node for the configuration of a Microchip USB251x/xBi USB 2.0
4Hi-Speed Controller.
5
6Required properties :
7 - compatible : Should be "microchip,usb251xb" or one of the specific types:
8 "microchip,usb2512b", "microchip,usb2512bi", "microchip,usb2513b",
9 "microchip,usb2513bi", "microchip,usb2514b", "microchip,usb2514bi",
10 "microchip,usb2517", "microchip,usb2517i", "microchip,usb2422"
11 - reg : I2C address on the selected bus (default is <0x2C>)
12
13Optional properties :
14 - reset-gpios : Should specify the gpio for hub reset
15 - vdd-supply : Should specify the phandle to the regulator supplying vdd
16 - skip-config : Skip Hub configuration, but only send the USB-Attach command
17 - vendor-id : Set USB Vendor ID of the hub (16 bit, default is 0x0424)
18 - product-id : Set USB Product ID of the hub (16 bit, default depends on type)
19 - device-id : Set USB Device ID of the hub (16 bit, default is 0x0bb3)
20 - language-id : Set USB Language ID (16 bit, default is 0x0000)
21 - manufacturer : Set USB Manufacturer string (max 31 characters long)
22 - product : Set USB Product string (max 31 characters long)
23 - serial : Set USB Serial string (max 31 characters long)
24 - {bus,self}-powered : selects between self- and bus-powered operation
25 (boolean, default is self-powered)
26 - disable-hi-speed : disable USB Hi-Speed support (boolean)
27 - {multi,single}-tt : selects between multi- and single-transaction-translator
28 (boolean, default is multi-tt)
29 - disable-eop : disable End of Packet generation in full-speed mode (boolean)
30 - {ganged,individual}-sensing : select over-current sense type in self-powered
31 mode (boolean, default is individual)
32 - {ganged,individual}-port-switching : select port power switching mode
33 (boolean, default is individual)
34 - dynamic-power-switching : enable auto-switching from self- to bus-powered
35 operation if the local power source is removed or unavailable (boolean)
36 - oc-delay-us : Delay time (in microseconds) for filtering the over-current
37 sense inputs. Valid values are 100, 4000, 8000 (default) and 16000. If
38 an invalid value is given, the default is used instead.
39 - compound-device : indicate the hub is part of a compound device (boolean)
40 - port-mapping-mode : enable port mapping mode (boolean)
41 - led-{usb,speed}-mode : led usb/speed indication mode selection
42 (boolean, default is speed mode)
43 - string-support : enable string descriptor support (required for manufacturer,
44 product and serial string configuration)
45 - non-removable-ports : Should specify the ports which have a non-removable
46 device connected.
47 - sp-disabled-ports : Specifies the ports which will be self-power disabled
48 - bp-disabled-ports : Specifies the ports which will be bus-power disabled
49 - sp-max-total-current-microamp: Specifies max current consumed by the hub
50 from VBUS when operating in self-powered hub. It includes the hub
51 silicon along with all associated circuitry including a permanently
52 attached peripheral (range: 0 - 100000 uA, default 1000 uA)
53 - bp-max-total-current-microamp: Specifies max current consumed by the hub
54 from VBUS when operating in self-powered hub. It includes the hub
55 silicon along with all associated circuitry including a permanently
56 attached peripheral (range: 0 - 510000 uA, default 100000 uA)
57 - sp-max-removable-current-microamp: Specifies max current consumed by the hub
58 from VBUS when operating in self-powered hub. It includes the hub
59 silicon along with all associated circuitry excluding a permanently
60 attached peripheral (range: 0 - 100000 uA, default 1000 uA)
61 - bp-max-removable-current-microamp: Specifies max current consumed by the hub
62 from VBUS when operating in self-powered hub. It includes the hub
63 silicon along with all associated circuitry excluding a permanently
64 attached peripheral (range: 0 - 510000 uA, default 100000 uA)
65 - power-on-time-ms : Specifies the time it takes from the time the host
66 initiates the power-on sequence to a port until the port has adequate
67 power. The value is given in ms in a 0 - 510 range (default is 100ms).
68 - swap-dx-lanes : Specifies the ports which will swap the differential-pair
69 (D+/D-), default is not-swapped.
70
71Examples:
72 usb2512b@2c {
73 compatible = "microchip,usb2512b";
74 reg = <0x2c>;
75 reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
76 };
77
78 usb2514b@2c {
79 compatible = "microchip,usb2514b";
80 reg = <0x2c>;
81 vendor-id = /bits/ 16 <0x0000>;
82 product-id = /bits/ 16 <0x0000>;
83 string-support;
84 manufacturer = "Foo";
85 product = "Foo-Bar";
86 serial = "1234567890A";
87 /* correct misplaced usb connectors on port 1,2 */
88 swap-dx-lanes = <1 2>;
89 };
Documentation/devicetree/bindings/usb/usb251xb.yaml+271−0
@@ -0,0 +1,271 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/usb/usb251xb.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Microchip USB 2.0 Hi-Speed Hub Controller
8
9maintainers:
10 - Richard Leitner <richard.leitner@skidata.com>
11
12properties:
13 compatible:
14 enum:
15 - microchip,usb2422
16 - microchip,usb2512b
17 - microchip,usb2512bi
18 - microchip,usb2513b
19 - microchip,usb2513bi
20 - microchip,usb2514b
21 - microchip,usb2514bi
22 - microchip,usb2517
23 - microchip,usb2517i
24 - microchip,usb251xb
25
26 reg:
27 maxItems: 1
28
29 reset-gpios:
30 description: |
31 Should specify the gpio for hub reset
32
33 vdd-supply:
34 description: |
35 Should specify the phandle to the regulator supplying vdd
36
37 skip-config:
38 $ref: /schemas/types.yaml#/definitions/flag
39 description: |
40 Skip Hub configuration, but only send the USB-Attach command
41
42 vendor-id:
43 $ref: /schemas/types.yaml#/definitions/uint16
44 default: 0x0424
45 description: |
46 Set USB Vendor ID of the hub
47
48 product-id:
49 $ref: /schemas/types.yaml#/definitions/uint16
50 description: |
51 Set USB Product ID of the hub
52
53 device-id:
54 $ref: /schemas/types.yaml#/definitions/uint16
55 default: 0x0bb3
56 description: |
57 Set USB Device ID of the hub
58
59 language-id:
60 $ref: /schemas/types.yaml#/definitions/uint16
61 default: 0x0000
62 description: |
63 Set USB Language ID
64
65 manufacturer:
66 $ref: /schemas/types.yaml#/definitions/string
67 description: |
68 Set USB Manufacturer string (max 31 characters long)
69
70 product:
71 $ref: /schemas/types.yaml#/definitions/string
72 description: |
73 Set USB Product string (max 31 characters long)
74
75 serial:
76 $ref: /schemas/types.yaml#/definitions/string
77 description: |
78 Set USB Serial string (max 31 characters long)
79
80 bus-powered:
81 $ref: /schemas/types.yaml#/definitions/flag
82 description: |
83 selects between self- and bus-powered operation
84 (boolean, default is self-powered)
85
86 self-powered:
87 $ref: /schemas/types.yaml#/definitions/flag
88 description: |
89 selects between self- and bus-powered operation
90 (boolean, default is self-powered)
91
92 disable-hi-speed:
93 $ref: /schemas/types.yaml#/definitions/flag
94 description: |
95 disable USB Hi-Speed support (boolean)
96
97 multi-tt:
98 $ref: /schemas/types.yaml#/definitions/flag
99 description: |
100 selects between multi- and single-transaction-translator
101 (boolean, default is multi-tt)
102
103 single-tt:
104 $ref: /schemas/types.yaml#/definitions/flag
105 description: |
106 selects between multi- and single-transaction-translator
107 (boolean, default is multi-tt)
108
109 disable-eop:
110 $ref: /schemas/types.yaml#/definitions/flag
111 description: |
112 disable End of Packet generation in full-speed mode (boolean)
113
114 ganged-sensing:
115 $ref: /schemas/types.yaml#/definitions/flag
116 description: |
117 select over-current sense type in self-powered mode
118 (boolean, default is individual)
119
120 individual-sensing:
121 $ref: /schemas/types.yaml#/definitions/flag
122 description: |
123 select over-current sense type in self-powered mode
124 (boolean, default is individual)
125
126 ganged-port-switching:
127 $ref: /schemas/types.yaml#/definitions/flag
128 description: |
129 select port power switching mode (boolean, default is individual)
130
131 individual-port-switching:
132 $ref: /schemas/types.yaml#/definitions/flag
133 description: |
134 select port power switching mode (boolean, default is individual)
135
136 dynamic-power-switching:
137 $ref: /schemas/types.yaml#/definitions/flag
138 description: |
139 enable auto-switching from self- to bus-powered operation if the
140 local power source is removed or unavailable (boolean)
141
142 oc-delay-us:
143 enum: [100, 4000, 8000, 16000]
144 default: 8000
145 description: |
146 Delay time (in microseconds) for filtering the over-current sense
147 inputs. If an invalid value is given, the default is used instead.
148
149 compound-device:
150 $ref: /schemas/types.yaml#/definitions/flag
151 description: |
152 indicate the hub is part of a compound device (boolean)
153
154 port-mapping-mode:
155 $ref: /schemas/types.yaml#/definitions/flag
156 description: |
157 enable port mapping mode (boolean)
158
159 led-usb-mode:
160 $ref: /schemas/types.yaml#/definitions/flag
161 description: |
162 led usb/speed indication mode selection (boolean, default is speed mode)
163
164 led-speed-mode:
165 $ref: /schemas/types.yaml#/definitions/flag
166 description: |
167 led usb/speed indication mode selection (boolean, default is speed mode)
168
169 string-support:
170 $ref: /schemas/types.yaml#/definitions/flag
171 description: |
172 enable string descriptor support (required for manufacturer, product
173 and serial string configuration)
174
175 non-removable-ports:
176 $ref: /schemas/types.yaml#/definitions/uint8-array
177 description: |
178 Should specify the ports which have a non-removable device connected.
179
180 sp-disabled-ports:
181 $ref: /schemas/types.yaml#/definitions/uint8-array
182 description: |
183 Specifies the ports which will be self-power disabled
184
185 bp-disabled-ports:
186 $ref: /schemas/types.yaml#/definitions/uint8-array
187 description: |
188 Specifies the ports which will be bus-power disabled
189
190 sp-max-total-current-microamp:
191 maximum: 100000
192 default: 1000
193 description: |
194 Specifies max current consumed by the hub from VBUS when
195 operating in self-powered hub. It includes the hub silicon
196 along with all associated circuitry including a permanently
197 attached peripheral.
198
199 bp-max-total-current-microamp:
200 maximum: 510000
201 default: 100000
202 description: |
203 Specifies max current consumed by the hub from VBUS when
204 operating in self-powered hub. It includes the hub silicon
205 along with all associated circuitry including a permanently
206 attached peripheral.
207
208 sp-max-removable-current-microamp:
209 maximum: 100000
210 default: 1000
211 description: |
212 Specifies max current consumed by the hub from VBUS when
213 operating in self-powered hub. It includes the hub silicon
214 along with all associated circuitry excluding a permanently
215 attached peripheral.
216
217 bp-max-removable-current-microamp:
218 maximum: 510000
219 default: 100000
220 description: |
221 Specifies max current consumed by the hub from VBUS when
222 operating in self-powered hub. It includes the hub silicon
223 along with all associated circuitry excluding a permanently
224 attached peripheral.
225
226 power-on-time-ms:
227 maximum: 510
228 default: 100
229 description: |
230 Specifies the time it takes from the time the host initiates the
231 power-on sequence to a port until the port has adequate power.
232
233 swap-dx-lanes:
234 $ref: /schemas/types.yaml#/definitions/uint8-array
235 description: |
236 Specifies the ports which will swap the differential-pair (D+/D-),
237 default is not-swapped.
238
239additionalProperties: false
240
241required:
242 - compatible
243 - reg
244
245examples:
246 - |
247 #include <dt-bindings/gpio/gpio.h>
248
249 i2c {
250 #address-cells = <1>;
251 #size-cells = <0>;
252
253 usb-hub@2c {
254 compatible = "microchip,usb2512b";
255 reg = <0x2c>;
256 reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
257 };
258
259 usb-hub@2d {
260 compatible = "microchip,usb2514b";
261 reg = <0x2d>;
262 vendor-id = /bits/ 16 <0x0000>;
263 product-id = /bits/ 16 <0x0000>;
264 string-support;
265 manufacturer = "Foo";
266 product = "Foo-Bar";
267 serial = "1234567890A";
268 /* correct misplaced usb connectors on port 1,2 */
269 swap-dx-lanes = <1 2>;
270 };
271 };
Documentation/devicetree/bindings/vendor-prefixes.yaml+2−0
@@ -494,6 +494,8 @@ patternProperties: · 493 unmodified lines
494 description: GE Fanuc Intelligent Platforms Embedded Systems, Inc.494 description: GE Fanuc Intelligent Platforms Embedded Systems, Inc.
495 "^gemei,.*":495 "^gemei,.*":
496 description: Gemei Digital Technology Co., Ltd.496 description: Gemei Digital Technology Co., Ltd.
497 "^genesys,.*":
498 description: Genesys Logic, Inc.
497 "^geniatech,.*":499 "^geniatech,.*":
498 description: Geniatech, Inc.500 description: Geniatech, Inc.
499 "^giantec,.*":501 "^giantec,.*":
Documentation/driver-api/driver-model/devres.rst+2−0
@@ -395,6 +395,8 @@ PCI · 394 unmodified lines
395 395
396PHY396PHY
397 devm_usb_get_phy()397 devm_usb_get_phy()
398 devm_usb_get_phy_by_node()
399 devm_usb_get_phy_by_phandle()
398 devm_usb_put_phy()400 devm_usb_put_phy()
399 401
400PINCTRL402PINCTRL
MAINTAINERS+7−1
@@ -7935,6 +7935,12 @@ F: fs/notify/fanotify/ · 7934 unmodified lines
7935F: include/linux/fanotify.h7935F: include/linux/fanotify.h
7936F: include/uapi/linux/fanotify.h7936F: include/uapi/linux/fanotify.h
7937 7937
7938FARADAY FOTG210 USB2 DUAL-ROLE CONTROLLER
7939M: Linus Walleij <linus.walleij@linaro.org>
7940L: linux-usb@vger.kernel.org
7941S: Maintained
7942F: drivers/usb/fotg210/
7943
7938FARSYNC SYNCHRONOUS DRIVER7944FARSYNC SYNCHRONOUS DRIVER
7939M: Kevin Curtis <kevin.curtis@farsite.co.uk>7945M: Kevin Curtis <kevin.curtis@farsite.co.uk>
7940S: Supported7946S: Supported
@@ -13795,7 +13801,7 @@ MICROCHIP USB251XB DRIVER · 5854 unmodified lines
13795M: Richard Leitner <richard.leitner@skidata.com>13801M: Richard Leitner <richard.leitner@skidata.com>
13796L: linux-usb@vger.kernel.org13802L: linux-usb@vger.kernel.org
13797S: Maintained13803S: Maintained
13798F: Documentation/devicetree/bindings/usb/usb251xb.txt13804F: Documentation/devicetree/bindings/usb/usb251xb.yaml
13799F: drivers/usb/misc/usb251xb.c13805F: drivers/usb/misc/usb251xb.c
13800 13806
13801MICROCHIP USBA UDC DRIVER13807MICROCHIP USBA UDC DRIVER
arch/powerpc/configs/ppc6xx_defconfig+0−1
@@ -911,7 +911,6 @@ CONFIG_USB_IDMOUSE=m · 910 unmodified lines
911CONFIG_USB_FTDI_ELAN=m911CONFIG_USB_FTDI_ELAN=m
912CONFIG_USB_APPLEDISPLAY=m912CONFIG_USB_APPLEDISPLAY=m
913CONFIG_USB_SISUSBVGA=m913CONFIG_USB_SISUSBVGA=m
914CONFIG_USB_SISUSBVGA_CON=y
915CONFIG_USB_LD=m914CONFIG_USB_LD=m
916CONFIG_USB_TRANCEVIBRATOR=m915CONFIG_USB_TRANCEVIBRATOR=m
917CONFIG_USB_IOWARRIOR=m916CONFIG_USB_IOWARRIOR=m
arch/sh/configs/landisk_defconfig+0−1
@@ -92,7 +92,6 @@ CONFIG_USB_SERIAL_PL2303=m · 91 unmodified lines
92CONFIG_USB_EMI62=m92CONFIG_USB_EMI62=m
93CONFIG_USB_EMI26=m93CONFIG_USB_EMI26=m
94CONFIG_USB_SISUSBVGA=m94CONFIG_USB_SISUSBVGA=m
95CONFIG_USB_SISUSBVGA_CON=y
96CONFIG_EXT2_FS=y95CONFIG_EXT2_FS=y
97CONFIG_EXT3_FS=y96CONFIG_EXT3_FS=y
98# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set97# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
drivers/extcon/extcon-usbc-tusb320.c+12−5
@@ -313,9 +313,9 @@ static void tusb320_typec_irq_handler(struct tusb320_priv *priv, u8 reg9) · 312 unmodified lines
313 typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB);313 typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB);
314}314}
315 315
316static irqreturn_t tusb320_irq_handler(int irq, void *dev_id)316static irqreturn_t tusb320_state_update_handler(struct tusb320_priv *priv,
317 bool force_update)
317{318{
318 struct tusb320_priv *priv = dev_id;
319 unsigned int reg;319 unsigned int reg;
320 320
321 if (regmap_read(priv->regmap, TUSB320_REG9, &reg)) {321 if (regmap_read(priv->regmap, TUSB320_REG9, &reg)) {
@@ -323,7 +323,7 @@ static irqreturn_t tusb320_irq_handler(int irq, void *dev_id) · 1 unmodified line
323 return IRQ_NONE;323 return IRQ_NONE;
324 }324 }
325 325
326 if (!(reg & TUSB320_REG9_INTERRUPT_STATUS))326 if (!force_update && !(reg & TUSB320_REG9_INTERRUPT_STATUS))
327 return IRQ_NONE;327 return IRQ_NONE;
328 328
329 tusb320_extcon_irq_handler(priv, reg);329 tusb320_extcon_irq_handler(priv, reg);
@@ -340,6 +340,13 @@ static irqreturn_t tusb320_irq_handler(int irq, void *dev_id) · 10 unmodified lines
340 return IRQ_HANDLED;340 return IRQ_HANDLED;
341}341}
342 342
343static irqreturn_t tusb320_irq_handler(int irq, void *dev_id)
344{
345 struct tusb320_priv *priv = dev_id;
346
347 return tusb320_state_update_handler(priv, false);
348}
349
343static const struct regmap_config tusb320_regmap_config = {350static const struct regmap_config tusb320_regmap_config = {
344 .reg_bits = 8,351 .reg_bits = 8,
345 .val_bits = 8,352 .val_bits = 8,
@@ -466,7 +473,7 @@ static int tusb320_probe(struct i2c_client *client, · 120 unmodified lines
466 return ret;473 return ret;
467 474
468 /* update initial state */475 /* update initial state */
469 tusb320_irq_handler(client->irq, priv);476 tusb320_state_update_handler(priv, true);
470 477
471 /* Reset chip to its default state */478 /* Reset chip to its default state */
472 ret = tusb320_reset(priv);479 ret = tusb320_reset(priv);
@@ -477,7 +484,7 @@ static int tusb320_probe(struct i2c_client *client, · 4 unmodified lines
477 * State and polarity might change after a reset, so update484 * State and polarity might change after a reset, so update
478 * them again and make sure the interrupt status bit is cleared.485 * them again and make sure the interrupt status bit is cleared.
479 */486 */
480 tusb320_irq_handler(client->irq, priv);487 tusb320_state_update_handler(priv, true);
481 488
482 ret = devm_request_threaded_irq(priv->dev, client->irq, NULL,489 ret = devm_request_threaded_irq(priv->dev, client->irq, NULL,
483 tusb320_irq_handler,490 tusb320_irq_handler,
drivers/platform/chrome/cros_ec_typec.c+1−1
@@ -971,7 +971,7 @@ static void cros_typec_register_partner_pdos(struct cros_typec_data *typec, · 970 unmodified lines
971 if (!resp->source_cap_count && !resp->sink_cap_count)971 if (!resp->source_cap_count && !resp->sink_cap_count)
972 return;972 return;
973 973
974 port->partner_pd = usb_power_delivery_register(NULL, &desc);974 port->partner_pd = typec_partner_usb_power_delivery_register(port->partner, &desc);
975 if (IS_ERR(port->partner_pd)) {975 if (IS_ERR(port->partner_pd)) {
976 dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n", port_num);976 dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n", port_num);
977 return;977 return;
drivers/thunderbolt/acpi.c+4−8
@@ -15,24 +15,20 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data, · 14 unmodified lines
15 void **return_value)15 void **return_value)
16{16{
17 struct acpi_device *adev = acpi_fetch_acpi_dev(handle);17 struct acpi_device *adev = acpi_fetch_acpi_dev(handle);
18 struct fwnode_reference_args args;
19 struct fwnode_handle *fwnode;18 struct fwnode_handle *fwnode;
20 struct tb_nhi *nhi = data;19 struct tb_nhi *nhi = data;
21 struct pci_dev *pdev;20 struct pci_dev *pdev;
22 struct device *dev;21 struct device *dev;
23 int ret;
24 22
25 if (!adev)23 if (!adev)
26 return AE_OK;24 return AE_OK;
27 25
28 fwnode = acpi_fwnode_handle(adev);26 fwnode = fwnode_find_reference(acpi_fwnode_handle(adev), "usb4-host-interface", 0);
29 ret = fwnode_property_get_reference_args(fwnode, "usb4-host-interface",27 if (IS_ERR(fwnode))
30 NULL, 0, 0, &args);
31 if (ret)
32 return AE_OK;28 return AE_OK;
33 29
34 /* It needs to reference this NHI */30 /* It needs to reference this NHI */
35 if (dev_fwnode(&nhi->pdev->dev) != args.fwnode)31 if (dev_fwnode(&nhi->pdev->dev) != fwnode)
36 goto out_put;32 goto out_put;
37 33
38 /*34 /*
@@ -100,7 +96,7 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data, · 61 unmodified lines
100 }96 }
101 97
102out_put:98out_put:
103 fwnode_handle_put(args.fwnode);99 fwnode_handle_put(fwnode);
104 return AE_OK;100 return AE_OK;
105}101}
106 102
drivers/thunderbolt/switch.c+3−2
@@ -8,12 +8,13 @@ · 7 unmodified lines
8 8
9#include <linux/delay.h>9#include <linux/delay.h>
10#include <linux/idr.h>10#include <linux/idr.h>
11#include <linux/module.h>
11#include <linux/nvmem-provider.h>12#include <linux/nvmem-provider.h>
12#include <linux/pm_runtime.h>13#include <linux/pm_runtime.h>
13#include <linux/sched/signal.h>14#include <linux/sched/signal.h>
14#include <linux/sizes.h>15#include <linux/sizes.h>
15#include <linux/slab.h>16#include <linux/slab.h>
16#include <linux/module.h>17#include <linux/string_helpers.h>
17 18
18#include "tb.h"19#include "tb.h"
19 20
@@ -644,7 +645,7 @@ static int __tb_port_enable(struct tb_port *port, bool enable) · 624 unmodified lines
644 if (ret)645 if (ret)
645 return ret;646 return ret;
646 647
647 tb_port_dbg(port, "lane %sabled\n", enable ? "en" : "dis");648 tb_port_dbg(port, "lane %s\n", str_enabled_disabled(enable));
648 return 0;649 return 0;
649}650}
650 651
drivers/thunderbolt/tb_regs.h+2−0
@@ -361,6 +361,8 @@ struct tb_regs_port_header { · 360 unmodified lines
361#define PORT_CS_18_BE BIT(8)361#define PORT_CS_18_BE BIT(8)
362#define PORT_CS_18_TCM BIT(9)362#define PORT_CS_18_TCM BIT(9)
363#define PORT_CS_18_CPS BIT(10)363#define PORT_CS_18_CPS BIT(10)
364#define PORT_CS_18_WOCS BIT(16)
365#define PORT_CS_18_WODS BIT(17)
364#define PORT_CS_18_WOU4S BIT(18)366#define PORT_CS_18_WOU4S BIT(18)
365#define PORT_CS_19 0x13367#define PORT_CS_19 0x13
366#define PORT_CS_19_PC BIT(3)368#define PORT_CS_19_PC BIT(3)
drivers/thunderbolt/usb4.c+25−8
@@ -155,6 +155,8 @@ static inline int usb4_switch_op_data(struct tb_switch *sw, u16 opcode, · 154 unmodified lines
155 155
156static void usb4_switch_check_wakes(struct tb_switch *sw)156static void usb4_switch_check_wakes(struct tb_switch *sw)
157{157{
158 bool wakeup_usb4 = false;
159 struct usb4_port *usb4;
158 struct tb_port *port;160 struct tb_port *port;
159 bool wakeup = false;161 bool wakeup = false;
160 u32 val;162 u32 val;
@@ -173,20 +175,31 @@ static void usb4_switch_check_wakes(struct tb_switch *sw) · 12 unmodified lines
173 wakeup = val & (ROUTER_CS_6_WOPS | ROUTER_CS_6_WOUS);175 wakeup = val & (ROUTER_CS_6_WOPS | ROUTER_CS_6_WOUS);
174 }176 }
175 177
176 /* Check for any connected downstream ports for USB4 wake */178 /*
179 * Check for any downstream ports for USB4 wake,
180 * connection wake and disconnection wake.
181 */
177 tb_switch_for_each_port(sw, port) {182 tb_switch_for_each_port(sw, port) {
178 if (!tb_port_has_remote(port))183 if (!port->cap_usb4)
179 continue;184 continue;
180 185
181 if (tb_port_read(port, &val, TB_CFG_PORT,186 if (tb_port_read(port, &val, TB_CFG_PORT,
182 port->cap_usb4 + PORT_CS_18, 1))187 port->cap_usb4 + PORT_CS_18, 1))
183 break;188 break;
184 189
185 tb_port_dbg(port, "USB4 wake: %s\n",190 tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n",
186 (val & PORT_CS_18_WOU4S) ? "yes" : "no");191 (val & PORT_CS_18_WOU4S) ? "yes" : "no",
192 (val & PORT_CS_18_WOCS) ? "yes" : "no",
193 (val & PORT_CS_18_WODS) ? "yes" : "no");
194
195 wakeup_usb4 = val & (PORT_CS_18_WOU4S | PORT_CS_18_WOCS |
196 PORT_CS_18_WODS);
197
198 usb4 = port->usb4;
199 if (device_may_wakeup(&usb4->dev) && wakeup_usb4)
200 pm_wakeup_event(&usb4->dev, 0);
187 201
188 if (val & PORT_CS_18_WOU4S)202 wakeup |= wakeup_usb4;
189 wakeup = true;
190 }203 }
191 204
192 if (wakeup)205 if (wakeup)
@@ -366,6 +379,7 @@ bool usb4_switch_lane_bonding_possible(struct tb_switch *sw) · 173 unmodified lines
366 */379 */
367int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)380int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)
368{381{
382 struct usb4_port *usb4;
369 struct tb_port *port;383 struct tb_port *port;
370 u64 route = tb_route(sw);384 u64 route = tb_route(sw);
371 u32 val;385 u32 val;
@@ -395,10 +409,13 @@ int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags) · 23 unmodified lines
395 val |= PORT_CS_19_WOU4;409 val |= PORT_CS_19_WOU4;
396 } else {410 } else {
397 bool configured = val & PORT_CS_19_PC;411 bool configured = val & PORT_CS_19_PC;
412 usb4 = port->usb4;
398 413
399 if ((flags & TB_WAKE_ON_CONNECT) && !configured)414 if (((flags & TB_WAKE_ON_CONNECT) |
415 device_may_wakeup(&usb4->dev)) && !configured)
400 val |= PORT_CS_19_WOC;416 val |= PORT_CS_19_WOC;
401 if ((flags & TB_WAKE_ON_DISCONNECT) && configured)417 if (((flags & TB_WAKE_ON_DISCONNECT) |
418 device_may_wakeup(&usb4->dev)) && configured)
402 val |= PORT_CS_19_WOD;419 val |= PORT_CS_19_WOD;
403 if ((flags & TB_WAKE_ON_USB4) && configured)420 if ((flags & TB_WAKE_ON_USB4) && configured)
404 val |= PORT_CS_19_WOU4;421 val |= PORT_CS_19_WOU4;
drivers/thunderbolt/usb4_port.c+3−0
@@ -284,6 +284,9 @@ struct usb4_port *usb4_port_device_add(struct tb_port *port) · 283 unmodified lines
284 }284 }
285 }285 }
286 286
287 if (!tb_is_upstream_port(port))
288 device_set_wakeup_capable(&usb4->dev, true);
289
287 pm_runtime_no_callbacks(&usb4->dev);290 pm_runtime_no_callbacks(&usb4->dev);
288 pm_runtime_set_active(&usb4->dev);291 pm_runtime_set_active(&usb4->dev);
289 pm_runtime_enable(&usb4->dev);292 pm_runtime_enable(&usb4->dev);
drivers/thunderbolt/xdomain.c+2−2
@@ -13,6 +13,7 @@ · 12 unmodified lines
13#include <linux/module.h>13#include <linux/module.h>
14#include <linux/pm_runtime.h>14#include <linux/pm_runtime.h>
15#include <linux/prandom.h>15#include <linux/prandom.h>
16#include <linux/string_helpers.h>
16#include <linux/utsname.h>17#include <linux/utsname.h>
17#include <linux/uuid.h>18#include <linux/uuid.h>
18#include <linux/workqueue.h>19#include <linux/workqueue.h>
@@ -341,7 +342,6 @@ static int tb_xdp_properties_request(struct tb_ctl *ctl, u64 route, · 322 unmodified lines
341 memcpy(&req.src_uuid, src_uuid, sizeof(*src_uuid));342 memcpy(&req.src_uuid, src_uuid, sizeof(*src_uuid));
342 memcpy(&req.dst_uuid, dst_uuid, sizeof(*dst_uuid));343 memcpy(&req.dst_uuid, dst_uuid, sizeof(*dst_uuid));
343 344
344 len = 0;
345 data_len = 0;345 data_len = 0;
346 346
347 do {347 do {
@@ -1344,7 +1344,7 @@ static int tb_xdomain_bond_lanes_uuid_high(struct tb_xdomain *xd) · 996 unmodified lines
1344 tb_port_update_credits(port);1344 tb_port_update_credits(port);
1345 tb_xdomain_update_link_attributes(xd);1345 tb_xdomain_update_link_attributes(xd);
1346 1346
1347 dev_dbg(&xd->dev, "lane bonding %sabled\n", width == 2 ? "en" : "dis");1347 dev_dbg(&xd->dev, "lane bonding %s\n", str_enabled_disabled(width == 2));
1348 return 0;1348 return 0;
1349}1349}
1350 1350
drivers/usb/Kconfig+4−0
@@ -111,8 +111,12 @@ source "drivers/usb/usbip/Kconfig" · 110 unmodified lines
111 111
112endif112endif
113 113
114comment "USB dual-mode controller drivers"
115
114source "drivers/usb/cdns3/Kconfig"116source "drivers/usb/cdns3/Kconfig"
115 117
118source "drivers/usb/fotg210/Kconfig"
119
116source "drivers/usb/mtu3/Kconfig"120source "drivers/usb/mtu3/Kconfig"
117 121
118source "drivers/usb/musb/Kconfig"122source "drivers/usb/musb/Kconfig"
drivers/usb/Makefile+2−0
@@ -17,6 +17,8 @@ obj-$(CONFIG_USB_CDNS_SUPPORT) += cdns3/ · 16 unmodified lines
17obj-$(CONFIG_USB_CDNS3) += cdns3/17obj-$(CONFIG_USB_CDNS3) += cdns3/
18obj-$(CONFIG_USB_CDNSP_PCI) += cdns3/18obj-$(CONFIG_USB_CDNSP_PCI) += cdns3/
19 19
20obj-$(CONFIG_USB_FOTG210) += fotg210/
21
20obj-$(CONFIG_USB_MON) += mon/22obj-$(CONFIG_USB_MON) += mon/
21obj-$(CONFIG_USB_MTU3) += mtu3/23obj-$(CONFIG_USB_MTU3) += mtu3/
22 24
drivers/usb/cdns3/cdnsp-pci.c+3−5
@@ -192,14 +192,12 @@ static void cdnsp_pci_remove(struct pci_dev *pdev) · 191 unmodified lines
192 if (pci_dev_run_wake(pdev))192 if (pci_dev_run_wake(pdev))
193 pm_runtime_get_noresume(&pdev->dev);193 pm_runtime_get_noresume(&pdev->dev);
194 194
195 if (!pci_is_enabled(func)) {195 if (pci_is_enabled(func)) {
196 cdns_remove(cdnsp);
197 } else {
196 kfree(cdnsp);198 kfree(cdnsp);
197 goto pci_put;
198 }199 }
199 200
200 cdns_remove(cdnsp);
201
202pci_put:
203 pci_dev_put(func);201 pci_dev_put(func);
204}202}
205 203
drivers/usb/cdns3/cdnsp-ring.c+32−10
@@ -2006,10 +2006,11 @@ int cdnsp_queue_bulk_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq) · 2005 unmodified lines
2006 2006
2007int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq)2007int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq)
2008{2008{
2009 u32 field, length_field, remainder;2009 u32 field, length_field, zlp = 0;
2010 struct cdnsp_ep *pep = preq->pep;2010 struct cdnsp_ep *pep = preq->pep;
2011 struct cdnsp_ring *ep_ring;2011 struct cdnsp_ring *ep_ring;
2012 int num_trbs;2012 int num_trbs;
2013 u32 maxp;
2013 int ret;2014 int ret;
2014 2015
2015 ep_ring = cdnsp_request_to_transfer_ring(pdev, preq);2016 ep_ring = cdnsp_request_to_transfer_ring(pdev, preq);
@@ -2019,26 +2020,33 @@ int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq) · 3 unmodified lines
2019 /* 1 TRB for data, 1 for status */2020 /* 1 TRB for data, 1 for status */
2020 num_trbs = (pdev->three_stage_setup) ? 2 : 1;2021 num_trbs = (pdev->three_stage_setup) ? 2 : 1;
2021 2022
2023 maxp = usb_endpoint_maxp(pep->endpoint.desc);
2024
2025 if (preq->request.zero && preq->request.length &&
2026 (preq->request.length % maxp == 0)) {
2027 num_trbs++;
2028 zlp = 1;
2029 }
2030
2022 ret = cdnsp_prepare_transfer(pdev, preq, num_trbs);2031 ret = cdnsp_prepare_transfer(pdev, preq, num_trbs);
2023 if (ret)2032 if (ret)
2024 return ret;2033 return ret;
2025 2034
2026 /* If there's data, queue data TRBs */2035 /* If there's data, queue data TRBs */
2027 if (pdev->ep0_expect_in)
2028 field = TRB_TYPE(TRB_DATA) | TRB_IOC;
2029 else
2030 field = TRB_ISP | TRB_TYPE(TRB_DATA) | TRB_IOC;
2031
2032 if (preq->request.length > 0) {2036 if (preq->request.length > 0) {
2033 remainder = cdnsp_td_remainder(pdev, 0, preq->request.length,2037 field = TRB_TYPE(TRB_DATA);
2034 preq->request.length, preq, 1, 0);
2035 2038
2036 length_field = TRB_LEN(preq->request.length) |2039 if (zlp)
2037 TRB_TD_SIZE(remainder) | TRB_INTR_TARGET(0);2040 field |= TRB_CHAIN;
2041 else
2042 field |= TRB_IOC | (pdev->ep0_expect_in ? 0 : TRB_ISP);
2038 2043
2039 if (pdev->ep0_expect_in)2044 if (pdev->ep0_expect_in)
2040 field |= TRB_DIR_IN;2045 field |= TRB_DIR_IN;
2041 2046
2047 length_field = TRB_LEN(preq->request.length) |
2048 TRB_TD_SIZE(zlp) | TRB_INTR_TARGET(0);
2049
2042 cdnsp_queue_trb(pdev, ep_ring, true,2050 cdnsp_queue_trb(pdev, ep_ring, true,
2043 lower_32_bits(preq->request.dma),2051 lower_32_bits(preq->request.dma),
2044 upper_32_bits(preq->request.dma), length_field,2052 upper_32_bits(preq->request.dma), length_field,
@@ -2046,6 +2054,20 @@ int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq) · 1 unmodified line
2046 TRB_SETUPID(pdev->setup_id) |2054 TRB_SETUPID(pdev->setup_id) |
2047 pdev->setup_speed);2055 pdev->setup_speed);
2048 2056
2057 if (zlp) {
2058 field = TRB_TYPE(TRB_NORMAL) | TRB_IOC;
2059
2060 if (!pdev->ep0_expect_in)
2061 field = TRB_ISP;
2062
2063 cdnsp_queue_trb(pdev, ep_ring, true,
2064 lower_32_bits(preq->request.dma),
2065 upper_32_bits(preq->request.dma), 0,
2066 field | ep_ring->cycle_state |
2067 TRB_SETUPID(pdev->setup_id) |
2068 pdev->setup_speed);
2069 }
2070
2049 pdev->ep0_stage = CDNSP_DATA_STAGE;2071 pdev->ep0_stage = CDNSP_DATA_STAGE;
2050 }2072 }
2051 2073
drivers/usb/chipidea/ci.h+4−0
@@ -127,12 +127,16 @@ enum ci_revision { · 126 unmodified lines
127 * struct ci_role_driver - host/gadget role driver127 * struct ci_role_driver - host/gadget role driver
128 * @start: start this role128 * @start: start this role
129 * @stop: stop this role129 * @stop: stop this role
130 * @suspend: system suspend handler for this role
131 * @resume: system resume handler for this role
130 * @irq: irq handler for this role132 * @irq: irq handler for this role
131 * @name: role name string (host/gadget)133 * @name: role name string (host/gadget)
132 */134 */
133struct ci_role_driver {135struct ci_role_driver {
134 int (*start)(struct ci_hdrc *);136 int (*start)(struct ci_hdrc *);
135 void (*stop)(struct ci_hdrc *);137 void (*stop)(struct ci_hdrc *);
138 void (*suspend)(struct ci_hdrc *ci);
139 void (*resume)(struct ci_hdrc *ci, bool power_lost);
136 irqreturn_t (*irq)(struct ci_hdrc *);140 irqreturn_t (*irq)(struct ci_hdrc *);
137 const char *name;141 const char *name;
138};142};
drivers/usb/chipidea/ci_hdrc_imx.c+16−35
@@ -355,7 +355,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) · 354 unmodified lines
355 data->hsic_pad_regulator =355 data->hsic_pad_regulator =
356 devm_regulator_get_optional(dev, "hsic");356 devm_regulator_get_optional(dev, "hsic");
357 if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) {357 if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) {
358 /* no pad regualator is needed */358 /* no pad regulator is needed */
359 data->hsic_pad_regulator = NULL;359 data->hsic_pad_regulator = NULL;
360 } else if (IS_ERR(data->hsic_pad_regulator))360 } else if (IS_ERR(data->hsic_pad_regulator))
361 return dev_err_probe(dev, PTR_ERR(data->hsic_pad_regulator),361 return dev_err_probe(dev, PTR_ERR(data->hsic_pad_regulator),
@@ -527,16 +527,19 @@ static void ci_hdrc_imx_shutdown(struct platform_device *pdev) · 165 unmodified lines
527 ci_hdrc_imx_remove(pdev);527 ci_hdrc_imx_remove(pdev);
528}528}
529 529
530static int __maybe_unused imx_controller_suspend(struct device *dev)530static int __maybe_unused imx_controller_suspend(struct device *dev,
531 pm_message_t msg)
531{532{
532 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);533 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
533 int ret = 0;534 int ret = 0;
534 535
535 dev_dbg(dev, "at %s\n", __func__);536 dev_dbg(dev, "at %s\n", __func__);
536 537
537 ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, false);538 ret = imx_usbmisc_suspend(data->usbmisc_data,
539 PMSG_IS_AUTO(msg) || device_may_wakeup(dev));
538 if (ret) {540 if (ret) {
539 dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret);541 dev_err(dev,
542 "usbmisc suspend failed, ret=%d\n", ret);
540 return ret;543 return ret;
541 }544 }
542 545
@@ -549,7 +552,8 @@ static int __maybe_unused imx_controller_suspend(struct device *dev) · 6 unmodified lines
549 return 0;552 return 0;
550}553}
551 554
552static int __maybe_unused imx_controller_resume(struct device *dev)555static int __maybe_unused imx_controller_resume(struct device *dev,
556 pm_message_t msg)
553{557{
554 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);558 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
555 int ret = 0;559 int ret = 0;
@@ -570,22 +574,15 @@ static int __maybe_unused imx_controller_resume(struct device *dev) · 14 unmodified lines
570 574
571 data->in_lpm = false;575 data->in_lpm = false;
572 576
573 ret = imx_usbmisc_set_wakeup(data->usbmisc_data, false);577 ret = imx_usbmisc_resume(data->usbmisc_data,
578 PMSG_IS_AUTO(msg) || device_may_wakeup(dev));
574 if (ret) {579 if (ret) {
575 dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret);580 dev_err(dev, "usbmisc resume failed, ret=%d\n", ret);
576 goto clk_disable;581 goto clk_disable;
577 }582 }
578 583
579 ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, true);
580 if (ret) {
581 dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret);
582 goto hsic_set_clk_fail;
583 }
584
585 return 0;584 return 0;
586 585
587hsic_set_clk_fail:
588 imx_usbmisc_set_wakeup(data->usbmisc_data, true);
589clk_disable:586clk_disable:
590 imx_disable_unprepare_clks(dev);587 imx_disable_unprepare_clks(dev);
591 return ret;588 return ret;
@@ -601,16 +598,7 @@ static int __maybe_unused ci_hdrc_imx_suspend(struct device *dev) · 9 unmodified lines
601 /* The core's suspend doesn't run */598 /* The core's suspend doesn't run */
602 return 0;599 return 0;
603 600
604 if (device_may_wakeup(dev)) {601 ret = imx_controller_suspend(dev, PMSG_SUSPEND);
605 ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true);
606 if (ret) {
607 dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n",
608 ret);
609 return ret;
610 }
611 }
612
613 ret = imx_controller_suspend(dev);
614 if (ret)602 if (ret)
615 return ret;603 return ret;
616 604
@@ -624,7 +612,7 @@ static int __maybe_unused ci_hdrc_imx_resume(struct device *dev) · 7 unmodified lines
624 int ret;612 int ret;
625 613
626 pinctrl_pm_select_default_state(dev);614 pinctrl_pm_select_default_state(dev);
627 ret = imx_controller_resume(dev);615 ret = imx_controller_resume(dev, PMSG_RESUME);
628 if (!ret && data->supports_runtime_pm) {616 if (!ret && data->supports_runtime_pm) {
629 pm_runtime_disable(dev);617 pm_runtime_disable(dev);
630 pm_runtime_set_active(dev);618 pm_runtime_set_active(dev);
@@ -637,25 +625,18 @@ static int __maybe_unused ci_hdrc_imx_resume(struct device *dev) · 6 unmodified lines
637static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev)625static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev)
638{626{
639 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);627 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
640 int ret;
641 628
642 if (data->in_lpm) {629 if (data->in_lpm) {
643 WARN_ON(1);630 WARN_ON(1);
644 return 0;631 return 0;
645 }632 }
646 633
647 ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true);634 return imx_controller_suspend(dev, PMSG_AUTO_SUSPEND);
648 if (ret) {
649 dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret);
650 return ret;
651 }
652
653 return imx_controller_suspend(dev);
654}635}
655 636
656static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev)637static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev)
657{638{
658 return imx_controller_resume(dev);639 return imx_controller_resume(dev, PMSG_AUTO_RESUME);
659}640}
660 641
661static const struct dev_pm_ops ci_hdrc_imx_pm_ops = {642static const struct dev_pm_ops ci_hdrc_imx_pm_ops = {
drivers/usb/chipidea/ci_hdrc_imx.h+2−2
@@ -32,9 +32,9 @@ struct imx_usbmisc_data { · 31 unmodified lines
32 32
33int imx_usbmisc_init(struct imx_usbmisc_data *data);33int imx_usbmisc_init(struct imx_usbmisc_data *data);
34int imx_usbmisc_init_post(struct imx_usbmisc_data *data);34int imx_usbmisc_init_post(struct imx_usbmisc_data *data);
35int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled);
36int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data);35int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data);
37int imx_usbmisc_hsic_set_clk(struct imx_usbmisc_data *data, bool on);
38int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect);36int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect);
37int imx_usbmisc_suspend(struct imx_usbmisc_data *data, bool wakeup);
38int imx_usbmisc_resume(struct imx_usbmisc_data *data, bool wakeup);
39 39
40#endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H */40#endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H */
drivers/usb/chipidea/core.c+89−54
@@ -608,52 +608,59 @@ static int ci_usb_role_switch_set(struct usb_role_switch *sw, · 607 unmodified lines
608 enum usb_role role)608 enum usb_role role)
609{609{
610 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw);610 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw);
611 struct ci_hdrc_cable *cable = NULL;611 struct ci_hdrc_cable *cable;
612 enum usb_role current_role = ci_role_to_usb_role(ci);
613 enum ci_role ci_role = usb_role_to_ci_role(role);
614 unsigned long flags;
615
616 if ((ci_role != CI_ROLE_END && !ci->roles[ci_role]) ||
617 (current_role == role))
618 return 0;
619 612
620 pm_runtime_get_sync(ci->dev);613 if (role == USB_ROLE_HOST) {
621 /* Stop current role */614 cable = &ci->platdata->id_extcon;
622 spin_lock_irqsave(&ci->lock, flags);615 cable->changed = true;
623 if (current_role == USB_ROLE_DEVICE)616 cable->connected = true;
624 cable = &ci->platdata->vbus_extcon;617 cable = &ci->platdata->vbus_extcon;
625 else if (current_role == USB_ROLE_HOST)618 cable->changed = true;
619 cable->connected = false;
620 } else if (role == USB_ROLE_DEVICE) {
626 cable = &ci->platdata->id_extcon;621 cable = &ci->platdata->id_extcon;
627
628 if (cable) {
629 cable->changed = true;622 cable->changed = true;
630 cable->connected = false;623 cable->connected = false;
631 ci_irq(ci);
632 spin_unlock_irqrestore(&ci->lock, flags);
633 if (ci->wq && role != USB_ROLE_NONE)
634 flush_workqueue(ci->wq);
635 spin_lock_irqsave(&ci->lock, flags);
636 }
637
638 cable = NULL;
639
640 /* Start target role */
641 if (role == USB_ROLE_DEVICE)
642 cable = &ci->platdata->vbus_extcon;624 cable = &ci->platdata->vbus_extcon;
643 else if (role == USB_ROLE_HOST)
644 cable = &ci->platdata->id_extcon;
645
646 if (cable) {
647 cable->changed = true;625 cable->changed = true;
648 cable->connected = true;626 cable->connected = true;
649 ci_irq(ci);627 } else {
628 cable = &ci->platdata->id_extcon;
629 cable->changed = true;
630 cable->connected = false;
631 cable = &ci->platdata->vbus_extcon;
632 cable->changed = true;
633 cable->connected = false;
650 }634 }
651 spin_unlock_irqrestore(&ci->lock, flags);
652 pm_runtime_put_sync(ci->dev);
653 635
636 ci_irq(ci);
654 return 0;637 return 0;
655}638}
656 639
640static enum ci_role ci_get_role(struct ci_hdrc *ci)
641{
642 enum ci_role role;
643
644 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
645 if (ci->is_otg) {
646 role = ci_otg_role(ci);
647 hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE);
648 } else {
649 /*
650 * If the controller is not OTG capable, but support
651 * role switch, the defalt role is gadget, and the
652 * user can switch it through debugfs.
653 */
654 role = CI_ROLE_GADGET;
655 }
656 } else {
657 role = ci->roles[CI_ROLE_HOST] ? CI_ROLE_HOST
658 : CI_ROLE_GADGET;
659 }
660
661 return role;
662}
663
657static struct usb_role_switch_desc ci_role_switch = {664static struct usb_role_switch_desc ci_role_switch = {
658 .set = ci_usb_role_switch_set,665 .set = ci_usb_role_switch_set,
659 .get = ci_usb_role_switch_get,666 .get = ci_usb_role_switch_get,
@@ -1151,25 +1158,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) · 491 unmodified lines
1151 }1158 }
1152 }1159 }
1153 1160
1154 if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {1161 ci->role = ci_get_role(ci);
1155 if (ci->is_otg) {
1156 ci->role = ci_otg_role(ci);
1157 /* Enable ID change irq */
1158 hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE);
1159 } else {
1160 /*
1161 * If the controller is not OTG capable, but support
1162 * role switch, the defalt role is gadget, and the
1163 * user can switch it through debugfs.
1164 */
1165 ci->role = CI_ROLE_GADGET;
1166 }
1167 } else {
1168 ci->role = ci->roles[CI_ROLE_HOST]
1169 ? CI_ROLE_HOST
1170 : CI_ROLE_GADGET;
1171 }
1172
1173 if (!ci_otg_is_fsm_mode(ci)) {1162 if (!ci_otg_is_fsm_mode(ci)) {
1174 /* only update vbus status for peripheral */1163 /* only update vbus status for peripheral */
1175 if (ci->role == CI_ROLE_GADGET) {1164 if (ci->role == CI_ROLE_GADGET) {
@@ -1305,11 +1294,13 @@ static void ci_extcon_wakeup_int(struct ci_hdrc *ci) · 129 unmodified lines
1305 cable_id = &ci->platdata->id_extcon;1294 cable_id = &ci->platdata->id_extcon;
1306 cable_vbus = &ci->platdata->vbus_extcon;1295 cable_vbus = &ci->platdata->vbus_extcon;
1307 1296
1308 if (!IS_ERR(cable_id->edev) && ci->is_otg &&1297 if ((!IS_ERR(cable_id->edev) || !IS_ERR(ci->role_switch))
1298 && ci->is_otg &&
1309 (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS))1299 (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS))
1310 ci_irq(ci);1300 ci_irq(ci);
1311 1301
1312 if (!IS_ERR(cable_vbus->edev) && ci->is_otg &&1302 if ((!IS_ERR(cable_vbus->edev) || !IS_ERR(ci->role_switch))
1303 && ci->is_otg &&
1313 (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS))1304 (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS))
1314 ci_irq(ci);1305 ci_irq(ci);
1315}1306}
@@ -1373,6 +1364,10 @@ static int ci_suspend(struct device *dev) · 57 unmodified lines
1373 return 0;1364 return 0;
1374 }1365 }
1375 1366
1367 /* Extra routine per role before system suspend */
1368 if (ci->role != CI_ROLE_END && ci_role(ci)->suspend)
1369 ci_role(ci)->suspend(ci);
1370
1376 if (device_may_wakeup(dev)) {1371 if (device_may_wakeup(dev)) {
1377 if (ci_otg_is_fsm_mode(ci))1372 if (ci_otg_is_fsm_mode(ci))
1378 ci_otg_fsm_suspend_for_srp(ci);1373 ci_otg_fsm_suspend_for_srp(ci);
@@ -1386,11 +1381,38 @@ static int ci_suspend(struct device *dev) · 7 unmodified lines
1386 return 0;1381 return 0;
1387}1382}
1388 1383
1384static void ci_handle_power_lost(struct ci_hdrc *ci)
1385{
1386 enum ci_role role;
1387
1388 disable_irq_nosync(ci->irq);
1389 if (!ci_otg_is_fsm_mode(ci)) {
1390 role = ci_get_role(ci);
1391
1392 if (ci->role != role) {
1393 ci_handle_id_switch(ci);
1394 } else if (role == CI_ROLE_GADGET) {
1395 if (ci->is_otg && hw_read_otgsc(ci, OTGSC_BSV))
1396 usb_gadget_vbus_connect(&ci->gadget);
1397 }
1398 }
1399
1400 enable_irq(ci->irq);
1401}
1402
1389static int ci_resume(struct device *dev)1403static int ci_resume(struct device *dev)
1390{1404{
1391 struct ci_hdrc *ci = dev_get_drvdata(dev);1405 struct ci_hdrc *ci = dev_get_drvdata(dev);
1406 bool power_lost;
1392 int ret;1407 int ret;
1393 1408
1409 /* Since ASYNCLISTADDR (host mode) and ENDPTLISTADDR (device
1410 * mode) share the same register address. We can check if
1411 * controller resume from power lost based on this address
1412 * due to this register will be reset after power lost.
1413 */
1414 power_lost = !hw_read(ci, OP_ENDPTLISTADDR, ~0);
1415
1394 if (device_may_wakeup(dev))1416 if (device_may_wakeup(dev))
1395 disable_irq_wake(ci->irq);1417 disable_irq_wake(ci->irq);
1396 1418
@@ -1398,6 +1420,19 @@ static int ci_resume(struct device *dev) · 1 unmodified line
1398 if (ret)1420 if (ret)
1399 return ret;1421 return ret;
1400 1422
1423 if (power_lost) {
1424 /* shutdown and re-init for phy */
1425 ci_usb_phy_exit(ci);
1426 ci_usb_phy_init(ci);
1427 }
1428
1429 /* Extra routine per role after system resume */
1430 if (ci->role != CI_ROLE_END && ci_role(ci)->resume)
1431 ci_role(ci)->resume(ci, power_lost);
1432
1433 if (power_lost)
1434 ci_handle_power_lost(ci);
1435
1401 if (ci->supports_runtime_pm) {1436 if (ci->supports_runtime_pm) {
1402 pm_runtime_disable(dev);1437 pm_runtime_disable(dev);
1403 pm_runtime_set_active(dev);1438 pm_runtime_set_active(dev);
drivers/usb/chipidea/host.c+16−0
@@ -459,6 +459,18 @@ static void ci_hdrc_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) · 458 unmodified lines
459 ci_hdrc_free_dma_aligned_buffer(urb);459 ci_hdrc_free_dma_aligned_buffer(urb);
460}460}
461 461
462#ifdef CONFIG_PM_SLEEP
463static void ci_hdrc_host_suspend(struct ci_hdrc *ci)
464{
465 ehci_suspend(ci->hcd, device_may_wakeup(ci->dev));
466}
467
468static void ci_hdrc_host_resume(struct ci_hdrc *ci, bool power_lost)
469{
470 ehci_resume(ci->hcd, power_lost);
471}
472#endif
473
462int ci_hdrc_host_init(struct ci_hdrc *ci)474int ci_hdrc_host_init(struct ci_hdrc *ci)
463{475{
464 struct ci_role_driver *rdrv;476 struct ci_role_driver *rdrv;
@@ -472,6 +484,10 @@ int ci_hdrc_host_init(struct ci_hdrc *ci) · 7 unmodified lines
472 484
473 rdrv->start = host_start;485 rdrv->start = host_start;
474 rdrv->stop = host_stop;486 rdrv->stop = host_stop;
487#ifdef CONFIG_PM_SLEEP
488 rdrv->suspend = ci_hdrc_host_suspend;
489 rdrv->resume = ci_hdrc_host_resume;
490#endif
475 rdrv->irq = host_irq;491 rdrv->irq = host_irq;
476 rdrv->name = "host";492 rdrv->name = "host";
477 ci->roles[CI_ROLE_HOST] = rdrv;493 ci->roles[CI_ROLE_HOST] = rdrv;
drivers/usb/chipidea/otg.c+1−1
@@ -165,7 +165,7 @@ static int hw_wait_vbus_lower_bsv(struct ci_hdrc *ci) · 164 unmodified lines
165 return 0;165 return 0;
166}166}
167 167
168static void ci_handle_id_switch(struct ci_hdrc *ci)168void ci_handle_id_switch(struct ci_hdrc *ci)
169{169{
170 enum ci_role role = ci_otg_role(ci);170 enum ci_role role = ci_otg_role(ci);
171 171
drivers/usb/chipidea/otg.h+1−0
@@ -14,6 +14,7 @@ int ci_hdrc_otg_init(struct ci_hdrc *ci); · 13 unmodified lines
14void ci_hdrc_otg_destroy(struct ci_hdrc *ci);14void ci_hdrc_otg_destroy(struct ci_hdrc *ci);
15enum ci_role ci_otg_role(struct ci_hdrc *ci);15enum ci_role ci_otg_role(struct ci_hdrc *ci);
16void ci_handle_vbus_change(struct ci_hdrc *ci);16void ci_handle_vbus_change(struct ci_hdrc *ci);
17void ci_handle_id_switch(struct ci_hdrc *ci);
17static inline void ci_otg_queue_work(struct ci_hdrc *ci)18static inline void ci_otg_queue_work(struct ci_hdrc *ci)
18{19{
19 disable_irq_nosync(ci->irq);20 disable_irq_nosync(ci->irq);
drivers/usb/chipidea/udc.c+32−0
@@ -2181,6 +2181,34 @@ static void udc_id_switch_for_host(struct ci_hdrc *ci) · 2180 unmodified lines
2181 ci->platdata->pins_default);2181 ci->platdata->pins_default);
2182}2182}
2183 2183
2184#ifdef CONFIG_PM_SLEEP
2185static void udc_suspend(struct ci_hdrc *ci)
2186{
2187 /*
2188 * Set OP_ENDPTLISTADDR to be non-zero for
2189 * checking if controller resume from power lost
2190 * in non-host mode.
2191 */
2192 if (hw_read(ci, OP_ENDPTLISTADDR, ~0) == 0)
2193 hw_write(ci, OP_ENDPTLISTADDR, ~0, ~0);
2194}
2195
2196static void udc_resume(struct ci_hdrc *ci, bool power_lost)
2197{
2198 if (power_lost) {
2199 if (ci->is_otg)
2200 hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE,
2201 OTGSC_BSVIS | OTGSC_BSVIE);
2202 if (ci->vbus_active)
2203 usb_gadget_vbus_disconnect(&ci->gadget);
2204 }
2205
2206 /* Restore value 0 if it was set for power lost check */
2207 if (hw_read(ci, OP_ENDPTLISTADDR, ~0) == 0xFFFFFFFF)
2208 hw_write(ci, OP_ENDPTLISTADDR, ~0, 0);
2209}
2210#endif
2211
2184/**2212/**
2185 * ci_hdrc_gadget_init - initialize device related bits2213 * ci_hdrc_gadget_init - initialize device related bits
2186 * @ci: the controller2214 * @ci: the controller
@@ -2201,6 +2229,10 @@ int ci_hdrc_gadget_init(struct ci_hdrc *ci) · 14 unmodified lines
2201 2229
2202 rdrv->start = udc_id_switch_for_device;2230 rdrv->start = udc_id_switch_for_device;
2203 rdrv->stop = udc_id_switch_for_host;2231 rdrv->stop = udc_id_switch_for_host;
2232#ifdef CONFIG_PM_SLEEP
2233 rdrv->suspend = udc_suspend;
2234 rdrv->resume = udc_resume;
2235#endif
2204 rdrv->irq = udc_irq;2236 rdrv->irq = udc_irq;
2205 rdrv->name = "gadget";2237 rdrv->name = "gadget";
2206 2238
drivers/usb/chipidea/usbmisc_imx.c+130−30
@@ -150,6 +150,8 @@ struct usbmisc_ops { · 149 unmodified lines
150 int (*hsic_set_clk)(struct imx_usbmisc_data *data, bool enabled);150 int (*hsic_set_clk)(struct imx_usbmisc_data *data, bool enabled);
151 /* usb charger detection */151 /* usb charger detection */
152 int (*charger_detection)(struct imx_usbmisc_data *data);152 int (*charger_detection)(struct imx_usbmisc_data *data);
153 /* It's called when system resume from usb power lost */
154 int (*power_lost_check)(struct imx_usbmisc_data *data);
153};155};
154 156
155struct imx_usbmisc {157struct imx_usbmisc {
@@ -937,6 +939,44 @@ static int usbmisc_imx7ulp_init(struct imx_usbmisc_data *data) · 781 unmodified lines
937 return 0;939 return 0;
938}940}
939 941
942static int usbmisc_imx7d_power_lost_check(struct imx_usbmisc_data *data)
943{
944 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
945 unsigned long flags;
946 u32 val;
947
948 spin_lock_irqsave(&usbmisc->lock, flags);
949 val = readl(usbmisc->base);
950 spin_unlock_irqrestore(&usbmisc->lock, flags);
951 /*
952 * Here use a power on reset value to judge
953 * if the controller experienced a power lost
954 */
955 if (val == 0x30001000)
956 return 1;
957 else
958 return 0;
959}
960
961static int usbmisc_imx6sx_power_lost_check(struct imx_usbmisc_data *data)
962{
963 struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
964 unsigned long flags;
965 u32 val;
966
967 spin_lock_irqsave(&usbmisc->lock, flags);
968 val = readl(usbmisc->base + data->index * 4);
969 spin_unlock_irqrestore(&usbmisc->lock, flags);
970 /*
971 * Here use a power on reset value to judge
972 * if the controller experienced a power lost
973 */
974 if (val == 0x30001000)
975 return 1;
976 else
977 return 0;
978}
979
940static const struct usbmisc_ops imx25_usbmisc_ops = {980static const struct usbmisc_ops imx25_usbmisc_ops = {
941 .init = usbmisc_imx25_init,981 .init = usbmisc_imx25_init,
942 .post = usbmisc_imx25_post,982 .post = usbmisc_imx25_post,
@@ -970,12 +1010,14 @@ static const struct usbmisc_ops imx6sx_usbmisc_ops = { · 27 unmodified lines
970 .init = usbmisc_imx6sx_init,1010 .init = usbmisc_imx6sx_init,
971 .hsic_set_connect = usbmisc_imx6_hsic_set_connect,1011 .hsic_set_connect = usbmisc_imx6_hsic_set_connect,
972 .hsic_set_clk = usbmisc_imx6_hsic_set_clk,1012 .hsic_set_clk = usbmisc_imx6_hsic_set_clk,
1013 .power_lost_check = usbmisc_imx6sx_power_lost_check,
973};1014};
974 1015
975static const struct usbmisc_ops imx7d_usbmisc_ops = {1016static const struct usbmisc_ops imx7d_usbmisc_ops = {
976 .init = usbmisc_imx7d_init,1017 .init = usbmisc_imx7d_init,
977 .set_wakeup = usbmisc_imx7d_set_wakeup,1018 .set_wakeup = usbmisc_imx7d_set_wakeup,
978 .charger_detection = imx7d_charger_detection,1019 .charger_detection = imx7d_charger_detection,
1020 .power_lost_check = usbmisc_imx7d_power_lost_check,
979};1021};
980 1022
981static const struct usbmisc_ops imx7ulp_usbmisc_ops = {1023static const struct usbmisc_ops imx7ulp_usbmisc_ops = {
@@ -983,6 +1025,7 @@ static const struct usbmisc_ops imx7ulp_usbmisc_ops = { · 1 unmodified line
983 .set_wakeup = usbmisc_imx7d_set_wakeup,1025 .set_wakeup = usbmisc_imx7d_set_wakeup,
984 .hsic_set_connect = usbmisc_imx6_hsic_set_connect,1026 .hsic_set_connect = usbmisc_imx6_hsic_set_connect,
985 .hsic_set_clk = usbmisc_imx6_hsic_set_clk,1027 .hsic_set_clk = usbmisc_imx6_hsic_set_clk,
1028 .power_lost_check = usbmisc_imx7d_power_lost_check,
986};1029};
987 1030
988static inline bool is_imx53_usbmisc(struct imx_usbmisc_data *data)1031static inline bool is_imx53_usbmisc(struct imx_usbmisc_data *data)
@@ -1009,30 +1052,29 @@ EXPORT_SYMBOL_GPL(imx_usbmisc_init); · 20 unmodified lines
1009int imx_usbmisc_init_post(struct imx_usbmisc_data *data)1052int imx_usbmisc_init_post(struct imx_usbmisc_data *data)
1010{1053{
1011 struct imx_usbmisc *usbmisc;1054 struct imx_usbmisc *usbmisc;
1055 int ret = 0;
1012 1056
1013 if (!data)1057 if (!data)
1014 return 0;1058 return 0;
1015 1059
1016 usbmisc = dev_get_drvdata(data->dev);1060 usbmisc = dev_get_drvdata(data->dev);
1017 if (!usbmisc->ops->post)1061 if (usbmisc->ops->post)
1018 return 0;1062 ret = usbmisc->ops->post(data);
1019 return usbmisc->ops->post(data);1063 if (ret) {
1020}1064 dev_err(data->dev, "post init failed, ret=%d\n", ret);
1021EXPORT_SYMBOL_GPL(imx_usbmisc_init_post);1065 return ret;
1022 1066 }
1023int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled)
1024{
1025 struct imx_usbmisc *usbmisc;
1026 1067
1027 if (!data)1068 if (usbmisc->ops->set_wakeup)
1028 return 0;1069 ret = usbmisc->ops->set_wakeup(data, false);
1070 if (ret) {
1071 dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret);
1072 return ret;
1073 }
1029 1074
1030 usbmisc = dev_get_drvdata(data->dev);1075 return 0;
1031 if (!usbmisc->ops->set_wakeup)
1032 return 0;
1033 return usbmisc->ops->set_wakeup(data, enabled);
1034}1076}
1035EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup);1077EXPORT_SYMBOL_GPL(imx_usbmisc_init_post);
1036 1078
1037int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data)1079int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data)
1038{1080{
@@ -1048,20 +1090,6 @@ int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data) · 9 unmodified lines
1048}1090}
1049EXPORT_SYMBOL_GPL(imx_usbmisc_hsic_set_connect);1091EXPORT_SYMBOL_GPL(imx_usbmisc_hsic_set_connect);
1050 1092
1051int imx_usbmisc_hsic_set_clk(struct imx_usbmisc_data *data, bool on)
1052{
1053 struct imx_usbmisc *usbmisc;
1054
1055 if (!data)
1056 return 0;
1057
1058 usbmisc = dev_get_drvdata(data->dev);
1059 if (!usbmisc->ops->hsic_set_clk || !data->hsic)
1060 return 0;
1061 return usbmisc->ops->hsic_set_clk(data, on);
1062}
1063EXPORT_SYMBOL_GPL(imx_usbmisc_hsic_set_clk);
1064
1065int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect)1093int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect)
1066{1094{
1067 struct imx_usbmisc *usbmisc;1095 struct imx_usbmisc *usbmisc;
@@ -1094,6 +1122,78 @@ int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect) · 26 unmodified lines
1094}1122}
1095EXPORT_SYMBOL_GPL(imx_usbmisc_charger_detection);1123EXPORT_SYMBOL_GPL(imx_usbmisc_charger_detection);
1096 1124
1125int imx_usbmisc_suspend(struct imx_usbmisc_data *data, bool wakeup)
1126{
1127 struct imx_usbmisc *usbmisc;
1128 int ret = 0;
1129
1130 if (!data)
1131 return 0;
1132
1133 usbmisc = dev_get_drvdata(data->dev);
1134
1135 if (wakeup && usbmisc->ops->set_wakeup)
1136 ret = usbmisc->ops->set_wakeup(data, true);
1137 if (ret) {
1138 dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret);
1139 return ret;
1140 }
1141
1142 if (usbmisc->ops->hsic_set_clk && data->hsic)
1143 ret = usbmisc->ops->hsic_set_clk(data, false);
1144 if (ret) {
1145 dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret);
1146 return ret;
1147 }
1148
1149 return ret;
1150}
1151EXPORT_SYMBOL_GPL(imx_usbmisc_suspend);
1152
1153int imx_usbmisc_resume(struct imx_usbmisc_data *data, bool wakeup)
1154{
1155 struct imx_usbmisc *usbmisc;
1156 int ret = 0;
1157
1158 if (!data)
1159 return 0;
1160
1161 usbmisc = dev_get_drvdata(data->dev);
1162
1163 if (usbmisc->ops->power_lost_check)
1164 ret = usbmisc->ops->power_lost_check(data);
1165 if (ret > 0) {
1166 /* re-init if resume from power lost */
1167 ret = imx_usbmisc_init(data);
1168 if (ret) {
1169 dev_err(data->dev, "re-init failed, ret=%d\n", ret);
1170 return ret;
1171 }
1172 }
1173
1174 if (wakeup && usbmisc->ops->set_wakeup)
1175 ret = usbmisc->ops->set_wakeup(data, false);
1176 if (ret) {
1177 dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret);
1178 return ret;
1179 }
1180
1181 if (usbmisc->ops->hsic_set_clk && data->hsic)
1182 ret = usbmisc->ops->hsic_set_clk(data, true);
1183 if (ret) {
1184 dev_err(data->dev, "set_wakeup failed, ret=%d\n", ret);
1185 goto hsic_set_clk_fail;
1186 }
1187
1188 return 0;
1189
1190hsic_set_clk_fail:
1191 if (wakeup && usbmisc->ops->set_wakeup)
1192 usbmisc->ops->set_wakeup(data, true);
1193 return ret;
1194}
1195EXPORT_SYMBOL_GPL(imx_usbmisc_resume);
1196
1097static const struct of_device_id usbmisc_imx_dt_ids[] = {1197static const struct of_device_id usbmisc_imx_dt_ids[] = {
1098 {1198 {
1099 .compatible = "fsl,imx25-usbmisc",1199 .compatible = "fsl,imx25-usbmisc",
drivers/usb/common/ulpi.c+1−1
@@ -207,7 +207,7 @@ static int ulpi_read_id(struct ulpi *ulpi) · 206 unmodified lines
207 /* Test the interface */207 /* Test the interface */
208 ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa);208 ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa);
209 if (ret < 0)209 if (ret < 0)
210 goto err;210 return ret;
211 211
212 ret = ulpi_read(ulpi, ULPI_SCRATCH);212 ret = ulpi_read(ulpi, ULPI_SCRATCH);
213 if (ret < 0)213 if (ret < 0)
drivers/usb/core/config.c+41−41
@@ -61,7 +61,7 @@ static void usb_parse_ssp_isoc_endpoint_companion(struct device *ddev, · 60 unmodified lines
61 desc = (struct usb_ssp_isoc_ep_comp_descriptor *) buffer;61 desc = (struct usb_ssp_isoc_ep_comp_descriptor *) buffer;
62 if (desc->bDescriptorType != USB_DT_SSP_ISOC_ENDPOINT_COMP ||62 if (desc->bDescriptorType != USB_DT_SSP_ISOC_ENDPOINT_COMP ||
63 size < USB_DT_SSP_ISOC_EP_COMP_SIZE) {63 size < USB_DT_SSP_ISOC_EP_COMP_SIZE) {
64 dev_warn(ddev, "Invalid SuperSpeedPlus isoc endpoint companion"64 dev_notice(ddev, "Invalid SuperSpeedPlus isoc endpoint companion"
65 "for config %d interface %d altsetting %d ep %d.\n",65 "for config %d interface %d altsetting %d ep %d.\n",
66 cfgno, inum, asnum, ep->desc.bEndpointAddress);66 cfgno, inum, asnum, ep->desc.bEndpointAddress);
67 return;67 return;
@@ -83,7 +83,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 15 unmodified lines
83 83
84 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP ||84 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP ||
85 size < USB_DT_SS_EP_COMP_SIZE) {85 size < USB_DT_SS_EP_COMP_SIZE) {
86 dev_warn(ddev, "No SuperSpeed endpoint companion for config %d "86 dev_notice(ddev, "No SuperSpeed endpoint companion for config %d "
87 " interface %d altsetting %d ep %d: "87 " interface %d altsetting %d ep %d: "
88 "using minimum values\n",88 "using minimum values\n",
89 cfgno, inum, asnum, ep->desc.bEndpointAddress);89 cfgno, inum, asnum, ep->desc.bEndpointAddress);
@@ -109,13 +109,13 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 19 unmodified lines
109 109
110 /* Check the various values */110 /* Check the various values */
111 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) {111 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) {
112 dev_warn(ddev, "Control endpoint with bMaxBurst = %d in "112 dev_notice(ddev, "Control endpoint with bMaxBurst = %d in "
113 "config %d interface %d altsetting %d ep %d: "113 "config %d interface %d altsetting %d ep %d: "
114 "setting to zero\n", desc->bMaxBurst,114 "setting to zero\n", desc->bMaxBurst,
115 cfgno, inum, asnum, ep->desc.bEndpointAddress);115 cfgno, inum, asnum, ep->desc.bEndpointAddress);
116 ep->ss_ep_comp.bMaxBurst = 0;116 ep->ss_ep_comp.bMaxBurst = 0;
117 } else if (desc->bMaxBurst > 15) {117 } else if (desc->bMaxBurst > 15) {
118 dev_warn(ddev, "Endpoint with bMaxBurst = %d in "118 dev_notice(ddev, "Endpoint with bMaxBurst = %d in "
119 "config %d interface %d altsetting %d ep %d: "119 "config %d interface %d altsetting %d ep %d: "
120 "setting to 15\n", desc->bMaxBurst,120 "setting to 15\n", desc->bMaxBurst,
121 cfgno, inum, asnum, ep->desc.bEndpointAddress);121 cfgno, inum, asnum, ep->desc.bEndpointAddress);
@@ -125,7 +125,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 3 unmodified lines
125 if ((usb_endpoint_xfer_control(&ep->desc) ||125 if ((usb_endpoint_xfer_control(&ep->desc) ||
126 usb_endpoint_xfer_int(&ep->desc)) &&126 usb_endpoint_xfer_int(&ep->desc)) &&
127 desc->bmAttributes != 0) {127 desc->bmAttributes != 0) {
128 dev_warn(ddev, "%s endpoint with bmAttributes = %d in "128 dev_notice(ddev, "%s endpoint with bmAttributes = %d in "
129 "config %d interface %d altsetting %d ep %d: "129 "config %d interface %d altsetting %d ep %d: "
130 "setting to zero\n",130 "setting to zero\n",
131 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk",131 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk",
@@ -134,7 +134,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 2 unmodified lines
134 ep->ss_ep_comp.bmAttributes = 0;134 ep->ss_ep_comp.bmAttributes = 0;
135 } else if (usb_endpoint_xfer_bulk(&ep->desc) &&135 } else if (usb_endpoint_xfer_bulk(&ep->desc) &&
136 desc->bmAttributes > 16) {136 desc->bmAttributes > 16) {
137 dev_warn(ddev, "Bulk endpoint with more than 65536 streams in "137 dev_notice(ddev, "Bulk endpoint with more than 65536 streams in "
138 "config %d interface %d altsetting %d ep %d: "138 "config %d interface %d altsetting %d ep %d: "
139 "setting to max\n",139 "setting to max\n",
140 cfgno, inum, asnum, ep->desc.bEndpointAddress);140 cfgno, inum, asnum, ep->desc.bEndpointAddress);
@@ -142,7 +142,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 1 unmodified line
142 } else if (usb_endpoint_xfer_isoc(&ep->desc) &&142 } else if (usb_endpoint_xfer_isoc(&ep->desc) &&
143 !USB_SS_SSP_ISOC_COMP(desc->bmAttributes) &&143 !USB_SS_SSP_ISOC_COMP(desc->bmAttributes) &&
144 USB_SS_MULT(desc->bmAttributes) > 3) {144 USB_SS_MULT(desc->bmAttributes) > 3) {
145 dev_warn(ddev, "Isoc endpoint has Mult of %d in "145 dev_notice(ddev, "Isoc endpoint has Mult of %d in "
146 "config %d interface %d altsetting %d ep %d: "146 "config %d interface %d altsetting %d ep %d: "
147 "setting to 3\n",147 "setting to 3\n",
148 USB_SS_MULT(desc->bmAttributes),148 USB_SS_MULT(desc->bmAttributes),
@@ -160,7 +160,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 11 unmodified lines
160 else160 else
161 max_tx = 999999;161 max_tx = 999999;
162 if (le16_to_cpu(desc->wBytesPerInterval) > max_tx) {162 if (le16_to_cpu(desc->wBytesPerInterval) > max_tx) {
163 dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in "163 dev_notice(ddev, "%s endpoint with wBytesPerInterval of %d in "
164 "config %d interface %d altsetting %d ep %d: "164 "config %d interface %d altsetting %d ep %d: "
165 "setting to %d\n",165 "setting to %d\n",
166 usb_endpoint_xfer_isoc(&ep->desc) ? "Isoc" : "Int",166 usb_endpoint_xfer_isoc(&ep->desc) ? "Isoc" : "Int",
@@ -273,7 +273,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 106 unmodified lines
273 else if (d->bLength >= USB_DT_ENDPOINT_SIZE)273 else if (d->bLength >= USB_DT_ENDPOINT_SIZE)
274 n = USB_DT_ENDPOINT_SIZE;274 n = USB_DT_ENDPOINT_SIZE;
275 else {275 else {
276 dev_warn(ddev, "config %d interface %d altsetting %d has an "276 dev_notice(ddev, "config %d interface %d altsetting %d has an "
277 "invalid endpoint descriptor of length %d, skipping\n",277 "invalid endpoint descriptor of length %d, skipping\n",
278 cfgno, inum, asnum, d->bLength);278 cfgno, inum, asnum, d->bLength);
279 goto skip_to_next_endpoint_or_interface_descriptor;279 goto skip_to_next_endpoint_or_interface_descriptor;
@@ -281,7 +281,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 1 unmodified line
281 281
282 i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK;282 i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK;
283 if (i >= 16 || i == 0) {283 if (i >= 16 || i == 0) {
284 dev_warn(ddev, "config %d interface %d altsetting %d has an "284 dev_notice(ddev, "config %d interface %d altsetting %d has an "
285 "invalid endpoint with address 0x%X, skipping\n",285 "invalid endpoint with address 0x%X, skipping\n",
286 cfgno, inum, asnum, d->bEndpointAddress);286 cfgno, inum, asnum, d->bEndpointAddress);
287 goto skip_to_next_endpoint_or_interface_descriptor;287 goto skip_to_next_endpoint_or_interface_descriptor;
@@ -293,7 +293,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 5 unmodified lines
293 293
294 /* Check for duplicate endpoint addresses */294 /* Check for duplicate endpoint addresses */
295 if (config_endpoint_is_duplicate(config, inum, asnum, d)) {295 if (config_endpoint_is_duplicate(config, inum, asnum, d)) {
296 dev_warn(ddev, "config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n",296 dev_notice(ddev, "config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n",
297 cfgno, inum, asnum, d->bEndpointAddress);297 cfgno, inum, asnum, d->bEndpointAddress);
298 goto skip_to_next_endpoint_or_interface_descriptor;298 goto skip_to_next_endpoint_or_interface_descriptor;
299 }299 }
@@ -301,7 +301,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 1 unmodified line
301 /* Ignore some endpoints */301 /* Ignore some endpoints */
302 if (udev->quirks & USB_QUIRK_ENDPOINT_IGNORE) {302 if (udev->quirks & USB_QUIRK_ENDPOINT_IGNORE) {
303 if (usb_endpoint_is_ignored(udev, ifp, d)) {303 if (usb_endpoint_is_ignored(udev, ifp, d)) {
304 dev_warn(ddev, "config %d interface %d altsetting %d has an ignored endpoint with address 0x%X, skipping\n",304 dev_notice(ddev, "config %d interface %d altsetting %d has an ignored endpoint with address 0x%X, skipping\n",
305 cfgno, inum, asnum,305 cfgno, inum, asnum,
306 d->bEndpointAddress);306 d->bEndpointAddress);
307 goto skip_to_next_endpoint_or_interface_descriptor;307 goto skip_to_next_endpoint_or_interface_descriptor;
@@ -378,7 +378,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 70 unmodified lines
378 }378 }
379 }379 }
380 if (d->bInterval < i || d->bInterval > j) {380 if (d->bInterval < i || d->bInterval > j) {
381 dev_warn(ddev, "config %d interface %d altsetting %d "381 dev_notice(ddev, "config %d interface %d altsetting %d "
382 "endpoint 0x%X has an invalid bInterval %d, "382 "endpoint 0x%X has an invalid bInterval %d, "
383 "changing to %d\n",383 "changing to %d\n",
384 cfgno, inum, asnum,384 cfgno, inum, asnum,
@@ -391,7 +391,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 6 unmodified lines
391 * them usable, we will try treating them as Interrupt endpoints.391 * them usable, we will try treating them as Interrupt endpoints.
392 */392 */
393 if (udev->speed == USB_SPEED_LOW && usb_endpoint_xfer_bulk(d)) {393 if (udev->speed == USB_SPEED_LOW && usb_endpoint_xfer_bulk(d)) {
394 dev_warn(ddev, "config %d interface %d altsetting %d "394 dev_notice(ddev, "config %d interface %d altsetting %d "
395 "endpoint 0x%X is Bulk; changing to Interrupt\n",395 "endpoint 0x%X is Bulk; changing to Interrupt\n",
396 cfgno, inum, asnum, d->bEndpointAddress);396 cfgno, inum, asnum, d->bEndpointAddress);
397 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT;397 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT;
@@ -408,7 +408,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 10 unmodified lines
408 */408 */
409 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize);409 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize);
410 if (maxp == 0 && !(usb_endpoint_xfer_isoc(d) && asnum == 0)) {410 if (maxp == 0 && !(usb_endpoint_xfer_isoc(d) && asnum == 0)) {
411 dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid wMaxPacketSize 0\n",411 dev_notice(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid wMaxPacketSize 0\n",
412 cfgno, inum, asnum, d->bEndpointAddress);412 cfgno, inum, asnum, d->bEndpointAddress);
413 }413 }
414 414
@@ -439,7 +439,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 24 unmodified lines
439 j = maxpacket_maxes[usb_endpoint_type(&endpoint->desc)];439 j = maxpacket_maxes[usb_endpoint_type(&endpoint->desc)];
440 440
441 if (maxp > j) {441 if (maxp > j) {
442 dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid maxpacket %d, setting to %d\n",442 dev_notice(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid maxpacket %d, setting to %d\n",
443 cfgno, inum, asnum, d->bEndpointAddress, maxp, j);443 cfgno, inum, asnum, d->bEndpointAddress, maxp, j);
444 maxp = j;444 maxp = j;
445 endpoint->desc.wMaxPacketSize = cpu_to_le16(i | maxp);445 endpoint->desc.wMaxPacketSize = cpu_to_le16(i | maxp);
@@ -452,7 +452,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 6 unmodified lines
452 */452 */
453 if (udev->speed == USB_SPEED_HIGH && usb_endpoint_xfer_bulk(d)) {453 if (udev->speed == USB_SPEED_HIGH && usb_endpoint_xfer_bulk(d)) {
454 if (maxp != 512)454 if (maxp != 512)
455 dev_warn(ddev, "config %d interface %d altsetting %d "455 dev_notice(ddev, "config %d interface %d altsetting %d "
456 "bulk endpoint 0x%X has invalid maxpacket %d\n",456 "bulk endpoint 0x%X has invalid maxpacket %d\n",
457 cfgno, inum, asnum, d->bEndpointAddress,457 cfgno, inum, asnum, d->bEndpointAddress,
458 maxp);458 maxp);
@@ -533,7 +533,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno, · 74 unmodified lines
533 i < intfc->num_altsetting;533 i < intfc->num_altsetting;
534 (++i, ++alt)) {534 (++i, ++alt)) {
535 if (alt->desc.bAlternateSetting == asnum) {535 if (alt->desc.bAlternateSetting == asnum) {
536 dev_warn(ddev, "Duplicate descriptor for config %d "536 dev_notice(ddev, "Duplicate descriptor for config %d "
537 "interface %d altsetting %d, skipping\n",537 "interface %d altsetting %d, skipping\n",
538 cfgno, inum, asnum);538 cfgno, inum, asnum);
539 goto skip_to_next_interface_descriptor;539 goto skip_to_next_interface_descriptor;
@@ -559,7 +559,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno, · 19 unmodified lines
559 num_ep = num_ep_orig = alt->desc.bNumEndpoints;559 num_ep = num_ep_orig = alt->desc.bNumEndpoints;
560 alt->desc.bNumEndpoints = 0; /* Use as a counter */560 alt->desc.bNumEndpoints = 0; /* Use as a counter */
561 if (num_ep > USB_MAXENDPOINTS) {561 if (num_ep > USB_MAXENDPOINTS) {
562 dev_warn(ddev, "too many endpoints for config %d interface %d "562 dev_notice(ddev, "too many endpoints for config %d interface %d "
563 "altsetting %d: %d, using maximum allowed: %d\n",563 "altsetting %d: %d, using maximum allowed: %d\n",
564 cfgno, inum, asnum, num_ep, USB_MAXENDPOINTS);564 cfgno, inum, asnum, num_ep, USB_MAXENDPOINTS);
565 num_ep = USB_MAXENDPOINTS;565 num_ep = USB_MAXENDPOINTS;
@@ -590,7 +590,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno, · 24 unmodified lines
590 }590 }
591 591
592 if (n != num_ep_orig)592 if (n != num_ep_orig)
593 dev_warn(ddev, "config %d interface %d altsetting %d has %d "593 dev_notice(ddev, "config %d interface %d altsetting %d has %d "
594 "endpoint descriptor%s, different from the interface "594 "endpoint descriptor%s, different from the interface "
595 "descriptor's value: %d\n",595 "descriptor's value: %d\n",
596 cfgno, inum, asnum, n, plural(n), num_ep_orig);596 cfgno, inum, asnum, n, plural(n), num_ep_orig);
@@ -625,7 +625,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 28 unmodified lines
625 if (config->desc.bDescriptorType != USB_DT_CONFIG ||625 if (config->desc.bDescriptorType != USB_DT_CONFIG ||
626 config->desc.bLength < USB_DT_CONFIG_SIZE ||626 config->desc.bLength < USB_DT_CONFIG_SIZE ||
627 config->desc.bLength > size) {627 config->desc.bLength > size) {
628 dev_err(ddev, "invalid descriptor for config index %d: "628 dev_notice(ddev, "invalid descriptor for config index %d: "
629 "type = 0x%X, length = %d\n", cfgidx,629 "type = 0x%X, length = %d\n", cfgidx,
630 config->desc.bDescriptorType, config->desc.bLength);630 config->desc.bDescriptorType, config->desc.bLength);
631 return -EINVAL;631 return -EINVAL;
@@ -636,7 +636,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 4 unmodified lines
636 size -= config->desc.bLength;636 size -= config->desc.bLength;
637 637
638 if (nintf > USB_MAXINTERFACES) {638 if (nintf > USB_MAXINTERFACES) {
639 dev_warn(ddev, "config %d has too many interfaces: %d, "639 dev_notice(ddev, "config %d has too many interfaces: %d, "
640 "using maximum allowed: %d\n",640 "using maximum allowed: %d\n",
641 cfgno, nintf, USB_MAXINTERFACES);641 cfgno, nintf, USB_MAXINTERFACES);
642 nintf = USB_MAXINTERFACES;642 nintf = USB_MAXINTERFACES;
@@ -650,7 +650,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 7 unmodified lines
650 (buffer2 += header->bLength, size2 -= header->bLength)) {650 (buffer2 += header->bLength, size2 -= header->bLength)) {
651 651
652 if (size2 < sizeof(struct usb_descriptor_header)) {652 if (size2 < sizeof(struct usb_descriptor_header)) {
653 dev_warn(ddev, "config %d descriptor has %d excess "653 dev_notice(ddev, "config %d descriptor has %d excess "
654 "byte%s, ignoring\n",654 "byte%s, ignoring\n",
655 cfgno, size2, plural(size2));655 cfgno, size2, plural(size2));
656 break;656 break;
@@ -658,7 +658,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 1 unmodified line
658 658
659 header = (struct usb_descriptor_header *) buffer2;659 header = (struct usb_descriptor_header *) buffer2;
660 if ((header->bLength > size2) || (header->bLength < 2)) {660 if ((header->bLength > size2) || (header->bLength < 2)) {
661 dev_warn(ddev, "config %d has an invalid descriptor "661 dev_notice(ddev, "config %d has an invalid descriptor "
662 "of length %d, skipping remainder of the config\n",662 "of length %d, skipping remainder of the config\n",
663 cfgno, header->bLength);663 cfgno, header->bLength);
664 break;664 break;
@@ -670,7 +670,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 5 unmodified lines
670 670
671 d = (struct usb_interface_descriptor *) header;671 d = (struct usb_interface_descriptor *) header;
672 if (d->bLength < USB_DT_INTERFACE_SIZE) {672 if (d->bLength < USB_DT_INTERFACE_SIZE) {
673 dev_warn(ddev, "config %d has an invalid "673 dev_notice(ddev, "config %d has an invalid "
674 "interface descriptor of length %d, "674 "interface descriptor of length %d, "
675 "skipping\n", cfgno, d->bLength);675 "skipping\n", cfgno, d->bLength);
676 continue;676 continue;
@@ -680,7 +680,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 3 unmodified lines
680 680
681 if ((dev->quirks & USB_QUIRK_HONOR_BNUMINTERFACES) &&681 if ((dev->quirks & USB_QUIRK_HONOR_BNUMINTERFACES) &&
682 n >= nintf_orig) {682 n >= nintf_orig) {
683 dev_warn(ddev, "config %d has more interface "683 dev_notice(ddev, "config %d has more interface "
684 "descriptors, than it declares in "684 "descriptors, than it declares in "
685 "bNumInterfaces, ignoring interface "685 "bNumInterfaces, ignoring interface "
686 "number: %d\n", cfgno, inum);686 "number: %d\n", cfgno, inum);
@@ -688,7 +688,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 1 unmodified line
688 }688 }
689 689
690 if (inum >= nintf_orig)690 if (inum >= nintf_orig)
691 dev_warn(ddev, "config %d has an invalid "691 dev_notice(ddev, "config %d has an invalid "
692 "interface number: %d but max is %d\n",692 "interface number: %d but max is %d\n",
693 cfgno, inum, nintf_orig - 1);693 cfgno, inum, nintf_orig - 1);
694 694
@@ -713,14 +713,14 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 18 unmodified lines
713 713
714 d = (struct usb_interface_assoc_descriptor *)header;714 d = (struct usb_interface_assoc_descriptor *)header;
715 if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) {715 if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) {
716 dev_warn(ddev,716 dev_notice(ddev,
717 "config %d has an invalid interface association descriptor of length %d, skipping\n",717 "config %d has an invalid interface association descriptor of length %d, skipping\n",
718 cfgno, d->bLength);718 cfgno, d->bLength);
719 continue;719 continue;
720 }720 }
721 721
722 if (iad_num == USB_MAXIADS) {722 if (iad_num == USB_MAXIADS) {
723 dev_warn(ddev, "found more Interface "723 dev_notice(ddev, "found more Interface "
724 "Association Descriptors "724 "Association Descriptors "
725 "than allocated for in "725 "than allocated for in "
726 "configuration %d\n", cfgno);726 "configuration %d\n", cfgno);
@@ -731,7 +731,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 4 unmodified lines
731 731
732 } else if (header->bDescriptorType == USB_DT_DEVICE ||732 } else if (header->bDescriptorType == USB_DT_DEVICE ||
733 header->bDescriptorType == USB_DT_CONFIG)733 header->bDescriptorType == USB_DT_CONFIG)
734 dev_warn(ddev, "config %d contains an unexpected "734 dev_notice(ddev, "config %d contains an unexpected "
735 "descriptor of type 0x%X, skipping\n",735 "descriptor of type 0x%X, skipping\n",
736 cfgno, header->bDescriptorType);736 cfgno, header->bDescriptorType);
737 737
@@ -740,11 +740,11 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 2 unmodified lines
740 config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0);740 config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0);
741 741
742 if (n != nintf)742 if (n != nintf)
743 dev_warn(ddev, "config %d has %d interface%s, different from "743 dev_notice(ddev, "config %d has %d interface%s, different from "
744 "the descriptor's value: %d\n",744 "the descriptor's value: %d\n",
745 cfgno, n, plural(n), nintf_orig);745 cfgno, n, plural(n), nintf_orig);
746 else if (n == 0)746 else if (n == 0)
747 dev_warn(ddev, "config %d has no interfaces?\n", cfgno);747 dev_notice(ddev, "config %d has no interfaces?\n", cfgno);
748 config->desc.bNumInterfaces = nintf = n;748 config->desc.bNumInterfaces = nintf = n;
749 749
750 /* Check for missing interface numbers */750 /* Check for missing interface numbers */
@@ -754,7 +754,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 3 unmodified lines
754 break;754 break;
755 }755 }
756 if (j >= nintf)756 if (j >= nintf)
757 dev_warn(ddev, "config %d has no interface number "757 dev_notice(ddev, "config %d has no interface number "
758 "%d\n", cfgno, i);758 "%d\n", cfgno, i);
759 }759 }
760 760
@@ -762,7 +762,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 1 unmodified line
762 for (i = 0; i < nintf; ++i) {762 for (i = 0; i < nintf; ++i) {
763 j = nalts[i];763 j = nalts[i];
764 if (j > USB_MAXALTSETTING) {764 if (j > USB_MAXALTSETTING) {
765 dev_warn(ddev, "too many alternate settings for "765 dev_notice(ddev, "too many alternate settings for "
766 "config %d interface %d: %d, "766 "config %d interface %d: %d, "
767 "using maximum allowed: %d\n",767 "using maximum allowed: %d\n",
768 cfgno, inums[i], j, USB_MAXALTSETTING);768 cfgno, inums[i], j, USB_MAXALTSETTING);
@@ -811,7 +811,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 42 unmodified lines
811 break;811 break;
812 }812 }
813 if (n >= intfc->num_altsetting)813 if (n >= intfc->num_altsetting)
814 dev_warn(ddev, "config %d interface %d has no "814 dev_notice(ddev, "config %d interface %d has no "
815 "altsetting %d\n", cfgno, inums[i], j);815 "altsetting %d\n", cfgno, inums[i], j);
816 }816 }
817 }817 }
@@ -868,7 +868,7 @@ int usb_get_configuration(struct usb_device *dev) · 50 unmodified lines
868 int result;868 int result;
869 869
870 if (ncfg > USB_MAXCONFIG) {870 if (ncfg > USB_MAXCONFIG) {
871 dev_warn(ddev, "too many configurations: %d, "871 dev_notice(ddev, "too many configurations: %d, "
872 "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);872 "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
873 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;873 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
874 }874 }
@@ -902,7 +902,7 @@ int usb_get_configuration(struct usb_device *dev) · 27 unmodified lines
902 "descriptor/%s: %d\n", cfgno, "start", result);902 "descriptor/%s: %d\n", cfgno, "start", result);
903 if (result != -EPIPE)903 if (result != -EPIPE)
904 goto err;904 goto err;
905 dev_err(ddev, "chopping to %d config(s)\n", cfgno);905 dev_notice(ddev, "chopping to %d config(s)\n", cfgno);
906 dev->descriptor.bNumConfigurations = cfgno;906 dev->descriptor.bNumConfigurations = cfgno;
907 break;907 break;
908 } else if (result < 4) {908 } else if (result < 4) {
@@ -934,7 +934,7 @@ int usb_get_configuration(struct usb_device *dev) · 25 unmodified lines
934 goto err;934 goto err;
935 }935 }
936 if (result < length) {936 if (result < length) {
937 dev_warn(ddev, "config index %d descriptor too short "937 dev_notice(ddev, "config index %d descriptor too short "
938 "(expected %i, got %i)\n", cfgno, length, result);938 "(expected %i, got %i)\n", cfgno, length, result);
939 length = result;939 length = result;
940 }940 }
@@ -993,7 +993,7 @@ int usb_get_bos_descriptor(struct usb_device *dev) · 52 unmodified lines
993 /* Get BOS descriptor */993 /* Get BOS descriptor */
994 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, bos, USB_DT_BOS_SIZE);994 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, bos, USB_DT_BOS_SIZE);
995 if (ret < USB_DT_BOS_SIZE || bos->bLength < USB_DT_BOS_SIZE) {995 if (ret < USB_DT_BOS_SIZE || bos->bLength < USB_DT_BOS_SIZE) {
996 dev_err(ddev, "unable to get BOS descriptor or descriptor too short\n");996 dev_notice(ddev, "unable to get BOS descriptor or descriptor too short\n");
997 if (ret >= 0)997 if (ret >= 0)
998 ret = -ENOMSG;998 ret = -ENOMSG;
999 kfree(bos);999 kfree(bos);
@@ -1021,7 +1021,7 @@ int usb_get_bos_descriptor(struct usb_device *dev) · 21 unmodified lines
1021 1021
1022 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, buffer, total_len);1022 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, buffer, total_len);
1023 if (ret < total_len) {1023 if (ret < total_len) {
1024 dev_err(ddev, "unable to get BOS descriptor set\n");1024 dev_notice(ddev, "unable to get BOS descriptor set\n");
1025 if (ret >= 0)1025 if (ret >= 0)
1026 ret = -ENOMSG;1026 ret = -ENOMSG;
1027 goto err;1027 goto err;
@@ -1046,7 +1046,7 @@ int usb_get_bos_descriptor(struct usb_device *dev) · 18 unmodified lines
1046 }1046 }
1047 1047
1048 if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {1048 if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
1049 dev_warn(ddev, "descriptor type invalid, skip\n");1049 dev_notice(ddev, "descriptor type invalid, skip\n");
1050 continue;1050 continue;
1051 }1051 }
1052 1052
drivers/usb/core/hcd-pci.c+13−0
@@ -558,6 +558,17 @@ static int hcd_pci_suspend_noirq(struct device *dev) · 557 unmodified lines
558 return retval;558 return retval;
559}559}
560 560
561static int hcd_pci_poweroff_late(struct device *dev)
562{
563 struct pci_dev *pci_dev = to_pci_dev(dev);
564 struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
565
566 if (hcd->driver->pci_poweroff_late && !HCD_DEAD(hcd))
567 return hcd->driver->pci_poweroff_late(hcd, device_may_wakeup(dev));
568
569 return 0;
570}
571
561static int hcd_pci_resume_noirq(struct device *dev)572static int hcd_pci_resume_noirq(struct device *dev)
562{573{
563 powermac_set_asic(to_pci_dev(dev), 1);574 powermac_set_asic(to_pci_dev(dev), 1);
@@ -578,6 +589,7 @@ static int hcd_pci_restore(struct device *dev) · 14 unmodified lines
578 589
579#define hcd_pci_suspend NULL590#define hcd_pci_suspend NULL
580#define hcd_pci_suspend_noirq NULL591#define hcd_pci_suspend_noirq NULL
592#define hcd_pci_poweroff_late NULL
581#define hcd_pci_resume_noirq NULL593#define hcd_pci_resume_noirq NULL
582#define hcd_pci_resume NULL594#define hcd_pci_resume NULL
583#define hcd_pci_restore NULL595#define hcd_pci_restore NULL
@@ -615,6 +627,7 @@ const struct dev_pm_ops usb_hcd_pci_pm_ops = { · 31 unmodified lines
615 .thaw_noirq = NULL,627 .thaw_noirq = NULL,
616 .thaw = hcd_pci_resume,628 .thaw = hcd_pci_resume,
617 .poweroff = hcd_pci_suspend,629 .poweroff = hcd_pci_suspend,
630 .poweroff_late = hcd_pci_poweroff_late,
618 .poweroff_noirq = hcd_pci_suspend_noirq,631 .poweroff_noirq = hcd_pci_suspend_noirq,
619 .restore_noirq = hcd_pci_resume_noirq,632 .restore_noirq = hcd_pci_resume_noirq,
620 .restore = hcd_pci_restore,633 .restore = hcd_pci_restore,
drivers/usb/core/hcd.c+5−1
@@ -3133,8 +3133,12 @@ int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr, · 3132 unmodified lines
3133 GFP_KERNEL,3133 GFP_KERNEL,
3134 DMA_ATTR_WRITE_COMBINE);3134 DMA_ATTR_WRITE_COMBINE);
3135 3135
3136 if (IS_ERR(local_mem))3136 if (IS_ERR_OR_NULL(local_mem)) {
3137 if (!local_mem)
3138 return -ENOMEM;
3139
3137 return PTR_ERR(local_mem);3140 return PTR_ERR(local_mem);
3141 }
3138 3142
3139 /*3143 /*
3140 * Here we pass a dma_addr_t but the arg type is a phys_addr_t.3144 * Here we pass a dma_addr_t but the arg type is a phys_addr_t.
drivers/usb/core/hub.c+60−0
@@ -3081,6 +3081,48 @@ done: · 3080 unmodified lines
3081 return status;3081 return status;
3082}3082}
3083 3083
3084/*
3085 * hub_port_stop_enumerate - stop USB enumeration or ignore port events
3086 * @hub: target hub
3087 * @port1: port num of the port
3088 * @retries: port retries number of hub_port_init()
3089 *
3090 * Return:
3091 * true: ignore port actions/events or give up connection attempts.
3092 * false: keep original behavior.
3093 *
3094 * This function will be based on retries to check whether the port which is
3095 * marked with early_stop attribute would stop enumeration or ignore events.
3096 *
3097 * Note:
3098 * This function didn't change anything if early_stop is not set, and it will
3099 * prevent all connection attempts when early_stop is set and the attempts of
3100 * the port are more than 1.
3101 */
3102static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries)
3103{
3104 struct usb_port *port_dev = hub->ports[port1 - 1];
3105
3106 if (port_dev->early_stop) {
3107 if (port_dev->ignore_event)
3108 return true;
3109
3110 /*
3111 * We want unsuccessful attempts to fail quickly.
3112 * Since some devices may need one failure during
3113 * port initialization, we allow two tries but no
3114 * more.
3115 */
3116 if (retries < 2)
3117 return false;
3118
3119 port_dev->ignore_event = 1;
3120 } else
3121 port_dev->ignore_event = 0;
3122
3123 return port_dev->ignore_event;
3124}
3125
3084/* Check if a port is power on */3126/* Check if a port is power on */
3085int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus)3127int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus)
3086{3128{
@@ -4796,6 +4838,11 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, · 1709 unmodified lines
4796 do_new_scheme = use_new_scheme(udev, retry_counter, port_dev);4838 do_new_scheme = use_new_scheme(udev, retry_counter, port_dev);
4797 4839
4798 for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) {4840 for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) {
4841 if (hub_port_stop_enumerate(hub, port1, retries)) {
4842 retval = -ENODEV;
4843 break;
4844 }
4845
4799 if (do_new_scheme) {4846 if (do_new_scheme) {
4800 struct usb_device_descriptor *buf;4847 struct usb_device_descriptor *buf;
4801 int r = 0;4848 int r = 0;
@@ -5246,6 +5293,11 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, · 444 unmodified lines
5246 status = 0;5293 status = 0;
5247 5294
5248 for (i = 0; i < PORT_INIT_TRIES; i++) {5295 for (i = 0; i < PORT_INIT_TRIES; i++) {
5296 if (hub_port_stop_enumerate(hub, port1, i)) {
5297 status = -ENODEV;
5298 break;
5299 }
5300
5249 usb_lock_port(port_dev);5301 usb_lock_port(port_dev);
5250 mutex_lock(hcd->address0_mutex);5302 mutex_lock(hcd->address0_mutex);
5251 retry_locked = true;5303 retry_locked = true;
@@ -5614,6 +5666,10 @@ static void port_event(struct usb_hub *hub, int port1) · 362 unmodified lines
5614 if (!pm_runtime_active(&port_dev->dev))5666 if (!pm_runtime_active(&port_dev->dev))
5615 return;5667 return;
5616 5668
5669 /* skip port actions if ignore_event and early_stop are true */
5670 if (port_dev->ignore_event && port_dev->early_stop)
5671 return;
5672
5617 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange))5673 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange))
5618 connect_change = 1;5674 connect_change = 1;
5619 5675
@@ -5927,6 +5983,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev) · 307 unmodified lines
5927 mutex_lock(hcd->address0_mutex);5983 mutex_lock(hcd->address0_mutex);
5928 5984
5929 for (i = 0; i < PORT_INIT_TRIES; ++i) {5985 for (i = 0; i < PORT_INIT_TRIES; ++i) {
5986 if (hub_port_stop_enumerate(parent_hub, port1, i)) {
5987 ret = -ENODEV;
5988 break;
5989 }
5930 5990
5931 /* ep0 maxpacket size may change; let the HCD know about it.5991 /* ep0 maxpacket size may change; let the HCD know about it.
5932 * Other endpoints will be handled by re-enumeration. */5992 * Other endpoints will be handled by re-enumeration. */
drivers/usb/core/hub.h+4−0
@@ -90,6 +90,8 @@ struct usb_hub { · 89 unmodified lines
90 * @is_superspeed cache super-speed status90 * @is_superspeed cache super-speed status
91 * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.91 * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.
92 * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted.92 * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted.
93 * @early_stop: whether port initialization will be stopped earlier.
94 * @ignore_event: whether events of the port are ignored.
93 */95 */
94struct usb_port {96struct usb_port {
95 struct usb_device *child;97 struct usb_device *child;
@@ -103,6 +105,8 @@ struct usb_port { · 7 unmodified lines
103 u32 over_current_count;105 u32 over_current_count;
104 u8 portnum;106 u8 portnum;
105 u32 quirks;107 u32 quirks;
108 unsigned int early_stop:1;
109 unsigned int ignore_event:1;
106 unsigned int is_superspeed:1;110 unsigned int is_superspeed:1;
107 unsigned int usb3_lpm_u1_permit:1;111 unsigned int usb3_lpm_u1_permit:1;
108 unsigned int usb3_lpm_u2_permit:1;112 unsigned int usb3_lpm_u2_permit:1;
drivers/usb/core/port.c+29−1
@@ -7,6 +7,7 @@ · 6 unmodified lines
7 * Author: Lan Tianyu <tianyu.lan@intel.com>7 * Author: Lan Tianyu <tianyu.lan@intel.com>
8 */8 */
9 9
10#include <linux/kstrtox.h>
10#include <linux/slab.h>11#include <linux/slab.h>
11#include <linux/pm_qos.h>12#include <linux/pm_qos.h>
12#include <linux/component.h>13#include <linux/component.h>
@@ -17,6 +18,32 @@ static int usb_port_block_power_off; · 4 unmodified lines
17 18
18static const struct attribute_group *port_dev_group[];19static const struct attribute_group *port_dev_group[];
19 20
21static ssize_t early_stop_show(struct device *dev,
22 struct device_attribute *attr, char *buf)
23{
24 struct usb_port *port_dev = to_usb_port(dev);
25
26 return sysfs_emit(buf, "%s\n", port_dev->early_stop ? "yes" : "no");
27}
28
29static ssize_t early_stop_store(struct device *dev, struct device_attribute *attr,
30 const char *buf, size_t count)
31{
32 struct usb_port *port_dev = to_usb_port(dev);
33 bool value;
34
35 if (kstrtobool(buf, &value))
36 return -EINVAL;
37
38 if (value)
39 port_dev->early_stop = 1;
40 else
41 port_dev->early_stop = 0;
42
43 return count;
44}
45static DEVICE_ATTR_RW(early_stop);
46
20static ssize_t disable_show(struct device *dev,47static ssize_t disable_show(struct device *dev,
21 struct device_attribute *attr, char *buf)48 struct device_attribute *attr, char *buf)
22{49{
@@ -63,7 +90,7 @@ static ssize_t disable_store(struct device *dev, struct device_attribute *attr, · 40 unmodified lines
63 bool disabled;90 bool disabled;
64 int rc;91 int rc;
65 92
66 rc = strtobool(buf, &disabled);93 rc = kstrtobool(buf, &disabled);
67 if (rc)94 if (rc)
68 return rc;95 return rc;
69 96
@@ -236,6 +263,7 @@ static struct attribute *port_dev_attrs[] = { · 166 unmodified lines
236 &dev_attr_quirks.attr,263 &dev_attr_quirks.attr,
237 &dev_attr_over_current_count.attr,264 &dev_attr_over_current_count.attr,
238 &dev_attr_disable.attr,265 &dev_attr_disable.attr,
266 &dev_attr_early_stop.attr,
239 NULL,267 NULL,
240};268};
241 269
drivers/usb/core/sysfs.c+4−3
@@ -13,6 +13,7 @@ · 12 unmodified lines
13 13
14 14
15#include <linux/kernel.h>15#include <linux/kernel.h>
16#include <linux/kstrtox.h>
16#include <linux/string.h>17#include <linux/string.h>
17#include <linux/usb.h>18#include <linux/usb.h>
18#include <linux/usb/hcd.h>19#include <linux/usb/hcd.h>
@@ -505,7 +506,7 @@ static ssize_t usb2_hardware_lpm_store(struct device *dev, · 486 unmodified lines
505 if (ret < 0)506 if (ret < 0)
506 return -EINTR;507 return -EINTR;
507 508
508 ret = strtobool(buf, &value);509 ret = kstrtobool(buf, &value);
509 510
510 if (!ret) {511 if (!ret) {
511 udev->usb2_hw_lpm_allowed = value;512 udev->usb2_hw_lpm_allowed = value;
@@ -975,7 +976,7 @@ static ssize_t interface_authorized_default_store(struct device *dev, · 463 unmodified lines
975 int rc = count;976 int rc = count;
976 bool val;977 bool val;
977 978
978 if (strtobool(buf, &val) != 0)979 if (kstrtobool(buf, &val) != 0)
979 return -EINVAL;980 return -EINVAL;
980 981
981 if (val)982 if (val)
@@ -1176,7 +1177,7 @@ static ssize_t interface_authorized_store(struct device *dev, · 194 unmodified lines
1176 struct usb_interface *intf = to_usb_interface(dev);1177 struct usb_interface *intf = to_usb_interface(dev);
1177 bool val;1178 bool val;
1178 1179
1179 if (strtobool(buf, &val) != 0)1180 if (kstrtobool(buf, &val) != 0)
1180 return -EINVAL;1181 return -EINVAL;
1181 1182
1182 if (val)1183 if (val)
drivers/usb/dwc2/gadget.c+4−2
@@ -4549,7 +4549,8 @@ static int dwc2_hsotg_udc_start(struct usb_gadget *gadget, · 4548 unmodified lines
4549 hsotg->gadget.dev.of_node = hsotg->dev->of_node;4549 hsotg->gadget.dev.of_node = hsotg->dev->of_node;
4550 hsotg->gadget.speed = USB_SPEED_UNKNOWN;4550 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
4551 4551
4552 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) {4552 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL ||
4553 (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg))) {
4553 ret = dwc2_lowlevel_hw_enable(hsotg);4554 ret = dwc2_lowlevel_hw_enable(hsotg);
4554 if (ret)4555 if (ret)
4555 goto err;4556 goto err;
@@ -4611,7 +4612,8 @@ static int dwc2_hsotg_udc_stop(struct usb_gadget *gadget) · 55 unmodified lines
4611 if (!IS_ERR_OR_NULL(hsotg->uphy))4612 if (!IS_ERR_OR_NULL(hsotg->uphy))
4612 otg_set_peripheral(hsotg->uphy->otg, NULL);4613 otg_set_peripheral(hsotg->uphy->otg, NULL);
4613 4614
4614 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)4615 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL ||
4616 (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)))
4615 dwc2_lowlevel_hw_disable(hsotg);4617 dwc2_lowlevel_hw_disable(hsotg);
4616 4618
4617 return 0;4619 return 0;
drivers/usb/dwc2/params.c+4−0
@@ -113,6 +113,10 @@ static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg) · 112 unmodified lines
113 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<113 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
114 GAHBCFG_HBSTLEN_SHIFT;114 GAHBCFG_HBSTLEN_SHIFT;
115 p->power_down = DWC2_POWER_DOWN_PARAM_NONE;115 p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
116 p->lpm = false;
117 p->lpm_clock_gating = false;
118 p->besl = false;
119 p->hird_threshold_en = false;
116}120}
117 121
118static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg)122static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg)
drivers/usb/dwc2/platform.c+3−2
@@ -321,7 +321,7 @@ static int dwc2_driver_remove(struct platform_device *dev) · 320 unmodified lines
321 reset_control_assert(hsotg->reset);321 reset_control_assert(hsotg->reset);
322 reset_control_assert(hsotg->reset_ecc);322 reset_control_assert(hsotg->reset_ecc);
323 323
324 return ret;324 return 0;
325}325}
326 326
327/**327/**
@@ -576,7 +576,8 @@ static int dwc2_driver_probe(struct platform_device *dev) · 248 unmodified lines
576 dwc2_debugfs_init(hsotg);576 dwc2_debugfs_init(hsotg);
577 577
578 /* Gadget code manages lowlevel hw on its own */578 /* Gadget code manages lowlevel hw on its own */
579 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)579 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL ||
580 (hsotg->dr_mode == USB_DR_MODE_OTG && dwc2_is_device_mode(hsotg)))
580 dwc2_lowlevel_hw_disable(hsotg);581 dwc2_lowlevel_hw_disable(hsotg);
581 582
582#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \583#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
drivers/usb/dwc3/Kconfig+2−2
@@ -152,11 +152,11 @@ config USB_DWC3_IMX8MP · 151 unmodified lines
152 152
153config USB_DWC3_XILINX153config USB_DWC3_XILINX
154 tristate "Xilinx Platforms"154 tristate "Xilinx Platforms"
155 depends on (ARCH_ZYNQMP || ARCH_VERSAL) && OF155 depends on (ARCH_ZYNQMP || COMPILE_TEST) && OF
156 default USB_DWC3156 default USB_DWC3
157 help157 help
158 Support Xilinx SoCs with DesignWare Core USB3 IP.158 Support Xilinx SoCs with DesignWare Core USB3 IP.
159 This driver handles both ZynqMP and Versal SoC operations.159 This driver handles ZynqMP SoC operations.
160 Say 'Y' or 'M' if you have one such device.160 Say 'Y' or 'M' if you have one such device.
161 161
162config USB_DWC3_AM62162config USB_DWC3_AM62
drivers/usb/dwc3/core.c+16−7
@@ -122,21 +122,25 @@ static void __dwc3_set_mode(struct work_struct *work) · 121 unmodified lines
122 unsigned long flags;122 unsigned long flags;
123 int ret;123 int ret;
124 u32 reg;124 u32 reg;
125 u32 desired_dr_role;
125 126
126 mutex_lock(&dwc->mutex);127 mutex_lock(&dwc->mutex);
128 spin_lock_irqsave(&dwc->lock, flags);
129 desired_dr_role = dwc->desired_dr_role;
130 spin_unlock_irqrestore(&dwc->lock, flags);
127 131
128 pm_runtime_get_sync(dwc->dev);132 pm_runtime_get_sync(dwc->dev);
129 133
130 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)134 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
131 dwc3_otg_update(dwc, 0);135 dwc3_otg_update(dwc, 0);
132 136
133 if (!dwc->desired_dr_role)137 if (!desired_dr_role)
134 goto out;138 goto out;
135 139
136 if (dwc->desired_dr_role == dwc->current_dr_role)140 if (desired_dr_role == dwc->current_dr_role)
137 goto out;141 goto out;
138 142
139 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)143 if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
140 goto out;144 goto out;
141 145
142 switch (dwc->current_dr_role) {146 switch (dwc->current_dr_role) {
@@ -164,7 +168,7 @@ static void __dwc3_set_mode(struct work_struct *work) · 21 unmodified lines
164 */168 */
165 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||169 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||
166 DWC3_VER_IS_PRIOR(DWC31, 190A)) &&170 DWC3_VER_IS_PRIOR(DWC31, 190A)) &&
167 dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {171 desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
168 reg = dwc3_readl(dwc->regs, DWC3_GCTL);172 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
169 reg |= DWC3_GCTL_CORESOFTRESET;173 reg |= DWC3_GCTL_CORESOFTRESET;
170 dwc3_writel(dwc->regs, DWC3_GCTL, reg);174 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
@@ -184,11 +188,11 @@ static void __dwc3_set_mode(struct work_struct *work) · 13 unmodified lines
184 188
185 spin_lock_irqsave(&dwc->lock, flags);189 spin_lock_irqsave(&dwc->lock, flags);
186 190
187 dwc3_set_prtcap(dwc, dwc->desired_dr_role);191 dwc3_set_prtcap(dwc, desired_dr_role);
188 192
189 spin_unlock_irqrestore(&dwc->lock, flags);193 spin_unlock_irqrestore(&dwc->lock, flags);
190 194
191 switch (dwc->desired_dr_role) {195 switch (desired_dr_role) {
192 case DWC3_GCTL_PRTCAP_HOST:196 case DWC3_GCTL_PRTCAP_HOST:
193 ret = dwc3_host_init(dwc);197 ret = dwc3_host_init(dwc);
194 if (ret) {198 if (ret) {
@@ -1096,8 +1100,13 @@ static int dwc3_core_init(struct dwc3 *dwc) · 901 unmodified lines
1096 1100
1097 if (!dwc->ulpi_ready) {1101 if (!dwc->ulpi_ready) {
1098 ret = dwc3_core_ulpi_init(dwc);1102 ret = dwc3_core_ulpi_init(dwc);
1099 if (ret)1103 if (ret) {
1104 if (ret == -ETIMEDOUT) {
1105 dwc3_core_soft_reset(dwc);
1106 ret = -EPROBE_DEFER;
1107 }
1100 goto err0;1108 goto err0;
1109 }
1101 dwc->ulpi_ready = true;1110 dwc->ulpi_ready = true;
1102 }1111 }
1103 1112
drivers/usb/dwc3/dwc3-pci.c+1−1
@@ -45,7 +45,7 @@ · 44 unmodified lines
45#define PCI_DEVICE_ID_INTEL_ADLN 0x465e45#define PCI_DEVICE_ID_INTEL_ADLN 0x465e
46#define PCI_DEVICE_ID_INTEL_ADLN_PCH 0x54ee46#define PCI_DEVICE_ID_INTEL_ADLN_PCH 0x54ee
47#define PCI_DEVICE_ID_INTEL_ADLS 0x7ae147#define PCI_DEVICE_ID_INTEL_ADLS 0x7ae1
48#define PCI_DEVICE_ID_INTEL_RPL 0x460e48#define PCI_DEVICE_ID_INTEL_RPL 0xa70e
49#define PCI_DEVICE_ID_INTEL_RPLS 0x7a6149#define PCI_DEVICE_ID_INTEL_RPLS 0x7a61
50#define PCI_DEVICE_ID_INTEL_MTLP 0x7ec150#define PCI_DEVICE_ID_INTEL_MTLP 0x7ec1
51#define PCI_DEVICE_ID_INTEL_MTL 0x7e7e51#define PCI_DEVICE_ID_INTEL_MTL 0x7e7e
drivers/usb/dwc3/dwc3-qcom.c+10−3
@@ -261,7 +261,8 @@ static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom) · 260 unmodified lines
261 if (IS_ERR(qcom->icc_path_apps)) {261 if (IS_ERR(qcom->icc_path_apps)) {
262 dev_err(dev, "failed to get apps-usb path: %ld\n",262 dev_err(dev, "failed to get apps-usb path: %ld\n",
263 PTR_ERR(qcom->icc_path_apps));263 PTR_ERR(qcom->icc_path_apps));
264 return PTR_ERR(qcom->icc_path_apps);264 ret = PTR_ERR(qcom->icc_path_apps);
265 goto put_path_ddr;
265 }266 }
266 267
267 max_speed = usb_get_maximum_speed(&qcom->dwc3->dev);268 max_speed = usb_get_maximum_speed(&qcom->dwc3->dev);
@@ -274,16 +275,22 @@ static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom) · 6 unmodified lines
274 }275 }
275 if (ret) {276 if (ret) {
276 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret);277 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret);
277 return ret;278 goto put_path_apps;
278 }279 }
279 280
280 ret = icc_set_bw(qcom->icc_path_apps, APPS_USB_AVG_BW, APPS_USB_PEAK_BW);281 ret = icc_set_bw(qcom->icc_path_apps, APPS_USB_AVG_BW, APPS_USB_PEAK_BW);
281 if (ret) {282 if (ret) {
282 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret);283 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret);
283 return ret;284 goto put_path_apps;
284 }285 }
285 286
286 return 0;287 return 0;
288
289put_path_apps:
290 icc_put(qcom->icc_path_apps);
291put_path_ddr:
292 icc_put(qcom->icc_path_ddr);
293 return ret;
287}294}
288 295
289/**296/**
drivers/usb/dwc3/gadget.c+12−2
@@ -1464,8 +1464,18 @@ static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep, · 1463 unmodified lines
1464 */1464 */
1465 if (num_trbs_left == 1 || (needs_extra_trb &&1465 if (num_trbs_left == 1 || (needs_extra_trb &&
1466 num_trbs_left <= 2 &&1466 num_trbs_left <= 2 &&
1467 sg_dma_len(sg_next(s)) >= length))1467 sg_dma_len(sg_next(s)) >= length)) {
1468 must_interrupt = true;1468 struct dwc3_request *r;
1469
1470 /* Check if previous requests already set IOC */
1471 list_for_each_entry(r, &dep->started_list, list) {
1472 if (r != req && !r->request.no_interrupt)
1473 break;
1474
1475 if (r == req)
1476 must_interrupt = true;
1477 }
1478 }
1469 1479
1470 dwc3_prepare_one_trb(dep, req, trb_length, 1, i, false,1480 dwc3_prepare_one_trb(dep, req, trb_length, 1, i, false,
1471 must_interrupt);1481 must_interrupt);
drivers/usb/fotg210/Kconfig+38−0
@@ -0,0 +1,38 @@
1# SPDX-License-Identifier: GPL-2.0
2
3config USB_FOTG210
4 tristate "Faraday FOTG210 USB2 Dual Role controller"
5 depends on USB || USB_GADGET
6 depends on HAS_DMA && HAS_IOMEM
7 depends on ARCH_GEMINI || COMPILE_TEST
8 default ARCH_GEMINI
9 select MFD_SYSCON
10 help
11 Faraday FOTG210 is a dual-mode USB controller that can act
12 in both host controller and peripheral controller mode.
13
14if USB_FOTG210
15
16config USB_FOTG210_HCD
17 bool "Faraday FOTG210 USB Host Controller support"
18 depends on USB=y || USB=USB_FOTG210
19 help
20 Faraday FOTG210 is an OTG controller which can be configured as
21 an USB2.0 host. It is designed to meet USB2.0 EHCI specification
22 with minor modification.
23
24 To compile this driver as a module, choose M here: the
25 module will be called fotg210-hcd.
26
27config USB_FOTG210_UDC
28 depends on USB_GADGET=y || USB_GADGET=USB_FOTG210
29 bool "Faraday FOTG210 USB Peripheral Controller support"
30 help
31 Faraday USB2.0 OTG controller which can be configured as
32 high speed or full speed USB device. This driver suppports
33 Bulk Transfer so far.
34
35 Say "y" to link the driver statically, or "m" to build a
36 dynamically linked module called "fotg210-udc".
37
38endif
drivers/usb/fotg210/Makefile+10−0
@@ -0,0 +1,10 @@
1# SPDX-License-Identifier: GPL-2.0
2
3# This setup links the different object files into one single
4# module so we don't have to EXPORT() a lot of internal symbols
5# or create unnecessary submodules.
6fotg210-objs-y += fotg210-core.o
7fotg210-objs-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o
8fotg210-objs-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
9fotg210-objs := $(fotg210-objs-y)
10obj-$(CONFIG_USB_FOTG210) += fotg210.o
drivers/usb/fotg210/fotg210-core.c+166−0
@@ -0,0 +1,166 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Central probing code for the FOTG210 dual role driver
4 * We register one driver for the hardware and then we decide
5 * whether to proceed with probing the host or the peripheral
6 * driver.
7 */
8#include <linux/bitops.h>
9#include <linux/device.h>
10#include <linux/mfd/syscon.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/platform_device.h>
14#include <linux/regmap.h>
15#include <linux/usb.h>
16#include <linux/usb/otg.h>
17
18#include "fotg210.h"
19
20/*
21 * Gemini-specific initialization function, only executed on the
22 * Gemini SoC using the global misc control register.
23 *
24 * The gemini USB blocks are connected to either Mini-A (host mode) or
25 * Mini-B (peripheral mode) plugs. There is no role switch support on the
26 * Gemini SoC, just either-or.
27 */
28#define GEMINI_GLOBAL_MISC_CTRL 0x30
29#define GEMINI_MISC_USB0_WAKEUP BIT(14)
30#define GEMINI_MISC_USB1_WAKEUP BIT(15)
31#define GEMINI_MISC_USB0_VBUS_ON BIT(22)
32#define GEMINI_MISC_USB1_VBUS_ON BIT(23)
33#define GEMINI_MISC_USB0_MINI_B BIT(29)
34#define GEMINI_MISC_USB1_MINI_B BIT(30)
35
36static int fotg210_gemini_init(struct device *dev, struct resource *res,
37 enum usb_dr_mode mode)
38{
39 struct device_node *np = dev->of_node;
40 struct regmap *map;
41 bool wakeup;
42 u32 mask, val;
43 int ret;
44
45 map = syscon_regmap_lookup_by_phandle(np, "syscon");
46 if (IS_ERR(map)) {
47 dev_err(dev, "no syscon\n");
48 return PTR_ERR(map);
49 }
50 wakeup = of_property_read_bool(np, "wakeup-source");
51
52 /*
53 * Figure out if this is USB0 or USB1 by simply checking the
54 * physical base address.
55 */
56 mask = 0;
57 if (res->start == 0x69000000) {
58 mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B |
59 GEMINI_MISC_USB1_WAKEUP;
60 if (mode == USB_DR_MODE_HOST)
61 val = GEMINI_MISC_USB1_VBUS_ON;
62 else
63 val = GEMINI_MISC_USB1_MINI_B;
64 if (wakeup)
65 val |= GEMINI_MISC_USB1_WAKEUP;
66 } else {
67 mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B |
68 GEMINI_MISC_USB0_WAKEUP;
69 if (mode == USB_DR_MODE_HOST)
70 val = GEMINI_MISC_USB0_VBUS_ON;
71 else
72 val = GEMINI_MISC_USB0_MINI_B;
73 if (wakeup)
74 val |= GEMINI_MISC_USB0_WAKEUP;
75 }
76
77 ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
78 if (ret) {
79 dev_err(dev, "failed to initialize Gemini PHY\n");
80 return ret;
81 }
82
83 dev_info(dev, "initialized Gemini PHY in %s mode\n",
84 (mode == USB_DR_MODE_HOST) ? "host" : "gadget");
85 return 0;
86}
87
88static int fotg210_probe(struct platform_device *pdev)
89{
90 struct device *dev = &pdev->dev;
91 enum usb_dr_mode mode;
92 int ret;
93
94 mode = usb_get_dr_mode(dev);
95
96 if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
97 struct resource *res;
98
99 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
100 ret = fotg210_gemini_init(dev, res, mode);
101 if (ret)
102 return ret;
103 }
104
105 if (mode == USB_DR_MODE_PERIPHERAL)
106 ret = fotg210_udc_probe(pdev);
107 else
108 ret = fotg210_hcd_probe(pdev);
109
110 return ret;
111}
112
113static int fotg210_remove(struct platform_device *pdev)
114{
115 struct device *dev = &pdev->dev;
116 enum usb_dr_mode mode;
117
118 mode = usb_get_dr_mode(dev);
119
120 if (mode == USB_DR_MODE_PERIPHERAL)
121 fotg210_udc_remove(pdev);
122 else
123 fotg210_hcd_remove(pdev);
124
125 return 0;
126}
127
128#ifdef CONFIG_OF
129static const struct of_device_id fotg210_of_match[] = {
130 { .compatible = "faraday,fotg210" },
131 {},
132};
133MODULE_DEVICE_TABLE(of, fotg210_of_match);
134#endif
135
136static struct platform_driver fotg210_driver = {
137 .driver = {
138 .name = "fotg210",
139 .of_match_table = of_match_ptr(fotg210_of_match),
140 },
141 .probe = fotg210_probe,
142 .remove = fotg210_remove,
143};
144
145static int __init fotg210_init(void)
146{
147 if (usb_disabled())
148 return -ENODEV;
149
150 if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
151 fotg210_hcd_init();
152 return platform_driver_register(&fotg210_driver);
153}
154module_init(fotg210_init);
155
156static void __exit fotg210_cleanup(void)
157{
158 platform_driver_unregister(&fotg210_driver);
159 if (IS_ENABLED(CONFIG_USB_FOTG210_HCD))
160 fotg210_hcd_cleanup();
161}
162module_exit(fotg210_cleanup);
163
164MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang");
165MODULE_LICENSE("GPL");
166MODULE_DESCRIPTION("FOTG210 Dual Role Controller Driver");
drivers/usb/fotg210/fotg210-hcd.crenamed from drivers/usb/host/fotg210-hcd.c+8−43
@@ -39,8 +39,8 @@ · 38 unmodified lines
39#include <asm/irq.h>39#include <asm/irq.h>
40#include <asm/unaligned.h>40#include <asm/unaligned.h>
41 41
42#define DRIVER_AUTHOR "Yuan-Hsin Chen"42#include "fotg210.h"
43#define DRIVER_DESC "FOTG210 Host Controller (EHCI) Driver"43
44static const char hcd_name[] = "fotg210_hcd";44static const char hcd_name[] = "fotg210_hcd";
45 45
46#undef FOTG210_URB_TRACE46#undef FOTG210_URB_TRACE
@@ -77,7 +77,7 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us"); · 30 unmodified lines
77 77
78#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)78#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
79 79
80#include "fotg210.h"80#include "fotg210-hcd.h"
81 81
82#define fotg210_dbg(fotg210, fmt, args...) \82#define fotg210_dbg(fotg210, fmt, args...) \
83 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)83 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
@@ -5490,9 +5490,6 @@ static int fotg210_get_frame(struct usb_hcd *hcd) · 5406 unmodified lines
5490 * functions and in order to facilitate role switching we cannot5490 * functions and in order to facilitate role switching we cannot
5491 * give the fotg210 driver exclusive access to those.5491 * give the fotg210 driver exclusive access to those.
5492 */5492 */
5493MODULE_DESCRIPTION(DRIVER_DESC);
5494MODULE_AUTHOR(DRIVER_AUTHOR);
5495MODULE_LICENSE("GPL");
5496 5493
5497static const struct hc_driver fotg210_fotg210_hc_driver = {5494static const struct hc_driver fotg210_fotg210_hc_driver = {
5498 .description = hcd_name,5495 .description = hcd_name,
@@ -5560,7 +5557,7 @@ static void fotg210_init(struct fotg210_hcd *fotg210) · 61 unmodified lines
5560 * then invokes the start() method for the HCD associated with it5557 * then invokes the start() method for the HCD associated with it
5561 * through the hotplug entry's driver_data.5558 * through the hotplug entry's driver_data.
5562 */5559 */
5563static int fotg210_hcd_probe(struct platform_device *pdev)5560int fotg210_hcd_probe(struct platform_device *pdev)
5564{5561{
5565 struct device *dev = &pdev->dev;5562 struct device *dev = &pdev->dev;
5566 struct usb_hcd *hcd;5563 struct usb_hcd *hcd;
@@ -5652,7 +5649,7 @@ fail_create_hcd: · 85 unmodified lines
5652 * @dev: USB Host Controller being removed5649 * @dev: USB Host Controller being removed
5653 *5650 *
5654 */5651 */
5655static int fotg210_hcd_remove(struct platform_device *pdev)5652int fotg210_hcd_remove(struct platform_device *pdev)
5656{5653{
5657 struct usb_hcd *hcd = platform_get_drvdata(pdev);5654 struct usb_hcd *hcd = platform_get_drvdata(pdev);
5658 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);5655 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
@@ -5668,27 +5665,8 @@ static int fotg210_hcd_remove(struct platform_device *pdev) · 9 unmodified lines
5668 return 0;5665 return 0;
5669}5666}
5670 5667
5671#ifdef CONFIG_OF5668int __init fotg210_hcd_init(void)
5672static const struct of_device_id fotg210_of_match[] = {
5673 { .compatible = "faraday,fotg210" },
5674 {},
5675};
5676MODULE_DEVICE_TABLE(of, fotg210_of_match);
5677#endif
5678
5679static struct platform_driver fotg210_hcd_driver = {
5680 .driver = {
5681 .name = "fotg210-hcd",
5682 .of_match_table = of_match_ptr(fotg210_of_match),
5683 },
5684 .probe = fotg210_hcd_probe,
5685 .remove = fotg210_hcd_remove,
5686};
5687
5688static int __init fotg210_hcd_init(void)
5689{5669{
5690 int retval = 0;
5691
5692 if (usb_disabled())5670 if (usb_disabled())
5693 return -ENODEV;5671 return -ENODEV;
5694 5672
@@ -5704,24 +5682,11 @@ static int __init fotg210_hcd_init(void) · 9 unmodified lines
5704 5682
5705 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);5683 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);
5706 5684
5707 retval = platform_driver_register(&fotg210_hcd_driver);5685 return 0;
5708 if (retval < 0)
5709 goto clean;
5710 return retval;
5711
5712clean:
5713 debugfs_remove(fotg210_debug_root);
5714 fotg210_debug_root = NULL;
5715
5716 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
5717 return retval;
5718}5686}
5719module_init(fotg210_hcd_init);
5720 5687
5721static void __exit fotg210_hcd_cleanup(void)5688void __exit fotg210_hcd_cleanup(void)
5722{5689{
5723 platform_driver_unregister(&fotg210_hcd_driver);
5724 debugfs_remove(fotg210_debug_root);5690 debugfs_remove(fotg210_debug_root);
5725 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);5691 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
5726}5692}
5727module_exit(fotg210_hcd_cleanup);
drivers/usb/fotg210/fotg210-hcd.hrenamed from drivers/usb/host/fotg210.h+0−0

File renamed without changes.

drivers/usb/fotg210/fotg210-udc.crenamed from drivers/usb/gadget/udc/fotg210-udc.c+123−41
@@ -15,8 +15,12 @@ · 14 unmodified lines
15#include <linux/platform_device.h>15#include <linux/platform_device.h>
16#include <linux/usb/ch9.h>16#include <linux/usb/ch9.h>
17#include <linux/usb/gadget.h>17#include <linux/usb/gadget.h>
18#include <linux/clk.h>
19#include <linux/usb/otg.h>
20#include <linux/usb/phy.h>
18 21
19#include "fotg210.h"22#include "fotg210.h"
23#include "fotg210-udc.h"
20 24
21#define DRIVER_DESC "FOTG210 USB Device Controller Driver"25#define DRIVER_DESC "FOTG210 USB Device Controller Driver"
22#define DRIVER_VERSION "30-April-2013"26#define DRIVER_VERSION "30-April-2013"
@@ -629,10 +633,10 @@ static void fotg210_request_error(struct fotg210_udc *fotg210) · 606 unmodified lines
629static void fotg210_set_address(struct fotg210_udc *fotg210,633static void fotg210_set_address(struct fotg210_udc *fotg210,
630 struct usb_ctrlrequest *ctrl)634 struct usb_ctrlrequest *ctrl)
631{635{
632 if (ctrl->wValue >= 0x0100) {636 if (le16_to_cpu(ctrl->wValue) >= 0x0100) {
633 fotg210_request_error(fotg210);637 fotg210_request_error(fotg210);
634 } else {638 } else {
635 fotg210_set_dev_addr(fotg210, ctrl->wValue);639 fotg210_set_dev_addr(fotg210, le16_to_cpu(ctrl->wValue));
636 fotg210_set_cxdone(fotg210);640 fotg210_set_cxdone(fotg210);
637 }641 }
638}642}
@@ -713,17 +717,17 @@ static void fotg210_get_status(struct fotg210_udc *fotg210, · 74 unmodified lines
713 717
714 switch (ctrl->bRequestType & USB_RECIP_MASK) {718 switch (ctrl->bRequestType & USB_RECIP_MASK) {
715 case USB_RECIP_DEVICE:719 case USB_RECIP_DEVICE:
716 fotg210->ep0_data = 1 << USB_DEVICE_SELF_POWERED;720 fotg210->ep0_data = cpu_to_le16(1 << USB_DEVICE_SELF_POWERED);
717 break;721 break;
718 case USB_RECIP_INTERFACE:722 case USB_RECIP_INTERFACE:
719 fotg210->ep0_data = 0;723 fotg210->ep0_data = cpu_to_le16(0);
720 break;724 break;
721 case USB_RECIP_ENDPOINT:725 case USB_RECIP_ENDPOINT:
722 epnum = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK;726 epnum = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK;
723 if (epnum)727 if (epnum)
724 fotg210->ep0_data =728 fotg210->ep0_data =
725 fotg210_is_epnstall(fotg210->ep[epnum])729 cpu_to_le16(fotg210_is_epnstall(fotg210->ep[epnum])
726 << USB_ENDPOINT_HALT;730 << USB_ENDPOINT_HALT);
727 else731 else
728 fotg210_request_error(fotg210);732 fotg210_request_error(fotg210);
729 break;733 break;
@@ -1007,11 +1011,19 @@ static int fotg210_udc_start(struct usb_gadget *g, · 277 unmodified lines
1007{1011{
1008 struct fotg210_udc *fotg210 = gadget_to_fotg210(g);1012 struct fotg210_udc *fotg210 = gadget_to_fotg210(g);
1009 u32 value;1013 u32 value;
1014 int ret;
1010 1015
1011 /* hook up the driver */1016 /* hook up the driver */
1012 driver->driver.bus = NULL;1017 driver->driver.bus = NULL;
1013 fotg210->driver = driver;1018 fotg210->driver = driver;
1014 1019
1020 if (!IS_ERR_OR_NULL(fotg210->phy)) {
1021 ret = otg_set_peripheral(fotg210->phy->otg,
1022 &fotg210->gadget);
1023 if (ret)
1024 dev_err(fotg210->dev, "can't bind to phy\n");
1025 }
1026
1015 /* enable device global interrupt */1027 /* enable device global interrupt */
1016 value = ioread32(fotg210->reg + FOTG210_DMCR);1028 value = ioread32(fotg210->reg + FOTG210_DMCR);
1017 value |= DMCR_GLINT_EN;1029 value |= DMCR_GLINT_EN;
@@ -1053,6 +1065,9 @@ static int fotg210_udc_stop(struct usb_gadget *g) · 35 unmodified lines
1053 struct fotg210_udc *fotg210 = gadget_to_fotg210(g);1065 struct fotg210_udc *fotg210 = gadget_to_fotg210(g);
1054 unsigned long flags;1066 unsigned long flags;
1055 1067
1068 if (!IS_ERR_OR_NULL(fotg210->phy))
1069 return otg_set_peripheral(fotg210->phy->otg, NULL);
1070
1056 spin_lock_irqsave(&fotg210->lock, flags);1071 spin_lock_irqsave(&fotg210->lock, flags);
1057 1072
1058 fotg210_init(fotg210);1073 fotg210_init(fotg210);
@@ -1068,28 +1083,71 @@ static const struct usb_gadget_ops fotg210_gadget_ops = { · 9 unmodified lines
1068 .udc_stop = fotg210_udc_stop,1083 .udc_stop = fotg210_udc_stop,
1069};1084};
1070 1085
1071static int fotg210_udc_remove(struct platform_device *pdev)1086/**
1087 * fotg210_phy_event - Called by phy upon VBus event
1088 * @nb: notifier block
1089 * @action: phy action, is vbus connect or disconnect
1090 * @data: the usb_gadget structure in fotg210
1091 *
1092 * Called by the USB Phy when a cable connect or disconnect is sensed.
1093 *
1094 * Returns NOTIFY_OK or NOTIFY_DONE
1095 */
1096static int fotg210_phy_event(struct notifier_block *nb, unsigned long action,
1097 void *data)
1098{
1099 struct usb_gadget *gadget = data;
1100
1101 if (!gadget)
1102 return NOTIFY_DONE;
1103
1104 switch (action) {
1105 case USB_EVENT_VBUS:
1106 usb_gadget_vbus_connect(gadget);
1107 return NOTIFY_OK;
1108 case USB_EVENT_NONE:
1109 usb_gadget_vbus_disconnect(gadget);
1110 return NOTIFY_OK;
1111 default:
1112 return NOTIFY_DONE;
1113 }
1114}
1115
1116static struct notifier_block fotg210_phy_notifier = {
1117 .notifier_call = fotg210_phy_event,
1118};
1119
1120int fotg210_udc_remove(struct platform_device *pdev)
1072{1121{
1073 struct fotg210_udc *fotg210 = platform_get_drvdata(pdev);1122 struct fotg210_udc *fotg210 = platform_get_drvdata(pdev);
1074 int i;1123 int i;
1075 1124
1076 usb_del_gadget_udc(&fotg210->gadget);1125 usb_del_gadget_udc(&fotg210->gadget);
1126 if (!IS_ERR_OR_NULL(fotg210->phy)) {
1127 usb_unregister_notifier(fotg210->phy, &fotg210_phy_notifier);
1128 usb_put_phy(fotg210->phy);
1129 }
1077 iounmap(fotg210->reg);1130 iounmap(fotg210->reg);
1078 free_irq(platform_get_irq(pdev, 0), fotg210);1131 free_irq(platform_get_irq(pdev, 0), fotg210);
1079 1132
1080 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);1133 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);
1081 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)1134 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
1082 kfree(fotg210->ep[i]);1135 kfree(fotg210->ep[i]);
1136
1137 if (!IS_ERR(fotg210->pclk))
1138 clk_disable_unprepare(fotg210->pclk);
1139
1083 kfree(fotg210);1140 kfree(fotg210);
1084 1141
1085 return 0;1142 return 0;
1086}1143}
1087 1144
1088static int fotg210_udc_probe(struct platform_device *pdev)1145int fotg210_udc_probe(struct platform_device *pdev)
1089{1146{
1090 struct resource *res, *ires;1147 struct resource *res;
1091 struct fotg210_udc *fotg210 = NULL;1148 struct fotg210_udc *fotg210 = NULL;
1092 struct fotg210_ep *_ep[FOTG210_MAX_NUM_EP];1149 struct device *dev = &pdev->dev;
1150 int irq;
1093 int ret = 0;1151 int ret = 0;
1094 int i;1152 int i;
1095 1153
@@ -1099,29 +1157,59 @@ static int fotg210_udc_probe(struct platform_device *pdev) · 3 unmodified lines
1099 return -ENODEV;1157 return -ENODEV;
1100 }1158 }
1101 1159
1102 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);1160 irq = platform_get_irq(pdev, 0);
1103 if (!ires) {1161 if (irq < 0) {
1104 pr_err("platform_get_resource IORESOURCE_IRQ error.\n");1162 pr_err("could not get irq\n");
1105 return -ENODEV;1163 return -ENODEV;
1106 }1164 }
1107 1165
1108 ret = -ENOMEM;
1109
1110 /* initialize udc */1166 /* initialize udc */
1111 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL);1167 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL);
1112 if (fotg210 == NULL)1168 if (fotg210 == NULL)
1169 return -ENOMEM;
1170
1171 fotg210->dev = dev;
1172
1173 /* It's OK not to supply this clock */
1174 fotg210->pclk = devm_clk_get(dev, "PCLK");
1175 if (!IS_ERR(fotg210->pclk)) {
1176 ret = clk_prepare_enable(fotg210->pclk);
1177 if (ret) {
1178 dev_err(dev, "failed to enable PCLK\n");
1179 goto err;
1180 }
1181 } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
1182 /*
1183 * Percolate deferrals, for anything else,
1184 * just live without the clocking.
1185 */
1186 ret = -EPROBE_DEFER;
1113 goto err;1187 goto err;
1188 }
1189
1190 fotg210->phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
1191 if (IS_ERR(fotg210->phy)) {
1192 ret = PTR_ERR(fotg210->phy);
1193 if (ret == -EPROBE_DEFER)
1194 goto err_pclk;
1195 dev_info(dev, "no PHY found\n");
1196 fotg210->phy = NULL;
1197 } else {
1198 ret = usb_phy_init(fotg210->phy);
1199 if (ret)
1200 goto err_pclk;
1201 dev_info(dev, "found and initialized PHY\n");
1202 }
1114 1203
1115 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) {1204 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) {
1116 _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL);1205 fotg210->ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL);
1117 if (_ep[i] == NULL)1206 if (!fotg210->ep[i])
1118 goto err_alloc;1207 goto err_alloc;
1119 fotg210->ep[i] = _ep[i];
1120 }1208 }
1121 1209
1122 fotg210->reg = ioremap(res->start, resource_size(res));1210 fotg210->reg = ioremap(res->start, resource_size(res));
1123 if (fotg210->reg == NULL) {1211 if (fotg210->reg == NULL) {
1124 pr_err("ioremap error.\n");1212 dev_err(dev, "ioremap error\n");
1125 goto err_alloc;1213 goto err_alloc;
1126 }1214 }
1127 1215
@@ -1132,8 +1220,8 @@ static int fotg210_udc_probe(struct platform_device *pdev) · 4 unmodified lines
1132 fotg210->gadget.ops = &fotg210_gadget_ops;1220 fotg210->gadget.ops = &fotg210_gadget_ops;
1133 1221
1134 fotg210->gadget.max_speed = USB_SPEED_HIGH;1222 fotg210->gadget.max_speed = USB_SPEED_HIGH;
1135 fotg210->gadget.dev.parent = &pdev->dev;1223 fotg210->gadget.dev.parent = dev;
1136 fotg210->gadget.dev.dma_mask = pdev->dev.dma_mask;1224 fotg210->gadget.dev.dma_mask = dev->dma_mask;
1137 fotg210->gadget.name = udc_name;1225 fotg210->gadget.name = udc_name;
1138 1226
1139 INIT_LIST_HEAD(&fotg210->gadget.ep_list);1227 INIT_LIST_HEAD(&fotg210->gadget.ep_list);
@@ -1176,23 +1264,28 @@ static int fotg210_udc_probe(struct platform_device *pdev) · 36 unmodified lines
1176 1264
1177 fotg210_disable_unplug(fotg210);1265 fotg210_disable_unplug(fotg210);
1178 1266
1179 ret = request_irq(ires->start, fotg210_irq, IRQF_SHARED,1267 ret = request_irq(irq, fotg210_irq, IRQF_SHARED,
1180 udc_name, fotg210);1268 udc_name, fotg210);
1181 if (ret < 0) {1269 if (ret < 0) {
1182 pr_err("request_irq error (%d)\n", ret);1270 dev_err(dev, "request_irq error (%d)\n", ret);
1183 goto err_req;1271 goto err_req;
1184 }1272 }
1185 1273
1186 ret = usb_add_gadget_udc(&pdev->dev, &fotg210->gadget);1274 if (!IS_ERR_OR_NULL(fotg210->phy))
1275 usb_register_notifier(fotg210->phy, &fotg210_phy_notifier);
1276
1277 ret = usb_add_gadget_udc(dev, &fotg210->gadget);
1187 if (ret)1278 if (ret)
1188 goto err_add_udc;1279 goto err_add_udc;
1189 1280
1190 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);1281 dev_info(dev, "version %s\n", DRIVER_VERSION);
1191 1282
1192 return 0;1283 return 0;
1193 1284
1194err_add_udc:1285err_add_udc:
1195 free_irq(ires->start, fotg210);1286 if (!IS_ERR_OR_NULL(fotg210->phy))
1287 usb_unregister_notifier(fotg210->phy, &fotg210_phy_notifier);
1288 free_irq(irq, fotg210);
1196 1289
1197err_req:1290err_req:
1198 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);1291 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);
@@ -1203,22 +1296,11 @@ err_map: · 4 unmodified lines
1203err_alloc:1296err_alloc:
1204 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)1297 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
1205 kfree(fotg210->ep[i]);1298 kfree(fotg210->ep[i]);
1206 kfree(fotg210);1299err_pclk:
1300 if (!IS_ERR(fotg210->pclk))
1301 clk_disable_unprepare(fotg210->pclk);
1207 1302
1208err:1303err:
1304 kfree(fotg210);
1209 return ret;1305 return ret;
1210}1306}
1211
1212static struct platform_driver fotg210_driver = {
1213 .driver = {
1214 .name = udc_name,
1215 },
1216 .probe = fotg210_udc_probe,
1217 .remove = fotg210_udc_remove,
1218};
1219
1220module_platform_driver(fotg210_driver);
1221
1222MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang <john453@faraday-tech.com>");
1223MODULE_LICENSE("GPL");
1224MODULE_DESCRIPTION(DRIVER_DESC);
drivers/usb/fotg210/fotg210-udc.hrenamed from drivers/usb/gadget/udc/fotg210.h+3−0
@@ -231,9 +231,12 @@ struct fotg210_ep { · 230 unmodified lines
231struct fotg210_udc {231struct fotg210_udc {
232 spinlock_t lock; /* protect the struct */232 spinlock_t lock; /* protect the struct */
233 void __iomem *reg;233 void __iomem *reg;
234 struct clk *pclk;
234 235
235 unsigned long irq_trigger;236 unsigned long irq_trigger;
236 237
238 struct device *dev;
239 struct usb_phy *phy;
237 struct usb_gadget gadget;240 struct usb_gadget gadget;
238 struct usb_gadget_driver *driver;241 struct usb_gadget_driver *driver;
239 242
drivers/usb/fotg210/fotg210.h+42−0
@@ -0,0 +1,42 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __FOTG210_H
3#define __FOTG210_H
4
5#ifdef CONFIG_USB_FOTG210_HCD
6int fotg210_hcd_probe(struct platform_device *pdev);
7int fotg210_hcd_remove(struct platform_device *pdev);
8int fotg210_hcd_init(void);
9void fotg210_hcd_cleanup(void);
10#else
11static inline int fotg210_hcd_probe(struct platform_device *pdev)
12{
13 return 0;
14}
15static inline int fotg210_hcd_remove(struct platform_device *pdev)
16{
17 return 0;
18}
19static inline int fotg210_hcd_init(void)
20{
21 return 0;
22}
23static inline void fotg210_hcd_cleanup(void)
24{
25}
26#endif
27
28#ifdef CONFIG_USB_FOTG210_UDC
29int fotg210_udc_probe(struct platform_device *pdev);
30int fotg210_udc_remove(struct platform_device *pdev);
31#else
32static inline int fotg210_udc_probe(struct platform_device *pdev)
33{
34 return 0;
35}
36static inline int fotg210_udc_remove(struct platform_device *pdev)
37{
38 return 0;
39}
40#endif
41
42#endif /* __FOTG210_H */
drivers/usb/gadget/configfs.c+2−1
@@ -3,6 +3,7 @@ · 2 unmodified lines
3#include <linux/module.h>3#include <linux/module.h>
4#include <linux/slab.h>4#include <linux/slab.h>
5#include <linux/device.h>5#include <linux/device.h>
6#include <linux/kstrtox.h>
6#include <linux/nls.h>7#include <linux/nls.h>
7#include <linux/usb/composite.h>8#include <linux/usb/composite.h>
8#include <linux/usb/gadget_configfs.h>9#include <linux/usb/gadget_configfs.h>
@@ -800,7 +801,7 @@ static ssize_t os_desc_use_store(struct config_item *item, const char *page, · 791 unmodified lines
800 bool use;801 bool use;
801 802
802 mutex_lock(&gi->lock);803 mutex_lock(&gi->lock);
803 ret = strtobool(page, &use);804 ret = kstrtobool(page, &use);
804 if (!ret) {805 if (!ret) {
805 gi->use_os_desc = use;806 gi->use_os_desc = use;
806 ret = len;807 ret = len;
drivers/usb/gadget/function/f_ecm.c+9−13
@@ -685,7 +685,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) · 684 unmodified lines
685 struct usb_composite_dev *cdev = c->cdev;685 struct usb_composite_dev *cdev = c->cdev;
686 struct f_ecm *ecm = func_to_ecm(f);686 struct f_ecm *ecm = func_to_ecm(f);
687 struct usb_string *us;687 struct usb_string *us;
688 int status;688 int status = 0;
689 struct usb_ep *ep;689 struct usb_ep *ep;
690 690
691 struct f_ecm_opts *ecm_opts;691 struct f_ecm_opts *ecm_opts;
@@ -695,23 +695,19 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) · 3 unmodified lines
695 695
696 ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst);696 ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst);
697 697
698 /*698 mutex_lock(&ecm_opts->lock);
699 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()699
700 * configurations are bound in sequence with list_for_each_entry,700 gether_set_gadget(ecm_opts->net, cdev->gadget);
701 * in each configuration its functions are bound in sequence701
702 * with list_for_each_entry, so we assume no race condition
703 * with regard to ecm_opts->bound access
704 */
705 if (!ecm_opts->bound) {702 if (!ecm_opts->bound) {
706 mutex_lock(&ecm_opts->lock);
707 gether_set_gadget(ecm_opts->net, cdev->gadget);
708 status = gether_register_netdev(ecm_opts->net);703 status = gether_register_netdev(ecm_opts->net);
709 mutex_unlock(&ecm_opts->lock);
710 if (status)
711 return status;
712 ecm_opts->bound = true;704 ecm_opts->bound = true;
713 }705 }
714 706
707 mutex_unlock(&ecm_opts->lock);
708 if (status)
709 return status;
710
715 ecm_string_defs[1].s = ecm->ethaddr;711 ecm_string_defs[1].s = ecm->ethaddr;
716 712
717 us = usb_gstrings_attach(cdev, ecm_strings,713 us = usb_gstrings_attach(cdev, ecm_strings,
drivers/usb/gadget/function/f_hid.c+33−27
@@ -71,7 +71,7 @@ struct f_hidg { · 70 unmodified lines
71 wait_queue_head_t write_queue;71 wait_queue_head_t write_queue;
72 struct usb_request *req;72 struct usb_request *req;
73 73
74 int minor;74 struct device dev;
75 struct cdev cdev;75 struct cdev cdev;
76 struct usb_function func;76 struct usb_function func;
77 77
@@ -84,6 +84,14 @@ static inline struct f_hidg *func_to_hidg(struct usb_function *f) · 6 unmodified lines
84 return container_of(f, struct f_hidg, func);84 return container_of(f, struct f_hidg, func);
85}85}
86 86
87static void hidg_release(struct device *dev)
88{
89 struct f_hidg *hidg = container_of(dev, struct f_hidg, dev);
90
91 kfree(hidg->set_report_buf);
92 kfree(hidg);
93}
94
87/*-------------------------------------------------------------------------*/95/*-------------------------------------------------------------------------*/
88/* Static descriptors */96/* Static descriptors */
89 97
@@ -904,9 +912,7 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f) · 814 unmodified lines
904 struct usb_ep *ep;912 struct usb_ep *ep;
905 struct f_hidg *hidg = func_to_hidg(f);913 struct f_hidg *hidg = func_to_hidg(f);
906 struct usb_string *us;914 struct usb_string *us;
907 struct device *device;
908 int status;915 int status;
909 dev_t dev;
910 916
911 /* maybe allocate device-global string IDs, and patch descriptors */917 /* maybe allocate device-global string IDs, and patch descriptors */
912 us = usb_gstrings_attach(c->cdev, ct_func_strings,918 us = usb_gstrings_attach(c->cdev, ct_func_strings,
@@ -999,21 +1005,11 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f) · 86 unmodified lines
999 1005
1000 /* create char device */1006 /* create char device */
1001 cdev_init(&hidg->cdev, &f_hidg_fops);1007 cdev_init(&hidg->cdev, &f_hidg_fops);
1002 dev = MKDEV(major, hidg->minor);1008 status = cdev_device_add(&hidg->cdev, &hidg->dev);
1003 status = cdev_add(&hidg->cdev, dev, 1);
1004 if (status)1009 if (status)
1005 goto fail_free_descs;1010 goto fail_free_descs;
1006 1011
1007 device = device_create(hidg_class, NULL, dev, NULL,
1008 "%s%d", "hidg", hidg->minor);
1009 if (IS_ERR(device)) {
1010 status = PTR_ERR(device);
1011 goto del;
1012 }
1013
1014 return 0;1012 return 0;
1015del:
1016 cdev_del(&hidg->cdev);
1017fail_free_descs:1013fail_free_descs:
1018 usb_free_all_descriptors(f);1014 usb_free_all_descriptors(f);
1019fail:1015fail:
@@ -1244,9 +1240,7 @@ static void hidg_free(struct usb_function *f) · 224 unmodified lines
1244 1240
1245 hidg = func_to_hidg(f);1241 hidg = func_to_hidg(f);
1246 opts = container_of(f->fi, struct f_hid_opts, func_inst);1242 opts = container_of(f->fi, struct f_hid_opts, func_inst);
1247 kfree(hidg->report_desc);1243 put_device(&hidg->dev);
1248 kfree(hidg->set_report_buf);
1249 kfree(hidg);
1250 mutex_lock(&opts->lock);1244 mutex_lock(&opts->lock);
1251 --opts->refcnt;1245 --opts->refcnt;
1252 mutex_unlock(&opts->lock);1246 mutex_unlock(&opts->lock);
@@ -1256,8 +1250,7 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f) · 3 unmodified lines
1256{1250{
1257 struct f_hidg *hidg = func_to_hidg(f);1251 struct f_hidg *hidg = func_to_hidg(f);
1258 1252
1259 device_destroy(hidg_class, MKDEV(major, hidg->minor));1253 cdev_device_del(&hidg->cdev, &hidg->dev);
1260 cdev_del(&hidg->cdev);
1261 1254
1262 usb_free_all_descriptors(f);1255 usb_free_all_descriptors(f);
1263}1256}
@@ -1266,6 +1259,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) · 2 unmodified lines
1266{1259{
1267 struct f_hidg *hidg;1260 struct f_hidg *hidg;
1268 struct f_hid_opts *opts;1261 struct f_hid_opts *opts;
1262 int ret;
1269 1263
1270 /* allocate and initialize one new instance */1264 /* allocate and initialize one new instance */
1271 hidg = kzalloc(sizeof(*hidg), GFP_KERNEL);1265 hidg = kzalloc(sizeof(*hidg), GFP_KERNEL);
@@ -1275,25 +1269,31 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) · 3 unmodified lines
1275 opts = container_of(fi, struct f_hid_opts, func_inst);1269 opts = container_of(fi, struct f_hid_opts, func_inst);
1276 1270
1277 mutex_lock(&opts->lock);1271 mutex_lock(&opts->lock);
1278 ++opts->refcnt;
1279 1272
1280 hidg->minor = opts->minor;1273 device_initialize(&hidg->dev);
1274 hidg->dev.release = hidg_release;
1275 hidg->dev.class = hidg_class;
1276 hidg->dev.devt = MKDEV(major, opts->minor);
1277 ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor);
1278 if (ret)
1279 goto err_unlock;
1280
1281 hidg->bInterfaceSubClass = opts->subclass;1281 hidg->bInterfaceSubClass = opts->subclass;
1282 hidg->bInterfaceProtocol = opts->protocol;1282 hidg->bInterfaceProtocol = opts->protocol;
1283 hidg->report_length = opts->report_length;1283 hidg->report_length = opts->report_length;
1284 hidg->report_desc_length = opts->report_desc_length;1284 hidg->report_desc_length = opts->report_desc_length;
1285 if (opts->report_desc) {1285 if (opts->report_desc) {
1286 hidg->report_desc = kmemdup(opts->report_desc,1286 hidg->report_desc = devm_kmemdup(&hidg->dev, opts->report_desc,
1287 opts->report_desc_length,1287 opts->report_desc_length,
1288 GFP_KERNEL);1288 GFP_KERNEL);
1289 if (!hidg->report_desc) {1289 if (!hidg->report_desc) {
1290 kfree(hidg);1290 ret = -ENOMEM;
1291 mutex_unlock(&opts->lock);1291 goto err_put_device;
1292 return ERR_PTR(-ENOMEM);
1293 }1292 }
1294 }1293 }
1295 hidg->use_out_ep = !opts->no_out_endpoint;1294 hidg->use_out_ep = !opts->no_out_endpoint;
1296 1295
1296 ++opts->refcnt;
1297 mutex_unlock(&opts->lock);1297 mutex_unlock(&opts->lock);
1298 1298
1299 hidg->func.name = "hid";1299 hidg->func.name = "hid";
@@ -1308,6 +1308,12 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) · 8 unmodified lines
1308 hidg->qlen = 4;1308 hidg->qlen = 4;
1309 1309
1310 return &hidg->func;1310 return &hidg->func;
1311
1312err_put_device:
1313 put_device(&hidg->dev);
1314err_unlock:
1315 mutex_unlock(&opts->lock);
1316 return ERR_PTR(ret);
1311}1317}
1312 1318
1313DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc);1319DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc);
drivers/usb/gadget/function/f_mass_storage.c+2−1
@@ -176,6 +176,7 @@ · 175 unmodified lines
176#include <linux/fcntl.h>176#include <linux/fcntl.h>
177#include <linux/file.h>177#include <linux/file.h>
178#include <linux/fs.h>178#include <linux/fs.h>
179#include <linux/kstrtox.h>
179#include <linux/kthread.h>180#include <linux/kthread.h>
180#include <linux/sched/signal.h>181#include <linux/sched/signal.h>
181#include <linux/limits.h>182#include <linux/limits.h>
@@ -3387,7 +3388,7 @@ static ssize_t fsg_opts_stall_store(struct config_item *item, const char *page, · 3205 unmodified lines
3387 return -EBUSY;3388 return -EBUSY;
3388 }3389 }
3389 3390
3390 ret = strtobool(page, &stall);3391 ret = kstrtobool(page, &stall);
3391 if (!ret) {3392 if (!ret) {
3392 opts->common->can_stall = stall;3393 opts->common->can_stall = stall;
3393 ret = len;3394 ret = len;
drivers/usb/gadget/function/f_printer.c+1−8
@@ -364,7 +364,7 @@ printer_open(struct inode *inode, struct file *fd) · 363 unmodified lines
364 spin_unlock_irqrestore(&dev->lock, flags);364 spin_unlock_irqrestore(&dev->lock, flags);
365 365
366 kref_get(&dev->kref);366 kref_get(&dev->kref);
367 DBG(dev, "printer_open returned %x\n", ret);367
368 return ret;368 return ret;
369}369}
370 370
@@ -382,7 +382,6 @@ printer_close(struct inode *inode, struct file *fd) · 11 unmodified lines
382 spin_unlock_irqrestore(&dev->lock, flags);382 spin_unlock_irqrestore(&dev->lock, flags);
383 383
384 kref_put(&dev->kref, printer_dev_free);384 kref_put(&dev->kref, printer_dev_free);
385 DBG(dev, "printer_close\n");
386 385
387 return 0;386 return 0;
388}387}
@@ -848,8 +847,6 @@ static void printer_reset_interface(struct printer_dev *dev) · 459 unmodified lines
848 if (dev->interface < 0)847 if (dev->interface < 0)
849 return;848 return;
850 849
851 DBG(dev, "%s\n", __func__);
852
853 if (dev->in_ep->desc)850 if (dev->in_ep->desc)
854 usb_ep_disable(dev->in_ep);851 usb_ep_disable(dev->in_ep);
855 852
@@ -887,8 +884,6 @@ static void printer_soft_reset(struct printer_dev *dev) · 31 unmodified lines
887{884{
888 struct usb_request *req;885 struct usb_request *req;
889 886
890 INFO(dev, "Received Printer Reset Request\n");
891
892 if (usb_ep_disable(dev->in_ep))887 if (usb_ep_disable(dev->in_ep))
893 DBG(dev, "Failed to disable USB in_ep\n");888 DBG(dev, "Failed to disable USB in_ep\n");
894 if (usb_ep_disable(dev->out_ep))889 if (usb_ep_disable(dev->out_ep))
@@ -1185,8 +1180,6 @@ static void printer_func_disable(struct usb_function *f) · 290 unmodified lines
1185{1180{
1186 struct printer_dev *dev = func_to_printer(f);1181 struct printer_dev *dev = func_to_printer(f);
1187 1182
1188 DBG(dev, "%s\n", __func__);
1189
1190 printer_reset_interface(dev);1183 printer_reset_interface(dev);
1191}1184}
1192 1185
drivers/usb/gadget/function/f_uvc.c+15−5
@@ -39,9 +39,6 @@ MODULE_PARM_DESC(trace, "Trace level bitmask"); · 38 unmodified lines
39 39
40/* string IDs are assigned dynamically */40/* string IDs are assigned dynamically */
41 41
42#define UVC_STRING_CONTROL_IDX 0
43#define UVC_STRING_STREAMING_IDX 1
44
45static struct usb_string uvc_en_us_strings[] = {42static struct usb_string uvc_en_us_strings[] = {
46 /* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */43 /* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */
47 [UVC_STRING_STREAMING_IDX].s = "Video Streaming",44 [UVC_STRING_STREAMING_IDX].s = "Video Streaming",
@@ -216,8 +213,9 @@ uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req) · 168 unmodified lines
216 213
217 memset(&v4l2_event, 0, sizeof(v4l2_event));214 memset(&v4l2_event, 0, sizeof(v4l2_event));
218 v4l2_event.type = UVC_EVENT_DATA;215 v4l2_event.type = UVC_EVENT_DATA;
219 uvc_event->data.length = req->actual;216 uvc_event->data.length = min_t(unsigned int, req->actual,
220 memcpy(&uvc_event->data.data, req->buf, req->actual);217 sizeof(uvc_event->data.data));
218 memcpy(&uvc_event->data.data, req->buf, uvc_event->data.length);
221 v4l2_event_queue(&uvc->vdev, &v4l2_event);219 v4l2_event_queue(&uvc->vdev, &v4l2_event);
222 }220 }
223}221}
@@ -228,6 +226,8 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) · 4 unmodified lines
228 struct uvc_device *uvc = to_uvc(f);226 struct uvc_device *uvc = to_uvc(f);
229 struct v4l2_event v4l2_event;227 struct v4l2_event v4l2_event;
230 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;228 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
229 unsigned int interface = le16_to_cpu(ctrl->wIndex) & 0xff;
230 struct usb_ctrlrequest *mctrl;
231 231
232 if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) {232 if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) {
233 uvcg_info(f, "invalid request type\n");233 uvcg_info(f, "invalid request type\n");
@@ -248,6 +248,16 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) · 14 unmodified lines
248 memset(&v4l2_event, 0, sizeof(v4l2_event));248 memset(&v4l2_event, 0, sizeof(v4l2_event));
249 v4l2_event.type = UVC_EVENT_SETUP;249 v4l2_event.type = UVC_EVENT_SETUP;
250 memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req));250 memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req));
251
252 /* check for the interface number, fixup the interface number in
253 * the ctrl request so the userspace doesn't have to bother with
254 * offset and configfs parsing
255 */
256 mctrl = &uvc_event->req;
257 mctrl->wIndex &= ~cpu_to_le16(0xff);
258 if (interface == uvc->streaming_intf)
259 mctrl->wIndex = cpu_to_le16(UVC_STRING_STREAMING_IDX);
260
251 v4l2_event_queue(&uvc->vdev, &v4l2_event);261 v4l2_event_queue(&uvc->vdev, &v4l2_event);
252 262
253 return 0;263 return 0;
drivers/usb/gadget/function/storage_common.c+5−4
@@ -23,6 +23,7 @@ · 22 unmodified lines
23#include <linux/blkdev.h>23#include <linux/blkdev.h>
24#include <linux/file.h>24#include <linux/file.h>
25#include <linux/fs.h>25#include <linux/fs.h>
26#include <linux/kstrtox.h>
26#include <linux/usb/composite.h>27#include <linux/usb/composite.h>
27 28
28#include "storage_common.h"29#include "storage_common.h"
@@ -396,7 +397,7 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, · 367 unmodified lines
396 ssize_t rc;397 ssize_t rc;
397 bool ro;398 bool ro;
398 399
399 rc = strtobool(buf, &ro);400 rc = kstrtobool(buf, &ro);
400 if (rc)401 if (rc)
401 return rc;402 return rc;
402 403
@@ -419,7 +420,7 @@ ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) · 16 unmodified lines
419 bool nofua;420 bool nofua;
420 int ret;421 int ret;
421 422
422 ret = strtobool(buf, &nofua);423 ret = kstrtobool(buf, &nofua);
423 if (ret)424 if (ret)
424 return ret;425 return ret;
425 426
@@ -470,7 +471,7 @@ ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, · 44 unmodified lines
470 bool cdrom;471 bool cdrom;
471 int ret;472 int ret;
472 473
473 ret = strtobool(buf, &cdrom);474 ret = kstrtobool(buf, &cdrom);
474 if (ret)475 if (ret)
475 return ret;476 return ret;
476 477
@@ -493,7 +494,7 @@ ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, · 16 unmodified lines
493 bool removable;494 bool removable;
494 int ret;495 int ret;
495 496
496 ret = strtobool(buf, &removable);497 ret = kstrtobool(buf, &removable);
497 if (ret)498 if (ret)
498 return ret;499 return ret;
499 500
drivers/usb/gadget/function/u_ether.c+0−4
@@ -798,7 +798,6 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, · 797 unmodified lines
798 net->max_mtu = GETHER_MAX_MTU_SIZE;798 net->max_mtu = GETHER_MAX_MTU_SIZE;
799 799
800 dev->gadget = g;800 dev->gadget = g;
801 SET_NETDEV_DEV(net, &g->dev);
802 SET_NETDEV_DEVTYPE(net, &gadget_type);801 SET_NETDEV_DEVTYPE(net, &gadget_type);
803 802
804 status = register_netdev(net);803 status = register_netdev(net);
@@ -873,8 +872,6 @@ int gether_register_netdev(struct net_device *net) · 68 unmodified lines
873 struct usb_gadget *g;872 struct usb_gadget *g;
874 int status;873 int status;
875 874
876 if (!net->dev.parent)
877 return -EINVAL;
878 dev = netdev_priv(net);875 dev = netdev_priv(net);
879 g = dev->gadget;876 g = dev->gadget;
880 877
@@ -905,7 +902,6 @@ void gether_set_gadget(struct net_device *net, struct usb_gadget *g) · 24 unmodified lines
905 902
906 dev = netdev_priv(net);903 dev = netdev_priv(net);
907 dev->gadget = g;904 dev->gadget = g;
908 SET_NETDEV_DEV(net, &g->dev);
909}905}
910EXPORT_SYMBOL_GPL(gether_set_gadget);906EXPORT_SYMBOL_GPL(gether_set_gadget);
911 907
drivers/usb/gadget/function/u_serial.c+2−1
@@ -24,6 +24,7 @@ · 23 unmodified lines
24#include <linux/export.h>24#include <linux/export.h>
25#include <linux/module.h>25#include <linux/module.h>
26#include <linux/console.h>26#include <linux/console.h>
27#include <linux/kstrtox.h>
27#include <linux/kthread.h>28#include <linux/kthread.h>
28#include <linux/workqueue.h>29#include <linux/workqueue.h>
29#include <linux/kfifo.h>30#include <linux/kfifo.h>
@@ -1070,7 +1071,7 @@ ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t cou · 1040 unmodified lines
1070 bool enable;1071 bool enable;
1071 int ret;1072 int ret;
1072 1073
1073 ret = strtobool(page, &enable);1074 ret = kstrtobool(page, &enable);
1074 if (ret)1075 if (ret)
1075 return ret;1076 return ret;
1076 1077
drivers/usb/gadget/function/uvc_configfs.c+6−6
@@ -1512,7 +1512,7 @@ UVCG_UNCOMPRESSED_ATTR(b_bits_per_pixel, bBitsPerPixel, 8); · 1511 unmodified lines
1512UVCG_UNCOMPRESSED_ATTR(b_default_frame_index, bDefaultFrameIndex, 8);1512UVCG_UNCOMPRESSED_ATTR(b_default_frame_index, bDefaultFrameIndex, 8);
1513UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8);1513UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8);
1514UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8);1514UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8);
1515UVCG_UNCOMPRESSED_ATTR_RO(bm_interface_flags, bmInterfaceFlags, 8);1515UVCG_UNCOMPRESSED_ATTR_RO(bm_interlace_flags, bmInterlaceFlags, 8);
1516 1516
1517#undef UVCG_UNCOMPRESSED_ATTR1517#undef UVCG_UNCOMPRESSED_ATTR
1518#undef UVCG_UNCOMPRESSED_ATTR_RO1518#undef UVCG_UNCOMPRESSED_ATTR_RO
@@ -1541,7 +1541,7 @@ static struct configfs_attribute *uvcg_uncompressed_attrs[] = { · 22 unmodified lines
1541 &uvcg_uncompressed_attr_b_default_frame_index,1541 &uvcg_uncompressed_attr_b_default_frame_index,
1542 &uvcg_uncompressed_attr_b_aspect_ratio_x,1542 &uvcg_uncompressed_attr_b_aspect_ratio_x,
1543 &uvcg_uncompressed_attr_b_aspect_ratio_y,1543 &uvcg_uncompressed_attr_b_aspect_ratio_y,
1544 &uvcg_uncompressed_attr_bm_interface_flags,1544 &uvcg_uncompressed_attr_bm_interlace_flags,
1545 &uvcg_uncompressed_attr_bma_controls,1545 &uvcg_uncompressed_attr_bma_controls,
1546 NULL,1546 NULL,
1547};1547};
@@ -1574,7 +1574,7 @@ static struct config_group *uvcg_uncompressed_make(struct config_group *group, · 26 unmodified lines
1574 h->desc.bDefaultFrameIndex = 1;1574 h->desc.bDefaultFrameIndex = 1;
1575 h->desc.bAspectRatioX = 0;1575 h->desc.bAspectRatioX = 0;
1576 h->desc.bAspectRatioY = 0;1576 h->desc.bAspectRatioY = 0;
1577 h->desc.bmInterfaceFlags = 0;1577 h->desc.bmInterlaceFlags = 0;
1578 h->desc.bCopyProtect = 0;1578 h->desc.bCopyProtect = 0;
1579 1579
1580 INIT_LIST_HEAD(&h->fmt.frames);1580 INIT_LIST_HEAD(&h->fmt.frames);
@@ -1700,7 +1700,7 @@ UVCG_MJPEG_ATTR(b_default_frame_index, bDefaultFrameIndex, 8); · 119 unmodified lines
1700UVCG_MJPEG_ATTR_RO(bm_flags, bmFlags, 8);1700UVCG_MJPEG_ATTR_RO(bm_flags, bmFlags, 8);
1701UVCG_MJPEG_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8);1701UVCG_MJPEG_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8);
1702UVCG_MJPEG_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8);1702UVCG_MJPEG_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8);
1703UVCG_MJPEG_ATTR_RO(bm_interface_flags, bmInterfaceFlags, 8);1703UVCG_MJPEG_ATTR_RO(bm_interlace_flags, bmInterlaceFlags, 8);
1704 1704
1705#undef UVCG_MJPEG_ATTR1705#undef UVCG_MJPEG_ATTR
1706#undef UVCG_MJPEG_ATTR_RO1706#undef UVCG_MJPEG_ATTR_RO
@@ -1728,7 +1728,7 @@ static struct configfs_attribute *uvcg_mjpeg_attrs[] = { · 21 unmodified lines
1728 &uvcg_mjpeg_attr_bm_flags,1728 &uvcg_mjpeg_attr_bm_flags,
1729 &uvcg_mjpeg_attr_b_aspect_ratio_x,1729 &uvcg_mjpeg_attr_b_aspect_ratio_x,
1730 &uvcg_mjpeg_attr_b_aspect_ratio_y,1730 &uvcg_mjpeg_attr_b_aspect_ratio_y,
1731 &uvcg_mjpeg_attr_bm_interface_flags,1731 &uvcg_mjpeg_attr_bm_interlace_flags,
1732 &uvcg_mjpeg_attr_bma_controls,1732 &uvcg_mjpeg_attr_bma_controls,
1733 NULL,1733 NULL,
1734};1734};
@@ -1755,7 +1755,7 @@ static struct config_group *uvcg_mjpeg_make(struct config_group *group, · 20 unmodified lines
1755 h->desc.bDefaultFrameIndex = 1;1755 h->desc.bDefaultFrameIndex = 1;
1756 h->desc.bAspectRatioX = 0;1756 h->desc.bAspectRatioX = 0;
1757 h->desc.bAspectRatioY = 0;1757 h->desc.bAspectRatioY = 0;
1758 h->desc.bmInterfaceFlags = 0;1758 h->desc.bmInterlaceFlags = 0;
1759 h->desc.bCopyProtect = 0;1759 h->desc.bCopyProtect = 0;
1760 1760
1761 INIT_LIST_HEAD(&h->fmt.frames);1761 INIT_LIST_HEAD(&h->fmt.frames);
drivers/usb/gadget/legacy/serial.c+2−1
@@ -9,6 +9,7 @@ · 8 unmodified lines
9 9
10#include <linux/kernel.h>10#include <linux/kernel.h>
11#include <linux/device.h>11#include <linux/device.h>
12#include <linux/kstrtox.h>
12#include <linux/module.h>13#include <linux/module.h>
13#include <linux/tty.h>14#include <linux/tty.h>
14#include <linux/tty_flip.h>15#include <linux/tty_flip.h>
@@ -109,7 +110,7 @@ static int enable_set(const char *s, const struct kernel_param *kp) · 94 unmodified lines
109 if (!s) /* called for no-arg enable == default */110 if (!s) /* called for no-arg enable == default */
110 return 0;111 return 0;
111 112
112 ret = strtobool(s, &do_enable);113 ret = kstrtobool(s, &do_enable);
113 if (ret || enable == do_enable)114 if (ret || enable == do_enable)
114 return ret;115 return ret;
115 116
drivers/usb/gadget/legacy/webcam.c+2−2
@@ -171,7 +171,7 @@ static const struct uvc_format_uncompressed uvc_format_yuv = { · 170 unmodified lines
171 .bDefaultFrameIndex = 1,171 .bDefaultFrameIndex = 1,
172 .bAspectRatioX = 0,172 .bAspectRatioX = 0,
173 .bAspectRatioY = 0,173 .bAspectRatioY = 0,
174 .bmInterfaceFlags = 0,174 .bmInterlaceFlags = 0,
175 .bCopyProtect = 0,175 .bCopyProtect = 0,
176};176};
177 177
@@ -222,7 +222,7 @@ static const struct uvc_format_mjpeg uvc_format_mjpg = { · 44 unmodified lines
222 .bDefaultFrameIndex = 1,222 .bDefaultFrameIndex = 1,
223 .bAspectRatioX = 0,223 .bAspectRatioX = 0,
224 .bAspectRatioY = 0,224 .bAspectRatioY = 0,
225 .bmInterfaceFlags = 0,225 .bmInterlaceFlags = 0,
226 .bCopyProtect = 0,226 .bCopyProtect = 0,
227};227};
228 228
drivers/usb/gadget/udc/Kconfig+2−13
@@ -33,7 +33,7 @@ menu "USB Peripheral Controller" · 32 unmodified lines
33config USB_AT9133config USB_AT91
34 tristate "Atmel AT91 USB Device Port"34 tristate "Atmel AT91 USB Device Port"
35 depends on ARCH_AT9135 depends on ARCH_AT91
36 depends on OF || COMPILE_TEST36 depends on OF
37 help37 help
38 Many Atmel AT91 processors (such as the AT91RM2000) have a38 Many Atmel AT91 processors (such as the AT91RM2000) have a
39 full speed USB Device Port with support for five configurable39 full speed USB Device Port with support for five configurable
@@ -108,17 +108,6 @@ config USB_FUSB300 · 68 unmodified lines
108 help108 help
109 Faraday usb device controller FUSB300 driver109 Faraday usb device controller FUSB300 driver
110 110
111config USB_FOTG210_UDC
112 depends on HAS_DMA
113 tristate "Faraday FOTG210 USB Peripheral Controller"
114 help
115 Faraday USB2.0 OTG controller which can be configured as
116 high speed or full speed USB device. This driver supppors
117 Bulk Transfer so far.
118
119 Say "y" to link the driver statically, or "m" to build a
120 dynamically linked module called "fotg210_udc".
121
122config USB_GR_UDC111config USB_GR_UDC
123 tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver"112 tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver"
124 depends on HAS_DMA113 depends on HAS_DMA
@@ -430,7 +419,7 @@ config USB_EG20T · 305 unmodified lines
430config USB_GADGET_XILINX419config USB_GADGET_XILINX
431 tristate "Xilinx USB Driver"420 tristate "Xilinx USB Driver"
432 depends on HAS_DMA421 depends on HAS_DMA
433 depends on OF || COMPILE_TEST422 depends on OF
434 help423 help
435 USB peripheral controller driver for Xilinx USB2 device.424 USB peripheral controller driver for Xilinx USB2 device.
436 Xilinx USB2 device is a soft IP which supports both full425 Xilinx USB2 device is a soft IP which supports both full
drivers/usb/gadget/udc/Makefile+0−1
@@ -34,7 +34,6 @@ obj-$(CONFIG_USB_EG20T) += pch_udc.o · 33 unmodified lines
34obj-$(CONFIG_USB_MV_UDC) += mv_udc.o34obj-$(CONFIG_USB_MV_UDC) += mv_udc.o
35mv_udc-y := mv_udc_core.o35mv_udc-y := mv_udc_core.o
36obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o36obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
37obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
38obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o37obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
39obj-$(CONFIG_USB_GR_UDC) += gr_udc.o38obj-$(CONFIG_USB_GR_UDC) += gr_udc.o
40obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o39obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o
drivers/usb/gadget/udc/aspeed-vhub/core.c+1−1
@@ -37,7 +37,7 @@ void ast_vhub_done(struct ast_vhub_ep *ep, struct ast_vhub_req *req, · 36 unmodified lines
37 37
38 list_del_init(&req->queue);38 list_del_init(&req->queue);
39 39
40 if (req->req.status == -EINPROGRESS)40 if ((req->req.status == -EINPROGRESS) || (status == -EOVERFLOW))
41 req->req.status = status;41 req->req.status = status;
42 42
43 if (req->req.dma) {43 if (req->req.dma) {
drivers/usb/gadget/udc/aspeed-vhub/epn.c+12−4
@@ -84,6 +84,7 @@ static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) · 83 unmodified lines
84{84{
85 struct ast_vhub_req *req;85 struct ast_vhub_req *req;
86 unsigned int len;86 unsigned int len;
87 int status = 0;
87 u32 stat;88 u32 stat;
88 89
89 /* Read EP status */90 /* Read EP status */
@@ -119,9 +120,15 @@ static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) · 29 unmodified lines
119 len = VHUB_EP_DMA_TX_SIZE(stat);120 len = VHUB_EP_DMA_TX_SIZE(stat);
120 121
121 /* If not using DMA, copy data out if needed */122 /* If not using DMA, copy data out if needed */
122 if (!req->req.dma && !ep->epn.is_in && len)123 if (!req->req.dma && !ep->epn.is_in && len) {
123 memcpy(req->req.buf + req->req.actual, ep->buf, len);124 if (req->req.actual + len > req->req.length) {
124 125 req->last_desc = 1;
126 status = -EOVERFLOW;
127 goto done;
128 } else {
129 memcpy(req->req.buf + req->req.actual, ep->buf, len);
130 }
131 }
125 /* Adjust size */132 /* Adjust size */
126 req->req.actual += len;133 req->req.actual += len;
127 134
@@ -129,9 +136,10 @@ static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) · 1 unmodified line
129 if (len < ep->ep.maxpacket)136 if (len < ep->ep.maxpacket)
130 req->last_desc = 1;137 req->last_desc = 1;
131 138
139done:
132 /* That's it ? complete the request and pick a new one */140 /* That's it ? complete the request and pick a new one */
133 if (req->last_desc >= 0) {141 if (req->last_desc >= 0) {
134 ast_vhub_done(ep, req, 0);142 ast_vhub_done(ep, req, status);
135 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req,143 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req,
136 queue);144 queue);
137 145
drivers/usb/gadget/udc/at91_udc.c+1−4
@@ -1628,10 +1628,7 @@ static int at91rm9200_udc_init(struct at91_udc *udc) · 1627 unmodified lines
1628 1628
1629static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on)1629static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on)
1630{1630{
1631 if (is_on)1631 gpiod_set_value(udc->board.pullup_pin, is_on);
1632 gpiod_set_value(udc->board.pullup_pin, 1);
1633 else
1634 gpiod_set_value(udc->board.pullup_pin, 0);
1635}1632}
1636 1633
1637static const struct at91_udc_caps at91rm9200_udc_caps = {1634static const struct at91_udc_caps at91rm9200_udc_caps = {
drivers/usb/gadget/udc/core.c+6−6
@@ -734,13 +734,13 @@ int usb_gadget_disconnect(struct usb_gadget *gadget) · 733 unmodified lines
734 }734 }
735 735
736 ret = gadget->ops->pullup(gadget, 0);736 ret = gadget->ops->pullup(gadget, 0);
737 if (!ret) {737 if (!ret)
738 gadget->connected = 0;738 gadget->connected = 0;
739 mutex_lock(&udc_lock);739
740 if (gadget->udc->driver)740 mutex_lock(&udc_lock);
741 gadget->udc->driver->disconnect(gadget);741 if (gadget->udc->driver)
742 mutex_unlock(&udc_lock);742 gadget->udc->driver->disconnect(gadget);
743 }743 mutex_unlock(&udc_lock);
744 744
745out:745out:
746 trace_usb_gadget_disconnect(gadget, ret);746 trace_usb_gadget_disconnect(gadget, ret);
drivers/usb/host/Kconfig+1−12
@@ -47,7 +47,7 @@ config USB_XHCI_PCI_RENESAS · 46 unmodified lines
47 tristate "Support for additional Renesas xHCI controller with firmware"47 tristate "Support for additional Renesas xHCI controller with firmware"
48 help48 help
49 Say 'Y' to enable the support for the Renesas xHCI controller with49 Say 'Y' to enable the support for the Renesas xHCI controller with
50 firmware. Make sure you have the firwmare for the device and50 firmware. Make sure you have the firmware for the device and
51 installed on your system for this device to work.51 installed on your system for this device to work.
52 If unsure, say 'N'.52 If unsure, say 'N'.
53 53
@@ -389,17 +389,6 @@ config USB_ISP1362_HCD · 335 unmodified lines
389 To compile this driver as a module, choose M here: the389 To compile this driver as a module, choose M here: the
390 module will be called isp1362-hcd.390 module will be called isp1362-hcd.
391 391
392config USB_FOTG210_HCD
393 tristate "FOTG210 HCD support"
394 depends on USB && HAS_DMA && HAS_IOMEM
395 help
396 Faraday FOTG210 is an OTG controller which can be configured as
397 an USB2.0 host. It is designed to meet USB2.0 EHCI specification
398 with minor modification.
399
400 To compile this driver as a module, choose M here: the
401 module will be called fotg210-hcd.
402
403config USB_MAX3421_HCD392config USB_MAX3421_HCD
404 tristate "MAX3421 HCD (USB-over-SPI) support"393 tristate "MAX3421 HCD (USB-over-SPI) support"
405 depends on USB && SPI394 depends on USB && SPI
drivers/usb/host/Makefile+0−1
@@ -84,6 +84,5 @@ obj-$(CONFIG_USB_EHCI_FSL) += ehci-fsl.o · 83 unmodified lines
84obj-$(CONFIG_USB_EHCI_MV) += ehci-mv.o84obj-$(CONFIG_USB_EHCI_MV) += ehci-mv.o
85obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o85obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o
86obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o86obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o
87obj-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o
88obj-$(CONFIG_USB_MAX3421_HCD) += max3421-hcd.o87obj-$(CONFIG_USB_MAX3421_HCD) += max3421-hcd.o
89obj-$(CONFIG_USB_XEN_HCD) += xen-hcd.o88obj-$(CONFIG_USB_XEN_HCD) += xen-hcd.o
drivers/usb/host/ehci-grlib.c+1−1
@@ -99,7 +99,7 @@ static int ehci_hcd_grlib_probe(struct platform_device *op) · 98 unmodified lines
99 hcd->rsrc_len = resource_size(&res);99 hcd->rsrc_len = resource_size(&res);
100 100
101 irq = irq_of_parse_and_map(dn, 0);101 irq = irq_of_parse_and_map(dn, 0);
102 if (irq == NO_IRQ) {102 if (!irq) {
103 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",103 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
104 __FILE__);104 __FILE__);
105 rv = -EBUSY;105 rv = -EBUSY;
drivers/usb/host/ehci-pci.c+4−3
@@ -411,11 +411,12 @@ static struct pci_driver ehci_pci_driver = { · 410 unmodified lines
411 .remove = ehci_pci_remove,411 .remove = ehci_pci_remove,
412 .shutdown = usb_hcd_pci_shutdown,412 .shutdown = usb_hcd_pci_shutdown,
413 413
414#ifdef CONFIG_PM
415 .driver = {414 .driver = {
416 .pm = &usb_hcd_pci_pm_ops415#ifdef CONFIG_PM
417 },416 .pm = &usb_hcd_pci_pm_ops,
418#endif417#endif
418 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
419 },
419};420};
420 421
421static int __init ehci_pci_init(void)422static int __init ehci_pci_init(void)
drivers/usb/host/ehci-ppc-of.c+1−1
@@ -119,7 +119,7 @@ static int ehci_hcd_ppc_of_probe(struct platform_device *op) · 118 unmodified lines
119 hcd->rsrc_len = resource_size(&res);119 hcd->rsrc_len = resource_size(&res);
120 120
121 irq = irq_of_parse_and_map(dn, 0);121 irq = irq_of_parse_and_map(dn, 0);
122 if (irq == NO_IRQ) {122 if (!irq) {
123 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",123 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
124 __FILE__);124 __FILE__);
125 rv = -EBUSY;125 rv = -EBUSY;
drivers/usb/host/ehci.h+1−1
@@ -471,7 +471,7 @@ struct ehci_iso_sched { · 470 unmodified lines
471 * acts like a qh would, if EHCI had them for ISO.471 * acts like a qh would, if EHCI had them for ISO.
472 */472 */
473struct ehci_iso_stream {473struct ehci_iso_stream {
474 /* first field matches ehci_hq, but is NULL */474 /* first field matches ehci_qh, but is NULL */
475 struct ehci_qh_hw *hw;475 struct ehci_qh_hw *hw;
476 476
477 u8 bEndpointAddress;477 u8 bEndpointAddress;
drivers/usb/host/fhci-hcd.c+1−1
@@ -676,7 +676,7 @@ static int of_fhci_probe(struct platform_device *ofdev) · 675 unmodified lines
676 676
677 /* USB Host interrupt. */677 /* USB Host interrupt. */
678 usb_irq = irq_of_parse_and_map(node, 0);678 usb_irq = irq_of_parse_and_map(node, 0);
679 if (usb_irq == NO_IRQ) {679 if (!usb_irq) {
680 dev_err(dev, "could not get usb irq\n");680 dev_err(dev, "could not get usb irq\n");
681 ret = -EINVAL;681 ret = -EINVAL;
682 goto err_usb_irq;682 goto err_usb_irq;
drivers/usb/host/ohci-ppc-of.c+1−1
@@ -120,7 +120,7 @@ static int ohci_hcd_ppc_of_probe(struct platform_device *op) · 119 unmodified lines
120 }120 }
121 121
122 irq = irq_of_parse_and_map(dn, 0);122 irq = irq_of_parse_and_map(dn, 0);
123 if (irq == NO_IRQ) {123 if (!irq) {
124 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",124 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
125 __FILE__);125 __FILE__);
126 rv = -EBUSY;126 rv = -EBUSY;
drivers/usb/host/uhci-grlib.c+1−1
@@ -116,7 +116,7 @@ static int uhci_hcd_grlib_probe(struct platform_device *op) · 115 unmodified lines
116 hcd->rsrc_len = resource_size(&res);116 hcd->rsrc_len = resource_size(&res);
117 117
118 irq = irq_of_parse_and_map(dn, 0);118 irq = irq_of_parse_and_map(dn, 0);
119 if (irq == NO_IRQ) {119 if (!irq) {
120 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);120 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
121 rv = -EBUSY;121 rv = -EBUSY;
122 goto err_usb;122 goto err_usb;
drivers/usb/host/xhci-hub.c+18−4
@@ -426,24 +426,37 @@ static unsigned int xhci_port_speed(unsigned int port_status) · 425 unmodified lines
426 */426 */
427#define XHCI_PORT_RZ ((1<<2) | (1<<24) | (0xf<<28))427#define XHCI_PORT_RZ ((1<<2) | (1<<24) | (0xf<<28))
428 428
429/*429/**
430 * xhci_port_state_to_neutral() - Clean up read portsc value back into writeable
431 * @state: u32 port value read from portsc register to be cleanup up
432 *
430 * Given a port state, this function returns a value that would result in the433 * Given a port state, this function returns a value that would result in the
431 * port being in the same state, if the value was written to the port status434 * port being in the same state, if the value was written to the port status
432 * control register.435 * control register.
433 * Save Read Only (RO) bits and save read/write bits where436 * Save Read Only (RO) bits and save read/write bits where
434 * writing a 0 clears the bit and writing a 1 sets the bit (RWS).437 * writing a 0 clears the bit and writing a 1 sets the bit (RWS).
435 * For all other types (RW1S, RW1CS, RW, and RZ), writing a '0' has no effect.438 * For all other types (RW1S, RW1CS, RW, and RZ), writing a '0' has no effect.
439 *
440 * Return: u32 value that can be written back to portsc register without
441 * changing port state.
436 */442 */
443
437u32 xhci_port_state_to_neutral(u32 state)444u32 xhci_port_state_to_neutral(u32 state)
438{445{
439 /* Save read-only status and port state */446 /* Save read-only status and port state */
440 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS);447 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS);
441}448}
449EXPORT_SYMBOL_GPL(xhci_port_state_to_neutral);
442 450
443/*451/**
444 * find slot id based on port number.452 * xhci_find_slot_id_by_port() - Find slot id of a usb device on a roothub port
445 * @port: The one-based port number from one of the two split roothubs.453 * @hcd: pointer to hcd of the roothub
454 * @xhci: pointer to xhci structure
455 * @port: one-based port number of the port in this roothub.
456 *
457 * Return: Slot id of the usb device connected to the root port, 0 if not found
446 */458 */
459
447int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,460int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
448 u16 port)461 u16 port)
449{462{
@@ -465,6 +478,7 @@ int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, · 15 unmodified lines
465 478
466 return slot_id;479 return slot_id;
467}480}
481EXPORT_SYMBOL_GPL(xhci_find_slot_id_by_port);
468 482
469/*483/*
470 * Stop device484 * Stop device
drivers/usb/host/xhci-mtk.c+46−27
@@ -485,6 +485,7 @@ static int xhci_mtk_probe(struct platform_device *pdev) · 484 unmodified lines
485 const struct hc_driver *driver;485 const struct hc_driver *driver;
486 struct xhci_hcd *xhci;486 struct xhci_hcd *xhci;
487 struct resource *res;487 struct resource *res;
488 struct usb_hcd *usb3_hcd;
488 struct usb_hcd *hcd;489 struct usb_hcd *hcd;
489 int ret = -ENODEV;490 int ret = -ENODEV;
490 int wakeup_irq;491 int wakeup_irq;
@@ -593,6 +594,7 @@ static int xhci_mtk_probe(struct platform_device *pdev) · 102 unmodified lines
593 594
594 xhci = hcd_to_xhci(hcd);595 xhci = hcd_to_xhci(hcd);
595 xhci->main_hcd = hcd;596 xhci->main_hcd = hcd;
597 xhci->allow_single_roothub = 1;
596 598
597 /*599 /*
598 * imod_interval is the interrupt moderation value in nanoseconds.600 * imod_interval is the interrupt moderation value in nanoseconds.
@@ -602,24 +604,29 @@ static int xhci_mtk_probe(struct platform_device *pdev) · 3 unmodified lines
602 xhci->imod_interval = 5000;604 xhci->imod_interval = 5000;
603 device_property_read_u32(dev, "imod-interval-ns", &xhci->imod_interval);605 device_property_read_u32(dev, "imod-interval-ns", &xhci->imod_interval);
604 606
605 xhci->shared_hcd = usb_create_shared_hcd(driver, dev,
606 dev_name(dev), hcd);
607 if (!xhci->shared_hcd) {
608 ret = -ENOMEM;
609 goto disable_device_wakeup;
610 }
611
612 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);607 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
613 if (ret)608 if (ret)
614 goto put_usb3_hcd;609 goto disable_device_wakeup;
615 610
616 if (HCC_MAX_PSA(xhci->hcc_params) >= 4 &&611 if (!xhci_has_one_roothub(xhci)) {
612 xhci->shared_hcd = usb_create_shared_hcd(driver, dev,
613 dev_name(dev), hcd);
614 if (!xhci->shared_hcd) {
615 ret = -ENOMEM;
616 goto dealloc_usb2_hcd;
617 }
618 }
619
620 usb3_hcd = xhci_get_usb3_hcd(xhci);
621 if (usb3_hcd && HCC_MAX_PSA(xhci->hcc_params) >= 4 &&
617 !(xhci->quirks & XHCI_BROKEN_STREAMS))622 !(xhci->quirks & XHCI_BROKEN_STREAMS))
618 xhci->shared_hcd->can_do_streams = 1;623 usb3_hcd->can_do_streams = 1;
619 624
620 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);625 if (xhci->shared_hcd) {
621 if (ret)626 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
622 goto dealloc_usb2_hcd;627 if (ret)
628 goto put_usb3_hcd;
629 }
623 630
624 if (wakeup_irq > 0) {631 if (wakeup_irq > 0) {
625 ret = dev_pm_set_dedicated_wake_irq_reverse(dev, wakeup_irq);632 ret = dev_pm_set_dedicated_wake_irq_reverse(dev, wakeup_irq);
@@ -639,15 +646,14 @@ static int xhci_mtk_probe(struct platform_device *pdev) · 13 unmodified lines
639 646
640dealloc_usb3_hcd:647dealloc_usb3_hcd:
641 usb_remove_hcd(xhci->shared_hcd);648 usb_remove_hcd(xhci->shared_hcd);
642 xhci->shared_hcd = NULL;
643
644dealloc_usb2_hcd:
645 usb_remove_hcd(hcd);
646 649
647put_usb3_hcd:650put_usb3_hcd:
648 xhci_mtk_sch_exit(mtk);
649 usb_put_hcd(xhci->shared_hcd);651 usb_put_hcd(xhci->shared_hcd);
650 652
653dealloc_usb2_hcd:
654 xhci_mtk_sch_exit(mtk);
655 usb_remove_hcd(hcd);
656
651disable_device_wakeup:657disable_device_wakeup:
652 device_init_wakeup(dev, false);658 device_init_wakeup(dev, false);
653 659
@@ -679,10 +685,15 @@ static int xhci_mtk_remove(struct platform_device *pdev) · 25 unmodified lines
679 dev_pm_clear_wake_irq(dev);685 dev_pm_clear_wake_irq(dev);
680 device_init_wakeup(dev, false);686 device_init_wakeup(dev, false);
681 687
682 usb_remove_hcd(shared_hcd);688 if (shared_hcd) {
683 xhci->shared_hcd = NULL;689 usb_remove_hcd(shared_hcd);
690 xhci->shared_hcd = NULL;
691 }
684 usb_remove_hcd(hcd);692 usb_remove_hcd(hcd);
685 usb_put_hcd(shared_hcd);693
694 if (shared_hcd)
695 usb_put_hcd(shared_hcd);
696
686 usb_put_hcd(hcd);697 usb_put_hcd(hcd);
687 xhci_mtk_sch_exit(mtk);698 xhci_mtk_sch_exit(mtk);
688 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks);699 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks);
@@ -700,13 +711,16 @@ static int __maybe_unused xhci_mtk_suspend(struct device *dev) · 11 unmodified lines
700 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);711 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
701 struct usb_hcd *hcd = mtk->hcd;712 struct usb_hcd *hcd = mtk->hcd;
702 struct xhci_hcd *xhci = hcd_to_xhci(hcd);713 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
714 struct usb_hcd *shared_hcd = xhci->shared_hcd;
703 int ret;715 int ret;
704 716
705 xhci_dbg(xhci, "%s: stop port polling\n", __func__);717 xhci_dbg(xhci, "%s: stop port polling\n", __func__);
706 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);718 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
707 del_timer_sync(&hcd->rh_timer);719 del_timer_sync(&hcd->rh_timer);
708 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);720 if (shared_hcd) {
709 del_timer_sync(&xhci->shared_hcd->rh_timer);721 clear_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags);
722 del_timer_sync(&shared_hcd->rh_timer);
723 }
710 724
711 ret = xhci_mtk_host_disable(mtk);725 ret = xhci_mtk_host_disable(mtk);
712 if (ret)726 if (ret)
@@ -718,8 +732,10 @@ static int __maybe_unused xhci_mtk_suspend(struct device *dev) · 5 unmodified lines
718 732
719restart_poll_rh:733restart_poll_rh:
720 xhci_dbg(xhci, "%s: restart port polling\n", __func__);734 xhci_dbg(xhci, "%s: restart port polling\n", __func__);
721 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);735 if (shared_hcd) {
722 usb_hcd_poll_rh_status(xhci->shared_hcd);736 set_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags);
737 usb_hcd_poll_rh_status(shared_hcd);
738 }
723 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);739 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
724 usb_hcd_poll_rh_status(hcd);740 usb_hcd_poll_rh_status(hcd);
725 return ret;741 return ret;
@@ -730,6 +746,7 @@ static int __maybe_unused xhci_mtk_resume(struct device *dev) · 4 unmodified lines
730 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);746 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
731 struct usb_hcd *hcd = mtk->hcd;747 struct usb_hcd *hcd = mtk->hcd;
732 struct xhci_hcd *xhci = hcd_to_xhci(hcd);748 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
749 struct usb_hcd *shared_hcd = xhci->shared_hcd;
733 int ret;750 int ret;
734 751
735 usb_wakeup_set(mtk, false);752 usb_wakeup_set(mtk, false);
@@ -742,8 +759,10 @@ static int __maybe_unused xhci_mtk_resume(struct device *dev) · 6 unmodified lines
742 goto disable_clks;759 goto disable_clks;
743 760
744 xhci_dbg(xhci, "%s: restart port polling\n", __func__);761 xhci_dbg(xhci, "%s: restart port polling\n", __func__);
745 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);762 if (shared_hcd) {
746 usb_hcd_poll_rh_status(xhci->shared_hcd);763 set_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags);
764 usb_hcd_poll_rh_status(shared_hcd);
765 }
747 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);766 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
748 usb_hcd_poll_rh_status(hcd);767 usb_hcd_poll_rh_status(hcd);
749 return 0;768 return 0;
drivers/usb/host/xhci-pci.c+59−4
@@ -59,6 +59,7 @@ · 58 unmodified lines
59#define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a1359#define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13
60#define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x113860#define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x1138
61#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed61#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed
62#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI 0x54ed
62 63
63#define PCI_DEVICE_ID_AMD_RENOIR_XHCI 0x163964#define PCI_DEVICE_ID_AMD_RENOIR_XHCI 0x1639
64#define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b965#define PCI_DEVICE_ID_AMD_PROMONTORYA_4 0x43b9
@@ -246,7 +247,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) · 181 unmodified lines
246 xhci->quirks |= XHCI_MISSING_CAS;247 xhci->quirks |= XHCI_MISSING_CAS;
247 248
248 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&249 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
249 pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI)250 (pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI ||
251 pdev->device == PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI))
250 xhci->quirks |= XHCI_RESET_TO_DEFAULT;252 xhci->quirks |= XHCI_RESET_TO_DEFAULT;
251 253
252 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&254 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
@@ -620,6 +622,57 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) · 367 unmodified lines
620 return retval;622 return retval;
621}623}
622 624
625static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup)
626{
627 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
628 struct xhci_port *port;
629 struct usb_device *udev;
630 unsigned int slot_id;
631 u32 portsc;
632 int i;
633
634 /*
635 * Systems with XHCI_RESET_TO_DEFAULT quirk have boot firmware that
636 * cause significant boot delay if usb ports are in suspended U3 state
637 * during boot. Some USB devices survive in U3 state over S4 hibernate
638 *
639 * Disable ports that are in U3 if remote wake is not enabled for either
640 * host controller or connected device
641 */
642
643 if (!(xhci->quirks & XHCI_RESET_TO_DEFAULT))
644 return 0;
645
646 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
647 port = &xhci->hw_ports[i];
648 portsc = readl(port->addr);
649
650 if ((portsc & PORT_PLS_MASK) != XDEV_U3)
651 continue;
652
653 slot_id = xhci_find_slot_id_by_port(port->rhub->hcd, xhci,
654 port->hcd_portnum + 1);
655 if (!slot_id || !xhci->devs[slot_id]) {
656 xhci_err(xhci, "No dev for slot_id %d for port %d-%d in U3\n",
657 slot_id, port->rhub->hcd->self.busnum, port->hcd_portnum + 1);
658 continue;
659 }
660
661 udev = xhci->devs[slot_id]->udev;
662
663 /* if wakeup is enabled then don't disable the port */
664 if (udev->do_remote_wakeup && do_wakeup)
665 continue;
666
667 xhci_dbg(xhci, "port %d-%d in U3 without wakeup, disable it\n",
668 port->rhub->hcd->self.busnum, port->hcd_portnum + 1);
669 portsc = xhci_port_state_to_neutral(portsc);
670 writel(portsc | PORT_PE, port->addr);
671 }
672
673 return 0;
674}
675
623static void xhci_pci_shutdown(struct usb_hcd *hcd)676static void xhci_pci_shutdown(struct usb_hcd *hcd)
624{677{
625 struct xhci_hcd *xhci = hcd_to_xhci(hcd);678 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
@@ -673,11 +726,12 @@ static struct pci_driver xhci_pci_driver = { · 47 unmodified lines
673 /* suspend and resume implemented later */726 /* suspend and resume implemented later */
674 727
675 .shutdown = usb_hcd_pci_shutdown,728 .shutdown = usb_hcd_pci_shutdown,
676#ifdef CONFIG_PM
677 .driver = {729 .driver = {
678 .pm = &usb_hcd_pci_pm_ops730#ifdef CONFIG_PM
679 },731 .pm = &usb_hcd_pci_pm_ops,
680#endif732#endif
733 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
734 },
681};735};
682 736
683static int __init xhci_pci_init(void)737static int __init xhci_pci_init(void)
@@ -686,6 +740,7 @@ static int __init xhci_pci_init(void) · 2 unmodified lines
686#ifdef CONFIG_PM740#ifdef CONFIG_PM
687 xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend;741 xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend;
688 xhci_pci_hc_driver.pci_resume = xhci_pci_resume;742 xhci_pci_hc_driver.pci_resume = xhci_pci_resume;
743 xhci_pci_hc_driver.pci_poweroff_late = xhci_pci_poweroff_late;
689 xhci_pci_hc_driver.shutdown = xhci_pci_shutdown;744 xhci_pci_hc_driver.shutdown = xhci_pci_shutdown;
690#endif745#endif
691 return pci_register_driver(&xhci_pci_driver);746 return pci_register_driver(&xhci_pci_driver);
drivers/usb/host/xhci-ring.c+23−19
@@ -896,7 +896,7 @@ done: · 895 unmodified lines
896}896}
897 897
898static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci,898static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci,
899 struct xhci_virt_ep *ep, unsigned int stream_id,899 struct xhci_virt_ep *ep,
900 struct xhci_td *td,900 struct xhci_td *td,
901 enum xhci_ep_reset_type reset_type)901 enum xhci_ep_reset_type reset_type)
902{902{
@@ -1110,8 +1110,7 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, · 207 unmodified lines
1110 td->status = -EPROTO;1110 td->status = -EPROTO;
1111 }1111 }
1112 /* reset ep, reset handler cleans up cancelled tds */1112 /* reset ep, reset handler cleans up cancelled tds */
1113 err = xhci_handle_halted_endpoint(xhci, ep, 0, td,1113 err = xhci_handle_halted_endpoint(xhci, ep, td, reset_type);
1114 reset_type);
1115 if (err)1114 if (err)
1116 break;1115 break;
1117 ep->ep_state &= ~EP_STOP_CMD_PENDING;1116 ep->ep_state &= ~EP_STOP_CMD_PENDING;
@@ -2183,8 +2182,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 1065 unmodified lines
2183 }2182 }
2184 /* Almost same procedure as for STALL_ERROR below */2183 /* Almost same procedure as for STALL_ERROR below */
2185 xhci_clear_hub_tt_buffer(xhci, td, ep);2184 xhci_clear_hub_tt_buffer(xhci, td, ep);
2186 xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,2185 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET);
2187 EP_HARD_RESET);
2188 return 0;2186 return 0;
2189 case COMP_STALL_ERROR:2187 case COMP_STALL_ERROR:
2190 /*2188 /*
@@ -2200,8 +2198,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 9 unmodified lines
2200 if (ep->ep_index != 0)2198 if (ep->ep_index != 0)
2201 xhci_clear_hub_tt_buffer(xhci, td, ep);2199 xhci_clear_hub_tt_buffer(xhci, td, ep);
2202 2200
2203 xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,2201 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET);
2204 EP_HARD_RESET);
2205 2202
2206 return 0; /* xhci_handle_halted_endpoint marked td cancelled */2203 return 0; /* xhci_handle_halted_endpoint marked td cancelled */
2207 default:2204 default:
@@ -2458,7 +2455,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 250 unmodified lines
2458 2455
2459 switch (trb_comp_code) {2456 switch (trb_comp_code) {
2460 case COMP_SUCCESS:2457 case COMP_SUCCESS:
2461 ep_ring->err_count = 0;2458 ep->err_count = 0;
2462 /* handle success with untransferred data as short packet */2459 /* handle success with untransferred data as short packet */
2463 if (ep_trb != td->last_trb || remaining) {2460 if (ep_trb != td->last_trb || remaining) {
2464 xhci_warn(xhci, "WARN Successful completion on short TX\n");2461 xhci_warn(xhci, "WARN Successful completion on short TX\n");
@@ -2484,14 +2481,13 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 19 unmodified lines
2484 break;2481 break;
2485 case COMP_USB_TRANSACTION_ERROR:2482 case COMP_USB_TRANSACTION_ERROR:
2486 if (xhci->quirks & XHCI_NO_SOFT_RETRY ||2483 if (xhci->quirks & XHCI_NO_SOFT_RETRY ||
2487 (ep_ring->err_count++ > MAX_SOFT_RETRY) ||2484 (ep->err_count++ > MAX_SOFT_RETRY) ||
2488 le32_to_cpu(slot_ctx->tt_info) & TT_SLOT)2485 le32_to_cpu(slot_ctx->tt_info) & TT_SLOT)
2489 break;2486 break;
2490 2487
2491 td->status = 0;2488 td->status = 0;
2492 2489
2493 xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,2490 xhci_handle_halted_endpoint(xhci, ep, td, EP_SOFT_RESET);
2494 EP_SOFT_RESET);
2495 return 0;2491 return 0;
2496 default:2492 default:
2497 /* do nothing */2493 /* do nothing */
@@ -2565,8 +2561,14 @@ static int handle_tx_event(struct xhci_hcd *xhci, · 67 unmodified lines
2565 case COMP_USB_TRANSACTION_ERROR:2561 case COMP_USB_TRANSACTION_ERROR:
2566 case COMP_INVALID_STREAM_TYPE_ERROR:2562 case COMP_INVALID_STREAM_TYPE_ERROR:
2567 case COMP_INVALID_STREAM_ID_ERROR:2563 case COMP_INVALID_STREAM_ID_ERROR:
2568 xhci_handle_halted_endpoint(xhci, ep, 0, NULL,2564 xhci_dbg(xhci, "Stream transaction error ep %u no id\n",
2569 EP_SOFT_RESET);2565 ep_index);
2566 if (ep->err_count++ > MAX_SOFT_RETRY)
2567 xhci_handle_halted_endpoint(xhci, ep, NULL,
2568 EP_HARD_RESET);
2569 else
2570 xhci_handle_halted_endpoint(xhci, ep, NULL,
2571 EP_SOFT_RESET);
2570 goto cleanup;2572 goto cleanup;
2571 case COMP_RING_UNDERRUN:2573 case COMP_RING_UNDERRUN:
2572 case COMP_RING_OVERRUN:2574 case COMP_RING_OVERRUN:
@@ -2749,9 +2751,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, · 176 unmodified lines
2749 if (trb_comp_code == COMP_STALL_ERROR ||2751 if (trb_comp_code == COMP_STALL_ERROR ||
2750 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,2752 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
2751 trb_comp_code)) {2753 trb_comp_code)) {
2752 xhci_handle_halted_endpoint(xhci, ep,2754 xhci_handle_halted_endpoint(xhci, ep, NULL,
2753 ep_ring->stream_id,
2754 NULL,
2755 EP_HARD_RESET);2755 EP_HARD_RESET);
2756 }2756 }
2757 goto cleanup;2757 goto cleanup;
@@ -2844,9 +2844,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, · 86 unmodified lines
2844 if (trb_comp_code == COMP_STALL_ERROR ||2844 if (trb_comp_code == COMP_STALL_ERROR ||
2845 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,2845 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
2846 trb_comp_code))2846 trb_comp_code))
2847 xhci_handle_halted_endpoint(xhci, ep,2847 xhci_handle_halted_endpoint(xhci, ep, td,
2848 ep_ring->stream_id,2848 EP_HARD_RESET);
2849 td, EP_HARD_RESET);
2850 goto cleanup;2849 goto cleanup;
2851 }2850 }
2852 2851
@@ -3031,6 +3030,11 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) · 178 unmodified lines
3031 if (!(status & STS_EINT))3030 if (!(status & STS_EINT))
3032 goto out;3031 goto out;
3033 3032
3033 if (status & STS_HCE) {
3034 xhci_warn(xhci, "WARNING: Host Controller Error\n");
3035 goto out;
3036 }
3037
3034 if (status & STS_FATAL) {3038 if (status & STS_FATAL) {
3035 xhci_warn(xhci, "WARNING: Host System Error\n");3039 xhci_warn(xhci, "WARNING: Host System Error\n");
3036 xhci_halt(xhci);3040 xhci_halt(xhci);
drivers/usb/host/xhci.h+1−1
@@ -933,6 +933,7 @@ struct xhci_virt_ep { · 932 unmodified lines
933 * have to restore the device state to the previous state933 * have to restore the device state to the previous state
934 */934 */
935 struct xhci_ring *new_ring;935 struct xhci_ring *new_ring;
936 unsigned int err_count;
936 unsigned int ep_state;937 unsigned int ep_state;
937#define SET_DEQ_PENDING (1 << 0)938#define SET_DEQ_PENDING (1 << 0)
938#define EP_HALTED (1 << 1) /* For stall handling */939#define EP_HALTED (1 << 1) /* For stall handling */
@@ -1627,7 +1628,6 @@ struct xhci_ring { · 688 unmodified lines
1627 * if we own the TRB (if we are the consumer). See section 4.9.1.1628 * if we own the TRB (if we are the consumer). See section 4.9.1.
1628 */1629 */
1629 u32 cycle_state;1630 u32 cycle_state;
1630 unsigned int err_count;
1631 unsigned int stream_id;1631 unsigned int stream_id;
1632 unsigned int num_segs;1632 unsigned int num_segs;
1633 unsigned int num_trbs_free;1633 unsigned int num_trbs_free;
drivers/usb/misc/Kconfig+1−1
@@ -298,7 +298,7 @@ config BRCM_USB_PINMAP · 297 unmodified lines
298 298
299config USB_ONBOARD_HUB299config USB_ONBOARD_HUB
300 tristate "Onboard USB hub support"300 tristate "Onboard USB hub support"
301 depends on OF || COMPILE_TEST301 depends on OF
302 help302 help
303 Say Y here if you want to support discrete onboard USB hubs that303 Say Y here if you want to support discrete onboard USB hubs that
304 don't require an additional control bus for initialization, but304 don't require an additional control bus for initialization, but
drivers/usb/misc/ftdi-elan.c+0−4
@@ -1624,7 +1624,6 @@ wait:if (ftdi->disconnected > 0) { · 1623 unmodified lines
1624 char data[30 *3 + 4];1624 char data[30 *3 + 4];
1625 char *d = data;1625 char *d = data;
1626 int m = (sizeof(data) - 1) / 3 - 1;1626 int m = (sizeof(data) - 1) / 3 - 1;
1627 int l = 0;
1628 struct u132_target *target = &ftdi->target[ed];1627 struct u132_target *target = &ftdi->target[ed];
1629 struct u132_command *command = &ftdi->command[1628 struct u132_command *command = &ftdi->command[
1630 COMMAND_MASK & ftdi->command_next];1629 COMMAND_MASK & ftdi->command_next];
@@ -1647,7 +1646,6 @@ wait:if (ftdi->disconnected > 0) { · 16 unmodified lines
1647 } else if (i++ < m) {1646 } else if (i++ < m) {
1648 int w = sprintf(d, " %02X", *b++);1647 int w = sprintf(d, " %02X", *b++);
1649 d += w;1648 d += w;
1650 l += w;
1651 } else1649 } else
1652 d += sprintf(d, " ..");1650 d += sprintf(d, " ..");
1653 }1651 }
@@ -1956,7 +1954,6 @@ static int ftdi_elan_synchronize(struct usb_ftdi *ftdi) · 302 unmodified lines
1956 int long_stop = 10;1954 int long_stop = 10;
1957 int retry_on_timeout = 5;1955 int retry_on_timeout = 5;
1958 int retry_on_empty = 10;1956 int retry_on_empty = 10;
1959 int err_count = 0;
1960 retval = ftdi_elan_flush_input_fifo(ftdi);1957 retval = ftdi_elan_flush_input_fifo(ftdi);
1961 if (retval)1958 if (retval)
1962 return retval;1959 return retval;
@@ -2051,7 +2048,6 @@ static int ftdi_elan_synchronize(struct usb_ftdi *ftdi) · 88 unmodified lines
2051 continue;2048 continue;
2052 }2049 }
2053 } else {2050 } else {
2054 err_count += 1;
2055 dev_err(&ftdi->udev->dev, "error = %d\n",2051 dev_err(&ftdi->udev->dev, "error = %d\n",
2056 retval);2052 retval);
2057 if (read_stop-- > 0) {2053 if (read_stop-- > 0) {
drivers/usb/misc/onboard_usb_hub.c+2−0
@@ -331,6 +331,7 @@ static struct platform_driver onboard_hub_driver = { · 330 unmodified lines
331 331
332/************************** USB driver **************************/332/************************** USB driver **************************/
333 333
334#define VENDOR_ID_GENESYS 0x05e3
334#define VENDOR_ID_MICROCHIP 0x0424335#define VENDOR_ID_MICROCHIP 0x0424
335#define VENDOR_ID_REALTEK 0x0bda336#define VENDOR_ID_REALTEK 0x0bda
336#define VENDOR_ID_TI 0x0451337#define VENDOR_ID_TI 0x0451
@@ -407,6 +408,7 @@ static void onboard_hub_usbdev_disconnect(struct usb_device *udev) · 70 unmodified lines
407}408}
408 409
409static const struct usb_device_id onboard_hub_id_table[] = {410static const struct usb_device_id onboard_hub_id_table[] = {
411 { USB_DEVICE(VENDOR_ID_GENESYS, 0x0608) }, /* Genesys Logic GL850G USB 2.0 */
410 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 */412 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 */
411 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 */413 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 */
412 { USB_DEVICE(VENDOR_ID_REALTEK, 0x5411) }, /* RTS5411 USB 2.1 */414 { USB_DEVICE(VENDOR_ID_REALTEK, 0x5411) }, /* RTS5411 USB 2.1 */
drivers/usb/misc/onboard_usb_hub.h+5−0
@@ -22,10 +22,15 @@ static const struct onboard_hub_pdata ti_tusb8041_data = { · 21 unmodified lines
22 .reset_us = 3000,22 .reset_us = 3000,
23};23};
24 24
25static const struct onboard_hub_pdata genesys_gl850g_data = {
26 .reset_us = 3,
27};
28
25static const struct of_device_id onboard_hub_match[] = {29static const struct of_device_id onboard_hub_match[] = {
26 { .compatible = "usb424,2514", .data = &microchip_usb424_data, },30 { .compatible = "usb424,2514", .data = &microchip_usb424_data, },
27 { .compatible = "usb451,8140", .data = &ti_tusb8041_data, },31 { .compatible = "usb451,8140", .data = &ti_tusb8041_data, },
28 { .compatible = "usb451,8142", .data = &ti_tusb8041_data, },32 { .compatible = "usb451,8142", .data = &ti_tusb8041_data, },
33 { .compatible = "usb5e3,608", .data = &genesys_gl850g_data, },
29 { .compatible = "usbbda,411", .data = &realtek_rts5411_data, },34 { .compatible = "usbbda,411", .data = &realtek_rts5411_data, },
30 { .compatible = "usbbda,5411", .data = &realtek_rts5411_data, },35 { .compatible = "usbbda,5411", .data = &realtek_rts5411_data, },
31 { .compatible = "usbbda,414", .data = &realtek_rts5411_data, },36 { .compatible = "usbbda,414", .data = &realtek_rts5411_data, },
drivers/usb/misc/sisusbvga/Kconfig+0−34
@@ -3,7 +3,6 @@ · 2 unmodified lines
3config USB_SISUSBVGA3config USB_SISUSBVGA
4 tristate "USB 2.0 SVGA dongle support (Net2280/SiS315)"4 tristate "USB 2.0 SVGA dongle support (Net2280/SiS315)"
5 depends on (USB_MUSB_HDRC || USB_EHCI_HCD)5 depends on (USB_MUSB_HDRC || USB_EHCI_HCD)
6 select FONT_SUPPORT if USB_SISUSBVGA_CON
7 help6 help
8 Say Y here if you intend to attach a USB2VGA dongle based on a7 Say Y here if you intend to attach a USB2VGA dongle based on a
9 Net2280 and a SiS315 chip.8 Net2280 and a SiS315 chip.
@@ -13,36 +12,3 @@ config USB_SISUSBVGA · 3 unmodified lines
13 12
14 To compile this driver as a module, choose M here; the module will be13 To compile this driver as a module, choose M here; the module will be
15 called sisusbvga. If unsure, say N.14 called sisusbvga. If unsure, say N.
16
17config USB_SISUSBVGA_CON
18 bool "Text console and mode switching support" if USB_SISUSBVGA
19 depends on VT && BROKEN
20 select FONT_8x16
21 help
22 Say Y here if you want a VGA text console via the USB dongle or
23 want to support userland applications that utilize the driver's
24 display mode switching capabilities.
25
26 Note that this console supports VGA/EGA text mode only.
27
28 By default, the console part of the driver will not kick in when
29 the driver is initialized. If you want the driver to take over
30 one or more of the consoles, you need to specify the number of
31 the first and last consoles (starting at 1) as driver parameters.
32
33 For example, if the driver is compiled as a module:
34
35 modprobe sisusbvga first=1 last=5
36
37 If you use hotplug, add this to your modutils config files with
38 the "options" keyword, such as eg.
39
40 options sisusbvga first=1 last=5
41
42 If the driver is compiled into the kernel image, the parameters
43 must be given in the kernel command like, such as
44
45 sisusbvga.first=1 sisusbvga.last=5
46
47
48
drivers/usb/misc/sisusbvga/Makefile+0−3
@@ -4,6 +4,3 @@ · 3 unmodified lines
4#4#
5 5
6obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga.o6obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga.o
7
8sisusbvga-y := sisusb.o
9sisusbvga-$(CONFIG_USB_SISUSBVGA_CON) += sisusb_con.o sisusb_init.o
drivers/usb/misc/sisusbvga/sisusb.h+0−21
@@ -48,7 +48,6 @@ · 47 unmodified lines
48 48
49/* Include console and mode switching code? */49/* Include console and mode switching code? */
50 50
51#include <linux/console.h>
52#include <linux/vt_kern.h>51#include <linux/vt_kern.h>
53#include "sisusb_struct.h"52#include "sisusb_struct.h"
54 53
@@ -126,26 +125,6 @@ struct sisusb_usb_data { · 71 unmodified lines
126 unsigned char gfxinit; /* graphics core initialized? */125 unsigned char gfxinit; /* graphics core initialized? */
127 unsigned short chipid, chipvendor;126 unsigned short chipid, chipvendor;
128 unsigned short chiprevision;127 unsigned short chiprevision;
129#ifdef CONFIG_USB_SISUSBVGA_CON
130 struct SiS_Private *SiS_Pr;
131 unsigned long scrbuf;
132 unsigned int scrbuf_size;
133 int haveconsole, con_first, con_last;
134 int havethisconsole[MAX_NR_CONSOLES];
135 int textmodedestroyed;
136 unsigned int sisusb_num_columns; /* real number, not vt's idea */
137 int cur_start_addr, con_rolled_over;
138 int sisusb_cursor_loc, bad_cursor_pos;
139 int sisusb_cursor_size_from;
140 int sisusb_cursor_size_to;
141 int current_font_height, current_font_512;
142 int font_backup_size, font_backup_height, font_backup_512;
143 char *font_backup;
144 int font_slot;
145 struct vc_data *sisusb_display_fg;
146 int is_gfx;
147 int con_blanked;
148#endif
149};128};
150 129
151#define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)130#define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)
drivers/usb/misc/sisusbvga/sisusb_con.c+0−1496
@@ -1,1496 +0,0 @@
1// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2/*
3 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
4 *
5 * VGA text mode console part
6 *
7 * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
8 *
9 * If distributed as part of the Linux kernel, this code is licensed under the
10 * terms of the GPL v2.
11 *
12 * Otherwise, the following license terms apply:
13 *
14 * * Redistribution and use in source and binary forms, with or without
15 * * modification, are permitted provided that the following conditions
16 * * are met:
17 * * 1) Redistributions of source code must retain the above copyright
18 * * notice, this list of conditions and the following disclaimer.
19 * * 2) Redistributions in binary form must reproduce the above copyright
20 * * notice, this list of conditions and the following disclaimer in the
21 * * documentation and/or other materials provided with the distribution.
22 * * 3) The name of the author may not be used to endorse or promote products
23 * * derived from this software without specific psisusbr written permission.
24 * *
25 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
26 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 * Author: Thomas Winischhofer <thomas@winischhofer.net>
37 *
38 * Portions based on vgacon.c which are
39 * Created 28 Sep 1997 by Geert Uytterhoeven
40 * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
41 * based on code Copyright (C) 1991, 1992 Linus Torvalds
42 * 1995 Jay Estabrook
43 *
44 * A note on using in_atomic() in here: We can't handle console
45 * calls from non-schedulable context due to our USB-dependend
46 * nature. For now, this driver just ignores any calls if it
47 * detects this state.
48 *
49 */
50
51#include <linux/mutex.h>
52#include <linux/module.h>
53#include <linux/kernel.h>
54#include <linux/signal.h>
55#include <linux/fs.h>
56#include <linux/usb.h>
57#include <linux/tty.h>
58#include <linux/console.h>
59#include <linux/string.h>
60#include <linux/kd.h>
61#include <linux/init.h>
62#include <linux/vt_kern.h>
63#include <linux/selection.h>
64#include <linux/spinlock.h>
65#include <linux/kref.h>
66#include <linux/ioport.h>
67#include <linux/interrupt.h>
68#include <linux/vmalloc.h>
69
70#include "sisusb.h"
71#include "sisusb_init.h"
72
73/* vc_data -> sisusb conversion table */
74static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
75
76/* Forward declaration */
77static const struct consw sisusb_con;
78
79static inline void
80sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
81{
82 memset16(s, c, count / 2);
83}
84
85static inline void
86sisusb_initialize(struct sisusb_usb_data *sisusb)
87{
88 /* Reset cursor and start address */
89 if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00))
90 return;
91 if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00))
92 return;
93 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00))
94 return;
95 sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00);
96}
97
98static inline void
99sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c)
100{
101 sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2;
102
103 sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
104 sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
105}
106
107void
108sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location)
109{
110 if (sisusb->sisusb_cursor_loc == location)
111 return;
112
113 sisusb->sisusb_cursor_loc = location;
114
115 /* Hardware bug: Text cursor appears twice or not at all
116 * at some positions. Work around it with the cursor skew
117 * bits.
118 */
119
120 if ((location & 0x0007) == 0x0007) {
121 sisusb->bad_cursor_pos = 1;
122 location--;
123 if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20))
124 return;
125 } else if (sisusb->bad_cursor_pos) {
126 if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f))
127 return;
128 sisusb->bad_cursor_pos = 0;
129 }
130
131 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8)))
132 return;
133 sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff));
134}
135
136static inline struct sisusb_usb_data *
137sisusb_get_sisusb(unsigned short console)
138{
139 return mysisusbs[console];
140}
141
142static inline int
143sisusb_sisusb_valid(struct sisusb_usb_data *sisusb)
144{
145 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev)
146 return 0;
147
148 return 1;
149}
150
151static struct sisusb_usb_data *
152sisusb_get_sisusb_lock_and_check(unsigned short console)
153{
154 struct sisusb_usb_data *sisusb;
155
156 /* We can't handle console calls in non-schedulable
157 * context due to our locks and the USB transport.
158 * So we simply ignore them. This should only affect
159 * some calls to printk.
160 */
161 if (in_atomic())
162 return NULL;
163
164 sisusb = sisusb_get_sisusb(console);
165 if (!sisusb)
166 return NULL;
167
168 mutex_lock(&sisusb->lock);
169
170 if (!sisusb_sisusb_valid(sisusb) ||
171 !sisusb->havethisconsole[console]) {
172 mutex_unlock(&sisusb->lock);
173 return NULL;
174 }
175
176 return sisusb;
177}
178
179static int
180sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb)
181{
182 if (sisusb->is_gfx ||
183 sisusb->textmodedestroyed ||
184 c->vc_mode != KD_TEXT)
185 return 1;
186
187 return 0;
188}
189
190/* con_startup console interface routine */
191static const char *
192sisusbcon_startup(void)
193{
194 return "SISUSBCON";
195}
196
197/* con_init console interface routine */
198static void
199sisusbcon_init(struct vc_data *c, int init)
200{
201 struct sisusb_usb_data *sisusb;
202 int cols, rows;
203
204 /* This is called by do_take_over_console(),
205 * ie by us/under our control. It is
206 * only called after text mode and fonts
207 * are set up/restored.
208 */
209
210 sisusb = sisusb_get_sisusb(c->vc_num);
211 if (!sisusb)
212 return;
213
214 mutex_lock(&sisusb->lock);
215
216 if (!sisusb_sisusb_valid(sisusb)) {
217 mutex_unlock(&sisusb->lock);
218 return;
219 }
220
221 c->vc_can_do_color = 1;
222
223 c->vc_complement_mask = 0x7700;
224
225 c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0;
226
227 sisusb->haveconsole = 1;
228
229 sisusb->havethisconsole[c->vc_num] = 1;
230
231 /* We only support 640x400 */
232 c->vc_scan_lines = 400;
233
234 c->vc_font.height = sisusb->current_font_height;
235
236 /* We only support width = 8 */
237 cols = 80;
238 rows = c->vc_scan_lines / c->vc_font.height;
239
240 /* Increment usage count for our sisusb.
241 * Doing so saves us from upping/downing
242 * the disconnect semaphore; we can't
243 * lose our sisusb until this is undone
244 * in con_deinit. For all other console
245 * interface functions, it suffices to
246 * use sisusb->lock and do a quick check
247 * of sisusb for device disconnection.
248 */
249 kref_get(&sisusb->kref);
250
251 if (!*c->uni_pagedict_loc)
252 con_set_default_unimap(c);
253
254 mutex_unlock(&sisusb->lock);
255
256 if (init) {
257 c->vc_cols = cols;
258 c->vc_rows = rows;
259 } else
260 vc_resize(c, cols, rows);
261}
262
263/* con_deinit console interface routine */
264static void
265sisusbcon_deinit(struct vc_data *c)
266{
267 struct sisusb_usb_data *sisusb;
268 int i;
269
270 /* This is called by do_take_over_console()
271 * and others, ie not under our control.
272 */
273
274 sisusb = sisusb_get_sisusb(c->vc_num);
275 if (!sisusb)
276 return;
277
278 mutex_lock(&sisusb->lock);
279
280 /* Clear ourselves in mysisusbs */
281 mysisusbs[c->vc_num] = NULL;
282
283 sisusb->havethisconsole[c->vc_num] = 0;
284
285 /* Free our font buffer if all consoles are gone */
286 if (sisusb->font_backup) {
287 for(i = 0; i < MAX_NR_CONSOLES; i++) {
288 if (sisusb->havethisconsole[c->vc_num])
289 break;
290 }
291 if (i == MAX_NR_CONSOLES) {
292 vfree(sisusb->font_backup);
293 sisusb->font_backup = NULL;
294 }
295 }
296
297 mutex_unlock(&sisusb->lock);
298
299 /* decrement the usage count on our sisusb */
300 kref_put(&sisusb->kref, sisusb_delete);
301}
302
303/* interface routine */
304static u8
305sisusbcon_build_attr(struct vc_data *c, u8 color, enum vc_intensity intensity,
306 bool blink, bool underline, bool reverse,
307 bool unused)
308{
309 u8 attr = color;
310
311 if (underline)
312 attr = (attr & 0xf0) | c->vc_ulcolor;
313 else if (intensity == VCI_HALF_BRIGHT)
314 attr = (attr & 0xf0) | c->vc_halfcolor;
315
316 if (reverse)
317 attr = ((attr) & 0x88) |
318 ((((attr) >> 4) |
319 ((attr) << 4)) & 0x77);
320
321 if (blink)
322 attr ^= 0x80;
323
324 if (intensity == VCI_BOLD)
325 attr ^= 0x08;
326
327 return attr;
328}
329
330/* Interface routine */
331static void
332sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count)
333{
334 /* Invert a region. This is called with a pointer
335 * to the console's internal screen buffer. So we
336 * simply do the inversion there and rely on
337 * a call to putc(s) to update the real screen.
338 */
339
340 while (count--) {
341 u16 a = *p;
342
343 *p++ = ((a) & 0x88ff) |
344 (((a) & 0x7000) >> 4) |
345 (((a) & 0x0700) << 4);
346 }
347}
348
349static inline void *sisusb_vaddr(const struct sisusb_usb_data *sisusb,
350 const struct vc_data *c, unsigned int x, unsigned int y)
351{
352 return (u16 *)c->vc_origin + y * sisusb->sisusb_num_columns + x;
353}
354
355static inline unsigned long sisusb_haddr(const struct sisusb_usb_data *sisusb,
356 const struct vc_data *c, unsigned int x, unsigned int y)
357{
358 unsigned long offset = c->vc_origin - sisusb->scrbuf;
359
360 /* 2 bytes per each character */
361 offset += 2 * (y * sisusb->sisusb_num_columns + x);
362
363 return sisusb->vrambase + offset;
364}
365
366/* Interface routine */
367static void
368sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
369{
370 struct sisusb_usb_data *sisusb;
371
372 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
373 if (!sisusb)
374 return;
375
376 /* sisusb->lock is down */
377 if (sisusb_is_inactive(c, sisusb)) {
378 mutex_unlock(&sisusb->lock);
379 return;
380 }
381
382 sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, x, y),
383 sisusb_haddr(sisusb, c, x, y), 2);
384
385 mutex_unlock(&sisusb->lock);
386}
387
388/* Interface routine */
389static void
390sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
391 int count, int y, int x)
392{
393 struct sisusb_usb_data *sisusb;
394
395 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
396 if (!sisusb)
397 return;
398
399 /* sisusb->lock is down */
400
401 /* Need to put the characters into the buffer ourselves,
402 * because the vt does this AFTER calling us.
403 */
404
405 memcpy(sisusb_vaddr(sisusb, c, x, y), s, count * 2);
406
407 if (sisusb_is_inactive(c, sisusb)) {
408 mutex_unlock(&sisusb->lock);
409 return;
410 }
411
412 sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, x, y),
413 sisusb_haddr(sisusb, c, x, y), count * 2);
414
415 mutex_unlock(&sisusb->lock);
416}
417
418/* Interface routine */
419static void
420sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
421{
422 struct sisusb_usb_data *sisusb;
423 u16 eattr = c->vc_video_erase_char;
424 int i, length, cols;
425 u16 *dest;
426
427 if (width <= 0 || height <= 0)
428 return;
429
430 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
431 if (!sisusb)
432 return;
433
434 /* sisusb->lock is down */
435
436 /* Need to clear buffer ourselves, because the vt does
437 * this AFTER calling us.
438 */
439
440 dest = sisusb_vaddr(sisusb, c, x, y);
441
442 cols = sisusb->sisusb_num_columns;
443
444 if (width > cols)
445 width = cols;
446
447 if (x == 0 && width >= c->vc_cols) {
448
449 sisusbcon_memsetw(dest, eattr, height * cols * 2);
450
451 } else {
452
453 for (i = height; i > 0; i--, dest += cols)
454 sisusbcon_memsetw(dest, eattr, width * 2);
455
456 }
457
458 if (sisusb_is_inactive(c, sisusb)) {
459 mutex_unlock(&sisusb->lock);
460 return;
461 }
462
463 length = ((height * cols) - x - (cols - width - x)) * 2;
464
465
466 sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, x, y),
467 sisusb_haddr(sisusb, c, x, y), length);
468
469 mutex_unlock(&sisusb->lock);
470}
471
472/* interface routine */
473static int
474sisusbcon_switch(struct vc_data *c)
475{
476 struct sisusb_usb_data *sisusb;
477 int length;
478
479 /* Returnvalue 0 means we have fully restored screen,
480 * and vt doesn't need to call do_update_region().
481 * Returnvalue != 0 naturally means the opposite.
482 */
483
484 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
485 if (!sisusb)
486 return 0;
487
488 /* sisusb->lock is down */
489
490 /* Don't write to screen if in gfx mode */
491 if (sisusb_is_inactive(c, sisusb)) {
492 mutex_unlock(&sisusb->lock);
493 return 0;
494 }
495
496 /* That really should not happen. It would mean we are
497 * being called while the vc is using its private buffer
498 * as origin.
499 */
500 if (c->vc_origin == (unsigned long)c->vc_screenbuf) {
501 mutex_unlock(&sisusb->lock);
502 dev_dbg(&sisusb->sisusb_dev->dev, "ASSERT ORIGIN != SCREENBUF!\n");
503 return 0;
504 }
505
506 /* Check that we don't copy too much */
507 length = min((int)c->vc_screenbuf_size,
508 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
509
510 /* Restore the screen contents */
511 memcpy((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf, length);
512
513 sisusb_copy_memory(sisusb, (u8 *)c->vc_origin,
514 sisusb_haddr(sisusb, c, 0, 0), length);
515
516 mutex_unlock(&sisusb->lock);
517
518 return 0;
519}
520
521/* interface routine */
522static void
523sisusbcon_save_screen(struct vc_data *c)
524{
525 struct sisusb_usb_data *sisusb;
526 int length;
527
528 /* Save the current screen contents to vc's private
529 * buffer.
530 */
531
532 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
533 if (!sisusb)
534 return;
535
536 /* sisusb->lock is down */
537
538 if (sisusb_is_inactive(c, sisusb)) {
539 mutex_unlock(&sisusb->lock);
540 return;
541 }
542
543 /* Check that we don't copy too much */
544 length = min((int)c->vc_screenbuf_size,
545 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
546
547 /* Save the screen contents to vc's private buffer */
548 memcpy((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin, length);
549
550 mutex_unlock(&sisusb->lock);
551}
552
553/* interface routine */
554static void
555sisusbcon_set_palette(struct vc_data *c, const unsigned char *table)
556{
557 struct sisusb_usb_data *sisusb;
558 int i, j;
559
560 /* Return value not used by vt */
561
562 if (!con_is_visible(c))
563 return;
564
565 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
566 if (!sisusb)
567 return;
568
569 /* sisusb->lock is down */
570
571 if (sisusb_is_inactive(c, sisusb)) {
572 mutex_unlock(&sisusb->lock);
573 return;
574 }
575
576 for (i = j = 0; i < 16; i++) {
577 if (sisusb_setreg(sisusb, SISCOLIDX, table[i]))
578 break;
579 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
580 break;
581 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
582 break;
583 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
584 break;
585 }
586
587 mutex_unlock(&sisusb->lock);
588}
589
590/* interface routine */
591static int
592sisusbcon_blank(struct vc_data *c, int blank, int mode_switch)
593{
594 struct sisusb_usb_data *sisusb;
595 u8 sr1, cr17, pmreg, cr63;
596 int ret = 0;
597
598 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
599 if (!sisusb)
600 return 0;
601
602 /* sisusb->lock is down */
603
604 if (mode_switch)
605 sisusb->is_gfx = blank ? 1 : 0;
606
607 if (sisusb_is_inactive(c, sisusb)) {
608 mutex_unlock(&sisusb->lock);
609 return 0;
610 }
611
612 switch (blank) {
613
614 case 1: /* Normal blanking: Clear screen */
615 case -1:
616 sisusbcon_memsetw((u16 *)c->vc_origin,
617 c->vc_video_erase_char,
618 c->vc_screenbuf_size);
619 sisusb_copy_memory(sisusb, (u8 *)c->vc_origin,
620 sisusb_haddr(sisusb, c, 0, 0),
621 c->vc_screenbuf_size);
622 sisusb->con_blanked = 1;
623 ret = 1;
624 break;
625
626 default: /* VESA blanking */
627 switch (blank) {
628 case 0: /* Unblank */
629 sr1 = 0x00;
630 cr17 = 0x80;
631 pmreg = 0x00;
632 cr63 = 0x00;
633 ret = 1;
634 sisusb->con_blanked = 0;
635 break;
636 case VESA_VSYNC_SUSPEND + 1:
637 sr1 = 0x20;
638 cr17 = 0x80;
639 pmreg = 0x80;
640 cr63 = 0x40;
641 break;
642 case VESA_HSYNC_SUSPEND + 1:
643 sr1 = 0x20;
644 cr17 = 0x80;
645 pmreg = 0x40;
646 cr63 = 0x40;
647 break;
648 case VESA_POWERDOWN + 1:
649 sr1 = 0x20;
650 cr17 = 0x00;
651 pmreg = 0xc0;
652 cr63 = 0x40;
653 break;
654 default:
655 mutex_unlock(&sisusb->lock);
656 return -EINVAL;
657 }
658
659 sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1);
660 sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17);
661 sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg);
662 sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63);
663
664 }
665
666 mutex_unlock(&sisusb->lock);
667
668 return ret;
669}
670
671/* interface routine */
672static void
673sisusbcon_scrolldelta(struct vc_data *c, int lines)
674{
675 struct sisusb_usb_data *sisusb;
676
677 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
678 if (!sisusb)
679 return;
680
681 /* sisusb->lock is down */
682
683 if (sisusb_is_inactive(c, sisusb)) {
684 mutex_unlock(&sisusb->lock);
685 return;
686 }
687
688 vc_scrolldelta_helper(c, lines, sisusb->con_rolled_over,
689 (void *)sisusb->scrbuf, sisusb->scrbuf_size);
690
691 sisusbcon_set_start_address(sisusb, c);
692
693 mutex_unlock(&sisusb->lock);
694}
695
696/* Interface routine */
697static void
698sisusbcon_cursor(struct vc_data *c, int mode)
699{
700 struct sisusb_usb_data *sisusb;
701 int from, to, baseline;
702
703 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
704 if (!sisusb)
705 return;
706
707 /* sisusb->lock is down */
708
709 if (sisusb_is_inactive(c, sisusb)) {
710 mutex_unlock(&sisusb->lock);
711 return;
712 }
713
714 if (c->vc_origin != c->vc_visible_origin) {
715 c->vc_visible_origin = c->vc_origin;
716 sisusbcon_set_start_address(sisusb, c);
717 }
718
719 if (mode == CM_ERASE) {
720 sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20);
721 sisusb->sisusb_cursor_size_to = -1;
722 mutex_unlock(&sisusb->lock);
723 return;
724 }
725
726 sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2);
727
728 baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2);
729
730 switch (CUR_SIZE(c->vc_cursor_type)) {
731 case CUR_BLOCK: from = 1;
732 to = c->vc_font.height;
733 break;
734 case CUR_TWO_THIRDS: from = c->vc_font.height / 3;
735 to = baseline;
736 break;
737 case CUR_LOWER_HALF: from = c->vc_font.height / 2;
738 to = baseline;
739 break;
740 case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3;
741 to = baseline;
742 break;
743 case CUR_NONE: from = 31;
744 to = 30;
745 break;
746 default:
747 case CUR_UNDERLINE: from = baseline - 1;
748 to = baseline;
749 break;
750 }
751
752 if (sisusb->sisusb_cursor_size_from != from ||
753 sisusb->sisusb_cursor_size_to != to) {
754
755 sisusb_setidxreg(sisusb, SISCR, 0x0a, from);
756 sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to);
757
758 sisusb->sisusb_cursor_size_from = from;
759 sisusb->sisusb_cursor_size_to = to;
760 }
761
762 mutex_unlock(&sisusb->lock);
763}
764
765static bool
766sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
767 unsigned int t, unsigned int b, enum con_scroll dir,
768 unsigned int lines)
769{
770 int cols = sisusb->sisusb_num_columns;
771 int length = ((b - t) * cols) * 2;
772 u16 eattr = c->vc_video_erase_char;
773
774 /* sisusb->lock is down */
775
776 /* Scroll an area which does not match the
777 * visible screen's dimensions. This needs
778 * to be done separately, as it does not
779 * use hardware panning.
780 */
781
782 switch (dir) {
783
784 case SM_UP:
785 memmove(sisusb_vaddr(sisusb, c, 0, t),
786 sisusb_vaddr(sisusb, c, 0, t + lines),
787 (b - t - lines) * cols * 2);
788 sisusbcon_memsetw(sisusb_vaddr(sisusb, c, 0, b - lines),
789 eattr, lines * cols * 2);
790 break;
791
792 case SM_DOWN:
793 memmove(sisusb_vaddr(sisusb, c, 0, t + lines),
794 sisusb_vaddr(sisusb, c, 0, t),
795 (b - t - lines) * cols * 2);
796 sisusbcon_memsetw(sisusb_vaddr(sisusb, c, 0, t), eattr,
797 lines * cols * 2);
798 break;
799 }
800
801 sisusb_copy_memory(sisusb, sisusb_vaddr(sisusb, c, 0, t),
802 sisusb_haddr(sisusb, c, 0, t), length);
803
804 mutex_unlock(&sisusb->lock);
805
806 return true;
807}
808
809/* Interface routine */
810static bool
811sisusbcon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
812 enum con_scroll dir, unsigned int lines)
813{
814 struct sisusb_usb_data *sisusb;
815 u16 eattr = c->vc_video_erase_char;
816 int copyall = 0;
817 unsigned long oldorigin;
818 unsigned int delta = lines * c->vc_size_row;
819
820 /* Returning != 0 means we have done the scrolling successfully.
821 * Returning 0 makes vt do the scrolling on its own.
822 * Note that con_scroll is only called if the console is
823 * visible. In that case, the origin should be our buffer,
824 * not the vt's private one.
825 */
826
827 if (!lines)
828 return true;
829
830 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
831 if (!sisusb)
832 return false;
833
834 /* sisusb->lock is down */
835
836 if (sisusb_is_inactive(c, sisusb)) {
837 mutex_unlock(&sisusb->lock);
838 return false;
839 }
840
841 /* Special case */
842 if (t || b != c->vc_rows)
843 return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines);
844
845 if (c->vc_origin != c->vc_visible_origin) {
846 c->vc_visible_origin = c->vc_origin;
847 sisusbcon_set_start_address(sisusb, c);
848 }
849
850 /* limit amount to maximum realistic size */
851 if (lines > c->vc_rows)
852 lines = c->vc_rows;
853
854 oldorigin = c->vc_origin;
855
856 switch (dir) {
857
858 case SM_UP:
859
860 if (c->vc_scr_end + delta >=
861 sisusb->scrbuf + sisusb->scrbuf_size) {
862 memcpy((u16 *)sisusb->scrbuf,
863 (u16 *)(oldorigin + delta),
864 c->vc_screenbuf_size - delta);
865 c->vc_origin = sisusb->scrbuf;
866 sisusb->con_rolled_over = oldorigin - sisusb->scrbuf;
867 copyall = 1;
868 } else
869 c->vc_origin += delta;
870
871 sisusbcon_memsetw(
872 (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta),
873 eattr, delta);
874
875 break;
876
877 case SM_DOWN:
878
879 if (oldorigin - delta < sisusb->scrbuf) {
880 memmove((void *)sisusb->scrbuf + sisusb->scrbuf_size -
881 c->vc_screenbuf_size + delta,
882 (u16 *)oldorigin,
883 c->vc_screenbuf_size - delta);
884 c->vc_origin = sisusb->scrbuf +
885 sisusb->scrbuf_size -
886 c->vc_screenbuf_size;
887 sisusb->con_rolled_over = 0;
888 copyall = 1;
889 } else
890 c->vc_origin -= delta;
891
892 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
893
894 scr_memsetw((u16 *)(c->vc_origin), eattr, delta);
895
896 break;
897 }
898
899 if (copyall)
900 sisusb_copy_memory(sisusb,
901 (u8 *)c->vc_origin,
902 sisusb_haddr(sisusb, c, 0, 0),
903 c->vc_screenbuf_size);
904 else if (dir == SM_UP)
905 sisusb_copy_memory(sisusb,
906 (u8 *)c->vc_origin + c->vc_screenbuf_size - delta,
907 sisusb_haddr(sisusb, c, 0, 0) +
908 c->vc_screenbuf_size - delta,
909 delta);
910 else
911 sisusb_copy_memory(sisusb,
912 (u8 *)c->vc_origin,
913 sisusb_haddr(sisusb, c, 0, 0),
914 delta);
915
916 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
917 c->vc_visible_origin = c->vc_origin;
918
919 sisusbcon_set_start_address(sisusb, c);
920
921 c->vc_pos = c->vc_pos - oldorigin + c->vc_origin;
922
923 mutex_unlock(&sisusb->lock);
924
925 return true;
926}
927
928/* Interface routine */
929static int
930sisusbcon_set_origin(struct vc_data *c)
931{
932 struct sisusb_usb_data *sisusb;
933
934 /* Returning != 0 means we were successful.
935 * Returning 0 will vt make to use its own
936 * screenbuffer as the origin.
937 */
938
939 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
940 if (!sisusb)
941 return 0;
942
943 /* sisusb->lock is down */
944
945 if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) {
946 mutex_unlock(&sisusb->lock);
947 return 0;
948 }
949
950 c->vc_origin = c->vc_visible_origin = sisusb->scrbuf;
951
952 sisusbcon_set_start_address(sisusb, c);
953
954 sisusb->con_rolled_over = 0;
955
956 mutex_unlock(&sisusb->lock);
957
958 return true;
959}
960
961/* Interface routine */
962static int
963sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows,
964 unsigned int user)
965{
966 struct sisusb_usb_data *sisusb;
967 int fh;
968
969 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
970 if (!sisusb)
971 return -ENODEV;
972
973 fh = sisusb->current_font_height;
974
975 mutex_unlock(&sisusb->lock);
976
977 /* We are quite unflexible as regards resizing. The vt code
978 * handles sizes where the line length isn't equal the pitch
979 * quite badly. As regards the rows, our panning tricks only
980 * work well if the number of rows equals the visible number
981 * of rows.
982 */
983
984 if (newcols != 80 || c->vc_scan_lines / fh != newrows)
985 return -EINVAL;
986
987 return 0;
988}
989
990int
991sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
992 u8 *arg, int cmapsz, int ch512, int dorecalc,
993 struct vc_data *c, int fh, int uplock)
994{
995 int font_select = 0x00, i, err = 0;
996 u32 offset = 0;
997 u8 dummy;
998
999 /* sisusb->lock is down */
1000
1001 /*
1002 * The default font is kept in slot 0.
1003 * A user font is loaded in slot 2 (256 ch)
1004 * or 2+3 (512 ch).
1005 */
1006
1007 if ((slot != 0 && slot != 2) || !fh) {
1008 if (uplock)
1009 mutex_unlock(&sisusb->lock);
1010 return -EINVAL;
1011 }
1012
1013 if (set)
1014 sisusb->font_slot = slot;
1015
1016 /* Default font is always 256 */
1017 if (slot == 0)
1018 ch512 = 0;
1019 else
1020 offset = 4 * cmapsz;
1021
1022 font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a);
1023
1024 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1025 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04); /* Write to plane 2 */
1026 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07); /* Memory mode a0-bf */
1027 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset */
1028
1029 if (err)
1030 goto font_op_error;
1031
1032 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03); /* Select plane read 2 */
1033 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00); /* Disable odd/even */
1034 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00); /* Address range a0-bf */
1035
1036 if (err)
1037 goto font_op_error;
1038
1039 if (arg) {
1040 if (set)
1041 for (i = 0; i < cmapsz; i++) {
1042 err |= sisusb_writeb(sisusb,
1043 sisusb->vrambase + offset + i,
1044 arg[i]);
1045 if (err)
1046 break;
1047 }
1048 else
1049 for (i = 0; i < cmapsz; i++) {
1050 err |= sisusb_readb(sisusb,
1051 sisusb->vrambase + offset + i,
1052 &arg[i]);
1053 if (err)
1054 break;
1055 }
1056
1057 /*
1058 * In 512-character mode, the character map is not contiguous if
1059 * we want to remain EGA compatible -- which we do
1060 */
1061
1062 if (ch512) {
1063 if (set)
1064 for (i = 0; i < cmapsz; i++) {
1065 err |= sisusb_writeb(sisusb,
1066 sisusb->vrambase + offset +
1067 (2 * cmapsz) + i,
1068 arg[cmapsz + i]);
1069 if (err)
1070 break;
1071 }
1072 else
1073 for (i = 0; i < cmapsz; i++) {
1074 err |= sisusb_readb(sisusb,
1075 sisusb->vrambase + offset +
1076 (2 * cmapsz) + i,
1077 &arg[cmapsz + i]);
1078 if (err)
1079 break;
1080 }
1081 }
1082 }
1083
1084 if (err)
1085 goto font_op_error;
1086
1087 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1088 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03); /* Write to planes 0+1 */
1089 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03); /* Memory mode a0-bf */
1090 if (set)
1091 sisusb_setidxreg(sisusb, SISSR, 0x03, font_select);
1092 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset end */
1093
1094 if (err)
1095 goto font_op_error;
1096
1097 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00); /* Select plane read 0 */
1098 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10); /* Enable odd/even */
1099 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06); /* Address range b8-bf */
1100
1101 if (err)
1102 goto font_op_error;
1103
1104 if ((set) && (ch512 != sisusb->current_font_512)) {
1105
1106 /* Font is shared among all our consoles.
1107 * And so is the hi_font_mask.
1108 */
1109 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1110 struct vc_data *d = vc_cons[i].d;
1111 if (d && d->vc_sw == &sisusb_con)
1112 d->vc_hi_font_mask = ch512 ? 0x0800 : 0;
1113 }
1114
1115 sisusb->current_font_512 = ch512;
1116
1117 /* color plane enable register:
1118 256-char: enable intensity bit
1119 512-char: disable intensity bit */
1120 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1121 sisusb_setreg(sisusb, SISAR, 0x12);
1122 sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f);
1123
1124 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1125 sisusb_setreg(sisusb, SISAR, 0x20);
1126 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1127 }
1128
1129 if (dorecalc) {
1130
1131 /*
1132 * Adjust the screen to fit a font of a certain height
1133 */
1134
1135 unsigned char ovr, vde, fsr;
1136 int rows = 0, maxscan = 0;
1137
1138 if (c) {
1139
1140 /* Number of video rows */
1141 rows = c->vc_scan_lines / fh;
1142 /* Scan lines to actually display-1 */
1143 maxscan = rows * fh - 1;
1144
1145 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1146 rows, maxscan, fh, c->vc_scan_lines);*/
1147
1148 sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr);
1149 vde = maxscan & 0xff;
1150 ovr = (ovr & 0xbd) |
1151 ((maxscan & 0x100) >> 7) |
1152 ((maxscan & 0x200) >> 3);
1153 sisusb_setidxreg(sisusb, SISCR, 0x07, ovr);
1154 sisusb_setidxreg(sisusb, SISCR, 0x12, vde);
1155
1156 }
1157
1158 sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr);
1159 fsr = (fsr & 0xe0) | (fh - 1);
1160 sisusb_setidxreg(sisusb, SISCR, 0x09, fsr);
1161 sisusb->current_font_height = fh;
1162
1163 sisusb->sisusb_cursor_size_from = -1;
1164 sisusb->sisusb_cursor_size_to = -1;
1165
1166 }
1167
1168 if (uplock)
1169 mutex_unlock(&sisusb->lock);
1170
1171 if (dorecalc && c) {
1172 int rows = c->vc_scan_lines / fh;
1173
1174 /* Now adjust our consoles' size */
1175
1176 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1177 struct vc_data *vc = vc_cons[i].d;
1178
1179 if (vc && vc->vc_sw == &sisusb_con) {
1180 if (con_is_visible(vc)) {
1181 vc->vc_sw->con_cursor(vc, CM_DRAW);
1182 }
1183 vc->vc_font.height = fh;
1184 vc_resize(vc, 0, rows);
1185 }
1186 }
1187 }
1188
1189 return 0;
1190
1191font_op_error:
1192 if (uplock)
1193 mutex_unlock(&sisusb->lock);
1194
1195 return -EIO;
1196}
1197
1198/* Interface routine */
1199static int
1200sisusbcon_font_set(struct vc_data *c, struct console_font *font,
1201 unsigned int flags)
1202{
1203 struct sisusb_usb_data *sisusb;
1204 unsigned charcount = font->charcount;
1205
1206 if (font->width != 8 || (charcount != 256 && charcount != 512))
1207 return -EINVAL;
1208
1209 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
1210 if (!sisusb)
1211 return -ENODEV;
1212
1213 /* sisusb->lock is down */
1214
1215 /* Save the user-provided font into a buffer. This
1216 * is used for restoring text mode after quitting
1217 * from X and for the con_getfont routine.
1218 */
1219 if (sisusb->font_backup) {
1220 if (sisusb->font_backup_size < charcount) {
1221 vfree(sisusb->font_backup);
1222 sisusb->font_backup = NULL;
1223 }
1224 }
1225
1226 if (!sisusb->font_backup)
1227 sisusb->font_backup = vmalloc(array_size(charcount, 32));
1228
1229 if (sisusb->font_backup) {
1230 memcpy(sisusb->font_backup, font->data, array_size(charcount, 32));
1231 sisusb->font_backup_size = charcount;
1232 sisusb->font_backup_height = font->height;
1233 sisusb->font_backup_512 = (charcount == 512) ? 1 : 0;
1234 }
1235
1236 /* do_font_op ups sisusb->lock */
1237
1238 return sisusbcon_do_font_op(sisusb, 1, 2, font->data,
1239 8192, (charcount == 512),
1240 (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0,
1241 c, font->height, 1);
1242}
1243
1244/* Interface routine */
1245static int
1246sisusbcon_font_get(struct vc_data *c, struct console_font *font)
1247{
1248 struct sisusb_usb_data *sisusb;
1249
1250 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
1251 if (!sisusb)
1252 return -ENODEV;
1253
1254 /* sisusb->lock is down */
1255
1256 font->width = 8;
1257 font->height = c->vc_font.height;
1258 font->charcount = 256;
1259
1260 if (!font->data) {
1261 mutex_unlock(&sisusb->lock);
1262 return 0;
1263 }
1264
1265 if (!sisusb->font_backup) {
1266 mutex_unlock(&sisusb->lock);
1267 return -ENODEV;
1268 }
1269
1270 /* Copy 256 chars only, like vgacon */
1271 memcpy(font->data, sisusb->font_backup, 256 * 32);
1272
1273 mutex_unlock(&sisusb->lock);
1274
1275 return 0;
1276}
1277
1278/*
1279 * The console `switch' structure for the sisusb console
1280 */
1281
1282static const struct consw sisusb_con = {
1283 .owner = THIS_MODULE,
1284 .con_startup = sisusbcon_startup,
1285 .con_init = sisusbcon_init,
1286 .con_deinit = sisusbcon_deinit,
1287 .con_clear = sisusbcon_clear,
1288 .con_putc = sisusbcon_putc,
1289 .con_putcs = sisusbcon_putcs,
1290 .con_cursor = sisusbcon_cursor,
1291 .con_scroll = sisusbcon_scroll,
1292 .con_switch = sisusbcon_switch,
1293 .con_blank = sisusbcon_blank,
1294 .con_font_set = sisusbcon_font_set,
1295 .con_font_get = sisusbcon_font_get,
1296 .con_set_palette = sisusbcon_set_palette,
1297 .con_scrolldelta = sisusbcon_scrolldelta,
1298 .con_build_attr = sisusbcon_build_attr,
1299 .con_invert_region = sisusbcon_invert_region,
1300 .con_set_origin = sisusbcon_set_origin,
1301 .con_save_screen = sisusbcon_save_screen,
1302 .con_resize = sisusbcon_resize,
1303};
1304
1305/* Our very own dummy console driver */
1306
1307static const char *sisusbdummycon_startup(void)
1308{
1309 return "SISUSBVGADUMMY";
1310}
1311
1312static void sisusbdummycon_init(struct vc_data *vc, int init)
1313{
1314 vc->vc_can_do_color = 1;
1315 if (init) {
1316 vc->vc_cols = 80;
1317 vc->vc_rows = 25;
1318 } else
1319 vc_resize(vc, 80, 25);
1320}
1321
1322static void sisusbdummycon_deinit(struct vc_data *vc) { }
1323static void sisusbdummycon_clear(struct vc_data *vc, int sy, int sx,
1324 int height, int width) { }
1325static void sisusbdummycon_putc(struct vc_data *vc, int c, int ypos,
1326 int xpos) { }
1327static void sisusbdummycon_putcs(struct vc_data *vc, const unsigned short *s,
1328 int count, int ypos, int xpos) { }
1329static void sisusbdummycon_cursor(struct vc_data *vc, int mode) { }
1330
1331static bool sisusbdummycon_scroll(struct vc_data *vc, unsigned int top,
1332 unsigned int bottom, enum con_scroll dir,
1333 unsigned int lines)
1334{
1335 return false;
1336}
1337
1338static int sisusbdummycon_switch(struct vc_data *vc)
1339{
1340 return 0;
1341}
1342
1343static int sisusbdummycon_blank(struct vc_data *vc, int blank, int mode_switch)
1344{
1345 return 0;
1346}
1347
1348static const struct consw sisusb_dummy_con = {
1349 .owner = THIS_MODULE,
1350 .con_startup = sisusbdummycon_startup,
1351 .con_init = sisusbdummycon_init,
1352 .con_deinit = sisusbdummycon_deinit,
1353 .con_clear = sisusbdummycon_clear,
1354 .con_putc = sisusbdummycon_putc,
1355 .con_putcs = sisusbdummycon_putcs,
1356 .con_cursor = sisusbdummycon_cursor,
1357 .con_scroll = sisusbdummycon_scroll,
1358 .con_switch = sisusbdummycon_switch,
1359 .con_blank = sisusbdummycon_blank,
1360};
1361
1362int
1363sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last)
1364{
1365 int i, ret;
1366
1367 mutex_lock(&sisusb->lock);
1368
1369 /* Erm.. that should not happen */
1370 if (sisusb->haveconsole || !sisusb->SiS_Pr) {
1371 mutex_unlock(&sisusb->lock);
1372 return 1;
1373 }
1374
1375 sisusb->con_first = first;
1376 sisusb->con_last = last;
1377
1378 if (first > last ||
1379 first > MAX_NR_CONSOLES ||
1380 last > MAX_NR_CONSOLES) {
1381 mutex_unlock(&sisusb->lock);
1382 return 1;
1383 }
1384
1385 /* If gfxcore not initialized or no consoles given, quit graciously */
1386 if (!sisusb->gfxinit || first < 1 || last < 1) {
1387 mutex_unlock(&sisusb->lock);
1388 return 0;
1389 }
1390
1391 sisusb->sisusb_cursor_loc = -1;
1392 sisusb->sisusb_cursor_size_from = -1;
1393 sisusb->sisusb_cursor_size_to = -1;
1394
1395 /* Set up text mode (and upload default font) */
1396 if (sisusb_reset_text_mode(sisusb, 1)) {
1397 mutex_unlock(&sisusb->lock);
1398 dev_err(&sisusb->sisusb_dev->dev, "Failed to set up text mode\n");
1399 return 1;
1400 }
1401
1402 /* Initialize some gfx registers */
1403 sisusb_initialize(sisusb);
1404
1405 for (i = first - 1; i <= last - 1; i++) {
1406 /* Save sisusb for our interface routines */
1407 mysisusbs[i] = sisusb;
1408 }
1409
1410 /* Initial console setup */
1411 sisusb->sisusb_num_columns = 80;
1412
1413 /* Use a 32K buffer (matches b8000-bffff area) */
1414 sisusb->scrbuf_size = 32 * 1024;
1415
1416 /* Allocate screen buffer */
1417 if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) {
1418 mutex_unlock(&sisusb->lock);
1419 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate screen buffer\n");
1420 return 1;
1421 }
1422
1423 mutex_unlock(&sisusb->lock);
1424
1425 /* Now grab the desired console(s) */
1426 console_lock();
1427 ret = do_take_over_console(&sisusb_con, first - 1, last - 1, 0);
1428 console_unlock();
1429 if (!ret)
1430 sisusb->haveconsole = 1;
1431 else {
1432 for (i = first - 1; i <= last - 1; i++)
1433 mysisusbs[i] = NULL;
1434 }
1435
1436 return ret;
1437}
1438
1439void
1440sisusb_console_exit(struct sisusb_usb_data *sisusb)
1441{
1442 int i;
1443
1444 /* This is called if the device is disconnected
1445 * and while disconnect and lock semaphores
1446 * are up. This should be save because we
1447 * can't lose our sisusb any other way but by
1448 * disconnection (and hence, the disconnect
1449 * sema is for protecting all other access
1450 * functions from disconnection, not the
1451 * other way round).
1452 */
1453
1454 /* Now what do we do in case of disconnection:
1455 * One alternative would be to simply call
1456 * give_up_console(). Nah, not a good idea.
1457 * give_up_console() is obviously buggy as it
1458 * only discards the consw pointer from the
1459 * driver_map, but doesn't adapt vc->vc_sw
1460 * of the affected consoles. Hence, the next
1461 * call to any of the console functions will
1462 * eventually take a trip to oops county.
1463 * Also, give_up_console for some reason
1464 * doesn't decrement our module refcount.
1465 * Instead, we switch our consoles to a private
1466 * dummy console. This, of course, keeps our
1467 * refcount up as well, but it works perfectly.
1468 */
1469
1470 if (sisusb->haveconsole) {
1471 for (i = 0; i < MAX_NR_CONSOLES; i++)
1472 if (sisusb->havethisconsole[i]) {
1473 console_lock();
1474 do_take_over_console(&sisusb_dummy_con, i, i, 0);
1475 console_unlock();
1476 /* At this point, con_deinit for all our
1477 * consoles is executed by do_take_over_console().
1478 */
1479 }
1480 sisusb->haveconsole = 0;
1481 }
1482
1483 vfree((void *)sisusb->scrbuf);
1484 sisusb->scrbuf = 0;
1485
1486 vfree(sisusb->font_backup);
1487 sisusb->font_backup = NULL;
1488}
1489
1490void __init sisusb_init_concode(void)
1491{
1492 int i;
1493
1494 for (i = 0; i < MAX_NR_CONSOLES; i++)
1495 mysisusbs[i] = NULL;
1496}
drivers/usb/misc/sisusbvga/sisusb_init.c+0−955
@@ -1,955 +0,0 @@
1// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2/*
3 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
4 *
5 * Display mode initializing code
6 *
7 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
8 *
9 * If distributed as part of the Linux kernel, this code is licensed under the
10 * terms of the GPL v2.
11 *
12 * Otherwise, the following license terms apply:
13 *
14 * * Redistribution and use in source and binary forms, with or without
15 * * modification, are permitted provided that the following conditions
16 * * are met:
17 * * 1) Redistributions of source code must retain the above copyright
18 * * notice, this list of conditions and the following disclaimer.
19 * * 2) Redistributions in binary form must reproduce the above copyright
20 * * notice, this list of conditions and the following disclaimer in the
21 * * documentation and/or other materials provided with the distribution.
22 * * 3) The name of the author may not be used to endorse or promote products
23 * * derived from this software without specific prior written permission.
24 * *
25 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 * Author: Thomas Winischhofer <thomas@winischhofer.net>
37 *
38 */
39
40#include <linux/module.h>
41#include <linux/kernel.h>
42#include <linux/errno.h>
43#include <linux/poll.h>
44#include <linux/spinlock.h>
45
46#include "sisusb.h"
47#include "sisusb_init.h"
48#include "sisusb_tables.h"
49
50/*********************************************/
51/* POINTER INITIALIZATION */
52/*********************************************/
53
54static void SiSUSB_InitPtr(struct SiS_Private *SiS_Pr)
55{
56 SiS_Pr->SiS_ModeResInfo = SiSUSB_ModeResInfo;
57 SiS_Pr->SiS_StandTable = SiSUSB_StandTable;
58
59 SiS_Pr->SiS_SModeIDTable = SiSUSB_SModeIDTable;
60 SiS_Pr->SiS_EModeIDTable = SiSUSB_EModeIDTable;
61 SiS_Pr->SiS_RefIndex = SiSUSB_RefIndex;
62 SiS_Pr->SiS_CRT1Table = SiSUSB_CRT1Table;
63
64 SiS_Pr->SiS_VCLKData = SiSUSB_VCLKData;
65}
66
67/*********************************************/
68/* HELPER: SetReg, GetReg */
69/*********************************************/
70
71static void
72SiS_SetReg(struct SiS_Private *SiS_Pr, unsigned long port,
73 unsigned short index, unsigned short data)
74{
75 sisusb_setidxreg(SiS_Pr->sisusb, port, index, data);
76}
77
78static void
79SiS_SetRegByte(struct SiS_Private *SiS_Pr, unsigned long port,
80 unsigned short data)
81{
82 sisusb_setreg(SiS_Pr->sisusb, port, data);
83}
84
85static unsigned char
86SiS_GetReg(struct SiS_Private *SiS_Pr, unsigned long port, unsigned short index)
87{
88 u8 data;
89
90 sisusb_getidxreg(SiS_Pr->sisusb, port, index, &data);
91
92 return data;
93}
94
95static unsigned char
96SiS_GetRegByte(struct SiS_Private *SiS_Pr, unsigned long port)
97{
98 u8 data;
99
100 sisusb_getreg(SiS_Pr->sisusb, port, &data);
101
102 return data;
103}
104
105static void
106SiS_SetRegANDOR(struct SiS_Private *SiS_Pr, unsigned long port,
107 unsigned short index, unsigned short DataAND,
108 unsigned short DataOR)
109{
110 sisusb_setidxregandor(SiS_Pr->sisusb, port, index, DataAND, DataOR);
111}
112
113static void
114SiS_SetRegAND(struct SiS_Private *SiS_Pr, unsigned long port,
115 unsigned short index, unsigned short DataAND)
116{
117 sisusb_setidxregand(SiS_Pr->sisusb, port, index, DataAND);
118}
119
120static void
121SiS_SetRegOR(struct SiS_Private *SiS_Pr, unsigned long port,
122 unsigned short index, unsigned short DataOR)
123{
124 sisusb_setidxregor(SiS_Pr->sisusb, port, index, DataOR);
125}
126
127/*********************************************/
128/* HELPER: DisplayOn, DisplayOff */
129/*********************************************/
130
131static void SiS_DisplayOn(struct SiS_Private *SiS_Pr)
132{
133 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, 0xDF);
134}
135
136/*********************************************/
137/* HELPER: Init Port Addresses */
138/*********************************************/
139
140static void SiSUSBRegInit(struct SiS_Private *SiS_Pr, unsigned long BaseAddr)
141{
142 SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
143 SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
144 SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
145 SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
146 SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
147 SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
148 SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
149 SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
150 SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
151 SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
152 SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
153 SiS_Pr->SiS_P3cc = BaseAddr + 0x1c;
154 SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
155 SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
156 SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;
157}
158
159/*********************************************/
160/* HELPER: GetSysFlags */
161/*********************************************/
162
163static void SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
164{
165 SiS_Pr->SiS_MyCR63 = 0x63;
166}
167
168/*********************************************/
169/* HELPER: Init PCI & Engines */
170/*********************************************/
171
172static void SiSInitPCIetc(struct SiS_Private *SiS_Pr)
173{
174 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x20, 0xa1);
175 /* - Enable 2D (0x40)
176 * - Enable 3D (0x02)
177 * - Enable 3D vertex command fetch (0x10)
178 * - Enable 3D command parser (0x08)
179 * - Enable 3D G/L transformation engine (0x80)
180 */
181 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1E, 0xDA);
182}
183
184/*********************************************/
185/* HELPER: SET SEGMENT REGISTERS */
186/*********************************************/
187
188static void SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value)
189{
190 unsigned short temp;
191
192 value &= 0x00ff;
193 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb) & 0xf0;
194 temp |= (value >> 4);
195 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb, temp);
196 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd) & 0xf0;
197 temp |= (value & 0x0f);
198 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd, temp);
199}
200
201static void SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value)
202{
203 unsigned short temp;
204
205 value &= 0x00ff;
206 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb) & 0x0f;
207 temp |= (value & 0xf0);
208 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb, temp);
209 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd) & 0x0f;
210 temp |= (value << 4);
211 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd, temp);
212}
213
214static void SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value)
215{
216 SiS_SetSegRegLower(SiS_Pr, value);
217 SiS_SetSegRegUpper(SiS_Pr, value);
218}
219
220static void SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
221{
222 SiS_SetSegmentReg(SiS_Pr, 0);
223}
224
225static void
226SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value)
227{
228 unsigned short temp = value >> 8;
229
230 temp &= 0x07;
231 temp |= (temp << 4);
232 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1d, temp);
233 SiS_SetSegmentReg(SiS_Pr, value);
234}
235
236static void SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
237{
238 SiS_SetSegmentRegOver(SiS_Pr, 0);
239}
240
241static void SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
242{
243 SiS_ResetSegmentReg(SiS_Pr);
244 SiS_ResetSegmentRegOver(SiS_Pr);
245}
246
247/*********************************************/
248/* HELPER: SearchModeID */
249/*********************************************/
250
251static int
252SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
253 unsigned short *ModeIdIndex)
254{
255 if ((*ModeNo) <= 0x13) {
256
257 if ((*ModeNo) != 0x03)
258 return 0;
259
260 (*ModeIdIndex) = 0;
261
262 } else {
263
264 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
265
266 if (SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID ==
267 (*ModeNo))
268 break;
269
270 if (SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID ==
271 0xFF)
272 return 0;
273 }
274
275 }
276
277 return 1;
278}
279
280/*********************************************/
281/* HELPER: ENABLE CRT1 */
282/*********************************************/
283
284static void SiS_HandleCRT1(struct SiS_Private *SiS_Pr)
285{
286 /* Enable CRT1 gating */
287 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, SiS_Pr->SiS_MyCR63, 0xbf);
288}
289
290/*********************************************/
291/* HELPER: GetColorDepth */
292/*********************************************/
293
294static unsigned short
295SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
296 unsigned short ModeIdIndex)
297{
298 static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
299 unsigned short modeflag;
300 short index;
301
302 if (ModeNo <= 0x13) {
303 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
304 } else {
305 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
306 }
307
308 index = (modeflag & ModeTypeMask) - ModeEGA;
309 if (index < 0)
310 index = 0;
311 return ColorDepth[index];
312}
313
314/*********************************************/
315/* HELPER: GetOffset */
316/*********************************************/
317
318static unsigned short
319SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
320 unsigned short ModeIdIndex, unsigned short rrti)
321{
322 unsigned short xres, temp, colordepth, infoflag;
323
324 infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag;
325 xres = SiS_Pr->SiS_RefIndex[rrti].XRes;
326
327 colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex);
328
329 temp = xres / 16;
330
331 if (infoflag & InterlaceMode)
332 temp <<= 1;
333
334 temp *= colordepth;
335
336 if (xres % 16)
337 temp += (colordepth >> 1);
338
339 return temp;
340}
341
342/*********************************************/
343/* SEQ */
344/*********************************************/
345
346static void
347SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
348{
349 unsigned char SRdata;
350 int i;
351
352 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x00, 0x03);
353
354 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20;
355 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, SRdata);
356
357 for (i = 2; i <= 4; i++) {
358 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i - 1];
359 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, i, SRdata);
360 }
361}
362
363/*********************************************/
364/* MISC */
365/*********************************************/
366
367static void
368SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
369{
370 unsigned char Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC;
371
372 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c2, Miscdata);
373}
374
375/*********************************************/
376/* CRTC */
377/*********************************************/
378
379static void
380SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
381{
382 unsigned char CRTCdata;
383 unsigned short i;
384
385 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, 0x11, 0x7f);
386
387 for (i = 0; i <= 0x18; i++) {
388 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
389 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, i, CRTCdata);
390 }
391}
392
393/*********************************************/
394/* ATT */
395/*********************************************/
396
397static void
398SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
399{
400 unsigned char ARdata;
401 unsigned short i;
402
403 for (i = 0; i <= 0x13; i++) {
404 ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i];
405 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
406 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, i);
407 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, ARdata);
408 }
409 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
410 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x14);
411 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x00);
412
413 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
414 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x20);
415 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
416}
417
418/*********************************************/
419/* GRC */
420/*********************************************/
421
422static void
423SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
424{
425 unsigned char GRdata;
426 unsigned short i;
427
428 for (i = 0; i <= 0x08; i++) {
429 GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i];
430 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3ce, i, GRdata);
431 }
432
433 if (SiS_Pr->SiS_ModeType > ModeVGA) {
434 /* 256 color disable */
435 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3ce, 0x05, 0xBF);
436 }
437}
438
439/*********************************************/
440/* CLEAR EXTENDED REGISTERS */
441/*********************************************/
442
443static void SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
444{
445 int i;
446
447 for (i = 0x0A; i <= 0x0E; i++) {
448 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, i, 0x00);
449 }
450
451 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x37, 0xFE);
452}
453
454/*********************************************/
455/* Get rate index */
456/*********************************************/
457
458static unsigned short
459SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
460 unsigned short ModeIdIndex)
461{
462 unsigned short rrti, i, index, temp;
463
464 if (ModeNo <= 0x13)
465 return 0xFFFF;
466
467 index = SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x33) & 0x0F;
468 if (index > 0)
469 index--;
470
471 rrti = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
472 ModeNo = SiS_Pr->SiS_RefIndex[rrti].ModeID;
473
474 i = 0;
475 do {
476 if (SiS_Pr->SiS_RefIndex[rrti + i].ModeID != ModeNo)
477 break;
478
479 temp =
480 SiS_Pr->SiS_RefIndex[rrti + i].Ext_InfoFlag & ModeTypeMask;
481 if (temp < SiS_Pr->SiS_ModeType)
482 break;
483
484 i++;
485 index--;
486 } while (index != 0xFFFF);
487
488 i--;
489
490 return (rrti + i);
491}
492
493/*********************************************/
494/* SYNC */
495/*********************************************/
496
497static void SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short rrti)
498{
499 unsigned short sync = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag >> 8;
500 sync &= 0xC0;
501 sync |= 0x2f;
502 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c2, sync);
503}
504
505/*********************************************/
506/* CRTC/2 */
507/*********************************************/
508
509static void
510SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
511 unsigned short ModeIdIndex, unsigned short rrti)
512{
513 unsigned char index;
514 unsigned short temp, i, j, modeflag;
515
516 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, 0x11, 0x7f);
517
518 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
519
520 index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRT1CRTC;
521
522 for (i = 0, j = 0; i <= 7; i++, j++) {
523 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j,
524 SiS_Pr->SiS_CRT1Table[index].CR[i]);
525 }
526 for (j = 0x10; i <= 10; i++, j++) {
527 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j,
528 SiS_Pr->SiS_CRT1Table[index].CR[i]);
529 }
530 for (j = 0x15; i <= 12; i++, j++) {
531 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j,
532 SiS_Pr->SiS_CRT1Table[index].CR[i]);
533 }
534 for (j = 0x0A; i <= 15; i++, j++) {
535 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, j,
536 SiS_Pr->SiS_CRT1Table[index].CR[i]);
537 }
538
539 temp = SiS_Pr->SiS_CRT1Table[index].CR[16] & 0xE0;
540 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0E, temp);
541
542 temp = ((SiS_Pr->SiS_CRT1Table[index].CR[16]) & 0x01) << 5;
543 if (modeflag & DoubleScanMode)
544 temp |= 0x80;
545 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3d4, 0x09, 0x5F, temp);
546
547 if (SiS_Pr->SiS_ModeType > ModeVGA)
548 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x14, 0x4F);
549}
550
551/*********************************************/
552/* OFFSET & PITCH */
553/*********************************************/
554/* (partly overruled by SetPitch() in XF86) */
555/*********************************************/
556
557static void
558SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
559 unsigned short ModeIdIndex, unsigned short rrti)
560{
561 unsigned short du = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, rrti);
562 unsigned short infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag;
563 unsigned short temp;
564
565 temp = (du >> 8) & 0x0f;
566 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0E, 0xF0, temp);
567
568 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x13, (du & 0xFF));
569
570 if (infoflag & InterlaceMode)
571 du >>= 1;
572
573 du <<= 5;
574 temp = (du >> 8) & 0xff;
575 if (du & 0xff)
576 temp++;
577 temp++;
578 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x10, temp);
579}
580
581/*********************************************/
582/* VCLK */
583/*********************************************/
584
585static void
586SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
587 unsigned short rrti)
588{
589 unsigned short index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRTVCLK;
590 unsigned short clka = SiS_Pr->SiS_VCLKData[index].SR2B;
591 unsigned short clkb = SiS_Pr->SiS_VCLKData[index].SR2C;
592
593 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x31, 0xCF);
594
595 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x2B, clka);
596 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x2C, clkb);
597 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x2D, 0x01);
598}
599
600/*********************************************/
601/* FIFO */
602/*********************************************/
603
604static void
605SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
606 unsigned short mi)
607{
608 unsigned short modeflag = SiS_Pr->SiS_EModeIDTable[mi].Ext_ModeFlag;
609
610 /* disable auto-threshold */
611 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x3D, 0xFE);
612
613 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x08, 0xAE);
614 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x09, 0xF0);
615
616 if (ModeNo <= 0x13)
617 return;
618
619 if ((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
620 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x08, 0x34);
621 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x3D, 0x01);
622 }
623}
624
625/*********************************************/
626/* MODE REGISTERS */
627/*********************************************/
628
629static void
630SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
631 unsigned short rrti)
632{
633 unsigned short data = 0, VCLK = 0, index = 0;
634
635 if (ModeNo > 0x13) {
636 index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRTVCLK;
637 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
638 }
639
640 if (VCLK >= 166)
641 data |= 0x0c;
642 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x32, 0xf3, data);
643
644 if (VCLK >= 166)
645 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1f, 0xe7);
646
647 /* DAC speed */
648 data = 0x03;
649 if (VCLK >= 260)
650 data = 0x00;
651 else if (VCLK >= 160)
652 data = 0x01;
653 else if (VCLK >= 135)
654 data = 0x02;
655
656 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x07, 0xF8, data);
657}
658
659static void
660SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
661 unsigned short ModeIdIndex, unsigned short rrti)
662{
663 unsigned short data, infoflag = 0, modeflag;
664
665 if (ModeNo <= 0x13)
666 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
667 else {
668 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
669 infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag;
670 }
671
672 /* Disable DPMS */
673 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1F, 0x3F);
674
675 data = 0;
676 if (ModeNo > 0x13) {
677 if (SiS_Pr->SiS_ModeType > ModeEGA) {
678 data |= 0x02;
679 data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
680 }
681 if (infoflag & InterlaceMode)
682 data |= 0x20;
683 }
684 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x06, 0xC0, data);
685
686 data = 0;
687 if (infoflag & InterlaceMode) {
688 /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
689 unsigned short hrs =
690 (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x04) |
691 ((SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0b) & 0xc0) << 2))
692 - 3;
693 unsigned short hto =
694 (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x00) |
695 ((SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0b) & 0x03) << 8))
696 + 5;
697 data = hrs - (hto >> 1) + 3;
698 }
699 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x19, (data & 0xFF));
700 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3d4, 0x1a, 0xFC, (data >> 8));
701
702 if (modeflag & HalfDCLK)
703 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, 0x08);
704
705 data = 0;
706 if (modeflag & LineCompareOff)
707 data = 0x08;
708 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0F, 0xB7, data);
709
710 if ((SiS_Pr->SiS_ModeType == ModeEGA) && (ModeNo > 0x13))
711 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0F, 0x40);
712
713 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x31, 0xfb);
714
715 data = 0x60;
716 if (SiS_Pr->SiS_ModeType != ModeText) {
717 data ^= 0x60;
718 if (SiS_Pr->SiS_ModeType != ModeEGA)
719 data ^= 0xA0;
720 }
721 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x21, 0x1F, data);
722
723 SiS_SetVCLKState(SiS_Pr, ModeNo, rrti);
724
725 if (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x31) & 0x40)
726 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x52, 0x2c);
727 else
728 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x52, 0x6c);
729}
730
731/*********************************************/
732/* LOAD DAC */
733/*********************************************/
734
735static void
736SiS_WriteDAC(struct SiS_Private *SiS_Pr, unsigned long DACData,
737 unsigned short shiftflag, unsigned short dl, unsigned short ah,
738 unsigned short al, unsigned short dh)
739{
740 unsigned short d1, d2, d3;
741
742 switch (dl) {
743 case 0:
744 d1 = dh;
745 d2 = ah;
746 d3 = al;
747 break;
748 case 1:
749 d1 = ah;
750 d2 = al;
751 d3 = dh;
752 break;
753 default:
754 d1 = al;
755 d2 = dh;
756 d3 = ah;
757 }
758 SiS_SetRegByte(SiS_Pr, DACData, (d1 << shiftflag));
759 SiS_SetRegByte(SiS_Pr, DACData, (d2 << shiftflag));
760 SiS_SetRegByte(SiS_Pr, DACData, (d3 << shiftflag));
761}
762
763static void
764SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
765 unsigned short mi)
766{
767 unsigned short data, data2, time, i, j, k, m, n, o;
768 unsigned short si, di, bx, sf;
769 unsigned long DACAddr, DACData;
770 const unsigned char *table = NULL;
771
772 if (ModeNo < 0x13)
773 data = SiS_Pr->SiS_SModeIDTable[mi].St_ModeFlag;
774 else
775 data = SiS_Pr->SiS_EModeIDTable[mi].Ext_ModeFlag;
776
777 data &= DACInfoFlag;
778
779 j = time = 64;
780 if (data == 0x00)
781 table = SiS_MDA_DAC;
782 else if (data == 0x08)
783 table = SiS_CGA_DAC;
784 else if (data == 0x10)
785 table = SiS_EGA_DAC;
786 else {
787 j = 16;
788 time = 256;
789 table = SiS_VGA_DAC;
790 }
791
792 DACAddr = SiS_Pr->SiS_P3c8;
793 DACData = SiS_Pr->SiS_P3c9;
794 sf = 0;
795 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c6, 0xFF);
796
797 SiS_SetRegByte(SiS_Pr, DACAddr, 0x00);
798
799 for (i = 0; i < j; i++) {
800 data = table[i];
801 for (k = 0; k < 3; k++) {
802 data2 = 0;
803 if (data & 0x01)
804 data2 += 0x2A;
805 if (data & 0x02)
806 data2 += 0x15;
807 SiS_SetRegByte(SiS_Pr, DACData, (data2 << sf));
808 data >>= 2;
809 }
810 }
811
812 if (time == 256) {
813 for (i = 16; i < 32; i++) {
814 data = table[i] << sf;
815 for (k = 0; k < 3; k++)
816 SiS_SetRegByte(SiS_Pr, DACData, data);
817 }
818 si = 32;
819 for (m = 0; m < 9; m++) {
820 di = si;
821 bx = si + 4;
822 for (n = 0; n < 3; n++) {
823 for (o = 0; o < 5; o++) {
824 SiS_WriteDAC(SiS_Pr, DACData, sf, n,
825 table[di], table[bx],
826 table[si]);
827 si++;
828 }
829 si -= 2;
830 for (o = 0; o < 3; o++) {
831 SiS_WriteDAC(SiS_Pr, DACData, sf, n,
832 table[di], table[si],
833 table[bx]);
834 si--;
835 }
836 }
837 si += 5;
838 }
839 }
840}
841
842/*********************************************/
843/* SET CRT1 REGISTER GROUP */
844/*********************************************/
845
846static void
847SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
848 unsigned short ModeIdIndex)
849{
850 unsigned short StandTableIndex, rrti;
851
852 SiS_Pr->SiS_CRT1Mode = ModeNo;
853
854 if (ModeNo <= 0x13)
855 StandTableIndex = 0;
856 else
857 StandTableIndex = 1;
858
859 SiS_ResetSegmentRegisters(SiS_Pr);
860 SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
861 SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
862 SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
863 SiS_SetATTRegs(SiS_Pr, StandTableIndex);
864 SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
865 SiS_ClearExt1Regs(SiS_Pr, ModeNo);
866
867 rrti = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
868
869 if (rrti != 0xFFFF) {
870 SiS_SetCRT1Sync(SiS_Pr, rrti);
871 SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, rrti);
872 SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, rrti);
873 SiS_SetCRT1VCLK(SiS_Pr, ModeNo, rrti);
874 }
875
876 SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
877
878 SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, rrti);
879
880 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
881
882 SiS_DisplayOn(SiS_Pr);
883}
884
885/*********************************************/
886/* SiSSetMode() */
887/*********************************************/
888
889int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
890{
891 unsigned short ModeIdIndex;
892 unsigned long BaseAddr = SiS_Pr->IOAddress;
893
894 SiSUSB_InitPtr(SiS_Pr);
895 SiSUSBRegInit(SiS_Pr, BaseAddr);
896 SiS_GetSysFlags(SiS_Pr);
897
898 if (!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex)))
899 return 0;
900
901 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x05, 0x86);
902
903 SiSInitPCIetc(SiS_Pr);
904
905 ModeNo &= 0x7f;
906
907 SiS_Pr->SiS_ModeType =
908 SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag & ModeTypeMask;
909
910 SiS_Pr->SiS_SetFlag = LowModeTests;
911
912 /* Set mode on CRT1 */
913 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
914
915 SiS_HandleCRT1(SiS_Pr);
916
917 SiS_DisplayOn(SiS_Pr);
918 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c6, 0xFF);
919
920 /* Store mode number */
921 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x34, ModeNo);
922
923 return 1;
924}
925
926int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo)
927{
928 unsigned short ModeNo = 0;
929 int i;
930
931 SiSUSB_InitPtr(SiS_Pr);
932
933 if (VModeNo == 0x03) {
934
935 ModeNo = 0x03;
936
937 } else {
938
939 i = 0;
940 do {
941
942 if (SiS_Pr->SiS_EModeIDTable[i].Ext_VESAID == VModeNo) {
943 ModeNo = SiS_Pr->SiS_EModeIDTable[i].Ext_ModeID;
944 break;
945 }
946
947 } while (SiS_Pr->SiS_EModeIDTable[i++].Ext_ModeID != 0xff);
948
949 }
950
951 if (!ModeNo)
952 return 0;
953
954 return SiSUSBSetMode(SiS_Pr, ModeNo);
955}
drivers/usb/misc/sisusbvga/sisusb_init.h+0−180
@@ -1,180 +0,0 @@
1/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2/* $XFree86$ */
3/* $XdotOrg$ */
4/*
5 * Data and prototypes for init.c
6 *
7 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
8 *
9 * If distributed as part of the Linux kernel, the following license terms
10 * apply:
11 *
12 * * This program is free software; you can redistribute it and/or modify
13 * * it under the terms of the GNU General Public License as published by
14 * * the Free Software Foundation; either version 2 of the named License,
15 * * or any later version.
16 * *
17 * * This program is distributed in the hope that it will be useful,
18 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * * GNU General Public License for more details.
21 * *
22 * * You should have received a copy of the GNU General Public License
23 * * along with this program; if not, write to the Free Software
24 * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
25 *
26 * Otherwise, the following license terms apply:
27 *
28 * * Redistribution and use in source and binary forms, with or without
29 * * modification, are permitted provided that the following conditions
30 * * are met:
31 * * 1) Redistributions of source code must retain the above copyright
32 * * notice, this list of conditions and the following disclaimer.
33 * * 2) Redistributions in binary form must reproduce the above copyright
34 * * notice, this list of conditions and the following disclaimer in the
35 * * documentation and/or other materials provided with the distribution.
36 * * 3) The name of the author may not be used to endorse or promote products
37 * * derived from this software without specific prior written permission.
38 * *
39 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
40 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
43 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
48 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 *
50 * Author: Thomas Winischhofer <thomas@winischhofer.net>
51 *
52 */
53
54#ifndef _SISUSB_INIT_H_
55#define _SISUSB_INIT_H_
56
57/* SiS_ModeType */
58#define ModeText 0x00
59#define ModeCGA 0x01
60#define ModeEGA 0x02
61#define ModeVGA 0x03
62#define Mode15Bpp 0x04
63#define Mode16Bpp 0x05
64#define Mode24Bpp 0x06
65#define Mode32Bpp 0x07
66
67#define ModeTypeMask 0x07
68#define IsTextMode 0x07
69
70#define DACInfoFlag 0x0018
71#define MemoryInfoFlag 0x01E0
72#define MemorySizeShift 5
73
74/* modeflag */
75#define Charx8Dot 0x0200
76#define LineCompareOff 0x0400
77#define CRT2Mode 0x0800
78#define HalfDCLK 0x1000
79#define NoSupportSimuTV 0x2000
80#define NoSupportLCDScale 0x4000 /* SiS bridge: No scaling possible (no matter what panel) */
81#define DoubleScanMode 0x8000
82
83/* Infoflag */
84#define SupportTV 0x0008
85#define SupportTV1024 0x0800
86#define SupportCHTV 0x0800
87#define Support64048060Hz 0x0800 /* Special for 640x480 LCD */
88#define SupportHiVision 0x0010
89#define SupportYPbPr750p 0x1000
90#define SupportLCD 0x0020
91#define SupportRAMDAC2 0x0040 /* All (<= 100Mhz) */
92#define SupportRAMDAC2_135 0x0100 /* All except DH (<= 135Mhz) */
93#define SupportRAMDAC2_162 0x0200 /* B, C (<= 162Mhz) */
94#define SupportRAMDAC2_202 0x0400 /* C (<= 202Mhz) */
95#define InterlaceMode 0x0080
96#define SyncPP 0x0000
97#define SyncPN 0x4000
98#define SyncNP 0x8000
99#define SyncNN 0xc000
100
101/* SetFlag */
102#define ProgrammingCRT2 0x0001
103#define LowModeTests 0x0002
104#define LCDVESATiming 0x0008
105#define EnableLVDSDDA 0x0010
106#define SetDispDevSwitchFlag 0x0020
107#define CheckWinDos 0x0040
108#define SetDOSMode 0x0080
109
110/* Index in ModeResInfo table */
111#define SIS_RI_320x200 0
112#define SIS_RI_320x240 1
113#define SIS_RI_320x400 2
114#define SIS_RI_400x300 3
115#define SIS_RI_512x384 4
116#define SIS_RI_640x400 5
117#define SIS_RI_640x480 6
118#define SIS_RI_800x600 7
119#define SIS_RI_1024x768 8
120#define SIS_RI_1280x1024 9
121#define SIS_RI_1600x1200 10
122#define SIS_RI_1920x1440 11
123#define SIS_RI_2048x1536 12
124#define SIS_RI_720x480 13
125#define SIS_RI_720x576 14
126#define SIS_RI_1280x960 15
127#define SIS_RI_800x480 16
128#define SIS_RI_1024x576 17
129#define SIS_RI_1280x720 18
130#define SIS_RI_856x480 19
131#define SIS_RI_1280x768 20
132#define SIS_RI_1400x1050 21
133#define SIS_RI_1152x864 22 /* Up to here SiS conforming */
134#define SIS_RI_848x480 23
135#define SIS_RI_1360x768 24
136#define SIS_RI_1024x600 25
137#define SIS_RI_1152x768 26
138#define SIS_RI_768x576 27
139#define SIS_RI_1360x1024 28
140#define SIS_RI_1680x1050 29
141#define SIS_RI_1280x800 30
142#define SIS_RI_1920x1080 31
143#define SIS_RI_960x540 32
144#define SIS_RI_960x600 33
145
146#define SIS_VIDEO_CAPTURE 0x00 - 0x30
147#define SIS_VIDEO_PLAYBACK 0x02 - 0x30
148#define SIS_CRT2_PORT_04 0x04 - 0x30
149
150int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
151int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo);
152
153extern int sisusb_setreg(struct sisusb_usb_data *sisusb, u32 port, u8 data);
154extern int sisusb_getreg(struct sisusb_usb_data *sisusb, u32 port, u8 * data);
155extern int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
156 u8 index, u8 data);
157extern int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,
158 u8 index, u8 * data);
159extern int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port,
160 u8 idx, u8 myand, u8 myor);
161extern int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,
162 u8 index, u8 myor);
163extern int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,
164 u8 idx, u8 myand);
165
166void sisusb_delete(struct kref *kref);
167int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data);
168int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 * data);
169int sisusb_copy_memory(struct sisusb_usb_data *sisusb, u8 *src,
170 u32 dest, int length);
171int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init);
172int sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
173 u8 * arg, int cmapsz, int ch512, int dorecalc,
174 struct vc_data *c, int fh, int uplock);
175void sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location);
176int sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last);
177void sisusb_console_exit(struct sisusb_usb_data *sisusb);
178void sisusb_init_concode(void);
179
180#endif
drivers/usb/misc/sisusbvga/sisusbvga.crenamed from drivers/usb/misc/sisusbvga/sisusb.c+7−282
@@ -51,25 +51,11 @@ · 50 unmodified lines
51#include <linux/vmalloc.h>51#include <linux/vmalloc.h>
52 52
53#include "sisusb.h"53#include "sisusb.h"
54#include "sisusb_init.h"
55
56#ifdef CONFIG_USB_SISUSBVGA_CON
57#include <linux/font.h>
58#endif
59 54
60#define SISUSB_DONTSYNC55#define SISUSB_DONTSYNC
61 56
62/* Forward declarations / clean-up routines */57/* Forward declarations / clean-up routines */
63 58
64#ifdef CONFIG_USB_SISUSBVGA_CON
65static int sisusb_first_vc;
66static int sisusb_last_vc;
67module_param_named(first, sisusb_first_vc, int, 0);
68module_param_named(last, sisusb_last_vc, int, 0);
69MODULE_PARM_DESC(first, "Number of first console to take over (1 - MAX_NR_CONSOLES)");
70MODULE_PARM_DESC(last, "Number of last console to take over (1 - MAX_NR_CONSOLES)");
71#endif
72
73static struct usb_driver sisusb_driver;59static struct usb_driver sisusb_driver;
74 60
75static void sisusb_free_buffers(struct sisusb_usb_data *sisusb)61static void sisusb_free_buffers(struct sisusb_usb_data *sisusb)
@@ -1198,19 +1184,7 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr, · 1122 unmodified lines
1198 1184
1199/* High level: Gfx (indexed) register access */1185/* High level: Gfx (indexed) register access */
1200 1186
1201#ifdef CONFIG_USB_SISUSBVGA_CON1187static int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
1202int sisusb_setreg(struct sisusb_usb_data *sisusb, u32 port, u8 data)
1203{
1204 return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
1205}
1206
1207int sisusb_getreg(struct sisusb_usb_data *sisusb, u32 port, u8 *data)
1208{
1209 return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
1210}
1211#endif
1212
1213int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
1214 u8 index, u8 data)1188 u8 index, u8 data)
1215{1189{
1216 int ret;1190 int ret;
@@ -1220,7 +1194,7 @@ int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port, · 3 unmodified lines
1220 return ret;1194 return ret;
1221}1195}
1222 1196
1223int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,1197static int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,
1224 u8 index, u8 *data)1198 u8 index, u8 *data)
1225{1199{
1226 int ret;1200 int ret;
@@ -1230,7 +1204,7 @@ int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port, · 3 unmodified lines
1230 return ret;1204 return ret;
1231}1205}
1232 1206
1233int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, u8 idx,1207static int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, u8 idx,
1234 u8 myand, u8 myor)1208 u8 myand, u8 myor)
1235{1209{
1236 int ret;1210 int ret;
@@ -1258,13 +1232,13 @@ static int sisusb_setidxregmask(struct sisusb_usb_data *sisusb, · 21 unmodified lines
1258 return ret;1232 return ret;
1259}1233}
1260 1234
1261int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,1235static int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,
1262 u8 index, u8 myor)1236 u8 index, u8 myor)
1263{1237{
1264 return sisusb_setidxregandor(sisusb, port, index, 0xff, myor);1238 return sisusb_setidxregandor(sisusb, port, index, 0xff, myor);
1265}1239}
1266 1240
1267int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,1241static int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,
1268 u8 idx, u8 myand)1242 u8 idx, u8 myand)
1269{1243{
1270 return sisusb_setidxregandor(sisusb, port, idx, myand, 0x00);1244 return sisusb_setidxregandor(sisusb, port, idx, myand, 0x00);
@@ -1272,38 +1246,6 @@ int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port, · 1 unmodified line
1272 1246
1273/* Write/read video ram */1247/* Write/read video ram */
1274 1248
1275#ifdef CONFIG_USB_SISUSBVGA_CON
1276int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data)
1277{
1278 return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data);
1279}
1280
1281int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data)
1282{
1283 return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data);
1284}
1285
1286int sisusb_copy_memory(struct sisusb_usb_data *sisusb, u8 *src,
1287 u32 dest, int length)
1288{
1289 size_t dummy;
1290
1291 return sisusb_write_mem_bulk(sisusb, dest, src, length,
1292 NULL, 0, &dummy);
1293}
1294
1295#ifdef SISUSBENDIANTEST
1296static int sisusb_read_memory(struct sisusb_usb_data *sisusb, char *dest,
1297 u32 src, int length)
1298{
1299 size_t dummy;
1300
1301 return sisusb_read_mem_bulk(sisusb, src, dest, length,
1302 NULL, &dummy);
1303}
1304#endif
1305#endif
1306
1307#ifdef SISUSBENDIANTEST1249#ifdef SISUSBENDIANTEST
1308static void sisusb_testreadwrite(struct sisusb_usb_data *sisusb)1250static void sisusb_testreadwrite(struct sisusb_usb_data *sisusb)
1309{1251{
@@ -2252,131 +2194,6 @@ static int sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen) · 942 unmodified lines
2252 return ret;2194 return ret;
2253}2195}
2254 2196
2255
2256#ifdef CONFIG_USB_SISUSBVGA_CON
2257
2258/* Set up default text mode:
2259 * - Set text mode (0x03)
2260 * - Upload default font
2261 * - Upload user font (if available)
2262 */
2263
2264int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
2265{
2266 int ret = 0, slot = sisusb->font_slot, i;
2267 const struct font_desc *myfont;
2268 u8 *tempbuf;
2269 u16 *tempbufb;
2270 static const char bootstring[] =
2271 "SiSUSB VGA text console, (C) 2005 Thomas Winischhofer.";
2272 static const char bootlogo[] = "(o_ //\\ V_/_";
2273
2274 /* sisusb->lock is down */
2275
2276 if (!sisusb->SiS_Pr)
2277 return 1;
2278
2279 sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
2280 sisusb->SiS_Pr->sisusb = (void *)sisusb;
2281
2282 /* Set mode 0x03 */
2283 SiSUSBSetMode(sisusb->SiS_Pr, 0x03);
2284
2285 myfont = find_font("VGA8x16");
2286 if (!myfont)
2287 return 1;
2288
2289 tempbuf = vmalloc(8192);
2290 if (!tempbuf)
2291 return 1;
2292
2293 for (i = 0; i < 256; i++)
2294 memcpy(tempbuf + (i * 32), myfont->data + (i * 16), 16);
2295
2296 /* Upload default font */
2297 ret = sisusbcon_do_font_op(sisusb, 1, 0, tempbuf, 8192,
2298 0, 1, NULL, 16, 0);
2299
2300 vfree(tempbuf);
2301
2302 /* Upload user font (and reset current slot) */
2303 if (sisusb->font_backup) {
2304 ret |= sisusbcon_do_font_op(sisusb, 1, 2, sisusb->font_backup,
2305 8192, sisusb->font_backup_512, 1, NULL,
2306 sisusb->font_backup_height, 0);
2307 if (slot != 2)
2308 sisusbcon_do_font_op(sisusb, 1, 0, NULL, 0, 0, 1,
2309 NULL, 16, 0);
2310 }
2311
2312 if (init && !sisusb->scrbuf) {
2313
2314 tempbuf = vmalloc(8192);
2315 if (tempbuf) {
2316
2317 i = 4096;
2318 tempbufb = (u16 *)tempbuf;
2319 while (i--)
2320 *(tempbufb++) = 0x0720;
2321
2322 i = 0;
2323 tempbufb = (u16 *)tempbuf;
2324 while (bootlogo[i]) {
2325 *(tempbufb++) = 0x0700 | bootlogo[i++];
2326 if (!(i % 4))
2327 tempbufb += 76;
2328 }
2329
2330 i = 0;
2331 tempbufb = (u16 *)tempbuf + 6;
2332 while (bootstring[i])
2333 *(tempbufb++) = 0x0700 | bootstring[i++];
2334
2335 ret |= sisusb_copy_memory(sisusb, tempbuf,
2336 sisusb->vrambase, 8192);
2337
2338 vfree(tempbuf);
2339
2340 }
2341
2342 } else if (sisusb->scrbuf) {
2343 ret |= sisusb_copy_memory(sisusb, (u8 *)sisusb->scrbuf,
2344 sisusb->vrambase, sisusb->scrbuf_size);
2345 }
2346
2347 if (sisusb->sisusb_cursor_size_from >= 0 &&
2348 sisusb->sisusb_cursor_size_to >= 0) {
2349 sisusb_setidxreg(sisusb, SISCR, 0x0a,
2350 sisusb->sisusb_cursor_size_from);
2351 sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0,
2352 sisusb->sisusb_cursor_size_to);
2353 } else {
2354 sisusb_setidxreg(sisusb, SISCR, 0x0a, 0x2d);
2355 sisusb_setidxreg(sisusb, SISCR, 0x0b, 0x0e);
2356 sisusb->sisusb_cursor_size_to = -1;
2357 }
2358
2359 slot = sisusb->sisusb_cursor_loc;
2360 if (slot < 0)
2361 slot = 0;
2362
2363 sisusb->sisusb_cursor_loc = -1;
2364 sisusb->bad_cursor_pos = 1;
2365
2366 sisusb_set_cursor(sisusb, slot);
2367
2368 sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
2369 sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
2370
2371 sisusb->textmodedestroyed = 0;
2372
2373 /* sisusb->lock is down */
2374
2375 return ret;
2376}
2377
2378#endif
2379
2380/* fops */2197/* fops */
2381 2198
2382static int sisusb_open(struct inode *inode, struct file *file)2199static int sisusb_open(struct inode *inode, struct file *file)
@@ -2434,7 +2251,7 @@ static int sisusb_open(struct inode *inode, struct file *file) · 51 unmodified lines
2434 return 0;2251 return 0;
2435}2252}
2436 2253
2437void sisusb_delete(struct kref *kref)2254static void sisusb_delete(struct kref *kref)
2438{2255{
2439 struct sisusb_usb_data *sisusb = to_sisusb_dev(kref);2256 struct sisusb_usb_data *sisusb = to_sisusb_dev(kref);
2440 2257
@@ -2446,9 +2263,6 @@ void sisusb_delete(struct kref *kref) · 5 unmodified lines
2446 sisusb->sisusb_dev = NULL;2263 sisusb->sisusb_dev = NULL;
2447 sisusb_free_buffers(sisusb);2264 sisusb_free_buffers(sisusb);
2448 sisusb_free_urbs(sisusb);2265 sisusb_free_urbs(sisusb);
2449#ifdef CONFIG_USB_SISUSBVGA_CON
2450 kfree(sisusb->SiS_Pr);
2451#endif
2452 kfree(sisusb);2266 kfree(sisusb);
2453}2267}
2454 2268
@@ -2842,54 +2656,8 @@ static int sisusb_handle_command(struct sisusb_usb_data *sisusb, · 387 unmodified lines
2842 2656
2843 case SUCMD_HANDLETEXTMODE:2657 case SUCMD_HANDLETEXTMODE:
2844 retval = 0;2658 retval = 0;
2845#ifdef CONFIG_USB_SISUSBVGA_CON
2846 /* Gfx core must be initialized, SiS_Pr must exist */
2847 if (!sisusb->gfxinit || !sisusb->SiS_Pr)
2848 return -ENODEV;
2849
2850 switch (y->data0) {
2851 case 0:
2852 retval = sisusb_reset_text_mode(sisusb, 0);
2853 break;
2854 case 1:
2855 sisusb->textmodedestroyed = 1;
2856 break;
2857 }
2858#endif
2859 break;
2860
2861#ifdef CONFIG_USB_SISUSBVGA_CON
2862 case SUCMD_SETMODE:
2863 /* Gfx core must be initialized, SiS_Pr must exist */
2864 if (!sisusb->gfxinit || !sisusb->SiS_Pr)
2865 return -ENODEV;
2866
2867 retval = 0;
2868
2869 sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
2870 sisusb->SiS_Pr->sisusb = (void *)sisusb;
2871
2872 if (SiSUSBSetMode(sisusb->SiS_Pr, y->data3))
2873 retval = -EINVAL;
2874
2875 break;2659 break;
2876 2660
2877 case SUCMD_SETVESAMODE:
2878 /* Gfx core must be initialized, SiS_Pr must exist */
2879 if (!sisusb->gfxinit || !sisusb->SiS_Pr)
2880 return -ENODEV;
2881
2882 retval = 0;
2883
2884 sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
2885 sisusb->SiS_Pr->sisusb = (void *)sisusb;
2886
2887 if (SiSUSBSetVESAMode(sisusb->SiS_Pr, y->data3))
2888 retval = -EINVAL;
2889
2890 break;
2891#endif
2892
2893 default:2661 default:
2894 retval = -EINVAL;2662 retval = -EINVAL;
2895 }2663 }
@@ -2942,11 +2710,7 @@ static long sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 46 unmodified lines
2942 x.sisusb_vramsize = sisusb->vramsize;2710 x.sisusb_vramsize = sisusb->vramsize;
2943 x.sisusb_minor = sisusb->minor;2711 x.sisusb_minor = sisusb->minor;
2944 x.sisusb_fbdevactive = 0;2712 x.sisusb_fbdevactive = 0;
2945#ifdef CONFIG_USB_SISUSBVGA_CON
2946 x.sisusb_conactive = sisusb->haveconsole ? 1 : 0;
2947#else
2948 x.sisusb_conactive = 0;2713 x.sisusb_conactive = 0;
2949#endif
2950 memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved));2714 memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved));
2951 2715
2952 if (copy_to_user((void __user *)arg, &x, sizeof(x)))2716 if (copy_to_user((void __user *)arg, &x, sizeof(x)))
@@ -3090,15 +2854,6 @@ static int sisusb_probe(struct usb_interface *intf, · 137 unmodified lines
3090 dev_info(&sisusb->sisusb_dev->dev, "Allocated %d output buffers\n",2854 dev_info(&sisusb->sisusb_dev->dev, "Allocated %d output buffers\n",
3091 sisusb->numobufs);2855 sisusb->numobufs);
3092 2856
3093#ifdef CONFIG_USB_SISUSBVGA_CON
3094 /* Allocate our SiS_Pr */
3095 sisusb->SiS_Pr = kmalloc(sizeof(struct SiS_Private), GFP_KERNEL);
3096 if (!sisusb->SiS_Pr) {
3097 retval = -ENOMEM;
3098 goto error_4;
3099 }
3100#endif
3101
3102 /* Do remaining init stuff */2857 /* Do remaining init stuff */
3103 2858
3104 init_waitqueue_head(&sisusb->wait_q);2859 init_waitqueue_head(&sisusb->wait_q);
@@ -3111,12 +2866,6 @@ static int sisusb_probe(struct usb_interface *intf, · 6 unmodified lines
3111 2866
3112 if (dev->speed == USB_SPEED_HIGH || dev->speed >= USB_SPEED_SUPER) {2867 if (dev->speed == USB_SPEED_HIGH || dev->speed >= USB_SPEED_SUPER) {
3113 int initscreen = 1;2868 int initscreen = 1;
3114#ifdef CONFIG_USB_SISUSBVGA_CON
3115 if (sisusb_first_vc > 0 && sisusb_last_vc > 0 &&
3116 sisusb_first_vc <= sisusb_last_vc &&
3117 sisusb_last_vc <= MAX_NR_CONSOLES)
3118 initscreen = 0;
3119#endif
3120 if (sisusb_init_gfxdevice(sisusb, initscreen))2869 if (sisusb_init_gfxdevice(sisusb, initscreen))
3121 dev_err(&sisusb->sisusb_dev->dev,2870 dev_err(&sisusb->sisusb_dev->dev,
3122 "Failed to early initialize device\n");2871 "Failed to early initialize device\n");
@@ -3133,10 +2882,6 @@ static int sisusb_probe(struct usb_interface *intf, · 10 unmodified lines
3133 dev_dbg(&sisusb->sisusb_dev->dev, "*** RWTEST END ***\n");2882 dev_dbg(&sisusb->sisusb_dev->dev, "*** RWTEST END ***\n");
3134#endif2883#endif
3135 2884
3136#ifdef CONFIG_USB_SISUSBVGA_CON
3137 sisusb_console_init(sisusb, sisusb_first_vc, sisusb_last_vc);
3138#endif
3139
3140 return 0;2885 return 0;
3141 2886
3142error_4:2887error_4:
@@ -3159,10 +2904,6 @@ static void sisusb_disconnect(struct usb_interface *intf) · 16 unmodified lines
3159 if (!sisusb)2904 if (!sisusb)
3160 return;2905 return;
3161 2906
3162#ifdef CONFIG_USB_SISUSBVGA_CON
3163 sisusb_console_exit(sisusb);
3164#endif
3165
3166 usb_deregister_dev(intf, &usb_sisusb_class);2907 usb_deregister_dev(intf, &usb_sisusb_class);
3167 2908
3168 mutex_lock(&sisusb->lock);2909 mutex_lock(&sisusb->lock);
@@ -3206,23 +2947,7 @@ static struct usb_driver sisusb_driver = { · 37 unmodified lines
3206 .id_table = sisusb_table,2947 .id_table = sisusb_table,
3207};2948};
3208 2949
3209static int __init usb_sisusb_init(void)2950module_usb_driver(sisusb_driver);
3210{
3211
3212#ifdef CONFIG_USB_SISUSBVGA_CON
3213 sisusb_init_concode();
3214#endif
3215
3216 return usb_register(&sisusb_driver);
3217}
3218
3219static void __exit usb_sisusb_exit(void)
3220{
3221 usb_deregister(&sisusb_driver);
3222}
3223
3224module_init(usb_sisusb_init);
3225module_exit(usb_sisusb_exit);
3226 2951
3227MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>");2952MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>");
3228MODULE_DESCRIPTION("sisusbvga - Driver for Net2280/SiS315-based USB2VGA dongles");2953MODULE_DESCRIPTION("sisusbvga - Driver for Net2280/SiS315-based USB2VGA dongles");
drivers/usb/misc/usb251xb.c+2−3
@@ -699,8 +699,7 @@ static int usb251xb_probe(struct usb251xb *hub) · 698 unmodified lines
699 return 0;699 return 0;
700}700}
701 701
702static int usb251xb_i2c_probe(struct i2c_client *i2c,702static int usb251xb_i2c_probe(struct i2c_client *i2c)
703 const struct i2c_device_id *id)
704{703{
705 struct usb251xb *hub;704 struct usb251xb *hub;
706 705
@@ -758,7 +757,7 @@ static struct i2c_driver usb251xb_i2c_driver = { · 51 unmodified lines
758 .of_match_table = of_match_ptr(usb251xb_of_match),757 .of_match_table = of_match_ptr(usb251xb_of_match),
759 .pm = &usb251xb_pm_ops,758 .pm = &usb251xb_pm_ops,
760 },759 },
761 .probe = usb251xb_i2c_probe,760 .probe_new = usb251xb_i2c_probe,
762 .id_table = usb251xb_id,761 .id_table = usb251xb_id,
763};762};
764 763
drivers/usb/misc/usb3503.c+2−3
@@ -280,8 +280,7 @@ err_clk: · 279 unmodified lines
280 return err;280 return err;
281}281}
282 282
283static int usb3503_i2c_probe(struct i2c_client *i2c,283static int usb3503_i2c_probe(struct i2c_client *i2c)
284 const struct i2c_device_id *id)
285{284{
286 struct usb3503 *hub;285 struct usb3503 *hub;
287 int err;286 int err;
@@ -400,7 +399,7 @@ static struct i2c_driver usb3503_i2c_driver = { · 112 unmodified lines
400 .pm = pm_ptr(&usb3503_i2c_pm_ops),399 .pm = pm_ptr(&usb3503_i2c_pm_ops),
401 .of_match_table = of_match_ptr(usb3503_of_match),400 .of_match_table = of_match_ptr(usb3503_of_match),
402 },401 },
403 .probe = usb3503_i2c_probe,402 .probe_new = usb3503_i2c_probe,
404 .remove = usb3503_i2c_remove,403 .remove = usb3503_i2c_remove,
405 .id_table = usb3503_id,404 .id_table = usb3503_id,
406};405};
drivers/usb/misc/usb4604.c+2−3
@@ -97,8 +97,7 @@ static int usb4604_probe(struct usb4604 *hub) · 96 unmodified lines
97 return usb4604_switch_mode(hub, hub->mode);97 return usb4604_switch_mode(hub, hub->mode);
98}98}
99 99
100static int usb4604_i2c_probe(struct i2c_client *i2c,100static int usb4604_i2c_probe(struct i2c_client *i2c)
101 const struct i2c_device_id *id)
102{101{
103 struct usb4604 *hub;102 struct usb4604 *hub;
104 103
@@ -155,7 +154,7 @@ static struct i2c_driver usb4604_i2c_driver = { · 50 unmodified lines
155 .pm = pm_ptr(&usb4604_i2c_pm_ops),154 .pm = pm_ptr(&usb4604_i2c_pm_ops),
156 .of_match_table = of_match_ptr(usb4604_of_match),155 .of_match_table = of_match_ptr(usb4604_of_match),
157 },156 },
158 .probe = usb4604_i2c_probe,157 .probe_new = usb4604_i2c_probe,
159 .id_table = usb4604_id,158 .id_table = usb4604_id,
160};159};
161module_i2c_driver(usb4604_i2c_driver);160module_i2c_driver(usb4604_i2c_driver);
drivers/usb/musb/Kconfig+0−18
@@ -70,12 +70,6 @@ config USB_MUSB_SUNXI · 69 unmodified lines
70 select GENERIC_PHY70 select GENERIC_PHY
71 select SUNXI_SRAM71 select SUNXI_SRAM
72 72
73config USB_MUSB_DAVINCI
74 tristate "DaVinci"
75 depends on ARCH_DAVINCI_DMx
76 depends on NOP_USB_XCEIV
77 depends on BROKEN
78
79config USB_MUSB_DA8XX73config USB_MUSB_DA8XX
80 tristate "DA8xx/OMAP-L1x"74 tristate "DA8xx/OMAP-L1x"
81 depends on ARCH_DAVINCI_DA8XX75 depends on ARCH_DAVINCI_DA8XX
@@ -94,11 +88,6 @@ config USB_MUSB_OMAP2PLUS · 12 unmodified lines
94 depends on OMAP_CONTROL_PHY || !OMAP_CONTROL_PHY88 depends on OMAP_CONTROL_PHY || !OMAP_CONTROL_PHY
95 select GENERIC_PHY89 select GENERIC_PHY
96 90
97config USB_MUSB_AM35X
98 tristate "AM35x"
99 depends on ARCH_OMAP
100 depends on NOP_USB_XCEIV
101
102config USB_MUSB_DSPS91config USB_MUSB_DSPS
103 tristate "TI DSPS platforms"92 tristate "TI DSPS platforms"
104 depends on ARCH_OMAP2PLUS || COMPILE_TEST93 depends on ARCH_OMAP2PLUS || COMPILE_TEST
@@ -113,7 +102,6 @@ config USB_MUSB_JZ4740 · 8 unmodified lines
113 depends on OF102 depends on OF
114 depends on MIPS || COMPILE_TEST103 depends on MIPS || COMPILE_TEST
115 depends on USB_MUSB_GADGET104 depends on USB_MUSB_GADGET
116 depends on USB=n || USB_OTG_DISABLE_EXTERNAL_HUB
117 select USB_ROLE_SWITCH105 select USB_ROLE_SWITCH
118 106
119config USB_MUSB_MEDIATEK107config USB_MUSB_MEDIATEK
@@ -161,12 +149,6 @@ config USB_INVENTRA_DMA · 41 unmodified lines
161 help149 help
162 Enable DMA transfers using Mentor's engine.150 Enable DMA transfers using Mentor's engine.
163 151
164config USB_TI_CPPI_DMA
165 bool 'TI CPPI (Davinci)'
166 depends on USB_MUSB_DAVINCI
167 help
168 Enable DMA transfers when TI CPPI DMA is available.
169
170config USB_TI_CPPI41_DMA152config USB_TI_CPPI41_DMA
171 bool 'TI CPPI 4.1'153 bool 'TI CPPI 4.1'
172 depends on (ARCH_OMAP || ARCH_DAVINCI_DA8XX) && DMADEVICES154 depends on (ARCH_OMAP || ARCH_DAVINCI_DA8XX) && DMADEVICES
drivers/usb/musb/Makefile+0−3
@@ -16,10 +16,8 @@ musb_hdrc-$(CONFIG_DEBUG_FS) += musb_debugfs.o · 15 unmodified lines
16 16
17# Hardware Glue Layer17# Hardware Glue Layer
18obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o18obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o
19obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o
20obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o19obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o
21obj-$(CONFIG_USB_MUSB_TUSB6010) += tusb6010.o20obj-$(CONFIG_USB_MUSB_TUSB6010) += tusb6010.o
22obj-$(CONFIG_USB_MUSB_DAVINCI) += davinci.o
23obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o21obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
24obj-$(CONFIG_USB_MUSB_UX500) += ux500.o22obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
25obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o23obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o
@@ -33,7 +31,6 @@ obj-$(CONFIG_USB_MUSB_POLARFIRE_SOC) += mpfs.o · 7 unmodified lines
33# though PIO is always there to back up DMA, and for ep031# though PIO is always there to back up DMA, and for ep0
34 32
35musb_hdrc-$(CONFIG_USB_INVENTRA_DMA) += musbhsdma.o33musb_hdrc-$(CONFIG_USB_INVENTRA_DMA) += musbhsdma.o
36musb_hdrc-$(CONFIG_USB_TI_CPPI_DMA) += cppi_dma.o
37musb_hdrc-$(CONFIG_USB_TUSB_OMAP_DMA) += tusb6010_omap.o34musb_hdrc-$(CONFIG_USB_TUSB_OMAP_DMA) += tusb6010_omap.o
38musb_hdrc-$(CONFIG_USB_UX500_DMA) += ux500_dma.o35musb_hdrc-$(CONFIG_USB_UX500_DMA) += ux500_dma.o
39musb_hdrc-$(CONFIG_USB_TI_CPPI41_DMA) += musb_cppi41.o36musb_hdrc-$(CONFIG_USB_TI_CPPI41_DMA) += musb_cppi41.o
drivers/usb/musb/am35x.c+0−610
@@ -1,610 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * Texas Instruments AM35x "glue layer"
5 *
6 * Copyright (c) 2010, by Texas Instruments
7 *
8 * Based on the DA8xx "glue layer" code.
9 * Copyright (c) 2008-2009, MontaVista Software, Inc. <source@mvista.com>
10 *
11 * This file is part of the Inventra Controller Driver for Linux.
12 */
13
14#include <linux/module.h>
15#include <linux/clk.h>
16#include <linux/err.h>
17#include <linux/io.h>
18#include <linux/platform_device.h>
19#include <linux/dma-mapping.h>
20#include <linux/usb/usb_phy_generic.h>
21#include <linux/platform_data/usb-omap.h>
22
23#include "musb_core.h"
24
25/*
26 * AM35x specific definitions
27 */
28/* USB 2.0 OTG module registers */
29#define USB_REVISION_REG 0x00
30#define USB_CTRL_REG 0x04
31#define USB_STAT_REG 0x08
32#define USB_EMULATION_REG 0x0c
33/* 0x10 Reserved */
34#define USB_AUTOREQ_REG 0x14
35#define USB_SRP_FIX_TIME_REG 0x18
36#define USB_TEARDOWN_REG 0x1c
37#define EP_INTR_SRC_REG 0x20
38#define EP_INTR_SRC_SET_REG 0x24
39#define EP_INTR_SRC_CLEAR_REG 0x28
40#define EP_INTR_MASK_REG 0x2c
41#define EP_INTR_MASK_SET_REG 0x30
42#define EP_INTR_MASK_CLEAR_REG 0x34
43#define EP_INTR_SRC_MASKED_REG 0x38
44#define CORE_INTR_SRC_REG 0x40
45#define CORE_INTR_SRC_SET_REG 0x44
46#define CORE_INTR_SRC_CLEAR_REG 0x48
47#define CORE_INTR_MASK_REG 0x4c
48#define CORE_INTR_MASK_SET_REG 0x50
49#define CORE_INTR_MASK_CLEAR_REG 0x54
50#define CORE_INTR_SRC_MASKED_REG 0x58
51/* 0x5c Reserved */
52#define USB_END_OF_INTR_REG 0x60
53
54/* Control register bits */
55#define AM35X_SOFT_RESET_MASK 1
56
57/* USB interrupt register bits */
58#define AM35X_INTR_USB_SHIFT 16
59#define AM35X_INTR_USB_MASK (0x1ff << AM35X_INTR_USB_SHIFT)
60#define AM35X_INTR_DRVVBUS 0x100
61#define AM35X_INTR_RX_SHIFT 16
62#define AM35X_INTR_TX_SHIFT 0
63#define AM35X_TX_EP_MASK 0xffff /* EP0 + 15 Tx EPs */
64#define AM35X_RX_EP_MASK 0xfffe /* 15 Rx EPs */
65#define AM35X_TX_INTR_MASK (AM35X_TX_EP_MASK << AM35X_INTR_TX_SHIFT)
66#define AM35X_RX_INTR_MASK (AM35X_RX_EP_MASK << AM35X_INTR_RX_SHIFT)
67
68#define USB_MENTOR_CORE_OFFSET 0x400
69
70struct am35x_glue {
71 struct device *dev;
72 struct platform_device *musb;
73 struct platform_device *phy;
74 struct clk *phy_clk;
75 struct clk *clk;
76};
77
78/*
79 * am35x_musb_enable - enable interrupts
80 */
81static void am35x_musb_enable(struct musb *musb)
82{
83 void __iomem *reg_base = musb->ctrl_base;
84 u32 epmask;
85
86 /* Workaround: setup IRQs through both register sets. */
87 epmask = ((musb->epmask & AM35X_TX_EP_MASK) << AM35X_INTR_TX_SHIFT) |
88 ((musb->epmask & AM35X_RX_EP_MASK) << AM35X_INTR_RX_SHIFT);
89
90 musb_writel(reg_base, EP_INTR_MASK_SET_REG, epmask);
91 musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK);
92
93 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
94 musb_writel(reg_base, CORE_INTR_SRC_SET_REG,
95 AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT);
96}
97
98/*
99 * am35x_musb_disable - disable HDRC and flush interrupts
100 */
101static void am35x_musb_disable(struct musb *musb)
102{
103 void __iomem *reg_base = musb->ctrl_base;
104
105 musb_writel(reg_base, CORE_INTR_MASK_CLEAR_REG, AM35X_INTR_USB_MASK);
106 musb_writel(reg_base, EP_INTR_MASK_CLEAR_REG,
107 AM35X_TX_INTR_MASK | AM35X_RX_INTR_MASK);
108 musb_writel(reg_base, USB_END_OF_INTR_REG, 0);
109}
110
111#define portstate(stmt) stmt
112
113static void am35x_musb_set_vbus(struct musb *musb, int is_on)
114{
115 WARN_ON(is_on && is_peripheral_active(musb));
116}
117
118#define POLL_SECONDS 2
119
120static void otg_timer(struct timer_list *t)
121{
122 struct musb *musb = from_timer(musb, t, dev_timer);
123 void __iomem *mregs = musb->mregs;
124 u8 devctl;
125 unsigned long flags;
126
127 /*
128 * We poll because AM35x's won't expose several OTG-critical
129 * status change events (from the transceiver) otherwise.
130 */
131 devctl = musb_readb(mregs, MUSB_DEVCTL);
132 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
133 usb_otg_state_string(musb->xceiv->otg->state));
134
135 spin_lock_irqsave(&musb->lock, flags);
136 switch (musb->xceiv->otg->state) {
137 case OTG_STATE_A_WAIT_BCON:
138 devctl &= ~MUSB_DEVCTL_SESSION;
139 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
140
141 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
142 if (devctl & MUSB_DEVCTL_BDEVICE) {
143 musb->xceiv->otg->state = OTG_STATE_B_IDLE;
144 MUSB_DEV_MODE(musb);
145 } else {
146 musb->xceiv->otg->state = OTG_STATE_A_IDLE;
147 MUSB_HST_MODE(musb);
148 }
149 break;
150 case OTG_STATE_A_WAIT_VFALL:
151 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
152 musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG,
153 MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT);
154 break;
155 case OTG_STATE_B_IDLE:
156 devctl = musb_readb(mregs, MUSB_DEVCTL);
157 if (devctl & MUSB_DEVCTL_BDEVICE)
158 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
159 else
160 musb->xceiv->otg->state = OTG_STATE_A_IDLE;
161 break;
162 default:
163 break;
164 }
165 spin_unlock_irqrestore(&musb->lock, flags);
166}
167
168static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
169{
170 static unsigned long last_timer;
171
172 if (timeout == 0)
173 timeout = jiffies + msecs_to_jiffies(3);
174
175 /* Never idle if active, or when VBUS timeout is not set as host */
176 if (musb->is_active || (musb->a_wait_bcon == 0 &&
177 musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) {
178 dev_dbg(musb->controller, "%s active, deleting timer\n",
179 usb_otg_state_string(musb->xceiv->otg->state));
180 del_timer(&musb->dev_timer);
181 last_timer = jiffies;
182 return;
183 }
184
185 if (time_after(last_timer, timeout) && timer_pending(&musb->dev_timer)) {
186 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n");
187 return;
188 }
189 last_timer = timeout;
190
191 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
192 usb_otg_state_string(musb->xceiv->otg->state),
193 jiffies_to_msecs(timeout - jiffies));
194 mod_timer(&musb->dev_timer, timeout);
195}
196
197static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
198{
199 struct musb *musb = hci;
200 void __iomem *reg_base = musb->ctrl_base;
201 struct device *dev = musb->controller;
202 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
203 struct omap_musb_board_data *data = plat->board_data;
204 unsigned long flags;
205 irqreturn_t ret = IRQ_NONE;
206 u32 epintr, usbintr;
207
208 spin_lock_irqsave(&musb->lock, flags);
209
210 /* Get endpoint interrupts */
211 epintr = musb_readl(reg_base, EP_INTR_SRC_MASKED_REG);
212
213 if (epintr) {
214 musb_writel(reg_base, EP_INTR_SRC_CLEAR_REG, epintr);
215
216 musb->int_rx =
217 (epintr & AM35X_RX_INTR_MASK) >> AM35X_INTR_RX_SHIFT;
218 musb->int_tx =
219 (epintr & AM35X_TX_INTR_MASK) >> AM35X_INTR_TX_SHIFT;
220 }
221
222 /* Get usb core interrupts */
223 usbintr = musb_readl(reg_base, CORE_INTR_SRC_MASKED_REG);
224 if (!usbintr && !epintr)
225 goto eoi;
226
227 if (usbintr) {
228 musb_writel(reg_base, CORE_INTR_SRC_CLEAR_REG, usbintr);
229
230 musb->int_usb =
231 (usbintr & AM35X_INTR_USB_MASK) >> AM35X_INTR_USB_SHIFT;
232 }
233 /*
234 * DRVVBUS IRQs are the only proxy we have (a very poor one!) for
235 * AM35x's missing ID change IRQ. We need an ID change IRQ to
236 * switch appropriately between halves of the OTG state machine.
237 * Managing DEVCTL.SESSION per Mentor docs requires that we know its
238 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
239 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
240 */
241 if (usbintr & (AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT)) {
242 int drvvbus = musb_readl(reg_base, USB_STAT_REG);
243 void __iomem *mregs = musb->mregs;
244 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
245 int err;
246
247 err = musb->int_usb & MUSB_INTR_VBUSERROR;
248 if (err) {
249 /*
250 * The Mentor core doesn't debounce VBUS as needed
251 * to cope with device connect current spikes. This
252 * means it's not uncommon for bus-powered devices
253 * to get VBUS errors during enumeration.
254 *
255 * This is a workaround, but newer RTL from Mentor
256 * seems to allow a better one: "re"-starting sessions
257 * without waiting for VBUS to stop registering in
258 * devctl.
259 */
260 musb->int_usb &= ~MUSB_INTR_VBUSERROR;
261 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
262 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
263 WARNING("VBUS error workaround (delay coming)\n");
264 } else if (drvvbus) {
265 MUSB_HST_MODE(musb);
266 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
267 portstate(musb->port1_status |= USB_PORT_STAT_POWER);
268 del_timer(&musb->dev_timer);
269 } else {
270 musb->is_active = 0;
271 MUSB_DEV_MODE(musb);
272 musb->xceiv->otg->state = OTG_STATE_B_IDLE;
273 portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
274 }
275
276 /* NOTE: this must complete power-on within 100 ms. */
277 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
278 drvvbus ? "on" : "off",
279 usb_otg_state_string(musb->xceiv->otg->state),
280 err ? " ERROR" : "",
281 devctl);
282 ret = IRQ_HANDLED;
283 }
284
285 /* Drop spurious RX and TX if device is disconnected */
286 if (musb->int_usb & MUSB_INTR_DISCONNECT) {
287 musb->int_tx = 0;
288 musb->int_rx = 0;
289 }
290
291 if (musb->int_tx || musb->int_rx || musb->int_usb)
292 ret |= musb_interrupt(musb);
293
294eoi:
295 /* EOI needs to be written for the IRQ to be re-asserted. */
296 if (ret == IRQ_HANDLED || epintr || usbintr) {
297 /* clear level interrupt */
298 if (data->clear_irq)
299 data->clear_irq();
300 /* write EOI */
301 musb_writel(reg_base, USB_END_OF_INTR_REG, 0);
302 }
303
304 /* Poll for ID change */
305 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE)
306 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
307
308 spin_unlock_irqrestore(&musb->lock, flags);
309
310 return ret;
311}
312
313static int am35x_musb_set_mode(struct musb *musb, u8 musb_mode)
314{
315 struct device *dev = musb->controller;
316 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
317 struct omap_musb_board_data *data = plat->board_data;
318 int retval = 0;
319
320 if (data->set_mode)
321 data->set_mode(musb_mode);
322 else
323 retval = -EIO;
324
325 return retval;
326}
327
328static int am35x_musb_init(struct musb *musb)
329{
330 struct device *dev = musb->controller;
331 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
332 struct omap_musb_board_data *data = plat->board_data;
333 void __iomem *reg_base = musb->ctrl_base;
334 u32 rev;
335
336 musb->mregs += USB_MENTOR_CORE_OFFSET;
337
338 /* Returns zero if e.g. not clocked */
339 rev = musb_readl(reg_base, USB_REVISION_REG);
340 if (!rev)
341 return -ENODEV;
342
343 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
344 if (IS_ERR_OR_NULL(musb->xceiv))
345 return -EPROBE_DEFER;
346
347 timer_setup(&musb->dev_timer, otg_timer, 0);
348
349 /* Reset the musb */
350 if (data->reset)
351 data->reset();
352
353 /* Reset the controller */
354 musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK);
355
356 /* Start the on-chip PHY and its PLL. */
357 if (data->set_phy_power)
358 data->set_phy_power(1);
359
360 msleep(5);
361
362 musb->isr = am35x_musb_interrupt;
363
364 /* clear level interrupt */
365 if (data->clear_irq)
366 data->clear_irq();
367
368 return 0;
369}
370
371static int am35x_musb_exit(struct musb *musb)
372{
373 struct device *dev = musb->controller;
374 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
375 struct omap_musb_board_data *data = plat->board_data;
376
377 del_timer_sync(&musb->dev_timer);
378
379 /* Shutdown the on-chip PHY and its PLL. */
380 if (data->set_phy_power)
381 data->set_phy_power(0);
382
383 usb_put_phy(musb->xceiv);
384
385 return 0;
386}
387
388/* AM35x supports only 32bit read operation */
389static void am35x_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
390{
391 void __iomem *fifo = hw_ep->fifo;
392 u32 val;
393 int i;
394
395 /* Read for 32bit-aligned destination address */
396 if (likely((0x03 & (unsigned long) dst) == 0) && len >= 4) {
397 readsl(fifo, dst, len >> 2);
398 dst += len & ~0x03;
399 len &= 0x03;
400 }
401 /*
402 * Now read the remaining 1 to 3 byte or complete length if
403 * unaligned address.
404 */
405 if (len > 4) {
406 for (i = 0; i < (len >> 2); i++) {
407 *(u32 *) dst = musb_readl(fifo, 0);
408 dst += 4;
409 }
410 len &= 0x03;
411 }
412 if (len > 0) {
413 val = musb_readl(fifo, 0);
414 memcpy(dst, &val, len);
415 }
416}
417
418static const struct musb_platform_ops am35x_ops = {
419 .quirks = MUSB_DMA_INVENTRA | MUSB_INDEXED_EP,
420 .init = am35x_musb_init,
421 .exit = am35x_musb_exit,
422
423 .read_fifo = am35x_read_fifo,
424#ifdef CONFIG_USB_INVENTRA_DMA
425 .dma_init = musbhs_dma_controller_create,
426 .dma_exit = musbhs_dma_controller_destroy,
427#endif
428 .enable = am35x_musb_enable,
429 .disable = am35x_musb_disable,
430
431 .set_mode = am35x_musb_set_mode,
432 .try_idle = am35x_musb_try_idle,
433
434 .set_vbus = am35x_musb_set_vbus,
435};
436
437static const struct platform_device_info am35x_dev_info = {
438 .name = "musb-hdrc",
439 .id = PLATFORM_DEVID_AUTO,
440 .dma_mask = DMA_BIT_MASK(32),
441};
442
443static int am35x_probe(struct platform_device *pdev)
444{
445 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
446 struct platform_device *musb;
447 struct am35x_glue *glue;
448 struct platform_device_info pinfo;
449 struct clk *phy_clk;
450 struct clk *clk;
451
452 int ret = -ENOMEM;
453
454 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
455 if (!glue)
456 goto err0;
457
458 phy_clk = clk_get(&pdev->dev, "fck");
459 if (IS_ERR(phy_clk)) {
460 dev_err(&pdev->dev, "failed to get PHY clock\n");
461 ret = PTR_ERR(phy_clk);
462 goto err3;
463 }
464
465 clk = clk_get(&pdev->dev, "ick");
466 if (IS_ERR(clk)) {
467 dev_err(&pdev->dev, "failed to get clock\n");
468 ret = PTR_ERR(clk);
469 goto err4;
470 }
471
472 ret = clk_enable(phy_clk);
473 if (ret) {
474 dev_err(&pdev->dev, "failed to enable PHY clock\n");
475 goto err5;
476 }
477
478 ret = clk_enable(clk);
479 if (ret) {
480 dev_err(&pdev->dev, "failed to enable clock\n");
481 goto err6;
482 }
483
484 glue->dev = &pdev->dev;
485 glue->phy_clk = phy_clk;
486 glue->clk = clk;
487
488 pdata->platform_ops = &am35x_ops;
489
490 glue->phy = usb_phy_generic_register();
491 if (IS_ERR(glue->phy)) {
492 ret = PTR_ERR(glue->phy);
493 goto err7;
494 }
495 platform_set_drvdata(pdev, glue);
496
497 pinfo = am35x_dev_info;
498 pinfo.parent = &pdev->dev;
499 pinfo.res = pdev->resource;
500 pinfo.num_res = pdev->num_resources;
501 pinfo.data = pdata;
502 pinfo.size_data = sizeof(*pdata);
503 pinfo.fwnode = of_fwnode_handle(pdev->dev.of_node);
504 pinfo.of_node_reused = true;
505
506 glue->musb = musb = platform_device_register_full(&pinfo);
507 if (IS_ERR(musb)) {
508 ret = PTR_ERR(musb);
509 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
510 goto err8;
511 }
512
513 return 0;
514
515err8:
516 usb_phy_generic_unregister(glue->phy);
517
518err7:
519 clk_disable(clk);
520
521err6:
522 clk_disable(phy_clk);
523
524err5:
525 clk_put(clk);
526
527err4:
528 clk_put(phy_clk);
529
530err3:
531 kfree(glue);
532
533err0:
534 return ret;
535}
536
537static int am35x_remove(struct platform_device *pdev)
538{
539 struct am35x_glue *glue = platform_get_drvdata(pdev);
540
541 platform_device_unregister(glue->musb);
542 usb_phy_generic_unregister(glue->phy);
543 clk_disable(glue->clk);
544 clk_disable(glue->phy_clk);
545 clk_put(glue->clk);
546 clk_put(glue->phy_clk);
547 kfree(glue);
548
549 return 0;
550}
551
552#ifdef CONFIG_PM_SLEEP
553static int am35x_suspend(struct device *dev)
554{
555 struct am35x_glue *glue = dev_get_drvdata(dev);
556 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
557 struct omap_musb_board_data *data = plat->board_data;
558
559 /* Shutdown the on-chip PHY and its PLL. */
560 if (data->set_phy_power)
561 data->set_phy_power(0);
562
563 clk_disable(glue->phy_clk);
564 clk_disable(glue->clk);
565
566 return 0;
567}
568
569static int am35x_resume(struct device *dev)
570{
571 struct am35x_glue *glue = dev_get_drvdata(dev);
572 struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
573 struct omap_musb_board_data *data = plat->board_data;
574 int ret;
575
576 /* Start the on-chip PHY and its PLL. */
577 if (data->set_phy_power)
578 data->set_phy_power(1);
579
580 ret = clk_enable(glue->phy_clk);
581 if (ret) {
582 dev_err(dev, "failed to enable PHY clock\n");
583 return ret;
584 }
585
586 ret = clk_enable(glue->clk);
587 if (ret) {
588 dev_err(dev, "failed to enable clock\n");
589 return ret;
590 }
591
592 return 0;
593}
594#endif
595
596static SIMPLE_DEV_PM_OPS(am35x_pm_ops, am35x_suspend, am35x_resume);
597
598static struct platform_driver am35x_driver = {
599 .probe = am35x_probe,
600 .remove = am35x_remove,
601 .driver = {
602 .name = "musb-am35x",
603 .pm = &am35x_pm_ops,
604 },
605};
606
607MODULE_DESCRIPTION("AM35x MUSB Glue Layer");
608MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
609MODULE_LICENSE("GPL v2");
610module_platform_driver(am35x_driver);
drivers/usb/musb/cppi_dma.c+0−1547
@@ -1,1547 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2005-2006 by Texas Instruments
4 *
5 * This file implements a DMA interface using TI's CPPI DMA.
6 * For now it's DaVinci-only, but CPPI isn't specific to DaVinci or USB.
7 * The TUSB6020, using VLYNQ, has CPPI that looks much like DaVinci.
8 */
9
10#include <linux/module.h>
11#include <linux/platform_device.h>
12#include <linux/slab.h>
13#include <linux/usb.h>
14
15#include "musb_core.h"
16#include "musb_debug.h"
17#include "cppi_dma.h"
18#include "davinci.h"
19
20
21/* CPPI DMA status 7-mar-2006:
22 *
23 * - See musb_{host,gadget}.c for more info
24 *
25 * - Correct RX DMA generally forces the engine into irq-per-packet mode,
26 * which can easily saturate the CPU under non-mass-storage loads.
27 *
28 * NOTES 24-aug-2006 (2.6.18-rc4):
29 *
30 * - peripheral RXDMA wedged in a test with packets of length 512/512/1.
31 * evidently after the 1 byte packet was received and acked, the queue
32 * of BDs got garbaged so it wouldn't empty the fifo. (rxcsr 0x2003,
33 * and RX DMA0: 4 left, 80000000 8feff880, 8feff860 8feff860; 8f321401
34 * 004001ff 00000001 .. 8feff860) Host was just getting NAKed on tx
35 * of its next (512 byte) packet. IRQ issues?
36 *
37 * REVISIT: the "transfer DMA" glue between CPPI and USB fifos will
38 * evidently also directly update the RX and TX CSRs ... so audit all
39 * host and peripheral side DMA code to avoid CSR access after DMA has
40 * been started.
41 */
42
43/* REVISIT now we can avoid preallocating these descriptors; or
44 * more simply, switch to a global freelist not per-channel ones.
45 * Note: at full speed, 64 descriptors == 4K bulk data.
46 */
47#define NUM_TXCHAN_BD 64
48#define NUM_RXCHAN_BD 64
49
50static inline void cpu_drain_writebuffer(void)
51{
52 wmb();
53#ifdef CONFIG_CPU_ARM926T
54 /* REVISIT this "should not be needed",
55 * but lack of it sure seemed to hurt ...
56 */
57 asm("mcr p15, 0, r0, c7, c10, 4 @ drain write buffer\n");
58#endif
59}
60
61static inline struct cppi_descriptor *cppi_bd_alloc(struct cppi_channel *c)
62{
63 struct cppi_descriptor *bd = c->freelist;
64
65 if (bd)
66 c->freelist = bd->next;
67 return bd;
68}
69
70static inline void
71cppi_bd_free(struct cppi_channel *c, struct cppi_descriptor *bd)
72{
73 if (!bd)
74 return;
75 bd->next = c->freelist;
76 c->freelist = bd;
77}
78
79/*
80 * Start DMA controller
81 *
82 * Initialize the DMA controller as necessary.
83 */
84
85/* zero out entire rx state RAM entry for the channel */
86static void cppi_reset_rx(struct cppi_rx_stateram __iomem *rx)
87{
88 musb_writel(&rx->rx_skipbytes, 0, 0);
89 musb_writel(&rx->rx_head, 0, 0);
90 musb_writel(&rx->rx_sop, 0, 0);
91 musb_writel(&rx->rx_current, 0, 0);
92 musb_writel(&rx->rx_buf_current, 0, 0);
93 musb_writel(&rx->rx_len_len, 0, 0);
94 musb_writel(&rx->rx_cnt_cnt, 0, 0);
95}
96
97/* zero out entire tx state RAM entry for the channel */
98static void cppi_reset_tx(struct cppi_tx_stateram __iomem *tx, u32 ptr)
99{
100 musb_writel(&tx->tx_head, 0, 0);
101 musb_writel(&tx->tx_buf, 0, 0);
102 musb_writel(&tx->tx_current, 0, 0);
103 musb_writel(&tx->tx_buf_current, 0, 0);
104 musb_writel(&tx->tx_info, 0, 0);
105 musb_writel(&tx->tx_rem_len, 0, 0);
106 /* musb_writel(&tx->tx_dummy, 0, 0); */
107 musb_writel(&tx->tx_complete, 0, ptr);
108}
109
110static void cppi_pool_init(struct cppi *cppi, struct cppi_channel *c)
111{
112 int j;
113
114 /* initialize channel fields */
115 c->head = NULL;
116 c->tail = NULL;
117 c->last_processed = NULL;
118 c->channel.status = MUSB_DMA_STATUS_UNKNOWN;
119 c->controller = cppi;
120 c->is_rndis = 0;
121 c->freelist = NULL;
122
123 /* build the BD Free list for the channel */
124 for (j = 0; j < NUM_TXCHAN_BD + 1; j++) {
125 struct cppi_descriptor *bd;
126 dma_addr_t dma;
127
128 bd = dma_pool_alloc(cppi->pool, GFP_KERNEL, &dma);
129 bd->dma = dma;
130 cppi_bd_free(c, bd);
131 }
132}
133
134static int cppi_channel_abort(struct dma_channel *);
135
136static void cppi_pool_free(struct cppi_channel *c)
137{
138 struct cppi *cppi = c->controller;
139 struct cppi_descriptor *bd;
140
141 (void) cppi_channel_abort(&c->channel);
142 c->channel.status = MUSB_DMA_STATUS_UNKNOWN;
143 c->controller = NULL;
144
145 /* free all its bds */
146 bd = c->last_processed;
147 do {
148 if (bd)
149 dma_pool_free(cppi->pool, bd, bd->dma);
150 bd = cppi_bd_alloc(c);
151 } while (bd);
152 c->last_processed = NULL;
153}
154
155static void cppi_controller_start(struct cppi *controller)
156{
157 void __iomem *tibase;
158 int i;
159
160 /* do whatever is necessary to start controller */
161 for (i = 0; i < ARRAY_SIZE(controller->tx); i++) {
162 controller->tx[i].transmit = true;
163 controller->tx[i].index = i;
164 }
165 for (i = 0; i < ARRAY_SIZE(controller->rx); i++) {
166 controller->rx[i].transmit = false;
167 controller->rx[i].index = i;
168 }
169
170 /* setup BD list on a per channel basis */
171 for (i = 0; i < ARRAY_SIZE(controller->tx); i++)
172 cppi_pool_init(controller, controller->tx + i);
173 for (i = 0; i < ARRAY_SIZE(controller->rx); i++)
174 cppi_pool_init(controller, controller->rx + i);
175
176 tibase = controller->tibase;
177 INIT_LIST_HEAD(&controller->tx_complete);
178
179 /* initialise tx/rx channel head pointers to zero */
180 for (i = 0; i < ARRAY_SIZE(controller->tx); i++) {
181 struct cppi_channel *tx_ch = controller->tx + i;
182 struct cppi_tx_stateram __iomem *tx;
183
184 INIT_LIST_HEAD(&tx_ch->tx_complete);
185
186 tx = tibase + DAVINCI_TXCPPI_STATERAM_OFFSET(i);
187 tx_ch->state_ram = tx;
188 cppi_reset_tx(tx, 0);
189 }
190 for (i = 0; i < ARRAY_SIZE(controller->rx); i++) {
191 struct cppi_channel *rx_ch = controller->rx + i;
192 struct cppi_rx_stateram __iomem *rx;
193
194 INIT_LIST_HEAD(&rx_ch->tx_complete);
195
196 rx = tibase + DAVINCI_RXCPPI_STATERAM_OFFSET(i);
197 rx_ch->state_ram = rx;
198 cppi_reset_rx(rx);
199 }
200
201 /* enable individual cppi channels */
202 musb_writel(tibase, DAVINCI_TXCPPI_INTENAB_REG,
203 DAVINCI_DMA_ALL_CHANNELS_ENABLE);
204 musb_writel(tibase, DAVINCI_RXCPPI_INTENAB_REG,
205 DAVINCI_DMA_ALL_CHANNELS_ENABLE);
206
207 /* enable tx/rx CPPI control */
208 musb_writel(tibase, DAVINCI_TXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_ENABLE);
209 musb_writel(tibase, DAVINCI_RXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_ENABLE);
210
211 /* disable RNDIS mode, also host rx RNDIS autorequest */
212 musb_writel(tibase, DAVINCI_RNDIS_REG, 0);
213 musb_writel(tibase, DAVINCI_AUTOREQ_REG, 0);
214}
215
216/*
217 * Stop DMA controller
218 *
219 * De-Init the DMA controller as necessary.
220 */
221
222static void cppi_controller_stop(struct cppi *controller)
223{
224 void __iomem *tibase;
225 int i;
226 struct musb *musb;
227
228 musb = controller->controller.musb;
229
230 tibase = controller->tibase;
231 /* DISABLE INDIVIDUAL CHANNEL Interrupts */
232 musb_writel(tibase, DAVINCI_TXCPPI_INTCLR_REG,
233 DAVINCI_DMA_ALL_CHANNELS_ENABLE);
234 musb_writel(tibase, DAVINCI_RXCPPI_INTCLR_REG,
235 DAVINCI_DMA_ALL_CHANNELS_ENABLE);
236
237 musb_dbg(musb, "Tearing down RX and TX Channels");
238 for (i = 0; i < ARRAY_SIZE(controller->tx); i++) {
239 /* FIXME restructure of txdma to use bds like rxdma */
240 controller->tx[i].last_processed = NULL;
241 cppi_pool_free(controller->tx + i);
242 }
243 for (i = 0; i < ARRAY_SIZE(controller->rx); i++)
244 cppi_pool_free(controller->rx + i);
245
246 /* in Tx Case proper teardown is supported. We resort to disabling
247 * Tx/Rx CPPI after cleanup of Tx channels. Before TX teardown is
248 * complete TX CPPI cannot be disabled.
249 */
250 /*disable tx/rx cppi */
251 musb_writel(tibase, DAVINCI_TXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE);
252 musb_writel(tibase, DAVINCI_RXCPPI_CTRL_REG, DAVINCI_DMA_CTRL_DISABLE);
253}
254
255/* While dma channel is allocated, we only want the core irqs active
256 * for fault reports, otherwise we'd get irqs that we don't care about.
257 * Except for TX irqs, where dma done != fifo empty and reusable ...
258 *
259 * NOTE: docs don't say either way, but irq masking **enables** irqs.
260 *
261 * REVISIT same issue applies to pure PIO usage too, and non-cppi dma...
262 */
263static inline void core_rxirq_disable(void __iomem *tibase, unsigned epnum)
264{
265 musb_writel(tibase, DAVINCI_USB_INT_MASK_CLR_REG, 1 << (epnum + 8));
266}
267
268static inline void core_rxirq_enable(void __iomem *tibase, unsigned epnum)
269{
270 musb_writel(tibase, DAVINCI_USB_INT_MASK_SET_REG, 1 << (epnum + 8));
271}
272
273
274/*
275 * Allocate a CPPI Channel for DMA. With CPPI, channels are bound to
276 * each transfer direction of a non-control endpoint, so allocating
277 * (and deallocating) is mostly a way to notice bad housekeeping on
278 * the software side. We assume the irqs are always active.
279 */
280static struct dma_channel *
281cppi_channel_allocate(struct dma_controller *c,
282 struct musb_hw_ep *ep, u8 transmit)
283{
284 struct cppi *controller;
285 u8 index;
286 struct cppi_channel *cppi_ch;
287 void __iomem *tibase;
288 struct musb *musb;
289
290 controller = container_of(c, struct cppi, controller);
291 tibase = controller->tibase;
292 musb = c->musb;
293
294 /* ep0 doesn't use DMA; remember cppi indices are 0..N-1 */
295 index = ep->epnum - 1;
296
297 /* return the corresponding CPPI Channel Handle, and
298 * probably disable the non-CPPI irq until we need it.
299 */
300 if (transmit) {
301 if (index >= ARRAY_SIZE(controller->tx)) {
302 musb_dbg(musb, "no %cX%d CPPI channel", 'T', index);
303 return NULL;
304 }
305 cppi_ch = controller->tx + index;
306 } else {
307 if (index >= ARRAY_SIZE(controller->rx)) {
308 musb_dbg(musb, "no %cX%d CPPI channel", 'R', index);
309 return NULL;
310 }
311 cppi_ch = controller->rx + index;
312 core_rxirq_disable(tibase, ep->epnum);
313 }
314
315 /* REVISIT make this an error later once the same driver code works
316 * with the other DMA engine too
317 */
318 if (cppi_ch->hw_ep)
319 musb_dbg(musb, "re-allocating DMA%d %cX channel %p",
320 index, transmit ? 'T' : 'R', cppi_ch);
321 cppi_ch->hw_ep = ep;
322 cppi_ch->channel.status = MUSB_DMA_STATUS_FREE;
323 cppi_ch->channel.max_len = 0x7fffffff;
324
325 musb_dbg(musb, "Allocate CPPI%d %cX", index, transmit ? 'T' : 'R');
326 return &cppi_ch->channel;
327}
328
329/* Release a CPPI Channel. */
330static void cppi_channel_release(struct dma_channel *channel)
331{
332 struct cppi_channel *c;
333 void __iomem *tibase;
334
335 /* REVISIT: for paranoia, check state and abort if needed... */
336
337 c = container_of(channel, struct cppi_channel, channel);
338 tibase = c->controller->tibase;
339 if (!c->hw_ep)
340 musb_dbg(c->controller->controller.musb,
341 "releasing idle DMA channel %p", c);
342 else if (!c->transmit)
343 core_rxirq_enable(tibase, c->index + 1);
344
345 /* for now, leave its cppi IRQ enabled (we won't trigger it) */
346 c->hw_ep = NULL;
347 channel->status = MUSB_DMA_STATUS_UNKNOWN;
348}
349
350/* Context: controller irqlocked */
351static void
352cppi_dump_rx(int level, struct cppi_channel *c, const char *tag)
353{
354 void __iomem *base = c->controller->mregs;
355 struct cppi_rx_stateram __iomem *rx = c->state_ram;
356
357 musb_ep_select(base, c->index + 1);
358
359 musb_dbg(c->controller->controller.musb,
360 "RX DMA%d%s: %d left, csr %04x, "
361 "%08x H%08x S%08x C%08x, "
362 "B%08x L%08x %08x .. %08x",
363 c->index, tag,
364 musb_readl(c->controller->tibase,
365 DAVINCI_RXCPPI_BUFCNT0_REG + 4 * c->index),
366 musb_readw(c->hw_ep->regs, MUSB_RXCSR),
367
368 musb_readl(&rx->rx_skipbytes, 0),
369 musb_readl(&rx->rx_head, 0),
370 musb_readl(&rx->rx_sop, 0),
371 musb_readl(&rx->rx_current, 0),
372
373 musb_readl(&rx->rx_buf_current, 0),
374 musb_readl(&rx->rx_len_len, 0),
375 musb_readl(&rx->rx_cnt_cnt, 0),
376 musb_readl(&rx->rx_complete, 0)
377 );
378}
379
380/* Context: controller irqlocked */
381static void
382cppi_dump_tx(int level, struct cppi_channel *c, const char *tag)
383{
384 void __iomem *base = c->controller->mregs;
385 struct cppi_tx_stateram __iomem *tx = c->state_ram;
386
387 musb_ep_select(base, c->index + 1);
388
389 musb_dbg(c->controller->controller.musb,
390 "TX DMA%d%s: csr %04x, "
391 "H%08x S%08x C%08x %08x, "
392 "F%08x L%08x .. %08x",
393 c->index, tag,
394 musb_readw(c->hw_ep->regs, MUSB_TXCSR),
395
396 musb_readl(&tx->tx_head, 0),
397 musb_readl(&tx->tx_buf, 0),
398 musb_readl(&tx->tx_current, 0),
399 musb_readl(&tx->tx_buf_current, 0),
400
401 musb_readl(&tx->tx_info, 0),
402 musb_readl(&tx->tx_rem_len, 0),
403 /* dummy/unused word 6 */
404 musb_readl(&tx->tx_complete, 0)
405 );
406}
407
408/* Context: controller irqlocked */
409static inline void
410cppi_rndis_update(struct cppi_channel *c, int is_rx,
411 void __iomem *tibase, int is_rndis)
412{
413 /* we may need to change the rndis flag for this cppi channel */
414 if (c->is_rndis != is_rndis) {
415 u32 value = musb_readl(tibase, DAVINCI_RNDIS_REG);
416 u32 temp = 1 << (c->index);
417
418 if (is_rx)
419 temp <<= 16;
420 if (is_rndis)
421 value |= temp;
422 else
423 value &= ~temp;
424 musb_writel(tibase, DAVINCI_RNDIS_REG, value);
425 c->is_rndis = is_rndis;
426 }
427}
428
429static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd)
430{
431 pr_debug("RXBD/%s %08x: "
432 "nxt %08x buf %08x off.blen %08x opt.plen %08x\n",
433 tag, bd->dma,
434 bd->hw_next, bd->hw_bufp, bd->hw_off_len,
435 bd->hw_options);
436}
437
438static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx)
439{
440 struct cppi_descriptor *bd;
441
442 cppi_dump_rx(level, rx, tag);
443 if (rx->last_processed)
444 cppi_dump_rxbd("last", rx->last_processed);
445 for (bd = rx->head; bd; bd = bd->next)
446 cppi_dump_rxbd("active", bd);
447}
448
449
450/* NOTE: DaVinci autoreq is ignored except for host side "RNDIS" mode RX;
451 * so we won't ever use it (see "CPPI RX Woes" below).
452 */
453static inline int cppi_autoreq_update(struct cppi_channel *rx,
454 void __iomem *tibase, int onepacket, unsigned n_bds)
455{
456 u32 val;
457
458#ifdef RNDIS_RX_IS_USABLE
459 u32 tmp;
460 /* assert(is_host_active(musb)) */
461
462 /* start from "AutoReq never" */
463 tmp = musb_readl(tibase, DAVINCI_AUTOREQ_REG);
464 val = tmp & ~((0x3) << (rx->index * 2));
465
466 /* HCD arranged reqpkt for packet #1. we arrange int
467 * for all but the last one, maybe in two segments.
468 */
469 if (!onepacket) {
470#if 0
471 /* use two segments, autoreq "all" then the last "never" */
472 val |= ((0x3) << (rx->index * 2));
473 n_bds--;
474#else
475 /* one segment, autoreq "all-but-last" */
476 val |= ((0x1) << (rx->index * 2));
477#endif
478 }
479
480 if (val != tmp) {
481 int n = 100;
482
483 /* make sure that autoreq is updated before continuing */
484 musb_writel(tibase, DAVINCI_AUTOREQ_REG, val);
485 do {
486 tmp = musb_readl(tibase, DAVINCI_AUTOREQ_REG);
487 if (tmp == val)
488 break;
489 cpu_relax();
490 } while (n-- > 0);
491 }
492#endif
493
494 /* REQPKT is turned off after each segment */
495 if (n_bds && rx->channel.actual_len) {
496 void __iomem *regs = rx->hw_ep->regs;
497
498 val = musb_readw(regs, MUSB_RXCSR);
499 if (!(val & MUSB_RXCSR_H_REQPKT)) {
500 val |= MUSB_RXCSR_H_REQPKT | MUSB_RXCSR_H_WZC_BITS;
501 musb_writew(regs, MUSB_RXCSR, val);
502 /* flush writebuffer */
503 val = musb_readw(regs, MUSB_RXCSR);
504 }
505 }
506 return n_bds;
507}
508
509
510/* Buffer enqueuing Logic:
511 *
512 * - RX builds new queues each time, to help handle routine "early
513 * termination" cases (faults, including errors and short reads)
514 * more correctly.
515 *
516 * - for now, TX reuses the same queue of BDs every time
517 *
518 * REVISIT long term, we want a normal dynamic model.
519 * ... the goal will be to append to the
520 * existing queue, processing completed "dma buffers" (segments) on the fly.
521 *
522 * Otherwise we force an IRQ latency between requests, which slows us a lot
523 * (especially in "transparent" dma). Unfortunately that model seems to be
524 * inherent in the DMA model from the Mentor code, except in the rare case
525 * of transfers big enough (~128+ KB) that we could append "middle" segments
526 * in the TX paths. (RX can't do this, see below.)
527 *
528 * That's true even in the CPPI- friendly iso case, where most urbs have
529 * several small segments provided in a group and where the "packet at a time"
530 * "transparent" DMA model is always correct, even on the RX side.
531 */
532
533/*
534 * CPPI TX:
535 * ========
536 * TX is a lot more reasonable than RX; it doesn't need to run in
537 * irq-per-packet mode very often. RNDIS mode seems to behave too
538 * (except how it handles the exactly-N-packets case). Building a
539 * txdma queue with multiple requests (urb or usb_request) looks
540 * like it would work ... but fault handling would need much testing.
541 *
542 * The main issue with TX mode RNDIS relates to transfer lengths that
543 * are an exact multiple of the packet length. It appears that there's
544 * a hiccup in that case (maybe the DMA completes before the ZLP gets
545 * written?) boiling down to not being able to rely on CPPI writing any
546 * terminating zero length packet before the next transfer is written.
547 * So that's punted to PIO; better yet, gadget drivers can avoid it.
548 *
549 * Plus, there's allegedly an undocumented constraint that rndis transfer
550 * length be a multiple of 64 bytes ... but the chip doesn't act that
551 * way, and we really don't _want_ that behavior anyway.
552 *
553 * On TX, "transparent" mode works ... although experiments have shown
554 * problems trying to use the SOP/EOP bits in different USB packets.
555 *
556 * REVISIT try to handle terminating zero length packets using CPPI
557 * instead of doing it by PIO after an IRQ. (Meanwhile, make Ethernet
558 * links avoid that issue by forcing them to avoid zlps.)
559 */
560static void
561cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx)
562{
563 unsigned maxpacket = tx->maxpacket;
564 dma_addr_t addr = tx->buf_dma + tx->offset;
565 size_t length = tx->buf_len - tx->offset;
566 struct cppi_descriptor *bd;
567 unsigned n_bds;
568 unsigned i;
569 struct cppi_tx_stateram __iomem *tx_ram = tx->state_ram;
570 int rndis;
571
572 /* TX can use the CPPI "rndis" mode, where we can probably fit this
573 * transfer in one BD and one IRQ. The only time we would NOT want
574 * to use it is when hardware constraints prevent it, or if we'd
575 * trigger the "send a ZLP?" confusion.
576 */
577 rndis = (maxpacket & 0x3f) == 0
578 && length > maxpacket
579 && length < 0xffff
580 && (length % maxpacket) != 0;
581
582 if (rndis) {
583 maxpacket = length;
584 n_bds = 1;
585 } else {
586 if (length)
587 n_bds = DIV_ROUND_UP(length, maxpacket);
588 else
589 n_bds = 1;
590 n_bds = min(n_bds, (unsigned) NUM_TXCHAN_BD);
591 length = min(n_bds * maxpacket, length);
592 }
593
594 musb_dbg(musb, "TX DMA%d, pktSz %d %s bds %d dma 0x%llx len %u",
595 tx->index,
596 maxpacket,
597 rndis ? "rndis" : "transparent",
598 n_bds,
599 (unsigned long long)addr, length);
600
601 cppi_rndis_update(tx, 0, musb->ctrl_base, rndis);
602
603 /* assuming here that channel_program is called during
604 * transfer initiation ... current code maintains state
605 * for one outstanding request only (no queues, not even
606 * the implicit ones of an iso urb).
607 */
608
609 bd = tx->freelist;
610 tx->head = bd;
611 tx->last_processed = NULL;
612
613 /* FIXME use BD pool like RX side does, and just queue
614 * the minimum number for this request.
615 */
616
617 /* Prepare queue of BDs first, then hand it to hardware.
618 * All BDs except maybe the last should be of full packet
619 * size; for RNDIS there _is_ only that last packet.
620 */
621 for (i = 0; i < n_bds; ) {
622 if (++i < n_bds && bd->next)
623 bd->hw_next = bd->next->dma;
624 else
625 bd->hw_next = 0;
626
627 bd->hw_bufp = tx->buf_dma + tx->offset;
628
629 /* FIXME set EOP only on the last packet,
630 * SOP only on the first ... avoid IRQs
631 */
632 if ((tx->offset + maxpacket) <= tx->buf_len) {
633 tx->offset += maxpacket;
634 bd->hw_off_len = maxpacket;
635 bd->hw_options = CPPI_SOP_SET | CPPI_EOP_SET
636 | CPPI_OWN_SET | maxpacket;
637 } else {
638 /* only this one may be a partial USB Packet */
639 u32 partial_len;
640
641 partial_len = tx->buf_len - tx->offset;
642 tx->offset = tx->buf_len;
643 bd->hw_off_len = partial_len;
644
645 bd->hw_options = CPPI_SOP_SET | CPPI_EOP_SET
646 | CPPI_OWN_SET | partial_len;
647 if (partial_len == 0)
648 bd->hw_options |= CPPI_ZERO_SET;
649 }
650
651 musb_dbg(musb, "TXBD %p: nxt %08x buf %08x len %04x opt %08x",
652 bd, bd->hw_next, bd->hw_bufp,
653 bd->hw_off_len, bd->hw_options);
654
655 /* update the last BD enqueued to the list */
656 tx->tail = bd;
657 bd = bd->next;
658 }
659
660 /* BDs live in DMA-coherent memory, but writes might be pending */
661 cpu_drain_writebuffer();
662
663 /* Write to the HeadPtr in state RAM to trigger */
664 musb_writel(&tx_ram->tx_head, 0, (u32)tx->freelist->dma);
665
666 cppi_dump_tx(5, tx, "/S");
667}
668
669/*
670 * CPPI RX Woes:
671 * =============
672 * Consider a 1KB bulk RX buffer in two scenarios: (a) it's fed two 300 byte
673 * packets back-to-back, and (b) it's fed two 512 byte packets back-to-back.
674 * (Full speed transfers have similar scenarios.)
675 *
676 * The correct behavior for Linux is that (a) fills the buffer with 300 bytes,
677 * and the next packet goes into a buffer that's queued later; while (b) fills
678 * the buffer with 1024 bytes. How to do that with CPPI?
679 *
680 * - RX queues in "rndis" mode -- one single BD -- handle (a) correctly, but
681 * (b) loses **BADLY** because nothing (!) happens when that second packet
682 * fills the buffer, much less when a third one arrives. (Which makes this
683 * not a "true" RNDIS mode. In the RNDIS protocol short-packet termination
684 * is optional, and it's fine if peripherals -- not hosts! -- pad messages
685 * out to end-of-buffer. Standard PCI host controller DMA descriptors
686 * implement that mode by default ... which is no accident.)
687 *
688 * - RX queues in "transparent" mode -- two BDs with 512 bytes each -- have
689 * converse problems: (b) is handled right, but (a) loses badly. CPPI RX
690 * ignores SOP/EOP markings and processes both of those BDs; so both packets
691 * are loaded into the buffer (with a 212 byte gap between them), and the next
692 * buffer queued will NOT get its 300 bytes of data. (It seems like SOP/EOP
693 * are intended as outputs for RX queues, not inputs...)
694 *
695 * - A variant of "transparent" mode -- one BD at a time -- is the only way to
696 * reliably make both cases work, with software handling both cases correctly
697 * and at the significant penalty of needing an IRQ per packet. (The lack of
698 * I/O overlap can be slightly ameliorated by enabling double buffering.)
699 *
700 * So how to get rid of IRQ-per-packet? The transparent multi-BD case could
701 * be used in special cases like mass storage, which sets URB_SHORT_NOT_OK
702 * (or maybe its peripheral side counterpart) to flag (a) scenarios as errors
703 * with guaranteed driver level fault recovery and scrubbing out what's left
704 * of that garbaged datastream.
705 *
706 * But there seems to be no way to identify the cases where CPPI RNDIS mode
707 * is appropriate -- which do NOT include RNDIS host drivers, but do include
708 * the CDC Ethernet driver! -- and the documentation is incomplete/wrong.
709 * So we can't _ever_ use RX RNDIS mode ... except by using a heuristic
710 * that applies best on the peripheral side (and which could fail rudely).
711 *
712 * Leaving only "transparent" mode; we avoid multi-bd modes in almost all
713 * cases other than mass storage class. Otherwise we're correct but slow,
714 * since CPPI penalizes our need for a "true RNDIS" default mode.
715 */
716
717
718/* Heuristic, intended to kick in for ethernet/rndis peripheral ONLY
719 *
720 * IFF
721 * (a) peripheral mode ... since rndis peripherals could pad their
722 * writes to hosts, causing i/o failure; or we'd have to cope with
723 * a largely unknowable variety of host side protocol variants
724 * (b) and short reads are NOT errors ... since full reads would
725 * cause those same i/o failures
726 * (c) and read length is
727 * - less than 64KB (max per cppi descriptor)
728 * - not a multiple of 4096 (g_zero default, full reads typical)
729 * - N (>1) packets long, ditto (full reads not EXPECTED)
730 * THEN
731 * try rx rndis mode
732 *
733 * Cost of heuristic failing: RXDMA wedges at the end of transfers that
734 * fill out the whole buffer. Buggy host side usb network drivers could
735 * trigger that, but "in the field" such bugs seem to be all but unknown.
736 *
737 * So this module parameter lets the heuristic be disabled. When using
738 * gadgetfs, the heuristic will probably need to be disabled.
739 */
740static bool cppi_rx_rndis = 1;
741
742module_param(cppi_rx_rndis, bool, 0);
743MODULE_PARM_DESC(cppi_rx_rndis, "enable/disable RX RNDIS heuristic");
744
745
746/**
747 * cppi_next_rx_segment - dma read for the next chunk of a buffer
748 * @musb: the controller
749 * @rx: dma channel
750 * @onepacket: true unless caller treats short reads as errors, and
751 * performs fault recovery above usbcore.
752 * Context: controller irqlocked
753 *
754 * See above notes about why we can't use multi-BD RX queues except in
755 * rare cases (mass storage class), and can never use the hardware "rndis"
756 * mode (since it's not a "true" RNDIS mode) with complete safety..
757 *
758 * It's ESSENTIAL that callers specify "onepacket" mode unless they kick in
759 * code to recover from corrupted datastreams after each short transfer.
760 */
761static void
762cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
763{
764 unsigned maxpacket = rx->maxpacket;
765 dma_addr_t addr = rx->buf_dma + rx->offset;
766 size_t length = rx->buf_len - rx->offset;
767 struct cppi_descriptor *bd, *tail;
768 unsigned n_bds;
769 unsigned i;
770 void __iomem *tibase = musb->ctrl_base;
771 int is_rndis = 0;
772 struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram;
773 struct cppi_descriptor *d;
774
775 if (onepacket) {
776 /* almost every USB driver, host or peripheral side */
777 n_bds = 1;
778
779 /* maybe apply the heuristic above */
780 if (cppi_rx_rndis
781 && is_peripheral_active(musb)
782 && length > maxpacket
783 && (length & ~0xffff) == 0
784 && (length & 0x0fff) != 0
785 && (length & (maxpacket - 1)) == 0) {
786 maxpacket = length;
787 is_rndis = 1;
788 }
789 } else {
790 /* virtually nothing except mass storage class */
791 if (length > 0xffff) {
792 n_bds = 0xffff / maxpacket;
793 length = n_bds * maxpacket;
794 } else {
795 n_bds = DIV_ROUND_UP(length, maxpacket);
796 }
797 if (n_bds == 1)
798 onepacket = 1;
799 else
800 n_bds = min(n_bds, (unsigned) NUM_RXCHAN_BD);
801 }
802
803 /* In host mode, autorequest logic can generate some IN tokens; it's
804 * tricky since we can't leave REQPKT set in RXCSR after the transfer
805 * finishes. So: multipacket transfers involve two or more segments.
806 * And always at least two IRQs ... RNDIS mode is not an option.
807 */
808 if (is_host_active(musb))
809 n_bds = cppi_autoreq_update(rx, tibase, onepacket, n_bds);
810
811 cppi_rndis_update(rx, 1, musb->ctrl_base, is_rndis);
812
813 length = min(n_bds * maxpacket, length);
814
815 musb_dbg(musb, "RX DMA%d seg, maxp %d %s bds %d (cnt %d) "
816 "dma 0x%llx len %u %u/%u",
817 rx->index, maxpacket,
818 onepacket
819 ? (is_rndis ? "rndis" : "onepacket")
820 : "multipacket",
821 n_bds,
822 musb_readl(tibase,
823 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4))
824 & 0xffff,
825 (unsigned long long)addr, length,
826 rx->channel.actual_len, rx->buf_len);
827
828 /* only queue one segment at a time, since the hardware prevents
829 * correct queue shutdown after unexpected short packets
830 */
831 bd = cppi_bd_alloc(rx);
832 rx->head = bd;
833
834 /* Build BDs for all packets in this segment */
835 for (i = 0, tail = NULL; bd && i < n_bds; i++, tail = bd) {
836 u32 bd_len;
837
838 if (i) {
839 bd = cppi_bd_alloc(rx);
840 if (!bd)
841 break;
842 tail->next = bd;
843 tail->hw_next = bd->dma;
844 }
845 bd->hw_next = 0;
846
847 /* all but the last packet will be maxpacket size */
848 if (maxpacket < length)
849 bd_len = maxpacket;
850 else
851 bd_len = length;
852
853 bd->hw_bufp = addr;
854 addr += bd_len;
855 rx->offset += bd_len;
856
857 bd->hw_off_len = (0 /*offset*/ << 16) + bd_len;
858 bd->buflen = bd_len;
859
860 bd->hw_options = CPPI_OWN_SET | (i == 0 ? length : 0);
861 length -= bd_len;
862 }
863
864 /* we always expect at least one reusable BD! */
865 if (!tail) {
866 WARNING("rx dma%d -- no BDs? need %d\n", rx->index, n_bds);
867 return;
868 } else if (i < n_bds)
869 WARNING("rx dma%d -- only %d of %d BDs\n", rx->index, i, n_bds);
870
871 tail->next = NULL;
872 tail->hw_next = 0;
873
874 bd = rx->head;
875 rx->tail = tail;
876
877 /* short reads and other faults should terminate this entire
878 * dma segment. we want one "dma packet" per dma segment, not
879 * one per USB packet, terminating the whole queue at once...
880 * NOTE that current hardware seems to ignore SOP and EOP.
881 */
882 bd->hw_options |= CPPI_SOP_SET;
883 tail->hw_options |= CPPI_EOP_SET;
884
885 for (d = rx->head; d; d = d->next)
886 cppi_dump_rxbd("S", d);
887
888 /* in case the preceding transfer left some state... */
889 tail = rx->last_processed;
890 if (tail) {
891 tail->next = bd;
892 tail->hw_next = bd->dma;
893 }
894
895 core_rxirq_enable(tibase, rx->index + 1);
896
897 /* BDs live in DMA-coherent memory, but writes might be pending */
898 cpu_drain_writebuffer();
899
900 /* REVISIT specs say to write this AFTER the BUFCNT register
901 * below ... but that loses badly.
902 */
903 musb_writel(&rx_ram->rx_head, 0, bd->dma);
904
905 /* bufferCount must be at least 3, and zeroes on completion
906 * unless it underflows below zero, or stops at two, or keeps
907 * growing ... grr.
908 */
909 i = musb_readl(tibase,
910 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4))
911 & 0xffff;
912
913 if (!i)
914 musb_writel(tibase,
915 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4),
916 n_bds + 2);
917 else if (n_bds > (i - 3))
918 musb_writel(tibase,
919 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4),
920 n_bds - (i - 3));
921
922 i = musb_readl(tibase,
923 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4))
924 & 0xffff;
925 if (i < (2 + n_bds)) {
926 musb_dbg(musb, "bufcnt%d underrun - %d (for %d)",
927 rx->index, i, n_bds);
928 musb_writel(tibase,
929 DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4),
930 n_bds + 2);
931 }
932
933 cppi_dump_rx(4, rx, "/S");
934}
935
936/**
937 * cppi_channel_program - program channel for data transfer
938 * @ch: the channel
939 * @maxpacket: max packet size
940 * @mode: For RX, 1 unless the usb protocol driver promised to treat
941 * all short reads as errors and kick in high level fault recovery.
942 * For TX, ignored because of RNDIS mode races/glitches.
943 * @dma_addr: dma address of buffer
944 * @len: length of buffer
945 * Context: controller irqlocked
946 */
947static int cppi_channel_program(struct dma_channel *ch,
948 u16 maxpacket, u8 mode,
949 dma_addr_t dma_addr, u32 len)
950{
951 struct cppi_channel *cppi_ch;
952 struct cppi *controller;
953 struct musb *musb;
954
955 cppi_ch = container_of(ch, struct cppi_channel, channel);
956 controller = cppi_ch->controller;
957 musb = controller->controller.musb;
958
959 switch (ch->status) {
960 case MUSB_DMA_STATUS_BUS_ABORT:
961 case MUSB_DMA_STATUS_CORE_ABORT:
962 /* fault irq handler should have handled cleanup */
963 WARNING("%cX DMA%d not cleaned up after abort!\n",
964 cppi_ch->transmit ? 'T' : 'R',
965 cppi_ch->index);
966 /* WARN_ON(1); */
967 break;
968 case MUSB_DMA_STATUS_BUSY:
969 WARNING("program active channel? %cX DMA%d\n",
970 cppi_ch->transmit ? 'T' : 'R',
971 cppi_ch->index);
972 /* WARN_ON(1); */
973 break;
974 case MUSB_DMA_STATUS_UNKNOWN:
975 musb_dbg(musb, "%cX DMA%d not allocated!",
976 cppi_ch->transmit ? 'T' : 'R',
977 cppi_ch->index);
978 fallthrough;
979 case MUSB_DMA_STATUS_FREE:
980 break;
981 }
982
983 ch->status = MUSB_DMA_STATUS_BUSY;
984
985 /* set transfer parameters, then queue up its first segment */
986 cppi_ch->buf_dma = dma_addr;
987 cppi_ch->offset = 0;
988 cppi_ch->maxpacket = maxpacket;
989 cppi_ch->buf_len = len;
990 cppi_ch->channel.actual_len = 0;
991
992 /* TX channel? or RX? */
993 if (cppi_ch->transmit)
994 cppi_next_tx_segment(musb, cppi_ch);
995 else
996 cppi_next_rx_segment(musb, cppi_ch, mode);
997
998 return true;
999}
1000
1001static bool cppi_rx_scan(struct cppi *cppi, unsigned ch)
1002{
1003 struct cppi_channel *rx = &cppi->rx[ch];
1004 struct cppi_rx_stateram __iomem *state = rx->state_ram;
1005 struct cppi_descriptor *bd;
1006 struct cppi_descriptor *last = rx->last_processed;
1007 bool completed = false;
1008 bool acked = false;
1009 int i;
1010 dma_addr_t safe2ack;
1011 void __iomem *regs = rx->hw_ep->regs;
1012 struct musb *musb = cppi->controller.musb;
1013
1014 cppi_dump_rx(6, rx, "/K");
1015
1016 bd = last ? last->next : rx->head;
1017 if (!bd)
1018 return false;
1019
1020 /* run through all completed BDs */
1021 for (i = 0, safe2ack = musb_readl(&state->rx_complete, 0);
1022 (safe2ack || completed) && bd && i < NUM_RXCHAN_BD;
1023 i++, bd = bd->next) {
1024 u16 len;
1025
1026 /* catch latest BD writes from CPPI */
1027 rmb();
1028 if (!completed && (bd->hw_options & CPPI_OWN_SET))
1029 break;
1030
1031 musb_dbg(musb, "C/RXBD %llx: nxt %08x buf %08x "
1032 "off.len %08x opt.len %08x (%d)",
1033 (unsigned long long)bd->dma, bd->hw_next, bd->hw_bufp,
1034 bd->hw_off_len, bd->hw_options,
1035 rx->channel.actual_len);
1036
1037 /* actual packet received length */
1038 if ((bd->hw_options & CPPI_SOP_SET) && !completed)
1039 len = bd->hw_off_len & CPPI_RECV_PKTLEN_MASK;
1040 else
1041 len = 0;
1042
1043 if (bd->hw_options & CPPI_EOQ_MASK)
1044 completed = true;
1045
1046 if (!completed && len < bd->buflen) {
1047 /* NOTE: when we get a short packet, RXCSR_H_REQPKT
1048 * must have been cleared, and no more DMA packets may
1049 * active be in the queue... TI docs didn't say, but
1050 * CPPI ignores those BDs even though OWN is still set.
1051 */
1052 completed = true;
1053 musb_dbg(musb, "rx short %d/%d (%d)",
1054 len, bd->buflen,
1055 rx->channel.actual_len);
1056 }
1057
1058 /* If we got here, we expect to ack at least one BD; meanwhile
1059 * CPPI may completing other BDs while we scan this list...
1060 *
1061 * RACE: we can notice OWN cleared before CPPI raises the
1062 * matching irq by writing that BD as the completion pointer.
1063 * In such cases, stop scanning and wait for the irq, avoiding
1064 * lost acks and states where BD ownership is unclear.
1065 */
1066 if (bd->dma == safe2ack) {
1067 musb_writel(&state->rx_complete, 0, safe2ack);
1068 safe2ack = musb_readl(&state->rx_complete, 0);
1069 acked = true;
1070 if (bd->dma == safe2ack)
1071 safe2ack = 0;
1072 }
1073
1074 rx->channel.actual_len += len;
1075
1076 cppi_bd_free(rx, last);
1077 last = bd;
1078
1079 /* stop scanning on end-of-segment */
1080 if (bd->hw_next == 0)
1081 completed = true;
1082 }
1083 rx->last_processed = last;
1084
1085 /* dma abort, lost ack, or ... */
1086 if (!acked && last) {
1087 int csr;
1088
1089 if (safe2ack == 0 || safe2ack == rx->last_processed->dma)
1090 musb_writel(&state->rx_complete, 0, safe2ack);
1091 if (safe2ack == 0) {
1092 cppi_bd_free(rx, last);
1093 rx->last_processed = NULL;
1094
1095 /* if we land here on the host side, H_REQPKT will
1096 * be clear and we need to restart the queue...
1097 */
1098 WARN_ON(rx->head);
1099 }
1100 musb_ep_select(cppi->mregs, rx->index + 1);
1101 csr = musb_readw(regs, MUSB_RXCSR);
1102 if (csr & MUSB_RXCSR_DMAENAB) {
1103 musb_dbg(musb, "list%d %p/%p, last %llx%s, csr %04x",
1104 rx->index,
1105 rx->head, rx->tail,
1106 rx->last_processed
1107 ? (unsigned long long)
1108 rx->last_processed->dma
1109 : 0,
1110 completed ? ", completed" : "",
1111 csr);
1112 cppi_dump_rxq(4, "/what?", rx);
1113 }
1114 }
1115 if (!completed) {
1116 int csr;
1117
1118 rx->head = bd;
1119
1120 /* REVISIT seems like "autoreq all but EOP" doesn't...
1121 * setting it here "should" be racey, but seems to work
1122 */
1123 csr = musb_readw(rx->hw_ep->regs, MUSB_RXCSR);
1124 if (is_host_active(cppi->controller.musb)
1125 && bd
1126 && !(csr & MUSB_RXCSR_H_REQPKT)) {
1127 csr |= MUSB_RXCSR_H_REQPKT;
1128 musb_writew(regs, MUSB_RXCSR,
1129 MUSB_RXCSR_H_WZC_BITS | csr);
1130 csr = musb_readw(rx->hw_ep->regs, MUSB_RXCSR);
1131 }
1132 } else {
1133 rx->head = NULL;
1134 rx->tail = NULL;
1135 }
1136
1137 cppi_dump_rx(6, rx, completed ? "/completed" : "/cleaned");
1138 return completed;
1139}
1140
1141irqreturn_t cppi_interrupt(int irq, void *dev_id)
1142{
1143 struct musb *musb = dev_id;
1144 struct cppi *cppi;
1145 void __iomem *tibase;
1146 struct musb_hw_ep *hw_ep = NULL;
1147 u32 rx, tx;
1148 int i, index;
1149 unsigned long flags;
1150
1151 cppi = container_of(musb->dma_controller, struct cppi, controller);
1152 if (cppi->irq)
1153 spin_lock_irqsave(&musb->lock, flags);
1154
1155 tibase = musb->ctrl_base;
1156
1157 tx = musb_readl(tibase, DAVINCI_TXCPPI_MASKED_REG);
1158 rx = musb_readl(tibase, DAVINCI_RXCPPI_MASKED_REG);
1159
1160 if (!tx && !rx) {
1161 if (cppi->irq)
1162 spin_unlock_irqrestore(&musb->lock, flags);
1163 return IRQ_NONE;
1164 }
1165
1166 musb_dbg(musb, "CPPI IRQ Tx%x Rx%x", tx, rx);
1167
1168 /* process TX channels */
1169 for (index = 0; tx; tx = tx >> 1, index++) {
1170 struct cppi_channel *tx_ch;
1171 struct cppi_tx_stateram __iomem *tx_ram;
1172 bool completed = false;
1173 struct cppi_descriptor *bd;
1174
1175 if (!(tx & 1))
1176 continue;
1177
1178 tx_ch = cppi->tx + index;
1179 tx_ram = tx_ch->state_ram;
1180
1181 /* FIXME need a cppi_tx_scan() routine, which
1182 * can also be called from abort code
1183 */
1184
1185 cppi_dump_tx(5, tx_ch, "/E");
1186
1187 bd = tx_ch->head;
1188
1189 /*
1190 * If Head is null then this could mean that a abort interrupt
1191 * that needs to be acknowledged.
1192 */
1193 if (NULL == bd) {
1194 musb_dbg(musb, "null BD");
1195 musb_writel(&tx_ram->tx_complete, 0, 0);
1196 continue;
1197 }
1198
1199 /* run through all completed BDs */
1200 for (i = 0; !completed && bd && i < NUM_TXCHAN_BD;
1201 i++, bd = bd->next) {
1202 u16 len;
1203
1204 /* catch latest BD writes from CPPI */
1205 rmb();
1206 if (bd->hw_options & CPPI_OWN_SET)
1207 break;
1208
1209 musb_dbg(musb, "C/TXBD %p n %x b %x off %x opt %x",
1210 bd, bd->hw_next, bd->hw_bufp,
1211 bd->hw_off_len, bd->hw_options);
1212
1213 len = bd->hw_off_len & CPPI_BUFFER_LEN_MASK;
1214 tx_ch->channel.actual_len += len;
1215
1216 tx_ch->last_processed = bd;
1217
1218 /* write completion register to acknowledge
1219 * processing of completed BDs, and possibly
1220 * release the IRQ; EOQ might not be set ...
1221 *
1222 * REVISIT use the same ack strategy as rx
1223 *
1224 * REVISIT have observed bit 18 set; huh??
1225 */
1226 /* if ((bd->hw_options & CPPI_EOQ_MASK)) */
1227 musb_writel(&tx_ram->tx_complete, 0, bd->dma);
1228
1229 /* stop scanning on end-of-segment */
1230 if (bd->hw_next == 0)
1231 completed = true;
1232 }
1233
1234 /* on end of segment, maybe go to next one */
1235 if (completed) {
1236 /* cppi_dump_tx(4, tx_ch, "/complete"); */
1237
1238 /* transfer more, or report completion */
1239 if (tx_ch->offset >= tx_ch->buf_len) {
1240 tx_ch->head = NULL;
1241 tx_ch->tail = NULL;
1242 tx_ch->channel.status = MUSB_DMA_STATUS_FREE;
1243
1244 hw_ep = tx_ch->hw_ep;
1245
1246 musb_dma_completion(musb, index + 1, 1);
1247
1248 } else {
1249 /* Bigger transfer than we could fit in
1250 * that first batch of descriptors...
1251 */
1252 cppi_next_tx_segment(musb, tx_ch);
1253 }
1254 } else
1255 tx_ch->head = bd;
1256 }
1257
1258 /* Start processing the RX block */
1259 for (index = 0; rx; rx = rx >> 1, index++) {
1260
1261 if (rx & 1) {
1262 struct cppi_channel *rx_ch;
1263
1264 rx_ch = cppi->rx + index;
1265
1266 /* let incomplete dma segments finish */
1267 if (!cppi_rx_scan(cppi, index))
1268 continue;
1269
1270 /* start another dma segment if needed */
1271 if (rx_ch->channel.actual_len != rx_ch->buf_len
1272 && rx_ch->channel.actual_len
1273 == rx_ch->offset) {
1274 cppi_next_rx_segment(musb, rx_ch, 1);
1275 continue;
1276 }
1277
1278 /* all segments completed! */
1279 rx_ch->channel.status = MUSB_DMA_STATUS_FREE;
1280
1281 hw_ep = rx_ch->hw_ep;
1282
1283 core_rxirq_disable(tibase, index + 1);
1284 musb_dma_completion(musb, index + 1, 0);
1285 }
1286 }
1287
1288 /* write to CPPI EOI register to re-enable interrupts */
1289 musb_writel(tibase, DAVINCI_CPPI_EOI_REG, 0);
1290
1291 if (cppi->irq)
1292 spin_unlock_irqrestore(&musb->lock, flags);
1293
1294 return IRQ_HANDLED;
1295}
1296EXPORT_SYMBOL_GPL(cppi_interrupt);
1297
1298/* Instantiate a software object representing a DMA controller. */
1299struct dma_controller *
1300cppi_dma_controller_create(struct musb *musb, void __iomem *mregs)
1301{
1302 struct cppi *controller;
1303 struct device *dev = musb->controller;
1304 struct platform_device *pdev = to_platform_device(dev);
1305 int irq = platform_get_irq_byname(pdev, "dma");
1306
1307 controller = kzalloc(sizeof *controller, GFP_KERNEL);
1308 if (!controller)
1309 return NULL;
1310
1311 controller->mregs = mregs;
1312 controller->tibase = mregs - DAVINCI_BASE_OFFSET;
1313
1314 controller->controller.musb = musb;
1315 controller->controller.channel_alloc = cppi_channel_allocate;
1316 controller->controller.channel_release = cppi_channel_release;
1317 controller->controller.channel_program = cppi_channel_program;
1318 controller->controller.channel_abort = cppi_channel_abort;
1319
1320 /* NOTE: allocating from on-chip SRAM would give the least
1321 * contention for memory access, if that ever matters here.
1322 */
1323
1324 /* setup BufferPool */
1325 controller->pool = dma_pool_create("cppi",
1326 controller->controller.musb->controller,
1327 sizeof(struct cppi_descriptor),
1328 CPPI_DESCRIPTOR_ALIGN, 0);
1329 if (!controller->pool) {
1330 kfree(controller);
1331 return NULL;
1332 }
1333
1334 if (irq > 0) {
1335 if (request_irq(irq, cppi_interrupt, 0, "cppi-dma", musb)) {
1336 dev_err(dev, "request_irq %d failed!\n", irq);
1337 musb_dma_controller_destroy(&controller->controller);
1338 return NULL;
1339 }
1340 controller->irq = irq;
1341 }
1342
1343 cppi_controller_start(controller);
1344 return &controller->controller;
1345}
1346EXPORT_SYMBOL_GPL(cppi_dma_controller_create);
1347
1348/*
1349 * Destroy a previously-instantiated DMA controller.
1350 */
1351void cppi_dma_controller_destroy(struct dma_controller *c)
1352{
1353 struct cppi *cppi;
1354
1355 cppi = container_of(c, struct cppi, controller);
1356
1357 cppi_controller_stop(cppi);
1358
1359 if (cppi->irq)
1360 free_irq(cppi->irq, cppi->controller.musb);
1361
1362 /* assert: caller stopped the controller first */
1363 dma_pool_destroy(cppi->pool);
1364
1365 kfree(cppi);
1366}
1367EXPORT_SYMBOL_GPL(cppi_dma_controller_destroy);
1368
1369/*
1370 * Context: controller irqlocked, endpoint selected
1371 */
1372static int cppi_channel_abort(struct dma_channel *channel)
1373{
1374 struct cppi_channel *cppi_ch;
1375 struct cppi *controller;
1376 void __iomem *mbase;
1377 void __iomem *tibase;
1378 void __iomem *regs;
1379 u32 value;
1380 struct cppi_descriptor *queue;
1381
1382 cppi_ch = container_of(channel, struct cppi_channel, channel);
1383
1384 controller = cppi_ch->controller;
1385
1386 switch (channel->status) {
1387 case MUSB_DMA_STATUS_BUS_ABORT:
1388 case MUSB_DMA_STATUS_CORE_ABORT:
1389 /* from RX or TX fault irq handler */
1390 case MUSB_DMA_STATUS_BUSY:
1391 /* the hardware needs shutting down */
1392 regs = cppi_ch->hw_ep->regs;
1393 break;
1394 case MUSB_DMA_STATUS_UNKNOWN:
1395 case MUSB_DMA_STATUS_FREE:
1396 return 0;
1397 default:
1398 return -EINVAL;
1399 }
1400
1401 if (!cppi_ch->transmit && cppi_ch->head)
1402 cppi_dump_rxq(3, "/abort", cppi_ch);
1403
1404 mbase = controller->mregs;
1405 tibase = controller->tibase;
1406
1407 queue = cppi_ch->head;
1408 cppi_ch->head = NULL;
1409 cppi_ch->tail = NULL;
1410
1411 /* REVISIT should rely on caller having done this,
1412 * and caller should rely on us not changing it.
1413 * peripheral code is safe ... check host too.
1414 */
1415 musb_ep_select(mbase, cppi_ch->index + 1);
1416
1417 if (cppi_ch->transmit) {
1418 struct cppi_tx_stateram __iomem *tx_ram;
1419 /* REVISIT put timeouts on these controller handshakes */
1420
1421 cppi_dump_tx(6, cppi_ch, " (teardown)");
1422
1423 /* teardown DMA engine then usb core */
1424 do {
1425 value = musb_readl(tibase, DAVINCI_TXCPPI_TEAR_REG);
1426 } while (!(value & CPPI_TEAR_READY));
1427 musb_writel(tibase, DAVINCI_TXCPPI_TEAR_REG, cppi_ch->index);
1428
1429 tx_ram = cppi_ch->state_ram;
1430 do {
1431 value = musb_readl(&tx_ram->tx_complete, 0);
1432 } while (0xFFFFFFFC != value);
1433
1434 /* FIXME clean up the transfer state ... here?
1435 * the completion routine should get called with
1436 * an appropriate status code.
1437 */
1438
1439 value = musb_readw(regs, MUSB_TXCSR);
1440 value &= ~MUSB_TXCSR_DMAENAB;
1441 value |= MUSB_TXCSR_FLUSHFIFO;
1442 musb_writew(regs, MUSB_TXCSR, value);
1443 musb_writew(regs, MUSB_TXCSR, value);
1444
1445 /*
1446 * 1. Write to completion Ptr value 0x1(bit 0 set)
1447 * (write back mode)
1448 * 2. Wait for abort interrupt and then put the channel in
1449 * compare mode by writing 1 to the tx_complete register.
1450 */
1451 cppi_reset_tx(tx_ram, 1);
1452 cppi_ch->head = NULL;
1453 musb_writel(&tx_ram->tx_complete, 0, 1);
1454 cppi_dump_tx(5, cppi_ch, " (done teardown)");
1455
1456 /* REVISIT tx side _should_ clean up the same way
1457 * as the RX side ... this does no cleanup at all!
1458 */
1459
1460 } else /* RX */ {
1461 u16 csr;
1462
1463 /* NOTE: docs don't guarantee any of this works ... we
1464 * expect that if the usb core stops telling the cppi core
1465 * to pull more data from it, then it'll be safe to flush
1466 * current RX DMA state iff any pending fifo transfer is done.
1467 */
1468
1469 core_rxirq_disable(tibase, cppi_ch->index + 1);
1470
1471 /* for host, ensure ReqPkt is never set again */
1472 if (is_host_active(cppi_ch->controller->controller.musb)) {
1473 value = musb_readl(tibase, DAVINCI_AUTOREQ_REG);
1474 value &= ~((0x3) << (cppi_ch->index * 2));
1475 musb_writel(tibase, DAVINCI_AUTOREQ_REG, value);
1476 }
1477
1478 csr = musb_readw(regs, MUSB_RXCSR);
1479
1480 /* for host, clear (just) ReqPkt at end of current packet(s) */
1481 if (is_host_active(cppi_ch->controller->controller.musb)) {
1482 csr |= MUSB_RXCSR_H_WZC_BITS;
1483 csr &= ~MUSB_RXCSR_H_REQPKT;
1484 } else
1485 csr |= MUSB_RXCSR_P_WZC_BITS;
1486
1487 /* clear dma enable */
1488 csr &= ~(MUSB_RXCSR_DMAENAB);
1489 musb_writew(regs, MUSB_RXCSR, csr);
1490 csr = musb_readw(regs, MUSB_RXCSR);
1491
1492 /* Quiesce: wait for current dma to finish (if not cleanup).
1493 * We can't use bit zero of stateram->rx_sop, since that
1494 * refers to an entire "DMA packet" not just emptying the
1495 * current fifo. Most segments need multiple usb packets.
1496 */
1497 if (channel->status == MUSB_DMA_STATUS_BUSY)
1498 udelay(50);
1499
1500 /* scan the current list, reporting any data that was
1501 * transferred and acking any IRQ
1502 */
1503 cppi_rx_scan(controller, cppi_ch->index);
1504
1505 /* clobber the existing state once it's idle
1506 *
1507 * NOTE: arguably, we should also wait for all the other
1508 * RX channels to quiesce (how??) and then temporarily
1509 * disable RXCPPI_CTRL_REG ... but it seems that we can
1510 * rely on the controller restarting from state ram, with
1511 * only RXCPPI_BUFCNT state being bogus. BUFCNT will
1512 * correct itself after the next DMA transfer though.
1513 *
1514 * REVISIT does using rndis mode change that?
1515 */
1516 cppi_reset_rx(cppi_ch->state_ram);
1517
1518 /* next DMA request _should_ load cppi head ptr */
1519
1520 /* ... we don't "free" that list, only mutate it in place. */
1521 cppi_dump_rx(5, cppi_ch, " (done abort)");
1522
1523 /* clean up previously pending bds */
1524 cppi_bd_free(cppi_ch, cppi_ch->last_processed);
1525 cppi_ch->last_processed = NULL;
1526
1527 while (queue) {
1528 struct cppi_descriptor *tmp = queue->next;
1529
1530 cppi_bd_free(cppi_ch, queue);
1531 queue = tmp;
1532 }
1533 }
1534
1535 channel->status = MUSB_DMA_STATUS_FREE;
1536 cppi_ch->buf_dma = 0;
1537 cppi_ch->offset = 0;
1538 cppi_ch->buf_len = 0;
1539 cppi_ch->maxpacket = 0;
1540 return 0;
1541}
1542
1543/* TBD Queries:
1544 *
1545 * Power Management ... probably turn off cppi during suspend, restart;
1546 * check state ram? Clocking is presumably shared with usb core.
1547 */
drivers/usb/musb/davinci.c+0−606
@@ -1,606 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2005-2006 by Texas Instruments
4 *
5 * This file is part of the Inventra Controller Driver for Linux.
6 */
7
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/sched.h>
11#include <linux/list.h>
12#include <linux/delay.h>
13#include <linux/clk.h>
14#include <linux/err.h>
15#include <linux/io.h>
16#include <linux/gpio/consumer.h>
17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
19#include <linux/usb/usb_phy_generic.h>
20
21#include <mach/cputype.h>
22#include <mach/hardware.h>
23
24#include <asm/mach-types.h>
25
26#include "musb_core.h"
27
28#include "davinci.h"
29#include "cppi_dma.h"
30
31
32#define USB_PHY_CTRL IO_ADDRESS(USBPHY_CTL_PADDR)
33#define DM355_DEEPSLEEP IO_ADDRESS(DM355_DEEPSLEEP_PADDR)
34
35struct davinci_glue {
36 struct device *dev;
37 struct platform_device *musb;
38 struct clk *clk;
39 bool vbus_state;
40 struct gpio_desc *vbus;
41 struct work_struct vbus_work;
42};
43
44/* REVISIT (PM) we should be able to keep the PHY in low power mode most
45 * of the time (24 MHZ oscillator and PLL off, etc) by setting POWER.D0
46 * and, when in host mode, autosuspending idle root ports... PHYPLLON
47 * (overriding SUSPENDM?) then likely needs to stay off.
48 */
49
50static inline void phy_on(void)
51{
52 u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
53
54 /* power everything up; start the on-chip PHY and its PLL */
55 phy_ctrl &= ~(USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN);
56 phy_ctrl |= USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON;
57 __raw_writel(phy_ctrl, USB_PHY_CTRL);
58
59 /* wait for PLL to lock before proceeding */
60 while ((__raw_readl(USB_PHY_CTRL) & USBPHY_PHYCLKGD) == 0)
61 cpu_relax();
62}
63
64static inline void phy_off(void)
65{
66 u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
67
68 /* powerdown the on-chip PHY, its PLL, and the OTG block */
69 phy_ctrl &= ~(USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON);
70 phy_ctrl |= USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN;
71 __raw_writel(phy_ctrl, USB_PHY_CTRL);
72}
73
74static int dma_off = 1;
75
76static void davinci_musb_enable(struct musb *musb)
77{
78 u32 tmp, old, val;
79
80 /* workaround: setup irqs through both register sets */
81 tmp = (musb->epmask & DAVINCI_USB_TX_ENDPTS_MASK)
82 << DAVINCI_USB_TXINT_SHIFT;
83 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp);
84 old = tmp;
85 tmp = (musb->epmask & (0xfffe & DAVINCI_USB_RX_ENDPTS_MASK))
86 << DAVINCI_USB_RXINT_SHIFT;
87 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp);
88 tmp |= old;
89
90 val = ~MUSB_INTR_SOF;
91 tmp |= ((val & 0x01ff) << DAVINCI_USB_USBINT_SHIFT);
92 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp);
93
94 if (is_dma_capable() && !dma_off)
95 printk(KERN_WARNING "%s %s: dma not reactivated\n",
96 __FILE__, __func__);
97 else
98 dma_off = 0;
99
100 /* force a DRVVBUS irq so we can start polling for ID change */
101 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
102 DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT);
103}
104
105/*
106 * Disable the HDRC and flush interrupts
107 */
108static void davinci_musb_disable(struct musb *musb)
109{
110 /* because we don't set CTRLR.UINT, "important" to:
111 * - not read/write INTRUSB/INTRUSBE
112 * - (except during initial setup, as workaround)
113 * - use INTSETR/INTCLRR instead
114 */
115 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_CLR_REG,
116 DAVINCI_USB_USBINT_MASK
117 | DAVINCI_USB_TXINT_MASK
118 | DAVINCI_USB_RXINT_MASK);
119 musb_writel(musb->ctrl_base, DAVINCI_USB_EOI_REG, 0);
120
121 if (is_dma_capable() && !dma_off)
122 WARNING("dma still active\n");
123}
124
125
126#define portstate(stmt) stmt
127
128/*
129 * VBUS SWITCHING IS BOARD-SPECIFIC ... at least for the DM6446 EVM,
130 * which doesn't wire DRVVBUS to the FET that switches it. Unclear
131 * if that's a problem with the DM6446 chip or just with that board.
132 *
133 * In either case, the DM355 EVM automates DRVVBUS the normal way,
134 * when J10 is out, and TI documents it as handling OTG.
135 */
136
137/* I2C operations are always synchronous, and require a task context.
138 * With unloaded systems, using the shared workqueue seems to suffice
139 * to satisfy the 100msec A_WAIT_VRISE timeout...
140 */
141static void evm_deferred_drvvbus(struct work_struct *work)
142{
143 struct davinci_glue *glue = container_of(work, struct davinci_glue,
144 vbus_work);
145
146 gpiod_set_value_cansleep(glue->vbus, glue->vbus_state);
147 glue->vbus_state = !glue->vbus_state;
148}
149
150static void davinci_musb_source_power(struct musb *musb, int is_on,
151 int immediate)
152{
153 struct davinci_glue *glue = dev_get_drvdata(musb->controller->parent);
154
155 /* This GPIO handling is entirely optional */
156 if (!glue->vbus)
157 return;
158
159 if (is_on)
160 is_on = 1;
161
162 if (glue->vbus_state == is_on)
163 return;
164 /* 0/1 vs "-1 == unknown/init" */
165 glue->vbus_state = !is_on;
166
167 if (machine_is_davinci_evm()) {
168 if (immediate)
169 gpiod_set_value_cansleep(glue->vbus, glue->vbus_state);
170 else
171 schedule_work(&glue->vbus_work);
172 }
173 if (immediate)
174 glue->vbus_state = is_on;
175}
176
177static void davinci_musb_set_vbus(struct musb *musb, int is_on)
178{
179 WARN_ON(is_on && is_peripheral_active(musb));
180 davinci_musb_source_power(musb, is_on, 0);
181}
182
183
184#define POLL_SECONDS 2
185
186static void otg_timer(struct timer_list *t)
187{
188 struct musb *musb = from_timer(musb, t, dev_timer);
189 void __iomem *mregs = musb->mregs;
190 u8 devctl;
191 unsigned long flags;
192
193 /* We poll because DaVinci's won't expose several OTG-critical
194 * status change events (from the transceiver) otherwise.
195 */
196 devctl = musb_readb(mregs, MUSB_DEVCTL);
197 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl,
198 usb_otg_state_string(musb->xceiv->otg->state));
199
200 spin_lock_irqsave(&musb->lock, flags);
201 switch (musb->xceiv->otg->state) {
202 case OTG_STATE_A_WAIT_VFALL:
203 /* Wait till VBUS falls below SessionEnd (~0.2V); the 1.3 RTL
204 * seems to mis-handle session "start" otherwise (or in our
205 * case "recover"), in routine "VBUS was valid by the time
206 * VBUSERR got reported during enumeration" cases.
207 */
208 if (devctl & MUSB_DEVCTL_VBUS) {
209 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
210 break;
211 }
212 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
213 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
214 MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT);
215 break;
216 case OTG_STATE_B_IDLE:
217 /*
218 * There's no ID-changed IRQ, so we have no good way to tell
219 * when to switch to the A-Default state machine (by setting
220 * the DEVCTL.SESSION flag).
221 *
222 * Workaround: whenever we're in B_IDLE, try setting the
223 * session flag every few seconds. If it works, ID was
224 * grounded and we're now in the A-Default state machine.
225 *
226 * NOTE setting the session flag is _supposed_ to trigger
227 * SRP, but clearly it doesn't.
228 */
229 musb_writeb(mregs, MUSB_DEVCTL,
230 devctl | MUSB_DEVCTL_SESSION);
231 devctl = musb_readb(mregs, MUSB_DEVCTL);
232 if (devctl & MUSB_DEVCTL_BDEVICE)
233 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
234 else
235 musb->xceiv->otg->state = OTG_STATE_A_IDLE;
236 break;
237 default:
238 break;
239 }
240 spin_unlock_irqrestore(&musb->lock, flags);
241}
242
243static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
244{
245 unsigned long flags;
246 irqreturn_t retval = IRQ_NONE;
247 struct musb *musb = __hci;
248 struct usb_otg *otg = musb->xceiv->otg;
249 void __iomem *tibase = musb->ctrl_base;
250 struct cppi *cppi;
251 u32 tmp;
252
253 spin_lock_irqsave(&musb->lock, flags);
254
255 /* NOTE: DaVinci shadows the Mentor IRQs. Don't manage them through
256 * the Mentor registers (except for setup), use the TI ones and EOI.
257 *
258 * Docs describe irq "vector" registers associated with the CPPI and
259 * USB EOI registers. These hold a bitmask corresponding to the
260 * current IRQ, not an irq handler address. Would using those bits
261 * resolve some of the races observed in this dispatch code??
262 */
263
264 /* CPPI interrupts share the same IRQ line, but have their own
265 * mask, state, "vector", and EOI registers.
266 */
267 cppi = container_of(musb->dma_controller, struct cppi, controller);
268 if (is_cppi_enabled(musb) && musb->dma_controller && !cppi->irq)
269 retval = cppi_interrupt(irq, __hci);
270
271 /* ack and handle non-CPPI interrupts */
272 tmp = musb_readl(tibase, DAVINCI_USB_INT_SRC_MASKED_REG);
273 musb_writel(tibase, DAVINCI_USB_INT_SRC_CLR_REG, tmp);
274 dev_dbg(musb->controller, "IRQ %08x\n", tmp);
275
276 musb->int_rx = (tmp & DAVINCI_USB_RXINT_MASK)
277 >> DAVINCI_USB_RXINT_SHIFT;
278 musb->int_tx = (tmp & DAVINCI_USB_TXINT_MASK)
279 >> DAVINCI_USB_TXINT_SHIFT;
280 musb->int_usb = (tmp & DAVINCI_USB_USBINT_MASK)
281 >> DAVINCI_USB_USBINT_SHIFT;
282
283 /* DRVVBUS irqs are the only proxy we have (a very poor one!) for
284 * DaVinci's missing ID change IRQ. We need an ID change IRQ to
285 * switch appropriately between halves of the OTG state machine.
286 * Managing DEVCTL.SESSION per Mentor docs requires we know its
287 * value, but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
288 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
289 */
290 if (tmp & (DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT)) {
291 int drvvbus = musb_readl(tibase, DAVINCI_USB_STAT_REG);
292 void __iomem *mregs = musb->mregs;
293 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
294 int err = musb->int_usb & MUSB_INTR_VBUSERROR;
295
296 err = musb->int_usb & MUSB_INTR_VBUSERROR;
297 if (err) {
298 /* The Mentor core doesn't debounce VBUS as needed
299 * to cope with device connect current spikes. This
300 * means it's not uncommon for bus-powered devices
301 * to get VBUS errors during enumeration.
302 *
303 * This is a workaround, but newer RTL from Mentor
304 * seems to allow a better one: "re"starting sessions
305 * without waiting (on EVM, a **long** time) for VBUS
306 * to stop registering in devctl.
307 */
308 musb->int_usb &= ~MUSB_INTR_VBUSERROR;
309 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
310 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
311 WARNING("VBUS error workaround (delay coming)\n");
312 } else if (drvvbus) {
313 MUSB_HST_MODE(musb);
314 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
315 portstate(musb->port1_status |= USB_PORT_STAT_POWER);
316 del_timer(&musb->dev_timer);
317 } else {
318 musb->is_active = 0;
319 MUSB_DEV_MODE(musb);
320 musb->xceiv->otg->state = OTG_STATE_B_IDLE;
321 portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
322 }
323
324 /* NOTE: this must complete poweron within 100 msec
325 * (OTG_TIME_A_WAIT_VRISE) but we don't check for that.
326 */
327 davinci_musb_source_power(musb, drvvbus, 0);
328 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
329 drvvbus ? "on" : "off",
330 usb_otg_state_string(musb->xceiv->otg->state),
331 err ? " ERROR" : "",
332 devctl);
333 retval = IRQ_HANDLED;
334 }
335
336 if (musb->int_tx || musb->int_rx || musb->int_usb)
337 retval |= musb_interrupt(musb);
338
339 /* irq stays asserted until EOI is written */
340 musb_writel(tibase, DAVINCI_USB_EOI_REG, 0);
341
342 /* poll for ID change */
343 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE)
344 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
345
346 spin_unlock_irqrestore(&musb->lock, flags);
347
348 return retval;
349}
350
351static int davinci_musb_set_mode(struct musb *musb, u8 mode)
352{
353 /* EVM can't do this (right?) */
354 return -EIO;
355}
356
357static int davinci_musb_init(struct musb *musb)
358{
359 void __iomem *tibase = musb->ctrl_base;
360 u32 revision;
361 int ret = -ENODEV;
362
363 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
364 if (IS_ERR_OR_NULL(musb->xceiv)) {
365 ret = -EPROBE_DEFER;
366 goto unregister;
367 }
368
369 musb->mregs += DAVINCI_BASE_OFFSET;
370
371 /* returns zero if e.g. not clocked */
372 revision = musb_readl(tibase, DAVINCI_USB_VERSION_REG);
373 if (revision == 0)
374 goto fail;
375
376 timer_setup(&musb->dev_timer, otg_timer, 0);
377
378 davinci_musb_source_power(musb, 0, 1);
379
380 /* dm355 EVM swaps D+/D- for signal integrity, and
381 * is clocked from the main 24 MHz crystal.
382 */
383 if (machine_is_davinci_dm355_evm()) {
384 u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
385
386 phy_ctrl &= ~(3 << 9);
387 phy_ctrl |= USBPHY_DATAPOL;
388 __raw_writel(phy_ctrl, USB_PHY_CTRL);
389 }
390
391 /* On dm355, the default-A state machine needs DRVVBUS control.
392 * If we won't be a host, there's no need to turn it on.
393 */
394 if (cpu_is_davinci_dm355()) {
395 u32 deepsleep = __raw_readl(DM355_DEEPSLEEP);
396
397 deepsleep &= ~DRVVBUS_FORCE;
398 __raw_writel(deepsleep, DM355_DEEPSLEEP);
399 }
400
401 /* reset the controller */
402 musb_writel(tibase, DAVINCI_USB_CTRL_REG, 0x1);
403
404 /* start the on-chip PHY and its PLL */
405 phy_on();
406
407 msleep(5);
408
409 /* NOTE: irqs are in mixed mode, not bypass to pure-musb */
410 pr_debug("DaVinci OTG revision %08x phy %03x control %02x\n",
411 revision, __raw_readl(USB_PHY_CTRL),
412 musb_readb(tibase, DAVINCI_USB_CTRL_REG));
413
414 musb->isr = davinci_musb_interrupt;
415 return 0;
416
417fail:
418 usb_put_phy(musb->xceiv);
419unregister:
420 usb_phy_generic_unregister();
421 return ret;
422}
423
424static int davinci_musb_exit(struct musb *musb)
425{
426 int maxdelay = 30;
427 u8 devctl, warn = 0;
428
429 del_timer_sync(&musb->dev_timer);
430
431 /* force VBUS off */
432 if (cpu_is_davinci_dm355()) {
433 u32 deepsleep = __raw_readl(DM355_DEEPSLEEP);
434
435 deepsleep &= ~DRVVBUS_FORCE;
436 deepsleep |= DRVVBUS_OVERRIDE;
437 __raw_writel(deepsleep, DM355_DEEPSLEEP);
438 }
439
440 davinci_musb_source_power(musb, 0 /*off*/, 1);
441
442 /*
443 * delay, to avoid problems with module reload.
444 * if there's no peripheral connected, this can take a
445 * long time to fall, especially on EVM with huge C133.
446 */
447 do {
448 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
449 if (!(devctl & MUSB_DEVCTL_VBUS))
450 break;
451 if ((devctl & MUSB_DEVCTL_VBUS) != warn) {
452 warn = devctl & MUSB_DEVCTL_VBUS;
453 dev_dbg(musb->controller, "VBUS %d\n",
454 warn >> MUSB_DEVCTL_VBUS_SHIFT);
455 }
456 msleep(1000);
457 maxdelay--;
458 } while (maxdelay > 0);
459
460 /* in OTG mode, another host might be connected */
461 if (devctl & MUSB_DEVCTL_VBUS)
462 dev_dbg(musb->controller, "VBUS off timeout (devctl %02x)\n", devctl);
463
464 phy_off();
465
466 usb_put_phy(musb->xceiv);
467
468 return 0;
469}
470
471static const struct musb_platform_ops davinci_ops = {
472 .quirks = MUSB_DMA_CPPI,
473 .init = davinci_musb_init,
474 .exit = davinci_musb_exit,
475
476#ifdef CONFIG_USB_TI_CPPI_DMA
477 .dma_init = cppi_dma_controller_create,
478 .dma_exit = cppi_dma_controller_destroy,
479#endif
480 .enable = davinci_musb_enable,
481 .disable = davinci_musb_disable,
482
483 .set_mode = davinci_musb_set_mode,
484
485 .set_vbus = davinci_musb_set_vbus,
486};
487
488static const struct platform_device_info davinci_dev_info = {
489 .name = "musb-hdrc",
490 .id = PLATFORM_DEVID_AUTO,
491 .dma_mask = DMA_BIT_MASK(32),
492};
493
494static int davinci_probe(struct platform_device *pdev)
495{
496 struct resource musb_resources[3];
497 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
498 struct platform_device *musb;
499 struct davinci_glue *glue;
500 struct platform_device_info pinfo;
501 struct clk *clk;
502
503 int ret = -ENOMEM;
504
505 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
506 if (!glue)
507 goto err0;
508
509 clk = devm_clk_get(&pdev->dev, "usb");
510 if (IS_ERR(clk)) {
511 dev_err(&pdev->dev, "failed to get clock\n");
512 ret = PTR_ERR(clk);
513 goto err0;
514 }
515
516 ret = clk_enable(clk);
517 if (ret) {
518 dev_err(&pdev->dev, "failed to enable clock\n");
519 goto err0;
520 }
521
522 glue->dev = &pdev->dev;
523 glue->clk = clk;
524
525 pdata->platform_ops = &davinci_ops;
526
527 glue->vbus = devm_gpiod_get_optional(&pdev->dev, NULL, GPIOD_OUT_LOW);
528 if (IS_ERR(glue->vbus)) {
529 ret = PTR_ERR(glue->vbus);
530 goto err0;
531 } else {
532 glue->vbus_state = -1;
533 INIT_WORK(&glue->vbus_work, evm_deferred_drvvbus);
534 }
535
536 usb_phy_generic_register();
537 platform_set_drvdata(pdev, glue);
538
539 memset(musb_resources, 0x00, sizeof(*musb_resources) *
540 ARRAY_SIZE(musb_resources));
541
542 musb_resources[0].name = pdev->resource[0].name;
543 musb_resources[0].start = pdev->resource[0].start;
544 musb_resources[0].end = pdev->resource[0].end;
545 musb_resources[0].flags = pdev->resource[0].flags;
546
547 musb_resources[1].name = pdev->resource[1].name;
548 musb_resources[1].start = pdev->resource[1].start;
549 musb_resources[1].end = pdev->resource[1].end;
550 musb_resources[1].flags = pdev->resource[1].flags;
551
552 /*
553 * For DM6467 3 resources are passed. A placeholder for the 3rd
554 * resource is always there, so it's safe to always copy it...
555 */
556 musb_resources[2].name = pdev->resource[2].name;
557 musb_resources[2].start = pdev->resource[2].start;
558 musb_resources[2].end = pdev->resource[2].end;
559 musb_resources[2].flags = pdev->resource[2].flags;
560
561 pinfo = davinci_dev_info;
562 pinfo.parent = &pdev->dev;
563 pinfo.res = musb_resources;
564 pinfo.num_res = ARRAY_SIZE(musb_resources);
565 pinfo.data = pdata;
566 pinfo.size_data = sizeof(*pdata);
567
568 glue->musb = musb = platform_device_register_full(&pinfo);
569 if (IS_ERR(musb)) {
570 ret = PTR_ERR(musb);
571 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
572 goto err1;
573 }
574
575 return 0;
576
577err1:
578 clk_disable(clk);
579
580err0:
581 return ret;
582}
583
584static int davinci_remove(struct platform_device *pdev)
585{
586 struct davinci_glue *glue = platform_get_drvdata(pdev);
587
588 platform_device_unregister(glue->musb);
589 usb_phy_generic_unregister();
590 clk_disable(glue->clk);
591
592 return 0;
593}
594
595static struct platform_driver davinci_driver = {
596 .probe = davinci_probe,
597 .remove = davinci_remove,
598 .driver = {
599 .name = "musb-davinci",
600 },
601};
602
603MODULE_DESCRIPTION("DaVinci MUSB Glue Layer");
604MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
605MODULE_LICENSE("GPL v2");
606module_platform_driver(davinci_driver);
drivers/usb/musb/davinci.h+0−103
@@ -1,103 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2005-2006 by Texas Instruments
4 */
5
6#ifndef __MUSB_HDRDF_H__
7#define __MUSB_HDRDF_H__
8
9/*
10 * DaVinci-specific definitions
11 */
12
13/* Integrated highspeed/otg PHY */
14#define USBPHY_CTL_PADDR 0x01c40034
15#define USBPHY_DATAPOL BIT(11) /* (dm355) switch D+/D- */
16#define USBPHY_PHYCLKGD BIT(8)
17#define USBPHY_SESNDEN BIT(7) /* v(sess_end) comparator */
18#define USBPHY_VBDTCTEN BIT(6) /* v(bus) comparator */
19#define USBPHY_VBUSSENS BIT(5) /* (dm355,ro) is vbus > 0.5V */
20#define USBPHY_PHYPLLON BIT(4) /* override pll suspend */
21#define USBPHY_CLKO1SEL BIT(3)
22#define USBPHY_OSCPDWN BIT(2)
23#define USBPHY_OTGPDWN BIT(1)
24#define USBPHY_PHYPDWN BIT(0)
25
26#define DM355_DEEPSLEEP_PADDR 0x01c40048
27#define DRVVBUS_FORCE BIT(2)
28#define DRVVBUS_OVERRIDE BIT(1)
29
30/* For now include usb OTG module registers here */
31#define DAVINCI_USB_VERSION_REG 0x00
32#define DAVINCI_USB_CTRL_REG 0x04
33#define DAVINCI_USB_STAT_REG 0x08
34#define DAVINCI_RNDIS_REG 0x10
35#define DAVINCI_AUTOREQ_REG 0x14
36#define DAVINCI_USB_INT_SOURCE_REG 0x20
37#define DAVINCI_USB_INT_SET_REG 0x24
38#define DAVINCI_USB_INT_SRC_CLR_REG 0x28
39#define DAVINCI_USB_INT_MASK_REG 0x2c
40#define DAVINCI_USB_INT_MASK_SET_REG 0x30
41#define DAVINCI_USB_INT_MASK_CLR_REG 0x34
42#define DAVINCI_USB_INT_SRC_MASKED_REG 0x38
43#define DAVINCI_USB_EOI_REG 0x3c
44#define DAVINCI_USB_EOI_INTVEC 0x40
45
46/* BEGIN CPPI-generic (?) */
47
48/* CPPI related registers */
49#define DAVINCI_TXCPPI_CTRL_REG 0x80
50#define DAVINCI_TXCPPI_TEAR_REG 0x84
51#define DAVINCI_CPPI_EOI_REG 0x88
52#define DAVINCI_CPPI_INTVEC_REG 0x8c
53#define DAVINCI_TXCPPI_MASKED_REG 0x90
54#define DAVINCI_TXCPPI_RAW_REG 0x94
55#define DAVINCI_TXCPPI_INTENAB_REG 0x98
56#define DAVINCI_TXCPPI_INTCLR_REG 0x9c
57
58#define DAVINCI_RXCPPI_CTRL_REG 0xC0
59#define DAVINCI_RXCPPI_MASKED_REG 0xD0
60#define DAVINCI_RXCPPI_RAW_REG 0xD4
61#define DAVINCI_RXCPPI_INTENAB_REG 0xD8
62#define DAVINCI_RXCPPI_INTCLR_REG 0xDC
63
64#define DAVINCI_RXCPPI_BUFCNT0_REG 0xE0
65#define DAVINCI_RXCPPI_BUFCNT1_REG 0xE4
66#define DAVINCI_RXCPPI_BUFCNT2_REG 0xE8
67#define DAVINCI_RXCPPI_BUFCNT3_REG 0xEC
68
69/* CPPI state RAM entries */
70#define DAVINCI_CPPI_STATERAM_BASE_OFFSET 0x100
71
72#define DAVINCI_TXCPPI_STATERAM_OFFSET(chnum) \
73 (DAVINCI_CPPI_STATERAM_BASE_OFFSET + ((chnum) * 0x40))
74#define DAVINCI_RXCPPI_STATERAM_OFFSET(chnum) \
75 (DAVINCI_CPPI_STATERAM_BASE_OFFSET + 0x20 + ((chnum) * 0x40))
76
77/* CPPI masks */
78#define DAVINCI_DMA_CTRL_ENABLE 1
79#define DAVINCI_DMA_CTRL_DISABLE 0
80
81#define DAVINCI_DMA_ALL_CHANNELS_ENABLE 0xF
82#define DAVINCI_DMA_ALL_CHANNELS_DISABLE 0xF
83
84/* END CPPI-generic (?) */
85
86#define DAVINCI_USB_TX_ENDPTS_MASK 0x1f /* ep0 + 4 tx */
87#define DAVINCI_USB_RX_ENDPTS_MASK 0x1e /* 4 rx */
88
89#define DAVINCI_USB_USBINT_SHIFT 16
90#define DAVINCI_USB_TXINT_SHIFT 0
91#define DAVINCI_USB_RXINT_SHIFT 8
92
93#define DAVINCI_INTR_DRVVBUS 0x0100
94
95#define DAVINCI_USB_USBINT_MASK 0x01ff0000 /* 8 Mentor, DRVVBUS */
96#define DAVINCI_USB_TXINT_MASK \
97 (DAVINCI_USB_TX_ENDPTS_MASK << DAVINCI_USB_TXINT_SHIFT)
98#define DAVINCI_USB_RXINT_MASK \
99 (DAVINCI_USB_RX_ENDPTS_MASK << DAVINCI_USB_RXINT_SHIFT)
100
101#define DAVINCI_BASE_OFFSET 0x400
102
103#endif /* __MUSB_HDRDF_H__ */
drivers/usb/musb/jz4740.c+54−8
@@ -11,6 +11,7 @@ · 10 unmodified lines
11#include <linux/kernel.h>11#include <linux/kernel.h>
12#include <linux/module.h>12#include <linux/module.h>
13#include <linux/of_device.h>13#include <linux/of_device.h>
14#include <linux/phy/phy.h>
14#include <linux/platform_device.h>15#include <linux/platform_device.h>
15#include <linux/usb/role.h>16#include <linux/usb/role.h>
16#include <linux/usb/usb_phy_generic.h>17#include <linux/usb/usb_phy_generic.h>
@@ -81,6 +82,9 @@ static int jz4740_musb_role_switch_set(struct usb_role_switch *sw, · 64 unmodified lines
81 struct jz4740_glue *glue = usb_role_switch_get_drvdata(sw);82 struct jz4740_glue *glue = usb_role_switch_get_drvdata(sw);
82 struct usb_phy *phy = glue->musb->xceiv;83 struct usb_phy *phy = glue->musb->xceiv;
83 84
85 if (!phy)
86 return 0;
87
84 switch (role) {88 switch (role) {
85 case USB_ROLE_NONE:89 case USB_ROLE_NONE:
86 atomic_notifier_call_chain(&phy->notifier, USB_EVENT_NONE, phy);90 atomic_notifier_call_chain(&phy->notifier, USB_EVENT_NONE, phy);
@@ -105,21 +109,51 @@ static int jz4740_musb_init(struct musb *musb) · 18 unmodified lines
105 .driver_data = glue,109 .driver_data = glue,
106 .fwnode = dev_fwnode(dev),110 .fwnode = dev_fwnode(dev),
107 };111 };
112 int err;
108 113
109 glue->musb = musb;114 glue->musb = musb;
110 115
111 if (dev->of_node)116 if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
112 musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0);117 musb->phy = devm_of_phy_get_by_index(dev, dev->of_node, 0);
113 else118 if (IS_ERR(musb->phy)) {
114 musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);119 err = PTR_ERR(musb->phy);
115 if (IS_ERR(musb->xceiv))120 if (err != -ENODEV) {
116 return dev_err_probe(dev, PTR_ERR(musb->xceiv),121 dev_err(dev, "Unable to get PHY\n");
117 "No transceiver configured\n");122 return err;
123 }
124
125 musb->phy = NULL;
126 }
127 }
128
129 if (musb->phy) {
130 err = phy_init(musb->phy);
131 if (err) {
132 dev_err(dev, "Failed to init PHY\n");
133 return err;
134 }
135
136 err = phy_power_on(musb->phy);
137 if (err) {
138 dev_err(dev, "Unable to power on PHY\n");
139 goto err_phy_shutdown;
140 }
141 } else {
142 if (dev->of_node)
143 musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0);
144 else
145 musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
146 if (IS_ERR(musb->xceiv)) {
147 dev_err(dev, "No transceiver configured\n");
148 return PTR_ERR(musb->xceiv);
149 }
150 }
118 151
119 glue->role_sw = usb_role_switch_register(dev, &role_sw_desc);152 glue->role_sw = usb_role_switch_register(dev, &role_sw_desc);
120 if (IS_ERR(glue->role_sw)) {153 if (IS_ERR(glue->role_sw)) {
121 dev_err(dev, "Failed to register USB role switch\n");154 dev_err(dev, "Failed to register USB role switch\n");
122 return PTR_ERR(glue->role_sw);155 err = PTR_ERR(glue->role_sw);
156 goto err_phy_power_down;
123 }157 }
124 158
125 /*159 /*
@@ -131,6 +165,14 @@ static int jz4740_musb_init(struct musb *musb) · 5 unmodified lines
131 musb->isr = jz4740_musb_interrupt;165 musb->isr = jz4740_musb_interrupt;
132 166
133 return 0;167 return 0;
168
169err_phy_power_down:
170 if (musb->phy)
171 phy_power_off(musb->phy);
172err_phy_shutdown:
173 if (musb->phy)
174 phy_exit(musb->phy);
175 return err;
134}176}
135 177
136static int jz4740_musb_exit(struct musb *musb)178static int jz4740_musb_exit(struct musb *musb)
@@ -138,6 +180,10 @@ static int jz4740_musb_exit(struct musb *musb) · 1 unmodified line
138 struct jz4740_glue *glue = dev_get_drvdata(musb->controller->parent);180 struct jz4740_glue *glue = dev_get_drvdata(musb->controller->parent);
139 181
140 usb_role_switch_unregister(glue->role_sw);182 usb_role_switch_unregister(glue->role_sw);
183 if (musb->phy) {
184 phy_power_off(musb->phy);
185 phy_exit(musb->phy);
186 }
141 187
142 return 0;188 return 0;
143}189}
drivers/usb/musb/musb_core.c+51−56
@@ -502,7 +502,7 @@ int musb_set_host(struct musb *musb) · 501 unmodified lines
502 502
503init_data:503init_data:
504 musb->is_active = 1;504 musb->is_active = 1;
505 musb->xceiv->otg->state = OTG_STATE_A_IDLE;505 musb_set_state(musb, OTG_STATE_A_IDLE);
506 MUSB_HST_MODE(musb);506 MUSB_HST_MODE(musb);
507 507
508 return error;508 return error;
@@ -549,7 +549,7 @@ int musb_set_peripheral(struct musb *musb) · 40 unmodified lines
549 549
550init_data:550init_data:
551 musb->is_active = 0;551 musb->is_active = 0;
552 musb->xceiv->otg->state = OTG_STATE_B_IDLE;552 musb_set_state(musb, OTG_STATE_B_IDLE);
553 MUSB_DEV_MODE(musb);553 MUSB_DEV_MODE(musb);
554 554
555 return error;555 return error;
@@ -599,24 +599,24 @@ static void musb_otg_timer_func(struct timer_list *t) · 43 unmodified lines
599 unsigned long flags;599 unsigned long flags;
600 600
601 spin_lock_irqsave(&musb->lock, flags);601 spin_lock_irqsave(&musb->lock, flags);
602 switch (musb->xceiv->otg->state) {602 switch (musb_get_state(musb)) {
603 case OTG_STATE_B_WAIT_ACON:603 case OTG_STATE_B_WAIT_ACON:
604 musb_dbg(musb,604 musb_dbg(musb,
605 "HNP: b_wait_acon timeout; back to b_peripheral");605 "HNP: b_wait_acon timeout; back to b_peripheral");
606 musb_g_disconnect(musb);606 musb_g_disconnect(musb);
607 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;607 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
608 musb->is_active = 0;608 musb->is_active = 0;
609 break;609 break;
610 case OTG_STATE_A_SUSPEND:610 case OTG_STATE_A_SUSPEND:
611 case OTG_STATE_A_WAIT_BCON:611 case OTG_STATE_A_WAIT_BCON:
612 musb_dbg(musb, "HNP: %s timeout",612 musb_dbg(musb, "HNP: %s timeout",
613 usb_otg_state_string(musb->xceiv->otg->state));613 musb_otg_state_string(musb));
614 musb_platform_set_vbus(musb, 0);614 musb_platform_set_vbus(musb, 0);
615 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;615 musb_set_state(musb, OTG_STATE_A_WAIT_VFALL);
616 break;616 break;
617 default:617 default:
618 musb_dbg(musb, "HNP: Unhandled mode %s",618 musb_dbg(musb, "HNP: Unhandled mode %s",
619 usb_otg_state_string(musb->xceiv->otg->state));619 musb_otg_state_string(musb));
620 }620 }
621 spin_unlock_irqrestore(&musb->lock, flags);621 spin_unlock_irqrestore(&musb->lock, flags);
622}622}
@@ -630,20 +630,18 @@ void musb_hnp_stop(struct musb *musb) · 7 unmodified lines
630 void __iomem *mbase = musb->mregs;630 void __iomem *mbase = musb->mregs;
631 u8 reg;631 u8 reg;
632 632
633 musb_dbg(musb, "HNP: stop from %s",633 musb_dbg(musb, "HNP: stop from %s", musb_otg_state_string(musb));
634 usb_otg_state_string(musb->xceiv->otg->state));
635 634
636 switch (musb->xceiv->otg->state) {635 switch (musb_get_state(musb)) {
637 case OTG_STATE_A_PERIPHERAL:636 case OTG_STATE_A_PERIPHERAL:
638 musb_g_disconnect(musb);637 musb_g_disconnect(musb);
639 musb_dbg(musb, "HNP: back to %s",638 musb_dbg(musb, "HNP: back to %s", musb_otg_state_string(musb));
640 usb_otg_state_string(musb->xceiv->otg->state));
641 break;639 break;
642 case OTG_STATE_B_HOST:640 case OTG_STATE_B_HOST:
643 musb_dbg(musb, "HNP: Disabling HR");641 musb_dbg(musb, "HNP: Disabling HR");
644 if (hcd)642 if (hcd)
645 hcd->self.is_b_host = 0;643 hcd->self.is_b_host = 0;
646 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;644 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
647 MUSB_DEV_MODE(musb);645 MUSB_DEV_MODE(musb);
648 reg = musb_readb(mbase, MUSB_POWER);646 reg = musb_readb(mbase, MUSB_POWER);
649 reg |= MUSB_POWER_SUSPENDM;647 reg |= MUSB_POWER_SUSPENDM;
@@ -652,7 +650,7 @@ void musb_hnp_stop(struct musb *musb) · 2 unmodified lines
652 break;650 break;
653 default:651 default:
654 musb_dbg(musb, "HNP: Stopping in unknown state %s",652 musb_dbg(musb, "HNP: Stopping in unknown state %s",
655 usb_otg_state_string(musb->xceiv->otg->state));653 musb_otg_state_string(musb));
656 }654 }
657 655
658 /*656 /*
@@ -667,11 +665,10 @@ static void musb_recover_from_babble(struct musb *musb); · 8 unmodified lines
667 665
668static void musb_handle_intr_resume(struct musb *musb, u8 devctl)666static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
669{667{
670 musb_dbg(musb, "RESUME (%s)",668 musb_dbg(musb, "RESUME (%s)", musb_otg_state_string(musb));
671 usb_otg_state_string(musb->xceiv->otg->state));
672 669
673 if (devctl & MUSB_DEVCTL_HM) {670 if (devctl & MUSB_DEVCTL_HM) {
674 switch (musb->xceiv->otg->state) {671 switch (musb_get_state(musb)) {
675 case OTG_STATE_A_SUSPEND:672 case OTG_STATE_A_SUSPEND:
676 /* remote wakeup? */673 /* remote wakeup? */
677 musb->port1_status |=674 musb->port1_status |=
@@ -679,27 +676,27 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl) · 1 unmodified line
679 | MUSB_PORT_STAT_RESUME;676 | MUSB_PORT_STAT_RESUME;
680 musb->rh_timer = jiffies677 musb->rh_timer = jiffies
681 + msecs_to_jiffies(USB_RESUME_TIMEOUT);678 + msecs_to_jiffies(USB_RESUME_TIMEOUT);
682 musb->xceiv->otg->state = OTG_STATE_A_HOST;679 musb_set_state(musb, OTG_STATE_A_HOST);
683 musb->is_active = 1;680 musb->is_active = 1;
684 musb_host_resume_root_hub(musb);681 musb_host_resume_root_hub(musb);
685 schedule_delayed_work(&musb->finish_resume_work,682 schedule_delayed_work(&musb->finish_resume_work,
686 msecs_to_jiffies(USB_RESUME_TIMEOUT));683 msecs_to_jiffies(USB_RESUME_TIMEOUT));
687 break;684 break;
688 case OTG_STATE_B_WAIT_ACON:685 case OTG_STATE_B_WAIT_ACON:
689 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;686 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
690 musb->is_active = 1;687 musb->is_active = 1;
691 MUSB_DEV_MODE(musb);688 MUSB_DEV_MODE(musb);
692 break;689 break;
693 default:690 default:
694 WARNING("bogus %s RESUME (%s)\n",691 WARNING("bogus %s RESUME (%s)\n",
695 "host",692 "host",
696 usb_otg_state_string(musb->xceiv->otg->state));693 musb_otg_state_string(musb));
697 }694 }
698 } else {695 } else {
699 switch (musb->xceiv->otg->state) {696 switch (musb_get_state(musb)) {
700 case OTG_STATE_A_SUSPEND:697 case OTG_STATE_A_SUSPEND:
701 /* possibly DISCONNECT is upcoming */698 /* possibly DISCONNECT is upcoming */
702 musb->xceiv->otg->state = OTG_STATE_A_HOST;699 musb_set_state(musb, OTG_STATE_A_HOST);
703 musb_host_resume_root_hub(musb);700 musb_host_resume_root_hub(musb);
704 break;701 break;
705 case OTG_STATE_B_WAIT_ACON:702 case OTG_STATE_B_WAIT_ACON:
@@ -722,7 +719,7 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl) · 16 unmodified lines
722 default:719 default:
723 WARNING("bogus %s RESUME (%s)\n",720 WARNING("bogus %s RESUME (%s)\n",
724 "peripheral",721 "peripheral",
725 usb_otg_state_string(musb->xceiv->otg->state));722 musb_otg_state_string(musb));
726 }723 }
727 }724 }
728}725}
@@ -738,8 +735,7 @@ static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl) · 9 unmodified lines
738 return IRQ_HANDLED;735 return IRQ_HANDLED;
739 }736 }
740 737
741 musb_dbg(musb, "SESSION_REQUEST (%s)",738 musb_dbg(musb, "SESSION_REQUEST (%s)", musb_otg_state_string(musb));
742 usb_otg_state_string(musb->xceiv->otg->state));
743 739
744 /* IRQ arrives from ID pin sense or (later, if VBUS power740 /* IRQ arrives from ID pin sense or (later, if VBUS power
745 * is removed) SRP. responses are time critical:741 * is removed) SRP. responses are time critical:
@@ -750,7 +746,7 @@ static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl) · 4 unmodified lines
750 */746 */
751 musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);747 musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
752 musb->ep0_stage = MUSB_EP0_START;748 musb->ep0_stage = MUSB_EP0_START;
753 musb->xceiv->otg->state = OTG_STATE_A_IDLE;749 musb_set_state(musb, OTG_STATE_A_IDLE);
754 MUSB_HST_MODE(musb);750 MUSB_HST_MODE(musb);
755 musb_platform_set_vbus(musb, 1);751 musb_platform_set_vbus(musb, 1);
756 752
@@ -777,7 +773,7 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl) · 20 unmodified lines
777 * REVISIT: do delays from lots of DEBUG_KERNEL checks773 * REVISIT: do delays from lots of DEBUG_KERNEL checks
778 * make trouble here, keeping VBUS < 4.4V ?774 * make trouble here, keeping VBUS < 4.4V ?
779 */775 */
780 switch (musb->xceiv->otg->state) {776 switch (musb_get_state(musb)) {
781 case OTG_STATE_A_HOST:777 case OTG_STATE_A_HOST:
782 /* recovery is dicey once we've gotten past the778 /* recovery is dicey once we've gotten past the
783 * initial stages of enumeration, but if VBUS779 * initial stages of enumeration, but if VBUS
@@ -806,7 +802,7 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl) · 22 unmodified lines
806 802
807 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,803 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
808 "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",804 "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
809 usb_otg_state_string(musb->xceiv->otg->state),805 musb_otg_state_string(musb),
810 devctl,806 devctl,
811 ({ char *s;807 ({ char *s;
812 switch (devctl & MUSB_DEVCTL_VBUS) {808 switch (devctl & MUSB_DEVCTL_VBUS) {
@@ -831,9 +827,9 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl) · 18 unmodified lines
831static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)827static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
832{828{
833 musb_dbg(musb, "SUSPEND (%s) devctl %02x",829 musb_dbg(musb, "SUSPEND (%s) devctl %02x",
834 usb_otg_state_string(musb->xceiv->otg->state), devctl);830 musb_otg_state_string(musb), devctl);
835 831
836 switch (musb->xceiv->otg->state) {832 switch (musb_get_state(musb)) {
837 case OTG_STATE_A_PERIPHERAL:833 case OTG_STATE_A_PERIPHERAL:
838 /* We also come here if the cable is removed, since834 /* We also come here if the cable is removed, since
839 * this silicon doesn't report ID-no-longer-grounded.835 * this silicon doesn't report ID-no-longer-grounded.
@@ -858,7 +854,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) · 18 unmodified lines
858 musb_g_suspend(musb);854 musb_g_suspend(musb);
859 musb->is_active = musb->g.b_hnp_enable;855 musb->is_active = musb->g.b_hnp_enable;
860 if (musb->is_active) {856 if (musb->is_active) {
861 musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON;857 musb_set_state(musb, OTG_STATE_B_WAIT_ACON);
862 musb_dbg(musb, "HNP: Setting timer for b_ase0_brst");858 musb_dbg(musb, "HNP: Setting timer for b_ase0_brst");
863 mod_timer(&musb->otg_timer, jiffies859 mod_timer(&musb->otg_timer, jiffies
864 + msecs_to_jiffies(860 + msecs_to_jiffies(
@@ -871,7 +867,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) · 6 unmodified lines
871 + msecs_to_jiffies(musb->a_wait_bcon));867 + msecs_to_jiffies(musb->a_wait_bcon));
872 break;868 break;
873 case OTG_STATE_A_HOST:869 case OTG_STATE_A_HOST:
874 musb->xceiv->otg->state = OTG_STATE_A_SUSPEND;870 musb_set_state(musb, OTG_STATE_A_SUSPEND);
875 musb->is_active = musb->hcd->self.b_hnp_enable;871 musb->is_active = musb->hcd->self.b_hnp_enable;
876 break;872 break;
877 case OTG_STATE_B_HOST:873 case OTG_STATE_B_HOST:
@@ -909,7 +905,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb) · 31 unmodified lines
909 musb->port1_status |= USB_PORT_STAT_LOW_SPEED;905 musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
910 906
911 /* indicate new connection to OTG machine */907 /* indicate new connection to OTG machine */
912 switch (musb->xceiv->otg->state) {908 switch (musb_get_state(musb)) {
913 case OTG_STATE_B_PERIPHERAL:909 case OTG_STATE_B_PERIPHERAL:
914 if (int_usb & MUSB_INTR_SUSPEND) {910 if (int_usb & MUSB_INTR_SUSPEND) {
915 musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host");911 musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host");
@@ -921,7 +917,7 @@ static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb) · 5 unmodified lines
921 case OTG_STATE_B_WAIT_ACON:917 case OTG_STATE_B_WAIT_ACON:
922 musb_dbg(musb, "HNP: CONNECT, now b_host");918 musb_dbg(musb, "HNP: CONNECT, now b_host");
923b_host:919b_host:
924 musb->xceiv->otg->state = OTG_STATE_B_HOST;920 musb_set_state(musb, OTG_STATE_B_HOST);
925 if (musb->hcd)921 if (musb->hcd)
926 musb->hcd->self.is_b_host = 1;922 musb->hcd->self.is_b_host = 1;
927 del_timer(&musb->otg_timer);923 del_timer(&musb->otg_timer);
@@ -929,7 +925,7 @@ b_host: · 1 unmodified line
929 default:925 default:
930 if ((devctl & MUSB_DEVCTL_VBUS)926 if ((devctl & MUSB_DEVCTL_VBUS)
931 == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {927 == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
932 musb->xceiv->otg->state = OTG_STATE_A_HOST;928 musb_set_state(musb, OTG_STATE_A_HOST);
933 if (hcd)929 if (hcd)
934 hcd->self.is_b_host = 0;930 hcd->self.is_b_host = 0;
935 }931 }
@@ -939,16 +935,16 @@ b_host: · 3 unmodified lines
939 musb_host_poke_root_hub(musb);935 musb_host_poke_root_hub(musb);
940 936
941 musb_dbg(musb, "CONNECT (%s) devctl %02x",937 musb_dbg(musb, "CONNECT (%s) devctl %02x",
942 usb_otg_state_string(musb->xceiv->otg->state), devctl);938 musb_otg_state_string(musb), devctl);
943}939}
944 940
945static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)941static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)
946{942{
947 musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x",943 musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x",
948 usb_otg_state_string(musb->xceiv->otg->state),944 musb_otg_state_string(musb),
949 MUSB_MODE(musb), devctl);945 MUSB_MODE(musb), devctl);
950 946
951 switch (musb->xceiv->otg->state) {947 switch (musb_get_state(musb)) {
952 case OTG_STATE_A_HOST:948 case OTG_STATE_A_HOST:
953 case OTG_STATE_A_SUSPEND:949 case OTG_STATE_A_SUSPEND:
954 musb_host_resume_root_hub(musb);950 musb_host_resume_root_hub(musb);
@@ -966,7 +962,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) · 11 unmodified lines
966 musb_root_disconnect(musb);962 musb_root_disconnect(musb);
967 if (musb->hcd)963 if (musb->hcd)
968 musb->hcd->self.is_b_host = 0;964 musb->hcd->self.is_b_host = 0;
969 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;965 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
970 MUSB_DEV_MODE(musb);966 MUSB_DEV_MODE(musb);
971 musb_g_disconnect(musb);967 musb_g_disconnect(musb);
972 break;968 break;
@@ -981,7 +977,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) · 8 unmodified lines
981 break;977 break;
982 default:978 default:
983 WARNING("unhandled DISCONNECT transition (%s)\n",979 WARNING("unhandled DISCONNECT transition (%s)\n",
984 usb_otg_state_string(musb->xceiv->otg->state));980 musb_otg_state_string(musb));
985 break;981 break;
986 }982 }
987}983}
@@ -1004,16 +1000,15 @@ static void musb_handle_intr_reset(struct musb *musb) · 16 unmodified lines
1004 dev_err(musb->controller, "Babble\n");1000 dev_err(musb->controller, "Babble\n");
1005 musb_recover_from_babble(musb);1001 musb_recover_from_babble(musb);
1006 } else {1002 } else {
1007 musb_dbg(musb, "BUS RESET as %s",1003 musb_dbg(musb, "BUS RESET as %s", musb_otg_state_string(musb));
1008 usb_otg_state_string(musb->xceiv->otg->state));1004 switch (musb_get_state(musb)) {
1009 switch (musb->xceiv->otg->state) {
1010 case OTG_STATE_A_SUSPEND:1005 case OTG_STATE_A_SUSPEND:
1011 musb_g_reset(musb);1006 musb_g_reset(musb);
1012 fallthrough;1007 fallthrough;
1013 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */1008 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
1014 /* never use invalid T(a_wait_bcon) */1009 /* never use invalid T(a_wait_bcon) */
1015 musb_dbg(musb, "HNP: in %s, %d msec timeout",1010 musb_dbg(musb, "HNP: in %s, %d msec timeout",
1016 usb_otg_state_string(musb->xceiv->otg->state),1011 musb_otg_state_string(musb),
1017 TA_WAIT_BCON(musb));1012 TA_WAIT_BCON(musb));
1018 mod_timer(&musb->otg_timer, jiffies1013 mod_timer(&musb->otg_timer, jiffies
1019 + msecs_to_jiffies(TA_WAIT_BCON(musb)));1014 + msecs_to_jiffies(TA_WAIT_BCON(musb)));
@@ -1024,19 +1019,19 @@ static void musb_handle_intr_reset(struct musb *musb) · 4 unmodified lines
1024 break;1019 break;
1025 case OTG_STATE_B_WAIT_ACON:1020 case OTG_STATE_B_WAIT_ACON:
1026 musb_dbg(musb, "HNP: RESET (%s), to b_peripheral",1021 musb_dbg(musb, "HNP: RESET (%s), to b_peripheral",
1027 usb_otg_state_string(musb->xceiv->otg->state));1022 musb_otg_state_string(musb));
1028 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;1023 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
1029 musb_g_reset(musb);1024 musb_g_reset(musb);
1030 break;1025 break;
1031 case OTG_STATE_B_IDLE:1026 case OTG_STATE_B_IDLE:
1032 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;1027 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
1033 fallthrough;1028 fallthrough;
1034 case OTG_STATE_B_PERIPHERAL:1029 case OTG_STATE_B_PERIPHERAL:
1035 musb_g_reset(musb);1030 musb_g_reset(musb);
1036 break;1031 break;
1037 default:1032 default:
1038 musb_dbg(musb, "Unhandled BUS RESET as %s",1033 musb_dbg(musb, "Unhandled BUS RESET as %s",
1039 usb_otg_state_string(musb->xceiv->otg->state));1034 musb_otg_state_string(musb));
1040 }1035 }
1041 }1036 }
1042}1037}
@@ -1216,8 +1211,8 @@ void musb_start(struct musb *musb) · 173 unmodified lines
1216 * (c) peripheral initiates, using SRP1211 * (c) peripheral initiates, using SRP
1217 */1212 */
1218 if (musb->port_mode != MUSB_HOST &&1213 if (musb->port_mode != MUSB_HOST &&
1219 musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON &&1214 musb_get_state(musb) != OTG_STATE_A_WAIT_BCON &&
1220 (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {1215 (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
1221 musb->is_active = 1;1216 musb->is_active = 1;
1222 } else {1217 } else {
1223 devctl |= MUSB_DEVCTL_SESSION;1218 devctl |= MUSB_DEVCTL_SESSION;
@@ -1863,7 +1858,7 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) · 639 unmodified lines
1863 int ret;1858 int ret;
1864 1859
1865 spin_lock_irqsave(&musb->lock, flags);1860 spin_lock_irqsave(&musb->lock, flags);
1866 ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->otg->state));1861 ret = sprintf(buf, "%s\n", musb_otg_state_string(musb));
1867 spin_unlock_irqrestore(&musb->lock, flags);1862 spin_unlock_irqrestore(&musb->lock, flags);
1868 1863
1869 return ret;1864 return ret;
@@ -1908,7 +1903,7 @@ vbus_store(struct device *dev, struct device_attribute *attr, · 38 unmodified lines
1908 spin_lock_irqsave(&musb->lock, flags);1903 spin_lock_irqsave(&musb->lock, flags);
1909 /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */1904 /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
1910 musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;1905 musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;
1911 if (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)1906 if (musb_get_state(musb) == OTG_STATE_A_WAIT_BCON)
1912 musb->is_active = 0;1907 musb->is_active = 0;
1913 musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));1908 musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
1914 spin_unlock_irqrestore(&musb->lock, flags);1909 spin_unlock_irqrestore(&musb->lock, flags);
@@ -2089,8 +2084,8 @@ static void musb_irq_work(struct work_struct *data) · 174 unmodified lines
2089 2084
2090 musb_pm_runtime_check_session(musb);2085 musb_pm_runtime_check_session(musb);
2091 2086
2092 if (musb->xceiv->otg->state != musb->xceiv_old_state) {2087 if (musb_get_state(musb) != musb->xceiv_old_state) {
2093 musb->xceiv_old_state = musb->xceiv->otg->state;2088 musb->xceiv_old_state = musb_get_state(musb);
2094 sysfs_notify(&musb->controller->kobj, NULL, "mode");2089 sysfs_notify(&musb->controller->kobj, NULL, "mode");
2095 }2090 }
2096 2091
@@ -2453,7 +2448,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) · 356 unmodified lines
2453 else2448 else
2454 musb->io.set_toggle = musb_default_set_toggle;2449 musb->io.set_toggle = musb_default_set_toggle;
2455 2450
2456 if (!musb->xceiv->io_ops) {2451 if (IS_ENABLED(CONFIG_USB_PHY) && musb->xceiv && !musb->xceiv->io_ops) {
2457 musb->xceiv->io_dev = musb->controller;2452 musb->xceiv->io_dev = musb->controller;
2458 musb->xceiv->io_priv = musb->mregs;2453 musb->xceiv->io_priv = musb->mregs;
2459 musb->xceiv->io_ops = &musb_ulpi_access;2454 musb->xceiv->io_ops = &musb_ulpi_access;
@@ -2532,7 +2527,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) · 72 unmodified lines
2532 }2527 }
2533 2528
2534 MUSB_DEV_MODE(musb);2529 MUSB_DEV_MODE(musb);
2535 musb->xceiv->otg->state = OTG_STATE_B_IDLE;2530 musb_set_state(musb, OTG_STATE_B_IDLE);
2536 2531
2537 switch (musb->port_mode) {2532 switch (musb->port_mode) {
2538 case MUSB_HOST:2533 case MUSB_HOST:
drivers/usb/musb/musb_core.h+24−0
@@ -339,6 +339,8 @@ struct musb { · 338 unmodified lines
339 struct usb_phy *xceiv;339 struct usb_phy *xceiv;
340 struct phy *phy;340 struct phy *phy;
341 341
342 enum usb_otg_state otg_state;
343
342 int nIrq;344 int nIrq;
343 unsigned irq_wake:1;345 unsigned irq_wake:1;
344 346
@@ -592,6 +594,28 @@ static inline void musb_platform_clear_ep_rxintr(struct musb *musb, int epnum) · 247 unmodified lines
592 musb->ops->clear_ep_rxintr(musb, epnum);594 musb->ops->clear_ep_rxintr(musb, epnum);
593}595}
594 596
597static inline void musb_set_state(struct musb *musb,
598 enum usb_otg_state otg_state)
599{
600 if (musb->xceiv)
601 musb->xceiv->otg->state = otg_state;
602 else
603 musb->otg_state = otg_state;
604}
605
606static inline enum usb_otg_state musb_get_state(struct musb *musb)
607{
608 if (musb->xceiv)
609 return musb->xceiv->otg->state;
610
611 return musb->otg_state;
612}
613
614static inline const char *musb_otg_state_string(struct musb *musb)
615{
616 return usb_otg_state_string(musb_get_state(musb));
617}
618
595/*619/*
596 * gets the "dr_mode" property from DT and converts it into musb_mode620 * gets the "dr_mode" property from DT and converts it into musb_mode
597 * if the property is not found or not recognized returns MUSB_OTG621 * if the property is not found or not recognized returns MUSB_OTG
drivers/usb/musb/musb_debugfs.c+3−3
@@ -235,7 +235,7 @@ static int musb_softconnect_show(struct seq_file *s, void *unused) · 234 unmodified lines
235 u8 reg;235 u8 reg;
236 int connect;236 int connect;
237 237
238 switch (musb->xceiv->otg->state) {238 switch (musb_get_state(musb)) {
239 case OTG_STATE_A_HOST:239 case OTG_STATE_A_HOST:
240 case OTG_STATE_A_WAIT_BCON:240 case OTG_STATE_A_WAIT_BCON:
241 pm_runtime_get_sync(musb->controller);241 pm_runtime_get_sync(musb->controller);
@@ -275,7 +275,7 @@ static ssize_t musb_softconnect_write(struct file *file, · 33 unmodified lines
275 275
276 pm_runtime_get_sync(musb->controller);276 pm_runtime_get_sync(musb->controller);
277 if (!strncmp(buf, "0", 1)) {277 if (!strncmp(buf, "0", 1)) {
278 switch (musb->xceiv->otg->state) {278 switch (musb_get_state(musb)) {
279 case OTG_STATE_A_HOST:279 case OTG_STATE_A_HOST:
280 musb_root_disconnect(musb);280 musb_root_disconnect(musb);
281 reg = musb_readb(musb->mregs, MUSB_DEVCTL);281 reg = musb_readb(musb->mregs, MUSB_DEVCTL);
@@ -286,7 +286,7 @@ static ssize_t musb_softconnect_write(struct file *file, · 4 unmodified lines
286 break;286 break;
287 }287 }
288 } else if (!strncmp(buf, "1", 1)) {288 } else if (!strncmp(buf, "1", 1)) {
289 switch (musb->xceiv->otg->state) {289 switch (musb_get_state(musb)) {
290 case OTG_STATE_A_WAIT_BCON:290 case OTG_STATE_A_WAIT_BCON:
291 /*291 /*
292 * musb_save_context() called in musb_runtime_suspend()292 * musb_save_context() called in musb_runtime_suspend()
drivers/usb/musb/musb_dma.h+3−10
@@ -61,12 +61,6 @@ struct musb_hw_ep; · 60 unmodified lines
61#define musb_dma_cppi41(musb) 061#define musb_dma_cppi41(musb) 0
62#endif62#endif
63 63
64#ifdef CONFIG_USB_TI_CPPI_DMA
65#define musb_dma_cppi(musb) (musb->ops->quirks & MUSB_DMA_CPPI)
66#else
67#define musb_dma_cppi(musb) 0
68#endif
69
70#ifdef CONFIG_USB_TUSB_OMAP_DMA64#ifdef CONFIG_USB_TUSB_OMAP_DMA
71#define tusb_dma_omap(musb) (musb->ops->quirks & MUSB_DMA_TUSB_OMAP)65#define tusb_dma_omap(musb) (musb->ops->quirks & MUSB_DMA_TUSB_OMAP)
72#else66#else
@@ -79,11 +73,10 @@ struct musb_hw_ep; · 6 unmodified lines
79#define musb_dma_inventra(musb) 073#define musb_dma_inventra(musb) 0
80#endif74#endif
81 75
82#if defined(CONFIG_USB_TI_CPPI_DMA) || defined(CONFIG_USB_TI_CPPI41_DMA)76#if defined(CONFIG_USB_TI_CPPI41_DMA)
83#define is_cppi_enabled(musb) \77#define is_cppi_enabled(musb) musb_dma_cppi41(musb)
84 (musb_dma_cppi(musb) || musb_dma_cppi41(musb))
85#else78#else
86#define is_cppi_enabled(musb) 079#define is_cppi_enabled(musb) 0
87#endif80#endif
88 81
89/*82/*
drivers/usb/musb/musb_gadget.c+34−27
@@ -1523,7 +1523,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) · 1522 unmodified lines
1523 1523
1524 spin_lock_irqsave(&musb->lock, flags);1524 spin_lock_irqsave(&musb->lock, flags);
1525 1525
1526 switch (musb->xceiv->otg->state) {1526 switch (musb_get_state(musb)) {
1527 case OTG_STATE_B_PERIPHERAL:1527 case OTG_STATE_B_PERIPHERAL:
1528 /* NOTE: OTG state machine doesn't include B_SUSPENDED;1528 /* NOTE: OTG state machine doesn't include B_SUSPENDED;
1529 * that's part of the standard usb 1.1 state machine, and1529 * that's part of the standard usb 1.1 state machine, and
@@ -1552,9 +1552,11 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) · 22 unmodified lines
1552 break;1552 break;
1553 }1553 }
1554 1554
1555 spin_unlock_irqrestore(&musb->lock, flags);1555 if (musb->xceiv) {
1556 otg_start_srp(musb->xceiv->otg);1556 spin_unlock_irqrestore(&musb->lock, flags);
1557 spin_lock_irqsave(&musb->lock, flags);1557 otg_start_srp(musb->xceiv->otg);
1558 spin_lock_irqsave(&musb->lock, flags);
1559 }
1558 1560
1559 /* Block idling for at least 1s */1561 /* Block idling for at least 1s */
1560 musb_platform_try_idle(musb,1562 musb_platform_try_idle(musb,
@@ -1564,7 +1566,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) · 3 unmodified lines
1564 goto done;1566 goto done;
1565 default:1567 default:
1566 musb_dbg(musb, "Unhandled wake: %s",1568 musb_dbg(musb, "Unhandled wake: %s",
1567 usb_otg_state_string(musb->xceiv->otg->state));1569 musb_otg_state_string(musb));
1568 goto done;1570 goto done;
1569 }1571 }
1570 1572
@@ -1628,8 +1630,6 @@ static int musb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) · 57 unmodified lines
1628{1630{
1629 struct musb *musb = gadget_to_musb(gadget);1631 struct musb *musb = gadget_to_musb(gadget);
1630 1632
1631 if (!musb->xceiv->set_power)
1632 return -EOPNOTSUPP;
1633 return usb_phy_set_power(musb->xceiv, mA);1633 return usb_phy_set_power(musb->xceiv, mA);
1634}1634}
1635 1635
@@ -1787,7 +1787,7 @@ int musb_gadget_setup(struct musb *musb) · 151 unmodified lines
1787 musb->g.speed = USB_SPEED_UNKNOWN;1787 musb->g.speed = USB_SPEED_UNKNOWN;
1788 1788
1789 MUSB_DEV_MODE(musb);1789 MUSB_DEV_MODE(musb);
1790 musb->xceiv->otg->state = OTG_STATE_B_IDLE;1790 musb_set_state(musb, OTG_STATE_B_IDLE);
1791 1791
1792 /* this "gadget" abstracts/virtualizes the controller */1792 /* this "gadget" abstracts/virtualizes the controller */
1793 musb->g.name = musb_driver_name;1793 musb->g.name = musb_driver_name;
@@ -1834,7 +1834,6 @@ static int musb_gadget_start(struct usb_gadget *g, · 40 unmodified lines
1834 struct usb_gadget_driver *driver)1834 struct usb_gadget_driver *driver)
1835{1835{
1836 struct musb *musb = gadget_to_musb(g);1836 struct musb *musb = gadget_to_musb(g);
1837 struct usb_otg *otg = musb->xceiv->otg;
1838 unsigned long flags;1837 unsigned long flags;
1839 int retval = 0;1838 int retval = 0;
1840 1839
@@ -1851,8 +1850,12 @@ static int musb_gadget_start(struct usb_gadget *g, · 10 unmodified lines
1851 spin_lock_irqsave(&musb->lock, flags);1850 spin_lock_irqsave(&musb->lock, flags);
1852 musb->is_active = 1;1851 musb->is_active = 1;
1853 1852
1854 otg_set_peripheral(otg, &musb->g);1853 if (musb->xceiv)
1855 musb->xceiv->otg->state = OTG_STATE_B_IDLE;1854 otg_set_peripheral(musb->xceiv->otg, &musb->g);
1855 else
1856 phy_set_mode(musb->phy, PHY_MODE_USB_DEVICE);
1857
1858 musb_set_state(musb, OTG_STATE_B_IDLE);
1856 spin_unlock_irqrestore(&musb->lock, flags);1859 spin_unlock_irqrestore(&musb->lock, flags);
1857 1860
1858 musb_start(musb);1861 musb_start(musb);
@@ -1861,7 +1864,7 @@ static int musb_gadget_start(struct usb_gadget *g, · 2 unmodified lines
1861 * handles power budgeting ... this way also1864 * handles power budgeting ... this way also
1862 * ensures HdrcStart is indirectly called.1865 * ensures HdrcStart is indirectly called.
1863 */1866 */
1864 if (musb->xceiv->last_event == USB_EVENT_ID)1867 if (musb->xceiv && musb->xceiv->last_event == USB_EVENT_ID)
1865 musb_platform_set_vbus(musb, 1);1868 musb_platform_set_vbus(musb, 1);
1866 1869
1867 pm_runtime_mark_last_busy(musb->controller);1870 pm_runtime_mark_last_busy(musb->controller);
@@ -1897,9 +1900,13 @@ static int musb_gadget_stop(struct usb_gadget *g) · 29 unmodified lines
1897 1900
1898 (void) musb_gadget_vbus_draw(&musb->g, 0);1901 (void) musb_gadget_vbus_draw(&musb->g, 0);
1899 1902
1900 musb->xceiv->otg->state = OTG_STATE_UNDEFINED;1903 musb_set_state(musb, OTG_STATE_UNDEFINED);
1901 musb_stop(musb);1904 musb_stop(musb);
1902 otg_set_peripheral(musb->xceiv->otg, NULL);1905
1906 if (musb->xceiv)
1907 otg_set_peripheral(musb->xceiv->otg, NULL);
1908 else
1909 phy_set_mode(musb->phy, PHY_MODE_INVALID);
1903 1910
1904 musb->is_active = 0;1911 musb->is_active = 0;
1905 musb->gadget_driver = NULL;1912 musb->gadget_driver = NULL;
@@ -1926,7 +1933,7 @@ static int musb_gadget_stop(struct usb_gadget *g) · 20 unmodified lines
1926void musb_g_resume(struct musb *musb)1933void musb_g_resume(struct musb *musb)
1927{1934{
1928 musb->is_suspended = 0;1935 musb->is_suspended = 0;
1929 switch (musb->xceiv->otg->state) {1936 switch (musb_get_state(musb)) {
1930 case OTG_STATE_B_IDLE:1937 case OTG_STATE_B_IDLE:
1931 break;1938 break;
1932 case OTG_STATE_B_WAIT_ACON:1939 case OTG_STATE_B_WAIT_ACON:
@@ -1940,7 +1947,7 @@ void musb_g_resume(struct musb *musb) · 7 unmodified lines
1940 break;1947 break;
1941 default:1948 default:
1942 WARNING("unhandled RESUME transition (%s)\n",1949 WARNING("unhandled RESUME transition (%s)\n",
1943 usb_otg_state_string(musb->xceiv->otg->state));1950 musb_otg_state_string(musb));
1944 }1951 }
1945}1952}
1946 1953
@@ -1952,10 +1959,10 @@ void musb_g_suspend(struct musb *musb) · 5 unmodified lines
1952 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);1959 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
1953 musb_dbg(musb, "musb_g_suspend: devctl %02x", devctl);1960 musb_dbg(musb, "musb_g_suspend: devctl %02x", devctl);
1954 1961
1955 switch (musb->xceiv->otg->state) {1962 switch (musb_get_state(musb)) {
1956 case OTG_STATE_B_IDLE:1963 case OTG_STATE_B_IDLE:
1957 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)1964 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
1958 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;1965 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
1959 break;1966 break;
1960 case OTG_STATE_B_PERIPHERAL:1967 case OTG_STATE_B_PERIPHERAL:
1961 musb->is_suspended = 1;1968 musb->is_suspended = 1;
@@ -1970,7 +1977,7 @@ void musb_g_suspend(struct musb *musb) · 8 unmodified lines
1970 * A_PERIPHERAL may need care too1977 * A_PERIPHERAL may need care too
1971 */1978 */
1972 WARNING("unhandled SUSPEND transition (%s)",1979 WARNING("unhandled SUSPEND transition (%s)",
1973 usb_otg_state_string(musb->xceiv->otg->state));1980 musb_otg_state_string(musb));
1974 }1981 }
1975}1982}
1976 1983
@@ -2001,22 +2008,22 @@ void musb_g_disconnect(struct musb *musb) · 24 unmodified lines
2001 spin_lock(&musb->lock);2008 spin_lock(&musb->lock);
2002 }2009 }
2003 2010
2004 switch (musb->xceiv->otg->state) {2011 switch (musb_get_state(musb)) {
2005 default:2012 default:
2006 musb_dbg(musb, "Unhandled disconnect %s, setting a_idle",2013 musb_dbg(musb, "Unhandled disconnect %s, setting a_idle",
2007 usb_otg_state_string(musb->xceiv->otg->state));2014 musb_otg_state_string(musb));
2008 musb->xceiv->otg->state = OTG_STATE_A_IDLE;2015 musb_set_state(musb, OTG_STATE_A_IDLE);
2009 MUSB_HST_MODE(musb);2016 MUSB_HST_MODE(musb);
2010 break;2017 break;
2011 case OTG_STATE_A_PERIPHERAL:2018 case OTG_STATE_A_PERIPHERAL:
2012 musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON;2019 musb_set_state(musb, OTG_STATE_A_WAIT_BCON);
2013 MUSB_HST_MODE(musb);2020 MUSB_HST_MODE(musb);
2014 break;2021 break;
2015 case OTG_STATE_B_WAIT_ACON:2022 case OTG_STATE_B_WAIT_ACON:
2016 case OTG_STATE_B_HOST:2023 case OTG_STATE_B_HOST:
2017 case OTG_STATE_B_PERIPHERAL:2024 case OTG_STATE_B_PERIPHERAL:
2018 case OTG_STATE_B_IDLE:2025 case OTG_STATE_B_IDLE:
2019 musb->xceiv->otg->state = OTG_STATE_B_IDLE;2026 musb_set_state(musb, OTG_STATE_B_IDLE);
2020 break;2027 break;
2021 case OTG_STATE_B_SRP_INIT:2028 case OTG_STATE_B_SRP_INIT:
2022 break;2029 break;
@@ -2080,13 +2087,13 @@ __acquires(musb->lock) · 57 unmodified lines
2080 * In that case, do not rely on devctl for setting2087 * In that case, do not rely on devctl for setting
2081 * peripheral mode.2088 * peripheral mode.
2082 */2089 */
2083 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;2090 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
2084 musb->g.is_a_peripheral = 0;2091 musb->g.is_a_peripheral = 0;
2085 } else if (devctl & MUSB_DEVCTL_BDEVICE) {2092 } else if (devctl & MUSB_DEVCTL_BDEVICE) {
2086 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;2093 musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
2087 musb->g.is_a_peripheral = 0;2094 musb->g.is_a_peripheral = 0;
2088 } else {2095 } else {
2089 musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL;2096 musb_set_state(musb, OTG_STATE_A_PERIPHERAL);
2090 musb->g.is_a_peripheral = 1;2097 musb->g.is_a_peripheral = 1;
2091 }2098 }
2092 2099
drivers/usb/musb/musb_host.c+12−6
@@ -2501,7 +2501,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) · 2500 unmodified lines
2501 if (!is_host_active(musb))2501 if (!is_host_active(musb))
2502 return 0;2502 return 0;
2503 2503
2504 switch (musb->xceiv->otg->state) {2504 switch (musb_get_state(musb)) {
2505 case OTG_STATE_A_SUSPEND:2505 case OTG_STATE_A_SUSPEND:
2506 return 0;2506 return 0;
2507 case OTG_STATE_A_WAIT_VRISE:2507 case OTG_STATE_A_WAIT_VRISE:
@@ -2511,7 +2511,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) · 3 unmodified lines
2511 */2511 */
2512 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);2512 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
2513 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)2513 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
2514 musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON;2514 musb_set_state(musb, OTG_STATE_A_WAIT_BCON);
2515 break;2515 break;
2516 default:2516 default:
2517 break;2517 break;
@@ -2519,7 +2519,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) · 1 unmodified line
2519 2519
2520 if (musb->is_active) {2520 if (musb->is_active) {
2521 WARNING("trying to suspend as %s while active\n",2521 WARNING("trying to suspend as %s while active\n",
2522 usb_otg_state_string(musb->xceiv->otg->state));2522 musb_otg_state_string(musb));
2523 return -EBUSY;2523 return -EBUSY;
2524 } else2524 } else
2525 return 0;2525 return 0;
@@ -2720,12 +2720,18 @@ int musb_host_setup(struct musb *musb, int power_budget) · 194 unmodified lines
2720 2720
2721 if (musb->port_mode == MUSB_HOST) {2721 if (musb->port_mode == MUSB_HOST) {
2722 MUSB_HST_MODE(musb);2722 MUSB_HST_MODE(musb);
2723 musb->xceiv->otg->state = OTG_STATE_A_IDLE;2723 musb_set_state(musb, OTG_STATE_A_IDLE);
2724 }2724 }
2725 otg_set_host(musb->xceiv->otg, &hcd->self);2725
2726 if (musb->xceiv) {
2727 otg_set_host(musb->xceiv->otg, &hcd->self);
2728 musb->xceiv->otg->host = &hcd->self;
2729 } else {
2730 phy_set_mode(musb->phy, PHY_MODE_USB_HOST);
2731 }
2732
2726 /* don't support otg protocols */2733 /* don't support otg protocols */
2727 hcd->self.otg_port = 0;2734 hcd->self.otg_port = 0;
2728 musb->xceiv->otg->host = &hcd->self;
2729 hcd->power_budget = 2 * (power_budget ? : 250);2735 hcd->power_budget = 2 * (power_budget ? : 250);
2730 hcd->skip_phy_initialization = 1;2736 hcd->skip_phy_initialization = 1;
2731 2737
drivers/usb/musb/musb_virthub.c+16−17
@@ -43,14 +43,13 @@ void musb_host_finish_resume(struct work_struct *work) · 42 unmodified lines
43 musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16;43 musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16;
44 usb_hcd_poll_rh_status(musb->hcd);44 usb_hcd_poll_rh_status(musb->hcd);
45 /* NOTE: it might really be A_WAIT_BCON ... */45 /* NOTE: it might really be A_WAIT_BCON ... */
46 musb->xceiv->otg->state = OTG_STATE_A_HOST;46 musb_set_state(musb, OTG_STATE_A_HOST);
47 47
48 spin_unlock_irqrestore(&musb->lock, flags);48 spin_unlock_irqrestore(&musb->lock, flags);
49}49}
50 50
51int musb_port_suspend(struct musb *musb, bool do_suspend)51int musb_port_suspend(struct musb *musb, bool do_suspend)
52{52{
53 struct usb_otg *otg = musb->xceiv->otg;
54 u8 power;53 u8 power;
55 void __iomem *mbase = musb->mregs;54 void __iomem *mbase = musb->mregs;
56 55
@@ -85,10 +84,11 @@ int musb_port_suspend(struct musb *musb, bool do_suspend) · 28 unmodified lines
85 musb_dbg(musb, "Root port suspended, power %02x", power);84 musb_dbg(musb, "Root port suspended, power %02x", power);
86 85
87 musb->port1_status |= USB_PORT_STAT_SUSPEND;86 musb->port1_status |= USB_PORT_STAT_SUSPEND;
88 switch (musb->xceiv->otg->state) {87 switch (musb_get_state(musb)) {
89 case OTG_STATE_A_HOST:88 case OTG_STATE_A_HOST:
90 musb->xceiv->otg->state = OTG_STATE_A_SUSPEND;89 musb_set_state(musb, OTG_STATE_A_SUSPEND);
91 musb->is_active = otg->host->b_hnp_enable;90 musb->is_active = musb->xceiv &&
91 musb->xceiv->otg->host->b_hnp_enable;
92 if (musb->is_active)92 if (musb->is_active)
93 mod_timer(&musb->otg_timer, jiffies93 mod_timer(&musb->otg_timer, jiffies
94 + msecs_to_jiffies(94 + msecs_to_jiffies(
@@ -96,13 +96,14 @@ int musb_port_suspend(struct musb *musb, bool do_suspend) · 1 unmodified line
96 musb_platform_try_idle(musb, 0);96 musb_platform_try_idle(musb, 0);
97 break;97 break;
98 case OTG_STATE_B_HOST:98 case OTG_STATE_B_HOST:
99 musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON;99 musb_set_state(musb, OTG_STATE_B_WAIT_ACON);
100 musb->is_active = otg->host->b_hnp_enable;100 musb->is_active = musb->xceiv &&
101 musb->xceiv->otg->host->b_hnp_enable;
101 musb_platform_try_idle(musb, 0);102 musb_platform_try_idle(musb, 0);
102 break;103 break;
103 default:104 default:
104 musb_dbg(musb, "bogus rh suspend? %s",105 musb_dbg(musb, "bogus rh suspend? %s",
105 usb_otg_state_string(musb->xceiv->otg->state));106 musb_otg_state_string(musb));
106 }107 }
107 } else if (power & MUSB_POWER_SUSPENDM) {108 } else if (power & MUSB_POWER_SUSPENDM) {
108 power &= ~MUSB_POWER_SUSPENDM;109 power &= ~MUSB_POWER_SUSPENDM;
@@ -123,7 +124,7 @@ void musb_port_reset(struct musb *musb, bool do_reset) · 14 unmodified lines
123 u8 power;124 u8 power;
124 void __iomem *mbase = musb->mregs;125 void __iomem *mbase = musb->mregs;
125 126
126 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) {127 if (musb_get_state(musb) == OTG_STATE_B_IDLE) {
127 musb_dbg(musb, "HNP: Returning from HNP; no hub reset from b_idle");128 musb_dbg(musb, "HNP: Returning from HNP; no hub reset from b_idle");
128 musb->port1_status &= ~USB_PORT_STAT_RESET;129 musb->port1_status &= ~USB_PORT_STAT_RESET;
129 return;130 return;
@@ -196,32 +197,30 @@ void musb_port_reset(struct musb *musb, bool do_reset) · 66 unmodified lines
196 197
197void musb_root_disconnect(struct musb *musb)198void musb_root_disconnect(struct musb *musb)
198{199{
199 struct usb_otg *otg = musb->xceiv->otg;
200
201 musb->port1_status = USB_PORT_STAT_POWER200 musb->port1_status = USB_PORT_STAT_POWER
202 | (USB_PORT_STAT_C_CONNECTION << 16);201 | (USB_PORT_STAT_C_CONNECTION << 16);
203 202
204 usb_hcd_poll_rh_status(musb->hcd);203 usb_hcd_poll_rh_status(musb->hcd);
205 musb->is_active = 0;204 musb->is_active = 0;
206 205
207 switch (musb->xceiv->otg->state) {206 switch (musb_get_state(musb)) {
208 case OTG_STATE_A_SUSPEND:207 case OTG_STATE_A_SUSPEND:
209 if (otg->host->b_hnp_enable) {208 if (musb->xceiv && musb->xceiv->otg->host->b_hnp_enable) {
210 musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL;209 musb_set_state(musb, OTG_STATE_A_PERIPHERAL);
211 musb->g.is_a_peripheral = 1;210 musb->g.is_a_peripheral = 1;
212 break;211 break;
213 }212 }
214 fallthrough;213 fallthrough;
215 case OTG_STATE_A_HOST:214 case OTG_STATE_A_HOST:
216 musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON;215 musb_set_state(musb, OTG_STATE_A_WAIT_BCON);
217 musb->is_active = 0;216 musb->is_active = 0;
218 break;217 break;
219 case OTG_STATE_A_WAIT_VFALL:218 case OTG_STATE_A_WAIT_VFALL:
220 musb->xceiv->otg->state = OTG_STATE_B_IDLE;219 musb_set_state(musb, OTG_STATE_B_IDLE);
221 break;220 break;
222 default:221 default:
223 musb_dbg(musb, "host disconnect (%s)",222 musb_dbg(musb, "host disconnect (%s)",
224 usb_otg_state_string(musb->xceiv->otg->state));223 musb_otg_state_string(musb));
225 }224 }
226}225}
227EXPORT_SYMBOL_GPL(musb_root_disconnect);226EXPORT_SYMBOL_GPL(musb_root_disconnect);
drivers/usb/musb/omap2430.c+54−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
15#include <linux/list.h>15#include <linux/list.h>
16#include <linux/io.h>16#include <linux/io.h>
17#include <linux/of.h>17#include <linux/of.h>
18#include <linux/of_irq.h>
18#include <linux/platform_device.h>19#include <linux/platform_device.h>
19#include <linux/dma-mapping.h>20#include <linux/dma-mapping.h>
20#include <linux/pm_runtime.h>21#include <linux/pm_runtime.h>
@@ -310,6 +311,7 @@ static int omap2430_probe(struct platform_device *pdev) · 289 unmodified lines
310 struct device_node *control_node;311 struct device_node *control_node;
311 struct platform_device *control_pdev;312 struct platform_device *control_pdev;
312 int ret = -ENOMEM, val;313 int ret = -ENOMEM, val;
314 bool populate_irqs = false;
313 315
314 if (!np)316 if (!np)
315 return -ENODEV;317 return -ENODEV;
@@ -328,6 +330,18 @@ static int omap2430_probe(struct platform_device *pdev) · 12 unmodified lines
328 musb->dev.dma_mask = &omap2430_dmamask;330 musb->dev.dma_mask = &omap2430_dmamask;
329 musb->dev.coherent_dma_mask = omap2430_dmamask;331 musb->dev.coherent_dma_mask = omap2430_dmamask;
330 332
333 /*
334 * Legacy SoCs using omap_device get confused if node is moved
335 * because of interconnect properties mixed into the node.
336 */
337 if (of_get_property(np, "ti,hwmods", NULL)) {
338 dev_warn(&pdev->dev, "please update to probe with ti-sysc\n");
339 populate_irqs = true;
340 } else {
341 device_set_of_node_from_dev(&musb->dev, &pdev->dev);
342 }
343 of_node_put(np);
344
331 glue->dev = &pdev->dev;345 glue->dev = &pdev->dev;
332 glue->musb = musb;346 glue->musb = musb;
333 glue->status = MUSB_UNKNOWN;347 glue->status = MUSB_UNKNOWN;
@@ -389,6 +403,46 @@ static int omap2430_probe(struct platform_device *pdev) · 55 unmodified lines
389 goto err2;403 goto err2;
390 }404 }
391 405
406 if (populate_irqs) {
407 struct resource musb_res[3];
408 struct resource *res;
409 int i = 0;
410
411 memset(musb_res, 0, sizeof(*musb_res) * ARRAY_SIZE(musb_res));
412
413 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
414 if (!res)
415 goto err2;
416
417 musb_res[i].start = res->start;
418 musb_res[i].end = res->end;
419 musb_res[i].flags = res->flags;
420 musb_res[i].name = res->name;
421 i++;
422
423 ret = of_irq_get_byname(np, "mc");
424 if (ret > 0) {
425 musb_res[i].start = ret;
426 musb_res[i].flags = IORESOURCE_IRQ;
427 musb_res[i].name = "mc";
428 i++;
429 }
430
431 ret = of_irq_get_byname(np, "dma");
432 if (ret > 0) {
433 musb_res[i].start = ret;
434 musb_res[i].flags = IORESOURCE_IRQ;
435 musb_res[i].name = "dma";
436 i++;
437 }
438
439 ret = platform_device_add_resources(musb, musb_res, i);
440 if (ret) {
441 dev_err(&pdev->dev, "failed to add IRQ resources\n");
442 goto err2;
443 }
444 }
445
392 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));446 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
393 if (ret) {447 if (ret) {
394 dev_err(&pdev->dev, "failed to add platform_data\n");448 dev_err(&pdev->dev, "failed to add platform_data\n");
drivers/usb/phy/Kconfig+5−9
@@ -93,12 +93,16 @@ config USB_GPIO_VBUS · 92 unmodified lines
93 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"93 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"
94 depends on GPIOLIB || COMPILE_TEST94 depends on GPIOLIB || COMPILE_TEST
95 depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y'95 depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y'
96 depends on !USB_CONN_GPIO
96 select USB_PHY97 select USB_PHY
97 help98 help
98 Provides simple GPIO VBUS sensing for controllers with an99 Provides simple GPIO VBUS sensing for controllers with an
99 internal transceiver via the usb_phy interface, and100 internal transceiver via the usb_phy interface, and
100 optionally control of a D+ pullup GPIO as well as a VBUS101 optionally control of a D+ pullup GPIO as well as a VBUS
101 current limit regulator.102 current limit regulator. This driver is for devices that do
103 NOT support role switch. OTG devices that can do role switch
104 (master/peripheral) shall use the USB based connection
105 detection driver USB_CONN_GPIO.
102 106
103config OMAP_OTG107config OMAP_OTG
104 tristate "OMAP USB OTG controller driver"108 tristate "OMAP USB OTG controller driver"
@@ -185,12 +189,4 @@ config USB_ULPI_VIEWPORT · 80 unmodified lines
185 Provides read/write operations to the ULPI phy register set for189 Provides read/write operations to the ULPI phy register set for
186 controllers with a viewport register (e.g. Chipidea/ARC controllers).190 controllers with a viewport register (e.g. Chipidea/ARC controllers).
187 191
188config JZ4770_PHY
189 tristate "Ingenic SoCs Transceiver Driver"
190 depends on MIPS || COMPILE_TEST
191 select USB_PHY
192 help
193 This driver provides PHY support for the USB controller found
194 on the JZ-series and X-series SoCs from Ingenic.
195
196endmenu192endmenu
drivers/usb/phy/Makefile+0−1
@@ -24,4 +24,3 @@ obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o · 23 unmodified lines
24obj-$(CONFIG_USB_ULPI) += phy-ulpi.o24obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
25obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o25obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o
26obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o26obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o
27obj-$(CONFIG_JZ4770_PHY) += phy-jz4770.o
drivers/usb/phy/phy-generic.c+9−9
@@ -209,7 +209,7 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop) · 208 unmodified lines
209 int err = 0;209 int err = 0;
210 210
211 u32 clk_rate = 0;211 u32 clk_rate = 0;
212 bool needs_vcc = false, needs_clk = false;212 bool needs_clk = false;
213 213
214 if (dev->of_node) {214 if (dev->of_node) {
215 struct device_node *node = dev->of_node;215 struct device_node *node = dev->of_node;
@@ -217,7 +217,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop) · 1 unmodified line
217 if (of_property_read_u32(node, "clock-frequency", &clk_rate))217 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
218 clk_rate = 0;218 clk_rate = 0;
219 219
220 needs_vcc = of_property_read_bool(node, "vcc-supply");
221 needs_clk = of_property_read_bool(node, "clocks");220 needs_clk = of_property_read_bool(node, "clocks");
222 }221 }
223 nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset",222 nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
@@ -257,13 +256,10 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop) · 33 unmodified lines
257 }256 }
258 }257 }
259 258
260 nop->vcc = devm_regulator_get(dev, "vcc");259 nop->vcc = devm_regulator_get_optional(dev, "vcc");
261 if (IS_ERR(nop->vcc)) {260 if (IS_ERR(nop->vcc) && PTR_ERR(nop->vcc) != -ENODEV)
262 dev_dbg(dev, "Error getting vcc regulator: %ld\n",261 return dev_err_probe(dev, PTR_ERR(nop->vcc),
263 PTR_ERR(nop->vcc));262 "could not get vcc regulator\n");
264 if (needs_vcc)
265 return -EPROBE_DEFER;
266 }
267 263
268 nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus");264 nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus");
269 if (PTR_ERR(nop->vbus_draw) == -ENODEV)265 if (PTR_ERR(nop->vbus_draw) == -ENODEV)
@@ -290,6 +286,7 @@ EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); · 20 unmodified lines
290static int usb_phy_generic_probe(struct platform_device *pdev)286static int usb_phy_generic_probe(struct platform_device *pdev)
291{287{
292 struct device *dev = &pdev->dev;288 struct device *dev = &pdev->dev;
289 struct device_node *dn = dev->of_node;
293 struct usb_phy_generic *nop;290 struct usb_phy_generic *nop;
294 int err;291 int err;
295 292
@@ -327,6 +324,9 @@ static int usb_phy_generic_probe(struct platform_device *pdev) · 31 unmodified lines
327 324
328 platform_set_drvdata(pdev, nop);325 platform_set_drvdata(pdev, nop);
329 326
327 device_set_wakeup_capable(&pdev->dev,
328 of_property_read_bool(dn, "wakeup-source"));
329
330 return 0;330 return 0;
331}331}
332 332
drivers/usb/phy/phy-gpio-vbus-usb.c+12−0
@@ -366,12 +366,24 @@ static const struct dev_pm_ops gpio_vbus_dev_pm_ops = { · 365 unmodified lines
366 366
367MODULE_ALIAS("platform:gpio-vbus");367MODULE_ALIAS("platform:gpio-vbus");
368 368
369/*
370 * NOTE: this driver matches against "gpio-usb-b-connector" for
371 * devices that do NOT support role switch.
372 */
373static const struct of_device_id gpio_vbus_of_match[] = {
374 {
375 .compatible = "gpio-usb-b-connector",
376 },
377 {},
378};
379
369static struct platform_driver gpio_vbus_driver = {380static struct platform_driver gpio_vbus_driver = {
370 .driver = {381 .driver = {
371 .name = "gpio-vbus",382 .name = "gpio-vbus",
372#ifdef CONFIG_PM383#ifdef CONFIG_PM
373 .pm = &gpio_vbus_dev_pm_ops,384 .pm = &gpio_vbus_dev_pm_ops,
374#endif385#endif
386 .of_match_table = gpio_vbus_of_match,
375 },387 },
376 .probe = gpio_vbus_probe,388 .probe = gpio_vbus_probe,
377 .remove = gpio_vbus_remove,389 .remove = gpio_vbus_remove,
drivers/usb/phy/phy-isp1301-omap.c+2−2
@@ -1471,7 +1471,7 @@ isp1301_start_hnp(struct usb_otg *otg) · 1470 unmodified lines
1471/*-------------------------------------------------------------------------*/1471/*-------------------------------------------------------------------------*/
1472 1472
1473static int1473static int
1474isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)1474isp1301_probe(struct i2c_client *i2c)
1475{1475{
1476 int status;1476 int status;
1477 struct isp1301 *isp;1477 struct isp1301 *isp;
@@ -1616,7 +1616,7 @@ static struct i2c_driver isp1301_driver = { · 138 unmodified lines
1616 .driver = {1616 .driver = {
1617 .name = "isp1301_omap",1617 .name = "isp1301_omap",
1618 },1618 },
1619 .probe = isp1301_probe,1619 .probe_new = isp1301_probe,
1620 .remove = isp1301_remove,1620 .remove = isp1301_remove,
1621 .id_table = isp1301_id,1621 .id_table = isp1301_id,
1622};1622};
drivers/usb/phy/phy-isp1301.c+2−3
@@ -92,8 +92,7 @@ static int isp1301_phy_set_vbus(struct usb_phy *phy, int on) · 91 unmodified lines
92 return 0;92 return 0;
93}93}
94 94
95static int isp1301_probe(struct i2c_client *client,95static int isp1301_probe(struct i2c_client *client)
96 const struct i2c_device_id *i2c_id)
97{96{
98 struct isp1301 *isp;97 struct isp1301 *isp;
99 struct usb_phy *phy;98 struct usb_phy *phy;
@@ -133,7 +132,7 @@ static struct i2c_driver isp1301_driver = { · 33 unmodified lines
133 .name = DRV_NAME,132 .name = DRV_NAME,
134 .of_match_table = isp1301_of_match,133 .of_match_table = isp1301_of_match,
135 },134 },
136 .probe = isp1301_probe,135 .probe_new = isp1301_probe,
137 .remove = isp1301_remove,136 .remove = isp1301_remove,
138 .id_table = isp1301_id,137 .id_table = isp1301_id,
139};138};
drivers/usb/phy/phy-jz4770.c+0−353
@@ -1,353 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Ingenic SoCs USB PHY driver
4 * Copyright (c) Paul Cercueil <paul@crapouillou.net>
5 * Copyright (c) 漆鹏振 (Qi Pengzhen) <aric.pzqi@ingenic.com>
6 * Copyright (c) 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
7 */
8
9#include <linux/clk.h>
10#include <linux/io.h>
11#include <linux/module.h>
12#include <linux/platform_device.h>
13#include <linux/regulator/consumer.h>
14#include <linux/usb/otg.h>
15#include <linux/usb/phy.h>
16
17/* OTGPHY register offsets */
18#define REG_USBPCR_OFFSET 0x00
19#define REG_USBRDT_OFFSET 0x04
20#define REG_USBVBFIL_OFFSET 0x08
21#define REG_USBPCR1_OFFSET 0x0c
22
23/* bits within the USBPCR register */
24#define USBPCR_USB_MODE BIT(31)
25#define USBPCR_AVLD_REG BIT(30)
26#define USBPCR_COMMONONN BIT(25)
27#define USBPCR_VBUSVLDEXT BIT(24)
28#define USBPCR_VBUSVLDEXTSEL BIT(23)
29#define USBPCR_POR BIT(22)
30#define USBPCR_SIDDQ BIT(21)
31#define USBPCR_OTG_DISABLE BIT(20)
32#define USBPCR_TXPREEMPHTUNE BIT(6)
33
34#define USBPCR_IDPULLUP_LSB 28
35#define USBPCR_IDPULLUP_MASK GENMASK(29, USBPCR_IDPULLUP_LSB)
36#define USBPCR_IDPULLUP_ALWAYS (0x2 << USBPCR_IDPULLUP_LSB)
37#define USBPCR_IDPULLUP_SUSPEND (0x1 << USBPCR_IDPULLUP_LSB)
38#define USBPCR_IDPULLUP_OTG (0x0 << USBPCR_IDPULLUP_LSB)
39
40#define USBPCR_COMPDISTUNE_LSB 17
41#define USBPCR_COMPDISTUNE_MASK GENMASK(19, USBPCR_COMPDISTUNE_LSB)
42#define USBPCR_COMPDISTUNE_DFT (0x4 << USBPCR_COMPDISTUNE_LSB)
43
44#define USBPCR_OTGTUNE_LSB 14
45#define USBPCR_OTGTUNE_MASK GENMASK(16, USBPCR_OTGTUNE_LSB)
46#define USBPCR_OTGTUNE_DFT (0x4 << USBPCR_OTGTUNE_LSB)
47
48#define USBPCR_SQRXTUNE_LSB 11
49#define USBPCR_SQRXTUNE_MASK GENMASK(13, USBPCR_SQRXTUNE_LSB)
50#define USBPCR_SQRXTUNE_DCR_20PCT (0x7 << USBPCR_SQRXTUNE_LSB)
51#define USBPCR_SQRXTUNE_DFT (0x3 << USBPCR_SQRXTUNE_LSB)
52
53#define USBPCR_TXFSLSTUNE_LSB 7
54#define USBPCR_TXFSLSTUNE_MASK GENMASK(10, USBPCR_TXFSLSTUNE_LSB)
55#define USBPCR_TXFSLSTUNE_DCR_50PPT (0xf << USBPCR_TXFSLSTUNE_LSB)
56#define USBPCR_TXFSLSTUNE_DCR_25PPT (0x7 << USBPCR_TXFSLSTUNE_LSB)
57#define USBPCR_TXFSLSTUNE_DFT (0x3 << USBPCR_TXFSLSTUNE_LSB)
58#define USBPCR_TXFSLSTUNE_INC_25PPT (0x1 << USBPCR_TXFSLSTUNE_LSB)
59#define USBPCR_TXFSLSTUNE_INC_50PPT (0x0 << USBPCR_TXFSLSTUNE_LSB)
60
61#define USBPCR_TXHSXVTUNE_LSB 4
62#define USBPCR_TXHSXVTUNE_MASK GENMASK(5, USBPCR_TXHSXVTUNE_LSB)
63#define USBPCR_TXHSXVTUNE_DFT (0x3 << USBPCR_TXHSXVTUNE_LSB)
64#define USBPCR_TXHSXVTUNE_DCR_15MV (0x1 << USBPCR_TXHSXVTUNE_LSB)
65
66#define USBPCR_TXRISETUNE_LSB 4
67#define USBPCR_TXRISETUNE_MASK GENMASK(5, USBPCR_TXRISETUNE_LSB)
68#define USBPCR_TXRISETUNE_DFT (0x3 << USBPCR_TXRISETUNE_LSB)
69
70#define USBPCR_TXVREFTUNE_LSB 0
71#define USBPCR_TXVREFTUNE_MASK GENMASK(3, USBPCR_TXVREFTUNE_LSB)
72#define USBPCR_TXVREFTUNE_INC_25PPT (0x7 << USBPCR_TXVREFTUNE_LSB)
73#define USBPCR_TXVREFTUNE_DFT (0x5 << USBPCR_TXVREFTUNE_LSB)
74
75/* bits within the USBRDTR register */
76#define USBRDT_UTMI_RST BIT(27)
77#define USBRDT_HB_MASK BIT(26)
78#define USBRDT_VBFIL_LD_EN BIT(25)
79#define USBRDT_IDDIG_EN BIT(24)
80#define USBRDT_IDDIG_REG BIT(23)
81#define USBRDT_VBFIL_EN BIT(2)
82
83/* bits within the USBPCR1 register */
84#define USBPCR1_BVLD_REG BIT(31)
85#define USBPCR1_DPPD BIT(29)
86#define USBPCR1_DMPD BIT(28)
87#define USBPCR1_USB_SEL BIT(28)
88#define USBPCR1_WORD_IF_16BIT BIT(19)
89
90enum ingenic_usb_phy_version {
91 ID_JZ4770,
92 ID_JZ4780,
93 ID_X1000,
94 ID_X1830,
95};
96
97struct ingenic_soc_info {
98 enum ingenic_usb_phy_version version;
99
100 void (*usb_phy_init)(struct usb_phy *phy);
101};
102
103struct jz4770_phy {
104 const struct ingenic_soc_info *soc_info;
105
106 struct usb_phy phy;
107 struct usb_otg otg;
108 struct device *dev;
109 void __iomem *base;
110 struct clk *clk;
111 struct regulator *vcc_supply;
112};
113
114static inline struct jz4770_phy *otg_to_jz4770_phy(struct usb_otg *otg)
115{
116 return container_of(otg, struct jz4770_phy, otg);
117}
118
119static inline struct jz4770_phy *phy_to_jz4770_phy(struct usb_phy *phy)
120{
121 return container_of(phy, struct jz4770_phy, phy);
122}
123
124static int ingenic_usb_phy_set_peripheral(struct usb_otg *otg,
125 struct usb_gadget *gadget)
126{
127 struct jz4770_phy *priv = otg_to_jz4770_phy(otg);
128 u32 reg;
129
130 if (priv->soc_info->version >= ID_X1000) {
131 reg = readl(priv->base + REG_USBPCR1_OFFSET);
132 reg |= USBPCR1_BVLD_REG;
133 writel(reg, priv->base + REG_USBPCR1_OFFSET);
134 }
135
136 reg = readl(priv->base + REG_USBPCR_OFFSET);
137 reg &= ~USBPCR_USB_MODE;
138 reg |= USBPCR_VBUSVLDEXT | USBPCR_VBUSVLDEXTSEL | USBPCR_OTG_DISABLE;
139 writel(reg, priv->base + REG_USBPCR_OFFSET);
140
141 return 0;
142}
143
144static int ingenic_usb_phy_set_host(struct usb_otg *otg, struct usb_bus *host)
145{
146 struct jz4770_phy *priv = otg_to_jz4770_phy(otg);
147 u32 reg;
148
149 reg = readl(priv->base + REG_USBPCR_OFFSET);
150 reg &= ~(USBPCR_VBUSVLDEXT | USBPCR_VBUSVLDEXTSEL | USBPCR_OTG_DISABLE);
151 reg |= USBPCR_USB_MODE;
152 writel(reg, priv->base + REG_USBPCR_OFFSET);
153
154 return 0;
155}
156
157static int ingenic_usb_phy_init(struct usb_phy *phy)
158{
159 struct jz4770_phy *priv = phy_to_jz4770_phy(phy);
160 int err;
161 u32 reg;
162
163 err = regulator_enable(priv->vcc_supply);
164 if (err) {
165 dev_err(priv->dev, "Unable to enable VCC: %d\n", err);
166 return err;
167 }
168
169 err = clk_prepare_enable(priv->clk);
170 if (err) {
171 dev_err(priv->dev, "Unable to start clock: %d\n", err);
172 return err;
173 }
174
175 priv->soc_info->usb_phy_init(phy);
176
177 /* Wait for PHY to reset */
178 usleep_range(30, 300);
179 reg = readl(priv->base + REG_USBPCR_OFFSET);
180 writel(reg & ~USBPCR_POR, priv->base + REG_USBPCR_OFFSET);
181 usleep_range(300, 1000);
182
183 return 0;
184}
185
186static void ingenic_usb_phy_shutdown(struct usb_phy *phy)
187{
188 struct jz4770_phy *priv = phy_to_jz4770_phy(phy);
189
190 clk_disable_unprepare(priv->clk);
191 regulator_disable(priv->vcc_supply);
192}
193
194static void ingenic_usb_phy_remove(void *phy)
195{
196 usb_remove_phy(phy);
197}
198
199static void jz4770_usb_phy_init(struct usb_phy *phy)
200{
201 struct jz4770_phy *priv = phy_to_jz4770_phy(phy);
202 u32 reg;
203
204 reg = USBPCR_AVLD_REG | USBPCR_COMMONONN | USBPCR_IDPULLUP_ALWAYS |
205 USBPCR_COMPDISTUNE_DFT | USBPCR_OTGTUNE_DFT | USBPCR_SQRXTUNE_DFT |
206 USBPCR_TXFSLSTUNE_DFT | USBPCR_TXRISETUNE_DFT | USBPCR_TXVREFTUNE_DFT |
207 USBPCR_POR;
208 writel(reg, priv->base + REG_USBPCR_OFFSET);
209}
210
211static void jz4780_usb_phy_init(struct usb_phy *phy)
212{
213 struct jz4770_phy *priv = phy_to_jz4770_phy(phy);
214 u32 reg;
215
216 reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_USB_SEL |
217 USBPCR1_WORD_IF_16BIT;
218 writel(reg, priv->base + REG_USBPCR1_OFFSET);
219
220 reg = USBPCR_TXPREEMPHTUNE | USBPCR_COMMONONN | USBPCR_POR;
221 writel(reg, priv->base + REG_USBPCR_OFFSET);
222}
223
224static void x1000_usb_phy_init(struct usb_phy *phy)
225{
226 struct jz4770_phy *priv = phy_to_jz4770_phy(phy);
227 u32 reg;
228
229 reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_WORD_IF_16BIT;
230 writel(reg, priv->base + REG_USBPCR1_OFFSET);
231
232 reg = USBPCR_SQRXTUNE_DCR_20PCT | USBPCR_TXPREEMPHTUNE |
233 USBPCR_TXHSXVTUNE_DCR_15MV | USBPCR_TXVREFTUNE_INC_25PPT |
234 USBPCR_COMMONONN | USBPCR_POR;
235 writel(reg, priv->base + REG_USBPCR_OFFSET);
236}
237
238static void x1830_usb_phy_init(struct usb_phy *phy)
239{
240 struct jz4770_phy *priv = phy_to_jz4770_phy(phy);
241 u32 reg;
242
243 /* rdt */
244 writel(USBRDT_VBFIL_EN | USBRDT_UTMI_RST, priv->base + REG_USBRDT_OFFSET);
245
246 reg = readl(priv->base + REG_USBPCR1_OFFSET) | USBPCR1_WORD_IF_16BIT |
247 USBPCR1_DMPD | USBPCR1_DPPD;
248 writel(reg, priv->base + REG_USBPCR1_OFFSET);
249
250 reg = USBPCR_IDPULLUP_OTG | USBPCR_VBUSVLDEXT | USBPCR_TXPREEMPHTUNE |
251 USBPCR_COMMONONN | USBPCR_POR;
252 writel(reg, priv->base + REG_USBPCR_OFFSET);
253}
254
255static const struct ingenic_soc_info jz4770_soc_info = {
256 .version = ID_JZ4770,
257
258 .usb_phy_init = jz4770_usb_phy_init,
259};
260
261static const struct ingenic_soc_info jz4780_soc_info = {
262 .version = ID_JZ4780,
263
264 .usb_phy_init = jz4780_usb_phy_init,
265};
266
267static const struct ingenic_soc_info x1000_soc_info = {
268 .version = ID_X1000,
269
270 .usb_phy_init = x1000_usb_phy_init,
271};
272
273static const struct ingenic_soc_info x1830_soc_info = {
274 .version = ID_X1830,
275
276 .usb_phy_init = x1830_usb_phy_init,
277};
278
279static const struct of_device_id ingenic_usb_phy_of_matches[] = {
280 { .compatible = "ingenic,jz4770-phy", .data = &jz4770_soc_info },
281 { .compatible = "ingenic,jz4780-phy", .data = &jz4780_soc_info },
282 { .compatible = "ingenic,x1000-phy", .data = &x1000_soc_info },
283 { .compatible = "ingenic,x1830-phy", .data = &x1830_soc_info },
284 { /* sentinel */ }
285};
286MODULE_DEVICE_TABLE(of, ingenic_usb_phy_of_matches);
287
288static int jz4770_phy_probe(struct platform_device *pdev)
289{
290 struct device *dev = &pdev->dev;
291 struct jz4770_phy *priv;
292 int err;
293
294 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
295 if (!priv)
296 return -ENOMEM;
297
298 priv->soc_info = device_get_match_data(&pdev->dev);
299 if (!priv->soc_info) {
300 dev_err(&pdev->dev, "Error: No device match found\n");
301 return -ENODEV;
302 }
303
304 platform_set_drvdata(pdev, priv);
305 priv->dev = dev;
306 priv->phy.dev = dev;
307 priv->phy.otg = &priv->otg;
308 priv->phy.label = "ingenic-usb-phy";
309 priv->phy.init = ingenic_usb_phy_init;
310 priv->phy.shutdown = ingenic_usb_phy_shutdown;
311
312 priv->otg.state = OTG_STATE_UNDEFINED;
313 priv->otg.usb_phy = &priv->phy;
314 priv->otg.set_host = ingenic_usb_phy_set_host;
315 priv->otg.set_peripheral = ingenic_usb_phy_set_peripheral;
316
317 priv->base = devm_platform_ioremap_resource(pdev, 0);
318 if (IS_ERR(priv->base)) {
319 dev_err(dev, "Failed to map registers\n");
320 return PTR_ERR(priv->base);
321 }
322
323 priv->clk = devm_clk_get(dev, NULL);
324 if (IS_ERR(priv->clk))
325 return dev_err_probe(dev, PTR_ERR(priv->clk),
326 "Failed to get clock\n");
327
328 priv->vcc_supply = devm_regulator_get(dev, "vcc");
329 if (IS_ERR(priv->vcc_supply))
330 return dev_err_probe(dev, PTR_ERR(priv->vcc_supply),
331 "Failed to get regulator\n");
332
333 err = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
334 if (err)
335 return dev_err_probe(dev, err, "Unable to register PHY\n");
336
337 return devm_add_action_or_reset(dev, ingenic_usb_phy_remove, &priv->phy);
338}
339
340static struct platform_driver ingenic_phy_driver = {
341 .probe = jz4770_phy_probe,
342 .driver = {
343 .name = "jz4770-phy",
344 .of_match_table = ingenic_usb_phy_of_matches,
345 },
346};
347module_platform_driver(ingenic_phy_driver);
348
349MODULE_AUTHOR("周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>");
350MODULE_AUTHOR("漆鹏振 (Qi Pengzhen) <aric.pzqi@ingenic.com>");
351MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>");
352MODULE_DESCRIPTION("Ingenic SoCs USB PHY driver");
353MODULE_LICENSE("GPL");
drivers/usb/roles/class.c+4−1
@@ -106,10 +106,13 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode) · 105 unmodified lines
106 struct fwnode_handle *parent = fwnode_get_parent(fwnode);106 struct fwnode_handle *parent = fwnode_get_parent(fwnode);
107 struct device *dev;107 struct device *dev;
108 108
109 if (!parent || !fwnode_property_present(parent, "usb-role-switch"))109 if (!fwnode_property_present(parent, "usb-role-switch")) {
110 fwnode_handle_put(parent);
110 return NULL;111 return NULL;
112 }
111 113
112 dev = class_find_device_by_fwnode(role_class, parent);114 dev = class_find_device_by_fwnode(role_class, parent);
115 fwnode_handle_put(parent);
113 return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);116 return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
114}117}
115 118
drivers/usb/serial/cp210x.c+17−4
@@ -195,6 +195,8 @@ static const struct usb_device_id id_table[] = { · 194 unmodified lines
195 { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */195 { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */
196 { USB_DEVICE(0x17A8, 0x0001) }, /* Kamstrup Optical Eye/3-wire */196 { USB_DEVICE(0x17A8, 0x0001) }, /* Kamstrup Optical Eye/3-wire */
197 { USB_DEVICE(0x17A8, 0x0005) }, /* Kamstrup M-Bus Master MultiPort 250D */197 { USB_DEVICE(0x17A8, 0x0005) }, /* Kamstrup M-Bus Master MultiPort 250D */
198 { USB_DEVICE(0x17A8, 0x0011) }, /* Kamstrup 444 MHz RF sniffer */
199 { USB_DEVICE(0x17A8, 0x0013) }, /* Kamstrup 870 MHz RF sniffer */
198 { USB_DEVICE(0x17A8, 0x0101) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Int Ant) */200 { USB_DEVICE(0x17A8, 0x0101) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Int Ant) */
199 { USB_DEVICE(0x17A8, 0x0102) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Ext Ant) */201 { USB_DEVICE(0x17A8, 0x0102) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Ext Ant) */
200 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */202 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */
@@ -1047,11 +1049,12 @@ static void cp210x_change_speed(struct tty_struct *tty, · 846 unmodified lines
1047 struct cp210x_serial_private *priv = usb_get_serial_data(serial);1049 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
1048 u32 baud;1050 u32 baud;
1049 1051
1052 if (tty->termios.c_ospeed == 0)
1053 return;
1054
1050 /*1055 /*
1051 * This maps the requested rate to the actual rate, a valid rate on1056 * This maps the requested rate to the actual rate, a valid rate on
1052 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].1057 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
1053 *
1054 * NOTE: B0 is not implemented.
1055 */1058 */
1056 baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);1059 baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
1057 1060
@@ -1144,7 +1147,8 @@ static void cp210x_set_flow_control(struct tty_struct *tty, · 86 unmodified lines
1144 tty->termios.c_iflag &= ~(IXON | IXOFF);1147 tty->termios.c_iflag &= ~(IXON | IXOFF);
1145 }1148 }
1146 1149
1147 if (old_termios &&1150 if (tty->termios.c_ospeed != 0 &&
1151 old_termios && old_termios->c_ospeed != 0 &&
1148 C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) &&1152 C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) &&
1149 I_IXON(tty) == (old_termios->c_iflag & IXON) &&1153 I_IXON(tty) == (old_termios->c_iflag & IXON) &&
1150 I_IXOFF(tty) == (old_termios->c_iflag & IXOFF) &&1154 I_IXOFF(tty) == (old_termios->c_iflag & IXOFF) &&
@@ -1169,6 +1173,14 @@ static void cp210x_set_flow_control(struct tty_struct *tty, · 18 unmodified lines
1169 1173
1170 mutex_lock(&port_priv->mutex);1174 mutex_lock(&port_priv->mutex);
1171 1175
1176 if (tty->termios.c_ospeed == 0) {
1177 port_priv->dtr = false;
1178 port_priv->rts = false;
1179 } else if (old_termios && old_termios->c_ospeed == 0) {
1180 port_priv->dtr = true;
1181 port_priv->rts = true;
1182 }
1183
1172 ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,1184 ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
1173 sizeof(flow_ctl));1185 sizeof(flow_ctl));
1174 if (ret)1186 if (ret)
@@ -1241,7 +1253,8 @@ static void cp210x_set_termios(struct tty_struct *tty, · 66 unmodified lines
1241 u16 bits;1253 u16 bits;
1242 int ret;1254 int ret;
1243 1255
1244 if (old_termios && !cp210x_termios_change(&tty->termios, old_termios))1256 if (old_termios && !cp210x_termios_change(&tty->termios, old_termios) &&
1257 tty->termios.c_ospeed != 0)
1245 return;1258 return;
1246 1259
1247 if (!old_termios || tty->termios.c_ospeed != old_termios->c_ospeed)1260 if (!old_termios || tty->termios.c_ospeed != old_termios->c_ospeed)
drivers/usb/serial/f81232.c+7−5
@@ -130,9 +130,6 @@ static u8 const clock_table[] = { F81232_CLK_1_846_MHZ, F81232_CLK_14_77_MHZ, · 129 unmodified lines
130 130
131static int calc_baud_divisor(speed_t baudrate, speed_t clockrate)131static int calc_baud_divisor(speed_t baudrate, speed_t clockrate)
132{132{
133 if (!baudrate)
134 return 0;
135
136 return DIV_ROUND_CLOSEST(clockrate, baudrate);133 return DIV_ROUND_CLOSEST(clockrate, baudrate);
137}134}
138 135
@@ -498,9 +495,14 @@ static void f81232_set_baudrate(struct tty_struct *tty, · 359 unmodified lines
498 speed_t baud_list[] = { baudrate, old_baudrate, F81232_DEF_BAUDRATE };495 speed_t baud_list[] = { baudrate, old_baudrate, F81232_DEF_BAUDRATE };
499 496
500 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {497 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {
501 idx = f81232_find_clk(baud_list[i]);498 baudrate = baud_list[i];
499 if (baudrate == 0) {
500 tty_encode_baud_rate(tty, 0, 0);
501 return;
502 }
503
504 idx = f81232_find_clk(baudrate);
502 if (idx >= 0) {505 if (idx >= 0) {
503 baudrate = baud_list[i];
504 tty_encode_baud_rate(tty, baudrate, baudrate);506 tty_encode_baud_rate(tty, baudrate, baudrate);
505 break;507 break;
506 }508 }
drivers/usb/serial/f81534.c+7−5
@@ -536,9 +536,6 @@ static int f81534_submit_writer(struct usb_serial_port *port, gfp_t mem_flags) · 535 unmodified lines
536 536
537static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)537static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)
538{538{
539 if (!baudrate)
540 return 0;
541
542 /* Round to nearest divisor */539 /* Round to nearest divisor */
543 return DIV_ROUND_CLOSEST(clockrate, baudrate);540 return DIV_ROUND_CLOSEST(clockrate, baudrate);
544}541}
@@ -568,9 +565,14 @@ static int f81534_set_port_config(struct usb_serial_port *port, · 23 unmodified lines
568 u32 baud_list[] = {baudrate, old_baudrate, F81534_DEFAULT_BAUD_RATE};565 u32 baud_list[] = {baudrate, old_baudrate, F81534_DEFAULT_BAUD_RATE};
569 566
570 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {567 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {
571 idx = f81534_find_clk(baud_list[i]);568 baudrate = baud_list[i];
569 if (baudrate == 0) {
570 tty_encode_baud_rate(tty, 0, 0);
571 return 0;
572 }
573
574 idx = f81534_find_clk(baudrate);
572 if (idx >= 0) {575 if (idx >= 0) {
573 baudrate = baud_list[i];
574 tty_encode_baud_rate(tty, baudrate, baudrate);576 tty_encode_baud_rate(tty, baudrate, baudrate);
575 break;577 break;
576 }578 }
drivers/usb/serial/option.c+3−0
@@ -255,6 +255,7 @@ static void option_instat_callback(struct urb *urb); · 254 unmodified lines
255#define QUECTEL_PRODUCT_EP06 0x0306255#define QUECTEL_PRODUCT_EP06 0x0306
256#define QUECTEL_PRODUCT_EM05G 0x030a256#define QUECTEL_PRODUCT_EM05G 0x030a
257#define QUECTEL_PRODUCT_EM060K 0x030b257#define QUECTEL_PRODUCT_EM060K 0x030b
258#define QUECTEL_PRODUCT_EM05G_SG 0x0311
258#define QUECTEL_PRODUCT_EM12 0x0512259#define QUECTEL_PRODUCT_EM12 0x0512
259#define QUECTEL_PRODUCT_RM500Q 0x0800260#define QUECTEL_PRODUCT_RM500Q 0x0800
260#define QUECTEL_PRODUCT_RM520N 0x0801261#define QUECTEL_PRODUCT_RM520N 0x0801
@@ -1160,6 +1161,8 @@ static const struct usb_device_id option_ids[] = { · 899 unmodified lines
1160 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0, 0) },1161 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0, 0) },
1161 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G, 0xff),1162 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G, 0xff),
1162 .driver_info = RSVD(6) | ZLP },1163 .driver_info = RSVD(6) | ZLP },
1164 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G_SG, 0xff),
1165 .driver_info = RSVD(6) | ZLP },
1163 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0x00, 0x40) },1166 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0x00, 0x40) },
1164 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0xff, 0x30) },1167 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0xff, 0x30) },
1165 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0xff, 0x40) },1168 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0xff, 0x40) },
drivers/usb/serial/xr_serial.c+0−2
@@ -749,8 +749,6 @@ static void xr_cdc_set_line_coding(struct tty_struct *tty, · 748 unmodified lines
749 749
750 if (tty->termios.c_ospeed)750 if (tty->termios.c_ospeed)
751 lc->dwDTERate = cpu_to_le32(tty->termios.c_ospeed);751 lc->dwDTERate = cpu_to_le32(tty->termios.c_ospeed);
752 else if (old_termios)
753 lc->dwDTERate = cpu_to_le32(old_termios->c_ospeed);
754 else752 else
755 lc->dwDTERate = cpu_to_le32(9600);753 lc->dwDTERate = cpu_to_le32(9600);
756 754
drivers/usb/storage/alauda.c+2−0
@@ -438,6 +438,8 @@ static int alauda_init_media(struct us_data *us) · 437 unmodified lines
438 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift);438 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift);
439 MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);439 MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
440 MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);440 MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
441 if (MEDIA_INFO(us).pba_to_lba == NULL || MEDIA_INFO(us).lba_to_pba == NULL)
442 return USB_STOR_TRANSPORT_ERROR;
441 443
442 if (alauda_reset_media(us) != USB_STOR_XFER_GOOD)444 if (alauda_reset_media(us) != USB_STOR_XFER_GOOD)
443 return USB_STOR_TRANSPORT_ERROR;445 return USB_STOR_TRANSPORT_ERROR;
drivers/usb/typec/anx7411.c+2−3
@@ -1440,8 +1440,7 @@ static int anx7411_psy_register(struct anx7411_data *ctx) · 1439 unmodified lines
1440 return PTR_ERR_OR_ZERO(ctx->psy);1440 return PTR_ERR_OR_ZERO(ctx->psy);
1441}1441}
1442 1442
1443static int anx7411_i2c_probe(struct i2c_client *client,1443static int anx7411_i2c_probe(struct i2c_client *client)
1444 const struct i2c_device_id *id)
1445{1444{
1446 struct anx7411_data *plat;1445 struct anx7411_data *plat;
1447 struct device *dev = &client->dev;1446 struct device *dev = &client->dev;
@@ -1585,7 +1584,7 @@ static struct i2c_driver anx7411_driver = { · 137 unmodified lines
1585 .of_match_table = anx_match_table,1584 .of_match_table = anx_match_table,
1586 .pm = &anx7411_pm_ops,1585 .pm = &anx7411_pm_ops,
1587 },1586 },
1588 .probe = anx7411_i2c_probe,1587 .probe_new = anx7411_i2c_probe,
1589 .remove = anx7411_i2c_remove,1588 .remove = anx7411_i2c_remove,
1590 1589
1591 .id_table = anx7411_id,1590 .id_table = anx7411_id,
drivers/usb/typec/bus.c+1−1
@@ -134,7 +134,7 @@ int typec_altmode_exit(struct typec_altmode *adev) · 133 unmodified lines
134 if (!adev || !adev->active)134 if (!adev || !adev->active)
135 return 0;135 return 0;
136 136
137 if (!pdev->ops || !pdev->ops->enter)137 if (!pdev->ops || !pdev->ops->exit)
138 return -EOPNOTSUPP;138 return -EOPNOTSUPP;
139 139
140 /* Moving to USB Safe State */140 /* Moving to USB Safe State */
drivers/usb/typec/class.c+19−0
@@ -821,6 +821,25 @@ void typec_partner_set_svdm_version(struct typec_partner *partner, · 820 unmodified lines
821}821}
822EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version);822EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version);
823 823
824/**
825 * typec_partner_usb_power_delivery_register - Register Type-C partner USB Power Delivery Support
826 * @partner: Type-C partner device.
827 * @desc: Description of the USB PD contract.
828 *
829 * This routine is a wrapper around usb_power_delivery_register(). It registers
830 * USB Power Delivery Capabilities for a Type-C partner device. Specifically,
831 * it sets the Type-C partner device as a parent for the resulting USB Power Delivery object.
832 *
833 * Returns handle to struct usb_power_delivery or ERR_PTR.
834 */
835struct usb_power_delivery *
836typec_partner_usb_power_delivery_register(struct typec_partner *partner,
837 struct usb_power_delivery_desc *desc)
838{
839 return usb_power_delivery_register(&partner->dev, desc);
840}
841EXPORT_SYMBOL_GPL(typec_partner_usb_power_delivery_register);
842
824/**843/**
825 * typec_register_partner - Register a USB Type-C Partner844 * typec_register_partner - Register a USB Type-C Partner
826 * @port: The USB Type-C Port the partner is connected to845 * @port: The USB Type-C Port the partner is connected to
drivers/usb/typec/hd3ss3220.c+2−3
@@ -148,8 +148,7 @@ static const struct regmap_config config = { · 147 unmodified lines
148 .max_register = 0x0A,148 .max_register = 0x0A,
149};149};
150 150
151static int hd3ss3220_probe(struct i2c_client *client,151static int hd3ss3220_probe(struct i2c_client *client)
152 const struct i2c_device_id *id)
153{152{
154 struct typec_capability typec_cap = { };153 struct typec_capability typec_cap = { };
155 struct hd3ss3220 *hd3ss3220;154 struct hd3ss3220 *hd3ss3220;
@@ -264,7 +263,7 @@ static struct i2c_driver hd3ss3220_driver = { · 108 unmodified lines
264 .name = "hd3ss3220",263 .name = "hd3ss3220",
265 .of_match_table = of_match_ptr(dev_ids),264 .of_match_table = of_match_ptr(dev_ids),
266 },265 },
267 .probe = hd3ss3220_probe,266 .probe_new = hd3ss3220_probe,
268 .remove = hd3ss3220_remove,267 .remove = hd3ss3220_remove,
269};268};
270 269
drivers/usb/typec/retimer.c+2−14
@@ -17,21 +17,9 @@ · 16 unmodified lines
17#include "class.h"17#include "class.h"
18#include "retimer.h"18#include "retimer.h"
19 19
20static bool dev_name_ends_with(struct device *dev, const char *suffix)
21{
22 const char *name = dev_name(dev);
23 const int name_len = strlen(name);
24 const int suffix_len = strlen(suffix);
25
26 if (suffix_len > name_len)
27 return false;
28
29 return strcmp(name + (name_len - suffix_len), suffix) == 0;
30}
31
32static int retimer_fwnode_match(struct device *dev, const void *fwnode)20static int retimer_fwnode_match(struct device *dev, const void *fwnode)
33{21{
34 return device_match_fwnode(dev, fwnode) && dev_name_ends_with(dev, "-retimer");22 return is_typec_retimer(dev) && device_match_fwnode(dev, fwnode);
35}23}
36 24
37static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data)25static void *typec_retimer_match(struct fwnode_handle *fwnode, const char *id, void *data)
@@ -97,7 +85,7 @@ static void typec_retimer_release(struct device *dev) · 59 unmodified lines
97 kfree(to_typec_retimer(dev));85 kfree(to_typec_retimer(dev));
98}86}
99 87
100static const struct device_type typec_retimer_dev_type = {88const struct device_type typec_retimer_dev_type = {
101 .name = "typec_retimer",89 .name = "typec_retimer",
102 .release = typec_retimer_release,90 .release = typec_retimer_release,
103};91};
drivers/usb/typec/retimer.h+4−0
@@ -12,4 +12,8 @@ struct typec_retimer { · 11 unmodified lines
12 12
13#define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev)13#define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev)
14 14
15const struct device_type typec_retimer_dev_type;
16
17#define is_typec_retimer(dev) ((dev)->type == &typec_retimer_dev_type)
18
15#endif /* __USB_TYPEC_RETIMER__ */19#endif /* __USB_TYPEC_RETIMER__ */
drivers/usb/typec/tcpm/fusb302.c+2−3
@@ -1677,8 +1677,7 @@ static struct fwnode_handle *fusb302_fwnode_get(struct device *dev) · 1676 unmodified lines
1677 return fwnode;1677 return fwnode;
1678}1678}
1679 1679
1680static int fusb302_probe(struct i2c_client *client,1680static int fusb302_probe(struct i2c_client *client)
1681 const struct i2c_device_id *id)
1682{1681{
1683 struct fusb302_chip *chip;1682 struct fusb302_chip *chip;
1684 struct i2c_adapter *adapter = client->adapter;1683 struct i2c_adapter *adapter = client->adapter;
@@ -1837,7 +1836,7 @@ static struct i2c_driver fusb302_driver = { · 152 unmodified lines
1837 .pm = &fusb302_pm_ops,1836 .pm = &fusb302_pm_ops,
1838 .of_match_table = of_match_ptr(fusb302_dt_match),1837 .of_match_table = of_match_ptr(fusb302_dt_match),
1839 },1838 },
1840 .probe = fusb302_probe,1839 .probe_new = fusb302_probe,
1841 .remove = fusb302_remove,1840 .remove = fusb302_remove,
1842 .id_table = fusb302_i2c_device_id,1841 .id_table = fusb302_i2c_device_id,
1843};1842};
drivers/usb/typec/tcpm/tcpci.c+6−4
@@ -794,8 +794,10 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) · 793 unmodified lines
794 return ERR_PTR(err);794 return ERR_PTR(err);
795 795
796 tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);796 tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
797 if (IS_ERR(tcpci->port))797 if (IS_ERR(tcpci->port)) {
798 fwnode_handle_put(tcpci->tcpc.fwnode);
798 return ERR_CAST(tcpci->port);799 return ERR_CAST(tcpci->port);
800 }
799 801
800 return tcpci;802 return tcpci;
801}803}
@@ -804,11 +806,11 @@ EXPORT_SYMBOL_GPL(tcpci_register_port); · 2 unmodified lines
804void tcpci_unregister_port(struct tcpci *tcpci)806void tcpci_unregister_port(struct tcpci *tcpci)
805{807{
806 tcpm_unregister_port(tcpci->port);808 tcpm_unregister_port(tcpci->port);
809 fwnode_handle_put(tcpci->tcpc.fwnode);
807}810}
808EXPORT_SYMBOL_GPL(tcpci_unregister_port);811EXPORT_SYMBOL_GPL(tcpci_unregister_port);
809 812
810static int tcpci_probe(struct i2c_client *client,813static int tcpci_probe(struct i2c_client *client)
811 const struct i2c_device_id *i2c_id)
812{814{
813 struct tcpci_chip *chip;815 struct tcpci_chip *chip;
814 int err;816 int err;
@@ -878,7 +880,7 @@ static struct i2c_driver tcpci_i2c_driver = { · 63 unmodified lines
878 .name = "tcpci",880 .name = "tcpci",
879 .of_match_table = of_match_ptr(tcpci_of_match),881 .of_match_table = of_match_ptr(tcpci_of_match),
880 },882 },
881 .probe = tcpci_probe,883 .probe_new = tcpci_probe,
882 .remove = tcpci_remove,884 .remove = tcpci_remove,
883 .id_table = tcpci_id,885 .id_table = tcpci_id,
884};886};
drivers/usb/typec/tcpm/tcpci_maxim.c+2−2
@@ -438,7 +438,7 @@ static int tcpci_init(struct tcpci *tcpci, struct tcpci_data *data) · 437 unmodified lines
438 return -1;438 return -1;
439}439}
440 440
441static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id)441static int max_tcpci_probe(struct i2c_client *client)
442{442{
443 int ret;443 int ret;
444 struct max_tcpci_chip *chip;444 struct max_tcpci_chip *chip;
@@ -519,7 +519,7 @@ static struct i2c_driver max_tcpci_i2c_driver = { · 74 unmodified lines
519 .name = "maxtcpc",519 .name = "maxtcpc",
520 .of_match_table = of_match_ptr(max_tcpci_of_match),520 .of_match_table = of_match_ptr(max_tcpci_of_match),
521 },521 },
522 .probe = max_tcpci_probe,522 .probe_new = max_tcpci_probe,
523 .remove = max_tcpci_remove,523 .remove = max_tcpci_remove,
524 .id_table = max_tcpci_id,524 .id_table = max_tcpci_id,
525};525};
drivers/usb/typec/tcpm/tcpci_rt1711h.c+2−3
@@ -327,8 +327,7 @@ static int rt1711h_check_revision(struct i2c_client *i2c, struct rt1711h_chip *c · 326 unmodified lines
327 return ret;327 return ret;
328}328}
329 329
330static int rt1711h_probe(struct i2c_client *client,330static int rt1711h_probe(struct i2c_client *client)
331 const struct i2c_device_id *i2c_id)
332{331{
333 int ret;332 int ret;
334 struct rt1711h_chip *chip;333 struct rt1711h_chip *chip;
@@ -413,7 +412,7 @@ static struct i2c_driver rt1711h_i2c_driver = { · 78 unmodified lines
413 .name = "rt1711h",412 .name = "rt1711h",
414 .of_match_table = of_match_ptr(rt1711h_of_match),413 .of_match_table = of_match_ptr(rt1711h_of_match),
415 },414 },
416 .probe = rt1711h_probe,415 .probe_new = rt1711h_probe,
417 .remove = rt1711h_remove,416 .remove = rt1711h_remove,
418 .id_table = rt1711h_id,417 .id_table = rt1711h_id,
419};418};
drivers/usb/typec/tipd/core.c+12−8
@@ -14,6 +14,7 @@ · 13 unmodified lines
14#include <linux/regmap.h>14#include <linux/regmap.h>
15#include <linux/interrupt.h>15#include <linux/interrupt.h>
16#include <linux/usb/typec.h>16#include <linux/usb/typec.h>
17#include <linux/usb/typec_altmode.h>
17#include <linux/usb/role.h>18#include <linux/usb/role.h>
18 19
19#include "tps6598x.h"20#include "tps6598x.h"
@@ -257,6 +258,7 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status) · 237 unmodified lines
257 typec_set_orientation(tps->port, TYPEC_ORIENTATION_REVERSE);258 typec_set_orientation(tps->port, TYPEC_ORIENTATION_REVERSE);
258 else259 else
259 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NORMAL);260 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NORMAL);
261 typec_set_mode(tps->port, TYPEC_STATE_USB);
260 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), true);262 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), true);
261 263
262 tps->partner = typec_register_partner(tps->port, &desc);264 tps->partner = typec_register_partner(tps->port, &desc);
@@ -280,6 +282,7 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 status) · 17 unmodified lines
280 typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status));282 typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status));
281 typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status));283 typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status));
282 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NONE);284 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NONE);
285 typec_set_mode(tps->port, TYPEC_STATE_SAFE);
283 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), false);286 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), false);
284 287
285 power_supply_changed(tps->psy);288 power_supply_changed(tps->psy);
@@ -814,20 +817,19 @@ static int tps6598x_probe(struct i2c_client *client) · 528 unmodified lines
814 817
815 ret = devm_tps6598_psy_register(tps);818 ret = devm_tps6598_psy_register(tps);
816 if (ret)819 if (ret)
817 return ret;820 goto err_role_put;
818 821
819 tps->port = typec_register_port(&client->dev, &typec_cap);822 tps->port = typec_register_port(&client->dev, &typec_cap);
820 if (IS_ERR(tps->port)) {823 if (IS_ERR(tps->port)) {
821 ret = PTR_ERR(tps->port);824 ret = PTR_ERR(tps->port);
822 goto err_role_put;825 goto err_role_put;
823 }826 }
824 fwnode_handle_put(fwnode);
825 827
826 if (status & TPS_STATUS_PLUG_PRESENT) {828 if (status & TPS_STATUS_PLUG_PRESENT) {
827 ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);829 ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
828 if (ret < 0) {830 if (ret < 0) {
829 dev_err(tps->dev, "failed to read power status: %d\n", ret);831 dev_err(tps->dev, "failed to read power status: %d\n", ret);
830 goto err_role_put;832 goto err_unregister_port;
831 }833 }
832 ret = tps6598x_connect(tps, status);834 ret = tps6598x_connect(tps, status);
833 if (ret)835 if (ret)
@@ -838,16 +840,18 @@ static int tps6598x_probe(struct i2c_client *client) · 4 unmodified lines
838 irq_handler,840 irq_handler,
839 IRQF_SHARED | IRQF_ONESHOT,841 IRQF_SHARED | IRQF_ONESHOT,
840 dev_name(&client->dev), tps);842 dev_name(&client->dev), tps);
841 if (ret) {843 if (ret)
842 tps6598x_disconnect(tps, 0);844 goto err_disconnect;
843 typec_unregister_port(tps->port);
844 goto err_role_put;
845 }
846 845
847 i2c_set_clientdata(client, tps);846 i2c_set_clientdata(client, tps);
847 fwnode_handle_put(fwnode);
848 848
849 return 0;849 return 0;
850 850
851err_disconnect:
852 tps6598x_disconnect(tps, 0);
853err_unregister_port:
854 typec_unregister_port(tps->port);
851err_role_put:855err_role_put:
852 usb_role_switch_put(tps->role_sw);856 usb_role_switch_put(tps->role_sw);
853err_fwnode_put:857err_fwnode_put:
drivers/usb/typec/ucsi/ucsi.c+13−4
@@ -1270,8 +1270,9 @@ err: · 1269 unmodified lines
1270 return ret;1270 return ret;
1271}1271}
1272 1272
1273int ucsi_resume(struct ucsi *ucsi)1273static void ucsi_resume_work(struct work_struct *work)
1274{1274{
1275 struct ucsi *ucsi = container_of(work, struct ucsi, resume_work);
1275 struct ucsi_connector *con;1276 struct ucsi_connector *con;
1276 u64 command;1277 u64 command;
1277 int ret;1278 int ret;
@@ -1279,15 +1280,21 @@ int ucsi_resume(struct ucsi *ucsi) · 1 unmodified line
1279 /* Restore UCSI notification enable mask after system resume */1280 /* Restore UCSI notification enable mask after system resume */
1280 command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;1281 command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;
1281 ret = ucsi_send_command(ucsi, command, NULL, 0);1282 ret = ucsi_send_command(ucsi, command, NULL, 0);
1282 if (ret < 0)1283 if (ret < 0) {
1283 return ret;1284 dev_err(ucsi->dev, "failed to re-enable notifications (%d)\n", ret);
1285 return;
1286 }
1284 1287
1285 for (con = ucsi->connector; con->port; con++) {1288 for (con = ucsi->connector; con->port; con++) {
1286 mutex_lock(&con->lock);1289 mutex_lock(&con->lock);
1287 ucsi_check_connection(con);1290 ucsi_partner_task(con, ucsi_check_connection, 1, 0);
1288 mutex_unlock(&con->lock);1291 mutex_unlock(&con->lock);
1289 }1292 }
1293}
1290 1294
1295int ucsi_resume(struct ucsi *ucsi)
1296{
1297 queue_work(system_long_wq, &ucsi->resume_work);
1291 return 0;1298 return 0;
1292}1299}
1293EXPORT_SYMBOL_GPL(ucsi_resume);1300EXPORT_SYMBOL_GPL(ucsi_resume);
@@ -1347,6 +1354,7 @@ struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops) · 53 unmodified lines
1347 if (!ucsi)1354 if (!ucsi)
1348 return ERR_PTR(-ENOMEM);1355 return ERR_PTR(-ENOMEM);
1349 1356
1357 INIT_WORK(&ucsi->resume_work, ucsi_resume_work);
1350 INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work);1358 INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work);
1351 mutex_init(&ucsi->ppm_lock);1359 mutex_init(&ucsi->ppm_lock);
1352 ucsi->dev = dev;1360 ucsi->dev = dev;
@@ -1401,6 +1409,7 @@ void ucsi_unregister(struct ucsi *ucsi) · 48 unmodified lines
1401 1409
1402 /* Make sure that we are not in the middle of driver initialization */1410 /* Make sure that we are not in the middle of driver initialization */
1403 cancel_delayed_work_sync(&ucsi->work);1411 cancel_delayed_work_sync(&ucsi->work);
1412 cancel_work_sync(&ucsi->resume_work);
1404 1413
1405 /* Disable notifications */1414 /* Disable notifications */
1406 ucsi->ops->async_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));1415 ucsi->ops->async_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
drivers/usb/typec/ucsi/ucsi.h+1−0
@@ -287,6 +287,7 @@ struct ucsi { · 286 unmodified lines
287 struct ucsi_capability cap;287 struct ucsi_capability cap;
288 struct ucsi_connector *connector;288 struct ucsi_connector *connector;
289 289
290 struct work_struct resume_work;
290 struct delayed_work work;291 struct delayed_work work;
291 int work_count;292 int work_count;
292#define UCSI_ROLE_SWITCH_RETRY_PER_HZ 10293#define UCSI_ROLE_SWITCH_RETRY_PER_HZ 10
drivers/usb/typec/ucsi/ucsi_ccg.c+2−3
@@ -1338,8 +1338,7 @@ static struct attribute *ucsi_ccg_attrs[] = { · 1337 unmodified lines
1338};1338};
1339ATTRIBUTE_GROUPS(ucsi_ccg);1339ATTRIBUTE_GROUPS(ucsi_ccg);
1340 1340
1341static int ucsi_ccg_probe(struct i2c_client *client,1341static int ucsi_ccg_probe(struct i2c_client *client)
1342 const struct i2c_device_id *id)
1343{1342{
1344 struct device *dev = &client->dev;1343 struct device *dev = &client->dev;
1345 struct ucsi_ccg *uc;1344 struct ucsi_ccg *uc;
@@ -1482,7 +1481,7 @@ static struct i2c_driver ucsi_ccg_driver = { · 136 unmodified lines
1482 .dev_groups = ucsi_ccg_groups,1481 .dev_groups = ucsi_ccg_groups,
1483 .acpi_match_table = amd_i2c_ucsi_match,1482 .acpi_match_table = amd_i2c_ucsi_match,
1484 },1483 },
1485 .probe = ucsi_ccg_probe,1484 .probe_new = ucsi_ccg_probe,
1486 .remove = ucsi_ccg_remove,1485 .remove = ucsi_ccg_remove,
1487 .id_table = ucsi_ccg_device_id,1486 .id_table = ucsi_ccg_device_id,
1488};1487};
drivers/usb/typec/ucsi/ucsi_stm32g0.c+2−2
@@ -626,7 +626,7 @@ static int ucsi_stm32g0_probe_bootloader(struct ucsi *ucsi) · 625 unmodified lines
626 return 0;626 return 0;
627}627}
628 628
629static int ucsi_stm32g0_probe(struct i2c_client *client, const struct i2c_device_id *id)629static int ucsi_stm32g0_probe(struct i2c_client *client)
630{630{
631 struct device *dev = &client->dev;631 struct device *dev = &client->dev;
632 struct ucsi_stm32g0 *g0;632 struct ucsi_stm32g0 *g0;
@@ -763,7 +763,7 @@ static struct i2c_driver ucsi_stm32g0_i2c_driver = { · 130 unmodified lines
763 .of_match_table = of_match_ptr(ucsi_stm32g0_typec_of_match),763 .of_match_table = of_match_ptr(ucsi_stm32g0_typec_of_match),
764 .pm = pm_sleep_ptr(&ucsi_stm32g0_pm_ops),764 .pm = pm_sleep_ptr(&ucsi_stm32g0_pm_ops),
765 },765 },
766 .probe = ucsi_stm32g0_probe,766 .probe_new = ucsi_stm32g0_probe,
767 .remove = ucsi_stm32g0_remove,767 .remove = ucsi_stm32g0_remove,
768 .id_table = ucsi_stm32g0_typec_i2c_devid768 .id_table = ucsi_stm32g0_typec_i2c_devid
769};769};
drivers/usb/typec/wusb3801.c+1−1
@@ -364,7 +364,7 @@ static int wusb3801_probe(struct i2c_client *client) · 363 unmodified lines
364 /* Initialize the hardware with the devicetree settings. */364 /* Initialize the hardware with the devicetree settings. */
365 ret = wusb3801_hw_init(wusb3801);365 ret = wusb3801_hw_init(wusb3801);
366 if (ret)366 if (ret)
367 return ret;367 goto err_put_connector;
368 368
369 wusb3801->cap.revision = USB_TYPEC_REV_1_2;369 wusb3801->cap.revision = USB_TYPEC_REV_1_2;
370 wusb3801->cap.accessory[0] = TYPEC_ACCESSORY_AUDIO;370 wusb3801->cap.accessory[0] = TYPEC_ACCESSORY_AUDIO;
drivers/usb/usb-skeleton.c+0−1
@@ -564,7 +564,6 @@ static void skel_disconnect(struct usb_interface *interface) · 563 unmodified lines
564 int minor = interface->minor;564 int minor = interface->minor;
565 565
566 dev = usb_get_intfdata(interface);566 dev = usb_get_intfdata(interface);
567 usb_set_intfdata(interface, NULL);
568 567
569 /* give back our minor */568 /* give back our minor */
570 usb_deregister_dev(interface, &skel_class);569 usb_deregister_dev(interface, &skel_class);
drivers/usb/usbip/stub_dev.c+3−1
@@ -30,7 +30,7 @@ static ssize_t usbip_status_show(struct device *dev, · 29 unmodified lines
30 status = sdev->ud.status;30 status = sdev->ud.status;
31 spin_unlock_irq(&sdev->ud.lock);31 spin_unlock_irq(&sdev->ud.lock);
32 32
33 return snprintf(buf, PAGE_SIZE, "%d\n", status);33 return sysfs_emit(buf, "%d\n", status);
34}34}
35static DEVICE_ATTR_RO(usbip_status);35static DEVICE_ATTR_RO(usbip_status);
36 36
@@ -118,6 +118,8 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a · 81 unmodified lines
118 } else {118 } else {
119 dev_info(dev, "stub down\n");119 dev_info(dev, "stub down\n");
120 120
121 mutex_lock(&sdev->ud.sysfs_lock);
122
121 spin_lock_irq(&sdev->ud.lock);123 spin_lock_irq(&sdev->ud.lock);
122 if (sdev->ud.status != SDEV_ST_USED)124 if (sdev->ud.status != SDEV_ST_USED)
123 goto err;125 goto err;
drivers/usb/usbip/vudc_rx.c+3−1
@@ -149,7 +149,9 @@ static int v_recv_cmd_submit(struct vudc *udc, · 148 unmodified lines
149 urb_p->urb->status = -EINPROGRESS;149 urb_p->urb->status = -EINPROGRESS;
150 150
151 /* FIXME: more pipe setup to please usbip_common */151 /* FIXME: more pipe setup to please usbip_common */
152 urb_p->urb->pipe &= ~(3 << 30);152 BUILD_BUG_ON_MSG(PIPE_BULK != 3, "PIPE_* doesn't range from 0 to 3");
153
154 urb_p->urb->pipe &= ~(PIPE_BULK << 30);
153 switch (urb_p->ep->type) {155 switch (urb_p->ep->type) {
154 case USB_ENDPOINT_XFER_BULK:156 case USB_ENDPOINT_XFER_BULK:
155 urb_p->urb->pipe |= (PIPE_BULK << 30);157 urb_p->urb->pipe |= (PIPE_BULK << 30);
drivers/usb/usbip/vudc_sysfs.c+1−1
@@ -242,7 +242,7 @@ static ssize_t usbip_status_show(struct device *dev, · 241 unmodified lines
242 status = udc->ud.status;242 status = udc->ud.status;
243 spin_unlock_irq(&udc->ud.lock);243 spin_unlock_irq(&udc->ud.lock);
244 244
245 return snprintf(out, PAGE_SIZE, "%d\n", status);245 return sysfs_emit(out, "%d\n", status);
246}246}
247static DEVICE_ATTR_RO(usbip_status);247static DEVICE_ATTR_RO(usbip_status);
248 248
include/linux/usb.h+12−0
@@ -265,6 +265,18 @@ static inline void *usb_get_intfdata(struct usb_interface *intf) · 264 unmodified lines
265 return dev_get_drvdata(&intf->dev);265 return dev_get_drvdata(&intf->dev);
266}266}
267 267
268/**
269 * usb_set_intfdata() - associate driver-specific data with the interface
270 * @intf: the usb interface
271 * @data: pointer to the device priv structure or %NULL
272 *
273 * Drivers should use this function in their probe() to associate their
274 * driver-specific data with the usb interface.
275 *
276 * When disconnecting, the core will take care of setting @intf back to %NULL,
277 * so no actions are needed on the driver side. The interface should not be set
278 * to %NULL before all actions completed (e.g. no outsanding URB remaining).
279 */
268static inline void usb_set_intfdata(struct usb_interface *intf, void *data)280static inline void usb_set_intfdata(struct usb_interface *intf, void *data)
269{281{
270 dev_set_drvdata(&intf->dev, data);282 dev_set_drvdata(&intf->dev, data);
include/linux/usb/hcd.h+3−0
@@ -269,6 +269,9 @@ struct hc_driver { · 268 unmodified lines
269 /* called after entering D0 (etc), before resuming the hub */269 /* called after entering D0 (etc), before resuming the hub */
270 int (*pci_resume)(struct usb_hcd *hcd, bool hibernated);270 int (*pci_resume)(struct usb_hcd *hcd, bool hibernated);
271 271
272 /* called just before hibernate final D3 state, allows host to poweroff parts */
273 int (*pci_poweroff_late)(struct usb_hcd *hcd, bool do_wakeup);
274
272 /* cleanly make HCD stop writing memory and doing I/O */275 /* cleanly make HCD stop writing memory and doing I/O */
273 void (*stop) (struct usb_hcd *hcd);276 void (*stop) (struct usb_hcd *hcd);
274 277
include/linux/usb/typec.h+4−0
@@ -23,6 +23,7 @@ struct fwnode_handle; · 22 unmodified lines
23struct device;23struct device;
24 24
25struct usb_power_delivery;25struct usb_power_delivery;
26struct usb_power_delivery_desc;
26 27
27enum typec_port_type {28enum typec_port_type {
28 TYPEC_PORT_SRC,29 TYPEC_PORT_SRC,
@@ -327,6 +328,9 @@ void typec_partner_set_svdm_version(struct typec_partner *partner, · 298 unmodified lines
327 enum usb_pd_svdm_ver svdm_version);328 enum usb_pd_svdm_ver svdm_version);
328int typec_get_negotiated_svdm_version(struct typec_port *port);329int typec_get_negotiated_svdm_version(struct typec_port *port);
329 330
331struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner,
332 struct usb_power_delivery_desc *desc);
333
330int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd);334int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd);
331int typec_partner_set_usb_power_delivery(struct typec_partner *partner,335int typec_partner_set_usb_power_delivery(struct typec_partner *partner,
332 struct usb_power_delivery *pd);336 struct usb_power_delivery *pd);
include/uapi/linux/usb/g_uvc.h+3−0
@@ -21,6 +21,9 @@ · 20 unmodified lines
21#define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)21#define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
22#define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)22#define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
23 23
24#define UVC_STRING_CONTROL_IDX 0
25#define UVC_STRING_STREAMING_IDX 1
26
24struct uvc_request_data {27struct uvc_request_data {
25 __s32 length;28 __s32 length;
26 __u8 data[60];29 __u8 data[60];
include/uapi/linux/usb/video.h+2−2
@@ -466,7 +466,7 @@ struct uvc_format_uncompressed { · 465 unmodified lines
466 __u8 bDefaultFrameIndex;466 __u8 bDefaultFrameIndex;
467 __u8 bAspectRatioX;467 __u8 bAspectRatioX;
468 __u8 bAspectRatioY;468 __u8 bAspectRatioY;
469 __u8 bmInterfaceFlags;469 __u8 bmInterlaceFlags;
470 __u8 bCopyProtect;470 __u8 bCopyProtect;
471} __attribute__((__packed__));471} __attribute__((__packed__));
472 472
@@ -522,7 +522,7 @@ struct uvc_format_mjpeg { · 49 unmodified lines
522 __u8 bDefaultFrameIndex;522 __u8 bDefaultFrameIndex;
523 __u8 bAspectRatioX;523 __u8 bAspectRatioX;
524 __u8 bAspectRatioY;524 __u8 bAspectRatioY;
525 __u8 bmInterfaceFlags;525 __u8 bmInterlaceFlags;
526 __u8 bCopyProtect;526 __u8 bCopyProtect;
527} __attribute__((__packed__));527} __attribute__((__packed__));
528 528
tools/usb/ffs-aio-example/simple/device_app/aio_simple.c+31−13
@@ -25,7 +25,9 @@ · 24 unmodified lines
25 * For more information, please refer to <http://unlicense.org/>25 * For more information, please refer to <http://unlicense.org/>
26 */26 */
27 27
28#define _BSD_SOURCE /* for endian.h */28/* $(CROSS_COMPILE)cc -g -o aio_simple aio_simple.c -laio */
29
30#define _DEFAULT_SOURCE /* for endian.h */
29 31
30#include <endian.h>32#include <endian.h>
31#include <errno.h>33#include <errno.h>
@@ -49,6 +51,22 @@ · 17 unmodified lines
49 51
50#define BUF_LEN 819252#define BUF_LEN 8192
51 53
54/*
55 * cpu_to_le16/32 are used when initializing structures, a context where a
56 * function call is not allowed. To solve this, we code cpu_to_le16/32 in a way
57 * that allows them to be used when initializing structures.
58 */
59
60#if BYTE_ORDER == __LITTLE_ENDIAN
61#define cpu_to_le16(x) (x)
62#define cpu_to_le32(x) (x)
63#else
64#define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
65#define cpu_to_le32(x) \
66 ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
67 (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
68#endif
69
52/******************** Descriptors and Strings *******************************/70/******************** Descriptors and Strings *******************************/
53 71
54static const struct {72static const struct {
@@ -62,12 +80,12 @@ static const struct { · 7 unmodified lines
62 } __attribute__ ((__packed__)) fs_descs, hs_descs;80 } __attribute__ ((__packed__)) fs_descs, hs_descs;
63} __attribute__ ((__packed__)) descriptors = {81} __attribute__ ((__packed__)) descriptors = {
64 .header = {82 .header = {
65 .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),83 .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
66 .flags = htole32(FUNCTIONFS_HAS_FS_DESC |84 .flags = cpu_to_le32(FUNCTIONFS_HAS_FS_DESC |
67 FUNCTIONFS_HAS_HS_DESC),85 FUNCTIONFS_HAS_HS_DESC),
68 .length = htole32(sizeof(descriptors)),86 .length = cpu_to_le32(sizeof(descriptors)),
69 },87 },
70 .fs_count = htole32(3),88 .fs_count = cpu_to_le32(3),
71 .fs_descs = {89 .fs_descs = {
72 .intf = {90 .intf = {
73 .bLength = sizeof(descriptors.fs_descs.intf),91 .bLength = sizeof(descriptors.fs_descs.intf),
@@ -89,7 +107,7 @@ static const struct { · 15 unmodified lines
89 .bmAttributes = USB_ENDPOINT_XFER_BULK,107 .bmAttributes = USB_ENDPOINT_XFER_BULK,
90 },108 },
91 },109 },
92 .hs_count = htole32(3),110 .hs_count = cpu_to_le32(3),
93 .hs_descs = {111 .hs_descs = {
94 .intf = {112 .intf = {
95 .bLength = sizeof(descriptors.hs_descs.intf),113 .bLength = sizeof(descriptors.hs_descs.intf),
@@ -103,14 +121,14 @@ static const struct { · 7 unmodified lines
103 .bDescriptorType = USB_DT_ENDPOINT,121 .bDescriptorType = USB_DT_ENDPOINT,
104 .bEndpointAddress = 1 | USB_DIR_IN,122 .bEndpointAddress = 1 | USB_DIR_IN,
105 .bmAttributes = USB_ENDPOINT_XFER_BULK,123 .bmAttributes = USB_ENDPOINT_XFER_BULK,
106 .wMaxPacketSize = htole16(512),124 .wMaxPacketSize = cpu_to_le16(512),
107 },125 },
108 .bulk_source = {126 .bulk_source = {
109 .bLength = sizeof(descriptors.hs_descs.bulk_source),127 .bLength = sizeof(descriptors.hs_descs.bulk_source),
110 .bDescriptorType = USB_DT_ENDPOINT,128 .bDescriptorType = USB_DT_ENDPOINT,
111 .bEndpointAddress = 2 | USB_DIR_OUT,129 .bEndpointAddress = 2 | USB_DIR_OUT,
112 .bmAttributes = USB_ENDPOINT_XFER_BULK,130 .bmAttributes = USB_ENDPOINT_XFER_BULK,
113 .wMaxPacketSize = htole16(512),131 .wMaxPacketSize = cpu_to_le16(512),
114 },132 },
115 },133 },
116};134};
@@ -125,13 +143,13 @@ static const struct { · 8 unmodified lines
125 } __attribute__ ((__packed__)) lang0;143 } __attribute__ ((__packed__)) lang0;
126} __attribute__ ((__packed__)) strings = {144} __attribute__ ((__packed__)) strings = {
127 .header = {145 .header = {
128 .magic = htole32(FUNCTIONFS_STRINGS_MAGIC),146 .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC),
129 .length = htole32(sizeof(strings)),147 .length = cpu_to_le32(sizeof(strings)),
130 .str_count = htole32(1),148 .str_count = cpu_to_le32(1),
131 .lang_count = htole32(1),149 .lang_count = cpu_to_le32(1),
132 },150 },
133 .lang0 = {151 .lang0 = {
134 htole16(0x0409), /* en-us */152 cpu_to_le16(0x0409), /* en-us */
135 STR_INTERFACE,153 STR_INTERFACE,
136 },154 },
137};155};

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