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
197197 read-only
198198 bmaControls this format's data for bmaControls in
199199 the streaming header
200− bmInterfaceFlags specifies interlace information,
200+ bmInterlaceFlags specifies interlace information,
201201 read-only
202202 bAspectRatioY the X dimension of the picture aspect
203203 ratio, read-only
@@ -253,7 +253,7 @@ Description: Specific uncompressed format descriptors · 49 unmodified lines
253253 read-only
254254 bmaControls this format's data for bmaControls in
255255 the streaming header
256− bmInterfaceFlags specifies interlace information,
256+ bmInterlaceFlags specifies interlace information,
257257 read-only
258258 bAspectRatioY the X dimension of the picture aspect
259259 ratio, read-only
Documentation/ABI/testing/sysfs-bus-usb+11−0
@@ -264,6 +264,17 @@ Description: · 263 unmodified lines
264264 attached to the port will not be detected, initialized,
265265 or enumerated.
266266
267+What: /sys/bus/usb/devices/.../<hub_interface>/port<X>/early_stop
268+Date: Sep 2022
269+Contact: Ray Chi <raychi@google.com>
270+Description:
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+
267278 What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout
268279 Date: May 2013
269280 Contact: 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
2828 items:
2929 - const: phy
3030
31+ power-domains:
32+ maxItems: 1
33+
3134 vbus-supply:
3235 description:
3336 A phandle to the regulator for USB VBUS.
Documentation/devicetree/bindings/usb/dwc2.yaml+3−0
@@ -43,7 +43,10 @@ properties: · 42 unmodified lines
4343 - const: rockchip,rk3066-usb
4444 - const: snps,dwc2
4545 - const: lantiq,arx100-usb
46+ - const: lantiq,ase-usb
47+ - const: lantiq,danube-usb
4648 - const: lantiq,xrx200-usb
49+ - const: lantiq,xrx300-usb
4750 - items:
4851 - enum:
4952 - 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+
7+title: Genesys Logic GL850G USB 2.0 hub controller
8+
9+maintainers:
10+ - Icenowy Zheng <uwu@icenowy.me>
11+
12+allOf:
13+ - $ref: usb-device.yaml#
14+
15+properties:
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+
29+required:
30+ - compatible
31+ - reg
32+
33+additionalProperties: false
34+
35+examples:
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
2828 - mediatek,mt7622-xhci
2929 - mediatek,mt7623-xhci
3030 - mediatek,mt7629-xhci
31+ - mediatek,mt7986-xhci
3132 - mediatek,mt8173-xhci
3233 - mediatek,mt8183-xhci
3334 - mediatek,mt8186-xhci
Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml+1−0
@@ -24,6 +24,7 @@ properties: · 23 unmodified lines
2424 - mediatek,mt2712-mtu3
2525 - mediatek,mt8173-mtu3
2626 - mediatek,mt8183-mtu3
27+ - mediatek,mt8186-mtu3
2728 - mediatek,mt8188-mtu3
2829 - mediatek,mt8192-mtu3
2930 - mediatek,mt8195-mtu3
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml+3−0
@@ -39,6 +39,7 @@ properties: · 38 unmodified lines
3939 - qcom,sm8250-dwc3
4040 - qcom,sm8350-dwc3
4141 - qcom,sm8450-dwc3
42+ - qcom,sm8550-dwc3
4243 - const: qcom,dwc3
4344
4445 reg:
@@ -301,6 +302,7 @@ allOf: · 256 unmodified lines
301302 - qcom,sm8150-dwc3
302303 - qcom,sm8250-dwc3
303304 - qcom,sm8450-dwc3
305+ - qcom,sm8550-dwc3
304306 then:
305307 properties:
306308 clocks:
@@ -358,6 +360,7 @@ allOf: · 51 unmodified lines
358360 - qcom,sm8250-dwc3
359361 - qcom,sm8350-dwc3
360362 - qcom,sm8450-dwc3
363+ - qcom,sm8550-dwc3
361364 then:
362365 properties:
363366 interrupts:
Documentation/devicetree/bindings/usb/usb-drd.yaml+1−0
@@ -27,6 +27,7 @@ properties: · 26 unmodified lines
2727 should default to OTG.
2828 $ref: /schemas/types.yaml#/definitions/string
2929 enum: [host, peripheral, otg]
30+ default: otg
3031
3132 hnp-disable:
3233 description:
Documentation/devicetree/bindings/usb/usb-nop-xceiv.yaml+5−0
@@ -39,6 +39,11 @@ properties: · 38 unmodified lines
3939 the VBus line.
4040 $ref: /schemas/types.yaml#/definitions/phandle
4141
42+ wakeup-source:
43+ description:
44+ Specify if the USB phy can detect the remote wakeup signal
45+ while the system sleep.
46+
4247 required:
4348 - compatible
4449 - '#phy-cells'
Documentation/devicetree/bindings/usb/usb251xb.txt+0−89
@@ -1,89 +0,0 @@
1−Microchip USB 2.0 Hi-Speed Hub Controller
2−
3−The device node for the configuration of a Microchip USB251x/xBi USB 2.0
4−Hi-Speed Controller.
5−
6−Required 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−
13−Optional 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−
71−Examples:
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+
7+title: Microchip USB 2.0 Hi-Speed Hub Controller
8+
9+maintainers:
10+ - Richard Leitner <richard.leitner@skidata.com>
11+
12+properties:
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+
239+additionalProperties: false
240+
241+required:
242+ - compatible
243+ - reg
244+
245+examples:
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
494494 description: GE Fanuc Intelligent Platforms Embedded Systems, Inc.
495495 "^gemei,.*":
496496 description: Gemei Digital Technology Co., Ltd.
497+ "^genesys,.*":
498+ description: Genesys Logic, Inc.
497499 "^geniatech,.*":
498500 description: Geniatech, Inc.
499501 "^giantec,.*":
Documentation/driver-api/driver-model/devres.rst+2−0
@@ -395,6 +395,8 @@ PCI · 394 unmodified lines
395395
396396 PHY
397397 devm_usb_get_phy()
398+ devm_usb_get_phy_by_node()
399+ devm_usb_get_phy_by_phandle()
398400 devm_usb_put_phy()
399401
400402 PINCTRL
MAINTAINERS+7−1
@@ -7935,6 +7935,12 @@ F: fs/notify/fanotify/ · 7934 unmodified lines
79357935 F: include/linux/fanotify.h
79367936 F: include/uapi/linux/fanotify.h
79377937
7938+FARADAY FOTG210 USB2 DUAL-ROLE CONTROLLER
7939+M: Linus Walleij <linus.walleij@linaro.org>
7940+L: linux-usb@vger.kernel.org
7941+S: Maintained
7942+F: drivers/usb/fotg210/
7943+
79387944 FARSYNC SYNCHRONOUS DRIVER
79397945 M: Kevin Curtis <kevin.curtis@farsite.co.uk>
79407946 S: Supported
@@ -13795,7 +13801,7 @@ MICROCHIP USB251XB DRIVER · 5854 unmodified lines
1379513801 M: Richard Leitner <richard.leitner@skidata.com>
1379613802 L: linux-usb@vger.kernel.org
1379713803 S: Maintained
13798−F: Documentation/devicetree/bindings/usb/usb251xb.txt
13804+F: Documentation/devicetree/bindings/usb/usb251xb.yaml
1379913805 F: drivers/usb/misc/usb251xb.c
1380013806
1380113807 MICROCHIP USBA UDC DRIVER
arch/powerpc/configs/ppc6xx_defconfig+0−1
@@ -911,7 +911,6 @@ CONFIG_USB_IDMOUSE=m · 910 unmodified lines
911911 CONFIG_USB_FTDI_ELAN=m
912912 CONFIG_USB_APPLEDISPLAY=m
913913 CONFIG_USB_SISUSBVGA=m
914−CONFIG_USB_SISUSBVGA_CON=y
915914 CONFIG_USB_LD=m
916915 CONFIG_USB_TRANCEVIBRATOR=m
917916 CONFIG_USB_IOWARRIOR=m
arch/sh/configs/landisk_defconfig+0−1
@@ -92,7 +92,6 @@ CONFIG_USB_SERIAL_PL2303=m · 91 unmodified lines
9292 CONFIG_USB_EMI62=m
9393 CONFIG_USB_EMI26=m
9494 CONFIG_USB_SISUSBVGA=m
95−CONFIG_USB_SISUSBVGA_CON=y
9695 CONFIG_EXT2_FS=y
9796 CONFIG_EXT3_FS=y
9897 # 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
313313 typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB);
314314 }
315315
316−static irqreturn_t tusb320_irq_handler(int irq, void *dev_id)
316+static irqreturn_t tusb320_state_update_handler(struct tusb320_priv *priv,
317+ bool force_update)
317318 {
318− struct tusb320_priv *priv = dev_id;
319319 unsigned int reg;
320320
321321 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
323323 return IRQ_NONE;
324324 }
325325
326− if (!(reg & TUSB320_REG9_INTERRUPT_STATUS))
326+ if (!force_update && !(reg & TUSB320_REG9_INTERRUPT_STATUS))
327327 return IRQ_NONE;
328328
329329 tusb320_extcon_irq_handler(priv, reg);
@@ -340,6 +340,13 @@ static irqreturn_t tusb320_irq_handler(int irq, void *dev_id) · 10 unmodified lines
340340 return IRQ_HANDLED;
341341 }
342342
343+static 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+
343350 static const struct regmap_config tusb320_regmap_config = {
344351 .reg_bits = 8,
345352 .val_bits = 8,
@@ -466,7 +473,7 @@ static int tusb320_probe(struct i2c_client *client, · 120 unmodified lines
466473 return ret;
467474
468475 /* update initial state */
469− tusb320_irq_handler(client->irq, priv);
476+ tusb320_state_update_handler(priv, true);
470477
471478 /* Reset chip to its default state */
472479 ret = tusb320_reset(priv);
@@ -477,7 +484,7 @@ static int tusb320_probe(struct i2c_client *client, · 4 unmodified lines
477484 * State and polarity might change after a reset, so update
478485 * them again and make sure the interrupt status bit is cleared.
479486 */
480− tusb320_irq_handler(client->irq, priv);
487+ tusb320_state_update_handler(priv, true);
481488
482489 ret = devm_request_threaded_irq(priv->dev, client->irq, NULL,
483490 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
971971 if (!resp->source_cap_count && !resp->sink_cap_count)
972972 return;
973973
974− port->partner_pd = usb_power_delivery_register(NULL, &desc);
974+ port->partner_pd = typec_partner_usb_power_delivery_register(port->partner, &desc);
975975 if (IS_ERR(port->partner_pd)) {
976976 dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n", port_num);
977977 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
1515 void **return_value)
1616 {
1717 struct acpi_device *adev = acpi_fetch_acpi_dev(handle);
18− struct fwnode_reference_args args;
1918 struct fwnode_handle *fwnode;
2019 struct tb_nhi *nhi = data;
2120 struct pci_dev *pdev;
2221 struct device *dev;
23− int ret;
2422
2523 if (!adev)
2624 return AE_OK;
2725
28− fwnode = acpi_fwnode_handle(adev);
29− ret = fwnode_property_get_reference_args(fwnode, "usb4-host-interface",
30− NULL, 0, 0, &args);
31− if (ret)
26+ fwnode = fwnode_find_reference(acpi_fwnode_handle(adev), "usb4-host-interface", 0);
27+ if (IS_ERR(fwnode))
3228 return AE_OK;
3329
3430 /* It needs to reference this NHI */
35− if (dev_fwnode(&nhi->pdev->dev) != args.fwnode)
31+ if (dev_fwnode(&nhi->pdev->dev) != fwnode)
3632 goto out_put;
3733
3834 /*
@@ -100,7 +96,7 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data, · 61 unmodified lines
10096 }
10197
10298 out_put:
103− fwnode_handle_put(args.fwnode);
99+ fwnode_handle_put(fwnode);
104100 return AE_OK;
105101 }
106102
drivers/thunderbolt/switch.c+3−2
@@ -8,12 +8,13 @@ · 7 unmodified lines
88
99 #include <linux/delay.h>
1010 #include <linux/idr.h>
11+#include <linux/module.h>
1112 #include <linux/nvmem-provider.h>
1213 #include <linux/pm_runtime.h>
1314 #include <linux/sched/signal.h>
1415 #include <linux/sizes.h>
1516 #include <linux/slab.h>
16−#include <linux/module.h>
17+#include <linux/string_helpers.h>
1718
1819 #include "tb.h"
1920
@@ -644,7 +645,7 @@ static int __tb_port_enable(struct tb_port *port, bool enable) · 624 unmodified lines
644645 if (ret)
645646 return ret;
646647
647− tb_port_dbg(port, "lane %sabled\n", enable ? "en" : "dis");
648+ tb_port_dbg(port, "lane %s\n", str_enabled_disabled(enable));
648649 return 0;
649650 }
650651
drivers/thunderbolt/tb_regs.h+2−0
@@ -361,6 +361,8 @@ struct tb_regs_port_header { · 360 unmodified lines
361361 #define PORT_CS_18_BE BIT(8)
362362 #define PORT_CS_18_TCM BIT(9)
363363 #define PORT_CS_18_CPS BIT(10)
364+#define PORT_CS_18_WOCS BIT(16)
365+#define PORT_CS_18_WODS BIT(17)
364366 #define PORT_CS_18_WOU4S BIT(18)
365367 #define PORT_CS_19 0x13
366368 #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
155155
156156 static void usb4_switch_check_wakes(struct tb_switch *sw)
157157 {
158+ bool wakeup_usb4 = false;
159+ struct usb4_port *usb4;
158160 struct tb_port *port;
159161 bool wakeup = false;
160162 u32 val;
@@ -173,20 +175,31 @@ static void usb4_switch_check_wakes(struct tb_switch *sw) · 12 unmodified lines
173175 wakeup = val & (ROUTER_CS_6_WOPS | ROUTER_CS_6_WOUS);
174176 }
175177
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+ */
177182 tb_switch_for_each_port(sw, port) {
178− if (!tb_port_has_remote(port))
183+ if (!port->cap_usb4)
179184 continue;
180185
181186 if (tb_port_read(port, &val, TB_CFG_PORT,
182187 port->cap_usb4 + PORT_CS_18, 1))
183188 break;
184189
185− tb_port_dbg(port, "USB4 wake: %s\n",
186− (val & PORT_CS_18_WOU4S) ? "yes" : "no");
190+ tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n",
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);
187201
188− if (val & PORT_CS_18_WOU4S)
189− wakeup = true;
202+ wakeup |= wakeup_usb4;
190203 }
191204
192205 if (wakeup)
@@ -366,6 +379,7 @@ bool usb4_switch_lane_bonding_possible(struct tb_switch *sw) · 173 unmodified lines
366379 */
367380 int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags)
368381 {
382+ struct usb4_port *usb4;
369383 struct tb_port *port;
370384 u64 route = tb_route(sw);
371385 u32 val;
@@ -395,10 +409,13 @@ int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags) · 23 unmodified lines
395409 val |= PORT_CS_19_WOU4;
396410 } else {
397411 bool configured = val & PORT_CS_19_PC;
412+ usb4 = port->usb4;
398413
399− if ((flags & TB_WAKE_ON_CONNECT) && !configured)
414+ if (((flags & TB_WAKE_ON_CONNECT) |
415+ device_may_wakeup(&usb4->dev)) && !configured)
400416 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)
402419 val |= PORT_CS_19_WOD;
403420 if ((flags & TB_WAKE_ON_USB4) && configured)
404421 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
284284 }
285285 }
286286
287+ if (!tb_is_upstream_port(port))
288+ device_set_wakeup_capable(&usb4->dev, true);
289+
287290 pm_runtime_no_callbacks(&usb4->dev);
288291 pm_runtime_set_active(&usb4->dev);
289292 pm_runtime_enable(&usb4->dev);
drivers/thunderbolt/xdomain.c+2−2
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <linux/module.h>
1414 #include <linux/pm_runtime.h>
1515 #include <linux/prandom.h>
16+#include <linux/string_helpers.h>
1617 #include <linux/utsname.h>
1718 #include <linux/uuid.h>
1819 #include <linux/workqueue.h>
@@ -341,7 +342,6 @@ static int tb_xdp_properties_request(struct tb_ctl *ctl, u64 route, · 322 unmodified lines
341342 memcpy(&req.src_uuid, src_uuid, sizeof(*src_uuid));
342343 memcpy(&req.dst_uuid, dst_uuid, sizeof(*dst_uuid));
343344
344− len = 0;
345345 data_len = 0;
346346
347347 do {
@@ -1344,7 +1344,7 @@ static int tb_xdomain_bond_lanes_uuid_high(struct tb_xdomain *xd) · 996 unmodified lines
13441344 tb_port_update_credits(port);
13451345 tb_xdomain_update_link_attributes(xd);
13461346
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));
13481348 return 0;
13491349 }
13501350
drivers/usb/Kconfig+4−0
@@ -111,8 +111,12 @@ source "drivers/usb/usbip/Kconfig" · 110 unmodified lines
111111
112112 endif
113113
114+comment "USB dual-mode controller drivers"
115+
114116 source "drivers/usb/cdns3/Kconfig"
115117
118+source "drivers/usb/fotg210/Kconfig"
119+
116120 source "drivers/usb/mtu3/Kconfig"
117121
118122 source "drivers/usb/musb/Kconfig"
drivers/usb/Makefile+2−0
@@ -17,6 +17,8 @@ obj-$(CONFIG_USB_CDNS_SUPPORT) += cdns3/ · 16 unmodified lines
1717 obj-$(CONFIG_USB_CDNS3) += cdns3/
1818 obj-$(CONFIG_USB_CDNSP_PCI) += cdns3/
1919
20+obj-$(CONFIG_USB_FOTG210) += fotg210/
21+
2022 obj-$(CONFIG_USB_MON) += mon/
2123 obj-$(CONFIG_USB_MTU3) += mtu3/
2224
drivers/usb/cdns3/cdnsp-pci.c+3−5
@@ -192,14 +192,12 @@ static void cdnsp_pci_remove(struct pci_dev *pdev) · 191 unmodified lines
192192 if (pci_dev_run_wake(pdev))
193193 pm_runtime_get_noresume(&pdev->dev);
194194
195− if (!pci_is_enabled(func)) {
195+ if (pci_is_enabled(func)) {
196+ cdns_remove(cdnsp);
197+ } else {
196198 kfree(cdnsp);
197− goto pci_put;
198199 }
199200
200− cdns_remove(cdnsp);
201−
202−pci_put:
203201 pci_dev_put(func);
204202 }
205203
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
20062006
20072007 int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq)
20082008 {
2009− u32 field, length_field, remainder;
2009+ u32 field, length_field, zlp = 0;
20102010 struct cdnsp_ep *pep = preq->pep;
20112011 struct cdnsp_ring *ep_ring;
20122012 int num_trbs;
2013+ u32 maxp;
20132014 int ret;
20142015
20152016 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
20192020 /* 1 TRB for data, 1 for status */
20202021 num_trbs = (pdev->three_stage_setup) ? 2 : 1;
20212022
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+
20222031 ret = cdnsp_prepare_transfer(pdev, preq, num_trbs);
20232032 if (ret)
20242033 return ret;
20252034
20262035 /* 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−
20322036 if (preq->request.length > 0) {
2033− remainder = cdnsp_td_remainder(pdev, 0, preq->request.length,
2034− preq->request.length, preq, 1, 0);
2037+ field = TRB_TYPE(TRB_DATA);
20352038
2036− length_field = TRB_LEN(preq->request.length) |
2037− TRB_TD_SIZE(remainder) | TRB_INTR_TARGET(0);
2039+ if (zlp)
2040+ field |= TRB_CHAIN;
2041+ else
2042+ field |= TRB_IOC | (pdev->ep0_expect_in ? 0 : TRB_ISP);
20382043
20392044 if (pdev->ep0_expect_in)
20402045 field |= TRB_DIR_IN;
20412046
2047+ length_field = TRB_LEN(preq->request.length) |
2048+ TRB_TD_SIZE(zlp) | TRB_INTR_TARGET(0);
2049+
20422050 cdnsp_queue_trb(pdev, ep_ring, true,
20432051 lower_32_bits(preq->request.dma),
20442052 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
20462054 TRB_SETUPID(pdev->setup_id) |
20472055 pdev->setup_speed);
20482056
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+
20492071 pdev->ep0_stage = CDNSP_DATA_STAGE;
20502072 }
20512073
drivers/usb/chipidea/ci.h+4−0
@@ -127,12 +127,16 @@ enum ci_revision { · 126 unmodified lines
127127 * struct ci_role_driver - host/gadget role driver
128128 * @start: start this role
129129 * @stop: stop this role
130+ * @suspend: system suspend handler for this role
131+ * @resume: system resume handler for this role
130132 * @irq: irq handler for this role
131133 * @name: role name string (host/gadget)
132134 */
133135 struct ci_role_driver {
134136 int (*start)(struct ci_hdrc *);
135137 void (*stop)(struct ci_hdrc *);
138+ void (*suspend)(struct ci_hdrc *ci);
139+ void (*resume)(struct ci_hdrc *ci, bool power_lost);
136140 irqreturn_t (*irq)(struct ci_hdrc *);
137141 const char *name;
138142 };
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
355355 data->hsic_pad_regulator =
356356 devm_regulator_get_optional(dev, "hsic");
357357 if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) {
358− /* no pad regualator is needed */
358+ /* no pad regulator is needed */
359359 data->hsic_pad_regulator = NULL;
360360 } else if (IS_ERR(data->hsic_pad_regulator))
361361 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
527527 ci_hdrc_imx_remove(pdev);
528528 }
529529
530−static int __maybe_unused imx_controller_suspend(struct device *dev)
530+static int __maybe_unused imx_controller_suspend(struct device *dev,
531+ pm_message_t msg)
531532 {
532533 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
533534 int ret = 0;
534535
535536 dev_dbg(dev, "at %s\n", __func__);
536537
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));
538540 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);
540543 return ret;
541544 }
542545
@@ -549,7 +552,8 @@ static int __maybe_unused imx_controller_suspend(struct device *dev) · 6 unmodified lines
549552 return 0;
550553 }
551554
552−static int __maybe_unused imx_controller_resume(struct device *dev)
555+static int __maybe_unused imx_controller_resume(struct device *dev,
556+ pm_message_t msg)
553557 {
554558 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
555559 int ret = 0;
@@ -570,22 +574,15 @@ static int __maybe_unused imx_controller_resume(struct device *dev) · 14 unmodified lines
570574
571575 data->in_lpm = false;
572576
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));
574579 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);
576581 goto clk_disable;
577582 }
578583
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−
585584 return 0;
586585
587−hsic_set_clk_fail:
588− imx_usbmisc_set_wakeup(data->usbmisc_data, true);
589586 clk_disable:
590587 imx_disable_unprepare_clks(dev);
591588 return ret;
@@ -601,16 +598,7 @@ static int __maybe_unused ci_hdrc_imx_suspend(struct device *dev) · 9 unmodified lines
601598 /* The core's suspend doesn't run */
602599 return 0;
603600
604− if (device_may_wakeup(dev)) {
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);
601+ ret = imx_controller_suspend(dev, PMSG_SUSPEND);
614602 if (ret)
615603 return ret;
616604
@@ -624,7 +612,7 @@ static int __maybe_unused ci_hdrc_imx_resume(struct device *dev) · 7 unmodified lines
624612 int ret;
625613
626614 pinctrl_pm_select_default_state(dev);
627− ret = imx_controller_resume(dev);
615+ ret = imx_controller_resume(dev, PMSG_RESUME);
628616 if (!ret && data->supports_runtime_pm) {
629617 pm_runtime_disable(dev);
630618 pm_runtime_set_active(dev);
@@ -637,25 +625,18 @@ static int __maybe_unused ci_hdrc_imx_resume(struct device *dev) · 6 unmodified lines
637625 static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev)
638626 {
639627 struct ci_hdrc_imx_data *data = dev_get_drvdata(dev);
640− int ret;
641628
642629 if (data->in_lpm) {
643630 WARN_ON(1);
644631 return 0;
645632 }
646633
647− ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true);
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);
634+ return imx_controller_suspend(dev, PMSG_AUTO_SUSPEND);
654635 }
655636
656637 static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev)
657638 {
658− return imx_controller_resume(dev);
639+ return imx_controller_resume(dev, PMSG_AUTO_RESUME);
659640 }
660641
661642 static 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
3232
3333 int imx_usbmisc_init(struct imx_usbmisc_data *data);
3434 int imx_usbmisc_init_post(struct imx_usbmisc_data *data);
35−int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled);
3635 int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data);
37−int imx_usbmisc_hsic_set_clk(struct imx_usbmisc_data *data, bool on);
3836 int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect);
37+int imx_usbmisc_suspend(struct imx_usbmisc_data *data, bool wakeup);
38+int imx_usbmisc_resume(struct imx_usbmisc_data *data, bool wakeup);
3939
4040 #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
608608 enum usb_role role)
609609 {
610610 struct ci_hdrc *ci = usb_role_switch_get_drvdata(sw);
611− struct ci_hdrc_cable *cable = NULL;
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;
611+ struct ci_hdrc_cable *cable;
619612
620− pm_runtime_get_sync(ci->dev);
621− /* Stop current role */
622− spin_lock_irqsave(&ci->lock, flags);
623− if (current_role == USB_ROLE_DEVICE)
613+ if (role == USB_ROLE_HOST) {
614+ cable = &ci->platdata->id_extcon;
615+ cable->changed = true;
616+ cable->connected = true;
624617 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) {
626621 cable = &ci->platdata->id_extcon;
627−
628− if (cable) {
629622 cable->changed = true;
630623 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)
642624 cable = &ci->platdata->vbus_extcon;
643− else if (role == USB_ROLE_HOST)
644− cable = &ci->platdata->id_extcon;
645−
646− if (cable) {
647625 cable->changed = true;
648626 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;
650634 }
651− spin_unlock_irqrestore(&ci->lock, flags);
652− pm_runtime_put_sync(ci->dev);
653635
636+ ci_irq(ci);
654637 return 0;
655638 }
656639
640+static 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+
657664 static struct usb_role_switch_desc ci_role_switch = {
658665 .set = ci_usb_role_switch_set,
659666 .get = ci_usb_role_switch_get,
@@ -1151,25 +1158,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) · 491 unmodified lines
11511158 }
11521159 }
11531160
1154− if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) {
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−
1161+ ci->role = ci_get_role(ci);
11731162 if (!ci_otg_is_fsm_mode(ci)) {
11741163 /* only update vbus status for peripheral */
11751164 if (ci->role == CI_ROLE_GADGET) {
@@ -1305,11 +1294,13 @@ static void ci_extcon_wakeup_int(struct ci_hdrc *ci) · 129 unmodified lines
13051294 cable_id = &ci->platdata->id_extcon;
13061295 cable_vbus = &ci->platdata->vbus_extcon;
13071296
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 &&
13091299 (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS))
13101300 ci_irq(ci);
13111301
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 &&
13131304 (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS))
13141305 ci_irq(ci);
13151306 }
@@ -1373,6 +1364,10 @@ static int ci_suspend(struct device *dev) · 57 unmodified lines
13731364 return 0;
13741365 }
13751366
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+
13761371 if (device_may_wakeup(dev)) {
13771372 if (ci_otg_is_fsm_mode(ci))
13781373 ci_otg_fsm_suspend_for_srp(ci);
@@ -1386,11 +1381,38 @@ static int ci_suspend(struct device *dev) · 7 unmodified lines
13861381 return 0;
13871382 }
13881383
1384+static 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+
13891403 static int ci_resume(struct device *dev)
13901404 {
13911405 struct ci_hdrc *ci = dev_get_drvdata(dev);
1406+ bool power_lost;
13921407 int ret;
13931408
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+
13941416 if (device_may_wakeup(dev))
13951417 disable_irq_wake(ci->irq);
13961418
@@ -1398,6 +1420,19 @@ static int ci_resume(struct device *dev) · 1 unmodified line
13981420 if (ret)
13991421 return ret;
14001422
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+
14011436 if (ci->supports_runtime_pm) {
14021437 pm_runtime_disable(dev);
14031438 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
459459 ci_hdrc_free_dma_aligned_buffer(urb);
460460 }
461461
462+#ifdef CONFIG_PM_SLEEP
463+static void ci_hdrc_host_suspend(struct ci_hdrc *ci)
464+{
465+ ehci_suspend(ci->hcd, device_may_wakeup(ci->dev));
466+}
467+
468+static void ci_hdrc_host_resume(struct ci_hdrc *ci, bool power_lost)
469+{
470+ ehci_resume(ci->hcd, power_lost);
471+}
472+#endif
473+
462474 int ci_hdrc_host_init(struct ci_hdrc *ci)
463475 {
464476 struct ci_role_driver *rdrv;
@@ -472,6 +484,10 @@ int ci_hdrc_host_init(struct ci_hdrc *ci) · 7 unmodified lines
472484
473485 rdrv->start = host_start;
474486 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
475491 rdrv->irq = host_irq;
476492 rdrv->name = "host";
477493 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
165165 return 0;
166166 }
167167
168−static void ci_handle_id_switch(struct ci_hdrc *ci)
168+void ci_handle_id_switch(struct ci_hdrc *ci)
169169 {
170170 enum ci_role role = ci_otg_role(ci);
171171
drivers/usb/chipidea/otg.h+1−0
@@ -14,6 +14,7 @@ int ci_hdrc_otg_init(struct ci_hdrc *ci); · 13 unmodified lines
1414 void ci_hdrc_otg_destroy(struct ci_hdrc *ci);
1515 enum ci_role ci_otg_role(struct ci_hdrc *ci);
1616 void ci_handle_vbus_change(struct ci_hdrc *ci);
17+void ci_handle_id_switch(struct ci_hdrc *ci);
1718 static inline void ci_otg_queue_work(struct ci_hdrc *ci)
1819 {
1920 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
21812181 ci->platdata->pins_default);
21822182 }
21832183
2184+#ifdef CONFIG_PM_SLEEP
2185+static 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+
2196+static 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+
21842212 /**
21852213 * ci_hdrc_gadget_init - initialize device related bits
21862214 * @ci: the controller
@@ -2201,6 +2229,10 @@ int ci_hdrc_gadget_init(struct ci_hdrc *ci) · 14 unmodified lines
22012229
22022230 rdrv->start = udc_id_switch_for_device;
22032231 rdrv->stop = udc_id_switch_for_host;
2232+#ifdef CONFIG_PM_SLEEP
2233+ rdrv->suspend = udc_suspend;
2234+ rdrv->resume = udc_resume;
2235+#endif
22042236 rdrv->irq = udc_irq;
22052237 rdrv->name = "gadget";
22062238
drivers/usb/chipidea/usbmisc_imx.c+130−30
@@ -150,6 +150,8 @@ struct usbmisc_ops { · 149 unmodified lines
150150 int (*hsic_set_clk)(struct imx_usbmisc_data *data, bool enabled);
151151 /* usb charger detection */
152152 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);
153155 };
154156
155157 struct imx_usbmisc {
@@ -937,6 +939,44 @@ static int usbmisc_imx7ulp_init(struct imx_usbmisc_data *data) · 781 unmodified lines
937939 return 0;
938940 }
939941
942+static 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+
961+static 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+
940980 static const struct usbmisc_ops imx25_usbmisc_ops = {
941981 .init = usbmisc_imx25_init,
942982 .post = usbmisc_imx25_post,
@@ -970,12 +1010,14 @@ static const struct usbmisc_ops imx6sx_usbmisc_ops = { · 27 unmodified lines
9701010 .init = usbmisc_imx6sx_init,
9711011 .hsic_set_connect = usbmisc_imx6_hsic_set_connect,
9721012 .hsic_set_clk = usbmisc_imx6_hsic_set_clk,
1013+ .power_lost_check = usbmisc_imx6sx_power_lost_check,
9731014 };
9741015
9751016 static const struct usbmisc_ops imx7d_usbmisc_ops = {
9761017 .init = usbmisc_imx7d_init,
9771018 .set_wakeup = usbmisc_imx7d_set_wakeup,
9781019 .charger_detection = imx7d_charger_detection,
1020+ .power_lost_check = usbmisc_imx7d_power_lost_check,
9791021 };
9801022
9811023 static const struct usbmisc_ops imx7ulp_usbmisc_ops = {
@@ -983,6 +1025,7 @@ static const struct usbmisc_ops imx7ulp_usbmisc_ops = { · 1 unmodified line
9831025 .set_wakeup = usbmisc_imx7d_set_wakeup,
9841026 .hsic_set_connect = usbmisc_imx6_hsic_set_connect,
9851027 .hsic_set_clk = usbmisc_imx6_hsic_set_clk,
1028+ .power_lost_check = usbmisc_imx7d_power_lost_check,
9861029 };
9871030
9881031 static inline bool is_imx53_usbmisc(struct imx_usbmisc_data *data)
@@ -1009,30 +1052,29 @@ EXPORT_SYMBOL_GPL(imx_usbmisc_init); · 20 unmodified lines
10091052 int imx_usbmisc_init_post(struct imx_usbmisc_data *data)
10101053 {
10111054 struct imx_usbmisc *usbmisc;
1055+ int ret = 0;
10121056
10131057 if (!data)
10141058 return 0;
10151059
10161060 usbmisc = dev_get_drvdata(data->dev);
1017− if (!usbmisc->ops->post)
1018− return 0;
1019− return usbmisc->ops->post(data);
1020−}
1021−EXPORT_SYMBOL_GPL(imx_usbmisc_init_post);
1022−
1023−int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled)
1024−{
1025− struct imx_usbmisc *usbmisc;
1061+ if (usbmisc->ops->post)
1062+ ret = usbmisc->ops->post(data);
1063+ if (ret) {
1064+ dev_err(data->dev, "post init failed, ret=%d\n", ret);
1065+ return ret;
1066+ }
10261067
1027− if (!data)
1028− return 0;
1068+ if (usbmisc->ops->set_wakeup)
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+ }
10291074
1030− usbmisc = dev_get_drvdata(data->dev);
1031− if (!usbmisc->ops->set_wakeup)
1032− return 0;
1033− return usbmisc->ops->set_wakeup(data, enabled);
1075+ return 0;
10341076 }
1035−EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup);
1077+EXPORT_SYMBOL_GPL(imx_usbmisc_init_post);
10361078
10371079 int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data)
10381080 {
@@ -1048,20 +1090,6 @@ int imx_usbmisc_hsic_set_connect(struct imx_usbmisc_data *data) · 9 unmodified lines
10481090 }
10491091 EXPORT_SYMBOL_GPL(imx_usbmisc_hsic_set_connect);
10501092
1051−int 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−}
1063−EXPORT_SYMBOL_GPL(imx_usbmisc_hsic_set_clk);
1064−
10651093 int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect)
10661094 {
10671095 struct imx_usbmisc *usbmisc;
@@ -1094,6 +1122,78 @@ int imx_usbmisc_charger_detection(struct imx_usbmisc_data *data, bool connect) · 26 unmodified lines
10941122 }
10951123 EXPORT_SYMBOL_GPL(imx_usbmisc_charger_detection);
10961124
1125+int 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+}
1151+EXPORT_SYMBOL_GPL(imx_usbmisc_suspend);
1152+
1153+int 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+
1190+hsic_set_clk_fail:
1191+ if (wakeup && usbmisc->ops->set_wakeup)
1192+ usbmisc->ops->set_wakeup(data, true);
1193+ return ret;
1194+}
1195+EXPORT_SYMBOL_GPL(imx_usbmisc_resume);
1196+
10971197 static const struct of_device_id usbmisc_imx_dt_ids[] = {
10981198 {
10991199 .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
207207 /* Test the interface */
208208 ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa);
209209 if (ret < 0)
210− goto err;
210+ return ret;
211211
212212 ret = ulpi_read(ulpi, ULPI_SCRATCH);
213213 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
6161 desc = (struct usb_ssp_isoc_ep_comp_descriptor *) buffer;
6262 if (desc->bDescriptorType != USB_DT_SSP_ISOC_ENDPOINT_COMP ||
6363 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"
6565 "for config %d interface %d altsetting %d ep %d.\n",
6666 cfgno, inum, asnum, ep->desc.bEndpointAddress);
6767 return;
@@ -83,7 +83,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 15 unmodified lines
8383
8484 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP ||
8585 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 "
8787 " interface %d altsetting %d ep %d: "
8888 "using minimum values\n",
8989 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
109109
110110 /* Check the various values */
111111 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 "
113113 "config %d interface %d altsetting %d ep %d: "
114114 "setting to zero\n", desc->bMaxBurst,
115115 cfgno, inum, asnum, ep->desc.bEndpointAddress);
116116 ep->ss_ep_comp.bMaxBurst = 0;
117117 } else if (desc->bMaxBurst > 15) {
118− dev_warn(ddev, "Endpoint with bMaxBurst = %d in "
118+ dev_notice(ddev, "Endpoint with bMaxBurst = %d in "
119119 "config %d interface %d altsetting %d ep %d: "
120120 "setting to 15\n", desc->bMaxBurst,
121121 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
125125 if ((usb_endpoint_xfer_control(&ep->desc) ||
126126 usb_endpoint_xfer_int(&ep->desc)) &&
127127 desc->bmAttributes != 0) {
128− dev_warn(ddev, "%s endpoint with bmAttributes = %d in "
128+ dev_notice(ddev, "%s endpoint with bmAttributes = %d in "
129129 "config %d interface %d altsetting %d ep %d: "
130130 "setting to zero\n",
131131 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
134134 ep->ss_ep_comp.bmAttributes = 0;
135135 } else if (usb_endpoint_xfer_bulk(&ep->desc) &&
136136 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 "
138138 "config %d interface %d altsetting %d ep %d: "
139139 "setting to max\n",
140140 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
142142 } else if (usb_endpoint_xfer_isoc(&ep->desc) &&
143143 !USB_SS_SSP_ISOC_COMP(desc->bmAttributes) &&
144144 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 "
146146 "config %d interface %d altsetting %d ep %d: "
147147 "setting to 3\n",
148148 USB_SS_MULT(desc->bmAttributes),
@@ -160,7 +160,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, · 11 unmodified lines
160160 else
161161 max_tx = 999999;
162162 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 "
164164 "config %d interface %d altsetting %d ep %d: "
165165 "setting to %d\n",
166166 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
273273 else if (d->bLength >= USB_DT_ENDPOINT_SIZE)
274274 n = USB_DT_ENDPOINT_SIZE;
275275 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 "
277277 "invalid endpoint descriptor of length %d, skipping\n",
278278 cfgno, inum, asnum, d->bLength);
279279 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
281281
282282 i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK;
283283 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 "
285285 "invalid endpoint with address 0x%X, skipping\n",
286286 cfgno, inum, asnum, d->bEndpointAddress);
287287 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
293293
294294 /* Check for duplicate endpoint addresses */
295295 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",
297297 cfgno, inum, asnum, d->bEndpointAddress);
298298 goto skip_to_next_endpoint_or_interface_descriptor;
299299 }
@@ -301,7 +301,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 1 unmodified line
301301 /* Ignore some endpoints */
302302 if (udev->quirks & USB_QUIRK_ENDPOINT_IGNORE) {
303303 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",
305305 cfgno, inum, asnum,
306306 d->bEndpointAddress);
307307 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
378378 }
379379 }
380380 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 "
382382 "endpoint 0x%X has an invalid bInterval %d, "
383383 "changing to %d\n",
384384 cfgno, inum, asnum,
@@ -391,7 +391,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 6 unmodified lines
391391 * them usable, we will try treating them as Interrupt endpoints.
392392 */
393393 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 "
395395 "endpoint 0x%X is Bulk; changing to Interrupt\n",
396396 cfgno, inum, asnum, d->bEndpointAddress);
397397 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT;
@@ -408,7 +408,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 10 unmodified lines
408408 */
409409 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize);
410410 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",
412412 cfgno, inum, asnum, d->bEndpointAddress);
413413 }
414414
@@ -439,7 +439,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, · 24 unmodified lines
439439 j = maxpacket_maxes[usb_endpoint_type(&endpoint->desc)];
440440
441441 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",
443443 cfgno, inum, asnum, d->bEndpointAddress, maxp, j);
444444 maxp = j;
445445 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
452452 */
453453 if (udev->speed == USB_SPEED_HIGH && usb_endpoint_xfer_bulk(d)) {
454454 if (maxp != 512)
455− dev_warn(ddev, "config %d interface %d altsetting %d "
455+ dev_notice(ddev, "config %d interface %d altsetting %d "
456456 "bulk endpoint 0x%X has invalid maxpacket %d\n",
457457 cfgno, inum, asnum, d->bEndpointAddress,
458458 maxp);
@@ -533,7 +533,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno, · 74 unmodified lines
533533 i < intfc->num_altsetting;
534534 (++i, ++alt)) {
535535 if (alt->desc.bAlternateSetting == asnum) {
536− dev_warn(ddev, "Duplicate descriptor for config %d "
536+ dev_notice(ddev, "Duplicate descriptor for config %d "
537537 "interface %d altsetting %d, skipping\n",
538538 cfgno, inum, asnum);
539539 goto skip_to_next_interface_descriptor;
@@ -559,7 +559,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno, · 19 unmodified lines
559559 num_ep = num_ep_orig = alt->desc.bNumEndpoints;
560560 alt->desc.bNumEndpoints = 0; /* Use as a counter */
561561 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 "
563563 "altsetting %d: %d, using maximum allowed: %d\n",
564564 cfgno, inum, asnum, num_ep, USB_MAXENDPOINTS);
565565 num_ep = USB_MAXENDPOINTS;
@@ -590,7 +590,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno, · 24 unmodified lines
590590 }
591591
592592 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 "
594594 "endpoint descriptor%s, different from the interface "
595595 "descriptor's value: %d\n",
596596 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
625625 if (config->desc.bDescriptorType != USB_DT_CONFIG ||
626626 config->desc.bLength < USB_DT_CONFIG_SIZE ||
627627 config->desc.bLength > size) {
628− dev_err(ddev, "invalid descriptor for config index %d: "
628+ dev_notice(ddev, "invalid descriptor for config index %d: "
629629 "type = 0x%X, length = %d\n", cfgidx,
630630 config->desc.bDescriptorType, config->desc.bLength);
631631 return -EINVAL;
@@ -636,7 +636,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 4 unmodified lines
636636 size -= config->desc.bLength;
637637
638638 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, "
640640 "using maximum allowed: %d\n",
641641 cfgno, nintf, USB_MAXINTERFACES);
642642 nintf = USB_MAXINTERFACES;
@@ -650,7 +650,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 7 unmodified lines
650650 (buffer2 += header->bLength, size2 -= header->bLength)) {
651651
652652 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 "
654654 "byte%s, ignoring\n",
655655 cfgno, size2, plural(size2));
656656 break;
@@ -658,7 +658,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 1 unmodified line
658658
659659 header = (struct usb_descriptor_header *) buffer2;
660660 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 "
662662 "of length %d, skipping remainder of the config\n",
663663 cfgno, header->bLength);
664664 break;
@@ -670,7 +670,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 5 unmodified lines
670670
671671 d = (struct usb_interface_descriptor *) header;
672672 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 "
674674 "interface descriptor of length %d, "
675675 "skipping\n", cfgno, d->bLength);
676676 continue;
@@ -680,7 +680,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 3 unmodified lines
680680
681681 if ((dev->quirks & USB_QUIRK_HONOR_BNUMINTERFACES) &&
682682 n >= nintf_orig) {
683− dev_warn(ddev, "config %d has more interface "
683+ dev_notice(ddev, "config %d has more interface "
684684 "descriptors, than it declares in "
685685 "bNumInterfaces, ignoring interface "
686686 "number: %d\n", cfgno, inum);
@@ -688,7 +688,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 1 unmodified line
688688 }
689689
690690 if (inum >= nintf_orig)
691− dev_warn(ddev, "config %d has an invalid "
691+ dev_notice(ddev, "config %d has an invalid "
692692 "interface number: %d but max is %d\n",
693693 cfgno, inum, nintf_orig - 1);
694694
@@ -713,14 +713,14 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 18 unmodified lines
713713
714714 d = (struct usb_interface_assoc_descriptor *)header;
715715 if (d->bLength < USB_DT_INTERFACE_ASSOCIATION_SIZE) {
716− dev_warn(ddev,
716+ dev_notice(ddev,
717717 "config %d has an invalid interface association descriptor of length %d, skipping\n",
718718 cfgno, d->bLength);
719719 continue;
720720 }
721721
722722 if (iad_num == USB_MAXIADS) {
723− dev_warn(ddev, "found more Interface "
723+ dev_notice(ddev, "found more Interface "
724724 "Association Descriptors "
725725 "than allocated for in "
726726 "configuration %d\n", cfgno);
@@ -731,7 +731,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 4 unmodified lines
731731
732732 } else if (header->bDescriptorType == USB_DT_DEVICE ||
733733 header->bDescriptorType == USB_DT_CONFIG)
734− dev_warn(ddev, "config %d contains an unexpected "
734+ dev_notice(ddev, "config %d contains an unexpected "
735735 "descriptor of type 0x%X, skipping\n",
736736 cfgno, header->bDescriptorType);
737737
@@ -740,11 +740,11 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 2 unmodified lines
740740 config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0);
741741
742742 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 "
744744 "the descriptor's value: %d\n",
745745 cfgno, n, plural(n), nintf_orig);
746746 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);
748748 config->desc.bNumInterfaces = nintf = n;
749749
750750 /* Check for missing interface numbers */
@@ -754,7 +754,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 3 unmodified lines
754754 break;
755755 }
756756 if (j >= nintf)
757− dev_warn(ddev, "config %d has no interface number "
757+ dev_notice(ddev, "config %d has no interface number "
758758 "%d\n", cfgno, i);
759759 }
760760
@@ -762,7 +762,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 1 unmodified line
762762 for (i = 0; i < nintf; ++i) {
763763 j = nalts[i];
764764 if (j > USB_MAXALTSETTING) {
765− dev_warn(ddev, "too many alternate settings for "
765+ dev_notice(ddev, "too many alternate settings for "
766766 "config %d interface %d: %d, "
767767 "using maximum allowed: %d\n",
768768 cfgno, inums[i], j, USB_MAXALTSETTING);
@@ -811,7 +811,7 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx, · 42 unmodified lines
811811 break;
812812 }
813813 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 "
815815 "altsetting %d\n", cfgno, inums[i], j);
816816 }
817817 }
@@ -868,7 +868,7 @@ int usb_get_configuration(struct usb_device *dev) · 50 unmodified lines
868868 int result;
869869
870870 if (ncfg > USB_MAXCONFIG) {
871− dev_warn(ddev, "too many configurations: %d, "
871+ dev_notice(ddev, "too many configurations: %d, "
872872 "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
873873 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
874874 }
@@ -902,7 +902,7 @@ int usb_get_configuration(struct usb_device *dev) · 27 unmodified lines
902902 "descriptor/%s: %d\n", cfgno, "start", result);
903903 if (result != -EPIPE)
904904 goto err;
905− dev_err(ddev, "chopping to %d config(s)\n", cfgno);
905+ dev_notice(ddev, "chopping to %d config(s)\n", cfgno);
906906 dev->descriptor.bNumConfigurations = cfgno;
907907 break;
908908 } else if (result < 4) {
@@ -934,7 +934,7 @@ int usb_get_configuration(struct usb_device *dev) · 25 unmodified lines
934934 goto err;
935935 }
936936 if (result < length) {
937− dev_warn(ddev, "config index %d descriptor too short "
937+ dev_notice(ddev, "config index %d descriptor too short "
938938 "(expected %i, got %i)\n", cfgno, length, result);
939939 length = result;
940940 }
@@ -993,7 +993,7 @@ int usb_get_bos_descriptor(struct usb_device *dev) · 52 unmodified lines
993993 /* Get BOS descriptor */
994994 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, bos, USB_DT_BOS_SIZE);
995995 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");
997997 if (ret >= 0)
998998 ret = -ENOMSG;
999999 kfree(bos);
@@ -1021,7 +1021,7 @@ int usb_get_bos_descriptor(struct usb_device *dev) · 21 unmodified lines
10211021
10221022 ret = usb_get_descriptor(dev, USB_DT_BOS, 0, buffer, total_len);
10231023 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");
10251025 if (ret >= 0)
10261026 ret = -ENOMSG;
10271027 goto err;
@@ -1046,7 +1046,7 @@ int usb_get_bos_descriptor(struct usb_device *dev) · 18 unmodified lines
10461046 }
10471047
10481048 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");
10501050 continue;
10511051 }
10521052
drivers/usb/core/hcd-pci.c+13−0
@@ -558,6 +558,17 @@ static int hcd_pci_suspend_noirq(struct device *dev) · 557 unmodified lines
558558 return retval;
559559 }
560560
561+static 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+
561572 static int hcd_pci_resume_noirq(struct device *dev)
562573 {
563574 powermac_set_asic(to_pci_dev(dev), 1);
@@ -578,6 +589,7 @@ static int hcd_pci_restore(struct device *dev) · 14 unmodified lines
578589
579590 #define hcd_pci_suspend NULL
580591 #define hcd_pci_suspend_noirq NULL
592+#define hcd_pci_poweroff_late NULL
581593 #define hcd_pci_resume_noirq NULL
582594 #define hcd_pci_resume NULL
583595 #define hcd_pci_restore NULL
@@ -615,6 +627,7 @@ const struct dev_pm_ops usb_hcd_pci_pm_ops = { · 31 unmodified lines
615627 .thaw_noirq = NULL,
616628 .thaw = hcd_pci_resume,
617629 .poweroff = hcd_pci_suspend,
630+ .poweroff_late = hcd_pci_poweroff_late,
618631 .poweroff_noirq = hcd_pci_suspend_noirq,
619632 .restore_noirq = hcd_pci_resume_noirq,
620633 .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
31333133 GFP_KERNEL,
31343134 DMA_ATTR_WRITE_COMBINE);
31353135
3136− if (IS_ERR(local_mem))
3136+ if (IS_ERR_OR_NULL(local_mem)) {
3137+ if (!local_mem)
3138+ return -ENOMEM;
3139+
31373140 return PTR_ERR(local_mem);
3141+ }
31383142
31393143 /*
31403144 * 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
30813081 return status;
30823082 }
30833083
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+ */
3102+static 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+
30843126 /* Check if a port is power on */
30853127 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus)
30863128 {
@@ -4796,6 +4838,11 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, · 1709 unmodified lines
47964838 do_new_scheme = use_new_scheme(udev, retry_counter, port_dev);
47974839
47984840 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+
47994846 if (do_new_scheme) {
48004847 struct usb_device_descriptor *buf;
48014848 int r = 0;
@@ -5246,6 +5293,11 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, · 444 unmodified lines
52465293 status = 0;
52475294
52485295 for (i = 0; i < PORT_INIT_TRIES; i++) {
5296+ if (hub_port_stop_enumerate(hub, port1, i)) {
5297+ status = -ENODEV;
5298+ break;
5299+ }
5300+
52495301 usb_lock_port(port_dev);
52505302 mutex_lock(hcd->address0_mutex);
52515303 retry_locked = true;
@@ -5614,6 +5666,10 @@ static void port_event(struct usb_hub *hub, int port1) · 362 unmodified lines
56145666 if (!pm_runtime_active(&port_dev->dev))
56155667 return;
56165668
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+
56175673 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange))
56185674 connect_change = 1;
56195675
@@ -5927,6 +5983,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev) · 307 unmodified lines
59275983 mutex_lock(hcd->address0_mutex);
59285984
59295985 for (i = 0; i < PORT_INIT_TRIES; ++i) {
5986+ if (hub_port_stop_enumerate(parent_hub, port1, i)) {
5987+ ret = -ENODEV;
5988+ break;
5989+ }
59305990
59315991 /* ep0 maxpacket size may change; let the HCD know about it.
59325992 * 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
9090 * @is_superspeed cache super-speed status
9191 * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.
9292 * @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.
9395 */
9496 struct usb_port {
9597 struct usb_device *child;
@@ -103,6 +105,8 @@ struct usb_port { · 7 unmodified lines
103105 u32 over_current_count;
104106 u8 portnum;
105107 u32 quirks;
108+ unsigned int early_stop:1;
109+ unsigned int ignore_event:1;
106110 unsigned int is_superspeed:1;
107111 unsigned int usb3_lpm_u1_permit:1;
108112 unsigned int usb3_lpm_u2_permit:1;
drivers/usb/core/port.c+29−1
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 * Author: Lan Tianyu <tianyu.lan@intel.com>
88 */
99
10+#include <linux/kstrtox.h>
1011 #include <linux/slab.h>
1112 #include <linux/pm_qos.h>
1213 #include <linux/component.h>
@@ -17,6 +18,32 @@ static int usb_port_block_power_off; · 4 unmodified lines
1718
1819 static const struct attribute_group *port_dev_group[];
1920
21+static 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+
29+static 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+}
45+static DEVICE_ATTR_RW(early_stop);
46+
2047 static ssize_t disable_show(struct device *dev,
2148 struct device_attribute *attr, char *buf)
2249 {
@@ -63,7 +90,7 @@ static ssize_t disable_store(struct device *dev, struct device_attribute *attr, · 40 unmodified lines
6390 bool disabled;
6491 int rc;
6592
66− rc = strtobool(buf, &disabled);
93+ rc = kstrtobool(buf, &disabled);
6794 if (rc)
6895 return rc;
6996
@@ -236,6 +263,7 @@ static struct attribute *port_dev_attrs[] = { · 166 unmodified lines
236263 &dev_attr_quirks.attr,
237264 &dev_attr_over_current_count.attr,
238265 &dev_attr_disable.attr,
266+ &dev_attr_early_stop.attr,
239267 NULL,
240268 };
241269
drivers/usb/core/sysfs.c+4−3
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313
1414
1515 #include <linux/kernel.h>
16+#include <linux/kstrtox.h>
1617 #include <linux/string.h>
1718 #include <linux/usb.h>
1819 #include <linux/usb/hcd.h>
@@ -505,7 +506,7 @@ static ssize_t usb2_hardware_lpm_store(struct device *dev, · 486 unmodified lines
505506 if (ret < 0)
506507 return -EINTR;
507508
508− ret = strtobool(buf, &value);
509+ ret = kstrtobool(buf, &value);
509510
510511 if (!ret) {
511512 udev->usb2_hw_lpm_allowed = value;
@@ -975,7 +976,7 @@ static ssize_t interface_authorized_default_store(struct device *dev, · 463 unmodified lines
975976 int rc = count;
976977 bool val;
977978
978− if (strtobool(buf, &val) != 0)
979+ if (kstrtobool(buf, &val) != 0)
979980 return -EINVAL;
980981
981982 if (val)
@@ -1176,7 +1177,7 @@ static ssize_t interface_authorized_store(struct device *dev, · 194 unmodified lines
11761177 struct usb_interface *intf = to_usb_interface(dev);
11771178 bool val;
11781179
1179− if (strtobool(buf, &val) != 0)
1180+ if (kstrtobool(buf, &val) != 0)
11801181 return -EINVAL;
11811182
11821183 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
45494549 hsotg->gadget.dev.of_node = hsotg->dev->of_node;
45504550 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
45514551
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))) {
45534554 ret = dwc2_lowlevel_hw_enable(hsotg);
45544555 if (ret)
45554556 goto err;
@@ -4611,7 +4612,8 @@ static int dwc2_hsotg_udc_stop(struct usb_gadget *gadget) · 55 unmodified lines
46114612 if (!IS_ERR_OR_NULL(hsotg->uphy))
46124613 otg_set_peripheral(hsotg->uphy->otg, NULL);
46134614
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)))
46154617 dwc2_lowlevel_hw_disable(hsotg);
46164618
46174619 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
113113 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
114114 GAHBCFG_HBSTLEN_SHIFT;
115115 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;
116120 }
117121
118122 static 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
321321 reset_control_assert(hsotg->reset);
322322 reset_control_assert(hsotg->reset_ecc);
323323
324− return ret;
324+ return 0;
325325 }
326326
327327 /**
@@ -576,7 +576,8 @@ static int dwc2_driver_probe(struct platform_device *dev) · 248 unmodified lines
576576 dwc2_debugfs_init(hsotg);
577577
578578 /* 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)))
580581 dwc2_lowlevel_hw_disable(hsotg);
581582
582583 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
drivers/usb/dwc3/Kconfig+2−2
@@ -152,11 +152,11 @@ config USB_DWC3_IMX8MP · 151 unmodified lines
152152
153153 config USB_DWC3_XILINX
154154 tristate "Xilinx Platforms"
155− depends on (ARCH_ZYNQMP || ARCH_VERSAL) && OF
155+ depends on (ARCH_ZYNQMP || COMPILE_TEST) && OF
156156 default USB_DWC3
157157 help
158158 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.
160160 Say 'Y' or 'M' if you have one such device.
161161
162162 config 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
122122 unsigned long flags;
123123 int ret;
124124 u32 reg;
125+ u32 desired_dr_role;
125126
126127 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);
127131
128132 pm_runtime_get_sync(dwc->dev);
129133
130134 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
131135 dwc3_otg_update(dwc, 0);
132136
133− if (!dwc->desired_dr_role)
137+ if (!desired_dr_role)
134138 goto out;
135139
136− if (dwc->desired_dr_role == dwc->current_dr_role)
140+ if (desired_dr_role == dwc->current_dr_role)
137141 goto out;
138142
139− if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
143+ if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
140144 goto out;
141145
142146 switch (dwc->current_dr_role) {
@@ -164,7 +168,7 @@ static void __dwc3_set_mode(struct work_struct *work) · 21 unmodified lines
164168 */
165169 if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||
166170 DWC3_VER_IS_PRIOR(DWC31, 190A)) &&
167− dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
171+ desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
168172 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
169173 reg |= DWC3_GCTL_CORESOFTRESET;
170174 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
@@ -184,11 +188,11 @@ static void __dwc3_set_mode(struct work_struct *work) · 13 unmodified lines
184188
185189 spin_lock_irqsave(&dwc->lock, flags);
186190
187− dwc3_set_prtcap(dwc, dwc->desired_dr_role);
191+ dwc3_set_prtcap(dwc, desired_dr_role);
188192
189193 spin_unlock_irqrestore(&dwc->lock, flags);
190194
191− switch (dwc->desired_dr_role) {
195+ switch (desired_dr_role) {
192196 case DWC3_GCTL_PRTCAP_HOST:
193197 ret = dwc3_host_init(dwc);
194198 if (ret) {
@@ -1096,8 +1100,13 @@ static int dwc3_core_init(struct dwc3 *dwc) · 901 unmodified lines
10961100
10971101 if (!dwc->ulpi_ready) {
10981102 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+ }
11001108 goto err0;
1109+ }
11011110 dwc->ulpi_ready = true;
11021111 }
11031112
drivers/usb/dwc3/dwc3-pci.c+1−1
@@ -45,7 +45,7 @@ · 44 unmodified lines
4545 #define PCI_DEVICE_ID_INTEL_ADLN 0x465e
4646 #define PCI_DEVICE_ID_INTEL_ADLN_PCH 0x54ee
4747 #define PCI_DEVICE_ID_INTEL_ADLS 0x7ae1
48−#define PCI_DEVICE_ID_INTEL_RPL 0x460e
48+#define PCI_DEVICE_ID_INTEL_RPL 0xa70e
4949 #define PCI_DEVICE_ID_INTEL_RPLS 0x7a61
5050 #define PCI_DEVICE_ID_INTEL_MTLP 0x7ec1
5151 #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
261261 if (IS_ERR(qcom->icc_path_apps)) {
262262 dev_err(dev, "failed to get apps-usb path: %ld\n",
263263 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;
265266 }
266267
267268 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
274275 }
275276 if (ret) {
276277 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret);
277− return ret;
278+ goto put_path_apps;
278279 }
279280
280281 ret = icc_set_bw(qcom->icc_path_apps, APPS_USB_AVG_BW, APPS_USB_PEAK_BW);
281282 if (ret) {
282283 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret);
283− return ret;
284+ goto put_path_apps;
284285 }
285286
286287 return 0;
288+
289+put_path_apps:
290+ icc_put(qcom->icc_path_apps);
291+put_path_ddr:
292+ icc_put(qcom->icc_path_ddr);
293+ return ret;
287294 }
288295
289296 /**
drivers/usb/dwc3/gadget.c+12−2
@@ -1464,8 +1464,18 @@ static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep, · 1463 unmodified lines
14641464 */
14651465 if (num_trbs_left == 1 || (needs_extra_trb &&
14661466 num_trbs_left <= 2 &&
1467− sg_dma_len(sg_next(s)) >= length))
1468− must_interrupt = true;
1467+ sg_dma_len(sg_next(s)) >= length)) {
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+ }
14691479
14701480 dwc3_prepare_one_trb(dep, req, trb_length, 1, i, false,
14711481 must_interrupt);
drivers/usb/fotg210/Kconfig+38−0
@@ -0,0 +1,38 @@
1+# SPDX-License-Identifier: GPL-2.0
2+
3+config 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+
14+if USB_FOTG210
15+
16+config 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+
27+config 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+
38+endif
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.
6+fotg210-objs-y += fotg210-core.o
7+fotg210-objs-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o
8+fotg210-objs-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
9+fotg210-objs := $(fotg210-objs-y)
10+obj-$(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+
36+static 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+
88+static 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+
113+static 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
129+static const struct of_device_id fotg210_of_match[] = {
130+ { .compatible = "faraday,fotg210" },
131+ {},
132+};
133+MODULE_DEVICE_TABLE(of, fotg210_of_match);
134+#endif
135+
136+static 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+
145+static 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+}
154+module_init(fotg210_init);
155+
156+static 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+}
162+module_exit(fotg210_cleanup);
163+
164+MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang");
165+MODULE_LICENSE("GPL");
166+MODULE_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
3939 #include <asm/irq.h>
4040 #include <asm/unaligned.h>
4141
42−#define DRIVER_AUTHOR "Yuan-Hsin Chen"
43−#define DRIVER_DESC "FOTG210 Host Controller (EHCI) Driver"
42+#include "fotg210.h"
43+
4444 static const char hcd_name[] = "fotg210_hcd";
4545
4646 #undef FOTG210_URB_TRACE
@@ -77,7 +77,7 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us"); · 30 unmodified lines
7777
7878 #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
7979
80−#include "fotg210.h"
80+#include "fotg210-hcd.h"
8181
8282 #define fotg210_dbg(fotg210, fmt, args...) \
8383 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
54905490 * functions and in order to facilitate role switching we cannot
54915491 * give the fotg210 driver exclusive access to those.
54925492 */
5493−MODULE_DESCRIPTION(DRIVER_DESC);
5494−MODULE_AUTHOR(DRIVER_AUTHOR);
5495−MODULE_LICENSE("GPL");
54965493
54975494 static const struct hc_driver fotg210_fotg210_hc_driver = {
54985495 .description = hcd_name,
@@ -5560,7 +5557,7 @@ static void fotg210_init(struct fotg210_hcd *fotg210) · 61 unmodified lines
55605557 * then invokes the start() method for the HCD associated with it
55615558 * through the hotplug entry's driver_data.
55625559 */
5563−static int fotg210_hcd_probe(struct platform_device *pdev)
5560+int fotg210_hcd_probe(struct platform_device *pdev)
55645561 {
55655562 struct device *dev = &pdev->dev;
55665563 struct usb_hcd *hcd;
@@ -5652,7 +5649,7 @@ fail_create_hcd: · 85 unmodified lines
56525649 * @dev: USB Host Controller being removed
56535650 *
56545651 */
5655−static int fotg210_hcd_remove(struct platform_device *pdev)
5652+int fotg210_hcd_remove(struct platform_device *pdev)
56565653 {
56575654 struct usb_hcd *hcd = platform_get_drvdata(pdev);
56585655 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
@@ -5668,27 +5665,8 @@ static int fotg210_hcd_remove(struct platform_device *pdev) · 9 unmodified lines
56685665 return 0;
56695666 }
56705667
5671−#ifdef CONFIG_OF
5672−static const struct of_device_id fotg210_of_match[] = {
5673− { .compatible = "faraday,fotg210" },
5674− {},
5675−};
5676−MODULE_DEVICE_TABLE(of, fotg210_of_match);
5677−#endif
5678−
5679−static 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−
5688−static int __init fotg210_hcd_init(void)
5668+int __init fotg210_hcd_init(void)
56895669 {
5690− int retval = 0;
5691−
56925670 if (usb_disabled())
56935671 return -ENODEV;
56945672
@@ -5704,24 +5682,11 @@ static int __init fotg210_hcd_init(void) · 9 unmodified lines
57045682
57055683 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);
57065684
5707− retval = platform_driver_register(&fotg210_hcd_driver);
5708− if (retval < 0)
5709− goto clean;
5710− return retval;
5711−
5712−clean:
5713− debugfs_remove(fotg210_debug_root);
5714− fotg210_debug_root = NULL;
5715−
5716− clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
5717− return retval;
5685+ return 0;
57185686 }
5719−module_init(fotg210_hcd_init);
57205687
5721−static void __exit fotg210_hcd_cleanup(void)
5688+void __exit fotg210_hcd_cleanup(void)
57225689 {
5723− platform_driver_unregister(&fotg210_hcd_driver);
57245690 debugfs_remove(fotg210_debug_root);
57255691 clear_bit(USB_EHCI_LOADED, &usb_hcds_loaded);
57265692 }
5727−module_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
1515 #include <linux/platform_device.h>
1616 #include <linux/usb/ch9.h>
1717 #include <linux/usb/gadget.h>
18+#include <linux/clk.h>
19+#include <linux/usb/otg.h>
20+#include <linux/usb/phy.h>
1821
1922 #include "fotg210.h"
23+#include "fotg210-udc.h"
2024
2125 #define DRIVER_DESC "FOTG210 USB Device Controller Driver"
2226 #define DRIVER_VERSION "30-April-2013"
@@ -629,10 +633,10 @@ static void fotg210_request_error(struct fotg210_udc *fotg210) · 606 unmodified lines
629633 static void fotg210_set_address(struct fotg210_udc *fotg210,
630634 struct usb_ctrlrequest *ctrl)
631635 {
632− if (ctrl->wValue >= 0x0100) {
636+ if (le16_to_cpu(ctrl->wValue) >= 0x0100) {
633637 fotg210_request_error(fotg210);
634638 } else {
635− fotg210_set_dev_addr(fotg210, ctrl->wValue);
639+ fotg210_set_dev_addr(fotg210, le16_to_cpu(ctrl->wValue));
636640 fotg210_set_cxdone(fotg210);
637641 }
638642 }
@@ -713,17 +717,17 @@ static void fotg210_get_status(struct fotg210_udc *fotg210, · 74 unmodified lines
713717
714718 switch (ctrl->bRequestType & USB_RECIP_MASK) {
715719 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);
717721 break;
718722 case USB_RECIP_INTERFACE:
719− fotg210->ep0_data = 0;
723+ fotg210->ep0_data = cpu_to_le16(0);
720724 break;
721725 case USB_RECIP_ENDPOINT:
722726 epnum = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK;
723727 if (epnum)
724728 fotg210->ep0_data =
725− fotg210_is_epnstall(fotg210->ep[epnum])
726− << USB_ENDPOINT_HALT;
729+ cpu_to_le16(fotg210_is_epnstall(fotg210->ep[epnum])
730+ << USB_ENDPOINT_HALT);
727731 else
728732 fotg210_request_error(fotg210);
729733 break;
@@ -1007,11 +1011,19 @@ static int fotg210_udc_start(struct usb_gadget *g, · 277 unmodified lines
10071011 {
10081012 struct fotg210_udc *fotg210 = gadget_to_fotg210(g);
10091013 u32 value;
1014+ int ret;
10101015
10111016 /* hook up the driver */
10121017 driver->driver.bus = NULL;
10131018 fotg210->driver = driver;
10141019
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+
10151027 /* enable device global interrupt */
10161028 value = ioread32(fotg210->reg + FOTG210_DMCR);
10171029 value |= DMCR_GLINT_EN;
@@ -1053,6 +1065,9 @@ static int fotg210_udc_stop(struct usb_gadget *g) · 35 unmodified lines
10531065 struct fotg210_udc *fotg210 = gadget_to_fotg210(g);
10541066 unsigned long flags;
10551067
1068+ if (!IS_ERR_OR_NULL(fotg210->phy))
1069+ return otg_set_peripheral(fotg210->phy->otg, NULL);
1070+
10561071 spin_lock_irqsave(&fotg210->lock, flags);
10571072
10581073 fotg210_init(fotg210);
@@ -1068,28 +1083,71 @@ static const struct usb_gadget_ops fotg210_gadget_ops = { · 9 unmodified lines
10681083 .udc_stop = fotg210_udc_stop,
10691084 };
10701085
1071−static 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+ */
1096+static 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+
1116+static struct notifier_block fotg210_phy_notifier = {
1117+ .notifier_call = fotg210_phy_event,
1118+};
1119+
1120+int fotg210_udc_remove(struct platform_device *pdev)
10721121 {
10731122 struct fotg210_udc *fotg210 = platform_get_drvdata(pdev);
10741123 int i;
10751124
10761125 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+ }
10771130 iounmap(fotg210->reg);
10781131 free_irq(platform_get_irq(pdev, 0), fotg210);
10791132
10801133 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);
10811134 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
10821135 kfree(fotg210->ep[i]);
1136+
1137+ if (!IS_ERR(fotg210->pclk))
1138+ clk_disable_unprepare(fotg210->pclk);
1139+
10831140 kfree(fotg210);
10841141
10851142 return 0;
10861143 }
10871144
1088−static int fotg210_udc_probe(struct platform_device *pdev)
1145+int fotg210_udc_probe(struct platform_device *pdev)
10891146 {
1090− struct resource *res, *ires;
1147+ struct resource *res;
10911148 struct fotg210_udc *fotg210 = NULL;
1092− struct fotg210_ep *_ep[FOTG210_MAX_NUM_EP];
1149+ struct device *dev = &pdev->dev;
1150+ int irq;
10931151 int ret = 0;
10941152 int i;
10951153
@@ -1099,29 +1157,59 @@ static int fotg210_udc_probe(struct platform_device *pdev) · 3 unmodified lines
10991157 return -ENODEV;
11001158 }
11011159
1102− ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1103− if (!ires) {
1104− pr_err("platform_get_resource IORESOURCE_IRQ error.\n");
1160+ irq = platform_get_irq(pdev, 0);
1161+ if (irq < 0) {
1162+ pr_err("could not get irq\n");
11051163 return -ENODEV;
11061164 }
11071165
1108− ret = -ENOMEM;
1109−
11101166 /* initialize udc */
11111167 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL);
11121168 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;
11131187 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+ }
11141203
11151204 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) {
1116− _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL);
1117− if (_ep[i] == NULL)
1205+ fotg210->ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL);
1206+ if (!fotg210->ep[i])
11181207 goto err_alloc;
1119− fotg210->ep[i] = _ep[i];
11201208 }
11211209
11221210 fotg210->reg = ioremap(res->start, resource_size(res));
11231211 if (fotg210->reg == NULL) {
1124− pr_err("ioremap error.\n");
1212+ dev_err(dev, "ioremap error\n");
11251213 goto err_alloc;
11261214 }
11271215
@@ -1132,8 +1220,8 @@ static int fotg210_udc_probe(struct platform_device *pdev) · 4 unmodified lines
11321220 fotg210->gadget.ops = &fotg210_gadget_ops;
11331221
11341222 fotg210->gadget.max_speed = USB_SPEED_HIGH;
1135− fotg210->gadget.dev.parent = &pdev->dev;
1136− fotg210->gadget.dev.dma_mask = pdev->dev.dma_mask;
1223+ fotg210->gadget.dev.parent = dev;
1224+ fotg210->gadget.dev.dma_mask = dev->dma_mask;
11371225 fotg210->gadget.name = udc_name;
11381226
11391227 INIT_LIST_HEAD(&fotg210->gadget.ep_list);
@@ -1176,23 +1264,28 @@ static int fotg210_udc_probe(struct platform_device *pdev) · 36 unmodified lines
11761264
11771265 fotg210_disable_unplug(fotg210);
11781266
1179− ret = request_irq(ires->start, fotg210_irq, IRQF_SHARED,
1267+ ret = request_irq(irq, fotg210_irq, IRQF_SHARED,
11801268 udc_name, fotg210);
11811269 if (ret < 0) {
1182− pr_err("request_irq error (%d)\n", ret);
1270+ dev_err(dev, "request_irq error (%d)\n", ret);
11831271 goto err_req;
11841272 }
11851273
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);
11871278 if (ret)
11881279 goto err_add_udc;
11891280
1190− dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1281+ dev_info(dev, "version %s\n", DRIVER_VERSION);
11911282
11921283 return 0;
11931284
11941285 err_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);
11961289
11971290 err_req:
11981291 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);
@@ -1203,22 +1296,11 @@ err_map: · 4 unmodified lines
12031296 err_alloc:
12041297 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
12051298 kfree(fotg210->ep[i]);
1206− kfree(fotg210);
1299+err_pclk:
1300+ if (!IS_ERR(fotg210->pclk))
1301+ clk_disable_unprepare(fotg210->pclk);
12071302
12081303 err:
1304+ kfree(fotg210);
12091305 return ret;
12101306 }
1211−
1212−static struct platform_driver fotg210_driver = {
1213− .driver = {
1214− .name = udc_name,
1215− },
1216− .probe = fotg210_udc_probe,
1217− .remove = fotg210_udc_remove,
1218−};
1219−
1220−module_platform_driver(fotg210_driver);
1221−
1222−MODULE_AUTHOR("Yuan-Hsin Chen, Feng-Hsin Chiang <john453@faraday-tech.com>");
1223−MODULE_LICENSE("GPL");
1224−MODULE_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
231231 struct fotg210_udc {
232232 spinlock_t lock; /* protect the struct */
233233 void __iomem *reg;
234+ struct clk *pclk;
234235
235236 unsigned long irq_trigger;
236237
238+ struct device *dev;
239+ struct usb_phy *phy;
237240 struct usb_gadget gadget;
238241 struct usb_gadget_driver *driver;
239242
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
6+int fotg210_hcd_probe(struct platform_device *pdev);
7+int fotg210_hcd_remove(struct platform_device *pdev);
8+int fotg210_hcd_init(void);
9+void fotg210_hcd_cleanup(void);
10+#else
11+static inline int fotg210_hcd_probe(struct platform_device *pdev)
12+{
13+ return 0;
14+}
15+static inline int fotg210_hcd_remove(struct platform_device *pdev)
16+{
17+ return 0;
18+}
19+static inline int fotg210_hcd_init(void)
20+{
21+ return 0;
22+}
23+static inline void fotg210_hcd_cleanup(void)
24+{
25+}
26+#endif
27+
28+#ifdef CONFIG_USB_FOTG210_UDC
29+int fotg210_udc_probe(struct platform_device *pdev);
30+int fotg210_udc_remove(struct platform_device *pdev);
31+#else
32+static inline int fotg210_udc_probe(struct platform_device *pdev)
33+{
34+ return 0;
35+}
36+static 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
33 #include <linux/module.h>
44 #include <linux/slab.h>
55 #include <linux/device.h>
6+#include <linux/kstrtox.h>
67 #include <linux/nls.h>
78 #include <linux/usb/composite.h>
89 #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
800801 bool use;
801802
802803 mutex_lock(&gi->lock);
803− ret = strtobool(page, &use);
804+ ret = kstrtobool(page, &use);
804805 if (!ret) {
805806 gi->use_os_desc = use;
806807 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
685685 struct usb_composite_dev *cdev = c->cdev;
686686 struct f_ecm *ecm = func_to_ecm(f);
687687 struct usb_string *us;
688− int status;
688+ int status = 0;
689689 struct usb_ep *ep;
690690
691691 struct f_ecm_opts *ecm_opts;
@@ -695,23 +695,19 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f) · 3 unmodified lines
695695
696696 ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst);
697697
698− /*
699− * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
700− * configurations are bound in sequence with list_for_each_entry,
701− * in each configuration its functions are bound in sequence
702− * with list_for_each_entry, so we assume no race condition
703− * with regard to ecm_opts->bound access
704− */
698+ mutex_lock(&ecm_opts->lock);
699+
700+ gether_set_gadget(ecm_opts->net, cdev->gadget);
701+
705702 if (!ecm_opts->bound) {
706− mutex_lock(&ecm_opts->lock);
707− gether_set_gadget(ecm_opts->net, cdev->gadget);
708703 status = gether_register_netdev(ecm_opts->net);
709− mutex_unlock(&ecm_opts->lock);
710− if (status)
711− return status;
712704 ecm_opts->bound = true;
713705 }
714706
707+ mutex_unlock(&ecm_opts->lock);
708+ if (status)
709+ return status;
710+
715711 ecm_string_defs[1].s = ecm->ethaddr;
716712
717713 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
7171 wait_queue_head_t write_queue;
7272 struct usb_request *req;
7373
74− int minor;
74+ struct device dev;
7575 struct cdev cdev;
7676 struct usb_function func;
7777
@@ -84,6 +84,14 @@ static inline struct f_hidg *func_to_hidg(struct usb_function *f) · 6 unmodified lines
8484 return container_of(f, struct f_hidg, func);
8585 }
8686
87+static 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+
8795 /*-------------------------------------------------------------------------*/
8896 /* Static descriptors */
8997
@@ -904,9 +912,7 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f) · 814 unmodified lines
904912 struct usb_ep *ep;
905913 struct f_hidg *hidg = func_to_hidg(f);
906914 struct usb_string *us;
907− struct device *device;
908915 int status;
909− dev_t dev;
910916
911917 /* maybe allocate device-global string IDs, and patch descriptors */
912918 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
9991005
10001006 /* create char device */
10011007 cdev_init(&hidg->cdev, &f_hidg_fops);
1002− dev = MKDEV(major, hidg->minor);
1003− status = cdev_add(&hidg->cdev, dev, 1);
1008+ status = cdev_device_add(&hidg->cdev, &hidg->dev);
10041009 if (status)
10051010 goto fail_free_descs;
10061011
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−
10141012 return 0;
1015−del:
1016− cdev_del(&hidg->cdev);
10171013 fail_free_descs:
10181014 usb_free_all_descriptors(f);
10191015 fail:
@@ -1244,9 +1240,7 @@ static void hidg_free(struct usb_function *f) · 224 unmodified lines
12441240
12451241 hidg = func_to_hidg(f);
12461242 opts = container_of(f->fi, struct f_hid_opts, func_inst);
1247− kfree(hidg->report_desc);
1248− kfree(hidg->set_report_buf);
1249− kfree(hidg);
1243+ put_device(&hidg->dev);
12501244 mutex_lock(&opts->lock);
12511245 --opts->refcnt;
12521246 mutex_unlock(&opts->lock);
@@ -1256,8 +1250,7 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f) · 3 unmodified lines
12561250 {
12571251 struct f_hidg *hidg = func_to_hidg(f);
12581252
1259− device_destroy(hidg_class, MKDEV(major, hidg->minor));
1260− cdev_del(&hidg->cdev);
1253+ cdev_device_del(&hidg->cdev, &hidg->dev);
12611254
12621255 usb_free_all_descriptors(f);
12631256 }
@@ -1266,6 +1259,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) · 2 unmodified lines
12661259 {
12671260 struct f_hidg *hidg;
12681261 struct f_hid_opts *opts;
1262+ int ret;
12691263
12701264 /* allocate and initialize one new instance */
12711265 hidg = kzalloc(sizeof(*hidg), GFP_KERNEL);
@@ -1275,25 +1269,31 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) · 3 unmodified lines
12751269 opts = container_of(fi, struct f_hid_opts, func_inst);
12761270
12771271 mutex_lock(&opts->lock);
1278− ++opts->refcnt;
12791272
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+
12811281 hidg->bInterfaceSubClass = opts->subclass;
12821282 hidg->bInterfaceProtocol = opts->protocol;
12831283 hidg->report_length = opts->report_length;
12841284 hidg->report_desc_length = opts->report_desc_length;
12851285 if (opts->report_desc) {
1286− hidg->report_desc = kmemdup(opts->report_desc,
1287− opts->report_desc_length,
1288− GFP_KERNEL);
1286+ hidg->report_desc = devm_kmemdup(&hidg->dev, opts->report_desc,
1287+ opts->report_desc_length,
1288+ GFP_KERNEL);
12891289 if (!hidg->report_desc) {
1290− kfree(hidg);
1291− mutex_unlock(&opts->lock);
1292− return ERR_PTR(-ENOMEM);
1290+ ret = -ENOMEM;
1291+ goto err_put_device;
12931292 }
12941293 }
12951294 hidg->use_out_ep = !opts->no_out_endpoint;
12961295
1296+ ++opts->refcnt;
12971297 mutex_unlock(&opts->lock);
12981298
12991299 hidg->func.name = "hid";
@@ -1308,6 +1308,12 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) · 8 unmodified lines
13081308 hidg->qlen = 4;
13091309
13101310 return &hidg->func;
1311+
1312+err_put_device:
1313+ put_device(&hidg->dev);
1314+err_unlock:
1315+ mutex_unlock(&opts->lock);
1316+ return ERR_PTR(ret);
13111317 }
13121318
13131319 DECLARE_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
176176 #include <linux/fcntl.h>
177177 #include <linux/file.h>
178178 #include <linux/fs.h>
179+#include <linux/kstrtox.h>
179180 #include <linux/kthread.h>
180181 #include <linux/sched/signal.h>
181182 #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
33873388 return -EBUSY;
33883389 }
33893390
3390− ret = strtobool(page, &stall);
3391+ ret = kstrtobool(page, &stall);
33913392 if (!ret) {
33923393 opts->common->can_stall = stall;
33933394 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
364364 spin_unlock_irqrestore(&dev->lock, flags);
365365
366366 kref_get(&dev->kref);
367− DBG(dev, "printer_open returned %x\n", ret);
367+
368368 return ret;
369369 }
370370
@@ -382,7 +382,6 @@ printer_close(struct inode *inode, struct file *fd) · 11 unmodified lines
382382 spin_unlock_irqrestore(&dev->lock, flags);
383383
384384 kref_put(&dev->kref, printer_dev_free);
385− DBG(dev, "printer_close\n");
386385
387386 return 0;
388387 }
@@ -848,8 +847,6 @@ static void printer_reset_interface(struct printer_dev *dev) · 459 unmodified lines
848847 if (dev->interface < 0)
849848 return;
850849
851− DBG(dev, "%s\n", __func__);
852−
853850 if (dev->in_ep->desc)
854851 usb_ep_disable(dev->in_ep);
855852
@@ -887,8 +884,6 @@ static void printer_soft_reset(struct printer_dev *dev) · 31 unmodified lines
887884 {
888885 struct usb_request *req;
889886
890− INFO(dev, "Received Printer Reset Request\n");
891−
892887 if (usb_ep_disable(dev->in_ep))
893888 DBG(dev, "Failed to disable USB in_ep\n");
894889 if (usb_ep_disable(dev->out_ep))
@@ -1185,8 +1180,6 @@ static void printer_func_disable(struct usb_function *f) · 290 unmodified lines
11851180 {
11861181 struct printer_dev *dev = func_to_printer(f);
11871182
1188− DBG(dev, "%s\n", __func__);
1189−
11901183 printer_reset_interface(dev);
11911184 }
11921185
drivers/usb/gadget/function/f_uvc.c+15−5
@@ -39,9 +39,6 @@ MODULE_PARM_DESC(trace, "Trace level bitmask"); · 38 unmodified lines
3939
4040 /* string IDs are assigned dynamically */
4141
42−#define UVC_STRING_CONTROL_IDX 0
43−#define UVC_STRING_STREAMING_IDX 1
44−
4542 static struct usb_string uvc_en_us_strings[] = {
4643 /* [UVC_STRING_CONTROL_IDX].s = DYNAMIC, */
4744 [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
216213
217214 memset(&v4l2_event, 0, sizeof(v4l2_event));
218215 v4l2_event.type = UVC_EVENT_DATA;
219− uvc_event->data.length = req->actual;
220− memcpy(&uvc_event->data.data, req->buf, req->actual);
216+ uvc_event->data.length = min_t(unsigned int, req->actual,
217+ sizeof(uvc_event->data.data));
218+ memcpy(&uvc_event->data.data, req->buf, uvc_event->data.length);
221219 v4l2_event_queue(&uvc->vdev, &v4l2_event);
222220 }
223221 }
@@ -228,6 +226,8 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) · 4 unmodified lines
228226 struct uvc_device *uvc = to_uvc(f);
229227 struct v4l2_event v4l2_event;
230228 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;
231231
232232 if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) {
233233 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
248248 memset(&v4l2_event, 0, sizeof(v4l2_event));
249249 v4l2_event.type = UVC_EVENT_SETUP;
250250 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+
251261 v4l2_event_queue(&uvc->vdev, &v4l2_event);
252262
253263 return 0;
drivers/usb/gadget/function/storage_common.c+5−4
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 #include <linux/blkdev.h>
2424 #include <linux/file.h>
2525 #include <linux/fs.h>
26+#include <linux/kstrtox.h>
2627 #include <linux/usb/composite.h>
2728
2829 #include "storage_common.h"
@@ -396,7 +397,7 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, · 367 unmodified lines
396397 ssize_t rc;
397398 bool ro;
398399
399− rc = strtobool(buf, &ro);
400+ rc = kstrtobool(buf, &ro);
400401 if (rc)
401402 return rc;
402403
@@ -419,7 +420,7 @@ ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) · 16 unmodified lines
419420 bool nofua;
420421 int ret;
421422
422− ret = strtobool(buf, &nofua);
423+ ret = kstrtobool(buf, &nofua);
423424 if (ret)
424425 return ret;
425426
@@ -470,7 +471,7 @@ ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, · 44 unmodified lines
470471 bool cdrom;
471472 int ret;
472473
473− ret = strtobool(buf, &cdrom);
474+ ret = kstrtobool(buf, &cdrom);
474475 if (ret)
475476 return ret;
476477
@@ -493,7 +494,7 @@ ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, · 16 unmodified lines
493494 bool removable;
494495 int ret;
495496
496− ret = strtobool(buf, &removable);
497+ ret = kstrtobool(buf, &removable);
497498 if (ret)
498499 return ret;
499500
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
798798 net->max_mtu = GETHER_MAX_MTU_SIZE;
799799
800800 dev->gadget = g;
801− SET_NETDEV_DEV(net, &g->dev);
802801 SET_NETDEV_DEVTYPE(net, &gadget_type);
803802
804803 status = register_netdev(net);
@@ -873,8 +872,6 @@ int gether_register_netdev(struct net_device *net) · 68 unmodified lines
873872 struct usb_gadget *g;
874873 int status;
875874
876− if (!net->dev.parent)
877− return -EINVAL;
878875 dev = netdev_priv(net);
879876 g = dev->gadget;
880877
@@ -905,7 +902,6 @@ void gether_set_gadget(struct net_device *net, struct usb_gadget *g) · 24 unmodified lines
905902
906903 dev = netdev_priv(net);
907904 dev->gadget = g;
908− SET_NETDEV_DEV(net, &g->dev);
909905 }
910906 EXPORT_SYMBOL_GPL(gether_set_gadget);
911907
drivers/usb/gadget/function/u_serial.c+2−1
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424 #include <linux/export.h>
2525 #include <linux/module.h>
2626 #include <linux/console.h>
27+#include <linux/kstrtox.h>
2728 #include <linux/kthread.h>
2829 #include <linux/workqueue.h>
2930 #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
10701071 bool enable;
10711072 int ret;
10721073
1073− ret = strtobool(page, &enable);
1074+ ret = kstrtobool(page, &enable);
10741075 if (ret)
10751076 return ret;
10761077
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
15121512 UVCG_UNCOMPRESSED_ATTR(b_default_frame_index, bDefaultFrameIndex, 8);
15131513 UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8);
15141514 UVCG_UNCOMPRESSED_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8);
1515−UVCG_UNCOMPRESSED_ATTR_RO(bm_interface_flags, bmInterfaceFlags, 8);
1515+UVCG_UNCOMPRESSED_ATTR_RO(bm_interlace_flags, bmInterlaceFlags, 8);
15161516
15171517 #undef UVCG_UNCOMPRESSED_ATTR
15181518 #undef UVCG_UNCOMPRESSED_ATTR_RO
@@ -1541,7 +1541,7 @@ static struct configfs_attribute *uvcg_uncompressed_attrs[] = { · 22 unmodified lines
15411541 &uvcg_uncompressed_attr_b_default_frame_index,
15421542 &uvcg_uncompressed_attr_b_aspect_ratio_x,
15431543 &uvcg_uncompressed_attr_b_aspect_ratio_y,
1544− &uvcg_uncompressed_attr_bm_interface_flags,
1544+ &uvcg_uncompressed_attr_bm_interlace_flags,
15451545 &uvcg_uncompressed_attr_bma_controls,
15461546 NULL,
15471547 };
@@ -1574,7 +1574,7 @@ static struct config_group *uvcg_uncompressed_make(struct config_group *group, · 26 unmodified lines
15741574 h->desc.bDefaultFrameIndex = 1;
15751575 h->desc.bAspectRatioX = 0;
15761576 h->desc.bAspectRatioY = 0;
1577− h->desc.bmInterfaceFlags = 0;
1577+ h->desc.bmInterlaceFlags = 0;
15781578 h->desc.bCopyProtect = 0;
15791579
15801580 INIT_LIST_HEAD(&h->fmt.frames);
@@ -1700,7 +1700,7 @@ UVCG_MJPEG_ATTR(b_default_frame_index, bDefaultFrameIndex, 8); · 119 unmodified lines
17001700 UVCG_MJPEG_ATTR_RO(bm_flags, bmFlags, 8);
17011701 UVCG_MJPEG_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8);
17021702 UVCG_MJPEG_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8);
1703−UVCG_MJPEG_ATTR_RO(bm_interface_flags, bmInterfaceFlags, 8);
1703+UVCG_MJPEG_ATTR_RO(bm_interlace_flags, bmInterlaceFlags, 8);
17041704
17051705 #undef UVCG_MJPEG_ATTR
17061706 #undef UVCG_MJPEG_ATTR_RO
@@ -1728,7 +1728,7 @@ static struct configfs_attribute *uvcg_mjpeg_attrs[] = { · 21 unmodified lines
17281728 &uvcg_mjpeg_attr_bm_flags,
17291729 &uvcg_mjpeg_attr_b_aspect_ratio_x,
17301730 &uvcg_mjpeg_attr_b_aspect_ratio_y,
1731− &uvcg_mjpeg_attr_bm_interface_flags,
1731+ &uvcg_mjpeg_attr_bm_interlace_flags,
17321732 &uvcg_mjpeg_attr_bma_controls,
17331733 NULL,
17341734 };
@@ -1755,7 +1755,7 @@ static struct config_group *uvcg_mjpeg_make(struct config_group *group, · 20 unmodified lines
17551755 h->desc.bDefaultFrameIndex = 1;
17561756 h->desc.bAspectRatioX = 0;
17571757 h->desc.bAspectRatioY = 0;
1758− h->desc.bmInterfaceFlags = 0;
1758+ h->desc.bmInterlaceFlags = 0;
17591759 h->desc.bCopyProtect = 0;
17601760
17611761 INIT_LIST_HEAD(&h->fmt.frames);
drivers/usb/gadget/legacy/serial.c+2−1
@@ -9,6 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/kernel.h>
1111 #include <linux/device.h>
12+#include <linux/kstrtox.h>
1213 #include <linux/module.h>
1314 #include <linux/tty.h>
1415 #include <linux/tty_flip.h>
@@ -109,7 +110,7 @@ static int enable_set(const char *s, const struct kernel_param *kp) · 94 unmodified lines
109110 if (!s) /* called for no-arg enable == default */
110111 return 0;
111112
112− ret = strtobool(s, &do_enable);
113+ ret = kstrtobool(s, &do_enable);
113114 if (ret || enable == do_enable)
114115 return ret;
115116
drivers/usb/gadget/legacy/webcam.c+2−2
@@ -171,7 +171,7 @@ static const struct uvc_format_uncompressed uvc_format_yuv = { · 170 unmodified lines
171171 .bDefaultFrameIndex = 1,
172172 .bAspectRatioX = 0,
173173 .bAspectRatioY = 0,
174− .bmInterfaceFlags = 0,
174+ .bmInterlaceFlags = 0,
175175 .bCopyProtect = 0,
176176 };
177177
@@ -222,7 +222,7 @@ static const struct uvc_format_mjpeg uvc_format_mjpg = { · 44 unmodified lines
222222 .bDefaultFrameIndex = 1,
223223 .bAspectRatioX = 0,
224224 .bAspectRatioY = 0,
225− .bmInterfaceFlags = 0,
225+ .bmInterlaceFlags = 0,
226226 .bCopyProtect = 0,
227227 };
228228
drivers/usb/gadget/udc/Kconfig+2−13
@@ -33,7 +33,7 @@ menu "USB Peripheral Controller" · 32 unmodified lines
3333 config USB_AT91
3434 tristate "Atmel AT91 USB Device Port"
3535 depends on ARCH_AT91
36− depends on OF || COMPILE_TEST
36+ depends on OF
3737 help
3838 Many Atmel AT91 processors (such as the AT91RM2000) have a
3939 full speed USB Device Port with support for five configurable
@@ -108,17 +108,6 @@ config USB_FUSB300 · 68 unmodified lines
108108 help
109109 Faraday usb device controller FUSB300 driver
110110
111−config 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−
122111 config USB_GR_UDC
123112 tristate "Aeroflex Gaisler GRUSBDC USB Peripheral Controller Driver"
124113 depends on HAS_DMA
@@ -430,7 +419,7 @@ config USB_EG20T · 305 unmodified lines
430419 config USB_GADGET_XILINX
431420 tristate "Xilinx USB Driver"
432421 depends on HAS_DMA
433− depends on OF || COMPILE_TEST
422+ depends on OF
434423 help
435424 USB peripheral controller driver for Xilinx USB2 device.
436425 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
3434 obj-$(CONFIG_USB_MV_UDC) += mv_udc.o
3535 mv_udc-y := mv_udc_core.o
3636 obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
37−obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
3837 obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
3938 obj-$(CONFIG_USB_GR_UDC) += gr_udc.o
4039 obj-$(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
3737
3838 list_del_init(&req->queue);
3939
40− if (req->req.status == -EINPROGRESS)
40+ if ((req->req.status == -EINPROGRESS) || (status == -EOVERFLOW))
4141 req->req.status = status;
4242
4343 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
8484 {
8585 struct ast_vhub_req *req;
8686 unsigned int len;
87+ int status = 0;
8788 u32 stat;
8889
8990 /* Read EP status */
@@ -119,9 +120,15 @@ static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) · 29 unmodified lines
119120 len = VHUB_EP_DMA_TX_SIZE(stat);
120121
121122 /* If not using DMA, copy data out if needed */
122− if (!req->req.dma && !ep->epn.is_in && len)
123− memcpy(req->req.buf + req->req.actual, ep->buf, len);
124−
123+ if (!req->req.dma && !ep->epn.is_in && len) {
124+ if (req->req.actual + len > req->req.length) {
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+ }
125132 /* Adjust size */
126133 req->req.actual += len;
127134
@@ -129,9 +136,10 @@ static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) · 1 unmodified line
129136 if (len < ep->ep.maxpacket)
130137 req->last_desc = 1;
131138
139+done:
132140 /* That's it ? complete the request and pick a new one */
133141 if (req->last_desc >= 0) {
134− ast_vhub_done(ep, req, 0);
142+ ast_vhub_done(ep, req, status);
135143 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req,
136144 queue);
137145
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
16281628
16291629 static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on)
16301630 {
1631− if (is_on)
1632− gpiod_set_value(udc->board.pullup_pin, 1);
1633− else
1634− gpiod_set_value(udc->board.pullup_pin, 0);
1631+ gpiod_set_value(udc->board.pullup_pin, is_on);
16351632 }
16361633
16371634 static 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
734734 }
735735
736736 ret = gadget->ops->pullup(gadget, 0);
737− if (!ret) {
737+ if (!ret)
738738 gadget->connected = 0;
739− mutex_lock(&udc_lock);
740− if (gadget->udc->driver)
741− gadget->udc->driver->disconnect(gadget);
742− mutex_unlock(&udc_lock);
743− }
739+
740+ mutex_lock(&udc_lock);
741+ if (gadget->udc->driver)
742+ gadget->udc->driver->disconnect(gadget);
743+ mutex_unlock(&udc_lock);
744744
745745 out:
746746 trace_usb_gadget_disconnect(gadget, ret);
drivers/usb/host/Kconfig+1−12
@@ -47,7 +47,7 @@ config USB_XHCI_PCI_RENESAS · 46 unmodified lines
4747 tristate "Support for additional Renesas xHCI controller with firmware"
4848 help
4949 Say 'Y' to enable the support for the Renesas xHCI controller with
50− firmware. Make sure you have the firwmare for the device and
50+ firmware. Make sure you have the firmware for the device and
5151 installed on your system for this device to work.
5252 If unsure, say 'N'.
5353
@@ -389,17 +389,6 @@ config USB_ISP1362_HCD · 335 unmodified lines
389389 To compile this driver as a module, choose M here: the
390390 module will be called isp1362-hcd.
391391
392−config 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−
403392 config USB_MAX3421_HCD
404393 tristate "MAX3421 HCD (USB-over-SPI) support"
405394 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
8484 obj-$(CONFIG_USB_EHCI_MV) += ehci-mv.o
8585 obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o
8686 obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o
87−obj-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o
8887 obj-$(CONFIG_USB_MAX3421_HCD) += max3421-hcd.o
8988 obj-$(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
9999 hcd->rsrc_len = resource_size(&res);
100100
101101 irq = irq_of_parse_and_map(dn, 0);
102− if (irq == NO_IRQ) {
102+ if (!irq) {
103103 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
104104 __FILE__);
105105 rv = -EBUSY;
drivers/usb/host/ehci-pci.c+4−3
@@ -411,11 +411,12 @@ static struct pci_driver ehci_pci_driver = { · 410 unmodified lines
411411 .remove = ehci_pci_remove,
412412 .shutdown = usb_hcd_pci_shutdown,
413413
414−#ifdef CONFIG_PM
415414 .driver = {
416− .pm = &usb_hcd_pci_pm_ops
417− },
415+#ifdef CONFIG_PM
416+ .pm = &usb_hcd_pci_pm_ops,
418417 #endif
418+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
419+ },
419420 };
420421
421422 static 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
119119 hcd->rsrc_len = resource_size(&res);
120120
121121 irq = irq_of_parse_and_map(dn, 0);
122− if (irq == NO_IRQ) {
122+ if (!irq) {
123123 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
124124 __FILE__);
125125 rv = -EBUSY;
drivers/usb/host/ehci.h+1−1
@@ -471,7 +471,7 @@ struct ehci_iso_sched { · 470 unmodified lines
471471 * acts like a qh would, if EHCI had them for ISO.
472472 */
473473 struct ehci_iso_stream {
474− /* first field matches ehci_hq, but is NULL */
474+ /* first field matches ehci_qh, but is NULL */
475475 struct ehci_qh_hw *hw;
476476
477477 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
676676
677677 /* USB Host interrupt. */
678678 usb_irq = irq_of_parse_and_map(node, 0);
679− if (usb_irq == NO_IRQ) {
679+ if (!usb_irq) {
680680 dev_err(dev, "could not get usb irq\n");
681681 ret = -EINVAL;
682682 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
120120 }
121121
122122 irq = irq_of_parse_and_map(dn, 0);
123− if (irq == NO_IRQ) {
123+ if (!irq) {
124124 dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
125125 __FILE__);
126126 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
116116 hcd->rsrc_len = resource_size(&res);
117117
118118 irq = irq_of_parse_and_map(dn, 0);
119− if (irq == NO_IRQ) {
119+ if (!irq) {
120120 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
121121 rv = -EBUSY;
122122 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
426426 */
427427 #define XHCI_PORT_RZ ((1<<2) | (1<<24) | (0xf<<28))
428428
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+ *
430433 * Given a port state, this function returns a value that would result in the
431434 * port being in the same state, if the value was written to the port status
432435 * control register.
433436 * Save Read Only (RO) bits and save read/write bits where
434437 * writing a 0 clears the bit and writing a 1 sets the bit (RWS).
435438 * 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.
436442 */
443+
437444 u32 xhci_port_state_to_neutral(u32 state)
438445 {
439446 /* Save read-only status and port state */
440447 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS);
441448 }
449+EXPORT_SYMBOL_GPL(xhci_port_state_to_neutral);
442450
443−/*
444− * find slot id based on port number.
445− * @port: The one-based port number from one of the two split roothubs.
451+/**
452+ * xhci_find_slot_id_by_port() - Find slot id of a usb device on a roothub port
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
446458 */
459+
447460 int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
448461 u16 port)
449462 {
@@ -465,6 +478,7 @@ int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, · 15 unmodified lines
465478
466479 return slot_id;
467480 }
481+EXPORT_SYMBOL_GPL(xhci_find_slot_id_by_port);
468482
469483 /*
470484 * 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
485485 const struct hc_driver *driver;
486486 struct xhci_hcd *xhci;
487487 struct resource *res;
488+ struct usb_hcd *usb3_hcd;
488489 struct usb_hcd *hcd;
489490 int ret = -ENODEV;
490491 int wakeup_irq;
@@ -593,6 +594,7 @@ static int xhci_mtk_probe(struct platform_device *pdev) · 102 unmodified lines
593594
594595 xhci = hcd_to_xhci(hcd);
595596 xhci->main_hcd = hcd;
597+ xhci->allow_single_roothub = 1;
596598
597599 /*
598600 * 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
602604 xhci->imod_interval = 5000;
603605 device_property_read_u32(dev, "imod-interval-ns", &xhci->imod_interval);
604606
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−
612607 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
613608 if (ret)
614− goto put_usb3_hcd;
609+ goto disable_device_wakeup;
615610
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 &&
617622 !(xhci->quirks & XHCI_BROKEN_STREAMS))
618− xhci->shared_hcd->can_do_streams = 1;
623+ usb3_hcd->can_do_streams = 1;
619624
620− ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
621− if (ret)
622− goto dealloc_usb2_hcd;
625+ if (xhci->shared_hcd) {
626+ ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
627+ if (ret)
628+ goto put_usb3_hcd;
629+ }
623630
624631 if (wakeup_irq > 0) {
625632 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
639646
640647 dealloc_usb3_hcd:
641648 usb_remove_hcd(xhci->shared_hcd);
642− xhci->shared_hcd = NULL;
643−
644−dealloc_usb2_hcd:
645− usb_remove_hcd(hcd);
646649
647650 put_usb3_hcd:
648− xhci_mtk_sch_exit(mtk);
649651 usb_put_hcd(xhci->shared_hcd);
650652
653+dealloc_usb2_hcd:
654+ xhci_mtk_sch_exit(mtk);
655+ usb_remove_hcd(hcd);
656+
651657 disable_device_wakeup:
652658 device_init_wakeup(dev, false);
653659
@@ -679,10 +685,15 @@ static int xhci_mtk_remove(struct platform_device *pdev) · 25 unmodified lines
679685 dev_pm_clear_wake_irq(dev);
680686 device_init_wakeup(dev, false);
681687
682− usb_remove_hcd(shared_hcd);
683− xhci->shared_hcd = NULL;
688+ if (shared_hcd) {
689+ usb_remove_hcd(shared_hcd);
690+ xhci->shared_hcd = NULL;
691+ }
684692 usb_remove_hcd(hcd);
685− usb_put_hcd(shared_hcd);
693+
694+ if (shared_hcd)
695+ usb_put_hcd(shared_hcd);
696+
686697 usb_put_hcd(hcd);
687698 xhci_mtk_sch_exit(mtk);
688699 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
700711 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
701712 struct usb_hcd *hcd = mtk->hcd;
702713 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
714+ struct usb_hcd *shared_hcd = xhci->shared_hcd;
703715 int ret;
704716
705717 xhci_dbg(xhci, "%s: stop port polling\n", __func__);
706718 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
707719 del_timer_sync(&hcd->rh_timer);
708− clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);
709− del_timer_sync(&xhci->shared_hcd->rh_timer);
720+ if (shared_hcd) {
721+ clear_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags);
722+ del_timer_sync(&shared_hcd->rh_timer);
723+ }
710724
711725 ret = xhci_mtk_host_disable(mtk);
712726 if (ret)
@@ -718,8 +732,10 @@ static int __maybe_unused xhci_mtk_suspend(struct device *dev) · 5 unmodified lines
718732
719733 restart_poll_rh:
720734 xhci_dbg(xhci, "%s: restart port polling\n", __func__);
721− set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);
722− usb_hcd_poll_rh_status(xhci->shared_hcd);
735+ if (shared_hcd) {
736+ set_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags);
737+ usb_hcd_poll_rh_status(shared_hcd);
738+ }
723739 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
724740 usb_hcd_poll_rh_status(hcd);
725741 return ret;
@@ -730,6 +746,7 @@ static int __maybe_unused xhci_mtk_resume(struct device *dev) · 4 unmodified lines
730746 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
731747 struct usb_hcd *hcd = mtk->hcd;
732748 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
749+ struct usb_hcd *shared_hcd = xhci->shared_hcd;
733750 int ret;
734751
735752 usb_wakeup_set(mtk, false);
@@ -742,8 +759,10 @@ static int __maybe_unused xhci_mtk_resume(struct device *dev) · 6 unmodified lines
742759 goto disable_clks;
743760
744761 xhci_dbg(xhci, "%s: restart port polling\n", __func__);
745− set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags);
746− usb_hcd_poll_rh_status(xhci->shared_hcd);
762+ if (shared_hcd) {
763+ set_bit(HCD_FLAG_POLL_RH, &shared_hcd->flags);
764+ usb_hcd_poll_rh_status(shared_hcd);
765+ }
747766 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
748767 usb_hcd_poll_rh_status(hcd);
749768 return 0;
drivers/usb/host/xhci-pci.c+59−4
@@ -59,6 +59,7 @@ · 58 unmodified lines
5959 #define PCI_DEVICE_ID_INTEL_TIGER_LAKE_XHCI 0x9a13
6060 #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x1138
6161 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed
62+#define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI 0x54ed
6263
6364 #define PCI_DEVICE_ID_AMD_RENOIR_XHCI 0x1639
6465 #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
246247 xhci->quirks |= XHCI_MISSING_CAS;
247248
248249 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))
250252 xhci->quirks |= XHCI_RESET_TO_DEFAULT;
251253
252254 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
620622 return retval;
621623 }
622624
625+static 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+
623676 static void xhci_pci_shutdown(struct usb_hcd *hcd)
624677 {
625678 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
@@ -673,11 +726,12 @@ static struct pci_driver xhci_pci_driver = { · 47 unmodified lines
673726 /* suspend and resume implemented later */
674727
675728 .shutdown = usb_hcd_pci_shutdown,
676−#ifdef CONFIG_PM
677729 .driver = {
678− .pm = &usb_hcd_pci_pm_ops
679− },
730+#ifdef CONFIG_PM
731+ .pm = &usb_hcd_pci_pm_ops,
680732 #endif
733+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
734+ },
681735 };
682736
683737 static int __init xhci_pci_init(void)
@@ -686,6 +740,7 @@ static int __init xhci_pci_init(void) · 2 unmodified lines
686740 #ifdef CONFIG_PM
687741 xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend;
688742 xhci_pci_hc_driver.pci_resume = xhci_pci_resume;
743+ xhci_pci_hc_driver.pci_poweroff_late = xhci_pci_poweroff_late;
689744 xhci_pci_hc_driver.shutdown = xhci_pci_shutdown;
690745 #endif
691746 return pci_register_driver(&xhci_pci_driver);
drivers/usb/host/xhci-ring.c+23−19
@@ -896,7 +896,7 @@ done: · 895 unmodified lines
896896 }
897897
898898 static 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,
900900 struct xhci_td *td,
901901 enum xhci_ep_reset_type reset_type)
902902 {
@@ -1110,8 +1110,7 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, · 207 unmodified lines
11101110 td->status = -EPROTO;
11111111 }
11121112 /* reset ep, reset handler cleans up cancelled tds */
1113− err = xhci_handle_halted_endpoint(xhci, ep, 0, td,
1114− reset_type);
1113+ err = xhci_handle_halted_endpoint(xhci, ep, td, reset_type);
11151114 if (err)
11161115 break;
11171116 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
21832182 }
21842183 /* Almost same procedure as for STALL_ERROR below */
21852184 xhci_clear_hub_tt_buffer(xhci, td, ep);
2186− xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,
2187− EP_HARD_RESET);
2185+ xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET);
21882186 return 0;
21892187 case COMP_STALL_ERROR:
21902188 /*
@@ -2200,8 +2198,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 9 unmodified lines
22002198 if (ep->ep_index != 0)
22012199 xhci_clear_hub_tt_buffer(xhci, td, ep);
22022200
2203− xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,
2204− EP_HARD_RESET);
2201+ xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET);
22052202
22062203 return 0; /* xhci_handle_halted_endpoint marked td cancelled */
22072204 default:
@@ -2458,7 +2455,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 250 unmodified lines
24582455
24592456 switch (trb_comp_code) {
24602457 case COMP_SUCCESS:
2461− ep_ring->err_count = 0;
2458+ ep->err_count = 0;
24622459 /* handle success with untransferred data as short packet */
24632460 if (ep_trb != td->last_trb || remaining) {
24642461 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
24842481 break;
24852482 case COMP_USB_TRANSACTION_ERROR:
24862483 if (xhci->quirks & XHCI_NO_SOFT_RETRY ||
2487− (ep_ring->err_count++ > MAX_SOFT_RETRY) ||
2484+ (ep->err_count++ > MAX_SOFT_RETRY) ||
24882485 le32_to_cpu(slot_ctx->tt_info) & TT_SLOT)
24892486 break;
24902487
24912488 td->status = 0;
24922489
2493− xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td,
2494− EP_SOFT_RESET);
2490+ xhci_handle_halted_endpoint(xhci, ep, td, EP_SOFT_RESET);
24952491 return 0;
24962492 default:
24972493 /* do nothing */
@@ -2565,8 +2561,14 @@ static int handle_tx_event(struct xhci_hcd *xhci, · 67 unmodified lines
25652561 case COMP_USB_TRANSACTION_ERROR:
25662562 case COMP_INVALID_STREAM_TYPE_ERROR:
25672563 case COMP_INVALID_STREAM_ID_ERROR:
2568− xhci_handle_halted_endpoint(xhci, ep, 0, NULL,
2569− EP_SOFT_RESET);
2564+ xhci_dbg(xhci, "Stream transaction error ep %u no id\n",
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);
25702572 goto cleanup;
25712573 case COMP_RING_UNDERRUN:
25722574 case COMP_RING_OVERRUN:
@@ -2749,9 +2751,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, · 176 unmodified lines
27492751 if (trb_comp_code == COMP_STALL_ERROR ||
27502752 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
27512753 trb_comp_code)) {
2752− xhci_handle_halted_endpoint(xhci, ep,
2753− ep_ring->stream_id,
2754− NULL,
2754+ xhci_handle_halted_endpoint(xhci, ep, NULL,
27552755 EP_HARD_RESET);
27562756 }
27572757 goto cleanup;
@@ -2844,9 +2844,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, · 86 unmodified lines
28442844 if (trb_comp_code == COMP_STALL_ERROR ||
28452845 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
28462846 trb_comp_code))
2847− xhci_handle_halted_endpoint(xhci, ep,
2848− ep_ring->stream_id,
2849− td, EP_HARD_RESET);
2847+ xhci_handle_halted_endpoint(xhci, ep, td,
2848+ EP_HARD_RESET);
28502849 goto cleanup;
28512850 }
28522851
@@ -3031,6 +3030,11 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) · 178 unmodified lines
30313030 if (!(status & STS_EINT))
30323031 goto out;
30333032
3033+ if (status & STS_HCE) {
3034+ xhci_warn(xhci, "WARNING: Host Controller Error\n");
3035+ goto out;
3036+ }
3037+
30343038 if (status & STS_FATAL) {
30353039 xhci_warn(xhci, "WARNING: Host System Error\n");
30363040 xhci_halt(xhci);
drivers/usb/host/xhci.h+1−1
@@ -933,6 +933,7 @@ struct xhci_virt_ep { · 932 unmodified lines
933933 * have to restore the device state to the previous state
934934 */
935935 struct xhci_ring *new_ring;
936+ unsigned int err_count;
936937 unsigned int ep_state;
937938 #define SET_DEQ_PENDING (1 << 0)
938939 #define EP_HALTED (1 << 1) /* For stall handling */
@@ -1627,7 +1628,6 @@ struct xhci_ring { · 688 unmodified lines
16271628 * if we own the TRB (if we are the consumer). See section 4.9.1.
16281629 */
16291630 u32 cycle_state;
1630− unsigned int err_count;
16311631 unsigned int stream_id;
16321632 unsigned int num_segs;
16331633 unsigned int num_trbs_free;
drivers/usb/misc/Kconfig+1−1
@@ -298,7 +298,7 @@ config BRCM_USB_PINMAP · 297 unmodified lines
298298
299299 config USB_ONBOARD_HUB
300300 tristate "Onboard USB hub support"
301− depends on OF || COMPILE_TEST
301+ depends on OF
302302 help
303303 Say Y here if you want to support discrete onboard USB hubs that
304304 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
16241624 char data[30 *3 + 4];
16251625 char *d = data;
16261626 int m = (sizeof(data) - 1) / 3 - 1;
1627− int l = 0;
16281627 struct u132_target *target = &ftdi->target[ed];
16291628 struct u132_command *command = &ftdi->command[
16301629 COMMAND_MASK & ftdi->command_next];
@@ -1647,7 +1646,6 @@ wait:if (ftdi->disconnected > 0) { · 16 unmodified lines
16471646 } else if (i++ < m) {
16481647 int w = sprintf(d, " %02X", *b++);
16491648 d += w;
1650− l += w;
16511649 } else
16521650 d += sprintf(d, " ..");
16531651 }
@@ -1956,7 +1954,6 @@ static int ftdi_elan_synchronize(struct usb_ftdi *ftdi) · 302 unmodified lines
19561954 int long_stop = 10;
19571955 int retry_on_timeout = 5;
19581956 int retry_on_empty = 10;
1959− int err_count = 0;
19601957 retval = ftdi_elan_flush_input_fifo(ftdi);
19611958 if (retval)
19621959 return retval;
@@ -2051,7 +2048,6 @@ static int ftdi_elan_synchronize(struct usb_ftdi *ftdi) · 88 unmodified lines
20512048 continue;
20522049 }
20532050 } else {
2054− err_count += 1;
20552051 dev_err(&ftdi->udev->dev, "error = %d\n",
20562052 retval);
20572053 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
331331
332332 /************************** USB driver **************************/
333333
334+#define VENDOR_ID_GENESYS 0x05e3
334335 #define VENDOR_ID_MICROCHIP 0x0424
335336 #define VENDOR_ID_REALTEK 0x0bda
336337 #define VENDOR_ID_TI 0x0451
@@ -407,6 +408,7 @@ static void onboard_hub_usbdev_disconnect(struct usb_device *udev) · 70 unmodified lines
407408 }
408409
409410 static const struct usb_device_id onboard_hub_id_table[] = {
411+ { USB_DEVICE(VENDOR_ID_GENESYS, 0x0608) }, /* Genesys Logic GL850G USB 2.0 */
410412 { USB_DEVICE(VENDOR_ID_MICROCHIP, 0x2514) }, /* USB2514B USB 2.0 */
411413 { USB_DEVICE(VENDOR_ID_REALTEK, 0x0411) }, /* RTS5411 USB 3.1 */
412414 { 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
2222 .reset_us = 3000,
2323 };
2424
25+static const struct onboard_hub_pdata genesys_gl850g_data = {
26+ .reset_us = 3,
27+};
28+
2529 static const struct of_device_id onboard_hub_match[] = {
2630 { .compatible = "usb424,2514", .data = &microchip_usb424_data, },
2731 { .compatible = "usb451,8140", .data = &ti_tusb8041_data, },
2832 { .compatible = "usb451,8142", .data = &ti_tusb8041_data, },
33+ { .compatible = "usb5e3,608", .data = &genesys_gl850g_data, },
2934 { .compatible = "usbbda,411", .data = &realtek_rts5411_data, },
3035 { .compatible = "usbbda,5411", .data = &realtek_rts5411_data, },
3136 { .compatible = "usbbda,414", .data = &realtek_rts5411_data, },
drivers/usb/misc/sisusbvga/Kconfig+0−34
@@ -3,7 +3,6 @@ · 2 unmodified lines
33 config USB_SISUSBVGA
44 tristate "USB 2.0 SVGA dongle support (Net2280/SiS315)"
55 depends on (USB_MUSB_HDRC || USB_EHCI_HCD)
6− select FONT_SUPPORT if USB_SISUSBVGA_CON
76 help
87 Say Y here if you intend to attach a USB2VGA dongle based on a
98 Net2280 and a SiS315 chip.
@@ -13,36 +12,3 @@ config USB_SISUSBVGA · 3 unmodified lines
1312
1413 To compile this driver as a module, choose M here; the module will be
1514 called sisusbvga. If unsure, say N.
16−
17−config 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
44 #
55
66 obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga.o
7−
8−sisusbvga-y := sisusb.o
9−sisusbvga-$(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
4848
4949 /* Include console and mode switching code? */
5050
51−#include <linux/console.h>
5251 #include <linux/vt_kern.h>
5352 #include "sisusb_struct.h"
5453
@@ -126,26 +125,6 @@ struct sisusb_usb_data { · 71 unmodified lines
126125 unsigned char gfxinit; /* graphics core initialized? */
127126 unsigned short chipid, chipvendor;
128127 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
149128 };
150129
151130 #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 */
74−static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
75−
76−/* Forward declaration */
77−static const struct consw sisusb_con;
78−
79−static inline void
80−sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
81−{
82− memset16(s, c, count / 2);
83−}
84−
85−static inline void
86−sisusb_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−
98−static inline void
99−sisusbcon_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−
107−void
108−sisusb_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−
136−static inline struct sisusb_usb_data *
137−sisusb_get_sisusb(unsigned short console)
138−{
139− return mysisusbs[console];
140−}
141−
142−static inline int
143−sisusb_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−
151−static struct sisusb_usb_data *
152−sisusb_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−
179−static int
180−sisusb_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 */
191−static const char *
192−sisusbcon_startup(void)
193−{
194− return "SISUSBCON";
195−}
196−
197−/* con_init console interface routine */
198−static void
199−sisusbcon_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 */
264−static void
265−sisusbcon_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 */
304−static u8
305−sisusbcon_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 */
331−static void
332−sisusbcon_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−
349−static 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−
355−static 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 */
367−static void
368−sisusbcon_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 */
389−static void
390−sisusbcon_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 */
419−static void
420−sisusbcon_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 */
473−static int
474−sisusbcon_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 */
522−static void
523−sisusbcon_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 */
554−static void
555−sisusbcon_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 */
591−static int
592−sisusbcon_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 */
672−static void
673−sisusbcon_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 */
697−static void
698−sisusbcon_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−
765−static bool
766−sisusbcon_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 */
810−static bool
811−sisusbcon_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 */
929−static int
930−sisusbcon_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 */
962−static int
963−sisusbcon_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−
990−int
991−sisusbcon_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−
1191−font_op_error:
1192− if (uplock)
1193− mutex_unlock(&sisusb->lock);
1194−
1195− return -EIO;
1196−}
1197−
1198−/* Interface routine */
1199−static int
1200−sisusbcon_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 */
1245−static int
1246−sisusbcon_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−
1282−static 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−
1307−static const char *sisusbdummycon_startup(void)
1308−{
1309− return "SISUSBVGADUMMY";
1310−}
1311−
1312−static 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−
1322−static void sisusbdummycon_deinit(struct vc_data *vc) { }
1323−static void sisusbdummycon_clear(struct vc_data *vc, int sy, int sx,
1324− int height, int width) { }
1325−static void sisusbdummycon_putc(struct vc_data *vc, int c, int ypos,
1326− int xpos) { }
1327−static void sisusbdummycon_putcs(struct vc_data *vc, const unsigned short *s,
1328− int count, int ypos, int xpos) { }
1329−static void sisusbdummycon_cursor(struct vc_data *vc, int mode) { }
1330−
1331−static 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−
1338−static int sisusbdummycon_switch(struct vc_data *vc)
1339−{
1340− return 0;
1341−}
1342−
1343−static int sisusbdummycon_blank(struct vc_data *vc, int blank, int mode_switch)
1344−{
1345− return 0;
1346−}
1347−
1348−static 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−
1362−int
1363−sisusb_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−
1439−void
1440−sisusb_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−
1490−void __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−
54−static 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−
71−static void
72−SiS_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−
78−static void
79−SiS_SetRegByte(struct SiS_Private *SiS_Pr, unsigned long port,
80− unsigned short data)
81−{
82− sisusb_setreg(SiS_Pr->sisusb, port, data);
83−}
84−
85−static unsigned char
86−SiS_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−
95−static unsigned char
96−SiS_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−
105−static void
106−SiS_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−
113−static void
114−SiS_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−
120−static void
121−SiS_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−
131−static 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−
140−static 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−
163−static 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−
172−static 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−
188−static 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−
201−static 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−
214−static 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−
220−static void SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
221−{
222− SiS_SetSegmentReg(SiS_Pr, 0);
223−}
224−
225−static void
226−SiS_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−
236−static void SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
237−{
238− SiS_SetSegmentRegOver(SiS_Pr, 0);
239−}
240−
241−static 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−
251−static int
252−SiS_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−
284−static 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−
294−static unsigned short
295−SiS_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−
318−static unsigned short
319−SiS_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−
346−static void
347−SiS_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−
367−static void
368−SiS_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−
379−static void
380−SiS_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−
397−static void
398−SiS_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−
422−static void
423−SiS_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−
443−static 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−
458−static unsigned short
459−SiS_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−
497−static 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−
509−static void
510−SiS_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−
557−static void
558−SiS_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−
585−static void
586−SiS_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−
604−static void
605−SiS_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−
629−static void
630−SiS_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−
659−static void
660−SiS_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−
735−static void
736−SiS_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−
763−static void
764−SiS_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−
846−static void
847−SiS_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−
889−int 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−
926−int 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−
150−int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
151−int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo);
152−
153−extern int sisusb_setreg(struct sisusb_usb_data *sisusb, u32 port, u8 data);
154−extern int sisusb_getreg(struct sisusb_usb_data *sisusb, u32 port, u8 * data);
155−extern int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
156− u8 index, u8 data);
157−extern int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,
158− u8 index, u8 * data);
159−extern int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port,
160− u8 idx, u8 myand, u8 myor);
161−extern int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,
162− u8 index, u8 myor);
163−extern int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,
164− u8 idx, u8 myand);
165−
166−void sisusb_delete(struct kref *kref);
167−int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data);
168−int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 * data);
169−int sisusb_copy_memory(struct sisusb_usb_data *sisusb, u8 *src,
170− u32 dest, int length);
171−int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init);
172−int 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);
175−void sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location);
176−int sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last);
177−void sisusb_console_exit(struct sisusb_usb_data *sisusb);
178−void 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
5151 #include <linux/vmalloc.h>
5252
5353 #include "sisusb.h"
54−#include "sisusb_init.h"
55−
56−#ifdef CONFIG_USB_SISUSBVGA_CON
57−#include <linux/font.h>
58−#endif
5954
6055 #define SISUSB_DONTSYNC
6156
6257 /* Forward declarations / clean-up routines */
6358
64−#ifdef CONFIG_USB_SISUSBVGA_CON
65−static int sisusb_first_vc;
66−static int sisusb_last_vc;
67−module_param_named(first, sisusb_first_vc, int, 0);
68−module_param_named(last, sisusb_last_vc, int, 0);
69−MODULE_PARM_DESC(first, "Number of first console to take over (1 - MAX_NR_CONSOLES)");
70−MODULE_PARM_DESC(last, "Number of last console to take over (1 - MAX_NR_CONSOLES)");
71−#endif
72−
7359 static struct usb_driver sisusb_driver;
7460
7561 static 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
11981184
11991185 /* High level: Gfx (indexed) register access */
12001186
1201−#ifdef CONFIG_USB_SISUSBVGA_CON
1202−int 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−
1207−int 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−
1213−int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
1187+static int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
12141188 u8 index, u8 data)
12151189 {
12161190 int ret;
@@ -1220,7 +1194,7 @@ int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port, · 3 unmodified lines
12201194 return ret;
12211195 }
12221196
1223−int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,
1197+static int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,
12241198 u8 index, u8 *data)
12251199 {
12261200 int ret;
@@ -1230,7 +1204,7 @@ int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port, · 3 unmodified lines
12301204 return ret;
12311205 }
12321206
1233−int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, u8 idx,
1207+static int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, u8 idx,
12341208 u8 myand, u8 myor)
12351209 {
12361210 int ret;
@@ -1258,13 +1232,13 @@ static int sisusb_setidxregmask(struct sisusb_usb_data *sisusb, · 21 unmodified lines
12581232 return ret;
12591233 }
12601234
1261−int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,
1235+static int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,
12621236 u8 index, u8 myor)
12631237 {
12641238 return sisusb_setidxregandor(sisusb, port, index, 0xff, myor);
12651239 }
12661240
1267−int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,
1241+static int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,
12681242 u8 idx, u8 myand)
12691243 {
12701244 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
12721246
12731247 /* Write/read video ram */
12741248
1275−#ifdef CONFIG_USB_SISUSBVGA_CON
1276−int 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−
1281−int 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−
1286−int 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
1296−static 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−
13071249 #ifdef SISUSBENDIANTEST
13081250 static void sisusb_testreadwrite(struct sisusb_usb_data *sisusb)
13091251 {
@@ -2252,131 +2194,6 @@ static int sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen) · 942 unmodified lines
22522194 return ret;
22532195 }
22542196
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−
2264−int 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−
23802197 /* fops */
23812198
23822199 static 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
24342251 return 0;
24352252 }
24362253
2437−void sisusb_delete(struct kref *kref)
2254+static void sisusb_delete(struct kref *kref)
24382255 {
24392256 struct sisusb_usb_data *sisusb = to_sisusb_dev(kref);
24402257
@@ -2446,9 +2263,6 @@ void sisusb_delete(struct kref *kref) · 5 unmodified lines
24462263 sisusb->sisusb_dev = NULL;
24472264 sisusb_free_buffers(sisusb);
24482265 sisusb_free_urbs(sisusb);
2449−#ifdef CONFIG_USB_SISUSBVGA_CON
2450− kfree(sisusb->SiS_Pr);
2451−#endif
24522266 kfree(sisusb);
24532267 }
24542268
@@ -2842,54 +2656,8 @@ static int sisusb_handle_command(struct sisusb_usb_data *sisusb, · 387 unmodified lines
28422656
28432657 case SUCMD_HANDLETEXTMODE:
28442658 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−
28752659 break;
28762660
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−
28932661 default:
28942662 retval = -EINVAL;
28952663 }
@@ -2942,11 +2710,7 @@ static long sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 46 unmodified lines
29422710 x.sisusb_vramsize = sisusb->vramsize;
29432711 x.sisusb_minor = sisusb->minor;
29442712 x.sisusb_fbdevactive = 0;
2945−#ifdef CONFIG_USB_SISUSBVGA_CON
2946− x.sisusb_conactive = sisusb->haveconsole ? 1 : 0;
2947−#else
29482713 x.sisusb_conactive = 0;
2949−#endif
29502714 memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved));
29512715
29522716 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
30902854 dev_info(&sisusb->sisusb_dev->dev, "Allocated %d output buffers\n",
30912855 sisusb->numobufs);
30922856
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−
31022857 /* Do remaining init stuff */
31032858
31042859 init_waitqueue_head(&sisusb->wait_q);
@@ -3111,12 +2866,6 @@ static int sisusb_probe(struct usb_interface *intf, · 6 unmodified lines
31112866
31122867 if (dev->speed == USB_SPEED_HIGH || dev->speed >= USB_SPEED_SUPER) {
31132868 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
31202869 if (sisusb_init_gfxdevice(sisusb, initscreen))
31212870 dev_err(&sisusb->sisusb_dev->dev,
31222871 "Failed to early initialize device\n");
@@ -3133,10 +2882,6 @@ static int sisusb_probe(struct usb_interface *intf, · 10 unmodified lines
31332882 dev_dbg(&sisusb->sisusb_dev->dev, "*** RWTEST END ***\n");
31342883 #endif
31352884
3136−#ifdef CONFIG_USB_SISUSBVGA_CON
3137− sisusb_console_init(sisusb, sisusb_first_vc, sisusb_last_vc);
3138−#endif
3139−
31402885 return 0;
31412886
31422887 error_4:
@@ -3159,10 +2904,6 @@ static void sisusb_disconnect(struct usb_interface *intf) · 16 unmodified lines
31592904 if (!sisusb)
31602905 return;
31612906
3162−#ifdef CONFIG_USB_SISUSBVGA_CON
3163− sisusb_console_exit(sisusb);
3164−#endif
3165−
31662907 usb_deregister_dev(intf, &usb_sisusb_class);
31672908
31682909 mutex_lock(&sisusb->lock);
@@ -3206,23 +2947,7 @@ static struct usb_driver sisusb_driver = { · 37 unmodified lines
32062947 .id_table = sisusb_table,
32072948 };
32082949
3209−static int __init usb_sisusb_init(void)
3210−{
3211−
3212−#ifdef CONFIG_USB_SISUSBVGA_CON
3213− sisusb_init_concode();
3214−#endif
3215−
3216− return usb_register(&sisusb_driver);
3217−}
3218−
3219−static void __exit usb_sisusb_exit(void)
3220−{
3221− usb_deregister(&sisusb_driver);
3222−}
3223−
3224−module_init(usb_sisusb_init);
3225−module_exit(usb_sisusb_exit);
2950+module_usb_driver(sisusb_driver);
32262951
32272952 MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>");
32282953 MODULE_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
699699 return 0;
700700 }
701701
702−static int usb251xb_i2c_probe(struct i2c_client *i2c,
703− const struct i2c_device_id *id)
702+static int usb251xb_i2c_probe(struct i2c_client *i2c)
704703 {
705704 struct usb251xb *hub;
706705
@@ -758,7 +757,7 @@ static struct i2c_driver usb251xb_i2c_driver = { · 51 unmodified lines
758757 .of_match_table = of_match_ptr(usb251xb_of_match),
759758 .pm = &usb251xb_pm_ops,
760759 },
761− .probe = usb251xb_i2c_probe,
760+ .probe_new = usb251xb_i2c_probe,
762761 .id_table = usb251xb_id,
763762 };
764763
drivers/usb/misc/usb3503.c+2−3
@@ -280,8 +280,7 @@ err_clk: · 279 unmodified lines
280280 return err;
281281 }
282282
283−static int usb3503_i2c_probe(struct i2c_client *i2c,
284− const struct i2c_device_id *id)
283+static int usb3503_i2c_probe(struct i2c_client *i2c)
285284 {
286285 struct usb3503 *hub;
287286 int err;
@@ -400,7 +399,7 @@ static struct i2c_driver usb3503_i2c_driver = { · 112 unmodified lines
400399 .pm = pm_ptr(&usb3503_i2c_pm_ops),
401400 .of_match_table = of_match_ptr(usb3503_of_match),
402401 },
403− .probe = usb3503_i2c_probe,
402+ .probe_new = usb3503_i2c_probe,
404403 .remove = usb3503_i2c_remove,
405404 .id_table = usb3503_id,
406405 };
drivers/usb/misc/usb4604.c+2−3
@@ -97,8 +97,7 @@ static int usb4604_probe(struct usb4604 *hub) · 96 unmodified lines
9797 return usb4604_switch_mode(hub, hub->mode);
9898 }
9999
100−static int usb4604_i2c_probe(struct i2c_client *i2c,
101− const struct i2c_device_id *id)
100+static int usb4604_i2c_probe(struct i2c_client *i2c)
102101 {
103102 struct usb4604 *hub;
104103
@@ -155,7 +154,7 @@ static struct i2c_driver usb4604_i2c_driver = { · 50 unmodified lines
155154 .pm = pm_ptr(&usb4604_i2c_pm_ops),
156155 .of_match_table = of_match_ptr(usb4604_of_match),
157156 },
158− .probe = usb4604_i2c_probe,
157+ .probe_new = usb4604_i2c_probe,
159158 .id_table = usb4604_id,
160159 };
161160 module_i2c_driver(usb4604_i2c_driver);
drivers/usb/musb/Kconfig+0−18
@@ -70,12 +70,6 @@ config USB_MUSB_SUNXI · 69 unmodified lines
7070 select GENERIC_PHY
7171 select SUNXI_SRAM
7272
73−config USB_MUSB_DAVINCI
74− tristate "DaVinci"
75− depends on ARCH_DAVINCI_DMx
76− depends on NOP_USB_XCEIV
77− depends on BROKEN
78−
7973 config USB_MUSB_DA8XX
8074 tristate "DA8xx/OMAP-L1x"
8175 depends on ARCH_DAVINCI_DA8XX
@@ -94,11 +88,6 @@ config USB_MUSB_OMAP2PLUS · 12 unmodified lines
9488 depends on OMAP_CONTROL_PHY || !OMAP_CONTROL_PHY
9589 select GENERIC_PHY
9690
97−config USB_MUSB_AM35X
98− tristate "AM35x"
99− depends on ARCH_OMAP
100− depends on NOP_USB_XCEIV
101−
10291 config USB_MUSB_DSPS
10392 tristate "TI DSPS platforms"
10493 depends on ARCH_OMAP2PLUS || COMPILE_TEST
@@ -113,7 +102,6 @@ config USB_MUSB_JZ4740 · 8 unmodified lines
113102 depends on OF
114103 depends on MIPS || COMPILE_TEST
115104 depends on USB_MUSB_GADGET
116− depends on USB=n || USB_OTG_DISABLE_EXTERNAL_HUB
117105 select USB_ROLE_SWITCH
118106
119107 config USB_MUSB_MEDIATEK
@@ -161,12 +149,6 @@ config USB_INVENTRA_DMA · 41 unmodified lines
161149 help
162150 Enable DMA transfers using Mentor's engine.
163151
164−config 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−
170152 config USB_TI_CPPI41_DMA
171153 bool 'TI CPPI 4.1'
172154 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
1616
1717 # Hardware Glue Layer
1818 obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o
19−obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o
2019 obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o
2120 obj-$(CONFIG_USB_MUSB_TUSB6010) += tusb6010.o
22−obj-$(CONFIG_USB_MUSB_DAVINCI) += davinci.o
2321 obj-$(CONFIG_USB_MUSB_DA8XX) += da8xx.o
2422 obj-$(CONFIG_USB_MUSB_UX500) += ux500.o
2523 obj-$(CONFIG_USB_MUSB_JZ4740) += jz4740.o
@@ -33,7 +31,6 @@ obj-$(CONFIG_USB_MUSB_POLARFIRE_SOC) += mpfs.o · 7 unmodified lines
3331 # though PIO is always there to back up DMA, and for ep0
3432
3533 musb_hdrc-$(CONFIG_USB_INVENTRA_DMA) += musbhsdma.o
36−musb_hdrc-$(CONFIG_USB_TI_CPPI_DMA) += cppi_dma.o
3734 musb_hdrc-$(CONFIG_USB_TUSB_OMAP_DMA) += tusb6010_omap.o
3835 musb_hdrc-$(CONFIG_USB_UX500_DMA) += ux500_dma.o
3936 musb_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−
70−struct 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− */
81−static 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− */
101−static 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−
113−static 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−
120−static 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−
168−static 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−
197−static 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−
294−eoi:
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−
313−static 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−
328−static 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−
371−static 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 */
389−static 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−
418−static 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−
437−static 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−
443−static 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−
515−err8:
516− usb_phy_generic_unregister(glue->phy);
517−
518−err7:
519− clk_disable(clk);
520−
521−err6:
522− clk_disable(phy_clk);
523−
524−err5:
525− clk_put(clk);
526−
527−err4:
528− clk_put(phy_clk);
529−
530−err3:
531− kfree(glue);
532−
533−err0:
534− return ret;
535−}
536−
537−static 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
553−static 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−
569−static 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−
596−static SIMPLE_DEV_PM_OPS(am35x_pm_ops, am35x_suspend, am35x_resume);
597−
598−static 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−
607−MODULE_DESCRIPTION("AM35x MUSB Glue Layer");
608−MODULE_AUTHOR("Ajay Kumar Gupta <ajay.gupta@ti.com>");
609−MODULE_LICENSE("GPL v2");
610−module_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−
50−static 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−
61−static 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−
70−static inline void
71−cppi_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 */
86−static 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 */
98−static 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−
110−static 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−
134−static int cppi_channel_abort(struct dma_channel *);
135−
136−static 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−
155−static 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−
222−static 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− */
263−static 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−
268−static 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− */
280−static struct dma_channel *
281−cppi_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. */
330−static 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 */
351−static void
352−cppi_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 */
381−static void
382−cppi_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 */
409−static inline void
410−cppi_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−
429−static 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−
438−static 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− */
453−static 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− */
560−static void
561−cppi_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− */
740−static bool cppi_rx_rndis = 1;
741−
742−module_param(cppi_rx_rndis, bool, 0);
743−MODULE_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− */
761−static void
762−cppi_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− */
947−static 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−
1001−static 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−
1141−irqreturn_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−}
1296−EXPORT_SYMBOL_GPL(cppi_interrupt);
1297−
1298−/* Instantiate a software object representing a DMA controller. */
1299−struct dma_controller *
1300−cppi_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−}
1346−EXPORT_SYMBOL_GPL(cppi_dma_controller_create);
1347−
1348−/*
1349− * Destroy a previously-instantiated DMA controller.
1350− */
1351−void 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−}
1367−EXPORT_SYMBOL_GPL(cppi_dma_controller_destroy);
1368−
1369−/*
1370− * Context: controller irqlocked, endpoint selected
1371− */
1372−static 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−
35−struct 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−
50−static 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−
64−static 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−
74−static int dma_off = 1;
75−
76−static 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− */
108−static 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− */
141−static 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−
150−static 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−
177−static 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−
186−static 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−
243−static 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−
351−static int davinci_musb_set_mode(struct musb *musb, u8 mode)
352−{
353− /* EVM can't do this (right?) */
354− return -EIO;
355−}
356−
357−static 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−
417−fail:
418− usb_put_phy(musb->xceiv);
419−unregister:
420− usb_phy_generic_unregister();
421− return ret;
422−}
423−
424−static 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−
471−static 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−
488−static 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−
494−static 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−
577−err1:
578− clk_disable(clk);
579−
580−err0:
581− return ret;
582−}
583−
584−static 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−
595−static struct platform_driver davinci_driver = {
596− .probe = davinci_probe,
597− .remove = davinci_remove,
598− .driver = {
599− .name = "musb-davinci",
600− },
601−};
602−
603−MODULE_DESCRIPTION("DaVinci MUSB Glue Layer");
604−MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
605−MODULE_LICENSE("GPL v2");
606−module_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
1111 #include <linux/kernel.h>
1212 #include <linux/module.h>
1313 #include <linux/of_device.h>
14+#include <linux/phy/phy.h>
1415 #include <linux/platform_device.h>
1516 #include <linux/usb/role.h>
1617 #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
8182 struct jz4740_glue *glue = usb_role_switch_get_drvdata(sw);
8283 struct usb_phy *phy = glue->musb->xceiv;
8384
85+ if (!phy)
86+ return 0;
87+
8488 switch (role) {
8589 case USB_ROLE_NONE:
8690 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
105109 .driver_data = glue,
106110 .fwnode = dev_fwnode(dev),
107111 };
112+ int err;
108113
109114 glue->musb = musb;
110115
111− if (dev->of_node)
112− musb->xceiv = devm_usb_get_phy_by_phandle(dev, "phys", 0);
113− else
114− musb->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
115− if (IS_ERR(musb->xceiv))
116− return dev_err_probe(dev, PTR_ERR(musb->xceiv),
117− "No transceiver configured\n");
116+ if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
117+ musb->phy = devm_of_phy_get_by_index(dev, dev->of_node, 0);
118+ if (IS_ERR(musb->phy)) {
119+ err = PTR_ERR(musb->phy);
120+ if (err != -ENODEV) {
121+ dev_err(dev, "Unable to get PHY\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+ }
118151
119152 glue->role_sw = usb_role_switch_register(dev, &role_sw_desc);
120153 if (IS_ERR(glue->role_sw)) {
121154 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;
123157 }
124158
125159 /*
@@ -131,6 +165,14 @@ static int jz4740_musb_init(struct musb *musb) · 5 unmodified lines
131165 musb->isr = jz4740_musb_interrupt;
132166
133167 return 0;
168+
169+err_phy_power_down:
170+ if (musb->phy)
171+ phy_power_off(musb->phy);
172+err_phy_shutdown:
173+ if (musb->phy)
174+ phy_exit(musb->phy);
175+ return err;
134176 }
135177
136178 static int jz4740_musb_exit(struct musb *musb)
@@ -138,6 +180,10 @@ static int jz4740_musb_exit(struct musb *musb) · 1 unmodified line
138180 struct jz4740_glue *glue = dev_get_drvdata(musb->controller->parent);
139181
140182 usb_role_switch_unregister(glue->role_sw);
183+ if (musb->phy) {
184+ phy_power_off(musb->phy);
185+ phy_exit(musb->phy);
186+ }
141187
142188 return 0;
143189 }
drivers/usb/musb/musb_core.c+51−56
@@ -502,7 +502,7 @@ int musb_set_host(struct musb *musb) · 501 unmodified lines
502502
503503 init_data:
504504 musb->is_active = 1;
505− musb->xceiv->otg->state = OTG_STATE_A_IDLE;
505+ musb_set_state(musb, OTG_STATE_A_IDLE);
506506 MUSB_HST_MODE(musb);
507507
508508 return error;
@@ -549,7 +549,7 @@ int musb_set_peripheral(struct musb *musb) · 40 unmodified lines
549549
550550 init_data:
551551 musb->is_active = 0;
552− musb->xceiv->otg->state = OTG_STATE_B_IDLE;
552+ musb_set_state(musb, OTG_STATE_B_IDLE);
553553 MUSB_DEV_MODE(musb);
554554
555555 return error;
@@ -599,24 +599,24 @@ static void musb_otg_timer_func(struct timer_list *t) · 43 unmodified lines
599599 unsigned long flags;
600600
601601 spin_lock_irqsave(&musb->lock, flags);
602− switch (musb->xceiv->otg->state) {
602+ switch (musb_get_state(musb)) {
603603 case OTG_STATE_B_WAIT_ACON:
604604 musb_dbg(musb,
605605 "HNP: b_wait_acon timeout; back to b_peripheral");
606606 musb_g_disconnect(musb);
607− musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
607+ musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
608608 musb->is_active = 0;
609609 break;
610610 case OTG_STATE_A_SUSPEND:
611611 case OTG_STATE_A_WAIT_BCON:
612612 musb_dbg(musb, "HNP: %s timeout",
613− usb_otg_state_string(musb->xceiv->otg->state));
613+ musb_otg_state_string(musb));
614614 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);
616616 break;
617617 default:
618618 musb_dbg(musb, "HNP: Unhandled mode %s",
619− usb_otg_state_string(musb->xceiv->otg->state));
619+ musb_otg_state_string(musb));
620620 }
621621 spin_unlock_irqrestore(&musb->lock, flags);
622622 }
@@ -630,20 +630,18 @@ void musb_hnp_stop(struct musb *musb) · 7 unmodified lines
630630 void __iomem *mbase = musb->mregs;
631631 u8 reg;
632632
633− musb_dbg(musb, "HNP: stop from %s",
634− usb_otg_state_string(musb->xceiv->otg->state));
633+ musb_dbg(musb, "HNP: stop from %s", musb_otg_state_string(musb));
635634
636− switch (musb->xceiv->otg->state) {
635+ switch (musb_get_state(musb)) {
637636 case OTG_STATE_A_PERIPHERAL:
638637 musb_g_disconnect(musb);
639− musb_dbg(musb, "HNP: back to %s",
640− usb_otg_state_string(musb->xceiv->otg->state));
638+ musb_dbg(musb, "HNP: back to %s", musb_otg_state_string(musb));
641639 break;
642640 case OTG_STATE_B_HOST:
643641 musb_dbg(musb, "HNP: Disabling HR");
644642 if (hcd)
645643 hcd->self.is_b_host = 0;
646− musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
644+ musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
647645 MUSB_DEV_MODE(musb);
648646 reg = musb_readb(mbase, MUSB_POWER);
649647 reg |= MUSB_POWER_SUSPENDM;
@@ -652,7 +650,7 @@ void musb_hnp_stop(struct musb *musb) · 2 unmodified lines
652650 break;
653651 default:
654652 musb_dbg(musb, "HNP: Stopping in unknown state %s",
655− usb_otg_state_string(musb->xceiv->otg->state));
653+ musb_otg_state_string(musb));
656654 }
657655
658656 /*
@@ -667,11 +665,10 @@ static void musb_recover_from_babble(struct musb *musb); · 8 unmodified lines
667665
668666 static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
669667 {
670− musb_dbg(musb, "RESUME (%s)",
671− usb_otg_state_string(musb->xceiv->otg->state));
668+ musb_dbg(musb, "RESUME (%s)", musb_otg_state_string(musb));
672669
673670 if (devctl & MUSB_DEVCTL_HM) {
674− switch (musb->xceiv->otg->state) {
671+ switch (musb_get_state(musb)) {
675672 case OTG_STATE_A_SUSPEND:
676673 /* remote wakeup? */
677674 musb->port1_status |=
@@ -679,27 +676,27 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl) · 1 unmodified line
679676 | MUSB_PORT_STAT_RESUME;
680677 musb->rh_timer = jiffies
681678 + msecs_to_jiffies(USB_RESUME_TIMEOUT);
682− musb->xceiv->otg->state = OTG_STATE_A_HOST;
679+ musb_set_state(musb, OTG_STATE_A_HOST);
683680 musb->is_active = 1;
684681 musb_host_resume_root_hub(musb);
685682 schedule_delayed_work(&musb->finish_resume_work,
686683 msecs_to_jiffies(USB_RESUME_TIMEOUT));
687684 break;
688685 case OTG_STATE_B_WAIT_ACON:
689− musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
686+ musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
690687 musb->is_active = 1;
691688 MUSB_DEV_MODE(musb);
692689 break;
693690 default:
694691 WARNING("bogus %s RESUME (%s)\n",
695692 "host",
696− usb_otg_state_string(musb->xceiv->otg->state));
693+ musb_otg_state_string(musb));
697694 }
698695 } else {
699− switch (musb->xceiv->otg->state) {
696+ switch (musb_get_state(musb)) {
700697 case OTG_STATE_A_SUSPEND:
701698 /* possibly DISCONNECT is upcoming */
702− musb->xceiv->otg->state = OTG_STATE_A_HOST;
699+ musb_set_state(musb, OTG_STATE_A_HOST);
703700 musb_host_resume_root_hub(musb);
704701 break;
705702 case OTG_STATE_B_WAIT_ACON:
@@ -722,7 +719,7 @@ static void musb_handle_intr_resume(struct musb *musb, u8 devctl) · 16 unmodified lines
722719 default:
723720 WARNING("bogus %s RESUME (%s)\n",
724721 "peripheral",
725− usb_otg_state_string(musb->xceiv->otg->state));
722+ musb_otg_state_string(musb));
726723 }
727724 }
728725 }
@@ -738,8 +735,7 @@ static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl) · 9 unmodified lines
738735 return IRQ_HANDLED;
739736 }
740737
741− musb_dbg(musb, "SESSION_REQUEST (%s)",
742− usb_otg_state_string(musb->xceiv->otg->state));
738+ musb_dbg(musb, "SESSION_REQUEST (%s)", musb_otg_state_string(musb));
743739
744740 /* IRQ arrives from ID pin sense or (later, if VBUS power
745741 * 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
750746 */
751747 musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
752748 musb->ep0_stage = MUSB_EP0_START;
753− musb->xceiv->otg->state = OTG_STATE_A_IDLE;
749+ musb_set_state(musb, OTG_STATE_A_IDLE);
754750 MUSB_HST_MODE(musb);
755751 musb_platform_set_vbus(musb, 1);
756752
@@ -777,7 +773,7 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl) · 20 unmodified lines
777773 * REVISIT: do delays from lots of DEBUG_KERNEL checks
778774 * make trouble here, keeping VBUS < 4.4V ?
779775 */
780− switch (musb->xceiv->otg->state) {
776+ switch (musb_get_state(musb)) {
781777 case OTG_STATE_A_HOST:
782778 /* recovery is dicey once we've gotten past the
783779 * 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
806802
807803 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
808804 "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),
810806 devctl,
811807 ({ char *s;
812808 switch (devctl & MUSB_DEVCTL_VBUS) {
@@ -831,9 +827,9 @@ static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl) · 18 unmodified lines
831827 static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
832828 {
833829 musb_dbg(musb, "SUSPEND (%s) devctl %02x",
834− usb_otg_state_string(musb->xceiv->otg->state), devctl);
830+ musb_otg_state_string(musb), devctl);
835831
836− switch (musb->xceiv->otg->state) {
832+ switch (musb_get_state(musb)) {
837833 case OTG_STATE_A_PERIPHERAL:
838834 /* We also come here if the cable is removed, since
839835 * 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
858854 musb_g_suspend(musb);
859855 musb->is_active = musb->g.b_hnp_enable;
860856 if (musb->is_active) {
861− musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON;
857+ musb_set_state(musb, OTG_STATE_B_WAIT_ACON);
862858 musb_dbg(musb, "HNP: Setting timer for b_ase0_brst");
863859 mod_timer(&musb->otg_timer, jiffies
864860 + msecs_to_jiffies(
@@ -871,7 +867,7 @@ static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) · 6 unmodified lines
871867 + msecs_to_jiffies(musb->a_wait_bcon));
872868 break;
873869 case OTG_STATE_A_HOST:
874− musb->xceiv->otg->state = OTG_STATE_A_SUSPEND;
870+ musb_set_state(musb, OTG_STATE_A_SUSPEND);
875871 musb->is_active = musb->hcd->self.b_hnp_enable;
876872 break;
877873 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
909905 musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
910906
911907 /* indicate new connection to OTG machine */
912− switch (musb->xceiv->otg->state) {
908+ switch (musb_get_state(musb)) {
913909 case OTG_STATE_B_PERIPHERAL:
914910 if (int_usb & MUSB_INTR_SUSPEND) {
915911 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
921917 case OTG_STATE_B_WAIT_ACON:
922918 musb_dbg(musb, "HNP: CONNECT, now b_host");
923919 b_host:
924− musb->xceiv->otg->state = OTG_STATE_B_HOST;
920+ musb_set_state(musb, OTG_STATE_B_HOST);
925921 if (musb->hcd)
926922 musb->hcd->self.is_b_host = 1;
927923 del_timer(&musb->otg_timer);
@@ -929,7 +925,7 @@ b_host: · 1 unmodified line
929925 default:
930926 if ((devctl & MUSB_DEVCTL_VBUS)
931927 == (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
932− musb->xceiv->otg->state = OTG_STATE_A_HOST;
928+ musb_set_state(musb, OTG_STATE_A_HOST);
933929 if (hcd)
934930 hcd->self.is_b_host = 0;
935931 }
@@ -939,16 +935,16 @@ b_host: · 3 unmodified lines
939935 musb_host_poke_root_hub(musb);
940936
941937 musb_dbg(musb, "CONNECT (%s) devctl %02x",
942− usb_otg_state_string(musb->xceiv->otg->state), devctl);
938+ musb_otg_state_string(musb), devctl);
943939 }
944940
945941 static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)
946942 {
947943 musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x",
948− usb_otg_state_string(musb->xceiv->otg->state),
944+ musb_otg_state_string(musb),
949945 MUSB_MODE(musb), devctl);
950946
951− switch (musb->xceiv->otg->state) {
947+ switch (musb_get_state(musb)) {
952948 case OTG_STATE_A_HOST:
953949 case OTG_STATE_A_SUSPEND:
954950 musb_host_resume_root_hub(musb);
@@ -966,7 +962,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) · 11 unmodified lines
966962 musb_root_disconnect(musb);
967963 if (musb->hcd)
968964 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);
970966 MUSB_DEV_MODE(musb);
971967 musb_g_disconnect(musb);
972968 break;
@@ -981,7 +977,7 @@ static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) · 8 unmodified lines
981977 break;
982978 default:
983979 WARNING("unhandled DISCONNECT transition (%s)\n",
984− usb_otg_state_string(musb->xceiv->otg->state));
980+ musb_otg_state_string(musb));
985981 break;
986982 }
987983 }
@@ -1004,16 +1000,15 @@ static void musb_handle_intr_reset(struct musb *musb) · 16 unmodified lines
10041000 dev_err(musb->controller, "Babble\n");
10051001 musb_recover_from_babble(musb);
10061002 } else {
1007− musb_dbg(musb, "BUS RESET as %s",
1008− usb_otg_state_string(musb->xceiv->otg->state));
1009− switch (musb->xceiv->otg->state) {
1003+ musb_dbg(musb, "BUS RESET as %s", musb_otg_state_string(musb));
1004+ switch (musb_get_state(musb)) {
10101005 case OTG_STATE_A_SUSPEND:
10111006 musb_g_reset(musb);
10121007 fallthrough;
10131008 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
10141009 /* never use invalid T(a_wait_bcon) */
10151010 musb_dbg(musb, "HNP: in %s, %d msec timeout",
1016− usb_otg_state_string(musb->xceiv->otg->state),
1011+ musb_otg_state_string(musb),
10171012 TA_WAIT_BCON(musb));
10181013 mod_timer(&musb->otg_timer, jiffies
10191014 + msecs_to_jiffies(TA_WAIT_BCON(musb)));
@@ -1024,19 +1019,19 @@ static void musb_handle_intr_reset(struct musb *musb) · 4 unmodified lines
10241019 break;
10251020 case OTG_STATE_B_WAIT_ACON:
10261021 musb_dbg(musb, "HNP: RESET (%s), to b_peripheral",
1027− usb_otg_state_string(musb->xceiv->otg->state));
1028− musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
1022+ musb_otg_state_string(musb));
1023+ musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
10291024 musb_g_reset(musb);
10301025 break;
10311026 case OTG_STATE_B_IDLE:
1032− musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
1027+ musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
10331028 fallthrough;
10341029 case OTG_STATE_B_PERIPHERAL:
10351030 musb_g_reset(musb);
10361031 break;
10371032 default:
10381033 musb_dbg(musb, "Unhandled BUS RESET as %s",
1039− usb_otg_state_string(musb->xceiv->otg->state));
1034+ musb_otg_state_string(musb));
10401035 }
10411036 }
10421037 }
@@ -1216,8 +1211,8 @@ void musb_start(struct musb *musb) · 173 unmodified lines
12161211 * (c) peripheral initiates, using SRP
12171212 */
12181213 if (musb->port_mode != MUSB_HOST &&
1219− musb->xceiv->otg->state != OTG_STATE_A_WAIT_BCON &&
1220− (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
1214+ musb_get_state(musb) != OTG_STATE_A_WAIT_BCON &&
1215+ (devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
12211216 musb->is_active = 1;
12221217 } else {
12231218 devctl |= MUSB_DEVCTL_SESSION;
@@ -1863,7 +1858,7 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) · 639 unmodified lines
18631858 int ret;
18641859
18651860 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));
18671862 spin_unlock_irqrestore(&musb->lock, flags);
18681863
18691864 return ret;
@@ -1908,7 +1903,7 @@ vbus_store(struct device *dev, struct device_attribute *attr, · 38 unmodified lines
19081903 spin_lock_irqsave(&musb->lock, flags);
19091904 /* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
19101905 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)
19121907 musb->is_active = 0;
19131908 musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
19141909 spin_unlock_irqrestore(&musb->lock, flags);
@@ -2089,8 +2084,8 @@ static void musb_irq_work(struct work_struct *data) · 174 unmodified lines
20892084
20902085 musb_pm_runtime_check_session(musb);
20912086
2092− if (musb->xceiv->otg->state != musb->xceiv_old_state) {
2093− musb->xceiv_old_state = musb->xceiv->otg->state;
2087+ if (musb_get_state(musb) != musb->xceiv_old_state) {
2088+ musb->xceiv_old_state = musb_get_state(musb);
20942089 sysfs_notify(&musb->controller->kobj, NULL, "mode");
20952090 }
20962091
@@ -2453,7 +2448,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) · 356 unmodified lines
24532448 else
24542449 musb->io.set_toggle = musb_default_set_toggle;
24552450
2456− if (!musb->xceiv->io_ops) {
2451+ if (IS_ENABLED(CONFIG_USB_PHY) && musb->xceiv && !musb->xceiv->io_ops) {
24572452 musb->xceiv->io_dev = musb->controller;
24582453 musb->xceiv->io_priv = musb->mregs;
24592454 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
25322527 }
25332528
25342529 MUSB_DEV_MODE(musb);
2535− musb->xceiv->otg->state = OTG_STATE_B_IDLE;
2530+ musb_set_state(musb, OTG_STATE_B_IDLE);
25362531
25372532 switch (musb->port_mode) {
25382533 case MUSB_HOST:
drivers/usb/musb/musb_core.h+24−0
@@ -339,6 +339,8 @@ struct musb { · 338 unmodified lines
339339 struct usb_phy *xceiv;
340340 struct phy *phy;
341341
342+ enum usb_otg_state otg_state;
343+
342344 int nIrq;
343345 unsigned irq_wake:1;
344346
@@ -592,6 +594,28 @@ static inline void musb_platform_clear_ep_rxintr(struct musb *musb, int epnum) · 247 unmodified lines
592594 musb->ops->clear_ep_rxintr(musb, epnum);
593595 }
594596
597+static 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+
606+static 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+
614+static inline const char *musb_otg_state_string(struct musb *musb)
615+{
616+ return usb_otg_state_string(musb_get_state(musb));
617+}
618+
595619 /*
596620 * gets the "dr_mode" property from DT and converts it into musb_mode
597621 * 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
235235 u8 reg;
236236 int connect;
237237
238− switch (musb->xceiv->otg->state) {
238+ switch (musb_get_state(musb)) {
239239 case OTG_STATE_A_HOST:
240240 case OTG_STATE_A_WAIT_BCON:
241241 pm_runtime_get_sync(musb->controller);
@@ -275,7 +275,7 @@ static ssize_t musb_softconnect_write(struct file *file, · 33 unmodified lines
275275
276276 pm_runtime_get_sync(musb->controller);
277277 if (!strncmp(buf, "0", 1)) {
278− switch (musb->xceiv->otg->state) {
278+ switch (musb_get_state(musb)) {
279279 case OTG_STATE_A_HOST:
280280 musb_root_disconnect(musb);
281281 reg = musb_readb(musb->mregs, MUSB_DEVCTL);
@@ -286,7 +286,7 @@ static ssize_t musb_softconnect_write(struct file *file, · 4 unmodified lines
286286 break;
287287 }
288288 } else if (!strncmp(buf, "1", 1)) {
289− switch (musb->xceiv->otg->state) {
289+ switch (musb_get_state(musb)) {
290290 case OTG_STATE_A_WAIT_BCON:
291291 /*
292292 * 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
6161 #define musb_dma_cppi41(musb) 0
6262 #endif
6363
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−
7064 #ifdef CONFIG_USB_TUSB_OMAP_DMA
7165 #define tusb_dma_omap(musb) (musb->ops->quirks & MUSB_DMA_TUSB_OMAP)
7266 #else
@@ -79,11 +73,10 @@ struct musb_hw_ep; · 6 unmodified lines
7973 #define musb_dma_inventra(musb) 0
8074 #endif
8175
82−#if defined(CONFIG_USB_TI_CPPI_DMA) || defined(CONFIG_USB_TI_CPPI41_DMA)
83−#define is_cppi_enabled(musb) \
84− (musb_dma_cppi(musb) || musb_dma_cppi41(musb))
76+#if defined(CONFIG_USB_TI_CPPI41_DMA)
77+#define is_cppi_enabled(musb) musb_dma_cppi41(musb)
8578 #else
86−#define is_cppi_enabled(musb) 0
79+#define is_cppi_enabled(musb) 0
8780 #endif
8881
8982 /*
drivers/usb/musb/musb_gadget.c+34−27
@@ -1523,7 +1523,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) · 1522 unmodified lines
15231523
15241524 spin_lock_irqsave(&musb->lock, flags);
15251525
1526− switch (musb->xceiv->otg->state) {
1526+ switch (musb_get_state(musb)) {
15271527 case OTG_STATE_B_PERIPHERAL:
15281528 /* NOTE: OTG state machine doesn't include B_SUSPENDED;
15291529 * 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
15521552 break;
15531553 }
15541554
1555− spin_unlock_irqrestore(&musb->lock, flags);
1556− otg_start_srp(musb->xceiv->otg);
1557− spin_lock_irqsave(&musb->lock, flags);
1555+ if (musb->xceiv) {
1556+ spin_unlock_irqrestore(&musb->lock, flags);
1557+ otg_start_srp(musb->xceiv->otg);
1558+ spin_lock_irqsave(&musb->lock, flags);
1559+ }
15581560
15591561 /* Block idling for at least 1s */
15601562 musb_platform_try_idle(musb,
@@ -1564,7 +1566,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) · 3 unmodified lines
15641566 goto done;
15651567 default:
15661568 musb_dbg(musb, "Unhandled wake: %s",
1567− usb_otg_state_string(musb->xceiv->otg->state));
1569+ musb_otg_state_string(musb));
15681570 goto done;
15691571 }
15701572
@@ -1628,8 +1630,6 @@ static int musb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) · 57 unmodified lines
16281630 {
16291631 struct musb *musb = gadget_to_musb(gadget);
16301632
1631− if (!musb->xceiv->set_power)
1632− return -EOPNOTSUPP;
16331633 return usb_phy_set_power(musb->xceiv, mA);
16341634 }
16351635
@@ -1787,7 +1787,7 @@ int musb_gadget_setup(struct musb *musb) · 151 unmodified lines
17871787 musb->g.speed = USB_SPEED_UNKNOWN;
17881788
17891789 MUSB_DEV_MODE(musb);
1790− musb->xceiv->otg->state = OTG_STATE_B_IDLE;
1790+ musb_set_state(musb, OTG_STATE_B_IDLE);
17911791
17921792 /* this "gadget" abstracts/virtualizes the controller */
17931793 musb->g.name = musb_driver_name;
@@ -1834,7 +1834,6 @@ static int musb_gadget_start(struct usb_gadget *g, · 40 unmodified lines
18341834 struct usb_gadget_driver *driver)
18351835 {
18361836 struct musb *musb = gadget_to_musb(g);
1837− struct usb_otg *otg = musb->xceiv->otg;
18381837 unsigned long flags;
18391838 int retval = 0;
18401839
@@ -1851,8 +1850,12 @@ static int musb_gadget_start(struct usb_gadget *g, · 10 unmodified lines
18511850 spin_lock_irqsave(&musb->lock, flags);
18521851 musb->is_active = 1;
18531852
1854− otg_set_peripheral(otg, &musb->g);
1855− musb->xceiv->otg->state = OTG_STATE_B_IDLE;
1853+ if (musb->xceiv)
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);
18561859 spin_unlock_irqrestore(&musb->lock, flags);
18571860
18581861 musb_start(musb);
@@ -1861,7 +1864,7 @@ static int musb_gadget_start(struct usb_gadget *g, · 2 unmodified lines
18611864 * handles power budgeting ... this way also
18621865 * ensures HdrcStart is indirectly called.
18631866 */
1864− if (musb->xceiv->last_event == USB_EVENT_ID)
1867+ if (musb->xceiv && musb->xceiv->last_event == USB_EVENT_ID)
18651868 musb_platform_set_vbus(musb, 1);
18661869
18671870 pm_runtime_mark_last_busy(musb->controller);
@@ -1897,9 +1900,13 @@ static int musb_gadget_stop(struct usb_gadget *g) · 29 unmodified lines
18971900
18981901 (void) musb_gadget_vbus_draw(&musb->g, 0);
18991902
1900− musb->xceiv->otg->state = OTG_STATE_UNDEFINED;
1903+ musb_set_state(musb, OTG_STATE_UNDEFINED);
19011904 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);
19031910
19041911 musb->is_active = 0;
19051912 musb->gadget_driver = NULL;
@@ -1926,7 +1933,7 @@ static int musb_gadget_stop(struct usb_gadget *g) · 20 unmodified lines
19261933 void musb_g_resume(struct musb *musb)
19271934 {
19281935 musb->is_suspended = 0;
1929− switch (musb->xceiv->otg->state) {
1936+ switch (musb_get_state(musb)) {
19301937 case OTG_STATE_B_IDLE:
19311938 break;
19321939 case OTG_STATE_B_WAIT_ACON:
@@ -1940,7 +1947,7 @@ void musb_g_resume(struct musb *musb) · 7 unmodified lines
19401947 break;
19411948 default:
19421949 WARNING("unhandled RESUME transition (%s)\n",
1943− usb_otg_state_string(musb->xceiv->otg->state));
1950+ musb_otg_state_string(musb));
19441951 }
19451952 }
19461953
@@ -1952,10 +1959,10 @@ void musb_g_suspend(struct musb *musb) · 5 unmodified lines
19521959 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
19531960 musb_dbg(musb, "musb_g_suspend: devctl %02x", devctl);
19541961
1955− switch (musb->xceiv->otg->state) {
1962+ switch (musb_get_state(musb)) {
19561963 case OTG_STATE_B_IDLE:
19571964 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);
19591966 break;
19601967 case OTG_STATE_B_PERIPHERAL:
19611968 musb->is_suspended = 1;
@@ -1970,7 +1977,7 @@ void musb_g_suspend(struct musb *musb) · 8 unmodified lines
19701977 * A_PERIPHERAL may need care too
19711978 */
19721979 WARNING("unhandled SUSPEND transition (%s)",
1973− usb_otg_state_string(musb->xceiv->otg->state));
1980+ musb_otg_state_string(musb));
19741981 }
19751982 }
19761983
@@ -2001,22 +2008,22 @@ void musb_g_disconnect(struct musb *musb) · 24 unmodified lines
20012008 spin_lock(&musb->lock);
20022009 }
20032010
2004− switch (musb->xceiv->otg->state) {
2011+ switch (musb_get_state(musb)) {
20052012 default:
20062013 musb_dbg(musb, "Unhandled disconnect %s, setting a_idle",
2007− usb_otg_state_string(musb->xceiv->otg->state));
2008− musb->xceiv->otg->state = OTG_STATE_A_IDLE;
2014+ musb_otg_state_string(musb));
2015+ musb_set_state(musb, OTG_STATE_A_IDLE);
20092016 MUSB_HST_MODE(musb);
20102017 break;
20112018 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);
20132020 MUSB_HST_MODE(musb);
20142021 break;
20152022 case OTG_STATE_B_WAIT_ACON:
20162023 case OTG_STATE_B_HOST:
20172024 case OTG_STATE_B_PERIPHERAL:
20182025 case OTG_STATE_B_IDLE:
2019− musb->xceiv->otg->state = OTG_STATE_B_IDLE;
2026+ musb_set_state(musb, OTG_STATE_B_IDLE);
20202027 break;
20212028 case OTG_STATE_B_SRP_INIT:
20222029 break;
@@ -2080,13 +2087,13 @@ __acquires(musb->lock) · 57 unmodified lines
20802087 * In that case, do not rely on devctl for setting
20812088 * peripheral mode.
20822089 */
2083− musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
2090+ musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
20842091 musb->g.is_a_peripheral = 0;
20852092 } else if (devctl & MUSB_DEVCTL_BDEVICE) {
2086− musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
2093+ musb_set_state(musb, OTG_STATE_B_PERIPHERAL);
20872094 musb->g.is_a_peripheral = 0;
20882095 } else {
2089− musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL;
2096+ musb_set_state(musb, OTG_STATE_A_PERIPHERAL);
20902097 musb->g.is_a_peripheral = 1;
20912098 }
20922099
drivers/usb/musb/musb_host.c+12−6
@@ -2501,7 +2501,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) · 2500 unmodified lines
25012501 if (!is_host_active(musb))
25022502 return 0;
25032503
2504− switch (musb->xceiv->otg->state) {
2504+ switch (musb_get_state(musb)) {
25052505 case OTG_STATE_A_SUSPEND:
25062506 return 0;
25072507 case OTG_STATE_A_WAIT_VRISE:
@@ -2511,7 +2511,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) · 3 unmodified lines
25112511 */
25122512 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
25132513 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);
25152515 break;
25162516 default:
25172517 break;
@@ -2519,7 +2519,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd) · 1 unmodified line
25192519
25202520 if (musb->is_active) {
25212521 WARNING("trying to suspend as %s while active\n",
2522− usb_otg_state_string(musb->xceiv->otg->state));
2522+ musb_otg_state_string(musb));
25232523 return -EBUSY;
25242524 } else
25252525 return 0;
@@ -2720,12 +2720,18 @@ int musb_host_setup(struct musb *musb, int power_budget) · 194 unmodified lines
27202720
27212721 if (musb->port_mode == MUSB_HOST) {
27222722 MUSB_HST_MODE(musb);
2723− musb->xceiv->otg->state = OTG_STATE_A_IDLE;
2723+ musb_set_state(musb, OTG_STATE_A_IDLE);
27242724 }
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+
27262733 /* don't support otg protocols */
27272734 hcd->self.otg_port = 0;
2728− musb->xceiv->otg->host = &hcd->self;
27292735 hcd->power_budget = 2 * (power_budget ? : 250);
27302736 hcd->skip_phy_initialization = 1;
27312737
drivers/usb/musb/musb_virthub.c+16−17
@@ -43,14 +43,13 @@ void musb_host_finish_resume(struct work_struct *work) · 42 unmodified lines
4343 musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16;
4444 usb_hcd_poll_rh_status(musb->hcd);
4545 /* 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);
4747
4848 spin_unlock_irqrestore(&musb->lock, flags);
4949 }
5050
5151 int musb_port_suspend(struct musb *musb, bool do_suspend)
5252 {
53− struct usb_otg *otg = musb->xceiv->otg;
5453 u8 power;
5554 void __iomem *mbase = musb->mregs;
5655
@@ -85,10 +84,11 @@ int musb_port_suspend(struct musb *musb, bool do_suspend) · 28 unmodified lines
8584 musb_dbg(musb, "Root port suspended, power %02x", power);
8685
8786 musb->port1_status |= USB_PORT_STAT_SUSPEND;
88− switch (musb->xceiv->otg->state) {
87+ switch (musb_get_state(musb)) {
8988 case OTG_STATE_A_HOST:
90− musb->xceiv->otg->state = OTG_STATE_A_SUSPEND;
91− musb->is_active = otg->host->b_hnp_enable;
89+ musb_set_state(musb, OTG_STATE_A_SUSPEND);
90+ musb->is_active = musb->xceiv &&
91+ musb->xceiv->otg->host->b_hnp_enable;
9292 if (musb->is_active)
9393 mod_timer(&musb->otg_timer, jiffies
9494 + msecs_to_jiffies(
@@ -96,13 +96,14 @@ int musb_port_suspend(struct musb *musb, bool do_suspend) · 1 unmodified line
9696 musb_platform_try_idle(musb, 0);
9797 break;
9898 case OTG_STATE_B_HOST:
99− musb->xceiv->otg->state = OTG_STATE_B_WAIT_ACON;
100− musb->is_active = otg->host->b_hnp_enable;
99+ musb_set_state(musb, OTG_STATE_B_WAIT_ACON);
100+ musb->is_active = musb->xceiv &&
101+ musb->xceiv->otg->host->b_hnp_enable;
101102 musb_platform_try_idle(musb, 0);
102103 break;
103104 default:
104105 musb_dbg(musb, "bogus rh suspend? %s",
105− usb_otg_state_string(musb->xceiv->otg->state));
106+ musb_otg_state_string(musb));
106107 }
107108 } else if (power & MUSB_POWER_SUSPENDM) {
108109 power &= ~MUSB_POWER_SUSPENDM;
@@ -123,7 +124,7 @@ void musb_port_reset(struct musb *musb, bool do_reset) · 14 unmodified lines
123124 u8 power;
124125 void __iomem *mbase = musb->mregs;
125126
126− if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) {
127+ if (musb_get_state(musb) == OTG_STATE_B_IDLE) {
127128 musb_dbg(musb, "HNP: Returning from HNP; no hub reset from b_idle");
128129 musb->port1_status &= ~USB_PORT_STAT_RESET;
129130 return;
@@ -196,32 +197,30 @@ void musb_port_reset(struct musb *musb, bool do_reset) · 66 unmodified lines
196197
197198 void musb_root_disconnect(struct musb *musb)
198199 {
199− struct usb_otg *otg = musb->xceiv->otg;
200−
201200 musb->port1_status = USB_PORT_STAT_POWER
202201 | (USB_PORT_STAT_C_CONNECTION << 16);
203202
204203 usb_hcd_poll_rh_status(musb->hcd);
205204 musb->is_active = 0;
206205
207− switch (musb->xceiv->otg->state) {
206+ switch (musb_get_state(musb)) {
208207 case OTG_STATE_A_SUSPEND:
209− if (otg->host->b_hnp_enable) {
210− musb->xceiv->otg->state = OTG_STATE_A_PERIPHERAL;
208+ if (musb->xceiv && musb->xceiv->otg->host->b_hnp_enable) {
209+ musb_set_state(musb, OTG_STATE_A_PERIPHERAL);
211210 musb->g.is_a_peripheral = 1;
212211 break;
213212 }
214213 fallthrough;
215214 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);
217216 musb->is_active = 0;
218217 break;
219218 case OTG_STATE_A_WAIT_VFALL:
220− musb->xceiv->otg->state = OTG_STATE_B_IDLE;
219+ musb_set_state(musb, OTG_STATE_B_IDLE);
221220 break;
222221 default:
223222 musb_dbg(musb, "host disconnect (%s)",
224− usb_otg_state_string(musb->xceiv->otg->state));
223+ musb_otg_state_string(musb));
225224 }
226225 }
227226 EXPORT_SYMBOL_GPL(musb_root_disconnect);
drivers/usb/musb/omap2430.c+54−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #include <linux/list.h>
1616 #include <linux/io.h>
1717 #include <linux/of.h>
18+#include <linux/of_irq.h>
1819 #include <linux/platform_device.h>
1920 #include <linux/dma-mapping.h>
2021 #include <linux/pm_runtime.h>
@@ -310,6 +311,7 @@ static int omap2430_probe(struct platform_device *pdev) · 289 unmodified lines
310311 struct device_node *control_node;
311312 struct platform_device *control_pdev;
312313 int ret = -ENOMEM, val;
314+ bool populate_irqs = false;
313315
314316 if (!np)
315317 return -ENODEV;
@@ -328,6 +330,18 @@ static int omap2430_probe(struct platform_device *pdev) · 12 unmodified lines
328330 musb->dev.dma_mask = &omap2430_dmamask;
329331 musb->dev.coherent_dma_mask = omap2430_dmamask;
330332
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+
331345 glue->dev = &pdev->dev;
332346 glue->musb = musb;
333347 glue->status = MUSB_UNKNOWN;
@@ -389,6 +403,46 @@ static int omap2430_probe(struct platform_device *pdev) · 55 unmodified lines
389403 goto err2;
390404 }
391405
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+
392446 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
393447 if (ret) {
394448 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
9393 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"
9494 depends on GPIOLIB || COMPILE_TEST
9595 depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y'
96+ depends on !USB_CONN_GPIO
9697 select USB_PHY
9798 help
9899 Provides simple GPIO VBUS sensing for controllers with an
99100 internal transceiver via the usb_phy interface, and
100101 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.
102106
103107 config OMAP_OTG
104108 tristate "OMAP USB OTG controller driver"
@@ -185,12 +189,4 @@ config USB_ULPI_VIEWPORT · 80 unmodified lines
185189 Provides read/write operations to the ULPI phy register set for
186190 controllers with a viewport register (e.g. Chipidea/ARC controllers).
187191
188−config 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−
196192 endmenu
drivers/usb/phy/Makefile+0−1
@@ -24,4 +24,3 @@ obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o · 23 unmodified lines
2424 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
2525 obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o
2626 obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o
27−obj-$(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
209209 int err = 0;
210210
211211 u32 clk_rate = 0;
212− bool needs_vcc = false, needs_clk = false;
212+ bool needs_clk = false;
213213
214214 if (dev->of_node) {
215215 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
217217 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
218218 clk_rate = 0;
219219
220− needs_vcc = of_property_read_bool(node, "vcc-supply");
221220 needs_clk = of_property_read_bool(node, "clocks");
222221 }
223222 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
257256 }
258257 }
259258
260− nop->vcc = devm_regulator_get(dev, "vcc");
261− if (IS_ERR(nop->vcc)) {
262− dev_dbg(dev, "Error getting vcc regulator: %ld\n",
263− PTR_ERR(nop->vcc));
264− if (needs_vcc)
265− return -EPROBE_DEFER;
266− }
259+ nop->vcc = devm_regulator_get_optional(dev, "vcc");
260+ if (IS_ERR(nop->vcc) && PTR_ERR(nop->vcc) != -ENODEV)
261+ return dev_err_probe(dev, PTR_ERR(nop->vcc),
262+ "could not get vcc regulator\n");
267263
268264 nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus");
269265 if (PTR_ERR(nop->vbus_draw) == -ENODEV)
@@ -290,6 +286,7 @@ EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); · 20 unmodified lines
290286 static int usb_phy_generic_probe(struct platform_device *pdev)
291287 {
292288 struct device *dev = &pdev->dev;
289+ struct device_node *dn = dev->of_node;
293290 struct usb_phy_generic *nop;
294291 int err;
295292
@@ -327,6 +324,9 @@ static int usb_phy_generic_probe(struct platform_device *pdev) · 31 unmodified lines
327324
328325 platform_set_drvdata(pdev, nop);
329326
327+ device_set_wakeup_capable(&pdev->dev,
328+ of_property_read_bool(dn, "wakeup-source"));
329+
330330 return 0;
331331 }
332332
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
366366
367367 MODULE_ALIAS("platform:gpio-vbus");
368368
369+/*
370+ * NOTE: this driver matches against "gpio-usb-b-connector" for
371+ * devices that do NOT support role switch.
372+ */
373+static const struct of_device_id gpio_vbus_of_match[] = {
374+ {
375+ .compatible = "gpio-usb-b-connector",
376+ },
377+ {},
378+};
379+
369380 static struct platform_driver gpio_vbus_driver = {
370381 .driver = {
371382 .name = "gpio-vbus",
372383 #ifdef CONFIG_PM
373384 .pm = &gpio_vbus_dev_pm_ops,
374385 #endif
386+ .of_match_table = gpio_vbus_of_match,
375387 },
376388 .probe = gpio_vbus_probe,
377389 .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
14711471 /*-------------------------------------------------------------------------*/
14721472
14731473 static int
1474−isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
1474+isp1301_probe(struct i2c_client *i2c)
14751475 {
14761476 int status;
14771477 struct isp1301 *isp;
@@ -1616,7 +1616,7 @@ static struct i2c_driver isp1301_driver = { · 138 unmodified lines
16161616 .driver = {
16171617 .name = "isp1301_omap",
16181618 },
1619− .probe = isp1301_probe,
1619+ .probe_new = isp1301_probe,
16201620 .remove = isp1301_remove,
16211621 .id_table = isp1301_id,
16221622 };
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
9292 return 0;
9393 }
9494
95−static int isp1301_probe(struct i2c_client *client,
96− const struct i2c_device_id *i2c_id)
95+static int isp1301_probe(struct i2c_client *client)
9796 {
9897 struct isp1301 *isp;
9998 struct usb_phy *phy;
@@ -133,7 +132,7 @@ static struct i2c_driver isp1301_driver = { · 33 unmodified lines
133132 .name = DRV_NAME,
134133 .of_match_table = isp1301_of_match,
135134 },
136− .probe = isp1301_probe,
135+ .probe_new = isp1301_probe,
137136 .remove = isp1301_remove,
138137 .id_table = isp1301_id,
139138 };
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−
90−enum ingenic_usb_phy_version {
91− ID_JZ4770,
92− ID_JZ4780,
93− ID_X1000,
94− ID_X1830,
95−};
96−
97−struct ingenic_soc_info {
98− enum ingenic_usb_phy_version version;
99−
100− void (*usb_phy_init)(struct usb_phy *phy);
101−};
102−
103−struct 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−
114−static inline struct jz4770_phy *otg_to_jz4770_phy(struct usb_otg *otg)
115−{
116− return container_of(otg, struct jz4770_phy, otg);
117−}
118−
119−static inline struct jz4770_phy *phy_to_jz4770_phy(struct usb_phy *phy)
120−{
121− return container_of(phy, struct jz4770_phy, phy);
122−}
123−
124−static 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−
144−static 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−
157−static 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−
186−static 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−
194−static void ingenic_usb_phy_remove(void *phy)
195−{
196− usb_remove_phy(phy);
197−}
198−
199−static 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−
211−static 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−
224−static 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−
238−static 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−
255−static const struct ingenic_soc_info jz4770_soc_info = {
256− .version = ID_JZ4770,
257−
258− .usb_phy_init = jz4770_usb_phy_init,
259−};
260−
261−static const struct ingenic_soc_info jz4780_soc_info = {
262− .version = ID_JZ4780,
263−
264− .usb_phy_init = jz4780_usb_phy_init,
265−};
266−
267−static const struct ingenic_soc_info x1000_soc_info = {
268− .version = ID_X1000,
269−
270− .usb_phy_init = x1000_usb_phy_init,
271−};
272−
273−static const struct ingenic_soc_info x1830_soc_info = {
274− .version = ID_X1830,
275−
276− .usb_phy_init = x1830_usb_phy_init,
277−};
278−
279−static 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−};
286−MODULE_DEVICE_TABLE(of, ingenic_usb_phy_of_matches);
287−
288−static 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−
340−static 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−};
347−module_platform_driver(ingenic_phy_driver);
348−
349−MODULE_AUTHOR("周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>");
350−MODULE_AUTHOR("漆鹏振 (Qi Pengzhen) <aric.pzqi@ingenic.com>");
351−MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>");
352−MODULE_DESCRIPTION("Ingenic SoCs USB PHY driver");
353−MODULE_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
106106 struct fwnode_handle *parent = fwnode_get_parent(fwnode);
107107 struct device *dev;
108108
109− if (!parent || !fwnode_property_present(parent, "usb-role-switch"))
109+ if (!fwnode_property_present(parent, "usb-role-switch")) {
110+ fwnode_handle_put(parent);
110111 return NULL;
112+ }
111113
112114 dev = class_find_device_by_fwnode(role_class, parent);
115+ fwnode_handle_put(parent);
113116 return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
114117 }
115118
drivers/usb/serial/cp210x.c+17−4
@@ -195,6 +195,8 @@ static const struct usb_device_id id_table[] = { · 194 unmodified lines
195195 { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */
196196 { USB_DEVICE(0x17A8, 0x0001) }, /* Kamstrup Optical Eye/3-wire */
197197 { 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 */
198200 { USB_DEVICE(0x17A8, 0x0101) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Int Ant) */
199201 { USB_DEVICE(0x17A8, 0x0102) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Ext Ant) */
200202 { 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
10471049 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
10481050 u32 baud;
10491051
1052+ if (tty->termios.c_ospeed == 0)
1053+ return;
1054+
10501055 /*
10511056 * This maps the requested rate to the actual rate, a valid rate on
10521057 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
1053− *
1054− * NOTE: B0 is not implemented.
10551058 */
10561059 baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
10571060
@@ -1144,7 +1147,8 @@ static void cp210x_set_flow_control(struct tty_struct *tty, · 86 unmodified lines
11441147 tty->termios.c_iflag &= ~(IXON | IXOFF);
11451148 }
11461149
1147− if (old_termios &&
1150+ if (tty->termios.c_ospeed != 0 &&
1151+ old_termios && old_termios->c_ospeed != 0 &&
11481152 C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) &&
11491153 I_IXON(tty) == (old_termios->c_iflag & IXON) &&
11501154 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
11691173
11701174 mutex_lock(&port_priv->mutex);
11711175
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+
11721184 ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
11731185 sizeof(flow_ctl));
11741186 if (ret)
@@ -1241,7 +1253,8 @@ static void cp210x_set_termios(struct tty_struct *tty, · 66 unmodified lines
12411253 u16 bits;
12421254 int ret;
12431255
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)
12451258 return;
12461259
12471260 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
130130
131131 static int calc_baud_divisor(speed_t baudrate, speed_t clockrate)
132132 {
133− if (!baudrate)
134− return 0;
135−
136133 return DIV_ROUND_CLOSEST(clockrate, baudrate);
137134 }
138135
@@ -498,9 +495,14 @@ static void f81232_set_baudrate(struct tty_struct *tty, · 359 unmodified lines
498495 speed_t baud_list[] = { baudrate, old_baudrate, F81232_DEF_BAUDRATE };
499496
500497 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);
502505 if (idx >= 0) {
503− baudrate = baud_list[i];
504506 tty_encode_baud_rate(tty, baudrate, baudrate);
505507 break;
506508 }
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
536536
537537 static u32 f81534_calc_baud_divisor(u32 baudrate, u32 clockrate)
538538 {
539− if (!baudrate)
540− return 0;
541−
542539 /* Round to nearest divisor */
543540 return DIV_ROUND_CLOSEST(clockrate, baudrate);
544541 }
@@ -568,9 +565,14 @@ static int f81534_set_port_config(struct usb_serial_port *port, · 23 unmodified lines
568565 u32 baud_list[] = {baudrate, old_baudrate, F81534_DEFAULT_BAUD_RATE};
569566
570567 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);
572575 if (idx >= 0) {
573− baudrate = baud_list[i];
574576 tty_encode_baud_rate(tty, baudrate, baudrate);
575577 break;
576578 }
drivers/usb/serial/option.c+3−0
@@ -255,6 +255,7 @@ static void option_instat_callback(struct urb *urb); · 254 unmodified lines
255255 #define QUECTEL_PRODUCT_EP06 0x0306
256256 #define QUECTEL_PRODUCT_EM05G 0x030a
257257 #define QUECTEL_PRODUCT_EM060K 0x030b
258+#define QUECTEL_PRODUCT_EM05G_SG 0x0311
258259 #define QUECTEL_PRODUCT_EM12 0x0512
259260 #define QUECTEL_PRODUCT_RM500Q 0x0800
260261 #define QUECTEL_PRODUCT_RM520N 0x0801
@@ -1160,6 +1161,8 @@ static const struct usb_device_id option_ids[] = { · 899 unmodified lines
11601161 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0, 0) },
11611162 { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G, 0xff),
11621163 .driver_info = RSVD(6) | ZLP },
1164+ { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM05G_SG, 0xff),
1165+ .driver_info = RSVD(6) | ZLP },
11631166 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0x00, 0x40) },
11641167 { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EM060K, 0xff, 0xff, 0x30) },
11651168 { 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
749749
750750 if (tty->termios.c_ospeed)
751751 lc->dwDTERate = cpu_to_le32(tty->termios.c_ospeed);
752− else if (old_termios)
753− lc->dwDTERate = cpu_to_le32(old_termios->c_ospeed);
754752 else
755753 lc->dwDTERate = cpu_to_le32(9600);
756754
drivers/usb/storage/alauda.c+2−0
@@ -438,6 +438,8 @@ static int alauda_init_media(struct us_data *us) · 437 unmodified lines
438438 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift);
439439 MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
440440 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;
441443
442444 if (alauda_reset_media(us) != USB_STOR_XFER_GOOD)
443445 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
14401440 return PTR_ERR_OR_ZERO(ctx->psy);
14411441 }
14421442
1443−static int anx7411_i2c_probe(struct i2c_client *client,
1444− const struct i2c_device_id *id)
1443+static int anx7411_i2c_probe(struct i2c_client *client)
14451444 {
14461445 struct anx7411_data *plat;
14471446 struct device *dev = &client->dev;
@@ -1585,7 +1584,7 @@ static struct i2c_driver anx7411_driver = { · 137 unmodified lines
15851584 .of_match_table = anx_match_table,
15861585 .pm = &anx7411_pm_ops,
15871586 },
1588− .probe = anx7411_i2c_probe,
1587+ .probe_new = anx7411_i2c_probe,
15891588 .remove = anx7411_i2c_remove,
15901589
15911590 .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
134134 if (!adev || !adev->active)
135135 return 0;
136136
137− if (!pdev->ops || !pdev->ops->enter)
137+ if (!pdev->ops || !pdev->ops->exit)
138138 return -EOPNOTSUPP;
139139
140140 /* 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
821821 }
822822 EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version);
823823
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+ */
835+struct usb_power_delivery *
836+typec_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+}
841+EXPORT_SYMBOL_GPL(typec_partner_usb_power_delivery_register);
842+
824843 /**
825844 * typec_register_partner - Register a USB Type-C Partner
826845 * @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
148148 .max_register = 0x0A,
149149 };
150150
151−static int hd3ss3220_probe(struct i2c_client *client,
152− const struct i2c_device_id *id)
151+static int hd3ss3220_probe(struct i2c_client *client)
153152 {
154153 struct typec_capability typec_cap = { };
155154 struct hd3ss3220 *hd3ss3220;
@@ -264,7 +263,7 @@ static struct i2c_driver hd3ss3220_driver = { · 108 unmodified lines
264263 .name = "hd3ss3220",
265264 .of_match_table = of_match_ptr(dev_ids),
266265 },
267− .probe = hd3ss3220_probe,
266+ .probe_new = hd3ss3220_probe,
268267 .remove = hd3ss3220_remove,
269268 };
270269
drivers/usb/typec/retimer.c+2−14
@@ -17,21 +17,9 @@ · 16 unmodified lines
1717 #include "class.h"
1818 #include "retimer.h"
1919
20−static 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−
3220 static int retimer_fwnode_match(struct device *dev, const void *fwnode)
3321 {
34− return device_match_fwnode(dev, fwnode) && dev_name_ends_with(dev, "-retimer");
22+ return is_typec_retimer(dev) && device_match_fwnode(dev, fwnode);
3523 }
3624
3725 static 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
9785 kfree(to_typec_retimer(dev));
9886 }
9987
100−static const struct device_type typec_retimer_dev_type = {
88+const struct device_type typec_retimer_dev_type = {
10189 .name = "typec_retimer",
10290 .release = typec_retimer_release,
10391 };
drivers/usb/typec/retimer.h+4−0
@@ -12,4 +12,8 @@ struct typec_retimer { · 11 unmodified lines
1212
1313 #define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev)
1414
15+const struct device_type typec_retimer_dev_type;
16+
17+#define is_typec_retimer(dev) ((dev)->type == &typec_retimer_dev_type)
18+
1519 #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
16771677 return fwnode;
16781678 }
16791679
1680−static int fusb302_probe(struct i2c_client *client,
1681− const struct i2c_device_id *id)
1680+static int fusb302_probe(struct i2c_client *client)
16821681 {
16831682 struct fusb302_chip *chip;
16841683 struct i2c_adapter *adapter = client->adapter;
@@ -1837,7 +1836,7 @@ static struct i2c_driver fusb302_driver = { · 152 unmodified lines
18371836 .pm = &fusb302_pm_ops,
18381837 .of_match_table = of_match_ptr(fusb302_dt_match),
18391838 },
1840− .probe = fusb302_probe,
1839+ .probe_new = fusb302_probe,
18411840 .remove = fusb302_remove,
18421841 .id_table = fusb302_i2c_device_id,
18431842 };
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
794794 return ERR_PTR(err);
795795
796796 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);
798799 return ERR_CAST(tcpci->port);
800+ }
799801
800802 return tcpci;
801803 }
@@ -804,11 +806,11 @@ EXPORT_SYMBOL_GPL(tcpci_register_port); · 2 unmodified lines
804806 void tcpci_unregister_port(struct tcpci *tcpci)
805807 {
806808 tcpm_unregister_port(tcpci->port);
809+ fwnode_handle_put(tcpci->tcpc.fwnode);
807810 }
808811 EXPORT_SYMBOL_GPL(tcpci_unregister_port);
809812
810−static int tcpci_probe(struct i2c_client *client,
811− const struct i2c_device_id *i2c_id)
813+static int tcpci_probe(struct i2c_client *client)
812814 {
813815 struct tcpci_chip *chip;
814816 int err;
@@ -878,7 +880,7 @@ static struct i2c_driver tcpci_i2c_driver = { · 63 unmodified lines
878880 .name = "tcpci",
879881 .of_match_table = of_match_ptr(tcpci_of_match),
880882 },
881− .probe = tcpci_probe,
883+ .probe_new = tcpci_probe,
882884 .remove = tcpci_remove,
883885 .id_table = tcpci_id,
884886 };
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
438438 return -1;
439439 }
440440
441−static int max_tcpci_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id)
441+static int max_tcpci_probe(struct i2c_client *client)
442442 {
443443 int ret;
444444 struct max_tcpci_chip *chip;
@@ -519,7 +519,7 @@ static struct i2c_driver max_tcpci_i2c_driver = { · 74 unmodified lines
519519 .name = "maxtcpc",
520520 .of_match_table = of_match_ptr(max_tcpci_of_match),
521521 },
522− .probe = max_tcpci_probe,
522+ .probe_new = max_tcpci_probe,
523523 .remove = max_tcpci_remove,
524524 .id_table = max_tcpci_id,
525525 };
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
327327 return ret;
328328 }
329329
330−static int rt1711h_probe(struct i2c_client *client,
331− const struct i2c_device_id *i2c_id)
330+static int rt1711h_probe(struct i2c_client *client)
332331 {
333332 int ret;
334333 struct rt1711h_chip *chip;
@@ -413,7 +412,7 @@ static struct i2c_driver rt1711h_i2c_driver = { · 78 unmodified lines
413412 .name = "rt1711h",
414413 .of_match_table = of_match_ptr(rt1711h_of_match),
415414 },
416− .probe = rt1711h_probe,
415+ .probe_new = rt1711h_probe,
417416 .remove = rt1711h_remove,
418417 .id_table = rt1711h_id,
419418 };
drivers/usb/typec/tipd/core.c+12−8
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/regmap.h>
1515 #include <linux/interrupt.h>
1616 #include <linux/usb/typec.h>
17+#include <linux/usb/typec_altmode.h>
1718 #include <linux/usb/role.h>
1819
1920 #include "tps6598x.h"
@@ -257,6 +258,7 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status) · 237 unmodified lines
257258 typec_set_orientation(tps->port, TYPEC_ORIENTATION_REVERSE);
258259 else
259260 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NORMAL);
261+ typec_set_mode(tps->port, TYPEC_STATE_USB);
260262 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), true);
261263
262264 tps->partner = typec_register_partner(tps->port, &desc);
@@ -280,6 +282,7 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 status) · 17 unmodified lines
280282 typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status));
281283 typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status));
282284 typec_set_orientation(tps->port, TYPEC_ORIENTATION_NONE);
285+ typec_set_mode(tps->port, TYPEC_STATE_SAFE);
283286 tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), false);
284287
285288 power_supply_changed(tps->psy);
@@ -814,20 +817,19 @@ static int tps6598x_probe(struct i2c_client *client) · 528 unmodified lines
814817
815818 ret = devm_tps6598_psy_register(tps);
816819 if (ret)
817− return ret;
820+ goto err_role_put;
818821
819822 tps->port = typec_register_port(&client->dev, &typec_cap);
820823 if (IS_ERR(tps->port)) {
821824 ret = PTR_ERR(tps->port);
822825 goto err_role_put;
823826 }
824− fwnode_handle_put(fwnode);
825827
826828 if (status & TPS_STATUS_PLUG_PRESENT) {
827829 ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
828830 if (ret < 0) {
829831 dev_err(tps->dev, "failed to read power status: %d\n", ret);
830− goto err_role_put;
832+ goto err_unregister_port;
831833 }
832834 ret = tps6598x_connect(tps, status);
833835 if (ret)
@@ -838,16 +840,18 @@ static int tps6598x_probe(struct i2c_client *client) · 4 unmodified lines
838840 irq_handler,
839841 IRQF_SHARED | IRQF_ONESHOT,
840842 dev_name(&client->dev), tps);
841− if (ret) {
842− tps6598x_disconnect(tps, 0);
843− typec_unregister_port(tps->port);
844− goto err_role_put;
845− }
843+ if (ret)
844+ goto err_disconnect;
846845
847846 i2c_set_clientdata(client, tps);
847+ fwnode_handle_put(fwnode);
848848
849849 return 0;
850850
851+err_disconnect:
852+ tps6598x_disconnect(tps, 0);
853+err_unregister_port:
854+ typec_unregister_port(tps->port);
851855 err_role_put:
852856 usb_role_switch_put(tps->role_sw);
853857 err_fwnode_put:
drivers/usb/typec/ucsi/ucsi.c+13−4
@@ -1270,8 +1270,9 @@ err: · 1269 unmodified lines
12701270 return ret;
12711271 }
12721272
1273−int ucsi_resume(struct ucsi *ucsi)
1273+static void ucsi_resume_work(struct work_struct *work)
12741274 {
1275+ struct ucsi *ucsi = container_of(work, struct ucsi, resume_work);
12751276 struct ucsi_connector *con;
12761277 u64 command;
12771278 int ret;
@@ -1279,15 +1280,21 @@ int ucsi_resume(struct ucsi *ucsi) · 1 unmodified line
12791280 /* Restore UCSI notification enable mask after system resume */
12801281 command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;
12811282 ret = ucsi_send_command(ucsi, command, NULL, 0);
1282− if (ret < 0)
1283− return ret;
1283+ if (ret < 0) {
1284+ dev_err(ucsi->dev, "failed to re-enable notifications (%d)\n", ret);
1285+ return;
1286+ }
12841287
12851288 for (con = ucsi->connector; con->port; con++) {
12861289 mutex_lock(&con->lock);
1287− ucsi_check_connection(con);
1290+ ucsi_partner_task(con, ucsi_check_connection, 1, 0);
12881291 mutex_unlock(&con->lock);
12891292 }
1293+}
12901294
1295+int ucsi_resume(struct ucsi *ucsi)
1296+{
1297+ queue_work(system_long_wq, &ucsi->resume_work);
12911298 return 0;
12921299 }
12931300 EXPORT_SYMBOL_GPL(ucsi_resume);
@@ -1347,6 +1354,7 @@ struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops) · 53 unmodified lines
13471354 if (!ucsi)
13481355 return ERR_PTR(-ENOMEM);
13491356
1357+ INIT_WORK(&ucsi->resume_work, ucsi_resume_work);
13501358 INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work);
13511359 mutex_init(&ucsi->ppm_lock);
13521360 ucsi->dev = dev;
@@ -1401,6 +1409,7 @@ void ucsi_unregister(struct ucsi *ucsi) · 48 unmodified lines
14011409
14021410 /* Make sure that we are not in the middle of driver initialization */
14031411 cancel_delayed_work_sync(&ucsi->work);
1412+ cancel_work_sync(&ucsi->resume_work);
14041413
14051414 /* Disable notifications */
14061415 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
287287 struct ucsi_capability cap;
288288 struct ucsi_connector *connector;
289289
290+ struct work_struct resume_work;
290291 struct delayed_work work;
291292 int work_count;
292293 #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
13381338 };
13391339 ATTRIBUTE_GROUPS(ucsi_ccg);
13401340
1341−static int ucsi_ccg_probe(struct i2c_client *client,
1342− const struct i2c_device_id *id)
1341+static int ucsi_ccg_probe(struct i2c_client *client)
13431342 {
13441343 struct device *dev = &client->dev;
13451344 struct ucsi_ccg *uc;
@@ -1482,7 +1481,7 @@ static struct i2c_driver ucsi_ccg_driver = { · 136 unmodified lines
14821481 .dev_groups = ucsi_ccg_groups,
14831482 .acpi_match_table = amd_i2c_ucsi_match,
14841483 },
1485− .probe = ucsi_ccg_probe,
1484+ .probe_new = ucsi_ccg_probe,
14861485 .remove = ucsi_ccg_remove,
14871486 .id_table = ucsi_ccg_device_id,
14881487 };
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
626626 return 0;
627627 }
628628
629−static int ucsi_stm32g0_probe(struct i2c_client *client, const struct i2c_device_id *id)
629+static int ucsi_stm32g0_probe(struct i2c_client *client)
630630 {
631631 struct device *dev = &client->dev;
632632 struct ucsi_stm32g0 *g0;
@@ -763,7 +763,7 @@ static struct i2c_driver ucsi_stm32g0_i2c_driver = { · 130 unmodified lines
763763 .of_match_table = of_match_ptr(ucsi_stm32g0_typec_of_match),
764764 .pm = pm_sleep_ptr(&ucsi_stm32g0_pm_ops),
765765 },
766− .probe = ucsi_stm32g0_probe,
766+ .probe_new = ucsi_stm32g0_probe,
767767 .remove = ucsi_stm32g0_remove,
768768 .id_table = ucsi_stm32g0_typec_i2c_devid
769769 };
drivers/usb/typec/wusb3801.c+1−1
@@ -364,7 +364,7 @@ static int wusb3801_probe(struct i2c_client *client) · 363 unmodified lines
364364 /* Initialize the hardware with the devicetree settings. */
365365 ret = wusb3801_hw_init(wusb3801);
366366 if (ret)
367− return ret;
367+ goto err_put_connector;
368368
369369 wusb3801->cap.revision = USB_TYPEC_REV_1_2;
370370 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
564564 int minor = interface->minor;
565565
566566 dev = usb_get_intfdata(interface);
567− usb_set_intfdata(interface, NULL);
568567
569568 /* give back our minor */
570569 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
3030 status = sdev->ud.status;
3131 spin_unlock_irq(&sdev->ud.lock);
3232
33− return snprintf(buf, PAGE_SIZE, "%d\n", status);
33+ return sysfs_emit(buf, "%d\n", status);
3434 }
3535 static DEVICE_ATTR_RO(usbip_status);
3636
@@ -118,6 +118,8 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a · 81 unmodified lines
118118 } else {
119119 dev_info(dev, "stub down\n");
120120
121+ mutex_lock(&sdev->ud.sysfs_lock);
122+
121123 spin_lock_irq(&sdev->ud.lock);
122124 if (sdev->ud.status != SDEV_ST_USED)
123125 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
149149 urb_p->urb->status = -EINPROGRESS;
150150
151151 /* 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);
153155 switch (urb_p->ep->type) {
154156 case USB_ENDPOINT_XFER_BULK:
155157 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
242242 status = udc->ud.status;
243243 spin_unlock_irq(&udc->ud.lock);
244244
245− return snprintf(out, PAGE_SIZE, "%d\n", status);
245+ return sysfs_emit(out, "%d\n", status);
246246 }
247247 static DEVICE_ATTR_RO(usbip_status);
248248
include/linux/usb.h+12−0
@@ -265,6 +265,18 @@ static inline void *usb_get_intfdata(struct usb_interface *intf) · 264 unmodified lines
265265 return dev_get_drvdata(&intf->dev);
266266 }
267267
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+ */
268280 static inline void usb_set_intfdata(struct usb_interface *intf, void *data)
269281 {
270282 dev_set_drvdata(&intf->dev, data);
include/linux/usb/hcd.h+3−0
@@ -269,6 +269,9 @@ struct hc_driver { · 268 unmodified lines
269269 /* called after entering D0 (etc), before resuming the hub */
270270 int (*pci_resume)(struct usb_hcd *hcd, bool hibernated);
271271
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+
272275 /* cleanly make HCD stop writing memory and doing I/O */
273276 void (*stop) (struct usb_hcd *hcd);
274277
include/linux/usb/typec.h+4−0
@@ -23,6 +23,7 @@ struct fwnode_handle; · 22 unmodified lines
2323 struct device;
2424
2525 struct usb_power_delivery;
26+struct usb_power_delivery_desc;
2627
2728 enum typec_port_type {
2829 TYPEC_PORT_SRC,
@@ -327,6 +328,9 @@ void typec_partner_set_svdm_version(struct typec_partner *partner, · 298 unmodified lines
327328 enum usb_pd_svdm_ver svdm_version);
328329 int typec_get_negotiated_svdm_version(struct typec_port *port);
329330
331+struct usb_power_delivery *typec_partner_usb_power_delivery_register(struct typec_partner *partner,
332+ struct usb_power_delivery_desc *desc);
333+
330334 int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd);
331335 int typec_partner_set_usb_power_delivery(struct typec_partner *partner,
332336 struct usb_power_delivery *pd);
include/uapi/linux/usb/g_uvc.h+3−0
@@ -21,6 +21,9 @@ · 20 unmodified lines
2121 #define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
2222 #define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
2323
24+#define UVC_STRING_CONTROL_IDX 0
25+#define UVC_STRING_STREAMING_IDX 1
26+
2427 struct uvc_request_data {
2528 __s32 length;
2629 __u8 data[60];
include/uapi/linux/usb/video.h+2−2
@@ -466,7 +466,7 @@ struct uvc_format_uncompressed { · 465 unmodified lines
466466 __u8 bDefaultFrameIndex;
467467 __u8 bAspectRatioX;
468468 __u8 bAspectRatioY;
469− __u8 bmInterfaceFlags;
469+ __u8 bmInterlaceFlags;
470470 __u8 bCopyProtect;
471471 } __attribute__((__packed__));
472472
@@ -522,7 +522,7 @@ struct uvc_format_mjpeg { · 49 unmodified lines
522522 __u8 bDefaultFrameIndex;
523523 __u8 bAspectRatioX;
524524 __u8 bAspectRatioY;
525− __u8 bmInterfaceFlags;
525+ __u8 bmInterlaceFlags;
526526 __u8 bCopyProtect;
527527 } __attribute__((__packed__));
528528
tools/usb/ffs-aio-example/simple/device_app/aio_simple.c+31−13
@@ -25,7 +25,9 @@ · 24 unmodified lines
2525 * For more information, please refer to <http://unlicense.org/>
2626 */
2727
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 */
2931
3032 #include <endian.h>
3133 #include <errno.h>
@@ -49,6 +51,22 @@ · 17 unmodified lines
4951
5052 #define BUF_LEN 8192
5153
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+
5270 /******************** Descriptors and Strings *******************************/
5371
5472 static const struct {
@@ -62,12 +80,12 @@ static const struct { · 7 unmodified lines
6280 } __attribute__ ((__packed__)) fs_descs, hs_descs;
6381 } __attribute__ ((__packed__)) descriptors = {
6482 .header = {
65− .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
66− .flags = htole32(FUNCTIONFS_HAS_FS_DESC |
83+ .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
84+ .flags = cpu_to_le32(FUNCTIONFS_HAS_FS_DESC |
6785 FUNCTIONFS_HAS_HS_DESC),
68− .length = htole32(sizeof(descriptors)),
86+ .length = cpu_to_le32(sizeof(descriptors)),
6987 },
70− .fs_count = htole32(3),
88+ .fs_count = cpu_to_le32(3),
7189 .fs_descs = {
7290 .intf = {
7391 .bLength = sizeof(descriptors.fs_descs.intf),
@@ -89,7 +107,7 @@ static const struct { · 15 unmodified lines
89107 .bmAttributes = USB_ENDPOINT_XFER_BULK,
90108 },
91109 },
92− .hs_count = htole32(3),
110+ .hs_count = cpu_to_le32(3),
93111 .hs_descs = {
94112 .intf = {
95113 .bLength = sizeof(descriptors.hs_descs.intf),
@@ -103,14 +121,14 @@ static const struct { · 7 unmodified lines
103121 .bDescriptorType = USB_DT_ENDPOINT,
104122 .bEndpointAddress = 1 | USB_DIR_IN,
105123 .bmAttributes = USB_ENDPOINT_XFER_BULK,
106− .wMaxPacketSize = htole16(512),
124+ .wMaxPacketSize = cpu_to_le16(512),
107125 },
108126 .bulk_source = {
109127 .bLength = sizeof(descriptors.hs_descs.bulk_source),
110128 .bDescriptorType = USB_DT_ENDPOINT,
111129 .bEndpointAddress = 2 | USB_DIR_OUT,
112130 .bmAttributes = USB_ENDPOINT_XFER_BULK,
113− .wMaxPacketSize = htole16(512),
131+ .wMaxPacketSize = cpu_to_le16(512),
114132 },
115133 },
116134 };
@@ -125,13 +143,13 @@ static const struct { · 8 unmodified lines
125143 } __attribute__ ((__packed__)) lang0;
126144 } __attribute__ ((__packed__)) strings = {
127145 .header = {
128− .magic = htole32(FUNCTIONFS_STRINGS_MAGIC),
129− .length = htole32(sizeof(strings)),
130− .str_count = htole32(1),
131− .lang_count = htole32(1),
146+ .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC),
147+ .length = cpu_to_le32(sizeof(strings)),
148+ .str_count = cpu_to_le32(1),
149+ .lang_count = cpu_to_le32(1),
132150 },
133151 .lang0 = {
134− htole16(0x0409), /* en-us */
152+ cpu_to_le16(0x0409), /* en-us */
135153 STR_INTERFACE,
136154 },
137155 };

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