aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-09-05 13:26:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-05 13:26:01 -0400
commit1a3b85ea36d38d5732fdd86b321b10bcaeb53512 (patch)
treef3a7abeb6acaa47019e3d53b7ae75f7ae4361803
parent04759194dc447ff0b9ef35bc641ce3bb076c2930 (diff)
parent46f5489f781ae3e4d23a4e8e29e0ea3626739d2d (diff)
Merge tag 'usb-4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB/PHY driver updates from Greg KH: "Here is the large USB and PHY driver update for 4.14-rc1. Not all that exciting, a few new PHY drivers, the usual mess of gadget driver updates and fixes, and of course, xhci updates to try to tame that beast. A number of usb-serial updates and other small fixes all over the USB driver tree are in here as well. Full details are in the shortlog. All of these have been in linux-next for a while with no reported issues" * tag 'usb-4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (171 commits) usbip: vhci-hcd: make vhci_hc_driver const usb: phy: Avoid unchecked dereference warning usb: imx21-hcd: make imx21_hc_driver const usb: host: make ehci_fsl_overrides const and __initconst dt-bindings: mt8173-mtu3: add generic compatible and rename file dt-bindings: mt8173-xhci: add generic compatible and rename file usb: xhci-mtk: add generic compatible string usbip: auto retry for concurrent attach USB: serial: option: simplify 3 D-Link device entries USB: serial: option: add support for D-Link DWM-157 C1 usb: core: usbport: fix "BUG: key not in .data" when lockdep is enabled usb: chipidea: usb2: check memory allocation failure usb: Add device quirk for Logitech HD Pro Webcam C920-C usb: misc: lvstest: add entry to place port in compliance mode usb: xhci: Support enabling of compliance mode for xhci 1.1 usb:xhci:Fix regression when ATI chipsets detected usb: quirks: add delay init quirk for Corsair Strafe RGB keyboard usb: gadget: make snd_pcm_hardware const usb: common: use of_property_read_bool() USB: core: constify vm_operations_struct ...
-rw-r--r--Documentation/ABI/testing/configfs-usb-gadget-rndis3
-rw-r--r--Documentation/ABI/testing/sysfs-bus-usb-lvstest13
-rw-r--r--Documentation/devicetree/bindings/mfd/wm831x.txt1
-rw-r--r--Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt (renamed from Documentation/devicetree/bindings/phy/phy-mt65xx-usb.txt)17
-rw-r--r--Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt11
-rw-r--r--Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt11
-rw-r--r--Documentation/devicetree/bindings/phy/ralink-usb-phy.txt23
-rw-r--r--Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt10
-rw-r--r--Documentation/devicetree/bindings/usb/brcm,bdc.txt29
-rw-r--r--Documentation/devicetree/bindings/usb/keystone-usb.txt17
-rw-r--r--Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt (renamed from Documentation/devicetree/bindings/usb/mt8173-xhci.txt)14
-rw-r--r--Documentation/devicetree/bindings/usb/mediatek,mtu3.txt (renamed from Documentation/devicetree/bindings/usb/mt8173-mtu3.txt)8
-rw-r--r--Documentation/devicetree/bindings/usb/renesas_usb3.txt16
-rw-r--r--MAINTAINERS10
-rw-r--r--drivers/phy/Kconfig10
-rw-r--r--drivers/phy/Makefile3
-rw-r--r--drivers/phy/allwinner/phy-sun4i-usb.c112
-rw-r--r--drivers/phy/broadcom/phy-brcm-sata.c2
-rw-r--r--drivers/phy/mediatek/Kconfig14
-rw-r--r--drivers/phy/mediatek/Makefile5
-rw-r--r--drivers/phy/mediatek/phy-mtk-tphy.c (renamed from drivers/phy/phy-mt65xx-usb3.c)557
-rw-r--r--drivers/phy/motorola/phy-cpcap-usb.c2
-rw-r--r--drivers/phy/qualcomm/phy-qcom-qmp.c162
-rw-r--r--drivers/phy/ralink/Kconfig11
-rw-r--r--drivers/phy/ralink/Makefile1
-rw-r--r--drivers/phy/ralink/phy-ralink-usb.c249
-rw-r--r--drivers/phy/rockchip/phy-rockchip-inno-usb2.c215
-rw-r--r--drivers/phy/rockchip/phy-rockchip-typec.c3
-rw-r--r--drivers/phy/samsung/phy-exynos-dp-video.c5
-rw-r--r--drivers/phy/samsung/phy-exynos5-usbdrd.c7
-rw-r--r--drivers/phy/samsung/phy-samsung-usb2.c9
-rw-r--r--drivers/phy/ti/phy-ti-pipe3.c10
-rw-r--r--drivers/phy/ti/phy-twl4030-usb.c2
-rw-r--r--drivers/power/supply/wm831x_power.c72
-rw-r--r--drivers/usb/atm/cxacru.c2
-rw-r--r--drivers/usb/atm/speedtch.c6
-rw-r--r--drivers/usb/atm/ueagle-atm.c4
-rw-r--r--drivers/usb/atm/usbatm.c6
-rw-r--r--drivers/usb/atm/xusbatm.c1
-rw-r--r--drivers/usb/c67x00/c67x00-hcd.c2
-rw-r--r--drivers/usb/chipidea/Makefile1
-rw-r--r--drivers/usb/chipidea/ci_hdrc_msm.c2
-rw-r--r--drivers/usb/chipidea/ci_hdrc_pci.c1
-rw-r--r--drivers/usb/chipidea/ci_hdrc_tegra.c155
-rw-r--r--drivers/usb/chipidea/ci_hdrc_usb2.c2
-rw-r--r--drivers/usb/chipidea/core.c6
-rw-r--r--drivers/usb/chipidea/otg_fsm.c2
-rw-r--r--drivers/usb/chipidea/udc.c8
-rw-r--r--drivers/usb/class/cdc-wdm.c4
-rw-r--r--drivers/usb/class/usbtmc.c4
-rw-r--r--drivers/usb/common/common.c15
-rw-r--r--drivers/usb/common/ulpi.c2
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/core/hcd.c2
-rw-r--r--drivers/usb/core/hub.c19
-rw-r--r--drivers/usb/core/ledtrig-usbport.c5
-rw-r--r--drivers/usb/core/quirks.c6
-rw-r--r--drivers/usb/core/sysfs.c2
-rw-r--r--drivers/usb/dwc2/gadget.c2
-rw-r--r--drivers/usb/dwc2/hcd.c6
-rw-r--r--drivers/usb/dwc3/dwc3-keystone.c22
-rw-r--r--drivers/usb/dwc3/dwc3-of-simple.c4
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c4
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c2
-rw-r--r--drivers/usb/gadget/Kconfig2
-rw-r--r--drivers/usb/gadget/function/f_fs.c7
-rw-r--r--drivers/usb/gadget/function/f_hid.c17
-rw-r--r--drivers/usb/gadget/function/f_midi.c68
-rw-r--r--drivers/usb/gadget/function/f_ncm.c2
-rw-r--r--drivers/usb/gadget/function/f_rndis.c20
-rw-r--r--drivers/usb/gadget/function/u_audio.c4
-rw-r--r--drivers/usb/gadget/function/u_ether.c2
-rw-r--r--drivers/usb/gadget/function/u_ether.h1
-rw-r--r--drivers/usb/gadget/function/u_ether_configfs.h35
-rw-r--r--drivers/usb/gadget/function/u_rndis.h4
-rw-r--r--drivers/usb/gadget/function/u_serial.c2
-rw-r--r--drivers/usb/gadget/legacy/webcam.c1
-rw-r--r--drivers/usb/gadget/udc/bdc/Kconfig1
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc.h24
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_core.c148
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_dbg.c16
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_ep.c4
-rw-r--r--drivers/usb/gadget/udc/bdc/bdc_udc.c7
-rw-r--r--drivers/usb/gadget/udc/core.c20
-rw-r--r--drivers/usb/gadget/udc/dummy_hcd.c2
-rw-r--r--drivers/usb/gadget/udc/fsl_qe_udc.c2
-rw-r--r--drivers/usb/gadget/udc/mv_udc_core.c2
-rw-r--r--drivers/usb/gadget/udc/renesas_usb3.c117
-rw-r--r--drivers/usb/gadget/udc/s3c2410_udc.c4
-rw-r--r--drivers/usb/host/ehci-fsl.c2
-rw-r--r--drivers/usb/host/ehci-omap.c4
-rw-r--r--drivers/usb/host/fsl-mph-dr-of.c4
-rw-r--r--drivers/usb/host/hwa-hc.c4
-rw-r--r--drivers/usb/host/imx21-hcd.c8
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/isp1362-hcd.c2
-rw-r--r--drivers/usb/host/max3421-hcd.c2
-rw-r--r--drivers/usb/host/pci-quirks.c35
-rw-r--r--drivers/usb/host/r8a66597-hcd.c2
-rw-r--r--drivers/usb/host/sl811-hcd.c2
-rw-r--r--drivers/usb/host/u132-hcd.c2
-rw-r--r--drivers/usb/host/whci/hcd.c2
-rw-r--r--drivers/usb/host/xhci-hub.c127
-rw-r--r--drivers/usb/host/xhci-mtk.c1
-rw-r--r--drivers/usb/host/xhci-plat.c10
-rw-r--r--drivers/usb/host/xhci-rcar.c40
-rw-r--r--drivers/usb/host/xhci-ring.c22
-rw-r--r--drivers/usb/host/xhci-trace.h23
-rw-r--r--drivers/usb/host/xhci.h90
-rw-r--r--drivers/usb/image/microtek.c4
-rw-r--r--drivers/usb/isp1760/isp1760-hcd.c6
-rw-r--r--drivers/usb/misc/adutux.c2
-rw-r--r--drivers/usb/misc/chaoskey.c2
-rw-r--r--drivers/usb/misc/cytherm.c1
-rw-r--r--drivers/usb/misc/ftdi-elan.c33
-rw-r--r--drivers/usb/misc/idmouse.c2
-rw-r--r--drivers/usb/misc/iowarrior.c4
-rw-r--r--drivers/usb/misc/ldusb.c1
-rw-r--r--drivers/usb/misc/legousbtower.c2
-rw-r--r--drivers/usb/misc/lvstest.c41
-rw-r--r--drivers/usb/misc/rio500.c4
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c13
-rw-r--r--drivers/usb/misc/trancevibrator.c2
-rw-r--r--drivers/usb/misc/usb251xb.c1
-rw-r--r--drivers/usb/misc/usbsevseg.c2
-rw-r--r--drivers/usb/misc/uss720.c7
-rw-r--r--drivers/usb/mtu3/mtu3.h2
-rw-r--r--drivers/usb/mtu3/mtu3_dr.c58
-rw-r--r--drivers/usb/mtu3/mtu3_gadget.c4
-rw-r--r--drivers/usb/mtu3/mtu3_gadget_ep0.c23
-rw-r--r--drivers/usb/mtu3/mtu3_host.c4
-rw-r--r--drivers/usb/mtu3/mtu3_hw_regs.h4
-rw-r--r--drivers/usb/mtu3/mtu3_plat.c1
-rw-r--r--drivers/usb/musb/musb_core.c22
-rw-r--r--drivers/usb/musb/musb_core.h24
-rw-r--r--drivers/usb/musb/musb_dsps.c13
-rw-r--r--drivers/usb/musb/musb_gadget.c6
-rw-r--r--drivers/usb/musb/musb_host.c8
-rw-r--r--drivers/usb/phy/phy-mv-usb.c4
-rw-r--r--drivers/usb/phy/phy-qcom-8x16-usb.c9
-rw-r--r--drivers/usb/phy/phy-tahvo.c2
-rw-r--r--drivers/usb/phy/phy.c276
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c4
-rw-r--r--drivers/usb/renesas_usbhs/mod_host.c2
-rw-r--r--drivers/usb/renesas_usbhs/pipe.c2
-rw-r--r--drivers/usb/serial/option.c10
-rw-r--r--drivers/usb/storage/realtek_cr.c1
-rw-r--r--drivers/usb/usbip/stub_main.c2
-rw-r--r--drivers/usb/usbip/usbip_common.c2
-rw-r--r--drivers/usb/usbip/usbip_common.h2
-rw-r--r--drivers/usb/usbip/vhci_hcd.c4
-rw-r--r--drivers/usb/usbip/vhci_sysfs.c6
-rw-r--r--drivers/usb/wusbcore/cbaf.c2
-rw-r--r--drivers/usb/wusbcore/dev-sysfs.c2
-rw-r--r--drivers/usb/wusbcore/wusbhc.c2
-rw-r--r--drivers/uwb/lc-rc.c2
-rw-r--r--include/linux/hid.h6
-rw-r--r--include/linux/usb/chipidea.h1
-rw-r--r--include/linux/usb/gadget.h2
-rw-r--r--include/linux/usb/phy.h54
-rw-r--r--include/uapi/linux/usb/charger.h31
-rw-r--r--tools/usb/usbip/src/usbip_attach.c35
162 files changed, 2925 insertions, 667 deletions
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-rndis b/Documentation/ABI/testing/configfs-usb-gadget-rndis
index e32879b84b4d..137399095d74 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-rndis
+++ b/Documentation/ABI/testing/configfs-usb-gadget-rndis
@@ -12,3 +12,6 @@ Description:
12 Ethernet over USB link 12 Ethernet over USB link
13 dev_addr - MAC address of device's end of this 13 dev_addr - MAC address of device's end of this
14 Ethernet over USB link 14 Ethernet over USB link
15 class - USB interface class, default is 02 (hex)
16 subclass - USB interface subclass, default is 06 (hex)
17 protocol - USB interface protocol, default is 00 (hex)
diff --git a/Documentation/ABI/testing/sysfs-bus-usb-lvstest b/Documentation/ABI/testing/sysfs-bus-usb-lvstest
index 5151290cf8e7..ee0046dc4192 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb-lvstest
+++ b/Documentation/ABI/testing/sysfs-bus-usb-lvstest
@@ -45,3 +45,16 @@ Contact: Pratyush Anand <pratyush.anand@gmail.com>
45Description: 45Description:
46 Write to this node to issue "U3 exit" for Link Layer 46 Write to this node to issue "U3 exit" for Link Layer
47 Validation device. It is needed for TD.7.36. 47 Validation device. It is needed for TD.7.36.
48
49What: /sys/bus/usb/devices/.../enable_compliance
50Date: July 2017
51Description:
52 Write to this node to set the port to compliance mode to test
53 with Link Layer Validation device. It is needed for TD.7.34.
54
55What: /sys/bus/usb/devices/.../warm_reset
56Date: July 2017
57Description:
58 Write to this node to issue "Warm Reset" for Link Layer Validation
59 device. It may be needed to properly reset an xHCI 1.1 host port if
60 compliance mode needed to be explicitly enabled.
diff --git a/Documentation/devicetree/bindings/mfd/wm831x.txt b/Documentation/devicetree/bindings/mfd/wm831x.txt
index 9f8b7430673c..505709403d3f 100644
--- a/Documentation/devicetree/bindings/mfd/wm831x.txt
+++ b/Documentation/devicetree/bindings/mfd/wm831x.txt
@@ -31,6 +31,7 @@ Required properties:
31 ../interrupt-controller/interrupts.txt 31 ../interrupt-controller/interrupts.txt
32 32
33Optional sub-nodes: 33Optional sub-nodes:
34 - phys : Contains a phandle to the USB PHY.
34 - regulators : Contains sub-nodes for each of the regulators supplied by 35 - regulators : Contains sub-nodes for each of the regulators supplied by
35 the device. The regulators are bound using their names listed below: 36 the device. The regulators are bound using their names listed below:
36 37
diff --git a/Documentation/devicetree/bindings/phy/phy-mt65xx-usb.txt b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
index 0acc5a99fb79..faf18084a33a 100644
--- a/Documentation/devicetree/bindings/phy/phy-mt65xx-usb.txt
+++ b/Documentation/devicetree/bindings/phy/phy-mtk-tphy.txt
@@ -1,13 +1,18 @@
1mt65xx USB3.0 PHY binding 1MediaTek T-PHY binding
2-------------------------- 2--------------------------
3 3
4This binding describes a usb3.0 phy for mt65xx platforms of Medaitek SoC. 4T-phy controller supports physical layer functionality for a number of
5controllers on MediaTek SoCs, such as, USB2.0, USB3.0, PCIe, and SATA.
5 6
6Required properties (controller (parent) node): 7Required properties (controller (parent) node):
7 - compatible : should be one of 8 - compatible : should be one of
8 "mediatek,mt2701-u3phy" 9 "mediatek,generic-tphy-v1"
9 "mediatek,mt2712-u3phy" 10 "mediatek,generic-tphy-v2"
10 "mediatek,mt8173-u3phy" 11 "mediatek,mt2701-u3phy" (deprecated)
12 "mediatek,mt2712-u3phy" (deprecated)
13 "mediatek,mt8173-u3phy";
14 make use of "mediatek,generic-tphy-v1" on mt2701 instead and
15 "mediatek,generic-tphy-v2" on mt2712 instead.
11 - clocks : (deprecated, use port's clocks instead) a list of phandle + 16 - clocks : (deprecated, use port's clocks instead) a list of phandle +
12 clock-specifier pairs, one for each entry in clock-names 17 clock-specifier pairs, one for each entry in clock-names
13 - clock-names : (deprecated, use port's one instead) must contain 18 - clock-names : (deprecated, use port's one instead) must contain
@@ -35,6 +40,8 @@ Required properties (port (child) node):
35 cell after port phandle is phy type from: 40 cell after port phandle is phy type from:
36 - PHY_TYPE_USB2 41 - PHY_TYPE_USB2
37 - PHY_TYPE_USB3 42 - PHY_TYPE_USB3
43 - PHY_TYPE_PCIE
44 - PHY_TYPE_SATA
38 45
39Example: 46Example:
40 47
diff --git a/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt b/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt
index 84d59b0db8df..a67ef2a3874f 100644
--- a/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/phy-rockchip-inno-usb2.txt
@@ -6,6 +6,7 @@ Required properties (phy (parent) node):
6 * "rockchip,rk3328-usb2phy" 6 * "rockchip,rk3328-usb2phy"
7 * "rockchip,rk3366-usb2phy" 7 * "rockchip,rk3366-usb2phy"
8 * "rockchip,rk3399-usb2phy" 8 * "rockchip,rk3399-usb2phy"
9 * "rockchip,rv1108-usb2phy"
9 - reg : the address offset of grf for usb-phy configuration. 10 - reg : the address offset of grf for usb-phy configuration.
10 - #clock-cells : should be 0. 11 - #clock-cells : should be 0.
11 - clock-output-names : specify the 480m output clock name. 12 - clock-output-names : specify the 480m output clock name.
@@ -18,6 +19,10 @@ Optional properties:
18 usb-phy output 480m and xin24m. 19 usb-phy output 480m and xin24m.
19 Refer to clk/clock-bindings.txt for generic clock 20 Refer to clk/clock-bindings.txt for generic clock
20 consumer properties. 21 consumer properties.
22 - rockchip,usbgrf : phandle to the syscon managing the "usb general
23 register files". When set driver will request its
24 phandle as one companion-grf for some special SoCs
25 (e.g RV1108).
21 26
22Required nodes : a sub-node is required for each port the phy provides. 27Required nodes : a sub-node is required for each port the phy provides.
23 The sub-node name is used to identify host or otg port, 28 The sub-node name is used to identify host or otg port,
@@ -28,10 +33,14 @@ Required nodes : a sub-node is required for each port the phy provides.
28Required properties (port (child) node): 33Required properties (port (child) node):
29 - #phy-cells : must be 0. See ./phy-bindings.txt for details. 34 - #phy-cells : must be 0. See ./phy-bindings.txt for details.
30 - interrupts : specify an interrupt for each entry in interrupt-names. 35 - interrupts : specify an interrupt for each entry in interrupt-names.
31 - interrupt-names : a list which shall be the following entries: 36 - interrupt-names : a list which should be one of the following cases:
37 Regular case:
32 * "otg-id" : for the otg id interrupt. 38 * "otg-id" : for the otg id interrupt.
33 * "otg-bvalid" : for the otg vbus interrupt. 39 * "otg-bvalid" : for the otg vbus interrupt.
34 * "linestate" : for the host/otg linestate interrupt. 40 * "linestate" : for the host/otg linestate interrupt.
41 Some SoCs use one interrupt with the above muxed together, so for these
42 * "otg-mux" : otg-port interrupt, which mux otg-id/otg-bvalid/linestate
43 to one.
35 44
36Optional properties: 45Optional properties:
37 - phy-supply : phandle to a regulator that provides power to VBUS. 46 - phy-supply : phandle to a regulator that provides power to VBUS.
diff --git a/Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt b/Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt
index e11c563a65ec..b6a9f2b92bab 100644
--- a/Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt
+++ b/Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt
@@ -6,6 +6,7 @@ controllers on Qualcomm chipsets, such as, PCIe, UFS, and USB.
6 6
7Required properties: 7Required properties:
8 - compatible: compatible list, contains: 8 - compatible: compatible list, contains:
9 "qcom,ipq8074-qmp-pcie-phy" for PCIe phy on IPQ8074
9 "qcom,msm8996-qmp-pcie-phy" for 14nm PCIe phy on msm8996, 10 "qcom,msm8996-qmp-pcie-phy" for 14nm PCIe phy on msm8996,
10 "qcom,msm8996-qmp-usb3-phy" for 14nm USB3 phy on msm8996. 11 "qcom,msm8996-qmp-usb3-phy" for 14nm USB3 phy on msm8996.
11 12
@@ -38,6 +39,8 @@ Required properties:
38 "phy", "common", "cfg". 39 "phy", "common", "cfg".
39 For "qcom,msm8996-qmp-usb3-phy" must contain 40 For "qcom,msm8996-qmp-usb3-phy" must contain
40 "phy", "common". 41 "phy", "common".
42 For "qcom,ipq8074-qmp-pcie-phy" must contain:
43 "phy", "common".
41 44
42 - vdda-phy-supply: Phandle to a regulator supply to PHY core block. 45 - vdda-phy-supply: Phandle to a regulator supply to PHY core block.
43 - vdda-pll-supply: Phandle to 1.8V regulator supply to PHY refclk pll block. 46 - vdda-pll-supply: Phandle to 1.8V regulator supply to PHY refclk pll block.
@@ -60,6 +63,13 @@ Required properties for child node:
60 one for each entry in clock-names. 63 one for each entry in clock-names.
61 - clock-names: Must contain following for pcie and usb qmp phys: 64 - clock-names: Must contain following for pcie and usb qmp phys:
62 "pipe<lane-number>" for pipe clock specific to each lane. 65 "pipe<lane-number>" for pipe clock specific to each lane.
66 - clock-output-names: Name of the PHY clock that will be the parent for
67 the above pipe clock.
68
69 For "qcom,ipq8074-qmp-pcie-phy":
70 - "pcie20_phy0_pipe_clk" Pipe Clock parent
71 (or)
72 "pcie20_phy1_pipe_clk"
63 73
64 - resets: a list of phandles and reset controller specifier pairs, 74 - resets: a list of phandles and reset controller specifier pairs,
65 one for each entry in reset-names. 75 one for each entry in reset-names.
@@ -96,6 +106,7 @@ Example:
96 106
97 clocks = <&gcc GCC_PCIE_0_PIPE_CLK>; 107 clocks = <&gcc GCC_PCIE_0_PIPE_CLK>;
98 clock-names = "pipe0"; 108 clock-names = "pipe0";
109 clock-output-names = "pcie_0_pipe_clk_src";
99 resets = <&gcc GCC_PCIE_0_PHY_BCR>; 110 resets = <&gcc GCC_PCIE_0_PHY_BCR>;
100 reset-names = "lane0"; 111 reset-names = "lane0";
101 }; 112 };
diff --git a/Documentation/devicetree/bindings/phy/ralink-usb-phy.txt b/Documentation/devicetree/bindings/phy/ralink-usb-phy.txt
new file mode 100644
index 000000000000..9d2868a437ab
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/ralink-usb-phy.txt
@@ -0,0 +1,23 @@
1Mediatek/Ralink USB PHY
2
3Required properties:
4 - compatible: "ralink,rt3352-usbphy"
5 "mediatek,mt7620-usbphy"
6 "mediatek,mt7628-usbphy"
7 - reg: required for "mediatek,mt7628-usbphy", unused otherwise
8 - #phy-cells: should be 0
9 - ralink,sysctl: a phandle to a ralink syscon register region
10 - resets: the two reset controllers for host and device
11 - reset-names: the names of the 2 reset controllers
12
13Example:
14
15usbphy: phy {
16 compatible = "mediatek,mt7628-usbphy";
17 reg = <0x10120000 0x1000>;
18 #phy-cells = <0>;
19
20 ralink,sysctl = <&sysc>;
21 resets = <&rstctrl 22 &rstctrl 25>;
22 reset-names = "host", "device";
23};
diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 005bc22938ff..cbc7847dbf6c 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -9,6 +9,7 @@ Required properties:
9 * allwinner,sun7i-a20-usb-phy 9 * allwinner,sun7i-a20-usb-phy
10 * allwinner,sun8i-a23-usb-phy 10 * allwinner,sun8i-a23-usb-phy
11 * allwinner,sun8i-a33-usb-phy 11 * allwinner,sun8i-a33-usb-phy
12 * allwinner,sun8i-a83t-usb-phy
12 * allwinner,sun8i-h3-usb-phy 13 * allwinner,sun8i-h3-usb-phy
13 * allwinner,sun8i-v3s-usb-phy 14 * allwinner,sun8i-v3s-usb-phy
14 * allwinner,sun50i-a64-usb-phy 15 * allwinner,sun50i-a64-usb-phy
@@ -17,18 +18,22 @@ Required properties:
17 * "phy_ctrl" 18 * "phy_ctrl"
18 * "pmu0" for H3, V3s and A64 19 * "pmu0" for H3, V3s and A64
19 * "pmu1" 20 * "pmu1"
20 * "pmu2" for sun4i, sun6i or sun7i 21 * "pmu2" for sun4i, sun6i, sun7i, sun8i-a83t or sun8i-h3
22 * "pmu3" for sun8i-h3
21- #phy-cells : from the generic phy bindings, must be 1 23- #phy-cells : from the generic phy bindings, must be 1
22- clocks : phandle + clock specifier for the phy clocks 24- clocks : phandle + clock specifier for the phy clocks
23- clock-names : 25- clock-names :
24 * "usb_phy" for sun4i, sun5i or sun7i 26 * "usb_phy" for sun4i, sun5i or sun7i
25 * "usb0_phy", "usb1_phy" and "usb2_phy" for sun6i 27 * "usb0_phy", "usb1_phy" and "usb2_phy" for sun6i
26 * "usb0_phy", "usb1_phy" for sun8i 28 * "usb0_phy", "usb1_phy" for sun8i
29 * "usb0_phy", "usb1_phy", "usb2_phy" and "usb2_hsic_12M" for sun8i-a83t
30 * "usb0_phy", "usb1_phy", "usb2_phy" and "usb3_phy" for sun8i-h3
27- resets : a list of phandle + reset specifier pairs 31- resets : a list of phandle + reset specifier pairs
28- reset-names : 32- reset-names :
29 * "usb0_reset" 33 * "usb0_reset"
30 * "usb1_reset" 34 * "usb1_reset"
31 * "usb2_reset" for sun4i, sun6i or sun7i 35 * "usb2_reset" for sun4i, sun6i, sun7i, sun8i-a83t or sun8i-h3
36 * "usb3_reset" for sun8i-h3
32 37
33Optional properties: 38Optional properties:
34- usb0_id_det-gpios : gpio phandle for reading the otg id pin value 39- usb0_id_det-gpios : gpio phandle for reading the otg id pin value
@@ -37,6 +42,7 @@ Optional properties:
37- usb0_vbus-supply : regulator phandle for controller usb0 vbus 42- usb0_vbus-supply : regulator phandle for controller usb0 vbus
38- usb1_vbus-supply : regulator phandle for controller usb1 vbus 43- usb1_vbus-supply : regulator phandle for controller usb1 vbus
39- usb2_vbus-supply : regulator phandle for controller usb2 vbus 44- usb2_vbus-supply : regulator phandle for controller usb2 vbus
45- usb3_vbus-supply : regulator phandle for controller usb3 vbus
40 46
41Example: 47Example:
42 usbphy: phy@0x01c13400 { 48 usbphy: phy@0x01c13400 {
diff --git a/Documentation/devicetree/bindings/usb/brcm,bdc.txt b/Documentation/devicetree/bindings/usb/brcm,bdc.txt
new file mode 100644
index 000000000000..63e63af3bf59
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/brcm,bdc.txt
@@ -0,0 +1,29 @@
1Broadcom USB Device Controller (BDC)
2====================================
3
4Required properties:
5
6- compatible: must be one of:
7 "brcm,bdc-v0.16"
8 "brcm,bdc"
9- reg: the base register address and length
10- interrupts: the interrupt line for this controller
11
12Optional properties:
13
14On Broadcom STB platforms, these properties are required:
15
16- phys: phandle to one or two USB PHY blocks
17 NOTE: Some SoC's have a single phy and some have
18 USB 2.0 and USB 3.0 phys
19- clocks: phandle to the functional clock of this block
20
21Example:
22
23 bdc@f0b02000 {
24 compatible = "brcm,bdc-v0.16";
25 reg = <0xf0b02000 0xfc4>;
26 interrupts = <0x0 0x60 0x0>;
27 phys = <&usbphy_0 0x0>;
28 clocks = <&sw_usbd>;
29 };
diff --git a/Documentation/devicetree/bindings/usb/keystone-usb.txt b/Documentation/devicetree/bindings/usb/keystone-usb.txt
index 60527d335b58..2d1bef16f149 100644
--- a/Documentation/devicetree/bindings/usb/keystone-usb.txt
+++ b/Documentation/devicetree/bindings/usb/keystone-usb.txt
@@ -12,8 +12,21 @@ Required properties:
12 MPU. 12 MPU.
13 - ranges: allows valid 1:1 translation between child's address space and 13 - ranges: allows valid 1:1 translation between child's address space and
14 parent's address space. 14 parent's address space.
15 - clocks: Clock IDs array as required by the controller. 15
16 - clock-names: names of clocks correseponding to IDs in the clock property. 16SoC-specific Required Properties:
17The following are mandatory properties for Keystone 2 66AK2HK, 66AK2L and 66AK2E
18SoCs only:
19
20- clocks: Clock ID for USB functional clock.
21- clock-names: Must be "usb".
22
23
24The following are mandatory properties for Keystone 2 66AK2G SoCs only:
25
26- power-domains: Should contain a phandle to a PM domain provider node
27 and an args specifier containing the USB device id
28 value. This property is as per the binding,
29 Documentation/devicetree/bindings/soc/ti/sci-pm-domain.txt
17 30
18Sub-nodes: 31Sub-nodes:
19The dwc3 core should be added as subnode to Keystone DWC3 glue. 32The dwc3 core should be added as subnode to Keystone DWC3 glue.
diff --git a/Documentation/devicetree/bindings/usb/mt8173-xhci.txt b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 0acfc8acbea1..5611a2e4ddf0 100644
--- a/Documentation/devicetree/bindings/usb/mt8173-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -11,7 +11,11 @@ into two parts.
11------------------------------------------------------------------------ 11------------------------------------------------------------------------
12 12
13Required properties: 13Required properties:
14 - compatible : should contain "mediatek,mt8173-xhci" 14 - compatible : should be "mediatek,<soc-model>-xhci", "mediatek,mtk-xhci",
15 soc-model is the name of SoC, such as mt8173, mt2712 etc, when using
16 "mediatek,mtk-xhci" compatible string, you need SoC specific ones in
17 addition, one of:
18 - "mediatek,mt8173-xhci"
15 - reg : specifies physical base address and size of the registers 19 - reg : specifies physical base address and size of the registers
16 - reg-names: should be "mac" for xHCI MAC and "ippc" for IP port control 20 - reg-names: should be "mac" for xHCI MAC and "ippc" for IP port control
17 - interrupts : interrupt used by the controller 21 - interrupts : interrupt used by the controller
@@ -68,10 +72,14 @@ usb30: usb@11270000 {
68 72
69In the case, xhci is added as subnode to mtu3. An example and the DT binding 73In the case, xhci is added as subnode to mtu3. An example and the DT binding
70details of mtu3 can be found in: 74details of mtu3 can be found in:
71Documentation/devicetree/bindings/usb/mt8173-mtu3.txt 75Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
72 76
73Required properties: 77Required properties:
74 - compatible : should contain "mediatek,mt8173-xhci" 78 - compatible : should be "mediatek,<soc-model>-xhci", "mediatek,mtk-xhci",
79 soc-model is the name of SoC, such as mt8173, mt2712 etc, when using
80 "mediatek,mtk-xhci" compatible string, you need SoC specific ones in
81 addition, one of:
82 - "mediatek,mt8173-xhci"
75 - reg : specifies physical base address and size of the registers 83 - reg : specifies physical base address and size of the registers
76 - reg-names: should be "mac" for xHCI MAC 84 - reg-names: should be "mac" for xHCI MAC
77 - interrupts : interrupt used by the host controller 85 - interrupts : interrupt used by the host controller
diff --git a/Documentation/devicetree/bindings/usb/mt8173-mtu3.txt b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index 1d7c3bc677f7..838ae48eafc1 100644
--- a/Documentation/devicetree/bindings/usb/mt8173-mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -1,7 +1,11 @@
1The device node for Mediatek USB3.0 DRD controller 1The device node for Mediatek USB3.0 DRD controller
2 2
3Required properties: 3Required properties:
4 - compatible : should be "mediatek,mt8173-mtu3" 4 - compatible : should be "mediatek,<soc-model>-mtu3", "mediatek,mtu3",
5 soc-model is the name of SoC, such as mt8173, mt2712 etc,
6 when using "mediatek,mtu3" compatible string, you need SoC specific
7 ones in addition, one of:
8 - "mediatek,mt8173-mtu3"
5 - reg : specifies physical base address and size of the registers 9 - reg : specifies physical base address and size of the registers
6 - reg-names: should be "mac" for device IP and "ippc" for IP port control 10 - reg-names: should be "mac" for device IP and "ippc" for IP port control
7 - interrupts : interrupt used by the device IP 11 - interrupts : interrupt used by the device IP
@@ -44,7 +48,7 @@ Optional properties:
44Sub-nodes: 48Sub-nodes:
45The xhci should be added as subnode to mtu3 as shown in the following example 49The xhci should be added as subnode to mtu3 as shown in the following example
46if host mode is enabled. The DT binding details of xhci can be found in: 50if host mode is enabled. The DT binding details of xhci can be found in:
47Documentation/devicetree/bindings/usb/mt8173-xhci.txt 51Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
48 52
49Example: 53Example:
50ssusb: usb@11271000 { 54ssusb: usb@11271000 {
diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
index 8d52766f07b9..e28025883b79 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
@@ -3,20 +3,30 @@ Renesas Electronics USB3.0 Peripheral driver
3Required properties: 3Required properties:
4 - compatible: Must contain one of the following: 4 - compatible: Must contain one of the following:
5 - "renesas,r8a7795-usb3-peri" 5 - "renesas,r8a7795-usb3-peri"
6 - "renesas,r8a7796-usb3-peri"
7 - "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 compatible
8 device
9
10 When compatible with the generic version, nodes must list the
11 SoC-specific version corresponding to the platform first
12 followed by the generic version.
13
6 - reg: Base address and length of the register for the USB3.0 Peripheral 14 - reg: Base address and length of the register for the USB3.0 Peripheral
7 - interrupts: Interrupt specifier for the USB3.0 Peripheral 15 - interrupts: Interrupt specifier for the USB3.0 Peripheral
8 - clocks: clock phandle and specifier pair 16 - clocks: clock phandle and specifier pair
9 17
10Example: 18Example of R-Car H3 ES1.x:
11 usb3_peri0: usb@ee020000 { 19 usb3_peri0: usb@ee020000 {
12 compatible = "renesas,r8a7795-usb3-peri"; 20 compatible = "renesas,r8a7795-usb3-peri",
21 "renesas,rcar-gen3-usb3-peri";
13 reg = <0 0xee020000 0 0x400>; 22 reg = <0 0xee020000 0 0x400>;
14 interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>; 23 interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
15 clocks = <&cpg CPG_MOD 328>; 24 clocks = <&cpg CPG_MOD 328>;
16 }; 25 };
17 26
18 usb3_peri1: usb@ee060000 { 27 usb3_peri1: usb@ee060000 {
19 compatible = "renesas,r8a7795-usb3-peri"; 28 compatible = "renesas,r8a7795-usb3-peri",
29 "renesas,rcar-gen3-usb3-peri";
20 reg = <0 0xee060000 0 0x400>; 30 reg = <0 0xee060000 0 0x400>;
21 interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>; 31 interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
22 clocks = <&cpg CPG_MOD 327>; 32 clocks = <&cpg CPG_MOD 327>;
diff --git a/MAINTAINERS b/MAINTAINERS
index 8ef4694af6e8..8a28bad13e13 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1570,7 +1570,7 @@ M: Chunfeng Yun <chunfeng.yun@mediatek.com>
1570L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1570L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1571L: linux-mediatek@lists.infradead.org (moderated for non-subscribers) 1571L: linux-mediatek@lists.infradead.org (moderated for non-subscribers)
1572S: Maintained 1572S: Maintained
1573F: drivers/phy/phy-mt65xx-usb3.c 1573F: drivers/phy/mediatek/phy-mtk-tphy.c
1574 1574
1575ARM/MICREL KS8695 ARCHITECTURE 1575ARM/MICREL KS8695 ARCHITECTURE
1576M: Greg Ungerer <gerg@uclinux.org> 1576M: Greg Ungerer <gerg@uclinux.org>
@@ -8475,6 +8475,14 @@ M: Sean Wang <sean.wang@mediatek.com>
8475S: Maintained 8475S: Maintained
8476F: drivers/char/hw_random/mtk-rng.c 8476F: drivers/char/hw_random/mtk-rng.c
8477 8477
8478MEDIATEK USB3 DRD IP DRIVER
8479M: Chunfeng Yun <chunfeng.yun@mediatek.com>
8480L: linux-usb@vger.kernel.org (moderated for non-subscribers)
8481L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
8482L: linux-mediatek@lists.infradead.org (moderated for non-subscribers)
8483S: Maintained
8484F: drivers/usb/mtu3/
8485
8478MEGACHIPS STDPXXXX-GE-B850V3-FW LVDS/DP++ BRIDGES 8486MEGACHIPS STDPXXXX-GE-B850V3-FW LVDS/DP++ BRIDGES
8479M: Peter Senna Tschudin <peter.senna@collabora.com> 8487M: Peter Senna Tschudin <peter.senna@collabora.com>
8480M: Martin Donnelly <martin.donnelly@ge.com> 8488M: Martin Donnelly <martin.donnelly@ge.com>
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index c1807d4a0079..441912c10b82 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -26,14 +26,6 @@ config PHY_LPC18XX_USB_OTG
26 This driver is need for USB0 support on LPC18xx/43xx and takes 26 This driver is need for USB0 support on LPC18xx/43xx and takes
27 care of enabling and clock setup. 27 care of enabling and clock setup.
28 28
29config PHY_MT65XX_USB3
30 tristate "Mediatek USB3.0 PHY Driver"
31 depends on ARCH_MEDIATEK && OF
32 select GENERIC_PHY
33 help
34 Say 'Y' here to add support for Mediatek USB3.0 PHY driver,
35 it supports multiple usb2.0 and usb3.0 ports.
36
37config PHY_PISTACHIO_USB 29config PHY_PISTACHIO_USB
38 tristate "IMG Pistachio USB2.0 PHY driver" 30 tristate "IMG Pistachio USB2.0 PHY driver"
39 depends on MACH_PISTACHIO 31 depends on MACH_PISTACHIO
@@ -53,8 +45,10 @@ source "drivers/phy/amlogic/Kconfig"
53source "drivers/phy/broadcom/Kconfig" 45source "drivers/phy/broadcom/Kconfig"
54source "drivers/phy/hisilicon/Kconfig" 46source "drivers/phy/hisilicon/Kconfig"
55source "drivers/phy/marvell/Kconfig" 47source "drivers/phy/marvell/Kconfig"
48source "drivers/phy/mediatek/Kconfig"
56source "drivers/phy/motorola/Kconfig" 49source "drivers/phy/motorola/Kconfig"
57source "drivers/phy/qualcomm/Kconfig" 50source "drivers/phy/qualcomm/Kconfig"
51source "drivers/phy/ralink/Kconfig"
58source "drivers/phy/renesas/Kconfig" 52source "drivers/phy/renesas/Kconfig"
59source "drivers/phy/rockchip/Kconfig" 53source "drivers/phy/rockchip/Kconfig"
60source "drivers/phy/samsung/Kconfig" 54source "drivers/phy/samsung/Kconfig"
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index f252201e0ec9..06f3c500030d 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -4,12 +4,12 @@
4 4
5obj-$(CONFIG_GENERIC_PHY) += phy-core.o 5obj-$(CONFIG_GENERIC_PHY) += phy-core.o
6obj-$(CONFIG_PHY_LPC18XX_USB_OTG) += phy-lpc18xx-usb-otg.o 6obj-$(CONFIG_PHY_LPC18XX_USB_OTG) += phy-lpc18xx-usb-otg.o
7obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o
8obj-$(CONFIG_PHY_XGENE) += phy-xgene.o 7obj-$(CONFIG_PHY_XGENE) += phy-xgene.o
9obj-$(CONFIG_PHY_PISTACHIO_USB) += phy-pistachio-usb.o 8obj-$(CONFIG_PHY_PISTACHIO_USB) += phy-pistachio-usb.o
10 9
11obj-$(CONFIG_ARCH_SUNXI) += allwinner/ 10obj-$(CONFIG_ARCH_SUNXI) += allwinner/
12obj-$(CONFIG_ARCH_MESON) += amlogic/ 11obj-$(CONFIG_ARCH_MESON) += amlogic/
12obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
13obj-$(CONFIG_ARCH_RENESAS) += renesas/ 13obj-$(CONFIG_ARCH_RENESAS) += renesas/
14obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ 14obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
15obj-$(CONFIG_ARCH_TEGRA) += tegra/ 15obj-$(CONFIG_ARCH_TEGRA) += tegra/
@@ -18,6 +18,7 @@ obj-y += broadcom/ \
18 marvell/ \ 18 marvell/ \
19 motorola/ \ 19 motorola/ \
20 qualcomm/ \ 20 qualcomm/ \
21 ralink/ \
21 samsung/ \ 22 samsung/ \
22 st/ \ 23 st/ \
23 ti/ 24 ti/
diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index bbf06cfe5898..1161e11fb3cf 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -87,6 +87,16 @@
87#define PHY_DISCON_TH_SEL 0x2a 87#define PHY_DISCON_TH_SEL 0x2a
88#define PHY_SQUELCH_DETECT 0x3c 88#define PHY_SQUELCH_DETECT 0x3c
89 89
90/* A83T specific control bits for PHY0 */
91#define PHY_CTL_VBUSVLDEXT BIT(5)
92#define PHY_CTL_SIDDQ BIT(3)
93
94/* A83T specific control bits for PHY2 HSIC */
95#define SUNXI_EHCI_HS_FORCE BIT(20)
96#define SUNXI_HSIC_CONNECT_DET BIT(17)
97#define SUNXI_HSIC_CONNECT_INT BIT(16)
98#define SUNXI_HSIC BIT(1)
99
90#define MAX_PHYS 4 100#define MAX_PHYS 4
91 101
92/* 102/*
@@ -100,6 +110,7 @@ enum sun4i_usb_phy_type {
100 sun4i_a10_phy, 110 sun4i_a10_phy,
101 sun6i_a31_phy, 111 sun6i_a31_phy,
102 sun8i_a33_phy, 112 sun8i_a33_phy,
113 sun8i_a83t_phy,
103 sun8i_h3_phy, 114 sun8i_h3_phy,
104 sun8i_v3s_phy, 115 sun8i_v3s_phy,
105 sun50i_a64_phy, 116 sun50i_a64_phy,
@@ -107,6 +118,7 @@ enum sun4i_usb_phy_type {
107 118
108struct sun4i_usb_phy_cfg { 119struct sun4i_usb_phy_cfg {
109 int num_phys; 120 int num_phys;
121 int hsic_index;
110 enum sun4i_usb_phy_type type; 122 enum sun4i_usb_phy_type type;
111 u32 disc_thresh; 123 u32 disc_thresh;
112 u8 phyctl_offset; 124 u8 phyctl_offset;
@@ -126,6 +138,7 @@ struct sun4i_usb_phy_data {
126 struct regulator *vbus; 138 struct regulator *vbus;
127 struct reset_control *reset; 139 struct reset_control *reset;
128 struct clk *clk; 140 struct clk *clk;
141 struct clk *clk2;
129 bool regulator_on; 142 bool regulator_on;
130 int index; 143 int index;
131 } phys[MAX_PHYS]; 144 } phys[MAX_PHYS];
@@ -232,6 +245,7 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
232 245
233static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable) 246static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
234{ 247{
248 struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
235 u32 bits, reg_value; 249 u32 bits, reg_value;
236 250
237 if (!phy->pmu) 251 if (!phy->pmu)
@@ -240,6 +254,11 @@ static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
240 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN | 254 bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN |
241 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN; 255 SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN;
242 256
257 /* A83T USB2 is HSIC */
258 if (phy_data->cfg->type == sun8i_a83t_phy && phy->index == 2)
259 bits |= SUNXI_EHCI_HS_FORCE | SUNXI_HSIC_CONNECT_INT |
260 SUNXI_HSIC;
261
243 reg_value = readl(phy->pmu); 262 reg_value = readl(phy->pmu);
244 263
245 if (enable) 264 if (enable)
@@ -261,27 +280,43 @@ static int sun4i_usb_phy_init(struct phy *_phy)
261 if (ret) 280 if (ret)
262 return ret; 281 return ret;
263 282
264 ret = reset_control_deassert(phy->reset); 283 ret = clk_prepare_enable(phy->clk2);
265 if (ret) { 284 if (ret) {
266 clk_disable_unprepare(phy->clk); 285 clk_disable_unprepare(phy->clk);
267 return ret; 286 return ret;
268 } 287 }
269 288
270 if (phy->pmu && data->cfg->enable_pmu_unk1) { 289 ret = reset_control_deassert(phy->reset);
271 val = readl(phy->pmu + REG_PMU_UNK1); 290 if (ret) {
272 writel(val & ~2, phy->pmu + REG_PMU_UNK1); 291 clk_disable_unprepare(phy->clk2);
292 clk_disable_unprepare(phy->clk);
293 return ret;
273 } 294 }
274 295
275 /* Enable USB 45 Ohm resistor calibration */ 296 if (data->cfg->type == sun8i_a83t_phy) {
276 if (phy->index == 0) 297 if (phy->index == 0) {
277 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1); 298 val = readl(data->base + data->cfg->phyctl_offset);
299 val |= PHY_CTL_VBUSVLDEXT;
300 val &= ~PHY_CTL_SIDDQ;
301 writel(val, data->base + data->cfg->phyctl_offset);
302 }
303 } else {
304 if (phy->pmu && data->cfg->enable_pmu_unk1) {
305 val = readl(phy->pmu + REG_PMU_UNK1);
306 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
307 }
278 308
279 /* Adjust PHY's magnitude and rate */ 309 /* Enable USB 45 Ohm resistor calibration */
280 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5); 310 if (phy->index == 0)
311 sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
281 312
282 /* Disconnect threshold adjustment */ 313 /* Adjust PHY's magnitude and rate */
283 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, 314 sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
284 data->cfg->disc_thresh, 2); 315
316 /* Disconnect threshold adjustment */
317 sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
318 data->cfg->disc_thresh, 2);
319 }
285 320
286 sun4i_usb_phy_passby(phy, 1); 321 sun4i_usb_phy_passby(phy, 1);
287 322
@@ -307,6 +342,13 @@ static int sun4i_usb_phy_exit(struct phy *_phy)
307 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); 342 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
308 343
309 if (phy->index == 0) { 344 if (phy->index == 0) {
345 if (data->cfg->type == sun8i_a83t_phy) {
346 void __iomem *phyctl = data->base +
347 data->cfg->phyctl_offset;
348
349 writel(readl(phyctl) | PHY_CTL_SIDDQ, phyctl);
350 }
351
310 /* Disable pull-ups */ 352 /* Disable pull-ups */
311 sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0); 353 sun4i_usb_phy0_update_iscr(_phy, ISCR_DPDM_PULLUP_EN, 0);
312 sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0); 354 sun4i_usb_phy0_update_iscr(_phy, ISCR_ID_PULLUP_EN, 0);
@@ -315,6 +357,7 @@ static int sun4i_usb_phy_exit(struct phy *_phy)
315 357
316 sun4i_usb_phy_passby(phy, 0); 358 sun4i_usb_phy_passby(phy, 0);
317 reset_control_assert(phy->reset); 359 reset_control_assert(phy->reset);
360 clk_disable_unprepare(phy->clk2);
318 clk_disable_unprepare(phy->clk); 361 clk_disable_unprepare(phy->clk);
319 362
320 return 0; 363 return 0;
@@ -653,19 +696,25 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
653 696
654 data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det", 697 data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det",
655 GPIOD_IN); 698 GPIOD_IN);
656 if (IS_ERR(data->id_det_gpio)) 699 if (IS_ERR(data->id_det_gpio)) {
700 dev_err(dev, "Couldn't request ID GPIO\n");
657 return PTR_ERR(data->id_det_gpio); 701 return PTR_ERR(data->id_det_gpio);
702 }
658 703
659 data->vbus_det_gpio = devm_gpiod_get_optional(dev, "usb0_vbus_det", 704 data->vbus_det_gpio = devm_gpiod_get_optional(dev, "usb0_vbus_det",
660 GPIOD_IN); 705 GPIOD_IN);
661 if (IS_ERR(data->vbus_det_gpio)) 706 if (IS_ERR(data->vbus_det_gpio)) {
707 dev_err(dev, "Couldn't request VBUS detect GPIO\n");
662 return PTR_ERR(data->vbus_det_gpio); 708 return PTR_ERR(data->vbus_det_gpio);
709 }
663 710
664 if (of_find_property(np, "usb0_vbus_power-supply", NULL)) { 711 if (of_find_property(np, "usb0_vbus_power-supply", NULL)) {
665 data->vbus_power_supply = devm_power_supply_get_by_phandle(dev, 712 data->vbus_power_supply = devm_power_supply_get_by_phandle(dev,
666 "usb0_vbus_power-supply"); 713 "usb0_vbus_power-supply");
667 if (IS_ERR(data->vbus_power_supply)) 714 if (IS_ERR(data->vbus_power_supply)) {
715 dev_err(dev, "Couldn't get the VBUS power supply\n");
668 return PTR_ERR(data->vbus_power_supply); 716 return PTR_ERR(data->vbus_power_supply);
717 }
669 718
670 if (!data->vbus_power_supply) 719 if (!data->vbus_power_supply)
671 return -EPROBE_DEFER; 720 return -EPROBE_DEFER;
@@ -674,8 +723,10 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
674 data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0); 723 data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
675 724
676 data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable); 725 data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
677 if (IS_ERR(data->extcon)) 726 if (IS_ERR(data->extcon)) {
727 dev_err(dev, "Couldn't allocate our extcon device\n");
678 return PTR_ERR(data->extcon); 728 return PTR_ERR(data->extcon);
729 }
679 730
680 ret = devm_extcon_dev_register(dev, data->extcon); 731 ret = devm_extcon_dev_register(dev, data->extcon);
681 if (ret) { 732 if (ret) {
@@ -690,8 +741,13 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
690 snprintf(name, sizeof(name), "usb%d_vbus", i); 741 snprintf(name, sizeof(name), "usb%d_vbus", i);
691 phy->vbus = devm_regulator_get_optional(dev, name); 742 phy->vbus = devm_regulator_get_optional(dev, name);
692 if (IS_ERR(phy->vbus)) { 743 if (IS_ERR(phy->vbus)) {
693 if (PTR_ERR(phy->vbus) == -EPROBE_DEFER) 744 if (PTR_ERR(phy->vbus) == -EPROBE_DEFER) {
745 dev_err(dev,
746 "Couldn't get regulator %s... Deferring probe\n",
747 name);
694 return -EPROBE_DEFER; 748 return -EPROBE_DEFER;
749 }
750
695 phy->vbus = NULL; 751 phy->vbus = NULL;
696 } 752 }
697 753
@@ -706,6 +762,17 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
706 return PTR_ERR(phy->clk); 762 return PTR_ERR(phy->clk);
707 } 763 }
708 764
765 /* The first PHY is always tied to OTG, and never HSIC */
766 if (data->cfg->hsic_index && i == data->cfg->hsic_index) {
767 /* HSIC needs secondary clock */
768 snprintf(name, sizeof(name), "usb%d_hsic_12M", i);
769 phy->clk2 = devm_clk_get(dev, name);
770 if (IS_ERR(phy->clk2)) {
771 dev_err(dev, "failed to get clock %s\n", name);
772 return PTR_ERR(phy->clk2);
773 }
774 }
775
709 snprintf(name, sizeof(name), "usb%d_reset", i); 776 snprintf(name, sizeof(name), "usb%d_reset", i);
710 phy->reset = devm_reset_control_get(dev, name); 777 phy->reset = devm_reset_control_get(dev, name);
711 if (IS_ERR(phy->reset)) { 778 if (IS_ERR(phy->reset)) {
@@ -775,6 +842,8 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
775 return PTR_ERR(phy_provider); 842 return PTR_ERR(phy_provider);
776 } 843 }
777 844
845 dev_dbg(dev, "successfully loaded\n");
846
778 return 0; 847 return 0;
779} 848}
780 849
@@ -832,6 +901,14 @@ static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = {
832 .enable_pmu_unk1 = false, 901 .enable_pmu_unk1 = false,
833}; 902};
834 903
904static const struct sun4i_usb_phy_cfg sun8i_a83t_cfg = {
905 .num_phys = 3,
906 .hsic_index = 2,
907 .type = sun8i_a83t_phy,
908 .phyctl_offset = REG_PHYCTL_A33,
909 .dedicated_clocks = true,
910};
911
835static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = { 912static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
836 .num_phys = 4, 913 .num_phys = 4,
837 .type = sun8i_h3_phy, 914 .type = sun8i_h3_phy,
@@ -868,6 +945,7 @@ static const struct of_device_id sun4i_usb_phy_of_match[] = {
868 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg }, 945 { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg },
869 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg }, 946 { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg },
870 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg }, 947 { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
948 { .compatible = "allwinner,sun8i-a83t-usb-phy", .data = &sun8i_a83t_cfg },
871 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg }, 949 { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg },
872 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = &sun8i_v3s_cfg }, 950 { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = &sun8i_v3s_cfg },
873 { .compatible = "allwinner,sun50i-a64-usb-phy", 951 { .compatible = "allwinner,sun50i-a64-usb-phy",
diff --git a/drivers/phy/broadcom/phy-brcm-sata.c b/drivers/phy/broadcom/phy-brcm-sata.c
index e6544c8b1ace..9d7f74fe3d7c 100644
--- a/drivers/phy/broadcom/phy-brcm-sata.c
+++ b/drivers/phy/broadcom/phy-brcm-sata.c
@@ -335,7 +335,7 @@ static int brcm_nsp_sata_init(struct brcm_sata_port *port)
335 335
336 /* Wait for pll_seq_done bit */ 336 /* Wait for pll_seq_done bit */
337 try = 50; 337 try = 50;
338 while (try--) { 338 while (--try) {
339 val = brcm_sata_phy_rd(base, BLOCK0_REG_BANK, 339 val = brcm_sata_phy_rd(base, BLOCK0_REG_BANK,
340 BLOCK0_XGXSSTATUS); 340 BLOCK0_XGXSSTATUS);
341 if (val & BLOCK0_XGXSSTATUS_PLL_LOCK) 341 if (val & BLOCK0_XGXSSTATUS_PLL_LOCK)
diff --git a/drivers/phy/mediatek/Kconfig b/drivers/phy/mediatek/Kconfig
new file mode 100644
index 000000000000..88ab4e25e34f
--- /dev/null
+++ b/drivers/phy/mediatek/Kconfig
@@ -0,0 +1,14 @@
1#
2# Phy drivers for Mediatek devices
3#
4config PHY_MTK_TPHY
5 tristate "MediaTek T-PHY Driver"
6 depends on ARCH_MEDIATEK && OF
7 select GENERIC_PHY
8 help
9 Say 'Y' here to add support for MediaTek T-PHY driver,
10 it supports multiple usb2.0, usb3.0 ports, PCIe and
11 SATA, and meanwhile supports two version T-PHY which have
12 different banks layout, the T-PHY with shared banks between
13 multi-ports is first version, otherwise is second veriosn,
14 so you can easily distinguish them by banks layout.
diff --git a/drivers/phy/mediatek/Makefile b/drivers/phy/mediatek/Makefile
new file mode 100644
index 000000000000..763a92eefa00
--- /dev/null
+++ b/drivers/phy/mediatek/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for the phy drivers.
3#
4
5obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
diff --git a/drivers/phy/phy-mt65xx-usb3.c b/drivers/phy/mediatek/phy-mtk-tphy.c
index 59b110f795c3..e3baad78521f 100644
--- a/drivers/phy/phy-mt65xx-usb3.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -29,7 +29,7 @@
29#define SSUSB_SIFSLV_V1_U2FREQ 0x100 /* shared by u2 phys */ 29#define SSUSB_SIFSLV_V1_U2FREQ 0x100 /* shared by u2 phys */
30/* u2 phy bank */ 30/* u2 phy bank */
31#define SSUSB_SIFSLV_V1_U2PHY_COM 0x000 31#define SSUSB_SIFSLV_V1_U2PHY_COM 0x000
32/* u3 phy banks */ 32/* u3/pcie/sata phy banks */
33#define SSUSB_SIFSLV_V1_U3PHYD 0x000 33#define SSUSB_SIFSLV_V1_U3PHYD 0x000
34#define SSUSB_SIFSLV_V1_U3PHYA 0x200 34#define SSUSB_SIFSLV_V1_U3PHYA 0x200
35 35
@@ -38,7 +38,7 @@
38#define SSUSB_SIFSLV_V2_MISC 0x000 38#define SSUSB_SIFSLV_V2_MISC 0x000
39#define SSUSB_SIFSLV_V2_U2FREQ 0x100 39#define SSUSB_SIFSLV_V2_U2FREQ 0x100
40#define SSUSB_SIFSLV_V2_U2PHY_COM 0x300 40#define SSUSB_SIFSLV_V2_U2PHY_COM 0x300
41/* u3 phy banks */ 41/* u3/pcie/sata phy banks */
42#define SSUSB_SIFSLV_V2_SPLLC 0x000 42#define SSUSB_SIFSLV_V2_SPLLC 0x000
43#define SSUSB_SIFSLV_V2_CHIP 0x100 43#define SSUSB_SIFSLV_V2_CHIP 0x100
44#define SSUSB_SIFSLV_V2_U3PHYD 0x200 44#define SSUSB_SIFSLV_V2_U3PHYD 0x200
@@ -99,6 +99,23 @@
99#define P2C_RG_SESSEND BIT(4) 99#define P2C_RG_SESSEND BIT(4)
100#define P2C_RG_AVALID BIT(2) 100#define P2C_RG_AVALID BIT(2)
101 101
102#define U3P_U3_CHIP_GPIO_CTLD 0x0c
103#define P3C_REG_IP_SW_RST BIT(31)
104#define P3C_MCU_BUS_CK_GATE_EN BIT(30)
105#define P3C_FORCE_IP_SW_RST BIT(29)
106
107#define U3P_U3_CHIP_GPIO_CTLE 0x10
108#define P3C_RG_SWRST_U3_PHYD BIT(25)
109#define P3C_RG_SWRST_U3_PHYD_FORCE_EN BIT(24)
110
111#define U3P_U3_PHYA_REG0 0x000
112#define P3A_RG_CLKDRV_OFF GENMASK(3, 2)
113#define P3A_RG_CLKDRV_OFF_VAL(x) ((0x3 & (x)) << 2)
114
115#define U3P_U3_PHYA_REG1 0x004
116#define P3A_RG_CLKDRV_AMP GENMASK(31, 29)
117#define P3A_RG_CLKDRV_AMP_VAL(x) ((0x7 & (x)) << 29)
118
102#define U3P_U3_PHYA_REG6 0x018 119#define U3P_U3_PHYA_REG6 0x018
103#define P3A_RG_TX_EIDLE_CM GENMASK(31, 28) 120#define P3A_RG_TX_EIDLE_CM GENMASK(31, 28)
104#define P3A_RG_TX_EIDLE_CM_VAL(x) ((0xf & (x)) << 28) 121#define P3A_RG_TX_EIDLE_CM_VAL(x) ((0xf & (x)) << 28)
@@ -108,9 +125,40 @@
108#define P3A_RG_RX_DAC_MUX_VAL(x) ((0x1f & (x)) << 1) 125#define P3A_RG_RX_DAC_MUX_VAL(x) ((0x1f & (x)) << 1)
109 126
110#define U3P_U3_PHYA_DA_REG0 0x100 127#define U3P_U3_PHYA_DA_REG0 0x100
128#define P3A_RG_XTAL_EXT_PE2H GENMASK(17, 16)
129#define P3A_RG_XTAL_EXT_PE2H_VAL(x) ((0x3 & (x)) << 16)
130#define P3A_RG_XTAL_EXT_PE1H GENMASK(13, 12)
131#define P3A_RG_XTAL_EXT_PE1H_VAL(x) ((0x3 & (x)) << 12)
111#define P3A_RG_XTAL_EXT_EN_U3 GENMASK(11, 10) 132#define P3A_RG_XTAL_EXT_EN_U3 GENMASK(11, 10)
112#define P3A_RG_XTAL_EXT_EN_U3_VAL(x) ((0x3 & (x)) << 10) 133#define P3A_RG_XTAL_EXT_EN_U3_VAL(x) ((0x3 & (x)) << 10)
113 134
135#define U3P_U3_PHYA_DA_REG4 0x108
136#define P3A_RG_PLL_DIVEN_PE2H GENMASK(21, 19)
137#define P3A_RG_PLL_BC_PE2H GENMASK(7, 6)
138#define P3A_RG_PLL_BC_PE2H_VAL(x) ((0x3 & (x)) << 6)
139
140#define U3P_U3_PHYA_DA_REG5 0x10c
141#define P3A_RG_PLL_BR_PE2H GENMASK(29, 28)
142#define P3A_RG_PLL_BR_PE2H_VAL(x) ((0x3 & (x)) << 28)
143#define P3A_RG_PLL_IC_PE2H GENMASK(15, 12)
144#define P3A_RG_PLL_IC_PE2H_VAL(x) ((0xf & (x)) << 12)
145
146#define U3P_U3_PHYA_DA_REG6 0x110
147#define P3A_RG_PLL_IR_PE2H GENMASK(19, 16)
148#define P3A_RG_PLL_IR_PE2H_VAL(x) ((0xf & (x)) << 16)
149
150#define U3P_U3_PHYA_DA_REG7 0x114
151#define P3A_RG_PLL_BP_PE2H GENMASK(19, 16)
152#define P3A_RG_PLL_BP_PE2H_VAL(x) ((0xf & (x)) << 16)
153
154#define U3P_U3_PHYA_DA_REG20 0x13c
155#define P3A_RG_PLL_DELTA1_PE2H GENMASK(31, 16)
156#define P3A_RG_PLL_DELTA1_PE2H_VAL(x) ((0xffff & (x)) << 16)
157
158#define U3P_U3_PHYA_DA_REG25 0x148
159#define P3A_RG_PLL_DELTA_PE2H GENMASK(15, 0)
160#define P3A_RG_PLL_DELTA_PE2H_VAL(x) (0xffff & (x))
161
114#define U3P_U3_PHYD_LFPS1 0x00c 162#define U3P_U3_PHYD_LFPS1 0x00c
115#define P3D_RG_FWAKE_TH GENMASK(21, 16) 163#define P3D_RG_FWAKE_TH GENMASK(21, 16)
116#define P3D_RG_FWAKE_TH_VAL(x) ((0x3f & (x)) << 16) 164#define P3D_RG_FWAKE_TH_VAL(x) ((0x3f & (x)) << 16)
@@ -151,15 +199,74 @@
151#define U3P_SR_COEF_DIVISOR 1000 199#define U3P_SR_COEF_DIVISOR 1000
152#define U3P_FM_DET_CYCLE_CNT 1024 200#define U3P_FM_DET_CYCLE_CNT 1024
153 201
154enum mt_phy_version { 202/* SATA register setting */
155 MT_PHY_V1 = 1, 203#define PHYD_CTRL_SIGNAL_MODE4 0x1c
156 MT_PHY_V2, 204/* CDR Charge Pump P-path current adjustment */
205#define RG_CDR_BICLTD1_GEN1_MSK GENMASK(23, 20)
206#define RG_CDR_BICLTD1_GEN1_VAL(x) ((0xf & (x)) << 20)
207#define RG_CDR_BICLTD0_GEN1_MSK GENMASK(11, 8)
208#define RG_CDR_BICLTD0_GEN1_VAL(x) ((0xf & (x)) << 8)
209
210#define PHYD_DESIGN_OPTION2 0x24
211/* Symbol lock count selection */
212#define RG_LOCK_CNT_SEL_MSK GENMASK(5, 4)
213#define RG_LOCK_CNT_SEL_VAL(x) ((0x3 & (x)) << 4)
214
215#define PHYD_DESIGN_OPTION9 0x40
216/* COMWAK GAP width window */
217#define RG_TG_MAX_MSK GENMASK(20, 16)
218#define RG_TG_MAX_VAL(x) ((0x1f & (x)) << 16)
219/* COMINIT GAP width window */
220#define RG_T2_MAX_MSK GENMASK(13, 8)
221#define RG_T2_MAX_VAL(x) ((0x3f & (x)) << 8)
222/* COMWAK GAP width window */
223#define RG_TG_MIN_MSK GENMASK(7, 5)
224#define RG_TG_MIN_VAL(x) ((0x7 & (x)) << 5)
225/* COMINIT GAP width window */
226#define RG_T2_MIN_MSK GENMASK(4, 0)
227#define RG_T2_MIN_VAL(x) (0x1f & (x))
228
229#define ANA_RG_CTRL_SIGNAL1 0x4c
230/* TX driver tail current control for 0dB de-empahsis mdoe for Gen1 speed */
231#define RG_IDRV_0DB_GEN1_MSK GENMASK(13, 8)
232#define RG_IDRV_0DB_GEN1_VAL(x) ((0x3f & (x)) << 8)
233
234#define ANA_RG_CTRL_SIGNAL4 0x58
235#define RG_CDR_BICLTR_GEN1_MSK GENMASK(23, 20)
236#define RG_CDR_BICLTR_GEN1_VAL(x) ((0xf & (x)) << 20)
237/* Loop filter R1 resistance adjustment for Gen1 speed */
238#define RG_CDR_BR_GEN2_MSK GENMASK(10, 8)
239#define RG_CDR_BR_GEN2_VAL(x) ((0x7 & (x)) << 8)
240
241#define ANA_RG_CTRL_SIGNAL6 0x60
242/* I-path capacitance adjustment for Gen1 */
243#define RG_CDR_BC_GEN1_MSK GENMASK(28, 24)
244#define RG_CDR_BC_GEN1_VAL(x) ((0x1f & (x)) << 24)
245#define RG_CDR_BIRLTR_GEN1_MSK GENMASK(4, 0)
246#define RG_CDR_BIRLTR_GEN1_VAL(x) (0x1f & (x))
247
248#define ANA_EQ_EYE_CTRL_SIGNAL1 0x6c
249/* RX Gen1 LEQ tuning step */
250#define RG_EQ_DLEQ_LFI_GEN1_MSK GENMASK(11, 8)
251#define RG_EQ_DLEQ_LFI_GEN1_VAL(x) ((0xf & (x)) << 8)
252
253#define ANA_EQ_EYE_CTRL_SIGNAL4 0xd8
254#define RG_CDR_BIRLTD0_GEN1_MSK GENMASK(20, 16)
255#define RG_CDR_BIRLTD0_GEN1_VAL(x) ((0x1f & (x)) << 16)
256
257#define ANA_EQ_EYE_CTRL_SIGNAL5 0xdc
258#define RG_CDR_BIRLTD0_GEN3_MSK GENMASK(4, 0)
259#define RG_CDR_BIRLTD0_GEN3_VAL(x) (0x1f & (x))
260
261enum mtk_phy_version {
262 MTK_PHY_V1 = 1,
263 MTK_PHY_V2,
157}; 264};
158 265
159struct mt65xx_phy_pdata { 266struct mtk_phy_pdata {
160 /* avoid RX sensitivity level degradation only for mt8173 */ 267 /* avoid RX sensitivity level degradation only for mt8173 */
161 bool avoid_rx_sen_degradation; 268 bool avoid_rx_sen_degradation;
162 enum mt_phy_version version; 269 enum mtk_phy_version version;
163}; 270};
164 271
165struct u2phy_banks { 272struct u2phy_banks {
@@ -175,7 +282,7 @@ struct u3phy_banks {
175 void __iomem *phya; /* include u3phya_da */ 282 void __iomem *phya; /* include u3phya_da */
176}; 283};
177 284
178struct mt65xx_phy_instance { 285struct mtk_phy_instance {
179 struct phy *phy; 286 struct phy *phy;
180 void __iomem *port_base; 287 void __iomem *port_base;
181 union { 288 union {
@@ -187,18 +294,18 @@ struct mt65xx_phy_instance {
187 u8 type; 294 u8 type;
188}; 295};
189 296
190struct mt65xx_u3phy { 297struct mtk_tphy {
191 struct device *dev; 298 struct device *dev;
192 void __iomem *sif_base; /* only shared sif */ 299 void __iomem *sif_base; /* only shared sif */
193 /* deprecated, use @ref_clk instead in phy instance */ 300 /* deprecated, use @ref_clk instead in phy instance */
194 struct clk *u3phya_ref; /* reference clock of usb3 anolog phy */ 301 struct clk *u3phya_ref; /* reference clock of usb3 anolog phy */
195 const struct mt65xx_phy_pdata *pdata; 302 const struct mtk_phy_pdata *pdata;
196 struct mt65xx_phy_instance **phys; 303 struct mtk_phy_instance **phys;
197 int nphys; 304 int nphys;
198}; 305};
199 306
200static void hs_slew_rate_calibrate(struct mt65xx_u3phy *u3phy, 307static void hs_slew_rate_calibrate(struct mtk_tphy *tphy,
201 struct mt65xx_phy_instance *instance) 308 struct mtk_phy_instance *instance)
202{ 309{
203 struct u2phy_banks *u2_banks = &instance->u2_banks; 310 struct u2phy_banks *u2_banks = &instance->u2_banks;
204 void __iomem *fmreg = u2_banks->fmreg; 311 void __iomem *fmreg = u2_banks->fmreg;
@@ -222,7 +329,7 @@ static void hs_slew_rate_calibrate(struct mt65xx_u3phy *u3phy,
222 tmp = readl(fmreg + U3P_U2FREQ_FMCR0); 329 tmp = readl(fmreg + U3P_U2FREQ_FMCR0);
223 tmp &= ~(P2F_RG_CYCLECNT | P2F_RG_MONCLK_SEL); 330 tmp &= ~(P2F_RG_CYCLECNT | P2F_RG_MONCLK_SEL);
224 tmp |= P2F_RG_CYCLECNT_VAL(U3P_FM_DET_CYCLE_CNT); 331 tmp |= P2F_RG_CYCLECNT_VAL(U3P_FM_DET_CYCLE_CNT);
225 if (u3phy->pdata->version == MT_PHY_V1) 332 if (tphy->pdata->version == MTK_PHY_V1)
226 tmp |= P2F_RG_MONCLK_SEL_VAL(instance->index >> 1); 333 tmp |= P2F_RG_MONCLK_SEL_VAL(instance->index >> 1);
227 334
228 writel(tmp, fmreg + U3P_U2FREQ_FMCR0); 335 writel(tmp, fmreg + U3P_U2FREQ_FMCR0);
@@ -257,7 +364,7 @@ static void hs_slew_rate_calibrate(struct mt65xx_u3phy *u3phy,
257 /* if FM detection fail, set default value */ 364 /* if FM detection fail, set default value */
258 calibration_val = 4; 365 calibration_val = 4;
259 } 366 }
260 dev_dbg(u3phy->dev, "phy:%d, fm_out:%d, calib:%d\n", 367 dev_dbg(tphy->dev, "phy:%d, fm_out:%d, calib:%d\n",
261 instance->index, fm_out, calibration_val); 368 instance->index, fm_out, calibration_val);
262 369
263 /* set HS slew rate */ 370 /* set HS slew rate */
@@ -272,8 +379,8 @@ static void hs_slew_rate_calibrate(struct mt65xx_u3phy *u3phy,
272 writel(tmp, com + U3P_USBPHYACR5); 379 writel(tmp, com + U3P_USBPHYACR5);
273} 380}
274 381
275static void u3_phy_instance_init(struct mt65xx_u3phy *u3phy, 382static void u3_phy_instance_init(struct mtk_tphy *tphy,
276 struct mt65xx_phy_instance *instance) 383 struct mtk_phy_instance *instance)
277{ 384{
278 struct u3phy_banks *u3_banks = &instance->u3_banks; 385 struct u3phy_banks *u3_banks = &instance->u3_banks;
279 u32 tmp; 386 u32 tmp;
@@ -319,11 +426,11 @@ static void u3_phy_instance_init(struct mt65xx_u3phy *u3phy,
319 tmp |= P3D_RG_RXDET_STB2_SET_P3_VAL(0x10); 426 tmp |= P3D_RG_RXDET_STB2_SET_P3_VAL(0x10);
320 writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET2); 427 writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET2);
321 428
322 dev_dbg(u3phy->dev, "%s(%d)\n", __func__, instance->index); 429 dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index);
323} 430}
324 431
325static void phy_instance_init(struct mt65xx_u3phy *u3phy, 432static void u2_phy_instance_init(struct mtk_tphy *tphy,
326 struct mt65xx_phy_instance *instance) 433 struct mtk_phy_instance *instance)
327{ 434{
328 struct u2phy_banks *u2_banks = &instance->u2_banks; 435 struct u2phy_banks *u2_banks = &instance->u2_banks;
329 void __iomem *com = u2_banks->com; 436 void __iomem *com = u2_banks->com;
@@ -355,7 +462,7 @@ static void phy_instance_init(struct mt65xx_u3phy *u3phy,
355 writel(tmp, com + U3P_U2PHYACR4); 462 writel(tmp, com + U3P_U2PHYACR4);
356 } 463 }
357 464
358 if (u3phy->pdata->avoid_rx_sen_degradation) { 465 if (tphy->pdata->avoid_rx_sen_degradation) {
359 if (!index) { 466 if (!index) {
360 tmp = readl(com + U3P_USBPHYACR2); 467 tmp = readl(com + U3P_USBPHYACR2);
361 tmp |= PA2_RG_SIF_U2PLL_FORCE_EN; 468 tmp |= PA2_RG_SIF_U2PLL_FORCE_EN;
@@ -381,11 +488,11 @@ static void phy_instance_init(struct mt65xx_u3phy *u3phy,
381 tmp |= PA6_RG_U2_SQTH_VAL(2); 488 tmp |= PA6_RG_U2_SQTH_VAL(2);
382 writel(tmp, com + U3P_USBPHYACR6); 489 writel(tmp, com + U3P_USBPHYACR6);
383 490
384 dev_dbg(u3phy->dev, "%s(%d)\n", __func__, index); 491 dev_dbg(tphy->dev, "%s(%d)\n", __func__, index);
385} 492}
386 493
387static void phy_instance_power_on(struct mt65xx_u3phy *u3phy, 494static void u2_phy_instance_power_on(struct mtk_tphy *tphy,
388 struct mt65xx_phy_instance *instance) 495 struct mtk_phy_instance *instance)
389{ 496{
390 struct u2phy_banks *u2_banks = &instance->u2_banks; 497 struct u2phy_banks *u2_banks = &instance->u2_banks;
391 void __iomem *com = u2_banks->com; 498 void __iomem *com = u2_banks->com;
@@ -408,7 +515,7 @@ static void phy_instance_power_on(struct mt65xx_u3phy *u3phy,
408 tmp &= ~P2C_RG_SESSEND; 515 tmp &= ~P2C_RG_SESSEND;
409 writel(tmp, com + U3P_U2PHYDTM1); 516 writel(tmp, com + U3P_U2PHYDTM1);
410 517
411 if (u3phy->pdata->avoid_rx_sen_degradation && index) { 518 if (tphy->pdata->avoid_rx_sen_degradation && index) {
412 tmp = readl(com + U3D_U2PHYDCR0); 519 tmp = readl(com + U3D_U2PHYDCR0);
413 tmp |= P2C_RG_SIF_U2PLL_FORCE_ON; 520 tmp |= P2C_RG_SIF_U2PLL_FORCE_ON;
414 writel(tmp, com + U3D_U2PHYDCR0); 521 writel(tmp, com + U3D_U2PHYDCR0);
@@ -417,11 +524,11 @@ static void phy_instance_power_on(struct mt65xx_u3phy *u3phy,
417 tmp |= P2C_RG_SUSPENDM | P2C_FORCE_SUSPENDM; 524 tmp |= P2C_RG_SUSPENDM | P2C_FORCE_SUSPENDM;
418 writel(tmp, com + U3P_U2PHYDTM0); 525 writel(tmp, com + U3P_U2PHYDTM0);
419 } 526 }
420 dev_dbg(u3phy->dev, "%s(%d)\n", __func__, index); 527 dev_dbg(tphy->dev, "%s(%d)\n", __func__, index);
421} 528}
422 529
423static void phy_instance_power_off(struct mt65xx_u3phy *u3phy, 530static void u2_phy_instance_power_off(struct mtk_tphy *tphy,
424 struct mt65xx_phy_instance *instance) 531 struct mtk_phy_instance *instance)
425{ 532{
426 struct u2phy_banks *u2_banks = &instance->u2_banks; 533 struct u2phy_banks *u2_banks = &instance->u2_banks;
427 void __iomem *com = u2_banks->com; 534 void __iomem *com = u2_banks->com;
@@ -449,24 +556,24 @@ static void phy_instance_power_off(struct mt65xx_u3phy *u3phy,
449 tmp |= P2C_RG_SESSEND; 556 tmp |= P2C_RG_SESSEND;
450 writel(tmp, com + U3P_U2PHYDTM1); 557 writel(tmp, com + U3P_U2PHYDTM1);
451 558
452 if (u3phy->pdata->avoid_rx_sen_degradation && index) { 559 if (tphy->pdata->avoid_rx_sen_degradation && index) {
453 tmp = readl(com + U3D_U2PHYDCR0); 560 tmp = readl(com + U3D_U2PHYDCR0);
454 tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON; 561 tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON;
455 writel(tmp, com + U3D_U2PHYDCR0); 562 writel(tmp, com + U3D_U2PHYDCR0);
456 } 563 }
457 564
458 dev_dbg(u3phy->dev, "%s(%d)\n", __func__, index); 565 dev_dbg(tphy->dev, "%s(%d)\n", __func__, index);
459} 566}
460 567
461static void phy_instance_exit(struct mt65xx_u3phy *u3phy, 568static void u2_phy_instance_exit(struct mtk_tphy *tphy,
462 struct mt65xx_phy_instance *instance) 569 struct mtk_phy_instance *instance)
463{ 570{
464 struct u2phy_banks *u2_banks = &instance->u2_banks; 571 struct u2phy_banks *u2_banks = &instance->u2_banks;
465 void __iomem *com = u2_banks->com; 572 void __iomem *com = u2_banks->com;
466 u32 index = instance->index; 573 u32 index = instance->index;
467 u32 tmp; 574 u32 tmp;
468 575
469 if (u3phy->pdata->avoid_rx_sen_degradation && index) { 576 if (tphy->pdata->avoid_rx_sen_degradation && index) {
470 tmp = readl(com + U3D_U2PHYDCR0); 577 tmp = readl(com + U3D_U2PHYDCR0);
471 tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON; 578 tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON;
472 writel(tmp, com + U3D_U2PHYDCR0); 579 writel(tmp, com + U3D_U2PHYDCR0);
@@ -477,109 +584,307 @@ static void phy_instance_exit(struct mt65xx_u3phy *u3phy,
477 } 584 }
478} 585}
479 586
480static void phy_v1_banks_init(struct mt65xx_u3phy *u3phy, 587static void pcie_phy_instance_init(struct mtk_tphy *tphy,
481 struct mt65xx_phy_instance *instance) 588 struct mtk_phy_instance *instance)
589{
590 struct u3phy_banks *u3_banks = &instance->u3_banks;
591 u32 tmp;
592
593 if (tphy->pdata->version != MTK_PHY_V1)
594 return;
595
596 tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG0);
597 tmp &= ~(P3A_RG_XTAL_EXT_PE1H | P3A_RG_XTAL_EXT_PE2H);
598 tmp |= P3A_RG_XTAL_EXT_PE1H_VAL(0x2) | P3A_RG_XTAL_EXT_PE2H_VAL(0x2);
599 writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG0);
600
601 /* ref clk drive */
602 tmp = readl(u3_banks->phya + U3P_U3_PHYA_REG1);
603 tmp &= ~P3A_RG_CLKDRV_AMP;
604 tmp |= P3A_RG_CLKDRV_AMP_VAL(0x4);
605 writel(tmp, u3_banks->phya + U3P_U3_PHYA_REG1);
606
607 tmp = readl(u3_banks->phya + U3P_U3_PHYA_REG0);
608 tmp &= ~P3A_RG_CLKDRV_OFF;
609 tmp |= P3A_RG_CLKDRV_OFF_VAL(0x1);
610 writel(tmp, u3_banks->phya + U3P_U3_PHYA_REG0);
611
612 /* SSC delta -5000ppm */
613 tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG20);
614 tmp &= ~P3A_RG_PLL_DELTA1_PE2H;
615 tmp |= P3A_RG_PLL_DELTA1_PE2H_VAL(0x3c);
616 writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG20);
617
618 tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG25);
619 tmp &= ~P3A_RG_PLL_DELTA_PE2H;
620 tmp |= P3A_RG_PLL_DELTA_PE2H_VAL(0x36);
621 writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG25);
622
623 /* change pll BW 0.6M */
624 tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG5);
625 tmp &= ~(P3A_RG_PLL_BR_PE2H | P3A_RG_PLL_IC_PE2H);
626 tmp |= P3A_RG_PLL_BR_PE2H_VAL(0x1) | P3A_RG_PLL_IC_PE2H_VAL(0x1);
627 writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG5);
628
629 tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG4);
630 tmp &= ~(P3A_RG_PLL_DIVEN_PE2H | P3A_RG_PLL_BC_PE2H);
631 tmp |= P3A_RG_PLL_BC_PE2H_VAL(0x3);
632 writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG4);
633
634 tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG6);
635 tmp &= ~P3A_RG_PLL_IR_PE2H;
636 tmp |= P3A_RG_PLL_IR_PE2H_VAL(0x2);
637 writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG6);
638
639 tmp = readl(u3_banks->phya + U3P_U3_PHYA_DA_REG7);
640 tmp &= ~P3A_RG_PLL_BP_PE2H;
641 tmp |= P3A_RG_PLL_BP_PE2H_VAL(0xa);
642 writel(tmp, u3_banks->phya + U3P_U3_PHYA_DA_REG7);
643
644 /* Tx Detect Rx Timing: 10us -> 5us */
645 tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RXDET1);
646 tmp &= ~P3D_RG_RXDET_STB2_SET;
647 tmp |= P3D_RG_RXDET_STB2_SET_VAL(0x10);
648 writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET1);
649
650 tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RXDET2);
651 tmp &= ~P3D_RG_RXDET_STB2_SET_P3;
652 tmp |= P3D_RG_RXDET_STB2_SET_P3_VAL(0x10);
653 writel(tmp, u3_banks->phyd + U3P_U3_PHYD_RXDET2);
654
655 /* wait for PCIe subsys register to active */
656 usleep_range(2500, 3000);
657 dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index);
658}
659
660static void pcie_phy_instance_power_on(struct mtk_tphy *tphy,
661 struct mtk_phy_instance *instance)
662{
663 struct u3phy_banks *bank = &instance->u3_banks;
664 u32 tmp;
665
666 tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLD);
667 tmp &= ~(P3C_FORCE_IP_SW_RST | P3C_MCU_BUS_CK_GATE_EN |
668 P3C_REG_IP_SW_RST);
669 writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLD);
670
671 tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLE);
672 tmp &= ~(P3C_RG_SWRST_U3_PHYD_FORCE_EN | P3C_RG_SWRST_U3_PHYD);
673 writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLE);
674}
675
676static void pcie_phy_instance_power_off(struct mtk_tphy *tphy,
677 struct mtk_phy_instance *instance)
678
679{
680 struct u3phy_banks *bank = &instance->u3_banks;
681 u32 tmp;
682
683 tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLD);
684 tmp |= P3C_FORCE_IP_SW_RST | P3C_REG_IP_SW_RST;
685 writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLD);
686
687 tmp = readl(bank->chip + U3P_U3_CHIP_GPIO_CTLE);
688 tmp |= P3C_RG_SWRST_U3_PHYD_FORCE_EN | P3C_RG_SWRST_U3_PHYD;
689 writel(tmp, bank->chip + U3P_U3_CHIP_GPIO_CTLE);
690}
691
692static void sata_phy_instance_init(struct mtk_tphy *tphy,
693 struct mtk_phy_instance *instance)
694{
695 struct u3phy_banks *u3_banks = &instance->u3_banks;
696 void __iomem *phyd = u3_banks->phyd;
697 u32 tmp;
698
699 /* charge current adjustment */
700 tmp = readl(phyd + ANA_RG_CTRL_SIGNAL6);
701 tmp &= ~(RG_CDR_BIRLTR_GEN1_MSK | RG_CDR_BC_GEN1_MSK);
702 tmp |= RG_CDR_BIRLTR_GEN1_VAL(0x6) | RG_CDR_BC_GEN1_VAL(0x1a);
703 writel(tmp, phyd + ANA_RG_CTRL_SIGNAL6);
704
705 tmp = readl(phyd + ANA_EQ_EYE_CTRL_SIGNAL4);
706 tmp &= ~RG_CDR_BIRLTD0_GEN1_MSK;
707 tmp |= RG_CDR_BIRLTD0_GEN1_VAL(0x18);
708 writel(tmp, phyd + ANA_EQ_EYE_CTRL_SIGNAL4);
709
710 tmp = readl(phyd + ANA_EQ_EYE_CTRL_SIGNAL5);
711 tmp &= ~RG_CDR_BIRLTD0_GEN3_MSK;
712 tmp |= RG_CDR_BIRLTD0_GEN3_VAL(0x06);
713 writel(tmp, phyd + ANA_EQ_EYE_CTRL_SIGNAL5);
714
715 tmp = readl(phyd + ANA_RG_CTRL_SIGNAL4);
716 tmp &= ~(RG_CDR_BICLTR_GEN1_MSK | RG_CDR_BR_GEN2_MSK);
717 tmp |= RG_CDR_BICLTR_GEN1_VAL(0x0c) | RG_CDR_BR_GEN2_VAL(0x07);
718 writel(tmp, phyd + ANA_RG_CTRL_SIGNAL4);
719
720 tmp = readl(phyd + PHYD_CTRL_SIGNAL_MODE4);
721 tmp &= ~(RG_CDR_BICLTD0_GEN1_MSK | RG_CDR_BICLTD1_GEN1_MSK);
722 tmp |= RG_CDR_BICLTD0_GEN1_VAL(0x08) | RG_CDR_BICLTD1_GEN1_VAL(0x02);
723 writel(tmp, phyd + PHYD_CTRL_SIGNAL_MODE4);
724
725 tmp = readl(phyd + PHYD_DESIGN_OPTION2);
726 tmp &= ~RG_LOCK_CNT_SEL_MSK;
727 tmp |= RG_LOCK_CNT_SEL_VAL(0x02);
728 writel(tmp, phyd + PHYD_DESIGN_OPTION2);
729
730 tmp = readl(phyd + PHYD_DESIGN_OPTION9);
731 tmp &= ~(RG_T2_MIN_MSK | RG_TG_MIN_MSK |
732 RG_T2_MAX_MSK | RG_TG_MAX_MSK);
733 tmp |= RG_T2_MIN_VAL(0x12) | RG_TG_MIN_VAL(0x04) |
734 RG_T2_MAX_VAL(0x31) | RG_TG_MAX_VAL(0x0e);
735 writel(tmp, phyd + PHYD_DESIGN_OPTION9);
736
737 tmp = readl(phyd + ANA_RG_CTRL_SIGNAL1);
738 tmp &= ~RG_IDRV_0DB_GEN1_MSK;
739 tmp |= RG_IDRV_0DB_GEN1_VAL(0x20);
740 writel(tmp, phyd + ANA_RG_CTRL_SIGNAL1);
741
742 tmp = readl(phyd + ANA_EQ_EYE_CTRL_SIGNAL1);
743 tmp &= ~RG_EQ_DLEQ_LFI_GEN1_MSK;
744 tmp |= RG_EQ_DLEQ_LFI_GEN1_VAL(0x03);
745 writel(tmp, phyd + ANA_EQ_EYE_CTRL_SIGNAL1);
746
747 dev_dbg(tphy->dev, "%s(%d)\n", __func__, instance->index);
748}
749
750static void phy_v1_banks_init(struct mtk_tphy *tphy,
751 struct mtk_phy_instance *instance)
482{ 752{
483 struct u2phy_banks *u2_banks = &instance->u2_banks; 753 struct u2phy_banks *u2_banks = &instance->u2_banks;
484 struct u3phy_banks *u3_banks = &instance->u3_banks; 754 struct u3phy_banks *u3_banks = &instance->u3_banks;
485 755
486 if (instance->type == PHY_TYPE_USB2) { 756 switch (instance->type) {
757 case PHY_TYPE_USB2:
487 u2_banks->misc = NULL; 758 u2_banks->misc = NULL;
488 u2_banks->fmreg = u3phy->sif_base + SSUSB_SIFSLV_V1_U2FREQ; 759 u2_banks->fmreg = tphy->sif_base + SSUSB_SIFSLV_V1_U2FREQ;
489 u2_banks->com = instance->port_base + SSUSB_SIFSLV_V1_U2PHY_COM; 760 u2_banks->com = instance->port_base + SSUSB_SIFSLV_V1_U2PHY_COM;
490 } else if (instance->type == PHY_TYPE_USB3) { 761 break;
491 u3_banks->spllc = u3phy->sif_base + SSUSB_SIFSLV_V1_SPLLC; 762 case PHY_TYPE_USB3:
763 case PHY_TYPE_PCIE:
764 u3_banks->spllc = tphy->sif_base + SSUSB_SIFSLV_V1_SPLLC;
492 u3_banks->chip = NULL; 765 u3_banks->chip = NULL;
493 u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V1_U3PHYD; 766 u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V1_U3PHYD;
494 u3_banks->phya = instance->port_base + SSUSB_SIFSLV_V1_U3PHYA; 767 u3_banks->phya = instance->port_base + SSUSB_SIFSLV_V1_U3PHYA;
768 break;
769 case PHY_TYPE_SATA:
770 u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V1_U3PHYD;
771 break;
772 default:
773 dev_err(tphy->dev, "incompatible PHY type\n");
774 return;
495 } 775 }
496} 776}
497 777
498static void phy_v2_banks_init(struct mt65xx_u3phy *u3phy, 778static void phy_v2_banks_init(struct mtk_tphy *tphy,
499 struct mt65xx_phy_instance *instance) 779 struct mtk_phy_instance *instance)
500{ 780{
501 struct u2phy_banks *u2_banks = &instance->u2_banks; 781 struct u2phy_banks *u2_banks = &instance->u2_banks;
502 struct u3phy_banks *u3_banks = &instance->u3_banks; 782 struct u3phy_banks *u3_banks = &instance->u3_banks;
503 783
504 if (instance->type == PHY_TYPE_USB2) { 784 switch (instance->type) {
785 case PHY_TYPE_USB2:
505 u2_banks->misc = instance->port_base + SSUSB_SIFSLV_V2_MISC; 786 u2_banks->misc = instance->port_base + SSUSB_SIFSLV_V2_MISC;
506 u2_banks->fmreg = instance->port_base + SSUSB_SIFSLV_V2_U2FREQ; 787 u2_banks->fmreg = instance->port_base + SSUSB_SIFSLV_V2_U2FREQ;
507 u2_banks->com = instance->port_base + SSUSB_SIFSLV_V2_U2PHY_COM; 788 u2_banks->com = instance->port_base + SSUSB_SIFSLV_V2_U2PHY_COM;
508 } else if (instance->type == PHY_TYPE_USB3) { 789 break;
790 case PHY_TYPE_USB3:
791 case PHY_TYPE_PCIE:
509 u3_banks->spllc = instance->port_base + SSUSB_SIFSLV_V2_SPLLC; 792 u3_banks->spllc = instance->port_base + SSUSB_SIFSLV_V2_SPLLC;
510 u3_banks->chip = instance->port_base + SSUSB_SIFSLV_V2_CHIP; 793 u3_banks->chip = instance->port_base + SSUSB_SIFSLV_V2_CHIP;
511 u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V2_U3PHYD; 794 u3_banks->phyd = instance->port_base + SSUSB_SIFSLV_V2_U3PHYD;
512 u3_banks->phya = instance->port_base + SSUSB_SIFSLV_V2_U3PHYA; 795 u3_banks->phya = instance->port_base + SSUSB_SIFSLV_V2_U3PHYA;
796 break;
797 default:
798 dev_err(tphy->dev, "incompatible PHY type\n");
799 return;
513 } 800 }
514} 801}
515 802
516static int mt65xx_phy_init(struct phy *phy) 803static int mtk_phy_init(struct phy *phy)
517{ 804{
518 struct mt65xx_phy_instance *instance = phy_get_drvdata(phy); 805 struct mtk_phy_instance *instance = phy_get_drvdata(phy);
519 struct mt65xx_u3phy *u3phy = dev_get_drvdata(phy->dev.parent); 806 struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent);
520 int ret; 807 int ret;
521 808
522 ret = clk_prepare_enable(u3phy->u3phya_ref); 809 ret = clk_prepare_enable(tphy->u3phya_ref);
523 if (ret) { 810 if (ret) {
524 dev_err(u3phy->dev, "failed to enable u3phya_ref\n"); 811 dev_err(tphy->dev, "failed to enable u3phya_ref\n");
525 return ret; 812 return ret;
526 } 813 }
527 814
528 ret = clk_prepare_enable(instance->ref_clk); 815 ret = clk_prepare_enable(instance->ref_clk);
529 if (ret) { 816 if (ret) {
530 dev_err(u3phy->dev, "failed to enable ref_clk\n"); 817 dev_err(tphy->dev, "failed to enable ref_clk\n");
531 return ret; 818 return ret;
532 } 819 }
533 820
534 if (instance->type == PHY_TYPE_USB2) 821 switch (instance->type) {
535 phy_instance_init(u3phy, instance); 822 case PHY_TYPE_USB2:
536 else 823 u2_phy_instance_init(tphy, instance);
537 u3_phy_instance_init(u3phy, instance); 824 break;
825 case PHY_TYPE_USB3:
826 u3_phy_instance_init(tphy, instance);
827 break;
828 case PHY_TYPE_PCIE:
829 pcie_phy_instance_init(tphy, instance);
830 break;
831 case PHY_TYPE_SATA:
832 sata_phy_instance_init(tphy, instance);
833 break;
834 default:
835 dev_err(tphy->dev, "incompatible PHY type\n");
836 return -EINVAL;
837 }
538 838
539 return 0; 839 return 0;
540} 840}
541 841
542static int mt65xx_phy_power_on(struct phy *phy) 842static int mtk_phy_power_on(struct phy *phy)
543{ 843{
544 struct mt65xx_phy_instance *instance = phy_get_drvdata(phy); 844 struct mtk_phy_instance *instance = phy_get_drvdata(phy);
545 struct mt65xx_u3phy *u3phy = dev_get_drvdata(phy->dev.parent); 845 struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent);
546 846
547 if (instance->type == PHY_TYPE_USB2) { 847 if (instance->type == PHY_TYPE_USB2) {
548 phy_instance_power_on(u3phy, instance); 848 u2_phy_instance_power_on(tphy, instance);
549 hs_slew_rate_calibrate(u3phy, instance); 849 hs_slew_rate_calibrate(tphy, instance);
850 } else if (instance->type == PHY_TYPE_PCIE) {
851 pcie_phy_instance_power_on(tphy, instance);
550 } 852 }
853
551 return 0; 854 return 0;
552} 855}
553 856
554static int mt65xx_phy_power_off(struct phy *phy) 857static int mtk_phy_power_off(struct phy *phy)
555{ 858{
556 struct mt65xx_phy_instance *instance = phy_get_drvdata(phy); 859 struct mtk_phy_instance *instance = phy_get_drvdata(phy);
557 struct mt65xx_u3phy *u3phy = dev_get_drvdata(phy->dev.parent); 860 struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent);
558 861
559 if (instance->type == PHY_TYPE_USB2) 862 if (instance->type == PHY_TYPE_USB2)
560 phy_instance_power_off(u3phy, instance); 863 u2_phy_instance_power_off(tphy, instance);
864 else if (instance->type == PHY_TYPE_PCIE)
865 pcie_phy_instance_power_off(tphy, instance);
561 866
562 return 0; 867 return 0;
563} 868}
564 869
565static int mt65xx_phy_exit(struct phy *phy) 870static int mtk_phy_exit(struct phy *phy)
566{ 871{
567 struct mt65xx_phy_instance *instance = phy_get_drvdata(phy); 872 struct mtk_phy_instance *instance = phy_get_drvdata(phy);
568 struct mt65xx_u3phy *u3phy = dev_get_drvdata(phy->dev.parent); 873 struct mtk_tphy *tphy = dev_get_drvdata(phy->dev.parent);
569 874
570 if (instance->type == PHY_TYPE_USB2) 875 if (instance->type == PHY_TYPE_USB2)
571 phy_instance_exit(u3phy, instance); 876 u2_phy_instance_exit(tphy, instance);
572 877
573 clk_disable_unprepare(instance->ref_clk); 878 clk_disable_unprepare(instance->ref_clk);
574 clk_disable_unprepare(u3phy->u3phya_ref); 879 clk_disable_unprepare(tphy->u3phya_ref);
575 return 0; 880 return 0;
576} 881}
577 882
578static struct phy *mt65xx_phy_xlate(struct device *dev, 883static struct phy *mtk_phy_xlate(struct device *dev,
579 struct of_phandle_args *args) 884 struct of_phandle_args *args)
580{ 885{
581 struct mt65xx_u3phy *u3phy = dev_get_drvdata(dev); 886 struct mtk_tphy *tphy = dev_get_drvdata(dev);
582 struct mt65xx_phy_instance *instance = NULL; 887 struct mtk_phy_instance *instance = NULL;
583 struct device_node *phy_np = args->np; 888 struct device_node *phy_np = args->np;
584 int index; 889 int index;
585 890
@@ -588,9 +893,9 @@ static struct phy *mt65xx_phy_xlate(struct device *dev,
588 return ERR_PTR(-EINVAL); 893 return ERR_PTR(-EINVAL);
589 } 894 }
590 895
591 for (index = 0; index < u3phy->nphys; index++) 896 for (index = 0; index < tphy->nphys; index++)
592 if (phy_np == u3phy->phys[index]->phy->dev.of_node) { 897 if (phy_np == tphy->phys[index]->phy->dev.of_node) {
593 instance = u3phy->phys[index]; 898 instance = tphy->phys[index];
594 break; 899 break;
595 } 900 }
596 901
@@ -601,15 +906,17 @@ static struct phy *mt65xx_phy_xlate(struct device *dev,
601 906
602 instance->type = args->args[0]; 907 instance->type = args->args[0];
603 if (!(instance->type == PHY_TYPE_USB2 || 908 if (!(instance->type == PHY_TYPE_USB2 ||
604 instance->type == PHY_TYPE_USB3)) { 909 instance->type == PHY_TYPE_USB3 ||
910 instance->type == PHY_TYPE_PCIE ||
911 instance->type == PHY_TYPE_SATA)) {
605 dev_err(dev, "unsupported device type: %d\n", instance->type); 912 dev_err(dev, "unsupported device type: %d\n", instance->type);
606 return ERR_PTR(-EINVAL); 913 return ERR_PTR(-EINVAL);
607 } 914 }
608 915
609 if (u3phy->pdata->version == MT_PHY_V1) { 916 if (tphy->pdata->version == MTK_PHY_V1) {
610 phy_v1_banks_init(u3phy, instance); 917 phy_v1_banks_init(tphy, instance);
611 } else if (u3phy->pdata->version == MT_PHY_V2) { 918 } else if (tphy->pdata->version == MTK_PHY_V2) {
612 phy_v2_banks_init(u3phy, instance); 919 phy_v2_banks_init(tphy, instance);
613 } else { 920 } else {
614 dev_err(dev, "phy version is not supported\n"); 921 dev_err(dev, "phy version is not supported\n");
615 return ERR_PTR(-EINVAL); 922 return ERR_PTR(-EINVAL);
@@ -618,38 +925,40 @@ static struct phy *mt65xx_phy_xlate(struct device *dev,
618 return instance->phy; 925 return instance->phy;
619} 926}
620 927
621static const struct phy_ops mt65xx_u3phy_ops = { 928static const struct phy_ops mtk_tphy_ops = {
622 .init = mt65xx_phy_init, 929 .init = mtk_phy_init,
623 .exit = mt65xx_phy_exit, 930 .exit = mtk_phy_exit,
624 .power_on = mt65xx_phy_power_on, 931 .power_on = mtk_phy_power_on,
625 .power_off = mt65xx_phy_power_off, 932 .power_off = mtk_phy_power_off,
626 .owner = THIS_MODULE, 933 .owner = THIS_MODULE,
627}; 934};
628 935
629static const struct mt65xx_phy_pdata mt2701_pdata = { 936static const struct mtk_phy_pdata tphy_v1_pdata = {
630 .avoid_rx_sen_degradation = false, 937 .avoid_rx_sen_degradation = false,
631 .version = MT_PHY_V1, 938 .version = MTK_PHY_V1,
632}; 939};
633 940
634static const struct mt65xx_phy_pdata mt2712_pdata = { 941static const struct mtk_phy_pdata tphy_v2_pdata = {
635 .avoid_rx_sen_degradation = false, 942 .avoid_rx_sen_degradation = false,
636 .version = MT_PHY_V2, 943 .version = MTK_PHY_V2,
637}; 944};
638 945
639static const struct mt65xx_phy_pdata mt8173_pdata = { 946static const struct mtk_phy_pdata mt8173_pdata = {
640 .avoid_rx_sen_degradation = true, 947 .avoid_rx_sen_degradation = true,
641 .version = MT_PHY_V1, 948 .version = MTK_PHY_V1,
642}; 949};
643 950
644static const struct of_device_id mt65xx_u3phy_id_table[] = { 951static const struct of_device_id mtk_tphy_id_table[] = {
645 { .compatible = "mediatek,mt2701-u3phy", .data = &mt2701_pdata }, 952 { .compatible = "mediatek,mt2701-u3phy", .data = &tphy_v1_pdata },
646 { .compatible = "mediatek,mt2712-u3phy", .data = &mt2712_pdata }, 953 { .compatible = "mediatek,mt2712-u3phy", .data = &tphy_v2_pdata },
647 { .compatible = "mediatek,mt8173-u3phy", .data = &mt8173_pdata }, 954 { .compatible = "mediatek,mt8173-u3phy", .data = &mt8173_pdata },
955 { .compatible = "mediatek,generic-tphy-v1", .data = &tphy_v1_pdata },
956 { .compatible = "mediatek,generic-tphy-v2", .data = &tphy_v2_pdata },
648 { }, 957 { },
649}; 958};
650MODULE_DEVICE_TABLE(of, mt65xx_u3phy_id_table); 959MODULE_DEVICE_TABLE(of, mtk_tphy_id_table);
651 960
652static int mt65xx_u3phy_probe(struct platform_device *pdev) 961static int mtk_tphy_probe(struct platform_device *pdev)
653{ 962{
654 const struct of_device_id *match; 963 const struct of_device_id *match;
655 struct device *dev = &pdev->dev; 964 struct device *dev = &pdev->dev;
@@ -657,50 +966,50 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
657 struct device_node *child_np; 966 struct device_node *child_np;
658 struct phy_provider *provider; 967 struct phy_provider *provider;
659 struct resource *sif_res; 968 struct resource *sif_res;
660 struct mt65xx_u3phy *u3phy; 969 struct mtk_tphy *tphy;
661 struct resource res; 970 struct resource res;
662 int port, retval; 971 int port, retval;
663 972
664 match = of_match_node(mt65xx_u3phy_id_table, pdev->dev.of_node); 973 match = of_match_node(mtk_tphy_id_table, pdev->dev.of_node);
665 if (!match) 974 if (!match)
666 return -EINVAL; 975 return -EINVAL;
667 976
668 u3phy = devm_kzalloc(dev, sizeof(*u3phy), GFP_KERNEL); 977 tphy = devm_kzalloc(dev, sizeof(*tphy), GFP_KERNEL);
669 if (!u3phy) 978 if (!tphy)
670 return -ENOMEM; 979 return -ENOMEM;
671 980
672 u3phy->pdata = match->data; 981 tphy->pdata = match->data;
673 u3phy->nphys = of_get_child_count(np); 982 tphy->nphys = of_get_child_count(np);
674 u3phy->phys = devm_kcalloc(dev, u3phy->nphys, 983 tphy->phys = devm_kcalloc(dev, tphy->nphys,
675 sizeof(*u3phy->phys), GFP_KERNEL); 984 sizeof(*tphy->phys), GFP_KERNEL);
676 if (!u3phy->phys) 985 if (!tphy->phys)
677 return -ENOMEM; 986 return -ENOMEM;
678 987
679 u3phy->dev = dev; 988 tphy->dev = dev;
680 platform_set_drvdata(pdev, u3phy); 989 platform_set_drvdata(pdev, tphy);
681 990
682 if (u3phy->pdata->version == MT_PHY_V1) { 991 if (tphy->pdata->version == MTK_PHY_V1) {
683 /* get banks shared by multiple phys */ 992 /* get banks shared by multiple phys */
684 sif_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 993 sif_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
685 u3phy->sif_base = devm_ioremap_resource(dev, sif_res); 994 tphy->sif_base = devm_ioremap_resource(dev, sif_res);
686 if (IS_ERR(u3phy->sif_base)) { 995 if (IS_ERR(tphy->sif_base)) {
687 dev_err(dev, "failed to remap sif regs\n"); 996 dev_err(dev, "failed to remap sif regs\n");
688 return PTR_ERR(u3phy->sif_base); 997 return PTR_ERR(tphy->sif_base);
689 } 998 }
690 } 999 }
691 1000
692 /* it's deprecated, make it optional for backward compatibility */ 1001 /* it's deprecated, make it optional for backward compatibility */
693 u3phy->u3phya_ref = devm_clk_get(dev, "u3phya_ref"); 1002 tphy->u3phya_ref = devm_clk_get(dev, "u3phya_ref");
694 if (IS_ERR(u3phy->u3phya_ref)) { 1003 if (IS_ERR(tphy->u3phya_ref)) {
695 if (PTR_ERR(u3phy->u3phya_ref) == -EPROBE_DEFER) 1004 if (PTR_ERR(tphy->u3phya_ref) == -EPROBE_DEFER)
696 return -EPROBE_DEFER; 1005 return -EPROBE_DEFER;
697 1006
698 u3phy->u3phya_ref = NULL; 1007 tphy->u3phya_ref = NULL;
699 } 1008 }
700 1009
701 port = 0; 1010 port = 0;
702 for_each_child_of_node(np, child_np) { 1011 for_each_child_of_node(np, child_np) {
703 struct mt65xx_phy_instance *instance; 1012 struct mtk_phy_instance *instance;
704 struct phy *phy; 1013 struct phy *phy;
705 1014
706 instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL); 1015 instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL);
@@ -709,9 +1018,9 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
709 goto put_child; 1018 goto put_child;
710 } 1019 }
711 1020
712 u3phy->phys[port] = instance; 1021 tphy->phys[port] = instance;
713 1022
714 phy = devm_phy_create(dev, child_np, &mt65xx_u3phy_ops); 1023 phy = devm_phy_create(dev, child_np, &mtk_tphy_ops);
715 if (IS_ERR(phy)) { 1024 if (IS_ERR(phy)) {
716 dev_err(dev, "failed to create phy\n"); 1025 dev_err(dev, "failed to create phy\n");
717 retval = PTR_ERR(phy); 1026 retval = PTR_ERR(phy);
@@ -738,7 +1047,7 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
738 port++; 1047 port++;
739 1048
740 /* if deprecated clock is provided, ignore instance's one */ 1049 /* if deprecated clock is provided, ignore instance's one */
741 if (u3phy->u3phya_ref) 1050 if (tphy->u3phya_ref)
742 continue; 1051 continue;
743 1052
744 instance->ref_clk = devm_clk_get(&phy->dev, "ref"); 1053 instance->ref_clk = devm_clk_get(&phy->dev, "ref");
@@ -749,7 +1058,7 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
749 } 1058 }
750 } 1059 }
751 1060
752 provider = devm_of_phy_provider_register(dev, mt65xx_phy_xlate); 1061 provider = devm_of_phy_provider_register(dev, mtk_phy_xlate);
753 1062
754 return PTR_ERR_OR_ZERO(provider); 1063 return PTR_ERR_OR_ZERO(provider);
755put_child: 1064put_child:
@@ -757,16 +1066,16 @@ put_child:
757 return retval; 1066 return retval;
758} 1067}
759 1068
760static struct platform_driver mt65xx_u3phy_driver = { 1069static struct platform_driver mtk_tphy_driver = {
761 .probe = mt65xx_u3phy_probe, 1070 .probe = mtk_tphy_probe,
762 .driver = { 1071 .driver = {
763 .name = "mt65xx-u3phy", 1072 .name = "mtk-tphy",
764 .of_match_table = mt65xx_u3phy_id_table, 1073 .of_match_table = mtk_tphy_id_table,
765 }, 1074 },
766}; 1075};
767 1076
768module_platform_driver(mt65xx_u3phy_driver); 1077module_platform_driver(mtk_tphy_driver);
769 1078
770MODULE_AUTHOR("Chunfeng Yun <chunfeng.yun@mediatek.com>"); 1079MODULE_AUTHOR("Chunfeng Yun <chunfeng.yun@mediatek.com>");
771MODULE_DESCRIPTION("mt65xx USB PHY driver"); 1080MODULE_DESCRIPTION("MediaTek T-PHY driver");
772MODULE_LICENSE("GPL v2"); 1081MODULE_LICENSE("GPL v2");
diff --git a/drivers/phy/motorola/phy-cpcap-usb.c b/drivers/phy/motorola/phy-cpcap-usb.c
index 9b63efa5ae4d..accaaaccb662 100644
--- a/drivers/phy/motorola/phy-cpcap-usb.c
+++ b/drivers/phy/motorola/phy-cpcap-usb.c
@@ -506,7 +506,7 @@ static void cpcap_usb_init_optional_gpios(struct cpcap_phy_ddata *ddata)
506 if (IS_ERR(ddata->gpio[i])) { 506 if (IS_ERR(ddata->gpio[i])) {
507 dev_info(ddata->dev, "no mode change GPIO%i: %li\n", 507 dev_info(ddata->dev, "no mode change GPIO%i: %li\n",
508 i, PTR_ERR(ddata->gpio[i])); 508 i, PTR_ERR(ddata->gpio[i]));
509 ddata->gpio[i] = NULL; 509 ddata->gpio[i] = NULL;
510 } 510 }
511 } 511 }
512} 512}
diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c
index 78ca62897784..e17f0351ccc2 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp.c
@@ -59,6 +59,7 @@
59#define QSERDES_COM_PLL_RCTRL_MODE1 0x088 59#define QSERDES_COM_PLL_RCTRL_MODE1 0x088
60#define QSERDES_COM_PLL_CCTRL_MODE0 0x090 60#define QSERDES_COM_PLL_CCTRL_MODE0 0x090
61#define QSERDES_COM_PLL_CCTRL_MODE1 0x094 61#define QSERDES_COM_PLL_CCTRL_MODE1 0x094
62#define QSERDES_COM_BIAS_EN_CTRL_BY_PSM 0x0a8
62#define QSERDES_COM_SYSCLK_EN_SEL 0x0ac 63#define QSERDES_COM_SYSCLK_EN_SEL 0x0ac
63#define QSERDES_COM_RESETSM_CNTRL 0x0b4 64#define QSERDES_COM_RESETSM_CNTRL 0x0b4
64#define QSERDES_COM_RESTRIM_CTRL 0x0bc 65#define QSERDES_COM_RESTRIM_CTRL 0x0bc
@@ -143,6 +144,11 @@
143#define QPHY_LOCK_DETECT_CONFIG3 0x88 144#define QPHY_LOCK_DETECT_CONFIG3 0x88
144#define QPHY_PWRUP_RESET_DLY_TIME_AUXCLK 0xa0 145#define QPHY_PWRUP_RESET_DLY_TIME_AUXCLK 0xa0
145#define QPHY_LP_WAKEUP_DLY_TIME_AUXCLK 0xa4 146#define QPHY_LP_WAKEUP_DLY_TIME_AUXCLK 0xa4
147#define QPHY_PLL_LOCK_CHK_DLY_TIME_AUXCLK_LSB 0x1A8
148#define QPHY_OSC_DTCT_ACTIONS 0x1AC
149#define QPHY_RX_SIGDET_LVL 0x1D8
150#define QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB 0x1DC
151#define QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB 0x1E0
146 152
147/* QPHY_SW_RESET bit */ 153/* QPHY_SW_RESET bit */
148#define SW_RESET BIT(0) 154#define SW_RESET BIT(0)
@@ -382,6 +388,85 @@ static const struct qmp_phy_init_tbl msm8996_usb3_pcs_tbl[] = {
382 QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG2, 0x08), 388 QMP_PHY_INIT_CFG(QPHY_POWER_STATE_CONFIG2, 0x08),
383}; 389};
384 390
391static const struct qmp_phy_init_tbl ipq8074_pcie_serdes_tbl[] = {
392 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x18),
393 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_ENABLE1, 0x10),
394 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TRIM, 0xf),
395 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP_EN, 0x1),
396 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_MAP, 0x0),
397 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER1, 0x1f),
398 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_TIMER2, 0x3f),
399 QMP_PHY_INIT_CFG(QSERDES_COM_CMN_CONFIG, 0x6),
400 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_IVCO, 0xf),
401 QMP_PHY_INIT_CFG(QSERDES_COM_HSCLK_SEL, 0x0),
402 QMP_PHY_INIT_CFG(QSERDES_COM_SVS_MODE_CLK_SEL, 0x1),
403 QMP_PHY_INIT_CFG(QSERDES_COM_CORE_CLK_EN, 0x20),
404 QMP_PHY_INIT_CFG(QSERDES_COM_CORECLK_DIV, 0xa),
405 QMP_PHY_INIT_CFG(QSERDES_COM_RESETSM_CNTRL, 0x20),
406 QMP_PHY_INIT_CFG(QSERDES_COM_BG_TIMER, 0xa),
407 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_EN_SEL, 0xa),
408 QMP_PHY_INIT_CFG(QSERDES_COM_DEC_START_MODE0, 0x82),
409 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START3_MODE0, 0x3),
410 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START2_MODE0, 0x55),
411 QMP_PHY_INIT_CFG(QSERDES_COM_DIV_FRAC_START1_MODE0, 0x55),
412 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP3_MODE0, 0x0),
413 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP2_MODE0, 0xD),
414 QMP_PHY_INIT_CFG(QSERDES_COM_LOCK_CMP1_MODE0, 0xD04),
415 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_SELECT, 0x33),
416 QMP_PHY_INIT_CFG(QSERDES_COM_SYS_CLK_CTRL, 0x2),
417 QMP_PHY_INIT_CFG(QSERDES_COM_SYSCLK_BUF_ENABLE, 0x1f),
418 QMP_PHY_INIT_CFG(QSERDES_COM_CP_CTRL_MODE0, 0xb),
419 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_RCTRL_MODE0, 0x16),
420 QMP_PHY_INIT_CFG(QSERDES_COM_PLL_CCTRL_MODE0, 0x28),
421 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN1_MODE0, 0x0),
422 QMP_PHY_INIT_CFG(QSERDES_COM_INTEGLOOP_GAIN0_MODE0, 0x80),
423 QMP_PHY_INIT_CFG(QSERDES_COM_BIAS_EN_CTRL_BY_PSM, 0x1),
424 QMP_PHY_INIT_CFG(QSERDES_COM_VCO_TUNE_CTRL, 0xa),
425 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_EN_CENTER, 0x1),
426 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER1, 0x31),
427 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_PER2, 0x1),
428 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER1, 0x2),
429 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_ADJ_PER2, 0x0),
430 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE1, 0x2f),
431 QMP_PHY_INIT_CFG(QSERDES_COM_SSC_STEP_SIZE2, 0x19),
432 QMP_PHY_INIT_CFG(QSERDES_COM_CLK_EP_DIV, 0x19),
433 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_CNTRL, 0x7),
434};
435
436static const struct qmp_phy_init_tbl ipq8074_pcie_tx_tbl[] = {
437 QMP_PHY_INIT_CFG(QSERDES_TX_HIGHZ_TRANSCEIVEREN_BIAS_DRVR_EN, 0x45),
438 QMP_PHY_INIT_CFG(QSERDES_TX_LANE_MODE, 0x6),
439 QMP_PHY_INIT_CFG(QSERDES_TX_RES_CODE_LANE_OFFSET, 0x2),
440 QMP_PHY_INIT_CFG(QSERDES_TX_RCV_DETECT_LVL_2, 0x12),
441};
442
443static const struct qmp_phy_init_tbl ipq8074_pcie_rx_tbl[] = {
444 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_ENABLES, 0x1c),
445 QMP_PHY_INIT_CFG(QSERDES_RX_SIGDET_DEGLITCH_CNTRL, 0x14),
446 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL2, 0x1),
447 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL3, 0x0),
448 QMP_PHY_INIT_CFG(QSERDES_RX_RX_EQU_ADAPTOR_CNTRL4, 0xdb),
449 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_SATURATION_AND_ENABLE, 0x4b),
450 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN, 0x4),
451 QMP_PHY_INIT_CFG(QSERDES_RX_UCDR_SO_GAIN_HALF, 0x4),
452};
453
454static const struct qmp_phy_init_tbl ipq8074_pcie_pcs_tbl[] = {
455 QMP_PHY_INIT_CFG(QPHY_ENDPOINT_REFCLK_DRIVE, 0x4),
456 QMP_PHY_INIT_CFG(QPHY_OSC_DTCT_ACTIONS, 0x0),
457 QMP_PHY_INIT_CFG(QPHY_PWRUP_RESET_DLY_TIME_AUXCLK, 0x40),
458 QMP_PHY_INIT_CFG(QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_MSB, 0x0),
459 QMP_PHY_INIT_CFG(QPHY_L1SS_WAKEUP_DLY_TIME_AUXCLK_LSB, 0x40),
460 QMP_PHY_INIT_CFG(QPHY_PLL_LOCK_CHK_DLY_TIME_AUXCLK_LSB, 0x0),
461 QMP_PHY_INIT_CFG(QPHY_LP_WAKEUP_DLY_TIME_AUXCLK, 0x40),
462 QMP_PHY_INIT_CFG_L(QPHY_PLL_LOCK_CHK_DLY_TIME, 0x73),
463 QMP_PHY_INIT_CFG(QPHY_RX_SIGDET_LVL, 0x99),
464 QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M6DB_V0, 0x15),
465 QMP_PHY_INIT_CFG(QPHY_TXDEEMPH_M3P5DB_V0, 0xe),
466 QMP_PHY_INIT_CFG_L(QPHY_SW_RESET, 0x0),
467 QMP_PHY_INIT_CFG_L(QPHY_START_CTRL, 0x3),
468};
469
385/* struct qmp_phy_cfg - per-PHY initialization config */ 470/* struct qmp_phy_cfg - per-PHY initialization config */
386struct qmp_phy_cfg { 471struct qmp_phy_cfg {
387 /* phy-type - PCIE/UFS/USB */ 472 /* phy-type - PCIE/UFS/USB */
@@ -580,6 +665,42 @@ static const struct qmp_phy_cfg msm8996_usb3phy_cfg = {
580 .mask_pcs_ready = PHYSTATUS, 665 .mask_pcs_ready = PHYSTATUS,
581}; 666};
582 667
668/* list of resets */
669static const char * const ipq8074_pciephy_reset_l[] = {
670 "phy", "common",
671};
672
673static const struct qmp_phy_cfg ipq8074_pciephy_cfg = {
674 .type = PHY_TYPE_PCIE,
675 .nlanes = 1,
676
677 .serdes_tbl = ipq8074_pcie_serdes_tbl,
678 .serdes_tbl_num = ARRAY_SIZE(ipq8074_pcie_serdes_tbl),
679 .tx_tbl = ipq8074_pcie_tx_tbl,
680 .tx_tbl_num = ARRAY_SIZE(ipq8074_pcie_tx_tbl),
681 .rx_tbl = ipq8074_pcie_rx_tbl,
682 .rx_tbl_num = ARRAY_SIZE(ipq8074_pcie_rx_tbl),
683 .pcs_tbl = ipq8074_pcie_pcs_tbl,
684 .pcs_tbl_num = ARRAY_SIZE(ipq8074_pcie_pcs_tbl),
685 .clk_list = NULL,
686 .num_clks = 0,
687 .reset_list = ipq8074_pciephy_reset_l,
688 .num_resets = ARRAY_SIZE(ipq8074_pciephy_reset_l),
689 .vreg_list = NULL,
690 .num_vregs = 0,
691 .regs = pciephy_regs_layout,
692
693 .start_ctrl = SERDES_START | PCS_START,
694 .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL,
695 .mask_pcs_ready = PHYSTATUS,
696
697 .has_phy_com_ctrl = false,
698 .has_lane_rst = false,
699 .has_pwrdn_delay = true,
700 .pwrdn_delay_min = 995, /* us */
701 .pwrdn_delay_max = 1005, /* us */
702};
703
583static void qcom_qmp_phy_configure(void __iomem *base, 704static void qcom_qmp_phy_configure(void __iomem *base,
584 const unsigned int *regs, 705 const unsigned int *regs,
585 const struct qmp_phy_init_tbl tbl[], 706 const struct qmp_phy_init_tbl tbl[],
@@ -654,8 +775,6 @@ static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
654 if (ret) { 775 if (ret) {
655 dev_err(qmp->dev, "%s reset deassert failed\n", 776 dev_err(qmp->dev, "%s reset deassert failed\n",
656 qmp->cfg->reset_list[i]); 777 qmp->cfg->reset_list[i]);
657 while (--i >= 0)
658 reset_control_assert(qmp->resets[i]);
659 goto err_rst; 778 goto err_rst;
660 } 779 }
661 } 780 }
@@ -684,7 +803,7 @@ static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
684 if (ret) { 803 if (ret) {
685 dev_err(qmp->dev, 804 dev_err(qmp->dev,
686 "phy common block init timed-out\n"); 805 "phy common block init timed-out\n");
687 goto err_com_init; 806 goto err_rst;
688 } 807 }
689 } 808 }
690 809
@@ -692,11 +811,11 @@ static int qcom_qmp_phy_com_init(struct qcom_qmp *qmp)
692 811
693 return 0; 812 return 0;
694 813
695err_com_init: 814err_rst:
696 while (--i >= 0) 815 while (--i >= 0)
697 reset_control_assert(qmp->resets[i]); 816 reset_control_assert(qmp->resets[i]);
698err_rst:
699 mutex_unlock(&qmp->phy_mutex); 817 mutex_unlock(&qmp->phy_mutex);
818
700 return ret; 819 return ret;
701} 820}
702 821
@@ -749,14 +868,13 @@ static int qcom_qmp_phy_init(struct phy *phy)
749 if (ret) { 868 if (ret) {
750 dev_err(qmp->dev, "failed to enable %s clk, err=%d\n", 869 dev_err(qmp->dev, "failed to enable %s clk, err=%d\n",
751 qmp->cfg->clk_list[i], ret); 870 qmp->cfg->clk_list[i], ret);
752 while (--i >= 0) 871 goto err_clk;
753 clk_disable_unprepare(qmp->clks[i]);
754 } 872 }
755 } 873 }
756 874
757 ret = qcom_qmp_phy_com_init(qmp); 875 ret = qcom_qmp_phy_com_init(qmp);
758 if (ret) 876 if (ret)
759 goto err_com_init; 877 goto err_clk;
760 878
761 if (cfg->has_lane_rst) { 879 if (cfg->has_lane_rst) {
762 ret = reset_control_deassert(qphy->lane_rst); 880 ret = reset_control_deassert(qphy->lane_rst);
@@ -804,7 +922,7 @@ err_pcs_ready:
804 reset_control_assert(qphy->lane_rst); 922 reset_control_assert(qphy->lane_rst);
805err_lane_rst: 923err_lane_rst:
806 qcom_qmp_phy_com_exit(qmp); 924 qcom_qmp_phy_com_exit(qmp);
807err_com_init: 925err_clk:
808 while (--i >= 0) 926 while (--i >= 0)
809 clk_disable_unprepare(qmp->clks[i]); 927 clk_disable_unprepare(qmp->clks[i]);
810 928
@@ -925,29 +1043,28 @@ static int qcom_qmp_phy_clk_init(struct device *dev)
925 * clk | +-------+ | +-----+ 1043 * clk | +-------+ | +-----+
926 * +---------------+ 1044 * +---------------+
927 */ 1045 */
928static int phy_pipe_clk_register(struct qcom_qmp *qmp, int id) 1046static int phy_pipe_clk_register(struct qcom_qmp *qmp, struct device_node *np)
929{ 1047{
930 char name[24];
931 struct clk_fixed_rate *fixed; 1048 struct clk_fixed_rate *fixed;
932 struct clk_init_data init = { }; 1049 struct clk_init_data init = { };
1050 int ret;
933 1051
934 switch (qmp->cfg->type) { 1052 if ((qmp->cfg->type != PHY_TYPE_USB3) &&
935 case PHY_TYPE_USB3: 1053 (qmp->cfg->type != PHY_TYPE_PCIE)) {
936 snprintf(name, sizeof(name), "usb3_phy_pipe_clk_src");
937 break;
938 case PHY_TYPE_PCIE:
939 snprintf(name, sizeof(name), "pcie_%d_pipe_clk_src", id);
940 break;
941 default:
942 /* not all phys register pipe clocks, so return success */ 1054 /* not all phys register pipe clocks, so return success */
943 return 0; 1055 return 0;
944 } 1056 }
945 1057
1058 ret = of_property_read_string(np, "clock-output-names", &init.name);
1059 if (ret) {
1060 dev_err(qmp->dev, "%s: No clock-output-names\n", np->name);
1061 return ret;
1062 }
1063
946 fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL); 1064 fixed = devm_kzalloc(qmp->dev, sizeof(*fixed), GFP_KERNEL);
947 if (!fixed) 1065 if (!fixed)
948 return -ENOMEM; 1066 return -ENOMEM;
949 1067
950 init.name = name;
951 init.ops = &clk_fixed_rate_ops; 1068 init.ops = &clk_fixed_rate_ops;
952 1069
953 /* controllers using QMP phys use 125MHz pipe clock interface */ 1070 /* controllers using QMP phys use 125MHz pipe clock interface */
@@ -1049,6 +1166,9 @@ static const struct of_device_id qcom_qmp_phy_of_match_table[] = {
1049 }, { 1166 }, {
1050 .compatible = "qcom,msm8996-qmp-usb3-phy", 1167 .compatible = "qcom,msm8996-qmp-usb3-phy",
1051 .data = &msm8996_usb3phy_cfg, 1168 .data = &msm8996_usb3phy_cfg,
1169 }, {
1170 .compatible = "qcom,ipq8074-qmp-pcie-phy",
1171 .data = &ipq8074_pciephy_cfg,
1052 }, 1172 },
1053 { }, 1173 { },
1054}; 1174};
@@ -1122,7 +1242,7 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev)
1122 * Register the pipe clock provided by phy. 1242 * Register the pipe clock provided by phy.
1123 * See function description to see details of this pipe clock. 1243 * See function description to see details of this pipe clock.
1124 */ 1244 */
1125 ret = phy_pipe_clk_register(qmp, id); 1245 ret = phy_pipe_clk_register(qmp, child);
1126 if (ret) { 1246 if (ret) {
1127 dev_err(qmp->dev, 1247 dev_err(qmp->dev,
1128 "failed to register pipe clock source\n"); 1248 "failed to register pipe clock source\n");
diff --git a/drivers/phy/ralink/Kconfig b/drivers/phy/ralink/Kconfig
new file mode 100644
index 000000000000..b17635b407bc
--- /dev/null
+++ b/drivers/phy/ralink/Kconfig
@@ -0,0 +1,11 @@
1#
2# PHY drivers for Ralink platforms.
3#
4config PHY_RALINK_USB
5 tristate "Ralink USB PHY driver"
6 depends on RALINK || COMPILE_TEST
7 select GENERIC_PHY
8 select MFD_SYSCON
9 help
10 This option enables support for the Ralink USB PHY found inside
11 RT3352, MT7620, MT7628 and MT7688.
diff --git a/drivers/phy/ralink/Makefile b/drivers/phy/ralink/Makefile
new file mode 100644
index 000000000000..5c9e326e8757
--- /dev/null
+++ b/drivers/phy/ralink/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_PHY_RALINK_USB) += phy-ralink-usb.o
diff --git a/drivers/phy/ralink/phy-ralink-usb.c b/drivers/phy/ralink/phy-ralink-usb.c
new file mode 100644
index 000000000000..4fea31f8ac1c
--- /dev/null
+++ b/drivers/phy/ralink/phy-ralink-usb.c
@@ -0,0 +1,249 @@
1/*
2 * Copyright (C) 2017 John Crispin <john@phrozen.org>
3 *
4 * Based on code from
5 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/delay.h>
19#include <linux/err.h>
20#include <linux/io.h>
21#include <linux/kernel.h>
22#include <linux/mfd/syscon.h>
23#include <linux/module.h>
24#include <linux/mutex.h>
25#include <linux/of_platform.h>
26#include <linux/phy/phy.h>
27#include <linux/platform_device.h>
28#include <linux/regmap.h>
29#include <linux/reset.h>
30
31#define RT_SYSC_REG_SYSCFG1 0x014
32#define RT_SYSC_REG_CLKCFG1 0x030
33#define RT_SYSC_REG_USB_PHY_CFG 0x05c
34
35#define OFS_U2_PHY_AC0 0x800
36#define OFS_U2_PHY_AC1 0x804
37#define OFS_U2_PHY_AC2 0x808
38#define OFS_U2_PHY_ACR0 0x810
39#define OFS_U2_PHY_ACR1 0x814
40#define OFS_U2_PHY_ACR2 0x818
41#define OFS_U2_PHY_ACR3 0x81C
42#define OFS_U2_PHY_ACR4 0x820
43#define OFS_U2_PHY_AMON0 0x824
44#define OFS_U2_PHY_DCR0 0x860
45#define OFS_U2_PHY_DCR1 0x864
46#define OFS_U2_PHY_DTM0 0x868
47#define OFS_U2_PHY_DTM1 0x86C
48
49#define RT_RSTCTRL_UDEV BIT(25)
50#define RT_RSTCTRL_UHST BIT(22)
51#define RT_SYSCFG1_USB0_HOST_MODE BIT(10)
52
53#define MT7620_CLKCFG1_UPHY0_CLK_EN BIT(25)
54#define MT7620_CLKCFG1_UPHY1_CLK_EN BIT(22)
55#define RT_CLKCFG1_UPHY1_CLK_EN BIT(20)
56#define RT_CLKCFG1_UPHY0_CLK_EN BIT(18)
57
58#define USB_PHY_UTMI_8B60M BIT(1)
59#define UDEV_WAKEUP BIT(0)
60
61struct ralink_usb_phy {
62 struct reset_control *rstdev;
63 struct reset_control *rsthost;
64 u32 clk;
65 struct phy *phy;
66 void __iomem *base;
67 struct regmap *sysctl;
68};
69
70static void u2_phy_w32(struct ralink_usb_phy *phy, u32 val, u32 reg)
71{
72 writel(val, phy->base + reg);
73}
74
75static u32 u2_phy_r32(struct ralink_usb_phy *phy, u32 reg)
76{
77 return readl(phy->base + reg);
78}
79
80static void ralink_usb_phy_init(struct ralink_usb_phy *phy)
81{
82 u2_phy_r32(phy, OFS_U2_PHY_AC2);
83 u2_phy_r32(phy, OFS_U2_PHY_ACR0);
84 u2_phy_r32(phy, OFS_U2_PHY_DCR0);
85
86 u2_phy_w32(phy, 0x00ffff02, OFS_U2_PHY_DCR0);
87 u2_phy_r32(phy, OFS_U2_PHY_DCR0);
88 u2_phy_w32(phy, 0x00555502, OFS_U2_PHY_DCR0);
89 u2_phy_r32(phy, OFS_U2_PHY_DCR0);
90 u2_phy_w32(phy, 0x00aaaa02, OFS_U2_PHY_DCR0);
91 u2_phy_r32(phy, OFS_U2_PHY_DCR0);
92 u2_phy_w32(phy, 0x00000402, OFS_U2_PHY_DCR0);
93 u2_phy_r32(phy, OFS_U2_PHY_DCR0);
94 u2_phy_w32(phy, 0x0048086a, OFS_U2_PHY_AC0);
95 u2_phy_w32(phy, 0x4400001c, OFS_U2_PHY_AC1);
96 u2_phy_w32(phy, 0xc0200000, OFS_U2_PHY_ACR3);
97 u2_phy_w32(phy, 0x02000000, OFS_U2_PHY_DTM0);
98}
99
100static int ralink_usb_phy_power_on(struct phy *_phy)
101{
102 struct ralink_usb_phy *phy = phy_get_drvdata(_phy);
103 u32 t;
104
105 /* enable the phy */
106 regmap_update_bits(phy->sysctl, RT_SYSC_REG_CLKCFG1,
107 phy->clk, phy->clk);
108
109 /* setup host mode */
110 regmap_update_bits(phy->sysctl, RT_SYSC_REG_SYSCFG1,
111 RT_SYSCFG1_USB0_HOST_MODE,
112 RT_SYSCFG1_USB0_HOST_MODE);
113
114 /* deassert the reset lines */
115 reset_control_deassert(phy->rsthost);
116 reset_control_deassert(phy->rstdev);
117
118 /*
119 * The SDK kernel had a delay of 100ms. however on device
120 * testing showed that 10ms is enough
121 */
122 mdelay(10);
123
124 if (phy->base)
125 ralink_usb_phy_init(phy);
126
127 /* print some status info */
128 regmap_read(phy->sysctl, RT_SYSC_REG_USB_PHY_CFG, &t);
129 dev_info(&phy->phy->dev, "remote usb device wakeup %s\n",
130 (t & UDEV_WAKEUP) ? ("enabled") : ("disabled"));
131 if (t & USB_PHY_UTMI_8B60M)
132 dev_info(&phy->phy->dev, "UTMI 8bit 60MHz\n");
133 else
134 dev_info(&phy->phy->dev, "UTMI 16bit 30MHz\n");
135
136 return 0;
137}
138
139static int ralink_usb_phy_power_off(struct phy *_phy)
140{
141 struct ralink_usb_phy *phy = phy_get_drvdata(_phy);
142
143 /* disable the phy */
144 regmap_update_bits(phy->sysctl, RT_SYSC_REG_CLKCFG1,
145 phy->clk, 0);
146
147 /* assert the reset lines */
148 reset_control_assert(phy->rstdev);
149 reset_control_assert(phy->rsthost);
150
151 return 0;
152}
153
154static struct phy_ops ralink_usb_phy_ops = {
155 .power_on = ralink_usb_phy_power_on,
156 .power_off = ralink_usb_phy_power_off,
157 .owner = THIS_MODULE,
158};
159
160static const struct of_device_id ralink_usb_phy_of_match[] = {
161 {
162 .compatible = "ralink,rt3352-usbphy",
163 .data = (void *)(uintptr_t)(RT_CLKCFG1_UPHY1_CLK_EN |
164 RT_CLKCFG1_UPHY0_CLK_EN)
165 },
166 {
167 .compatible = "mediatek,mt7620-usbphy",
168 .data = (void *)(uintptr_t)(MT7620_CLKCFG1_UPHY1_CLK_EN |
169 MT7620_CLKCFG1_UPHY0_CLK_EN)
170 },
171 {
172 .compatible = "mediatek,mt7628-usbphy",
173 .data = (void *)(uintptr_t)(MT7620_CLKCFG1_UPHY1_CLK_EN |
174 MT7620_CLKCFG1_UPHY0_CLK_EN) },
175 { },
176};
177MODULE_DEVICE_TABLE(of, ralink_usb_phy_of_match);
178
179static int ralink_usb_phy_probe(struct platform_device *pdev)
180{
181 struct device *dev = &pdev->dev;
182 struct resource *res;
183 struct phy_provider *phy_provider;
184 const struct of_device_id *match;
185 struct ralink_usb_phy *phy;
186
187 match = of_match_device(ralink_usb_phy_of_match, &pdev->dev);
188 if (!match)
189 return -ENODEV;
190
191 phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
192 if (!phy)
193 return -ENOMEM;
194
195 phy->clk = (uintptr_t)match->data;
196 phy->base = NULL;
197
198 phy->sysctl = syscon_regmap_lookup_by_phandle(dev->of_node, "ralink,sysctl");
199 if (IS_ERR(phy->sysctl)) {
200 dev_err(dev, "failed to get sysctl registers\n");
201 return PTR_ERR(phy->sysctl);
202 }
203
204 /* The MT7628 and MT7688 require extra setup of PHY registers. */
205 if (of_device_is_compatible(dev->of_node, "mediatek,mt7628-usbphy")) {
206 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
207 phy->base = devm_ioremap_resource(&pdev->dev, res);
208 if (IS_ERR(phy->base)) {
209 dev_err(dev, "failed to remap register memory\n");
210 return PTR_ERR(phy->base);
211 }
212 }
213
214 phy->rsthost = devm_reset_control_get(&pdev->dev, "host");
215 if (IS_ERR(phy->rsthost)) {
216 dev_err(dev, "host reset is missing\n");
217 return PTR_ERR(phy->rsthost);
218 }
219
220 phy->rstdev = devm_reset_control_get(&pdev->dev, "device");
221 if (IS_ERR(phy->rstdev)) {
222 dev_err(dev, "device reset is missing\n");
223 return PTR_ERR(phy->rstdev);
224 }
225
226 phy->phy = devm_phy_create(dev, NULL, &ralink_usb_phy_ops);
227 if (IS_ERR(phy->phy)) {
228 dev_err(dev, "failed to create PHY\n");
229 return PTR_ERR(phy->phy);
230 }
231 phy_set_drvdata(phy->phy, phy);
232
233 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
234
235 return PTR_ERR_OR_ZERO(phy_provider);
236}
237
238static struct platform_driver ralink_usb_phy_driver = {
239 .probe = ralink_usb_phy_probe,
240 .driver = {
241 .of_match_table = ralink_usb_phy_of_match,
242 .name = "ralink-usb-phy",
243 }
244};
245module_platform_driver(ralink_usb_phy_driver);
246
247MODULE_DESCRIPTION("Ralink USB phy driver");
248MODULE_AUTHOR("John Crispin <john@phrozen.org>");
249MODULE_LICENSE("GPL v2");
diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index 626883d9d176..994cc1a08f50 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -172,6 +172,8 @@ struct rockchip_usb2phy_cfg {
172 * @vbus_attached: otg device vbus status. 172 * @vbus_attached: otg device vbus status.
173 * @bvalid_irq: IRQ number assigned for vbus valid rise detection. 173 * @bvalid_irq: IRQ number assigned for vbus valid rise detection.
174 * @ls_irq: IRQ number assigned for linestate detection. 174 * @ls_irq: IRQ number assigned for linestate detection.
175 * @otg_mux_irq: IRQ number which multiplex otg-id/otg-bvalid/linestate
176 * irqs to one irq in otg-port.
175 * @mutex: for register updating in sm_work. 177 * @mutex: for register updating in sm_work.
176 * @chg_work: charge detect work. 178 * @chg_work: charge detect work.
177 * @otg_sm_work: OTG state machine work. 179 * @otg_sm_work: OTG state machine work.
@@ -189,6 +191,7 @@ struct rockchip_usb2phy_port {
189 bool vbus_attached; 191 bool vbus_attached;
190 int bvalid_irq; 192 int bvalid_irq;
191 int ls_irq; 193 int ls_irq;
194 int otg_mux_irq;
192 struct mutex mutex; 195 struct mutex mutex;
193 struct delayed_work chg_work; 196 struct delayed_work chg_work;
194 struct delayed_work otg_sm_work; 197 struct delayed_work otg_sm_work;
@@ -202,6 +205,7 @@ struct rockchip_usb2phy_port {
202/** 205/**
203 * struct rockchip_usb2phy: usb2.0 phy driver data. 206 * struct rockchip_usb2phy: usb2.0 phy driver data.
204 * @grf: General Register Files regmap. 207 * @grf: General Register Files regmap.
208 * @usbgrf: USB General Register Files regmap.
205 * @clk: clock struct of phy input clk. 209 * @clk: clock struct of phy input clk.
206 * @clk480m: clock struct of phy output clk. 210 * @clk480m: clock struct of phy output clk.
207 * @clk_hw: clock struct of phy output clk management. 211 * @clk_hw: clock struct of phy output clk management.
@@ -216,6 +220,7 @@ struct rockchip_usb2phy_port {
216struct rockchip_usb2phy { 220struct rockchip_usb2phy {
217 struct device *dev; 221 struct device *dev;
218 struct regmap *grf; 222 struct regmap *grf;
223 struct regmap *usbgrf;
219 struct clk *clk; 224 struct clk *clk;
220 struct clk *clk480m; 225 struct clk *clk480m;
221 struct clk_hw clk480m_hw; 226 struct clk_hw clk480m_hw;
@@ -227,7 +232,12 @@ struct rockchip_usb2phy {
227 struct rockchip_usb2phy_port ports[USB2PHY_NUM_PORTS]; 232 struct rockchip_usb2phy_port ports[USB2PHY_NUM_PORTS];
228}; 233};
229 234
230static inline int property_enable(struct rockchip_usb2phy *rphy, 235static inline struct regmap *get_reg_base(struct rockchip_usb2phy *rphy)
236{
237 return rphy->usbgrf == NULL ? rphy->grf : rphy->usbgrf;
238}
239
240static inline int property_enable(struct regmap *base,
231 const struct usb2phy_reg *reg, bool en) 241 const struct usb2phy_reg *reg, bool en)
232{ 242{
233 unsigned int val, mask, tmp; 243 unsigned int val, mask, tmp;
@@ -236,17 +246,17 @@ static inline int property_enable(struct rockchip_usb2phy *rphy,
236 mask = GENMASK(reg->bitend, reg->bitstart); 246 mask = GENMASK(reg->bitend, reg->bitstart);
237 val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT); 247 val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);
238 248
239 return regmap_write(rphy->grf, reg->offset, val); 249 return regmap_write(base, reg->offset, val);
240} 250}
241 251
242static inline bool property_enabled(struct rockchip_usb2phy *rphy, 252static inline bool property_enabled(struct regmap *base,
243 const struct usb2phy_reg *reg) 253 const struct usb2phy_reg *reg)
244{ 254{
245 int ret; 255 int ret;
246 unsigned int tmp, orig; 256 unsigned int tmp, orig;
247 unsigned int mask = GENMASK(reg->bitend, reg->bitstart); 257 unsigned int mask = GENMASK(reg->bitend, reg->bitstart);
248 258
249 ret = regmap_read(rphy->grf, reg->offset, &orig); 259 ret = regmap_read(base, reg->offset, &orig);
250 if (ret) 260 if (ret)
251 return false; 261 return false;
252 262
@@ -258,11 +268,12 @@ static int rockchip_usb2phy_clk480m_prepare(struct clk_hw *hw)
258{ 268{
259 struct rockchip_usb2phy *rphy = 269 struct rockchip_usb2phy *rphy =
260 container_of(hw, struct rockchip_usb2phy, clk480m_hw); 270 container_of(hw, struct rockchip_usb2phy, clk480m_hw);
271 struct regmap *base = get_reg_base(rphy);
261 int ret; 272 int ret;
262 273
263 /* turn on 480m clk output if it is off */ 274 /* turn on 480m clk output if it is off */
264 if (!property_enabled(rphy, &rphy->phy_cfg->clkout_ctl)) { 275 if (!property_enabled(base, &rphy->phy_cfg->clkout_ctl)) {
265 ret = property_enable(rphy, &rphy->phy_cfg->clkout_ctl, true); 276 ret = property_enable(base, &rphy->phy_cfg->clkout_ctl, true);
266 if (ret) 277 if (ret)
267 return ret; 278 return ret;
268 279
@@ -277,17 +288,19 @@ static void rockchip_usb2phy_clk480m_unprepare(struct clk_hw *hw)
277{ 288{
278 struct rockchip_usb2phy *rphy = 289 struct rockchip_usb2phy *rphy =
279 container_of(hw, struct rockchip_usb2phy, clk480m_hw); 290 container_of(hw, struct rockchip_usb2phy, clk480m_hw);
291 struct regmap *base = get_reg_base(rphy);
280 292
281 /* turn off 480m clk output */ 293 /* turn off 480m clk output */
282 property_enable(rphy, &rphy->phy_cfg->clkout_ctl, false); 294 property_enable(base, &rphy->phy_cfg->clkout_ctl, false);
283} 295}
284 296
285static int rockchip_usb2phy_clk480m_prepared(struct clk_hw *hw) 297static int rockchip_usb2phy_clk480m_prepared(struct clk_hw *hw)
286{ 298{
287 struct rockchip_usb2phy *rphy = 299 struct rockchip_usb2phy *rphy =
288 container_of(hw, struct rockchip_usb2phy, clk480m_hw); 300 container_of(hw, struct rockchip_usb2phy, clk480m_hw);
301 struct regmap *base = get_reg_base(rphy);
289 302
290 return property_enabled(rphy, &rphy->phy_cfg->clkout_ctl); 303 return property_enabled(base, &rphy->phy_cfg->clkout_ctl);
291} 304}
292 305
293static unsigned long 306static unsigned long
@@ -409,13 +422,13 @@ static int rockchip_usb2phy_init(struct phy *phy)
409 if (rport->mode != USB_DR_MODE_HOST && 422 if (rport->mode != USB_DR_MODE_HOST &&
410 rport->mode != USB_DR_MODE_UNKNOWN) { 423 rport->mode != USB_DR_MODE_UNKNOWN) {
411 /* clear bvalid status and enable bvalid detect irq */ 424 /* clear bvalid status and enable bvalid detect irq */
412 ret = property_enable(rphy, 425 ret = property_enable(rphy->grf,
413 &rport->port_cfg->bvalid_det_clr, 426 &rport->port_cfg->bvalid_det_clr,
414 true); 427 true);
415 if (ret) 428 if (ret)
416 goto out; 429 goto out;
417 430
418 ret = property_enable(rphy, 431 ret = property_enable(rphy->grf,
419 &rport->port_cfg->bvalid_det_en, 432 &rport->port_cfg->bvalid_det_en,
420 true); 433 true);
421 if (ret) 434 if (ret)
@@ -429,11 +442,13 @@ static int rockchip_usb2phy_init(struct phy *phy)
429 } 442 }
430 } else if (rport->port_id == USB2PHY_PORT_HOST) { 443 } else if (rport->port_id == USB2PHY_PORT_HOST) {
431 /* clear linestate and enable linestate detect irq */ 444 /* clear linestate and enable linestate detect irq */
432 ret = property_enable(rphy, &rport->port_cfg->ls_det_clr, true); 445 ret = property_enable(rphy->grf,
446 &rport->port_cfg->ls_det_clr, true);
433 if (ret) 447 if (ret)
434 goto out; 448 goto out;
435 449
436 ret = property_enable(rphy, &rport->port_cfg->ls_det_en, true); 450 ret = property_enable(rphy->grf,
451 &rport->port_cfg->ls_det_en, true);
437 if (ret) 452 if (ret)
438 goto out; 453 goto out;
439 454
@@ -449,6 +464,7 @@ static int rockchip_usb2phy_power_on(struct phy *phy)
449{ 464{
450 struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy); 465 struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
451 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); 466 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
467 struct regmap *base = get_reg_base(rphy);
452 int ret; 468 int ret;
453 469
454 dev_dbg(&rport->phy->dev, "port power on\n"); 470 dev_dbg(&rport->phy->dev, "port power on\n");
@@ -460,7 +476,7 @@ static int rockchip_usb2phy_power_on(struct phy *phy)
460 if (ret) 476 if (ret)
461 return ret; 477 return ret;
462 478
463 ret = property_enable(rphy, &rport->port_cfg->phy_sus, false); 479 ret = property_enable(base, &rport->port_cfg->phy_sus, false);
464 if (ret) 480 if (ret)
465 return ret; 481 return ret;
466 482
@@ -475,6 +491,7 @@ static int rockchip_usb2phy_power_off(struct phy *phy)
475{ 491{
476 struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy); 492 struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
477 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); 493 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
494 struct regmap *base = get_reg_base(rphy);
478 int ret; 495 int ret;
479 496
480 dev_dbg(&rport->phy->dev, "port power off\n"); 497 dev_dbg(&rport->phy->dev, "port power off\n");
@@ -482,7 +499,7 @@ static int rockchip_usb2phy_power_off(struct phy *phy)
482 if (rport->suspended) 499 if (rport->suspended)
483 return 0; 500 return 0;
484 501
485 ret = property_enable(rphy, &rport->port_cfg->phy_sus, true); 502 ret = property_enable(base, &rport->port_cfg->phy_sus, true);
486 if (ret) 503 if (ret)
487 return ret; 504 return ret;
488 505
@@ -526,11 +543,11 @@ static void rockchip_usb2phy_otg_sm_work(struct work_struct *work)
526 bool vbus_attach, sch_work, notify_charger; 543 bool vbus_attach, sch_work, notify_charger;
527 544
528 if (rport->utmi_avalid) 545 if (rport->utmi_avalid)
529 vbus_attach = 546 vbus_attach = property_enabled(rphy->grf,
530 property_enabled(rphy, &rport->port_cfg->utmi_avalid); 547 &rport->port_cfg->utmi_avalid);
531 else 548 else
532 vbus_attach = 549 vbus_attach = property_enabled(rphy->grf,
533 property_enabled(rphy, &rport->port_cfg->utmi_bvalid); 550 &rport->port_cfg->utmi_bvalid);
534 551
535 sch_work = false; 552 sch_work = false;
536 notify_charger = false; 553 notify_charger = false;
@@ -650,22 +667,28 @@ static const char *chg_to_string(enum power_supply_type chg_type)
650static void rockchip_chg_enable_dcd(struct rockchip_usb2phy *rphy, 667static void rockchip_chg_enable_dcd(struct rockchip_usb2phy *rphy,
651 bool en) 668 bool en)
652{ 669{
653 property_enable(rphy, &rphy->phy_cfg->chg_det.rdm_pdwn_en, en); 670 struct regmap *base = get_reg_base(rphy);
654 property_enable(rphy, &rphy->phy_cfg->chg_det.idp_src_en, en); 671
672 property_enable(base, &rphy->phy_cfg->chg_det.rdm_pdwn_en, en);
673 property_enable(base, &rphy->phy_cfg->chg_det.idp_src_en, en);
655} 674}
656 675
657static void rockchip_chg_enable_primary_det(struct rockchip_usb2phy *rphy, 676static void rockchip_chg_enable_primary_det(struct rockchip_usb2phy *rphy,
658 bool en) 677 bool en)
659{ 678{
660 property_enable(rphy, &rphy->phy_cfg->chg_det.vdp_src_en, en); 679 struct regmap *base = get_reg_base(rphy);
661 property_enable(rphy, &rphy->phy_cfg->chg_det.idm_sink_en, en); 680
681 property_enable(base, &rphy->phy_cfg->chg_det.vdp_src_en, en);
682 property_enable(base, &rphy->phy_cfg->chg_det.idm_sink_en, en);
662} 683}
663 684
664static void rockchip_chg_enable_secondary_det(struct rockchip_usb2phy *rphy, 685static void rockchip_chg_enable_secondary_det(struct rockchip_usb2phy *rphy,
665 bool en) 686 bool en)
666{ 687{
667 property_enable(rphy, &rphy->phy_cfg->chg_det.vdm_src_en, en); 688 struct regmap *base = get_reg_base(rphy);
668 property_enable(rphy, &rphy->phy_cfg->chg_det.idp_sink_en, en); 689
690 property_enable(base, &rphy->phy_cfg->chg_det.vdm_src_en, en);
691 property_enable(base, &rphy->phy_cfg->chg_det.idp_sink_en, en);
669} 692}
670 693
671#define CHG_DCD_POLL_TIME (100 * HZ / 1000) 694#define CHG_DCD_POLL_TIME (100 * HZ / 1000)
@@ -677,6 +700,7 @@ static void rockchip_chg_detect_work(struct work_struct *work)
677 struct rockchip_usb2phy_port *rport = 700 struct rockchip_usb2phy_port *rport =
678 container_of(work, struct rockchip_usb2phy_port, chg_work.work); 701 container_of(work, struct rockchip_usb2phy_port, chg_work.work);
679 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); 702 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
703 struct regmap *base = get_reg_base(rphy);
680 bool is_dcd, tmout, vout; 704 bool is_dcd, tmout, vout;
681 unsigned long delay; 705 unsigned long delay;
682 706
@@ -687,7 +711,7 @@ static void rockchip_chg_detect_work(struct work_struct *work)
687 if (!rport->suspended) 711 if (!rport->suspended)
688 rockchip_usb2phy_power_off(rport->phy); 712 rockchip_usb2phy_power_off(rport->phy);
689 /* put the controller in non-driving mode */ 713 /* put the controller in non-driving mode */
690 property_enable(rphy, &rphy->phy_cfg->chg_det.opmode, false); 714 property_enable(base, &rphy->phy_cfg->chg_det.opmode, false);
691 /* Start DCD processing stage 1 */ 715 /* Start DCD processing stage 1 */
692 rockchip_chg_enable_dcd(rphy, true); 716 rockchip_chg_enable_dcd(rphy, true);
693 rphy->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; 717 rphy->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
@@ -696,7 +720,8 @@ static void rockchip_chg_detect_work(struct work_struct *work)
696 break; 720 break;
697 case USB_CHG_STATE_WAIT_FOR_DCD: 721 case USB_CHG_STATE_WAIT_FOR_DCD:
698 /* get data contact detection status */ 722 /* get data contact detection status */
699 is_dcd = property_enabled(rphy, &rphy->phy_cfg->chg_det.dp_det); 723 is_dcd = property_enabled(rphy->grf,
724 &rphy->phy_cfg->chg_det.dp_det);
700 tmout = ++rphy->dcd_retries == CHG_DCD_MAX_RETRIES; 725 tmout = ++rphy->dcd_retries == CHG_DCD_MAX_RETRIES;
701 /* stage 2 */ 726 /* stage 2 */
702 if (is_dcd || tmout) { 727 if (is_dcd || tmout) {
@@ -713,7 +738,8 @@ static void rockchip_chg_detect_work(struct work_struct *work)
713 } 738 }
714 break; 739 break;
715 case USB_CHG_STATE_DCD_DONE: 740 case USB_CHG_STATE_DCD_DONE:
716 vout = property_enabled(rphy, &rphy->phy_cfg->chg_det.cp_det); 741 vout = property_enabled(rphy->grf,
742 &rphy->phy_cfg->chg_det.cp_det);
717 rockchip_chg_enable_primary_det(rphy, false); 743 rockchip_chg_enable_primary_det(rphy, false);
718 if (vout) { 744 if (vout) {
719 /* Voltage Source on DM, Probe on DP */ 745 /* Voltage Source on DM, Probe on DP */
@@ -734,7 +760,8 @@ static void rockchip_chg_detect_work(struct work_struct *work)
734 } 760 }
735 break; 761 break;
736 case USB_CHG_STATE_PRIMARY_DONE: 762 case USB_CHG_STATE_PRIMARY_DONE:
737 vout = property_enabled(rphy, &rphy->phy_cfg->chg_det.dcp_det); 763 vout = property_enabled(rphy->grf,
764 &rphy->phy_cfg->chg_det.dcp_det);
738 /* Turn off voltage source */ 765 /* Turn off voltage source */
739 rockchip_chg_enable_secondary_det(rphy, false); 766 rockchip_chg_enable_secondary_det(rphy, false);
740 if (vout) 767 if (vout)
@@ -748,7 +775,7 @@ static void rockchip_chg_detect_work(struct work_struct *work)
748 /* fall through */ 775 /* fall through */
749 case USB_CHG_STATE_DETECTED: 776 case USB_CHG_STATE_DETECTED:
750 /* put the controller in normal mode */ 777 /* put the controller in normal mode */
751 property_enable(rphy, &rphy->phy_cfg->chg_det.opmode, true); 778 property_enable(base, &rphy->phy_cfg->chg_det.opmode, true);
752 rockchip_usb2phy_otg_sm_work(&rport->otg_sm_work.work); 779 rockchip_usb2phy_otg_sm_work(&rport->otg_sm_work.work);
753 dev_info(&rport->phy->dev, "charger = %s\n", 780 dev_info(&rport->phy->dev, "charger = %s\n",
754 chg_to_string(rphy->chg_type)); 781 chg_to_string(rphy->chg_type));
@@ -790,8 +817,7 @@ static void rockchip_usb2phy_sm_work(struct work_struct *work)
790 if (ret < 0) 817 if (ret < 0)
791 goto next_schedule; 818 goto next_schedule;
792 819
793 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset, 820 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset, &uhd);
794 &uhd);
795 if (ret < 0) 821 if (ret < 0)
796 goto next_schedule; 822 goto next_schedule;
797 823
@@ -845,8 +871,8 @@ static void rockchip_usb2phy_sm_work(struct work_struct *work)
845 * activate the linestate detection to get the next device 871 * activate the linestate detection to get the next device
846 * plug-in irq. 872 * plug-in irq.
847 */ 873 */
848 property_enable(rphy, &rport->port_cfg->ls_det_clr, true); 874 property_enable(rphy->grf, &rport->port_cfg->ls_det_clr, true);
849 property_enable(rphy, &rport->port_cfg->ls_det_en, true); 875 property_enable(rphy->grf, &rport->port_cfg->ls_det_en, true);
850 876
851 /* 877 /*
852 * we don't need to rearm the delayed work when the phy port 878 * we don't need to rearm the delayed work when the phy port
@@ -869,14 +895,14 @@ static irqreturn_t rockchip_usb2phy_linestate_irq(int irq, void *data)
869 struct rockchip_usb2phy_port *rport = data; 895 struct rockchip_usb2phy_port *rport = data;
870 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); 896 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
871 897
872 if (!property_enabled(rphy, &rport->port_cfg->ls_det_st)) 898 if (!property_enabled(rphy->grf, &rport->port_cfg->ls_det_st))
873 return IRQ_NONE; 899 return IRQ_NONE;
874 900
875 mutex_lock(&rport->mutex); 901 mutex_lock(&rport->mutex);
876 902
877 /* disable linestate detect irq and clear its status */ 903 /* disable linestate detect irq and clear its status */
878 property_enable(rphy, &rport->port_cfg->ls_det_en, false); 904 property_enable(rphy->grf, &rport->port_cfg->ls_det_en, false);
879 property_enable(rphy, &rport->port_cfg->ls_det_clr, true); 905 property_enable(rphy->grf, &rport->port_cfg->ls_det_clr, true);
880 906
881 mutex_unlock(&rport->mutex); 907 mutex_unlock(&rport->mutex);
882 908
@@ -896,13 +922,13 @@ static irqreturn_t rockchip_usb2phy_bvalid_irq(int irq, void *data)
896 struct rockchip_usb2phy_port *rport = data; 922 struct rockchip_usb2phy_port *rport = data;
897 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); 923 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
898 924
899 if (!property_enabled(rphy, &rport->port_cfg->bvalid_det_st)) 925 if (!property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st))
900 return IRQ_NONE; 926 return IRQ_NONE;
901 927
902 mutex_lock(&rport->mutex); 928 mutex_lock(&rport->mutex);
903 929
904 /* clear bvalid detect irq pending status */ 930 /* clear bvalid detect irq pending status */
905 property_enable(rphy, &rport->port_cfg->bvalid_det_clr, true); 931 property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, true);
906 932
907 mutex_unlock(&rport->mutex); 933 mutex_unlock(&rport->mutex);
908 934
@@ -911,6 +937,17 @@ static irqreturn_t rockchip_usb2phy_bvalid_irq(int irq, void *data)
911 return IRQ_HANDLED; 937 return IRQ_HANDLED;
912} 938}
913 939
940static irqreturn_t rockchip_usb2phy_otg_mux_irq(int irq, void *data)
941{
942 struct rockchip_usb2phy_port *rport = data;
943 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
944
945 if (property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st))
946 return rockchip_usb2phy_bvalid_irq(irq, data);
947 else
948 return IRQ_NONE;
949}
950
914static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy, 951static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy,
915 struct rockchip_usb2phy_port *rport, 952 struct rockchip_usb2phy_port *rport,
916 struct device_node *child_np) 953 struct device_node *child_np)
@@ -987,20 +1024,43 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
987 rport->utmi_avalid = 1024 rport->utmi_avalid =
988 of_property_read_bool(child_np, "rockchip,utmi-avalid"); 1025 of_property_read_bool(child_np, "rockchip,utmi-avalid");
989 1026
990 rport->bvalid_irq = of_irq_get_byname(child_np, "otg-bvalid"); 1027 /*
991 if (rport->bvalid_irq < 0) { 1028 * Some SoCs use one interrupt with otg-id/otg-bvalid/linestate
992 dev_err(rphy->dev, "no vbus valid irq provided\n"); 1029 * interrupts muxed together, so probe the otg-mux interrupt first,
993 ret = rport->bvalid_irq; 1030 * if not found, then look for the regular interrupts one by one.
994 goto out; 1031 */
995 } 1032 rport->otg_mux_irq = of_irq_get_byname(child_np, "otg-mux");
1033 if (rport->otg_mux_irq > 0) {
1034 ret = devm_request_threaded_irq(rphy->dev, rport->otg_mux_irq,
1035 NULL,
1036 rockchip_usb2phy_otg_mux_irq,
1037 IRQF_ONESHOT,
1038 "rockchip_usb2phy_otg",
1039 rport);
1040 if (ret) {
1041 dev_err(rphy->dev,
1042 "failed to request otg-mux irq handle\n");
1043 goto out;
1044 }
1045 } else {
1046 rport->bvalid_irq = of_irq_get_byname(child_np, "otg-bvalid");
1047 if (rport->bvalid_irq < 0) {
1048 dev_err(rphy->dev, "no vbus valid irq provided\n");
1049 ret = rport->bvalid_irq;
1050 goto out;
1051 }
996 1052
997 ret = devm_request_threaded_irq(rphy->dev, rport->bvalid_irq, NULL, 1053 ret = devm_request_threaded_irq(rphy->dev, rport->bvalid_irq,
998 rockchip_usb2phy_bvalid_irq, 1054 NULL,
999 IRQF_ONESHOT, 1055 rockchip_usb2phy_bvalid_irq,
1000 "rockchip_usb2phy_bvalid", rport); 1056 IRQF_ONESHOT,
1001 if (ret) { 1057 "rockchip_usb2phy_bvalid",
1002 dev_err(rphy->dev, "failed to request otg-bvalid irq handle\n"); 1058 rport);
1003 goto out; 1059 if (ret) {
1060 dev_err(rphy->dev,
1061 "failed to request otg-bvalid irq handle\n");
1062 goto out;
1063 }
1004 } 1064 }
1005 1065
1006 if (!IS_ERR(rphy->edev)) { 1066 if (!IS_ERR(rphy->edev)) {
@@ -1045,6 +1105,16 @@ static int rockchip_usb2phy_probe(struct platform_device *pdev)
1045 if (IS_ERR(rphy->grf)) 1105 if (IS_ERR(rphy->grf))
1046 return PTR_ERR(rphy->grf); 1106 return PTR_ERR(rphy->grf);
1047 1107
1108 if (of_device_is_compatible(np, "rockchip,rv1108-usb2phy")) {
1109 rphy->usbgrf =
1110 syscon_regmap_lookup_by_phandle(dev->of_node,
1111 "rockchip,usbgrf");
1112 if (IS_ERR(rphy->usbgrf))
1113 return PTR_ERR(rphy->usbgrf);
1114 } else {
1115 rphy->usbgrf = NULL;
1116 }
1117
1048 if (of_property_read_u32(np, "reg", &reg)) { 1118 if (of_property_read_u32(np, "reg", &reg)) {
1049 dev_err(dev, "the reg property is not assigned in %s node\n", 1119 dev_err(dev, "the reg property is not assigned in %s node\n",
1050 np->name); 1120 np->name);
@@ -1327,11 +1397,54 @@ static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = {
1327 { /* sentinel */ } 1397 { /* sentinel */ }
1328}; 1398};
1329 1399
1400static const struct rockchip_usb2phy_cfg rv1108_phy_cfgs[] = {
1401 {
1402 .reg = 0x100,
1403 .num_ports = 2,
1404 .clkout_ctl = { 0x108, 4, 4, 1, 0 },
1405 .port_cfgs = {
1406 [USB2PHY_PORT_OTG] = {
1407 .phy_sus = { 0x0100, 15, 0, 0, 0x1d1 },
1408 .bvalid_det_en = { 0x0680, 3, 3, 0, 1 },
1409 .bvalid_det_st = { 0x0690, 3, 3, 0, 1 },
1410 .bvalid_det_clr = { 0x06a0, 3, 3, 0, 1 },
1411 .ls_det_en = { 0x0680, 2, 2, 0, 1 },
1412 .ls_det_st = { 0x0690, 2, 2, 0, 1 },
1413 .ls_det_clr = { 0x06a0, 2, 2, 0, 1 },
1414 .utmi_bvalid = { 0x0804, 10, 10, 0, 1 },
1415 .utmi_ls = { 0x0804, 13, 12, 0, 1 },
1416 },
1417 [USB2PHY_PORT_HOST] = {
1418 .phy_sus = { 0x0104, 15, 0, 0, 0x1d1 },
1419 .ls_det_en = { 0x0680, 4, 4, 0, 1 },
1420 .ls_det_st = { 0x0690, 4, 4, 0, 1 },
1421 .ls_det_clr = { 0x06a0, 4, 4, 0, 1 },
1422 .utmi_ls = { 0x0804, 9, 8, 0, 1 },
1423 .utmi_hstdet = { 0x0804, 7, 7, 0, 1 }
1424 }
1425 },
1426 .chg_det = {
1427 .opmode = { 0x0100, 3, 0, 5, 1 },
1428 .cp_det = { 0x0804, 1, 1, 0, 1 },
1429 .dcp_det = { 0x0804, 0, 0, 0, 1 },
1430 .dp_det = { 0x0804, 2, 2, 0, 1 },
1431 .idm_sink_en = { 0x0108, 8, 8, 0, 1 },
1432 .idp_sink_en = { 0x0108, 7, 7, 0, 1 },
1433 .idp_src_en = { 0x0108, 9, 9, 0, 1 },
1434 .rdm_pdwn_en = { 0x0108, 10, 10, 0, 1 },
1435 .vdm_src_en = { 0x0108, 12, 12, 0, 1 },
1436 .vdp_src_en = { 0x0108, 11, 11, 0, 1 },
1437 },
1438 },
1439 { /* sentinel */ }
1440};
1441
1330static const struct of_device_id rockchip_usb2phy_dt_match[] = { 1442static const struct of_device_id rockchip_usb2phy_dt_match[] = {
1331 { .compatible = "rockchip,rk3228-usb2phy", .data = &rk3228_phy_cfgs }, 1443 { .compatible = "rockchip,rk3228-usb2phy", .data = &rk3228_phy_cfgs },
1332 { .compatible = "rockchip,rk3328-usb2phy", .data = &rk3328_phy_cfgs }, 1444 { .compatible = "rockchip,rk3328-usb2phy", .data = &rk3328_phy_cfgs },
1333 { .compatible = "rockchip,rk3366-usb2phy", .data = &rk3366_phy_cfgs }, 1445 { .compatible = "rockchip,rk3366-usb2phy", .data = &rk3366_phy_cfgs },
1334 { .compatible = "rockchip,rk3399-usb2phy", .data = &rk3399_phy_cfgs }, 1446 { .compatible = "rockchip,rk3399-usb2phy", .data = &rk3399_phy_cfgs },
1447 { .compatible = "rockchip,rv1108-usb2phy", .data = &rv1108_phy_cfgs },
1335 {} 1448 {}
1336}; 1449};
1337MODULE_DEVICE_TABLE(of, rockchip_usb2phy_dt_match); 1450MODULE_DEVICE_TABLE(of, rockchip_usb2phy_dt_match);
diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c
index 7cfb0f8995de..4d2c57f21d76 100644
--- a/drivers/phy/rockchip/phy-rockchip-typec.c
+++ b/drivers/phy/rockchip/phy-rockchip-typec.c
@@ -622,12 +622,11 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
622 struct extcon_dev *edev = tcphy->extcon; 622 struct extcon_dev *edev = tcphy->extcon;
623 union extcon_property_value property; 623 union extcon_property_value property;
624 unsigned int id; 624 unsigned int id;
625 bool dfp, ufp, dp; 625 bool ufp, dp;
626 u8 mode; 626 u8 mode;
627 int ret; 627 int ret;
628 628
629 ufp = extcon_get_state(edev, EXTCON_USB); 629 ufp = extcon_get_state(edev, EXTCON_USB);
630 dfp = extcon_get_state(edev, EXTCON_USB_HOST);
631 dp = extcon_get_state(edev, EXTCON_DISP_DP); 630 dp = extcon_get_state(edev, EXTCON_DISP_DP);
632 631
633 mode = MODE_DFP_USB; 632 mode = MODE_DFP_USB;
diff --git a/drivers/phy/samsung/phy-exynos-dp-video.c b/drivers/phy/samsung/phy-exynos-dp-video.c
index bb3279dbf88c..2dd6dd1f37a8 100644
--- a/drivers/phy/samsung/phy-exynos-dp-video.c
+++ b/drivers/phy/samsung/phy-exynos-dp-video.c
@@ -16,6 +16,7 @@
16#include <linux/mfd/syscon.h> 16#include <linux/mfd/syscon.h>
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_address.h> 18#include <linux/of_address.h>
19#include <linux/of_device.h>
19#include <linux/phy/phy.h> 20#include <linux/phy/phy.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/regmap.h> 22#include <linux/regmap.h>
@@ -78,7 +79,6 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev)
78{ 79{
79 struct exynos_dp_video_phy *state; 80 struct exynos_dp_video_phy *state;
80 struct device *dev = &pdev->dev; 81 struct device *dev = &pdev->dev;
81 const struct of_device_id *match;
82 struct phy_provider *phy_provider; 82 struct phy_provider *phy_provider;
83 struct phy *phy; 83 struct phy *phy;
84 84
@@ -93,8 +93,7 @@ static int exynos_dp_video_phy_probe(struct platform_device *pdev)
93 return PTR_ERR(state->regs); 93 return PTR_ERR(state->regs);
94 } 94 }
95 95
96 match = of_match_node(exynos_dp_video_phy_of_match, dev->of_node); 96 state->drvdata = of_device_get_match_data(dev);
97 state->drvdata = match->data;
98 97
99 phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops); 98 phy = devm_phy_create(dev, NULL, &exynos_dp_video_phy_ops);
100 if (IS_ERR(phy)) { 99 if (IS_ERR(phy)) {
diff --git a/drivers/phy/samsung/phy-exynos5-usbdrd.c b/drivers/phy/samsung/phy-exynos5-usbdrd.c
index 7c41daa2c625..22c68f58b181 100644
--- a/drivers/phy/samsung/phy-exynos5-usbdrd.c
+++ b/drivers/phy/samsung/phy-exynos5-usbdrd.c
@@ -18,6 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/of_address.h> 20#include <linux/of_address.h>
21#include <linux/of_device.h>
21#include <linux/phy/phy.h> 22#include <linux/phy/phy.h>
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <linux/mutex.h> 24#include <linux/mutex.h>
@@ -662,7 +663,6 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
662 struct exynos5_usbdrd_phy *phy_drd; 663 struct exynos5_usbdrd_phy *phy_drd;
663 struct phy_provider *phy_provider; 664 struct phy_provider *phy_provider;
664 struct resource *res; 665 struct resource *res;
665 const struct of_device_id *match;
666 const struct exynos5_usbdrd_phy_drvdata *drv_data; 666 const struct exynos5_usbdrd_phy_drvdata *drv_data;
667 struct regmap *reg_pmu; 667 struct regmap *reg_pmu;
668 u32 pmu_offset; 668 u32 pmu_offset;
@@ -681,9 +681,10 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
681 if (IS_ERR(phy_drd->reg_phy)) 681 if (IS_ERR(phy_drd->reg_phy))
682 return PTR_ERR(phy_drd->reg_phy); 682 return PTR_ERR(phy_drd->reg_phy);
683 683
684 match = of_match_node(exynos5_usbdrd_phy_of_match, pdev->dev.of_node); 684 drv_data = of_device_get_match_data(dev);
685 if (!drv_data)
686 return -EINVAL;
685 687
686 drv_data = match->data;
687 phy_drd->drv_data = drv_data; 688 phy_drd->drv_data = drv_data;
688 689
689 ret = exynos5_usbdrd_phy_clk_handle(phy_drd); 690 ret = exynos5_usbdrd_phy_clk_handle(phy_drd);
diff --git a/drivers/phy/samsung/phy-samsung-usb2.c b/drivers/phy/samsung/phy-samsung-usb2.c
index 1d22d93b552d..ea818866985a 100644
--- a/drivers/phy/samsung/phy-samsung-usb2.c
+++ b/drivers/phy/samsung/phy-samsung-usb2.c
@@ -14,6 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/of_address.h> 16#include <linux/of_address.h>
17#include <linux/of_device.h>
17#include <linux/phy/phy.h> 18#include <linux/phy/phy.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19#include <linux/spinlock.h> 20#include <linux/spinlock.h>
@@ -142,7 +143,6 @@ MODULE_DEVICE_TABLE(of, samsung_usb2_phy_of_match);
142 143
143static int samsung_usb2_phy_probe(struct platform_device *pdev) 144static int samsung_usb2_phy_probe(struct platform_device *pdev)
144{ 145{
145 const struct of_device_id *match;
146 const struct samsung_usb2_phy_config *cfg; 146 const struct samsung_usb2_phy_config *cfg;
147 struct device *dev = &pdev->dev; 147 struct device *dev = &pdev->dev;
148 struct phy_provider *phy_provider; 148 struct phy_provider *phy_provider;
@@ -155,12 +155,9 @@ static int samsung_usb2_phy_probe(struct platform_device *pdev)
155 return -EINVAL; 155 return -EINVAL;
156 } 156 }
157 157
158 match = of_match_node(samsung_usb2_phy_of_match, pdev->dev.of_node); 158 cfg = of_device_get_match_data(dev);
159 if (!match) { 159 if (!cfg)
160 dev_err(dev, "of_match_node() failed\n");
161 return -EINVAL; 160 return -EINVAL;
162 }
163 cfg = match->data;
164 161
165 drv = devm_kzalloc(dev, sizeof(struct samsung_usb2_phy_driver) + 162 drv = devm_kzalloc(dev, sizeof(struct samsung_usb2_phy_driver) +
166 cfg->num_phys * sizeof(struct samsung_usb2_phy_instance), 163 cfg->num_phys * sizeof(struct samsung_usb2_phy_instance),
diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c
index 9c84d32c6f60..0e564f32749f 100644
--- a/drivers/phy/ti/phy-ti-pipe3.c
+++ b/drivers/phy/ti/phy-ti-pipe3.c
@@ -118,12 +118,12 @@ static struct pipe3_dpll_map dpll_map_usb[] = {
118}; 118};
119 119
120static struct pipe3_dpll_map dpll_map_sata[] = { 120static struct pipe3_dpll_map dpll_map_sata[] = {
121 {12000000, {1000, 7, 4, 6, 0} }, /* 12 MHz */ 121 {12000000, {625, 4, 4, 6, 0} }, /* 12 MHz */
122 {16800000, {714, 7, 4, 6, 0} }, /* 16.8 MHz */ 122 {16800000, {625, 6, 4, 7, 0} }, /* 16.8 MHz */
123 {19200000, {625, 7, 4, 6, 0} }, /* 19.2 MHz */ 123 {19200000, {625, 7, 4, 6, 0} }, /* 19.2 MHz */
124 {20000000, {600, 7, 4, 6, 0} }, /* 20 MHz */ 124 {20000000, {750, 9, 4, 6, 0} }, /* 20 MHz */
125 {26000000, {461, 7, 4, 6, 0} }, /* 26 MHz */ 125 {26000000, {750, 12, 4, 6, 0} }, /* 26 MHz */
126 {38400000, {312, 7, 4, 6, 0} }, /* 38.4 MHz */ 126 {38400000, {625, 15, 4, 6, 0} }, /* 38.4 MHz */
127 { }, /* Terminator */ 127 { }, /* Terminator */
128}; 128};
129 129
diff --git a/drivers/phy/ti/phy-twl4030-usb.c b/drivers/phy/ti/phy-twl4030-usb.c
index 2990b3965460..0e9013868188 100644
--- a/drivers/phy/ti/phy-twl4030-usb.c
+++ b/drivers/phy/ti/phy-twl4030-usb.c
@@ -185,7 +185,7 @@ struct twl4030_usb {
185static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl, 185static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl,
186 u8 module, u8 data, u8 address) 186 u8 module, u8 data, u8 address)
187{ 187{
188 u8 check; 188 u8 check = 0xFF;
189 189
190 if ((twl_i2c_write_u8(module, data, address) >= 0) && 190 if ((twl_i2c_write_u8(module, data, address) >= 0) &&
191 (twl_i2c_read_u8(module, &check, address) >= 0) && 191 (twl_i2c_read_u8(module, &check, address) >= 0) &&
diff --git a/drivers/power/supply/wm831x_power.c b/drivers/power/supply/wm831x_power.c
index 7082301da945..927050d4444d 100644
--- a/drivers/power/supply/wm831x_power.c
+++ b/drivers/power/supply/wm831x_power.c
@@ -13,6 +13,7 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/power_supply.h> 14#include <linux/power_supply.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/usb/phy.h>
16 17
17#include <linux/mfd/wm831x/core.h> 18#include <linux/mfd/wm831x/core.h>
18#include <linux/mfd/wm831x/auxadc.h> 19#include <linux/mfd/wm831x/auxadc.h>
@@ -31,6 +32,8 @@ struct wm831x_power {
31 char usb_name[20]; 32 char usb_name[20];
32 char battery_name[20]; 33 char battery_name[20];
33 bool have_battery; 34 bool have_battery;
35 struct usb_phy *usb_phy;
36 struct notifier_block usb_notify;
34}; 37};
35 38
36static int wm831x_power_check_online(struct wm831x *wm831x, int supply, 39static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
@@ -125,6 +128,43 @@ static enum power_supply_property wm831x_usb_props[] = {
125 POWER_SUPPLY_PROP_VOLTAGE_NOW, 128 POWER_SUPPLY_PROP_VOLTAGE_NOW,
126}; 129};
127 130
131/* In milliamps */
132static const unsigned int wm831x_usb_limits[] = {
133 0,
134 2,
135 100,
136 500,
137 900,
138 1500,
139 1800,
140 550,
141};
142
143static int wm831x_usb_limit_change(struct notifier_block *nb,
144 unsigned long limit, void *data)
145{
146 struct wm831x_power *wm831x_power = container_of(nb,
147 struct wm831x_power,
148 usb_notify);
149 unsigned int i, best;
150
151 /* Find the highest supported limit */
152 best = 0;
153 for (i = 0; i < ARRAY_SIZE(wm831x_usb_limits); i++) {
154 if (limit >= wm831x_usb_limits[i] &&
155 wm831x_usb_limits[best] < wm831x_usb_limits[i])
156 best = i;
157 }
158
159 dev_dbg(wm831x_power->wm831x->dev,
160 "Limiting USB current to %umA", wm831x_usb_limits[best]);
161
162 wm831x_set_bits(wm831x_power->wm831x, WM831X_POWER_STATE,
163 WM831X_USB_ILIM_MASK, best);
164
165 return 0;
166}
167
128/********************************************************************* 168/*********************************************************************
129 * Battery properties 169 * Battery properties
130 *********************************************************************/ 170 *********************************************************************/
@@ -607,6 +647,33 @@ static int wm831x_power_probe(struct platform_device *pdev)
607 } 647 }
608 } 648 }
609 649
650 power->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "phys", 0);
651 ret = PTR_ERR_OR_ZERO(power->usb_phy);
652
653 switch (ret) {
654 case 0:
655 power->usb_notify.notifier_call = wm831x_usb_limit_change;
656 ret = usb_register_notifier(power->usb_phy, &power->usb_notify);
657 if (ret) {
658 dev_err(&pdev->dev, "Failed to register notifier: %d\n",
659 ret);
660 goto err_bat_irq;
661 }
662 break;
663 case -EINVAL:
664 case -ENODEV:
665 /* ignore missing usb-phy, it's optional */
666 power->usb_phy = NULL;
667 ret = 0;
668 break;
669 default:
670 dev_err(&pdev->dev, "Failed to find USB phy: %d\n", ret);
671 /* fall-through */
672 case -EPROBE_DEFER:
673 goto err_bat_irq;
674 break;
675 }
676
610 return ret; 677 return ret;
611 678
612err_bat_irq: 679err_bat_irq:
@@ -637,6 +704,11 @@ static int wm831x_power_remove(struct platform_device *pdev)
637 struct wm831x *wm831x = wm831x_power->wm831x; 704 struct wm831x *wm831x = wm831x_power->wm831x;
638 int irq, i; 705 int irq, i;
639 706
707 if (wm831x_power->usb_phy) {
708 usb_unregister_notifier(wm831x_power->usb_phy,
709 &wm831x_power->usb_notify);
710 }
711
640 for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) { 712 for (i = 0; i < ARRAY_SIZE(wm831x_bat_irqs); i++) {
641 irq = wm831x_irq(wm831x, 713 irq = wm831x_irq(wm831x,
642 platform_get_irq_byname(pdev, 714 platform_get_irq_byname(pdev,
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index d65a64c29b85..5160a4a966b3 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -43,7 +43,6 @@
43#include "usbatm.h" 43#include "usbatm.h"
44 44
45#define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott" 45#define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott"
46#define DRIVER_VERSION "0.4"
47#define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver" 46#define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
48 47
49static const char cxacru_driver_name[] = "cxacru"; 48static const char cxacru_driver_name[] = "cxacru";
@@ -1380,4 +1379,3 @@ module_usb_driver(cxacru_usb_driver);
1380MODULE_AUTHOR(DRIVER_AUTHOR); 1379MODULE_AUTHOR(DRIVER_AUTHOR);
1381MODULE_DESCRIPTION(DRIVER_DESC); 1380MODULE_DESCRIPTION(DRIVER_DESC);
1382MODULE_LICENSE("GPL"); 1381MODULE_LICENSE("GPL");
1383MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 5083eb5b0d5e..3676adb40d89 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -40,8 +40,7 @@
40#include "usbatm.h" 40#include "usbatm.h"
41 41
42#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 42#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
43#define DRIVER_VERSION "1.10" 43#define DRIVER_DESC "Alcatel SpeedTouch USB driver"
44#define DRIVER_DESC "Alcatel SpeedTouch USB driver version " DRIVER_VERSION
45 44
46static const char speedtch_driver_name[] = "speedtch"; 45static const char speedtch_driver_name[] = "speedtch";
47 46
@@ -738,7 +737,7 @@ static int speedtch_post_reset(struct usb_interface *intf)
738** USB ** 737** USB **
739**********/ 738**********/
740 739
741static struct usb_device_id speedtch_usb_ids[] = { 740static const struct usb_device_id speedtch_usb_ids[] = {
742 {USB_DEVICE(0x06b9, 0x4061)}, 741 {USB_DEVICE(0x06b9, 0x4061)},
743 {} 742 {}
744}; 743};
@@ -962,4 +961,3 @@ module_usb_driver(speedtch_usb_driver);
962MODULE_AUTHOR(DRIVER_AUTHOR); 961MODULE_AUTHOR(DRIVER_AUTHOR);
963MODULE_DESCRIPTION(DRIVER_DESC); 962MODULE_DESCRIPTION(DRIVER_DESC);
964MODULE_LICENSE("GPL"); 963MODULE_LICENSE("GPL");
965MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index df67815f74e6..ba7616395db2 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -2212,7 +2212,7 @@ static int uea_boot(struct uea_softc *sc)
2212 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL); 2212 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
2213 if (ret < 0) { 2213 if (ret < 0) {
2214 uea_err(INS_TO_USBDEV(sc), 2214 uea_err(INS_TO_USBDEV(sc),
2215 "urb submition failed with error %d\n", ret); 2215 "urb submission failed with error %d\n", ret);
2216 goto err1; 2216 goto err1;
2217 } 2217 }
2218 2218
@@ -2522,7 +2522,7 @@ static struct attribute *attrs[] = {
2522 &dev_attr_stat_firmid.attr, 2522 &dev_attr_stat_firmid.attr,
2523 NULL, 2523 NULL,
2524}; 2524};
2525static struct attribute_group attr_grp = { 2525static const struct attribute_group attr_grp = {
2526 .attrs = attrs, 2526 .attrs = attrs,
2527}; 2527};
2528 2528
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 3e80aa3b917a..8607af758bbd 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -93,8 +93,7 @@ static int usbatm_print_packet(struct usbatm_data *instance, const unsigned char
93#endif 93#endif
94 94
95#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" 95#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
96#define DRIVER_VERSION "1.10" 96#define DRIVER_DESC "Generic USB ATM/DSL I/O"
97#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
98 97
99static const char usbatm_driver_name[] = "usbatm"; 98static const char usbatm_driver_name[] = "usbatm";
100 99
@@ -174,7 +173,7 @@ static int usbatm_atm_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __us
174static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); 173static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
175static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page); 174static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page);
176 175
177static struct atmdev_ops usbatm_atm_devops = { 176static const struct atmdev_ops usbatm_atm_devops = {
178 .dev_close = usbatm_atm_dev_close, 177 .dev_close = usbatm_atm_dev_close,
179 .open = usbatm_atm_open, 178 .open = usbatm_atm_open,
180 .close = usbatm_atm_close, 179 .close = usbatm_atm_close,
@@ -1315,7 +1314,6 @@ module_exit(usbatm_usb_exit);
1315MODULE_AUTHOR(DRIVER_AUTHOR); 1314MODULE_AUTHOR(DRIVER_AUTHOR);
1316MODULE_DESCRIPTION(DRIVER_DESC); 1315MODULE_DESCRIPTION(DRIVER_DESC);
1317MODULE_LICENSE("GPL"); 1316MODULE_LICENSE("GPL");
1318MODULE_VERSION(DRIVER_VERSION);
1319 1317
1320/************ 1318/************
1321** debug ** 1319** debug **
diff --git a/drivers/usb/atm/xusbatm.c b/drivers/usb/atm/xusbatm.c
index a87597f88a84..c73c1ec3005e 100644
--- a/drivers/usb/atm/xusbatm.c
+++ b/drivers/usb/atm/xusbatm.c
@@ -228,4 +228,3 @@ module_exit(xusbatm_exit);
228MODULE_AUTHOR("Roman Kagan, Duncan Sands"); 228MODULE_AUTHOR("Roman Kagan, Duncan Sands");
229MODULE_DESCRIPTION("Driver for USB ADSL modems initialized in userspace"); 229MODULE_DESCRIPTION("Driver for USB ADSL modems initialized in userspace");
230MODULE_LICENSE("GPL"); 230MODULE_LICENSE("GPL");
231MODULE_VERSION("0.1");
diff --git a/drivers/usb/c67x00/c67x00-hcd.c b/drivers/usb/c67x00/c67x00-hcd.c
index c2d13968da82..30d3f346686e 100644
--- a/drivers/usb/c67x00/c67x00-hcd.c
+++ b/drivers/usb/c67x00/c67x00-hcd.c
@@ -305,7 +305,7 @@ static int c67x00_hcd_get_frame(struct usb_hcd *hcd)
305 return temp_val ? (temp_val - 1) : HOST_FRAME_MASK; 305 return temp_val ? (temp_val - 1) : HOST_FRAME_MASK;
306} 306}
307 307
308static struct hc_driver c67x00_hc_driver = { 308static const struct hc_driver c67x00_hc_driver = {
309 .description = "c67x00-hcd", 309 .description = "c67x00-hcd",
310 .product_desc = "Cypress C67X00 Host Controller", 310 .product_desc = "Cypress C67X00 Host Controller",
311 .hcd_priv_size = sizeof(struct c67x00_hcd), 311 .hcd_priv_size = sizeof(struct c67x00_hcd),
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 39fca5715ed3..ddcbddf8361a 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_zevio.o
15obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o 15obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o
16 16
17obj-$(CONFIG_USB_CHIPIDEA_OF) += usbmisc_imx.o ci_hdrc_imx.o 17obj-$(CONFIG_USB_CHIPIDEA_OF) += usbmisc_imx.o ci_hdrc_imx.o
18obj-$(CONFIG_USB_CHIPIDEA_OF) += ci_hdrc_tegra.o
diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c
index 0bdfcdcbf7a5..bb626120296f 100644
--- a/drivers/usb/chipidea/ci_hdrc_msm.c
+++ b/drivers/usb/chipidea/ci_hdrc_msm.c
@@ -251,7 +251,7 @@ static int ci_hdrc_msm_probe(struct platform_device *pdev)
251 if (ret) 251 if (ret)
252 goto err_mux; 252 goto err_mux;
253 253
254 ulpi_node = of_find_node_by_name(pdev->dev.of_node, "ulpi"); 254 ulpi_node = of_find_node_by_name(of_node_get(pdev->dev.of_node), "ulpi");
255 if (ulpi_node) { 255 if (ulpi_node) {
256 phy_node = of_get_next_available_child(ulpi_node, NULL); 256 phy_node = of_get_next_available_child(ulpi_node, NULL);
257 ci->hsic = of_device_is_compatible(phy_node, "qcom,usb-hsic-phy"); 257 ci->hsic = of_device_is_compatible(phy_node, "qcom,usb-hsic-phy");
diff --git a/drivers/usb/chipidea/ci_hdrc_pci.c b/drivers/usb/chipidea/ci_hdrc_pci.c
index b635ab67490d..39414e4b2d81 100644
--- a/drivers/usb/chipidea/ci_hdrc_pci.c
+++ b/drivers/usb/chipidea/ci_hdrc_pci.c
@@ -170,5 +170,4 @@ module_pci_driver(ci_hdrc_pci_driver);
170MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); 170MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
171MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); 171MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
172MODULE_LICENSE("GPL"); 172MODULE_LICENSE("GPL");
173MODULE_VERSION("June 2008");
174MODULE_ALIAS("platform:ci13xxx_pci"); 173MODULE_ALIAS("platform:ci13xxx_pci");
diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c
new file mode 100644
index 000000000000..bfcee2702d50
--- /dev/null
+++ b/drivers/usb/chipidea/ci_hdrc_tegra.c
@@ -0,0 +1,155 @@
1/*
2 * Copyright (c) 2016, NVIDIA Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 */
8
9#include <linux/clk.h>
10#include <linux/module.h>
11#include <linux/of_device.h>
12#include <linux/reset.h>
13
14#include <linux/usb/chipidea.h>
15
16#include "ci.h"
17
18struct tegra_udc {
19 struct ci_hdrc_platform_data data;
20 struct platform_device *dev;
21
22 struct usb_phy *phy;
23 struct clk *clk;
24};
25
26struct tegra_udc_soc_info {
27 unsigned long flags;
28};
29
30static const struct tegra_udc_soc_info tegra20_udc_soc_info = {
31 .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
32};
33
34static const struct tegra_udc_soc_info tegra30_udc_soc_info = {
35 .flags = 0,
36};
37
38static const struct tegra_udc_soc_info tegra114_udc_soc_info = {
39 .flags = 0,
40};
41
42static const struct tegra_udc_soc_info tegra124_udc_soc_info = {
43 .flags = 0,
44};
45
46static const struct of_device_id tegra_udc_of_match[] = {
47 {
48 .compatible = "nvidia,tegra20-udc",
49 .data = &tegra20_udc_soc_info,
50 }, {
51 .compatible = "nvidia,tegra30-udc",
52 .data = &tegra30_udc_soc_info,
53 }, {
54 .compatible = "nvidia,tegra114-udc",
55 .data = &tegra114_udc_soc_info,
56 }, {
57 .compatible = "nvidia,tegra124-udc",
58 .data = &tegra124_udc_soc_info,
59 }, {
60 /* sentinel */
61 }
62};
63MODULE_DEVICE_TABLE(of, tegra_udc_of_match);
64
65static int tegra_udc_probe(struct platform_device *pdev)
66{
67 const struct tegra_udc_soc_info *soc;
68 struct tegra_udc *udc;
69 int err;
70
71 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
72 if (!udc)
73 return -ENOMEM;
74
75 soc = of_device_get_match_data(&pdev->dev);
76 if (!soc) {
77 dev_err(&pdev->dev, "failed to match OF data\n");
78 return -EINVAL;
79 }
80
81 udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
82 if (IS_ERR(udc->phy)) {
83 err = PTR_ERR(udc->phy);
84 dev_err(&pdev->dev, "failed to get PHY: %d\n", err);
85 return err;
86 }
87
88 udc->clk = devm_clk_get(&pdev->dev, NULL);
89 if (IS_ERR(udc->clk)) {
90 err = PTR_ERR(udc->clk);
91 dev_err(&pdev->dev, "failed to get clock: %d\n", err);
92 return err;
93 }
94
95 err = clk_prepare_enable(udc->clk);
96 if (err < 0) {
97 dev_err(&pdev->dev, "failed to enable clock: %d\n", err);
98 return err;
99 }
100
101 /*
102 * Tegra's USB PHY driver doesn't implement optional phy_init()
103 * hook, so we have to power on UDC controller before ChipIdea
104 * driver initialization kicks in.
105 */
106 usb_phy_set_suspend(udc->phy, 0);
107
108 /* setup and register ChipIdea HDRC device */
109 udc->data.name = "tegra-udc";
110 udc->data.flags = soc->flags;
111 udc->data.usb_phy = udc->phy;
112 udc->data.capoffset = DEF_CAPOFFSET;
113
114 udc->dev = ci_hdrc_add_device(&pdev->dev, pdev->resource,
115 pdev->num_resources, &udc->data);
116 if (IS_ERR(udc->dev)) {
117 err = PTR_ERR(udc->dev);
118 dev_err(&pdev->dev, "failed to add HDRC device: %d\n", err);
119 goto fail_power_off;
120 }
121
122 platform_set_drvdata(pdev, udc);
123
124 return 0;
125
126fail_power_off:
127 usb_phy_set_suspend(udc->phy, 1);
128 clk_disable_unprepare(udc->clk);
129 return err;
130}
131
132static int tegra_udc_remove(struct platform_device *pdev)
133{
134 struct tegra_udc *udc = platform_get_drvdata(pdev);
135
136 usb_phy_set_suspend(udc->phy, 1);
137 clk_disable_unprepare(udc->clk);
138
139 return 0;
140}
141
142static struct platform_driver tegra_udc_driver = {
143 .driver = {
144 .name = "tegra-udc",
145 .of_match_table = tegra_udc_of_match,
146 },
147 .probe = tegra_udc_probe,
148 .remove = tegra_udc_remove,
149};
150module_platform_driver(tegra_udc_driver);
151
152MODULE_DESCRIPTION("NVIDIA Tegra USB device mode driver");
153MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
154MODULE_ALIAS("platform:tegra-udc");
155MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/chipidea/ci_hdrc_usb2.c b/drivers/usb/chipidea/ci_hdrc_usb2.c
index d162cc0bb8ce..99425db9ba62 100644
--- a/drivers/usb/chipidea/ci_hdrc_usb2.c
+++ b/drivers/usb/chipidea/ci_hdrc_usb2.c
@@ -52,6 +52,8 @@ static int ci_hdrc_usb2_probe(struct platform_device *pdev)
52 52
53 if (!ci_pdata) { 53 if (!ci_pdata) {
54 ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL); 54 ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL);
55 if (!ci_pdata)
56 return -ENOMEM;
55 *ci_pdata = ci_default_pdata; /* struct copy */ 57 *ci_pdata = ci_default_pdata; /* struct copy */
56 } 58 }
57 59
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index b17ed3a9a304..43ea5fb87b9a 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -736,7 +736,7 @@ static int ci_extcon_register(struct ci_hdrc *ci)
736 736
737 id = &ci->platdata->id_extcon; 737 id = &ci->platdata->id_extcon;
738 id->ci = ci; 738 id->ci = ci;
739 if (!IS_ERR(id->edev)) { 739 if (!IS_ERR_OR_NULL(id->edev)) {
740 ret = devm_extcon_register_notifier(ci->dev, id->edev, 740 ret = devm_extcon_register_notifier(ci->dev, id->edev,
741 EXTCON_USB_HOST, &id->nb); 741 EXTCON_USB_HOST, &id->nb);
742 if (ret < 0) { 742 if (ret < 0) {
@@ -747,7 +747,7 @@ static int ci_extcon_register(struct ci_hdrc *ci)
747 747
748 vbus = &ci->platdata->vbus_extcon; 748 vbus = &ci->platdata->vbus_extcon;
749 vbus->ci = ci; 749 vbus->ci = ci;
750 if (!IS_ERR(vbus->edev)) { 750 if (!IS_ERR_OR_NULL(vbus->edev)) {
751 ret = devm_extcon_register_notifier(ci->dev, vbus->edev, 751 ret = devm_extcon_register_notifier(ci->dev, vbus->edev,
752 EXTCON_USB, &vbus->nb); 752 EXTCON_USB, &vbus->nb);
753 if (ret < 0) { 753 if (ret < 0) {
@@ -887,7 +887,7 @@ static struct attribute *ci_attrs[] = {
887 NULL, 887 NULL,
888}; 888};
889 889
890static struct attribute_group ci_attr_group = { 890static const struct attribute_group ci_attr_group = {
891 .attrs = ci_attrs, 891 .attrs = ci_attrs,
892}; 892};
893 893
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index 949183ede16f..5ea0246f650d 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -193,7 +193,7 @@ static struct attribute *inputs_attrs[] = {
193 NULL, 193 NULL,
194}; 194};
195 195
196static struct attribute_group inputs_attr_group = { 196static const struct attribute_group inputs_attr_group = {
197 .name = "inputs", 197 .name = "inputs",
198 .attrs = inputs_attrs, 198 .attrs = inputs_attrs,
199}; 199};
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index d68b125796f9..fe8a90543ea3 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -944,7 +944,6 @@ isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req)
944 */ 944 */
945static int isr_setup_status_phase(struct ci_hdrc *ci) 945static int isr_setup_status_phase(struct ci_hdrc *ci)
946{ 946{
947 int retval;
948 struct ci_hw_ep *hwep; 947 struct ci_hw_ep *hwep;
949 948
950 /* 949 /*
@@ -960,9 +959,7 @@ static int isr_setup_status_phase(struct ci_hdrc *ci)
960 ci->status->context = ci; 959 ci->status->context = ci;
961 ci->status->complete = isr_setup_status_complete; 960 ci->status->complete = isr_setup_status_complete;
962 961
963 retval = _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC); 962 return _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC);
964
965 return retval;
966} 963}
967 964
968/** 965/**
@@ -1899,6 +1896,9 @@ static int udc_start(struct ci_hdrc *ci)
1899 ci->gadget.name = ci->platdata->name; 1896 ci->gadget.name = ci->platdata->name;
1900 ci->gadget.otg_caps = otg_caps; 1897 ci->gadget.otg_caps = otg_caps;
1901 1898
1899 if (ci->platdata->flags & CI_HDRC_REQUIRES_ALIGNED_DMA)
1900 ci->gadget.quirk_avoids_skb_reserve = 1;
1901
1902 if (ci->is_otg && (otg_caps->hnp_support || otg_caps->srp_support || 1902 if (ci->is_otg && (otg_caps->hnp_support || otg_caps->srp_support ||
1903 otg_caps->adp_support)) 1903 otg_caps->adp_support))
1904 ci->gadget.is_otg = 1; 1904 ci->gadget.is_otg = 1;
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 8f972247b1c1..5aacea1978a5 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -26,10 +26,6 @@
26#include <asm/unaligned.h> 26#include <asm/unaligned.h>
27#include <linux/usb/cdc-wdm.h> 27#include <linux/usb/cdc-wdm.h>
28 28
29/*
30 * Version Information
31 */
32#define DRIVER_VERSION "v0.03"
33#define DRIVER_AUTHOR "Oliver Neukum" 29#define DRIVER_AUTHOR "Oliver Neukum"
34#define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management" 30#define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management"
35 31
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 578f424decc2..6ebfabfa0dc7 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -1085,7 +1085,7 @@ static struct attribute *capability_attrs[] = {
1085 NULL, 1085 NULL,
1086}; 1086};
1087 1087
1088static struct attribute_group capability_attr_grp = { 1088static const struct attribute_group capability_attr_grp = {
1089 .attrs = capability_attrs, 1089 .attrs = capability_attrs,
1090}; 1090};
1091 1091
@@ -1151,7 +1151,7 @@ static struct attribute *data_attrs[] = {
1151 NULL, 1151 NULL,
1152}; 1152};
1153 1153
1154static struct attribute_group data_attr_grp = { 1154static const struct attribute_group data_attr_grp = {
1155 .attrs = data_attrs, 1155 .attrs = data_attrs,
1156}; 1156};
1157 1157
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 5ef8da6e67c3..552ff7ac5a6b 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -190,10 +190,7 @@ EXPORT_SYMBOL_GPL(of_usb_get_dr_mode_by_phy);
190 */ 190 */
191bool of_usb_host_tpl_support(struct device_node *np) 191bool of_usb_host_tpl_support(struct device_node *np)
192{ 192{
193 if (of_find_property(np, "tpl-support", NULL)) 193 return of_property_read_bool(np, "tpl-support");
194 return true;
195
196 return false;
197} 194}
198EXPORT_SYMBOL_GPL(of_usb_host_tpl_support); 195EXPORT_SYMBOL_GPL(of_usb_host_tpl_support);
199 196
@@ -227,8 +224,8 @@ int of_usb_update_otg_caps(struct device_node *np,
227 otg_caps->otg_rev = otg_rev; 224 otg_caps->otg_rev = otg_rev;
228 break; 225 break;
229 default: 226 default:
230 pr_err("%s: unsupported otg-rev: 0x%x\n", 227 pr_err("%pOF: unsupported otg-rev: 0x%x\n",
231 np->full_name, otg_rev); 228 np, otg_rev);
232 return -EINVAL; 229 return -EINVAL;
233 } 230 }
234 } else { 231 } else {
@@ -240,11 +237,11 @@ int of_usb_update_otg_caps(struct device_node *np,
240 otg_caps->otg_rev = 0; 237 otg_caps->otg_rev = 0;
241 } 238 }
242 239
243 if (of_find_property(np, "hnp-disable", NULL)) 240 if (of_property_read_bool(np, "hnp-disable"))
244 otg_caps->hnp_support = false; 241 otg_caps->hnp_support = false;
245 if (of_find_property(np, "srp-disable", NULL)) 242 if (of_property_read_bool(np, "srp-disable"))
246 otg_caps->srp_support = false; 243 otg_caps->srp_support = false;
247 if (of_find_property(np, "adp-disable", NULL) || 244 if (of_property_read_bool(np, "adp-disable") ||
248 (otg_caps->otg_rev < 0x0200)) 245 (otg_caps->otg_rev < 0x0200))
249 otg_caps->adp_support = false; 246 otg_caps->adp_support = false;
250 247
diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 930e8f35f8df..4aa5195db8ea 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -135,7 +135,7 @@ static void ulpi_dev_release(struct device *dev)
135 kfree(to_ulpi_dev(dev)); 135 kfree(to_ulpi_dev(dev));
136} 136}
137 137
138static struct device_type ulpi_dev_type = { 138static const struct device_type ulpi_dev_type = {
139 .name = "ulpi_device", 139 .name = "ulpi_device",
140 .groups = ulpi_dev_attr_groups, 140 .groups = ulpi_dev_attr_groups,
141 .release = ulpi_dev_release, 141 .release = ulpi_dev_release,
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index ebe27595c4af..318bb3b96687 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -210,7 +210,7 @@ static void usbdev_vm_close(struct vm_area_struct *vma)
210 dec_usb_memory_use_count(usbm, &usbm->vma_use_count); 210 dec_usb_memory_use_count(usbm, &usbm->vma_use_count);
211} 211}
212 212
213static struct vm_operations_struct usbdev_vm_ops = { 213static const struct vm_operations_struct usbdev_vm_ops = {
214 .open = usbdev_vm_open, 214 .open = usbdev_vm_open,
215 .close = usbdev_vm_close 215 .close = usbdev_vm_close
216}; 216};
@@ -623,6 +623,8 @@ static void async_completed(struct urb *urb)
623 if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET && 623 if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET &&
624 as->status != -ENOENT) 624 as->status != -ENOENT)
625 cancel_bulk_urbs(ps, as->bulk_addr); 625 cancel_bulk_urbs(ps, as->bulk_addr);
626
627 wake_up(&ps->wait);
626 spin_unlock(&ps->lock); 628 spin_unlock(&ps->lock);
627 629
628 if (signr) { 630 if (signr) {
@@ -630,8 +632,6 @@ static void async_completed(struct urb *urb)
630 put_pid(pid); 632 put_pid(pid);
631 put_cred(cred); 633 put_cred(cred);
632 } 634 }
633
634 wake_up(&ps->wait);
635} 635}
636 636
637static void destroy_async(struct usb_dev_state *ps, struct list_head *list) 637static void destroy_async(struct usb_dev_state *ps, struct list_head *list)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 7f277b092b5b..75ad6718858c 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -972,7 +972,7 @@ static struct attribute *usb_bus_attrs[] = {
972 NULL, 972 NULL,
973}; 973};
974 974
975static struct attribute_group usb_bus_attr_group = { 975static const struct attribute_group usb_bus_attr_group = {
976 .name = NULL, /* we want them in the same directory */ 976 .name = NULL, /* we want them in the same directory */
977 .attrs = usb_bus_attrs, 977 .attrs = usb_bus_attrs,
978}; 978};
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 822f8c50e423..41eaf0b52518 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2614,7 +2614,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
2614#define SET_CONFIG_TRIES (2 * (use_both_schemes + 1)) 2614#define SET_CONFIG_TRIES (2 * (use_both_schemes + 1))
2615#define USE_NEW_SCHEME(i) ((i) / 2 == (int)old_scheme_first) 2615#define USE_NEW_SCHEME(i) ((i) / 2 == (int)old_scheme_first)
2616 2616
2617#define HUB_ROOT_RESET_TIME 50 /* times are in msec */ 2617#define HUB_ROOT_RESET_TIME 60 /* times are in msec */
2618#define HUB_SHORT_RESET_TIME 10 2618#define HUB_SHORT_RESET_TIME 10
2619#define HUB_BH_RESET_TIME 50 2619#define HUB_BH_RESET_TIME 50
2620#define HUB_LONG_RESET_TIME 200 2620#define HUB_LONG_RESET_TIME 200
@@ -4342,6 +4342,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
4342 enum usb_device_speed oldspeed = udev->speed; 4342 enum usb_device_speed oldspeed = udev->speed;
4343 const char *speed; 4343 const char *speed;
4344 int devnum = udev->devnum; 4344 int devnum = udev->devnum;
4345 const char *driver_name;
4345 4346
4346 /* root hub ports have a slightly longer reset period 4347 /* root hub ports have a slightly longer reset period
4347 * (from USB 2.0 spec, section 7.1.7.5) 4348 * (from USB 2.0 spec, section 7.1.7.5)
@@ -4409,11 +4410,23 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
4409 else 4410 else
4410 speed = usb_speed_string(udev->speed); 4411 speed = usb_speed_string(udev->speed);
4411 4412
4413 /*
4414 * The controller driver may be NULL if the controller device
4415 * is the middle device between platform device and roothub.
4416 * This middle device may not need a device driver due to
4417 * all hardware control can be at platform device driver, this
4418 * platform device is usually a dual-role USB controller device.
4419 */
4420 if (udev->bus->controller->driver)
4421 driver_name = udev->bus->controller->driver->name;
4422 else
4423 driver_name = udev->bus->sysdev->driver->name;
4424
4412 if (udev->speed < USB_SPEED_SUPER) 4425 if (udev->speed < USB_SPEED_SUPER)
4413 dev_info(&udev->dev, 4426 dev_info(&udev->dev,
4414 "%s %s USB device number %d using %s\n", 4427 "%s %s USB device number %d using %s\n",
4415 (udev->config) ? "reset" : "new", speed, 4428 (udev->config) ? "reset" : "new", speed,
4416 devnum, udev->bus->controller->driver->name); 4429 devnum, driver_name);
4417 4430
4418 /* Set up TT records, if needed */ 4431 /* Set up TT records, if needed */
4419 if (hdev->tt) { 4432 if (hdev->tt) {
@@ -4545,7 +4558,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
4545 "%s SuperSpeed%s USB device number %d using %s\n", 4558 "%s SuperSpeed%s USB device number %d using %s\n",
4546 (udev->config) ? "reset" : "new", 4559 (udev->config) ? "reset" : "new",
4547 (udev->speed == USB_SPEED_SUPER_PLUS) ? "Plus" : "", 4560 (udev->speed == USB_SPEED_SUPER_PLUS) ? "Plus" : "",
4548 devnum, udev->bus->controller->driver->name); 4561 devnum, driver_name);
4549 } 4562 }
4550 4563
4551 /* cope with hardware quirkiness: 4564 /* cope with hardware quirkiness:
diff --git a/drivers/usb/core/ledtrig-usbport.c b/drivers/usb/core/ledtrig-usbport.c
index 16c19a31dad1..1af877942110 100644
--- a/drivers/usb/core/ledtrig-usbport.c
+++ b/drivers/usb/core/ledtrig-usbport.c
@@ -149,8 +149,8 @@ static bool usbport_trig_port_observed(struct usbport_trig_data *usbport_data,
149 count = of_count_phandle_with_args(led_np, "trigger-sources", 149 count = of_count_phandle_with_args(led_np, "trigger-sources",
150 "#trigger-source-cells"); 150 "#trigger-source-cells");
151 if (count < 0) { 151 if (count < 0) {
152 dev_warn(dev, "Failed to get trigger sources for %s\n", 152 dev_warn(dev, "Failed to get trigger sources for %pOF\n",
153 led_np->full_name); 153 led_np);
154 return false; 154 return false;
155 } 155 }
156 156
@@ -205,6 +205,7 @@ static int usbport_trig_add_port(struct usbport_trig_data *usbport_data,
205 } 205 }
206 snprintf(port->port_name, len, "%s-port%d", hub_name, portnum); 206 snprintf(port->port_name, len, "%s-port%d", hub_name, portnum);
207 207
208 sysfs_attr_init(&port->attr.attr);
208 port->attr.attr.name = port->port_name; 209 port->attr.attr.name = port->port_name;
209 port->attr.attr.mode = S_IRUSR | S_IWUSR; 210 port->attr.attr.mode = S_IRUSR | S_IWUSR;
210 port->attr.show = usbport_trig_port_show; 211 port->attr.show = usbport_trig_port_show;
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 574da2b4529c..82806e311202 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -57,8 +57,9 @@ static const struct usb_device_id usb_quirk_list[] = {
57 /* Microsoft LifeCam-VX700 v2.0 */ 57 /* Microsoft LifeCam-VX700 v2.0 */
58 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME }, 58 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
59 59
60 /* Logitech HD Pro Webcams C920 and C930e */ 60 /* Logitech HD Pro Webcams C920, C920-C and C930e */
61 { USB_DEVICE(0x046d, 0x082d), .driver_info = USB_QUIRK_DELAY_INIT }, 61 { USB_DEVICE(0x046d, 0x082d), .driver_info = USB_QUIRK_DELAY_INIT },
62 { USB_DEVICE(0x046d, 0x0841), .driver_info = USB_QUIRK_DELAY_INIT },
62 { USB_DEVICE(0x046d, 0x0843), .driver_info = USB_QUIRK_DELAY_INIT }, 63 { USB_DEVICE(0x046d, 0x0843), .driver_info = USB_QUIRK_DELAY_INIT },
63 64
64 /* Logitech ConferenceCam CC3000e */ 65 /* Logitech ConferenceCam CC3000e */
@@ -217,6 +218,9 @@ static const struct usb_device_id usb_quirk_list[] = {
217 { USB_DEVICE(0x1a0a, 0x0200), .driver_info = 218 { USB_DEVICE(0x1a0a, 0x0200), .driver_info =
218 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL }, 219 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL },
219 220
221 /* Corsair Strafe RGB */
222 { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT },
223
220 /* Acer C120 LED Projector */ 224 /* Acer C120 LED Projector */
221 { USB_DEVICE(0x1de1, 0xc102), .driver_info = USB_QUIRK_NO_LPM }, 225 { USB_DEVICE(0x1de1, 0xc102), .driver_info = USB_QUIRK_NO_LPM },
222 226
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index dfc68ed24db1..d930bfda4010 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -113,7 +113,7 @@ static ssize_t devspec_show(struct device *dev, struct device_attribute *attr,
113{ 113{
114 struct device_node *of_node = dev->of_node; 114 struct device_node *of_node = dev->of_node;
115 115
116 return sprintf(buf, "%s\n", of_node_full_name(of_node)); 116 return sprintf(buf, "%pOF\n", of_node);
117} 117}
118static DEVICE_ATTR_RO(devspec); 118static DEVICE_ATTR_RO(devspec);
119#endif 119#endif
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index c4066cd77e47..0d8e09ccb59c 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4179,7 +4179,7 @@ static int dwc2_hsotg_ep_sethalt_lock(struct usb_ep *ep, int value)
4179 return ret; 4179 return ret;
4180} 4180}
4181 4181
4182static struct usb_ep_ops dwc2_hsotg_ep_ops = { 4182static const struct usb_ep_ops dwc2_hsotg_ep_ops = {
4183 .enable = dwc2_hsotg_ep_enable, 4183 .enable = dwc2_hsotg_ep_enable,
4184 .disable = dwc2_hsotg_ep_disable, 4184 .disable = dwc2_hsotg_ep_disable,
4185 .alloc_request = dwc2_hsotg_ep_alloc_request, 4185 .alloc_request = dwc2_hsotg_ep_alloc_request,
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 740c7e86d31b..c2631145f404 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4388,6 +4388,9 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
4388 4388
4389 spin_lock_irqsave(&hsotg->lock, flags); 4389 spin_lock_irqsave(&hsotg->lock, flags);
4390 4390
4391 if (dwc2_is_device_mode(hsotg))
4392 goto unlock;
4393
4391 if (hsotg->lx_state != DWC2_L0) 4394 if (hsotg->lx_state != DWC2_L0)
4392 goto unlock; 4395 goto unlock;
4393 4396
@@ -4446,6 +4449,9 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
4446 4449
4447 spin_lock_irqsave(&hsotg->lock, flags); 4450 spin_lock_irqsave(&hsotg->lock, flags);
4448 4451
4452 if (dwc2_is_device_mode(hsotg))
4453 goto unlock;
4454
4449 if (hsotg->lx_state != DWC2_L2) 4455 if (hsotg->lx_state != DWC2_L2)
4450 goto unlock; 4456 goto unlock;
4451 4457
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
index 12ee23f53cdd..d2ed9523e77c 100644
--- a/drivers/usb/dwc3/dwc3-keystone.c
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -15,7 +15,6 @@
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 */ 16 */
17 17
18#include <linux/clk.h>
19#include <linux/module.h> 18#include <linux/module.h>
20#include <linux/kernel.h> 19#include <linux/kernel.h>
21#include <linux/interrupt.h> 20#include <linux/interrupt.h>
@@ -23,6 +22,7 @@
23#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
24#include <linux/io.h> 23#include <linux/io.h>
25#include <linux/of_platform.h> 24#include <linux/of_platform.h>
25#include <linux/pm_runtime.h>
26 26
27/* USBSS register offsets */ 27/* USBSS register offsets */
28#define USBSS_REVISION 0x0000 28#define USBSS_REVISION 0x0000
@@ -41,7 +41,6 @@
41 41
42struct dwc3_keystone { 42struct dwc3_keystone {
43 struct device *dev; 43 struct device *dev;
44 struct clk *clk;
45 void __iomem *usbss; 44 void __iomem *usbss;
46}; 45};
47 46
@@ -106,17 +105,13 @@ static int kdwc3_probe(struct platform_device *pdev)
106 if (IS_ERR(kdwc->usbss)) 105 if (IS_ERR(kdwc->usbss))
107 return PTR_ERR(kdwc->usbss); 106 return PTR_ERR(kdwc->usbss);
108 107
109 kdwc->clk = devm_clk_get(kdwc->dev, "usb"); 108 pm_runtime_enable(kdwc->dev);
110 if (IS_ERR(kdwc->clk)) {
111 dev_err(kdwc->dev, "unable to get usb clock\n");
112 return PTR_ERR(kdwc->clk);
113 }
114 109
115 error = clk_prepare_enable(kdwc->clk); 110 error = pm_runtime_get_sync(kdwc->dev);
116 if (error < 0) { 111 if (error < 0) {
117 dev_err(kdwc->dev, "unable to enable usb clock, error %d\n", 112 dev_err(kdwc->dev, "pm_runtime_get_sync failed, error %d\n",
118 error); 113 error);
119 return error; 114 goto err_irq;
120 } 115 }
121 116
122 irq = platform_get_irq(pdev, 0); 117 irq = platform_get_irq(pdev, 0);
@@ -147,7 +142,8 @@ static int kdwc3_probe(struct platform_device *pdev)
147err_core: 142err_core:
148 kdwc3_disable_irqs(kdwc); 143 kdwc3_disable_irqs(kdwc);
149err_irq: 144err_irq:
150 clk_disable_unprepare(kdwc->clk); 145 pm_runtime_put_sync(kdwc->dev);
146 pm_runtime_disable(kdwc->dev);
151 147
152 return error; 148 return error;
153} 149}
@@ -167,7 +163,9 @@ static int kdwc3_remove(struct platform_device *pdev)
167 163
168 kdwc3_disable_irqs(kdwc); 164 kdwc3_disable_irqs(kdwc);
169 device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core); 165 device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
170 clk_disable_unprepare(kdwc->clk); 166 pm_runtime_put_sync(kdwc->dev);
167 pm_runtime_disable(kdwc->dev);
168
171 platform_set_drvdata(pdev, NULL); 169 platform_set_drvdata(pdev, NULL);
172 170
173 return 0; 171 return 0;
diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
index fe414e7a9c78..4cef7d4f9cd0 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -25,7 +25,6 @@
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
27#include <linux/clk.h> 27#include <linux/clk.h>
28#include <linux/clk-provider.h>
29#include <linux/of.h> 28#include <linux/of.h>
30#include <linux/of_platform.h> 29#include <linux/of_platform.h>
31#include <linux/pm_runtime.h> 30#include <linux/pm_runtime.h>
@@ -96,7 +95,8 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
96 platform_set_drvdata(pdev, simple); 95 platform_set_drvdata(pdev, simple);
97 simple->dev = dev; 96 simple->dev = dev;
98 97
99 ret = dwc3_of_simple_clk_init(simple, of_clk_get_parent_count(np)); 98 ret = dwc3_of_simple_clk_init(simple, of_count_phandle_with_args(np,
99 "clocks", "#clock-cells"));
100 if (ret) 100 if (ret)
101 return ret; 101 return ret;
102 102
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index f5aaa0cf3873..3530795bbb8f 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -478,8 +478,8 @@ static int dwc3_omap_probe(struct platform_device *pdev)
478 478
479 irq = platform_get_irq(pdev, 0); 479 irq = platform_get_irq(pdev, 0);
480 if (irq < 0) { 480 if (irq < 0) {
481 dev_err(dev, "missing IRQ resource\n"); 481 dev_err(dev, "missing IRQ resource: %d\n", irq);
482 return -EINVAL; 482 return irq;
483 } 483 }
484 484
485 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 485 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 7e995df7a797..54343fbd85ee 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -345,7 +345,7 @@ static int dwc3_pci_resume(struct device *dev)
345} 345}
346#endif /* CONFIG_PM_SLEEP */ 346#endif /* CONFIG_PM_SLEEP */
347 347
348static struct dev_pm_ops dwc3_pci_dev_pm_ops = { 348static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
349 SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume) 349 SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
350 SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume, 350 SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
351 NULL) 351 NULL)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 35cc641d9f31..31cce7805eb2 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -130,7 +130,7 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
130 130
131config U_SERIAL_CONSOLE 131config U_SERIAL_CONSOLE
132 bool "Serial gadget console support" 132 bool "Serial gadget console support"
133 depends on USB_G_SERIAL 133 depends on USB_U_SERIAL
134 help 134 help
135 It supports the serial gadget can be used as a console. 135 It supports the serial gadget can be used as a console.
136 136
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index d21874b35cf6..9990944a7245 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -961,10 +961,9 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
961 /* In the meantime, endpoint got disabled or changed. */ 961 /* In the meantime, endpoint got disabled or changed. */
962 ret = -ESHUTDOWN; 962 ret = -ESHUTDOWN;
963 } else if (halt) { 963 } else if (halt) {
964 /* Halt */ 964 ret = usb_ep_set_halt(ep->ep);
965 if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep)) 965 if (!ret)
966 usb_ep_set_halt(ep->ep); 966 ret = -EBADMSG;
967 ret = -EBADMSG;
968 } else if (unlikely(data_len == -EINVAL)) { 967 } else if (unlikely(data_len == -EINVAL)) {
969 /* 968 /*
970 * Sanity Check: even though data_len can't be used 969 * Sanity Check: even though data_len can't be used
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 5eea44823ca0..d8e359ef6eb1 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -44,6 +44,7 @@ struct f_hidg {
44 /* configuration */ 44 /* configuration */
45 unsigned char bInterfaceSubClass; 45 unsigned char bInterfaceSubClass;
46 unsigned char bInterfaceProtocol; 46 unsigned char bInterfaceProtocol;
47 unsigned char protocol;
47 unsigned short report_desc_length; 48 unsigned short report_desc_length;
48 char *report_desc; 49 char *report_desc;
49 unsigned short report_length; 50 unsigned short report_length;
@@ -527,7 +528,9 @@ static int hidg_setup(struct usb_function *f,
527 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 528 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
528 | HID_REQ_GET_PROTOCOL): 529 | HID_REQ_GET_PROTOCOL):
529 VDBG(cdev, "get_protocol\n"); 530 VDBG(cdev, "get_protocol\n");
530 goto stall; 531 length = min_t(unsigned int, length, 1);
532 ((u8 *) req->buf)[0] = hidg->protocol;
533 goto respond;
531 break; 534 break;
532 535
533 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 536 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
@@ -539,6 +542,17 @@ static int hidg_setup(struct usb_function *f,
539 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 542 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
540 | HID_REQ_SET_PROTOCOL): 543 | HID_REQ_SET_PROTOCOL):
541 VDBG(cdev, "set_protocol\n"); 544 VDBG(cdev, "set_protocol\n");
545 if (value > HID_REPORT_PROTOCOL)
546 goto stall;
547 length = 0;
548 /*
549 * We assume that programs implementing the Boot protocol
550 * are also compatible with the Report Protocol
551 */
552 if (hidg->bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
553 hidg->protocol = value;
554 goto respond;
555 }
542 goto stall; 556 goto stall;
543 break; 557 break;
544 558
@@ -768,6 +782,7 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
768 /* set descriptor dynamic values */ 782 /* set descriptor dynamic values */
769 hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass; 783 hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
770 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol; 784 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
785 hidg->protocol = HID_REPORT_PROTOCOL;
771 hidg_ss_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length); 786 hidg_ss_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
772 hidg_ss_in_comp_desc.wBytesPerInterval = 787 hidg_ss_in_comp_desc.wBytesPerInterval =
773 cpu_to_le16(hidg->report_length); 788 cpu_to_le16(hidg->report_length);
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index a5719f271bf0..5d3d7941d2c2 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -98,6 +98,7 @@ struct f_midi {
98 DECLARE_KFIFO_PTR(in_req_fifo, struct usb_request *); 98 DECLARE_KFIFO_PTR(in_req_fifo, struct usb_request *);
99 spinlock_t transmit_lock; 99 spinlock_t transmit_lock;
100 unsigned int in_last_port; 100 unsigned int in_last_port;
101 unsigned char free_ref;
101 102
102 struct gmidi_in_port in_ports_array[/* in_ports */]; 103 struct gmidi_in_port in_ports_array[/* in_ports */];
103}; 104};
@@ -108,6 +109,7 @@ static inline struct f_midi *func_to_midi(struct usb_function *f)
108} 109}
109 110
110static void f_midi_transmit(struct f_midi *midi); 111static void f_midi_transmit(struct f_midi *midi);
112static void f_midi_rmidi_free(struct snd_rawmidi *rmidi);
111 113
112DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); 114DECLARE_UAC_AC_HEADER_DESCRIPTOR(1);
113DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); 115DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
@@ -163,6 +165,13 @@ static struct usb_endpoint_descriptor bulk_out_desc = {
163 .bmAttributes = USB_ENDPOINT_XFER_BULK, 165 .bmAttributes = USB_ENDPOINT_XFER_BULK,
164}; 166};
165 167
168static struct usb_ss_ep_comp_descriptor bulk_out_ss_comp_desc = {
169 .bLength = sizeof(bulk_out_ss_comp_desc),
170 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
171 /* .bMaxBurst = 0, */
172 /* .bmAttributes = 0, */
173};
174
166/* B.5.2 Class-specific MS Bulk OUT Endpoint Descriptor */ 175/* B.5.2 Class-specific MS Bulk OUT Endpoint Descriptor */
167static struct usb_ms_endpoint_descriptor_16 ms_out_desc = { 176static struct usb_ms_endpoint_descriptor_16 ms_out_desc = {
168 /* .bLength = DYNAMIC */ 177 /* .bLength = DYNAMIC */
@@ -180,6 +189,13 @@ static struct usb_endpoint_descriptor bulk_in_desc = {
180 .bmAttributes = USB_ENDPOINT_XFER_BULK, 189 .bmAttributes = USB_ENDPOINT_XFER_BULK,
181}; 190};
182 191
192static struct usb_ss_ep_comp_descriptor bulk_in_ss_comp_desc = {
193 .bLength = sizeof(bulk_in_ss_comp_desc),
194 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
195 /* .bMaxBurst = 0, */
196 /* .bmAttributes = 0, */
197};
198
183/* B.6.2 Class-specific MS Bulk IN Endpoint Descriptor */ 199/* B.6.2 Class-specific MS Bulk IN Endpoint Descriptor */
184static struct usb_ms_endpoint_descriptor_16 ms_in_desc = { 200static struct usb_ms_endpoint_descriptor_16 ms_in_desc = {
185 /* .bLength = DYNAMIC */ 201 /* .bLength = DYNAMIC */
@@ -755,13 +771,13 @@ static void f_midi_out_trigger(struct snd_rawmidi_substream *substream, int up)
755 clear_bit(substream->number, &midi->out_triggered); 771 clear_bit(substream->number, &midi->out_triggered);
756} 772}
757 773
758static struct snd_rawmidi_ops gmidi_in_ops = { 774static const struct snd_rawmidi_ops gmidi_in_ops = {
759 .open = f_midi_in_open, 775 .open = f_midi_in_open,
760 .close = f_midi_in_close, 776 .close = f_midi_in_close,
761 .trigger = f_midi_in_trigger, 777 .trigger = f_midi_in_trigger,
762}; 778};
763 779
764static struct snd_rawmidi_ops gmidi_out_ops = { 780static const struct snd_rawmidi_ops gmidi_out_ops = {
765 .open = f_midi_out_open, 781 .open = f_midi_out_open,
766 .close = f_midi_out_close, 782 .close = f_midi_out_close,
767 .trigger = f_midi_out_trigger 783 .trigger = f_midi_out_trigger
@@ -818,6 +834,8 @@ static int f_midi_register_card(struct f_midi *midi)
818 SNDRV_RAWMIDI_INFO_INPUT | 834 SNDRV_RAWMIDI_INFO_INPUT |
819 SNDRV_RAWMIDI_INFO_DUPLEX; 835 SNDRV_RAWMIDI_INFO_DUPLEX;
820 rmidi->private_data = midi; 836 rmidi->private_data = midi;
837 rmidi->private_free = f_midi_rmidi_free;
838 midi->free_ref++;
821 839
822 /* 840 /*
823 * Yes, rawmidi OUTPUT = USB IN, and rawmidi INPUT = USB OUT. 841 * Yes, rawmidi OUTPUT = USB IN, and rawmidi INPUT = USB OUT.
@@ -853,7 +871,7 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
853 struct usb_composite_dev *cdev = c->cdev; 871 struct usb_composite_dev *cdev = c->cdev;
854 struct f_midi *midi = func_to_midi(f); 872 struct f_midi *midi = func_to_midi(f);
855 struct usb_string *us; 873 struct usb_string *us;
856 int status, n, jack = 1, i = 0; 874 int status, n, jack = 1, i = 0, endpoint_descriptor_index = 0;
857 875
858 midi->gadget = cdev->gadget; 876 midi->gadget = cdev->gadget;
859 tasklet_init(&midi->tasklet, f_midi_in_tasklet, (unsigned long) midi); 877 tasklet_init(&midi->tasklet, f_midi_in_tasklet, (unsigned long) midi);
@@ -895,7 +913,7 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
895 goto fail; 913 goto fail;
896 914
897 /* allocate temporary function list */ 915 /* allocate temporary function list */
898 midi_function = kcalloc((MAX_PORTS * 4) + 9, sizeof(*midi_function), 916 midi_function = kcalloc((MAX_PORTS * 4) + 11, sizeof(*midi_function),
899 GFP_KERNEL); 917 GFP_KERNEL);
900 if (!midi_function) { 918 if (!midi_function) {
901 status = -ENOMEM; 919 status = -ENOMEM;
@@ -985,6 +1003,7 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
985 ms_in_desc.bNumEmbMIDIJack = midi->out_ports; 1003 ms_in_desc.bNumEmbMIDIJack = midi->out_ports;
986 1004
987 /* ... and add them to the list */ 1005 /* ... and add them to the list */
1006 endpoint_descriptor_index = i;
988 midi_function[i++] = (struct usb_descriptor_header *) &bulk_out_desc; 1007 midi_function[i++] = (struct usb_descriptor_header *) &bulk_out_desc;
989 midi_function[i++] = (struct usb_descriptor_header *) &ms_out_desc; 1008 midi_function[i++] = (struct usb_descriptor_header *) &ms_out_desc;
990 midi_function[i++] = (struct usb_descriptor_header *) &bulk_in_desc; 1009 midi_function[i++] = (struct usb_descriptor_header *) &bulk_in_desc;
@@ -1009,13 +1028,34 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
1009 goto fail_f_midi; 1028 goto fail_f_midi;
1010 } 1029 }
1011 1030
1031 if (gadget_is_superspeed(c->cdev->gadget)) {
1032 bulk_in_desc.wMaxPacketSize = cpu_to_le16(1024);
1033 bulk_out_desc.wMaxPacketSize = cpu_to_le16(1024);
1034 i = endpoint_descriptor_index;
1035 midi_function[i++] = (struct usb_descriptor_header *)
1036 &bulk_out_desc;
1037 midi_function[i++] = (struct usb_descriptor_header *)
1038 &bulk_out_ss_comp_desc;
1039 midi_function[i++] = (struct usb_descriptor_header *)
1040 &ms_out_desc;
1041 midi_function[i++] = (struct usb_descriptor_header *)
1042 &bulk_in_desc;
1043 midi_function[i++] = (struct usb_descriptor_header *)
1044 &bulk_in_ss_comp_desc;
1045 midi_function[i++] = (struct usb_descriptor_header *)
1046 &ms_in_desc;
1047 f->ss_descriptors = usb_copy_descriptors(midi_function);
1048 if (!f->ss_descriptors)
1049 goto fail_f_midi;
1050 }
1051
1012 kfree(midi_function); 1052 kfree(midi_function);
1013 1053
1014 return 0; 1054 return 0;
1015 1055
1016fail_f_midi: 1056fail_f_midi:
1017 kfree(midi_function); 1057 kfree(midi_function);
1018 usb_free_descriptors(f->hs_descriptors); 1058 usb_free_all_descriptors(f);
1019fail: 1059fail:
1020 f_midi_unregister_card(midi); 1060 f_midi_unregister_card(midi);
1021fail_register: 1061fail_register:
@@ -1197,14 +1237,21 @@ static void f_midi_free(struct usb_function *f)
1197 1237
1198 midi = func_to_midi(f); 1238 midi = func_to_midi(f);
1199 opts = container_of(f->fi, struct f_midi_opts, func_inst); 1239 opts = container_of(f->fi, struct f_midi_opts, func_inst);
1200 kfree(midi->id);
1201 mutex_lock(&opts->lock); 1240 mutex_lock(&opts->lock);
1202 kfifo_free(&midi->in_req_fifo); 1241 if (!--midi->free_ref) {
1203 kfree(midi); 1242 kfree(midi->id);
1204 --opts->refcnt; 1243 kfifo_free(&midi->in_req_fifo);
1244 kfree(midi);
1245 --opts->refcnt;
1246 }
1205 mutex_unlock(&opts->lock); 1247 mutex_unlock(&opts->lock);
1206} 1248}
1207 1249
1250static void f_midi_rmidi_free(struct snd_rawmidi *rmidi)
1251{
1252 f_midi_free(rmidi->private_data);
1253}
1254
1208static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f) 1255static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
1209{ 1256{
1210 struct usb_composite_dev *cdev = f->config->cdev; 1257 struct usb_composite_dev *cdev = f->config->cdev;
@@ -1219,7 +1266,7 @@ static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
1219 card = midi->card; 1266 card = midi->card;
1220 midi->card = NULL; 1267 midi->card = NULL;
1221 if (card) 1268 if (card)
1222 snd_card_free(card); 1269 snd_card_free_when_closed(card);
1223 1270
1224 usb_free_all_descriptors(f); 1271 usb_free_all_descriptors(f);
1225} 1272}
@@ -1263,6 +1310,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
1263 midi->buflen = opts->buflen; 1310 midi->buflen = opts->buflen;
1264 midi->qlen = opts->qlen; 1311 midi->qlen = opts->qlen;
1265 midi->in_last_port = 0; 1312 midi->in_last_port = 0;
1313 midi->free_ref = 1;
1266 1314
1267 status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL); 1315 status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL);
1268 if (status) 1316 if (status)
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index 24e34cfcb4bd..45b334ceaf2e 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -925,8 +925,6 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
925 */ 925 */
926 ncm->port.is_zlp_ok = 926 ncm->port.is_zlp_ok =
927 gadget_is_zlp_supported(cdev->gadget); 927 gadget_is_zlp_supported(cdev->gadget);
928 ncm->port.no_skb_reserve =
929 gadget_avoids_skb_reserve(cdev->gadget);
930 ncm->port.cdc_filter = DEFAULT_FILTER; 928 ncm->port.cdc_filter = DEFAULT_FILTER;
931 DBG(cdev, "activate ncm\n"); 929 DBG(cdev, "activate ncm\n");
932 net = gether_connect(&ncm->port); 930 net = gether_connect(&ncm->port);
diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c
index 16562e461121..e1d5853ef1e4 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -691,6 +691,10 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
691 f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc; 691 f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc;
692 } 692 }
693 693
694 rndis_iad_descriptor.bFunctionClass = rndis_opts->class;
695 rndis_iad_descriptor.bFunctionSubClass = rndis_opts->subclass;
696 rndis_iad_descriptor.bFunctionProtocol = rndis_opts->protocol;
697
694 /* 698 /*
695 * in drivers/usb/gadget/configfs.c:configfs_composite_bind() 699 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
696 * configurations are bound in sequence with list_for_each_entry, 700 * configurations are bound in sequence with list_for_each_entry,
@@ -866,11 +870,23 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);
866/* f_rndis_opts_ifname */ 870/* f_rndis_opts_ifname */
867USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis); 871USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis);
868 872
873/* f_rndis_opts_class */
874USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, class);
875
876/* f_rndis_opts_subclass */
877USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, subclass);
878
879/* f_rndis_opts_protocol */
880USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(rndis, protocol);
881
869static struct configfs_attribute *rndis_attrs[] = { 882static struct configfs_attribute *rndis_attrs[] = {
870 &rndis_opts_attr_dev_addr, 883 &rndis_opts_attr_dev_addr,
871 &rndis_opts_attr_host_addr, 884 &rndis_opts_attr_host_addr,
872 &rndis_opts_attr_qmult, 885 &rndis_opts_attr_qmult,
873 &rndis_opts_attr_ifname, 886 &rndis_opts_attr_ifname,
887 &rndis_opts_attr_class,
888 &rndis_opts_attr_subclass,
889 &rndis_opts_attr_protocol,
874 NULL, 890 NULL,
875}; 891};
876 892
@@ -916,6 +932,10 @@ static struct usb_function_instance *rndis_alloc_inst(void)
916 } 932 }
917 INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop); 933 INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop);
918 934
935 opts->class = rndis_iad_descriptor.bFunctionClass;
936 opts->subclass = rndis_iad_descriptor.bFunctionSubClass;
937 opts->protocol = rndis_iad_descriptor.bFunctionProtocol;
938
919 descs[0] = &opts->rndis_os_desc; 939 descs[0] = &opts->rndis_os_desc;
920 names[0] = "rndis"; 940 names[0] = "rndis";
921 config_group_init_type_name(&opts->func_inst.group, "", 941 config_group_init_type_name(&opts->func_inst.group, "",
diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index 5dd73b9e5172..3971bbab88bd 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -79,7 +79,7 @@ struct snd_uac_chip {
79 unsigned int p_framesize; 79 unsigned int p_framesize;
80}; 80};
81 81
82static struct snd_pcm_hardware uac_pcm_hardware = { 82static const struct snd_pcm_hardware uac_pcm_hardware = {
83 .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER 83 .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER
84 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID 84 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID
85 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME, 85 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
@@ -354,7 +354,7 @@ static int uac_pcm_null(struct snd_pcm_substream *substream)
354 return 0; 354 return 0;
355} 355}
356 356
357static struct snd_pcm_ops uac_pcm_ops = { 357static const struct snd_pcm_ops uac_pcm_ops = {
358 .open = uac_pcm_open, 358 .open = uac_pcm_open,
359 .close = uac_pcm_null, 359 .close = uac_pcm_null,
360 .ioctl = snd_pcm_lib_ioctl, 360 .ioctl = snd_pcm_lib_ioctl,
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index a8b40d07e927..bdbc3fdc7c4f 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -1073,7 +1073,7 @@ struct net_device *gether_connect(struct gether *link)
1073 1073
1074 if (result == 0) { 1074 if (result == 0) {
1075 dev->zlp = link->is_zlp_ok; 1075 dev->zlp = link->is_zlp_ok;
1076 dev->no_skb_reserve = link->no_skb_reserve; 1076 dev->no_skb_reserve = gadget_avoids_skb_reserve(dev->gadget);
1077 DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult)); 1077 DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult));
1078 1078
1079 dev->header_len = link->header_len; 1079 dev->header_len = link->header_len;
diff --git a/drivers/usb/gadget/function/u_ether.h b/drivers/usb/gadget/function/u_ether.h
index 81d94a7ae4b4..c77145bd6b5b 100644
--- a/drivers/usb/gadget/function/u_ether.h
+++ b/drivers/usb/gadget/function/u_ether.h
@@ -64,7 +64,6 @@ struct gether {
64 struct usb_ep *out_ep; 64 struct usb_ep *out_ep;
65 65
66 bool is_zlp_ok; 66 bool is_zlp_ok;
67 bool no_skb_reserve;
68 67
69 u16 cdc_filter; 68 u16 cdc_filter;
70 69
diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/gadget/function/u_ether_configfs.h
index c71133de17e7..e4c3f84af4c3 100644
--- a/drivers/usb/gadget/function/u_ether_configfs.h
+++ b/drivers/usb/gadget/function/u_ether_configfs.h
@@ -153,4 +153,39 @@ out: \
153 \ 153 \
154 CONFIGFS_ATTR_RO(_f_##_opts_, ifname) 154 CONFIGFS_ATTR_RO(_f_##_opts_, ifname)
155 155
156#define USB_ETHER_CONFIGFS_ITEM_ATTR_U8_RW(_f_, _n_) \
157 static ssize_t _f_##_opts_##_n_##_show(struct config_item *item,\
158 char *page) \
159 { \
160 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
161 int ret; \
162 \
163 mutex_lock(&opts->lock); \
164 ret = sprintf(page, "%02x\n", opts->_n_); \
165 mutex_unlock(&opts->lock); \
166 \
167 return ret; \
168 } \
169 \
170 static ssize_t _f_##_opts_##_n_##_store(struct config_item *item,\
171 const char *page, \
172 size_t len) \
173 { \
174 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
175 int ret; \
176 u8 val; \
177 \
178 mutex_lock(&opts->lock); \
179 ret = sscanf(page, "%02hhx", &val); \
180 if (ret > 0) { \
181 opts->_n_ = val; \
182 ret = len; \
183 } \
184 mutex_unlock(&opts->lock); \
185 \
186 return ret; \
187 } \
188 \
189 CONFIGFS_ATTR(_f_##_opts_, _n_)
190
156#endif /* __U_ETHER_CONFIGFS_H */ 191#endif /* __U_ETHER_CONFIGFS_H */
diff --git a/drivers/usb/gadget/function/u_rndis.h b/drivers/usb/gadget/function/u_rndis.h
index 4eafd5050545..a35ee3c2545d 100644
--- a/drivers/usb/gadget/function/u_rndis.h
+++ b/drivers/usb/gadget/function/u_rndis.h
@@ -29,6 +29,10 @@ struct f_rndis_opts {
29 struct usb_os_desc rndis_os_desc; 29 struct usb_os_desc rndis_os_desc;
30 char rndis_ext_compat_id[16]; 30 char rndis_ext_compat_id[16];
31 31
32 u8 class;
33 u8 subclass;
34 u8 protocol;
35
32 /* 36 /*
33 * Read/write access to configfs attributes is handled by configfs. 37 * Read/write access to configfs attributes is handled by configfs.
34 * 38 *
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 9b0805f55ad7..4176216d54be 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -537,7 +537,7 @@ static void gs_rx_push(unsigned long _port)
537 } 537 }
538 538
539 /* push data to (open) tty */ 539 /* push data to (open) tty */
540 if (req->actual) { 540 if (req->actual && tty) {
541 char *packet = req->buf; 541 char *packet = req->buf;
542 unsigned size = req->actual; 542 unsigned size = req->actual;
543 unsigned n; 543 unsigned n;
diff --git a/drivers/usb/gadget/legacy/webcam.c b/drivers/usb/gadget/legacy/webcam.c
index f9661cd627c8..82c13fce9232 100644
--- a/drivers/usb/gadget/legacy/webcam.c
+++ b/drivers/usb/gadget/legacy/webcam.c
@@ -436,5 +436,4 @@ module_usb_composite_driver(webcam_driver);
436MODULE_AUTHOR("Laurent Pinchart"); 436MODULE_AUTHOR("Laurent Pinchart");
437MODULE_DESCRIPTION("Webcam Video Gadget"); 437MODULE_DESCRIPTION("Webcam Video Gadget");
438MODULE_LICENSE("GPL"); 438MODULE_LICENSE("GPL");
439MODULE_VERSION("0.1.0");
440 439
diff --git a/drivers/usb/gadget/udc/bdc/Kconfig b/drivers/usb/gadget/udc/bdc/Kconfig
index eb8b55392360..c74ac25dddcd 100644
--- a/drivers/usb/gadget/udc/bdc/Kconfig
+++ b/drivers/usb/gadget/udc/bdc/Kconfig
@@ -1,6 +1,7 @@
1config USB_BDC_UDC 1config USB_BDC_UDC
2 tristate "Broadcom USB3.0 device controller IP driver(BDC)" 2 tristate "Broadcom USB3.0 device controller IP driver(BDC)"
3 depends on USB_GADGET && HAS_DMA 3 depends on USB_GADGET && HAS_DMA
4 default ARCH_BRCMSTB
4 5
5 help 6 help
6 BDC is Broadcom's USB3.0 device controller IP. If your SOC has a BDC IP 7 BDC is Broadcom's USB3.0 device controller IP. If your SOC has a BDC IP
diff --git a/drivers/usb/gadget/udc/bdc/bdc.h b/drivers/usb/gadget/udc/bdc/bdc.h
index 916d47135cac..6df0352cdc50 100644
--- a/drivers/usb/gadget/udc/bdc/bdc.h
+++ b/drivers/usb/gadget/udc/bdc/bdc.h
@@ -27,8 +27,8 @@
27#include <linux/usb/gadget.h> 27#include <linux/usb/gadget.h>
28#include <asm/unaligned.h> 28#include <asm/unaligned.h>
29 29
30#define BRCM_BDC_NAME "bdc_usb3" 30#define BRCM_BDC_NAME "bdc"
31#define BRCM_BDC_DESC "BDC device controller driver" 31#define BRCM_BDC_DESC "Broadcom USB Device Controller driver"
32 32
33#define DMA_ADDR_INVALID (~(dma_addr_t)0) 33#define DMA_ADDR_INVALID (~(dma_addr_t)0)
34 34
@@ -83,14 +83,14 @@
83 83
84#define BDC_DVCSA 0x50 84#define BDC_DVCSA 0x50
85#define BDC_DVCSB 0x54 85#define BDC_DVCSB 0x54
86#define BDC_EPSTS0(n) (0x60 + (n * 0x10)) 86#define BDC_EPSTS0 0x60
87#define BDC_EPSTS1(n) (0x64 + (n * 0x10)) 87#define BDC_EPSTS1 0x64
88#define BDC_EPSTS2(n) (0x68 + (n * 0x10)) 88#define BDC_EPSTS2 0x68
89#define BDC_EPSTS3(n) (0x6c + (n * 0x10)) 89#define BDC_EPSTS3 0x6c
90#define BDC_EPSTS4(n) (0x70 + (n * 0x10)) 90#define BDC_EPSTS4 0x70
91#define BDC_EPSTS5(n) (0x74 + (n * 0x10)) 91#define BDC_EPSTS5 0x74
92#define BDC_EPSTS6(n) (0x78 + (n * 0x10)) 92#define BDC_EPSTS6 0x78
93#define BDC_EPSTS7(n) (0x7c + (n * 0x10)) 93#define BDC_EPSTS7 0x7c
94#define BDC_SRRBAL(n) (0x200 + (n * 0x10)) 94#define BDC_SRRBAL(n) (0x200 + (n * 0x10))
95#define BDC_SRRBAH(n) (0x204 + (n * 0x10)) 95#define BDC_SRRBAH(n) (0x204 + (n * 0x10))
96#define BDC_SRRINT(n) (0x208 + (n * 0x10)) 96#define BDC_SRRINT(n) (0x208 + (n * 0x10))
@@ -413,6 +413,9 @@ struct bdc {
413 /* device lock */ 413 /* device lock */
414 spinlock_t lock; 414 spinlock_t lock;
415 415
416 /* generic phy */
417 struct phy **phys;
418 int num_phys;
416 /* num of endpoints for a particular instantiation of IP */ 419 /* num of endpoints for a particular instantiation of IP */
417 unsigned int num_eps; 420 unsigned int num_eps;
418 /* 421 /*
@@ -454,6 +457,7 @@ struct bdc {
454 * Func Wake packet every 2.5 secs. Refer to USB3 spec section 8.5.6.4 457 * Func Wake packet every 2.5 secs. Refer to USB3 spec section 8.5.6.4
455 */ 458 */
456 struct delayed_work func_wake_notify; 459 struct delayed_work func_wake_notify;
460 struct clk *clk;
457}; 461};
458 462
459static inline u32 bdc_readl(void __iomem *base, u32 offset) 463static inline u32 bdc_readl(void __iomem *base, u32 offset)
diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
index e9bd8d4abca0..7a8af4b916cf 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_core.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_core.c
@@ -24,9 +24,11 @@
24#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
25#include <linux/dmapool.h> 25#include <linux/dmapool.h>
26#include <linux/of.h> 26#include <linux/of.h>
27#include <linux/phy/phy.h>
27#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
28#include <linux/usb/ch9.h> 29#include <linux/usb/ch9.h>
29#include <linux/usb/gadget.h> 30#include <linux/usb/gadget.h>
31#include <linux/clk.h>
30 32
31#include "bdc.h" 33#include "bdc.h"
32#include "bdc_dbg.h" 34#include "bdc_dbg.h"
@@ -444,6 +446,43 @@ static int bdc_hw_init(struct bdc *bdc)
444 return 0; 446 return 0;
445} 447}
446 448
449static int bdc_phy_init(struct bdc *bdc)
450{
451 int phy_num;
452 int ret;
453
454 for (phy_num = 0; phy_num < bdc->num_phys; phy_num++) {
455 ret = phy_init(bdc->phys[phy_num]);
456 if (ret)
457 goto err_exit_phy;
458 ret = phy_power_on(bdc->phys[phy_num]);
459 if (ret) {
460 phy_exit(bdc->phys[phy_num]);
461 goto err_exit_phy;
462 }
463 }
464
465 return 0;
466
467err_exit_phy:
468 while (--phy_num >= 0) {
469 phy_power_off(bdc->phys[phy_num]);
470 phy_exit(bdc->phys[phy_num]);
471 }
472
473 return ret;
474}
475
476static void bdc_phy_exit(struct bdc *bdc)
477{
478 int phy_num;
479
480 for (phy_num = 0; phy_num < bdc->num_phys; phy_num++) {
481 phy_power_off(bdc->phys[phy_num]);
482 phy_exit(bdc->phys[phy_num]);
483 }
484}
485
447static int bdc_probe(struct platform_device *pdev) 486static int bdc_probe(struct platform_device *pdev)
448{ 487{
449 struct bdc *bdc; 488 struct bdc *bdc;
@@ -452,12 +491,29 @@ static int bdc_probe(struct platform_device *pdev)
452 int irq; 491 int irq;
453 u32 temp; 492 u32 temp;
454 struct device *dev = &pdev->dev; 493 struct device *dev = &pdev->dev;
494 struct clk *clk;
495 int phy_num;
455 496
456 dev_dbg(dev, "%s()\n", __func__); 497 dev_dbg(dev, "%s()\n", __func__);
498
499 clk = devm_clk_get(dev, "sw_usbd");
500 if (IS_ERR(clk)) {
501 dev_info(dev, "Clock not found in Device Tree\n");
502 clk = NULL;
503 }
504
505 ret = clk_prepare_enable(clk);
506 if (ret) {
507 dev_err(dev, "could not enable clock\n");
508 return ret;
509 }
510
457 bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL); 511 bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL);
458 if (!bdc) 512 if (!bdc)
459 return -ENOMEM; 513 return -ENOMEM;
460 514
515 bdc->clk = clk;
516
461 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 517 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
462 bdc->regs = devm_ioremap_resource(dev, res); 518 bdc->regs = devm_ioremap_resource(dev, res);
463 if (IS_ERR(bdc->regs)) { 519 if (IS_ERR(bdc->regs)) {
@@ -473,35 +529,66 @@ static int bdc_probe(struct platform_device *pdev)
473 platform_set_drvdata(pdev, bdc); 529 platform_set_drvdata(pdev, bdc);
474 bdc->irq = irq; 530 bdc->irq = irq;
475 bdc->dev = dev; 531 bdc->dev = dev;
476 dev_dbg(bdc->dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq); 532 dev_dbg(dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq);
533
534 bdc->num_phys = of_count_phandle_with_args(dev->of_node,
535 "phys", "#phy-cells");
536 if (bdc->num_phys > 0) {
537 bdc->phys = devm_kcalloc(dev, bdc->num_phys,
538 sizeof(struct phy *), GFP_KERNEL);
539 if (!bdc->phys)
540 return -ENOMEM;
541 } else {
542 bdc->num_phys = 0;
543 }
544 dev_info(dev, "Using %d phy(s)\n", bdc->num_phys);
545
546 for (phy_num = 0; phy_num < bdc->num_phys; phy_num++) {
547 bdc->phys[phy_num] = devm_of_phy_get_by_index(
548 dev, dev->of_node, phy_num);
549 if (IS_ERR(bdc->phys[phy_num])) {
550 ret = PTR_ERR(bdc->phys[phy_num]);
551 dev_err(bdc->dev,
552 "BDC phy specified but not found:%d\n", ret);
553 return ret;
554 }
555 }
556
557 ret = bdc_phy_init(bdc);
558 if (ret) {
559 dev_err(bdc->dev, "BDC phy init failure:%d\n", ret);
560 return ret;
561 }
477 562
478 temp = bdc_readl(bdc->regs, BDC_BDCCAP1); 563 temp = bdc_readl(bdc->regs, BDC_BDCCAP1);
479 if ((temp & BDC_P64) && 564 if ((temp & BDC_P64) &&
480 !dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) { 565 !dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) {
481 dev_dbg(bdc->dev, "Using 64-bit address\n"); 566 dev_dbg(dev, "Using 64-bit address\n");
482 } else { 567 } else {
483 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); 568 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
484 if (ret) { 569 if (ret) {
485 dev_err(bdc->dev, "No suitable DMA config available, abort\n"); 570 dev_err(dev,
571 "No suitable DMA config available, abort\n");
486 return -ENOTSUPP; 572 return -ENOTSUPP;
487 } 573 }
488 dev_dbg(bdc->dev, "Using 32-bit address\n"); 574 dev_dbg(dev, "Using 32-bit address\n");
489 } 575 }
490 ret = bdc_hw_init(bdc); 576 ret = bdc_hw_init(bdc);
491 if (ret) { 577 if (ret) {
492 dev_err(bdc->dev, "BDC init failure:%d\n", ret); 578 dev_err(dev, "BDC init failure:%d\n", ret);
493 return ret; 579 goto phycleanup;
494 } 580 }
495 ret = bdc_udc_init(bdc); 581 ret = bdc_udc_init(bdc);
496 if (ret) { 582 if (ret) {
497 dev_err(bdc->dev, "BDC Gadget init failure:%d\n", ret); 583 dev_err(dev, "BDC Gadget init failure:%d\n", ret);
498 goto cleanup; 584 goto cleanup;
499 } 585 }
500 return 0; 586 return 0;
501 587
502cleanup: 588cleanup:
503 bdc_hw_exit(bdc); 589 bdc_hw_exit(bdc);
504 590phycleanup:
591 bdc_phy_exit(bdc);
505 return ret; 592 return ret;
506} 593}
507 594
@@ -513,13 +600,56 @@ static int bdc_remove(struct platform_device *pdev)
513 dev_dbg(bdc->dev, "%s ()\n", __func__); 600 dev_dbg(bdc->dev, "%s ()\n", __func__);
514 bdc_udc_exit(bdc); 601 bdc_udc_exit(bdc);
515 bdc_hw_exit(bdc); 602 bdc_hw_exit(bdc);
603 bdc_phy_exit(bdc);
604 clk_disable_unprepare(bdc->clk);
605 return 0;
606}
607
608#ifdef CONFIG_PM_SLEEP
609static int bdc_suspend(struct device *dev)
610{
611 struct bdc *bdc = dev_get_drvdata(dev);
516 612
613 clk_disable_unprepare(bdc->clk);
517 return 0; 614 return 0;
518} 615}
519 616
617static int bdc_resume(struct device *dev)
618{
619 struct bdc *bdc = dev_get_drvdata(dev);
620 int ret;
621
622 ret = clk_prepare_enable(bdc->clk);
623 if (ret) {
624 dev_err(bdc->dev, "err enabling the clock\n");
625 return ret;
626 }
627 ret = bdc_reinit(bdc);
628 if (ret) {
629 dev_err(bdc->dev, "err in bdc reinit\n");
630 return ret;
631 }
632
633 return 0;
634}
635
636#endif /* CONFIG_PM_SLEEP */
637
638static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend,
639 bdc_resume);
640
641static const struct of_device_id bdc_of_match[] = {
642 { .compatible = "brcm,bdc-v0.16" },
643 { .compatible = "brcm,bdc" },
644 { /* sentinel */ }
645};
646
520static struct platform_driver bdc_driver = { 647static struct platform_driver bdc_driver = {
521 .driver = { 648 .driver = {
522 .name = BRCM_BDC_NAME, 649 .name = BRCM_BDC_NAME,
650 .owner = THIS_MODULE,
651 .pm = &bdc_pm_ops,
652 .of_match_table = bdc_of_match,
523 }, 653 },
524 .probe = bdc_probe, 654 .probe = bdc_probe,
525 .remove = bdc_remove, 655 .remove = bdc_remove,
diff --git a/drivers/usb/gadget/udc/bdc/bdc_dbg.c b/drivers/usb/gadget/udc/bdc/bdc_dbg.c
index 5945dbc47825..ac98f6f681b7 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_dbg.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_dbg.c
@@ -40,28 +40,28 @@ void bdc_dump_epsts(struct bdc *bdc)
40{ 40{
41 u32 temp; 41 u32 temp;
42 42
43 temp = bdc_readl(bdc->regs, BDC_EPSTS0(0)); 43 temp = bdc_readl(bdc->regs, BDC_EPSTS0);
44 dev_vdbg(bdc->dev, "BDC_EPSTS0:0x%08x\n", temp); 44 dev_vdbg(bdc->dev, "BDC_EPSTS0:0x%08x\n", temp);
45 45
46 temp = bdc_readl(bdc->regs, BDC_EPSTS1(0)); 46 temp = bdc_readl(bdc->regs, BDC_EPSTS1);
47 dev_vdbg(bdc->dev, "BDC_EPSTS1:0x%x\n", temp); 47 dev_vdbg(bdc->dev, "BDC_EPSTS1:0x%x\n", temp);
48 48
49 temp = bdc_readl(bdc->regs, BDC_EPSTS2(0)); 49 temp = bdc_readl(bdc->regs, BDC_EPSTS2);
50 dev_vdbg(bdc->dev, "BDC_EPSTS2:0x%08x\n", temp); 50 dev_vdbg(bdc->dev, "BDC_EPSTS2:0x%08x\n", temp);
51 51
52 temp = bdc_readl(bdc->regs, BDC_EPSTS3(0)); 52 temp = bdc_readl(bdc->regs, BDC_EPSTS3);
53 dev_vdbg(bdc->dev, "BDC_EPSTS3:0x%08x\n", temp); 53 dev_vdbg(bdc->dev, "BDC_EPSTS3:0x%08x\n", temp);
54 54
55 temp = bdc_readl(bdc->regs, BDC_EPSTS4(0)); 55 temp = bdc_readl(bdc->regs, BDC_EPSTS4);
56 dev_vdbg(bdc->dev, "BDC_EPSTS4:0x%08x\n", temp); 56 dev_vdbg(bdc->dev, "BDC_EPSTS4:0x%08x\n", temp);
57 57
58 temp = bdc_readl(bdc->regs, BDC_EPSTS5(0)); 58 temp = bdc_readl(bdc->regs, BDC_EPSTS5);
59 dev_vdbg(bdc->dev, "BDC_EPSTS5:0x%08x\n", temp); 59 dev_vdbg(bdc->dev, "BDC_EPSTS5:0x%08x\n", temp);
60 60
61 temp = bdc_readl(bdc->regs, BDC_EPSTS6(0)); 61 temp = bdc_readl(bdc->regs, BDC_EPSTS6);
62 dev_vdbg(bdc->dev, "BDC_EPSTS6:0x%08x\n", temp); 62 dev_vdbg(bdc->dev, "BDC_EPSTS6:0x%08x\n", temp);
63 63
64 temp = bdc_readl(bdc->regs, BDC_EPSTS7(0)); 64 temp = bdc_readl(bdc->regs, BDC_EPSTS7);
65 dev_vdbg(bdc->dev, "BDC_EPSTS7:0x%08x\n", temp); 65 dev_vdbg(bdc->dev, "BDC_EPSTS7:0x%08x\n", temp);
66} 66}
67 67
diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c
index ff1ef24d1777..bfd8f7ade935 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
@@ -777,9 +777,9 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req)
777 */ 777 */
778 778
779 /* The current hw dequeue pointer */ 779 /* The current hw dequeue pointer */
780 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0(0)); 780 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0);
781 deq_ptr_64 = tmp_32; 781 deq_ptr_64 = tmp_32;
782 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS1(0)); 782 tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS1);
783 deq_ptr_64 |= ((u64)tmp_32 << 32); 783 deq_ptr_64 |= ((u64)tmp_32 << 32);
784 784
785 /* we have the dma addr of next bd that will be fetched by hardware */ 785 /* we have the dma addr of next bd that will be fetched by hardware */
diff --git a/drivers/usb/gadget/udc/bdc/bdc_udc.c b/drivers/usb/gadget/udc/bdc/bdc_udc.c
index aae7458d8986..c84346146456 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_udc.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_udc.c
@@ -249,6 +249,7 @@ void bdc_sr_uspc(struct bdc *bdc, struct bdc_sr *sreport)
249 disconn = true; 249 disconn = true;
250 else if ((uspc & BDC_PCS) && !BDC_PST(uspc)) 250 else if ((uspc & BDC_PCS) && !BDC_PST(uspc))
251 connected = true; 251 connected = true;
252 clear_flags |= BDC_PCC;
252 } 253 }
253 254
254 /* Change in VBus and VBus is present */ 255 /* Change in VBus and VBus is present */
@@ -259,16 +260,16 @@ void bdc_sr_uspc(struct bdc *bdc, struct bdc_sr *sreport)
259 bdc_softconn(bdc); 260 bdc_softconn(bdc);
260 usb_gadget_set_state(&bdc->gadget, USB_STATE_POWERED); 261 usb_gadget_set_state(&bdc->gadget, USB_STATE_POWERED);
261 } 262 }
262 clear_flags = BDC_VBC; 263 clear_flags |= BDC_VBC;
263 } else if ((uspc & BDC_PRS) || (uspc & BDC_PRC) || disconn) { 264 } else if ((uspc & BDC_PRS) || (uspc & BDC_PRC) || disconn) {
264 /* Hot reset, warm reset, 2.0 bus reset or disconn */ 265 /* Hot reset, warm reset, 2.0 bus reset or disconn */
265 dev_dbg(bdc->dev, "Port reset or disconn\n"); 266 dev_dbg(bdc->dev, "Port reset or disconn\n");
266 bdc_uspc_disconnected(bdc, disconn); 267 bdc_uspc_disconnected(bdc, disconn);
267 clear_flags = BDC_PCC|BDC_PCS|BDC_PRS|BDC_PRC; 268 clear_flags |= BDC_PRC;
268 } else if ((uspc & BDC_PSC) && (uspc & BDC_PCS)) { 269 } else if ((uspc & BDC_PSC) && (uspc & BDC_PCS)) {
269 /* Change in Link state */ 270 /* Change in Link state */
270 handle_link_state_change(bdc, uspc); 271 handle_link_state_change(bdc, uspc);
271 clear_flags = BDC_PSC|BDC_PCS; 272 clear_flags |= BDC_PSC;
272 } 273 }
273 274
274 /* 275 /*
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index e6f04eee95c4..75c51ca4ee0f 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -812,6 +812,8 @@ int usb_gadget_map_request_by_dev(struct device *dev,
812 dev_err(dev, "failed to map buffer\n"); 812 dev_err(dev, "failed to map buffer\n");
813 return -EFAULT; 813 return -EFAULT;
814 } 814 }
815
816 req->dma_mapped = 1;
815 } 817 }
816 818
817 return 0; 819 return 0;
@@ -836,9 +838,10 @@ void usb_gadget_unmap_request_by_dev(struct device *dev,
836 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 838 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
837 839
838 req->num_mapped_sgs = 0; 840 req->num_mapped_sgs = 0;
839 } else { 841 } else if (req->dma_mapped) {
840 dma_unmap_single(dev, req->dma, req->length, 842 dma_unmap_single(dev, req->dma, req->length,
841 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 843 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
844 req->dma_mapped = 0;
842 } 845 }
843} 846}
844EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev); 847EXPORT_SYMBOL_GPL(usb_gadget_unmap_request_by_dev);
@@ -1130,6 +1133,7 @@ static int check_pending_gadget_drivers(struct usb_udc *udc)
1130 * @release: a gadget release function. 1133 * @release: a gadget release function.
1131 * 1134 *
1132 * Returns zero on success, negative errno otherwise. 1135 * Returns zero on success, negative errno otherwise.
1136 * Calls the gadget release function in the latter case.
1133 */ 1137 */
1134int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, 1138int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1135 void (*release)(struct device *dev)) 1139 void (*release)(struct device *dev))
@@ -1137,10 +1141,6 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1137 struct usb_udc *udc; 1141 struct usb_udc *udc;
1138 int ret = -ENOMEM; 1142 int ret = -ENOMEM;
1139 1143
1140 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
1141 if (!udc)
1142 goto err1;
1143
1144 dev_set_name(&gadget->dev, "gadget"); 1144 dev_set_name(&gadget->dev, "gadget");
1145 INIT_WORK(&gadget->work, usb_gadget_state_work); 1145 INIT_WORK(&gadget->work, usb_gadget_state_work);
1146 gadget->dev.parent = parent; 1146 gadget->dev.parent = parent;
@@ -1150,7 +1150,13 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
1150 else 1150 else
1151 gadget->dev.release = usb_udc_nop_release; 1151 gadget->dev.release = usb_udc_nop_release;
1152 1152
1153 ret = device_register(&gadget->dev); 1153 device_initialize(&gadget->dev);
1154
1155 udc = kzalloc(sizeof(*udc), GFP_KERNEL);
1156 if (!udc)
1157 goto err1;
1158
1159 ret = device_add(&gadget->dev);
1154 if (ret) 1160 if (ret)
1155 goto err2; 1161 goto err2;
1156 1162
@@ -1197,10 +1203,10 @@ err3:
1197 device_del(&gadget->dev); 1203 device_del(&gadget->dev);
1198 1204
1199err2: 1205err2:
1200 put_device(&gadget->dev);
1201 kfree(udc); 1206 kfree(udc);
1202 1207
1203err1: 1208err1:
1209 put_device(&gadget->dev);
1204 return ret; 1210 return ret;
1205} 1211}
1206EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); 1212EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index 3c3760315910..a030d7923d7d 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -2776,7 +2776,7 @@ static int __init init(void)
2776 if (retval < 0) { 2776 if (retval < 0) {
2777 i--; 2777 i--;
2778 while (i >= 0) 2778 while (i >= 0)
2779 platform_device_del(the_udc_pdev[i]); 2779 platform_device_del(the_udc_pdev[i--]);
2780 goto err_add_udc; 2780 goto err_add_udc;
2781 } 2781 }
2782 } 2782 }
diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c b/drivers/usb/gadget/udc/fsl_qe_udc.c
index 303328ce59ee..a3e72d690eef 100644
--- a/drivers/usb/gadget/udc/fsl_qe_udc.c
+++ b/drivers/usb/gadget/udc/fsl_qe_udc.c
@@ -62,7 +62,7 @@ static const char *const ep_name[] = {
62 "ep3", 62 "ep3",
63}; 63};
64 64
65static struct usb_endpoint_descriptor qe_ep0_desc = { 65static const struct usb_endpoint_descriptor qe_ep0_desc = {
66 .bLength = USB_DT_ENDPOINT_SIZE, 66 .bLength = USB_DT_ENDPOINT_SIZE,
67 .bDescriptorType = USB_DT_ENDPOINT, 67 .bDescriptorType = USB_DT_ENDPOINT,
68 68
diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c
index 8a708d0a1042..4103bf7cf52a 100644
--- a/drivers/usb/gadget/udc/mv_udc_core.c
+++ b/drivers/usb/gadget/udc/mv_udc_core.c
@@ -39,7 +39,6 @@
39#include "mv_udc.h" 39#include "mv_udc.h"
40 40
41#define DRIVER_DESC "Marvell PXA USB Device Controller driver" 41#define DRIVER_DESC "Marvell PXA USB Device Controller driver"
42#define DRIVER_VERSION "8 Nov 2010"
43 42
44#define ep_dir(ep) (((ep)->ep_num == 0) ? \ 43#define ep_dir(ep) (((ep)->ep_num == 0) ? \
45 ((ep)->udc->ep0_dir) : ((ep)->direction)) 44 ((ep)->udc->ep0_dir) : ((ep)->direction))
@@ -2427,5 +2426,4 @@ module_platform_driver(udc_driver);
2427MODULE_ALIAS("platform:mv-udc"); 2426MODULE_ALIAS("platform:mv-udc");
2428MODULE_DESCRIPTION(DRIVER_DESC); 2427MODULE_DESCRIPTION(DRIVER_DESC);
2429MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>"); 2428MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>");
2430MODULE_VERSION(DRIVER_VERSION);
2431MODULE_LICENSE("GPL"); 2429MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
index e1de8fe599a3..df37c1e6e9d5 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -8,6 +8,7 @@
8 * the Free Software Foundation; version 2 of the License. 8 * the Free Software Foundation; version 2 of the License.
9 */ 9 */
10 10
11#include <linux/debugfs.h>
11#include <linux/delay.h> 12#include <linux/delay.h>
12#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
13#include <linux/err.h> 14#include <linux/err.h>
@@ -20,6 +21,8 @@
20#include <linux/pm_runtime.h> 21#include <linux/pm_runtime.h>
21#include <linux/sizes.h> 22#include <linux/sizes.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/sys_soc.h>
25#include <linux/uaccess.h>
23#include <linux/usb/ch9.h> 26#include <linux/usb/ch9.h>
24#include <linux/usb/gadget.h> 27#include <linux/usb/gadget.h>
25 28
@@ -347,6 +350,7 @@ struct renesas_usb3 {
347 bool workaround_for_vbus; 350 bool workaround_for_vbus;
348 bool extcon_host; /* check id and set EXTCON_USB_HOST */ 351 bool extcon_host; /* check id and set EXTCON_USB_HOST */
349 bool extcon_usb; /* check vbus and set EXTCON_USB */ 352 bool extcon_usb; /* check vbus and set EXTCON_USB */
353 bool forced_b_device;
350}; 354};
351 355
352#define gadget_to_renesas_usb3(_gadget) \ 356#define gadget_to_renesas_usb3(_gadget) \
@@ -663,7 +667,9 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev)
663 spin_lock_irqsave(&usb3->lock, flags); 667 spin_lock_irqsave(&usb3->lock, flags);
664 usb3_set_mode(usb3, host); 668 usb3_set_mode(usb3, host);
665 usb3_vbus_out(usb3, a_dev); 669 usb3_vbus_out(usb3, a_dev);
666 if (!host && a_dev) /* for A-Peripheral */ 670 /* for A-Peripheral or forced B-device mode */
671 if ((!host && a_dev) ||
672 (usb3->workaround_for_vbus && usb3->forced_b_device))
667 usb3_connect(usb3); 673 usb3_connect(usb3);
668 spin_unlock_irqrestore(&usb3->lock, flags); 674 spin_unlock_irqrestore(&usb3->lock, flags);
669} 675}
@@ -677,7 +683,7 @@ static void usb3_check_id(struct renesas_usb3 *usb3)
677{ 683{
678 usb3->extcon_host = usb3_is_a_device(usb3); 684 usb3->extcon_host = usb3_is_a_device(usb3);
679 685
680 if (usb3->extcon_host) 686 if (usb3->extcon_host && !usb3->forced_b_device)
681 usb3_mode_config(usb3, true, true); 687 usb3_mode_config(usb3, true, true);
682 else 688 else
683 usb3_mode_config(usb3, false, false); 689 usb3_mode_config(usb3, false, false);
@@ -2192,7 +2198,7 @@ static void renesas_usb3_ep_fifo_flush(struct usb_ep *_ep)
2192 } 2198 }
2193} 2199}
2194 2200
2195static struct usb_ep_ops renesas_usb3_ep_ops = { 2201static const struct usb_ep_ops renesas_usb3_ep_ops = {
2196 .enable = renesas_usb3_ep_enable, 2202 .enable = renesas_usb3_ep_enable,
2197 .disable = renesas_usb3_ep_disable, 2203 .disable = renesas_usb3_ep_disable,
2198 2204
@@ -2283,6 +2289,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
2283 if (!usb3->driver) 2289 if (!usb3->driver)
2284 return -ENODEV; 2290 return -ENODEV;
2285 2291
2292 if (usb3->forced_b_device)
2293 return -EBUSY;
2294
2286 if (!strncmp(buf, "host", strlen("host"))) 2295 if (!strncmp(buf, "host", strlen("host")))
2287 new_mode_is_host = true; 2296 new_mode_is_host = true;
2288 else if (!strncmp(buf, "peripheral", strlen("peripheral"))) 2297 else if (!strncmp(buf, "peripheral", strlen("peripheral")))
@@ -2310,6 +2319,70 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr,
2310} 2319}
2311static DEVICE_ATTR_RW(role); 2320static DEVICE_ATTR_RW(role);
2312 2321
2322static int renesas_usb3_b_device_show(struct seq_file *s, void *unused)
2323{
2324 struct renesas_usb3 *usb3 = s->private;
2325
2326 seq_printf(s, "%d\n", usb3->forced_b_device);
2327
2328 return 0;
2329}
2330
2331static int renesas_usb3_b_device_open(struct inode *inode, struct file *file)
2332{
2333 return single_open(file, renesas_usb3_b_device_show, inode->i_private);
2334}
2335
2336static ssize_t renesas_usb3_b_device_write(struct file *file,
2337 const char __user *ubuf,
2338 size_t count, loff_t *ppos)
2339{
2340 struct seq_file *s = file->private_data;
2341 struct renesas_usb3 *usb3 = s->private;
2342 char buf[32];
2343
2344 if (!usb3->driver)
2345 return -ENODEV;
2346
2347 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
2348 return -EFAULT;
2349
2350 if (!strncmp(buf, "1", 1))
2351 usb3->forced_b_device = true;
2352 else
2353 usb3->forced_b_device = false;
2354
2355 /* Let this driver call usb3_connect() anyway */
2356 usb3_check_id(usb3);
2357
2358 return count;
2359}
2360
2361static const struct file_operations renesas_usb3_b_device_fops = {
2362 .open = renesas_usb3_b_device_open,
2363 .write = renesas_usb3_b_device_write,
2364 .read = seq_read,
2365 .llseek = seq_lseek,
2366 .release = single_release,
2367};
2368
2369static void renesas_usb3_debugfs_init(struct renesas_usb3 *usb3,
2370 struct device *dev)
2371{
2372 struct dentry *root, *file;
2373
2374 root = debugfs_create_dir(dev_name(dev), NULL);
2375 if (IS_ERR_OR_NULL(root)) {
2376 dev_info(dev, "%s: Can't create the root\n", __func__);
2377 return;
2378 }
2379
2380 file = debugfs_create_file("b_device", 0644, root, usb3,
2381 &renesas_usb3_b_device_fops);
2382 if (!file)
2383 dev_info(dev, "%s: Can't create debugfs mode\n", __func__);
2384}
2385
2313/*------- platform_driver ------------------------------------------------*/ 2386/*------- platform_driver ------------------------------------------------*/
2314static int renesas_usb3_remove(struct platform_device *pdev) 2387static int renesas_usb3_remove(struct platform_device *pdev)
2315{ 2388{
@@ -2432,22 +2505,40 @@ static void renesas_usb3_init_ram(struct renesas_usb3 *usb3, struct device *dev,
2432 } 2505 }
2433} 2506}
2434 2507
2435static const struct renesas_usb3_priv renesas_usb3_priv_r8a7795 = { 2508static const struct renesas_usb3_priv renesas_usb3_priv_r8a7795_es1 = {
2436 .ramsize_per_ramif = SZ_16K, 2509 .ramsize_per_ramif = SZ_16K,
2437 .num_ramif = 2, 2510 .num_ramif = 2,
2438 .ramsize_per_pipe = SZ_4K, 2511 .ramsize_per_pipe = SZ_4K,
2439 .workaround_for_vbus = true, 2512 .workaround_for_vbus = true,
2440}; 2513};
2441 2514
2515static const struct renesas_usb3_priv renesas_usb3_priv_gen3 = {
2516 .ramsize_per_ramif = SZ_16K,
2517 .num_ramif = 4,
2518 .ramsize_per_pipe = SZ_4K,
2519};
2520
2442static const struct of_device_id usb3_of_match[] = { 2521static const struct of_device_id usb3_of_match[] = {
2443 { 2522 {
2444 .compatible = "renesas,r8a7795-usb3-peri", 2523 .compatible = "renesas,r8a7795-usb3-peri",
2445 .data = &renesas_usb3_priv_r8a7795, 2524 .data = &renesas_usb3_priv_gen3,
2525 },
2526 {
2527 .compatible = "renesas,rcar-gen3-usb3-peri",
2528 .data = &renesas_usb3_priv_gen3,
2446 }, 2529 },
2447 { }, 2530 { },
2448}; 2531};
2449MODULE_DEVICE_TABLE(of, usb3_of_match); 2532MODULE_DEVICE_TABLE(of, usb3_of_match);
2450 2533
2534static const struct soc_device_attribute renesas_usb3_quirks_match[] = {
2535 {
2536 .soc_id = "r8a7795", .revision = "ES1.*",
2537 .data = &renesas_usb3_priv_r8a7795_es1,
2538 },
2539 { /* sentinel */ },
2540};
2541
2451static const unsigned int renesas_usb3_cable[] = { 2542static const unsigned int renesas_usb3_cable[] = {
2452 EXTCON_USB, 2543 EXTCON_USB,
2453 EXTCON_USB_HOST, 2544 EXTCON_USB_HOST,
@@ -2461,15 +2552,23 @@ static int renesas_usb3_probe(struct platform_device *pdev)
2461 const struct of_device_id *match; 2552 const struct of_device_id *match;
2462 int irq, ret; 2553 int irq, ret;
2463 const struct renesas_usb3_priv *priv; 2554 const struct renesas_usb3_priv *priv;
2555 const struct soc_device_attribute *attr;
2464 2556
2465 match = of_match_node(usb3_of_match, pdev->dev.of_node); 2557 match = of_match_node(usb3_of_match, pdev->dev.of_node);
2466 if (!match) 2558 if (!match)
2467 return -ENODEV; 2559 return -ENODEV;
2468 priv = match->data; 2560
2561 attr = soc_device_match(renesas_usb3_quirks_match);
2562 if (attr)
2563 priv = attr->data;
2564 else
2565 priv = match->data;
2469 2566
2470 irq = platform_get_irq(pdev, 0); 2567 irq = platform_get_irq(pdev, 0);
2471 if (irq < 0) 2568 if (irq < 0) {
2472 return -ENODEV; 2569 dev_err(&pdev->dev, "Failed to get IRQ: %d\n", irq);
2570 return irq;
2571 }
2473 2572
2474 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); 2573 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL);
2475 if (!usb3) 2574 if (!usb3)
@@ -2527,6 +2626,8 @@ static int renesas_usb3_probe(struct platform_device *pdev)
2527 2626
2528 usb3->workaround_for_vbus = priv->workaround_for_vbus; 2627 usb3->workaround_for_vbus = priv->workaround_for_vbus;
2529 2628
2629 renesas_usb3_debugfs_init(usb3, &pdev->dev);
2630
2530 dev_info(&pdev->dev, "probed\n"); 2631 dev_info(&pdev->dev, "probed\n");
2531 2632
2532 return 0; 2633 return 0;
diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c b/drivers/usb/gadget/udc/s3c2410_udc.c
index 4643a01262b4..394abd5d65c0 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -51,7 +51,6 @@
51#include "s3c2410_udc.h" 51#include "s3c2410_udc.h"
52 52
53#define DRIVER_DESC "S3C2410 USB Device Controller Gadget" 53#define DRIVER_DESC "S3C2410 USB Device Controller Gadget"
54#define DRIVER_VERSION "29 Apr 2007"
55#define DRIVER_AUTHOR "Herbert Pötzl <herbert@13thfloor.at>, " \ 54#define DRIVER_AUTHOR "Herbert Pötzl <herbert@13thfloor.at>, " \
56 "Arnaud Patard <arnaud.patard@rtp-net.org>" 55 "Arnaud Patard <arnaud.patard@rtp-net.org>"
57 56
@@ -1996,7 +1995,7 @@ static int __init udc_init(void)
1996{ 1995{
1997 int retval; 1996 int retval;
1998 1997
1999 dprintk(DEBUG_NORMAL, "%s: version %s\n", gadget_name, DRIVER_VERSION); 1998 dprintk(DEBUG_NORMAL, "%s\n", gadget_name);
2000 1999
2001 s3c2410_udc_debugfs_root = debugfs_create_dir(gadget_name, NULL); 2000 s3c2410_udc_debugfs_root = debugfs_create_dir(gadget_name, NULL);
2002 if (IS_ERR(s3c2410_udc_debugfs_root)) { 2001 if (IS_ERR(s3c2410_udc_debugfs_root)) {
@@ -2027,5 +2026,4 @@ module_exit(udc_exit);
2027 2026
2028MODULE_AUTHOR(DRIVER_AUTHOR); 2027MODULE_AUTHOR(DRIVER_AUTHOR);
2029MODULE_DESCRIPTION(DRIVER_DESC); 2028MODULE_DESCRIPTION(DRIVER_DESC);
2030MODULE_VERSION(DRIVER_VERSION);
2031MODULE_LICENSE("GPL"); 2029MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 4a08b70c81aa..d025cc06dda7 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -642,7 +642,7 @@ static int ehci_start_port_reset(struct usb_hcd *hcd, unsigned port)
642#define ehci_start_port_reset NULL 642#define ehci_start_port_reset NULL
643#endif /* CONFIG_USB_OTG */ 643#endif /* CONFIG_USB_OTG */
644 644
645static struct ehci_driver_overrides ehci_fsl_overrides __initdata = { 645static const struct ehci_driver_overrides ehci_fsl_overrides __initconst = {
646 .extra_priv_size = sizeof(struct ehci_fsl), 646 .extra_priv_size = sizeof(struct ehci_fsl),
647 .reset = ehci_fsl_setup, 647 .reset = ehci_fsl_setup,
648}; 648};
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 94ea9fff13e6..4d308533bc83 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -130,8 +130,8 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
130 130
131 irq = platform_get_irq(pdev, 0); 131 irq = platform_get_irq(pdev, 0);
132 if (irq < 0) { 132 if (irq < 0) {
133 dev_err(dev, "EHCI irq failed\n"); 133 dev_err(dev, "EHCI irq failed: %d\n", irq);
134 return -ENODEV; 134 return irq;
135 } 135 }
136 136
137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index e90ddb530765..ba557cdba8ef 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -55,8 +55,8 @@ static struct fsl_usb2_dev_data *get_dr_mode_data(struct device_node *np)
55 return &dr_mode_data[i]; 55 return &dr_mode_data[i];
56 } 56 }
57 } 57 }
58 pr_warn("%s: Invalid 'dr_mode' property, fallback to host mode\n", 58 pr_warn("%pOF: Invalid 'dr_mode' property, fallback to host mode\n",
59 np->full_name); 59 np);
60 return &dr_mode_data[0]; /* mode not specified, use host */ 60 return &dr_mode_data[0]; /* mode not specified, use host */
61} 61}
62 62
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 1db0626c8bf4..da3b18038d23 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -614,7 +614,7 @@ error:
614 return result; 614 return result;
615} 615}
616 616
617static struct hc_driver hwahc_hc_driver = { 617static const struct hc_driver hwahc_hc_driver = {
618 .description = "hwa-hcd", 618 .description = "hwa-hcd",
619 .product_desc = "Wireless USB HWA host controller", 619 .product_desc = "Wireless USB HWA host controller",
620 .hcd_priv_size = sizeof(struct hwahc) - sizeof(struct usb_hcd), 620 .hcd_priv_size = sizeof(struct hwahc) - sizeof(struct usb_hcd),
@@ -860,7 +860,7 @@ static void hwahc_disconnect(struct usb_interface *usb_iface)
860 usb_put_hcd(usb_hcd); 860 usb_put_hcd(usb_hcd);
861} 861}
862 862
863static struct usb_device_id hwahc_id_table[] = { 863static const struct usb_device_id hwahc_id_table[] = {
864 /* Alereon 5310 */ 864 /* Alereon 5310 */
865 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x02, 0x01), 865 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x02, 0x01),
866 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC | 866 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC |
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index f542045dc2a6..39ae7fb64b6f 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -1779,7 +1779,7 @@ static void imx21_hc_stop(struct usb_hcd *hcd)
1779/* Driver glue */ 1779/* Driver glue */
1780/* =========================================== */ 1780/* =========================================== */
1781 1781
1782static struct hc_driver imx21_hc_driver = { 1782static const struct hc_driver imx21_hc_driver = {
1783 .description = hcd_name, 1783 .description = hcd_name,
1784 .product_desc = "IMX21 USB Host Controller", 1784 .product_desc = "IMX21 USB Host Controller",
1785 .hcd_priv_size = sizeof(struct imx21), 1785 .hcd_priv_size = sizeof(struct imx21),
@@ -1849,8 +1849,10 @@ static int imx21_probe(struct platform_device *pdev)
1849 if (!res) 1849 if (!res)
1850 return -ENODEV; 1850 return -ENODEV;
1851 irq = platform_get_irq(pdev, 0); 1851 irq = platform_get_irq(pdev, 0);
1852 if (irq < 0) 1852 if (irq < 0) {
1853 return -ENXIO; 1853 dev_err(&pdev->dev, "Failed to get IRQ: %d\n", irq);
1854 return irq;
1855 }
1854 1856
1855 hcd = usb_create_hcd(&imx21_hc_driver, 1857 hcd = usb_create_hcd(&imx21_hc_driver,
1856 &pdev->dev, dev_name(&pdev->dev)); 1858 &pdev->dev, dev_name(&pdev->dev));
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index d089b3fb7a13..73fec38754f9 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1511,7 +1511,7 @@ static int isp116x_bus_resume(struct usb_hcd *hcd)
1511 1511
1512#endif 1512#endif
1513 1513
1514static struct hc_driver isp116x_hc_driver = { 1514static const struct hc_driver isp116x_hc_driver = {
1515 .description = hcd_name, 1515 .description = hcd_name,
1516 .product_desc = "ISP116x Host Controller", 1516 .product_desc = "ISP116x Host Controller",
1517 .hcd_priv_size = sizeof(struct isp116x), 1517 .hcd_priv_size = sizeof(struct isp116x),
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 0f2b4b358e1a..9b7e307e2d54 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -2591,7 +2591,7 @@ static int isp1362_hc_start(struct usb_hcd *hcd)
2591 2591
2592/*-------------------------------------------------------------------------*/ 2592/*-------------------------------------------------------------------------*/
2593 2593
2594static struct hc_driver isp1362_hc_driver = { 2594static const struct hc_driver isp1362_hc_driver = {
2595 .description = hcd_name, 2595 .description = hcd_name,
2596 .product_desc = "ISP1362 Host Controller", 2596 .product_desc = "ISP1362 Host Controller",
2597 .hcd_priv_size = sizeof(struct isp1362_hcd), 2597 .hcd_priv_size = sizeof(struct isp1362_hcd),
diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
index 369869a29ebd..0ece9a9341e5 100644
--- a/drivers/usb/host/max3421-hcd.c
+++ b/drivers/usb/host/max3421-hcd.c
@@ -1811,7 +1811,7 @@ max3421_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1811{ 1811{
1812} 1812}
1813 1813
1814static struct hc_driver max3421_hcd_desc = { 1814static const struct hc_driver max3421_hcd_desc = {
1815 .description = "max3421", 1815 .description = "max3421",
1816 .product_desc = DRIVER_DESC, 1816 .product_desc = DRIVER_DESC,
1817 .hcd_priv_size = sizeof(struct max3421_hcd), 1817 .hcd_priv_size = sizeof(struct max3421_hcd),
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index c8f38649f749..658d9d1f9ea3 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -142,29 +142,30 @@ static int amd_chipset_sb_type_init(struct amd_chipset_info *pinfo)
142 pinfo->sb_type.gen = AMD_CHIPSET_SB700; 142 pinfo->sb_type.gen = AMD_CHIPSET_SB700;
143 else if (rev >= 0x40 && rev <= 0x4f) 143 else if (rev >= 0x40 && rev <= 0x4f)
144 pinfo->sb_type.gen = AMD_CHIPSET_SB800; 144 pinfo->sb_type.gen = AMD_CHIPSET_SB800;
145 }
146 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
147 0x145c, NULL);
148 if (pinfo->smbus_dev) {
149 pinfo->sb_type.gen = AMD_CHIPSET_TAISHAN;
150 } else { 145 } else {
151 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 146 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
152 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL); 147 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
153 148
154 if (!pinfo->smbus_dev) { 149 if (pinfo->smbus_dev) {
155 pinfo->sb_type.gen = NOT_AMD_CHIPSET; 150 rev = pinfo->smbus_dev->revision;
156 return 0; 151 if (rev >= 0x11 && rev <= 0x14)
152 pinfo->sb_type.gen = AMD_CHIPSET_HUDSON2;
153 else if (rev >= 0x15 && rev <= 0x18)
154 pinfo->sb_type.gen = AMD_CHIPSET_BOLTON;
155 else if (rev >= 0x39 && rev <= 0x3a)
156 pinfo->sb_type.gen = AMD_CHIPSET_YANGTZE;
157 } else {
158 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
159 0x145c, NULL);
160 if (pinfo->smbus_dev) {
161 rev = pinfo->smbus_dev->revision;
162 pinfo->sb_type.gen = AMD_CHIPSET_TAISHAN;
163 } else {
164 pinfo->sb_type.gen = NOT_AMD_CHIPSET;
165 return 0;
166 }
157 } 167 }
158
159 rev = pinfo->smbus_dev->revision;
160 if (rev >= 0x11 && rev <= 0x14)
161 pinfo->sb_type.gen = AMD_CHIPSET_HUDSON2;
162 else if (rev >= 0x15 && rev <= 0x18)
163 pinfo->sb_type.gen = AMD_CHIPSET_BOLTON;
164 else if (rev >= 0x39 && rev <= 0x3a)
165 pinfo->sb_type.gen = AMD_CHIPSET_YANGTZE;
166 } 168 }
167
168 pinfo->sb_type.rev = rev; 169 pinfo->sb_type.rev = rev;
169 return 1; 170 return 1;
170} 171}
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 7bf78be1fd32..5e5fc9d7d533 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -2312,7 +2312,7 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd)
2312#define r8a66597_bus_resume NULL 2312#define r8a66597_bus_resume NULL
2313#endif 2313#endif
2314 2314
2315static struct hc_driver r8a66597_hc_driver = { 2315static const struct hc_driver r8a66597_hc_driver = {
2316 .description = hcd_name, 2316 .description = hcd_name,
2317 .hcd_priv_size = sizeof(struct r8a66597), 2317 .hcd_priv_size = sizeof(struct r8a66597),
2318 .irq = r8a66597_irq, 2318 .irq = r8a66597_irq,
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index fd2a11473be7..24ad1d6cec25 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1554,7 +1554,7 @@ sl811h_start(struct usb_hcd *hcd)
1554 1554
1555/*-------------------------------------------------------------------------*/ 1555/*-------------------------------------------------------------------------*/
1556 1556
1557static struct hc_driver sl811h_hc_driver = { 1557static const struct hc_driver sl811h_hc_driver = {
1558 .description = hcd_name, 1558 .description = hcd_name,
1559 .hcd_priv_size = sizeof(struct sl811), 1559 .hcd_priv_size = sizeof(struct sl811),
1560 1560
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 43d52931b5bf..c38855aed62c 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -2941,7 +2941,7 @@ static int u132_bus_resume(struct usb_hcd *hcd)
2941#define u132_bus_suspend NULL 2941#define u132_bus_suspend NULL
2942#define u132_bus_resume NULL 2942#define u132_bus_resume NULL
2943#endif 2943#endif
2944static struct hc_driver u132_hc_driver = { 2944static const struct hc_driver u132_hc_driver = {
2945 .description = hcd_name, 2945 .description = hcd_name,
2946 .hcd_priv_size = sizeof(struct u132), 2946 .hcd_priv_size = sizeof(struct u132),
2947 .irq = NULL, 2947 .irq = NULL,
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index 5b3603c360ab..cf84269c3e6d 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -213,7 +213,7 @@ static void whc_endpoint_reset(struct usb_hcd *usb_hcd,
213} 213}
214 214
215 215
216static struct hc_driver whc_hc_driver = { 216static const struct hc_driver whc_hc_driver = {
217 .description = "whci-hcd", 217 .description = "whci-hcd",
218 .product_desc = "Wireless host controller", 218 .product_desc = "Wireless host controller",
219 .hcd_priv_size = sizeof(struct whc) - sizeof(struct usb_hcd), 219 .hcd_priv_size = sizeof(struct whc) - sizeof(struct usb_hcd),
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 00721e8807ab..ad89a6d4111b 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1179,6 +1179,39 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1179 break; 1179 break;
1180 } 1180 }
1181 1181
1182 /*
1183 * For xHCI 1.1 according to section 4.19.1.2.4.1 a
1184 * root hub port's transition to compliance mode upon
1185 * detecting LFPS timeout may be controlled by an
1186 * Compliance Transition Enabled (CTE) flag (not
1187 * software visible). This flag is set by writing 0xA
1188 * to PORTSC PLS field which will allow transition to
1189 * compliance mode the next time LFPS timeout is
1190 * encountered. A warm reset will clear it.
1191 *
1192 * The CTE flag is only supported if the HCCPARAMS2 CTC
1193 * flag is set, otherwise, the compliance substate is
1194 * automatically entered as on 1.0 and prior.
1195 */
1196 if (link_state == USB_SS_PORT_LS_COMP_MOD) {
1197 if (!HCC2_CTC(xhci->hcc_params2)) {
1198 xhci_dbg(xhci, "CTC flag is 0, port already supports entering compliance mode\n");
1199 break;
1200 }
1201
1202 if ((temp & PORT_CONNECT)) {
1203 xhci_warn(xhci, "Can't set compliance mode when port is connected\n");
1204 goto error;
1205 }
1206
1207 xhci_dbg(xhci, "Enable compliance mode transition for port %d\n",
1208 wIndex);
1209 xhci_set_link_state(xhci, port_array, wIndex,
1210 link_state);
1211 temp = readl(port_array[wIndex]);
1212 break;
1213 }
1214
1182 /* Software should not attempt to set 1215 /* Software should not attempt to set
1183 * port link state above '3' (U3) and the port 1216 * port link state above '3' (U3) and the port
1184 * must be enabled. 1217 * must be enabled.
@@ -1521,15 +1554,14 @@ static bool xhci_port_missing_cas_quirk(int port_index,
1521int xhci_bus_resume(struct usb_hcd *hcd) 1554int xhci_bus_resume(struct usb_hcd *hcd)
1522{ 1555{
1523 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1556 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1524 int max_ports, port_index;
1525 __le32 __iomem **port_array;
1526 struct xhci_bus_state *bus_state; 1557 struct xhci_bus_state *bus_state;
1527 u32 temp; 1558 __le32 __iomem **port_array;
1528 unsigned long flags; 1559 unsigned long flags;
1529 unsigned long port_was_suspended = 0; 1560 int max_ports, port_index;
1530 bool need_usb2_u3_exit = false;
1531 int slot_id; 1561 int slot_id;
1532 int sret; 1562 int sret;
1563 u32 next_state;
1564 u32 temp, portsc;
1533 1565
1534 max_ports = xhci_get_ports(hcd, &port_array); 1566 max_ports = xhci_get_ports(hcd, &port_array);
1535 bus_state = &xhci->bus_state[hcd_index(hcd)]; 1567 bus_state = &xhci->bus_state[hcd_index(hcd)];
@@ -1548,68 +1580,77 @@ int xhci_bus_resume(struct usb_hcd *hcd)
1548 temp &= ~CMD_EIE; 1580 temp &= ~CMD_EIE;
1549 writel(temp, &xhci->op_regs->command); 1581 writel(temp, &xhci->op_regs->command);
1550 1582
1583 /* bus specific resume for ports we suspended at bus_suspend */
1584 if (hcd->speed >= HCD_USB3)
1585 next_state = XDEV_U0;
1586 else
1587 next_state = XDEV_RESUME;
1588
1551 port_index = max_ports; 1589 port_index = max_ports;
1552 while (port_index--) { 1590 while (port_index--) {
1553 /* Check whether need resume ports. If needed 1591 portsc = readl(port_array[port_index]);
1554 resume port and disable remote wakeup */
1555 u32 temp;
1556
1557 temp = readl(port_array[port_index]);
1558 1592
1559 /* warm reset CAS limited ports stuck in polling/compliance */ 1593 /* warm reset CAS limited ports stuck in polling/compliance */
1560 if ((xhci->quirks & XHCI_MISSING_CAS) && 1594 if ((xhci->quirks & XHCI_MISSING_CAS) &&
1561 (hcd->speed >= HCD_USB3) && 1595 (hcd->speed >= HCD_USB3) &&
1562 xhci_port_missing_cas_quirk(port_index, port_array)) { 1596 xhci_port_missing_cas_quirk(port_index, port_array)) {
1563 xhci_dbg(xhci, "reset stuck port %d\n", port_index); 1597 xhci_dbg(xhci, "reset stuck port %d\n", port_index);
1598 clear_bit(port_index, &bus_state->bus_suspended);
1564 continue; 1599 continue;
1565 } 1600 }
1566 if (DEV_SUPERSPEED_ANY(temp)) 1601 /* resume if we suspended the link, and it is still suspended */
1567 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); 1602 if (test_bit(port_index, &bus_state->bus_suspended))
1568 else 1603 switch (portsc & PORT_PLS_MASK) {
1569 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); 1604 case XDEV_U3:
1570 if (test_bit(port_index, &bus_state->bus_suspended) && 1605 portsc = xhci_port_state_to_neutral(portsc);
1571 (temp & PORT_PLS_MASK)) { 1606 portsc &= ~PORT_PLS_MASK;
1572 set_bit(port_index, &port_was_suspended); 1607 portsc |= PORT_LINK_STROBE | next_state;
1573 if (!DEV_SUPERSPEED_ANY(temp)) { 1608 break;
1574 xhci_set_link_state(xhci, port_array, 1609 case XDEV_RESUME:
1575 port_index, XDEV_RESUME); 1610 /* resume already initiated */
1576 need_usb2_u3_exit = true; 1611 break;
1612 default:
1613 /* not in a resumeable state, ignore it */
1614 clear_bit(port_index,
1615 &bus_state->bus_suspended);
1616 break;
1577 } 1617 }
1578 } else 1618 /* disable wake for all ports, write new link state if needed */
1579 writel(temp, port_array[port_index]); 1619 portsc &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
1580 } 1620 writel(portsc, port_array[port_index]);
1581
1582 if (need_usb2_u3_exit) {
1583 spin_unlock_irqrestore(&xhci->lock, flags);
1584 msleep(USB_RESUME_TIMEOUT);
1585 spin_lock_irqsave(&xhci->lock, flags);
1586 } 1621 }
1587 1622
1588 port_index = max_ports; 1623 /* USB2 specific resume signaling delay and U0 link state transition */
1589 while (port_index--) { 1624 if (hcd->speed < HCD_USB3) {
1590 if (!(port_was_suspended & BIT(port_index))) 1625 if (bus_state->bus_suspended) {
1591 continue; 1626 spin_unlock_irqrestore(&xhci->lock, flags);
1592 /* Clear PLC to poll it later after XDEV_U0 */ 1627 msleep(USB_RESUME_TIMEOUT);
1593 xhci_test_and_clear_bit(xhci, port_array, port_index, PORT_PLC); 1628 spin_lock_irqsave(&xhci->lock, flags);
1594 xhci_set_link_state(xhci, port_array, port_index, XDEV_U0); 1629 }
1630 for_each_set_bit(port_index, &bus_state->bus_suspended,
1631 BITS_PER_LONG) {
1632 /* Clear PLC to poll it later for U0 transition */
1633 xhci_test_and_clear_bit(xhci, port_array, port_index,
1634 PORT_PLC);
1635 xhci_set_link_state(xhci, port_array, port_index,
1636 XDEV_U0);
1637 }
1595 } 1638 }
1596 1639
1597 port_index = max_ports; 1640 /* poll for U0 link state complete, both USB2 and USB3 */
1598 while (port_index--) { 1641 for_each_set_bit(port_index, &bus_state->bus_suspended, BITS_PER_LONG) {
1599 if (!(port_was_suspended & BIT(port_index)))
1600 continue;
1601 /* Poll and Clear PLC */
1602 sret = xhci_handshake(port_array[port_index], PORT_PLC, 1642 sret = xhci_handshake(port_array[port_index], PORT_PLC,
1603 PORT_PLC, 10 * 1000); 1643 PORT_PLC, 10 * 1000);
1604 if (sret) 1644 if (sret) {
1605 xhci_warn(xhci, "port %d resume PLC timeout\n", 1645 xhci_warn(xhci, "port %d resume PLC timeout\n",
1606 port_index); 1646 port_index);
1647 continue;
1648 }
1607 xhci_test_and_clear_bit(xhci, port_array, port_index, PORT_PLC); 1649 xhci_test_and_clear_bit(xhci, port_array, port_index, PORT_PLC);
1608 slot_id = xhci_find_slot_id_by_port(hcd, xhci, port_index + 1); 1650 slot_id = xhci_find_slot_id_by_port(hcd, xhci, port_index + 1);
1609 if (slot_id) 1651 if (slot_id)
1610 xhci_ring_device(xhci, slot_id); 1652 xhci_ring_device(xhci, slot_id);
1611 } 1653 }
1612
1613 (void) readl(&xhci->op_regs->command); 1654 (void) readl(&xhci->op_regs->command);
1614 1655
1615 bus_state->next_statechange = jiffies + msecs_to_jiffies(5); 1656 bus_state->next_statechange = jiffies + msecs_to_jiffies(5);
diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 67d5dc79b6b5..8fb60657ed4f 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -795,6 +795,7 @@ static const struct dev_pm_ops xhci_mtk_pm_ops = {
795#ifdef CONFIG_OF 795#ifdef CONFIG_OF
796static const struct of_device_id mtk_xhci_of_match[] = { 796static const struct of_device_id mtk_xhci_of_match[] = {
797 { .compatible = "mediatek,mt8173-xhci"}, 797 { .compatible = "mediatek,mt8173-xhci"},
798 { .compatible = "mediatek,mtk-xhci"},
798 { }, 799 { },
799}; 800};
800MODULE_DEVICE_TABLE(of, mtk_xhci_of_match); 801MODULE_DEVICE_TABLE(of, mtk_xhci_of_match);
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index c04144b25a67..163bafde709f 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -107,14 +107,6 @@ static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = {
107}; 107};
108 108
109static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = { 109static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = {
110 .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V2,
111 .init_quirk = xhci_rcar_init_quirk,
112 .plat_start = xhci_rcar_start,
113 .resume_quirk = xhci_rcar_resume_quirk,
114};
115
116static const struct xhci_plat_priv xhci_plat_renesas_rcar_r8a7796 = {
117 .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V3,
118 .init_quirk = xhci_rcar_init_quirk, 110 .init_quirk = xhci_rcar_init_quirk,
119 .plat_start = xhci_rcar_start, 111 .plat_start = xhci_rcar_start,
120 .resume_quirk = xhci_rcar_resume_quirk, 112 .resume_quirk = xhci_rcar_resume_quirk,
@@ -145,7 +137,7 @@ static const struct of_device_id usb_xhci_of_match[] = {
145 .data = &xhci_plat_renesas_rcar_gen3, 137 .data = &xhci_plat_renesas_rcar_gen3,
146 }, { 138 }, {
147 .compatible = "renesas,xhci-r8a7796", 139 .compatible = "renesas,xhci-r8a7796",
148 .data = &xhci_plat_renesas_rcar_r8a7796, 140 .data = &xhci_plat_renesas_rcar_gen3,
149 }, { 141 }, {
150 .compatible = "renesas,rcar-gen2-xhci", 142 .compatible = "renesas,rcar-gen2-xhci",
151 .data = &xhci_plat_renesas_rcar_gen2, 143 .data = &xhci_plat_renesas_rcar_gen2,
diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index 07278228214b..198bc188ab25 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -13,13 +13,15 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/of.h> 14#include <linux/of.h>
15#include <linux/usb/phy.h> 15#include <linux/usb/phy.h>
16#include <linux/sys_soc.h>
16 17
17#include "xhci.h" 18#include "xhci.h"
18#include "xhci-plat.h" 19#include "xhci-plat.h"
19#include "xhci-rcar.h" 20#include "xhci-rcar.h"
20 21
21/* 22/*
22* - The V3 firmware is for r8a7796 (with good performance). 23* - The V3 firmware is for r8a7796 (with good performance) and r8a7795 es2.0
24* or later.
23* - The V2 firmware can be used on both r8a7795 (es1.x) and r8a7796. 25* - The V2 firmware can be used on both r8a7795 (es1.x) and r8a7796.
24* - The V2 firmware is possible to use on R-Car Gen2. However, the V2 causes 26* - The V2 firmware is possible to use on R-Car Gen2. However, the V2 causes
25* performance degradation. So, this driver continues to use the V1 if R-Car 27* performance degradation. So, this driver continues to use the V1 if R-Car
@@ -67,6 +69,26 @@ MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V3);
67#define RCAR_USB3_RX_POL_VAL BIT(21) 69#define RCAR_USB3_RX_POL_VAL BIT(21)
68#define RCAR_USB3_TX_POL_VAL BIT(4) 70#define RCAR_USB3_TX_POL_VAL BIT(4)
69 71
72/* For soc_device_attribute */
73#define RCAR_XHCI_FIRMWARE_V2 BIT(0) /* FIRMWARE V2 */
74#define RCAR_XHCI_FIRMWARE_V3 BIT(1) /* FIRMWARE V3 */
75
76static const struct soc_device_attribute rcar_quirks_match[] = {
77 {
78 .soc_id = "r8a7795", .revision = "ES1.*",
79 .data = (void *)RCAR_XHCI_FIRMWARE_V2,
80 },
81 {
82 .soc_id = "r8a7795",
83 .data = (void *)RCAR_XHCI_FIRMWARE_V3,
84 },
85 {
86 .soc_id = "r8a7796",
87 .data = (void *)RCAR_XHCI_FIRMWARE_V3,
88 },
89 { /* sentinel */ },
90};
91
70static void xhci_rcar_start_gen2(struct usb_hcd *hcd) 92static void xhci_rcar_start_gen2(struct usb_hcd *hcd)
71{ 93{
72 /* LCLK Select */ 94 /* LCLK Select */
@@ -122,9 +144,23 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
122 int retval, index, j, time; 144 int retval, index, j, time;
123 int timeout = 10000; 145 int timeout = 10000;
124 u32 data, val, temp; 146 u32 data, val, temp;
147 u32 quirks = 0;
148 const struct soc_device_attribute *attr;
149 const char *firmware_name;
150
151 attr = soc_device_match(rcar_quirks_match);
152 if (attr)
153 quirks = (uintptr_t)attr->data;
154
155 if (quirks & RCAR_XHCI_FIRMWARE_V2)
156 firmware_name = XHCI_RCAR_FIRMWARE_NAME_V2;
157 else if (quirks & RCAR_XHCI_FIRMWARE_V3)
158 firmware_name = XHCI_RCAR_FIRMWARE_NAME_V3;
159 else
160 firmware_name = priv->firmware_name;
125 161
126 /* request R-Car USB3.0 firmware */ 162 /* request R-Car USB3.0 firmware */
127 retval = request_firmware(&fw, priv->firmware_name, dev); 163 retval = request_firmware(&fw, firmware_name, dev);
128 if (retval) 164 if (retval)
129 return retval; 165 return retval;
130 166
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index cc368ad2b51e..a9443651ce0f 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1572,7 +1572,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
1572{ 1572{
1573 struct usb_hcd *hcd; 1573 struct usb_hcd *hcd;
1574 u32 port_id; 1574 u32 port_id;
1575 u32 temp, temp1; 1575 u32 portsc, cmd_reg;
1576 int max_ports; 1576 int max_ports;
1577 int slot_id; 1577 int slot_id;
1578 unsigned int faked_port_index; 1578 unsigned int faked_port_index;
@@ -1636,26 +1636,28 @@ static void handle_port_status(struct xhci_hcd *xhci,
1636 /* Find the faked port hub number */ 1636 /* Find the faked port hub number */
1637 faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci, 1637 faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci,
1638 port_id); 1638 port_id);
1639 portsc = readl(port_array[faked_port_index]);
1640
1641 trace_xhci_handle_port_status(faked_port_index, portsc);
1639 1642
1640 temp = readl(port_array[faked_port_index]);
1641 if (hcd->state == HC_STATE_SUSPENDED) { 1643 if (hcd->state == HC_STATE_SUSPENDED) {
1642 xhci_dbg(xhci, "resume root hub\n"); 1644 xhci_dbg(xhci, "resume root hub\n");
1643 usb_hcd_resume_root_hub(hcd); 1645 usb_hcd_resume_root_hub(hcd);
1644 } 1646 }
1645 1647
1646 if (hcd->speed >= HCD_USB3 && (temp & PORT_PLS_MASK) == XDEV_INACTIVE) 1648 if (hcd->speed >= HCD_USB3 && (portsc & PORT_PLS_MASK) == XDEV_INACTIVE)
1647 bus_state->port_remote_wakeup &= ~(1 << faked_port_index); 1649 bus_state->port_remote_wakeup &= ~(1 << faked_port_index);
1648 1650
1649 if ((temp & PORT_PLC) && (temp & PORT_PLS_MASK) == XDEV_RESUME) { 1651 if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) {
1650 xhci_dbg(xhci, "port resume event for port %d\n", port_id); 1652 xhci_dbg(xhci, "port resume event for port %d\n", port_id);
1651 1653
1652 temp1 = readl(&xhci->op_regs->command); 1654 cmd_reg = readl(&xhci->op_regs->command);
1653 if (!(temp1 & CMD_RUN)) { 1655 if (!(cmd_reg & CMD_RUN)) {
1654 xhci_warn(xhci, "xHC is not running.\n"); 1656 xhci_warn(xhci, "xHC is not running.\n");
1655 goto cleanup; 1657 goto cleanup;
1656 } 1658 }
1657 1659
1658 if (DEV_SUPERSPEED_ANY(temp)) { 1660 if (DEV_SUPERSPEED_ANY(portsc)) {
1659 xhci_dbg(xhci, "remote wake SS port %d\n", port_id); 1661 xhci_dbg(xhci, "remote wake SS port %d\n", port_id);
1660 /* Set a flag to say the port signaled remote wakeup, 1662 /* Set a flag to say the port signaled remote wakeup,
1661 * so we can tell the difference between the end of 1663 * so we can tell the difference between the end of
@@ -1683,8 +1685,8 @@ static void handle_port_status(struct xhci_hcd *xhci,
1683 } 1685 }
1684 } 1686 }
1685 1687
1686 if ((temp & PORT_PLC) && (temp & PORT_PLS_MASK) == XDEV_U0 && 1688 if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_U0 &&
1687 DEV_SUPERSPEED_ANY(temp)) { 1689 DEV_SUPERSPEED_ANY(portsc)) {
1688 xhci_dbg(xhci, "resume SS port %d finished\n", port_id); 1690 xhci_dbg(xhci, "resume SS port %d finished\n", port_id);
1689 /* We've just brought the device into U0 through either the 1691 /* We've just brought the device into U0 through either the
1690 * Resume state after a device remote wakeup, or through the 1692 * Resume state after a device remote wakeup, or through the
@@ -1714,7 +1716,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
1714 * RExit to a disconnect state). If so, let the the driver know it's 1716 * RExit to a disconnect state). If so, let the the driver know it's
1715 * out of the RExit state. 1717 * out of the RExit state.
1716 */ 1718 */
1717 if (!DEV_SUPERSPEED_ANY(temp) && 1719 if (!DEV_SUPERSPEED_ANY(portsc) &&
1718 test_and_clear_bit(faked_port_index, 1720 test_and_clear_bit(faked_port_index,
1719 &bus_state->rexit_ports)) { 1721 &bus_state->rexit_ports)) {
1720 complete(&bus_state->rexit_done[faked_port_index]); 1722 complete(&bus_state->rexit_done[faked_port_index]);
diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h
index 8ce96de10e8a..f20753b99624 100644
--- a/drivers/usb/host/xhci-trace.h
+++ b/drivers/usb/host/xhci-trace.h
@@ -453,6 +453,29 @@ DEFINE_EVENT(xhci_log_ring, xhci_inc_deq,
453 TP_PROTO(struct xhci_ring *ring), 453 TP_PROTO(struct xhci_ring *ring),
454 TP_ARGS(ring) 454 TP_ARGS(ring)
455); 455);
456
457DECLARE_EVENT_CLASS(xhci_log_portsc,
458 TP_PROTO(u32 portnum, u32 portsc),
459 TP_ARGS(portnum, portsc),
460 TP_STRUCT__entry(
461 __field(u32, portnum)
462 __field(u32, portsc)
463 ),
464 TP_fast_assign(
465 __entry->portnum = portnum;
466 __entry->portsc = portsc;
467 ),
468 TP_printk("port-%d: %s",
469 __entry->portnum,
470 xhci_decode_portsc(__entry->portsc)
471 )
472);
473
474DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
475 TP_PROTO(u32 portnum, u32 portsc),
476 TP_ARGS(portnum, portsc)
477);
478
456#endif /* __XHCI_TRACE_H */ 479#endif /* __XHCI_TRACE_H */
457 480
458/* this part must be outside header guard */ 481/* this part must be outside header guard */
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index e3e935291ed6..2abaa4d6d39d 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -311,12 +311,19 @@ struct xhci_op_regs {
311 */ 311 */
312#define PORT_PLS_MASK (0xf << 5) 312#define PORT_PLS_MASK (0xf << 5)
313#define XDEV_U0 (0x0 << 5) 313#define XDEV_U0 (0x0 << 5)
314#define XDEV_U1 (0x1 << 5)
314#define XDEV_U2 (0x2 << 5) 315#define XDEV_U2 (0x2 << 5)
315#define XDEV_U3 (0x3 << 5) 316#define XDEV_U3 (0x3 << 5)
317#define XDEV_DISABLED (0x4 << 5)
318#define XDEV_RXDETECT (0x5 << 5)
316#define XDEV_INACTIVE (0x6 << 5) 319#define XDEV_INACTIVE (0x6 << 5)
317#define XDEV_POLLING (0x7 << 5) 320#define XDEV_POLLING (0x7 << 5)
318#define XDEV_COMP_MODE (0xa << 5) 321#define XDEV_RECOVERY (0x8 << 5)
322#define XDEV_HOT_RESET (0x9 << 5)
323#define XDEV_COMP_MODE (0xa << 5)
324#define XDEV_TEST_MODE (0xb << 5)
319#define XDEV_RESUME (0xf << 5) 325#define XDEV_RESUME (0xf << 5)
326
320/* true: port has power (see HCC_PPC) */ 327/* true: port has power (see HCC_PPC) */
321#define PORT_POWER (1 << 9) 328#define PORT_POWER (1 << 9)
322/* bits 10:13 indicate device speed: 329/* bits 10:13 indicate device speed:
@@ -2392,6 +2399,87 @@ static inline const char *xhci_decode_slot_context(u32 info, u32 info2,
2392 return str; 2399 return str;
2393} 2400}
2394 2401
2402
2403static inline const char *xhci_portsc_link_state_string(u32 portsc)
2404{
2405 switch (portsc & PORT_PLS_MASK) {
2406 case XDEV_U0:
2407 return "U0";
2408 case XDEV_U1:
2409 return "U1";
2410 case XDEV_U2:
2411 return "U2";
2412 case XDEV_U3:
2413 return "U3";
2414 case XDEV_DISABLED:
2415 return "Disabled";
2416 case XDEV_RXDETECT:
2417 return "RxDetect";
2418 case XDEV_INACTIVE:
2419 return "Inactive";
2420 case XDEV_POLLING:
2421 return "Polling";
2422 case XDEV_RECOVERY:
2423 return "Recovery";
2424 case XDEV_HOT_RESET:
2425 return "Hot Reset";
2426 case XDEV_COMP_MODE:
2427 return "Compliance mode";
2428 case XDEV_TEST_MODE:
2429 return "Test mode";
2430 case XDEV_RESUME:
2431 return "Resume";
2432 default:
2433 break;
2434 }
2435 return "Unknown";
2436}
2437
2438static inline const char *xhci_decode_portsc(u32 portsc)
2439{
2440 static char str[256];
2441 int ret;
2442
2443 ret = sprintf(str, "%s %s %s Link:%s ",
2444 portsc & PORT_POWER ? "Powered" : "Powered-off",
2445 portsc & PORT_CONNECT ? "Connected" : "Not-connected",
2446 portsc & PORT_PE ? "Enabled" : "Disabled",
2447 xhci_portsc_link_state_string(portsc));
2448
2449 if (portsc & PORT_OC)
2450 ret += sprintf(str + ret, "OverCurrent ");
2451 if (portsc & PORT_RESET)
2452 ret += sprintf(str + ret, "In-Reset ");
2453
2454 ret += sprintf(str + ret, "Change: ");
2455 if (portsc & PORT_CSC)
2456 ret += sprintf(str + ret, "CSC ");
2457 if (portsc & PORT_PEC)
2458 ret += sprintf(str + ret, "PEC ");
2459 if (portsc & PORT_WRC)
2460 ret += sprintf(str + ret, "WRC ");
2461 if (portsc & PORT_OCC)
2462 ret += sprintf(str + ret, "OCC ");
2463 if (portsc & PORT_RC)
2464 ret += sprintf(str + ret, "PRC ");
2465 if (portsc & PORT_PLC)
2466 ret += sprintf(str + ret, "PLC ");
2467 if (portsc & PORT_CEC)
2468 ret += sprintf(str + ret, "CEC ");
2469 if (portsc & PORT_CAS)
2470 ret += sprintf(str + ret, "CAS ");
2471
2472 ret += sprintf(str + ret, "Wake: ");
2473 if (portsc & PORT_WKCONN_E)
2474 ret += sprintf(str + ret, "WCE ");
2475 if (portsc & PORT_WKDISC_E)
2476 ret += sprintf(str + ret, "WDE ");
2477 if (portsc & PORT_WKOC_E)
2478 ret += sprintf(str + ret, "WOE ");
2479
2480 return str;
2481}
2482
2395static inline const char *xhci_ep_state_string(u8 state) 2483static inline const char *xhci_ep_state_string(u8 state)
2396{ 2484{
2397 switch (state) { 2485 switch (state) {
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index a4dbb0cd80da..0b21ba757bba 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -137,10 +137,6 @@
137 137
138#include "microtek.h" 138#include "microtek.h"
139 139
140/*
141 * Version Information
142 */
143#define DRIVER_VERSION "v0.4.3"
144#define DRIVER_AUTHOR "John Fremlin <vii@penguinpowered.com>, Oliver Neukum <Oliver.Neukum@lrz.uni-muenchen.de>" 140#define DRIVER_AUTHOR "John Fremlin <vii@penguinpowered.com>, Oliver Neukum <Oliver.Neukum@lrz.uni-muenchen.de>"
145#define DRIVER_DESC "Microtek Scanmaker X6 USB scanner driver" 141#define DRIVER_DESC "Microtek Scanmaker X6 USB scanner driver"
146 142
diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c
index ac31d19cc54b..8e59e0c02b8a 100644
--- a/drivers/usb/isp1760/isp1760-hcd.c
+++ b/drivers/usb/isp1760/isp1760-hcd.c
@@ -396,7 +396,6 @@ static int handshake(struct usb_hcd *hcd, u32 reg,
396/* reset a non-running (STS_HALT == 1) controller */ 396/* reset a non-running (STS_HALT == 1) controller */
397static int ehci_reset(struct usb_hcd *hcd) 397static int ehci_reset(struct usb_hcd *hcd)
398{ 398{
399 int retval;
400 struct isp1760_hcd *priv = hcd_to_priv(hcd); 399 struct isp1760_hcd *priv = hcd_to_priv(hcd);
401 400
402 u32 command = reg_read32(hcd->regs, HC_USBCMD); 401 u32 command = reg_read32(hcd->regs, HC_USBCMD);
@@ -405,9 +404,8 @@ static int ehci_reset(struct usb_hcd *hcd)
405 reg_write32(hcd->regs, HC_USBCMD, command); 404 reg_write32(hcd->regs, HC_USBCMD, command);
406 hcd->state = HC_STATE_HALT; 405 hcd->state = HC_STATE_HALT;
407 priv->next_statechange = jiffies; 406 priv->next_statechange = jiffies;
408 retval = handshake(hcd, HC_USBCMD, 407
409 CMD_RESET, 0, 250 * 1000); 408 return handshake(hcd, HC_USBCMD, CMD_RESET, 0, 250 * 1000);
410 return retval;
411} 409}
412 410
413static struct isp1760_qh *qh_alloc(gfp_t flags) 411static struct isp1760_qh *qh_alloc(gfp_t flags)
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index dfd54ea4808f..1c0ada75c35d 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -29,8 +29,6 @@
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/uaccess.h> 30#include <linux/uaccess.h>
31 31
32/* Version Information */
33#define DRIVER_VERSION "v0.0.13"
34#define DRIVER_AUTHOR "John Homppi" 32#define DRIVER_AUTHOR "John Homppi"
35#define DRIVER_DESC "adutux (see www.ontrak.net)" 33#define DRIVER_DESC "adutux (see www.ontrak.net)"
36 34
diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
index 15d4e64d3b65..abec6e604a62 100644
--- a/drivers/usb/misc/chaoskey.c
+++ b/drivers/usb/misc/chaoskey.c
@@ -42,12 +42,10 @@ static int chaoskey_rng_read(struct hwrng *rng, void *data,
42 dev_err(&(usb_if)->dev, format, ## arg) 42 dev_err(&(usb_if)->dev, format, ## arg)
43 43
44/* Version Information */ 44/* Version Information */
45#define DRIVER_VERSION "v0.1"
46#define DRIVER_AUTHOR "Keith Packard, keithp@keithp.com" 45#define DRIVER_AUTHOR "Keith Packard, keithp@keithp.com"
47#define DRIVER_DESC "Altus Metrum ChaosKey driver" 46#define DRIVER_DESC "Altus Metrum ChaosKey driver"
48#define DRIVER_SHORT "chaoskey" 47#define DRIVER_SHORT "chaoskey"
49 48
50MODULE_VERSION(DRIVER_VERSION);
51MODULE_AUTHOR(DRIVER_AUTHOR); 49MODULE_AUTHOR(DRIVER_AUTHOR);
52MODULE_DESCRIPTION(DRIVER_DESC); 50MODULE_DESCRIPTION(DRIVER_DESC);
53MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c
index 9d8bb8dacdcd..63207c42acf6 100644
--- a/drivers/usb/misc/cytherm.c
+++ b/drivers/usb/misc/cytherm.c
@@ -20,7 +20,6 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/usb.h> 21#include <linux/usb.h>
22 22
23#define DRIVER_VERSION "v1.0"
24#define DRIVER_AUTHOR "Erik Rigtorp" 23#define DRIVER_AUTHOR "Erik Rigtorp"
25#define DRIVER_DESC "Cypress USB Thermometer driver" 24#define DRIVER_DESC "Cypress USB Thermometer driver"
26 25
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 8291499d0581..424ff12f3b51 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -305,9 +305,9 @@ static int ftdi_elan_command_engine(struct usb_ftdi *ftdi);
305static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi); 305static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi);
306static int ftdi_elan_hcd_init(struct usb_ftdi *ftdi) 306static int ftdi_elan_hcd_init(struct usb_ftdi *ftdi)
307{ 307{
308 int result;
309 if (ftdi->platform_dev.dev.parent) 308 if (ftdi->platform_dev.dev.parent)
310 return -EBUSY; 309 return -EBUSY;
310
311 ftdi_elan_get_kref(ftdi); 311 ftdi_elan_get_kref(ftdi);
312 ftdi->platform_data.potpg = 100; 312 ftdi->platform_data.potpg = 100;
313 ftdi->platform_data.reset = NULL; 313 ftdi->platform_data.reset = NULL;
@@ -324,8 +324,8 @@ static int ftdi_elan_hcd_init(struct usb_ftdi *ftdi)
324 request_module("u132_hcd"); 324 request_module("u132_hcd");
325 dev_info(&ftdi->udev->dev, "registering '%s'\n", 325 dev_info(&ftdi->udev->dev, "registering '%s'\n",
326 ftdi->platform_dev.name); 326 ftdi->platform_dev.name);
327 result = platform_device_register(&ftdi->platform_dev); 327
328 return result; 328 return platform_device_register(&ftdi->platform_dev);
329} 329}
330 330
331static void ftdi_elan_abandon_completions(struct usb_ftdi *ftdi) 331static void ftdi_elan_abandon_completions(struct usb_ftdi *ftdi)
@@ -857,7 +857,7 @@ static char *have_ed_set_response(struct usb_ftdi *ftdi,
857 target->actual = 0; 857 target->actual = 0;
858 target->non_null = (ed_length >> 15) & 0x0001; 858 target->non_null = (ed_length >> 15) & 0x0001;
859 target->repeat_number = (ed_length >> 11) & 0x000F; 859 target->repeat_number = (ed_length >> 11) & 0x000F;
860 if (ed_type == 0x02) { 860 if (ed_type == 0x02 || ed_type == 0x03) {
861 if (payload == 0 || target->abandoning > 0) { 861 if (payload == 0 || target->abandoning > 0) {
862 target->abandoning = 0; 862 target->abandoning = 0;
863 mutex_unlock(&ftdi->u132_lock); 863 mutex_unlock(&ftdi->u132_lock);
@@ -873,31 +873,6 @@ static char *have_ed_set_response(struct usb_ftdi *ftdi,
873 mutex_unlock(&ftdi->u132_lock); 873 mutex_unlock(&ftdi->u132_lock);
874 return b; 874 return b;
875 } 875 }
876 } else if (ed_type == 0x03) {
877 if (payload == 0 || target->abandoning > 0) {
878 target->abandoning = 0;
879 mutex_unlock(&ftdi->u132_lock);
880 ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
881 payload);
882 ftdi->received = 0;
883 ftdi->expected = 4;
884 ftdi->ed_found = 0;
885 return ftdi->response;
886 } else {
887 ftdi->expected = 4 + payload;
888 ftdi->ed_found = 1;
889 mutex_unlock(&ftdi->u132_lock);
890 return b;
891 }
892 } else if (ed_type == 0x01) {
893 target->abandoning = 0;
894 mutex_unlock(&ftdi->u132_lock);
895 ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
896 payload);
897 ftdi->received = 0;
898 ftdi->expected = 4;
899 ftdi->ed_found = 0;
900 return ftdi->response;
901 } else { 876 } else {
902 target->abandoning = 0; 877 target->abandoning = 0;
903 mutex_unlock(&ftdi->u132_lock); 878 mutex_unlock(&ftdi->u132_lock);
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index 81fcbf024c65..39d8fedfaf3b 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -33,8 +33,6 @@
33#define HEADER "P5 225 289 255 " 33#define HEADER "P5 225 289 255 "
34#define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1) 34#define IMGSIZE ((WIDTH * HEIGHT) + sizeof(HEADER)-1)
35 35
36/* version information */
37#define DRIVER_VERSION "0.6"
38#define DRIVER_SHORT "idmouse" 36#define DRIVER_SHORT "idmouse"
39#define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>" 37#define DRIVER_AUTHOR "Florian 'Floe' Echtler <echtler@fs.tum.de>"
40#define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver" 38#define DRIVER_DESC "Siemens ID Mouse FingerTIP Sensor Driver"
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 7ca4c7e0ea0d..be5881303681 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -21,10 +21,8 @@
21#include <linux/poll.h> 21#include <linux/poll.h>
22#include <linux/usb/iowarrior.h> 22#include <linux/usb/iowarrior.h>
23 23
24/* Version Information */
25#define DRIVER_VERSION "v0.4.0"
26#define DRIVER_AUTHOR "Christian Lucht <lucht@codemercs.com>" 24#define DRIVER_AUTHOR "Christian Lucht <lucht@codemercs.com>"
27#define DRIVER_DESC "USB IO-Warrior driver (Linux 2.6.x)" 25#define DRIVER_DESC "USB IO-Warrior driver"
28 26
29#define USB_VENDOR_ID_CODEMERCS 1984 27#define USB_VENDOR_ID_CODEMERCS 1984
30/* low speed iowarrior */ 28/* low speed iowarrior */
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 9d9487c66f87..680bddb3ce05 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -112,7 +112,6 @@ static const struct usb_device_id ld_usb_table[] = {
112 { } /* Terminating entry */ 112 { } /* Terminating entry */
113}; 113};
114MODULE_DEVICE_TABLE(usb, ld_usb_table); 114MODULE_DEVICE_TABLE(usb, ld_usb_table);
115MODULE_VERSION("V0.14");
116MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>"); 115MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
117MODULE_DESCRIPTION("LD USB Driver"); 116MODULE_DESCRIPTION("LD USB Driver");
118MODULE_LICENSE("GPL"); 117MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 0782ac6f5edf..5628f678ab59 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -88,8 +88,6 @@
88#include <linux/poll.h> 88#include <linux/poll.h>
89 89
90 90
91/* Version Information */
92#define DRIVER_VERSION "v0.96"
93#define DRIVER_AUTHOR "Juergen Stuber <starblue@sourceforge.net>" 91#define DRIVER_AUTHOR "Juergen Stuber <starblue@sourceforge.net>"
94#define DRIVER_DESC "LEGO USB Tower Driver" 92#define DRIVER_DESC "LEGO USB Tower Driver"
95 93
diff --git a/drivers/usb/misc/lvstest.c b/drivers/usb/misc/lvstest.c
index 2142132a1f82..ddddd6387f66 100644
--- a/drivers/usb/misc/lvstest.c
+++ b/drivers/usb/misc/lvstest.c
@@ -178,6 +178,25 @@ static ssize_t hot_reset_store(struct device *dev,
178} 178}
179static DEVICE_ATTR_WO(hot_reset); 179static DEVICE_ATTR_WO(hot_reset);
180 180
181static ssize_t warm_reset_store(struct device *dev,
182 struct device_attribute *attr, const char *buf, size_t count)
183{
184 struct usb_interface *intf = to_usb_interface(dev);
185 struct usb_device *hdev = interface_to_usbdev(intf);
186 struct lvs_rh *lvs = usb_get_intfdata(intf);
187 int ret;
188
189 ret = lvs_rh_set_port_feature(hdev, lvs->portnum,
190 USB_PORT_FEAT_BH_PORT_RESET);
191 if (ret < 0) {
192 dev_err(dev, "can't issue warm reset %d\n", ret);
193 return ret;
194 }
195
196 return count;
197}
198static DEVICE_ATTR_WO(warm_reset);
199
181static ssize_t u2_timeout_store(struct device *dev, 200static ssize_t u2_timeout_store(struct device *dev,
182 struct device_attribute *attr, const char *buf, size_t count) 201 struct device_attribute *attr, const char *buf, size_t count)
183{ 202{
@@ -274,13 +293,35 @@ free_desc:
274} 293}
275static DEVICE_ATTR_WO(get_dev_desc); 294static DEVICE_ATTR_WO(get_dev_desc);
276 295
296static ssize_t enable_compliance_store(struct device *dev,
297 struct device_attribute *attr, const char *buf, size_t count)
298{
299 struct usb_interface *intf = to_usb_interface(dev);
300 struct usb_device *hdev = interface_to_usbdev(intf);
301 struct lvs_rh *lvs = usb_get_intfdata(intf);
302 int ret;
303
304 ret = lvs_rh_set_port_feature(hdev,
305 lvs->portnum | USB_SS_PORT_LS_COMP_MOD << 3,
306 USB_PORT_FEAT_LINK_STATE);
307 if (ret < 0) {
308 dev_err(dev, "can't enable compliance mode %d\n", ret);
309 return ret;
310 }
311
312 return count;
313}
314static DEVICE_ATTR_WO(enable_compliance);
315
277static struct attribute *lvs_attributes[] = { 316static struct attribute *lvs_attributes[] = {
278 &dev_attr_get_dev_desc.attr, 317 &dev_attr_get_dev_desc.attr,
279 &dev_attr_u1_timeout.attr, 318 &dev_attr_u1_timeout.attr,
280 &dev_attr_u2_timeout.attr, 319 &dev_attr_u2_timeout.attr,
281 &dev_attr_hot_reset.attr, 320 &dev_attr_hot_reset.attr,
321 &dev_attr_warm_reset.attr,
282 &dev_attr_u3_entry.attr, 322 &dev_attr_u3_entry.attr,
283 &dev_attr_u3_exit.attr, 323 &dev_attr_u3_exit.attr,
324 &dev_attr_enable_compliance.attr,
284 NULL 325 NULL
285}; 326};
286 327
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index b106ce76997b..ddfebb144aaa 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -43,10 +43,6 @@
43 43
44#include "rio500_usb.h" 44#include "rio500_usb.h"
45 45
46/*
47 * Version Information
48 */
49#define DRIVER_VERSION "v1.1"
50#define DRIVER_AUTHOR "Cesar Miquel <miquel@df.uba.ar>" 46#define DRIVER_AUTHOR "Cesar Miquel <miquel@df.uba.ar>"
51#define DRIVER_DESC "USB Rio 500 driver" 47#define DRIVER_DESC "USB Rio 500 driver"
52 48
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 440d7fef58cc..30774e0aeadd 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -610,13 +610,11 @@ static int sisusb_write_memio_byte(struct sisusb_usb_data *sisusb, int type,
610 u32 addr, u8 data) 610 u32 addr, u8 data)
611{ 611{
612 struct sisusb_packet packet; 612 struct sisusb_packet packet;
613 int ret;
614 613
615 packet.header = (1 << (addr & 3)) | (type << 6); 614 packet.header = (1 << (addr & 3)) | (type << 6);
616 packet.address = addr & ~3; 615 packet.address = addr & ~3;
617 packet.data = data << ((addr & 3) << 3); 616 packet.data = data << ((addr & 3) << 3);
618 ret = sisusb_send_packet(sisusb, 10, &packet); 617 return sisusb_send_packet(sisusb, 10, &packet);
619 return ret;
620} 618}
621 619
622static int sisusb_write_memio_word(struct sisusb_usb_data *sisusb, int type, 620static int sisusb_write_memio_word(struct sisusb_usb_data *sisusb, int type,
@@ -1333,13 +1331,11 @@ static int sisusb_write_pci_config(struct sisusb_usb_data *sisusb,
1333 int regnum, u32 data) 1331 int regnum, u32 data)
1334{ 1332{
1335 struct sisusb_packet packet; 1333 struct sisusb_packet packet;
1336 int ret;
1337 1334
1338 packet.header = 0x008f; 1335 packet.header = 0x008f;
1339 packet.address = regnum | 0x10000; 1336 packet.address = regnum | 0x10000;
1340 packet.data = data; 1337 packet.data = data;
1341 ret = sisusb_send_packet(sisusb, 10, &packet); 1338 return sisusb_send_packet(sisusb, 10, &packet);
1342 return ret;
1343} 1339}
1344 1340
1345static int sisusb_read_pci_config(struct sisusb_usb_data *sisusb, 1341static int sisusb_read_pci_config(struct sisusb_usb_data *sisusb,
@@ -2982,14 +2978,11 @@ err_out:
2982static long sisusb_compat_ioctl(struct file *f, unsigned int cmd, 2978static long sisusb_compat_ioctl(struct file *f, unsigned int cmd,
2983 unsigned long arg) 2979 unsigned long arg)
2984{ 2980{
2985 long retval;
2986
2987 switch (cmd) { 2981 switch (cmd) {
2988 case SISUSB_GET_CONFIG_SIZE: 2982 case SISUSB_GET_CONFIG_SIZE:
2989 case SISUSB_GET_CONFIG: 2983 case SISUSB_GET_CONFIG:
2990 case SISUSB_COMMAND: 2984 case SISUSB_COMMAND:
2991 retval = sisusb_ioctl(f, cmd, arg); 2985 return sisusb_ioctl(f, cmd, arg);
2992 return retval;
2993 2986
2994 default: 2987 default:
2995 return -ENOIOCTLCMD; 2988 return -ENOIOCTLCMD;
diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c
index 9795457723d8..1862ed15ce28 100644
--- a/drivers/usb/misc/trancevibrator.c
+++ b/drivers/usb/misc/trancevibrator.c
@@ -25,8 +25,6 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27 27
28/* Version Information */
29#define DRIVER_VERSION "v1.1"
30#define DRIVER_AUTHOR "Sam Hocevar, sam@zoy.org" 28#define DRIVER_AUTHOR "Sam Hocevar, sam@zoy.org"
31#define DRIVER_DESC "PlayStation 2 Trance Vibrator driver" 29#define DRIVER_DESC "PlayStation 2 Trance Vibrator driver"
32 30
diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 91f66d68bcb7..135c91c434bf 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -114,7 +114,6 @@
114 114
115#define DRIVER_NAME "usb251xb" 115#define DRIVER_NAME "usb251xb"
116#define DRIVER_DESC "Microchip USB 2.0 Hi-Speed Hub Controller" 116#define DRIVER_DESC "Microchip USB 2.0 Hi-Speed Hub Controller"
117#define DRIVER_VERSION "1.0"
118 117
119struct usb251xb { 118struct usb251xb {
120 struct device *dev; 119 struct device *dev;
diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c
index 388fae6373db..3f6a28045b53 100644
--- a/drivers/usb/misc/usbsevseg.c
+++ b/drivers/usb/misc/usbsevseg.c
@@ -330,7 +330,7 @@ static struct attribute *dev_attrs[] = {
330 NULL 330 NULL
331}; 331};
332 332
333static struct attribute_group dev_attr_grp = { 333static const struct attribute_group dev_attr_grp = {
334 .attrs = dev_attrs, 334 .attrs = dev_attrs,
335}; 335};
336 336
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index 5947373700a1..8a13b2fcf3e1 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -52,10 +52,6 @@
52#include <linux/slab.h> 52#include <linux/slab.h>
53#include <linux/sched/signal.h> 53#include <linux/sched/signal.h>
54 54
55/*
56 * Version Information
57 */
58#define DRIVER_VERSION "v0.6"
59#define DRIVER_AUTHOR "Thomas M. Sailer, t.sailer@alumni.ethz.ch" 55#define DRIVER_AUTHOR "Thomas M. Sailer, t.sailer@alumni.ethz.ch"
60#define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip" 56#define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip"
61 57
@@ -816,8 +812,7 @@ static int __init uss720_init(void)
816 if (retval) 812 if (retval)
817 goto out; 813 goto out;
818 814
819 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 815 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
820 DRIVER_DESC "\n");
821 printk(KERN_INFO KBUILD_MODNAME ": NOTE: this is a special purpose " 816 printk(KERN_INFO KBUILD_MODNAME ": NOTE: this is a special purpose "
822 "driver to allow nonstandard\n"); 817 "driver to allow nonstandard\n");
823 printk(KERN_INFO KBUILD_MODNAME ": protocols (eg. bitbang) over " 818 printk(KERN_INFO KBUILD_MODNAME ": protocols (eg. bitbang) over "
diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index 7b6dc23d77e9..b26fffc58446 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -288,6 +288,7 @@ static inline struct ssusb_mtk *dev_to_ssusb(struct device *dev)
288 * MTU3_U3_IP_SLOT_DEFAULT for U3 IP 288 * MTU3_U3_IP_SLOT_DEFAULT for U3 IP
289 * @may_wakeup: means device's remote wakeup is enabled 289 * @may_wakeup: means device's remote wakeup is enabled
290 * @is_self_powered: is reported in device status and the config descriptor 290 * @is_self_powered: is reported in device status and the config descriptor
291 * @delayed_status: true when function drivers ask for delayed status
291 * @ep0_req: dummy request used while handling standard USB requests 292 * @ep0_req: dummy request used while handling standard USB requests
292 * for GET_STATUS and SET_SEL 293 * for GET_STATUS and SET_SEL
293 * @setup_buf: ep0 response buffer for GET_STATUS and SET_SEL requests 294 * @setup_buf: ep0 response buffer for GET_STATUS and SET_SEL requests
@@ -327,6 +328,7 @@ struct mtu3 {
327 unsigned u1_enable:1; 328 unsigned u1_enable:1;
328 unsigned u2_enable:1; 329 unsigned u2_enable:1;
329 unsigned is_u3_ip:1; 330 unsigned is_u3_ip:1;
331 unsigned delayed_status:1;
330 332
331 u8 address; 333 u8 address;
332 u8 test_mode_nr; 334 u8 test_mode_nr;
diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c
index 11a0d3b84c5e..560256115b23 100644
--- a/drivers/usb/mtu3/mtu3_dr.c
+++ b/drivers/usb/mtu3/mtu3_dr.c
@@ -322,23 +322,65 @@ static const struct file_operations ssusb_mode_fops = {
322 .release = single_release, 322 .release = single_release,
323}; 323};
324 324
325static int ssusb_vbus_show(struct seq_file *sf, void *unused)
326{
327 struct ssusb_mtk *ssusb = sf->private;
328 struct otg_switch_mtk *otg_sx = &ssusb->otg_switch;
329
330 seq_printf(sf, "vbus state: %s\n(echo on/off)\n",
331 regulator_is_enabled(otg_sx->vbus) ? "on" : "off");
332
333 return 0;
334}
335
336static int ssusb_vbus_open(struct inode *inode, struct file *file)
337{
338 return single_open(file, ssusb_vbus_show, inode->i_private);
339}
340
341static ssize_t ssusb_vbus_write(struct file *file,
342 const char __user *ubuf, size_t count, loff_t *ppos)
343{
344 struct seq_file *sf = file->private_data;
345 struct ssusb_mtk *ssusb = sf->private;
346 struct otg_switch_mtk *otg_sx = &ssusb->otg_switch;
347 char buf[16];
348 bool enable;
349
350 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
351 return -EFAULT;
352
353 if (kstrtobool(buf, &enable)) {
354 dev_err(ssusb->dev, "wrong setting\n");
355 return -EINVAL;
356 }
357
358 ssusb_set_vbus(otg_sx, enable);
359
360 return count;
361}
362
363static const struct file_operations ssusb_vbus_fops = {
364 .open = ssusb_vbus_open,
365 .write = ssusb_vbus_write,
366 .read = seq_read,
367 .llseek = seq_lseek,
368 .release = single_release,
369};
370
325static void ssusb_debugfs_init(struct ssusb_mtk *ssusb) 371static void ssusb_debugfs_init(struct ssusb_mtk *ssusb)
326{ 372{
327 struct dentry *root; 373 struct dentry *root;
328 struct dentry *file;
329 374
330 root = debugfs_create_dir(dev_name(ssusb->dev), usb_debug_root); 375 root = debugfs_create_dir(dev_name(ssusb->dev), usb_debug_root);
331 if (IS_ERR_OR_NULL(root)) { 376 if (!root) {
332 if (!root) 377 dev_err(ssusb->dev, "create debugfs root failed\n");
333 dev_err(ssusb->dev, "create debugfs root failed\n");
334 return; 378 return;
335 } 379 }
336 ssusb->dbgfs_root = root; 380 ssusb->dbgfs_root = root;
337 381
338 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, 382 debugfs_create_file("mode", 0644, root, ssusb, &ssusb_mode_fops);
339 ssusb, &ssusb_mode_fops); 383 debugfs_create_file("vbus", 0644, root, ssusb, &ssusb_vbus_fops);
340 if (!file)
341 dev_dbg(ssusb->dev, "create debugfs mode failed\n");
342} 384}
343 385
344static void ssusb_debugfs_exit(struct ssusb_mtk *ssusb) 386static void ssusb_debugfs_exit(struct ssusb_mtk *ssusb)
diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index 9dd2441b4fa1..434fca58143c 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -663,6 +663,7 @@ int mtu3_gadget_setup(struct mtu3 *mtu)
663 mtu->g.sg_supported = 0; 663 mtu->g.sg_supported = 0;
664 mtu->g.name = MTU3_DRIVER_NAME; 664 mtu->g.name = MTU3_DRIVER_NAME;
665 mtu->is_active = 0; 665 mtu->is_active = 0;
666 mtu->delayed_status = false;
666 667
667 mtu3_gadget_init_eps(mtu); 668 mtu3_gadget_init_eps(mtu);
668 669
@@ -727,4 +728,7 @@ void mtu3_gadget_reset(struct mtu3 *mtu)
727 mtu->address = 0; 728 mtu->address = 0;
728 mtu->ep0_state = MU3D_EP0_STATE_SETUP; 729 mtu->ep0_state = MU3D_EP0_STATE_SETUP;
729 mtu->may_wakeup = 0; 730 mtu->may_wakeup = 0;
731 mtu->u1_enable = 0;
732 mtu->u2_enable = 0;
733 mtu->delayed_status = false;
730} 734}
diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index 2d7427b48775..958d74dd2b78 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -16,6 +16,8 @@
16 * 16 *
17 */ 17 */
18 18
19#include <linux/usb/composite.h>
20
19#include "mtu3.h" 21#include "mtu3.h"
20 22
21/* ep0 is always mtu3->in_eps[0] */ 23/* ep0 is always mtu3->in_eps[0] */
@@ -150,6 +152,7 @@ static void ep0_stall_set(struct mtu3_ep *mep0, bool set, u32 pktrdy)
150 csr = (csr & ~EP0_SENDSTALL) | EP0_SENTSTALL; 152 csr = (csr & ~EP0_SENDSTALL) | EP0_SENTSTALL;
151 mtu3_writel(mtu->mac_base, U3D_EP0CSR, csr); 153 mtu3_writel(mtu->mac_base, U3D_EP0CSR, csr);
152 154
155 mtu->delayed_status = false;
153 mtu->ep0_state = MU3D_EP0_STATE_SETUP; 156 mtu->ep0_state = MU3D_EP0_STATE_SETUP;
154 157
155 dev_dbg(mtu->dev, "ep0: %s STALL, ep0_state: %s\n", 158 dev_dbg(mtu->dev, "ep0: %s STALL, ep0_state: %s\n",
@@ -656,6 +659,9 @@ stall:
656finish: 659finish:
657 if (mtu->test_mode) { 660 if (mtu->test_mode) {
658 ; /* nothing to do */ 661 ; /* nothing to do */
662 } else if (handled == USB_GADGET_DELAYED_STATUS) {
663 /* handle the delay STATUS phase till receive ep_queue on ep0 */
664 mtu->delayed_status = true;
659 } else if (le16_to_cpu(setup.wLength) == 0) { /* no data stage */ 665 } else if (le16_to_cpu(setup.wLength) == 0) { /* no data stage */
660 666
661 mtu3_writel(mbase, U3D_EP0CSR, 667 mtu3_writel(mbase, U3D_EP0CSR,
@@ -775,9 +781,6 @@ static int ep0_queue(struct mtu3_ep *mep, struct mtu3_request *mreq)
775 dev_dbg(mtu->dev, "%s %s (ep0_state: %s), len#%d\n", __func__, 781 dev_dbg(mtu->dev, "%s %s (ep0_state: %s), len#%d\n", __func__,
776 mep->name, decode_ep0_state(mtu), mreq->request.length); 782 mep->name, decode_ep0_state(mtu), mreq->request.length);
777 783
778 if (!list_empty(&mep->req_list))
779 return -EBUSY;
780
781 switch (mtu->ep0_state) { 784 switch (mtu->ep0_state) {
782 case MU3D_EP0_STATE_SETUP: 785 case MU3D_EP0_STATE_SETUP:
783 case MU3D_EP0_STATE_RX: /* control-OUT data */ 786 case MU3D_EP0_STATE_RX: /* control-OUT data */
@@ -789,6 +792,20 @@ static int ep0_queue(struct mtu3_ep *mep, struct mtu3_request *mreq)
789 return -EINVAL; 792 return -EINVAL;
790 } 793 }
791 794
795 if (mtu->delayed_status) {
796 u32 csr;
797
798 mtu->delayed_status = false;
799 csr = mtu3_readl(mtu->mac_base, U3D_EP0CSR) & EP0_W1C_BITS;
800 csr |= EP0_SETUPPKTRDY | EP0_DATAEND;
801 mtu3_writel(mtu->mac_base, U3D_EP0CSR, csr);
802 /* needn't giveback the request for handling delay STATUS */
803 return 0;
804 }
805
806 if (!list_empty(&mep->req_list))
807 return -EBUSY;
808
792 list_add_tail(&mreq->list, &mep->req_list); 809 list_add_tail(&mreq->list, &mep->req_list);
793 810
794 /* sequence #1, IN ... start writing the data */ 811 /* sequence #1, IN ... start writing the data */
diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c
index cd4d01087855..e42d308b8dc2 100644
--- a/drivers/usb/mtu3/mtu3_host.c
+++ b/drivers/usb/mtu3/mtu3_host.c
@@ -258,8 +258,8 @@ int ssusb_host_init(struct ssusb_mtk *ssusb, struct device_node *parent_dn)
258 258
259 ret = of_platform_populate(parent_dn, NULL, NULL, parent_dev); 259 ret = of_platform_populate(parent_dn, NULL, NULL, parent_dev);
260 if (ret) { 260 if (ret) {
261 dev_dbg(parent_dev, "failed to create child devices at %s\n", 261 dev_dbg(parent_dev, "failed to create child devices at %pOF\n",
262 parent_dn->full_name); 262 parent_dn);
263 return ret; 263 return ret;
264 } 264 }
265 265
diff --git a/drivers/usb/mtu3/mtu3_hw_regs.h b/drivers/usb/mtu3/mtu3_hw_regs.h
index 212367295276..06b29664470f 100644
--- a/drivers/usb/mtu3/mtu3_hw_regs.h
+++ b/drivers/usb/mtu3/mtu3_hw_regs.h
@@ -462,10 +462,12 @@
462#define SSUSB_U3_PORT_DIS BIT(0) 462#define SSUSB_U3_PORT_DIS BIT(0)
463 463
464/* U3D_SSUSB_U2_CTRL_0P */ 464/* U3D_SSUSB_U2_CTRL_0P */
465#define SSUSB_U2_PORT_VBUSVALID BIT(9)
465#define SSUSB_U2_PORT_OTG_SEL BIT(7) 466#define SSUSB_U2_PORT_OTG_SEL BIT(7)
466#define SSUSB_U2_PORT_HOST_SEL BIT(2) 467#define SSUSB_U2_PORT_HOST BIT(2)
467#define SSUSB_U2_PORT_PDN BIT(1) 468#define SSUSB_U2_PORT_PDN BIT(1)
468#define SSUSB_U2_PORT_DIS BIT(0) 469#define SSUSB_U2_PORT_DIS BIT(0)
470#define SSUSB_U2_PORT_HOST_SEL (SSUSB_U2_PORT_VBUSVALID | SSUSB_U2_PORT_HOST)
469 471
470/* U3D_SSUSB_DEV_RST_CTRL */ 472/* U3D_SSUSB_DEV_RST_CTRL */
471#define SSUSB_DEV_SW_RST BIT(0) 473#define SSUSB_DEV_SW_RST BIT(0)
diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 0d3ebb353e08..088e3e685c4f 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -500,6 +500,7 @@ static const struct dev_pm_ops mtu3_pm_ops = {
500 500
501static const struct of_device_id mtu3_of_match[] = { 501static const struct of_device_id mtu3_of_match[] = {
502 {.compatible = "mediatek,mt8173-mtu3",}, 502 {.compatible = "mediatek,mt8173-mtu3",},
503 {.compatible = "mediatek,mtu3",},
503 {}, 504 {},
504}; 505};
505 506
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 87cbd56cc761..029692053dd3 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1156,8 +1156,8 @@ static struct musb_fifo_cfg mode_2_cfg[] = {
1156{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1156{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1157{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, 1157{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
1158{ .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, }, 1158{ .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
1159{ .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, }, 1159{ .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 960, },
1160{ .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, }, 1160{ .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 1024, },
1161}; 1161};
1162 1162
1163/* mode 3 - fits in 4KB */ 1163/* mode 3 - fits in 4KB */
@@ -2671,6 +2671,13 @@ static int musb_suspend(struct device *dev)
2671{ 2671{
2672 struct musb *musb = dev_to_musb(dev); 2672 struct musb *musb = dev_to_musb(dev);
2673 unsigned long flags; 2673 unsigned long flags;
2674 int ret;
2675
2676 ret = pm_runtime_get_sync(dev);
2677 if (ret < 0) {
2678 pm_runtime_put_noidle(dev);
2679 return ret;
2680 }
2674 2681
2675 musb_platform_disable(musb); 2682 musb_platform_disable(musb);
2676 musb_disable_interrupts(musb); 2683 musb_disable_interrupts(musb);
@@ -2721,14 +2728,6 @@ static int musb_resume(struct device *dev)
2721 if ((devctl & mask) != (musb->context.devctl & mask)) 2728 if ((devctl & mask) != (musb->context.devctl & mask))
2722 musb->port1_status = 0; 2729 musb->port1_status = 0;
2723 2730
2724 /*
2725 * The USB HUB code expects the device to be in RPM_ACTIVE once it came
2726 * out of suspend
2727 */
2728 pm_runtime_disable(dev);
2729 pm_runtime_set_active(dev);
2730 pm_runtime_enable(dev);
2731
2732 musb_start(musb); 2731 musb_start(musb);
2733 2732
2734 spin_lock_irqsave(&musb->lock, flags); 2733 spin_lock_irqsave(&musb->lock, flags);
@@ -2738,6 +2737,9 @@ static int musb_resume(struct device *dev)
2738 error); 2737 error);
2739 spin_unlock_irqrestore(&musb->lock, flags); 2738 spin_unlock_irqrestore(&musb->lock, flags);
2740 2739
2740 pm_runtime_mark_last_busy(dev);
2741 pm_runtime_put_autosuspend(dev);
2742
2741 return 0; 2743 return 0;
2742} 2744}
2743 2745
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 9f22c5b8ce37..c748f4ac1154 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -465,6 +465,30 @@ static inline struct musb *gadget_to_musb(struct usb_gadget *g)
465 return container_of(g, struct musb, g); 465 return container_of(g, struct musb, g);
466} 466}
467 467
468static inline char *musb_ep_xfertype_string(u8 type)
469{
470 char *s;
471
472 switch (type) {
473 case USB_ENDPOINT_XFER_CONTROL:
474 s = "ctrl";
475 break;
476 case USB_ENDPOINT_XFER_ISOC:
477 s = "iso";
478 break;
479 case USB_ENDPOINT_XFER_BULK:
480 s = "bulk";
481 break;
482 case USB_ENDPOINT_XFER_INT:
483 s = "int";
484 break;
485 default:
486 s = "";
487 break;
488 }
489 return s;
490}
491
468#ifdef CONFIG_BLACKFIN 492#ifdef CONFIG_BLACKFIN
469static inline int musb_read_fifosize(struct musb *musb, 493static inline int musb_read_fifosize(struct musb *musb,
470 struct musb_hw_ep *hw_ep, u8 epnum) 494 struct musb_hw_ep *hw_ep, u8 epnum)
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index bc6a9be2ccc5..f6b526606ad1 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -1015,13 +1015,20 @@ static int dsps_suspend(struct device *dev)
1015 const struct dsps_musb_wrapper *wrp = glue->wrp; 1015 const struct dsps_musb_wrapper *wrp = glue->wrp;
1016 struct musb *musb = platform_get_drvdata(glue->musb); 1016 struct musb *musb = platform_get_drvdata(glue->musb);
1017 void __iomem *mbase; 1017 void __iomem *mbase;
1018 1018 int ret;
1019 del_timer_sync(&glue->timer);
1020 1019
1021 if (!musb) 1020 if (!musb)
1022 /* This can happen if the musb device is in -EPROBE_DEFER */ 1021 /* This can happen if the musb device is in -EPROBE_DEFER */
1023 return 0; 1022 return 0;
1024 1023
1024 ret = pm_runtime_get_sync(dev);
1025 if (ret < 0) {
1026 pm_runtime_put_noidle(dev);
1027 return ret;
1028 }
1029
1030 del_timer_sync(&glue->timer);
1031
1025 mbase = musb->ctrl_base; 1032 mbase = musb->ctrl_base;
1026 glue->context.control = musb_readl(mbase, wrp->control); 1033 glue->context.control = musb_readl(mbase, wrp->control);
1027 glue->context.epintr = musb_readl(mbase, wrp->epintr_set); 1034 glue->context.epintr = musb_readl(mbase, wrp->epintr_set);
@@ -1060,6 +1067,8 @@ static int dsps_resume(struct device *dev)
1060 musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE) 1067 musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
1061 dsps_mod_timer(glue, -1); 1068 dsps_mod_timer(glue, -1);
1062 1069
1070 pm_runtime_put(dev);
1071
1063 return 0; 1072 return 0;
1064} 1073}
1065#endif 1074#endif
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 1acc4864f9f6..bc6d1717c9ec 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1105,11 +1105,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
1105 1105
1106 pr_debug("%s periph: enabled %s for %s %s, %smaxpacket %d\n", 1106 pr_debug("%s periph: enabled %s for %s %s, %smaxpacket %d\n",
1107 musb_driver_name, musb_ep->end_point.name, 1107 musb_driver_name, musb_ep->end_point.name,
1108 ({ char *s; switch (musb_ep->type) { 1108 musb_ep_xfertype_string(musb_ep->type),
1109 case USB_ENDPOINT_XFER_BULK: s = "bulk"; break;
1110 case USB_ENDPOINT_XFER_INT: s = "int"; break;
1111 default: s = "iso"; break;
1112 } s; }),
1113 musb_ep->is_in ? "IN" : "OUT", 1109 musb_ep->is_in ? "IN" : "OUT",
1114 musb_ep->dma ? "dma, " : "", 1110 musb_ep->dma ? "dma, " : "",
1115 musb_ep->packet_sz); 1111 musb_ep->packet_sz);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 3344ffd5bb13..b17450a59882 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2152,6 +2152,10 @@ static int musb_schedule(
2152 (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4; 2152 (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4;
2153 goto success; 2153 goto success;
2154 } else if (best_end < 0) { 2154 } else if (best_end < 0) {
2155 dev_err(musb->controller,
2156 "%s hwep alloc failed for %dx%d\n",
2157 musb_ep_xfertype_string(qh->type),
2158 qh->hb_mult, qh->maxpacket);
2155 return -ENOSPC; 2159 return -ENOSPC;
2156 } 2160 }
2157 2161
@@ -2244,6 +2248,10 @@ static int musb_urb_enqueue(
2244 ok = (usb_pipein(urb->pipe) && musb->hb_iso_rx) 2248 ok = (usb_pipein(urb->pipe) && musb->hb_iso_rx)
2245 || (usb_pipeout(urb->pipe) && musb->hb_iso_tx); 2249 || (usb_pipeout(urb->pipe) && musb->hb_iso_tx);
2246 if (!ok) { 2250 if (!ok) {
2251 dev_err(musb->controller,
2252 "high bandwidth %s (%dx%d) not supported\n",
2253 musb_ep_xfertype_string(qh->type),
2254 qh->hb_mult, qh->maxpacket & 0x7ff);
2247 ret = -EMSGSIZE; 2255 ret = -EMSGSIZE;
2248 goto done; 2256 goto done;
2249 } 2257 }
diff --git a/drivers/usb/phy/phy-mv-usb.c b/drivers/usb/phy/phy-mv-usb.c
index 697a741a0cb1..0e315694adc9 100644
--- a/drivers/usb/phy/phy-mv-usb.c
+++ b/drivers/usb/phy/phy-mv-usb.c
@@ -29,10 +29,8 @@
29#include "phy-mv-usb.h" 29#include "phy-mv-usb.h"
30 30
31#define DRIVER_DESC "Marvell USB OTG transceiver driver" 31#define DRIVER_DESC "Marvell USB OTG transceiver driver"
32#define DRIVER_VERSION "Jan 20, 2010"
33 32
34MODULE_DESCRIPTION(DRIVER_DESC); 33MODULE_DESCRIPTION(DRIVER_DESC);
35MODULE_VERSION(DRIVER_VERSION);
36MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
37 35
38static const char driver_name[] = "mv-otg"; 36static const char driver_name[] = "mv-otg";
@@ -650,7 +648,7 @@ static struct attribute *inputs_attrs[] = {
650 NULL, 648 NULL,
651}; 649};
652 650
653static struct attribute_group inputs_attr_group = { 651static const struct attribute_group inputs_attr_group = {
654 .name = "inputs", 652 .name = "inputs",
655 .attrs = inputs_attrs, 653 .attrs = inputs_attrs,
656}; 654};
diff --git a/drivers/usb/phy/phy-qcom-8x16-usb.c b/drivers/usb/phy/phy-qcom-8x16-usb.c
index b6a83a5cbad3..679afeaaa9a8 100644
--- a/drivers/usb/phy/phy-qcom-8x16-usb.c
+++ b/drivers/usb/phy/phy-qcom-8x16-usb.c
@@ -270,12 +270,9 @@ static int phy_8x16_probe(struct platform_device *pdev)
270 platform_set_drvdata(pdev, qphy); 270 platform_set_drvdata(pdev, qphy);
271 271
272 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 272 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
273 if (!res) 273 qphy->regs = devm_ioremap_resource(&pdev->dev, res);
274 return -EINVAL; 274 if (IS_ERR(qphy->regs))
275 275 return PTR_ERR(qphy->regs);
276 qphy->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
277 if (!qphy->regs)
278 return -ENOMEM;
279 276
280 phy = &qphy->phy; 277 phy = &qphy->phy;
281 phy->dev = &pdev->dev; 278 phy->dev = &pdev->dev;
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
index a31c8682e998..8babd318c0ed 100644
--- a/drivers/usb/phy/phy-tahvo.c
+++ b/drivers/usb/phy/phy-tahvo.c
@@ -326,7 +326,7 @@ static struct attribute *tahvo_attributes[] = {
326 NULL 326 NULL
327}; 327};
328 328
329static struct attribute_group tahvo_attr_group = { 329static const struct attribute_group tahvo_attr_group = {
330 .attrs = tahvo_attributes, 330 .attrs = tahvo_attributes,
331}; 331};
332 332
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
index 032f5afaad4b..89f4ac4cd93e 100644
--- a/drivers/usb/phy/phy.c
+++ b/drivers/usb/phy/phy.c
@@ -18,6 +18,18 @@
18 18
19#include <linux/usb/phy.h> 19#include <linux/usb/phy.h>
20 20
21/* Default current range by charger type. */
22#define DEFAULT_SDP_CUR_MIN 2
23#define DEFAULT_SDP_CUR_MAX 500
24#define DEFAULT_SDP_CUR_MIN_SS 150
25#define DEFAULT_SDP_CUR_MAX_SS 900
26#define DEFAULT_DCP_CUR_MIN 500
27#define DEFAULT_DCP_CUR_MAX 5000
28#define DEFAULT_CDP_CUR_MIN 1500
29#define DEFAULT_CDP_CUR_MAX 5000
30#define DEFAULT_ACA_CUR_MIN 1500
31#define DEFAULT_ACA_CUR_MAX 5000
32
21static LIST_HEAD(phy_list); 33static LIST_HEAD(phy_list);
22static LIST_HEAD(phy_bind_list); 34static LIST_HEAD(phy_bind_list);
23static DEFINE_SPINLOCK(phy_lock); 35static DEFINE_SPINLOCK(phy_lock);
@@ -77,6 +89,221 @@ static struct usb_phy *__of_usb_find_phy(struct device_node *node)
77 return ERR_PTR(-EPROBE_DEFER); 89 return ERR_PTR(-EPROBE_DEFER);
78} 90}
79 91
92static void usb_phy_set_default_current(struct usb_phy *usb_phy)
93{
94 usb_phy->chg_cur.sdp_min = DEFAULT_SDP_CUR_MIN;
95 usb_phy->chg_cur.sdp_max = DEFAULT_SDP_CUR_MAX;
96 usb_phy->chg_cur.dcp_min = DEFAULT_DCP_CUR_MIN;
97 usb_phy->chg_cur.dcp_max = DEFAULT_DCP_CUR_MAX;
98 usb_phy->chg_cur.cdp_min = DEFAULT_CDP_CUR_MIN;
99 usb_phy->chg_cur.cdp_max = DEFAULT_CDP_CUR_MAX;
100 usb_phy->chg_cur.aca_min = DEFAULT_ACA_CUR_MIN;
101 usb_phy->chg_cur.aca_max = DEFAULT_ACA_CUR_MAX;
102}
103
104/**
105 * usb_phy_notify_charger_work - notify the USB charger state
106 * @work - the charger work to notify the USB charger state
107 *
108 * This work can be issued when USB charger state has been changed or
109 * USB charger current has been changed, then we can notify the current
110 * what can be drawn to power user and the charger state to userspace.
111 *
112 * If we get the charger type from extcon subsystem, we can notify the
113 * charger state to power user automatically by usb_phy_get_charger_type()
114 * issuing from extcon subsystem.
115 *
116 * If we get the charger type from ->charger_detect() instead of extcon
117 * subsystem, the usb phy driver should issue usb_phy_set_charger_state()
118 * to set charger state when the charger state has been changed.
119 */
120static void usb_phy_notify_charger_work(struct work_struct *work)
121{
122 struct usb_phy *usb_phy = container_of(work, struct usb_phy, chg_work);
123 char uchger_state[50] = { 0 };
124 char *envp[] = { uchger_state, NULL };
125 unsigned int min, max;
126
127 switch (usb_phy->chg_state) {
128 case USB_CHARGER_PRESENT:
129 usb_phy_get_charger_current(usb_phy, &min, &max);
130
131 atomic_notifier_call_chain(&usb_phy->notifier, max, usb_phy);
132 snprintf(uchger_state, ARRAY_SIZE(uchger_state),
133 "USB_CHARGER_STATE=%s", "USB_CHARGER_PRESENT");
134 break;
135 case USB_CHARGER_ABSENT:
136 usb_phy_set_default_current(usb_phy);
137
138 atomic_notifier_call_chain(&usb_phy->notifier, 0, usb_phy);
139 snprintf(uchger_state, ARRAY_SIZE(uchger_state),
140 "USB_CHARGER_STATE=%s", "USB_CHARGER_ABSENT");
141 break;
142 default:
143 dev_warn(usb_phy->dev, "Unknown USB charger state: %d\n",
144 usb_phy->chg_state);
145 return;
146 }
147
148 kobject_uevent_env(&usb_phy->dev->kobj, KOBJ_CHANGE, envp);
149}
150
151static void __usb_phy_get_charger_type(struct usb_phy *usb_phy)
152{
153 if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_SDP) > 0) {
154 usb_phy->chg_type = SDP_TYPE;
155 usb_phy->chg_state = USB_CHARGER_PRESENT;
156 } else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_CDP) > 0) {
157 usb_phy->chg_type = CDP_TYPE;
158 usb_phy->chg_state = USB_CHARGER_PRESENT;
159 } else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_DCP) > 0) {
160 usb_phy->chg_type = DCP_TYPE;
161 usb_phy->chg_state = USB_CHARGER_PRESENT;
162 } else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_ACA) > 0) {
163 usb_phy->chg_type = ACA_TYPE;
164 usb_phy->chg_state = USB_CHARGER_PRESENT;
165 } else {
166 usb_phy->chg_type = UNKNOWN_TYPE;
167 usb_phy->chg_state = USB_CHARGER_ABSENT;
168 }
169
170 schedule_work(&usb_phy->chg_work);
171}
172
173/**
174 * usb_phy_get_charger_type - get charger type from extcon subsystem
175 * @nb -the notifier block to determine charger type
176 * @state - the cable state
177 * @data - private data
178 *
179 * Determin the charger type from extcon subsystem which also means the
180 * charger state has been chaned, then we should notify this event.
181 */
182static int usb_phy_get_charger_type(struct notifier_block *nb,
183 unsigned long state, void *data)
184{
185 struct usb_phy *usb_phy = container_of(nb, struct usb_phy, type_nb);
186
187 __usb_phy_get_charger_type(usb_phy);
188 return NOTIFY_OK;
189}
190
191/**
192 * usb_phy_set_charger_current - set the USB charger current
193 * @usb_phy - the USB phy to be used
194 * @mA - the current need to be set
195 *
196 * Usually we only change the charger default current when USB finished the
197 * enumeration as one SDP charger. As one SDP charger, usb_phy_set_power()
198 * will issue this function to change charger current when after setting USB
199 * configuration, or suspend/resume USB. For other type charger, we should
200 * use the default charger current and we do not suggest to issue this function
201 * to change the charger current.
202 *
203 * When USB charger current has been changed, we need to notify the power users.
204 */
205void usb_phy_set_charger_current(struct usb_phy *usb_phy, unsigned int mA)
206{
207 switch (usb_phy->chg_type) {
208 case SDP_TYPE:
209 if (usb_phy->chg_cur.sdp_max == mA)
210 return;
211
212 usb_phy->chg_cur.sdp_max = (mA > DEFAULT_SDP_CUR_MAX_SS) ?
213 DEFAULT_SDP_CUR_MAX_SS : mA;
214 break;
215 case DCP_TYPE:
216 if (usb_phy->chg_cur.dcp_max == mA)
217 return;
218
219 usb_phy->chg_cur.dcp_max = (mA > DEFAULT_DCP_CUR_MAX) ?
220 DEFAULT_DCP_CUR_MAX : mA;
221 break;
222 case CDP_TYPE:
223 if (usb_phy->chg_cur.cdp_max == mA)
224 return;
225
226 usb_phy->chg_cur.cdp_max = (mA > DEFAULT_CDP_CUR_MAX) ?
227 DEFAULT_CDP_CUR_MAX : mA;
228 break;
229 case ACA_TYPE:
230 if (usb_phy->chg_cur.aca_max == mA)
231 return;
232
233 usb_phy->chg_cur.aca_max = (mA > DEFAULT_ACA_CUR_MAX) ?
234 DEFAULT_ACA_CUR_MAX : mA;
235 break;
236 default:
237 return;
238 }
239
240 schedule_work(&usb_phy->chg_work);
241}
242EXPORT_SYMBOL_GPL(usb_phy_set_charger_current);
243
244/**
245 * usb_phy_get_charger_current - get the USB charger current
246 * @usb_phy - the USB phy to be used
247 * @min - the minimum current
248 * @max - the maximum current
249 *
250 * Usually we will notify the maximum current to power user, but for some
251 * special case, power user also need the minimum current value. Then the
252 * power user can issue this function to get the suitable current.
253 */
254void usb_phy_get_charger_current(struct usb_phy *usb_phy,
255 unsigned int *min, unsigned int *max)
256{
257 switch (usb_phy->chg_type) {
258 case SDP_TYPE:
259 *min = usb_phy->chg_cur.sdp_min;
260 *max = usb_phy->chg_cur.sdp_max;
261 break;
262 case DCP_TYPE:
263 *min = usb_phy->chg_cur.dcp_min;
264 *max = usb_phy->chg_cur.dcp_max;
265 break;
266 case CDP_TYPE:
267 *min = usb_phy->chg_cur.cdp_min;
268 *max = usb_phy->chg_cur.cdp_max;
269 break;
270 case ACA_TYPE:
271 *min = usb_phy->chg_cur.aca_min;
272 *max = usb_phy->chg_cur.aca_max;
273 break;
274 default:
275 *min = 0;
276 *max = 0;
277 break;
278 }
279}
280EXPORT_SYMBOL_GPL(usb_phy_get_charger_current);
281
282/**
283 * usb_phy_set_charger_state - set the USB charger state
284 * @usb_phy - the USB phy to be used
285 * @state - the new state need to be set for charger
286 *
287 * The usb phy driver can issue this function when the usb phy driver
288 * detected the charger state has been changed, in this case the charger
289 * type should be get from ->charger_detect().
290 */
291void usb_phy_set_charger_state(struct usb_phy *usb_phy,
292 enum usb_charger_state state)
293{
294 if (usb_phy->chg_state == state || !usb_phy->charger_detect)
295 return;
296
297 usb_phy->chg_state = state;
298 if (usb_phy->chg_state == USB_CHARGER_PRESENT)
299 usb_phy->chg_type = usb_phy->charger_detect(usb_phy);
300 else
301 usb_phy->chg_type = UNKNOWN_TYPE;
302
303 schedule_work(&usb_phy->chg_work);
304}
305EXPORT_SYMBOL_GPL(usb_phy_set_charger_state);
306
80static void devm_usb_phy_release(struct device *dev, void *res) 307static void devm_usb_phy_release(struct device *dev, void *res)
81{ 308{
82 struct usb_phy *phy = *(struct usb_phy **)res; 309 struct usb_phy *phy = *(struct usb_phy **)res;
@@ -124,6 +351,44 @@ static int usb_add_extcon(struct usb_phy *x)
124 "register VBUS notifier failed\n"); 351 "register VBUS notifier failed\n");
125 return ret; 352 return ret;
126 } 353 }
354 } else {
355 x->type_nb.notifier_call = usb_phy_get_charger_type;
356
357 ret = devm_extcon_register_notifier(x->dev, x->edev,
358 EXTCON_CHG_USB_SDP,
359 &x->type_nb);
360 if (ret) {
361 dev_err(x->dev,
362 "register extcon USB SDP failed.\n");
363 return ret;
364 }
365
366 ret = devm_extcon_register_notifier(x->dev, x->edev,
367 EXTCON_CHG_USB_CDP,
368 &x->type_nb);
369 if (ret) {
370 dev_err(x->dev,
371 "register extcon USB CDP failed.\n");
372 return ret;
373 }
374
375 ret = devm_extcon_register_notifier(x->dev, x->edev,
376 EXTCON_CHG_USB_DCP,
377 &x->type_nb);
378 if (ret) {
379 dev_err(x->dev,
380 "register extcon USB DCP failed.\n");
381 return ret;
382 }
383
384 ret = devm_extcon_register_notifier(x->dev, x->edev,
385 EXTCON_CHG_USB_ACA,
386 &x->type_nb);
387 if (ret) {
388 dev_err(x->dev,
389 "register extcon USB ACA failed.\n");
390 return ret;
391 }
127 } 392 }
128 393
129 if (x->id_nb.notifier_call) { 394 if (x->id_nb.notifier_call) {
@@ -145,6 +410,13 @@ static int usb_add_extcon(struct usb_phy *x)
145 } 410 }
146 } 411 }
147 412
413 usb_phy_set_default_current(x);
414 INIT_WORK(&x->chg_work, usb_phy_notify_charger_work);
415 x->chg_type = UNKNOWN_TYPE;
416 x->chg_state = USB_CHARGER_DEFAULT;
417 if (x->type_nb.notifier_call)
418 __usb_phy_get_charger_type(x);
419
148 return 0; 420 return 0;
149} 421}
150 422
@@ -302,8 +574,8 @@ struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
302 574
303 node = of_parse_phandle(dev->of_node, phandle, index); 575 node = of_parse_phandle(dev->of_node, phandle, index);
304 if (!node) { 576 if (!node) {
305 dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle, 577 dev_dbg(dev, "failed to get %s phandle in %pOF node\n", phandle,
306 dev->of_node->full_name); 578 dev->of_node);
307 return ERR_PTR(-ENODEV); 579 return ERR_PTR(-ENODEV);
308 } 580 }
309 phy = devm_usb_get_phy_by_node(dev, node, NULL); 581 phy = devm_usb_get_phy_by_node(dev, node, NULL);
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 2c8161bcf5b5..c068b673420b 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -764,7 +764,7 @@ static int usbhsg_ep_set_wedge(struct usb_ep *ep)
764 return __usbhsg_ep_set_halt_wedge(ep, 1, 1); 764 return __usbhsg_ep_set_halt_wedge(ep, 1, 1);
765} 765}
766 766
767static struct usb_ep_ops usbhsg_ep_ops = { 767static const struct usb_ep_ops usbhsg_ep_ops = {
768 .enable = usbhsg_ep_enable, 768 .enable = usbhsg_ep_enable,
769 .disable = usbhsg_ep_disable, 769 .disable = usbhsg_ep_disable,
770 770
@@ -1082,7 +1082,6 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1082 ret = -ENOMEM; 1082 ret = -ENOMEM;
1083 goto usbhs_mod_gadget_probe_err_gpriv; 1083 goto usbhs_mod_gadget_probe_err_gpriv;
1084 } 1084 }
1085 spin_lock_init(&uep->lock);
1086 1085
1087 gpriv->transceiver = usb_get_phy(USB_PHY_TYPE_UNDEFINED); 1086 gpriv->transceiver = usb_get_phy(USB_PHY_TYPE_UNDEFINED);
1088 dev_info(dev, "%stransceiver found\n", 1087 dev_info(dev, "%stransceiver found\n",
@@ -1132,6 +1131,7 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1132 uep->ep.name = uep->ep_name; 1131 uep->ep.name = uep->ep_name;
1133 uep->ep.ops = &usbhsg_ep_ops; 1132 uep->ep.ops = &usbhsg_ep_ops;
1134 INIT_LIST_HEAD(&uep->ep.ep_list); 1133 INIT_LIST_HEAD(&uep->ep.ep_list);
1134 spin_lock_init(&uep->lock);
1135 1135
1136 /* init DCP */ 1136 /* init DCP */
1137 if (usbhsg_is_dcp(uep)) { 1137 if (usbhsg_is_dcp(uep)) {
diff --git a/drivers/usb/renesas_usbhs/mod_host.c b/drivers/usb/renesas_usbhs/mod_host.c
index dfb346e9bd0c..e256351cb72d 100644
--- a/drivers/usb/renesas_usbhs/mod_host.c
+++ b/drivers/usb/renesas_usbhs/mod_host.c
@@ -1285,7 +1285,7 @@ static int usbhsh_bus_nop(struct usb_hcd *hcd)
1285 return 0; 1285 return 0;
1286} 1286}
1287 1287
1288static struct hc_driver usbhsh_driver = { 1288static const struct hc_driver usbhsh_driver = {
1289 .description = usbhsh_hcd_name, 1289 .description = usbhsh_hcd_name,
1290 .hcd_priv_size = sizeof(struct usbhsh_hpriv), 1290 .hcd_priv_size = sizeof(struct usbhsh_hpriv),
1291 1291
diff --git a/drivers/usb/renesas_usbhs/pipe.c b/drivers/usb/renesas_usbhs/pipe.c
index 9396a8c14af8..d811f0550c04 100644
--- a/drivers/usb/renesas_usbhs/pipe.c
+++ b/drivers/usb/renesas_usbhs/pipe.c
@@ -401,7 +401,7 @@ static int usbhsp_setup_pipecfg(struct usbhs_pipe *pipe, int is_host,
401 u16 dir = 0; 401 u16 dir = 0;
402 u16 epnum = 0; 402 u16 epnum = 0;
403 u16 shtnak = 0; 403 u16 shtnak = 0;
404 u16 type_array[] = { 404 static const u16 type_array[] = {
405 [USB_ENDPOINT_XFER_BULK] = TYPE_BULK, 405 [USB_ENDPOINT_XFER_BULK] = TYPE_BULK,
406 [USB_ENDPOINT_XFER_INT] = TYPE_INT, 406 [USB_ENDPOINT_XFER_INT] = TYPE_INT,
407 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO, 407 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index fe123153b1a5..54bfef13966a 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -2016,13 +2016,11 @@ static const struct usb_device_id option_ids[] = {
2016 { USB_DEVICE(TPLINK_VENDOR_ID, 0x9000), /* TP-Link MA260 */ 2016 { USB_DEVICE(TPLINK_VENDOR_ID, 0x9000), /* TP-Link MA260 */
2017 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 2017 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
2018 { USB_DEVICE(CHANGHONG_VENDOR_ID, CHANGHONG_PRODUCT_CH690) }, 2018 { USB_DEVICE(CHANGHONG_VENDOR_ID, CHANGHONG_PRODUCT_CH690) },
2019 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d01, 0xff, 0x02, 0x01) }, /* D-Link DWM-156 (variant) */ 2019 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7d01, 0xff) }, /* D-Link DWM-156 (variant) */
2020 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d01, 0xff, 0x00, 0x00) }, /* D-Link DWM-156 (variant) */ 2020 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7d02, 0xff) },
2021 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d02, 0xff, 0x02, 0x01) }, 2021 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7d03, 0xff) },
2022 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d02, 0xff, 0x00, 0x00) },
2023 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x02, 0x01) },
2024 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x00, 0x00) },
2025 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7d04, 0xff) }, /* D-Link DWM-158 */ 2022 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7d04, 0xff) }, /* D-Link DWM-158 */
2023 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7d0e, 0xff) }, /* D-Link DWM-157 C1 */
2026 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7e19, 0xff), /* D-Link DWM-221 B1 */ 2024 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7e19, 0xff), /* D-Link DWM-221 B1 */
2027 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 2025 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
2028 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7e35, 0xff), /* D-Link DWM-222 */ 2026 { USB_DEVICE_INTERFACE_CLASS(0x2001, 0x7e35, 0xff), /* D-Link DWM-222 */
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
index 4176d1af9bf2..ec83b3b5efa9 100644
--- a/drivers/usb/storage/realtek_cr.c
+++ b/drivers/usb/storage/realtek_cr.c
@@ -47,7 +47,6 @@
47MODULE_DESCRIPTION("Driver for Realtek USB Card Reader"); 47MODULE_DESCRIPTION("Driver for Realtek USB Card Reader");
48MODULE_AUTHOR("wwang <wei_wang@realsil.com.cn>"); 48MODULE_AUTHOR("wwang <wei_wang@realsil.com.cn>");
49MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
50MODULE_VERSION("1.03");
51 50
52static int auto_delink_en = 1; 51static int auto_delink_en = 1;
53module_param(auto_delink_en, int, S_IRUGO | S_IWUSR); 52module_param(auto_delink_en, int, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
index 660180a5d5c4..7170404e8979 100644
--- a/drivers/usb/usbip/stub_main.c
+++ b/drivers/usb/usbip/stub_main.c
@@ -302,7 +302,6 @@ static int __init usbip_host_init(void)
302 goto err_create_file; 302 goto err_create_file;
303 } 303 }
304 304
305 pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
306 return ret; 305 return ret;
307 306
308err_create_file: 307err_create_file:
@@ -335,4 +334,3 @@ module_exit(usbip_host_exit);
335MODULE_AUTHOR(DRIVER_AUTHOR); 334MODULE_AUTHOR(DRIVER_AUTHOR);
336MODULE_DESCRIPTION(DRIVER_DESC); 335MODULE_DESCRIPTION(DRIVER_DESC);
337MODULE_LICENSE("GPL"); 336MODULE_LICENSE("GPL");
338MODULE_VERSION(USBIP_VERSION);
diff --git a/drivers/usb/usbip/usbip_common.c b/drivers/usb/usbip/usbip_common.c
index cab2b71a80d0..2281f3562870 100644
--- a/drivers/usb/usbip/usbip_common.c
+++ b/drivers/usb/usbip/usbip_common.c
@@ -763,7 +763,6 @@ static int __init usbip_core_init(void)
763{ 763{
764 int ret; 764 int ret;
765 765
766 pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
767 ret = usbip_init_eh(); 766 ret = usbip_init_eh();
768 if (ret) 767 if (ret)
769 return ret; 768 return ret;
@@ -783,4 +782,3 @@ module_exit(usbip_core_exit);
783MODULE_AUTHOR(DRIVER_AUTHOR); 782MODULE_AUTHOR(DRIVER_AUTHOR);
784MODULE_DESCRIPTION(DRIVER_DESC); 783MODULE_DESCRIPTION(DRIVER_DESC);
785MODULE_LICENSE("GPL"); 784MODULE_LICENSE("GPL");
786MODULE_VERSION(USBIP_VERSION);
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
index f8573a52e41a..3050fc99a417 100644
--- a/drivers/usb/usbip/usbip_common.h
+++ b/drivers/usb/usbip/usbip_common.h
@@ -34,8 +34,6 @@
34#include <linux/sched/task.h> 34#include <linux/sched/task.h>
35#include <uapi/linux/usbip.h> 35#include <uapi/linux/usbip.h>
36 36
37#define USBIP_VERSION "1.0.0"
38
39#undef pr_fmt 37#undef pr_fmt
40 38
41#ifdef DEBUG 39#ifdef DEBUG
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 2c4b2fd40406..11b9a22799cc 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1274,7 +1274,7 @@ static int vhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
1274 return 0; 1274 return 0;
1275} 1275}
1276 1276
1277static struct hc_driver vhci_hc_driver = { 1277static const struct hc_driver vhci_hc_driver = {
1278 .description = driver_name, 1278 .description = driver_name,
1279 .product_desc = driver_desc, 1279 .product_desc = driver_desc,
1280 .hcd_priv_size = sizeof(struct vhci_hcd), 1280 .hcd_priv_size = sizeof(struct vhci_hcd),
@@ -1516,7 +1516,6 @@ static int __init vhci_hcd_init(void)
1516 } 1516 }
1517 } 1517 }
1518 1518
1519 pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
1520 return ret; 1519 return ret;
1521 1520
1522err_add_hcd: 1521err_add_hcd:
@@ -1542,4 +1541,3 @@ module_exit(vhci_hcd_exit);
1542MODULE_AUTHOR(DRIVER_AUTHOR); 1541MODULE_AUTHOR(DRIVER_AUTHOR);
1543MODULE_DESCRIPTION(DRIVER_DESC); 1542MODULE_DESCRIPTION(DRIVER_DESC);
1544MODULE_LICENSE("GPL"); 1543MODULE_LICENSE("GPL");
1545MODULE_VERSION(USBIP_VERSION);
diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
index 5778b640ba9c..1b9f60a22e0b 100644
--- a/drivers/usb/usbip/vhci_sysfs.c
+++ b/drivers/usb/usbip/vhci_sysfs.c
@@ -366,7 +366,11 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
366 sockfd_put(socket); 366 sockfd_put(socket);
367 367
368 dev_err(dev, "port %d already used\n", rhport); 368 dev_err(dev, "port %d already used\n", rhport);
369 return -EINVAL; 369 /*
370 * Will be retried from userspace
371 * if there's another free port.
372 */
373 return -EBUSY;
370 } 374 }
371 375
372 dev_info(dev, "pdev(%u) rhport(%u) sockfd(%d)\n", 376 dev_info(dev, "pdev(%u) rhport(%u) sockfd(%d)\n",
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
index fb70cbef0671..aa4e440e9975 100644
--- a/drivers/usb/wusbcore/cbaf.c
+++ b/drivers/usb/wusbcore/cbaf.c
@@ -586,7 +586,7 @@ static struct attribute *cbaf_dev_attrs[] = {
586 NULL, 586 NULL,
587}; 587};
588 588
589static struct attribute_group cbaf_dev_attr_group = { 589static const struct attribute_group cbaf_dev_attr_group = {
590 .name = NULL, /* we want them in the same directory */ 590 .name = NULL, /* we want them in the same directory */
591 .attrs = cbaf_dev_attrs, 591 .attrs = cbaf_dev_attrs,
592}; 592};
diff --git a/drivers/usb/wusbcore/dev-sysfs.c b/drivers/usb/wusbcore/dev-sysfs.c
index d4de56b93d68..78212f8180ce 100644
--- a/drivers/usb/wusbcore/dev-sysfs.c
+++ b/drivers/usb/wusbcore/dev-sysfs.c
@@ -114,7 +114,7 @@ static struct attribute *wusb_dev_attrs[] = {
114 NULL, 114 NULL,
115}; 115};
116 116
117static struct attribute_group wusb_dev_attr_group = { 117static const struct attribute_group wusb_dev_attr_group = {
118 .name = NULL, /* we want them in the same directory */ 118 .name = NULL, /* we want them in the same directory */
119 .attrs = wusb_dev_attrs, 119 .attrs = wusb_dev_attrs,
120}; 120};
diff --git a/drivers/usb/wusbcore/wusbhc.c b/drivers/usb/wusbcore/wusbhc.c
index a273a91cf667..5338e42533c8 100644
--- a/drivers/usb/wusbcore/wusbhc.c
+++ b/drivers/usb/wusbcore/wusbhc.c
@@ -244,7 +244,7 @@ static struct attribute *wusbhc_attrs[] = {
244 NULL, 244 NULL,
245}; 245};
246 246
247static struct attribute_group wusbhc_attr_group = { 247static const struct attribute_group wusbhc_attr_group = {
248 .name = NULL, /* we want them in the same directory */ 248 .name = NULL, /* we want them in the same directory */
249 .attrs = wusbhc_attrs, 249 .attrs = wusbhc_attrs,
250}; 250};
diff --git a/drivers/uwb/lc-rc.c b/drivers/uwb/lc-rc.c
index 97ee1b46db69..b0816c753a63 100644
--- a/drivers/uwb/lc-rc.c
+++ b/drivers/uwb/lc-rc.c
@@ -228,7 +228,7 @@ static struct attribute *rc_attrs[] = {
228 NULL, 228 NULL,
229}; 229};
230 230
231static struct attribute_group rc_attr_group = { 231static const struct attribute_group rc_attr_group = {
232 .attrs = rc_attrs, 232 .attrs = rc_attrs,
233}; 233};
234 234
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 5006f9b5d837..6519cdc4c7d3 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -363,6 +363,12 @@ struct hid_item {
363#define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102 363#define HID_GROUP_LOGITECH_DJ_DEVICE 0x0102
364 364
365/* 365/*
366 * HID protocol status
367 */
368#define HID_REPORT_PROTOCOL 1
369#define HID_BOOT_PROTOCOL 0
370
371/*
366 * This is the global environment of the parser. This information is 372 * This is the global environment of the parser. This information is
367 * persistent for main-items. The global environment can be saved and 373 * persistent for main-items. The global environment can be saved and
368 * restored with PUSH/POP statements. 374 * restored with PUSH/POP statements.
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index c5fdfcf99828..d725cff7268d 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -58,6 +58,7 @@ struct ci_hdrc_platform_data {
58#define CI_HDRC_OVERRIDE_TX_BURST BIT(10) 58#define CI_HDRC_OVERRIDE_TX_BURST BIT(10)
59#define CI_HDRC_OVERRIDE_RX_BURST BIT(11) 59#define CI_HDRC_OVERRIDE_RX_BURST BIT(11)
60#define CI_HDRC_OVERRIDE_PHY_CONTROL BIT(12) /* Glue layer manages phy */ 60#define CI_HDRC_OVERRIDE_PHY_CONTROL BIT(12) /* Glue layer manages phy */
61#define CI_HDRC_REQUIRES_ALIGNED_DMA BIT(13)
61 enum usb_dr_mode dr_mode; 62 enum usb_dr_mode dr_mode;
62#define CI_HDRC_CONTROLLER_RESET_EVENT 0 63#define CI_HDRC_CONTROLLER_RESET_EVENT 0
63#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1 64#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 1a4a4bacfae6..21468a722c4a 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -48,6 +48,7 @@ struct usb_ep;
48 * by adding a zero length packet as needed; 48 * by adding a zero length packet as needed;
49 * @short_not_ok: When reading data, makes short packets be 49 * @short_not_ok: When reading data, makes short packets be
50 * treated as errors (queue stops advancing till cleanup). 50 * treated as errors (queue stops advancing till cleanup).
51 * @dma_mapped: Indicates if request has been mapped to DMA (internal)
51 * @complete: Function called when request completes, so this request and 52 * @complete: Function called when request completes, so this request and
52 * its buffer may be re-used. The function will always be called with 53 * its buffer may be re-used. The function will always be called with
53 * interrupts disabled, and it must not sleep. 54 * interrupts disabled, and it must not sleep.
@@ -103,6 +104,7 @@ struct usb_request {
103 unsigned no_interrupt:1; 104 unsigned no_interrupt:1;
104 unsigned zero:1; 105 unsigned zero:1;
105 unsigned short_not_ok:1; 106 unsigned short_not_ok:1;
107 unsigned dma_mapped:1;
106 108
107 void (*complete)(struct usb_ep *ep, 109 void (*complete)(struct usb_ep *ep,
108 struct usb_request *req); 110 struct usb_request *req);
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 299245105610..8c6914873a16 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -12,6 +12,7 @@
12#include <linux/extcon.h> 12#include <linux/extcon.h>
13#include <linux/notifier.h> 13#include <linux/notifier.h>
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <uapi/linux/usb/charger.h>
15 16
16enum usb_phy_interface { 17enum usb_phy_interface {
17 USBPHY_INTERFACE_MODE_UNKNOWN, 18 USBPHY_INTERFACE_MODE_UNKNOWN,
@@ -72,6 +73,17 @@ struct usb_phy_io_ops {
72 int (*write)(struct usb_phy *x, u32 val, u32 reg); 73 int (*write)(struct usb_phy *x, u32 val, u32 reg);
73}; 74};
74 75
76struct usb_charger_current {
77 unsigned int sdp_min;
78 unsigned int sdp_max;
79 unsigned int dcp_min;
80 unsigned int dcp_max;
81 unsigned int cdp_min;
82 unsigned int cdp_max;
83 unsigned int aca_min;
84 unsigned int aca_max;
85};
86
75struct usb_phy { 87struct usb_phy {
76 struct device *dev; 88 struct device *dev;
77 const char *label; 89 const char *label;
@@ -91,6 +103,13 @@ struct usb_phy {
91 struct extcon_dev *id_edev; 103 struct extcon_dev *id_edev;
92 struct notifier_block vbus_nb; 104 struct notifier_block vbus_nb;
93 struct notifier_block id_nb; 105 struct notifier_block id_nb;
106 struct notifier_block type_nb;
107
108 /* Support USB charger */
109 enum usb_charger_type chg_type;
110 enum usb_charger_state chg_state;
111 struct usb_charger_current chg_cur;
112 struct work_struct chg_work;
94 113
95 /* for notification of usb_phy_events */ 114 /* for notification of usb_phy_events */
96 struct atomic_notifier_head notifier; 115 struct atomic_notifier_head notifier;
@@ -129,6 +148,12 @@ struct usb_phy {
129 enum usb_device_speed speed); 148 enum usb_device_speed speed);
130 int (*notify_disconnect)(struct usb_phy *x, 149 int (*notify_disconnect)(struct usb_phy *x,
131 enum usb_device_speed speed); 150 enum usb_device_speed speed);
151
152 /*
153 * Charger detection method can be implemented if you need to
154 * manually detect the charger type.
155 */
156 enum usb_charger_type (*charger_detect)(struct usb_phy *x);
132}; 157};
133 158
134/** 159/**
@@ -219,6 +244,12 @@ extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
219extern int usb_bind_phy(const char *dev_name, u8 index, 244extern int usb_bind_phy(const char *dev_name, u8 index,
220 const char *phy_dev_name); 245 const char *phy_dev_name);
221extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); 246extern void usb_phy_set_event(struct usb_phy *x, unsigned long event);
247extern void usb_phy_set_charger_current(struct usb_phy *usb_phy,
248 unsigned int mA);
249extern void usb_phy_get_charger_current(struct usb_phy *usb_phy,
250 unsigned int *min, unsigned int *max);
251extern void usb_phy_set_charger_state(struct usb_phy *usb_phy,
252 enum usb_charger_state state);
222#else 253#else
223static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) 254static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
224{ 255{
@@ -270,12 +301,33 @@ static inline int usb_bind_phy(const char *dev_name, u8 index,
270static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) 301static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event)
271{ 302{
272} 303}
304
305static inline void usb_phy_set_charger_current(struct usb_phy *usb_phy,
306 unsigned int mA)
307{
308}
309
310static inline void usb_phy_get_charger_current(struct usb_phy *usb_phy,
311 unsigned int *min,
312 unsigned int *max)
313{
314}
315
316static inline void usb_phy_set_charger_state(struct usb_phy *usb_phy,
317 enum usb_charger_state state)
318{
319}
273#endif 320#endif
274 321
275static inline int 322static inline int
276usb_phy_set_power(struct usb_phy *x, unsigned mA) 323usb_phy_set_power(struct usb_phy *x, unsigned mA)
277{ 324{
278 if (x && x->set_power) 325 if (!x)
326 return 0;
327
328 usb_phy_set_charger_current(x, mA);
329
330 if (x->set_power)
279 return x->set_power(x, mA); 331 return x->set_power(x, mA);
280 return 0; 332 return 0;
281} 333}
diff --git a/include/uapi/linux/usb/charger.h b/include/uapi/linux/usb/charger.h
new file mode 100644
index 000000000000..5f72af35b3ed
--- /dev/null
+++ b/include/uapi/linux/usb/charger.h
@@ -0,0 +1,31 @@
1/*
2 * This file defines the USB charger type and state that are needed for
3 * USB device APIs.
4 */
5
6#ifndef _UAPI__LINUX_USB_CHARGER_H
7#define _UAPI__LINUX_USB_CHARGER_H
8
9/*
10 * USB charger type:
11 * SDP (Standard Downstream Port)
12 * DCP (Dedicated Charging Port)
13 * CDP (Charging Downstream Port)
14 * ACA (Accessory Charger Adapters)
15 */
16enum usb_charger_type {
17 UNKNOWN_TYPE,
18 SDP_TYPE,
19 DCP_TYPE,
20 CDP_TYPE,
21 ACA_TYPE,
22};
23
24/* USB charger state */
25enum usb_charger_state {
26 USB_CHARGER_DEFAULT,
27 USB_CHARGER_PRESENT,
28 USB_CHARGER_ABSENT,
29};
30
31#endif /* _UAPI__LINUX_USB_CHARGER_H */
diff --git a/tools/usb/usbip/src/usbip_attach.c b/tools/usb/usbip/src/usbip_attach.c
index 6e89768ffe30..7f07b2d50f59 100644
--- a/tools/usb/usbip/src/usbip_attach.c
+++ b/tools/usb/usbip/src/usbip_attach.c
@@ -99,29 +99,34 @@ static int import_device(int sockfd, struct usbip_usb_device *udev)
99 rc = usbip_vhci_driver_open(); 99 rc = usbip_vhci_driver_open();
100 if (rc < 0) { 100 if (rc < 0) {
101 err("open vhci_driver"); 101 err("open vhci_driver");
102 return -1; 102 goto err_out;
103 } 103 }
104 104
105 port = usbip_vhci_get_free_port(speed); 105 do {
106 if (port < 0) { 106 port = usbip_vhci_get_free_port(speed);
107 err("no free port"); 107 if (port < 0) {
108 usbip_vhci_driver_close(); 108 err("no free port");
109 return -1; 109 goto err_driver_close;
110 } 110 }
111 111
112 dbg("got free port %d", port); 112 dbg("got free port %d", port);
113 113
114 rc = usbip_vhci_attach_device(port, sockfd, udev->busnum, 114 rc = usbip_vhci_attach_device(port, sockfd, udev->busnum,
115 udev->devnum, udev->speed); 115 udev->devnum, udev->speed);
116 if (rc < 0) { 116 if (rc < 0 && errno != EBUSY) {
117 err("import device"); 117 err("import device");
118 usbip_vhci_driver_close(); 118 goto err_driver_close;
119 return -1; 119 }
120 } 120 } while (rc < 0);
121 121
122 usbip_vhci_driver_close(); 122 usbip_vhci_driver_close();
123 123
124 return port; 124 return port;
125
126err_driver_close:
127 usbip_vhci_driver_close();
128err_out:
129 return -1;
125} 130}
126 131
127static int query_import_device(int sockfd, char *busid) 132static int query_import_device(int sockfd, char *busid)